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