blob: 5f24bc1c7d7fadf9c93c0af2a6c10b5a67844ee6 [file] [log] [blame]
Myles Watson34261952010-03-19 02:33:40 +00001#include <lib.h> /* Prototypes */
2
Eric Biederman8ca8d762003-04-22 19:02:15 +00003static void write_phys(unsigned long addr, unsigned long value)
4{
Stefan Reinauera7acc512010-02-25 13:40:49 +00005 // Assembler in lib/ is very ugly. But we properly guarded
6 // it so let's obey this one for now
7#if CONFIG_SSE2
Eric Biederman8d9c1232003-06-17 08:42:17 +00008 asm volatile(
9 "movnti %1, (%0)"
10 : /* outputs */
11 : "r" (addr), "r" (value) /* inputs */
Stefan Reinauer76712932004-05-27 11:13:24 +000012#ifndef __GNUC__
Eric Biederman8d9c1232003-06-17 08:42:17 +000013 : /* clobbers */
Stefan Reinauer76712932004-05-27 11:13:24 +000014#endif
Eric Biederman8d9c1232003-06-17 08:42:17 +000015 );
16#else
Eric Biederman52685572003-05-19 19:16:21 +000017 volatile unsigned long *ptr;
Eric Biederman8ca8d762003-04-22 19:02:15 +000018 ptr = (void *)addr;
19 *ptr = value;
Eric Biederman8d9c1232003-06-17 08:42:17 +000020#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000021}
22
23static unsigned long read_phys(unsigned long addr)
24{
Eric Biederman52685572003-05-19 19:16:21 +000025 volatile unsigned long *ptr;
Eric Biederman8ca8d762003-04-22 19:02:15 +000026 ptr = (void *)addr;
27 return *ptr;
28}
29
Eric Biederman8d9c1232003-06-17 08:42:17 +000030static void ram_fill(unsigned long start, unsigned long stop)
Eric Biederman8ca8d762003-04-22 19:02:15 +000031{
32 unsigned long addr;
33 /*
34 * Fill.
35 */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000036#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000037 printk(BIOS_DEBUG, "DRAM fill: 0x%08lx-0x%08lx\r\n", start, stop);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000038#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000039 print_debug("DRAM fill: ");
40 print_debug_hex32(start);
41 print_debug("-");
42 print_debug_hex32(stop);
43 print_debug("\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000044#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000045 for(addr = start; addr < stop ; addr += 4) {
46 /* Display address being filled */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000047 if (!(addr & 0xfffff)) {
48#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000049 printk(BIOS_DEBUG, "%08lx \r", addr);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000050#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000051 print_debug_hex32(addr);
Eric Biederman69afe282004-11-11 06:53:24 +000052 print_debug(" \r");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000053#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000054 }
55 write_phys(addr, addr);
56 };
Stefan Reinauera7acc512010-02-25 13:40:49 +000057#if CONFIG_SSE2
58 // Needed for movnti
59 asm volatile ("sfence" ::: "memory");
60#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000061 /* Display final address */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000062#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000063 printk(BIOS_DEBUG, "%08lx\r\nDRAM filled\r\n", addr);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000064#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000065 print_debug_hex32(addr);
66 print_debug("\r\nDRAM filled\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000067#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000068}
69
Eric Biederman8d9c1232003-06-17 08:42:17 +000070static void ram_verify(unsigned long start, unsigned long stop)
Eric Biederman8ca8d762003-04-22 19:02:15 +000071{
72 unsigned long addr;
Eric Biederman69afe282004-11-11 06:53:24 +000073 int i = 0;
Eric Biederman8ca8d762003-04-22 19:02:15 +000074 /*
75 * Verify.
76 */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000077#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000078 printk(BIOS_DEBUG, "DRAM verify: 0x%08lx-0x%08lx\r\n", start, stop);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000079#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000080 print_debug("DRAM verify: ");
81 print_debug_hex32(start);
82 print_debug_char('-');
83 print_debug_hex32(stop);
84 print_debug("\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000085#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000086 for(addr = start; addr < stop ; addr += 4) {
87 unsigned long value;
88 /* Display address being tested */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000089 if (!(addr & 0xfffff)) {
90#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000091 printk(BIOS_DEBUG, "%08lx \r", addr);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000092#else
Eric Biederman8ca8d762003-04-22 19:02:15 +000093 print_debug_hex32(addr);
Eric Biederman69afe282004-11-11 06:53:24 +000094 print_debug(" \r");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +000095#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000096 }
97 value = read_phys(addr);
98 if (value != addr) {
99 /* Display address with error */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000100#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000101 printk(BIOS_ERR, "Fail: @0x%08lx Read value=0x%08lx\r\n", addr, value);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000102#else
Richard Smithffb7d8a2006-04-01 04:10:44 +0000103 print_err("Fail: @0x");
Eric Biederman8ca8d762003-04-22 19:02:15 +0000104 print_err_hex32(addr);
Richard Smithffb7d8a2006-04-01 04:10:44 +0000105 print_err(" Read value=0x");
Eric Biederman8ca8d762003-04-22 19:02:15 +0000106 print_err_hex32(value);
107 print_err("\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000108#endif
Eric Biederman69afe282004-11-11 06:53:24 +0000109 i++;
Richard Smithffb7d8a2006-04-01 04:10:44 +0000110 if(i>256) {
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000111#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000112 printk(BIOS_DEBUG, "Aborting.\n\r");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000113#else
Richard Smithffb7d8a2006-04-01 04:10:44 +0000114 print_debug("Aborting.\n\r");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000115#endif
Richard Smithffb7d8a2006-04-01 04:10:44 +0000116 break;
117 }
Eric Biederman8ca8d762003-04-22 19:02:15 +0000118 }
119 }
120 /* Display final address */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000121#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000122 printk(BIOS_DEBUG, "%08lx", addr);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000123#else
Eric Biederman8ca8d762003-04-22 19:02:15 +0000124 print_debug_hex32(addr);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000125#endif
126
Richard Smithffb7d8a2006-04-01 04:10:44 +0000127 if (i) {
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000128#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000129 printk(BIOS_DEBUG, "\r\nDRAM did _NOT_ verify!\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000130#else
Richard Smithffb7d8a2006-04-01 04:10:44 +0000131 print_debug("\r\nDRAM did _NOT_ verify!\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000132#endif
133 die("DRAM ERROR");
Richard Smithffb7d8a2006-04-01 04:10:44 +0000134 }
135 else {
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000136#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000137 printk(BIOS_DEBUG, "\r\nDRAM range verified.\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000138#else
Richard Smithffb7d8a2006-04-01 04:10:44 +0000139 print_debug("\r\nDRAM range verified.\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000140#endif
Richard Smithffb7d8a2006-04-01 04:10:44 +0000141 }
Eric Biederman8ca8d762003-04-22 19:02:15 +0000142}
143
144
Eric Biederman8d9c1232003-06-17 08:42:17 +0000145void ram_check(unsigned long start, unsigned long stop)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000146{
Eric Biederman8ca8d762003-04-22 19:02:15 +0000147 /*
148 * This is much more of a "Is my DRAM properly configured?"
149 * test than a "Is my DRAM faulty?" test. Not all bits
150 * are tested. -Tyson
151 */
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000152#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000153 printk(BIOS_DEBUG, "Testing DRAM : %08lx - %08lx\r\n", start, stop);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000154#else
Ronald G. Minnichbfdc5622004-03-22 04:24:29 +0000155 print_debug("Testing DRAM : ");
156 print_debug_hex32(start);
157 print_debug("-");
158 print_debug_hex32(stop);
159 print_debug("\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000160#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +0000161 ram_fill(start, stop);
162 ram_verify(start, stop);
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000163#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000164 printk(BIOS_DEBUG, "Done.\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000165#else
Ronald G. Minnichbfdc5622004-03-22 04:24:29 +0000166 print_debug("Done.\r\n");
Stefan Reinauer48b85fc2008-08-01 12:12:37 +0000167#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +0000168}
169