Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 1 | #include <lib.h> /* Prototypes */ |
| 2 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 3 | static void write_phys(unsigned long addr, unsigned long value) |
| 4 | { |
Stefan Reinauer | a7acc51 | 2010-02-25 13:40:49 +0000 | [diff] [blame] | 5 | // 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 Biederman | 8d9c123 | 2003-06-17 08:42:17 +0000 | [diff] [blame] | 8 | asm volatile( |
| 9 | "movnti %1, (%0)" |
| 10 | : /* outputs */ |
| 11 | : "r" (addr), "r" (value) /* inputs */ |
Stefan Reinauer | 7671293 | 2004-05-27 11:13:24 +0000 | [diff] [blame] | 12 | #ifndef __GNUC__ |
Eric Biederman | 8d9c123 | 2003-06-17 08:42:17 +0000 | [diff] [blame] | 13 | : /* clobbers */ |
Stefan Reinauer | 7671293 | 2004-05-27 11:13:24 +0000 | [diff] [blame] | 14 | #endif |
Eric Biederman | 8d9c123 | 2003-06-17 08:42:17 +0000 | [diff] [blame] | 15 | ); |
| 16 | #else |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 17 | volatile unsigned long *ptr; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 18 | ptr = (void *)addr; |
| 19 | *ptr = value; |
Eric Biederman | 8d9c123 | 2003-06-17 08:42:17 +0000 | [diff] [blame] | 20 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | static unsigned long read_phys(unsigned long addr) |
| 24 | { |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 25 | volatile unsigned long *ptr; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 26 | ptr = (void *)addr; |
| 27 | return *ptr; |
| 28 | } |
| 29 | |
Eric Biederman | 8d9c123 | 2003-06-17 08:42:17 +0000 | [diff] [blame] | 30 | static void ram_fill(unsigned long start, unsigned long stop) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 31 | { |
| 32 | unsigned long addr; |
| 33 | /* |
| 34 | * Fill. |
| 35 | */ |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 36 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 37 | printk(BIOS_DEBUG, "DRAM fill: 0x%08lx-0x%08lx\r\n", start, stop); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 38 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 39 | print_debug("DRAM fill: "); |
| 40 | print_debug_hex32(start); |
| 41 | print_debug("-"); |
| 42 | print_debug_hex32(stop); |
| 43 | print_debug("\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 44 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 45 | for(addr = start; addr < stop ; addr += 4) { |
| 46 | /* Display address being filled */ |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 47 | if (!(addr & 0xfffff)) { |
| 48 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 49 | printk(BIOS_DEBUG, "%08lx \r", addr); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 50 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 51 | print_debug_hex32(addr); |
Eric Biederman | 69afe28 | 2004-11-11 06:53:24 +0000 | [diff] [blame] | 52 | print_debug(" \r"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 53 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 54 | } |
| 55 | write_phys(addr, addr); |
| 56 | }; |
Stefan Reinauer | a7acc51 | 2010-02-25 13:40:49 +0000 | [diff] [blame] | 57 | #if CONFIG_SSE2 |
| 58 | // Needed for movnti |
| 59 | asm volatile ("sfence" ::: "memory"); |
| 60 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 61 | /* Display final address */ |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 62 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 63 | printk(BIOS_DEBUG, "%08lx\r\nDRAM filled\r\n", addr); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 64 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 65 | print_debug_hex32(addr); |
| 66 | print_debug("\r\nDRAM filled\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 67 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Eric Biederman | 8d9c123 | 2003-06-17 08:42:17 +0000 | [diff] [blame] | 70 | static void ram_verify(unsigned long start, unsigned long stop) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 71 | { |
| 72 | unsigned long addr; |
Eric Biederman | 69afe28 | 2004-11-11 06:53:24 +0000 | [diff] [blame] | 73 | int i = 0; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 74 | /* |
| 75 | * Verify. |
| 76 | */ |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 77 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 78 | printk(BIOS_DEBUG, "DRAM verify: 0x%08lx-0x%08lx\r\n", start, stop); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 79 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 80 | print_debug("DRAM verify: "); |
| 81 | print_debug_hex32(start); |
| 82 | print_debug_char('-'); |
| 83 | print_debug_hex32(stop); |
| 84 | print_debug("\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 85 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 86 | for(addr = start; addr < stop ; addr += 4) { |
| 87 | unsigned long value; |
| 88 | /* Display address being tested */ |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 89 | if (!(addr & 0xfffff)) { |
| 90 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 91 | printk(BIOS_DEBUG, "%08lx \r", addr); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 92 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 93 | print_debug_hex32(addr); |
Eric Biederman | 69afe28 | 2004-11-11 06:53:24 +0000 | [diff] [blame] | 94 | print_debug(" \r"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 95 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 96 | } |
| 97 | value = read_phys(addr); |
| 98 | if (value != addr) { |
| 99 | /* Display address with error */ |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 100 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 101 | printk(BIOS_ERR, "Fail: @0x%08lx Read value=0x%08lx\r\n", addr, value); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 102 | #else |
Richard Smith | ffb7d8a | 2006-04-01 04:10:44 +0000 | [diff] [blame] | 103 | print_err("Fail: @0x"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 104 | print_err_hex32(addr); |
Richard Smith | ffb7d8a | 2006-04-01 04:10:44 +0000 | [diff] [blame] | 105 | print_err(" Read value=0x"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 106 | print_err_hex32(value); |
| 107 | print_err("\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 108 | #endif |
Eric Biederman | 69afe28 | 2004-11-11 06:53:24 +0000 | [diff] [blame] | 109 | i++; |
Richard Smith | ffb7d8a | 2006-04-01 04:10:44 +0000 | [diff] [blame] | 110 | if(i>256) { |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 111 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 112 | printk(BIOS_DEBUG, "Aborting.\n\r"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 113 | #else |
Richard Smith | ffb7d8a | 2006-04-01 04:10:44 +0000 | [diff] [blame] | 114 | print_debug("Aborting.\n\r"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 115 | #endif |
Richard Smith | ffb7d8a | 2006-04-01 04:10:44 +0000 | [diff] [blame] | 116 | break; |
| 117 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | /* Display final address */ |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 121 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 122 | printk(BIOS_DEBUG, "%08lx", addr); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 123 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 124 | print_debug_hex32(addr); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 125 | #endif |
| 126 | |
Richard Smith | ffb7d8a | 2006-04-01 04:10:44 +0000 | [diff] [blame] | 127 | if (i) { |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 128 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 129 | printk(BIOS_DEBUG, "\r\nDRAM did _NOT_ verify!\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 130 | #else |
Richard Smith | ffb7d8a | 2006-04-01 04:10:44 +0000 | [diff] [blame] | 131 | print_debug("\r\nDRAM did _NOT_ verify!\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 132 | #endif |
| 133 | die("DRAM ERROR"); |
Richard Smith | ffb7d8a | 2006-04-01 04:10:44 +0000 | [diff] [blame] | 134 | } |
| 135 | else { |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 136 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 137 | printk(BIOS_DEBUG, "\r\nDRAM range verified.\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 138 | #else |
Richard Smith | ffb7d8a | 2006-04-01 04:10:44 +0000 | [diff] [blame] | 139 | print_debug("\r\nDRAM range verified.\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 140 | #endif |
Richard Smith | ffb7d8a | 2006-04-01 04:10:44 +0000 | [diff] [blame] | 141 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | |
Eric Biederman | 8d9c123 | 2003-06-17 08:42:17 +0000 | [diff] [blame] | 145 | void ram_check(unsigned long start, unsigned long stop) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 146 | { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 147 | /* |
| 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 Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 152 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 153 | printk(BIOS_DEBUG, "Testing DRAM : %08lx - %08lx\r\n", start, stop); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 154 | #else |
Ronald G. Minnich | bfdc562 | 2004-03-22 04:24:29 +0000 | [diff] [blame] | 155 | print_debug("Testing DRAM : "); |
| 156 | print_debug_hex32(start); |
| 157 | print_debug("-"); |
| 158 | print_debug_hex32(stop); |
| 159 | print_debug("\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 160 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 161 | ram_fill(start, stop); |
| 162 | ram_verify(start, stop); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 163 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame^] | 164 | printk(BIOS_DEBUG, "Done.\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 165 | #else |
Ronald G. Minnich | bfdc562 | 2004-03-22 04:24:29 +0000 | [diff] [blame] | 166 | print_debug("Done.\r\n"); |
Stefan Reinauer | 48b85fc | 2008-08-01 12:12:37 +0000 | [diff] [blame] | 167 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 168 | } |
| 169 | |