- Changes to the pci config routines moving them closer to the non romcc API
[coreboot.git] / src / northbridge / amd / amdk8 / raminit.c
1 #define MEMORY_512MB  0  /* SuSE Solo configuration */
2 #define MEMORY_1024MB 1  /* LNXI Solo configuration */
3
4 static void sdram_set_registers(void)
5 {
6         static const unsigned int register_values[] = {
7         /* Careful set limit registers before base registers which contain the enables */
8         /* DRAM Limit i Registers
9          * F1:0x44 i = 0
10          * F1:0x4C i = 1
11          * F1:0x54 i = 2
12          * F1:0x5C i = 3
13          * F1:0x64 i = 4
14          * F1:0x6C i = 5
15          * F1:0x74 i = 6
16          * F1:0x7C i = 7
17          * [ 2: 0] Destination Node ID
18          *         000 = Node 0
19          *         001 = Node 1
20          *         010 = Node 2
21          *         011 = Node 3
22          *         100 = Node 4
23          *         101 = Node 5
24          *         110 = Node 6
25          *         111 = Node 7
26          * [ 7: 3] Reserved
27          * [10: 8] Interleave select
28          *         specifies the values of A[14:12] to use with interleave enable.
29          * [15:11] Reserved
30          * [31:16] DRAM Limit Address i Bits 39-24
31          *         This field defines the upper address bits of a 40 bit  address
32          *         that define the end of the DRAM region.
33          */
34 #if MEMORY_1024MB
35         PCI_ADDR(0, 0x18, 1, 0x44), 0x0000f8f8, 0x003f0000,
36 #endif
37 #if MEMORY_512MB
38         PCI_ADDR(0, 0x18, 1, 0x44), 0x0000f8f8, 0x001f0000,
39 #endif
40         PCI_ADDR(0, 0x18, 1, 0x4C), 0x0000f8f8, 0x00000001,
41         PCI_ADDR(0, 0x18, 1, 0x54), 0x0000f8f8, 0x00000002,
42         PCI_ADDR(0, 0x18, 1, 0x5C), 0x0000f8f8, 0x00000003,
43         PCI_ADDR(0, 0x18, 1, 0x64), 0x0000f8f8, 0x00000004,
44         PCI_ADDR(0, 0x18, 1, 0x6C), 0x0000f8f8, 0x00000005,
45         PCI_ADDR(0, 0x18, 1, 0x74), 0x0000f8f8, 0x00000006,
46         PCI_ADDR(0, 0x18, 1, 0x7C), 0x0000f8f8, 0x00000007,
47         /* DRAM Base i Registers
48          * F1:0x40 i = 0
49          * F1:0x48 i = 1
50          * F1:0x50 i = 2
51          * F1:0x58 i = 3
52          * F1:0x60 i = 4
53          * F1:0x68 i = 5
54          * F1:0x70 i = 6
55          * F1:0x78 i = 7
56          * [ 0: 0] Read Enable
57          *         0 = Reads Disabled
58          *         1 = Reads Enabled
59          * [ 1: 1] Write Enable
60          *         0 = Writes Disabled
61          *         1 = Writes Enabled
62          * [ 7: 2] Reserved
63          * [10: 8] Interleave Enable
64          *         000 = No interleave
65          *         001 = Interleave on A[12] (2 nodes)
66          *         010 = reserved
67          *         011 = Interleave on A[12] and A[14] (4 nodes)
68          *         100 = reserved
69          *         101 = reserved
70          *         110 = reserved
71          *         111 = Interleve on A[12] and A[13] and A[14] (8 nodes)
72          * [15:11] Reserved
73          * [13:16] DRAM Base Address i Bits 39-24
74          *         This field defines the upper address bits of a 40-bit address
75          *         that define the start of the DRAM region.
76          */
77         PCI_ADDR(0, 0x18, 1, 0x40), 0x0000f8fc, 0x00000003,
78 #if MEMORY_1024MB
79         PCI_ADDR(0, 0x18, 1, 0x48), 0x0000f8fc, 0x00400000,
80         PCI_ADDR(0, 0x18, 1, 0x50), 0x0000f8fc, 0x00400000,
81         PCI_ADDR(0, 0x18, 1, 0x58), 0x0000f8fc, 0x00400000,
82         PCI_ADDR(0, 0x18, 1, 0x60), 0x0000f8fc, 0x00400000,
83         PCI_ADDR(0, 0x18, 1, 0x68), 0x0000f8fc, 0x00400000,
84         PCI_ADDR(0, 0x18, 1, 0x70), 0x0000f8fc, 0x00400000,
85         PCI_ADDR(0, 0x18, 1, 0x78), 0x0000f8fc, 0x00400000,
86 #endif
87 #if MEMORY_512MB
88         PCI_ADDR(0, 0x18, 1, 0x48), 0x0000f8fc, 0x00200000,
89         PCI_ADDR(0, 0x18, 1, 0x50), 0x0000f8fc, 0x00200000,
90         PCI_ADDR(0, 0x18, 1, 0x58), 0x0000f8fc, 0x00200000,
91         PCI_ADDR(0, 0x18, 1, 0x60), 0x0000f8fc, 0x00200000,
92         PCI_ADDR(0, 0x18, 1, 0x68), 0x0000f8fc, 0x00200000,
93         PCI_ADDR(0, 0x18, 1, 0x70), 0x0000f8fc, 0x00200000,
94         PCI_ADDR(0, 0x18, 1, 0x78), 0x0000f8fc, 0x00200000,
95 #endif
96
97         /* Memory-Mapped I/O Limit i Registers
98          * F1:0x84 i = 0
99          * F1:0x8C i = 1
100          * F1:0x94 i = 2
101          * F1:0x9C i = 3
102          * F1:0xA4 i = 4
103          * F1:0xAC i = 5
104          * F1:0xB4 i = 6
105          * F1:0xBC i = 7
106          * [ 2: 0] Destination Node ID
107          *         000 = Node 0
108          *         001 = Node 1
109          *         010 = Node 2
110          *         011 = Node 3
111          *         100 = Node 4
112          *         101 = Node 5
113          *         110 = Node 6
114          *         111 = Node 7
115          * [ 3: 3] Reserved
116          * [ 5: 4] Destination Link ID
117          *         00 = Link 0
118          *         01 = Link 1
119          *         10 = Link 2
120          *         11 = Reserved
121          * [ 6: 6] Reserved
122          * [ 7: 7] Non-Posted
123          *         0 = CPU writes may be posted
124          *         1 = CPU writes must be non-posted
125          * [31: 8] Memory-Mapped I/O Limit Address i (39-16)
126          *         This field defines the upp adddress bits of a 40-bit address that
127          *         defines the end of a memory-mapped I/O region n
128          */
129         PCI_ADDR(0, 0x18, 1, 0x84), 0x00000048, 0x00e1ff00,
130         PCI_ADDR(0, 0x18, 1, 0x8C), 0x00000048, 0x00dfff00,
131         PCI_ADDR(0, 0x18, 1, 0x94), 0x00000048, 0x00e3ff00,
132         PCI_ADDR(0, 0x18, 1, 0x9C), 0x00000048, 0x00000000,
133         PCI_ADDR(0, 0x18, 1, 0xA4), 0x00000048, 0x00000000,
134         PCI_ADDR(0, 0x18, 1, 0xAC), 0x00000048, 0x00000000,
135         PCI_ADDR(0, 0x18, 1, 0xB4), 0x00000048, 0x00000b00,
136         PCI_ADDR(0, 0x18, 1, 0xBC), 0x00000048, 0x00fe0b00,
137
138         /* Memory-Mapped I/O Base i Registers
139          * F1:0x80 i = 0
140          * F1:0x88 i = 1
141          * F1:0x90 i = 2
142          * F1:0x98 i = 3
143          * F1:0xA0 i = 4
144          * F1:0xA8 i = 5
145          * F1:0xB0 i = 6
146          * F1:0xB8 i = 7
147          * [ 0: 0] Read Enable
148          *         0 = Reads disabled
149          *         1 = Reads Enabled
150          * [ 1: 1] Write Enable
151          *         0 = Writes disabled
152          *         1 = Writes Enabled
153          * [ 2: 2] Cpu Disable
154          *         0 = Cpu can use this I/O range
155          *         1 = Cpu requests do not use this I/O range
156          * [ 3: 3] Lock
157          *         0 = base/limit registers i are read/write
158          *         1 = base/limit registers i are read-only
159          * [ 7: 4] Reserved
160          * [31: 8] Memory-Mapped I/O Base Address i (39-16)
161          *         This field defines the upper address bits of a 40bit address 
162          *         that defines the start of memory-mapped I/O region i
163          */
164         PCI_ADDR(0, 0x18, 1, 0x80), 0x000000f0, 0x00e00003,
165         PCI_ADDR(0, 0x18, 1, 0x88), 0x000000f0, 0x00d80003,
166         PCI_ADDR(0, 0x18, 1, 0x90), 0x000000f0, 0x00e20003,
167         PCI_ADDR(0, 0x18, 1, 0x98), 0x000000f0, 0x00000000,
168         PCI_ADDR(0, 0x18, 1, 0xA0), 0x000000f0, 0x00000000,
169         PCI_ADDR(0, 0x18, 1, 0xA8), 0x000000f0, 0x00000000,
170         PCI_ADDR(0, 0x18, 1, 0xB0), 0x000000f0, 0x00000a03,
171 #if MEMORY_1024MB
172         PCI_ADDR(0, 0x18, 1, 0xB8), 0x000000f0, 0x00400003,
173 #endif
174 #if MEMORY_512MB
175         PCI_ADDR(0, 0x18, 1, 0xB8), 0x000000f0, 0x00200003,
176 #endif
177
178         /* PCI I/O Limit i Registers
179          * F1:0xC4 i = 0
180          * F1:0xCC i = 1
181          * F1:0xD4 i = 2
182          * F1:0xDC i = 3
183          * [ 2: 0] Destination Node ID
184          *         000 = Node 0
185          *         001 = Node 1
186          *         010 = Node 2
187          *         011 = Node 3
188          *         100 = Node 4
189          *         101 = Node 5
190          *         110 = Node 6
191          *         111 = Node 7
192          * [ 3: 3] Reserved
193          * [ 5: 4] Destination Link ID
194          *         00 = Link 0
195          *         01 = Link 1
196          *         10 = Link 2
197          *         11 = reserved
198          * [11: 6] Reserved
199          * [24:12] PCI I/O Limit Address i
200          *         This field defines the end of PCI I/O region n
201          * [31:25] Reserved
202          */
203         PCI_ADDR(0, 0x18, 1, 0xC4), 0xFE000FC8, 0x0000d000,
204         PCI_ADDR(0, 0x18, 1, 0xCC), 0xFE000FC8, 0x000ff000,
205         PCI_ADDR(0, 0x18, 1, 0xD4), 0xFE000FC8, 0x00000000,
206         PCI_ADDR(0, 0x18, 1, 0xDC), 0xFE000FC8, 0x00000000,
207
208         /* PCI I/O Base i Registers
209          * F1:0xC0 i = 0
210          * F1:0xC8 i = 1
211          * F1:0xD0 i = 2
212          * F1:0xD8 i = 3
213          * [ 0: 0] Read Enable
214          *         0 = Reads Disabled
215          *         1 = Reads Enabled
216          * [ 1: 1] Write Enable
217          *         0 = Writes Disabled
218          *         1 = Writes Enabled
219          * [ 3: 2] Reserved
220          * [ 4: 4] VGA Enable
221          *         0 = VGA matches Disabled
222          *         1 = matches all address < 64K and where A[9:0] is in the 
223          *             range 3B0-3BB or 3C0-3DF independen of the base & limit registers
224          * [ 5: 5] ISA Enable
225          *         0 = ISA matches Disabled
226          *         1 = Blocks address < 64K and in the last 768 bytes of eack 1K block
227          *             from matching agains this base/limit pair
228          * [11: 6] Reserved
229          * [24:12] PCI I/O Base i
230          *         This field defines the start of PCI I/O region n 
231          * [31:25] Reserved
232          */
233         PCI_ADDR(0, 0x18, 1, 0xC0), 0xFE000FCC, 0x0000d003,
234         PCI_ADDR(0, 0x18, 1, 0xC8), 0xFE000FCC, 0x00001013,
235         PCI_ADDR(0, 0x18, 1, 0xD0), 0xFE000FCC, 0x00000000,
236         PCI_ADDR(0, 0x18, 1, 0xD8), 0xFE000FCC, 0x00000000,
237
238         /* Config Base and Limit i Registers
239          * F1:0xE0 i = 0
240          * F1:0xE4 i = 1
241          * F1:0xE8 i = 2
242          * F1:0xEC i = 3
243          * [ 0: 0] Read Enable
244          *         0 = Reads Disabled
245          *         1 = Reads Enabled
246          * [ 1: 1] Write Enable
247          *         0 = Writes Disabled
248          *         1 = Writes Enabled
249          * [ 2: 2] Device Number Compare Enable
250          *         0 = The ranges are based on bus number
251          *         1 = The ranges are ranges of devices on bus 0
252          * [ 3: 3] Reserved
253          * [ 6: 4] Destination Node
254          *         000 = Node 0
255          *         001 = Node 1
256          *         010 = Node 2
257          *         011 = Node 3
258          *         100 = Node 4
259          *         101 = Node 5
260          *         110 = Node 6
261          *         111 = Node 7
262          * [ 7: 7] Reserved
263          * [ 9: 8] Destination Link
264          *         00 = Link 0
265          *         01 = Link 1
266          *         10 = Link 2
267          *         11 - Reserved
268          * [15:10] Reserved
269          * [23:16] Bus Number Base i
270          *         This field defines the lowest bus number in configuration region i
271          * [31:24] Bus Number Limit i
272          *         This field defines the highest bus number in configuration regin i
273          */
274         PCI_ADDR(0, 0x18, 1, 0xE0), 0x0000FC88, 0xff000003,
275         PCI_ADDR(0, 0x18, 1, 0xE4), 0x0000FC88, 0x00000000,
276         PCI_ADDR(0, 0x18, 1, 0xE8), 0x0000FC88, 0x00000000,
277         PCI_ADDR(0, 0x18, 1, 0xEC), 0x0000FC88, 0x00000000,
278
279         /* DRAM CS Base Address i Registers
280          * F2:0x40 i = 0
281          * F2:0x44 i = 1
282          * F2:0x48 i = 2
283          * F2:0x4C i = 3
284          * F2:0x50 i = 4
285          * F2:0x54 i = 5
286          * F2:0x58 i = 6
287          * F2:0x5C i = 7
288          * [ 0: 0] Chip-Select Bank Enable
289          *         0 = Bank Disabled
290          *         1 = Bank Enabled
291          * [ 8: 1] Reserved
292          * [15: 9] Base Address (19-13)
293          *         An optimization used when all DIMM are the same size...
294          * [20:16] Reserved
295          * [31:21] Base Address (35-25)
296          *         This field defines the top 11 addresses bit of a 40-bit
297          *         address that define the memory address space.  These
298          *         bits decode 32-MByte blocks of memory.
299          */
300         PCI_ADDR(0, 0x18, 2, 0x40), 0x001f01fe, 0x00000001,
301 #if MEMORY_1024MB
302         PCI_ADDR(0, 0x18, 2, 0x44), 0x001f01fe, 0x01000001,
303         PCI_ADDR(0, 0x18, 2, 0x48), 0x001f01fe, 0x02000001,
304         PCI_ADDR(0, 0x18, 2, 0x4C), 0x001f01fe, 0x03000001,
305 #endif
306 #if MEMORY_512MB
307         PCI_ADDR(0, 0x18, 2, 0x44), 0x001f01fe, 0x00800001,
308         PCI_ADDR(0, 0x18, 2, 0x48), 0x001f01fe, 0x01000001,
309         PCI_ADDR(0, 0x18, 2, 0x4C), 0x001f01fe, 0x01800001,
310 #endif
311         PCI_ADDR(0, 0x18, 2, 0x50), 0x001f01fe, 0x00000000,
312         PCI_ADDR(0, 0x18, 2, 0x54), 0x001f01fe, 0x00000000,
313         PCI_ADDR(0, 0x18, 2, 0x58), 0x001f01fe, 0x00000000,
314         PCI_ADDR(0, 0x18, 2, 0x5C), 0x001f01fe, 0x00000000,
315         /* DRAM CS Mask Address i Registers
316          * F2:0x60 i = 0
317          * F2:0x64 i = 1
318          * F2:0x68 i = 2
319          * F2:0x6C i = 3
320          * F2:0x70 i = 4
321          * F2:0x74 i = 5
322          * F2:0x78 i = 6
323          * F2:0x7C i = 7
324          * Select bits to exclude from comparison with the DRAM Base address register.
325          * [ 8: 0] Reserved
326          * [15: 9] Address Mask (19-13)
327          *         Address to be excluded from the optimized case
328          * [20:16] Reserved
329          * [29:21] Address Mask (33-25)
330          *         The bits with an address mask of 1 are excluded from address comparison
331          * [31:30] Reserved
332          * 
333          */
334 #if MEMORY_1024MB
335         PCI_ADDR(0, 0x18, 2, 0x60), 0xC01f01ff, 0x00e0fe00,
336         PCI_ADDR(0, 0x18, 2, 0x64), 0xC01f01ff, 0x00e0fe00,
337         PCI_ADDR(0, 0x18, 2, 0x68), 0xC01f01ff, 0x00e0fe00,
338         PCI_ADDR(0, 0x18, 2, 0x6C), 0xC01f01ff, 0x00e0fe00,
339 #endif
340 #if MEMORY_512MB
341         PCI_ADDR(0, 0x18, 2, 0x60), 0xC01f01ff, 0x0060fe00,
342         PCI_ADDR(0, 0x18, 2, 0x64), 0xC01f01ff, 0x0060fe00,
343         PCI_ADDR(0, 0x18, 2, 0x68), 0xC01f01ff, 0x0060fe00,
344         PCI_ADDR(0, 0x18, 2, 0x6C), 0xC01f01ff, 0x0060fe00,
345 #endif
346         PCI_ADDR(0, 0x18, 2, 0x70), 0xC01f01ff, 0x00000000,
347         PCI_ADDR(0, 0x18, 2, 0x74), 0xC01f01ff, 0x00000000,
348         PCI_ADDR(0, 0x18, 2, 0x78), 0xC01f01ff, 0x00000000,
349         PCI_ADDR(0, 0x18, 2, 0x7C), 0xC01f01ff, 0x00000000,
350         /* DRAM Bank Address Mapping Register
351          * F2:0x80
352          * Specify the memory module size
353          * [ 2: 0] CS1/0 
354          * [ 6: 4] CS3/2
355          * [10: 8] CS5/4
356          * [14:12] CS7/6
357          *         000 = 32Mbyte  (Rows = 12 & Col =  8)
358          *         001 = 64Mbyte  (Rows = 12 & Col =  9)
359          *         010 = 128Mbyte (Rows = 13 & Col =  9)|(Rows = 12 & Col = 10)
360          *         011 = 256Mbyte (Rows = 13 & Col = 10)|(Rows = 12 & Col = 11)
361          *         100 = 512Mbyte (Rows = 13 & Col = 11)|(Rows = 14 & Col = 10)
362          *         101 = 1Gbyte   (Rows = 14 & Col = 11)|(Rows = 13 & Col = 12)
363          *         110 = 2Gbyte   (Rows = 14 & Col = 12)
364          *         111 = reserved 
365          * [ 3: 3] Reserved
366          * [ 7: 7] Reserved
367          * [11:11] Reserved
368          * [31:15]
369          */
370 #if MEMORY_1024MB
371         PCI_ADDR(0, 0x18, 2, 0x80), 0xffff8888, 0x00000033,
372 #endif
373 #if MEMORY_512MB
374         PCI_ADDR(0, 0x18, 2, 0x80), 0xffff8888, 0x00000022,
375 #endif
376         /* DRAM Timing Low Register
377          * F2:0x88
378          * [ 2: 0] Tcl (Cas# Latency, Cas# to read-data-valid)
379          *         000 = reserved
380          *         001 = CL 2
381          *         010 = CL 3
382          *         011 = reserved
383          *         100 = reserved
384          *         101 = CL 2.5
385          *         110 = reserved
386          *         111 = reserved
387          * [ 3: 3] Reserved
388          * [ 7: 4] Trc (Row Cycle Time, Ras#-active to Ras#-active/bank auto refresh)
389          *         0000 =  7 bus clocks
390          *         0001 =  8 bus clocks
391          *         ...
392          *         1110 = 21 bus clocks
393          *         1111 = 22 bus clocks
394          * [11: 8] Trfc (Row refresh Cycle time, Auto-refresh-active to RAS#-active or RAS#auto-refresh)
395          *         0000 = 9 bus clocks
396          *         0010 = 10 bus clocks
397          *         ....
398          *         1110 = 23 bus clocks
399          *         1111 = 24 bus clocks
400          * [14:12] Trcd (Ras#-active to Case#-read/write Delay)
401          *         000 = reserved
402          *         001 = reserved
403          *         010 = 2 bus clocks
404          *         011 = 3 bus clocks
405          *         100 = 4 bus clocks
406          *         101 = 5 bus clocks
407          *         110 = 6 bus clocks
408          *         111 = reserved
409          * [15:15] Reserved
410          * [18:16] Trrd (Ras# to Ras# Delay)
411          *         000 = reserved
412          *         001 = reserved
413          *         010 = 2 bus clocks
414          *         011 = 3 bus clocks
415          *         100 = 4 bus clocks
416          *         101 = reserved
417          *         110 = reserved
418          *         111 = reserved
419          * [19:19] Reserved
420          * [23:20] Tras (Minmum Ras# Active Time)
421          *         0000 to 0100 = reserved
422          *         0101 = 5 bus clocks
423          *         ...
424          *         1111 = 15 bus clocks
425          * [26:24] Trp (Row Precharge Time)
426          *         000 = reserved
427          *         001 = reserved
428          *         010 = 2 bus clocks
429          *         011 = 3 bus clocks
430          *         100 = 4 bus clocks
431          *         101 = 5 bus clocks
432          *         110 = 6 bus clocks
433          *         111 = reserved
434          * [27:27] Reserved
435          * [28:28] Twr (Write Recovery Time)
436          *         0 = 2 bus clocks
437          *         1 = 3 bus clocks
438          * [31:29] Reserved
439          */
440         PCI_ADDR(0, 0x18, 2, 0x88), 0xe8088008, 0x03623125,
441         /* DRAM Timing High Register
442          * F2:0x8C
443          * [ 0: 0] Twtr (Write to Read Delay)
444          *         0 = 1 bus Clocks
445          *         1 = 2 bus Clocks
446          * [ 3: 1] Reserved
447          * [ 6: 4] Trwf (Read to Write Delay)
448          *         000 = 1 bus clocks
449          *         001 = 2 bus clocks
450          *         010 = 3 bus clocks
451          *         011 = 4 bus clocks
452          *         100 = 5 bus clocks
453          *         101 = 6 bus clocks
454          *         110 = reserved
455          *         111 = reserved
456          * [ 7: 7] Reserved
457          * [12: 8] Tref (Refresh Rate)
458          *         00000 = 100Mhz 4K rows
459          *         00001 = 133Mhz 4K rows
460          *         00010 = 166Mhz 4K rows
461          *         01000 = 100Mhz 8K/16K rows
462          *         01001 = 133Mhz 8K/16K rows
463          *         01010 = 166Mhz 8K/16K rows
464          * [19:13] Reserved
465          * [22:20] Twcl (Write CAS Latency)
466          *         000 = 1 Mem clock after CAS# (Unbuffered Dimms)
467          *         001 = 2 Mem clocks after CAS# (Registered Dimms)
468          * [31:23] Reserved
469          */
470 #if MEMORY_1024MB
471         PCI_ADDR(0, 0x18, 2, 0x8c), 0xff8fe08e, 0x00000930,
472 #endif
473 #if MEMORY_512MB
474         PCI_ADDR(0, 0x18, 2, 0x8c), 0xff8fe08e, 0x00000130,
475 #endif
476
477         /* DRAM Config Low Register
478          * F2:0x90
479          * [ 0: 0] DLL Disable
480          *         0 = Enabled
481          *         1 = Disabled
482          * [ 1: 1] D_DRV
483          *         0 = Normal Drive
484          *         1 = Weak Drive
485          * [ 2: 2] QFC_EN
486          *         0 = Disabled
487          *         1 = Enabled
488          * [ 3: 3] Disable DQS Hystersis  (FIXME handle this one carefully)
489          *         0 = Enable DQS input filter 
490          *         1 = Disable DQS input filtering 
491          * [ 7: 4] Reserved
492          * [ 8: 8] DRAM_Init
493          *         0 = Initialization done or not yet started.
494          *         1 = Initiate DRAM intialization sequence
495          * [ 9: 9] SO-Dimm Enable
496          *         0 = Do nothing
497          *         1 = SO-Dimms present
498          * [10:10] DramEnable
499          *         0 = DRAM not enabled
500          *         1 = DRAM initialized and enabled
501          * [11:11] Memory Clear Status
502          *         0 = Memory Clear function has not completed
503          *         1 = Memory Clear function has completed
504          * [12:12] Exit Self-Refresh
505          *         0 = Exit from self-refresh done or not yet started
506          *         1 = DRAM exiting from self refresh
507          * [13:13] Self-Refresh Status
508          *         0 = Normal Operation
509          *         1 = Self-refresh mode active
510          * [15:14] Read/Write Queue Bypass Count
511          *         00 = 2
512          *         01 = 4
513          *         10 = 8
514          *         11 = 16
515          * [16:16] 128-bit/64-Bit
516          *         0 = 64bit Interface to DRAM
517          *         1 = 128bit Interface to DRAM
518          * [17:17] DIMM ECC Enable
519          *         0 = Some DIMMs do not have ECC
520          *         1 = ALL DIMMS have ECC bits
521          * [18:18] UnBuffered DIMMs
522          *         0 = Buffered DIMMS
523          *         1 = Unbuffered DIMMS
524          * [19:19] Enable 32-Byte Granularity
525          *         0 = Optimize for 64byte bursts
526          *         1 = Optimize for 32byte bursts
527          * [20:20] DIMM 0 is x4
528          * [21:21] DIMM 1 is x4
529          * [22:22] DIMM 2 is x4
530          * [23:23] DIMM 3 is x4
531          *         0 = DIMM is not x4
532          *         1 = x4 DIMM present
533          * [24:24] Disable DRAM Receivers
534          *         0 = Receivers enabled
535          *         1 = Receivers disabled
536          * [27:25] Bypass Max
537          *         000 = Arbiters chois is always respected
538          *         001 = Oldest entry in DCQ can be bypassed 1 time
539          *         010 = Oldest entry in DCQ can be bypassed 2 times
540          *         011 = Oldest entry in DCQ can be bypassed 3 times
541          *         100 = Oldest entry in DCQ can be bypassed 4 times
542          *         101 = Oldest entry in DCQ can be bypassed 5 times
543          *         110 = Oldest entry in DCQ can be bypassed 6 times
544          *         111 = Oldest entry in DCQ can be bypassed 7 times
545          * [31:28] Reserved
546          */
547         PCI_ADDR(0, 0x18, 2, 0x90), 0xf0000000, 
548         (4 << 25)|(0 << 24)| 
549         (0 << 23)|(0 << 22)|(0 << 21)|(0 << 20)| 
550         (1 << 19)|(1 << 18)|(0 << 17)|(0 << 16)| 
551         (2 << 14)|(0 << 13)|(0 << 12)| 
552         (0 << 11)|(0 << 10)|(0 << 9)|(0 << 8)| 
553         (0 << 3) |(0 << 1) |(0 << 0),
554         /* DRAM Config High Register
555          * F2:0x94
556          * [ 0: 3] Maximum Asynchronous Latency
557          *         0000 = 0 ns
558          *         ...
559          *         1111 = 15 ns
560          * [ 7: 4] Reserved
561          * [11: 8] Read Preamble
562          *         0000 = 2.0 ns
563          *         0001 = 2.5 ns
564          *         0010 = 3.0 ns
565          *         0011 = 3.5 ns
566          *         0100 = 4.0 ns
567          *         0101 = 4.5 ns
568          *         0110 = 5.0 ns
569          *         0111 = 5.5 ns
570          *         1000 = 6.0 ns
571          *         1001 = 6.5 ns
572          *         1010 = 7.0 ns
573          *         1011 = 7.5 ns
574          *         1100 = 8.0 ns
575          *         1101 = 8.5 ns
576          *         1110 = 9.0 ns
577          *         1111 = 9.5 ns
578          * [15:12] Reserved
579          * [18:16] Idle Cycle Limit
580          *         000 = 0 cycles
581          *         001 = 4 cycles
582          *         010 = 8 cycles
583          *         011 = 16 cycles
584          *         100 = 32 cycles
585          *         101 = 64 cycles
586          *         110 = 128 cycles
587          *         111 = 256 cycles
588          * [19:19] Dynamic Idle Cycle Center Enable
589          *         0 = Use Idle Cycle Limit
590          *         1 = Generate a dynamic Idle cycle limit
591          * [22:20] DRAM MEMCLK Frequency
592          *         000 = 100Mhz
593          *         001 = reserved
594          *         010 = 133Mhz
595          *         011 = reserved
596          *         100 = reserved
597          *         101 = 166Mhz
598          *         110 = reserved
599          *         111 = reserved
600          * [24:23] Reserved
601          * [25:25] Memory Clock Ratio Valid (FIXME carefully enable memclk)
602          *         0 = Disable MemClks
603          *         1 = Enable MemClks
604          * [26:26] Memory Clock 0 Enable
605          *         0 = Disabled
606          *         1 = Enabled
607          * [27:27] Memory Clock 1 Enable
608          *         0 = Disabled
609          *         1 = Enabled
610          * [28:28] Memory Clock 2 Enable
611          *         0 = Disabled
612          *         1 = Enabled
613          * [29:29] Memory Clock 3 Enable
614          *         0 = Disabled
615          *         1 = Enabled
616          * [31:30] Reserved
617          */
618 #if MEMORY_1024MB
619         PCI_ADDR(0, 0x18, 2, 0x94), 0xc180f0f0, 0x0e2b0a05,
620 #endif
621 #if MEMORY_512MB
622         PCI_ADDR(0, 0x18, 2, 0x94), 0xc180f0f0, 0x0e2b0a06,
623 #endif
624         /* DRAM Delay Line Register
625          * F2:0x98
626          * Adjust the skew of the input DQS strobe relative to DATA
627          * [15: 0] Reserved
628          * [23:16] Delay Line Adjust
629          *         Adjusts the DLL derived PDL delay by one or more delay stages
630          *         in either the faster or slower direction.
631          * [24:24} Adjust Slower
632          *         0 = Do Nothing
633          *         1 = Adj is used to increase the PDL delay
634          * [25:25] Adjust Faster
635          *         0 = Do Nothing
636          *         1 = Adj is used to decrease the PDL delay
637          * [31:26] Reserved
638          */
639         PCI_ADDR(0, 0x18, 2, 0x98), 0xfc00ffff, 0x00000000,
640         /* DRAM Scrub Control Register
641          * F3:0x58
642          * [ 4: 0] DRAM Scrube Rate
643          * [ 7: 5] reserved
644          * [12: 8] L2 Scrub Rate
645          * [15:13] reserved
646          * [20:16] Dcache Scrub
647          * [31:21] reserved
648          *         Scrub Rates
649          *         00000 = Do not scrub
650          *         00001 =  40.00 ns
651          *         00010 =  80.00 ns
652          *         00011 = 160.00 ns
653          *         00100 = 320.00 ns
654          *         00101 = 640.00 ns
655          *         00110 =   1.28 us
656          *         00111 =   2.56 us
657          *         01000 =   5.12 us
658          *         01001 =  10.20 us
659          *         01011 =  41.00 us
660          *         01100 =  81.90 us
661          *         01101 = 163.80 us
662          *         01110 = 327.70 us
663          *         01111 = 655.40 us
664          *         10000 =   1.31 ms
665          *         10001 =   2.62 ms
666          *         10010 =   5.24 ms
667          *         10011 =  10.49 ms
668          *         10100 =  20.97 ms
669          *         10101 =  42.00 ms
670          *         10110 =  84.00 ms
671          *         All Others = Reserved
672          */
673         PCI_ADDR(0, 0x18, 3, 0x58), 0xffe0e0e0, 0x00000000,
674         /* DRAM Scrub Address Low Register
675          * F3:0x5C
676          * [ 0: 0] DRAM Scrubber Redirect Enable
677          *         0 = Do nothing
678          *         1 = Scrubber Corrects errors found in normal operation
679          * [ 5: 1] Reserved
680          * [31: 6] DRAM Scrub Address 31-6
681          */
682         PCI_ADDR(0, 0x18, 3, 0x5C), 0x0000003e, 0x00000000,
683         /* DRAM Scrub Address High Register
684          * F3:0x60
685          * [ 7: 0] DRAM Scrubb Address 39-32
686          * [31: 8] Reserved
687          */
688         PCI_ADDR(0, 0x18, 3, 0x60), 0xffffff00, 0x00000000,
689         };
690         int i;
691         int max;
692         print_debug("setting up CPU0 northbridge registers\r\n");
693         max = sizeof(register_values)/sizeof(register_values[0]);
694         for(i = 0; i < max; i += 3) {
695                 device_t dev;
696                 unsigned where;
697                 unsigned long reg;
698 #if 0
699                 print_debug_hex32(register_values[i]);
700                 print_debug(" <-");
701                 print_debug_hex32(register_values[i+2]);
702                 print_debug("\r\n");
703 #endif
704                 dev = register_values[i] & ~0xff;
705                 where = register_values[i] & 0xff;
706                 reg = pci_read_config32(dev, where);
707                 reg &= register_values[i+1];
708                 reg |= register_values[i+2];
709                 pci_write_config32(dev, where, reg);
710 #if 0
711
712                 reg = pci_read_config32(register_values[i]);
713                 reg &= register_values[i+1];
714                 reg |= register_values[i+2];
715                 pci_write_config32(register_values[i], reg);
716 #endif
717         }
718         print_debug("done.\r\n");
719 }
720
721 #define DRAM_CONFIG_LOW 0x90
722 #define  DCL_DLL_Disable   (1<<0)
723 #define  DCL_D_DRV         (1<<1)
724 #define  DCL_QFC_EN        (1<<2)
725 #define  DCL_DisDqsHys     (1<<3)
726 #define  DCL_DramInit      (1<<8)
727 #define  DCL_DramEnable    (1<<10)
728 #define  DCL_MemClrStatus  (1<<11)
729 #define  DCL_DimmEcEn      (1<<17)
730
731 #define NODE_ID         0x60
732 #define HT_INIT_CONTROL 0x6c
733
734 #define HTIC_ColdR_Detect  (1<<4)
735 #define HTIC_BIOSR_Detect  (1<<5)
736 #define HTIC_INIT_Detect   (1<<6)
737
738 static void sdram_set_spd_registers(void) 
739 {
740         unsigned long dcl;
741         dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
742         /* Until I know what is going on disable ECC support */
743         dcl &= ~DCL_DimmEcEn;
744         pci_write_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW, dcl);
745 }
746
747 #define TIMEOUT_LOOPS 300000
748 static void sdram_enable(void)
749 {
750         unsigned long dcl;
751
752         /* Toggle DisDqsHys to get it working */
753         dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
754         print_debug("dcl: ");
755         print_debug_hex32(dcl);
756         print_debug("\r\n");
757         dcl |= DCL_DisDqsHys;
758         pci_write_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW, dcl);
759         dcl &= ~DCL_DisDqsHys;
760         dcl &= ~DCL_DLL_Disable;
761         dcl &= ~DCL_D_DRV;
762         dcl &= ~DCL_QFC_EN;
763         dcl |= DCL_DramInit;
764         pci_write_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW, dcl);
765         
766         print_debug("Initializing memory: ");
767         int loops = 0;
768         do {
769                 dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
770                 loops += 1;
771                 if ((loops & 1023) == 0) {
772                         print_debug(".");
773                 }
774         } while(((dcl & DCL_DramInit) != 0) && (loops < TIMEOUT_LOOPS));
775         if (loops >= TIMEOUT_LOOPS) {
776                 print_debug(" failed\r\n");
777         } else {
778                 print_debug(" done\r\n");
779         }
780
781 #if 0
782         print_debug("Clearing memory: ");
783         loops = 0;
784         do {
785                 dcl = pci_read_config32(PCI_DEV(0, 0x18, 2), DRAM_CONFIG_LOW);
786                 loops += 1;
787                 if ((loops & 1023) == 0) {
788                         print_debug(" ");
789                         print_debug_hex32(loops);
790                 }
791         } while(((dcl & DCL_MemClrStatus) == 0) && (loops < TIMEOUT_LOOPS));
792         if (loops >= TIMEOUT_LOOPS) {
793                 print_debug("failed\r\n");
794         } else {
795                 print_debug("done\r\n");
796         }
797 #endif
798 }
799
800 static void sdram_first_normal_reference(void) {}
801 static void sdram_enable_refresh(void) {}
802 static void sdram_special_finishup(void) {}
803