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