blob: dd3af6e7b39a078835abd589feeaeee0b6184907 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Dave Jonesf4432c52008-10-20 13:31:45 -04002 * Athlon specific Machine Check Exception Reporting
3 * (C) Copyright 2002 Dave Jones <davej@redhat.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5
6#include <linux/init.h>
7#include <linux/types.h>
8#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/interrupt.h>
10#include <linux/smp.h>
11
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020012#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/system.h>
14#include <asm/msr.h>
15
16#include "mce.h"
17
18/* Machine Check Handler For AMD Athlon/Duron */
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020019static void k7_machine_check(struct pt_regs *regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020021 int recover = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 u32 alow, ahigh, high, low;
23 u32 mcgstl, mcgsth;
24 int i;
25
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020026 rdmsr(MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 if (mcgstl & (1<<0)) /* Recoverable ? */
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020028 recover = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Andrew Mortonb912a1c2008-01-30 13:32:12 +010030 printk(KERN_EMERG "CPU %d: Machine Check Exception: %08x%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 smp_processor_id(), mcgsth, mcgstl);
32
Andrew Mortonb912a1c2008-01-30 13:32:12 +010033 for (i = 1; i < nr_mce_banks; i++) {
Andrew Morton72713392008-01-30 13:32:13 +010034 rdmsr(MSR_IA32_MC0_STATUS+i*4, low, high);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 if (high&(1<<31)) {
Min Zhang9e8b6d92008-01-30 13:32:11 +010036 char misc[20];
37 char addr[24];
38 misc[0] = addr[0] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 if (high & (1<<29))
40 recover |= 1;
41 if (high & (1<<25))
42 recover |= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 high &= ~(1<<31);
44 if (high & (1<<27)) {
Andrew Mortonb912a1c2008-01-30 13:32:12 +010045 rdmsr(MSR_IA32_MC0_MISC+i*4, alow, ahigh);
46 snprintf(misc, 20, "[%08x%08x]", ahigh, alow);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 }
48 if (high & (1<<26)) {
Andrew Mortonb912a1c2008-01-30 13:32:12 +010049 rdmsr(MSR_IA32_MC0_ADDR+i*4, alow, ahigh);
50 snprintf(addr, 24, " at %08x%08x", ahigh, alow);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 }
Andrew Mortonb912a1c2008-01-30 13:32:12 +010052 printk(KERN_EMERG "CPU %d: Bank %d: %08x%08x%s%s\n",
Min Zhang9e8b6d92008-01-30 13:32:11 +010053 smp_processor_id(), i, high, low, misc, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 /* Clear it */
Andrew Mortonb912a1c2008-01-30 13:32:12 +010055 wrmsr(MSR_IA32_MC0_STATUS+i*4, 0UL, 0UL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 /* Serialize */
57 wmb();
58 add_taint(TAINT_MACHINE_CHECK);
59 }
60 }
61
62 if (recover&2)
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020063 panic("CPU context corrupt");
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 if (recover&1)
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020065 panic("Unable to continue");
66 printk(KERN_EMERG "Attempting to continue.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 mcgstl &= ~(1<<2);
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020068 wrmsr(MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71
72/* AMD K7 machine check is Intel like */
Shaohua Li31ab2692005-11-07 00:58:42 -080073void amd_mcheck_init(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 u32 l, h;
76 int i;
77
Joachim Deguara2f3c30e2007-05-02 19:27:18 +020078 if (!cpu_has(c, X86_FEATURE_MCE))
79 return;
80
Andi Kleenc12ceb72007-05-21 14:31:47 +020081 machine_check_vector = k7_machine_check;
82 wmb();
83
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020084 printk(KERN_INFO "Intel machine check architecture supported.\n");
85 rdmsr(MSR_IA32_MCG_CAP, l, h);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 if (l & (1<<8)) /* Control register present ? */
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020087 wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 nr_mce_banks = l & 0xff;
89
90 /* Clear status for MC index 0 separately, we don't touch CTL,
Andi Kleende90c5c2007-05-02 19:27:12 +020091 * as some K7 Athlons cause spurious MCEs when its enabled. */
92 if (boot_cpu_data.x86 == 6) {
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020093 wrmsr(MSR_IA32_MC0_STATUS, 0x0, 0x0);
Andi Kleende90c5c2007-05-02 19:27:12 +020094 i = 1;
95 } else
96 i = 0;
Paolo Ciarrocchi51756762008-06-14 14:37:14 +020097 for (; i < nr_mce_banks; i++) {
98 wrmsr(MSR_IA32_MC0_CTL+4*i, 0xffffffff, 0xffffffff);
99 wrmsr(MSR_IA32_MC0_STATUS+4*i, 0x0, 0x0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
101
Paolo Ciarrocchi51756762008-06-14 14:37:14 +0200102 set_in_cr4(X86_CR4_MCE);
103 printk(KERN_INFO "Intel machine check reporting enabled on CPU#%d.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 smp_processor_id());
105}