blob: 563933e06a35fa48f6c828d3884f9b35886ab4eb [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_MCE_H
2#define _ASM_X86_MCE_H
Thomas Gleixnere2f43022007-10-17 18:04:40 +02003
4#ifdef __x86_64__
5
Jaswinder Singh Rajput999b6972009-01-30 22:47:27 +05306#include <linux/types.h>
Thomas Gleixnere2f43022007-10-17 18:04:40 +02007#include <asm/ioctls.h>
Thomas Gleixnere2f43022007-10-17 18:04:40 +02008
9/*
10 * Machine Check support for x86
11 */
12
13#define MCG_CTL_P (1UL<<8) /* MCG_CAP register available */
Andi Kleen03195c62009-02-12 13:49:35 +010014#define MCG_EXT_P (1ULL<<9) /* Extended registers available */
15#define MCG_CMCI_P (1ULL<<10) /* CMCI supported */
Thomas Gleixnere2f43022007-10-17 18:04:40 +020016
17#define MCG_STATUS_RIPV (1UL<<0) /* restart ip valid */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010018#define MCG_STATUS_EIPV (1UL<<1) /* ip points to correct instruction */
Thomas Gleixnere2f43022007-10-17 18:04:40 +020019#define MCG_STATUS_MCIP (1UL<<2) /* machine check in progress */
20
21#define MCI_STATUS_VAL (1UL<<63) /* valid error */
22#define MCI_STATUS_OVER (1UL<<62) /* previous errors lost */
23#define MCI_STATUS_UC (1UL<<61) /* uncorrected error */
24#define MCI_STATUS_EN (1UL<<60) /* error enabled */
25#define MCI_STATUS_MISCV (1UL<<59) /* misc error reg. valid */
26#define MCI_STATUS_ADDRV (1UL<<58) /* addr reg. valid */
27#define MCI_STATUS_PCC (1UL<<57) /* processor context corrupt */
28
29/* Fields are zero when not available */
30struct mce {
31 __u64 status;
32 __u64 misc;
33 __u64 addr;
34 __u64 mcgstatus;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010035 __u64 ip;
Thomas Gleixnere2f43022007-10-17 18:04:40 +020036 __u64 tsc; /* cpu time stamp counter */
37 __u64 res1; /* for future extension */
38 __u64 res2; /* dito. */
39 __u8 cs; /* code segment */
40 __u8 bank; /* machine check bank */
41 __u8 cpu; /* cpu that raised the error */
42 __u8 finished; /* entry is valid */
43 __u32 pad;
44};
45
46/*
47 * This structure contains all data related to the MCE log. Also
48 * carries a signature to make it easier to find from external
49 * debugging tools. Each entry is only valid when its finished flag
50 * is set.
51 */
52
53#define MCE_LOG_LEN 32
54
55struct mce_log {
56 char signature[12]; /* "MACHINECHECK" */
57 unsigned len; /* = MCE_LOG_LEN */
58 unsigned next;
59 unsigned flags;
60 unsigned pad0;
61 struct mce entry[MCE_LOG_LEN];
62};
63
64#define MCE_OVERFLOW 0 /* bit 0 in flags means overflow */
65
66#define MCE_LOG_SIGNATURE "MACHINECHECK"
67
68#define MCE_GET_RECORD_LEN _IOR('M', 1, int)
69#define MCE_GET_LOG_LEN _IOR('M', 2, int)
70#define MCE_GETCLEAR_FLAGS _IOR('M', 3, int)
71
72/* Software defined banks */
73#define MCE_EXTENDED_BANK 128
74#define MCE_THERMAL_BANK MCE_EXTENDED_BANK + 0
75
76#define K8_MCE_THRESHOLD_BASE (MCE_EXTENDED_BANK + 1) /* MCE_AMD */
77#define K8_MCE_THRESHOLD_BANK_0 (MCE_THRESHOLD_BASE + 0 * 9)
78#define K8_MCE_THRESHOLD_BANK_1 (MCE_THRESHOLD_BASE + 1 * 9)
79#define K8_MCE_THRESHOLD_BANK_2 (MCE_THRESHOLD_BASE + 2 * 9)
80#define K8_MCE_THRESHOLD_BANK_3 (MCE_THRESHOLD_BASE + 3 * 9)
81#define K8_MCE_THRESHOLD_BANK_4 (MCE_THRESHOLD_BASE + 4 * 9)
82#define K8_MCE_THRESHOLD_BANK_5 (MCE_THRESHOLD_BASE + 5 * 9)
83#define K8_MCE_THRESHOLD_DRAM_ECC (MCE_THRESHOLD_BANK_4 + 0)
84
85#endif /* __x86_64__ */
86
87#ifdef __KERNEL__
88
Thomas Gleixner96a388d2007-10-11 11:20:03 +020089#ifdef CONFIG_X86_32
Thomas Gleixnere2f43022007-10-17 18:04:40 +020090extern int mce_disabled;
Thomas Gleixnere2f43022007-10-17 18:04:40 +020091#else /* CONFIG_X86_32 */
92
93#include <asm/atomic.h>
94
Andi Kleenb5f2fa42009-02-12 13:43:22 +010095void mce_setup(struct mce *m);
Thomas Gleixnere2f43022007-10-17 18:04:40 +020096void mce_log(struct mce *m);
97DECLARE_PER_CPU(struct sys_device, device_mce);
Rafael J. Wysocki87357282008-08-22 22:23:09 +020098extern void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu);
Thomas Gleixnere2f43022007-10-17 18:04:40 +020099
Andi Kleen41fdff32009-02-12 13:49:30 +0100100/*
101 * To support more than 128 would need to escape the predefined
102 * Linux defined extended banks first.
103 */
104#define MAX_NR_BANKS (MCE_EXTENDED_BANK - 1)
105
Thomas Gleixnere2f43022007-10-17 18:04:40 +0200106#ifdef CONFIG_X86_MCE_INTEL
107void mce_intel_feature_init(struct cpuinfo_x86 *c);
Andi Kleen88ccbed2009-02-12 13:49:36 +0100108void cmci_clear(void);
109void cmci_reenable(void);
110void cmci_rediscover(int dying);
111void cmci_recheck(void);
Thomas Gleixnere2f43022007-10-17 18:04:40 +0200112#else
113static inline void mce_intel_feature_init(struct cpuinfo_x86 *c) { }
Andi Kleen88ccbed2009-02-12 13:49:36 +0100114static inline void cmci_clear(void) {}
115static inline void cmci_reenable(void) {}
116static inline void cmci_rediscover(int dying) {}
117static inline void cmci_recheck(void) {}
Thomas Gleixnere2f43022007-10-17 18:04:40 +0200118#endif
119
120#ifdef CONFIG_X86_MCE_AMD
121void mce_amd_feature_init(struct cpuinfo_x86 *c);
122#else
123static inline void mce_amd_feature_init(struct cpuinfo_x86 *c) { }
124#endif
125
Andi Kleen88ccbed2009-02-12 13:49:36 +0100126extern int mce_available(struct cpuinfo_x86 *c);
127
Andi Kleenb5f2fa42009-02-12 13:43:22 +0100128void mce_log_therm_throt_event(__u64 status);
Thomas Gleixnere2f43022007-10-17 18:04:40 +0200129
130extern atomic_t mce_entry;
131
132extern void do_machine_check(struct pt_regs *, long);
Andi Kleenb79109c2009-02-12 13:43:23 +0100133
Andi Kleenee031c32009-02-12 13:49:34 +0100134typedef DECLARE_BITMAP(mce_banks_t, MAX_NR_BANKS);
135DECLARE_PER_CPU(mce_banks_t, mce_poll_banks);
136
Andi Kleenb79109c2009-02-12 13:43:23 +0100137enum mcp_flags {
138 MCP_TIMESTAMP = (1 << 0), /* log time stamp */
139 MCP_UC = (1 << 1), /* log uncorrected errors */
140};
Andi Kleenee031c32009-02-12 13:49:34 +0100141extern void machine_check_poll(enum mcp_flags flags, mce_banks_t *b);
Andi Kleenb79109c2009-02-12 13:43:23 +0100142
Thomas Gleixnere2f43022007-10-17 18:04:40 +0200143extern int mce_notify_user(void);
144
145#endif /* !CONFIG_X86_32 */
146
Thomas Gleixneraf7a78e2008-01-30 13:30:17 +0100147#ifdef CONFIG_X86_MCE
148extern void mcheck_init(struct cpuinfo_x86 *c);
149#else
150#define mcheck_init(c) do { } while (0)
151#endif
Thomas Gleixnere2f43022007-10-17 18:04:40 +0200152
Andi Kleenb2762682009-02-12 13:49:31 +0100153extern void (*mce_threshold_vector)(void);
154
Thomas Gleixnere2f43022007-10-17 18:04:40 +0200155#endif /* __KERNEL__ */
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700156#endif /* _ASM_X86_MCE_H */