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 CONFIG_CACHE_AS_RAM
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 CONFIG_CACHE_AS_RAM
69 printk(BIOS_DEBUG
, "%08lx \r", addr
);
71 print_debug_hex32(addr
);
75 write_phys(addr
, (u32
)addr
);
77 /* Display final address */
78 #if CONFIG_CACHE_AS_RAM
79 printk(BIOS_DEBUG
, "%08lx\nDRAM filled\n", addr
);
81 print_debug_hex32(addr
);
82 print_debug("\nDRAM filled\n");
86 static void ram_verify(unsigned long start
, unsigned long stop
)
93 #if CONFIG_CACHE_AS_RAM
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 CONFIG_CACHE_AS_RAM
107 printk(BIOS_DEBUG
, "%08lx \r", addr
);
109 print_debug_hex32(addr
);
113 value
= read_phys(addr
);
115 /* Display address with error */
116 #if CONFIG_CACHE_AS_RAM
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 CONFIG_CACHE_AS_RAM
128 printk(BIOS_DEBUG
, "Aborting.\n");
130 print_debug("Aborting.\n");
136 /* Display final address */
137 #if CONFIG_CACHE_AS_RAM
138 printk(BIOS_DEBUG
, "%08lx", addr
);
140 print_debug_hex32(addr
);
144 #if CONFIG_CACHE_AS_RAM
145 printk(BIOS_DEBUG
, "\nDRAM did _NOT_ verify!\n");
147 print_debug("\nDRAM did _NOT_ verify!\n");
152 #if CONFIG_CACHE_AS_RAM
153 printk(BIOS_DEBUG
, "\nDRAM range verified.\n");
155 print_debug("\nDRAM range verified.\n");
161 void ram_check(unsigned long start
, unsigned long stop
)
164 * This is much more of a "Is my DRAM properly configured?"
165 * test than a "Is my DRAM faulty?" test. Not all bits
168 #if CONFIG_CACHE_AS_RAM
169 printk(BIOS_DEBUG
, "Testing DRAM : %08lx - %08lx\n", start
, stop
);
171 print_debug("Testing DRAM : ");
172 print_debug_hex32(start
);
174 print_debug_hex32(stop
);
177 ram_fill(start
, stop
);
178 /* Make sure we don't read before we wrote */
179 phys_memory_barrier();
180 ram_verify(start
, stop
);
181 #if CONFIG_CACHE_AS_RAM
182 printk(BIOS_DEBUG
, "Done.\n");
184 print_debug("Done.\n");
188 void quick_ram_check(void)
192 backup
= read_phys(CONFIG_RAMBASE
);
193 write_phys(CONFIG_RAMBASE
, 0x55555555);
194 phys_memory_barrier();
195 if (read_phys(CONFIG_RAMBASE
) != 0x55555555)
197 write_phys(CONFIG_RAMBASE
, 0xaaaaaaaa);
198 phys_memory_barrier();
199 if (read_phys(CONFIG_RAMBASE
) != 0xaaaaaaaa)
201 write_phys(CONFIG_RAMBASE
, 0x00000000);
202 phys_memory_barrier();
203 if (read_phys(CONFIG_RAMBASE
) != 0x00000000)
205 write_phys(CONFIG_RAMBASE
, 0xffffffff);
206 phys_memory_barrier();
207 if (read_phys(CONFIG_RAMBASE
) != 0xffffffff)
210 write_phys(CONFIG_RAMBASE
, backup
);
213 die("RAM INIT FAILURE!\n");
215 phys_memory_barrier();