- Update the romcc version.
[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 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
661         PCI_ADDR(0, 0x18, 2, 0x40), 0x001f01fe, 0x00000000,
662         PCI_ADDR(0, 0x18, 2, 0x44), 0x001f01fe, 0x00000000,
663         PCI_ADDR(0, 0x18, 2, 0x48), 0x001f01fe, 0x00000000,
664         PCI_ADDR(0, 0x18, 2, 0x4C), 0x001f01fe, 0x00000000,
665 #endif
666 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
667         PCI_ADDR(0, 0x18, 2, 0x40), 0x001f01fe, 0x00000001,
668         PCI_ADDR(0, 0x18, 2, 0x44), 0x001f01fe, 0x00800001,
669         PCI_ADDR(0, 0x18, 2, 0x48), 0x001f01fe, 0x01000001,
670         PCI_ADDR(0, 0x18, 2, 0x4C), 0x001f01fe, 0x01800001,
671 #endif
672 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
673         PCI_ADDR(0, 0x18, 2, 0x40), 0x001f01fe, 0x00000001,
674         PCI_ADDR(0, 0x18, 2, 0x44), 0x001f01fe, 0x00001001,
675         PCI_ADDR(0, 0x18, 2, 0x48), 0x001f01fe, 0x00000000,
676         PCI_ADDR(0, 0x18, 2, 0x4C), 0x001f01fe, 0x00000000,
677 #endif
678         PCI_ADDR(0, 0x18, 2, 0x50), 0x001f01fe, 0x00000000,
679         PCI_ADDR(0, 0x18, 2, 0x54), 0x001f01fe, 0x00000000,
680         PCI_ADDR(0, 0x18, 2, 0x58), 0x001f01fe, 0x00000000,
681         PCI_ADDR(0, 0x18, 2, 0x5C), 0x001f01fe, 0x00000000,
682         /* DRAM CS Mask Address i Registers
683          * F2:0x60 i = 0
684          * F2:0x64 i = 1
685          * F2:0x68 i = 2
686          * F2:0x6C i = 3
687          * F2:0x70 i = 4
688          * F2:0x74 i = 5
689          * F2:0x78 i = 6
690          * F2:0x7C i = 7
691          * Select bits to exclude from comparison with the DRAM Base address register.
692          * [ 8: 0] Reserved
693          * [15: 9] Address Mask (19-13)
694          *         Address to be excluded from the optimized case
695          * [20:16] Reserved
696          * [29:21] Address Mask (33-25)
697          *         The bits with an address mask of 1 are excluded from address comparison
698          * [31:30] Reserved
699          * 
700          */
701 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
702         PCI_ADDR(0, 0x18, 2, 0x60), 0xC01f01ff, 0x00000000,
703         PCI_ADDR(0, 0x18, 2, 0x64), 0xC01f01ff, 0x00000000,
704         PCI_ADDR(0, 0x18, 2, 0x68), 0xC01f01ff, 0x00000000,
705         PCI_ADDR(0, 0x18, 2, 0x6C), 0xC01f01ff, 0x00000000,
706 #endif
707 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
708         PCI_ADDR(0, 0x18, 2, 0x60), 0xC01f01ff, 0x0060fe00,
709         PCI_ADDR(0, 0x18, 2, 0x64), 0xC01f01ff, 0x0060fe00,
710         PCI_ADDR(0, 0x18, 2, 0x68), 0xC01f01ff, 0x0060fe00,
711         PCI_ADDR(0, 0x18, 2, 0x6C), 0xC01f01ff, 0x0060fe00,
712 #endif
713 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
714         PCI_ADDR(0, 0x18, 2, 0x60), 0xC01f01ff, 0x03e0ee00,
715         PCI_ADDR(0, 0x18, 2, 0x64), 0xC01f01ff, 0x03e0ee00,
716         PCI_ADDR(0, 0x18, 2, 0x68), 0xC01f01ff, 0x00000000,
717         PCI_ADDR(0, 0x18, 2, 0x6C), 0xC01f01ff, 0x00000000,
718 #endif
719         PCI_ADDR(0, 0x18, 2, 0x70), 0xC01f01ff, 0x00000000,
720         PCI_ADDR(0, 0x18, 2, 0x74), 0xC01f01ff, 0x00000000,
721         PCI_ADDR(0, 0x18, 2, 0x78), 0xC01f01ff, 0x00000000,
722         PCI_ADDR(0, 0x18, 2, 0x7C), 0xC01f01ff, 0x00000000,
723         /* DRAM Bank Address Mapping Register
724          * F2:0x80
725          * Specify the memory module size
726          * [ 2: 0] CS1/0 
727          * [ 6: 4] CS3/2
728          * [10: 8] CS5/4
729          * [14:12] CS7/6
730          *         000 = 32Mbyte  (Rows = 12 & Col =  8)
731          *         001 = 64Mbyte  (Rows = 12 & Col =  9)
732          *         010 = 128Mbyte (Rows = 13 & Col =  9)|(Rows = 12 & Col = 10)
733          *         011 = 256Mbyte (Rows = 13 & Col = 10)|(Rows = 12 & Col = 11)
734          *         100 = 512Mbyte (Rows = 13 & Col = 11)|(Rows = 14 & Col = 10)
735          *         101 = 1Gbyte   (Rows = 14 & Col = 11)|(Rows = 13 & Col = 12)
736          *         110 = 2Gbyte   (Rows = 14 & Col = 12)
737          *         111 = reserved 
738          * [ 3: 3] Reserved
739          * [ 7: 7] Reserved
740          * [11:11] Reserved
741          * [31:15]
742          */
743 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
744         PCI_ADDR(0, 0x18, 2, 0x80), 0xffff8888, 0x00000000,
745 #endif
746 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
747         PCI_ADDR(0, 0x18, 2, 0x80), 0xffff8888, 0x00000022,
748 #endif
749 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
750         PCI_ADDR(0, 0x18, 2, 0x80), 0xffff8888, 0x00000003,
751 #endif
752         /* DRAM Timing Low Register
753          * F2:0x88
754          * [ 2: 0] Tcl (Cas# Latency, Cas# to read-data-valid)
755          *         000 = reserved
756          *         001 = CL 2
757          *         010 = CL 3
758          *         011 = reserved
759          *         100 = reserved
760          *         101 = CL 2.5
761          *         110 = reserved
762          *         111 = reserved
763          * [ 3: 3] Reserved
764          * [ 7: 4] Trc (Row Cycle Time, Ras#-active to Ras#-active/bank auto refresh)
765          *         0000 =  7 bus clocks
766          *         0001 =  8 bus clocks
767          *         ...
768          *         1110 = 21 bus clocks
769          *         1111 = 22 bus clocks
770          * [11: 8] Trfc (Row refresh Cycle time, Auto-refresh-active to RAS#-active or RAS#auto-refresh)
771          *         0000 = 9 bus clocks
772          *         0010 = 10 bus clocks
773          *         ....
774          *         1110 = 23 bus clocks
775          *         1111 = 24 bus clocks
776          * [14:12] Trcd (Ras#-active to Case#-read/write Delay)
777          *         000 = reserved
778          *         001 = reserved
779          *         010 = 2 bus clocks
780          *         011 = 3 bus clocks
781          *         100 = 4 bus clocks
782          *         101 = 5 bus clocks
783          *         110 = 6 bus clocks
784          *         111 = reserved
785          * [15:15] Reserved
786          * [18:16] Trrd (Ras# to Ras# Delay)
787          *         000 = reserved
788          *         001 = reserved
789          *         010 = 2 bus clocks
790          *         011 = 3 bus clocks
791          *         100 = 4 bus clocks
792          *         101 = reserved
793          *         110 = reserved
794          *         111 = reserved
795          * [19:19] Reserved
796          * [23:20] Tras (Minmum Ras# Active Time)
797          *         0000 to 0100 = reserved
798          *         0101 = 5 bus clocks
799          *         ...
800          *         1111 = 15 bus clocks
801          * [26:24] Trp (Row Precharge Time)
802          *         000 = reserved
803          *         001 = reserved
804          *         010 = 2 bus clocks
805          *         011 = 3 bus clocks
806          *         100 = 4 bus clocks
807          *         101 = 5 bus clocks
808          *         110 = 6 bus clocks
809          *         111 = reserved
810          * [27:27] Reserved
811          * [28:28] Twr (Write Recovery Time)
812          *         0 = 2 bus clocks
813          *         1 = 3 bus clocks
814          * [31:29] Reserved
815          */
816 #if (MEMORY_CONFIG == MEMORY_LNXI_SOLO) || (MEMORY_CONFIG == MEMORY_SUSE_SOLO)
817         PCI_ADDR(0, 0x18, 2, 0x88), 0xe8088008, 0x03623125,
818 #endif
819 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
820         PCI_ADDR(0, 0x18, 2, 0x88), 0xe8088008, 0x13723335,
821 #endif
822         /* DRAM Timing High Register
823          * F2:0x8C
824          * [ 0: 0] Twtr (Write to Read Delay)
825          *         0 = 1 bus Clocks
826          *         1 = 2 bus Clocks
827          * [ 3: 1] Reserved
828          * [ 6: 4] Trwf (Read to Write Delay)
829          *         000 = 1 bus clocks
830          *         001 = 2 bus clocks
831          *         010 = 3 bus clocks
832          *         011 = 4 bus clocks
833          *         100 = 5 bus clocks
834          *         101 = 6 bus clocks
835          *         110 = reserved
836          *         111 = reserved
837          * [ 7: 7] Reserved
838          * [12: 8] Tref (Refresh Rate)
839          *         00000 = 100Mhz 4K rows
840          *         00001 = 133Mhz 4K rows
841          *         00010 = 166Mhz 4K rows
842          *         01000 = 100Mhz 8K/16K rows
843          *         01001 = 133Mhz 8K/16K rows
844          *         01010 = 166Mhz 8K/16K rows
845          * [19:13] Reserved
846          * [22:20] Twcl (Write CAS Latency)
847          *         000 = 1 Mem clock after CAS# (Unbuffered Dimms)
848          *         001 = 2 Mem clocks after CAS# (Registered Dimms)
849          * [31:23] Reserved
850          */
851 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
852         PCI_ADDR(0, 0x18, 2, 0x8c), 0xff8fe08e, 0x00000930,
853 #endif
854 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
855         PCI_ADDR(0, 0x18, 2, 0x8c), 0xff8fe08e, 0x00000130,
856 #endif
857 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
858         PCI_ADDR(0, 0x18, 2, 0x8c), 0xff8fe08e, 0x00100a20,
859 #endif
860         /* DRAM Config Low Register
861          * F2:0x90
862          * [ 0: 0] DLL Disable
863          *         0 = Enabled
864          *         1 = Disabled
865          * [ 1: 1] D_DRV
866          *         0 = Normal Drive
867          *         1 = Weak Drive
868          * [ 2: 2] QFC_EN
869          *         0 = Disabled
870          *         1 = Enabled
871          * [ 3: 3] Disable DQS Hystersis  (FIXME handle this one carefully)
872          *         0 = Enable DQS input filter 
873          *         1 = Disable DQS input filtering 
874          * [ 7: 4] Reserved
875          * [ 8: 8] DRAM_Init
876          *         0 = Initialization done or not yet started.
877          *         1 = Initiate DRAM intialization sequence
878          * [ 9: 9] SO-Dimm Enable
879          *         0 = Do nothing
880          *         1 = SO-Dimms present
881          * [10:10] DramEnable
882          *         0 = DRAM not enabled
883          *         1 = DRAM initialized and enabled
884          * [11:11] Memory Clear Status
885          *         0 = Memory Clear function has not completed
886          *         1 = Memory Clear function has completed
887          * [12:12] Exit Self-Refresh
888          *         0 = Exit from self-refresh done or not yet started
889          *         1 = DRAM exiting from self refresh
890          * [13:13] Self-Refresh Status
891          *         0 = Normal Operation
892          *         1 = Self-refresh mode active
893          * [15:14] Read/Write Queue Bypass Count
894          *         00 = 2
895          *         01 = 4
896          *         10 = 8
897          *         11 = 16
898          * [16:16] 128-bit/64-Bit
899          *         0 = 64bit Interface to DRAM
900          *         1 = 128bit Interface to DRAM
901          * [17:17] DIMM ECC Enable
902          *         0 = Some DIMMs do not have ECC
903          *         1 = ALL DIMMS have ECC bits
904          * [18:18] UnBuffered DIMMs
905          *         0 = Buffered DIMMS
906          *         1 = Unbuffered DIMMS
907          * [19:19] Enable 32-Byte Granularity
908          *         0 = Optimize for 64byte bursts
909          *         1 = Optimize for 32byte bursts
910          * [20:20] DIMM 0 is x4
911          * [21:21] DIMM 1 is x4
912          * [22:22] DIMM 2 is x4
913          * [23:23] DIMM 3 is x4
914          *         0 = DIMM is not x4
915          *         1 = x4 DIMM present
916          * [24:24] Disable DRAM Receivers
917          *         0 = Receivers enabled
918          *         1 = Receivers disabled
919          * [27:25] Bypass Max
920          *         000 = Arbiters chois is always respected
921          *         001 = Oldest entry in DCQ can be bypassed 1 time
922          *         010 = Oldest entry in DCQ can be bypassed 2 times
923          *         011 = Oldest entry in DCQ can be bypassed 3 times
924          *         100 = Oldest entry in DCQ can be bypassed 4 times
925          *         101 = Oldest entry in DCQ can be bypassed 5 times
926          *         110 = Oldest entry in DCQ can be bypassed 6 times
927          *         111 = Oldest entry in DCQ can be bypassed 7 times
928          * [31:28] Reserved
929          */
930 #if (MEMORY_CONFIG == MEMORY_LNXI_SOLO) || (MEMORY_CONFIG == MEMORY_SUSE_SOLO)
931         PCI_ADDR(0, 0x18, 2, 0x90), 0xf0000000, 
932         (4 << 25)|(0 << 24)| 
933         (0 << 23)|(0 << 22)|(0 << 21)|(0 << 20)| 
934         (1 << 19)|(1 << 18)|(0 << 17)|(0 << 16)| 
935         (2 << 14)|(0 << 13)|(0 << 12)| 
936         (0 << 11)|(0 << 10)|(0 << 9)|(0 << 8)| 
937         (0 << 3) |(0 << 1) |(0 << 0),
938 #endif
939 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
940         PCI_ADDR(0, 0x18, 2, 0x90), 0xf0000000, 
941         (4 << 25)|(0 << 24)|
942         (0 << 23)|(0 << 22)|(0 << 21)|(0 << 20)|
943         (0 << 19)|(0 << 18)|(0 << 17)|(1 << 16)|
944         (2 << 14)|(0 << 13)|(0 << 12)|
945         (0 << 11)|(0 << 10)|(0 << 9)|(0 << 8)|
946         (0 << 3) |(0 << 1) |(0 << 0),
947 #endif
948         /* DRAM Config High Register
949          * F2:0x94
950          * [ 0: 3] Maximum Asynchronous Latency
951          *         0000 = 0 ns
952          *         ...
953          *         1111 = 15 ns
954          * [ 7: 4] Reserved
955          * [11: 8] Read Preamble
956          *         0000 = 2.0 ns
957          *         0001 = 2.5 ns
958          *         0010 = 3.0 ns
959          *         0011 = 3.5 ns
960          *         0100 = 4.0 ns
961          *         0101 = 4.5 ns
962          *         0110 = 5.0 ns
963          *         0111 = 5.5 ns
964          *         1000 = 6.0 ns
965          *         1001 = 6.5 ns
966          *         1010 = 7.0 ns
967          *         1011 = 7.5 ns
968          *         1100 = 8.0 ns
969          *         1101 = 8.5 ns
970          *         1110 = 9.0 ns
971          *         1111 = 9.5 ns
972          * [15:12] Reserved
973          * [18:16] Idle Cycle Limit
974          *         000 = 0 cycles
975          *         001 = 4 cycles
976          *         010 = 8 cycles
977          *         011 = 16 cycles
978          *         100 = 32 cycles
979          *         101 = 64 cycles
980          *         110 = 128 cycles
981          *         111 = 256 cycles
982          * [19:19] Dynamic Idle Cycle Center Enable
983          *         0 = Use Idle Cycle Limit
984          *         1 = Generate a dynamic Idle cycle limit
985          * [22:20] DRAM MEMCLK Frequency
986          *         000 = 100Mhz
987          *         001 = reserved
988          *         010 = 133Mhz
989          *         011 = reserved
990          *         100 = reserved
991          *         101 = 166Mhz
992          *         110 = reserved
993          *         111 = reserved
994          * [24:23] Reserved
995          * [25:25] Memory Clock Ratio Valid (FIXME carefully enable memclk)
996          *         0 = Disable MemClks
997          *         1 = Enable MemClks
998          * [26:26] Memory Clock 0 Enable
999          *         0 = Disabled
1000          *         1 = Enabled
1001          * [27:27] Memory Clock 1 Enable
1002          *         0 = Disabled
1003          *         1 = Enabled
1004          * [28:28] Memory Clock 2 Enable
1005          *         0 = Disabled
1006          *         1 = Enabled
1007          * [29:29] Memory Clock 3 Enable
1008          *         0 = Disabled
1009          *         1 = Enabled
1010          * [31:30] Reserved
1011          */
1012 #if MEMORY_CONFIG == MEMORY_LNXI_SOLO
1013         PCI_ADDR(0, 0x18, 2, 0x94), 0xc180f0f0, 0x0e2b0a05,
1014 #endif
1015 #if MEMORY_CONFIG == MEMORY_SUSE_SOLO
1016         PCI_ADDR(0, 0x18, 2, 0x94), 0xc180f0f0, 0x0e2b0a06,
1017 #endif
1018 #if MEMORY_CONFIG == MEMORY_LNXI_HDAMA
1019         PCI_ADDR(0, 0x18, 2, 0x94), 0xc180f0f0, 0x065b0b08,
1020 #endif
1021         /* DRAM Delay Line Register
1022          * F2:0x98
1023          * Adjust the skew of the input DQS strobe relative to DATA
1024          * [15: 0] Reserved
1025          * [23:16] Delay Line Adjust
1026          *         Adjusts the DLL derived PDL delay by one or more delay stages
1027          *         in either the faster or slower direction.
1028          * [24:24} Adjust Slower
1029          *         0 = Do Nothing
1030          *         1 = Adj is used to increase the PDL delay
1031          * [25:25] Adjust Faster
1032          *         0 = Do Nothing
1033          *         1 = Adj is used to decrease the PDL delay
1034          * [31:26] Reserved
1035          */
1036         PCI_ADDR(0, 0x18, 2, 0x98), 0xfc00ffff, 0x00000000,
1037         /* DRAM Scrub Control Register
1038          * F3:0x58
1039          * [ 4: 0] DRAM Scrube Rate
1040          * [ 7: 5] reserved
1041          * [12: 8] L2 Scrub Rate
1042          * [15:13] reserved
1043          * [20:16] Dcache Scrub
1044          * [31:21] reserved
1045          *         Scrub Rates
1046          *         00000 = Do not scrub
1047          *         00001 =  40.00 ns
1048          *         00010 =  80.00 ns
1049          *         00011 = 160.00 ns
1050          *         00100 = 320.00 ns
1051          *         00101 = 640.00 ns
1052          *         00110 =   1.28 us
1053          *         00111 =   2.56 us
1054          *         01000 =   5.12 us
1055          *         01001 =  10.20 us
1056          *         01011 =  41.00 us
1057          *         01100 =  81.90 us
1058          *         01101 = 163.80 us
1059          *         01110 = 327.70 us
1060          *         01111 = 655.40 us
1061          *         10000 =   1.31 ms
1062          *         10001 =   2.62 ms
1063          *         10010 =   5.24 ms
1064          *         10011 =  10.49 ms
1065          *         10100 =  20.97 ms
1066          *         10101 =  42.00 ms
1067          *         10110 =  84.00 ms
1068          *         All Others = Reserved
1069          */
1070         PCI_ADDR(0, 0x18, 3, 0x58), 0xffe0e0e0, 0x00000000,
1071         /* DRAM Scrub Address Low Register
1072          * F3:0x5C
1073          * [ 0: 0] DRAM Scrubber Redirect Enable
1074          *         0 = Do nothing
1075          *         1 = Scrubber Corrects errors found in normal operation
1076          * [ 5: 1] Reserved
1077          * [31: 6] DRAM Scrub Address 31-6
1078          */
1079         PCI_ADDR(0, 0x18, 3, 0x5C), 0x0000003e, 0x00000000,
1080         /* DRAM Scrub Address High Register
1081          * F3:0x60
1082          * [ 7: 0] DRAM Scrubb Address 39-32
1083          * [31: 8] Reserved
1084          */
1085         PCI_ADDR(0, 0x18, 3, 0x60), 0xffffff00, 0x00000000,
1086         };
1087         int i;
1088         int max;
1089         print_debug("setting up CPU0 northbridge registers\r\n");
1090         max = sizeof(register_values)/sizeof(register_values[0]);
1091         for(i = 0; i < max; i += 3) {
1092                 device_t dev;
1093                 unsigned where;
1094                 unsigned long reg;
1095 #if 0
1096                 print_debug_hex32(register_values[i]);
1097                 print_debug(" <-");
1098                 print_debug_hex32(register_values[i+2]);
1099                 print_debug("\r\n");
1100 #endif
1101                 dev = register_values[i] & ~0xff;
1102                 where = register_values[i] & 0xff;
1103                 reg = pci_read_config32(dev, where);
1104                 reg &= register_values[i+1];
1105                 reg |= register_values[i+2];
1106                 pci_write_config32(dev, where, reg);
1107 #if 0
1108
1109                 reg = pci_read_config32(register_values[i]);
1110                 reg &= register_values[i+1];
1111                 reg |= register_values[i+2];
1112                 pci_write_config32(register_values[i], reg);
1113 #endif
1114         }
1115         print_debug("done.\r\n");
1116 }
1117
1118
1119 struct dimm_size {
1120         unsigned long side1;
1121         unsigned long side2;
1122 };
1123 static struct dimm_size spd_get_dimm_size(unsigned device)
1124 {
1125         /* Calculate the log base 2 size of a DIMM in bits */
1126         struct dimm_size sz;
1127         int value, low;
1128         sz.side1 = 0;
1129         sz.side2 = 0;
1130
1131         /* Note it might be easier to use byte 31 here, it has the DIMM size as
1132          * a multiple of 4MB.  The way we do it now we can size both
1133          * sides of an assymetric dimm.
1134          */
1135         value = smbus_read_byte(device, 3);     /* rows */
1136         if (value < 0) return sz;
1137         sz.side1 += value & 0xf;
1138
1139         value = smbus_read_byte(device, 4);     /* columns */
1140         if (value < 0) return sz;
1141         sz.side1 += value & 0xf;
1142
1143         value = smbus_read_byte(device, 17);    /* banks */
1144         if (value < 0) return sz;
1145         sz.side1 += log2(value & 0xff);
1146
1147         /* Get the module data widht and convert it to a power of two */
1148         value = smbus_read_byte(device, 7);     /* (high byte) */
1149         if (value < 0) return sz;
1150         value &= 0xff;
1151         value <<= 8;
1152         
1153         low = smbus_read_byte(device, 6);       /* (low byte) */
1154         if (low < 0) return sz;
1155         value = value | (low & 0xff);
1156         sz.side1 += log2(value);
1157
1158         /* side 2 */
1159         value = smbus_read_byte(device, 5);     /* number of physical banks */
1160         if (value <= 1) return sz;
1161
1162         /* Start with the symmetrical case */
1163         sz.side2 = sz.side1;
1164
1165         value = smbus_read_byte(device, 3);     /* rows */
1166         if (value < 0) return sz;
1167         if ((value & 0xf0) == 0) return sz;     /* If symmetrical we are done */
1168         sz.side2 -= (value & 0x0f);             /* Subtract out rows on side 1 */
1169         sz.side2 += ((value >> 4) & 0x0f);      /* Add in rows on side 2 */
1170
1171         value = smbus_read_byte(device, 4);     /* columns */
1172         if (value < 0) return sz;
1173         sz.side2 -= (value & 0x0f);             /* Subtract out columns on side 1 */
1174         sz.side2 += ((value >> 4) & 0x0f);      /* Add in columsn on side 2 */
1175         return sz;
1176 }
1177
1178 static unsigned spd_to_dimm(unsigned device)
1179 {
1180         return (device - SMBUS_MEM_DEVICE_START);
1181 }
1182
1183 static void set_dimm_size(struct dimm_size sz, unsigned index)
1184 {
1185         uint32_t base0, base1, map;
1186
1187 #if 1
1188         print_debug("set_dimm_size: (");
1189         print_debug_hex32(sz.side1);
1190         print_debug_char(',');
1191         print_debug_hex32(sz.side2);
1192         print_debug_char(',');
1193         print_debug_hex32(index);
1194         print_debug(")\r\n");
1195 #endif
1196         if (sz.side1 != sz.side2) {
1197                 sz.side2 = 0;
1198         }
1199         map = pci_read_config32(PCI_DEV(0, 0x18, 2), 0x80);
1200         map &= ~(0xf << (index + 4));
1201
1202         /* For each base register.
1203          * Place the dimm size in 32 MB quantities in the bits 31 - 21.
1204          * The initialize dimm size is in bits.
1205          * Set the base enable bit0.
1206          */
1207         
1208         base0 = base1 = 0;
1209
1210         /* Make certain side1 of the dimm is at least 32MB */
1211         if (sz.side1 >= (25 + 3)) {
1212                 base0 = (1 << ((sz.side1 - (25 + 3)) + 21)) | 1;
1213                 map |= (sz.side1 - (25 + 3)) << (index *4);
1214         }
1215
1216         /* Make certain side2 of the dimm is at least 32MB */
1217         if (sz.side2 >= (25 + 3)) {
1218                 base1 = (1 << ((sz.side2 - (25 + 3)) + 21)) | 1;
1219         }
1220         
1221         /* Set the appropriate DIMM base address register */
1222         pci_write_config32(PCI_DEV(0, 0x18, 2), 0x40 + (((index << 1)+0)<<2), base0);
1223         pci_write_config32(PCI_DEV(0, 0x18, 2), 0x40 + (((index << 1)+1)<<2), base1);
1224         pci_write_config32(PCI_DEV(0, 0x18, 2), 0x80, map);
1225 }
1226
1227 static void spd_set_ram_size(void)
1228 {
1229         unsigned device;
1230         for(device = SMBUS_MEM_DEVICE_START; 
1231                 device <= SMBUS_MEM_DEVICE_END;
1232                 device += SMBUS_MEM_DEVICE_INC) 
1233         {
1234                 struct dimm_size sz;
1235                 sz = spd_get_dimm_size(device);
1236                 set_dimm_size(sz, spd_to_dimm(device));
1237         }
1238 }
1239
1240 static void set_top_mem(unsigned tom_k)
1241 {
1242         /* Error if I don't have memory */
1243         if (!tom_k) {
1244                 die("No memory");
1245         }
1246         /* Now set top of memory */
1247         msr_t msr;
1248         msr.lo = (tom_k & 0x003fffff) << 10;
1249         msr.hi = (tom_k & 0xffc00000) >> 22;
1250         wrmsr(TOP_MEM, msr);
1251
1252 #if 1
1253         /* And report the amount of memory.  (I run out of registers if i don't) */
1254         print_debug("RAM: 0x");
1255         print_debug_hex32(tom_k);
1256         print_debug(" KB\r\n");
1257 #endif
1258 }
1259
1260 static void order_dimms(void)
1261 {
1262         unsigned long tom;
1263
1264         /* Remember which registers we have used in the high 8 bits of tom */
1265         tom = 0;
1266         for(;;) {
1267                 /* Find the largest remaining canidate */
1268                 unsigned index, canidate;
1269                 uint32_t csbase, csmask;
1270                 unsigned size;
1271                 csbase = 0;
1272                 canidate = 0;
1273                 for(index = 0; index < 8; index++) {
1274                         uint32_t value;
1275                         value = pci_read_config32(PCI_DEV(0, 0x18, 2), 0x40 + (index << 2));
1276
1277                         /* Is it enabled? */
1278                         if (!(value & 1)) {
1279                                 continue;
1280                         }
1281                         
1282                         /* Is it greater? */
1283                         if (value <= csbase) {
1284                                 continue;
1285                         }
1286                         
1287                         /* Has it already been selected */
1288                         if (tom & (1 << (index + 24))) {
1289                                 continue;
1290                         }
1291                         /* I have a new canidate */
1292                         csbase = value;
1293                         canidate = index;
1294                 }
1295                 /* See if I have found a new canidate */
1296                 if (csbase == 0) {
1297                         break;
1298                 }
1299
1300                 /* Remember I have used this register */
1301                 tom |= (1 << (canidate + 24));
1302
1303                 /* Remember the dimm size */
1304                 size = csbase >> 21;
1305
1306                 /* Recompute the cs base register value */
1307                 csbase = (tom << 21) | 1;
1308
1309                 /* Increment the top of memory */
1310                 tom += size;
1311
1312                 /* Compute the memory mask */
1313                 csmask = ((size -1) << 21);
1314                 csmask |= 0xfe00;               /* For now don't optimize */
1315
1316                 /* Write the new base register */
1317                 pci_write_config32(PCI_DEV(0, 0x18, 2), 0x40 + (canidate << 2), csbase);
1318                 /* Write the new mask register */
1319                 pci_write_config32(PCI_DEV(0, 0x18, 2), 0x60 + (canidate << 2), csmask);
1320                 
1321         }
1322         set_top_mem((tom & ~0xff000000) << 15);
1323 }
1324
1325 static void spd_set_dram_timing(void)
1326 {
1327         
1328 }
1329
1330 #define DRAM_CONFIG_LOW 0x90
1331 #define  DCL_DLL_Disable   (1<<0)
1332 #define  DCL_D_DRV         (1<<1)
1333 #define  DCL_QFC_EN        (1<<2)
1334 #define  DCL_DisDqsHys     (1<<3)
1335 #define  DCL_DramInit      (1<<8)
1336 #define  DCL_DramEnable    (1<<10)
1337 #define  DCL_MemClrStatus  (1<<11)
1338 #define  DCL_DimmEcEn      (1<<17)
1339
1340
1341 static void spd_set_ecc_mode(void)
1342 {
1343         unsigned long dcl;
1344         dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
1345         /* Until I know what is going on disable ECC support */
1346         dcl &= ~DCL_DimmEcEn;
1347         pci_write_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW, dcl);
1348
1349 }
1350 static void sdram_set_spd_registers(void) 
1351 {
1352         spd_set_ram_size();
1353         spd_set_dram_timing();
1354         spd_set_ecc_mode();
1355         order_dimms();
1356 }
1357
1358 #define TIMEOUT_LOOPS 300000
1359 static void sdram_enable(void)
1360 {
1361         unsigned long dcl;
1362
1363         /* Toggle DisDqsHys to get it working */
1364         dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
1365         print_debug("dcl: ");
1366         print_debug_hex32(dcl);
1367         print_debug("\r\n");
1368         dcl |= DCL_DisDqsHys;
1369         pci_write_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW, dcl);
1370         dcl &= ~DCL_DisDqsHys;
1371         dcl &= ~DCL_DLL_Disable;
1372         dcl &= ~DCL_D_DRV;
1373         dcl &= ~DCL_QFC_EN;
1374         dcl |= DCL_DramInit;
1375         pci_write_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW, dcl);
1376         
1377         print_debug("Initializing memory: ");
1378         int loops = 0;
1379         do {
1380                 dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
1381                 loops += 1;
1382                 if ((loops & 1023) == 0) {
1383                         print_debug(".");
1384                 }
1385         } while(((dcl & DCL_DramInit) != 0) && (loops < TIMEOUT_LOOPS));
1386         if (loops >= TIMEOUT_LOOPS) {
1387                 print_debug(" failed\r\n");
1388         } else {
1389                 print_debug(" done\r\n");
1390         }
1391
1392 #if 0
1393         print_debug("Clearing memory: ");
1394         loops = 0;
1395         do {
1396                 dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
1397                 loops += 1;
1398                 if ((loops & 1023) == 0) {
1399                         print_debug(" ");
1400                         print_debug_hex32(loops);
1401                 }
1402         } while(((dcl & DCL_MemClrStatus) == 0) && (loops < TIMEOUT_LOOPS));
1403         if (loops >= TIMEOUT_LOOPS) {
1404                 print_debug("failed\r\n");
1405         } else {
1406                 print_debug("done\r\n");
1407         }
1408 #endif
1409 }
1410
1411 static void sdram_first_normal_reference(void) {}
1412 static void sdram_enable_refresh(void) {}
1413 static void sdram_special_finishup(void) {}
1414