2 /* This was originally for the e7500, modified for i855pm
5 /* converted to C 6/2004 yhlu */
7 #define DEBUG_RAM_CONFIG 1
9 #define dumpnorth() dump_pci_device(PCI_DEV(0, 0, 0))
11 /* DDR DIMM Mode register Definitions */
13 #define BURST_2 (1<<0)
14 #define BURST_4 (2<<0)
15 #define BURST_8 (3<<0)
17 #define BURST_SEQUENTIAL (0<<3)
18 #define BURST_INTERLEAVED (1<<3)
20 #define CAS_2_0 (0x2<<4)
21 #define CAS_3_0 (0x3<<4)
22 #define CAS_1_5 (0x5<<4)
23 #define CAS_2_5 (0x6<<4)
25 #define MODE_NORM (0 << 7)
26 #define MODE_DLL_RESET (2 << 7)
27 #define MODE_TEST (1 << 7)
29 #define BURST_LENGTH BURST_4
30 #define BURST_TYPE BURST_INTERLEAVED
31 #define CAS_LATENCY CAS_2_0
32 //#define CAS_LATENCY CAS_2_5
33 //#define CAS_LATENCY CAS_1_5
35 #define MRS_VALUE (MODE_NORM | CAS_LATENCY | BURST_TYPE | BURST_LENGTH)
36 #define EMRS_VALUE 0x000
40 #define RAM_COMMAND_NONE 0x0
41 #define RAM_COMMAND_NOP 0x1
42 #define RAM_COMMAND_PRECHARGE 0x2
43 #define RAM_COMMAND_MRS 0x3
44 #define RAM_COMMAND_EMRS 0x4
45 #define RAM_COMMAND_CBR 0x6
46 #define RAM_COMMAND_NORMAL 0x7
49 static inline void do_ram_command (const struct mem_controller *ctrl, uint32_t value) {
54 #if DEBUG_RAM_CONFIG >= 2
56 print_debug_hex8(value);
59 /* %ecx - initial address to read from */
60 /* Compute the offset */
63 /* Set the ram command */
64 byte = pci_read_config8(ctrl->d0, 0x7c);
66 byte |= (uint8_t)(value & 0xff);
67 pci_write_config8(ctrl->d0, 0x7c, byte);
69 /* Assert the command to the memory */
70 #if DEBUG_RAM_CONFIG >= 2
72 print_debug_hex32(dword);
76 result = read32(dword);
78 /* Go to the next base address */
83 /* The command has been sent to all dimms so get out */
87 static inline void RAM_CMD(const struct mem_controller *ctrl, uint32_t command, uint32_t offset) {
88 uint32_t value = ((offset) << (MD_SHIFT + 16))|((command << 4) & 0x70) ;
89 do_ram_command(ctrl, value);
92 #define RAM_NOP(ctrl) RAM_CMD(ctrl, RAM_COMMAND_NOP, 0)
93 #define RAM_PRECHARGE(ctrl) RAM_CMD(ctrl, RAM_COMMAND_PRECHARGE, 0)
94 #define RAM_CBR(ctrl) RAM_CMD(ctrl, RAM_COMMAND_CBR, 0)
95 #define RAM_EMRS(ctrl) RAM_CMD(ctrl, RAM_COMMAND_EMRS, EMRS_VALUE)
97 static const uint8_t ram_cas_latency[] = {
98 CAS_2_5, CAS_2_0, CAS_1_5, CAS_2_5
101 static inline void ram_mrs(const struct mem_controller *ctrl, uint32_t value){
102 /* Read the cas latency setting */
105 byte = pci_read_config8(ctrl->d0, 0x78);
106 /* Transform it into the form expected by SDRAM */
107 dword = ram_cas_latency[(byte>>4) & 3];
109 value |= (dword<<(16+MD_SHIFT));
111 value |= (MODE_NORM | BURST_TYPE | BURST_LENGTH) << (16+MD_SHIFT);
113 do_ram_command(ctrl, value);
116 #define RAM_MRS(ctrl, dll_reset) ram_mrs( ctrl, (dll_reset << (8+MD_SHIFT+ 16)) | ((RAM_COMMAND_MRS <<4)& 0x70) )
118 static void RAM_NORMAL(const struct mem_controller *ctrl) {
120 byte = pci_read_config8(ctrl->d0, 0x7c);
122 byte |= (RAM_COMMAND_NORMAL << 4);
123 pci_write_config8(ctrl->d0, 0x7c, byte);
126 static void RAM_RESET_DDR_PTR(const struct mem_controller *ctrl) {
128 byte = pci_read_config8(ctrl->d0, 0x88);
130 pci_write_config8(ctrl->d0, 0x88, byte);
131 byte = pci_read_config8(ctrl->d0, 0x88);
133 pci_write_config8(ctrl->d0, 0x88, byte);
136 static void ENABLE_REFRESH(const struct mem_controller *ctrl)
139 dword = pci_read_config32(ctrl->d0, 0x7c);
141 pci_write_config32(ctrl->d0, 0x7c, dword);
145 * Table: constant_register_values
147 static const long register_values[] = {
148 /* SVID - Subsystem Vendor Identification Register
150 * [15:00] Subsytem Vendor ID (Indicates system board vendor)
152 /* SID - Subsystem Identification Register
154 * [15:00] Subsystem ID
156 0x2c, 0, (0x15d9 << 0) | (0x3580 << 16),
160 * This register has something to do with CAS latencies,
161 * possibily this is the real chipset control.
162 * At 0x00 CAS latency 1.5 works.
163 * At 0x06 CAS latency 2.5 works.
164 * At 0x01 CAS latency 2.0 works.
166 /* This is still undocumented in e7501, but with different values
167 * CAS 2.0 values taken from Intel BIOS settings, others are a guess
168 * and may be terribly wrong. Old values preserved as comments until I
169 * figure this out for sure.
170 * e7501 docs claim that CAS1.5 is unsupported, so it may or may not
172 * Steven James 02/06/2003
174 #if CAS_LATENCY == CAS_2_5
175 // 0x80, 0xfffffe00, 0x06 /* Intel E7500 recommended */
176 0x80, 0xfffff000, 0x0662, /* from Factory Bios */
177 #elif CAS_LATENCY == CAS_2_0
178 // 0x80, 0xfffffe00, 0x0d /* values for register 0x80 */
179 0x80, 0xfffff000, 0x0bb1, /* values for register 0x80 */
182 /* Enable periodic memory recalibration */
183 0x88, 0xffffff00, 0x80,
185 /* FDHC - Fixed DRAM Hole Control
188 * 0 == No memory Hole
189 * 1 == Memory Hole from 15MB to 16MB
192 * PAM - Programmable Attribute Map
193 * 0x59 [1:0] Reserved
194 * 0x59 [5:4] 0xF0000 - 0xFFFFF
195 * 0x5A [1:0] 0xC0000 - 0xC3FFF
196 * 0x5A [5:4] 0xC4000 - 0xC7FFF
197 * 0x5B [1:0] 0xC8000 - 0xCBFFF
198 * 0x5B [5:4] 0xCC000 - 0xCFFFF
199 * 0x5C [1:0] 0xD0000 - 0xD3FFF
200 * 0x5C [5:4] 0xD4000 - 0xD7FFF
201 * 0x5D [1:0] 0xD8000 - 0xDBFFF
202 * 0x5D [5:4] 0xDC000 - 0xDFFFF
203 * 0x5E [1:0] 0xE0000 - 0xE3FFF
204 * 0x5E [5:4] 0xE4000 - 0xE7FFF
205 * 0x5F [1:0] 0xE8000 - 0xEBFFF
206 * 0x5F [5:4] 0xEC000 - 0xEFFFF
207 * 00 == DRAM Disabled (All Access go to memory mapped I/O space)
208 * 01 == Read Only (Reads to DRAM, Writes to memory mapped I/O space)
209 * 10 == Write Only (Writes to DRAM, Reads to memory mapped I/O space)
210 * 11 == Normal (All Access go to DRAM)
212 0x58, 0xcccccf7f, (0x00 << 0) | (0x30 << 8) | (0x33 << 16) | (0x33 << 24),
213 0x5C, 0xcccccccc, (0x33 << 0) | (0x33 << 8) | (0x33 << 16) | (0x33 << 24),
215 /* DRB - DRAM Row Boundary Registers
217 * An array of 8 byte registers, which hold the ending
218 * memory address assigned to each pair of DIMMS, in 64MB
221 /* Conservatively say each row has 64MB of ram, we will fix this up later */
222 0x60, 0x00000000, (0x01 << 0) | (0x02 << 8) | (0x03 << 16) | (0x04 << 24),
223 0x64, 0x00000000, (0x05 << 0) | (0x06 << 8) | (0x07 << 16) | (0x08 << 24),
227 /* DRA - DRAM Row Attribute Register
232 * [7:7] Device width for Odd numbered rows
233 * 0 == 8 bits wide x8
234 * 1 == 4 bits wide x4
235 * [6:4] Row Attributes for Odd numbered rows
241 * [3:3] Device width for Even numbered rows
242 * 0 == 8 bits wide x8
243 * 1 == 4 bits wide x4
244 * [2:0] Row Attributes for Even numbered rows
248 * 101 == 64KB (This page size appears broken)
252 (((0<<3)|(0<<0))<< 0) |
253 (((0<<3)|(0<<0))<< 4) |
254 (((0<<3)|(0<<0))<< 8) |
255 (((0<<3)|(0<<0))<<12) |
256 (((0<<3)|(0<<0))<<16) |
257 (((0<<3)|(0<<0))<<20) |
258 (((0<<3)|(0<<0))<<24) |
259 (((0<<3)|(0<<0))<<28),
262 /* DRT - DRAM Time Register
265 * [29:29] Back to Back Write-Read Turn Around
266 * 0 == 3 clocks between WR-RD commands
267 * 1 == 2 clocks between WR-RD commands
268 * [28:28] Back to Back Read-Write Turn Around
269 * 0 == 5 clocks between RD-WR commands
270 * 1 == 4 clocks between RD-WR commands
271 * [27:27] Back to Back Read Turn Around
272 * 0 == 4 clocks between RD commands
273 * 1 == 3 clocks between RD commands
274 * [26:24] Read Delay (tRD)
280 * [18:16] DRAM idle timer
282 * 011 == 16 dram clocks
283 * 001 == Datasheet says reserved, but Intel BIOS sets it
285 * [10:09] Active to Precharge (tRAS)
291 * [05:04] Cas Latency (tCL)
296 * [03:03] Write Ras# to Cas# Delay (tRCD)
299 * [02:01] Read RAS# to CAS# Delay (tRCD)
302 * 10 == 3 DRAM Clocks
303 * 11 == 2 DRAM Clocks
304 * [00:00] DRAM RAS# to Precharge (tRP)
308 #define DRT_CAS_2_5 (0<<4)
309 #define DRT_CAS_2_0 (1<<4)
310 #define DRT_CAS_1_5 (2<<4)
311 #define DRT_CAS_MASK (3<<4)
313 #if CAS_LATENCY == CAS_2_5
314 #define DRT_CL DRT_CAS_2_5
315 #elif CAS_LATENCY == CAS_2_0
316 #define DRT_CL DRT_CAS_2_0
317 #elif CAS_LATENCY == CAS_1_5
318 #define DRT_CL DRT_CAS_1_5
321 /* Most aggressive settings possible */
322 // 0x78, 0xc0fff8c4, (1<<29)|(1<<28)|(1<<27)|(2<<24)|(2<<9)|DRT_CL|(1<<3)|(1<<1)|(1<<0),
323 // 0x78, 0xc0f8f8c0, (1<<29)|(1<<28)|(1<<27)|(1<<24)|(1<<16)|(2<<9)|DRT_CL|(1<<3)|(3<<1)|(1<<0),
324 0x78, 0xc0f8f9c0, (1<<29)|(1<<28)|(1<<27)|(1<<24)|(1<<16)|(2<<9)|DRT_CL|(1<<3)|(3<<1)|(1<<0),
326 /* FIXME why was I attempting to set a reserved bit? */
329 /* DRC - DRAM Contoller Mode Register
332 * [29:29] Initialization Complete
337 * 0 == Single channel
339 * [21:20] DRAM Data Integrity Mode
340 * 00 == Disabled, no ECC
342 * 10 == Error checking, using chip-kill, with correction
346 * [17:17] (Intel Undocumented) should always be set to 1
347 * [16:16] Command Per Clock - Address/Control Assertion Rule (CPC)
351 * [10:08] Refresh mode select
352 * 000 == Refresh disabled
353 * 001 == Refresh interval 15.6 usec
354 * 010 == Refresh interval 7.8 usec
355 * 011 == Refresh interval 64 usec
356 * 111 == Refresh every 64 clocks (fast refresh)
358 * [06:04] Mode Select (SMS)
359 * 000 == Self Refresh Mode
361 * 010 == All Banks Precharge
362 * 011 == Mode Register Set
363 * 100 == Extended Mode Register Set
366 * 111 == Normal Operation
369 // .long 0x7c, 0xffcefcff, (1<<22)|(2 << 20)|(1 << 16)| (0 << 8),
370 // .long 0x7c, 0xff8cfcff, (1<<22)|(2 << 20)|(1 << 17)|(1 << 16)| (0 << 8),
371 // .long 0x7c, 0xff80fcff, (1<<22)|(2 << 20)|(1 << 18)|(1 << 17)|(1 << 16)| (0 << 8),
372 0x7c, 0xff82fcff, (1<<22)|(2 << 20)|(1 << 18)|(1 << 16)| (0 << 8),
375 /* Another Intel undocumented register */
376 0x88, 0x080007ff, (1<<31)|(1 << 30)|(1<<28)|(0 << 26)|(0x10 << 21)|(10 << 16)|(0x13 << 11),
378 /* CLOCK_DIS - CK/CK# Disable Register
394 0x8C, 0xfffffff0, 0xf,
396 /* TOLM - Top of Low Memory Register
398 * [15:11] Top of low memory (TOLM)
399 * The address below 4GB that should be treated as RAM,
400 * on a 128MB granularity.
403 /* REMAPBASE - Remap Base Address Regsiter
406 * [09:00] Remap Base Address [35:26] 64M aligned
407 * Bits [25:0] are assumed to be 0.
409 0xc4, 0xfc0007ff, (0x2000 << 0) | (0x3ff << 16),
410 /* REMAPLIMIT - Remap Limit Address Register
413 * [09:00] Remap Limit Address [35:26] 64M aligned
414 * When remaplimit < remapbase this register is disabled.
418 /* DVNP - Device Not Present Register
421 * [04:04] Device 4 Function 1 Present
424 * [03:03] Device 3 Function 1 Present
427 * [02:02] Device 2 Function 1 Present
431 * [00:00] Device 0 Function 1 Present
435 0xe0, 0xffffffe2, (1<<4)|(1<<3)|(1<<2)|(0<<0),
436 0xd8, 0xffff9fff, 0x00000000,
437 0xf4, 0x3f8ffffd, 0x40300002,
438 0x1050, 0xffffffcf, 0x00000030,
443 * Routine: ram_set_registers
446 * Trashed: %eax, %ebx, %ecx, %edx, %esi, %eflags
447 * Effects: Do basic ram setup that does not depend on serial
448 * presence detect information.
449 * This sets PCI configuration registers to known good
450 * values based on the table:
451 * constant_register_values
452 * Which are a triple of configuration regiser, mask, and value.
455 /* from 1M or 512K */
456 #define RCOMP_MMIO 0x100000
458 /* DDR RECOMP table */
460 static const long ddr_rcomp_1[] = {
461 0x44332211, 0xc9776655, 0xffffffff, 0xffffffff,
462 0x22111111, 0x55444332, 0xfffca876, 0xffffffff,
464 static const long ddr_rcomp_2[] = {
465 0x00000000, 0x76543210, 0xffffeca8, 0xffffffff,
466 0x21000000, 0xa8765432, 0xffffffec, 0xffffffff,
468 static const long ddr_rcomp_3[] = {
469 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
470 0x88888888, 0x88888888, 0x88888888, 0x88888888,
473 #define rcomp_init_str "Setting RCOMP registers.\r\n"
475 static void write_8dwords(uint32_t src_addr, uint32_t dst_addr) {
479 dword = read32(src_addr);
480 write32(dst_addr, dword);
487 //#define SLOW_DOWN_IO inb(0x80);
488 #define SLOW_DOWN_IO udelay(40);
490 static void ram_set_rcomp_regs(const struct mem_controller *ctrl) {
493 print_debug(rcomp_init_str);
496 /*enable access to the rcomp bar */
497 dword = pci_read_config32(ctrl->d0, 0x0f4);
499 dword |=((1<<30)|1<<22);
500 pci_write_config32(ctrl->d0, 0x0f4, dword);
503 /* Set the MMIO address to 512K */
504 pci_write_config32(ctrl->d0, 0x14, RCOMP_MMIO);
506 dword = read32(RCOMP_MMIO + 0x20);
508 write32(RCOMP_MMIO + 0x20, dword);
511 /* Begin to write the RCOMP registers */
513 write8(RCOMP_MMIO + 0x2c, 0xff);
514 write32(RCOMP_MMIO + 0x30, 0x01040444);
515 write8(RCOMP_MMIO + 0x34, 0x04);
516 write32(RCOMP_MMIO + 0x40, 0);
517 write16(RCOMP_MMIO + 0x44, 0);
518 write16(RCOMP_MMIO + 0x48, 0);
519 write16(RCOMP_MMIO + 0x50, 0);
520 write_8dwords((uint32_t)ddr_rcomp_1, RCOMP_MMIO + 0x60);
521 write_8dwords((uint32_t)ddr_rcomp_2, RCOMP_MMIO + 0x80);
522 write_8dwords((uint32_t)ddr_rcomp_2, RCOMP_MMIO + 0xa0);
523 write_8dwords((uint32_t)ddr_rcomp_2, RCOMP_MMIO + 0x140);
524 write_8dwords((uint32_t)ddr_rcomp_2, RCOMP_MMIO + 0x1c0);
525 write_8dwords((uint32_t)ddr_rcomp_3, RCOMP_MMIO + 0x180);
527 #if 0 /* Print the RCOMP registers */
528 movl $RCOMP_MMIO, %ecx
532 CONSOLE_INFO_TX_CHAR($'\r')
533 CONSOLE_INFO_TX_CHAR($'\n')
534 CONSOLE_INFO_TX_HEX32(%ecx)
535 CONSOLE_INFO_TX_CHAR($' ')
536 CONSOLE_INFO_TX_CHAR($'-')
537 CONSOLE_INFO_TX_CHAR($' ')
539 CONSOLE_INFO_TX_HEX32(%eax)
540 CONSOLE_INFO_TX_CHAR($' ')
542 cmpl $(RCOMP_MMIO + 0x1e0), %ecx
544 CONSOLE_INFO_TX_CHAR($'\r')
545 CONSOLE_INFO_TX_CHAR($'\n')
548 dword = read32(RCOMP_MMIO + 0x20);
551 write32(RCOMP_MMIO + 0x20, dword);
556 /* unblock updates */
557 dword = read32(RCOMP_MMIO + 0x20);
559 write32(RCOMP_MMIO+0x20, dword);
561 write32(RCOMP_MMIO+0x20, dword);
563 write32(RCOMP_MMIO+0x20, dword);
568 /*disable access to the rcomp bar */
569 dword = pci_read_config32(ctrl->d0, 0x0f4);
571 pci_write_config32(ctrl->d0, 0x0f4, dword);
575 static void ram_set_d0f0_regs(const struct mem_controller *ctrl) {
581 max = sizeof(register_values)/sizeof(register_values[0]);
582 for(i = 0; i < max; i += 3) {
585 print_debug_hex32(register_values[i]);
587 print_debug_hex32(register_values[i+2]);
590 reg = pci_read_config32(ctrl->d0,register_values[i]);
591 reg &= register_values[i+1];
592 reg |= register_values[i+2] & ~(register_values[i+1]);
593 pci_write_config32(ctrl->d0,register_values[i], reg);
601 static void sdram_set_registers(const struct mem_controller *ctrl){
602 ram_set_rcomp_regs(ctrl);
603 ram_set_d0f0_regs(ctrl);
608 * Routine: sdram_spd_get_page_size
609 * Arguments: %bl SMBUS_MEM_DEVICE
611 * %edi log base 2 page size of DIMM side 1 in bits
612 * %esi log base 2 page size of DIMM side 2 in bits
614 * Preserved: %ebx (except %bh), %ebp
616 * Trashed: %eax, %bh, %ecx, %edx, %esp, %eflags
617 * Used: %eax, %ebx, %ecx, %edx, %esi, %edi, %esp, %eflags
619 * Effects: Uses serial presence detect to set %edi & %esi
620 * to the page size of a dimm.
622 * %bl SMBUS_MEM_DEVICE
623 * %edi holds the page size for the first side of the DIMM.
624 * %esi holds the page size for the second side of the DIMM.
625 * memory size is represent as a power of 2.
627 * This routine may be worth moving into generic code somewhere.
629 struct dimm_page_size {
634 static struct dimm_page_size sdram_spd_get_page_size(unsigned device) {
638 struct dimm_page_size pgsz;
643 value = spd_read_byte(device, 4); /* columns */
644 if(value < 0) goto hw_err;
645 pgsz.side1 = value & 0xf;
647 /* Get the module data width and convert it to a power of two */
648 value = spd_read_byte(device,7); /* (high byte) */
649 if(value < 0) goto hw_err;
653 value = spd_read_byte(device, 6); /* (low byte) */
654 if(value < 0) goto hw_err;
655 ecx |= (value & 0xff);
657 pgsz.side1 += log2(ecx); /* compute cheap log base 2 */
660 value = spd_read_byte(device, 5); /* number of physical banks */
661 if(value < 0) goto hw_err;
662 if(value==1) goto out;
663 if(value!=2) goto val_err;
665 /* Start with the symmetrical case */
666 pgsz.side2 = pgsz.side1;
667 value = spd_read_byte(device,4); /* columns */
668 if(value < 0) goto hw_err;
669 if((value & 0xf0)==0 ) goto out;
670 pgsz.side2 -=value & 0xf; /* Subtract out columns on side 1 */
671 pgsz.side2 +=(value>>4)& 0xf; /* Add in columns on side 2 */
675 die("Bad SPD value\r\n");
676 /* If an hw_error occurs report that I have no memory */
686 * Routine: sdram_spd_get_width
687 * Arguments: %bl SMBUS_MEM_DEVICE
689 * %edi width of SDRAM chips on DIMM side 1 in bits
690 * %esi width of SDRAM chips on DIMM side 2 in bits
692 * Preserved: %ebx (except %bh), %ebp
694 * Trashed: %eax, %bh, %ecx, %edx, %esp, %eflags
695 * Used: %eax, %ebx, %ecx, %edx, %esi, %edi, %esp, %eflags
697 * Effects: Uses serial presence detect to set %edi & %esi
698 * to the width of a dimm.
700 * %bl SMBUS_MEM_DEVICE
701 * %edi holds the width for the first side of the DIMM.
702 * %esi holds the width for the second side of the DIMM.
703 * memory size is represent as a power of 2.
705 * This routine may be worth moving into generic code somewhere.
712 static struct dimm_width sdram_spd_get_width(unsigned device) {
714 struct dimm_width wd;
720 value = spd_read_byte(device, 13); /* sdram width */
721 if(value < 0 ) goto hw_err;
724 wd.side1 = value & 0x7f;
727 value = spd_read_byte(device, 5); /* number of physical banks */
728 if(value < 0 ) goto hw_err;
729 if(value <=1 ) goto out;
731 /* Start with the symmetrical case */
734 if((ecx & 0x80)==0) goto out;
746 * Routine: sdram_spd_get_dimm_size
747 * Arguments: %bl SMBUS_MEM_DEVICE
749 * %edi log base 2 size of DIMM side 1 in bits
750 * %esi log base 2 size of DIMM side 2 in bits
752 * Preserved: %ebx (except %bh), %ebp
754 * Trashed: %eax, %bh, %ecx, %edx, %esp, %eflags
755 * Used: %eax, %ebx, %ecx, %edx, %esi, %edi, %esp, %eflags
757 * Effects: Uses serial presence detect to set %edi & %esi
758 * the size of a dimm.
760 * %bl SMBUS_MEM_DEVICE
761 * %edi holds the memory size for the first side of the DIMM.
762 * %esi holds the memory size for the second side of the DIMM.
763 * memory size is represent as a power of 2.
765 * This routine may be worth moving into generic code somewhere.
773 static struct dimm_size spd_get_dimm_size(unsigned device)
775 /* Calculate the log base 2 size of a DIMM in bits */
781 /* Note it might be easier to use byte 31 here, it has the DIMM size as
782 * a multiple of 4MB. The way we do it now we can size both
783 * sides of an assymetric dimm.
785 value = spd_read_byte(device, 3); /* rows */
786 if (value < 0) goto hw_err;
787 // if ((value & 0xf) == 0) goto val_err;
788 sz.side1 += value & 0xf;
790 value = spd_read_byte(device, 4); /* columns */
791 if (value < 0) goto hw_err;
792 // if ((value & 0xf) == 0) goto val_err;
793 sz.side1 += value & 0xf;
795 value = spd_read_byte(device, 17); /* banks */
796 if (value < 0) goto hw_err;
797 // if ((value & 0xff) == 0) goto val_err;
799 sz.side1 += log2(value);
801 /* Get the module data width and convert it to a power of two */
802 value = spd_read_byte(device, 7); /* (high byte) */
803 if (value < 0) goto hw_err;
807 low = spd_read_byte(device, 6); /* (low byte) */
808 if (low < 0) goto hw_err;
809 value |= (low & 0xff);
810 // if ((value != 72) && (value != 64)) goto val_err;
811 sz.side1 += log2(value);
814 value = spd_read_byte(device, 5); /* number of physical banks */
815 if (value < 0) goto hw_err;
816 if (value == 1) goto out;
817 // if (value != 2) goto val_err;
819 /* Start with the symmetrical case */
822 value = spd_read_byte(device, 3); /* rows */
823 if (value < 0) goto hw_err;
824 if ((value & 0xf0) == 0) goto out; /* If symmetrical we are done */
825 sz.side2 -= (value & 0x0f); /* Subtract out rows on side 1 */
826 sz.side2 += ((value >> 4) & 0x0f); /* Add in rows on side 2 */
828 value = spd_read_byte(device, 4); /* columns */
829 if (value < 0) goto hw_err;
830 // if ((value & 0xff) == 0) goto val_err;
831 sz.side2 -= (value & 0x0f); /* Subtract out columns on side 1 */
832 sz.side2 += ((value >> 4) & 0x0f); /* Add in columsn on side 2 */
836 die("Bad SPD value\r\n");
837 /* If an hw_error occurs report that I have no memory */
848 * This is a place holder fill this out
849 * Routine: spd_set_row_attributes
850 * Arguments: %bl SMBUS_MEM_DEVICE
852 * %edi log base 2 size of DIMM side 1 in bits
853 * %esi log base 2 size of DIMM side 2 in bits
855 * Preserved: %ebx (except %bh), %ebp
857 * Trashed: %eax, %bh, %ecx, %edx, %esp, %eflags
858 * Used: %eax, %ebx, %ecx, %edx, %esi, %edi, %esp, %eflags
860 * Effects: Uses serial presence detect to set %edi & %esi
861 * the size of a dimm.
863 * %bl SMBUS_MEM_DEVICE
864 * %edi holds the memory size for the first side of the DIMM.
865 * %esi holds the memory size for the second side of the DIMM.
866 * memory size is represent as a power of 2.
868 * This routine may be worth moving into generic code somewhere.
870 static long spd_set_row_attributes(const struct mem_controller *ctrl, long dimm_mask) {
876 /* Walk through all dimms and find the interesection of the support
877 * for ecc sdram and refresh rates
881 for(i = 0; i < DIMM_SOCKETS; i++) {
882 if (!(dimm_mask & (1 << i))) {
885 /* Test to see if I have ecc sdram */
886 struct dimm_page_size sz;
887 sz = sdram_spd_get_page_size(ctrl->channel0[i]); /* SDRAM type */
889 print_debug("page size =");
890 print_debug_hex32(sz.side1);
892 print_debug_hex32(sz.side2);
896 /* Test to see if the dimm is present */
899 /* Test for a valid dimm width */
900 if((sz.side1 <15) || (sz.side1>18) ) {
901 print_err("unsupported page size\r\n");
904 /* double because I have 2 channels */
907 /* Convert to the format needed for the DRA register */
910 /* Place in the %ebp the dra place holder */ //i
911 dword |= sz.side1<<(i<<3);
913 /* Test to see if the second side is present */
917 /* Test for a valid dimm width */
918 if((sz.side2 <15) || (sz.side2>18) ) {
919 print_err("unsupported page size\r\n");
922 /* double because I have 2 channels */
925 /* Convert to the format needed for the DRA register */
928 /* Place in the %ebp the dra place holder */ //i
929 dword |= sz.side2<<((i<<3) + 4 );
934 /* Now add the SDRAM chip width to the DRA */
935 struct dimm_width wd;
936 wd = sdram_spd_get_width(ctrl->channel0[i]);
939 print_debug("width =");
940 print_debug_hex32(wd.side1);
942 print_debug_hex32(wd.side2);
946 if(wd.side1 == 0) continue;
948 /* Enable an x4 device */
949 dword |= 0x08 << (i<<3);
952 if(wd.side2 == 0) continue;
954 /* Enable an x4 device */
955 dword |= 0x08 << ((i<<3 ) + 4);
958 /* go to the next DIMM */
961 /* Write the new row attributes register */
962 pci_write_config32(ctrl->d0, 0x70, dword);
969 * Routine: sdram_read_paired_byte
970 * Arguments: %esp return address
971 * %bl device on the smbus to read from
972 * %bh address on the smbus to read
980 * Preserved: %ebx, %esi, %edi
982 * Trashed: %eax, %ecx, %edx, %ebp, %esp, %eflags
983 * Used: %eax, %ebx, %ecx, %edx, %esp, %eflags
985 * Effects: Reads two spd bytes from both ram channesl
986 * and errors if they are not equal.
987 * It then returns the equal result.
989 static spd_read_paired_byte () {
991 CALLSP(smbus_read_byte)
994 addb $(SMBUS_MEM_CHANNEL_OFF), %bl
995 CALLSP(smbus_read_byte)
998 subb $(SMBUS_MEM_CHANNEL_OFF), %bl
1000 /* See if dimms on both sides are equally present */
1002 jne sdram_presence_mismatch
1004 /* Leave if I have no data */
1006 jz spd_verify_byte_out
1008 /* Verify the data is identical */
1010 jne sdram_value_mismatch
1012 /* Clear the zero flag */
1014 spd_verify_byte_out:
1020 * Routine: spd_verify_dimms
1024 * Trashed: %eax, %ebx, %ecx, %edx, %ebp, %esi, %edi, %esp, %eflags
1025 * Used: %eax, %ebx, %ecx, %edx, %ebp, %esi, %edi, %esp, %eflags
1028 * - Verify all interesting spd information
1029 * matches for both dimm channels.
1030 * - Additional error checks that can be easily done
1031 * here are computed as well, so I don't need to
1032 * worry about them later.
1034 static spd_verify_dimms() {
1035 movl $(SMBUS_MEM_DEVICE_START), %ebx
1037 /* Verify this is DDR SDRAM */
1039 CALLSP(spd_read_paired_byte)
1040 jz spd_verify_next_dimm
1042 jne invalid_dimm_type
1044 /* Verify the row addresses */
1046 CALLSP(spd_read_paired_byte)
1051 /* Column addresses */
1053 CALLSP(spd_read_paired_byte)
1058 /* Physical Banks */
1060 CALLSP(spd_read_paired_byte)
1067 /* Module Data Width */
1069 CALLSP(spd_read_paired_byte)
1072 jne spd_invalid_data
1075 CALLSP(spd_read_paired_byte)
1081 jmp spd_unsupported_data
1084 /* Cycle time at highest CAS latency CL=X */
1086 CALLSP(spd_read_paired_byte)
1091 CALLSP(spd_read_paired_byte)
1094 /* Refresh Interval */
1096 CALLSP(spd_read_paired_byte)
1101 CALLSP(spd_read_paired_byte)
1108 jmp spd_unsupported_data
1111 /* Back-to-Back Random Column Accesses */
1113 CALLSP(spd_read_paired_byte)
1118 ja spd_unsupported_data
1122 CALLSP(spd_read_paired_byte)
1125 jz spd_unsupported_data
1129 CALLSP(spd_read_paired_byte)
1134 /* Supported CAS Latencies */
1136 CALLSP(spd_read_paired_byte)
1138 testb $(1 << 1), %al /* CL 1.5 */
1140 testb $(1 << 2), %al /* CL 2.0 */
1142 testb $(1 << 3), %al /* CL 2.5 */
1144 jmp spd_unsupported_data
1147 /* Cycle time at Cas Latency (CLX - 0.5) */
1149 CALLSP(spd_read_paired_byte)
1152 /* Cycle time at Cas Latency (CLX - 1.0) */
1154 CALLSP(spd_read_paired_byte)
1157 /* tRP Row precharge time */
1159 CALLSP(spd_read_paired_byte)
1165 /* tRCD RAS to CAS */
1167 CALLSP(spd_read_paired_byte)
1172 /* tRAS Activate to Precharge */
1174 CALLSP(spd_read_paired_byte)
1179 /* Module Bank Density */
1181 CALLSP(spd_read_paired_byte)
1183 testb $(1<<2), %al /* 16MB */
1184 jnz spd_unsupported_data
1186 jnz spd_unsupported_data /* 32MB */
1188 /* Address and Command Hold Time After Clock */
1190 CALLSP(spd_read_paired_byte)
1193 spd_verify_next_dimm:
1194 /* go to the next DIMM */
1195 addb $(SMBUS_MEM_DEVICE_INC), %bl /* increment the smbus device */
1196 cmpb $SMBUS_MEM_DEVICE_END, %bl
1198 spd_verify_dimms_out:
1199 RET_LABEL(spd_verify_dimms)
1202 #define spd_pre_init "Reading SPD data...\r\n"
1203 #define spd_pre_set "setting based on SPD data...\r\n"
1204 #define spd_post_init "done\r\n"
1207 static const uint32_t refresh_rate_rank[]= {
1208 /* Refresh rates ordered from most conservative (lowest)
1209 * to most agressive (highest)
1210 * disabled 0 -> rank 3
1211 * 15.6usec 1 -> rank 1
1212 * 7.8 usec 2 -> rank 0
1213 * 64usec 3 -> rank 2
1216 static const uint32_t refresh_rate_index[] = {
1217 /* Map the spd refresh rates to memory controller settings
1218 * 15.625us -> 15.6us
1227 #define MAX_SPD_REFRESH_RATE 5
1229 static long spd_set_dram_controller_mode (const struct mem_controller *ctrl, long dimm_mask) {
1237 /* Read the inititial state */
1238 dword = pci_read_config32(ctrl->d0, 0x7c);
1241 /* Test if ECC cmos option is enabled */
1242 movb $RTC_BOOT_BYTE, %al
1247 /* Clear the ecc enable */
1248 andl $~(3 << 20), %esi
1253 /* Walk through all dimms and find the interesection of the support
1254 * for ecc sdram and refresh rates
1258 for(i = 0; i < DIMM_SOCKETS; i++) {
1259 if (!(dimm_mask & (1 << i))) {
1262 /* Test to see if I have ecc sdram */
1263 value = spd_read_byte(ctrl->channel0[i], 11); /* SDRAM type */
1264 if(value < 0) continue;
1266 /* Clear the ecc enable */
1267 dword &= ~(3 << 20);
1269 value = spd_read_byte(ctrl->channel0[i], 12); /* SDRAM refresh rate */
1270 if(value < 0 ) continue;
1272 if(value > MAX_SPD_REFRESH_RATE) { print_err("unsupported refresh rate\r\n");}
1273 // if(value == 0xff) { print_err("unsupported refresh rate\r\n");}
1275 ecx = refresh_rate_index[value];
1277 /* Isolate the old refresh rate setting */
1278 /* Load the refresh rate ranks */
1279 edx = refresh_rate_rank[(dword >> 8) & 3]<<8;
1280 edx |= refresh_rate_rank[ecx] & 0xff;
1282 /* See if the new refresh rate is more conservative than the old
1283 * refresh rate setting. (Lower ranks are more conservative)
1285 if((edx & 0xff)< ((edx >> 8) & 0xff) ) {
1286 /* Clear the old refresh rate */
1288 /* Move in the new refresh rate */
1292 value = spd_read_byte(ctrl->channel0[i], 33); /* Address and command hold time after clock */
1293 if(value < 0) continue;
1294 if(value >= 0xa0) { /* At 133Mhz this constant should be 0x75 */
1295 dword &= ~(1<<16); /* Use two clock cyles instead of one */
1298 /* go to the next DIMM */
1301 /* Now write the controller mode */
1302 pci_write_config32(ctrl->d0, 0x7c, dword);
1307 static long spd_enable_clocks(const struct mem_controller *ctrl, long dimm_mask)
1313 /* Read the inititial state */
1314 dword = pci_read_config32(ctrl->d0, 0x8c);
1316 # Intel clears top bit here, should we?
1317 # No the default is on and for normal timming it should be on. Tom Z
1322 for(i = 0; i < DIMM_SOCKETS; i++) {
1323 if (!(dimm_mask & (1 << i))) {
1326 /* Read any spd byte to see if the dimm is present */
1327 value = spd_read_byte(ctrl->channel0[i], 5); /* Physical Banks */
1328 if(value < 0) continue;
1333 pci_write_config32(ctrl->d0, 0x8c, dword);
1338 static const uint16_t cas_latency_80[] = {
1339 /* For cas latency 2.0 0x01 works and until I see a large test sample
1340 * I am not prepared to change this value, to the intel recommended value
1341 * of 0x0d. Eric Biederman
1343 /* The E7501 requires b1 rather than 01 for CAS2 or memory will be hosed
1344 * CAS 1.5 is claimed to be unsupported, will try to test that
1345 * will need to determine correct values for other CAS values
1346 * (perhaps b5, b1, b6?)
1347 * Steven James 02/06/2003
1350 //# .byte 0x05, 0x01, 0x06
1351 //# .byte 0xb5, 0xb1, 0xb6
1352 0x0, 0x0bb1, 0x0662 /* RCVEN */
1354 static const uint16_t cas_latency_80_4dimms[] = {
1359 static const uint8_t cas_latency_78[] = {
1360 DRT_CAS_1_5, DRT_CAS_2_0, DRT_CAS_2_5
1363 static long spd_set_cas_latency(const struct mem_controller *ctrl, long dimm_mask) {
1364 /* Walk through all dimms and find the interesection of the
1365 * supported cas latencies.
1368 /* Initially allow cas latencies 2.5, 2.0
1369 * which the chipset supports.
1371 uint32_t dword = (1<<3)| (1<<2);// esi
1380 for(i = 0; i < DIMM_SOCKETS; i++) {
1381 if (!(dimm_mask & (1 << i))) {
1384 value = spd_read_byte(ctrl->channel0[i], 18);
1385 if(value < 0) continue;
1386 /* Find the highest supported cas latency */
1387 ecx = log2(value & 0xff);
1390 /* Remember the supported cas latencies */
1391 ecx = (value & 0xff);
1393 /* Verify each cas latency at 133Mhz */
1394 /* Verify slowest/highest CAS latency */
1395 value = spd_read_byte(ctrl->channel0[i], 9);
1396 if(value < 0 ) continue;
1398 /* The bus is too fast so we cannot support this case latency */
1402 /* Verify the highest CAS latency - 0.5 clocks */
1405 value = spd_read_byte(ctrl->channel0[i], 23);
1406 if(value < 0 ) continue;
1408 /* The bus is too fast so we cannot support this cas latency */
1413 /* Verify the highest CAS latency - 1.0 clocks */
1416 value = spd_read_byte(ctrl->channel0[i], 25);
1417 if(value < 0 ) continue;
1419 /* The bus is too fast so we cannot support this cas latency */
1424 /* Now find which cas latencies are supported for the bus */
1426 /* go to the next DIMM */
1429 /* After all of the arduous calculation setup with the fastest
1430 * cas latency I can use.
1432 value = __builtin_bsf(dword); // bsrl = log2 how about bsfl?
1433 if(value ==0 ) return -1;
1436 byte = pci_read_config8(ctrl->d0, 0x78);
1437 byte &= ~(DRT_CAS_MASK);
1438 byte |= cas_latency_78[ecx];
1439 pci_write_config8(ctrl->d0,0x78, byte);
1441 /* set master DLL reset */
1442 dword = pci_read_config32(ctrl->d0, 0x88);
1445 /* the rest of the references are words */
1446 // ecx<<=1; // don't need shift left, because we already define that in u16 array
1447 pci_write_config32(ctrl->d0, 0x88, dword);
1450 dword &= 0x0c0000ff; /* patch try register 88 is undocumented tnz */
1451 dword |= 0xd2109800;
1453 pci_write_config32(ctrl->d0, 0x88, dword);
1455 word = pci_read_config16(ctrl->d0, 0x80);
1457 word |= cas_latency_80[ecx];
1459 dword = pci_read_config32(ctrl->d0, 0x70);
1461 if((dword & 0xff) !=0 ) {
1463 if((dword & 0xff)!=0) {
1465 if((dword & 0xff)!=0) {
1467 if( (dword & 0xff)!=0) {
1468 word &=~(0x0fff); /* we have dimms in all 4 slots */
1469 word |=cas_latency_80_4dimms[ecx];
1475 pci_write_config16(ctrl->d0, 0x80, word);
1477 dword = pci_read_config32(ctrl->d0, 0x88); /* reset master DLL reset */
1479 pci_write_config32(ctrl->d0, 0x88, dword);
1481 RAM_RESET_DDR_PTR(ctrl);
1487 static long spd_set_dram_timing(const struct mem_controller *ctrl, long dimm_mask) {
1488 /* Walk through all dimms and find the interesection of the
1489 * supported dram timings.
1496 /* Read the inititial state */
1497 dword = pci_read_config32(ctrl->d0, 0x78);
1499 # Intel clears top bit here, should we?
1500 # No the default is on and for normal timming it should be on. Tom Z
1505 for(i = 0; i < DIMM_SOCKETS; i++) {
1506 if (!(dimm_mask & (1 << i))) {
1510 value = spd_read_byte(ctrl->channel0[i], 27);
1511 if(value < 0) continue;
1512 if(value > (15<<2)) {
1513 /* At 133Mhz if row precharge time is above than 15ns than we
1514 * need 3 clocks not 2 clocks.
1519 value = spd_read_byte(ctrl->channel0[i],29);
1520 if(value < 0 ) continue;
1521 if(value > (15<<2)) {
1522 /* At 133Mhz if the Minimum ras to cas delay is about 15ns we
1523 * need 3 clocks not 2 clocks.
1525 dword &= ~((1<<3)|(1<<1));
1528 value = spd_read_byte(ctrl->channel0[i],30);
1529 if(value < 0 ) continue;
1530 /* Convert tRAS from ns to 133Mhz clock cycles */
1531 value <<=1; /* mult by 2 to make 7.5 15 */
1532 value += 15; /* Make certain we round up */
1534 value &= 0xff; /* Clear the upper bits of eax */
1537 /* Don't even process small timings */
1540 /* Die if the value is to large */
1542 die ("unsupported_rcd\r\n");
1544 /* Convert to clocks - 5 */
1546 /* Convert the existing value into clocks - 5 */
1547 tmp = (~((dword>>9) & 3) - 1) & 3;
1548 /* See if we need a slower timing */
1550 /* O.k. put in our slower timing */
1552 dword |= ((~(value + 1)) & 3)<<9 ;
1557 /* Set to a 7 clock read delay. This is for 133Mhz
1558 * with a CAS latency of 2.5 if 2.0 a 6 clock
1560 if( (pci_read_config8(ctrl->d0, 0x78) & 0x30) ==0 ){
1561 dword &= ~(7<<24); /* CAS latency is 2.5, make 7 clks */
1565 * Back to Back Read Turn Around
1567 /* Set to a 3 clock back to back read turn around. This
1568 * is good for CAS latencys 2.5 and 2.0 */
1571 * Back to Back Read-Write Turn Around
1573 /* Set to a 5 clock back to back read to write turn around.
1574 * 4 is a good delay if the CAS latency is 2.0 */
1575 if( ( pci_read_config8(ctrl->d0, 0x78) & (1<<4)) == 0) {
1579 * Back to Back Write-Read Turn Around
1581 /* Set to a 2 clock back to back write to read turn around.
1582 * This is good for 2.5 and 2.0 CAS Latencies. */
1586 pci_write_config32(ctrl->d0, 0x78, dword);
1591 static unsigned int spd_detect_dimms(const struct mem_controller *ctrl)
1596 #if DEBUG_RAM_CONFIG
1597 print_debug("spd_detect_dimms:\r\n");
1599 for(i = 0; i < DIMM_SOCKETS; i++) {
1602 #if DEBUG_RAM_CONFIG
1603 print_debug_hex32(i);
1604 print_debug("\r\n");
1606 device = ctrl->channel0[i];
1608 byte = spd_read_byte(ctrl->channel0[i], 2); /* Type */
1610 dimm_mask |= (1 << i);
1614 device = ctrl->channel1[i];
1616 byte = spd_read_byte(ctrl->channel1[i], 2);
1618 dimm_mask |= (1 << (i + DIMM_SOCKETS));
1624 i = (dimm_mask>>DIMM_SOCKETS);
1625 if(i != (dimm_mask & ( (1<<DIMM_SOCKETS) - 1) ) ) {
1626 die("now we only support dual channel\r\n");
1634 static uint32_t set_dimm_size(const struct mem_controller *ctrl, struct dimm_size sz, uint32_t memsz, unsigned index)
1637 uint32_t base0, base1;
1641 /* Double the size if we are using dual channel memory */
1642 // if (is_dual_channel(ctrl)) {
1643 /* Since I have 2 identical channels double the sizes */
1648 if (sz.side1 != sz.side2) {
1652 /* Make certain side1 of the dimm is at least 64MB */
1653 if (sz.side1 >= (25 + 4)) {
1654 memsz += (1 << (sz.side1 - (25 + 4)) ) ;
1656 /* Write the size of side 1 of the dimm */
1658 pci_write_config8(ctrl->d0, 0x60+(index<<1), byte);
1660 /* Make certain side2 of the dimm is at least 64MB */
1661 if (sz.side2 >= (25 + 4)) {
1662 memsz += (1 << (sz.side2 - (25 + 4)) ) ;
1665 /* Write the size of side 2 of the dimm */
1667 pci_write_config8(ctrl->d0, 0x61+(index<<1), byte);
1669 /* now, fill in DRBs where no physical slot exists */
1671 for(i=index+1;i<4;i++) {
1672 pci_write_config8(ctrl->d0, 0x60+(i<<1),byte);
1673 pci_write_config8(ctrl->d0, 0x61+(i<<1),byte);
1680 /* LAST_DRB_SLOT is a constant for any E7500 board */
1681 #define LAST_DRB_SLOT 0x67
1683 static long spd_set_ram_size(const struct mem_controller *ctrl, long dimm_mask)
1689 for(i = 0; i < DIMM_SOCKETS; i++) {
1690 struct dimm_size sz;
1691 if (!(dimm_mask & (1 << i))) {
1694 sz = spd_get_dimm_size(ctrl->channel0[i]);
1695 #if DEBUG_RAM_CONFIG
1696 print_debug("dimm size =");
1697 print_debug_hex32(sz.side1);
1699 print_debug_hex32(sz.side2);
1700 print_debug("\r\n");
1703 if (sz.side1 == 0) {
1704 return -1; /* Report SPD error */
1706 memsz = set_dimm_size(ctrl, sz, memsz, i);
1708 /* For now hardset everything at 128MB boundaries */
1709 /* %ebp has the ram size in multiples of 64MB */
1710 // cmpl $0, %ebp /* test if there is no mem - smbus went bad */
1711 // jz no_memory_bad_smbus
1713 /* I should really adjust all of this in C after I have resources
1714 * to all of the pcie devices.
1717 /* Round up to 128M granularity */
1722 pci_write_config16(ctrl->d0, 0xc4, word);
1725 /* FIXME will this work with 3.5G of ram? */
1726 /* Put TOLM at 3G */
1727 pci_write_config16(ctrl->d0, 0xc4, 0xc000);
1728 /* Hard code a 1G remap window, right after the ram */
1730 word = 0x40; /* Ensure we are over 4G */
1734 pci_write_config16(ctrl->d0, 0xc6, word);
1736 pci_write_config16(ctrl->d0, 0xc8, word);
1743 static void sdram_set_spd_registers(const struct mem_controller *ctrl) {
1745 #if DEBUG_RAM_CONFIG
1746 print_debug(spd_pre_init);
1748 //activate_spd_rom(ctrl);
1749 dimm_mask = spd_detect_dimms(ctrl);
1750 if (!(dimm_mask & ((1 << DIMM_SOCKETS) - 1))) {
1751 print_debug("No memory for this controller\n");
1754 dimm_mask = spd_enable_clocks(ctrl, dimm_mask);
1757 //spd_verify_dimms(ctrl);
1758 #if DEBUG_RAM_CONFIG
1759 print_debug(spd_pre_set);
1761 dimm_mask = spd_set_row_attributes(ctrl,dimm_mask);
1764 dimm_mask = spd_set_dram_controller_mode(ctrl,dimm_mask);
1767 dimm_mask = spd_set_cas_latency(ctrl,dimm_mask);
1770 dimm_mask = spd_set_dram_timing(ctrl,dimm_mask);
1773 #if DEBUG_RAM_CONFIG
1774 print_debug(spd_post_init);
1776 //moved from dram_post_init
1777 spd_set_ram_size(ctrl, dimm_mask);
1780 /* Unrecoverable error reading SPD data */
1781 print_err("SPD error - reset\r\n");
1787 /* I have finally seen ram bad enough to cause LinuxBIOS
1788 * to die in mysterious ways, before booting up far
1789 * enough to run a memory tester. This code attempts
1790 * to catch this blatantly bad ram, with a spot check.
1791 * For most cases you should boot all of the way up
1792 * and run a memory tester.
1794 /* Ensure I read/write each stick of bank of memory &&
1795 * that I do more than 1000 bytes to avoid the northbridge cache.
1796 * Only 64M of each side of each DIMM is currently mapped,
1797 * so we can handle > 4GB of ram here.
1800 #define bank_msg "Bank "
1801 #define side_msg " Side "
1802 static void verify_ram() {
1804 /* Check to see if the RAM is present,
1805 * in the specified bank and side.
1809 addl $((5<<8) | SMBUS_MEM_DEVICE_START), %ebx
1810 CALLSP(smbus_read_byte)
1817 /* Display the bank and side we are spot checking.
1819 2: CONSOLE_INFO_TX_STRING($bank_msg)
1823 CONSOLE_INFO_TX_HEX8(%bl)
1824 CONSOLE_INFO_TX_STRING($side_msg)
1827 CONSOLE_INFO_TX_HEX8(%bl)
1829 /* Compute the memory address to spot check. */
1834 addl $0x04000000, %eax
1838 /* Spot check 512K of RAM */
1840 addl $0x0007ffff, %ebx
1843 /* Now find the next bank and side to spot check */
1845 cmpl $((SMBUS_MEM_DEVICE_END - SMBUS_MEM_DEVICE_START)<<1), %ecx
1847 RET_LABEL(verify_ram)
1853 static void ram_postinit(const struct mem_controller *ctrl) {
1854 #if DEBUG_RAM_CONFIG
1857 /* Include a test to verify that memory is more or less working o.k.
1858 * This test is to catch programming errors and hardware that is out of
1859 * spec, not a test to see if the memory dimms are working 100%
1861 //# CALL_LABEL(verify_ram)
1862 spd_set_ram_size(ctrl);
1864 #define FIRST_NORMAL_REFERENCE() CALL_LABEL(ram_postinit)
1866 #define SPECIAL_FINISHUP() CALL_LABEL(dram_finish)
1870 #define ecc_pre_init "Initializing ECC state...\r\n"
1871 #define ecc_post_init "ECC state initialized.\r\n"
1872 static void dram_finish(const struct mem_controller *ctrl)
1876 /* Test to see if ECC support is enabled */
1877 dword = pci_read_config32(ctrl->d0, 0x7c);
1882 #if DEBUG_RAM_CONFIG
1883 print_debug(ecc_pre_init);
1885 /* Initialize ECC bits , use ECC zero mode (new to 7501)*/
1886 pci_write_config8(ctrl->d0, 0x52, 0x06);
1887 pci_write_config8(ctrl->d0, 0x52, 0x07);
1889 byte = pci_read_config8(ctrl->d0, 0x52);
1891 } while ( (byte & 0x08 ) == 0);
1893 pci_write_config8(ctrl->d0, 0x52, byte & 0xfc);
1894 #if DEBUG_RAM_CONFIG
1895 print_debug(ecc_post_init);
1898 /* Clear the ECC error bits */
1899 pci_write_config8(ctrl->d0f1, 0x80, 0x03); /* dev 0, function 1, offset 80 */
1900 pci_write_config8(ctrl->d0f1, 0x82, 0x03); /* dev 0, function 1, offset 82 */
1902 pci_write_config32(ctrl->d0f1, 0x40, 1<<18); /* clear dev 0, function 1, offset 40; bit 18 by writing a 1 to it */
1903 pci_write_config32(ctrl->d0f1, 0x44, 1<<18); /* clear dev 0, function 1, offset 44; bit 18 by writing a 1 to it */
1905 pci_write_config8(ctrl->d0, 0x52, 0x0d);
1908 dword = pci_read_config32(ctrl->d0, 0x7c); /* FCS_EN */
1910 pci_write_config32(ctrl->d0, 0x7c, dword);
1913 #if DEBUG_RAM_CONFIG
1920 #define ERRFUNC(x, str) mem_err(x, str)
1923 ERRFUNC(invalid_dimm_type, "Invalid dimm type")
1924 ERRFUNC(spd_missing_data, "Missing sdram spd data")
1925 ERRFUNC(spd_invalid_data, "Invalid sdram spd data")
1926 ERRFUNC(spd_unsupported_data, "Unsupported sdram spd value")
1927 ERRFUNC(unsupported_page_size, "Unsupported page size")
1928 ERRFUNC(sdram_presence_mismatch, "DIMM presence mismatch")
1929 ERRFUNC(sdram_value_mismatch, "spd data does not match")
1930 ERRFUNC(unsupported_refresh_rate, "Unsuported spd refresh rate")
1931 ERRFUNC(inconsistent_cas_latencies, "No cas latency supported by all dimms")
1932 ERRFUNC(unsupported_rcd, "Unsupported ras to cas delay")
1935 #define mem_err_err "ERROR: "
1936 #define mem_err_pair " on dimm pair "
1937 #define mem_err_byte " spd byte "
1938 static void mem_err {
1940 CONSOLE_ERR_TX_STRING($mem_err_err)
1941 CONSOLE_ERR_TX_STRING(%esi)
1942 CONSOLE_ERR_TX_STRING($mem_err_pair)
1944 subb $(SMBUS_MEM_DEVICE_START), %bl
1945 CONSOLE_ERR_TX_HEX8(%bl)
1946 CONSOLE_ERR_TX_STRING($mem_err_byte)
1948 CONSOLE_ERR_TX_HEX8(%bh)
1956 #if ASM_CONSOLE_LOGLEVEL > BIOS_DEBUG
1957 #define ram_enable_1 "Ram Enable 1\r\n"
1958 #define ram_enable_2 "Ram Enable 2\r\n"
1959 #define ram_enable_3 "Ram Enable 3\r\n"
1960 #define ram_enable_4 "Ram Enable 4\r\n"
1961 #define ram_enable_5 "Ram Enable 5\r\n"
1962 #define ram_enable_6 "Ram Enable 6\r\n"
1963 #define ram_enable_7 "Ram Enable 7\r\n"
1964 #define ram_enable_8 "Ram Enable 8\r\n"
1965 #define ram_enable_9 "Ram Enable 9\r\n"
1966 #define ram_enable_10 "Ram Enable 10\r\n"
1967 #define ram_enable_11 "Ram Enable 11\r\n"
1970 /* Estimate that SLOW_DOWN_IO takes about 50&76us*/
1971 /* delay for 200us */
1975 // for(i=0; i<16;i++) { SLOW_DOWN_IO }
1978 #define EXTRA_DELAY DO_DELAY
1980 static void sdram_enable(int controllers, const struct mem_controller *ctrl)
1983 /* 1 & 2 Power up and start clocks */
1984 #if DEBUG_RAM_CONFIG
1985 print_debug(ram_enable_1);
1986 print_debug(ram_enable_2);
1989 /* A 200us delay is needed */
1995 #if DEBUG_RAM_CONFIG
1996 print_debug(ram_enable_3);
2001 /* 4 Precharge all */
2002 #if DEBUG_RAM_CONFIG
2003 print_debug(ram_enable_4);
2005 RAM_PRECHARGE(ctrl);
2008 /* wait until the all banks idle state... */
2009 /* 5. Issue EMRS to enable DLL */
2010 #if DEBUG_RAM_CONFIG
2011 print_debug(ram_enable_5);
2017 #if DEBUG_RAM_CONFIG
2018 print_debug(ram_enable_6);
2023 /* Ensure a 200us delay between the DLL reset in step 6 and the final
2024 * mode register set in step 9.
2025 * Infineon needs this before any other command is sent to the ram.
2030 /* 7 Precharge all */
2031 #if DEBUG_RAM_CONFIG
2032 print_debug(ram_enable_7);
2034 RAM_PRECHARGE(ctrl);
2037 /* 8 Now we need 2 AUTO REFRESH / CBR cycles to be performed */
2038 #if DEBUG_RAM_CONFIG
2039 print_debug(ram_enable_8);
2045 /* And for good luck 6 more CBRs */
2059 /* 9 mode register set */
2060 #if DEBUG_RAM_CONFIG
2061 print_debug(ram_enable_9);
2066 /* 10 DDR Receive FIFO RE-Sync */
2067 #if DEBUG_RAM_CONFIG
2068 print_debug(ram_enable_10);
2070 RAM_RESET_DDR_PTR(ctrl);
2073 /* 11 normal operation */
2074 #if DEBUG_RAM_CONFIG
2075 print_debug(ram_enable_11);
2081 //FIRST_NORMAL_REFERENCE();
2082 //spd_set_ram_size(ctrl, 0x03);
2084 /* Finally enable refresh */
2085 ENABLE_REFRESH(ctrl);
2087 //SPECIAL_FINISHUP();