Merge HEAD from ../scsi-misc-2.6-old
[pandora-kernel.git] / arch / i386 / kernel / cpu / mcheck / non-fatal.c
1 /*
2  * Non Fatal Machine Check Exception Reporting
3  *
4  * (C) Copyright 2002 Dave Jones. <davej@codemonkey.org.uk>
5  *
6  * This file contains routines to check for non-fatal MCEs every 15s
7  *
8  */
9
10 #include <linux/init.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/jiffies.h>
14 #include <linux/config.h>
15 #include <linux/workqueue.h>
16 #include <linux/interrupt.h>
17 #include <linux/smp.h>
18 #include <linux/module.h>
19
20 #include <asm/processor.h> 
21 #include <asm/system.h>
22 #include <asm/msr.h>
23
24 #include "mce.h"
25
26 static int firstbank;
27
28 #define MCE_RATE        15*HZ   /* timer rate is 15s */
29
30 static void mce_checkregs (void *info)
31 {
32         u32 low, high;
33         int i;
34
35         for (i=firstbank; i<nr_mce_banks; i++) {
36                 rdmsr (MSR_IA32_MC0_STATUS+i*4, low, high);
37
38                 if (high & (1<<31)) {
39                         printk(KERN_INFO "MCE: The hardware reports a non "
40                                 "fatal, correctable incident occurred on "
41                                 "CPU %d.\n",
42                                 smp_processor_id());
43                         printk (KERN_INFO "Bank %d: %08x%08x\n", i, high, low);
44
45                         /* Scrub the error so we don't pick it up in MCE_RATE seconds time. */
46                         wrmsr (MSR_IA32_MC0_STATUS+i*4, 0UL, 0UL);
47
48                         /* Serialize */
49                         wmb();
50                         add_taint(TAINT_MACHINE_CHECK);
51                 }
52         }
53 }
54
55 static void mce_work_fn(void *data);
56 static DECLARE_WORK(mce_work, mce_work_fn, NULL);
57
58 static void mce_work_fn(void *data)
59
60         on_each_cpu(mce_checkregs, NULL, 1, 1);
61         schedule_delayed_work(&mce_work, MCE_RATE);
62
63
64 static int __init init_nonfatal_mce_checker(void)
65 {
66         struct cpuinfo_x86 *c = &boot_cpu_data;
67
68         /* Check for MCE support */
69         if (!cpu_has(c, X86_FEATURE_MCE))
70                 return -ENODEV;
71
72         /* Check for PPro style MCA */
73         if (!cpu_has(c, X86_FEATURE_MCA))
74                 return -ENODEV;
75
76         /* Some Athlons misbehave when we frob bank 0 */
77         if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
78                 boot_cpu_data.x86 == 6)
79                         firstbank = 1;
80         else
81                         firstbank = 0;
82
83         /*
84          * Check for non-fatal errors every MCE_RATE s
85          */
86         schedule_delayed_work(&mce_work, MCE_RATE);
87         printk(KERN_INFO "Machine check exception polling timer started.\n");
88         return 0;
89 }
90 module_init(init_nonfatal_mce_checker);
91
92 MODULE_LICENSE("GPL");