]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/x86/mm/memtest.c
x86, UV: Fix macros for multiple coherency domains
[mirror_ubuntu-bionic-kernel.git] / arch / x86 / mm / memtest.c
CommitLineData
1f067167
YL
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
6d74171b
AH
12static u64 patterns[] __initdata = {
13 0,
14 0xffffffffffffffffULL,
15 0x5555555555555555ULL,
16 0xaaaaaaaaaaaaaaaaULL,
63823126
AH
17 0x1111111111111111ULL,
18 0x2222222222222222ULL,
19 0x4444444444444444ULL,
20 0x8888888888888888ULL,
21 0x3333333333333333ULL,
22 0x6666666666666666ULL,
23 0x9999999999999999ULL,
24 0xccccccccccccccccULL,
25 0x7777777777777777ULL,
26 0xbbbbbbbbbbbbbbbbULL,
27 0xddddddddddddddddULL,
28 0xeeeeeeeeeeeeeeeeULL,
29 0x7a6c7258554e494cULL, /* yeah ;-) */
6d74171b 30};
40823f73 31
570c9e69 32static void __init reserve_bad_mem(u64 pattern, u64 start_bad, u64 end_bad)
7dad169e 33{
570c9e69
AH
34 printk(KERN_INFO " %016llx bad mem addr %010llx - %010llx reserved\n",
35 (unsigned long long) pattern,
36 (unsigned long long) start_bad,
37 (unsigned long long) end_bad);
7dad169e
AH
38 reserve_early(start_bad, end_bad, "BAD RAM");
39}
40
570c9e69 41static void __init memtest(u64 pattern, u64 start_phys, u64 size)
1f067167 42{
570c9e69 43 u64 i, count;
6d74171b 44 u64 *start;
570c9e69
AH
45 u64 start_bad, last_bad;
46 u64 start_phys_aligned;
47 size_t incr;
1f067167 48
6d74171b 49 incr = sizeof(pattern);
1f067167
YL
50 start_phys_aligned = ALIGN(start_phys, incr);
51 count = (size - (start_phys_aligned - start_phys))/incr;
52 start = __va(start_phys_aligned);
53 start_bad = 0;
54 last_bad = 0;
55
56 for (i = 0; i < count; i++)
6d74171b 57 start[i] = pattern;
1f067167 58 for (i = 0; i < count; i++, start++, start_phys_aligned += incr) {
7dad169e
AH
59 if (*start == pattern)
60 continue;
61 if (start_phys_aligned == last_bad + incr) {
62 last_bad += incr;
63 continue;
1f067167 64 }
7dad169e
AH
65 if (start_bad)
66 reserve_bad_mem(pattern, start_bad, last_bad + incr);
67 start_bad = last_bad = start_phys_aligned;
1f067167 68 }
7dad169e
AH
69 if (start_bad)
70 reserve_bad_mem(pattern, start_bad, last_bad + incr);
1f067167
YL
71}
72
bfb4dc0d
AH
73static void __init do_one_pass(u64 pattern, u64 start, u64 end)
74{
75 u64 size = 0;
76
77 while (start < end) {
78 start = find_e820_area_size(start, &size, 1);
79
80 /* done ? */
81 if (start >= end)
82 break;
83 if (start + size > end)
84 size = end - start;
85
86 printk(KERN_INFO " %010llx - %010llx pattern %016llx\n",
87 (unsigned long long) start,
88 (unsigned long long) start + size,
89 (unsigned long long) cpu_to_be64(pattern));
90 memtest(pattern, start, size);
91
92 start += size;
93 }
94}
95
1f067167
YL
96/* default is disabled */
97static int memtest_pattern __initdata;
98
99static int __init parse_memtest(char *arg)
100{
101 if (arg)
102 memtest_pattern = simple_strtoul(arg, NULL, 0);
d1a8e779
YL
103 else
104 memtest_pattern = ARRAY_SIZE(patterns);
105
1f067167
YL
106 return 0;
107}
108
109early_param("memtest", parse_memtest);
110
111void __init early_memtest(unsigned long start, unsigned long end)
112{
6d74171b 113 unsigned int i;
bfb4dc0d 114 unsigned int idx = 0;
1f067167
YL
115
116 if (!memtest_pattern)
117 return;
118
570c9e69 119 printk(KERN_INFO "early_memtest: # of tests: %d\n", memtest_pattern);
6d74171b 120 for (i = 0; i < memtest_pattern; i++) {
bfb4dc0d
AH
121 idx = i % ARRAY_SIZE(patterns);
122 do_one_pass(patterns[idx], start, end);
123 }
124
125 if (idx > 0) {
126 printk(KERN_INFO "early_memtest: wipe out "
127 "test pattern from memory\n");
128 /* additional test with pattern 0 will do this */
129 do_one_pass(0, start, end);
1f067167 130 }
1f067167 131}