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