fix interrupt for f5 (ehci)
[coreboot.git] / src / ram / ramtest.c
1 static void write_phys(unsigned long addr, unsigned long value)
2 {
3 #if 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         print_debug("DRAM fill: ");
33         print_debug_hex32(start);
34         print_debug("-");
35         print_debug_hex32(stop);
36         print_debug("\r\n");
37         for(addr = start; addr < stop ; addr += 4) {
38                 /* Display address being filled */
39                 if (!(addr & 0xffff)) {
40                         print_debug_hex32(addr);
41                         print_debug(" \r");
42                 }
43                 write_phys(addr, addr);
44         };
45         /* Display final address */
46         print_debug_hex32(addr);
47         print_debug("\r\nDRAM filled\r\n");
48 }
49
50 static void ram_verify(unsigned long start, unsigned long stop)
51 {
52         unsigned long addr;
53         int i = 0;
54         /* 
55          * Verify.
56          */
57         print_debug("DRAM verify: ");
58         print_debug_hex32(start);
59         print_debug_char('-');
60         print_debug_hex32(stop);
61         print_debug("\r\n");
62         for(addr = start; addr < stop ; addr += 4) {
63                 unsigned long value;
64                 /* Display address being tested */
65                 if (!(addr & 0xffff)) {
66                         print_debug_hex32(addr);
67                         print_debug(" \r");
68                 }
69                 value = read_phys(addr);
70                 if (value != addr) {
71                         /* Display address with error */
72                         print_err("Fail: @0x");
73                         print_err_hex32(addr);
74                         print_err(" Read value=0x");
75                         print_err_hex32(value);
76                         print_err("\r\n");
77                         i++;
78                         if(i>256) {
79                                 print_debug("Aborting.\n\r");
80                                 break;
81                         }
82                 }
83         }
84         /* Display final address */
85         print_debug_hex32(addr);
86         if (i) {
87                 print_debug("\r\nDRAM did _NOT_ verify!\r\n");
88         }
89         else {
90                 print_debug("\r\nDRAM range verified.\r\n");
91         }
92 }
93
94
95 void ram_check(unsigned long start, unsigned long stop)
96 {
97         int result;
98         /*
99          * This is much more of a "Is my DRAM properly configured?"
100          * test than a "Is my DRAM faulty?" test.  Not all bits
101          * are tested.   -Tyson
102          */
103         print_debug("Testing DRAM : ");
104         print_debug_hex32(start);
105         print_debug("-");       
106         print_debug_hex32(stop);
107         print_debug("\r\n");
108         ram_fill(start, stop);
109         ram_verify(start, stop);
110         print_debug("Done.\r\n");
111 }
112