Merge tag 'smp-urgent-2023-09-02' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / arch / powerpc / include / asm / mce.h
CommitLineData
1a59d1b8 1/* SPDX-License-Identifier: GPL-2.0-or-later */
e22a2274
MS
2/*
3 * Machine check exception header file.
4 *
e22a2274
MS
5 * Copyright 2013 IBM Corporation
6 * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
7 */
8
9#ifndef __ASM_PPC64_MCE_H__
10#define __ASM_PPC64_MCE_H__
11
12#include <linux/bitops.h>
13
36df96f8
MS
14enum MCE_Version {
15 MCE_V1 = 1,
16};
17
18enum MCE_Severity {
19 MCE_SEV_NO_ERROR = 0,
20 MCE_SEV_WARNING = 1,
cda6618d 21 MCE_SEV_SEVERE = 2,
36df96f8
MS
22 MCE_SEV_FATAL = 3,
23};
24
25enum MCE_Disposition {
26 MCE_DISPOSITION_RECOVERED = 0,
27 MCE_DISPOSITION_NOT_RECOVERED = 1,
28};
29
30enum MCE_Initiator {
31 MCE_INITIATOR_UNKNOWN = 0,
32 MCE_INITIATOR_CPU = 1,
9ca766f9
NP
33 MCE_INITIATOR_PCI = 2,
34 MCE_INITIATOR_ISA = 3,
35 MCE_INITIATOR_MEMORY= 4,
36 MCE_INITIATOR_POWERMGM = 5,
36df96f8
MS
37};
38
39enum MCE_ErrorType {
40 MCE_ERROR_TYPE_UNKNOWN = 0,
41 MCE_ERROR_TYPE_UE = 1,
42 MCE_ERROR_TYPE_SLB = 2,
43 MCE_ERROR_TYPE_ERAT = 3,
44 MCE_ERROR_TYPE_TLB = 4,
7b9f71f9
NP
45 MCE_ERROR_TYPE_USER = 5,
46 MCE_ERROR_TYPE_RA = 6,
47 MCE_ERROR_TYPE_LINK = 7,
9ca766f9
NP
48 MCE_ERROR_TYPE_DCACHE = 8,
49 MCE_ERROR_TYPE_ICACHE = 9,
36df96f8
MS
50};
51
50dbabe0
MS
52enum MCE_ErrorClass {
53 MCE_ECLASS_UNKNOWN = 0,
54 MCE_ECLASS_HARDWARE,
55 MCE_ECLASS_HARD_INDETERMINATE,
56 MCE_ECLASS_SOFTWARE,
57 MCE_ECLASS_SOFT_INDETERMINATE,
58};
59
36df96f8
MS
60enum MCE_UeErrorType {
61 MCE_UE_ERROR_INDETERMINATE = 0,
62 MCE_UE_ERROR_IFETCH = 1,
63 MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH = 2,
64 MCE_UE_ERROR_LOAD_STORE = 3,
65 MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE = 4,
66};
67
68enum MCE_SlbErrorType {
69 MCE_SLB_ERROR_INDETERMINATE = 0,
70 MCE_SLB_ERROR_PARITY = 1,
71 MCE_SLB_ERROR_MULTIHIT = 2,
72};
73
74enum MCE_EratErrorType {
75 MCE_ERAT_ERROR_INDETERMINATE = 0,
76 MCE_ERAT_ERROR_PARITY = 1,
77 MCE_ERAT_ERROR_MULTIHIT = 2,
78};
79
80enum MCE_TlbErrorType {
81 MCE_TLB_ERROR_INDETERMINATE = 0,
82 MCE_TLB_ERROR_PARITY = 1,
83 MCE_TLB_ERROR_MULTIHIT = 2,
84};
85
7b9f71f9
NP
86enum MCE_UserErrorType {
87 MCE_USER_ERROR_INDETERMINATE = 0,
88 MCE_USER_ERROR_TLBIE = 1,
201220bb 89 MCE_USER_ERROR_SCV = 2,
7b9f71f9
NP
90};
91
92enum MCE_RaErrorType {
93 MCE_RA_ERROR_INDETERMINATE = 0,
94 MCE_RA_ERROR_IFETCH = 1,
90df4bfb
NP
95 MCE_RA_ERROR_IFETCH_FOREIGN = 2,
96 MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH = 3,
97 MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH_FOREIGN = 4,
98 MCE_RA_ERROR_LOAD = 5,
99 MCE_RA_ERROR_STORE = 6,
100 MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE = 7,
101 MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE_FOREIGN = 8,
102 MCE_RA_ERROR_LOAD_STORE_FOREIGN = 9,
7b9f71f9
NP
103};
104
105enum MCE_LinkErrorType {
106 MCE_LINK_ERROR_INDETERMINATE = 0,
107 MCE_LINK_ERROR_IFETCH_TIMEOUT = 1,
108 MCE_LINK_ERROR_PAGE_TABLE_WALK_IFETCH_TIMEOUT = 2,
109 MCE_LINK_ERROR_LOAD_TIMEOUT = 3,
110 MCE_LINK_ERROR_STORE_TIMEOUT = 4,
111 MCE_LINK_ERROR_PAGE_TABLE_WALK_LOAD_STORE_TIMEOUT = 5,
112};
113
36df96f8 114struct machine_check_event {
cda6618d
MS
115 enum MCE_Version version:8;
116 u8 in_use;
117 enum MCE_Severity severity:8;
118 enum MCE_Initiator initiator:8;
119 enum MCE_ErrorType error_type:8;
50dbabe0 120 enum MCE_ErrorClass error_class:8;
cda6618d
MS
121 enum MCE_Disposition disposition:8;
122 bool sync_error;
123 u16 cpu;
124 u64 gpr3;
125 u64 srr0;
126 u64 srr1;
127 union {
36df96f8
MS
128 struct {
129 enum MCE_UeErrorType ue_error_type:8;
cda6618d
MS
130 u8 effective_address_provided;
131 u8 physical_address_provided;
895e3dce
BS
132 u8 ignore_event;
133 u8 reserved_1[4];
cda6618d
MS
134 u64 effective_address;
135 u64 physical_address;
136 u8 reserved_2[8];
36df96f8
MS
137 } ue_error;
138
139 struct {
140 enum MCE_SlbErrorType slb_error_type:8;
cda6618d
MS
141 u8 effective_address_provided;
142 u8 reserved_1[6];
143 u64 effective_address;
144 u8 reserved_2[16];
36df96f8
MS
145 } slb_error;
146
147 struct {
148 enum MCE_EratErrorType erat_error_type:8;
cda6618d
MS
149 u8 effective_address_provided;
150 u8 reserved_1[6];
151 u64 effective_address;
152 u8 reserved_2[16];
36df96f8
MS
153 } erat_error;
154
155 struct {
156 enum MCE_TlbErrorType tlb_error_type:8;
cda6618d
MS
157 u8 effective_address_provided;
158 u8 reserved_1[6];
159 u64 effective_address;
160 u8 reserved_2[16];
36df96f8 161 } tlb_error;
7b9f71f9
NP
162
163 struct {
164 enum MCE_UserErrorType user_error_type:8;
cda6618d
MS
165 u8 effective_address_provided;
166 u8 reserved_1[6];
167 u64 effective_address;
168 u8 reserved_2[16];
7b9f71f9
NP
169 } user_error;
170
171 struct {
172 enum MCE_RaErrorType ra_error_type:8;
cda6618d
MS
173 u8 effective_address_provided;
174 u8 reserved_1[6];
175 u64 effective_address;
176 u8 reserved_2[16];
7b9f71f9
NP
177 } ra_error;
178
179 struct {
180 enum MCE_LinkErrorType link_error_type:8;
cda6618d
MS
181 u8 effective_address_provided;
182 u8 reserved_1[6];
183 u64 effective_address;
184 u8 reserved_2[16];
7b9f71f9 185 } link_error;
36df96f8
MS
186 } u;
187};
188
189struct mce_error_info {
190 enum MCE_ErrorType error_type:8;
191 union {
192 enum MCE_UeErrorType ue_error_type:8;
193 enum MCE_SlbErrorType slb_error_type:8;
194 enum MCE_EratErrorType erat_error_type:8;
195 enum MCE_TlbErrorType tlb_error_type:8;
7b9f71f9
NP
196 enum MCE_UserErrorType user_error_type:8;
197 enum MCE_RaErrorType ra_error_type:8;
198 enum MCE_LinkErrorType link_error_type:8;
36df96f8 199 } u;
c1bbf387
NP
200 enum MCE_Severity severity:8;
201 enum MCE_Initiator initiator:8;
50dbabe0 202 enum MCE_ErrorClass error_class:8;
cda6618d 203 bool sync_error;
895e3dce 204 bool ignore_event;
36df96f8
MS
205};
206
17c5cf0f 207#define MAX_MC_EVT 10
36df96f8 208
923b3cf0
GG
209struct mce_info {
210 int mce_nest_count;
211 struct machine_check_event mce_event[MAX_MC_EVT];
212 /* Queue for delayed MCE events. */
213 int mce_queue_count;
214 struct machine_check_event mce_event_queue[MAX_MC_EVT];
215 /* Queue for delayed MCE UE events. */
216 int mce_ue_count;
217 struct machine_check_event mce_ue_event_queue[MAX_MC_EVT];
218};
219
36df96f8
MS
220/* Release flags for get_mce_event() */
221#define MCE_EVENT_RELEASE true
222#define MCE_EVENT_DONTRELEASE false
223
388692e9
MS
224struct pt_regs;
225struct notifier_block;
226
36df96f8 227extern void save_mce_event(struct pt_regs *regs, long handled,
55672ecf 228 struct mce_error_info *mce_err, uint64_t nip,
ba41e1e1 229 uint64_t addr, uint64_t phys_addr);
36df96f8
MS
230extern int get_mce_event(struct machine_check_event *mce, bool release);
231extern void release_mce_event(void);
b5ff4211 232extern void machine_check_queue_event(void);
63f44d65 233extern void machine_check_print_event_info(struct machine_check_event *evt,
c0577201 234 bool user_mode, bool in_guest);
7f177f98 235unsigned long addr_to_pfn(struct pt_regs *regs, unsigned long addr);
efbc4303
GG
236extern void mce_common_process_ue(struct pt_regs *regs,
237 struct mce_error_info *mce_err);
cc15ff32 238void mce_irq_work_queue(void);
c37a63af
SS
239int mce_register_notifier(struct notifier_block *nb);
240int mce_unregister_notifier(struct notifier_block *nb);
cc15ff32
GG
241
242#ifdef CONFIG_PPC_BOOK3S_64
243void mce_run_irq_context_handlers(void);
244#else
245static inline void mce_run_irq_context_handlers(void) { };
246#endif /* CONFIG_PPC_BOOK3S_64 */
247
248#ifdef CONFIG_PPC_BOOK3S_64
249void set_mce_pending_irq_work(void);
250void clear_mce_pending_irq_work(void);
251#endif /* CONFIG_PPC_BOOK3S_64 */
252
a43c1590
MS
253#ifdef CONFIG_PPC_BOOK3S_64
254void flush_and_reload_slb(void);
82f70a05 255void flush_erat(void);
388692e9
MS
256long __machine_check_early_realmode_p7(struct pt_regs *regs);
257long __machine_check_early_realmode_p8(struct pt_regs *regs);
258long __machine_check_early_realmode_p9(struct pt_regs *regs);
259long __machine_check_early_realmode_p10(struct pt_regs *regs);
a43c1590 260#endif /* CONFIG_PPC_BOOK3S_64 */
923b3cf0
GG
261
262#ifdef CONFIG_PPC_BOOK3S_64
263void mce_init(void);
264#else
265static inline void mce_init(void) { };
266#endif /* CONFIG_PPC_BOOK3S_64 */
267
e22a2274 268#endif /* __ASM_PPC64_MCE_H__ */