- A new test case for romcc
[coreboot.git] / src / northbridge / amd / amdk8 / raminit.c
1 #include <cpu/k8/mtrr.h>
2 #define MEMORY_SUSE_SOLO  1 /* SuSE Solo configuration */
3 #define MEMORY_LNXI_SOLO  2 /* LNXI Solo configuration */
4 #define MEMORY_LNXI_HDAMA 3 /* LNXI HDAMA configuration */
5
6
7 #ifndef MEMORY_CONFIG
8 #define MEMORY_CONFIG MEMORY_SUSE_SOLO
9 #endif
10
11 static void setup_resource_map(const unsigned int *register_values, int max)
12 {
13         int i;
14         print_debug("setting up resource map....\r\n");
15         for(i = 0; i < max; i += 3) {
16                 device_t dev;
17                 unsigned where;
18                 unsigned long reg;
19 #if 0
20                 print_debug_hex32(register_values[i]);
21                 print_debug(" <-");
22                 print_debug_hex32(register_values[i+2]);
23                 print_debug("\r\n");
24 #endif
25                 dev = register_values[i] & ~0xff;
26                 where = register_values[i] & 0xff;
27                 reg = pci_read_config32(dev, where);
28                 reg &= register_values[i+1];
29                 reg |= register_values[i+2];
30                 pci_write_config32(dev, where, reg);
31 #if 0
32                 reg = pci_read_config32(register_values[i]);
33                 reg &= register_values[i+1];
34                 reg |= register_values[i+2] & ~register_values[i+1];
35                 pci_write_config32(register_values[i], reg);
36 #endif
37         }
38         print_debug("done.\r\n");
39 }
40
41 static void setup_default_resource_map(void)
42 {
43         static const unsigned int register_values[] = {
44         /* Careful set limit registers before base registers which contain the enables */
45         /* DRAM Limit i Registers
46          * F1:0x44 i = 0
47          * F1:0x4C i = 1
48          * F1:0x54 i = 2
49          * F1:0x5C i = 3
50          * F1:0x64 i = 4
51          * F1:0x6C i = 5
52          * F1:0x74 i = 6
53          * F1:0x7C i = 7
54          * [ 2: 0] Destination Node ID
55          *         000 = Node 0
56          *         001 = Node 1
57          *         010 = Node 2
58          *         011 = Node 3
59          *         100 = Node 4
60          *         101 = Node 5
61          *         110 = Node 6
62          *         111 = Node 7
63          * [ 7: 3] Reserved
64          * [10: 8] Interleave select
65          *         specifies the values of A[14:12] to use with interleave enable.
66          * [15:11] Reserved
67          * [31:16] DRAM Limit Address i Bits 39-24
68          *         This field defines the upper address bits of a 40 bit  address
69          *         that define the end of the DRAM region.
70          */
71         PCI_ADDR(0, 0x18, 1, 0x44), 0x0000f8f8, 0x00000000,
72         PCI_ADDR(0, 0x18, 1, 0x4C), 0x0000f8f8, 0x00000001,
73         PCI_ADDR(0, 0x18, 1, 0x54), 0x0000f8f8, 0x00000002,
74         PCI_ADDR(0, 0x18, 1, 0x5C), 0x0000f8f8, 0x00000003,
75         PCI_ADDR(0, 0x18, 1, 0x64), 0x0000f8f8, 0x00000004,
76         PCI_ADDR(0, 0x18, 1, 0x6C), 0x0000f8f8, 0x00000005,
77         PCI_ADDR(0, 0x18, 1, 0x74), 0x0000f8f8, 0x00000006,
78         PCI_ADDR(0, 0x18, 1, 0x7C), 0x0000f8f8, 0x00000007,
79         /* DRAM Base i Registers
80          * F1:0x40 i = 0
81          * F1:0x48 i = 1
82          * F1:0x50 i = 2
83          * F1:0x58 i = 3
84          * F1:0x60 i = 4
85          * F1:0x68 i = 5
86          * F1:0x70 i = 6
87          * F1:0x78 i = 7
88          * [ 0: 0] Read Enable
89          *         0 = Reads Disabled
90          *         1 = Reads Enabled
91          * [ 1: 1] Write Enable
92          *         0 = Writes Disabled
93          *         1 = Writes Enabled
94          * [ 7: 2] Reserved
95          * [10: 8] Interleave Enable
96          *         000 = No interleave
97          *         001 = Interleave on A[12] (2 nodes)
98          *         010 = reserved
99          *         011 = Interleave on A[12] and A[14] (4 nodes)
100          *         100 = reserved
101          *         101 = reserved
102          *         110 = reserved
103          *         111 = Interleve on A[12] and A[13] and A[14] (8 nodes)
104          * [15:11] Reserved
105          * [13:16] DRAM Base Address i Bits 39-24
106          *         This field defines the upper address bits of a 40-bit address
107          *         that define the start of the DRAM region.
108          */
109         PCI_ADDR(0, 0x18, 1, 0x40), 0x0000f8fc, 0x00000000,
110         PCI_ADDR(0, 0x18, 1, 0x48), 0x0000f8fc, 0x00000000,
111         PCI_ADDR(0, 0x18, 1, 0x50), 0x0000f8fc, 0x00000000,
112         PCI_ADDR(0, 0x18, 1, 0x58), 0x0000f8fc, 0x00000000,
113         PCI_ADDR(0, 0x18, 1, 0x60), 0x0000f8fc, 0x00000000,
114         PCI_ADDR(0, 0x18, 1, 0x68), 0x0000f8fc, 0x00000000,
115         PCI_ADDR(0, 0x18, 1, 0x70), 0x0000f8fc, 0x00000000,
116         PCI_ADDR(0, 0x18, 1, 0x78), 0x0000f8fc, 0x00000000,
117
118         /* Memory-Mapped I/O Limit i Registers
119          * F1:0x84 i = 0
120          * F1:0x8C i = 1
121          * F1:0x94 i = 2
122          * F1:0x9C i = 3
123          * F1:0xA4 i = 4
124          * F1:0xAC i = 5
125          * F1:0xB4 i = 6
126          * F1:0xBC i = 7
127          * [ 2: 0] Destination Node ID
128          *         000 = Node 0
129          *         001 = Node 1
130          *         010 = Node 2
131          *         011 = Node 3
132          *         100 = Node 4
133          *         101 = Node 5
134          *         110 = Node 6
135          *         111 = Node 7
136          * [ 3: 3] Reserved
137          * [ 5: 4] Destination Link ID
138          *         00 = Link 0
139          *         01 = Link 1
140          *         10 = Link 2
141          *         11 = Reserved
142          * [ 6: 6] Reserved
143          * [ 7: 7] Non-Posted
144          *         0 = CPU writes may be posted
145          *         1 = CPU writes must be non-posted
146          * [31: 8] Memory-Mapped I/O Limit Address i (39-16)
147          *         This field defines the upp adddress bits of a 40-bit address that
148          *         defines the end of a memory-mapped I/O region n
149          */
150         PCI_ADDR(0, 0x18, 1, 0x84), 0x00000048, 0x00000000,
151         PCI_ADDR(0, 0x18, 1, 0x8C), 0x00000048, 0x00000000,
152         PCI_ADDR(0, 0x18, 1, 0x94), 0x00000048, 0x00000000,
153         PCI_ADDR(0, 0x18, 1, 0x9C), 0x00000048, 0x00000000,
154         PCI_ADDR(0, 0x18, 1, 0xA4), 0x00000048, 0x00000000,
155         PCI_ADDR(0, 0x18, 1, 0xAC), 0x00000048, 0x00000000,
156         PCI_ADDR(0, 0x18, 1, 0xB4), 0x00000048, 0x00000000,
157         PCI_ADDR(0, 0x18, 1, 0xBC), 0x00000048, 0x00000000,
158
159         /* Memory-Mapped I/O Base i Registers
160          * F1:0x80 i = 0
161          * F1:0x88 i = 1
162          * F1:0x90 i = 2
163          * F1:0x98 i = 3
164          * F1:0xA0 i = 4
165          * F1:0xA8 i = 5
166          * F1:0xB0 i = 6
167          * F1:0xB8 i = 7
168          * [ 0: 0] Read Enable
169          *         0 = Reads disabled
170          *         1 = Reads Enabled
171          * [ 1: 1] Write Enable
172          *         0 = Writes disabled
173          *         1 = Writes Enabled
174          * [ 2: 2] Cpu Disable
175          *         0 = Cpu can use this I/O range
176          *         1 = Cpu requests do not use this I/O range
177          * [ 3: 3] Lock
178          *         0 = base/limit registers i are read/write
179          *         1 = base/limit registers i are read-only
180          * [ 7: 4] Reserved
181          * [31: 8] Memory-Mapped I/O Base Address i (39-16)
182          *         This field defines the upper address bits of a 40bit address 
183          *         that defines the start of memory-mapped I/O region i
184          */
185         PCI_ADDR(0, 0x18, 1, 0x80), 0x000000f0, 0x00000000,
186         PCI_ADDR(0, 0x18, 1, 0x88), 0x000000f0, 0x00000000,
187         PCI_ADDR(0, 0x18, 1, 0x90), 0x000000f0, 0x00000000,
188         PCI_ADDR(0, 0x18, 1, 0x98), 0x000000f0, 0x00000000,
189         PCI_ADDR(0, 0x18, 1, 0xA0), 0x000000f0, 0x00000000,
190         PCI_ADDR(0, 0x18, 1, 0xA8), 0x000000f0, 0x00000000,
191         PCI_ADDR(0, 0x18, 1, 0xB0), 0x000000f0, 0x00000000,
192         PCI_ADDR(0, 0x18, 1, 0xB8), 0x000000f0, 0x00000000,
193
194         /* PCI I/O Limit i Registers
195          * F1:0xC4 i = 0
196          * F1:0xCC i = 1
197          * F1:0xD4 i = 2
198          * F1:0xDC i = 3
199          * [ 2: 0] Destination Node ID
200          *         000 = Node 0
201          *         001 = Node 1
202          *         010 = Node 2
203          *         011 = Node 3
204          *         100 = Node 4
205          *         101 = Node 5
206          *         110 = Node 6
207          *         111 = Node 7
208          * [ 3: 3] Reserved
209          * [ 5: 4] Destination Link ID
210          *         00 = Link 0
211          *         01 = Link 1
212          *         10 = Link 2
213          *         11 = reserved
214          * [11: 6] Reserved
215          * [24:12] PCI I/O Limit Address i
216          *         This field defines the end of PCI I/O region n
217          * [31:25] Reserved
218          */
219         PCI_ADDR(0, 0x18, 1, 0xC4), 0xFE000FC8, 0x01fff000,
220         PCI_ADDR(0, 0x18, 1, 0xCC), 0xFE000FC8, 0x00000000,
221         PCI_ADDR(0, 0x18, 1, 0xD4), 0xFE000FC8, 0x00000000,
222         PCI_ADDR(0, 0x18, 1, 0xDC), 0xFE000FC8, 0x00000000,
223
224         /* PCI I/O Base i Registers
225          * F1:0xC0 i = 0
226          * F1:0xC8 i = 1
227          * F1:0xD0 i = 2
228          * F1:0xD8 i = 3
229          * [ 0: 0] Read Enable
230          *         0 = Reads Disabled
231          *         1 = Reads Enabled
232          * [ 1: 1] Write Enable
233          *         0 = Writes Disabled
234          *         1 = Writes Enabled
235          * [ 3: 2] Reserved
236          * [ 4: 4] VGA Enable
237          *         0 = VGA matches Disabled
238          *         1 = matches all address < 64K and where A[9:0] is in the 
239          *             range 3B0-3BB or 3C0-3DF independen of the base & limit registers
240          * [ 5: 5] ISA Enable
241          *         0 = ISA matches Disabled
242          *         1 = Blocks address < 64K and in the last 768 bytes of eack 1K block
243          *             from matching agains this base/limit pair
244          * [11: 6] Reserved
245          * [24:12] PCI I/O Base i
246          *         This field defines the start of PCI I/O region n 
247          * [31:25] Reserved
248          */
249         PCI_ADDR(0, 0x18, 1, 0xC0), 0xFE000FCC, 0x00000003,
250         PCI_ADDR(0, 0x18, 1, 0xC8), 0xFE000FCC, 0x00000000,
251         PCI_ADDR(0, 0x18, 1, 0xD0), 0xFE000FCC, 0x00000000,
252         PCI_ADDR(0, 0x18, 1, 0xD8), 0xFE000FCC, 0x00000000,
253
254         /* Config Base and Limit i Registers
255          * F1:0xE0 i = 0
256          * F1:0xE4 i = 1
257          * F1:0xE8 i = 2
258          * F1:0xEC i = 3
259          * [ 0: 0] Read Enable
260          *         0 = Reads Disabled
261          *         1 = Reads Enabled
262          * [ 1: 1] Write Enable
263          *         0 = Writes Disabled
264          *         1 = Writes Enabled
265          * [ 2: 2] Device Number Compare Enable
266          *         0 = The ranges are based on bus number
267          *         1 = The ranges are ranges of devices on bus 0
268          * [ 3: 3] Reserved
269          * [ 6: 4] Destination Node
270          *         000 = Node 0
271          *         001 = Node 1
272          *         010 = Node 2
273          *         011 = Node 3
274          *         100 = Node 4
275          *         101 = Node 5
276          *         110 = Node 6
277          *         111 = Node 7
278          * [ 7: 7] Reserved
279          * [ 9: 8] Destination Link
280          *         00 = Link 0
281          *         01 = Link 1
282          *         10 = Link 2
283          *         11 - Reserved
284          * [15:10] Reserved
285          * [23:16] Bus Number Base i
286          *         This field defines the lowest bus number in configuration region i
287          * [31:24] Bus Number Limit i
288          *         This field defines the highest bus number in configuration regin i
289          */
290         PCI_ADDR(0, 0x18, 1, 0xE0), 0x0000FC88, 0xff000003,
291         PCI_ADDR(0, 0x18, 1, 0xE4), 0x0000FC88, 0x00000000,
292         PCI_ADDR(0, 0x18, 1, 0xE8), 0x0000FC88, 0x00000000,
293         PCI_ADDR(0, 0x18, 1, 0xEC), 0x0000FC88, 0x00000000,
294         };
295         int max;
296         max = sizeof(register_values)/sizeof(register_values[0]);
297         setup_resource_map(register_values, max);
298 }
299
300 static void sdram_set_registers(void)
301 {
302         static const unsigned int register_values[] = {
303
304         /* Careful set limit registers before base registers which contain the enables */
305         /* DRAM Limit i Registers
306          * F1:0x44 i = 0
307          * F1:0x4C i = 1
308          * F1:0x54 i = 2
309          * F1:0x5C i = 3
310          * F1:0x64 i = 4
311          * F1:0x6C i = 5
312          * F1:0x74 i = 6
313          * F1:0x7C i = 7
314          * [ 2: 0] Destination Node ID
315          *         000 = Node 0
316          *         001 = Node 1
317          *         010 = Node 2
318          *         011 = Node 3
319          *         100 = Node 4
320          *         101 = Node 5
321          *         110 = Node 6
322          *         111 = Node 7
323          * [ 7: 3] Reserved
324          * [10: 8] Interleave select
325          *         specifies the values of A[14:12] to use with interleave enable.
326          * [15:11] Reserved
327          * [31:16] DRAM Limit Address i Bits 39-24
328          *         This field defines the upper address bits of a 40 bit  address
329          *         that define the end of the DRAM region.
330          */
331 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
332         PCI_ADDR(0, 0x18, 1, 0x44), 0x0000f8f8, 0x003f0000,
333         PCI_ADDR(0, 0x18, 1, 0x4C), 0x0000f8f8, 0x00000001,
334 #endif
335 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
336         PCI_ADDR(0, 0x18, 1, 0x44), 0x0000f8f8, 0x001f0000,
337         PCI_ADDR(0, 0x18, 1, 0x4C), 0x0000f8f8, 0x00000001,
338 #endif
339 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
340         PCI_ADDR(0, 0x18, 1, 0x44), 0x0000f8f8, 0x003f0000,
341         PCI_ADDR(0, 0x18, 1, 0x4C), 0x0000f8f8, 0x007f0001,
342 #endif
343         PCI_ADDR(0, 0x18, 1, 0x54), 0x0000f8f8, 0x00000002,
344         PCI_ADDR(0, 0x18, 1, 0x5C), 0x0000f8f8, 0x00000003,
345         PCI_ADDR(0, 0x18, 1, 0x64), 0x0000f8f8, 0x00000004,
346         PCI_ADDR(0, 0x18, 1, 0x6C), 0x0000f8f8, 0x00000005,
347         PCI_ADDR(0, 0x18, 1, 0x74), 0x0000f8f8, 0x00000006,
348         PCI_ADDR(0, 0x18, 1, 0x7C), 0x0000f8f8, 0x00000007,
349         /* DRAM Base i Registers
350          * F1:0x40 i = 0
351          * F1:0x48 i = 1
352          * F1:0x50 i = 2
353          * F1:0x58 i = 3
354          * F1:0x60 i = 4
355          * F1:0x68 i = 5
356          * F1:0x70 i = 6
357          * F1:0x78 i = 7
358          * [ 0: 0] Read Enable
359          *         0 = Reads Disabled
360          *         1 = Reads Enabled
361          * [ 1: 1] Write Enable
362          *         0 = Writes Disabled
363          *         1 = Writes Enabled
364          * [ 7: 2] Reserved
365          * [10: 8] Interleave Enable
366          *         000 = No interleave
367          *         001 = Interleave on A[12] (2 nodes)
368          *         010 = reserved
369          *         011 = Interleave on A[12] and A[14] (4 nodes)
370          *         100 = reserved
371          *         101 = reserved
372          *         110 = reserved
373          *         111 = Interleve on A[12] and A[13] and A[14] (8 nodes)
374          * [15:11] Reserved
375          * [13:16] DRAM Base Address i Bits 39-24
376          *         This field defines the upper address bits of a 40-bit address
377          *         that define the start of the DRAM region.
378          */
379         PCI_ADDR(0, 0x18, 1, 0x40), 0x0000f8fc, 0x00000003,
380 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
381         PCI_ADDR(0, 0x18, 1, 0x48), 0x0000f8fc, 0x00400000,
382         PCI_ADDR(0, 0x18, 1, 0x50), 0x0000f8fc, 0x00400000,
383         PCI_ADDR(0, 0x18, 1, 0x58), 0x0000f8fc, 0x00400000,
384         PCI_ADDR(0, 0x18, 1, 0x60), 0x0000f8fc, 0x00400000,
385         PCI_ADDR(0, 0x18, 1, 0x68), 0x0000f8fc, 0x00400000,
386         PCI_ADDR(0, 0x18, 1, 0x70), 0x0000f8fc, 0x00400000,
387         PCI_ADDR(0, 0x18, 1, 0x78), 0x0000f8fc, 0x00400000,
388 #endif
389 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
390         PCI_ADDR(0, 0x18, 1, 0x48), 0x0000f8fc, 0x00200000,
391         PCI_ADDR(0, 0x18, 1, 0x50), 0x0000f8fc, 0x00200000,
392         PCI_ADDR(0, 0x18, 1, 0x58), 0x0000f8fc, 0x00200000,
393         PCI_ADDR(0, 0x18, 1, 0x60), 0x0000f8fc, 0x00200000,
394         PCI_ADDR(0, 0x18, 1, 0x68), 0x0000f8fc, 0x00200000,
395         PCI_ADDR(0, 0x18, 1, 0x70), 0x0000f8fc, 0x00200000,
396         PCI_ADDR(0, 0x18, 1, 0x78), 0x0000f8fc, 0x00200000,
397 #endif
398 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
399         PCI_ADDR(0, 0x18, 1, 0x48), 0x0000f8fc, 0x00400003,
400         PCI_ADDR(0, 0x18, 1, 0x50), 0x0000f8fc, 0x00800000,
401         PCI_ADDR(0, 0x18, 1, 0x58), 0x0000f8fc, 0x00800000,
402         PCI_ADDR(0, 0x18, 1, 0x60), 0x0000f8fc, 0x00800000,
403         PCI_ADDR(0, 0x18, 1, 0x68), 0x0000f8fc, 0x00800000,
404         PCI_ADDR(0, 0x18, 1, 0x70), 0x0000f8fc, 0x00800000,
405         PCI_ADDR(0, 0x18, 1, 0x78), 0x0000f8fc, 0x00800000,
406         PCI_ADDR(0, 0x18, 1, 0x78), 0x0000f8fc, 0x00800000,
407 #endif
408
409         /* Memory-Mapped I/O Limit i Registers
410          * F1:0x84 i = 0
411          * F1:0x8C i = 1
412          * F1:0x94 i = 2
413          * F1:0x9C i = 3
414          * F1:0xA4 i = 4
415          * F1:0xAC i = 5
416          * F1:0xB4 i = 6
417          * F1:0xBC i = 7
418          * [ 2: 0] Destination Node ID
419          *         000 = Node 0
420          *         001 = Node 1
421          *         010 = Node 2
422          *         011 = Node 3
423          *         100 = Node 4
424          *         101 = Node 5
425          *         110 = Node 6
426          *         111 = Node 7
427          * [ 3: 3] Reserved
428          * [ 5: 4] Destination Link ID
429          *         00 = Link 0
430          *         01 = Link 1
431          *         10 = Link 2
432          *         11 = Reserved
433          * [ 6: 6] Reserved
434          * [ 7: 7] Non-Posted
435          *         0 = CPU writes may be posted
436          *         1 = CPU writes must be non-posted
437          * [31: 8] Memory-Mapped I/O Limit Address i (39-16)
438          *         This field defines the upp adddress bits of a 40-bit address that
439          *         defines the end of a memory-mapped I/O region n
440          */
441 #if (MEMORY_CONFIG == MEMORY_LNXI_SOLO) || (MEMORY_CONFIG == MEMORY_SUSE_SOLO)
442         PCI_ADDR(0, 0x18, 1, 0x84), 0x00000048, 0x00e1ff00,
443         PCI_ADDR(0, 0x18, 1, 0x8C), 0x00000048, 0x00dfff00,
444         PCI_ADDR(0, 0x18, 1, 0x94), 0x00000048, 0x00e3ff00,
445         PCI_ADDR(0, 0x18, 1, 0x9C), 0x00000048, 0x00000000,
446         PCI_ADDR(0, 0x18, 1, 0xA4), 0x00000048, 0x00000000,
447         PCI_ADDR(0, 0x18, 1, 0xAC), 0x00000048, 0x00000000,
448         PCI_ADDR(0, 0x18, 1, 0xB4), 0x00000048, 0x00000b00,
449         PCI_ADDR(0, 0x18, 1, 0xBC), 0x00000048, 0x00fe0b00,
450 #endif
451 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
452         PCI_ADDR(0, 0x18, 1, 0x84), 0x00000048, 0x00fe2f00,
453         PCI_ADDR(0, 0x18, 1, 0x8C), 0x00000048, 0x00000000,
454         PCI_ADDR(0, 0x18, 1, 0x94), 0x00000048, 0x00000000,
455         PCI_ADDR(0, 0x18, 1, 0x9C), 0x00000048, 0x00000000,
456         PCI_ADDR(0, 0x18, 1, 0xA4), 0x00000048, 0x00fec000,
457         PCI_ADDR(0, 0x18, 1, 0xAC), 0x00000048, 0x0000b000,
458         PCI_ADDR(0, 0x18, 1, 0xB4), 0x00000048, 0x00000000,
459         PCI_ADDR(0, 0x18, 1, 0xBC), 0x00000048, 0x00000000,
460 #endif
461
462         /* Memory-Mapped I/O Base i Registers
463          * F1:0x80 i = 0
464          * F1:0x88 i = 1
465          * F1:0x90 i = 2
466          * F1:0x98 i = 3
467          * F1:0xA0 i = 4
468          * F1:0xA8 i = 5
469          * F1:0xB0 i = 6
470          * F1:0xB8 i = 7
471          * [ 0: 0] Read Enable
472          *         0 = Reads disabled
473          *         1 = Reads Enabled
474          * [ 1: 1] Write Enable
475          *         0 = Writes disabled
476          *         1 = Writes Enabled
477          * [ 2: 2] Cpu Disable
478          *         0 = Cpu can use this I/O range
479          *         1 = Cpu requests do not use this I/O range
480          * [ 3: 3] Lock
481          *         0 = base/limit registers i are read/write
482          *         1 = base/limit registers i are read-only
483          * [ 7: 4] Reserved
484          * [31: 8] Memory-Mapped I/O Base Address i (39-16)
485          *         This field defines the upper address bits of a 40bit address 
486          *         that defines the start of memory-mapped I/O region i
487          */
488 #if (MEMORY_CONFIG == MEMORY_LNXI_SOLO) || (MEMORY_CONFIG == MEMORY_SUSE_SOLO)
489         PCI_ADDR(0, 0x18, 1, 0x80), 0x000000f0, 0x00e00003,
490         PCI_ADDR(0, 0x18, 1, 0x88), 0x000000f0, 0x00d80003,
491         PCI_ADDR(0, 0x18, 1, 0x90), 0x000000f0, 0x00e20003,
492         PCI_ADDR(0, 0x18, 1, 0x98), 0x000000f0, 0x00000000,
493         PCI_ADDR(0, 0x18, 1, 0xA0), 0x000000f0, 0x00000000,
494         PCI_ADDR(0, 0x18, 1, 0xA8), 0x000000f0, 0x00000000,
495         PCI_ADDR(0, 0x18, 1, 0xB0), 0x000000f0, 0x00000a03,
496 #endif
497 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
498         PCI_ADDR(0, 0x18, 1, 0xB8), 0x000000f0, 0x00400003,
499 #endif
500 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
501         PCI_ADDR(0, 0x18, 1, 0xB8), 0x000000f0, 0x00200003,
502 #endif
503 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
504         PCI_ADDR(0, 0x18, 1, 0x80), 0x000000f0, 0x00fc0003,
505         PCI_ADDR(0, 0x18, 1, 0x88), 0x000000f0, 0x00000000,
506         PCI_ADDR(0, 0x18, 1, 0x90), 0x000000f0, 0x00000000,
507         PCI_ADDR(0, 0x18, 1, 0x98), 0x000000f0, 0x00000000,
508         PCI_ADDR(0, 0x18, 1, 0xA0), 0x000000f0, 0x00fec00e,
509         PCI_ADDR(0, 0x18, 1, 0xA8), 0x000000f0, 0x00000a03,
510         PCI_ADDR(0, 0x18, 1, 0xB0), 0x000000f0, 0x00000000,
511         PCI_ADDR(0, 0x18, 1, 0xB8), 0x000000f0, 0x00000000,
512 #endif
513
514         /* PCI I/O Limit i Registers
515          * F1:0xC4 i = 0
516          * F1:0xCC i = 1
517          * F1:0xD4 i = 2
518          * F1:0xDC i = 3
519          * [ 2: 0] Destination Node ID
520          *         000 = Node 0
521          *         001 = Node 1
522          *         010 = Node 2
523          *         011 = Node 3
524          *         100 = Node 4
525          *         101 = Node 5
526          *         110 = Node 6
527          *         111 = Node 7
528          * [ 3: 3] Reserved
529          * [ 5: 4] Destination Link ID
530          *         00 = Link 0
531          *         01 = Link 1
532          *         10 = Link 2
533          *         11 = reserved
534          * [11: 6] Reserved
535          * [24:12] PCI I/O Limit Address i
536          *         This field defines the end of PCI I/O region n
537          * [31:25] Reserved
538          */
539 #if (MEMORY_CONFIG == MEMORY_LNXI_SOLO) || (MEMORY_CONFIG == MEMORY_SUSE_SOLO)
540         PCI_ADDR(0, 0x18, 1, 0xC4), 0xFE000FC8, 0x0000d000,
541         PCI_ADDR(0, 0x18, 1, 0xCC), 0xFE000FC8, 0x000ff000,
542         PCI_ADDR(0, 0x18, 1, 0xD4), 0xFE000FC8, 0x00000000,
543         PCI_ADDR(0, 0x18, 1, 0xDC), 0xFE000FC8, 0x00000000,
544 #endif
545 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
546         PCI_ADDR(0, 0x18, 1, 0xC4), 0xFE000FC8, 0x01fff000,
547         PCI_ADDR(0, 0x18, 1, 0xCC), 0xFE000FC8, 0x00000000,
548         PCI_ADDR(0, 0x18, 1, 0xD4), 0xFE000FC8, 0x00000000,
549         PCI_ADDR(0, 0x18, 1, 0xDC), 0xFE000FC8, 0x00000000,
550 #endif
551
552         /* PCI I/O Base i Registers
553          * F1:0xC0 i = 0
554          * F1:0xC8 i = 1
555          * F1:0xD0 i = 2
556          * F1:0xD8 i = 3
557          * [ 0: 0] Read Enable
558          *         0 = Reads Disabled
559          *         1 = Reads Enabled
560          * [ 1: 1] Write Enable
561          *         0 = Writes Disabled
562          *         1 = Writes Enabled
563          * [ 3: 2] Reserved
564          * [ 4: 4] VGA Enable
565          *         0 = VGA matches Disabled
566          *         1 = matches all address < 64K and where A[9:0] is in the 
567          *             range 3B0-3BB or 3C0-3DF independen of the base & limit registers
568          * [ 5: 5] ISA Enable
569          *         0 = ISA matches Disabled
570          *         1 = Blocks address < 64K and in the last 768 bytes of eack 1K block
571          *             from matching agains this base/limit pair
572          * [11: 6] Reserved
573          * [24:12] PCI I/O Base i
574          *         This field defines the start of PCI I/O region n 
575          * [31:25] Reserved
576          */
577 #if (MEMORY_CONFIG == MEMORY_LNXI_SOLO) || (MEMORY_CONFIG == MEMORY_SUSE_SOLO)
578         PCI_ADDR(0, 0x18, 1, 0xC0), 0xFE000FCC, 0x0000d003,
579         PCI_ADDR(0, 0x18, 1, 0xC8), 0xFE000FCC, 0x00001013,
580         PCI_ADDR(0, 0x18, 1, 0xD0), 0xFE000FCC, 0x00000000,
581         PCI_ADDR(0, 0x18, 1, 0xD8), 0xFE000FCC, 0x00000000,
582 #endif
583 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
584         PCI_ADDR(0, 0x18, 1, 0xC0), 0xFE000FCC, 0x00000033,
585         PCI_ADDR(0, 0x18, 1, 0xC8), 0xFE000FCC, 0x00000000,
586         PCI_ADDR(0, 0x18, 1, 0xD0), 0xFE000FCC, 0x00000000,
587         PCI_ADDR(0, 0x18, 1, 0xD8), 0xFE000FCC, 0x00000000,
588 #endif
589
590         /* Config Base and Limit i Registers
591          * F1:0xE0 i = 0
592          * F1:0xE4 i = 1
593          * F1:0xE8 i = 2
594          * F1:0xEC i = 3
595          * [ 0: 0] Read Enable
596          *         0 = Reads Disabled
597          *         1 = Reads Enabled
598          * [ 1: 1] Write Enable
599          *         0 = Writes Disabled
600          *         1 = Writes Enabled
601          * [ 2: 2] Device Number Compare Enable
602          *         0 = The ranges are based on bus number
603          *         1 = The ranges are ranges of devices on bus 0
604          * [ 3: 3] Reserved
605          * [ 6: 4] Destination Node
606          *         000 = Node 0
607          *         001 = Node 1
608          *         010 = Node 2
609          *         011 = Node 3
610          *         100 = Node 4
611          *         101 = Node 5
612          *         110 = Node 6
613          *         111 = Node 7
614          * [ 7: 7] Reserved
615          * [ 9: 8] Destination Link
616          *         00 = Link 0
617          *         01 = Link 1
618          *         10 = Link 2
619          *         11 - Reserved
620          * [15:10] Reserved
621          * [23:16] Bus Number Base i
622          *         This field defines the lowest bus number in configuration region i
623          * [31:24] Bus Number Limit i
624          *         This field defines the highest bus number in configuration regin i
625          */
626 #if (MEMORY_CONFIG == MEMORY_LNXI_SOLO) || (MEMORY_CONFIG == MEMORY_SUSE_SOLO)
627         PCI_ADDR(0, 0x18, 1, 0xE0), 0x0000FC88, 0xff000003,
628         PCI_ADDR(0, 0x18, 1, 0xE4), 0x0000FC88, 0x00000000,
629         PCI_ADDR(0, 0x18, 1, 0xE8), 0x0000FC88, 0x00000000,
630         PCI_ADDR(0, 0x18, 1, 0xEC), 0x0000FC88, 0x00000000,
631 #endif
632 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
633         PCI_ADDR(0, 0x18, 1, 0xE0), 0x0000FC88, 0xff000003,
634         PCI_ADDR(0, 0x18, 1, 0xE4), 0x0000FC88, 0x00000000,
635         PCI_ADDR(0, 0x18, 1, 0xE8), 0x0000FC88, 0x00000000,
636         PCI_ADDR(0, 0x18, 1, 0xEC), 0x0000FC88, 0x00000000,
637 #endif
638
639         /* DRAM CS Base Address i Registers
640          * F2:0x40 i = 0
641          * F2:0x44 i = 1
642          * F2:0x48 i = 2
643          * F2:0x4C i = 3
644          * F2:0x50 i = 4
645          * F2:0x54 i = 5
646          * F2:0x58 i = 6
647          * F2:0x5C i = 7
648          * [ 0: 0] Chip-Select Bank Enable
649          *         0 = Bank Disabled
650          *         1 = Bank Enabled
651          * [ 8: 1] Reserved
652          * [15: 9] Base Address (19-13)
653          *         An optimization used when all DIMM are the same size...
654          * [20:16] Reserved
655          * [31:21] Base Address (35-25)
656          *         This field defines the top 11 addresses bit of a 40-bit
657          *         address that define the memory address space.  These
658          *         bits decode 32-MByte blocks of memory.
659          */
660         PCI_ADDR(0, 0x18, 2, 0x40), 0x001f01fe, 0x00000001,
661 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
662         PCI_ADDR(0, 0x18, 2, 0x44), 0x001f01fe, 0x01000001,
663         PCI_ADDR(0, 0x18, 2, 0x48), 0x001f01fe, 0x02000001,
664         PCI_ADDR(0, 0x18, 2, 0x4C), 0x001f01fe, 0x03000001,
665 #endif
666 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
667         PCI_ADDR(0, 0x18, 2, 0x44), 0x001f01fe, 0x00800001,
668         PCI_ADDR(0, 0x18, 2, 0x48), 0x001f01fe, 0x01000001,
669         PCI_ADDR(0, 0x18, 2, 0x4C), 0x001f01fe, 0x01800001,
670 #endif
671 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
672         PCI_ADDR(0, 0x18, 2, 0x44), 0x001f01fe, 0x00001001,
673         PCI_ADDR(0, 0x18, 2, 0x48), 0x001f01fe, 0x00000000,
674         PCI_ADDR(0, 0x18, 2, 0x4C), 0x001f01fe, 0x00000000,
675 #endif
676         PCI_ADDR(0, 0x18, 2, 0x50), 0x001f01fe, 0x00000000,
677         PCI_ADDR(0, 0x18, 2, 0x54), 0x001f01fe, 0x00000000,
678         PCI_ADDR(0, 0x18, 2, 0x58), 0x001f01fe, 0x00000000,
679         PCI_ADDR(0, 0x18, 2, 0x5C), 0x001f01fe, 0x00000000,
680         /* DRAM CS Mask Address i Registers
681          * F2:0x60 i = 0
682          * F2:0x64 i = 1
683          * F2:0x68 i = 2
684          * F2:0x6C i = 3
685          * F2:0x70 i = 4
686          * F2:0x74 i = 5
687          * F2:0x78 i = 6
688          * F2:0x7C i = 7
689          * Select bits to exclude from comparison with the DRAM Base address register.
690          * [ 8: 0] Reserved
691          * [15: 9] Address Mask (19-13)
692          *         Address to be excluded from the optimized case
693          * [20:16] Reserved
694          * [29:21] Address Mask (33-25)
695          *         The bits with an address mask of 1 are excluded from address comparison
696          * [31:30] Reserved
697          * 
698          */
699 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
700         PCI_ADDR(0, 0x18, 2, 0x60), 0xC01f01ff, 0x00e0fe00,
701         PCI_ADDR(0, 0x18, 2, 0x64), 0xC01f01ff, 0x00e0fe00,
702         PCI_ADDR(0, 0x18, 2, 0x68), 0xC01f01ff, 0x00e0fe00,
703         PCI_ADDR(0, 0x18, 2, 0x6C), 0xC01f01ff, 0x00e0fe00,
704 #endif
705 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
706         PCI_ADDR(0, 0x18, 2, 0x60), 0xC01f01ff, 0x0060fe00,
707         PCI_ADDR(0, 0x18, 2, 0x64), 0xC01f01ff, 0x0060fe00,
708         PCI_ADDR(0, 0x18, 2, 0x68), 0xC01f01ff, 0x0060fe00,
709         PCI_ADDR(0, 0x18, 2, 0x6C), 0xC01f01ff, 0x0060fe00,
710 #endif
711 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
712         PCI_ADDR(0, 0x18, 2, 0x60), 0xC01f01ff, 0x03e0ee00,
713         PCI_ADDR(0, 0x18, 2, 0x64), 0xC01f01ff, 0x03e0ee00,
714         PCI_ADDR(0, 0x18, 2, 0x68), 0xC01f01ff, 0x00000000,
715         PCI_ADDR(0, 0x18, 2, 0x6C), 0xC01f01ff, 0x00000000,
716 #endif
717         PCI_ADDR(0, 0x18, 2, 0x70), 0xC01f01ff, 0x00000000,
718         PCI_ADDR(0, 0x18, 2, 0x74), 0xC01f01ff, 0x00000000,
719         PCI_ADDR(0, 0x18, 2, 0x78), 0xC01f01ff, 0x00000000,
720         PCI_ADDR(0, 0x18, 2, 0x7C), 0xC01f01ff, 0x00000000,
721         /* DRAM Bank Address Mapping Register
722          * F2:0x80
723          * Specify the memory module size
724          * [ 2: 0] CS1/0 
725          * [ 6: 4] CS3/2
726          * [10: 8] CS5/4
727          * [14:12] CS7/6
728          *         000 = 32Mbyte  (Rows = 12 & Col =  8)
729          *         001 = 64Mbyte  (Rows = 12 & Col =  9)
730          *         010 = 128Mbyte (Rows = 13 & Col =  9)|(Rows = 12 & Col = 10)
731          *         011 = 256Mbyte (Rows = 13 & Col = 10)|(Rows = 12 & Col = 11)
732          *         100 = 512Mbyte (Rows = 13 & Col = 11)|(Rows = 14 & Col = 10)
733          *         101 = 1Gbyte   (Rows = 14 & Col = 11)|(Rows = 13 & Col = 12)
734          *         110 = 2Gbyte   (Rows = 14 & Col = 12)
735          *         111 = reserved 
736          * [ 3: 3] Reserved
737          * [ 7: 7] Reserved
738          * [11:11] Reserved
739          * [31:15]
740          */
741 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
742         PCI_ADDR(0, 0x18, 2, 0x80), 0xffff8888, 0x00000033,
743 #endif
744 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
745         PCI_ADDR(0, 0x18, 2, 0x80), 0xffff8888, 0x00000022,
746 #endif
747 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
748         PCI_ADDR(0, 0x18, 2, 0x80), 0xffff8888, 0x00000003,
749 #endif
750         /* DRAM Timing Low Register
751          * F2:0x88
752          * [ 2: 0] Tcl (Cas# Latency, Cas# to read-data-valid)
753          *         000 = reserved
754          *         001 = CL 2
755          *         010 = CL 3
756          *         011 = reserved
757          *         100 = reserved
758          *         101 = CL 2.5
759          *         110 = reserved
760          *         111 = reserved
761          * [ 3: 3] Reserved
762          * [ 7: 4] Trc (Row Cycle Time, Ras#-active to Ras#-active/bank auto refresh)
763          *         0000 =  7 bus clocks
764          *         0001 =  8 bus clocks
765          *         ...
766          *         1110 = 21 bus clocks
767          *         1111 = 22 bus clocks
768          * [11: 8] Trfc (Row refresh Cycle time, Auto-refresh-active to RAS#-active or RAS#auto-refresh)
769          *         0000 = 9 bus clocks
770          *         0010 = 10 bus clocks
771          *         ....
772          *         1110 = 23 bus clocks
773          *         1111 = 24 bus clocks
774          * [14:12] Trcd (Ras#-active to Case#-read/write Delay)
775          *         000 = reserved
776          *         001 = reserved
777          *         010 = 2 bus clocks
778          *         011 = 3 bus clocks
779          *         100 = 4 bus clocks
780          *         101 = 5 bus clocks
781          *         110 = 6 bus clocks
782          *         111 = reserved
783          * [15:15] Reserved
784          * [18:16] Trrd (Ras# to Ras# Delay)
785          *         000 = reserved
786          *         001 = reserved
787          *         010 = 2 bus clocks
788          *         011 = 3 bus clocks
789          *         100 = 4 bus clocks
790          *         101 = reserved
791          *         110 = reserved
792          *         111 = reserved
793          * [19:19] Reserved
794          * [23:20] Tras (Minmum Ras# Active Time)
795          *         0000 to 0100 = reserved
796          *         0101 = 5 bus clocks
797          *         ...
798          *         1111 = 15 bus clocks
799          * [26:24] Trp (Row Precharge Time)
800          *         000 = reserved
801          *         001 = reserved
802          *         010 = 2 bus clocks
803          *         011 = 3 bus clocks
804          *         100 = 4 bus clocks
805          *         101 = 5 bus clocks
806          *         110 = 6 bus clocks
807          *         111 = reserved
808          * [27:27] Reserved
809          * [28:28] Twr (Write Recovery Time)
810          *         0 = 2 bus clocks
811          *         1 = 3 bus clocks
812          * [31:29] Reserved
813          */
814 #if (MEMORY_CONFIG == MEMORY_LNXI_SOLO) || (MEMORY_CONFIG == MEMORY_SUSE_SOLO)
815         PCI_ADDR(0, 0x18, 2, 0x88), 0xe8088008, 0x03623125,
816 #endif
817 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
818         PCI_ADDR(0, 0x18, 2, 0x88), 0xe8088008, 0x13723335,
819 #endif
820         /* DRAM Timing High Register
821          * F2:0x8C
822          * [ 0: 0] Twtr (Write to Read Delay)
823          *         0 = 1 bus Clocks
824          *         1 = 2 bus Clocks
825          * [ 3: 1] Reserved
826          * [ 6: 4] Trwf (Read to Write Delay)
827          *         000 = 1 bus clocks
828          *         001 = 2 bus clocks
829          *         010 = 3 bus clocks
830          *         011 = 4 bus clocks
831          *         100 = 5 bus clocks
832          *         101 = 6 bus clocks
833          *         110 = reserved
834          *         111 = reserved
835          * [ 7: 7] Reserved
836          * [12: 8] Tref (Refresh Rate)
837          *         00000 = 100Mhz 4K rows
838          *         00001 = 133Mhz 4K rows
839          *         00010 = 166Mhz 4K rows
840          *         01000 = 100Mhz 8K/16K rows
841          *         01001 = 133Mhz 8K/16K rows
842          *         01010 = 166Mhz 8K/16K rows
843          * [19:13] Reserved
844          * [22:20] Twcl (Write CAS Latency)
845          *         000 = 1 Mem clock after CAS# (Unbuffered Dimms)
846          *         001 = 2 Mem clocks after CAS# (Registered Dimms)
847          * [31:23] Reserved
848          */
849 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
850         PCI_ADDR(0, 0x18, 2, 0x8c), 0xff8fe08e, 0x00000930,
851 #endif
852 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
853         PCI_ADDR(0, 0x18, 2, 0x8c), 0xff8fe08e, 0x00000130,
854 #endif
855 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
856         PCI_ADDR(0, 0x18, 2, 0x8c), 0xff8fe08e, 0x00100a20,
857 #endif
858         /* DRAM Config Low Register
859          * F2:0x90
860          * [ 0: 0] DLL Disable
861          *         0 = Enabled
862          *         1 = Disabled
863          * [ 1: 1] D_DRV
864          *         0 = Normal Drive
865          *         1 = Weak Drive
866          * [ 2: 2] QFC_EN
867          *         0 = Disabled
868          *         1 = Enabled
869          * [ 3: 3] Disable DQS Hystersis  (FIXME handle this one carefully)
870          *         0 = Enable DQS input filter 
871          *         1 = Disable DQS input filtering 
872          * [ 7: 4] Reserved
873          * [ 8: 8] DRAM_Init
874          *         0 = Initialization done or not yet started.
875          *         1 = Initiate DRAM intialization sequence
876          * [ 9: 9] SO-Dimm Enable
877          *         0 = Do nothing
878          *         1 = SO-Dimms present
879          * [10:10] DramEnable
880          *         0 = DRAM not enabled
881          *         1 = DRAM initialized and enabled
882          * [11:11] Memory Clear Status
883          *         0 = Memory Clear function has not completed
884          *         1 = Memory Clear function has completed
885          * [12:12] Exit Self-Refresh
886          *         0 = Exit from self-refresh done or not yet started
887          *         1 = DRAM exiting from self refresh
888          * [13:13] Self-Refresh Status
889          *         0 = Normal Operation
890          *         1 = Self-refresh mode active
891          * [15:14] Read/Write Queue Bypass Count
892          *         00 = 2
893          *         01 = 4
894          *         10 = 8
895          *         11 = 16
896          * [16:16] 128-bit/64-Bit
897          *         0 = 64bit Interface to DRAM
898          *         1 = 128bit Interface to DRAM
899          * [17:17] DIMM ECC Enable
900          *         0 = Some DIMMs do not have ECC
901          *         1 = ALL DIMMS have ECC bits
902          * [18:18] UnBuffered DIMMs
903          *         0 = Buffered DIMMS
904          *         1 = Unbuffered DIMMS
905          * [19:19] Enable 32-Byte Granularity
906          *         0 = Optimize for 64byte bursts
907          *         1 = Optimize for 32byte bursts
908          * [20:20] DIMM 0 is x4
909          * [21:21] DIMM 1 is x4
910          * [22:22] DIMM 2 is x4
911          * [23:23] DIMM 3 is x4
912          *         0 = DIMM is not x4
913          *         1 = x4 DIMM present
914          * [24:24] Disable DRAM Receivers
915          *         0 = Receivers enabled
916          *         1 = Receivers disabled
917          * [27:25] Bypass Max
918          *         000 = Arbiters chois is always respected
919          *         001 = Oldest entry in DCQ can be bypassed 1 time
920          *         010 = Oldest entry in DCQ can be bypassed 2 times
921          *         011 = Oldest entry in DCQ can be bypassed 3 times
922          *         100 = Oldest entry in DCQ can be bypassed 4 times
923          *         101 = Oldest entry in DCQ can be bypassed 5 times
924          *         110 = Oldest entry in DCQ can be bypassed 6 times
925          *         111 = Oldest entry in DCQ can be bypassed 7 times
926          * [31:28] Reserved
927          */
928 #if (MEMORY_CONFIG == MEMORY_LNXI_SOLO) || (MEMORY_CONFIG == MEMORY_SUSE_SOLO)
929         PCI_ADDR(0, 0x18, 2, 0x90), 0xf0000000, 
930         (4 << 25)|(0 << 24)| 
931         (0 << 23)|(0 << 22)|(0 << 21)|(0 << 20)| 
932         (1 << 19)|(1 << 18)|(0 << 17)|(0 << 16)| 
933         (2 << 14)|(0 << 13)|(0 << 12)| 
934         (0 << 11)|(0 << 10)|(0 << 9)|(0 << 8)| 
935         (0 << 3) |(0 << 1) |(0 << 0),
936 #endif
937 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
938         PCI_ADDR(0, 0x18, 2, 0x90), 0xf0000000, 
939         (4 << 25)|(0 << 24)|
940         (0 << 23)|(0 << 22)|(0 << 21)|(0 << 20)|
941         (0 << 19)|(0 << 18)|(0 << 17)|(1 << 16)|
942         (2 << 14)|(0 << 13)|(0 << 12)|
943         (0 << 11)|(0 << 10)|(0 << 9)|(0 << 8)|
944         (0 << 3) |(0 << 1) |(0 << 0),
945 #endif
946         /* DRAM Config High Register
947          * F2:0x94
948          * [ 0: 3] Maximum Asynchronous Latency
949          *         0000 = 0 ns
950          *         ...
951          *         1111 = 15 ns
952          * [ 7: 4] Reserved
953          * [11: 8] Read Preamble
954          *         0000 = 2.0 ns
955          *         0001 = 2.5 ns
956          *         0010 = 3.0 ns
957          *         0011 = 3.5 ns
958          *         0100 = 4.0 ns
959          *         0101 = 4.5 ns
960          *         0110 = 5.0 ns
961          *         0111 = 5.5 ns
962          *         1000 = 6.0 ns
963          *         1001 = 6.5 ns
964          *         1010 = 7.0 ns
965          *         1011 = 7.5 ns
966          *         1100 = 8.0 ns
967          *         1101 = 8.5 ns
968          *         1110 = 9.0 ns
969          *         1111 = 9.5 ns
970          * [15:12] Reserved
971          * [18:16] Idle Cycle Limit
972          *         000 = 0 cycles
973          *         001 = 4 cycles
974          *         010 = 8 cycles
975          *         011 = 16 cycles
976          *         100 = 32 cycles
977          *         101 = 64 cycles
978          *         110 = 128 cycles
979          *         111 = 256 cycles
980          * [19:19] Dynamic Idle Cycle Center Enable
981          *         0 = Use Idle Cycle Limit
982          *         1 = Generate a dynamic Idle cycle limit
983          * [22:20] DRAM MEMCLK Frequency
984          *         000 = 100Mhz
985          *         001 = reserved
986          *         010 = 133Mhz
987          *         011 = reserved
988          *         100 = reserved
989          *         101 = 166Mhz
990          *         110 = reserved
991          *         111 = reserved
992          * [24:23] Reserved
993          * [25:25] Memory Clock Ratio Valid (FIXME carefully enable memclk)
994          *         0 = Disable MemClks
995          *         1 = Enable MemClks
996          * [26:26] Memory Clock 0 Enable
997          *         0 = Disabled
998          *         1 = Enabled
999          * [27:27] Memory Clock 1 Enable
1000          *         0 = Disabled
1001          *         1 = Enabled
1002          * [28:28] Memory Clock 2 Enable
1003          *         0 = Disabled
1004          *         1 = Enabled
1005          * [29:29] Memory Clock 3 Enable
1006          *         0 = Disabled
1007          *         1 = Enabled
1008          * [31:30] Reserved
1009          */
1010 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
1011         PCI_ADDR(0, 0x18, 2, 0x94), 0xc180f0f0, 0x0e2b0a05,
1012 #endif
1013 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
1014         PCI_ADDR(0, 0x18, 2, 0x94), 0xc180f0f0, 0x0e2b0a06,
1015 #endif
1016 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
1017         PCI_ADDR(0, 0x18, 2, 0x94), 0xc180f0f0, 0x065b0b08,
1018 #endif
1019         /* DRAM Delay Line Register
1020          * F2:0x98
1021          * Adjust the skew of the input DQS strobe relative to DATA
1022          * [15: 0] Reserved
1023          * [23:16] Delay Line Adjust
1024          *         Adjusts the DLL derived PDL delay by one or more delay stages
1025          *         in either the faster or slower direction.
1026          * [24:24} Adjust Slower
1027          *         0 = Do Nothing
1028          *         1 = Adj is used to increase the PDL delay
1029          * [25:25] Adjust Faster
1030          *         0 = Do Nothing
1031          *         1 = Adj is used to decrease the PDL delay
1032          * [31:26] Reserved
1033          */
1034         PCI_ADDR(0, 0x18, 2, 0x98), 0xfc00ffff, 0x00000000,
1035         /* DRAM Scrub Control Register
1036          * F3:0x58
1037          * [ 4: 0] DRAM Scrube Rate
1038          * [ 7: 5] reserved
1039          * [12: 8] L2 Scrub Rate
1040          * [15:13] reserved
1041          * [20:16] Dcache Scrub
1042          * [31:21] reserved
1043          *         Scrub Rates
1044          *         00000 = Do not scrub
1045          *         00001 =  40.00 ns
1046          *         00010 =  80.00 ns
1047          *         00011 = 160.00 ns
1048          *         00100 = 320.00 ns
1049          *         00101 = 640.00 ns
1050          *         00110 =   1.28 us
1051          *         00111 =   2.56 us
1052          *         01000 =   5.12 us
1053          *         01001 =  10.20 us
1054          *         01011 =  41.00 us
1055          *         01100 =  81.90 us
1056          *         01101 = 163.80 us
1057          *         01110 = 327.70 us
1058          *         01111 = 655.40 us
1059          *         10000 =   1.31 ms
1060          *         10001 =   2.62 ms
1061          *         10010 =   5.24 ms
1062          *         10011 =  10.49 ms
1063          *         10100 =  20.97 ms
1064          *         10101 =  42.00 ms
1065          *         10110 =  84.00 ms
1066          *         All Others = Reserved
1067          */
1068         PCI_ADDR(0, 0x18, 3, 0x58), 0xffe0e0e0, 0x00000000,
1069         /* DRAM Scrub Address Low Register
1070          * F3:0x5C
1071          * [ 0: 0] DRAM Scrubber Redirect Enable
1072          *         0 = Do nothing
1073          *         1 = Scrubber Corrects errors found in normal operation
1074          * [ 5: 1] Reserved
1075          * [31: 6] DRAM Scrub Address 31-6
1076          */
1077         PCI_ADDR(0, 0x18, 3, 0x5C), 0x0000003e, 0x00000000,
1078         /* DRAM Scrub Address High Register
1079          * F3:0x60
1080          * [ 7: 0] DRAM Scrubb Address 39-32
1081          * [31: 8] Reserved
1082          */
1083         PCI_ADDR(0, 0x18, 3, 0x60), 0xffffff00, 0x00000000,
1084         };
1085         int i;
1086         int max;
1087         print_debug("setting up CPU0 northbridge registers\r\n");
1088         max = sizeof(register_values)/sizeof(register_values[0]);
1089         for(i = 0; i < max; i += 3) {
1090                 device_t dev;
1091                 unsigned where;
1092                 unsigned long reg;
1093 #if 0
1094                 print_debug_hex32(register_values[i]);
1095                 print_debug(" <-");
1096                 print_debug_hex32(register_values[i+2]);
1097                 print_debug("\r\n");
1098 #endif
1099                 dev = register_values[i] & ~0xff;
1100                 where = register_values[i] & 0xff;
1101                 reg = pci_read_config32(dev, where);
1102                 reg &= register_values[i+1];
1103                 reg |= register_values[i+2];
1104                 pci_write_config32(dev, where, reg);
1105 #if 0
1106
1107                 reg = pci_read_config32(register_values[i]);
1108                 reg &= register_values[i+1];
1109                 reg |= register_values[i+2];
1110                 pci_write_config32(register_values[i], reg);
1111 #endif
1112         }
1113         print_debug("done.\r\n");
1114 }
1115
1116
1117 struct dimm_size {
1118         unsigned long side1;
1119         unsigned long side2;
1120 };
1121 static struct dimm_size spd_get_dimm_size(unsigned device)
1122 {
1123         /* Calculate the log base 2 size of a DIMM in bits */
1124         struct dimm_size sz;
1125         int value, low;
1126         sz.side1 = 0;
1127         sz.side2 = 0;
1128
1129         /* Note it might be easier to use byte 31 here, it has the DIMM size as
1130          * a multiple of 4MB.  The way we do it now we can size both
1131          * sides of an assymetric dimm.
1132          */
1133         value = smbus_read_byte(device, 3);     /* rows */
1134         if (value < 0) return sz;
1135         sz.side1 += value & 0xf;
1136
1137         value = smbus_read_byte(device, 4);     /* columns */
1138         if (value < 0) return sz;
1139         sz.side1 += value & 0xf;
1140
1141         value = smbus_read_byte(device, 17);    /* banks */
1142         if (value < 0) return sz;
1143         sz.side1 += log2(value & 0xff);
1144
1145         /* Get the module data widht and convert it to a power of two */
1146         value = smbus_read_byte(device, 7);     /* (high byte) */
1147         if (value < 0) return sz;
1148         value &= 0xff;
1149         value <<= 8;
1150         
1151         low = smbus_read_byte(device, 6);       /* (low byte) */
1152         if (low < 0) return sz;
1153         value = value | (low & 0xff);
1154         sz.side1 += log2(value);
1155
1156         /* side 2 */
1157         value = smbus_read_byte(device, 5);     /* number of physical banks */
1158         if (value <= 1) return sz;
1159
1160         /* Start with the symmetrical case */
1161         sz.side2 = sz.side1;
1162
1163         value = smbus_read_byte(device, 3);     /* rows */
1164         if (value < 0) return sz;
1165         if ((value & 0xf0) == 0) return sz;     /* If symmetrical we are done */
1166         sz.side2 -= (value & 0x0f);             /* Subtract out rows on side 1 */
1167         sz.side2 += ((value >> 4) & 0x0f);      /* Add in rows on side 2 */
1168
1169         value = smbus_read_byte(device, 4);     /* columns */
1170         if (value < 0) return sz;
1171         sz.side2 -= (value & 0x0f);             /* Subtract out columns on side 1 */
1172         sz.side2 += ((value >> 4) & 0x0f);      /* Add in columsn on side 2 */
1173         return sz;
1174 }
1175
1176 static unsigned spd_to_dimm_side0(unsigned device)
1177 {
1178         return (device - SMBUS_MEM_DEVICE_START) << 1;
1179 }
1180
1181 static unsigned spd_to_dimm_side1(unsigned device)
1182 {
1183         return ((device - SMBUS_MEM_DEVICE_START) << 1) + 1;
1184 }
1185
1186 static void set_dimm_size(unsigned long size, unsigned index)
1187 {
1188         unsigned value = 0;
1189         /* Make certain the dimm is at least 32MB */
1190         if (size >= (25 + 3)) {
1191                 /* Place the dimm size in 32 MB quantities in the bits 31 - 21.
1192                  * The initialize dimm size is in bits.
1193                  * Set the base enable bit0.
1194                  */
1195                 value = (1 << ((size - (25 + 3)) + 21)) | 1;
1196         }
1197         /* Set the appropriate DIMM base address register */
1198         pci_write_config32(PCI_DEV(0, 0x18, 2), 0x40 + (index << 2), value);
1199 }
1200
1201 static void spd_set_ram_size(void)
1202 {
1203         unsigned device;
1204         for(device = SMBUS_MEM_DEVICE_START; 
1205                 device <= SMBUS_MEM_DEVICE_END;
1206                 device += SMBUS_MEM_DEVICE_INC) 
1207         {
1208                 struct dimm_size sz;
1209                 sz = spd_get_dimm_size(device);
1210                 set_dimm_size(sz.side1, spd_to_dimm_side0(device));
1211                 set_dimm_size(sz.side2, spd_to_dimm_side1(device));
1212         }
1213 }
1214
1215 static void set_top_mem(unsigned tom_k)
1216 {
1217         /* Error if I don't have memory */
1218         if (!tom_k) {
1219                 die("No memory");
1220         }
1221         /* Now set top of memory */
1222         msr_t msr;
1223         msr.lo = (tom_k & 0x003fffff) << 10;
1224         msr.hi = (tom_k & 0xffc00000) >> 22;
1225         wrmsr(TOP_MEM, msr);
1226
1227 #if 1
1228         /* And report the amount of memory.  (I run out of registers if i don't) */
1229         print_debug("RAM: 0x");
1230         print_debug_hex32(tom_k);
1231         print_debug(" KB\r\n");
1232 #endif
1233 }
1234
1235 static void order_dimms(void)
1236 {
1237         unsigned long tom;
1238         unsigned mask;
1239         unsigned index;
1240
1241         /* Remember which registers we have used in the high 8 bits of tom */
1242         tom = 0;
1243         for(;;) {
1244                 /* Find the largest remaining canidate */
1245                 unsigned canidate;
1246                 uint32_t csbase, csmask;
1247                 unsigned size;
1248                 csbase = 0;
1249                 canidate = 0;
1250                 for(index = 0; index < 8; index++) {
1251                         uint32_t value;
1252                         value = pci_read_config32(PCI_DEV(0, 0x18, 2), 0x40 + (index << 2));
1253
1254                         /* Is it enabled? */
1255                         if (!(value & 1)) {
1256                                 continue;
1257                         }
1258                         
1259                         /* Is it greater? */
1260                         if (value <= csbase) {
1261                                 continue;
1262                         }
1263                         
1264                         /* Has it already been selected */
1265                         if (tom & (1 << (index + 24))) {
1266                                 continue;
1267                         }
1268                         /* I have a new canidate */
1269                         csbase = value;
1270                         canidate = index;
1271                 }
1272                 /* See if I have found a new canidate */
1273                 if (csbase == 0) {
1274                         break;
1275                 }
1276
1277                 /* Remember I have used this register */
1278                 tom |= (1 << (canidate + 24));
1279
1280                 /* Remember the dimm size */
1281                 size = csbase >> 21;
1282
1283                 /* Recompute the cs base register value */
1284                 csbase = (tom << 21) | 1;
1285
1286                 /* Increment the top of memory */
1287                 tom += size;
1288
1289                 /* Compute the memory mask */
1290                 csmask = ((size -1) << 21);
1291                 csmask |= 0xfe00;               /* For now don't optimize */
1292
1293                 /* Write the new base register */
1294                 pci_write_config32(PCI_DEV(0, 0x18, 2), 0x40 + (canidate << 2), csbase);
1295                 pci_write_config32(PCI_DEV(0, 0x18, 2), 0x60 + (canidate << 2), csmask);
1296                 
1297         }
1298         set_top_mem((tom & ~0xff000000) << 15);
1299 }
1300
1301
1302 #define DRAM_CONFIG_LOW 0x90
1303 #define  DCL_DLL_Disable   (1<<0)
1304 #define  DCL_D_DRV         (1<<1)
1305 #define  DCL_QFC_EN        (1<<2)
1306 #define  DCL_DisDqsHys     (1<<3)
1307 #define  DCL_DramInit      (1<<8)
1308 #define  DCL_DramEnable    (1<<10)
1309 #define  DCL_MemClrStatus  (1<<11)
1310 #define  DCL_DimmEcEn      (1<<17)
1311
1312
1313 static void spd_set_ecc_mode(void)
1314 {
1315         unsigned long dcl;
1316         dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
1317         /* Until I know what is going on disable ECC support */
1318         dcl &= ~DCL_DimmEcEn;
1319         pci_write_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW, dcl);
1320
1321 }
1322 static void sdram_set_spd_registers(void) 
1323 {
1324         spd_set_ram_size();
1325         spd_set_ecc_mode();
1326         order_dimms();
1327 }
1328
1329 #define TIMEOUT_LOOPS 300000
1330 static void sdram_enable(void)
1331 {
1332         unsigned long dcl;
1333
1334         /* Toggle DisDqsHys to get it working */
1335         dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
1336         print_debug("dcl: ");
1337         print_debug_hex32(dcl);
1338         print_debug("\r\n");
1339         dcl |= DCL_DisDqsHys;
1340         pci_write_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW, dcl);
1341         dcl &= ~DCL_DisDqsHys;
1342         dcl &= ~DCL_DLL_Disable;
1343         dcl &= ~DCL_D_DRV;
1344         dcl &= ~DCL_QFC_EN;
1345         dcl |= DCL_DramInit;
1346         pci_write_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW, dcl);
1347         
1348         print_debug("Initializing memory: ");
1349         int loops = 0;
1350         do {
1351                 dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
1352                 loops += 1;
1353                 if ((loops & 1023) == 0) {
1354                         print_debug(".");
1355                 }
1356         } while(((dcl & DCL_DramInit) != 0) && (loops < TIMEOUT_LOOPS));
1357         if (loops >= TIMEOUT_LOOPS) {
1358                 print_debug(" failed\r\n");
1359         } else {
1360                 print_debug(" done\r\n");
1361         }
1362
1363 #if 0
1364         print_debug("Clearing memory: ");
1365         loops = 0;
1366         do {
1367                 dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
1368                 loops += 1;
1369                 if ((loops & 1023) == 0) {
1370                         print_debug(" ");
1371                         print_debug_hex32(loops);
1372                 }
1373         } while(((dcl & DCL_MemClrStatus) == 0) && (loops < TIMEOUT_LOOPS));
1374         if (loops >= TIMEOUT_LOOPS) {
1375                 print_debug("failed\r\n");
1376         } else {
1377                 print_debug("done\r\n");
1378         }
1379 #endif
1380 }
1381
1382 static void sdram_first_normal_reference(void) {}
1383 static void sdram_enable_refresh(void) {}
1384 static void sdram_special_finishup(void) {}
1385