diff options
Diffstat (limited to 'arch/x86/mm/memtest.c')
-rw-r--r-- | arch/x86/mm/memtest.c | 159 |
1 files changed, 84 insertions, 75 deletions
diff --git a/arch/x86/mm/memtest.c b/arch/x86/mm/memtest.c index 9cab18b0b857..605c8be06217 100644 --- a/arch/x86/mm/memtest.c +++ b/arch/x86/mm/memtest.c | |||
@@ -9,44 +9,44 @@ | |||
9 | 9 | ||
10 | #include <asm/e820.h> | 10 | #include <asm/e820.h> |
11 | 11 | ||
12 | static void __init memtest(unsigned long start_phys, unsigned long size, | 12 | static u64 patterns[] __initdata = { |
13 | unsigned pattern) | 13 | 0, |
14 | 0xffffffffffffffffULL, | ||
15 | 0x5555555555555555ULL, | ||
16 | 0xaaaaaaaaaaaaaaaaULL, | ||
17 | 0x1111111111111111ULL, | ||
18 | 0x2222222222222222ULL, | ||
19 | 0x4444444444444444ULL, | ||
20 | 0x8888888888888888ULL, | ||
21 | 0x3333333333333333ULL, | ||
22 | 0x6666666666666666ULL, | ||
23 | 0x9999999999999999ULL, | ||
24 | 0xccccccccccccccccULL, | ||
25 | 0x7777777777777777ULL, | ||
26 | 0xbbbbbbbbbbbbbbbbULL, | ||
27 | 0xddddddddddddddddULL, | ||
28 | 0xeeeeeeeeeeeeeeeeULL, | ||
29 | 0x7a6c7258554e494cULL, /* yeah ;-) */ | ||
30 | }; | ||
31 | |||
32 | static void __init reserve_bad_mem(u64 pattern, u64 start_bad, u64 end_bad) | ||
14 | { | 33 | { |
15 | unsigned long i; | 34 | printk(KERN_INFO " %016llx bad mem addr %010llx - %010llx reserved\n", |
16 | unsigned long *start; | 35 | (unsigned long long) pattern, |
17 | unsigned long start_bad; | 36 | (unsigned long long) start_bad, |
18 | unsigned long last_bad; | 37 | (unsigned long long) end_bad); |
19 | unsigned long val; | 38 | reserve_early(start_bad, end_bad, "BAD RAM"); |
20 | unsigned long start_phys_aligned; | 39 | } |
21 | unsigned long count; | 40 | |
22 | unsigned long incr; | 41 | static void __init memtest(u64 pattern, u64 start_phys, u64 size) |
23 | 42 | { | |
24 | switch (pattern) { | 43 | u64 i, count; |
25 | case 0: | 44 | u64 *start; |
26 | val = 0UL; | 45 | u64 start_bad, last_bad; |
27 | break; | 46 | u64 start_phys_aligned; |
28 | case 1: | 47 | size_t incr; |
29 | val = -1UL; | ||
30 | break; | ||
31 | case 2: | ||
32 | #ifdef CONFIG_X86_64 | ||
33 | val = 0x5555555555555555UL; | ||
34 | #else | ||
35 | val = 0x55555555UL; | ||
36 | #endif | ||
37 | break; | ||
38 | case 3: | ||
39 | #ifdef CONFIG_X86_64 | ||
40 | val = 0xaaaaaaaaaaaaaaaaUL; | ||
41 | #else | ||
42 | val = 0xaaaaaaaaUL; | ||
43 | #endif | ||
44 | break; | ||
45 | default: | ||
46 | return; | ||
47 | } | ||
48 | 48 | ||
49 | incr = sizeof(unsigned long); | 49 | incr = sizeof(pattern); |
50 | start_phys_aligned = ALIGN(start_phys, incr); | 50 | start_phys_aligned = ALIGN(start_phys, incr); |
51 | count = (size - (start_phys_aligned - start_phys))/incr; | 51 | count = (size - (start_phys_aligned - start_phys))/incr; |
52 | start = __va(start_phys_aligned); | 52 | start = __va(start_phys_aligned); |
@@ -54,25 +54,42 @@ static void __init memtest(unsigned long start_phys, unsigned long size, | |||
54 | last_bad = 0; | 54 | last_bad = 0; |
55 | 55 | ||
56 | for (i = 0; i < count; i++) | 56 | for (i = 0; i < count; i++) |
57 | start[i] = val; | 57 | start[i] = pattern; |
58 | for (i = 0; i < count; i++, start++, start_phys_aligned += incr) { | 58 | for (i = 0; i < count; i++, start++, start_phys_aligned += incr) { |
59 | if (*start != val) { | 59 | if (*start == pattern) |
60 | if (start_phys_aligned == last_bad + incr) { | 60 | continue; |
61 | last_bad += incr; | 61 | if (start_phys_aligned == last_bad + incr) { |
62 | } else { | 62 | last_bad += incr; |
63 | if (start_bad) { | 63 | continue; |
64 | printk(KERN_CONT "\n %016lx bad mem addr %010lx - %010lx reserved", | ||
65 | val, start_bad, last_bad + incr); | ||
66 | reserve_early(start_bad, last_bad + incr, "BAD RAM"); | ||
67 | } | ||
68 | start_bad = last_bad = start_phys_aligned; | ||
69 | } | ||
70 | } | 64 | } |
65 | if (start_bad) | ||
66 | reserve_bad_mem(pattern, start_bad, last_bad + incr); | ||
67 | start_bad = last_bad = start_phys_aligned; | ||
71 | } | 68 | } |
72 | if (start_bad) { | 69 | if (start_bad) |
73 | printk(KERN_CONT "\n %016lx bad mem addr %010lx - %010lx reserved", | 70 | reserve_bad_mem(pattern, start_bad, last_bad + incr); |
74 | val, start_bad, last_bad + incr); | 71 | } |
75 | reserve_early(start_bad, last_bad + incr, "BAD RAM"); | 72 | |
73 | static void __init do_one_pass(u64 pattern, u64 start, u64 end) | ||
74 | { | ||
75 | u64 size = 0; | ||
76 | |||
77 | while (start < end) { | ||
78 | start = find_e820_area_size(start, &size, 1); | ||
79 | |||
80 | /* done ? */ | ||
81 | if (start >= end) | ||
82 | break; | ||
83 | if (start + size > end) | ||
84 | size = end - start; | ||
85 | |||
86 | printk(KERN_INFO " %010llx - %010llx pattern %016llx\n", | ||
87 | (unsigned long long) start, | ||
88 | (unsigned long long) start + size, | ||
89 | (unsigned long long) cpu_to_be64(pattern)); | ||
90 | memtest(pattern, start, size); | ||
91 | |||
92 | start += size; | ||
76 | } | 93 | } |
77 | } | 94 | } |
78 | 95 | ||
@@ -83,6 +100,9 @@ static int __init parse_memtest(char *arg) | |||
83 | { | 100 | { |
84 | if (arg) | 101 | if (arg) |
85 | memtest_pattern = simple_strtoul(arg, NULL, 0); | 102 | memtest_pattern = simple_strtoul(arg, NULL, 0); |
103 | else | ||
104 | memtest_pattern = ARRAY_SIZE(patterns); | ||
105 | |||
86 | return 0; | 106 | return 0; |
87 | } | 107 | } |
88 | 108 | ||
@@ -90,33 +110,22 @@ early_param("memtest", parse_memtest); | |||
90 | 110 | ||
91 | void __init early_memtest(unsigned long start, unsigned long end) | 111 | void __init early_memtest(unsigned long start, unsigned long end) |
92 | { | 112 | { |
93 | u64 t_start, t_size; | 113 | unsigned int i; |
94 | unsigned pattern; | 114 | unsigned int idx = 0; |
95 | 115 | ||
96 | if (!memtest_pattern) | 116 | if (!memtest_pattern) |
97 | return; | 117 | return; |
98 | 118 | ||
99 | printk(KERN_INFO "early_memtest: pattern num %d", memtest_pattern); | 119 | printk(KERN_INFO "early_memtest: # of tests: %d\n", memtest_pattern); |
100 | for (pattern = 0; pattern < memtest_pattern; pattern++) { | 120 | for (i = 0; i < memtest_pattern; i++) { |
101 | t_start = start; | 121 | idx = i % ARRAY_SIZE(patterns); |
102 | t_size = 0; | 122 | do_one_pass(patterns[idx], start, end); |
103 | while (t_start < end) { | 123 | } |
104 | t_start = find_e820_area_size(t_start, &t_size, 1); | ||
105 | |||
106 | /* done ? */ | ||
107 | if (t_start >= end) | ||
108 | break; | ||
109 | if (t_start + t_size > end) | ||
110 | t_size = end - t_start; | ||
111 | |||
112 | printk(KERN_CONT "\n %010llx - %010llx pattern %d", | ||
113 | (unsigned long long)t_start, | ||
114 | (unsigned long long)t_start + t_size, pattern); | ||
115 | |||
116 | memtest(t_start, t_size, pattern); | ||
117 | 124 | ||
118 | t_start += t_size; | 125 | if (idx > 0) { |
119 | } | 126 | printk(KERN_INFO "early_memtest: wipe out " |
127 | "test pattern from memory\n"); | ||
128 | /* additional test with pattern 0 will do this */ | ||
129 | do_one_pass(0, start, end); | ||
120 | } | 130 | } |
121 | printk(KERN_CONT "\n"); | ||
122 | } | 131 | } |