blob: 827f94044cfc30ac7faf78e56b8077fbcfe7cf92 [file] [log] [blame]
Yinghai Lu1f067162008-07-15 00:02:28 -07001#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 Herrmann6d741712009-02-25 11:27:27 +010012static u64 patterns[] __initdata = {
13 0,
14 0xffffffffffffffffULL,
15 0x5555555555555555ULL,
16 0xaaaaaaaaaaaaaaaaULL,
17};
Andreas Herrmann40823f72009-02-25 11:26:18 +010018
Yinghai Lu1f067162008-07-15 00:02:28 -070019static void __init memtest(unsigned long start_phys, unsigned long size,
Andreas Herrmann6d741712009-02-25 11:27:27 +010020 u64 pattern)
Yinghai Lu1f067162008-07-15 00:02:28 -070021{
22 unsigned long i;
Andreas Herrmann6d741712009-02-25 11:27:27 +010023 u64 *start;
Yinghai Lu1f067162008-07-15 00:02:28 -070024 unsigned long start_bad;
25 unsigned long last_bad;
Yinghai Lu1f067162008-07-15 00:02:28 -070026 unsigned long start_phys_aligned;
27 unsigned long count;
28 unsigned long incr;
29
Andreas Herrmann6d741712009-02-25 11:27:27 +010030 incr = sizeof(pattern);
Yinghai Lu1f067162008-07-15 00:02:28 -070031 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 Herrmann6d741712009-02-25 11:27:27 +010038 start[i] = pattern;
Yinghai Lu1f067162008-07-15 00:02:28 -070039 for (i = 0; i < count; i++, start++, start_phys_aligned += incr) {
Andreas Herrmann6d741712009-02-25 11:27:27 +010040 if (*start != pattern) {
Yinghai Lu1f067162008-07-15 00:02:28 -070041 if (start_phys_aligned == last_bad + incr) {
42 last_bad += incr;
43 } else {
44 if (start_bad) {
Andreas Herrmann6d741712009-02-25 11:27:27 +010045 printk(KERN_CONT "\n %016llx bad mem addr %010lx - %010lx reserved",
46 (unsigned long long) pattern,
47 start_bad, last_bad + incr);
Daniele Calore2cb0ebe2008-10-13 10:34:12 +020048 reserve_early(start_bad, last_bad + incr, "BAD RAM");
Yinghai Lu1f067162008-07-15 00:02:28 -070049 }
50 start_bad = last_bad = start_phys_aligned;
51 }
52 }
53 }
54 if (start_bad) {
Andreas Herrmann6d741712009-02-25 11:27:27 +010055 printk(KERN_CONT "\n %016llx bad mem addr %010lx - %010lx reserved",
56 (unsigned long long) pattern, start_bad,
57 last_bad + incr);
Daniele Calore2cb0ebe2008-10-13 10:34:12 +020058 reserve_early(start_bad, last_bad + incr, "BAD RAM");
Yinghai Lu1f067162008-07-15 00:02:28 -070059 }
Yinghai Lu1f067162008-07-15 00:02:28 -070060}
61
62/* default is disabled */
63static int memtest_pattern __initdata;
64
65static int __init parse_memtest(char *arg)
66{
67 if (arg)
68 memtest_pattern = simple_strtoul(arg, NULL, 0);
69 return 0;
70}
71
72early_param("memtest", parse_memtest);
73
74void __init early_memtest(unsigned long start, unsigned long end)
75{
76 u64 t_start, t_size;
Andreas Herrmann6d741712009-02-25 11:27:27 +010077 unsigned int i;
78 u64 pattern;
Yinghai Lu1f067162008-07-15 00:02:28 -070079
80 if (!memtest_pattern)
81 return;
82
83 printk(KERN_INFO "early_memtest: pattern num %d", memtest_pattern);
Andreas Herrmann6d741712009-02-25 11:27:27 +010084 for (i = 0; i < memtest_pattern; i++) {
85 unsigned int idx = i % ARRAY_SIZE(patterns);
86 pattern = patterns[idx];
Yinghai Lu1f067162008-07-15 00:02:28 -070087 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 Herrmann40823f72009-02-25 11:26:18 +010099 (unsigned long long)t_start,
Andreas Herrmann6d741712009-02-25 11:27:27 +0100100 (unsigned long long)t_start + t_size, idx);
Yinghai Lu1f067162008-07-15 00:02:28 -0700101
102 memtest(t_start, t_size, pattern);
103
104 t_start += t_size;
105 }
106 }
107 printk(KERN_CONT "\n");
108}