1 #include <linux/kernel.h>
2 #include <linux/errno.h>
3 #include <linux/string.h>
4 #include <linux/types.h>
7 #include <linux/init.h>
12 static void __init memtest(unsigned long start_phys, unsigned long size,
17 unsigned long start_bad;
18 unsigned long last_bad;
20 unsigned long start_phys_aligned;
33 val = 0x5555555555555555UL;
40 val = 0xaaaaaaaaaaaaaaaaUL;
49 incr = sizeof(unsigned long);
50 start_phys_aligned = ALIGN(start_phys, incr);
51 count = (size - (start_phys_aligned - start_phys))/incr;
52 start = __va(start_phys_aligned);
56 for (i = 0; i < count; i++)
58 for (i = 0; i < count; i++, start++, start_phys_aligned += incr) {
60 if (start_phys_aligned == last_bad + incr) {
64 printk(KERN_CONT "\n %010lx bad mem addr %010lx - %010lx reserved",
65 val, start_bad, last_bad + incr);
66 reserve_early(start_bad, last_bad - start_bad, "BAD RAM");
68 start_bad = last_bad = start_phys_aligned;
73 printk(KERN_CONT "\n %016lx bad mem addr %010lx - %010lx reserved",
74 val, start_bad, last_bad + incr);
75 reserve_early(start_bad, last_bad - start_bad, "BAD RAM");
80 /* default is disabled */
81 static int memtest_pattern __initdata;
83 static int __init parse_memtest(char *arg)
86 memtest_pattern = simple_strtoul(arg, NULL, 0);
90 early_param("memtest", parse_memtest);
92 void __init early_memtest(unsigned long start, unsigned long end)
100 printk(KERN_INFO "early_memtest: pattern num %d", memtest_pattern);
101 for (pattern = 0; pattern < memtest_pattern; pattern++) {
104 while (t_start < end) {
105 t_start = find_e820_area_size(t_start, &t_size, 1);
110 if (t_start + t_size > end)
111 t_size = end - t_start;
113 printk(KERN_CONT "\n %010llx - %010llx pattern %d",
114 (unsigned long long)t_start,
115 (unsigned long long)t_start + t_size, pattern);
117 memtest(t_start, t_size, pattern);
122 printk(KERN_CONT "\n");