diff options
author | Yinghai Lu <yhlu.kernel@gmail.com> | 2008-07-15 03:02:28 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-07-18 08:10:27 -0400 |
commit | 1f067167a83d1c7f80437fd1d32b55508aaca009 (patch) | |
tree | 6739a35c8c8c9e1a91a7c4fa79219278ac2316f8 /arch/x86/mm | |
parent | 5b664cb235e97afbf34db9c4d77f08ebd725335e (diff) |
x86: seperate memtest from init_64.c
it's separate functionality that deserves its own file.
This also prepares 32-bit memtest support.
Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/mm')
-rw-r--r-- | arch/x86/mm/Makefile | 1 | ||||
-rw-r--r-- | arch/x86/mm/init_64.c | 112 | ||||
-rw-r--r-- | arch/x86/mm/memtest.c | 123 |
3 files changed, 124 insertions, 112 deletions
diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index 9873716e9f76..1fbb844c3d7a 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile | |||
@@ -21,3 +21,4 @@ obj-$(CONFIG_K8_NUMA) += k8topology_64.o | |||
21 | endif | 21 | endif |
22 | obj-$(CONFIG_ACPI_NUMA) += srat_$(BITS).o | 22 | obj-$(CONFIG_ACPI_NUMA) += srat_$(BITS).o |
23 | 23 | ||
24 | obj-$(CONFIG_MEMTEST) += memtest.o | ||
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 306049edd553..ec37121f6709 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c | |||
@@ -517,118 +517,6 @@ static void __init init_gbpages(void) | |||
517 | direct_gbpages = 0; | 517 | direct_gbpages = 0; |
518 | } | 518 | } |
519 | 519 | ||
520 | #ifdef CONFIG_MEMTEST | ||
521 | |||
522 | static void __init memtest(unsigned long start_phys, unsigned long size, | ||
523 | unsigned pattern) | ||
524 | { | ||
525 | unsigned long i; | ||
526 | unsigned long *start; | ||
527 | unsigned long start_bad; | ||
528 | unsigned long last_bad; | ||
529 | unsigned long val; | ||
530 | unsigned long start_phys_aligned; | ||
531 | unsigned long count; | ||
532 | unsigned long incr; | ||
533 | |||
534 | switch (pattern) { | ||
535 | case 0: | ||
536 | val = 0UL; | ||
537 | break; | ||
538 | case 1: | ||
539 | val = -1UL; | ||
540 | break; | ||
541 | case 2: | ||
542 | val = 0x5555555555555555UL; | ||
543 | break; | ||
544 | case 3: | ||
545 | val = 0xaaaaaaaaaaaaaaaaUL; | ||
546 | break; | ||
547 | default: | ||
548 | return; | ||
549 | } | ||
550 | |||
551 | incr = sizeof(unsigned long); | ||
552 | start_phys_aligned = ALIGN(start_phys, incr); | ||
553 | count = (size - (start_phys_aligned - start_phys))/incr; | ||
554 | start = __va(start_phys_aligned); | ||
555 | start_bad = 0; | ||
556 | last_bad = 0; | ||
557 | |||
558 | for (i = 0; i < count; i++) | ||
559 | start[i] = val; | ||
560 | for (i = 0; i < count; i++, start++, start_phys_aligned += incr) { | ||
561 | if (*start != val) { | ||
562 | if (start_phys_aligned == last_bad + incr) { | ||
563 | last_bad += incr; | ||
564 | } else { | ||
565 | if (start_bad) { | ||
566 | printk(KERN_CONT "\n %016lx bad mem addr %016lx - %016lx reserved", | ||
567 | val, start_bad, last_bad + incr); | ||
568 | reserve_early(start_bad, last_bad - start_bad, "BAD RAM"); | ||
569 | } | ||
570 | start_bad = last_bad = start_phys_aligned; | ||
571 | } | ||
572 | } | ||
573 | } | ||
574 | if (start_bad) { | ||
575 | printk(KERN_CONT "\n %016lx bad mem addr %016lx - %016lx reserved", | ||
576 | val, start_bad, last_bad + incr); | ||
577 | reserve_early(start_bad, last_bad - start_bad, "BAD RAM"); | ||
578 | } | ||
579 | |||
580 | } | ||
581 | |||
582 | /* default is disabled */ | ||
583 | static int memtest_pattern __initdata; | ||
584 | |||
585 | static int __init parse_memtest(char *arg) | ||
586 | { | ||
587 | if (arg) | ||
588 | memtest_pattern = simple_strtoul(arg, NULL, 0); | ||
589 | return 0; | ||
590 | } | ||
591 | |||
592 | early_param("memtest", parse_memtest); | ||
593 | |||
594 | static void __init early_memtest(unsigned long start, unsigned long end) | ||
595 | { | ||
596 | u64 t_start, t_size; | ||
597 | unsigned pattern; | ||
598 | |||
599 | if (!memtest_pattern) | ||
600 | return; | ||
601 | |||
602 | printk(KERN_INFO "early_memtest: pattern num %d", memtest_pattern); | ||
603 | for (pattern = 0; pattern < memtest_pattern; pattern++) { | ||
604 | t_start = start; | ||
605 | t_size = 0; | ||
606 | while (t_start < end) { | ||
607 | t_start = find_e820_area_size(t_start, &t_size, 1); | ||
608 | |||
609 | /* done ? */ | ||
610 | if (t_start >= end) | ||
611 | break; | ||
612 | if (t_start + t_size > end) | ||
613 | t_size = end - t_start; | ||
614 | |||
615 | printk(KERN_CONT "\n %016llx - %016llx pattern %d", | ||
616 | (unsigned long long)t_start, | ||
617 | (unsigned long long)t_start + t_size, pattern); | ||
618 | |||
619 | memtest(t_start, t_size, pattern); | ||
620 | |||
621 | t_start += t_size; | ||
622 | } | ||
623 | } | ||
624 | printk(KERN_CONT "\n"); | ||
625 | } | ||
626 | #else | ||
627 | static void __init early_memtest(unsigned long start, unsigned long end) | ||
628 | { | ||
629 | } | ||
630 | #endif | ||
631 | |||
632 | static unsigned long __init kernel_physical_mapping_init(unsigned long start, | 520 | static unsigned long __init kernel_physical_mapping_init(unsigned long start, |
633 | unsigned long end, | 521 | unsigned long end, |
634 | unsigned long page_size_mask) | 522 | unsigned long page_size_mask) |
diff --git a/arch/x86/mm/memtest.c b/arch/x86/mm/memtest.c new file mode 100644 index 000000000000..672e17f8262a --- /dev/null +++ b/arch/x86/mm/memtest.c | |||
@@ -0,0 +1,123 @@ | |||
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 | |||
12 | static void __init memtest(unsigned long start_phys, unsigned long size, | ||
13 | unsigned pattern) | ||
14 | { | ||
15 | unsigned long i; | ||
16 | unsigned long *start; | ||
17 | unsigned long start_bad; | ||
18 | unsigned long last_bad; | ||
19 | unsigned long val; | ||
20 | unsigned long start_phys_aligned; | ||
21 | unsigned long count; | ||
22 | unsigned long incr; | ||
23 | |||
24 | switch (pattern) { | ||
25 | case 0: | ||
26 | val = 0UL; | ||
27 | break; | ||
28 | case 1: | ||
29 | val = -1UL; | ||
30 | break; | ||
31 | case 2: | ||
32 | #ifdef CONFIG_X86_64 | ||
33 | val = 0x5555555555555555UL; | ||
34 | #else | ||
35 | val = 0x55555555UL; | ||
36 | #endif | ||
37 | break; | ||
38 | case 3: | ||
39 | #ifdef CONFIG_X86_64 | ||
40 | val = 0xaaaaaaaaaaaaaaaaUL; | ||
41 | #else | ||
42 | val = 0xaaaaaaaaUL; | ||
43 | #endif | ||
44 | break; | ||
45 | default: | ||
46 | return; | ||
47 | } | ||
48 | |||
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); | ||
53 | start_bad = 0; | ||
54 | last_bad = 0; | ||
55 | |||
56 | for (i = 0; i < count; i++) | ||
57 | start[i] = val; | ||
58 | for (i = 0; i < count; i++, start++, start_phys_aligned += incr) { | ||
59 | if (*start != val) { | ||
60 | if (start_phys_aligned == last_bad + incr) { | ||
61 | last_bad += incr; | ||
62 | } else { | ||
63 | if (start_bad) { | ||
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"); | ||
67 | } | ||
68 | start_bad = last_bad = start_phys_aligned; | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | if (start_bad) { | ||
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"); | ||
76 | } | ||
77 | |||
78 | } | ||
79 | |||
80 | /* default is disabled */ | ||
81 | static int memtest_pattern __initdata; | ||
82 | |||
83 | static int __init parse_memtest(char *arg) | ||
84 | { | ||
85 | if (arg) | ||
86 | memtest_pattern = simple_strtoul(arg, NULL, 0); | ||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | early_param("memtest", parse_memtest); | ||
91 | |||
92 | void __init early_memtest(unsigned long start, unsigned long end) | ||
93 | { | ||
94 | u64 t_start, t_size; | ||
95 | unsigned pattern; | ||
96 | |||
97 | if (!memtest_pattern) | ||
98 | return; | ||
99 | |||
100 | printk(KERN_INFO "early_memtest: pattern num %d", memtest_pattern); | ||
101 | for (pattern = 0; pattern < memtest_pattern; pattern++) { | ||
102 | t_start = start; | ||
103 | t_size = 0; | ||
104 | while (t_start < end) { | ||
105 | t_start = find_e820_area_size(t_start, &t_size, 1); | ||
106 | |||
107 | /* done ? */ | ||
108 | if (t_start >= end) | ||
109 | break; | ||
110 | if (t_start + t_size > end) | ||
111 | t_size = end - t_start; | ||
112 | |||
113 | printk(KERN_CONT "\n %010llx - %010llx pattern %d", | ||
114 | (unsigned long long)t_start, | ||
115 | (unsigned long long)t_start + t_size, pattern); | ||
116 | |||
117 | memtest(t_start, t_size, pattern); | ||
118 | |||
119 | t_start += t_size; | ||
120 | } | ||
121 | } | ||
122 | printk(KERN_CONT "\n"); | ||
123 | } | ||