2 #include <lib.h> /* Prototypes */
3 #include <console/console.h>
5 static void write_phys(unsigned long addr, u32 value)
7 // Assembler in lib/ is very ugly. But we properly guarded
8 // it so let's obey this one for now
13 : "r" (addr), "r" (value) /* inputs */
14 #ifndef __GNUC__ /* GCC does not like empty clobbers? */
19 volatile unsigned long *ptr;
25 static u32 read_phys(unsigned long addr)
27 volatile unsigned long *ptr;
32 static void phys_memory_barrier(void)
39 #ifdef __GNUC__ /* ROMCC does not like memory clobbers */
44 #ifdef __GNUC__ /* ROMCC does not like empty asm statements */
45 asm volatile ("" ::: "memory");
50 static void ram_fill(unsigned long start, unsigned long stop)
56 #if !defined(__ROMCC__)
57 printk(BIOS_DEBUG, "DRAM fill: 0x%08lx-0x%08lx\n", start, stop);
59 print_debug("DRAM fill: ");
60 print_debug_hex32(start);
62 print_debug_hex32(stop);
65 for(addr = start; addr < stop ; addr += 4) {
66 /* Display address being filled */
67 if (!(addr & 0xfffff)) {
68 #if !defined(__ROMCC__)
69 printk(BIOS_DEBUG, "%08lx \r", addr);
71 print_debug_hex32(addr);
75 write_phys(addr, (u32)addr);
77 /* Display final address */
78 #if !defined(__ROMCC__)
79 printk(BIOS_DEBUG, "%08lx\nDRAM filled\n", addr);
81 print_debug_hex32(addr);
82 print_debug("\nDRAM filled\n");
86 static int ram_verify_nodie(unsigned long start, unsigned long stop)
93 #if !defined(__ROMCC__)
94 printk(BIOS_DEBUG, "DRAM verify: 0x%08lx-0x%08lx\n", start, stop);
96 print_debug("DRAM verify: ");
97 print_debug_hex32(start);
98 print_debug_char('-');
99 print_debug_hex32(stop);
102 for(addr = start; addr < stop ; addr += 4) {
104 /* Display address being tested */
105 if (!(addr & 0xfffff)) {
106 #if !defined(__ROMCC__)
107 printk(BIOS_DEBUG, "%08lx \r", addr);
109 print_debug_hex32(addr);
113 value = read_phys(addr);
115 /* Display address with error */
116 #if !defined(__ROMCC__)
117 printk(BIOS_ERR, "Fail: @0x%08lx Read value=0x%08lx\n", addr, value);
119 print_err("Fail: @0x");
120 print_err_hex32(addr);
121 print_err(" Read value=0x");
122 print_err_hex32(value);
127 #if !defined(__ROMCC__)
128 printk(BIOS_DEBUG, "Aborting.\n");
130 print_debug("Aborting.\n");
136 /* Display final address */
137 #if !defined(__ROMCC__)
138 printk(BIOS_DEBUG, "%08lx", addr);
140 print_debug_hex32(addr);
144 #if !defined(__ROMCC__)
145 printk(BIOS_DEBUG, "\nDRAM did _NOT_ verify!\n");
147 print_debug("\nDRAM did _NOT_ verify!\n");
152 #if !defined(__ROMCC__)
153 printk(BIOS_DEBUG, "\nDRAM range verified.\n");
155 print_debug("\nDRAM range verified.\n");
163 void ram_check(unsigned long start, unsigned long stop)
166 * This is much more of a "Is my DRAM properly configured?"
167 * test than a "Is my DRAM faulty?" test. Not all bits
170 #if !defined(__ROMCC__)
171 printk(BIOS_DEBUG, "Testing DRAM : %08lx - %08lx\n", start, stop);
173 print_debug("Testing DRAM : ");
174 print_debug_hex32(start);
176 print_debug_hex32(stop);
179 ram_fill(start, stop);
180 /* Make sure we don't read before we wrote */
181 phys_memory_barrier();
182 if (ram_verify_nodie(start, stop))
184 #if !defined(__ROMCC__)
185 printk(BIOS_DEBUG, "Done.\n");
187 print_debug("Done.\n");
192 int ram_check_nodie(unsigned long start, unsigned long stop)
196 * This is much more of a "Is my DRAM properly configured?"
197 * test than a "Is my DRAM faulty?" test. Not all bits
200 #if !defined(__ROMCC__)
201 printk(BIOS_DEBUG, "Testing DRAM : %08lx - %08lx\n", start, stop);
203 print_debug("Testing DRAM : ");
204 print_debug_hex32(start);
206 print_debug_hex32(stop);
209 ram_fill(start, stop);
210 /* Make sure we don't read before we wrote */
211 phys_memory_barrier();
212 ret = ram_verify_nodie(start, stop);
214 #if !defined(__ROMCC__)
215 printk(BIOS_DEBUG, "Done.\n");
217 print_debug("Done.\n");
222 void quick_ram_check(void)
226 backup = read_phys(CONFIG_RAMBASE);
227 write_phys(CONFIG_RAMBASE, 0x55555555);
228 phys_memory_barrier();
229 if (read_phys(CONFIG_RAMBASE) != 0x55555555)
231 write_phys(CONFIG_RAMBASE, 0xaaaaaaaa);
232 phys_memory_barrier();
233 if (read_phys(CONFIG_RAMBASE) != 0xaaaaaaaa)
235 write_phys(CONFIG_RAMBASE, 0x00000000);
236 phys_memory_barrier();
237 if (read_phys(CONFIG_RAMBASE) != 0x00000000)
239 write_phys(CONFIG_RAMBASE, 0xffffffff);
240 phys_memory_barrier();
241 if (read_phys(CONFIG_RAMBASE) != 0xffffffff)
244 write_phys(CONFIG_RAMBASE, backup);
247 die("RAM INIT FAILURE!\n");
249 phys_memory_barrier();