xen/pm_idle: Make pm_idle be default_idle under Xen.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / kernel / check.c
blob452932d3473077cabf505d00f96073319c93b983
1 #include <linux/module.h>
2 #include <linux/sched.h>
3 #include <linux/kthread.h>
4 #include <linux/workqueue.h>
5 #include <linux/memblock.h>
7 #include <asm/proto.h>
9 /*
10 * Some BIOSes seem to corrupt the low 64k of memory during events
11 * like suspend/resume and unplugging an HDMI cable. Reserve all
12 * remaining free memory in that area and fill it with a distinct
13 * pattern.
15 #define MAX_SCAN_AREAS 8
17 static int __read_mostly memory_corruption_check = -1;
19 static unsigned __read_mostly corruption_check_size = 64*1024;
20 static unsigned __read_mostly corruption_check_period = 60; /* seconds */
22 static struct scan_area {
23 u64 addr;
24 u64 size;
25 } scan_areas[MAX_SCAN_AREAS];
26 static int num_scan_areas;
28 static __init int set_corruption_check(char *arg)
30 char *end;
32 memory_corruption_check = simple_strtol(arg, &end, 10);
34 return (*end == 0) ? 0 : -EINVAL;
36 early_param("memory_corruption_check", set_corruption_check);
38 static __init int set_corruption_check_period(char *arg)
40 char *end;
42 corruption_check_period = simple_strtoul(arg, &end, 10);
44 return (*end == 0) ? 0 : -EINVAL;
46 early_param("memory_corruption_check_period", set_corruption_check_period);
48 static __init int set_corruption_check_size(char *arg)
50 char *end;
51 unsigned size;
53 size = memparse(arg, &end);
55 if (*end == '\0')
56 corruption_check_size = size;
58 return (size == corruption_check_size) ? 0 : -EINVAL;
60 early_param("memory_corruption_check_size", set_corruption_check_size);
63 void __init setup_bios_corruption_check(void)
65 u64 addr = PAGE_SIZE; /* assume first page is reserved anyway */
67 if (memory_corruption_check == -1) {
68 memory_corruption_check =
69 #ifdef CONFIG_X86_BOOTPARAM_MEMORY_CORRUPTION_CHECK
71 #else
73 #endif
77 if (corruption_check_size == 0)
78 memory_corruption_check = 0;
80 if (!memory_corruption_check)
81 return;
83 corruption_check_size = round_up(corruption_check_size, PAGE_SIZE);
85 while (addr < corruption_check_size && num_scan_areas < MAX_SCAN_AREAS) {
86 u64 size;
87 addr = memblock_x86_find_in_range_size(addr, &size, PAGE_SIZE);
89 if (addr == MEMBLOCK_ERROR)
90 break;
92 if (addr >= corruption_check_size)
93 break;
95 if ((addr + size) > corruption_check_size)
96 size = corruption_check_size - addr;
98 memblock_x86_reserve_range(addr, addr + size, "SCAN RAM");
99 scan_areas[num_scan_areas].addr = addr;
100 scan_areas[num_scan_areas].size = size;
101 num_scan_areas++;
103 /* Assume we've already mapped this early memory */
104 memset(__va(addr), 0, size);
106 addr += size;
109 if (num_scan_areas)
110 printk(KERN_INFO "Scanning %d areas for low memory corruption\n", num_scan_areas);
114 void check_for_bios_corruption(void)
116 int i;
117 int corruption = 0;
119 if (!memory_corruption_check)
120 return;
122 for (i = 0; i < num_scan_areas; i++) {
123 unsigned long *addr = __va(scan_areas[i].addr);
124 unsigned long size = scan_areas[i].size;
126 for (; size; addr++, size -= sizeof(unsigned long)) {
127 if (!*addr)
128 continue;
129 printk(KERN_ERR "Corrupted low memory at %p (%lx phys) = %08lx\n",
130 addr, __pa(addr), *addr);
131 corruption = 1;
132 *addr = 0;
136 WARN_ONCE(corruption, KERN_ERR "Memory corruption detected in low memory\n");
139 static void check_corruption(struct work_struct *dummy);
140 static DECLARE_DELAYED_WORK(bios_check_work, check_corruption);
142 static void check_corruption(struct work_struct *dummy)
144 check_for_bios_corruption();
145 schedule_delayed_work(&bios_check_work,
146 round_jiffies_relative(corruption_check_period*HZ));
149 static int start_periodic_check_for_corruption(void)
151 if (!num_scan_areas || !memory_corruption_check || corruption_check_period == 0)
152 return 0;
154 printk(KERN_INFO "Scanning for low memory corruption every %d seconds\n",
155 corruption_check_period);
157 /* First time we run the checks right away */
158 schedule_delayed_work(&bios_check_work, 0);
159 return 0;
162 module_init(start_periodic_check_for_corruption);