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 | |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 19 | static void __init memtest(unsigned long start_phys, unsigned long size, |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame^] | 20 | u64 pattern) |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 21 | { |
| 22 | unsigned long i; |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame^] | 23 | u64 *start; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 24 | unsigned long start_bad; |
| 25 | unsigned long last_bad; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 26 | unsigned long start_phys_aligned; |
| 27 | unsigned long count; |
| 28 | unsigned long incr; |
| 29 | |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame^] | 30 | incr = sizeof(pattern); |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 31 | start_phys_aligned = ALIGN(start_phys, incr); |
| 32 | count = (size - (start_phys_aligned - start_phys))/incr; |
| 33 | start = __va(start_phys_aligned); |
| 34 | start_bad = 0; |
| 35 | last_bad = 0; |
| 36 | |
| 37 | for (i = 0; i < count; i++) |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame^] | 38 | start[i] = pattern; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 39 | for (i = 0; i < count; i++, start++, start_phys_aligned += incr) { |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame^] | 40 | if (*start != pattern) { |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 41 | if (start_phys_aligned == last_bad + incr) { |
| 42 | last_bad += incr; |
| 43 | } else { |
| 44 | if (start_bad) { |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame^] | 45 | printk(KERN_CONT "\n %016llx bad mem addr %010lx - %010lx reserved", |
| 46 | (unsigned long long) pattern, |
| 47 | start_bad, last_bad + incr); |
Daniele Calore | 2cb0ebe | 2008-10-13 10:34:12 +0200 | [diff] [blame] | 48 | reserve_early(start_bad, last_bad + incr, "BAD RAM"); |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 49 | } |
| 50 | start_bad = last_bad = start_phys_aligned; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | if (start_bad) { |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame^] | 55 | printk(KERN_CONT "\n %016llx bad mem addr %010lx - %010lx reserved", |
| 56 | (unsigned long long) pattern, start_bad, |
| 57 | last_bad + incr); |
Daniele Calore | 2cb0ebe | 2008-10-13 10:34:12 +0200 | [diff] [blame] | 58 | reserve_early(start_bad, last_bad + incr, "BAD RAM"); |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 59 | } |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /* default is disabled */ |
| 63 | static int memtest_pattern __initdata; |
| 64 | |
| 65 | static int __init parse_memtest(char *arg) |
| 66 | { |
| 67 | if (arg) |
| 68 | memtest_pattern = simple_strtoul(arg, NULL, 0); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | early_param("memtest", parse_memtest); |
| 73 | |
| 74 | void __init early_memtest(unsigned long start, unsigned long end) |
| 75 | { |
| 76 | u64 t_start, t_size; |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame^] | 77 | unsigned int i; |
| 78 | u64 pattern; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 79 | |
| 80 | if (!memtest_pattern) |
| 81 | return; |
| 82 | |
| 83 | printk(KERN_INFO "early_memtest: pattern num %d", memtest_pattern); |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame^] | 84 | for (i = 0; i < memtest_pattern; i++) { |
| 85 | unsigned int idx = i % ARRAY_SIZE(patterns); |
| 86 | pattern = patterns[idx]; |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 87 | t_start = start; |
| 88 | t_size = 0; |
| 89 | while (t_start < end) { |
| 90 | t_start = find_e820_area_size(t_start, &t_size, 1); |
| 91 | |
| 92 | /* done ? */ |
| 93 | if (t_start >= end) |
| 94 | break; |
| 95 | if (t_start + t_size > end) |
| 96 | t_size = end - t_start; |
| 97 | |
| 98 | printk(KERN_CONT "\n %010llx - %010llx pattern %d", |
Andreas Herrmann | 40823f7 | 2009-02-25 11:26:18 +0100 | [diff] [blame] | 99 | (unsigned long long)t_start, |
Andreas Herrmann | 6d74171 | 2009-02-25 11:27:27 +0100 | [diff] [blame^] | 100 | (unsigned long long)t_start + t_size, idx); |
Yinghai Lu | 1f06716 | 2008-07-15 00:02:28 -0700 | [diff] [blame] | 101 | |
| 102 | memtest(t_start, t_size, pattern); |
| 103 | |
| 104 | t_start += t_size; |
| 105 | } |
| 106 | } |
| 107 | printk(KERN_CONT "\n"); |
| 108 | } |