blob: c40b4380951cb45518656a0e1030280d9253d852 [file] [log] [blame]
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +10001#ifndef _ASM_POWERPC_EXCEPTION_H
2#define _ASM_POWERPC_EXCEPTION_H
3/*
4 * Extracted from head_64.S
5 *
6 * PowerPC version
7 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
8 *
9 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
10 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
11 * Adapted for Power Macintosh by Paul Mackerras.
12 * Low-level exception handlers and MMU support
13 * rewritten by Paul Mackerras.
14 * Copyright (C) 1996 Paul Mackerras.
15 *
16 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
17 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
18 *
19 * This file contains the low-level support and setup for the
20 * PowerPC-64 platform, including trap and interrupt dispatch.
21 *
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version
25 * 2 of the License, or (at your option) any later version.
26 */
27/*
28 * The following macros define the code that appears as
29 * the prologue to each of the exception handlers. They
30 * are split into two parts to allow a single kernel binary
31 * to be used for pSeries and iSeries.
32 *
33 * We make as much of the exception code common between native
34 * exception handlers (including pSeries LPAR) and iSeries LPAR
35 * implementations as possible.
36 */
Michael Ellermanda2bc462016-09-30 19:43:18 +100037#include <asm/head-64.h>
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +100038
Nicholas Piggin8c388512017-05-21 23:15:46 +100039/* PACA save area offsets (exgen, exmc, etc) */
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +100040#define EX_R9 0
41#define EX_R10 8
42#define EX_R11 16
43#define EX_R12 24
44#define EX_R13 32
Nicholas Piggin36670fc2017-05-21 23:15:47 +100045#define EX_DAR 40
46#define EX_DSISR 48
47#define EX_CCR 52
Nicholas Piggin635942a2017-05-21 23:15:49 +100048#define EX_CFAR 56
49#define EX_PPR 64
Nicholas Piggin8568f1e02017-05-21 23:15:50 +100050#if defined(CONFIG_RELOCATABLE)
Nicholas Piggin635942a2017-05-21 23:15:49 +100051#define EX_CTR 72
Nicholas Piggin635942a2017-05-21 23:15:49 +100052#define EX_SIZE 10 /* size in u64 units */
Nicholas Piggin8568f1e02017-05-21 23:15:50 +100053#else
54#define EX_SIZE 9 /* size in u64 units */
55#endif
Nicholas Piggindbeea1d2017-05-21 23:15:48 +100056
57/*
Balbir Singhba41e1e2017-09-29 14:26:53 +100058 * maximum recursive depth of MCE exceptions
59 */
60#define MAX_MCE_DEPTH 4
61
62/*
Nicholas Piggindbeea1d2017-05-21 23:15:48 +100063 * EX_LR is only used in EXSLB and where it does not overlap with EX_DAR
64 * EX_CCR similarly with DSISR, but being 4 byte registers there is a hole
65 * in the save area so it's not necessary to overlap them. Could be used
66 * for future savings though if another 4 byte register was to be saved.
67 */
68#define EX_LR EX_DAR
Nicholas Piggin8c388512017-05-21 23:15:46 +100069
Nicholas Piggin635942a2017-05-21 23:15:49 +100070/*
71 * EX_R3 is only used by the bad_stack handler. bad_stack reloads and
72 * saves DAR from SPRN_DAR, and EX_DAR is not used. So EX_R3 can overlap
73 * with EX_DAR.
74 */
75#define EX_R3 EX_DAR
76
Nicholas Piggina048a072018-05-22 09:00:00 +100077#define STF_ENTRY_BARRIER_SLOT \
78 STF_ENTRY_BARRIER_FIXUP_SECTION; \
79 nop; \
80 nop; \
81 nop
82
83#define STF_EXIT_BARRIER_SLOT \
84 STF_EXIT_BARRIER_FIXUP_SECTION; \
85 nop; \
86 nop; \
87 nop; \
88 nop; \
89 nop; \
90 nop
91
92/*
93 * r10 must be free to use, r13 must be paca
94 */
95#define INTERRUPT_TO_KERNEL \
96 STF_ENTRY_BARRIER_SLOT
97
Michael Ellermanaa8a5e02018-01-10 03:07:15 +110098/*
99 * Macros for annotating the expected destination of (h)rfid
100 *
101 * The nop instructions allow us to insert one or more instructions to flush the
102 * L1-D cache when returning to userspace or a guest.
103 */
104#define RFI_FLUSH_SLOT \
105 RFI_FLUSH_FIXUP_SECTION; \
106 nop; \
107 nop; \
108 nop
Nicholas Piggin50e51c132018-01-10 03:07:15 +1100109
110#define RFI_TO_KERNEL \
111 rfid
112
113#define RFI_TO_USER \
Nicholas Piggina048a072018-05-22 09:00:00 +1000114 STF_EXIT_BARRIER_SLOT; \
Michael Ellermanaa8a5e02018-01-10 03:07:15 +1100115 RFI_FLUSH_SLOT; \
116 rfid; \
117 b rfi_flush_fallback
Nicholas Piggin50e51c132018-01-10 03:07:15 +1100118
119#define RFI_TO_USER_OR_KERNEL \
Nicholas Piggina048a072018-05-22 09:00:00 +1000120 STF_EXIT_BARRIER_SLOT; \
Michael Ellermanaa8a5e02018-01-10 03:07:15 +1100121 RFI_FLUSH_SLOT; \
122 rfid; \
123 b rfi_flush_fallback
Nicholas Piggin50e51c132018-01-10 03:07:15 +1100124
125#define RFI_TO_GUEST \
Nicholas Piggina048a072018-05-22 09:00:00 +1000126 STF_EXIT_BARRIER_SLOT; \
Michael Ellermanaa8a5e02018-01-10 03:07:15 +1100127 RFI_FLUSH_SLOT; \
128 rfid; \
129 b rfi_flush_fallback
Nicholas Piggin50e51c132018-01-10 03:07:15 +1100130
131#define HRFI_TO_KERNEL \
132 hrfid
133
134#define HRFI_TO_USER \
Nicholas Piggina048a072018-05-22 09:00:00 +1000135 STF_EXIT_BARRIER_SLOT; \
Michael Ellermanaa8a5e02018-01-10 03:07:15 +1100136 RFI_FLUSH_SLOT; \
137 hrfid; \
138 b hrfi_flush_fallback
Nicholas Piggin50e51c132018-01-10 03:07:15 +1100139
140#define HRFI_TO_USER_OR_KERNEL \
Nicholas Piggina048a072018-05-22 09:00:00 +1000141 STF_EXIT_BARRIER_SLOT; \
Michael Ellermanaa8a5e02018-01-10 03:07:15 +1100142 RFI_FLUSH_SLOT; \
143 hrfid; \
144 b hrfi_flush_fallback
Nicholas Piggin50e51c132018-01-10 03:07:15 +1100145
146#define HRFI_TO_GUEST \
Nicholas Piggina048a072018-05-22 09:00:00 +1000147 STF_EXIT_BARRIER_SLOT; \
Michael Ellermanaa8a5e02018-01-10 03:07:15 +1100148 RFI_FLUSH_SLOT; \
149 hrfid; \
150 b hrfi_flush_fallback
Nicholas Piggin50e51c132018-01-10 03:07:15 +1100151
152#define HRFI_TO_UNKNOWN \
Nicholas Piggina048a072018-05-22 09:00:00 +1000153 STF_EXIT_BARRIER_SLOT; \
Michael Ellermanaa8a5e02018-01-10 03:07:15 +1100154 RFI_FLUSH_SLOT; \
155 hrfid; \
156 b hrfi_flush_fallback
Nicholas Piggin50e51c132018-01-10 03:07:15 +1100157
Michael Neuling4700dfa2012-11-02 17:21:28 +1100158#ifdef CONFIG_RELOCATABLE
Paul Mackerras1707dd12013-02-04 18:10:15 +0000159#define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100160 mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
161 LOAD_HANDLER(r12,label); \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000162 mtctr r12; \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100163 mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
164 li r10,MSR_RI; \
165 mtmsrd r10,1; /* Set RI (EE=0) */ \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000166 bctr;
Michael Neuling4700dfa2012-11-02 17:21:28 +1100167#else
168/* If not relocatable, we can jump directly -- and save messing with LR */
Paul Mackerras1707dd12013-02-04 18:10:15 +0000169#define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100170 mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
171 mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
172 li r10,MSR_RI; \
173 mtmsrd r10,1; /* Set RI (EE=0) */ \
174 b label;
175#endif
Paul Mackerras1707dd12013-02-04 18:10:15 +0000176#define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
177 __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100178
179/*
180 * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on
181 * so no need to rfid. Save lr in case we're CONFIG_RELOCATABLE, in which
182 * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr.
183 */
184#define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000185 EXCEPTION_PROLOG_0(area); \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100186 EXCEPTION_PROLOG_1(area, extra, vec); \
187 EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
188
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000189/*
190 * We're short on space and time in the exception prolog, so we can't
Michael Ellerman27510232016-07-26 15:29:29 +1000191 * use the normal LOAD_REG_IMMEDIATE macro to load the address of label.
192 * Instead we get the base of the kernel from paca->kernelbase and or in the low
193 * part of label. This requires that the label be within 64KB of kernelbase, and
194 * that kernelbase be 64K aligned.
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000195 */
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000196#define LOAD_HANDLER(reg, label) \
Michael Ellermand8d42b02016-07-26 15:29:30 +1000197 ld reg,PACAKBASE(r13); /* get high part of &label */ \
Hugh Dickinse6740ae2016-11-07 22:28:21 -0800198 ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label);
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000199
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100200#define __LOAD_HANDLER(reg, label) \
201 ld reg,PACAKBASE(r13); \
202 ori reg,reg,(ABS_ADDR(label))@l;
203
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000204/*
205 * Branches from unrelocated code (e.g., interrupts) to labels outside
206 * head-y require >64K offsets.
207 */
208#define __LOAD_FAR_HANDLER(reg, label) \
209 ld reg,PACAKBASE(r13); \
210 ori reg,reg,(ABS_ADDR(label))@l; \
211 addis reg,reg,(ABS_ADDR(label))@h;
212
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000213/* Exception register prefixes */
214#define EXC_HV H
215#define EXC_STD
216
Michael Neuling4700dfa2012-11-02 17:21:28 +1100217#if defined(CONFIG_RELOCATABLE)
218/*
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000219 * If we support interrupts with relocation on AND we're a relocatable kernel,
220 * we need to use CTR to get to the 2nd level handler. So, save/restore it
221 * when required.
Michael Neuling4700dfa2012-11-02 17:21:28 +1100222 */
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000223#define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13)
224#define GET_CTR(reg, area) ld reg,area+EX_CTR(r13)
225#define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg
Michael Neuling4700dfa2012-11-02 17:21:28 +1100226#else
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000227/* ...else CTR is unused and in register. */
228#define SAVE_CTR(reg, area)
229#define GET_CTR(reg, area) mfctr reg
230#define RESTORE_CTR(reg, area)
Michael Neuling4700dfa2012-11-02 17:21:28 +1100231#endif
232
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000233/*
234 * PPR save/restore macros used in exceptions_64s.S
235 * Used for P7 or later processors
236 */
237#define SAVE_PPR(area, ra, rb) \
238BEGIN_FTR_SECTION_NESTED(940) \
239 ld ra,PACACURRENT(r13); \
240 ld rb,area+EX_PPR(r13); /* Read PPR from paca */ \
241 std rb,TASKTHREADPPR(ra); \
242END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940)
243
244#define RESTORE_PPR_PACA(area, ra) \
245BEGIN_FTR_SECTION_NESTED(941) \
246 ld ra,area+EX_PPR(r13); \
247 mtspr SPRN_PPR,ra; \
248END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941)
249
250/*
Paul Mackerras1707dd12013-02-04 18:10:15 +0000251 * Get an SPR into a register if the CPU has the given feature
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000252 */
Paul Mackerras1707dd12013-02-04 18:10:15 +0000253#define OPT_GET_SPR(ra, spr, ftr) \
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000254BEGIN_FTR_SECTION_NESTED(943) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000255 mfspr ra,spr; \
256END_FTR_SECTION_NESTED(ftr,ftr,943)
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000257
Paul Mackerras1707dd12013-02-04 18:10:15 +0000258/*
Mahesh Salgaonkard410ae22014-03-11 10:56:18 +0530259 * Set an SPR from a register if the CPU has the given feature
260 */
261#define OPT_SET_SPR(ra, spr, ftr) \
262BEGIN_FTR_SECTION_NESTED(943) \
263 mtspr spr,ra; \
264END_FTR_SECTION_NESTED(ftr,ftr,943)
265
266/*
Paul Mackerras1707dd12013-02-04 18:10:15 +0000267 * Save a register to the PACA if the CPU has the given feature
268 */
269#define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \
270BEGIN_FTR_SECTION_NESTED(943) \
271 std ra,offset(r13); \
272END_FTR_SECTION_NESTED(ftr,ftr,943)
273
Nicholas Piggin544686c2017-04-19 23:05:45 +1000274#define EXCEPTION_PROLOG_0(area) \
275 GET_PACA(r13); \
Haren Myneni44e93092012-12-06 21:51:04 +0000276 std r9,area+EX_R9(r13); /* save r9 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000277 OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR); \
278 HMT_MEDIUM; \
Haren Myneni44e93092012-12-06 21:51:04 +0000279 std r10,area+EX_R10(r13); /* save r10 - r12 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000280 OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR)
281
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530282#define __EXCEPTION_PROLOG_1_PRE(area) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000283 OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \
284 OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \
Nicholas Piggina048a072018-05-22 09:00:00 +1000285 INTERRUPT_TO_KERNEL; \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000286 SAVE_CTR(r10, area); \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530287 mfcr r9;
288
289#define __EXCEPTION_PROLOG_1_POST(area) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000290 std r11,area+EX_R11(r13); \
291 std r12,area+EX_R12(r13); \
292 GET_SCRATCH0(r10); \
293 std r10,area+EX_R13(r13)
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530294
295/*
296 * This version of the EXCEPTION_PROLOG_1 will carry
297 * addition parameter called "bitmask" to support
298 * checking of the interrupt maskable level in the SOFTEN_TEST.
299 * Intended to be used in MASKABLE_EXCPETION_* macros.
300 */
301#define MASKABLE_EXCEPTION_PROLOG_1(area, extra, vec, bitmask) \
302 __EXCEPTION_PROLOG_1_PRE(area); \
303 extra(vec, bitmask); \
304 __EXCEPTION_PROLOG_1_POST(area);
305
306/*
307 * This version of the EXCEPTION_PROLOG_1 is intended
308 * to be used in STD_EXCEPTION* macros
309 */
310#define _EXCEPTION_PROLOG_1(area, extra, vec) \
311 __EXCEPTION_PROLOG_1_PRE(area); \
312 extra(vec); \
313 __EXCEPTION_PROLOG_1_POST(area);
314
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000315#define EXCEPTION_PROLOG_1(area, extra, vec) \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530316 _EXCEPTION_PROLOG_1(area, extra, vec)
Stephen Rothwell7180e3e2007-08-22 13:48:37 +1000317
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000318#define __EXCEPTION_PROLOG_PSERIES_1(label, h) \
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000319 ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000320 mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000321 LOAD_HANDLER(r12,label) \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000322 mtspr SPRN_##h##SRR0,r12; \
323 mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
324 mtspr SPRN_##h##SRR1,r10; \
Nicholas Piggin222f20f2018-01-10 03:07:15 +1100325 h##RFI_TO_KERNEL; \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000326 b . /* prevent speculative execution */
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000327#define EXCEPTION_PROLOG_PSERIES_1(label, h) \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000328 __EXCEPTION_PROLOG_PSERIES_1(label, h)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000329
Nicholas Piggin83a980f2016-12-20 04:30:02 +1000330/* _NORI variant keeps MSR_RI clear */
331#define __EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \
332 ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \
333 xori r10,r10,MSR_RI; /* Clear MSR_RI */ \
334 mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
335 LOAD_HANDLER(r12,label) \
336 mtspr SPRN_##h##SRR0,r12; \
337 mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
338 mtspr SPRN_##h##SRR1,r10; \
Nicholas Piggin222f20f2018-01-10 03:07:15 +1100339 h##RFI_TO_KERNEL; \
Nicholas Piggin83a980f2016-12-20 04:30:02 +1000340 b . /* prevent speculative execution */
341
342#define EXCEPTION_PROLOG_PSERIES_1_NORI(label, h) \
343 __EXCEPTION_PROLOG_PSERIES_1_NORI(label, h)
344
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000345#define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000346 EXCEPTION_PROLOG_0(area); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000347 EXCEPTION_PROLOG_1(area, extra, vec); \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000348 EXCEPTION_PROLOG_PSERIES_1(label, h);
Benjamin Herrenschmidtc5a8c0c2009-07-16 19:36:57 +0000349
Michael Ellermanda2bc462016-09-30 19:43:18 +1000350#define __KVMTEST(h, n) \
351 lbz r10,HSTATE_IN_GUEST(r13); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000352 cmpwi r10,0; \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000353 bne do_kvm_##h##n
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000354
Aneesh Kumar K.Vdd96b2c2013-10-07 22:17:55 +0530355#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
356/*
357 * If hv is possible, interrupts come into to the hv version
358 * of the kvmppc_interrupt code, which then jumps to the PR handler,
359 * kvmppc_interrupt_pr, if the guest is a PR guest.
360 */
361#define kvmppc_interrupt kvmppc_interrupt_hv
362#else
363#define kvmppc_interrupt kvmppc_interrupt_pr
364#endif
365
Nicholas Pigginb51351e2017-06-13 23:05:50 +1000366/*
367 * Branch to label using its 0xC000 address. This results in instruction
368 * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned
369 * on using mtmsr rather than rfid.
370 *
371 * This could set the 0xc bits for !RELOCATABLE as an immediate, rather than
372 * load KBASE for a slight optimisation.
373 */
374#define BRANCH_TO_C000(reg, label) \
375 __LOAD_HANDLER(reg, label); \
376 mtctr reg; \
377 bctr
378
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100379#ifdef CONFIG_RELOCATABLE
380#define BRANCH_TO_COMMON(reg, label) \
381 __LOAD_HANDLER(reg, label); \
382 mtctr reg; \
383 bctr
384
Michael Ellermanbe5c5e82017-04-18 14:08:15 +1000385#define BRANCH_LINK_TO_FAR(label) \
386 __LOAD_FAR_HANDLER(r12, label); \
387 mtctr r12; \
Nicholas Piggin2337d202017-01-27 14:24:33 +1000388 bctrl
389
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000390/*
391 * KVM requires __LOAD_FAR_HANDLER.
392 *
393 * __BRANCH_TO_KVM_EXIT branches are also a special case because they
394 * explicitly use r9 then reload it from PACA before branching. Hence
395 * the double-underscore.
396 */
397#define __BRANCH_TO_KVM_EXIT(area, label) \
398 mfctr r9; \
399 std r9,HSTATE_SCRATCH1(r13); \
400 __LOAD_FAR_HANDLER(r9, label); \
401 mtctr r9; \
402 ld r9,area+EX_R9(r13); \
403 bctr
404
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100405#else
406#define BRANCH_TO_COMMON(reg, label) \
407 b label
408
Michael Ellermanbe5c5e82017-04-18 14:08:15 +1000409#define BRANCH_LINK_TO_FAR(label) \
Nicholas Piggin2337d202017-01-27 14:24:33 +1000410 bl label
411
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000412#define __BRANCH_TO_KVM_EXIT(area, label) \
413 ld r9,area+EX_R9(r13); \
414 b label
415
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100416#endif
417
Nicholas Pigginc4f3b522016-12-20 04:30:05 +1000418/* Do not enable RI */
419#define EXCEPTION_PROLOG_PSERIES_NORI(area, label, h, extra, vec) \
420 EXCEPTION_PROLOG_0(area); \
421 EXCEPTION_PROLOG_1(area, extra, vec); \
422 EXCEPTION_PROLOG_PSERIES_1_NORI(label, h);
423
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000424
Nicholas Piggind3918e72016-12-22 04:29:25 +1000425#define __KVM_HANDLER(area, h, n) \
Paul Mackerras0acb9112013-02-04 18:10:51 +0000426 BEGIN_FTR_SECTION_NESTED(947) \
427 ld r10,area+EX_CFAR(r13); \
428 std r10,HSTATE_CFAR(r13); \
429 END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947); \
Paul Mackerras4b8473c2013-09-20 14:52:39 +1000430 BEGIN_FTR_SECTION_NESTED(948) \
431 ld r10,area+EX_PPR(r13); \
432 std r10,HSTATE_PPR(r13); \
433 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000434 ld r10,area+EX_R10(r13); \
Paul Mackerras0acb9112013-02-04 18:10:51 +0000435 std r12,HSTATE_SCRATCH0(r13); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000436 sldi r12,r9,32; \
437 ori r12,r12,(n); \
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000438 /* This reloads r9 before branching to kvmppc_interrupt */ \
439 __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000440
441#define __KVM_HANDLER_SKIP(area, h, n) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000442 cmpwi r10,KVM_GUEST_MODE_SKIP; \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000443 beq 89f; \
Paul Mackerras4b8473c2013-09-20 14:52:39 +1000444 BEGIN_FTR_SECTION_NESTED(948) \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000445 ld r10,area+EX_PPR(r13); \
446 std r10,HSTATE_PPR(r13); \
Paul Mackerras4b8473c2013-09-20 14:52:39 +1000447 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000448 ld r10,area+EX_R10(r13); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000449 std r12,HSTATE_SCRATCH0(r13); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000450 sldi r12,r9,32; \
451 ori r12,r12,(n); \
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000452 /* This reloads r9 before branching to kvmppc_interrupt */ \
453 __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000045489: mtocrf 0x80,r9; \
455 ld r9,area+EX_R9(r13); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000456 ld r10,area+EX_R10(r13); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000457 b kvmppc_skip_##h##interrupt
458
459#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
Michael Ellermanda2bc462016-09-30 19:43:18 +1000460#define KVMTEST(h, n) __KVMTEST(h, n)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000461#define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n)
462#define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n)
463
464#else
Michael Ellermanda2bc462016-09-30 19:43:18 +1000465#define KVMTEST(h, n)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000466#define KVM_HANDLER(area, h, n)
467#define KVM_HANDLER_SKIP(area, h, n)
468#endif
469
470#define NOTEST(n)
471
Nicholas Piggina4087a42016-12-20 04:30:03 +1000472#define EXCEPTION_PROLOG_COMMON_1() \
473 std r9,_CCR(r1); /* save CR in stackframe */ \
474 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
475 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
476 std r10,0(r1); /* make stack chain pointer */ \
477 std r0,GPR0(r1); /* save r0 in stackframe */ \
478 std r10,GPR1(r1); /* save r1 in stackframe */ \
479
480
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000481/*
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000482 * The common exception prolog is used for all except a few exceptions
483 * such as a segment miss on a kernel address. We have to be prepared
484 * to take another exception from the point where we first touch the
485 * kernel stack onwards.
486 *
487 * On entry r13 points to the paca, r9-r13 are saved in the paca,
488 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
489 * SRR1, and relocation is on.
490 */
491#define EXCEPTION_PROLOG_COMMON(n, area) \
492 andi. r10,r12,MSR_PR; /* See if coming from user */ \
493 mr r10,r1; /* Save r1 */ \
494 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
495 beq- 1f; \
496 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
Michael Neuling90ff5d62013-12-16 15:12:43 +11004971: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \
Paul Mackerras1977b502011-05-01 19:46:44 +0000498 blt+ cr1,3f; /* abort if it is */ \
499 li r1,(n); /* will be reloaded later */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000500 sth r1,PACA_TRAP_SAVE(r13); \
Paul Mackerras1977b502011-05-01 19:46:44 +0000501 std r3,area+EX_R3(r13); \
502 addi r3,r13,area; /* r3 -> where regs are saved*/ \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000503 RESTORE_CTR(r1, area); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000504 b bad_stack; \
Nicholas Piggina4087a42016-12-20 04:30:03 +10005053: EXCEPTION_PROLOG_COMMON_1(); \
Haren Myneni5d75b262012-12-06 21:46:37 +0000506 beq 4f; /* if from kernel mode */ \
Christophe Leroyc223c902016-05-17 08:33:46 +0200507 ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \
Haren Myneni44e93092012-12-06 21:51:04 +0000508 SAVE_PPR(area, r9, r10); \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +05305094: EXCEPTION_PROLOG_COMMON_2(area) \
510 EXCEPTION_PROLOG_COMMON_3(n) \
511 ACCOUNT_STOLEN_TIME
512
513/* Save original regs values from save area to stack frame. */
514#define EXCEPTION_PROLOG_COMMON_2(area) \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000515 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
516 ld r10,area+EX_R10(r13); \
517 std r9,GPR9(r1); \
518 std r10,GPR10(r1); \
519 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
520 ld r10,area+EX_R12(r13); \
521 ld r11,area+EX_R13(r13); \
522 std r9,GPR11(r1); \
523 std r10,GPR12(r1); \
524 std r11,GPR13(r1); \
Paul Mackerras48404f22011-05-01 19:48:20 +0000525 BEGIN_FTR_SECTION_NESTED(66); \
526 ld r10,area+EX_CFAR(r13); \
527 std r10,ORIG_GPR3(r1); \
528 END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +0530529 GET_CTR(r10, area); \
530 std r10,_CTR(r1);
531
532#define EXCEPTION_PROLOG_COMMON_3(n) \
533 std r2,GPR2(r1); /* save r2 in stackframe */ \
534 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
535 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000536 mflr r9; /* Get LR, later save to stack */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000537 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000538 std r9,_LINK(r1); \
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +0530539 lbz r10,PACAIRQSOFTMASK(r13); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000540 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
541 std r10,SOFTE(r1); \
542 std r11,_XER(r1); \
543 li r9,(n)+1; \
544 std r9,_TRAP(r1); /* set trap number */ \
545 li r10,0; \
546 ld r11,exception_marker@toc(r2); \
547 std r10,RESULT(r1); /* clear regs->result */ \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +0530548 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000549
550/*
551 * Exception vectors.
552 */
Michael Ellermanda2bc462016-09-30 19:43:18 +1000553#define STD_EXCEPTION_PSERIES(vec, label) \
Paul Mackerras673b1892011-04-05 13:59:58 +1000554 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000555 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \
556 EXC_STD, KVMTEST_PR, vec); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000557
Paul Mackerras1707dd12013-02-04 18:10:15 +0000558/* Version of above for when we have to branch out-of-line */
Michael Ellermanda2bc462016-09-30 19:43:18 +1000559#define __OOL_EXCEPTION(vec, label, hdlr) \
560 SET_SCRATCH0(r13) \
561 EXCEPTION_PROLOG_0(PACA_EXGEN) \
562 b hdlr;
563
Paul Mackerras1707dd12013-02-04 18:10:15 +0000564#define STD_EXCEPTION_PSERIES_OOL(vec, label) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000565 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, vec); \
566 EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000567
Michael Ellermanda2bc462016-09-30 19:43:18 +1000568#define STD_EXCEPTION_HV(loc, vec, label) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000569 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000570 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \
571 EXC_HV, KVMTEST_HV, vec);
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000572
Michael Ellermanda2bc462016-09-30 19:43:18 +1000573#define STD_EXCEPTION_HV_OOL(vec, label) \
574 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \
575 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000576
Michael Neuling4700dfa2012-11-02 17:21:28 +1100577#define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100578 /* No guest interrupts come through here */ \
579 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000580 EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_STD, NOTEST, vec);
Michael Neuling4700dfa2012-11-02 17:21:28 +1100581
Paul Mackerras1707dd12013-02-04 18:10:15 +0000582#define STD_RELON_EXCEPTION_PSERIES_OOL(vec, label) \
Michael Ellermanc9f69512013-06-25 17:47:55 +1000583 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000584 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_STD)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000585
Michael Neuling4700dfa2012-11-02 17:21:28 +1100586#define STD_RELON_EXCEPTION_HV(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100587 SET_SCRATCH0(r13); /* save r13 */ \
Paul Mackerrasbc355122017-01-30 21:21:40 +1100588 EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, \
589 EXC_HV, KVMTEST_HV, vec);
Michael Neuling4700dfa2012-11-02 17:21:28 +1100590
Paul Mackerras1707dd12013-02-04 18:10:15 +0000591#define STD_RELON_EXCEPTION_HV_OOL(vec, label) \
Paul Mackerrasbc355122017-01-30 21:21:40 +1100592 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000593 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000594
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100595/* This associate vector numbers with bits in paca->irq_happened */
596#define SOFTEN_VALUE_0x500 PACA_IRQ_EE
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100597#define SOFTEN_VALUE_0x900 PACA_IRQ_DEC
Michael Ellermanda2bc462016-09-30 19:43:18 +1000598#define SOFTEN_VALUE_0x980 PACA_IRQ_DEC
Ian Munsie1dbdafe2012-11-14 18:49:46 +0000599#define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL
Ian Munsie655bb3f2012-11-14 18:49:45 +0000600#define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +0530601#define SOFTEN_VALUE_0xe60 PACA_IRQ_HMI
Benjamin Herrenschmidt9baaef0a2016-07-08 16:37:06 +1000602#define SOFTEN_VALUE_0xea0 PACA_IRQ_EE
Madhavan Srinivasanf442d002017-12-20 09:25:53 +0530603#define SOFTEN_VALUE_0xf00 PACA_IRQ_PMI
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100604
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530605#define __SOFTEN_TEST(h, vec, bitmask) \
Madhavan Srinivasan4e26bc42017-12-20 09:25:50 +0530606 lbz r10,PACAIRQSOFTMASK(r13); \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530607 andi. r10,r10,bitmask; \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100608 li r10,SOFTEN_VALUE_##vec; \
Madhavan Srinivasan01417c62017-12-20 09:25:49 +0530609 bne masked_##h##interrupt
Michael Ellermanda2bc462016-09-30 19:43:18 +1000610
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530611#define _SOFTEN_TEST(h, vec, bitmask) __SOFTEN_TEST(h, vec, bitmask)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000612
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530613#define SOFTEN_TEST_PR(vec, bitmask) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000614 KVMTEST(EXC_STD, vec); \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530615 _SOFTEN_TEST(EXC_STD, vec, bitmask)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000616
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530617#define SOFTEN_TEST_HV(vec, bitmask) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000618 KVMTEST(EXC_HV, vec); \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530619 _SOFTEN_TEST(EXC_HV, vec, bitmask)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000620
Michael Ellermanda2bc462016-09-30 19:43:18 +1000621#define KVMTEST_PR(vec) \
622 KVMTEST(EXC_STD, vec)
623
624#define KVMTEST_HV(vec) \
625 KVMTEST(EXC_HV, vec)
626
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530627#define SOFTEN_NOTEST_PR(vec, bitmask) _SOFTEN_TEST(EXC_STD, vec, bitmask)
628#define SOFTEN_NOTEST_HV(vec, bitmask) _SOFTEN_TEST(EXC_HV, vec, bitmask)
Michael Neuling4700dfa2012-11-02 17:21:28 +1100629
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530630#define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra, bitmask) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000631 SET_SCRATCH0(r13); /* save r13 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000632 EXCEPTION_PROLOG_0(PACA_EXGEN); \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530633 MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec, bitmask); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000634 EXCEPTION_PROLOG_PSERIES_1(label, h);
Paul Mackerras1707dd12013-02-04 18:10:15 +0000635
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530636#define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra, bitmask) \
637 __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra, bitmask)
Benjamin Herrenschmidtb3e6b5df2011-04-05 14:27:11 +1000638
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530639#define MASKABLE_EXCEPTION_PSERIES(loc, vec, label, bitmask) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000640 _MASKABLE_EXCEPTION_PSERIES(vec, label, \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530641 EXC_STD, SOFTEN_TEST_PR, bitmask)
Benjamin Herrenschmidtb3e6b5df2011-04-05 14:27:11 +1000642
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530643#define MASKABLE_EXCEPTION_PSERIES_OOL(vec, label, bitmask) \
644 MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_PR, vec, bitmask);\
Michael Ellermanda2bc462016-09-30 19:43:18 +1000645 EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD)
646
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530647#define MASKABLE_EXCEPTION_HV(loc, vec, label, bitmask) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000648 _MASKABLE_EXCEPTION_PSERIES(vec, label, \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530649 EXC_HV, SOFTEN_TEST_HV, bitmask)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000650
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530651#define MASKABLE_EXCEPTION_HV_OOL(vec, label, bitmask) \
652 MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec, bitmask);\
Michael Ellermanda2bc462016-09-30 19:43:18 +1000653 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000654
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530655#define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra, bitmask) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100656 SET_SCRATCH0(r13); /* save r13 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000657 EXCEPTION_PROLOG_0(PACA_EXGEN); \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530658 MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec, bitmask); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000659 EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
660
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530661#define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra, bitmask)\
662 __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra, bitmask)
Michael Neuling4700dfa2012-11-02 17:21:28 +1100663
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530664#define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label, bitmask) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100665 _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530666 EXC_STD, SOFTEN_NOTEST_PR, bitmask)
Michael Neuling4700dfa2012-11-02 17:21:28 +1100667
Madhavan Srinivasanf442d002017-12-20 09:25:53 +0530668#define MASKABLE_RELON_EXCEPTION_PSERIES_OOL(vec, label, bitmask) \
669 MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_NOTEST_PR, vec, bitmask);\
670 EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD);
671
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530672#define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label, bitmask) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100673 _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530674 EXC_HV, SOFTEN_TEST_HV, bitmask)
Michael Neuling4700dfa2012-11-02 17:21:28 +1100675
Madhavan Srinivasanf14e9532017-12-20 09:25:52 +0530676#define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label, bitmask) \
Madhavan Srinivasan5c11d1e2018-02-06 18:06:37 +0530677 MASKABLE_EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec, bitmask);\
Nicholas Piggina050d202017-04-13 19:45:48 +1000678 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000679
Benjamin Herrenschmidt1b701172012-03-01 15:42:56 +1100680/*
681 * Our exception common code can be passed various "additions"
682 * to specify the behaviour of interrupts, whether to kick the
683 * runlatch, etc...
684 */
685
Michael Ellerman9daf1122014-07-15 21:15:38 +1000686/*
687 * This addition reconciles our actual IRQ state with the various software
688 * flags that track it. This may call C code.
689 */
690#define ADD_RECONCILE RECONCILE_IRQ_STATE(r10,r11)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000691
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100692#define ADD_NVGPRS \
Anton Blanchardb1576fe2014-02-04 16:04:35 +1100693 bl save_nvgprs
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100694
695#define RUNLATCH_ON \
696BEGIN_FTR_SECTION \
Stuart Yoder9778b692012-07-05 04:41:35 +0000697 CURRENT_THREAD_INFO(r3, r1); \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100698 ld r4,TI_LOCAL_FLAGS(r3); \
699 andi. r0,r4,_TLF_RUNLATCH; \
700 beql ppc64_runlatch_on_trampoline; \
701END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
702
Nicholas Piggina3d96f72016-12-20 04:30:04 +1000703#define EXCEPTION_COMMON(area, trap, label, hdlr, ret, additions) \
704 EXCEPTION_PROLOG_COMMON(trap, area); \
Michael Ellermana1d711c2014-07-15 21:15:37 +1000705 /* Volatile regs are potentially clobbered here */ \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100706 additions; \
707 addi r3,r1,STACK_FRAME_OVERHEAD; \
708 bl hdlr; \
709 b ret
710
Nicholas Pigginb1ee8a32016-12-20 04:30:06 +1000711/*
712 * Exception where stack is already set in r1, r1 is saved in r10, and it
713 * continues rather than returns.
714 */
715#define EXCEPTION_COMMON_NORET_STACK(area, trap, label, hdlr, additions) \
716 EXCEPTION_PROLOG_COMMON_1(); \
717 EXCEPTION_PROLOG_COMMON_2(area); \
718 EXCEPTION_PROLOG_COMMON_3(trap); \
719 /* Volatile regs are potentially clobbered here */ \
720 additions; \
721 addi r3,r1,STACK_FRAME_OVERHEAD; \
722 bl hdlr
723
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100724#define STD_EXCEPTION_COMMON(trap, label, hdlr) \
Nicholas Piggina3d96f72016-12-20 04:30:04 +1000725 EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \
726 ret_from_except, ADD_NVGPRS;ADD_RECONCILE)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000727
728/*
729 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
Benjamin Herrenschmidt7450f6f2012-03-01 10:52:01 +1100730 * in the idle task and therefore need the special idle handling
731 * (finish nap and runlatch)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000732 */
Nicholas Piggina3d96f72016-12-20 04:30:04 +1000733#define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \
734 EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \
735 ret_from_except_lite, FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000736
737/*
738 * When the idle code in power4_idle puts the CPU into NAP mode,
739 * it has to do so in a loop, and relies on the external interrupt
740 * and decrementer interrupt entry code to get it out of the loop.
741 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
742 * to signal that it is in the loop and needs help to get out.
743 */
744#ifdef CONFIG_PPC_970_NAP
745#define FINISH_NAP \
746BEGIN_FTR_SECTION \
Stuart Yoder9778b692012-07-05 04:41:35 +0000747 CURRENT_THREAD_INFO(r11, r1); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000748 ld r9,TI_LOCAL_FLAGS(r11); \
749 andi. r10,r9,_TLF_NAPPING; \
750 bnel power4_fixup_nap; \
751END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
752#else
753#define FINISH_NAP
754#endif
755
756#endif /* _ASM_POWERPC_EXCEPTION_H */