blob: 068d3bd7055c2754e86dec5f23fb751ee45bb28c [file] [log] [blame]
Eric Biederman8d9c1232003-06-17 08:42:17 +00001#if defined(i786)
2#define HAVE_MOVNTI 1
3#endif
4#if defined(k8)
5#define HAVE_MOVNTI 1
6#endif
7
Eric Biederman8ca8d762003-04-22 19:02:15 +00008static void write_phys(unsigned long addr, unsigned long value)
9{
Eric Biederman8d9c1232003-06-17 08:42:17 +000010#if HAVE_MOVNTI
11 asm volatile(
12 "movnti %1, (%0)"
13 : /* outputs */
14 : "r" (addr), "r" (value) /* inputs */
15 : /* clobbers */
16 );
17#else
Eric Biederman52685572003-05-19 19:16:21 +000018 volatile unsigned long *ptr;
Eric Biederman8ca8d762003-04-22 19:02:15 +000019 ptr = (void *)addr;
20 *ptr = value;
Eric Biederman8d9c1232003-06-17 08:42:17 +000021#endif
Eric Biederman8ca8d762003-04-22 19:02:15 +000022}
23
24static unsigned long read_phys(unsigned long addr)
25{
Eric Biederman52685572003-05-19 19:16:21 +000026 volatile unsigned long *ptr;
Eric Biederman8ca8d762003-04-22 19:02:15 +000027 ptr = (void *)addr;
28 return *ptr;
29}
30
Eric Biederman8d9c1232003-06-17 08:42:17 +000031static void ram_fill(unsigned long start, unsigned long stop)
Eric Biederman8ca8d762003-04-22 19:02:15 +000032{
33 unsigned long addr;
34 /*
35 * Fill.
36 */
37 print_debug("DRAM fill: ");
38 print_debug_hex32(start);
39 print_debug("-");
40 print_debug_hex32(stop);
41 print_debug("\r\n");
42 for(addr = start; addr < stop ; addr += 4) {
43 /* Display address being filled */
Eric Biederman8d9c1232003-06-17 08:42:17 +000044 if (!(addr & 0xffff)) {
Eric Biederman8ca8d762003-04-22 19:02:15 +000045 print_debug_hex32(addr);
46 print_debug("\r");
47 }
48 write_phys(addr, addr);
49 };
50 /* Display final address */
51 print_debug_hex32(addr);
52 print_debug("\r\nDRAM filled\r\n");
53}
54
Eric Biederman8d9c1232003-06-17 08:42:17 +000055static void ram_verify(unsigned long start, unsigned long stop)
Eric Biederman8ca8d762003-04-22 19:02:15 +000056{
57 unsigned long addr;
58 /*
59 * Verify.
60 */
61 print_debug("DRAM verify: ");
62 print_debug_hex32(start);
63 print_debug_char('-');
64 print_debug_hex32(stop);
65 print_debug("\r\n");
66 for(addr = start; addr < stop ; addr += 4) {
67 unsigned long value;
68 /* Display address being tested */
Eric Biederman8d9c1232003-06-17 08:42:17 +000069 if (!(addr & 0xffff)) {
Eric Biederman8ca8d762003-04-22 19:02:15 +000070 print_debug_hex32(addr);
71 print_debug("\r");
72 }
73 value = read_phys(addr);
74 if (value != addr) {
75 /* Display address with error */
76 print_err_hex32(addr);
77 print_err_char(':');
78 print_err_hex32(value);
79 print_err("\r\n");
80 }
81 }
82 /* Display final address */
83 print_debug_hex32(addr);
84 print_debug("\r\nDRAM verified\r\n");
85}
86
87
Eric Biederman8d9c1232003-06-17 08:42:17 +000088void ram_check(unsigned long start, unsigned long stop)
Eric Biederman8ca8d762003-04-22 19:02:15 +000089{
90 int result;
91 /*
92 * This is much more of a "Is my DRAM properly configured?"
93 * test than a "Is my DRAM faulty?" test. Not all bits
94 * are tested. -Tyson
95 */
96 print_debug("Testing DRAM : ");
97 print_debug_hex32(start);
98 print_debug("-");
99 print_debug_hex32(stop);
100 print_debug("\r\n");
101 ram_fill(start, stop);
102 ram_verify(start, stop);
103 print_debug("Done.\n");
104}
105