- Initial checkin of the freebios2 tree
[coreboot.git] / src / mainboard / amd / solo / auto.c
1 #define ASSEMBLY 1
2 #include "arch/romcc_io.h"
3 #include "pc80/serial.c"
4 #include "arch/i386/lib/console.c"
5 #include "ram/ramtest.c"
6
7
8 static void sdram_set_registers(void)
9 {
10         static const unsigned int register_values[] = {
11         /* Routing Table Node i 
12          * F0:0x40 i = 0, 
13          * F0:0x44 i = 1,
14          * F0:0x48 i = 2, 
15          * F0:0x4c i = 3,
16          * F0:0x50 i = 4, 
17          * F0:0x54 i = 5,
18          * F0:0x58 i = 6, 
19          * F0:0x5c i = 7
20          * [ 0: 3] Request Route
21          *     [0] Route to this node
22          *     [1] Route to Link 0
23          *     [2] Route to Link 1
24          *     [3] Route to Link 2
25          * [11: 8] Response Route
26          *     [0] Route to this node
27          *     [1] Route to Link 0
28          *     [2] Route to Link 1
29          *     [3] Route to Link 2
30          * [19:16] Broadcast route
31          *     [0] Route to this node
32          *     [1] Route to Link 0
33          *     [2] Route to Link 1
34          *     [3] Route to Link 2
35          */
36         0xc040, 0xfff0f0f0, 0x00010101,
37         0xc044, 0xfff0f0f0, 0x00010101,
38         0xc048, 0xfff0f0f0, 0x00010101,
39         0xc04c, 0xfff0f0f0, 0x00010101,
40         0xc050, 0xfff0f0f0, 0x00010101,
41         0xc054, 0xfff0f0f0, 0x00010101,
42         0xc058, 0xfff0f0f0, 0x00010101,
43         0xc05c, 0xfff0f0f0, 0x00010101,
44
45         /* Hypetransport Transaction Control Register 
46          * F0:0x68
47          * [ 0: 0] Disable read byte probe
48          *         0 = Probes issues
49          *         1 = Probes not issued
50          * [ 1: 1] Disable Read Doubleword probe
51          *         0 = Probes issued
52          *         1 = Probes not issued
53          * [ 2: 2] Disable write byte probes
54          *         0 = Probes issued
55          *         1 = Probes not issued
56          * [ 3: 3] Disalbe Write Doubleword Probes
57          *         0 = Probes issued
58          *         1 = Probes not issued.
59          * [ 4: 4] Disable Memroy Controller Target Start
60          *         0 = TgtStart packets are generated
61          *         1 = TgtStart packets are not generated.
62          * [ 5: 5] CPU1 Enable
63          *         0 = Second CPU disabled or not present
64          *         1 = Second CPU enabled.
65          * [ 6: 6] CPU Request PassPW
66          *         0 = CPU requests do not pass posted writes
67          *         1 = CPU requests pass posted writes.
68          * [ 7: 7] CPU read Respons PassPW
69          *         0 = CPU Responses do not pass posted writes
70          *         1 = CPU responses pass posted writes.
71          * [ 8: 8] Disable Probe Memory Cancel
72          *         0 = Probes may generate MemCancels
73          *         1 = Probes may not generate MemCancels
74          * [ 9: 9] Disable Remote Probe Memory Cancel.
75          *         0 = Probes hitting dirty blocks generate memory cancel packets
76          *         1 = Only probed caches on the same node as the memory controller
77          *              generate cancel packets.
78          * [10:10] Disable Fill Probe
79          *         0 = Probes issued for cache fills
80          *         1 = Probes not issued for cache fills.
81          * [11:11] Response PassPw
82          *         0 = Downstream response PassPW based on original request
83          *         1 = Downstream response PassPW set to 1
84          * [12:12] Change ISOC to Ordered
85          *         0 = Bit 1 of coherent HT RdSz/WrSz command used for iosynchronous prioritization
86          *         1 = Bit 1 of coherent HT RdSz/WrSz command used for ordering.
87          * [14:13] Buffer Release Priority select 
88          *         00 = 64
89          *         01 = 16
90          *         10 = 8
91          *         11 = 2
92          * [15:15] Limit Coherent HT Configuration Space Range
93          *         0 = No coherent HT configuration space restrictions
94          *         1 = Limit coherent HT configuration space based on node count
95          * [16:16] Local Interrupt Conversion Enable.
96          *         0 = ExtInt/NMI interrups unaffected.
97          *         1 = ExtInt/NMI broadcat interrupts converted to LINT0/1
98          * [17:17] APIC Extended Broadcast Enable.
99          *         0 = APIC broadcast is 0F
100          *         1 = APIC broadcast is FF
101          * [18:18] APIC Extended ID Enable
102          *         0 = APIC ID is 4 bits.
103          *         1 = APIC ID is 8 bits.
104          * [19:19] APIC Extended Spurious Vector Enable
105          *         0 = Lower 4 bits of spurious vector are read-only 1111
106          *         1 = Lower 4 bits of spurious vecotr are writeable.
107          * [20:20] Sequence ID Source Node Enable
108          *         0 = Normal operation
109          *         1 = Keep SeqID on routed packets for debugging.
110          * [22:21] Downstream non-posted request limit
111          *         00 = No limit
112          *         01 = Limited to 1
113          *         10 = Limited to 4
114          *         11 = Limited to 8
115          * [23:23] RESERVED
116          * [25:24] Medium-Priority Bypass Count
117          *         - Maximum # of times a medium priority access can pass a low
118          *           priority access before Medium-Priority mode is disabled for one access.
119          * [27:26] High-Priority Bypass Count
120          *         - Maximum # of times a high prioirty access can pass a medium or low
121          *           priority access before High-prioirty mode is disabled for one access.
122          * [28:28] Enable High Priority CPU Reads
123          *         0 = Cpu reads are medium prioirty
124          *         1 = Cpu reads are high prioirty
125          * [29:29] Disable Low Priority Writes
126          *         0 = Non-isochronous writes are low priority
127          *         1 = Non-isochronous writes are medium prioirty
128          * [30:30] Disable High Priority Isochronous writes
129          *         0 = Isochronous writes are high priority
130          *         1 = Isochronous writes are medium priority
131          * [31:31] Disable Medium Priority Isochronous writes
132          *         0 = Isochronous writes are medium are high
133          *         1 = With bit 30 set makes Isochrouns writes low priority.
134          */
135         0xc068, 0x00800000, 0x0f00840f,
136         /* HT Initialization Control Register
137          * F0:0x68
138          * [ 0: 0] Routing Table Disable
139          *         0 = Packets are routed according to routing tables
140          *         1 = Packets are routed according to the default link field
141          * [ 1: 1] Request Disable (BSP should clear this)
142          *         0 = Request packets may be generated
143          *         1 = Request packets may not be generated.
144          * [ 3: 2] Default Link (Read-only)
145          *         00 = LDT0
146          *         01 = LDT1
147          *         10 = LDT2
148          *         11 = CPU on same node
149          * [ 4: 4] Cold Reset
150          *         - Scratch bit cleared by a cold reset
151          * [ 5: 5] BIOS Reset Detect
152          *         - Scratch bit cleared by a cold reset
153          * [ 6: 6] INIT Detect
154          *         - Scratch bit cleared by a warm or cold reset not by an INIT
155          *
156          */
157         0xc06C, 0xffffff8c, 0x00000000,
158         /* LDTi Capabilities Registers
159          * F0:0x80 i = 0,
160          * F0:0xA0 i = 1,
161          * F0:0xC0 i = 2,
162          */
163         /* LDTi Link Control Registrs
164          * F0:0x84 i = 0,
165          * F0:0xA4 i = 1,
166          * F0:0xC4 i = 2,
167          * [ 1: 1] CRC Flood Enable
168          *         0 = Do not generate sync packets on CRC error
169          *         1 = Generate sync packets on CRC error
170          * [ 2: 2] CRC Start Test (Read-Only)
171          * [ 3: 3] CRC Force Frame Error
172          *         0 = Do not generate bad CRC
173          *         1 = Generate bad CRC
174          * [ 4: 4] Link Failure
175          *         0 = No link failure detected
176          *         1 = Link failure detected
177          * [ 5: 5] Initialization Complete
178          *         0 = Initialization not complete
179          *         1 = Initialization complete
180          * [ 6: 6] Receiver off
181          *         0 = Recevier on
182          *         1 = Receiver off
183          * [ 7: 7] Transmitter Off
184          *         0 = Transmitter on
185          *         1 = Transmitter off
186          * [ 9: 8] CRC_Error
187          *         00 = No error
188          *         [0] = 1 Error on byte lane 0
189          *         [1] = 1 Error on byte lane 1
190          * [12:12] Isochrnous Enable  (Read-Only)
191          * [13:13] HT Stop Tristate Enable
192          *         0 = Driven during an LDTSTOP_L
193          *         1 = Tristated during and LDTSTOP_L
194          * [14:14] Extended CTL Time 
195          *         0 = CTL is asserted for 16 bit times during link initialization
196          *         1 = CTL is asserted for 50us during link initialization
197          * [18:16] Max Link Width In (Read-Only?)
198          *         000 = 8 bit link
199          *         001 = 16bit link
200          * [19:19] Doubleword Flow Control in (Read-Only)
201          *         0 = This link does not support doubleword flow control
202          *         1 = This link supports doubleword flow control
203          * [22:20] Max Link Width Out (Read-Only?)
204          *         000 = 8 bit link
205          *         001 = 16bit link
206          * [23:23] Doubleworld Flow Control out (Read-Only)
207          *         0 = This link does not support doubleword flow control
208          *         1 = This link supports doubleworkd flow control
209          * [26:24] Link Width In
210          *         000 = Use 8 bits
211          *         001 = Use 16 bits
212          *         010 = reserved
213          *         011 = Use 32 bits
214          *         100 = Use 2 bits
215          *         101 = Use 4 bits
216          *         110 = reserved
217          *         111 = Link physically not connected
218          * [27:27] Doubleword Flow Control In Enable
219          *         0 = Doubleword flow control disabled
220          *         1 = Doubleword flow control enabled (Not currently supported)
221          * [30:28] Link Width Out
222          *         000 = Use 8 bits
223          *         001 = Use 16 bits
224          *         010 = reserved
225          *         011 = Use 32 bits
226          *         100 = Use 2 bits
227          *         101 = Use 4 bits
228          *         110 = reserved
229          *         111 = Link physically not connected
230          * [31:31] Doubleworld Flow Control Out Enable
231          *         0 = Doubleworld flow control disabled
232          *         1 = Doubleword flow control enabled (Not currently supported)
233          */
234         0xc084, 0x00009c05, 0x11110020,
235         /* LDTi Frequency/Revision Registers
236          * F0:0x88 i = 0,
237          * F0:0xA8 i = 1,
238          * F0:0xC8 i = 2,
239          * [ 4: 0] Minor Revision
240          *         Contains the HT Minor revision
241          * [ 7: 5] Major Revision
242          *         Contains the HT Major revision
243          * [11: 8] Link Frequency  (Takes effect the next time the link is reconnected)
244          *         0000 = 200Mhz
245          *         0001 = reserved
246          *         0010 = 400Mhz
247          *         0011 = reserved
248          *         0100 = 600Mhz
249          *         0101 = 800Mhz
250          *         0110 = 1000Mhz
251          *         0111 = reserved
252          *         1000 = reserved
253          *         1001 = reserved
254          *         1010 = reserved
255          *         1011 = reserved
256          *         1100 = reserved
257          *         1101 = reserved
258          *         1110 = reserved
259          *         1111 = 100 Mhz
260          * [15:12] Error (Not currently Implemented)
261          * [31:16] Indicates the frequency capabilities of the link
262          *         [16] = 1 encoding 0000 of freq supported
263          *         [17] = 1 encoding 0001 of freq supported
264          *         [18] = 1 encoding 0010 of freq supported
265          *         [19] = 1 encoding 0011 of freq supported
266          *         [20] = 1 encoding 0100 of freq supported
267          *         [21] = 1 encoding 0101 of freq supported
268          *         [22] = 1 encoding 0110 of freq supported
269          *         [23] = 1 encoding 0111 of freq supported
270          *         [24] = 1 encoding 1000 of freq supported
271          *         [25] = 1 encoding 1001 of freq supported
272          *         [26] = 1 encoding 1010 of freq supported
273          *         [27] = 1 encoding 1011 of freq supported
274          *         [28] = 1 encoding 1100 of freq supported
275          *         [29] = 1 encoding 1101 of freq supported
276          *         [30] = 1 encoding 1110 of freq supported
277          *         [31] = 1 encoding 1111 of freq supported
278          */
279         0xC088, 0xfffff0ff, 0x00000200,
280         /* LDTi Feature Capability
281          * F0:0x8C i = 0,
282          * F0:0xAC i = 1,
283          * F0:0xCC i = 2,
284          */
285         /* LDTi Buffer Count Registers
286          * F0:0x90 i = 0,
287          * F0:0xB0 i = 1,
288          * F0:0xD0 i = 2,
289          */
290         /* LDTi Bus Number Registers
291          * F0:0x94 i = 0,
292          * F0:0xB4 i = 1,
293          * F0:0xD4 i = 2,
294          * For NonCoherent HT specifies the bus number downstream (behind the host bridge)
295          * [ 0: 7] Primary Bus Number
296          * [15: 8] Secondary Bus Number
297          * [23:15] Subordiante Bus Number
298          * [31:24] reserved
299          */
300         0xC094, 0xff000000, 0x00ff0000,
301         /* LDTi Type Registers
302          * F0:0x98 i = 0,
303          * F0:0xB8 i = 1,
304          * F0:0xD8 i = 2,
305          */
306         /* Careful set limit registers before base registers which contain the enables */
307         /* DRAM Limit i Registers
308          * F1:0x44 i = 0
309          * F1:0x4C i = 1
310          * F1:0x54 i = 2
311          * F1:0x5C i = 3
312          * F1:0x64 i = 4
313          * F1:0x6C i = 5
314          * F1:0x74 i = 6
315          * F1:0x7C i = 7
316          * [ 2: 0] Destination Node ID
317          *         000 = Node 0
318          *         001 = Node 1
319          *         010 = Node 2
320          *         011 = Node 3
321          *         100 = Node 4
322          *         101 = Node 5
323          *         110 = Node 6
324          *         111 = Node 7
325          * [ 7: 3] Reserved
326          * [10: 8] Interleave select
327          *         specifies the values of A[14:12] to use with interleave enable.
328          * [15:11] Reserved
329          * [31:16] DRAM Limit Address i Bits 39-24
330          *         This field defines the upper address bits of a 40 bit  address
331          *         that define the end of the DRAM region.
332          */
333         0xC144, 0x0000f8f8, 0x003f0000,
334         0xC148, 0x0000f8f8, 0x00000001,
335         0xC154, 0x0000f8f8, 0x00000002,
336         0xC158, 0x0000f8f8, 0x00000003,
337         0xC164, 0x0000f8f8, 0x00000004,
338         0xC168, 0x0000f8f8, 0x00000005,
339         0xC174, 0x0000f8f8, 0x00000006,
340         0xC178, 0x0000f8f8, 0x00000007,
341         /* DRAM Base i Registers
342          * F1:0x40 i = 0
343          * F1:0x48 i = 1
344          * F1:0x50 i = 2
345          * F1:0x58 i = 3
346          * F1:0x60 i = 4
347          * F1:0x68 i = 5
348          * F1:0x70 i = 6
349          * F1:0x78 i = 7
350          * [ 0: 0] Read Enable
351          *         0 = Reads Disabled
352          *         1 = Reads Enabled
353          * [ 1: 1] Write Enable
354          *         0 = Writes Disabled
355          *         1 = Writes Enabled
356          * [ 7: 2] Reserved
357          * [10: 8] Interleave Enable
358          *         000 = No interleave
359          *         001 = Interleave on A[12] (2 nodes)
360          *         010 = reserved
361          *         011 = Interleave on A[12] and A[14] (4 nodes)
362          *         100 = reserved
363          *         101 = reserved
364          *         110 = reserved
365          *         111 = Interleve on A[12] and A[13] and A[14] (8 nodes)
366          * [15:11] Reserved
367          * [13:16] DRAM Base Address i Bits 39-24
368          *         This field defines the upper address bits of a 40-bit address
369          *         that define the start of the DRAM region.
370          */
371         0xC140, 0x0000f8fc, 0x00000003,
372         0xC148, 0x0000f8fc, 0x00400000,
373         0xC150, 0x0000f8fc, 0x00400000,
374         0xC158, 0x0000f8fc, 0x00400000,
375         0xC160, 0x0000f8fc, 0x00400000,
376         0xC168, 0x0000f8fc, 0x00400000,
377         0xC170, 0x0000f8fc, 0x00400000,
378         0xC178, 0x0000f8fc, 0x00400000,
379
380         /* Memory-Mapped I/O Limit i Registers
381          * F1:0x84 i = 0
382          * F1:0x8C i = 1
383          * F1:0x94 i = 2
384          * F1:0x9C i = 3
385          * F1:0xA4 i = 4
386          * F1:0xAC i = 5
387          * F1:0xB4 i = 6
388          * F1:0xBC i = 7
389          * [ 2: 0] Destination Node ID
390          *         000 = Node 0
391          *         001 = Node 1
392          *         010 = Node 2
393          *         011 = Node 3
394          *         100 = Node 4
395          *         101 = Node 5
396          *         110 = Node 6
397          *         111 = Node 7
398          * [ 3: 3] Reserved
399          * [ 5: 4] Destination Link ID
400          *         00 = Link 0
401          *         01 = Link 1
402          *         10 = Link 2
403          *         11 = Reserved
404          * [ 6: 6] Reserved
405          * [ 7: 7] Non-Posted
406          *         0 = CPU writes may be posted
407          *         1 = CPU writes must be non-posted
408          * [31: 8] Memory-Mapped I/O Limit Address i (39-16)
409          *         This field defines the upp adddress bits of a 40-bit address that
410          *         defines the end of a memory-mapped I/O region n
411          */
412         0xC184, 0x00000048, 0x00e1ff00,
413         0xC18C, 0x00000048, 0x00dfff00,
414         0xC194, 0x00000048, 0x00e3ff00,
415         0xC19C, 0x00000048, 0x00000000,
416         0xC1A4, 0x00000048, 0x00000000,
417         0xC1AC, 0x00000048, 0x00000000,
418         0xC1B4, 0x00000048, 0x00000b00,
419
420
421         /* Memory-Mapped I/O Base i Registers
422          * F1:0x80 i = 0
423          * F1:0x88 i = 1
424          * F1:0x90 i = 2
425          * F1:0x98 i = 3
426          * F1:0xA0 i = 4
427          * F1:0xA8 i = 5
428          * F1:0xB0 i = 6
429          * F1:0xB8 i = 7
430          * [ 0: 0] Read Enable
431          *         0 = Reads disabled
432          *         1 = Reads Enabled
433          * [ 1: 1] Write Enable
434          *         0 = Writes disabled
435          *         1 = Writes Enabled
436          * [ 2: 2] Cpu Disable
437          *         0 = Cpu can use this I/O range
438          *         1 = Cpu requests do not use this I/O range
439          * [ 3: 3] Lock
440          *         0 = base/limit registers i are read/write
441          *         1 = base/limit registers i are read-only
442          * [ 7: 4] Reserved
443          * [31: 8] Memory-Mapped I/O Base Address i (39-16)
444          *         This field defines the upper address bits of a 40bit address 
445          *         that defines the start of memory-mapped I/O region i
446          */
447         0xC1BC, 0x00000048, 0x00fe0b00,
448         0xC180, 0x000000f0, 0x00e00003,
449         0xC188, 0x000000f0, 0x00d80003,
450         0xC190, 0x000000f0, 0x00e20003,
451         0xC198, 0x000000f0, 0x00000000,
452         0xC1A0, 0x000000f0, 0x00000000,
453         0xC1A8, 0x000000f0, 0x00000000,
454         0xC1B0, 0x000000f0, 0x0000a003,
455         0xC1B8, 0x000000f0, 0x00400003,
456
457         /* PCI I/O Limit i Registers
458          * F1:0xC4 i = 0
459          * F1:0xCC i = 1
460          * F1:0xD4 i = 2
461          * F1:0xDC i = 3
462          * [ 2: 0] Destination Node ID
463          *         000 = Node 0
464          *         001 = Node 1
465          *         010 = Node 2
466          *         011 = Node 3
467          *         100 = Node 4
468          *         101 = Node 5
469          *         110 = Node 6
470          *         111 = Node 7
471          * [ 3: 3] Reserved
472          * [ 5: 4] Destination Link ID
473          *         00 = Link 0
474          *         01 = Link 1
475          *         10 = Link 2
476          *         11 = reserved
477          * [11: 6] Reserved
478          * [24:12] PCI I/O Limit Address i
479          *         This field defines the end of PCI I/O region n
480          * [31:25] Reserved
481          */
482         0xC1C4, 0xFE000FC8, 0x0000d000,
483         0xC1CC, 0xFE000FC8, 0x000ff000,
484         0xC1D4, 0xFE000FC8, 0x00000000,
485         0xC1DC, 0xFE000FC8, 0x00000000,
486
487         /* PCI I/O Base i Registers
488          * F1:0xC0 i = 0
489          * F1:0xC8 i = 1
490          * F1:0xD0 i = 2
491          * F1:0xD8 i = 3
492          * [ 0: 0] Read Enable
493          *         0 = Reads Disabled
494          *         1 = Reads Enabled
495          * [ 1: 1] Write Enable
496          *         0 = Writes Disabled
497          *         1 = Writes Enabled
498          * [ 3: 2] Reserved
499          * [ 4: 4] VGA Enable
500          *         0 = VGA matches Disabled
501          *         1 = matches all address < 64K and where A[9:0] is in the 
502          *             range 3B0-3BB or 3C0-3DF independen of the base & limit registers
503          * [ 5: 5] ISA Enable
504          *         0 = ISA matches Disabled
505          *         1 = Blocks address < 64K and in the last 768 bytes of eack 1K block
506          *             from matching agains this base/limit pair
507          * [11: 6] Reserved
508          * [24:12] PCI I/O Base i
509          *         This field defines the start of PCI I/O region n 
510          * [31:25] Reserved
511          */
512         0xC1C0, 0xFE000FCC, 0x0000d003,
513         0xC1C8, 0xFE000FCC, 0x00001013,
514         0xC1D0, 0xFE000FCC, 0x00000000,
515         0xC1D8, 0xFE000FCC, 0x00000000,
516
517         /* Config Base and Limit i Registers
518          * F1:0xE0 i = 0
519          * F1:0xE4 i = 1
520          * F1:0xE8 i = 2
521          * F1:0xEC i = 3
522          * [ 0: 0] Read Enable
523          *         0 = Reads Disabled
524          *         1 = Reads Enabled
525          * [ 1: 1] Write Enable
526          *         0 = Writes Disabled
527          *         1 = Writes Enabled
528          * [ 2: 2] Device Number Compare Enable
529          *         0 = The ranges are based on bus number
530          *         1 = The ranges are ranges of devices on bus 0
531          * [ 3: 3] Reserved
532          * [ 6: 4] Destination Node
533          *         000 = Node 0
534          *         001 = Node 1
535          *         010 = Node 2
536          *         011 = Node 3
537          *         100 = Node 4
538          *         101 = Node 5
539          *         110 = Node 6
540          *         111 = Node 7
541          * [ 7: 7] Reserved
542          * [ 9: 8] Destination Link
543          *         00 = Link 0
544          *         01 = Link 1
545          *         10 = Link 2
546          *         11 - Reserved
547          * [15:10] Reserved
548          * [23:16] Bus Number Base i
549          *         This field defines the lowest bus number in configuration region i
550          * [31:24] Bus Number Limit i
551          *         This field defines the highest bus number in configuration regin i
552          */
553         0xC1E0, 0x0000FC88, 0xff000003,
554         0xC1E4, 0x0000FC88, 0x00000000,
555         0xC1E8, 0x0000FC88, 0x00000000,
556         0xC1EC, 0x0000FC88, 0x00000000,
557
558         /* DRAM CS Base Address i Registers
559          * F2:0x40 i = 0
560          * F2:0x44 i = 1
561          * F2:0x48 i = 2
562          * F2:0x4C i = 3
563          * F2:0x50 i = 4
564          * F2:0x54 i = 5
565          * F2:0x58 i = 6
566          * F2:0x5C i = 7
567          * [ 0: 0] Chip-Select Bank Enable
568          *         0 = Bank Disabled
569          *         1 = Bank Enabled
570          * [ 8: 1] Reserved
571          * [15: 9] Base Address (19-13)
572          *         An optimization used when all DIMM are the same size...
573          * [20:16] Reserved
574          * [31:21] Base Address (35-25)
575          *         This field defines the top 11 addresses bit of a 40-bit
576          *         address that define the memory address space.  These
577          *         bits decode 32-MByte blocks of memory.
578          */
579         0xC240, 0x001f01fe, 0x00000001,
580         0xC244, 0x001f01fe, 0x01000001,
581         0xC248, 0x001f01fe, 0x02000001,
582         0xC24C, 0x001f01fe, 0x03000001,
583         0xC250, 0x001f01fe, 0x00000000,
584         0xC254, 0x001f01fe, 0x00000000,
585         0xC258, 0x001f01fe, 0x00000000,
586         0xC25C, 0x001f01fe, 0x00000000,
587         /* DRAM CS Mask Address i Registers
588          * F2:0x60 i = 0
589          * F2:0x64 i = 1
590          * F2:0x68 i = 2
591          * F2:0x6C i = 3
592          * F2:0x70 i = 4
593          * F2:0x74 i = 5
594          * F2:0x78 i = 6
595          * F2:0x7C i = 7
596          * Select bits to exclude from comparison with the DRAM Base address register.
597          * [ 8: 0] Reserved
598          * [15: 9] Address Mask (19-13)
599          *         Address to be excluded from the optimized case
600          * [20:16] Reserved
601          * [29:21] Address Mask (33-25)
602          *         The bits with an address mask of 1 are excluded from address comparison
603          * [31:30] Reserved
604          * 
605          */
606         0xC260, 0xC01f01ff, 0x00e0fe00,
607         0xC264, 0xC01f01ff, 0x00e0fe00,
608         0xC268, 0xC01f01ff, 0x00e0fe00,
609         0xC26C, 0xC01f01ff, 0x00e0fe00,
610         0xC270, 0xC01f01ff, 0x00000000,
611         0xC274, 0xC01f01ff, 0x00000000,
612         0xC278, 0xC01f01ff, 0x00000000,
613         0xC27C, 0xC01f01ff, 0x00000000,
614         /* DRAM Bank Address Mapping Register
615          * F2:0x80
616          * Specify the memory module size
617          * [ 2: 0] CS1/0 
618          * [ 6: 4] CS3/2
619          * [10: 8] CS5/4
620          * [14:12] CS7/6
621          *         000 = 32Mbyte  (Rows = 12 & Col =  8)
622          *         001 = 64Mbyte  (Rows = 12 & Col =  9)
623          *         010 = 128Mbyte (Rows = 13 & Col =  9)|(Rows = 12 & Col = 10)
624          *         011 = 256Mbyte (Rows = 13 & Col = 10)|(Rows = 12 & Col = 11)
625          *         100 = 512Mbyte (Rows = 13 & Col = 11)|(Rows = 14 & Col = 10)
626          *         101 = 1Gbyte   (Rows = 14 & Col = 11)|(Rows = 13 & Col = 12)
627          *         110 = 2Gbyte   (Rows = 14 & Col = 12)
628          *         111 = reserved 
629          * [ 3: 3] Reserved
630          * [ 7: 7] Reserved
631          * [11:11] Reserved
632          * [31:15]
633          */
634         0xC280, 0xffff8888, 0x00000033,
635         /* DRAM Timing Low Register
636          * F2:0x88
637          * [ 2: 0] Tcl (Cas# Latency, Cas# to read-data-valid)
638          *         000 = reserved
639          *         001 = CL 2
640          *         010 = CL 3
641          *         011 = reserved
642          *         100 = reserved
643          *         101 = CL 2.5
644          *         110 = reserved
645          *         111 = reserved
646          * [ 3: 3] Reserved
647          * [ 7: 4] Trc (Row Cycle Time, Ras#-active to Ras#-active/bank auto refresh)
648          *         0000 =  7 bus clocks
649          *         0001 =  8 bus clocks
650          *         ...
651          *         1110 = 21 bus clocks
652          *         1111 = 22 bus clocks
653          * [11: 8] Trfc (Row refresh Cycle time, Auto-refresh-active to RAS#-active or RAS#auto-refresh)
654          *         0000 = 9 bus clocks
655          *         0010 = 10 bus clocks
656          *         ....
657          *         1110 = 23 bus clocks
658          *         1111 = 24 bus clocks
659          * [14:12] Trcd (Ras#-active to Case#-read/write Delay)
660          *         000 = reserved
661          *         001 = reserved
662          *         010 = 2 bus clocks
663          *         011 = 3 bus clocks
664          *         100 = 4 bus clocks
665          *         101 = 5 bus clocks
666          *         110 = 6 bus clocks
667          *         111 = reserved
668          * [15:15] Reserved
669          * [18:16] Trrd (Ras# to Ras# Delay)
670          *         000 = reserved
671          *         001 = reserved
672          *         010 = 2 bus clocks
673          *         011 = 3 bus clocks
674          *         100 = 4 bus clocks
675          *         101 = reserved
676          *         110 = reserved
677          *         111 = reserved
678          * [19:19] Reserved
679          * [23:20] Tras (Minmum Ras# Active Time)
680          *         0000 to 0100 = reserved
681          *         0101 = 5 bus clocks
682          *         ...
683          *         1111 = 15 bus clocks
684          * [26:24] Trp (Row Precharge Time)
685          *         000 = reserved
686          *         001 = reserved
687          *         010 = 2 bus clocks
688          *         011 = 3 bus clocks
689          *         100 = 4 bus clocks
690          *         101 = 5 bus clocks
691          *         110 = 6 bus clocks
692          *         111 = reserved
693          * [27:27] Reserved
694          * [28:28] Twr (Write Recovery Time)
695          *         0 = 2 bus clocks
696          *         1 = 3 bus clocks
697          * [31:29] Reserved
698          */
699         0xC288, 0xe8088008, 0x03623125,
700         /* DRAM Timing High Register
701          * F2:0x8C
702          * [ 0: 0] Twtr (Write to Read Delay)
703          *         0 = 1 bus Clocks
704          *         1 = 2 bus Clocks
705          * [ 3: 1] Reserved
706          * [ 6: 4] Trwf (Read to Write Delay)
707          *         000 = 1 bus clocks
708          *         001 = 2 bus clocks
709          *         010 = 3 bus clocks
710          *         011 = 4 bus clocks
711          *         100 = 5 bus clocks
712          *         101 = 6 bus clocks
713          *         110 = reserved
714          *         111 = reserved
715          * [ 7: 7] Reserved
716          * [12: 8] Tref (Refresh Rate)
717          *         00000 = 100Mhz 4K rows
718          *         00001 = 133Mhz 4K rows
719          *         00010 = 166Mhz 4K rows
720          *         01000 = 100Mhz 8K/16K rows
721          *         01001 = 133Mhz 8K/16K rows
722          *         01010 = 166Mhz 8K/16K rows
723          * [19:13] Reserved
724          * [22:20] Twcl (Write CAS Latency)
725          *         000 = 1 Mem clock after CAS# (Unbuffered Dimms)
726          *         001 = 2 Mem clocks after CAS# (Registered Dimms)
727          * [31:23] Reserved
728          */
729         0xC28c, 0xff8fe08e, 0x00000930,
730
731         /* DRAM Config Low Register
732          * F2:0x90
733          * [ 0: 0] DLL Disable
734          *         0 = Enabled
735          *         1 = Disabled
736          * [ 1: 1] D_DRV
737          *         0 = Normal Drive
738          *         1 = Weak Drive
739          * [ 2: 2] QFC_EN
740          *         0 = Disabled
741          *         1 = Enabled
742          * [ 3: 3] Disable DQS Hystersis  (FIXME handle this one carefully)
743          *         0 = Enable DQS input filter 
744          *         1 = Disable DQS input filtering 
745          * [ 7: 4] Reserved
746          * [ 8: 8] DRAM_Init
747          *         0 = Initialization done or not yet started.
748          *         1 = Initiate DRAM intialization sequence
749          * [ 9: 9] SO-Dimm Enable
750          *         0 = Do nothing
751          *         1 = SO-Dimms present
752          * [10:10] DramEnable
753          *         0 = DRAM not enabled
754          *         1 = DRAM initialized and enabled
755          * [11:11] Memory Clear Status
756          *         0 = Memory Clear function has not completed
757          *         1 = Memory Clear function has completed
758          * [12:12] Exit Self-Refresh
759          *         0 = Exit from self-refresh done or not yet started
760          *         1 = DRAM exiting from self refresh
761          * [13:13] Self-Refresh Status
762          *         0 = Normal Operation
763          *         1 = Self-refresh mode active
764          * [15:14] Read/Write Queue Bypass Count
765          *         00 = 2
766          *         01 = 4
767          *         10 = 8
768          *         11 = 16
769          * [16:16] 128-bit/64-Bit
770          *         0 = 64bit Interface to DRAM
771          *         1 = 128bit Interface to DRAM
772          * [17:17] DIMM ECC Enable
773          *         0 = Some DIMMs do not have ECC
774          *         1 = ALL DIMMS have ECC bits
775          * [18:18] UnBuffered DIMMs
776          *         0 = Buffered DIMMS
777          *         1 = Unbuffered DIMMS
778          * [19:19] Enable 32-Byte Granularity
779          *         0 = Optimize for 64byte bursts
780          *         1 = Optimize for 32byte bursts
781          * [20:20] DIMM 0 is x4
782          * [21:21] DIMM 1 is x4
783          * [22:22] DIMM 2 is x4
784          * [23:23] DIMM 3 is x4
785          *         0 = DIMM is not x4
786          *         1 = x4 DIMM present
787          * [24:24] Disable DRAM Receivers
788          *         0 = Receivers enabled
789          *         1 = Receivers disabled
790          * [27:25] Bypass Max
791          *         000 = Arbiters chois is always respected
792          *         001 = Oldest entry in DCQ can be bypassed 1 time
793          *         010 = Oldest entry in DCQ can be bypassed 2 times
794          *         011 = Oldest entry in DCQ can be bypassed 3 times
795          *         100 = Oldest entry in DCQ can be bypassed 4 times
796          *         101 = Oldest entry in DCQ can be bypassed 5 times
797          *         110 = Oldest entry in DCQ can be bypassed 6 times
798          *         111 = Oldest entry in DCQ can be bypassed 7 times
799          * [31:28] Reserved
800          */
801         0xC290, 0xf0000000, 
802         (4 << 25)|(0 << 24)| 
803         (0 << 23)|(0 << 22)|(0 << 21)|(0 << 20)| 
804         (1 << 19)|(1 << 18)|(0 << 17)|(0 << 16)| 
805         (2 << 14)|(0 << 13)|(0 << 12)| 
806         (0 << 11)|(0 << 10)|(0 << 9)|(0 << 8)| 
807         (0 << 3) |(0 << 1) |(0 << 0),
808         /* DRAM Config High Register
809          * F2:0x94
810          * [ 0: 3] Maximum Asynchronous Latency
811          *         0000 = 0 ns
812          *         ...
813          *         1111 = 15 ns
814          * [ 7: 4] Reserved
815          * [11: 8] Read Preamble
816          *         0000 = 2.0 ns
817          *         0001 = 2.5 ns
818          *         0010 = 3.0 ns
819          *         0011 = 3.5 ns
820          *         0100 = 4.0 ns
821          *         0101 = 4.5 ns
822          *         0110 = 5.0 ns
823          *         0111 = 5.5 ns
824          *         1000 = 6.0 ns
825          *         1001 = 6.5 ns
826          *         1010 = 7.0 ns
827          *         1011 = 7.5 ns
828          *         1100 = 8.0 ns
829          *         1101 = 8.5 ns
830          *         1110 = 9.0 ns
831          *         1111 = 9.5 ns
832          * [15:12] Reserved
833          * [18:16] Idle Cycle Limit
834          *         000 = 0 cycles
835          *         001 = 4 cycles
836          *         010 = 8 cycles
837          *         011 = 16 cycles
838          *         100 = 32 cycles
839          *         101 = 64 cycles
840          *         110 = 128 cycles
841          *         111 = 256 cycles
842          * [19:19] Dynamic Idle Cycle Center Enable
843          *         0 = Use Idle Cycle Limit
844          *         1 = Generate a dynamic Idle cycle limit
845          * [22:20] DRAM MEMCLK Frequency
846          *         000 = 100Mhz
847          *         001 = reserved
848          *         010 = 133Mhz
849          *         011 = reserved
850          *         100 = reserved
851          *         101 = 166Mhz
852          *         110 = reserved
853          *         111 = reserved
854          * [24:23] Reserved
855          * [25:25] Memory Clock Ratio Valid (FIXME carefully enable memclk)
856          *         0 = Disable MemClks
857          *         1 = Enable MemClks
858          * [26:26] Memory Clock 0 Enable
859          *         0 = Disabled
860          *         1 = Enabled
861          * [27:27] Memory Clock 1 Enable
862          *         0 = Disabled
863          *         1 = Enabled
864          * [28:28] Memory Clock 2 Enable
865          *         0 = Disabled
866          *         1 = Enabled
867          * [29:29] Memory Clock 3 Enable
868          *         0 = Disabled
869          *         1 = Enabled
870          * [31:30] Reserved
871          */
872         0xC294, 0xc180f0f0, 0x0e2b0a05,
873         /* DRAM Delay Line Register
874          * F2:0x98
875          * Adjust the skew of the input DQS strobe relative to DATA
876          * [15: 0] Reserved
877          * [23:16] Delay Line Adjust
878          *         Adjusts the DLL derived PDL delay by one or more delay stages
879          *         in either the faster or slower direction.
880          * [24:24} Adjust Slower
881          *         0 = Do Nothing
882          *         1 = Adj is used to increase the PDL delay
883          * [25:25] Adjust Faster
884          *         0 = Do Nothing
885          *         1 = Adj is used to decrease the PDL delay
886          * [31:26] Reserved
887          */
888         0xC298, 0xfc00ffff, 0x00000000,
889         /* DRAM Scrub Control Register
890          * F3:0x58
891          * [ 4: 0] DRAM Scrube Rate
892          * [ 7: 5] reserved
893          * [12: 8] L2 Scrub Rate
894          * [15:13] reserved
895          * [20:16] Dcache Scrub
896          * [31:21] reserved
897          *         Scrub Rates
898          *         00000 = Do not scrub
899          *         00001 =  40.00 ns
900          *         00010 =  80.00 ns
901          *         00011 = 160.00 ns
902          *         00100 = 320.00 ns
903          *         00101 = 640.00 ns
904          *         00110 =   1.28 us
905          *         00111 =   2.56 us
906          *         01000 =   5.12 us
907          *         01001 =  10.20 us
908          *         01011 =  41.00 us
909          *         01100 =  81.90 us
910          *         01101 = 163.80 us
911          *         01110 = 327.70 us
912          *         01111 = 655.40 us
913          *         10000 =   1.31 ms
914          *         10001 =   2.62 ms
915          *         10010 =   5.24 ms
916          *         10011 =  10.49 ms
917          *         10100 =  20.97 ms
918          *         10101 =  42.00 ms
919          *         10110 =  84.00 ms
920          *         All Others = Reserved
921          */
922         0xC358, 0xffe0e0e0, 0x00000000,
923         /* DRAM Scrub Address Low Register
924          * F3:0x5C
925          * [ 0: 0] DRAM Scrubber Redirect Enable
926          *         0 = Do nothing
927          *         1 = Scrubber Corrects errors found in normal operation
928          * [ 5: 1] Reserved
929          * [31: 6] DRAM Scrub Address 31-6
930          */
931         0xC35C, 0x0000003e, 0x00000000,
932         /* DRAM Scrub Address High Register
933          * F3:0x60
934          * [ 7: 0] DRAM Scrubb Address 39-32
935          * [31: 8] Reserved
936          */
937         0xC360, 0xffffff00, 0x00000000,
938         };
939         int i;
940         int max;
941         print_debug("setting up northbridge registers\r\n");
942         max = sizeof(register_values)/sizeof(register_values[0]);
943         for(i = 0; i < max; i += 3) {
944                 unsigned long reg;
945 #if 0
946                 print_debug_hex32(register_values[i]);
947                 print_debug(" <-");
948                 print_debug_hex32(register_values[i+2]);
949                 print_debug("\r\n");
950 #endif
951                 reg = pcibios_read_config_dword(
952                         0, register_values[i] >> 8, register_values[i] & 0xff);
953                 reg &= register_values[i+1];
954                 reg |= register_values[i+2] & ~register_values[i+1];
955                 pcibios_write_config_dword(
956                         0, register_values[i] >> 8, register_values[i] & 0xff, reg);
957         }
958         print_debug("setting up northbridge registers done. hurray!\r\n");
959 }
960
961 #define PCI_DEVFN(slot,func)    ((((slot) & 0x1f) << 3) | ((func) & 0x07))
962
963 #define DRAM_CONFIG_LOW 0x90
964 #define  DCL_DLL_Disable   (1<<0)
965 #define  DCL_D_DRV         (1<<1)
966 #define  DCL_QFC_EN        (1<<2)
967 #define  DCL_DisDqsHys     (1<<3)
968 #define  DCL_DramInit      (1<<8)
969 #define  DCL_DramEnable    (1<<10)
970 #define  DCL_MemClrStatus  (1<<11)
971 #define  DCL_DimmEcEn      (1<<17)
972
973 static void sdram_set_spd_registers(void) 
974 {
975         unsigned long dcl;
976         dcl = pcibios_read_config_dword(0, PCI_DEVFN(0x18,2), DRAM_CONFIG_LOW);
977         /* Until I know what is going on disable ECC support */
978         dcl &= ~DCL_DimmEcEn;
979         pcibios_write_config_dword(0, PCI_DEVFN(0x18,2), DRAM_CONFIG_LOW, dcl);
980 }
981
982 #define TIMEOUT_LOOPS 300000
983 static void sdram_enable(void)
984 {
985         unsigned long dcl;
986
987         /* Toggle DisDqsHys to get it working */
988         dcl = pcibios_read_config_dword(0, PCI_DEVFN(0x18,2), DRAM_CONFIG_LOW);
989         print_debug("dcl: ");
990         print_debug_hex32(dcl);
991         print_debug("\r\n");
992         dcl |= DCL_DisDqsHys;
993         pcibios_write_config_dword(0, PCI_DEVFN(0x18, 2), DRAM_CONFIG_LOW, dcl);
994         dcl &= ~DCL_DisDqsHys;
995         dcl &= ~DCL_DLL_Disable;
996         dcl &= ~DCL_D_DRV;
997         dcl &= ~DCL_QFC_EN;
998         dcl |= DCL_DramInit;
999         pcibios_write_config_dword(0, PCI_DEVFN(0x18, 2), DRAM_CONFIG_LOW, dcl);
1000         
1001         print_debug("Initializing memory: ");
1002         int loops = 0;
1003         do {
1004                 dcl = pcibios_read_config_dword(0, PCI_DEVFN(0x18, 2), DRAM_CONFIG_LOW);
1005                 loops += 1;
1006                 if ((loops & 1023) == 0) {
1007                         print_debug(" ");
1008                         print_debug_hex32(loops);
1009                 }
1010         } while(((dcl & DCL_DramInit) != 0) && (loops < TIMEOUT_LOOPS));
1011         if (loops >= TIMEOUT_LOOPS) {
1012                 print_debug(" failed\r\n");
1013         } else {
1014                 print_debug(" done\r\n");
1015         }
1016
1017 #if 0
1018         print_debug("Clearing memory: ");
1019         loops = 0;
1020         do {
1021                 dcl = pcibios_read_config_dword(0, PCI_DEVFN(0x18, 2), DRAM_CONFIG_LOW);
1022                 loops += 1;
1023                 if ((loops & 1023) == 0) {
1024                         print_debug(" ");
1025                         print_debug_hex32(loops);
1026                 }
1027         } while(((dcl & DCL_MemClrStatus) == 0) && (loops < TIMEOUT_LOOPS));
1028         if (loops >= TIMEOUT_LOOPS) {
1029                 print_debug("failed\r\n");
1030         } else {
1031                 print_debug("done\r\n");
1032         }
1033 #endif
1034 }
1035
1036 static void sdram_first_normal_reference(void) {}
1037 static void sdram_enable_refresh(void) {}
1038 static void sdram_special_finishup(void) {}
1039
1040 static int sdram_enabled(void)
1041 {
1042         unsigned long dcl;
1043         int enabled;
1044         dcl = pcibios_read_config_dword(0, PCI_DEVFN(0x18, 2), DRAM_CONFIG_LOW);
1045         enabled = !!(dcl & DCL_DramEnable);
1046         if (enabled) {
1047                 print_debug("DRAM already enabled.");
1048         }
1049         return enabled;
1050 }
1051
1052
1053 #include "sdram/generic_sdram.c"
1054
1055 static void main(void)
1056 {
1057         uart_init();
1058         console_init();
1059         if (!sdram_enabled()) {
1060                 sdram_initialize();
1061 #if 0
1062                 ram_fill(  0x00100000, 0x00180000);
1063                 ram_verify(0x00100000, 0x00180000);
1064 #endif
1065 #if 1
1066                 ram_fill(  0x00000000, 0x00001000);
1067                 ram_verify(0x00000000, 0x00001000);
1068 #endif
1069         }
1070 }