1 #include <cpu/k8/mtrr.h>
7 #define DRAM_CSBASE 0x40
8 #define DRAM_CSMASK 0x60
9 #define DRAM_BANK_ADDR_MAP 0x80
10 #define DRAM_TIMING_LOW 0x88
11 #define DTL_TCL_SHIFT 0
12 #define DTL_TCL_MASK 0x7
16 #define DTL_TRC_SHIFT 4
17 #define DTL_TRC_MASK 0xf
18 #define DTL_TRC_BASE 7
20 #define DTL_TRC_MAX 22
21 #define DTL_TRFC_SHIFT 8
22 #define DTL_TRFC_MASK 0xf
23 #define DTL_TRFC_BASE 9
24 #define DTL_TRFC_MIN 9
25 #define DTL_TRFC_MAX 24
26 #define DTL_TRCD_SHIFT 12
27 #define DTL_TRCD_MASK 0x7
28 #define DTL_TRCD_BASE 0
29 #define DTL_TRCD_MIN 2
30 #define DTL_TRCD_MAX 6
31 #define DTL_TRRD_SHIFT 16
32 #define DTL_TRRD_MASK 0x7
33 #define DTL_TRRD_BASE 0
34 #define DTL_TRRD_MIN 2
35 #define DTL_TRRD_MAX 4
36 #define DTL_TRAS_SHIFT 20
37 #define DTL_TRAS_MASK 0xf
38 #define DTL_TRAS_BASE 0
39 #define DTL_TRAS_MIN 5
40 #define DTL_TRAS_MAX 15
41 #define DTL_TRP_SHIFT 24
42 #define DTL_TRP_MASK 0x7
43 #define DTL_TRP_BASE 0
46 #define DTL_TWR_SHIFT 28
47 #define DTL_TWR_MASK 0x1
48 #define DTL_TWR_BASE 2
51 #define DRAM_TIMING_HIGH 0x8c
52 #define DTH_TWTR_SHIFT 0
53 #define DTH_TWTR_MASK 0x1
54 #define DTH_TWTR_BASE 1
55 #define DTH_TWTR_MIN 1
56 #define DTH_TWTR_MAX 2
57 #define DTH_TRWT_SHIFT 4
58 #define DTH_TRWT_MASK 0x7
59 #define DTH_TRWT_BASE 1
60 #define DTH_TRWT_MIN 1
61 #define DTH_TRWT_MAX 6
62 #define DTH_TREF_SHIFT 8
63 #define DTH_TREF_MASK 0x1f
64 #define DTH_TREF_100MHZ_4K 0x00
65 #define DTH_TREF_133MHZ_4K 0x01
66 #define DTH_TREF_166MHZ_4K 0x02
67 #define DTH_TREF_200MHZ_4K 0x03
68 #define DTH_TREF_100MHZ_8K 0x08
69 #define DTH_TREF_133MHZ_8K 0x09
70 #define DTH_TREF_166MHZ_8K 0x0A
71 #define DTH_TREF_200MHZ_8K 0x0B
72 #define DTH_TWCL_SHIFT 20
73 #define DTH_TWCL_MASK 0x7
74 #define DTH_TWCL_BASE 1
75 #define DTH_TWCL_MIN 1
76 #define DTH_TWCL_MAX 2
77 #define DRAM_CONFIG_LOW 0x90
78 #define DCL_DLL_Disable (1<<0)
79 #define DCL_D_DRV (1<<1)
80 #define DCL_QFC_EN (1<<2)
81 #define DCL_DisDqsHys (1<<3)
82 #define DCL_DramInit (1<<8)
83 #define DCL_DramEnable (1<<10)
84 #define DCL_MemClrStatus (1<<11)
85 #define DCL_ESR (1<<12)
86 #define DCL_SRS (1<<13)
87 #define DCL_128BitEn (1<<16)
88 #define DCL_DimmEccEn (1<<17)
89 #define DCL_UnBufDimm (1<<18)
90 #define DCL_32ByteEn (1<<19)
91 #define DCL_x4DIMM_SHIFT 20
92 #define DRAM_CONFIG_HIGH 0x94
93 #define DCH_ASYNC_LAT_SHIFT 0
94 #define DCH_ASYNC_LAT_MASK 0xf
95 #define DCH_ASYNC_LAT_BASE 0
96 #define DCH_ASYNC_LAT_MIN 0
97 #define DCH_ASYNC_LAT_MAX 15
98 #define DCH_RDPREAMBLE_SHIFT 8
99 #define DCH_RDPREAMBLE_MASK 0xf
100 #define DCH_RDPREAMBLE_BASE ((2<<1)+0) /* 2.0 ns */
101 #define DCH_RDPREAMBLE_MIN ((2<<1)+0) /* 2.0 ns */
102 #define DCH_RDPREAMBLE_MAX ((9<<1)+1) /* 9.5 ns */
103 #define DCH_IDLE_LIMIT_SHIFT 16
104 #define DCH_IDLE_LIMIT_MASK 0x7
105 #define DCH_IDLE_LIMIT_0 0
106 #define DCH_IDLE_LIMIT_4 1
107 #define DCH_IDLE_LIMIT_8 2
108 #define DCH_IDLE_LIMIT_16 3
109 #define DCH_IDLE_LIMIT_32 4
110 #define DCH_IDLE_LIMIT_64 5
111 #define DCH_IDLE_LIMIT_128 6
112 #define DCH_IDLE_LIMIT_256 7
113 #define DCH_DYN_IDLE_CTR_EN (1 << 19)
114 #define DCH_MEMCLK_SHIFT 20
115 #define DCH_MEMCLK_MASK 0x7
116 #define DCH_MEMCLK_100MHZ 0
117 #define DCH_MEMCLK_133MHZ 2
118 #define DCH_MEMCLK_166MHZ 5
119 #define DCH_MEMCLK_200MHZ 7
120 #define DCH_MEMCLK_VALID (1 << 25)
121 #define DCH_MEMCLK_EN0 (1 << 26)
122 #define DCH_MEMCLK_EN1 (1 << 27)
123 #define DCH_MEMCLK_EN2 (1 << 28)
124 #define DCH_MEMCLK_EN3 (1 << 29)
127 #define SCRUB_CONTROL 0x58
131 #define SCRUB_160ns 3
132 #define SCRUB_320ns 4
133 #define SCRUB_640ns 5
134 #define SCRUB_1_28us 6
135 #define SCRUB_2_56us 7
136 #define SCRUB_5_12us 8
137 #define SCRUB_10_2us 9
138 #define SCRUB_20_5us 10
139 #define SCRUB_41_0us 11
140 #define SCRUB_81_9us 12
141 #define SCRUB_163_8us 13
142 #define SCRUB_327_7us 14
143 #define SCRUB_655_4us 15
144 #define SCRUB_1_31ms 16
145 #define SCRUB_2_62ms 17
146 #define SCRUB_5_24ms 18
147 #define SCRUB_10_49ms 19
148 #define SCRUB_20_97ms 20
149 #define SCRUB_42ms 21
150 #define SCRUB_84ms 22
151 #define SC_DRAM_SCRUB_RATE_SHFIT 0
152 #define SC_DRAM_SCRUB_RATE_MASK 0x1f
153 #define SC_L2_SCRUB_RATE_SHIFT 8
154 #define SC_L2_SCRUB_RATE_MASK 0x1f
155 #define SC_L1D_SCRUB_RATE_SHIFT 16
156 #define SC_L1D_SCRUB_RATE_MASK 0x1f
157 #define SCRUB_ADDR_LOW 0x5C
158 #define SCRUB_ADDR_HIGH 0x60
159 #define NORTHBRIDGE_CAP 0xE8
160 #define NBCAP_128Bit 0x0001
161 #define NBCAP_MP 0x0002
162 #define NBCAP_BIG_MP 0x0004
163 #define NBCAP_ECC 0x0004
164 #define NBCAP_CHIPKILL_ECC 0x0010
165 #define NBCAP_MEMCLK_SHIFT 5
166 #define NBCAP_MEMCLK_MASK 3
167 #define NBCAP_MEMCLK_100MHZ 3
168 #define NBCAP_MEMCLK_133MHZ 2
169 #define NBCAP_MEMCLK_166MHZ 1
170 #define NBCAP_MEMCLK_200MHZ 0
171 #define NBCAP_MEMCTRL 0x0100
174 static void setup_resource_map(const unsigned int *register_values, int max)
177 print_debug("setting up resource map....\r\n");
178 for(i = 0; i < max; i += 3) {
183 print_debug_hex32(register_values[i]);
185 print_debug_hex32(register_values[i+2]);
188 dev = register_values[i] & ~0xff;
189 where = register_values[i] & 0xff;
190 reg = pci_read_config32(dev, where);
191 reg &= register_values[i+1];
192 reg |= register_values[i+2];
193 pci_write_config32(dev, where, reg);
195 reg = pci_read_config32(register_values[i]);
196 reg &= register_values[i+1];
197 reg |= register_values[i+2] & ~register_values[i+1];
198 pci_write_config32(register_values[i], reg);
201 print_debug("done.\r\n");
204 static void setup_default_resource_map(void)
206 static const unsigned int register_values[] = {
207 /* Careful set limit registers before base registers which contain the enables */
208 /* DRAM Limit i Registers
217 * [ 2: 0] Destination Node ID
227 * [10: 8] Interleave select
228 * specifies the values of A[14:12] to use with interleave enable.
230 * [31:16] DRAM Limit Address i Bits 39-24
231 * This field defines the upper address bits of a 40 bit address
232 * that define the end of the DRAM region.
234 PCI_ADDR(0, 0x18, 1, 0x44), 0x0000f8f8, 0x00000000,
235 PCI_ADDR(0, 0x18, 1, 0x4C), 0x0000f8f8, 0x00000001,
236 PCI_ADDR(0, 0x18, 1, 0x54), 0x0000f8f8, 0x00000002,
237 PCI_ADDR(0, 0x18, 1, 0x5C), 0x0000f8f8, 0x00000003,
238 PCI_ADDR(0, 0x18, 1, 0x64), 0x0000f8f8, 0x00000004,
239 PCI_ADDR(0, 0x18, 1, 0x6C), 0x0000f8f8, 0x00000005,
240 PCI_ADDR(0, 0x18, 1, 0x74), 0x0000f8f8, 0x00000006,
241 PCI_ADDR(0, 0x18, 1, 0x7C), 0x0000f8f8, 0x00000007,
242 /* DRAM Base i Registers
251 * [ 0: 0] Read Enable
254 * [ 1: 1] Write Enable
255 * 0 = Writes Disabled
258 * [10: 8] Interleave Enable
259 * 000 = No interleave
260 * 001 = Interleave on A[12] (2 nodes)
262 * 011 = Interleave on A[12] and A[14] (4 nodes)
266 * 111 = Interleve on A[12] and A[13] and A[14] (8 nodes)
268 * [13:16] DRAM Base Address i Bits 39-24
269 * This field defines the upper address bits of a 40-bit address
270 * that define the start of the DRAM region.
272 PCI_ADDR(0, 0x18, 1, 0x40), 0x0000f8fc, 0x00000000,
273 PCI_ADDR(0, 0x18, 1, 0x48), 0x0000f8fc, 0x00000000,
274 PCI_ADDR(0, 0x18, 1, 0x50), 0x0000f8fc, 0x00000000,
275 PCI_ADDR(0, 0x18, 1, 0x58), 0x0000f8fc, 0x00000000,
276 PCI_ADDR(0, 0x18, 1, 0x60), 0x0000f8fc, 0x00000000,
277 PCI_ADDR(0, 0x18, 1, 0x68), 0x0000f8fc, 0x00000000,
278 PCI_ADDR(0, 0x18, 1, 0x70), 0x0000f8fc, 0x00000000,
279 PCI_ADDR(0, 0x18, 1, 0x78), 0x0000f8fc, 0x00000000,
281 /* Memory-Mapped I/O Limit i Registers
290 * [ 2: 0] Destination Node ID
300 * [ 5: 4] Destination Link ID
307 * 0 = CPU writes may be posted
308 * 1 = CPU writes must be non-posted
309 * [31: 8] Memory-Mapped I/O Limit Address i (39-16)
310 * This field defines the upp adddress bits of a 40-bit address that
311 * defines the end of a memory-mapped I/O region n
313 PCI_ADDR(0, 0x18, 1, 0x84), 0x00000048, 0x00000000,
314 PCI_ADDR(0, 0x18, 1, 0x8C), 0x00000048, 0x00000000,
315 PCI_ADDR(0, 0x18, 1, 0x94), 0x00000048, 0x00000000,
316 PCI_ADDR(0, 0x18, 1, 0x9C), 0x00000048, 0x00000000,
317 PCI_ADDR(0, 0x18, 1, 0xA4), 0x00000048, 0x00000000,
318 PCI_ADDR(0, 0x18, 1, 0xAC), 0x00000048, 0x00000000,
319 PCI_ADDR(0, 0x18, 1, 0xB4), 0x00000048, 0x00000000,
320 PCI_ADDR(0, 0x18, 1, 0xBC), 0x00000048, 0x00ffff00,
322 /* Memory-Mapped I/O Base i Registers
331 * [ 0: 0] Read Enable
334 * [ 1: 1] Write Enable
335 * 0 = Writes disabled
337 * [ 2: 2] Cpu Disable
338 * 0 = Cpu can use this I/O range
339 * 1 = Cpu requests do not use this I/O range
341 * 0 = base/limit registers i are read/write
342 * 1 = base/limit registers i are read-only
344 * [31: 8] Memory-Mapped I/O Base Address i (39-16)
345 * This field defines the upper address bits of a 40bit address
346 * that defines the start of memory-mapped I/O region i
348 PCI_ADDR(0, 0x18, 1, 0x80), 0x000000f0, 0x00000000,
349 PCI_ADDR(0, 0x18, 1, 0x88), 0x000000f0, 0x00000000,
350 PCI_ADDR(0, 0x18, 1, 0x90), 0x000000f0, 0x00000000,
351 PCI_ADDR(0, 0x18, 1, 0x98), 0x000000f0, 0x00000000,
352 PCI_ADDR(0, 0x18, 1, 0xA0), 0x000000f0, 0x00000000,
353 PCI_ADDR(0, 0x18, 1, 0xA8), 0x000000f0, 0x00000000,
354 PCI_ADDR(0, 0x18, 1, 0xB0), 0x000000f0, 0x00000000,
355 PCI_ADDR(0, 0x18, 1, 0xB8), 0x000000f0, 0x00fc0003,
357 /* PCI I/O Limit i Registers
362 * [ 2: 0] Destination Node ID
372 * [ 5: 4] Destination Link ID
378 * [24:12] PCI I/O Limit Address i
379 * This field defines the end of PCI I/O region n
382 PCI_ADDR(0, 0x18, 1, 0xC4), 0xFE000FC8, 0x01fff000,
383 PCI_ADDR(0, 0x18, 1, 0xCC), 0xFE000FC8, 0x00000000,
384 PCI_ADDR(0, 0x18, 1, 0xD4), 0xFE000FC8, 0x00000000,
385 PCI_ADDR(0, 0x18, 1, 0xDC), 0xFE000FC8, 0x00000000,
387 /* PCI I/O Base i Registers
392 * [ 0: 0] Read Enable
395 * [ 1: 1] Write Enable
396 * 0 = Writes Disabled
400 * 0 = VGA matches Disabled
401 * 1 = matches all address < 64K and where A[9:0] is in the
402 * range 3B0-3BB or 3C0-3DF independen of the base & limit registers
404 * 0 = ISA matches Disabled
405 * 1 = Blocks address < 64K and in the last 768 bytes of eack 1K block
406 * from matching agains this base/limit pair
408 * [24:12] PCI I/O Base i
409 * This field defines the start of PCI I/O region n
412 PCI_ADDR(0, 0x18, 1, 0xC0), 0xFE000FCC, 0x00000003,
413 PCI_ADDR(0, 0x18, 1, 0xC8), 0xFE000FCC, 0x00000000,
414 PCI_ADDR(0, 0x18, 1, 0xD0), 0xFE000FCC, 0x00000000,
415 PCI_ADDR(0, 0x18, 1, 0xD8), 0xFE000FCC, 0x00000000,
417 /* Config Base and Limit i Registers
422 * [ 0: 0] Read Enable
425 * [ 1: 1] Write Enable
426 * 0 = Writes Disabled
428 * [ 2: 2] Device Number Compare Enable
429 * 0 = The ranges are based on bus number
430 * 1 = The ranges are ranges of devices on bus 0
432 * [ 6: 4] Destination Node
442 * [ 9: 8] Destination Link
448 * [23:16] Bus Number Base i
449 * This field defines the lowest bus number in configuration region i
450 * [31:24] Bus Number Limit i
451 * This field defines the highest bus number in configuration regin i
453 PCI_ADDR(0, 0x18, 1, 0xE0), 0x0000FC88, 0xff000003,
454 PCI_ADDR(0, 0x18, 1, 0xE4), 0x0000FC88, 0x00000000,
455 PCI_ADDR(0, 0x18, 1, 0xE8), 0x0000FC88, 0x00000000,
456 PCI_ADDR(0, 0x18, 1, 0xEC), 0x0000FC88, 0x00000000,
459 max = sizeof(register_values)/sizeof(register_values[0]);
460 setup_resource_map(register_values, max);
463 static void sdram_set_registers(const struct mem_controller *ctrl)
465 static const unsigned int register_values[] = {
467 /* Careful set limit registers before base registers which contain the enables */
468 /* DRAM Limit i Registers
477 * [ 2: 0] Destination Node ID
487 * [10: 8] Interleave select
488 * specifies the values of A[14:12] to use with interleave enable.
490 * [31:16] DRAM Limit Address i Bits 39-24
491 * This field defines the upper address bits of a 40 bit address
492 * that define the end of the DRAM region.
494 PCI_ADDR(0, 0x18, 1, 0x44), 0x0000f8f8, 0x00000000,
495 PCI_ADDR(0, 0x18, 1, 0x4C), 0x0000f8f8, 0x00000001,
496 PCI_ADDR(0, 0x18, 1, 0x54), 0x0000f8f8, 0x00000002,
497 PCI_ADDR(0, 0x18, 1, 0x5C), 0x0000f8f8, 0x00000003,
498 PCI_ADDR(0, 0x18, 1, 0x64), 0x0000f8f8, 0x00000004,
499 PCI_ADDR(0, 0x18, 1, 0x6C), 0x0000f8f8, 0x00000005,
500 PCI_ADDR(0, 0x18, 1, 0x74), 0x0000f8f8, 0x00000006,
501 PCI_ADDR(0, 0x18, 1, 0x7C), 0x0000f8f8, 0x00000007,
502 /* DRAM Base i Registers
511 * [ 0: 0] Read Enable
514 * [ 1: 1] Write Enable
515 * 0 = Writes Disabled
518 * [10: 8] Interleave Enable
519 * 000 = No interleave
520 * 001 = Interleave on A[12] (2 nodes)
522 * 011 = Interleave on A[12] and A[14] (4 nodes)
526 * 111 = Interleve on A[12] and A[13] and A[14] (8 nodes)
528 * [13:16] DRAM Base Address i Bits 39-24
529 * This field defines the upper address bits of a 40-bit address
530 * that define the start of the DRAM region.
532 PCI_ADDR(0, 0x18, 1, 0x40), 0x0000f8fc, 0x00000000,
533 PCI_ADDR(0, 0x18, 1, 0x48), 0x0000f8fc, 0x00000000,
534 PCI_ADDR(0, 0x18, 1, 0x50), 0x0000f8fc, 0x00000000,
535 PCI_ADDR(0, 0x18, 1, 0x58), 0x0000f8fc, 0x00000000,
536 PCI_ADDR(0, 0x18, 1, 0x60), 0x0000f8fc, 0x00000000,
537 PCI_ADDR(0, 0x18, 1, 0x68), 0x0000f8fc, 0x00000000,
538 PCI_ADDR(0, 0x18, 1, 0x70), 0x0000f8fc, 0x00000000,
539 PCI_ADDR(0, 0x18, 1, 0x78), 0x0000f8fc, 0x00000000,
541 /* DRAM CS Base Address i Registers
550 * [ 0: 0] Chip-Select Bank Enable
554 * [15: 9] Base Address (19-13)
555 * An optimization used when all DIMM are the same size...
557 * [31:21] Base Address (35-25)
558 * This field defines the top 11 addresses bit of a 40-bit
559 * address that define the memory address space. These
560 * bits decode 32-MByte blocks of memory.
562 PCI_ADDR(0, 0x18, 2, 0x40), 0x001f01fe, 0x00000000,
563 PCI_ADDR(0, 0x18, 2, 0x44), 0x001f01fe, 0x00000000,
564 PCI_ADDR(0, 0x18, 2, 0x48), 0x001f01fe, 0x00000000,
565 PCI_ADDR(0, 0x18, 2, 0x4C), 0x001f01fe, 0x00000000,
566 PCI_ADDR(0, 0x18, 2, 0x50), 0x001f01fe, 0x00000000,
567 PCI_ADDR(0, 0x18, 2, 0x54), 0x001f01fe, 0x00000000,
568 PCI_ADDR(0, 0x18, 2, 0x58), 0x001f01fe, 0x00000000,
569 PCI_ADDR(0, 0x18, 2, 0x5C), 0x001f01fe, 0x00000000,
570 /* DRAM CS Mask Address i Registers
579 * Select bits to exclude from comparison with the DRAM Base address register.
581 * [15: 9] Address Mask (19-13)
582 * Address to be excluded from the optimized case
584 * [29:21] Address Mask (33-25)
585 * The bits with an address mask of 1 are excluded from address comparison
589 PCI_ADDR(0, 0x18, 2, 0x60), 0xC01f01ff, 0x00000000,
590 PCI_ADDR(0, 0x18, 2, 0x64), 0xC01f01ff, 0x00000000,
591 PCI_ADDR(0, 0x18, 2, 0x68), 0xC01f01ff, 0x00000000,
592 PCI_ADDR(0, 0x18, 2, 0x6C), 0xC01f01ff, 0x00000000,
593 PCI_ADDR(0, 0x18, 2, 0x70), 0xC01f01ff, 0x00000000,
594 PCI_ADDR(0, 0x18, 2, 0x74), 0xC01f01ff, 0x00000000,
595 PCI_ADDR(0, 0x18, 2, 0x78), 0xC01f01ff, 0x00000000,
596 PCI_ADDR(0, 0x18, 2, 0x7C), 0xC01f01ff, 0x00000000,
597 /* DRAM Bank Address Mapping Register
599 * Specify the memory module size
604 * 000 = 32Mbyte (Rows = 12 & Col = 8)
605 * 001 = 64Mbyte (Rows = 12 & Col = 9)
606 * 010 = 128Mbyte (Rows = 13 & Col = 9)|(Rows = 12 & Col = 10)
607 * 011 = 256Mbyte (Rows = 13 & Col = 10)|(Rows = 12 & Col = 11)
608 * 100 = 512Mbyte (Rows = 13 & Col = 11)|(Rows = 14 & Col = 10)
609 * 101 = 1Gbyte (Rows = 14 & Col = 11)|(Rows = 13 & Col = 12)
610 * 110 = 2Gbyte (Rows = 14 & Col = 12)
617 PCI_ADDR(0, 0x18, 2, 0x80), 0xffff8888, 0x00000000,
618 /* DRAM Timing Low Register
620 * [ 2: 0] Tcl (Cas# Latency, Cas# to read-data-valid)
630 * [ 7: 4] Trc (Row Cycle Time, Ras#-active to Ras#-active/bank auto refresh)
631 * 0000 = 7 bus clocks
632 * 0001 = 8 bus clocks
634 * 1110 = 21 bus clocks
635 * 1111 = 22 bus clocks
636 * [11: 8] Trfc (Row refresh Cycle time, Auto-refresh-active to RAS#-active or RAS#auto-refresh)
637 * 0000 = 9 bus clocks
638 * 0010 = 10 bus clocks
640 * 1110 = 23 bus clocks
641 * 1111 = 24 bus clocks
642 * [14:12] Trcd (Ras#-active to Case#-read/write Delay)
652 * [18:16] Trrd (Ras# to Ras# Delay)
662 * [23:20] Tras (Minmum Ras# Active Time)
663 * 0000 to 0100 = reserved
664 * 0101 = 5 bus clocks
666 * 1111 = 15 bus clocks
667 * [26:24] Trp (Row Precharge Time)
677 * [28:28] Twr (Write Recovery Time)
682 PCI_ADDR(0, 0x18, 2, 0x88), 0xe8088008, 0x02522001 /* 0x03623125 */ ,
683 /* DRAM Timing High Register
685 * [ 0: 0] Twtr (Write to Read Delay)
689 * [ 6: 4] Trwt (Read to Write Delay)
699 * [12: 8] Tref (Refresh Rate)
700 * 00000 = 100Mhz 4K rows
701 * 00001 = 133Mhz 4K rows
702 * 00010 = 166Mhz 4K rows
703 * 00011 = 200Mhz 4K rows
704 * 01000 = 100Mhz 8K/16K rows
705 * 01001 = 133Mhz 8K/16K rows
706 * 01010 = 166Mhz 8K/16K rows
707 * 01011 = 200Mhz 8K/16K rows
709 * [22:20] Twcl (Write CAS Latency)
710 * 000 = 1 Mem clock after CAS# (Unbuffered Dimms)
711 * 001 = 2 Mem clocks after CAS# (Registered Dimms)
714 PCI_ADDR(0, 0x18, 2, 0x8c), 0xff8fe08e, (0 << 20)|(0 << 8)|(0 << 4)|(0 << 0),
715 /* DRAM Config Low Register
717 * [ 0: 0] DLL Disable
726 * [ 3: 3] Disable DQS Hystersis (FIXME handle this one carefully)
727 * 0 = Enable DQS input filter
728 * 1 = Disable DQS input filtering
731 * 0 = Initialization done or not yet started.
732 * 1 = Initiate DRAM intialization sequence
733 * [ 9: 9] SO-Dimm Enable
735 * 1 = SO-Dimms present
737 * 0 = DRAM not enabled
738 * 1 = DRAM initialized and enabled
739 * [11:11] Memory Clear Status
740 * 0 = Memory Clear function has not completed
741 * 1 = Memory Clear function has completed
742 * [12:12] Exit Self-Refresh
743 * 0 = Exit from self-refresh done or not yet started
744 * 1 = DRAM exiting from self refresh
745 * [13:13] Self-Refresh Status
746 * 0 = Normal Operation
747 * 1 = Self-refresh mode active
748 * [15:14] Read/Write Queue Bypass Count
753 * [16:16] 128-bit/64-Bit
754 * 0 = 64bit Interface to DRAM
755 * 1 = 128bit Interface to DRAM
756 * [17:17] DIMM ECC Enable
757 * 0 = Some DIMMs do not have ECC
758 * 1 = ALL DIMMS have ECC bits
759 * [18:18] UnBuffered DIMMs
761 * 1 = Unbuffered DIMMS
762 * [19:19] Enable 32-Byte Granularity
763 * 0 = Optimize for 64byte bursts
764 * 1 = Optimize for 32byte bursts
765 * [20:20] DIMM 0 is x4
766 * [21:21] DIMM 1 is x4
767 * [22:22] DIMM 2 is x4
768 * [23:23] DIMM 3 is x4
770 * 1 = x4 DIMM present
771 * [24:24] Disable DRAM Receivers
772 * 0 = Receivers enabled
773 * 1 = Receivers disabled
775 * 000 = Arbiters chois is always respected
776 * 001 = Oldest entry in DCQ can be bypassed 1 time
777 * 010 = Oldest entry in DCQ can be bypassed 2 times
778 * 011 = Oldest entry in DCQ can be bypassed 3 times
779 * 100 = Oldest entry in DCQ can be bypassed 4 times
780 * 101 = Oldest entry in DCQ can be bypassed 5 times
781 * 110 = Oldest entry in DCQ can be bypassed 6 times
782 * 111 = Oldest entry in DCQ can be bypassed 7 times
785 PCI_ADDR(0, 0x18, 2, 0x90), 0xf0000000,
787 (0 << 23)|(0 << 22)|(0 << 21)|(0 << 20)|
788 (1 << 19)|(0 << 18)|(1 << 17)|(0 << 16)|
789 (2 << 14)|(0 << 13)|(0 << 12)|
790 (0 << 11)|(0 << 10)|(0 << 9)|(0 << 8)|
791 (0 << 3) |(0 << 1) |(0 << 0),
792 /* DRAM Config High Register
794 * [ 0: 3] Maximum Asynchronous Latency
799 * [11: 8] Read Preamble
817 * [18:16] Idle Cycle Limit
826 * [19:19] Dynamic Idle Cycle Center Enable
827 * 0 = Use Idle Cycle Limit
828 * 1 = Generate a dynamic Idle cycle limit
829 * [22:20] DRAM MEMCLK Frequency
839 * [25:25] Memory Clock Ratio Valid (FIXME carefully enable memclk)
840 * 0 = Disable MemClks
842 * [26:26] Memory Clock 0 Enable
845 * [27:27] Memory Clock 1 Enable
848 * [28:28] Memory Clock 2 Enable
851 * [29:29] Memory Clock 3 Enable
856 PCI_ADDR(0, 0x18, 2, 0x94), 0xc180f0f0,
857 (0 << 29)|(0 << 28)|(0 << 27)|(0 << 26)|(0 << 25)|
858 (0 << 20)|(0 << 19)|(DCH_IDLE_LIMIT_16 << 16)|(0 << 8)|(0 << 0),
859 /* DRAM Delay Line Register
861 * Adjust the skew of the input DQS strobe relative to DATA
863 * [23:16] Delay Line Adjust
864 * Adjusts the DLL derived PDL delay by one or more delay stages
865 * in either the faster or slower direction.
866 * [24:24} Adjust Slower
868 * 1 = Adj is used to increase the PDL delay
869 * [25:25] Adjust Faster
871 * 1 = Adj is used to decrease the PDL delay
874 PCI_ADDR(0, 0x18, 2, 0x98), 0xfc00ffff, 0x00000000,
875 /* DRAM Scrub Control Register
877 * [ 4: 0] DRAM Scrube Rate
879 * [12: 8] L2 Scrub Rate
881 * [20:16] Dcache Scrub
884 * 00000 = Do not scrub
906 * All Others = Reserved
908 PCI_ADDR(0, 0x18, 3, 0x58), 0xffe0e0e0, 0x00000000,
909 /* DRAM Scrub Address Low Register
911 * [ 0: 0] DRAM Scrubber Redirect Enable
913 * 1 = Scrubber Corrects errors found in normal operation
915 * [31: 6] DRAM Scrub Address 31-6
917 PCI_ADDR(0, 0x18, 3, 0x5C), 0x0000003e, 0x00000000,
918 /* DRAM Scrub Address High Register
920 * [ 7: 0] DRAM Scrubb Address 39-32
923 PCI_ADDR(0, 0x18, 3, 0x60), 0xffffff00, 0x00000000,
925 #if ENABLE_IOMMU != 0
926 /* BY LYH add IOMMU 64M APERTURE */
927 PCI_ADDR(0, 0x18, 3, 0x94), 0xffff8000, 0x00000f70,
928 PCI_ADDR(0, 0x18, 3, 0x90), 0xffffff80, 0x00000002,
929 PCI_ADDR(0, 0x18, 3, 0x98), 0x0000000f, 0x00068300,
934 print_debug("setting up CPU");
935 print_debug_hex8(ctrl->node_id);
936 print_debug(" northbridge registers\r\n");
937 max = sizeof(register_values)/sizeof(register_values[0]);
938 for(i = 0; i < max; i += 3) {
943 print_debug_hex32(register_values[i]);
945 print_debug_hex32(register_values[i+2]);
948 dev = (register_values[i] & ~0xff) - PCI_DEV(0, 0x18, 0) + ctrl->f0;
949 where = register_values[i] & 0xff;
950 reg = pci_read_config32(dev, where);
951 reg &= register_values[i+1];
952 reg |= register_values[i+2];
953 pci_write_config32(dev, where, reg);
956 reg = pci_read_config32(register_values[i]);
957 reg &= register_values[i+1];
958 reg |= register_values[i+2];
959 pci_write_config32(register_values[i], reg);
962 print_debug("done.\r\n");
966 static int is_dual_channel(const struct mem_controller *ctrl)
969 dcl = pci_read_config32(ctrl->f2, DRAM_CONFIG_LOW);
970 return dcl & DCL_128BitEn;
973 static int is_opteron(const struct mem_controller *ctrl)
975 /* Test to see if I am an Opteron.
976 * FIXME Testing dual channel capability is correct for now
977 * but a beter test is probably required.
979 #warning "FIXME implement a better test for opterons"
981 nbcap = pci_read_config32(ctrl->f3, NORTHBRIDGE_CAP);
982 return !!(nbcap & NBCAP_128Bit);
985 static int is_registered(const struct mem_controller *ctrl)
987 /* Test to see if we are dealing with registered SDRAM.
988 * If we are not registered we are unbuffered.
989 * This function must be called after spd_handle_unbuffered_dimms.
992 dcl = pci_read_config32(ctrl->f2, DRAM_CONFIG_LOW);
993 return !(dcl & DCL_UnBufDimm);
1001 static struct dimm_size spd_get_dimm_size(unsigned device)
1003 /* Calculate the log base 2 size of a DIMM in bits */
1004 struct dimm_size sz;
1009 /* Note it might be easier to use byte 31 here, it has the DIMM size as
1010 * a multiple of 4MB. The way we do it now we can size both
1011 * sides of an assymetric dimm.
1013 value = spd_read_byte(device, 3); /* rows */
1014 if (value < 0) goto out;
1015 sz.side1 += value & 0xf;
1017 value = spd_read_byte(device, 4); /* columns */
1018 if (value < 0) goto out;
1019 sz.side1 += value & 0xf;
1021 value = spd_read_byte(device, 17); /* banks */
1022 if (value < 0) goto out;
1023 sz.side1 += log2(value & 0xff);
1025 /* Get the module data width and convert it to a power of two */
1026 value = spd_read_byte(device, 7); /* (high byte) */
1027 if (value < 0) goto out;
1031 low = spd_read_byte(device, 6); /* (low byte) */
1032 if (low < 0) goto out;
1033 value = value | (low & 0xff);
1034 sz.side1 += log2(value);
1037 value = spd_read_byte(device, 5); /* number of physical banks */
1038 if (value <= 1) goto out;
1040 /* Start with the symmetrical case */
1041 sz.side2 = sz.side1;
1043 value = spd_read_byte(device, 3); /* rows */
1044 if (value < 0) goto out;
1045 if ((value & 0xf0) == 0) goto out; /* If symmetrical we are done */
1046 sz.side2 -= (value & 0x0f); /* Subtract out rows on side 1 */
1047 sz.side2 += ((value >> 4) & 0x0f); /* Add in rows on side 2 */
1049 value = spd_read_byte(device, 4); /* columns */
1050 if (value < 0) goto out;
1051 sz.side2 -= (value & 0x0f); /* Subtract out columns on side 1 */
1052 sz.side2 += ((value >> 4) & 0x0f); /* Add in columsn on side 2 */
1058 static void set_dimm_size(const struct mem_controller *ctrl, struct dimm_size sz, unsigned index)
1060 uint32_t base0, base1, map;
1064 print_debug("set_dimm_size: (");
1065 print_debug_hex32(sz.side1);
1066 print_debug_char(',');
1067 print_debug_hex32(sz.side2);
1068 print_debug_char(',');
1069 print_debug_hex32(index);
1070 print_debug(")\r\n");
1072 if (sz.side1 != sz.side2) {
1075 map = pci_read_config32(ctrl->f2, DRAM_BANK_ADDR_MAP);
1076 map &= ~(0xf << (index + 4));
1078 /* For each base register.
1079 * Place the dimm size in 32 MB quantities in the bits 31 - 21.
1080 * The initialize dimm size is in bits.
1081 * Set the base enable bit0.
1086 /* Make certain side1 of the dimm is at least 32MB */
1087 if (sz.side1 >= (25 +3)) {
1088 map |= (sz.side1 - (25 + 3)) << (index *4);
1089 base0 = (1 << ((sz.side1 - (25 + 3)) + 21)) | 1;
1091 /* Make certain side2 of the dimm is at least 32MB */
1092 if (sz.side2 >= (25 + 3)) {
1093 base1 = (1 << ((sz.side2 - (25 + 3)) + 21)) | 1;
1096 /* Double the size if we are using dual channel memory */
1097 if (is_dual_channel(ctrl)) {
1098 base0 = (base0 << 1) | (base0 & 1);
1099 base1 = (base1 << 1) | (base1 & 1);
1102 /* Clear the reserved bits */
1103 base0 &= ~0x001ffffe;
1104 base1 &= ~0x001ffffe;
1106 /* Set the appropriate DIMM base address register */
1107 pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1)+0)<<2), base0);
1108 pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1)+1)<<2), base1);
1109 pci_write_config32(ctrl->f2, DRAM_BANK_ADDR_MAP, map);
1111 /* Enable the memory clocks for this DIMM */
1113 dch = pci_read_config32(ctrl->f2, DRAM_CONFIG_HIGH);
1114 dch |= DCH_MEMCLK_EN0 << index;
1115 pci_write_config32(ctrl->f2, DRAM_CONFIG_HIGH, dch);
1119 static void spd_set_ram_size(const struct mem_controller *ctrl)
1123 for(i = 0; (i < 4) && (ctrl->channel0[i]); i++) {
1124 struct dimm_size sz;
1125 sz = spd_get_dimm_size(ctrl->channel0[i]);
1126 set_dimm_size(ctrl, sz, i);
1130 //BY LYH //Fill next base reg with right value
1131 static void fill_last(unsigned long node_id,unsigned long base)
1137 for(device = PCI_DEV(0, 0x18, 1); device <= PCI_DEV(0, 0x1f, 1); device
1138 += PCI_DEV(0, 1, 0)) {
1139 for(i=node_id+1;i<=7;i++) {
1140 base_reg=0x40+(i<<3);
1141 pci_write_config32(device,base_reg,base);
1147 static void route_dram_accesses(const struct mem_controller *ctrl,
1148 unsigned long base_k, unsigned long limit_k)
1150 /* Route the addresses to the controller node */
1155 unsigned limit_reg, base_reg;
1158 node_id = ctrl->node_id;
1159 index = (node_id << 3);
1160 limit = (limit_k << 2);
1161 limit &= 0xffff0000;
1162 limit -= 0x00010000;
1163 limit |= ( 0 << 8) | (node_id << 0);
1164 base = (base_k << 2);
1166 base |= (0 << 8) | (1<<1) | (1<<0);
1168 limit_reg = 0x44 + index;
1169 base_reg = 0x40 + index;
1170 for(device = PCI_DEV(0, 0x18, 1); device <= PCI_DEV(0, 0x1f, 1); device += PCI_DEV(0, 1, 0)) {
1171 pci_write_config32(device, limit_reg, limit);
1172 pci_write_config32(device, base_reg, base);
1176 static void set_top_mem(unsigned tom_k)
1178 /* Error if I don't have memory */
1184 /* Report the amount of memory. */
1185 print_debug("RAM: 0x");
1186 print_debug_hex32(tom_k);
1187 print_debug(" KB\r\n");
1190 /* Now set top of memory */
1192 msr.lo = (tom_k & 0x003fffff) << 10;
1193 msr.hi = (tom_k & 0xffc00000) >> 22;
1194 wrmsr(TOP_MEM2, msr);
1196 /* Leave a 64M hole between TOP_MEM and TOP_MEM2
1197 * so I can see my rom chip and other I/O devices.
1199 if (tom_k >= 0x003f0000) {
1202 msr.lo = (tom_k & 0x003fffff) << 10;
1203 msr.hi = (tom_k & 0xffc00000) >> 22;
1204 wrmsr(TOP_MEM, msr);
1207 static void order_dimms(const struct mem_controller *ctrl)
1209 unsigned long tom, tom_k, base_k;
1212 /* Compute the memory base address address */
1214 /* Remember which registers we have used in the high 8 bits of tom */
1217 /* Find the largest remaining canidate */
1218 unsigned index, canidate;
1219 uint32_t csbase, csmask;
1223 for(index = 0; index < 8; index++) {
1225 value = pci_read_config32(ctrl->f2, DRAM_CSBASE + (index << 2));
1227 /* Is it enabled? */
1232 /* Is it greater? */
1233 if (value <= csbase) {
1237 /* Has it already been selected */
1238 if (tom & (1 << (index + 24))) {
1241 /* I have a new canidate */
1245 /* See if I have found a new canidate */
1250 /* Remember the dimm size */
1251 size = csbase >> 21;
1253 /* Remember I have used this register */
1254 tom |= (1 << (canidate + 24));
1256 /* Recompute the cs base register value */
1257 csbase = (tom << 21) | 1;
1259 /* Increment the top of memory */
1262 /* Compute the memory mask */
1263 csmask = ((size -1) << 21);
1264 csmask |= 0xfe00; /* For now don't optimize */
1265 #warning "Don't forget to optimize the DIMM size"
1267 /* Write the new base register */
1268 pci_write_config32(ctrl->f2, DRAM_CSBASE + (canidate << 2), csbase);
1269 /* Write the new mask register */
1270 pci_write_config32(ctrl->f2, DRAM_CSMASK + (canidate << 2), csmask);
1273 tom_k = (tom & ~0xff000000) << 15;
1275 /* Compute the memory base address */
1277 for(node_id = 0; node_id < ctrl->node_id; node_id++) {
1278 uint32_t limit, base;
1280 index = node_id << 3;
1281 base = pci_read_config32(ctrl->f1, 0x40 + index);
1282 /* Only look at the limit if the base is enabled */
1283 if ((base & 3) == 3) {
1284 limit = pci_read_config32(ctrl->f1, 0x44 + index);
1285 base_k = ((limit + 0x00010000) & 0xffff0000) >> 2;
1290 print_debug("tom: ");
1291 print_debug_hex32(tom);
1292 print_debug(" base_k: ");
1293 print_debug_hex32(base_k);
1294 print_debug(" tom_k: ");
1295 print_debug_hex32(tom_k);
1296 print_debug("\r\n");
1298 route_dram_accesses(ctrl, base_k, tom_k);
1300 fill_last(ctrl->node_id, tom_k<<2);
1305 static void disable_dimm(const struct mem_controller *ctrl, unsigned index)
1307 print_debug("disabling dimm");
1308 print_debug_hex8(index);
1309 print_debug("\r\n");
1310 pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1)+0)<<2), 0);
1311 pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1)+1)<<2), 0);
1315 static void spd_handle_unbuffered_dimms(const struct mem_controller *ctrl)
1323 for(i = 0; (i < 4) && (ctrl->channel0[i]); i++) {
1325 value = spd_read_byte(ctrl->channel0[i], 21);
1327 disable_dimm(ctrl, i);
1330 /* Registered dimm ? */
1331 if (value & (1 << 1)) {
1334 /* Otherwise it must be an unbuffered dimm */
1339 if (unbuffered && registered) {
1340 die("Mixed buffered and registered dimms not supported");
1342 if (unbuffered && is_opteron(ctrl)) {
1343 die("Unbuffered Dimms not supported on Opteron");
1346 dcl = pci_read_config32(ctrl->f2, DRAM_CONFIG_LOW);
1347 dcl &= ~DCL_UnBufDimm;
1349 dcl |= DCL_UnBufDimm;
1351 pci_write_config32(ctrl->f2, DRAM_CONFIG_LOW, dcl);
1353 if (is_registered(ctrl)) {
1354 print_debug("Registered\r\n");
1356 print_debug("Unbuffered\r\n");
1361 static void spd_enable_2channels(const struct mem_controller *ctrl)
1365 /* SPD addresses to verify are identical */
1366 #warning "FINISHME review and see if these are the bytes I need"
1367 /* FINISHME review and see if these are the bytes I need */
1368 static const unsigned addresses[] = {
1369 2, /* Type should be DDR SDRAM */
1370 3, /* *Row addresses */
1371 4, /* *Column addresses */
1372 5, /* *Physical Banks */
1373 6, /* *Module Data Width low */
1374 7, /* *Module Data Width high */
1375 9, /* *Cycle time at highest CAS Latency CL=X */
1376 11, /* *SDRAM Type */
1377 13, /* *SDRAM Width */
1378 17, /* *Logical Banks */
1379 18, /* *Supported CAS Latencies */
1380 21, /* *SDRAM Module Attributes */
1381 23, /* *Cycle time at CAS Latnecy (CLX - 0.5) */
1382 26, /* *Cycle time at CAS Latnecy (CLX - 1.0) */
1383 27, /* *tRP Row precharge time */
1384 28, /* *Minimum Row Active to Row Active Delay (tRRD) */
1385 29, /* *tRCD RAS to CAS */
1386 30, /* *tRAS Activate to Precharge */
1387 41, /* *Minimum Active to Active/Auto Refresh Time(Trc) */
1388 42, /* *Minimum Auto Refresh Command Time(Trfc) */
1390 nbcap = pci_read_config32(ctrl->f3, NORTHBRIDGE_CAP);
1391 if (!(nbcap & NBCAP_128Bit)) {
1394 for(i = 0; (i < 4) && (ctrl->channel0[i]); i++) {
1395 unsigned device0, device1;
1398 device0 = ctrl->channel0[i];
1399 device1 = ctrl->channel1[i];
1402 for(j = 0; j < sizeof(addresses)/sizeof(addresses[0]); j++) {
1404 addr = addresses[j];
1405 value0 = spd_read_byte(device0, addr);
1409 value1 = spd_read_byte(device1, addr);
1413 if (value0 != value1) {
1418 print_debug("Enabling dual channel memory\r\n");
1420 dcl = pci_read_config32(ctrl->f2, DRAM_CONFIG_LOW);
1421 dcl &= ~DCL_32ByteEn;
1422 dcl |= DCL_128BitEn;
1423 pci_write_config32(ctrl->f2, DRAM_CONFIG_LOW, dcl);
1428 uint8_t divisor; /* In 1/2 ns increments */
1431 uint32_t dch_memclk;
1432 uint16_t dch_tref4k, dch_tref8k;
1437 static const struct mem_param *get_mem_param(unsigned min_cycle_time)
1439 static const struct mem_param speed[] = {
1441 .name = "100Mhz\r\n",
1443 .divisor = (10 <<1),
1446 .dch_memclk = DCH_MEMCLK_100MHZ << DCH_MEMCLK_SHIFT,
1447 .dch_tref4k = DTH_TREF_100MHZ_4K,
1448 .dch_tref8k = DTH_TREF_100MHZ_8K,
1452 .name = "133Mhz\r\n",
1454 .divisor = (7<<1)+1,
1457 .dch_memclk = DCH_MEMCLK_133MHZ << DCH_MEMCLK_SHIFT,
1458 .dch_tref4k = DTH_TREF_133MHZ_4K,
1459 .dch_tref8k = DTH_TREF_133MHZ_8K,
1463 .name = "166Mhz\r\n",
1468 .dch_memclk = DCH_MEMCLK_166MHZ << DCH_MEMCLK_SHIFT,
1469 .dch_tref4k = DTH_TREF_166MHZ_4K,
1470 .dch_tref8k = DTH_TREF_166MHZ_8K,
1474 .name = "200Mhz\r\n",
1479 .dch_memclk = DCH_MEMCLK_200MHZ << DCH_MEMCLK_SHIFT,
1480 .dch_tref4k = DTH_TREF_200MHZ_4K,
1481 .dch_tref8k = DTH_TREF_200MHZ_8K,
1488 const struct mem_param *param;
1489 for(param = &speed[0]; param->cycle_time ; param++) {
1490 if (min_cycle_time > (param+1)->cycle_time) {
1494 if (!param->cycle_time) {
1495 die("min_cycle_time to low");
1498 print_debug(param->name);
1503 static const struct mem_param *spd_set_memclk(const struct mem_controller *ctrl)
1505 /* Compute the minimum cycle time for these dimms */
1506 const struct mem_param *param;
1507 unsigned min_cycle_time, min_latency;
1511 static const int latency_indicies[] = { 26, 23, 9 };
1512 static const unsigned char min_cycle_times[] = {
1513 [NBCAP_MEMCLK_200MHZ] = 0x50, /* 5ns */
1514 [NBCAP_MEMCLK_166MHZ] = 0x60, /* 6ns */
1515 [NBCAP_MEMCLK_133MHZ] = 0x75, /* 7.5ns */
1516 [NBCAP_MEMCLK_100MHZ] = 0xa0, /* 10ns */
1520 value = pci_read_config32(ctrl->f3, NORTHBRIDGE_CAP);
1521 min_cycle_time = min_cycle_times[(value >> NBCAP_MEMCLK_SHIFT) & NBCAP_MEMCLK_MASK];
1525 print_debug("min_cycle_time: ");
1526 print_debug_hex8(min_cycle_time);
1527 print_debug(" min_latency: ");
1528 print_debug_hex8(min_latency);
1529 print_debug("\r\n");
1532 /* Compute the least latency with the fastest clock supported
1533 * by both the memory controller and the dimms.
1535 for(i = 0; (i < 4) && (ctrl->channel0[i]); i++) {
1536 int new_cycle_time, new_latency;
1541 /* First find the supported CAS latencies
1542 * Byte 18 for DDR SDRAM is interpreted:
1543 * bit 0 == CAS Latency = 1.0
1544 * bit 1 == CAS Latency = 1.5
1545 * bit 2 == CAS Latency = 2.0
1546 * bit 3 == CAS Latency = 2.5
1547 * bit 4 == CAS Latency = 3.0
1548 * bit 5 == CAS Latency = 3.5
1552 new_cycle_time = 0xa0;
1555 latencies = spd_read_byte(ctrl->channel0[i], 18);
1556 if (latencies <= 0) continue;
1558 /* Compute the lowest cas latency supported */
1559 latency = log2(latencies) -2;
1561 /* Loop through and find a fast clock with a low latency */
1562 for(index = 0; index < 3; index++, latency++) {
1564 if ((latency < 2) || (latency > 4) ||
1565 (!(latencies & (1 << latency)))) {
1568 value = spd_read_byte(ctrl->channel0[i], latency_indicies[index]);
1573 /* Only increase the latency if we decreas the clock */
1574 if ((value >= min_cycle_time) && (value < new_cycle_time)) {
1575 new_cycle_time = value;
1576 new_latency = latency;
1579 if (new_latency > 4){
1582 /* Does min_latency need to be increased? */
1583 if (new_cycle_time > min_cycle_time) {
1584 min_cycle_time = new_cycle_time;
1586 /* Does min_cycle_time need to be increased? */
1587 if (new_latency > min_latency) {
1588 min_latency = new_latency;
1592 print_debug_hex8(i);
1593 print_debug(" min_cycle_time: ");
1594 print_debug_hex8(min_cycle_time);
1595 print_debug(" min_latency: ");
1596 print_debug_hex8(min_latency);
1597 print_debug("\r\n");
1600 /* Make a second pass through the dimms and disable
1601 * any that cannot support the selected memclk and cas latency.
1604 for(i = 0; (i < 4) && (ctrl->channel0[i]); i++) {
1610 latencies = spd_read_byte(ctrl->channel0[i], 18);
1611 if (latencies <= 0) {
1615 /* Compute the lowest cas latency supported */
1616 latency = log2(latencies) -2;
1618 /* Walk through searching for the selected latency */
1619 for(index = 0; index < 3; index++, latency++) {
1620 if (!(latencies & (1 << latency))) {
1623 if (latency == min_latency)
1626 /* If I can't find the latency or my index is bad error */
1627 if ((latency != min_latency) || (index >= 3)) {
1631 /* Read the min_cycle_time for this latency */
1632 value = spd_read_byte(ctrl->channel0[i], latency_indicies[index]);
1634 /* All is good if the selected clock speed
1635 * is what I need or slower.
1637 if (value <= min_cycle_time) {
1640 /* Otherwise I have an error, disable the dimm */
1642 disable_dimm(ctrl, i);
1645 print_debug("min_cycle_time: ");
1646 print_debug_hex8(min_cycle_time);
1647 print_debug(" min_latency: ");
1648 print_debug_hex8(min_latency);
1649 print_debug("\r\n");
1651 /* Now that I know the minimum cycle time lookup the memory parameters */
1652 param = get_mem_param(min_cycle_time);
1654 /* Update DRAM Config High with our selected memory speed */
1655 value = pci_read_config32(ctrl->f2, DRAM_CONFIG_HIGH);
1656 value &= ~(DCH_MEMCLK_MASK << DCH_MEMCLK_SHIFT);
1657 value |= param->dch_memclk;
1658 pci_write_config32(ctrl->f2, DRAM_CONFIG_HIGH, value);
1660 static const unsigned latencies[] = { DTL_CL_2, DTL_CL_2_5, DTL_CL_3 };
1661 /* Update DRAM Timing Low with our selected cas latency */
1662 value = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW);
1663 value &= ~(DTL_TCL_MASK << DTL_TCL_SHIFT);
1664 value |= latencies[min_latency - 2] << DTL_TCL_SHIFT;
1665 pci_write_config32(ctrl->f2, DRAM_TIMING_LOW, value);
1671 static int update_dimm_Trc(const struct mem_controller *ctrl, const struct mem_param *param, int i)
1673 unsigned clocks, old_clocks;
1676 value = spd_read_byte(ctrl->channel0[i], 41);
1677 if (value < 0) return -1;
1678 if ((value == 0) || (value == 0xff)) {
1681 clocks = ((value << 1) + param->divisor - 1)/param->divisor;
1682 if (clocks < DTL_TRC_MIN) {
1683 clocks = DTL_TRC_MIN;
1685 if (clocks > DTL_TRC_MAX) {
1689 dtl = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW);
1690 old_clocks = ((dtl >> DTL_TRC_SHIFT) & DTL_TRC_MASK) + DTL_TRC_BASE;
1691 if (old_clocks > clocks) {
1692 clocks = old_clocks;
1694 dtl &= ~(DTL_TRC_MASK << DTL_TRC_SHIFT);
1695 dtl |= ((clocks - DTL_TRC_BASE) << DTL_TRC_SHIFT);
1696 pci_write_config32(ctrl->f2, DRAM_TIMING_LOW, dtl);
1700 static int update_dimm_Trfc(const struct mem_controller *ctrl, const struct mem_param *param, int i)
1702 unsigned clocks, old_clocks;
1705 value = spd_read_byte(ctrl->channel0[i], 42);
1706 if (value < 0) return -1;
1707 if ((value == 0) || (value == 0xff)) {
1708 value = param->tRFC;
1710 clocks = ((value << 1) + param->divisor - 1)/param->divisor;
1711 if (clocks < DTL_TRFC_MIN) {
1712 clocks = DTL_TRFC_MIN;
1714 if (clocks > DTL_TRFC_MAX) {
1717 dtl = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW);
1718 old_clocks = ((dtl >> DTL_TRFC_SHIFT) & DTL_TRFC_MASK) + DTL_TRFC_BASE;
1719 if (old_clocks > clocks) {
1720 clocks = old_clocks;
1722 dtl &= ~(DTL_TRFC_MASK << DTL_TRFC_SHIFT);
1723 dtl |= ((clocks - DTL_TRFC_BASE) << DTL_TRFC_SHIFT);
1724 pci_write_config32(ctrl->f2, DRAM_TIMING_LOW, dtl);
1729 static int update_dimm_Trcd(const struct mem_controller *ctrl, const struct mem_param *param, int i)
1731 unsigned clocks, old_clocks;
1734 value = spd_read_byte(ctrl->channel0[i], 29);
1735 if (value < 0) return -1;
1737 clocks = (value + (param->divisor << 1) -1)/(param->divisor << 1);
1739 clocks = (value + ((param->divisor & 0xff) << 1) -1)/((param->divisor & 0xff) << 1);
1741 if (clocks < DTL_TRCD_MIN) {
1742 clocks = DTL_TRCD_MIN;
1744 if (clocks > DTL_TRCD_MAX) {
1747 dtl = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW);
1748 old_clocks = ((dtl >> DTL_TRCD_SHIFT) & DTL_TRCD_MASK) + DTL_TRCD_BASE;
1749 if (old_clocks > clocks) {
1750 clocks = old_clocks;
1752 dtl &= ~(DTL_TRCD_MASK << DTL_TRCD_SHIFT);
1753 dtl |= ((clocks - DTL_TRCD_BASE) << DTL_TRCD_SHIFT);
1754 pci_write_config32(ctrl->f2, DRAM_TIMING_LOW, dtl);
1758 static int update_dimm_Trrd(const struct mem_controller *ctrl, const struct mem_param *param, int i)
1760 unsigned clocks, old_clocks;
1763 value = spd_read_byte(ctrl->channel0[i], 28);
1764 if (value < 0) return -1;
1765 clocks = (value + ((param->divisor & 0xff) << 1) -1)/((param->divisor & 0xff) << 1);
1766 if (clocks < DTL_TRRD_MIN) {
1767 clocks = DTL_TRRD_MIN;
1769 if (clocks > DTL_TRRD_MAX) {
1772 dtl = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW);
1773 old_clocks = ((dtl >> DTL_TRRD_SHIFT) & DTL_TRRD_MASK) + DTL_TRRD_BASE;
1774 if (old_clocks > clocks) {
1775 clocks = old_clocks;
1777 dtl &= ~(DTL_TRRD_MASK << DTL_TRRD_SHIFT);
1778 dtl |= ((clocks - DTL_TRRD_BASE) << DTL_TRRD_SHIFT);
1779 pci_write_config32(ctrl->f2, DRAM_TIMING_LOW, dtl);
1783 static int update_dimm_Tras(const struct mem_controller *ctrl, const struct mem_param *param, int i)
1785 unsigned clocks, old_clocks;
1788 value = spd_read_byte(ctrl->channel0[i], 30);
1789 if (value < 0) return -1;
1790 clocks = ((value << 1) + param->divisor - 1)/param->divisor;
1791 if (clocks < DTL_TRAS_MIN) {
1792 clocks = DTL_TRAS_MIN;
1794 if (clocks > DTL_TRAS_MAX) {
1797 dtl = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW);
1798 old_clocks = ((dtl >> DTL_TRAS_SHIFT) & DTL_TRAS_MASK) + DTL_TRAS_BASE;
1799 if (old_clocks > clocks) {
1800 clocks = old_clocks;
1802 dtl &= ~(DTL_TRAS_MASK << DTL_TRAS_SHIFT);
1803 dtl |= ((clocks - DTL_TRAS_BASE) << DTL_TRAS_SHIFT);
1804 pci_write_config32(ctrl->f2, DRAM_TIMING_LOW, dtl);
1808 static int update_dimm_Trp(const struct mem_controller *ctrl, const struct mem_param *param, int i)
1810 unsigned clocks, old_clocks;
1813 value = spd_read_byte(ctrl->channel0[i], 27);
1814 if (value < 0) return -1;
1816 clocks = (value + (param->divisor << 1) - 1)/(param->divisor << 1);
1818 clocks = (value + ((param->divisor & 0xff) << 1) - 1)/((param->divisor & 0xff) << 1);
1821 print_debug("Trp: ");
1822 print_debug_hex8(clocks);
1823 print_debug(" spd value: ");
1824 print_debug_hex8(value);
1825 print_debug(" divisor: ");
1826 print_debug_hex8(param->divisor);
1827 print_debug("\r\n");
1829 if (clocks < DTL_TRP_MIN) {
1830 clocks = DTL_TRP_MIN;
1832 if (clocks > DTL_TRP_MAX) {
1835 dtl = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW);
1836 old_clocks = ((dtl >> DTL_TRP_SHIFT) & DTL_TRP_MASK) + DTL_TRP_BASE;
1837 if (old_clocks > clocks) {
1838 clocks = old_clocks;
1840 dtl &= ~(DTL_TRP_MASK << DTL_TRP_SHIFT);
1841 dtl |= ((clocks - DTL_TRP_BASE) << DTL_TRP_SHIFT);
1842 pci_write_config32(ctrl->f2, DRAM_TIMING_LOW, dtl);
1846 static void set_Twr(const struct mem_controller *ctrl, const struct mem_param *param)
1849 dtl = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW);
1850 dtl &= ~(DTL_TWR_MASK << DTL_TWR_SHIFT);
1851 dtl |= (param->dtl_twr - DTL_TWR_BASE) << DTL_TWR_SHIFT;
1852 pci_write_config32(ctrl->f2, DRAM_TIMING_LOW, dtl);
1856 static void init_Tref(const struct mem_controller *ctrl, const struct mem_param *param)
1859 dth = pci_read_config32(ctrl->f2, DRAM_TIMING_HIGH);
1860 dth &= ~(DTH_TREF_MASK << DTH_TREF_SHIFT);
1861 dth |= (param->dch_tref4k << DTH_TREF_SHIFT);
1862 pci_write_config32(ctrl->f2, DRAM_TIMING_HIGH, dth);
1865 static int update_dimm_Tref(const struct mem_controller *ctrl, const struct mem_param *param, int i)
1869 unsigned tref, old_tref;
1870 value = spd_read_byte(ctrl->channel0[i], 3);
1871 if (value < 0) return -1;
1874 tref = param->dch_tref8k;
1876 tref = param->dch_tref4k;
1879 dth = pci_read_config32(ctrl->f2, DRAM_TIMING_HIGH);
1880 old_tref = (dth >> DTH_TREF_SHIFT) & DTH_TREF_MASK;
1881 if ((value == 12) && (old_tref == param->dch_tref4k)) {
1882 tref = param->dch_tref4k;
1884 tref = param->dch_tref8k;
1886 dth &= ~(DTH_TREF_MASK << DTH_TREF_SHIFT);
1887 dth |= (tref << DTH_TREF_SHIFT);
1888 pci_write_config32(ctrl->f2, DRAM_TIMING_HIGH, dth);
1893 static int update_dimm_x4(const struct mem_controller *ctrl, const struct mem_param *param, int i)
1898 value = spd_read_byte(ctrl->channel0[i], 13);
1903 dimm += DCL_x4DIMM_SHIFT;
1904 dcl = pci_read_config32(ctrl->f2, DRAM_CONFIG_LOW);
1905 dcl &= ~(1 << dimm);
1909 pci_write_config32(ctrl->f2, DRAM_CONFIG_LOW, dcl);
1913 static int update_dimm_ecc(const struct mem_controller *ctrl, const struct mem_param *param, int i)
1917 value = spd_read_byte(ctrl->channel0[i], 11);
1922 dcl = pci_read_config32(ctrl->f2, DRAM_CONFIG_LOW);
1923 dcl &= ~DCL_DimmEccEn;
1924 pci_write_config32(ctrl->f2, DRAM_CONFIG_LOW, dcl);
1929 static int count_dimms(const struct mem_controller *ctrl)
1934 for(index = 0; index < 8; index += 2) {
1936 csbase = pci_read_config32(ctrl->f2, (DRAM_CSBASE + index << 2));
1944 static void set_Twtr(const struct mem_controller *ctrl, const struct mem_param *param)
1948 clocks = 1; /* AMD says hard code this */
1949 dth = pci_read_config32(ctrl->f2, DRAM_TIMING_HIGH);
1950 dth &= ~(DTH_TWTR_MASK << DTH_TWTR_SHIFT);
1951 dth |= ((clocks - DTH_TWTR_BASE) << DTH_TWTR_SHIFT);
1952 pci_write_config32(ctrl->f2, DRAM_TIMING_HIGH, dth);
1955 static void set_Trwt(const struct mem_controller *ctrl, const struct mem_param *param)
1963 dtl = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW);
1964 latency = (dtl >> DTL_TCL_SHIFT) & DTL_TCL_MASK;
1965 divisor = param->divisor;
1967 if (is_opteron(ctrl)) {
1968 if (latency == DTL_CL_2) {
1969 if (divisor == ((6 << 0) + 0)) {
1973 else if (divisor > ((6 << 0)+0)) {
1974 /* 100Mhz && 133Mhz */
1978 else if (latency == DTL_CL_2_5) {
1981 else if (latency == DTL_CL_3) {
1982 if (divisor == ((6 << 0)+0)) {
1986 else if (divisor > ((6 << 0)+0)) {
1987 /* 100Mhz && 133Mhz */
1992 else /* Athlon64 */ {
1993 if (is_registered(ctrl)) {
1994 if (latency == DTL_CL_2) {
1997 else if (latency == DTL_CL_2_5) {
2000 else if (latency == DTL_CL_3) {
2004 else /* Unbuffered */{
2005 if (latency == DTL_CL_2) {
2008 else if (latency == DTL_CL_2_5) {
2011 else if (latency == DTL_CL_3) {
2016 if ((clocks < DTH_TRWT_MIN) || (clocks > DTH_TRWT_MAX)) {
2017 die("Unknown Trwt");
2020 dth = pci_read_config32(ctrl->f2, DRAM_TIMING_HIGH);
2021 dth &= ~(DTH_TRWT_MASK << DTH_TRWT_SHIFT);
2022 dth |= ((clocks - DTH_TRWT_BASE) << DTH_TRWT_SHIFT);
2023 pci_write_config32(ctrl->f2, DRAM_TIMING_HIGH, dth);
2027 static void set_Twcl(const struct mem_controller *ctrl, const struct mem_param *param)
2029 /* Memory Clocks after CAS# */
2032 if (is_registered(ctrl)) {
2037 dth = pci_read_config32(ctrl->f2, DRAM_TIMING_HIGH);
2038 dth &= ~(DTH_TWCL_MASK << DTH_TWCL_SHIFT);
2039 dth |= ((clocks - DTH_TWCL_BASE) << DTH_TWCL_SHIFT);
2040 pci_write_config32(ctrl->f2, DRAM_TIMING_HIGH, dth);
2044 static void set_read_preamble(const struct mem_controller *ctrl, const struct mem_param *param)
2048 unsigned rdpreamble;
2049 divisor = param->divisor;
2050 dch = pci_read_config32(ctrl->f2, DRAM_CONFIG_HIGH);
2051 dch &= ~(DCH_RDPREAMBLE_MASK << DCH_RDPREAMBLE_SHIFT);
2053 if (is_registered(ctrl)) {
2054 if (divisor == ((10 << 1)+0)) {
2056 rdpreamble = ((9 << 1)+ 0);
2058 else if (divisor == ((7 << 1)+1)) {
2060 rdpreamble = ((8 << 1)+0);
2062 else if (divisor == ((6 << 1)+0)) {
2064 rdpreamble = ((7 << 1)+1);
2071 for(i = 0; i < 4; i++) {
2072 if (ctrl->channel0[i]) {
2076 if (divisor == ((10 << 1)+0)) {
2080 rdpreamble = ((9 << 1)+0);
2083 rdpreamble = ((14 << 1)+0);
2086 else if (divisor == ((7 << 1)+1)) {
2090 rdpreamble = ((7 << 1)+0);
2093 rdpreamble = ((11 << 1)+0);
2096 else if (divisor == ((6 << 1)+0)) {
2100 rdpreamble = ((7 << 1)+0);
2103 rdpreamble = ((9 << 1)+0);
2106 else if (divisor == ((5 << 1)+0)) {
2110 rdpreamble = ((5 << 1)+0);
2113 rdpreamble = ((7 << 1)+0);
2117 if ((rdpreamble < DCH_RDPREAMBLE_MIN) || (rdpreamble > DCH_RDPREAMBLE_MAX)) {
2118 die("Unknown rdpreamble");
2120 dch |= (rdpreamble - DCH_RDPREAMBLE_BASE) << DCH_RDPREAMBLE_SHIFT;
2121 pci_write_config32(ctrl->f2, DRAM_CONFIG_HIGH, dch);
2124 static void set_max_async_latency(const struct mem_controller *ctrl, const struct mem_param *param)
2131 dimms = count_dimms(ctrl);
2133 dch = pci_read_config32(ctrl->f2, DRAM_CONFIG_HIGH);
2134 dch &= ~(DCH_ASYNC_LAT_MASK << DCH_ASYNC_LAT_SHIFT);
2136 if (is_registered(ctrl)) {
2148 die("Too many unbuffered dimms");
2150 else if (dimms == 3) {
2159 dch |= ((async_lat - DCH_ASYNC_LAT_BASE) << DCH_ASYNC_LAT_SHIFT);
2160 pci_write_config32(ctrl->f2, DRAM_CONFIG_HIGH, dch);
2163 static void set_idle_cycle_limit(const struct mem_controller *ctrl, const struct mem_param *param)
2166 /* AMD says to Hardcode this */
2167 dch = pci_read_config32(ctrl->f2, DRAM_CONFIG_HIGH);
2168 dch &= ~(DCH_IDLE_LIMIT_MASK << DCH_IDLE_LIMIT_SHIFT);
2169 dch |= DCH_IDLE_LIMIT_16 << DCH_IDLE_LIMIT_SHIFT;
2170 dch |= DCH_DYN_IDLE_CTR_EN;
2171 pci_write_config32(ctrl->f2, DRAM_CONFIG_HIGH, dch);
2174 static void spd_set_dram_timing(const struct mem_controller *ctrl, const struct mem_param *param)
2178 init_Tref(ctrl, param);
2179 for(i = 0; (i < 4) && ctrl->channel0[i]; i++) {
2181 /* DRAM Timing Low Register */
2182 if (update_dimm_Trc (ctrl, param, i) < 0) goto dimm_err;
2183 if (update_dimm_Trfc(ctrl, param, i) < 0) goto dimm_err;
2184 if (update_dimm_Trcd(ctrl, param, i) < 0) goto dimm_err;
2185 if (update_dimm_Trrd(ctrl, param, i) < 0) goto dimm_err;
2186 if (update_dimm_Tras(ctrl, param, i) < 0) goto dimm_err;
2187 if (update_dimm_Trp (ctrl, param, i) < 0) goto dimm_err;
2189 /* DRAM Timing High Register */
2190 if (update_dimm_Tref(ctrl, param, i) < 0) goto dimm_err;
2192 /* DRAM Config Low */
2193 if (update_dimm_x4 (ctrl, param, i) < 0) goto dimm_err;
2194 if (update_dimm_ecc(ctrl, param, i) < 0) goto dimm_err;
2197 disable_dimm(ctrl, i);
2200 /* DRAM Timing Low Register */
2201 set_Twr(ctrl, param);
2203 /* DRAM Timing High Register */
2204 set_Twtr(ctrl, param);
2205 set_Trwt(ctrl, param);
2206 set_Twcl(ctrl, param);
2208 /* DRAM Config High */
2209 set_read_preamble(ctrl, param);
2210 set_max_async_latency(ctrl, param);
2211 set_idle_cycle_limit(ctrl, param);
2214 static void sdram_set_spd_registers(const struct mem_controller *ctrl)
2216 const struct mem_param *param;
2217 spd_enable_2channels(ctrl);
2218 spd_set_ram_size(ctrl);
2219 spd_handle_unbuffered_dimms(ctrl);
2220 param = spd_set_memclk(ctrl);
2221 spd_set_dram_timing(ctrl, param);
2225 #define TIMEOUT_LOOPS 300000
2226 static void sdram_enable(int controllers, const struct mem_controller *ctrl)
2230 /* Before enabling memory start the memory clocks */
2231 for(i = 0; i < controllers; i++) {
2233 dch = pci_read_config32(ctrl[i].f2, DRAM_CONFIG_HIGH);
2234 dch |= DCH_MEMCLK_VALID;
2235 pci_write_config32(ctrl[i].f2, DRAM_CONFIG_HIGH, dch);
2238 /* And if necessary toggle the the reset on the dimms by hand */
2239 memreset(controllers, ctrl);
2241 for(i = 0; i < controllers; i++) {
2243 /* Toggle DisDqsHys to get it working */
2244 dcl = pci_read_config32(ctrl[i].f2, DRAM_CONFIG_LOW);
2246 print_debug("dcl: ");
2247 print_debug_hex32(dcl);
2248 print_debug("\r\n");
2250 #warning "FIXME set the ECC type to perform"
2251 #warning "FIXME initialize the scrub registers"
2253 if (dcl & DCL_DimmEccEn) {
2254 print_debug("ECC enabled\r\n");
2257 dcl |= DCL_DisDqsHys;
2258 pci_write_config32(ctrl[i].f2, DRAM_CONFIG_LOW, dcl);
2259 dcl &= ~DCL_DisDqsHys;
2260 dcl &= ~DCL_DLL_Disable;
2263 dcl |= DCL_DramInit;
2264 pci_write_config32(ctrl[i].f2, DRAM_CONFIG_LOW, dcl);
2267 for(i = 0; i < controllers; i++) {
2269 print_debug("Initializing memory: ");
2272 dcl = pci_read_config32(ctrl[i].f2, DRAM_CONFIG_LOW);
2274 if ((loops & 1023) == 0) {
2277 } while(((dcl & DCL_DramInit) != 0) && (loops < TIMEOUT_LOOPS));
2278 if (loops >= TIMEOUT_LOOPS) {
2279 print_debug(" failed\r\n");
2281 print_debug(" done\r\n");
2284 if (dcl & DCL_DimmEccEn) {
2285 print_debug("Clearing memory: ");
2287 dcl &= ~DCL_MemClrStatus;
2288 pci_write_config32(ctrl[i].f2, DRAM_CONFIG_LOW, dcl);
2291 dcl = pci_read_config32(ctrl[i].f2, DRAM_CONFIG_LOW);
2293 if ((loops & 1023) == 0) {
2295 print_debug_hex32(loops);
2297 } while(((dcl & DCL_MemClrStatus) == 0) && (loops < TIMEOUT_LOOPS));
2298 if (loops >= TIMEOUT_LOOPS) {
2299 print_debug("failed\r\n");
2301 print_debug("done\r\n");
2303 pci_write_config32(ctrl[i].f3, SCRUB_ADDR_LOW, 0);
2304 pci_write_config32(ctrl[i].f3, SCRUB_ADDR_HIGH, 0);