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
9 #if IS_ENABLED(CONFIG_SSE2)
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)
34 #if IS_ENABLED(CONFIG_SSE2)
39 #ifdef __GNUC__ /* ROMCC does not like memory clobbers */
44 #ifdef __GNUC__ /* ROMCC does not like empty asm statements */
45 asm volatile ("" ::: "memory");
51 * Rotate ones test pattern that access every bit on a 128bit wide
52 * memory bus. To test most address lines, addresses are scattered
53 * using 256B, 4kB and 64kB increments.
55 * @param idx Index to test pattern (0=<idx<0x400)
56 * @param addr Memory to access on idx
57 * @param value Value to write or read at addr
59 static inline void test_pattern(unsigned short int idx
,
60 unsigned long *addr
, unsigned long *value
)
65 j
= (idx
>> 4) & 0x0f;
68 *value
= 0x01010101 << (j
& 7);
74 * Simple write-read-verify memory test. See console debug output for
75 * any dislocated bytes.
77 * Tests 1MiB of memory starting from start.
79 * @param start System memory offset, aligned to 128bytes
81 static int ram_bitset_nodie(unsigned long start
)
83 unsigned long addr
, value
, value2
;
84 unsigned short int idx
;
85 unsigned char failed
, failures
;
88 printk(BIOS_DEBUG
, "DRAM bitset write: 0x%08lx\n", start
);
89 for (idx
= 0; idx
< 0x400; idx
+= 4) {
90 test_pattern(idx
, &addr
, &value
);
91 write_phys(start
+ addr
, value
);
94 /* Make sure we don't read before we wrote */
95 phys_memory_barrier();
97 printk(BIOS_DEBUG
, "DRAM bitset verify: 0x%08lx\n", start
);
99 for (idx
= 0; idx
< 0x400; idx
+= 4) {
100 test_pattern(idx
, &addr
, &value
);
101 value2
= read_phys(start
+ addr
);
103 failed
= (value2
!= value
);
105 if (failed
&& !verbose
) {
106 printk(BIOS_ERR
, "0x%08lx wr: 0x%08lx rd: 0x%08lx FAIL\n",
107 start
+ addr
, value
, value2
);
110 if ((addr
& 0x0f) == 0)
111 printk(BIOS_DEBUG
, "%08lx wr: %08lx rd:",
112 start
+ addr
, value
);
114 printk(BIOS_DEBUG
, " %08lx!", value2
);
116 printk(BIOS_DEBUG
, " %08lx ", value2
);
117 if ((addr
& 0x0f) == 0xc)
118 printk(BIOS_DEBUG
, "\n");
123 printk(BIOS_DEBUG
, "\nDRAM did _NOT_ verify!\n");
126 printk(BIOS_DEBUG
, "\nDRAM range verified.\n");
131 void ram_check(unsigned long start
, unsigned long stop
)
134 * This is much more of a "Is my DRAM properly configured?"
135 * test than a "Is my DRAM faulty?" test. Not all bits
138 printk(BIOS_DEBUG
, "Testing DRAM at: %08lx\n", start
);
139 if (ram_bitset_nodie(start
))
141 printk(BIOS_DEBUG
, "Done.\n");
145 int ram_check_nodie(unsigned long start
, unsigned long stop
)
149 * This is much more of a "Is my DRAM properly configured?"
150 * test than a "Is my DRAM faulty?" test. Not all bits
153 printk(BIOS_DEBUG
, "Testing DRAM at : %08lx\n", start
);
155 ret
= ram_bitset_nodie(start
);
156 printk(BIOS_DEBUG
, "Done.\n");
160 int ram_check_noprint_nodie(unsigned long start
, unsigned long stop
)
162 unsigned long addr
, value
, value2
;
163 unsigned short int idx
;
164 unsigned char failed
, failures
;
166 for (idx
= 0; idx
< 0x400; idx
+= 4) {
167 test_pattern(idx
, &addr
, &value
);
168 write_phys(start
+ addr
, value
);
171 /* Make sure we don't read before we wrote */
172 phys_memory_barrier();
175 for (idx
= 0; idx
< 0x400; idx
+= 4) {
176 test_pattern(idx
, &addr
, &value
);
177 value2
= read_phys(start
+ addr
);
179 failed
= (value2
!= value
);
185 static void __quick_ram_check(uintptr_t dst
)
189 backup
= read_phys(dst
);
190 write_phys(dst
, 0x55555555);
191 phys_memory_barrier();
192 if (read_phys(dst
) != 0x55555555)
194 write_phys(dst
, 0xaaaaaaaa);
195 phys_memory_barrier();
196 if (read_phys(dst
) != 0xaaaaaaaa)
198 write_phys(dst
, 0x00000000);
199 phys_memory_barrier();
200 if (read_phys(dst
) != 0x00000000)
202 write_phys(dst
, 0xffffffff);
203 phys_memory_barrier();
204 if (read_phys(dst
) != 0xffffffff)
207 write_phys(dst
, backup
);
210 die("RAM INIT FAILURE!\n");
212 phys_memory_barrier();
215 void quick_ram_check(void)
217 __quick_ram_check(0x100000);