ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.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/irq.h>
16 #include <linux/workqueue.h>
17 #include <linux/interrupt.h>
18 #include <linux/smp.h>
19 #include <linux/module.h>
20
21 #include <asm/processor.h> 
22 #include <asm/system.h>
23 #include <asm/msr.h>
24
25 #include "mce.h"
26
27 static int firstbank;
28
29 #define MCE_RATE        15*HZ   /* timer rate is 15s */
30
31 static void mce_checkregs (void *info)
32 {
33         u32 low, high;
34         int i;
35
36         for (i=firstbank; i<nr_mce_banks; i++) {
37                 rdmsr (MSR_IA32_MC0_STATUS+i*4, low, high);
38
39                 if (high & (1<<31)) {
40                         printk(KERN_INFO "MCE: The hardware reports a non "
41                                 "fatal, correctable incident occurred on "
42                                 "CPU %d.\n",
43                                 smp_processor_id());
44                         printk (KERN_INFO "Bank %d: %08x%08x\n", i, high, low);
45
46                         /* Scrub the error so we don't pick it up in MCE_RATE seconds time. */
47                         wrmsr (MSR_IA32_MC0_STATUS+i*4, 0UL, 0UL);
48
49                         /* Serialize */
50                         wmb();
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");