Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/errno.h> |
| 3 | #include <linux/string.h> |
| 4 | #include <linux/types.h> |
| 5 | #include <linux/mm.h> |
| 6 | #include <linux/smp.h> |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/pfn.h> |
| 9 | |
| 10 | #include <asm/e820.h> |
| 11 | |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame] | 12 | static u64 patterns[] __initdata = { |
| 13 | 0, |
| 14 | 0xffffffffffffffffULL, |
| 15 | 0x5555555555555555ULL, |
| 16 | 0xaaaaaaaaaaaaaaaaULL, |
| 17 | }; |
Andreas Herrmann | 40823f7 | 2009-02-25 11:26:18 +0100 | [diff] [blame] | 18 | |
Andreas Herrmann | 570c9e6 | 2009-02-25 11:28:58 +0100 | [diff] [blame^] | 19 | static void __init reserve_bad_mem(u64 pattern, u64 start_bad, u64 end_bad) |
Andreas Herrmann | 7dad169 | 2009-02-25 11:28:07 +0100 | [diff] [blame] | 20 | { |
Andreas Herrmann | 570c9e6 | 2009-02-25 11:28:58 +0100 | [diff] [blame^] | 21 | printk(KERN_INFO " %016llx bad mem addr %010llx - %010llx reserved\n", |
| 22 | (unsigned long long) pattern, |
| 23 | (unsigned long long) start_bad, |
| 24 | (unsigned long long) end_bad); |
Andreas Herrmann | 7dad169 | 2009-02-25 11:28:07 +0100 | [diff] [blame] | 25 | reserve_early(start_bad, end_bad, "BAD RAM"); |
| 26 | } |
| 27 | |
Andreas Herrmann | 570c9e6 | 2009-02-25 11:28:58 +0100 | [diff] [blame^] | 28 | static void __init memtest(u64 pattern, u64 start_phys, u64 size) |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 29 | { |
Andreas Herrmann | 570c9e6 | 2009-02-25 11:28:58 +0100 | [diff] [blame^] | 30 | u64 i, count; |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame] | 31 | u64 *start; |
Andreas Herrmann | 570c9e6 | 2009-02-25 11:28:58 +0100 | [diff] [blame^] | 32 | u64 start_bad, last_bad; |
| 33 | u64 start_phys_aligned; |
| 34 | size_t incr; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 35 | |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame] | 36 | incr = sizeof(pattern); |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 37 | start_phys_aligned = ALIGN(start_phys, incr); |
| 38 | count = (size - (start_phys_aligned - start_phys))/incr; |
| 39 | start = __va(start_phys_aligned); |
| 40 | start_bad = 0; |
| 41 | last_bad = 0; |
| 42 | |
| 43 | for (i = 0; i < count; i++) |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame] | 44 | start[i] = pattern; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 45 | for (i = 0; i < count; i++, start++, start_phys_aligned += incr) { |
Andreas Herrmann | 7dad169 | 2009-02-25 11:28:07 +0100 | [diff] [blame] | 46 | if (*start == pattern) |
| 47 | continue; |
| 48 | if (start_phys_aligned == last_bad + incr) { |
| 49 | last_bad += incr; |
| 50 | continue; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 51 | } |
Andreas Herrmann | 7dad169 | 2009-02-25 11:28:07 +0100 | [diff] [blame] | 52 | if (start_bad) |
| 53 | reserve_bad_mem(pattern, start_bad, last_bad + incr); |
| 54 | start_bad = last_bad = start_phys_aligned; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 55 | } |
Andreas Herrmann | 7dad169 | 2009-02-25 11:28:07 +0100 | [diff] [blame] | 56 | if (start_bad) |
| 57 | reserve_bad_mem(pattern, start_bad, last_bad + incr); |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /* default is disabled */ |
| 61 | static int memtest_pattern __initdata; |
| 62 | |
| 63 | static int __init parse_memtest(char *arg) |
| 64 | { |
| 65 | if (arg) |
| 66 | memtest_pattern = simple_strtoul(arg, NULL, 0); |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | early_param("memtest", parse_memtest); |
| 71 | |
| 72 | void __init early_memtest(unsigned long start, unsigned long end) |
| 73 | { |
| 74 | u64 t_start, t_size; |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame] | 75 | unsigned int i; |
| 76 | u64 pattern; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 77 | |
| 78 | if (!memtest_pattern) |
| 79 | return; |
| 80 | |
Andreas Herrmann | 570c9e6 | 2009-02-25 11:28:58 +0100 | [diff] [blame^] | 81 | printk(KERN_INFO "early_memtest: # of tests: %d\n", memtest_pattern); |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame] | 82 | for (i = 0; i < memtest_pattern; i++) { |
| 83 | unsigned int idx = i % ARRAY_SIZE(patterns); |
| 84 | pattern = patterns[idx]; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 85 | t_start = start; |
| 86 | t_size = 0; |
| 87 | while (t_start < end) { |
| 88 | t_start = find_e820_area_size(t_start, &t_size, 1); |
| 89 | |
| 90 | /* done ? */ |
| 91 | if (t_start >= end) |
| 92 | break; |
| 93 | if (t_start + t_size > end) |
| 94 | t_size = end - t_start; |
| 95 | |
Andreas Herrmann | 570c9e6 | 2009-02-25 11:28:58 +0100 | [diff] [blame^] | 96 | printk(KERN_INFO " %010llx - %010llx pattern %016llx\n", |
| 97 | (unsigned long long) t_start, |
| 98 | (unsigned long long) t_start + t_size, |
| 99 | (unsigned long long) cpu_to_be64(pattern)); |
| 100 | memtest(pattern, t_start, t_size); |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 101 | |
| 102 | t_start += t_size; |
| 103 | } |
| 104 | } |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 105 | } |