This patch unifies the use of config options in v2 to all start with CONFIG_
[coreboot.git] / src / ram / ramtest.c
1 static void write_phys(unsigned long addr, unsigned long value)
2 {
3 #if CONFIG_HAVE_MOVNTI
4         asm volatile(
5                 "movnti %1, (%0)"
6                 : /* outputs */
7                 : "r" (addr), "r" (value) /* inputs */
8 #ifndef __GNUC__
9                 : /* clobbers */
10 #endif
11                 );
12 #else
13         volatile unsigned long *ptr;
14         ptr = (void *)addr;
15         *ptr = value;
16 #endif
17 }
18
19 static unsigned long read_phys(unsigned long addr)
20 {
21         volatile unsigned long *ptr;
22         ptr = (void *)addr;
23         return *ptr;
24 }
25
26 static void ram_fill(unsigned long start, unsigned long stop)
27 {
28         unsigned long addr;
29         /* 
30          * Fill.
31          */
32 #if CONFIG_USE_PRINTK_IN_CAR
33         printk_debug("DRAM fill: 0x%08x-0x%08x\r\n", start, stop);
34 #else
35         print_debug("DRAM fill: ");
36         print_debug_hex32(start);
37         print_debug("-");
38         print_debug_hex32(stop);
39         print_debug("\r\n");
40 #endif
41         for(addr = start; addr < stop ; addr += 4) {
42                 /* Display address being filled */
43                 if (!(addr & 0xfffff)) {
44 #if CONFIG_USE_PRINTK_IN_CAR
45                         printk_debug("%08x \r", addr);
46 #else
47                         print_debug_hex32(addr);
48                         print_debug(" \r");
49 #endif
50                 }
51                 write_phys(addr, addr);
52         };
53         /* Display final address */
54 #if CONFIG_USE_PRINTK_IN_CAR
55         printk_debug("%08x\r\nDRAM filled\r\n", addr);
56 #else
57         print_debug_hex32(addr);
58         print_debug("\r\nDRAM filled\r\n");
59 #endif
60 }
61
62 static void ram_verify(unsigned long start, unsigned long stop)
63 {
64         unsigned long addr;
65         int i = 0;
66         /* 
67          * Verify.
68          */
69 #if CONFIG_USE_PRINTK_IN_CAR
70         printk_debug("DRAM verify: 0x%08x-0x%08x\r\n", start, stop);
71 #else
72         print_debug("DRAM verify: ");
73         print_debug_hex32(start);
74         print_debug_char('-');
75         print_debug_hex32(stop);
76         print_debug("\r\n");
77 #endif
78         for(addr = start; addr < stop ; addr += 4) {
79                 unsigned long value;
80                 /* Display address being tested */
81                 if (!(addr & 0xfffff)) {
82 #if CONFIG_USE_PRINTK_IN_CAR
83                         printk_debug("%08x \r", addr);
84 #else
85                         print_debug_hex32(addr);
86                         print_debug(" \r");
87 #endif
88                 }
89                 value = read_phys(addr);
90                 if (value != addr) {
91                         /* Display address with error */
92 #if CONFIG_USE_PRINTK_IN_CAR
93                         printk_err("Fail: @0x%08x Read value=0x%08x\r\n", addr, value);
94 #else
95                         print_err("Fail: @0x");
96                         print_err_hex32(addr);
97                         print_err(" Read value=0x");
98                         print_err_hex32(value);
99                         print_err("\r\n");
100 #endif
101                         i++;
102                         if(i>256) {
103 #if CONFIG_USE_PRINTK_IN_CAR
104                                 printk_debug("Aborting.\n\r");
105 #else
106                                 print_debug("Aborting.\n\r");
107 #endif
108                                 break;
109                         }
110                 }
111         }
112         /* Display final address */
113 #if CONFIG_USE_PRINTK_IN_CAR
114         printk_debug("%08x", addr);
115 #else
116         print_debug_hex32(addr);
117 #endif
118
119         if (i) {
120 #if CONFIG_USE_PRINTK_IN_CAR
121                 printk_debug("\r\nDRAM did _NOT_ verify!\r\n");
122 #else
123                 print_debug("\r\nDRAM did _NOT_ verify!\r\n");
124 #endif
125                 die("DRAM ERROR");
126         }
127         else {
128 #if CONFIG_USE_PRINTK_IN_CAR
129                 printk_debug("\r\nDRAM range verified.\r\n");
130 #else
131                 print_debug("\r\nDRAM range verified.\r\n");
132 #endif
133         }
134 }
135
136
137 void ram_check(unsigned long start, unsigned long stop)
138 {
139         /*
140          * This is much more of a "Is my DRAM properly configured?"
141          * test than a "Is my DRAM faulty?" test.  Not all bits
142          * are tested.   -Tyson
143          */
144 #if CONFIG_USE_PRINTK_IN_CAR
145         printk_debug("Testing DRAM : %08x - %08x\r\n", start, stop);
146 #else
147         print_debug("Testing DRAM : ");
148         print_debug_hex32(start);
149         print_debug("-");       
150         print_debug_hex32(stop);
151         print_debug("\r\n");
152 #endif
153         ram_fill(start, stop);
154         ram_verify(start, stop);
155 #if CONFIG_USE_PRINTK_IN_CAR
156         printk_debug("Done.\r\n");
157 #else
158         print_debug("Done.\r\n");
159 #endif
160 }
161