blob: 6268aaa6cd516e319b792f3916a1288ab70a3106 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001static void write_phys(unsigned long addr, unsigned long value)
2{
Stefan Reinauera7acc512010-02-25 13:40:49 +00003 // Assembler in lib/ is very ugly. But we properly guarded
4 // it so let's obey this one for now
5#if CONFIG_SSE2
Eric Biederman8d9c1232003-06-17 08:42:17 +00006 asm volatile(
7 "movnti %1, (%0)"
8 : /* outputs */
9 : "r" (addr), "r" (value) /* inputs */
Stefan Reinauer76712932004-05-27 11:13:24 +000010#ifndef __GNUC__
Eric Biederman8d9c1232003-06-17 08:42:17 +000011 : /* clobbers */
Stefan Reinauer76712932004-05-27 11:13:24 +000012#endif
Eric Biederman8d9c1232003-06-17 08:42:17 +000013 );
14#else
Eric Biederman52685572003-05-19 19:16:21 +000015 volatile unsigned long *ptr;
Eric Biederman8ca8d762003-04-22 19:02:15 +000016 ptr = (void *)addr;
17 *ptr = value;
Eric Biederman8d9c1232003-06-17 08:42:17 +000018#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000019}
20
21static unsigned long read_phys(unsigned long addr)
22{
Eric Biederman52685572003-05-19 19:16:21 +000023 volatile unsigned long *ptr;
Eric Biederman8ca8d762003-04-22 19:02:15 +000024 ptr = (void *)addr;
25 return *ptr;
26}
27
Eric Biederman8d9c1232003-06-17 08:42:17 +000028static void ram_fill(unsigned long start, unsigned long stop)
Eric Biederman8ca8d762003-04-22 19:02:15 +000029{
30 unsigned long addr;
31 /*
32 * Fill.
33 */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000034#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerde3206a2010-02-22 06:09:43 +000035 printk_debug("DRAM fill: 0x%08lx-0x%08lx\r\n", start, stop);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000036#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000037 print_debug("DRAM fill: ");
38 print_debug_hex32(start);
39 print_debug("-");
40 print_debug_hex32(stop);
41 print_debug("\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000042#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000043 for(addr = start; addr < stop ; addr += 4) {
44 /* Display address being filled */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000045 if (!(addr & 0xfffff)) {
46#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerde3206a2010-02-22 06:09:43 +000047 printk_debug("%08lx \r", addr);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000048#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000049 print_debug_hex32(addr);
Eric Biederman69afe282004-11-11 06:53:24 +000050 print_debug(" \r");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000051#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000052 }
53 write_phys(addr, addr);
54 };
Stefan Reinauera7acc512010-02-25 13:40:49 +000055#if CONFIG_SSE2
56 // Needed for movnti
57 asm volatile ("sfence" ::: "memory");
58#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000059 /* Display final address */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000060#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerde3206a2010-02-22 06:09:43 +000061 printk_debug("%08lx\r\nDRAM filled\r\n", addr);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000062#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000063 print_debug_hex32(addr);
64 print_debug("\r\nDRAM filled\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000065#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000066}
67
Eric Biederman8d9c1232003-06-17 08:42:17 +000068static void ram_verify(unsigned long start, unsigned long stop)
Eric Biederman8ca8d762003-04-22 19:02:15 +000069{
70 unsigned long addr;
Eric Biederman69afe282004-11-11 06:53:24 +000071 int i = 0;
Eric Biederman8ca8d762003-04-22 19:02:15 +000072 /*
73 * Verify.
74 */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000075#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerde3206a2010-02-22 06:09:43 +000076 printk_debug("DRAM verify: 0x%08lx-0x%08lx\r\n", start, stop);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000077#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000078 print_debug("DRAM verify: ");
79 print_debug_hex32(start);
80 print_debug_char('-');
81 print_debug_hex32(stop);
82 print_debug("\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000083#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000084 for(addr = start; addr < stop ; addr += 4) {
85 unsigned long value;
86 /* Display address being tested */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000087 if (!(addr & 0xfffff)) {
88#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerde3206a2010-02-22 06:09:43 +000089 printk_debug("%08lx \r", addr);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000090#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000091 print_debug_hex32(addr);
Eric Biederman69afe282004-11-11 06:53:24 +000092 print_debug(" \r");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000093#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000094 }
95 value = read_phys(addr);
96 if (value != addr) {
97 /* Display address with error */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000098#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerde3206a2010-02-22 06:09:43 +000099 printk_err("Fail: @0x%08lx Read value=0x%08lx\r\n", addr, value);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000100#else
Richard Smithffb7d8a2006-04-01 04:10:44 +0000101 print_err("Fail: @0x");
Eric Biederman8ca8d762003-04-22 19:02:15 +0000102 print_err_hex32(addr);
Richard Smithffb7d8a2006-04-01 04:10:44 +0000103 print_err(" Read value=0x");
Eric Biederman8ca8d762003-04-22 19:02:15 +0000104 print_err_hex32(value);
105 print_err("\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000106#endif
Eric Biederman69afe282004-11-11 06:53:24 +0000107 i++;
Richard Smithffb7d8a2006-04-01 04:10:44 +0000108 if(i>256) {
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000109#if CONFIG_USE_PRINTK_IN_CAR
110 printk_debug("Aborting.\n\r");
111#else
Richard Smithffb7d8a2006-04-01 04:10:44 +0000112 print_debug("Aborting.\n\r");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000113#endif
Richard Smithffb7d8a2006-04-01 04:10:44 +0000114 break;
115 }
Eric Biederman8ca8d762003-04-22 19:02:15 +0000116 }
117 }
118 /* Display final address */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000119#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000120 printk_debug("%08lx", addr);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000121#else
Eric Biederman8ca8d762003-04-22 19:02:15 +0000122 print_debug_hex32(addr);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000123#endif
124
Richard Smithffb7d8a2006-04-01 04:10:44 +0000125 if (i) {
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000126#if CONFIG_USE_PRINTK_IN_CAR
127 printk_debug("\r\nDRAM did _NOT_ verify!\r\n");
128#else
Richard Smithffb7d8a2006-04-01 04:10:44 +0000129 print_debug("\r\nDRAM did _NOT_ verify!\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000130#endif
131 die("DRAM ERROR");
Richard Smithffb7d8a2006-04-01 04:10:44 +0000132 }
133 else {
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000134#if CONFIG_USE_PRINTK_IN_CAR
135 printk_debug("\r\nDRAM range verified.\r\n");
136#else
Richard Smithffb7d8a2006-04-01 04:10:44 +0000137 print_debug("\r\nDRAM range verified.\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000138#endif
Richard Smithffb7d8a2006-04-01 04:10:44 +0000139 }
Eric Biederman8ca8d762003-04-22 19:02:15 +0000140}
141
142
Eric Biederman8d9c1232003-06-17 08:42:17 +0000143void ram_check(unsigned long start, unsigned long stop)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000144{
Eric Biederman8ca8d762003-04-22 19:02:15 +0000145 /*
146 * This is much more of a "Is my DRAM properly configured?"
147 * test than a "Is my DRAM faulty?" test. Not all bits
148 * are tested. -Tyson
149 */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000150#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000151 printk_debug("Testing DRAM : %08lx - %08lx\r\n", start, stop);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000152#else
Ronald G. Minnichbfdc5622004-03-22 04:24:29 +0000153 print_debug("Testing DRAM : ");
154 print_debug_hex32(start);
155 print_debug("-");
156 print_debug_hex32(stop);
157 print_debug("\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000158#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +0000159 ram_fill(start, stop);
160 ram_verify(start, stop);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000161#if CONFIG_USE_PRINTK_IN_CAR
162 printk_debug("Done.\r\n");
163#else
Ronald G. Minnichbfdc5622004-03-22 04:24:29 +0000164 print_debug("Done.\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000165#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +0000166}
167