Linux 4.16-rc2
[linux-block.git] / arch / x86 / kernel / cpu / mcheck / mce-internal.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
262e6811
BP
2#ifndef __X86_MCE_INTERNAL_H__
3#define __X86_MCE_INTERNAL_H__
4
8a25a2fd 5#include <linux/device.h>
817f32d0
AK
6#include <asm/mce.h>
7
8enum severity_level {
9 MCE_NO_SEVERITY,
e3480271
CY
10 MCE_DEFERRED_SEVERITY,
11 MCE_UCNA_SEVERITY = MCE_DEFERRED_SEVERITY,
ed7290d0 12 MCE_KEEP_SEVERITY,
817f32d0 13 MCE_SOME_SEVERITY,
ed7290d0 14 MCE_AO_SEVERITY,
817f32d0 15 MCE_UC_SEVERITY,
ed7290d0 16 MCE_AR_SEVERITY,
817f32d0
AK
17 MCE_PANIC_SEVERITY,
18};
19
0dc9c639 20extern struct blocking_notifier_head x86_mce_decoder_chain;
648ed940 21
cebe1820 22#define ATTR_LEN 16
3f2f0680 23#define INITIAL_CHECK_INTERVAL 5 * 60 /* 5 minutes */
cebe1820
AK
24
25/* One object for each MCE bank, shared by all CPUs */
26struct mce_bank {
27 u64 ctl; /* subevents to enable */
28 unsigned char init; /* initialise bank? */
8a25a2fd 29 struct device_attribute attr; /* device attribute */
cebe1820
AK
30 char attrname[ATTR_LEN]; /* attribute name */
31};
32
648ed940
CG
33struct mce_evt_llist {
34 struct llist_node llnode;
35 struct mce mce;
36};
37
cff4c039 38void mce_gen_pool_process(struct work_struct *__unused);
648ed940
CG
39bool mce_gen_pool_empty(void);
40int mce_gen_pool_add(struct mce *mce);
41int mce_gen_pool_init(void);
5541c93c 42struct llist_node *mce_gen_pool_prepare_records(void);
648ed940 43
43eaa2a1 44extern int (*mce_severity)(struct mce *a, int tolerant, char **msg, bool is_excp);
5be9ed25 45struct dentry *mce_get_debugfs_dir(void);
ed7290d0 46
cebe1820 47extern struct mce_bank *mce_banks;
c3d1fb56 48extern mce_banks_t mce_banks_ce_disabled;
cebe1820 49
55babd8f 50#ifdef CONFIG_X86_MCE_INTEL
3f2f0680
BP
51unsigned long cmci_intel_adjust_timer(unsigned long interval);
52bool mce_intel_cmci_poll(void);
55babd8f 53void mce_intel_hcpu_update(unsigned long cpu);
c3d1fb56 54void cmci_disable_bank(int bank);
55babd8f 55#else
3f2f0680
BP
56# define cmci_intel_adjust_timer mce_adjust_timer_default
57static inline bool mce_intel_cmci_poll(void) { return false; }
55babd8f 58static inline void mce_intel_hcpu_update(unsigned long cpu) { }
c3d1fb56 59static inline void cmci_disable_bank(int bank) { }
55babd8f
CG
60#endif
61
62void mce_timer_kick(unsigned long interval);
63
482908b4
HY
64#ifdef CONFIG_ACPI_APEI
65int apei_write_mce(struct mce *m);
66ssize_t apei_read_mce(struct mce *m, u64 *record_id);
67int apei_check_mce(void);
68int apei_clear_mce(u64 record_id);
69#else
70static inline int apei_write_mce(struct mce *m)
71{
72 return -EINVAL;
73}
74static inline ssize_t apei_read_mce(struct mce *m, u64 *record_id)
75{
76 return 0;
77}
78static inline int apei_check_mce(void)
79{
80 return 0;
81}
82static inline int apei_clear_mce(u64 record_id)
83{
84 return -EINVAL;
85}
86#endif
a79da384
BP
87
88void mce_inject_log(struct mce *m);
5541c93c
TL
89
90/*
91 * We consider records to be equivalent if bank+status+addr+misc all match.
92 * This is only used when the system is going down because of a fatal error
93 * to avoid cluttering the console log with essentially repeated information.
94 * In normal processing all errors seen are logged.
95 */
96static inline bool mce_cmp(struct mce *m1, struct mce *m2)
97{
98 return m1->bank != m2->bank ||
99 m1->status != m2->status ||
100 m1->addr != m2->addr ||
101 m1->misc != m2->misc;
102}
5de97c9f
TL
103
104extern struct device_attribute dev_attr_trigger;
105
106#ifdef CONFIG_X86_MCELOG_LEGACY
fbe9ff9e
BP
107void mce_work_trigger(void);
108void mce_register_injector_chain(struct notifier_block *nb);
109void mce_unregister_injector_chain(struct notifier_block *nb);
5de97c9f
TL
110#else
111static inline void mce_work_trigger(void) { }
fbe9ff9e
BP
112static inline void mce_register_injector_chain(struct notifier_block *nb) { }
113static inline void mce_unregister_injector_chain(struct notifier_block *nb) { }
5de97c9f 114#endif
262e6811
BP
115
116extern struct mca_config mca_cfg;
117
fd0e786d
TL
118#ifndef CONFIG_X86_64
119/*
120 * On 32-bit systems it would be difficult to safely unmap a poison page
121 * from the kernel 1:1 map because there are no non-canonical addresses that
122 * we can use to refer to the address without risking a speculative access.
123 * However, this isn't much of an issue because:
124 * 1) Few unmappable pages are in the 1:1 map. Most are in HIGHMEM which
125 * are only mapped into the kernel as needed
126 * 2) Few people would run a 32-bit kernel on a machine that supports
127 * recoverable errors because they have too much memory to boot 32-bit.
128 */
129static inline void mce_unmap_kpfn(unsigned long pfn) {}
130#define mce_unmap_kpfn mce_unmap_kpfn
131#endif
132
262e6811 133#endif /* __X86_MCE_INTERNAL_H__ */