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 %016lx bad mem addr %010lx - %010lx reserved",
65 val, start_bad, last_bad + incr);
66 reserve_early(start_bad, last_bad + incr, "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 + incr, "BAD RAM");
79 /* default is disabled */
80 static int memtest_pattern __initdata;
82 static int __init parse_memtest(char *arg)
85 memtest_pattern = simple_strtoul(arg, NULL, 0);
89 early_param("memtest", parse_memtest);
91 void __init early_memtest(unsigned long start, unsigned long end)
99 printk(KERN_INFO "early_memtest: pattern num %d", memtest_pattern);
100 for (pattern = 0; pattern < memtest_pattern; pattern++) {
103 while (t_start < end) {
104 t_start = find_e820_area_size(t_start, &t_size, 1);
109 if (t_start + t_size > end)
110 t_size = end - t_start;
112 printk(KERN_CONT "\n %010llx - %010llx pattern %d",
113 (unsigned long long)t_start,
114 (unsigned long long)t_start + t_size, pattern);
116 memtest(t_start, t_size, pattern);
121 printk(KERN_CONT "\n");