powerpc/64s/exception: remove __BRANCH_TO_KVM
[linux-2.6-block.git] / arch / powerpc / kernel / exceptions-64s.S
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
0ebc4cda
BH
2/*
3 * This file contains the 64-bit "server" PowerPC variant
4 * of the low level exception handling including exception
5 * vectors, exception return, part of the slb and stab
6 * handling and other fixed offset specific things.
7 *
8 * This file is meant to be #included from head_64.S due to
25985edc 9 * position dependent assembly.
0ebc4cda
BH
10 *
11 * Most of this originates from head_64.S and thus has the same
12 * copyright history.
13 *
14 */
15
7230c564 16#include <asm/hw_irq.h>
8aa34ab8 17#include <asm/exception-64s.h>
46f52210 18#include <asm/ptrace.h>
7cba160a 19#include <asm/cpuidle.h>
da2bc464 20#include <asm/head-64.h>
2c86cd18 21#include <asm/feature-fixups.h>
890274c2 22#include <asm/kup.h>
8aa34ab8 23
12a04809
NP
24/*
25 * We're short on space and time in the exception prolog, so we can't
26 * use the normal LOAD_REG_IMMEDIATE macro to load the address of label.
27 * Instead we get the base of the kernel from paca->kernelbase and or in the low
28 * part of label. This requires that the label be within 64KB of kernelbase, and
29 * that kernelbase be 64K aligned.
30 */
31#define LOAD_HANDLER(reg, label) \
32 ld reg,PACAKBASE(r13); /* get high part of &label */ \
33 ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label)
34
35#define __LOAD_HANDLER(reg, label) \
36 ld reg,PACAKBASE(r13); \
37 ori reg,reg,(ABS_ADDR(label))@l
38
39/*
40 * Branches from unrelocated code (e.g., interrupts) to labels outside
41 * head-y require >64K offsets.
42 */
43#define __LOAD_FAR_HANDLER(reg, label) \
44 ld reg,PACAKBASE(r13); \
45 ori reg,reg,(ABS_ADDR(label))@l; \
46 addis reg,reg,(ABS_ADDR(label))@h
47
48/* Exception register prefixes */
49#define EXC_HV 1
50#define EXC_STD 0
51
52#if defined(CONFIG_RELOCATABLE)
53/*
54 * If we support interrupts with relocation on AND we're a relocatable kernel,
55 * we need to use CTR to get to the 2nd level handler. So, save/restore it
56 * when required.
57 */
58#define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13)
59#define GET_CTR(reg, area) ld reg,area+EX_CTR(r13)
60#define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg
61#else
62/* ...else CTR is unused and in register. */
63#define SAVE_CTR(reg, area)
64#define GET_CTR(reg, area) mfctr reg
65#define RESTORE_CTR(reg, area)
66#endif
67
68/*
69 * PPR save/restore macros used in exceptions-64s.S
70 * Used for P7 or later processors
71 */
72#define SAVE_PPR(area, ra) \
73BEGIN_FTR_SECTION_NESTED(940) \
74 ld ra,area+EX_PPR(r13); /* Read PPR from paca */ \
75 std ra,_PPR(r1); \
76END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940)
77
78#define RESTORE_PPR_PACA(area, ra) \
79BEGIN_FTR_SECTION_NESTED(941) \
80 ld ra,area+EX_PPR(r13); \
81 mtspr SPRN_PPR,ra; \
82END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941)
83
84/*
85 * Get an SPR into a register if the CPU has the given feature
86 */
87#define OPT_GET_SPR(ra, spr, ftr) \
88BEGIN_FTR_SECTION_NESTED(943) \
89 mfspr ra,spr; \
90END_FTR_SECTION_NESTED(ftr,ftr,943)
91
92/*
93 * Set an SPR from a register if the CPU has the given feature
94 */
95#define OPT_SET_SPR(ra, spr, ftr) \
96BEGIN_FTR_SECTION_NESTED(943) \
97 mtspr spr,ra; \
98END_FTR_SECTION_NESTED(ftr,ftr,943)
99
100/*
101 * Save a register to the PACA if the CPU has the given feature
102 */
103#define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \
104BEGIN_FTR_SECTION_NESTED(943) \
105 std ra,offset(r13); \
106END_FTR_SECTION_NESTED(ftr,ftr,943)
107
108.macro EXCEPTION_PROLOG_0 area
109 GET_PACA(r13)
110 std r9,\area\()+EX_R9(r13) /* save r9 */
111 OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR)
112 HMT_MEDIUM
113 std r10,\area\()+EX_R10(r13) /* save r10 - r12 */
114 OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR)
115.endm
116
117.macro EXCEPTION_PROLOG_1 hsrr, area, kvm, vec, bitmask
118 OPT_SAVE_REG_TO_PACA(\area\()+EX_PPR, r9, CPU_FTR_HAS_PPR)
119 OPT_SAVE_REG_TO_PACA(\area\()+EX_CFAR, r10, CPU_FTR_CFAR)
120 INTERRUPT_TO_KERNEL
121 SAVE_CTR(r10, \area\())
122 mfcr r9
123 .if \kvm
124 KVMTEST \hsrr \vec
125 .endif
126 .if \bitmask
127 lbz r10,PACAIRQSOFTMASK(r13)
128 andi. r10,r10,\bitmask
129 /* Associate vector numbers with bits in paca->irq_happened */
130 .if \vec == 0x500 || \vec == 0xea0
131 li r10,PACA_IRQ_EE
132 .elseif \vec == 0x900
133 li r10,PACA_IRQ_DEC
134 .elseif \vec == 0xa00 || \vec == 0xe80
135 li r10,PACA_IRQ_DBELL
136 .elseif \vec == 0xe60
137 li r10,PACA_IRQ_HMI
138 .elseif \vec == 0xf00
139 li r10,PACA_IRQ_PMI
140 .else
141 .abort "Bad maskable vector"
142 .endif
143
144 .if \hsrr
145 bne masked_Hinterrupt
146 .else
147 bne masked_interrupt
148 .endif
149 .endif
150
151 std r11,\area\()+EX_R11(r13)
152 std r12,\area\()+EX_R12(r13)
153 GET_SCRATCH0(r10)
154 std r10,\area\()+EX_R13(r13)
155.endm
156
157.macro EXCEPTION_PROLOG_2_REAL label, hsrr, set_ri
158 ld r10,PACAKMSR(r13) /* get MSR value for kernel */
159 .if ! \set_ri
160 xori r10,r10,MSR_RI /* Clear MSR_RI */
161 .endif
162 .if \hsrr
163 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
164 .else
165 mfspr r11,SPRN_SRR0 /* save SRR0 */
166 .endif
167 LOAD_HANDLER(r12, \label\())
168 .if \hsrr
169 mtspr SPRN_HSRR0,r12
170 mfspr r12,SPRN_HSRR1 /* and HSRR1 */
171 mtspr SPRN_HSRR1,r10
172 HRFI_TO_KERNEL
173 .else
174 mtspr SPRN_SRR0,r12
175 mfspr r12,SPRN_SRR1 /* and SRR1 */
176 mtspr SPRN_SRR1,r10
177 RFI_TO_KERNEL
178 .endif
179 b . /* prevent speculative execution */
180.endm
181
182.macro EXCEPTION_PROLOG_2_VIRT label, hsrr
183#ifdef CONFIG_RELOCATABLE
184 .if \hsrr
185 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
186 .else
187 mfspr r11,SPRN_SRR0 /* save SRR0 */
188 .endif
189 LOAD_HANDLER(r12, \label\())
190 mtctr r12
191 .if \hsrr
192 mfspr r12,SPRN_HSRR1 /* and HSRR1 */
193 .else
194 mfspr r12,SPRN_SRR1 /* and HSRR1 */
195 .endif
196 li r10,MSR_RI
197 mtmsrd r10,1 /* Set RI (EE=0) */
198 bctr
199#else
200 .if \hsrr
201 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
202 mfspr r12,SPRN_HSRR1 /* and HSRR1 */
203 .else
204 mfspr r11,SPRN_SRR0 /* save SRR0 */
205 mfspr r12,SPRN_SRR1 /* and SRR1 */
206 .endif
207 li r10,MSR_RI
208 mtmsrd r10,1 /* Set RI (EE=0) */
209 b \label
210#endif
211.endm
212
213/*
214 * Branch to label using its 0xC000 address. This results in instruction
215 * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned
216 * on using mtmsr rather than rfid.
217 *
218 * This could set the 0xc bits for !RELOCATABLE as an immediate, rather than
219 * load KBASE for a slight optimisation.
220 */
221#define BRANCH_TO_C000(reg, label) \
222 __LOAD_HANDLER(reg, label); \
223 mtctr reg; \
224 bctr
225
226#ifdef CONFIG_RELOCATABLE
227#define BRANCH_TO_COMMON(reg, label) \
228 __LOAD_HANDLER(reg, label); \
229 mtctr reg; \
230 bctr
231
232#define BRANCH_LINK_TO_FAR(label) \
233 __LOAD_FAR_HANDLER(r12, label); \
234 mtctr r12; \
235 bctrl
236
237#else
238#define BRANCH_TO_COMMON(reg, label) \
239 b label
240
241#define BRANCH_LINK_TO_FAR(label) \
242 bl label
243#endif
244
245#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
12a04809
NP
246#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
247/*
248 * If hv is possible, interrupts come into to the hv version
249 * of the kvmppc_interrupt code, which then jumps to the PR handler,
250 * kvmppc_interrupt_pr, if the guest is a PR guest.
251 */
252#define kvmppc_interrupt kvmppc_interrupt_hv
253#else
254#define kvmppc_interrupt kvmppc_interrupt_pr
255#endif
256
257.macro KVMTEST hsrr, n
258 lbz r10,HSTATE_IN_GUEST(r13)
259 cmpwi r10,0
260 .if \hsrr
261 bne do_kvm_H\n
262 .else
263 bne do_kvm_\n
264 .endif
265.endm
266
267.macro KVM_HANDLER area, hsrr, n, skip
268 .if \skip
269 cmpwi r10,KVM_GUEST_MODE_SKIP
270 beq 89f
271 .else
272 BEGIN_FTR_SECTION_NESTED(947)
273 ld r10,\area+EX_CFAR(r13)
274 std r10,HSTATE_CFAR(r13)
275 END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947)
276 .endif
277
278 BEGIN_FTR_SECTION_NESTED(948)
279 ld r10,\area+EX_PPR(r13)
280 std r10,HSTATE_PPR(r13)
281 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948)
282 ld r10,\area+EX_R10(r13)
283 std r12,HSTATE_SCRATCH0(r13)
284 sldi r12,r9,32
285 /* HSRR variants have the 0x2 bit added to their trap number */
286 .if \hsrr
287 ori r12,r12,(\n + 0x2)
288 .else
289 ori r12,r12,(\n)
290 .endif
64e41351
NP
291
292#ifdef CONFIG_RELOCATABLE
293 /*
294 * KVM requires __LOAD_FAR_HANDLER beause kvmppc_interrupt lives
295 * outside the head section. CONFIG_RELOCATABLE KVM expects CTR
296 * to be saved in HSTATE_SCRATCH1.
297 */
298 mfctr r9
299 std r9,HSTATE_SCRATCH1(r13)
300 __LOAD_FAR_HANDLER(r9, kvmppc_interrupt)
301 mtctr r9
302 ld r9,\area+EX_R9(r13)
303 bctr
304#else
305 ld r9,\area+EX_R9(r13)
306 b kvmppc_interrupt
307#endif
308
12a04809
NP
309
310 .if \skip
31189: mtocrf 0x80,r9
312 ld r9,\area+EX_R9(r13)
313 ld r10,\area+EX_R10(r13)
314 .if \hsrr
315 b kvmppc_skip_Hinterrupt
316 .else
317 b kvmppc_skip_interrupt
318 .endif
319 .endif
320.endm
321
322#else
323.macro KVMTEST hsrr, n
324.endm
325.macro KVM_HANDLER area, hsrr, n, skip
326.endm
327#endif
328
329#define EXCEPTION_PROLOG_COMMON_1() \
330 std r9,_CCR(r1); /* save CR in stackframe */ \
331 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
332 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
333 std r10,0(r1); /* make stack chain pointer */ \
334 std r0,GPR0(r1); /* save r0 in stackframe */ \
335 std r10,GPR1(r1); /* save r1 in stackframe */ \
336
337
338/*
339 * The common exception prolog is used for all except a few exceptions
340 * such as a segment miss on a kernel address. We have to be prepared
341 * to take another exception from the point where we first touch the
342 * kernel stack onwards.
343 *
344 * On entry r13 points to the paca, r9-r13 are saved in the paca,
345 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
346 * SRR1, and relocation is on.
347 */
348#define EXCEPTION_PROLOG_COMMON(n, area) \
349 andi. r10,r12,MSR_PR; /* See if coming from user */ \
350 mr r10,r1; /* Save r1 */ \
351 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
352 beq- 1f; \
353 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
3541: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \
355 blt+ cr1,3f; /* abort if it is */ \
356 li r1,(n); /* will be reloaded later */ \
357 sth r1,PACA_TRAP_SAVE(r13); \
358 std r3,area+EX_R3(r13); \
359 addi r3,r13,area; /* r3 -> where regs are saved*/ \
360 RESTORE_CTR(r1, area); \
361 b bad_stack; \
3623: EXCEPTION_PROLOG_COMMON_1(); \
363 kuap_save_amr_and_lock r9, r10, cr1, cr0; \
364 beq 4f; /* if from kernel mode */ \
365 ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \
366 SAVE_PPR(area, r9); \
3674: EXCEPTION_PROLOG_COMMON_2(area) \
368 EXCEPTION_PROLOG_COMMON_3(n) \
369 ACCOUNT_STOLEN_TIME
370
371/* Save original regs values from save area to stack frame. */
372#define EXCEPTION_PROLOG_COMMON_2(area) \
373 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
374 ld r10,area+EX_R10(r13); \
375 std r9,GPR9(r1); \
376 std r10,GPR10(r1); \
377 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
378 ld r10,area+EX_R12(r13); \
379 ld r11,area+EX_R13(r13); \
380 std r9,GPR11(r1); \
381 std r10,GPR12(r1); \
382 std r11,GPR13(r1); \
383 BEGIN_FTR_SECTION_NESTED(66); \
384 ld r10,area+EX_CFAR(r13); \
385 std r10,ORIG_GPR3(r1); \
386 END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \
387 GET_CTR(r10, area); \
388 std r10,_CTR(r1);
389
390#define EXCEPTION_PROLOG_COMMON_3(n) \
391 std r2,GPR2(r1); /* save r2 in stackframe */ \
392 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
393 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
394 mflr r9; /* Get LR, later save to stack */ \
395 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
396 std r9,_LINK(r1); \
397 lbz r10,PACAIRQSOFTMASK(r13); \
398 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
399 std r10,SOFTE(r1); \
400 std r11,_XER(r1); \
401 li r9,(n)+1; \
402 std r9,_TRAP(r1); /* set trap number */ \
403 li r10,0; \
404 ld r11,exception_marker@toc(r2); \
405 std r10,RESULT(r1); /* clear regs->result */ \
406 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
407
408#define RUNLATCH_ON \
409BEGIN_FTR_SECTION \
410 ld r3, PACA_THREAD_INFO(r13); \
411 ld r4,TI_LOCAL_FLAGS(r3); \
412 andi. r0,r4,_TLF_RUNLATCH; \
413 beql ppc64_runlatch_on_trampoline; \
414END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
415
416#define EXCEPTION_COMMON(area, trap) \
417 EXCEPTION_PROLOG_COMMON(trap, area); \
418
419/*
420 * Exception where stack is already set in r1, r1 is saved in r10
421 */
422#define EXCEPTION_COMMON_STACK(area, trap) \
423 EXCEPTION_PROLOG_COMMON_1(); \
424 kuap_save_amr_and_lock r9, r10, cr1; \
425 EXCEPTION_PROLOG_COMMON_2(area); \
426 EXCEPTION_PROLOG_COMMON_3(trap)
427
428/*
429 * When the idle code in power4_idle puts the CPU into NAP mode,
430 * it has to do so in a loop, and relies on the external interrupt
431 * and decrementer interrupt entry code to get it out of the loop.
432 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
433 * to signal that it is in the loop and needs help to get out.
434 */
435#ifdef CONFIG_PPC_970_NAP
436#define FINISH_NAP \
437BEGIN_FTR_SECTION \
438 ld r11, PACA_THREAD_INFO(r13); \
439 ld r9,TI_LOCAL_FLAGS(r11); \
440 andi. r10,r9,_TLF_NAPPING; \
441 bnel power4_fixup_nap; \
442END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
443#else
444#define FINISH_NAP
445#endif
446
a0502434
NP
447/*
448 * Following are the BOOK3S exception handler helper macros.
449 * Handlers come in a number of types, and each type has a number of varieties.
450 *
451 * EXC_REAL_* - real, unrelocated exception vectors
452 * EXC_VIRT_* - virt (AIL), unrelocated exception vectors
453 * TRAMP_REAL_* - real, unrelocated helpers (virt can call these)
454 * TRAMP_VIRT_* - virt, unreloc helpers (in practice, real can use)
455 * TRAMP_KVM - KVM handlers that get put into real, unrelocated
456 * EXC_COMMON - virt, relocated common handlers
457 *
458 * The EXC handlers are given a name, and branch to name_common, or the
459 * appropriate KVM or masking function. Vector handler verieties are as
460 * follows:
461 *
462 * EXC_{REAL|VIRT}_BEGIN/END - used to open-code the exception
463 *
464 * EXC_{REAL|VIRT} - standard exception
465 *
466 * EXC_{REAL|VIRT}_suffix
467 * where _suffix is:
468 * - _MASKABLE - maskable exception
469 * - _OOL - out of line with trampoline to common handler
470 * - _HV - HV exception
471 *
472 * There can be combinations, e.g., EXC_VIRT_OOL_MASKABLE_HV
473 *
474 * The one unusual case is __EXC_REAL_OOL_HV_DIRECT, which is
475 * an OOL vector that branches to a specified handler rather than the usual
476 * trampoline that goes to common. It, and other underscore macros, should
477 * be used with care.
478 *
479 * KVM handlers come in the following verieties:
480 * TRAMP_KVM
481 * TRAMP_KVM_SKIP
482 * TRAMP_KVM_HV
483 * TRAMP_KVM_HV_SKIP
484 *
485 * COMMON handlers come in the following verieties:
486 * EXC_COMMON_BEGIN/END - used to open-code the handler
487 * EXC_COMMON
488 * EXC_COMMON_ASYNC
489 *
490 * TRAMP_REAL and TRAMP_VIRT can be used with BEGIN/END. KVM
491 * and OOL handlers are implemented as types of TRAMP and TRAMP_VIRT handlers.
492 */
493
494#define __EXC_REAL(name, start, size, area) \
495 EXC_REAL_BEGIN(name, start, size); \
496 SET_SCRATCH0(r13); /* save r13 */ \
497 EXCEPTION_PROLOG_0 area ; \
498 EXCEPTION_PROLOG_1 EXC_STD, area, 1, start, 0 ; \
499 EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1 ; \
500 EXC_REAL_END(name, start, size)
501
502#define EXC_REAL(name, start, size) \
503 __EXC_REAL(name, start, size, PACA_EXGEN)
504
505#define __EXC_VIRT(name, start, size, realvec, area) \
506 EXC_VIRT_BEGIN(name, start, size); \
507 SET_SCRATCH0(r13); /* save r13 */ \
508 EXCEPTION_PROLOG_0 area ; \
509 EXCEPTION_PROLOG_1 EXC_STD, area, 0, realvec, 0; \
510 EXCEPTION_PROLOG_2_VIRT name##_common, EXC_STD ; \
511 EXC_VIRT_END(name, start, size)
512
513#define EXC_VIRT(name, start, size, realvec) \
514 __EXC_VIRT(name, start, size, realvec, PACA_EXGEN)
515
516#define EXC_REAL_MASKABLE(name, start, size, bitmask) \
517 EXC_REAL_BEGIN(name, start, size); \
518 SET_SCRATCH0(r13); /* save r13 */ \
519 EXCEPTION_PROLOG_0 PACA_EXGEN ; \
520 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, start, bitmask ; \
521 EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1 ; \
522 EXC_REAL_END(name, start, size)
523
524#define EXC_VIRT_MASKABLE(name, start, size, realvec, bitmask) \
525 EXC_VIRT_BEGIN(name, start, size); \
526 SET_SCRATCH0(r13); /* save r13 */ \
527 EXCEPTION_PROLOG_0 PACA_EXGEN ; \
528 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, realvec, bitmask ; \
529 EXCEPTION_PROLOG_2_VIRT name##_common, EXC_STD ; \
530 EXC_VIRT_END(name, start, size)
531
532#define EXC_REAL_HV(name, start, size) \
533 EXC_REAL_BEGIN(name, start, size); \
534 SET_SCRATCH0(r13); /* save r13 */ \
535 EXCEPTION_PROLOG_0 PACA_EXGEN; \
536 EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, start, 0 ; \
537 EXCEPTION_PROLOG_2_REAL name##_common, EXC_HV, 1 ; \
538 EXC_REAL_END(name, start, size)
539
540#define EXC_VIRT_HV(name, start, size, realvec) \
541 EXC_VIRT_BEGIN(name, start, size); \
542 SET_SCRATCH0(r13); /* save r13 */ \
543 EXCEPTION_PROLOG_0 PACA_EXGEN; \
544 EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, realvec, 0 ; \
545 EXCEPTION_PROLOG_2_VIRT name##_common, EXC_HV ; \
546 EXC_VIRT_END(name, start, size)
547
548#define __EXC_REAL_OOL(name, start, size) \
549 EXC_REAL_BEGIN(name, start, size); \
550 SET_SCRATCH0(r13); \
551 EXCEPTION_PROLOG_0 PACA_EXGEN ; \
552 b tramp_real_##name ; \
553 EXC_REAL_END(name, start, size)
554
555#define __TRAMP_REAL_OOL(name, vec) \
556 TRAMP_REAL_BEGIN(tramp_real_##name); \
557 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, vec, 0 ; \
558 EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1
559
560#define EXC_REAL_OOL(name, start, size) \
561 __EXC_REAL_OOL(name, start, size); \
562 __TRAMP_REAL_OOL(name, start)
563
564#define __EXC_REAL_OOL_MASKABLE(name, start, size) \
565 __EXC_REAL_OOL(name, start, size)
566
567#define __TRAMP_REAL_OOL_MASKABLE(name, vec, bitmask) \
568 TRAMP_REAL_BEGIN(tramp_real_##name); \
569 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, vec, bitmask ; \
570 EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1
571
572#define EXC_REAL_OOL_MASKABLE(name, start, size, bitmask) \
573 __EXC_REAL_OOL_MASKABLE(name, start, size); \
574 __TRAMP_REAL_OOL_MASKABLE(name, start, bitmask)
575
576#define __EXC_REAL_OOL_HV_DIRECT(name, start, size, handler) \
577 EXC_REAL_BEGIN(name, start, size); \
578 SET_SCRATCH0(r13); \
579 EXCEPTION_PROLOG_0 PACA_EXGEN ; \
580 b handler; \
581 EXC_REAL_END(name, start, size)
582
583#define __EXC_REAL_OOL_HV(name, start, size) \
584 __EXC_REAL_OOL(name, start, size)
585
586#define __TRAMP_REAL_OOL_HV(name, vec) \
587 TRAMP_REAL_BEGIN(tramp_real_##name); \
588 EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, vec, 0 ; \
589 EXCEPTION_PROLOG_2_REAL name##_common, EXC_HV, 1
590
591#define EXC_REAL_OOL_HV(name, start, size) \
592 __EXC_REAL_OOL_HV(name, start, size); \
593 __TRAMP_REAL_OOL_HV(name, start)
594
595#define __EXC_REAL_OOL_MASKABLE_HV(name, start, size) \
596 __EXC_REAL_OOL(name, start, size)
597
598#define __TRAMP_REAL_OOL_MASKABLE_HV(name, vec, bitmask) \
599 TRAMP_REAL_BEGIN(tramp_real_##name); \
600 EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, vec, bitmask ; \
601 EXCEPTION_PROLOG_2_REAL name##_common, EXC_HV, 1
602
603#define EXC_REAL_OOL_MASKABLE_HV(name, start, size, bitmask) \
604 __EXC_REAL_OOL_MASKABLE_HV(name, start, size); \
605 __TRAMP_REAL_OOL_MASKABLE_HV(name, start, bitmask)
606
607#define __EXC_VIRT_OOL(name, start, size) \
608 EXC_VIRT_BEGIN(name, start, size); \
609 SET_SCRATCH0(r13); \
610 EXCEPTION_PROLOG_0 PACA_EXGEN ; \
611 b tramp_virt_##name; \
612 EXC_VIRT_END(name, start, size)
613
614#define __TRAMP_VIRT_OOL(name, realvec) \
615 TRAMP_VIRT_BEGIN(tramp_virt_##name); \
616 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, vec, 0 ; \
617 EXCEPTION_PROLOG_2_VIRT name##_common, EXC_STD
618
619#define EXC_VIRT_OOL(name, start, size, realvec) \
620 __EXC_VIRT_OOL(name, start, size); \
621 __TRAMP_VIRT_OOL(name, realvec)
622
623#define __EXC_VIRT_OOL_MASKABLE(name, start, size) \
624 __EXC_VIRT_OOL(name, start, size)
625
626#define __TRAMP_VIRT_OOL_MASKABLE(name, realvec, bitmask) \
627 TRAMP_VIRT_BEGIN(tramp_virt_##name); \
628 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, realvec, bitmask ; \
629 EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1
630
631#define EXC_VIRT_OOL_MASKABLE(name, start, size, realvec, bitmask) \
632 __EXC_VIRT_OOL_MASKABLE(name, start, size); \
633 __TRAMP_VIRT_OOL_MASKABLE(name, realvec, bitmask)
634
635#define __EXC_VIRT_OOL_HV(name, start, size) \
636 __EXC_VIRT_OOL(name, start, size)
637
638#define __TRAMP_VIRT_OOL_HV(name, realvec) \
639 TRAMP_VIRT_BEGIN(tramp_virt_##name); \
640 EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, realvec, 0 ; \
641 EXCEPTION_PROLOG_2_VIRT name##_common, EXC_HV
642
643#define EXC_VIRT_OOL_HV(name, start, size, realvec) \
644 __EXC_VIRT_OOL_HV(name, start, size); \
645 __TRAMP_VIRT_OOL_HV(name, realvec)
646
647#define __EXC_VIRT_OOL_MASKABLE_HV(name, start, size) \
648 __EXC_VIRT_OOL(name, start, size)
649
650#define __TRAMP_VIRT_OOL_MASKABLE_HV(name, realvec, bitmask) \
651 TRAMP_VIRT_BEGIN(tramp_virt_##name); \
652 EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, realvec, bitmask ; \
653 EXCEPTION_PROLOG_2_VIRT name##_common, EXC_HV
654
655#define EXC_VIRT_OOL_MASKABLE_HV(name, start, size, realvec, bitmask) \
656 __EXC_VIRT_OOL_MASKABLE_HV(name, start, size); \
657 __TRAMP_VIRT_OOL_MASKABLE_HV(name, realvec, bitmask)
658
659#define TRAMP_KVM(area, n) \
660 TRAMP_KVM_BEGIN(do_kvm_##n); \
661 KVM_HANDLER area, EXC_STD, n, 0
662
663#define TRAMP_KVM_SKIP(area, n) \
664 TRAMP_KVM_BEGIN(do_kvm_##n); \
665 KVM_HANDLER area, EXC_STD, n, 1
666
667#define TRAMP_KVM_HV(area, n) \
668 TRAMP_KVM_BEGIN(do_kvm_H##n); \
669 KVM_HANDLER area, EXC_HV, n, 0
670
671#define TRAMP_KVM_HV_SKIP(area, n) \
672 TRAMP_KVM_BEGIN(do_kvm_H##n); \
673 KVM_HANDLER area, EXC_HV, n, 1
674
675#define EXC_COMMON(name, realvec, hdlr) \
676 EXC_COMMON_BEGIN(name); \
677 EXCEPTION_COMMON(PACA_EXGEN, realvec); \
678 bl save_nvgprs; \
679 RECONCILE_IRQ_STATE(r10, r11); \
680 addi r3,r1,STACK_FRAME_OVERHEAD; \
681 bl hdlr; \
682 b ret_from_except
683
684/*
685 * Like EXC_COMMON, but for exceptions that can occur in the idle task and
686 * therefore need the special idle handling (finish nap and runlatch)
687 */
688#define EXC_COMMON_ASYNC(name, realvec, hdlr) \
689 EXC_COMMON_BEGIN(name); \
690 EXCEPTION_COMMON(PACA_EXGEN, realvec); \
691 FINISH_NAP; \
692 RECONCILE_IRQ_STATE(r10, r11); \
693 RUNLATCH_ON; \
694 addi r3,r1,STACK_FRAME_OVERHEAD; \
695 bl hdlr; \
696 b ret_from_except_lite
697
12a04809 698
0ebc4cda 699/*
57f26649
NP
700 * There are a few constraints to be concerned with.
701 * - Real mode exceptions code/data must be located at their physical location.
702 * - Virtual mode exceptions must be mapped at their 0xc000... location.
703 * - Fixed location code must not call directly beyond the __end_interrupts
704 * area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence
705 * must be used.
706 * - LOAD_HANDLER targets must be within first 64K of physical 0 /
707 * virtual 0xc00...
708 * - Conditional branch targets must be within +/-32K of caller.
709 *
710 * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and
711 * therefore don't have to run in physically located code or rfid to
712 * virtual mode kernel code. However on relocatable kernels they do have
713 * to branch to KERNELBASE offset because the rest of the kernel (outside
714 * the exception vectors) may be located elsewhere.
715 *
716 * Virtual exceptions correspond with physical, except their entry points
717 * are offset by 0xc000000000000000 and also tend to get an added 0x4000
718 * offset applied. Virtual exceptions are enabled with the Alternate
719 * Interrupt Location (AIL) bit set in the LPCR. However this does not
720 * guarantee they will be delivered virtually. Some conditions (see the ISA)
721 * cause exceptions to be delivered in real mode.
722 *
723 * It's impossible to receive interrupts below 0x300 via AIL.
724 *
725 * KVM: None of the virtual exceptions are from the guest. Anything that
726 * escalated to HV=1 from HV=0 is delivered via real mode handlers.
727 *
728 *
0ebc4cda
BH
729 * We layout physical memory as follows:
730 * 0x0000 - 0x00ff : Secondary processor spin code
57f26649
NP
731 * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors
732 * 0x1900 - 0x3fff : Real mode trampolines
733 * 0x4000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors
734 * 0x5900 - 0x6fff : Relon mode trampolines
0ebc4cda 735 * 0x7000 - 0x7fff : FWNMI data area
57f26649
NP
736 * 0x8000 - .... : Common interrupt handlers, remaining early
737 * setup code, rest of kernel.
e0319829
NP
738 *
739 * We could reclaim 0x4000-0x42ff for real mode trampolines if the space
740 * is necessary. Until then it's more consistent to explicitly put VIRT_NONE
741 * vectors there.
57f26649
NP
742 */
743OPEN_FIXED_SECTION(real_vectors, 0x0100, 0x1900)
744OPEN_FIXED_SECTION(real_trampolines, 0x1900, 0x4000)
745OPEN_FIXED_SECTION(virt_vectors, 0x4000, 0x5900)
746OPEN_FIXED_SECTION(virt_trampolines, 0x5900, 0x7000)
ccd47702
NP
747
748#ifdef CONFIG_PPC_POWERNV
bd3524fe
NP
749 .globl start_real_trampolines
750 .globl end_real_trampolines
751 .globl start_virt_trampolines
752 .globl end_virt_trampolines
ccd47702
NP
753#endif
754
57f26649
NP
755#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
756/*
757 * Data area reserved for FWNMI option.
758 * This address (0x7000) is fixed by the RPA.
759 * pseries and powernv need to keep the whole page from
760 * 0x7000 to 0x8000 free for use by the firmware
0ebc4cda 761 */
57f26649
NP
762ZERO_FIXED_SECTION(fwnmi_page, 0x7000, 0x8000)
763OPEN_TEXT_SECTION(0x8000)
764#else
765OPEN_TEXT_SECTION(0x7000)
766#endif
767
768USE_FIXED_SECTION(real_vectors)
769
0ebc4cda
BH
770/*
771 * This is the start of the interrupt handlers for pSeries
772 * This code runs with relocation off.
773 * Code from here to __end_interrupts gets copied down to real
774 * address 0x100 when we are running a relocatable kernel.
775 * Therefore any relative branches in this section must only
776 * branch to labels in this section.
777 */
0ebc4cda
BH
778 .globl __start_interrupts
779__start_interrupts:
780
e0319829 781/* No virt vectors corresponding with 0x0..0x100 */
1a6822d1 782EXC_VIRT_NONE(0x4000, 0x100)
e0319829 783
fb479e44 784
a7c1ca19
NP
785EXC_REAL_BEGIN(system_reset, 0x100, 0x100)
786 SET_SCRATCH0(r13)
5dba1d50 787 EXCEPTION_PROLOG_0 PACA_EXNMI
a7c1ca19
NP
788
789 /* This is EXCEPTION_PROLOG_1 with the idle feature section added */
790 OPT_SAVE_REG_TO_PACA(PACA_EXNMI+EX_PPR, r9, CPU_FTR_HAS_PPR)
791 OPT_SAVE_REG_TO_PACA(PACA_EXNMI+EX_CFAR, r10, CPU_FTR_CFAR)
792 INTERRUPT_TO_KERNEL
793 SAVE_CTR(r10, PACA_EXNMI)
794 mfcr r9
795
948cf67c 796#ifdef CONFIG_PPC_P7_NAP
fb479e44
NP
797 /*
798 * If running native on arch 2.06 or later, check if we are waking up
ba6d334a
BH
799 * from nap/sleep/winkle, and branch to idle handler. This tests SRR1
800 * bits 46:47. A non-0 value indicates that we are coming from a power
801 * saving state. The idle wakeup handler initially runs in real mode,
802 * but we branch to the 0xc000... address so we can turn on relocation
803 * with mtmsr.
948cf67c 804 */
a7c1ca19
NP
805 BEGIN_FTR_SECTION
806 mfspr r10,SPRN_SRR1
807 rlwinm. r10,r10,47-31,30,31
808 beq- 1f
809 cmpwi cr1,r10,2
810 mfspr r3,SPRN_SRR1
811 bltlr cr1 /* no state loss, return to idle caller */
812 BRANCH_TO_C000(r10, system_reset_idle_common)
8131:
814 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
fb479e44 815#endif
371fefd6 816
a7c1ca19
NP
817 KVMTEST EXC_STD 0x100
818 std r11,PACA_EXNMI+EX_R11(r13)
819 std r12,PACA_EXNMI+EX_R12(r13)
820 GET_SCRATCH0(r10)
821 std r10,PACA_EXNMI+EX_R13(r13)
822
823 EXCEPTION_PROLOG_2_REAL system_reset_common, EXC_STD, 0
c4f3b52c
NP
824 /*
825 * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is
826 * being used, so a nested NMI exception would corrupt it.
827 */
fb479e44 828
1a6822d1
NP
829EXC_REAL_END(system_reset, 0x100, 0x100)
830EXC_VIRT_NONE(0x4100, 0x100)
6de6638b 831TRAMP_KVM(PACA_EXNMI, 0x100)
fb479e44
NP
832
833#ifdef CONFIG_PPC_P7_NAP
834EXC_COMMON_BEGIN(system_reset_idle_common)
10d91611
NP
835 /*
836 * This must be a direct branch (without linker branch stub) because
837 * we can not use TOC at this point as r2 may not be restored yet.
838 */
839 b idle_return_gpr_loss
371fefd6
PM
840#endif
841
a3d96f70 842EXC_COMMON_BEGIN(system_reset_common)
c4f3b52c
NP
843 /*
844 * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able
845 * to recover, but nested NMI will notice in_nmi and not recover
846 * because of the use of the NMI stack. in_nmi reentrancy is tested in
847 * system_reset_exception.
848 */
849 lhz r10,PACA_IN_NMI(r13)
850 addi r10,r10,1
851 sth r10,PACA_IN_NMI(r13)
852 li r10,MSR_RI
853 mtmsrd r10,1
aca79d2b 854
b1ee8a3d
NP
855 mr r10,r1
856 ld r1,PACA_NMI_EMERG_SP(r13)
857 subi r1,r1,INT_FRAME_SIZE
47169fba
NP
858 EXCEPTION_COMMON_STACK(PACA_EXNMI, 0x100)
859 bl save_nvgprs
860 /*
861 * Set IRQS_ALL_DISABLED unconditionally so arch_irqs_disabled does
862 * the right thing. We do not want to reconcile because that goes
863 * through irq tracing which we don't want in NMI.
864 *
865 * Save PACAIRQHAPPENED because some code will do a hard disable
866 * (e.g., xmon). So we want to restore this back to where it was
867 * when we return. DAR is unused in the stack, so save it there.
868 */
869 li r10,IRQS_ALL_DISABLED
870 stb r10,PACAIRQSOFTMASK(r13)
871 lbz r10,PACAIRQHAPPENED(r13)
872 std r10,_DAR(r1)
873
c06075f3
NP
874 addi r3,r1,STACK_FRAME_OVERHEAD
875 bl system_reset_exception
15b4dd79
NP
876
877 /* This (and MCE) can be simplified with mtmsrd L=1 */
878 /* Clear MSR_RI before setting SRR0 and SRR1. */
879 li r0,MSR_RI
880 mfmsr r9
881 andc r9,r9,r0
882 mtmsrd r9,1
c4f3b52c
NP
883
884 /*
15b4dd79 885 * MSR_RI is clear, now we can decrement paca->in_nmi.
c4f3b52c
NP
886 */
887 lhz r10,PACA_IN_NMI(r13)
888 subi r10,r10,1
889 sth r10,PACA_IN_NMI(r13)
890
15b4dd79
NP
891 /*
892 * Restore soft mask settings.
893 */
894 ld r10,_DAR(r1)
895 stb r10,PACAIRQHAPPENED(r13)
896 ld r10,SOFTE(r1)
897 stb r10,PACAIRQSOFTMASK(r13)
898
899 /*
900 * Keep below code in synch with MACHINE_CHECK_HANDLER_WINDUP.
901 * Should share common bits...
902 */
903
904 /* Move original SRR0 and SRR1 into the respective regs */
905 ld r9,_MSR(r1)
906 mtspr SPRN_SRR1,r9
907 ld r3,_NIP(r1)
908 mtspr SPRN_SRR0,r3
909 ld r9,_CTR(r1)
910 mtctr r9
911 ld r9,_XER(r1)
912 mtxer r9
913 ld r9,_LINK(r1)
914 mtlr r9
915 REST_GPR(0, r1)
916 REST_8GPRS(2, r1)
917 REST_GPR(10, r1)
918 ld r11,_CCR(r1)
919 mtcr r11
920 REST_GPR(11, r1)
921 REST_2GPRS(12, r1)
922 /* restore original r1. */
923 ld r1,GPR1(r1)
924 RFI_TO_USER_OR_KERNEL
582baf44
NP
925
926#ifdef CONFIG_PPC_PSERIES
927/*
928 * Vectors for the FWNMI option. Share common code.
929 */
930TRAMP_REAL_BEGIN(system_reset_fwnmi)
931 SET_SCRATCH0(r13) /* save r13 */
fc557537
NP
932 /* See comment at system_reset exception, don't turn on RI */
933 EXCEPTION_PROLOG_0 PACA_EXNMI
934 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXNMI, 0, 0x100, 0
935 EXCEPTION_PROLOG_2_REAL system_reset_common, EXC_STD, 0
936
582baf44
NP
937#endif /* CONFIG_PPC_PSERIES */
938
0ebc4cda 939
1a6822d1 940EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
b01c8b54
PM
941 /* This is moved out of line as it can be patched by FW, but
942 * some code path might still want to branch into the original
943 * vector
944 */
1707dd16 945 SET_SCRATCH0(r13) /* save r13 */
5dba1d50 946 EXCEPTION_PROLOG_0 PACA_EXMC
1e9b4507 947BEGIN_FTR_SECTION
db7d31ac 948 b machine_check_common_early
1e9b4507 949FTR_SECTION_ELSE
1707dd16 950 b machine_check_pSeries_0
1e9b4507 951ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
1a6822d1
NP
952EXC_REAL_END(machine_check, 0x200, 0x100)
953EXC_VIRT_NONE(0x4200, 0x100)
db7d31ac 954TRAMP_REAL_BEGIN(machine_check_common_early)
fa4cf6b7 955 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 0, 0x200, 0
afcf0095
NP
956 /*
957 * Register contents:
958 * R13 = PACA
959 * R9 = CR
960 * Original R9 to R13 is saved on PACA_EXMC
961 *
962 * Switch to mc_emergency stack and handle re-entrancy (we limit
963 * the nested MCE upto level 4 to avoid stack overflow).
964 * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
965 *
966 * We use paca->in_mce to check whether this is the first entry or
967 * nested machine check. We increment paca->in_mce to track nested
968 * machine checks.
969 *
970 * If this is the first entry then set stack pointer to
971 * paca->mc_emergency_sp, otherwise r1 is already pointing to
972 * stack frame on mc_emergency stack.
973 *
974 * NOTE: We are here with MSR_ME=0 (off), which means we risk a
975 * checkstop if we get another machine check exception before we do
976 * rfid with MSR_ME=1.
1945bc45
NP
977 *
978 * This interrupt can wake directly from idle. If that is the case,
979 * the machine check is handled then the idle wakeup code is called
2bf1071a 980 * to restore state.
afcf0095
NP
981 */
982 mr r11,r1 /* Save r1 */
983 lhz r10,PACA_IN_MCE(r13)
984 cmpwi r10,0 /* Are we in nested machine check */
985 bne 0f /* Yes, we are. */
986 /* First machine check entry */
987 ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
9880: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
989 addi r10,r10,1 /* increment paca->in_mce */
990 sth r10,PACA_IN_MCE(r13)
991 /* Limit nested MCE to level 4 to avoid stack overflow */
ba41e1e1 992 cmpwi r10,MAX_MCE_DEPTH
afcf0095
NP
993 bgt 2f /* Check if we hit limit of 4 */
994 std r11,GPR1(r1) /* Save r1 on the stack. */
995 std r11,0(r1) /* make stack chain pointer */
996 mfspr r11,SPRN_SRR0 /* Save SRR0 */
997 std r11,_NIP(r1)
998 mfspr r11,SPRN_SRR1 /* Save SRR1 */
999 std r11,_MSR(r1)
1000 mfspr r11,SPRN_DAR /* Save DAR */
1001 std r11,_DAR(r1)
1002 mfspr r11,SPRN_DSISR /* Save DSISR */
1003 std r11,_DSISR(r1)
1004 std r9,_CCR(r1) /* Save CR in stackframe */
e13e7cd4 1005 /* We don't touch AMR here, we never go to virtual mode */
afcf0095
NP
1006 /* Save r9 through r13 from EXMC save area to stack frame. */
1007 EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
1008 mfmsr r11 /* get MSR value */
db7d31ac 1009BEGIN_FTR_SECTION
afcf0095 1010 ori r11,r11,MSR_ME /* turn on ME bit */
db7d31ac 1011END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
afcf0095
NP
1012 ori r11,r11,MSR_RI /* turn on RI bit */
1013 LOAD_HANDLER(r12, machine_check_handle_early)
10141: mtspr SPRN_SRR0,r12
1015 mtspr SPRN_SRR1,r11
222f20f1 1016 RFI_TO_KERNEL
afcf0095
NP
1017 b . /* prevent speculative execution */
10182:
1019 /* Stack overflow. Stay on emergency stack and panic.
1020 * Keep the ME bit off while panic-ing, so that if we hit
1021 * another machine check we checkstop.
1022 */
1023 addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
1024 ld r11,PACAKMSR(r13)
1025 LOAD_HANDLER(r12, unrecover_mce)
1026 li r10,MSR_ME
1027 andc r11,r11,r10 /* Turn off MSR_ME */
1028 b 1b
1029 b . /* prevent speculative execution */
afcf0095
NP
1030
1031TRAMP_REAL_BEGIN(machine_check_pSeries)
1032 .globl machine_check_fwnmi
1033machine_check_fwnmi:
1034 SET_SCRATCH0(r13) /* save r13 */
5dba1d50 1035 EXCEPTION_PROLOG_0 PACA_EXMC
a43c1590 1036BEGIN_FTR_SECTION
db7d31ac 1037 b machine_check_common_early
a43c1590 1038END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
afcf0095 1039machine_check_pSeries_0:
fa4cf6b7 1040 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 1, 0x200, 0
afcf0095 1041 /*
83a980f7
NP
1042 * MSR_RI is not enabled, because PACA_EXMC is being used, so a
1043 * nested machine check corrupts it. machine_check_common enables
1044 * MSR_RI.
afcf0095 1045 */
2d046308 1046 EXCEPTION_PROLOG_2_REAL machine_check_common, EXC_STD, 0
afcf0095
NP
1047
1048TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
1049
1050EXC_COMMON_BEGIN(machine_check_common)
1051 /*
1052 * Machine check is different because we use a different
1053 * save area: PACA_EXMC instead of PACA_EXGEN.
1054 */
1055 mfspr r10,SPRN_DAR
1056 std r10,PACA_EXMC+EX_DAR(r13)
1057 mfspr r10,SPRN_DSISR
1058 stw r10,PACA_EXMC+EX_DSISR(r13)
1059 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
1060 FINISH_NAP
1061 RECONCILE_IRQ_STATE(r10, r11)
1062 ld r3,PACA_EXMC+EX_DAR(r13)
1063 lwz r4,PACA_EXMC+EX_DSISR(r13)
1064 /* Enable MSR_RI when finished with PACA_EXMC */
1065 li r10,MSR_RI
1066 mtmsrd r10,1
1067 std r3,_DAR(r1)
1068 std r4,_DSISR(r1)
1069 bl save_nvgprs
1070 addi r3,r1,STACK_FRAME_OVERHEAD
1071 bl machine_check_exception
1072 b ret_from_except
1073
1074#define MACHINE_CHECK_HANDLER_WINDUP \
1075 /* Clear MSR_RI before setting SRR0 and SRR1. */\
1076 li r0,MSR_RI; \
1077 mfmsr r9; /* get MSR value */ \
1078 andc r9,r9,r0; \
1079 mtmsrd r9,1; /* Clear MSR_RI */ \
1080 /* Move original SRR0 and SRR1 into the respective regs */ \
1081 ld r9,_MSR(r1); \
1082 mtspr SPRN_SRR1,r9; \
1083 ld r3,_NIP(r1); \
1084 mtspr SPRN_SRR0,r3; \
1085 ld r9,_CTR(r1); \
1086 mtctr r9; \
1087 ld r9,_XER(r1); \
1088 mtxer r9; \
1089 ld r9,_LINK(r1); \
1090 mtlr r9; \
1091 REST_GPR(0, r1); \
1092 REST_8GPRS(2, r1); \
1093 REST_GPR(10, r1); \
1094 ld r11,_CCR(r1); \
1095 mtcr r11; \
1096 /* Decrement paca->in_mce. */ \
1097 lhz r12,PACA_IN_MCE(r13); \
1098 subi r12,r12,1; \
1099 sth r12,PACA_IN_MCE(r13); \
1100 REST_GPR(11, r1); \
1101 REST_2GPRS(12, r1); \
1102 /* restore original r1. */ \
1103 ld r1,GPR1(r1)
1104
1945bc45
NP
1105#ifdef CONFIG_PPC_P7_NAP
1106/*
1107 * This is an idle wakeup. Low level machine check has already been
1108 * done. Queue the event then call the idle code to do the wake up.
1109 */
1110EXC_COMMON_BEGIN(machine_check_idle_common)
1111 bl machine_check_queue_event
1112
1113 /*
1114 * We have not used any non-volatile GPRs here, and as a rule
1115 * most exception code including machine check does not.
1116 * Therefore PACA_NAPSTATELOST does not need to be set. Idle
1117 * wakeup will restore volatile registers.
1118 *
1119 * Load the original SRR1 into r3 for pnv_powersave_wakeup_mce.
1120 *
1121 * Then decrement MCE nesting after finishing with the stack.
1122 */
1123 ld r3,_MSR(r1)
10d91611 1124 ld r4,_LINK(r1)
1945bc45
NP
1125
1126 lhz r11,PACA_IN_MCE(r13)
1127 subi r11,r11,1
1128 sth r11,PACA_IN_MCE(r13)
1129
10d91611
NP
1130 mtlr r4
1131 rlwinm r10,r3,47-31,30,31
1132 cmpwi cr1,r10,2
1133 bltlr cr1 /* no state loss, return to idle caller */
1134 b idle_return_gpr_loss
1945bc45 1135#endif
afcf0095
NP
1136 /*
1137 * Handle machine check early in real mode. We come here with
1138 * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
1139 */
1140EXC_COMMON_BEGIN(machine_check_handle_early)
1141 std r0,GPR0(r1) /* Save r0 */
1142 EXCEPTION_PROLOG_COMMON_3(0x200)
1143 bl save_nvgprs
1144 addi r3,r1,STACK_FRAME_OVERHEAD
1145 bl machine_check_early
1146 std r3,RESULT(r1) /* Save result */
1147 ld r12,_MSR(r1)
db7d31ac
MS
1148BEGIN_FTR_SECTION
1149 b 4f
1150END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
1945bc45 1151
afcf0095
NP
1152#ifdef CONFIG_PPC_P7_NAP
1153 /*
1154 * Check if thread was in power saving mode. We come here when any
1155 * of the following is true:
1156 * a. thread wasn't in power saving mode
1157 * b. thread was in power saving mode with no state loss,
1158 * supervisor state loss or hypervisor state loss.
1159 *
1160 * Go back to nap/sleep/winkle mode again if (b) is true.
1161 */
1945bc45
NP
1162 BEGIN_FTR_SECTION
1163 rlwinm. r11,r12,47-31,30,31
6102c005 1164 bne machine_check_idle_common
1945bc45 1165 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
afcf0095 1166#endif
1945bc45 1167
afcf0095
NP
1168 /*
1169 * Check if we are coming from hypervisor userspace. If yes then we
1170 * continue in host kernel in V mode to deliver the MC event.
1171 */
1172 rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
1173 beq 5f
db7d31ac 11744: andi. r11,r12,MSR_PR /* See if coming from user. */
afcf0095
NP
1175 bne 9f /* continue in V mode if we are. */
1176
11775:
1178#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
db7d31ac 1179BEGIN_FTR_SECTION
afcf0095
NP
1180 /*
1181 * We are coming from kernel context. Check if we are coming from
1182 * guest. if yes, then we can continue. We will fall through
1183 * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
1184 */
1185 lbz r11,HSTATE_IN_GUEST(r13)
1186 cmpwi r11,0 /* Check if coming from guest */
1187 bne 9f /* continue if we are. */
db7d31ac 1188END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
afcf0095
NP
1189#endif
1190 /*
1191 * At this point we are not sure about what context we come from.
1192 * Queue up the MCE event and return from the interrupt.
1193 * But before that, check if this is an un-recoverable exception.
1194 * If yes, then stay on emergency stack and panic.
1195 */
1196 andi. r11,r12,MSR_RI
1197 bne 2f
11981: mfspr r11,SPRN_SRR0
1199 LOAD_HANDLER(r10,unrecover_mce)
1200 mtspr SPRN_SRR0,r10
1201 ld r10,PACAKMSR(r13)
1202 /*
1203 * We are going down. But there are chances that we might get hit by
1204 * another MCE during panic path and we may run into unstable state
1205 * with no way out. Hence, turn ME bit off while going down, so that
1206 * when another MCE is hit during panic path, system will checkstop
1207 * and hypervisor will get restarted cleanly by SP.
1208 */
1209 li r3,MSR_ME
1210 andc r10,r10,r3 /* Turn off MSR_ME */
1211 mtspr SPRN_SRR1,r10
222f20f1 1212 RFI_TO_KERNEL
afcf0095
NP
1213 b .
12142:
1215 /*
1216 * Check if we have successfully handled/recovered from error, if not
1217 * then stay on emergency stack and panic.
1218 */
1219 ld r3,RESULT(r1) /* Load result */
1220 cmpdi r3,0 /* see if we handled MCE successfully */
1221
1222 beq 1b /* if !handled then panic */
db7d31ac 1223BEGIN_FTR_SECTION
afcf0095
NP
1224 /*
1225 * Return from MC interrupt.
1226 * Queue up the MCE event so that we can log it later, while
1227 * returning from kernel or opal call.
1228 */
1229 bl machine_check_queue_event
1230 MACHINE_CHECK_HANDLER_WINDUP
222f20f1 1231 RFI_TO_USER_OR_KERNEL
db7d31ac
MS
1232FTR_SECTION_ELSE
1233 /*
1234 * pSeries: Return from MC interrupt. Before that stay on emergency
1235 * stack and call machine_check_exception to log the MCE event.
1236 */
1237 LOAD_HANDLER(r10,mce_return)
1238 mtspr SPRN_SRR0,r10
1239 ld r10,PACAKMSR(r13)
1240 mtspr SPRN_SRR1,r10
1241 RFI_TO_KERNEL
1242 b .
1243ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
afcf0095
NP
12449:
1245 /* Deliver the machine check to host kernel in V mode. */
1246 MACHINE_CHECK_HANDLER_WINDUP
db7d31ac 1247 SET_SCRATCH0(r13) /* save r13 */
5dba1d50 1248 EXCEPTION_PROLOG_0 PACA_EXMC
db7d31ac 1249 b machine_check_pSeries_0
afcf0095
NP
1250
1251EXC_COMMON_BEGIN(unrecover_mce)
1252 /* Invoke machine_check_exception to print MCE event and panic. */
1253 addi r3,r1,STACK_FRAME_OVERHEAD
1254 bl machine_check_exception
1255 /*
1256 * We will not reach here. Even if we did, there is no way out. Call
1257 * unrecoverable_exception and die.
1258 */
12591: addi r3,r1,STACK_FRAME_OVERHEAD
1260 bl unrecoverable_exception
1261 b 1b
1262
a43c1590
MS
1263EXC_COMMON_BEGIN(mce_return)
1264 /* Invoke machine_check_exception to print MCE event and return. */
1265 addi r3,r1,STACK_FRAME_OVERHEAD
1266 bl machine_check_exception
db7d31ac 1267 MACHINE_CHECK_HANDLER_WINDUP
a43c1590
MS
1268 RFI_TO_KERNEL
1269 b .
0ebc4cda 1270
e779fc93
NP
1271EXC_REAL_BEGIN(data_access, 0x300, 0x80)
1272SET_SCRATCH0(r13) /* save r13 */
5dba1d50 1273EXCEPTION_PROLOG_0 PACA_EXGEN
e779fc93
NP
1274 b tramp_real_data_access
1275EXC_REAL_END(data_access, 0x300, 0x80)
1276
1277TRAMP_REAL_BEGIN(tramp_real_data_access)
fa4cf6b7 1278EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x300, 0
38555434
NP
1279 /*
1280 * DAR/DSISR must be read before setting MSR[RI], because
1281 * a d-side MCE will clobber those registers so is not
1282 * recoverable if they are live.
1283 */
1284 mfspr r10,SPRN_DAR
1285 mfspr r11,SPRN_DSISR
1286 std r10,PACA_EXGEN+EX_DAR(r13)
1287 stw r11,PACA_EXGEN+EX_DSISR(r13)
2d046308 1288EXCEPTION_PROLOG_2_REAL data_access_common, EXC_STD, 1
e779fc93
NP
1289
1290EXC_VIRT_BEGIN(data_access, 0x4300, 0x80)
1291SET_SCRATCH0(r13) /* save r13 */
5dba1d50 1292EXCEPTION_PROLOG_0 PACA_EXGEN
fa4cf6b7 1293EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, 0x300, 0
38555434
NP
1294 mfspr r10,SPRN_DAR
1295 mfspr r11,SPRN_DSISR
1296 std r10,PACA_EXGEN+EX_DAR(r13)
1297 stw r11,PACA_EXGEN+EX_DSISR(r13)
2d046308 1298EXCEPTION_PROLOG_2_VIRT data_access_common, EXC_STD
e779fc93
NP
1299EXC_VIRT_END(data_access, 0x4300, 0x80)
1300
80795e6c
NP
1301TRAMP_KVM_SKIP(PACA_EXGEN, 0x300)
1302
1303EXC_COMMON_BEGIN(data_access_common)
1304 /*
1305 * Here r13 points to the paca, r9 contains the saved CR,
1306 * SRR0 and SRR1 are saved in r11 and r12,
1307 * r9 - r13 are saved in paca->exgen.
38555434 1308 * EX_DAR and EX_DSISR have saved DAR/DSISR
80795e6c 1309 */
80795e6c
NP
1310 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
1311 RECONCILE_IRQ_STATE(r10, r11)
1312 ld r12,_MSR(r1)
1313 ld r3,PACA_EXGEN+EX_DAR(r13)
1314 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1315 li r5,0x300
1316 std r3,_DAR(r1)
1317 std r4,_DSISR(r1)
1318BEGIN_MMU_FTR_SECTION
1319 b do_hash_page /* Try to handle as hpte fault */
1320MMU_FTR_SECTION_ELSE
1321 b handle_page_fault
1322ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
1323
0ebc4cda 1324
1a6822d1 1325EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)
e779fc93 1326SET_SCRATCH0(r13) /* save r13 */
5dba1d50 1327EXCEPTION_PROLOG_0 PACA_EXSLB
e779fc93 1328 b tramp_real_data_access_slb
1a6822d1 1329EXC_REAL_END(data_access_slb, 0x380, 0x80)
0ebc4cda 1330
e779fc93 1331TRAMP_REAL_BEGIN(tramp_real_data_access_slb)
fa4cf6b7 1332EXCEPTION_PROLOG_1 EXC_STD, PACA_EXSLB, 1, 0x380, 0
38555434
NP
1333 mfspr r10,SPRN_DAR
1334 std r10,PACA_EXSLB+EX_DAR(r13)
2d046308 1335EXCEPTION_PROLOG_2_REAL data_access_slb_common, EXC_STD, 1
e779fc93 1336
1a6822d1 1337EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
e779fc93 1338SET_SCRATCH0(r13) /* save r13 */
5dba1d50 1339EXCEPTION_PROLOG_0 PACA_EXSLB
fa4cf6b7 1340EXCEPTION_PROLOG_1 EXC_STD, PACA_EXSLB, 0, 0x380, 0
38555434
NP
1341 mfspr r10,SPRN_DAR
1342 std r10,PACA_EXSLB+EX_DAR(r13)
2d046308 1343EXCEPTION_PROLOG_2_VIRT data_access_slb_common, EXC_STD
1a6822d1 1344EXC_VIRT_END(data_access_slb, 0x4380, 0x80)
48e7b769 1345
2b9af6e4
NP
1346TRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
1347
48e7b769 1348EXC_COMMON_BEGIN(data_access_slb_common)
48e7b769
NP
1349 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
1350 ld r4,PACA_EXSLB+EX_DAR(r13)
1351 std r4,_DAR(r1)
1352 addi r3,r1,STACK_FRAME_OVERHEAD
7100e870
NP
1353BEGIN_MMU_FTR_SECTION
1354 /* HPT case, do SLB fault */
48e7b769
NP
1355 bl do_slb_fault
1356 cmpdi r3,0
1357 bne- 1f
1358 b fast_exception_return
13591: /* Error case */
7100e870
NP
1360MMU_FTR_SECTION_ELSE
1361 /* Radix case, access is outside page table range */
1362 li r3,-EFAULT
1363ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
48e7b769
NP
1364 std r3,RESULT(r1)
1365 bl save_nvgprs
1366 RECONCILE_IRQ_STATE(r10, r11)
1367 ld r4,_DAR(r1)
1368 ld r5,RESULT(r1)
1369 addi r3,r1,STACK_FRAME_OVERHEAD
1370 bl do_bad_slb_fault
1371 b ret_from_except
1372
2b9af6e4 1373
1a6822d1
NP
1374EXC_REAL(instruction_access, 0x400, 0x80)
1375EXC_VIRT(instruction_access, 0x4400, 0x80, 0x400)
27ce77df
NP
1376TRAMP_KVM(PACA_EXGEN, 0x400)
1377
1378EXC_COMMON_BEGIN(instruction_access_common)
1379 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
1380 RECONCILE_IRQ_STATE(r10, r11)
1381 ld r12,_MSR(r1)
1382 ld r3,_NIP(r1)
475b581f 1383 andis. r4,r12,DSISR_SRR1_MATCH_64S@h
27ce77df
NP
1384 li r5,0x400
1385 std r3,_DAR(r1)
1386 std r4,_DSISR(r1)
1387BEGIN_MMU_FTR_SECTION
1388 b do_hash_page /* Try to handle as hpte fault */
1389MMU_FTR_SECTION_ELSE
1390 b handle_page_fault
1391ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
1392
0ebc4cda 1393
fc557537
NP
1394__EXC_REAL(instruction_access_slb, 0x480, 0x80, PACA_EXSLB)
1395__EXC_VIRT(instruction_access_slb, 0x4480, 0x80, 0x480, PACA_EXSLB)
48e7b769 1396TRAMP_KVM(PACA_EXSLB, 0x480)
54be0b9c 1397
48e7b769
NP
1398EXC_COMMON_BEGIN(instruction_access_slb_common)
1399 EXCEPTION_PROLOG_COMMON(0x480, PACA_EXSLB)
1400 ld r4,_NIP(r1)
1401 addi r3,r1,STACK_FRAME_OVERHEAD
7100e870
NP
1402BEGIN_MMU_FTR_SECTION
1403 /* HPT case, do SLB fault */
48e7b769
NP
1404 bl do_slb_fault
1405 cmpdi r3,0
1406 bne- 1f
1407 b fast_exception_return
14081: /* Error case */
7100e870
NP
1409MMU_FTR_SECTION_ELSE
1410 /* Radix case, access is outside page table range */
1411 li r3,-EFAULT
1412ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
48e7b769 1413 std r3,RESULT(r1)
8d04631a 1414 bl save_nvgprs
8d04631a 1415 RECONCILE_IRQ_STATE(r10, r11)
48e7b769
NP
1416 ld r4,_NIP(r1)
1417 ld r5,RESULT(r1)
1418 addi r3,r1,STACK_FRAME_OVERHEAD
1419 bl do_bad_slb_fault
8d04631a
NP
1420 b ret_from_except
1421
48e7b769 1422
1a6822d1 1423EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
80bd9177
NP
1424 SET_SCRATCH0(r13) /* save r13 */
1425 EXCEPTION_PROLOG_0 PACA_EXGEN
a5d4f3ad 1426 BEGIN_FTR_SECTION
fc557537
NP
1427 EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0x500, IRQS_DISABLED
1428 EXCEPTION_PROLOG_2_REAL hardware_interrupt_common, EXC_HV, 1
de56a948 1429 FTR_SECTION_ELSE
fc557537
NP
1430 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x500, IRQS_DISABLED
1431 EXCEPTION_PROLOG_2_REAL hardware_interrupt_common, EXC_STD, 1
969391c5 1432 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
1a6822d1 1433EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
da2bc464 1434
1a6822d1 1435EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
80bd9177
NP
1436 SET_SCRATCH0(r13) /* save r13 */
1437 EXCEPTION_PROLOG_0 PACA_EXGEN
c138e588 1438 BEGIN_FTR_SECTION
fc557537
NP
1439 EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0x500, IRQS_DISABLED
1440 EXCEPTION_PROLOG_2_VIRT hardware_interrupt_common, EXC_HV
c138e588 1441 FTR_SECTION_ELSE
fc557537
NP
1442 EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x500, IRQS_DISABLED
1443 EXCEPTION_PROLOG_2_VIRT hardware_interrupt_common, EXC_STD
c138e588 1444 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
1a6822d1 1445EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
c138e588 1446
7ede5317
NP
1447TRAMP_KVM(PACA_EXGEN, 0x500)
1448TRAMP_KVM_HV(PACA_EXGEN, 0x500)
c138e588
NP
1449EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
1450
1451
e779fc93
NP
1452EXC_REAL_BEGIN(alignment, 0x600, 0x100)
1453SET_SCRATCH0(r13) /* save r13 */
5dba1d50 1454EXCEPTION_PROLOG_0 PACA_EXGEN
fa4cf6b7 1455EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x600, 0
38555434
NP
1456 mfspr r10,SPRN_DAR
1457 mfspr r11,SPRN_DSISR
1458 std r10,PACA_EXGEN+EX_DAR(r13)
1459 stw r11,PACA_EXGEN+EX_DSISR(r13)
2d046308 1460EXCEPTION_PROLOG_2_REAL alignment_common, EXC_STD, 1
e779fc93
NP
1461EXC_REAL_END(alignment, 0x600, 0x100)
1462
1463EXC_VIRT_BEGIN(alignment, 0x4600, 0x100)
1464SET_SCRATCH0(r13) /* save r13 */
5dba1d50 1465EXCEPTION_PROLOG_0 PACA_EXGEN
fa4cf6b7 1466EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, 0x600, 0
38555434
NP
1467 mfspr r10,SPRN_DAR
1468 mfspr r11,SPRN_DSISR
1469 std r10,PACA_EXGEN+EX_DAR(r13)
1470 stw r11,PACA_EXGEN+EX_DSISR(r13)
2d046308 1471EXCEPTION_PROLOG_2_VIRT alignment_common, EXC_STD
e779fc93
NP
1472EXC_VIRT_END(alignment, 0x4600, 0x100)
1473
da2bc464 1474TRAMP_KVM(PACA_EXGEN, 0x600)
f9aa6714 1475EXC_COMMON_BEGIN(alignment_common)
f9aa6714
NP
1476 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1477 ld r3,PACA_EXGEN+EX_DAR(r13)
1478 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1479 std r3,_DAR(r1)
1480 std r4,_DSISR(r1)
1481 bl save_nvgprs
1482 RECONCILE_IRQ_STATE(r10, r11)
1483 addi r3,r1,STACK_FRAME_OVERHEAD
1484 bl alignment_exception
1485 b ret_from_except
1486
da2bc464 1487
1a6822d1
NP
1488EXC_REAL(program_check, 0x700, 0x100)
1489EXC_VIRT(program_check, 0x4700, 0x100, 0x700)
da2bc464 1490TRAMP_KVM(PACA_EXGEN, 0x700)
11e87346 1491EXC_COMMON_BEGIN(program_check_common)
265e60a1
CB
1492 /*
1493 * It's possible to receive a TM Bad Thing type program check with
1494 * userspace register values (in particular r1), but with SRR1 reporting
1495 * that we came from the kernel. Normally that would confuse the bad
1496 * stack logic, and we would report a bad kernel stack pointer. Instead
1497 * we switch to the emergency stack if we're taking a TM Bad Thing from
1498 * the kernel.
1499 */
1500 li r10,MSR_PR /* Build a mask of MSR_PR .. */
1501 oris r10,r10,0x200000@h /* .. and SRR1_PROGTM */
1502 and r10,r10,r12 /* Mask SRR1 with that. */
1503 srdi r10,r10,8 /* Shift it so we can compare */
1504 cmpldi r10,(0x200000 >> 8) /* .. with an immediate. */
1505 bne 1f /* If != go to normal path. */
1506
1507 /* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack */
1508 andi. r10,r12,MSR_PR; /* Set CR0 correctly for label */
1509 /* 3 in EXCEPTION_PROLOG_COMMON */
1510 mr r10,r1 /* Save r1 */
1511 ld r1,PACAEMERGSP(r13) /* Use emergency stack */
1512 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
1513 b 3f /* Jump into the macro !! */
15141: EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
11e87346
NP
1515 bl save_nvgprs
1516 RECONCILE_IRQ_STATE(r10, r11)
1517 addi r3,r1,STACK_FRAME_OVERHEAD
1518 bl program_check_exception
1519 b ret_from_except
1520
b01c8b54 1521
1a6822d1
NP
1522EXC_REAL(fp_unavailable, 0x800, 0x100)
1523EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
da2bc464 1524TRAMP_KVM(PACA_EXGEN, 0x800)
c78d9b97
NP
1525EXC_COMMON_BEGIN(fp_unavailable_common)
1526 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1527 bne 1f /* if from user, just load it up */
1528 bl save_nvgprs
1529 RECONCILE_IRQ_STATE(r10, r11)
1530 addi r3,r1,STACK_FRAME_OVERHEAD
1531 bl kernel_fp_unavailable_exception
1532 BUG_OPCODE
15331:
1534#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1535BEGIN_FTR_SECTION
1536 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1537 * transaction), go do TM stuff
1538 */
1539 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1540 bne- 2f
1541END_FTR_SECTION_IFSET(CPU_FTR_TM)
1542#endif
1543 bl load_up_fpu
1544 b fast_exception_return
1545#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
15462: /* User process was in a transaction */
1547 bl save_nvgprs
1548 RECONCILE_IRQ_STATE(r10, r11)
1549 addi r3,r1,STACK_FRAME_OVERHEAD
1550 bl fp_unavailable_tm
1551 b ret_from_except
1552#endif
1553
a5d4f3ad 1554
a048a07d 1555EXC_REAL_OOL_MASKABLE(decrementer, 0x900, 0x80, IRQS_DISABLED)
f14e953b 1556EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900, IRQS_DISABLED)
39c0da57
NP
1557TRAMP_KVM(PACA_EXGEN, 0x900)
1558EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
1559
a485c709 1560
1a6822d1
NP
1561EXC_REAL_HV(hdecrementer, 0x980, 0x80)
1562EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980)
facc6d74
NP
1563TRAMP_KVM_HV(PACA_EXGEN, 0x980)
1564EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
1565
a5d4f3ad 1566
f14e953b
MS
1567EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100, IRQS_DISABLED)
1568EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00, IRQS_DISABLED)
da2bc464 1569TRAMP_KVM(PACA_EXGEN, 0xa00)
ca243163
NP
1570#ifdef CONFIG_PPC_DOORBELL
1571EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
1572#else
1573EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
1574#endif
1575
0ebc4cda 1576
1a6822d1
NP
1577EXC_REAL(trap_0b, 0xb00, 0x100)
1578EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
da2bc464 1579TRAMP_KVM(PACA_EXGEN, 0xb00)
341215dc
NP
1580EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
1581
acd7d8ce
NP
1582/*
1583 * system call / hypercall (0xc00, 0x4c00)
1584 *
1585 * The system call exception is invoked with "sc 0" and does not alter HV bit.
1586 * There is support for kernel code to invoke system calls but there are no
1587 * in-tree users.
1588 *
1589 * The hypercall is invoked with "sc 1" and sets HV=1.
1590 *
1591 * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
1592 * 0x4c00 virtual mode.
1593 *
1594 * Call convention:
1595 *
1596 * syscall register convention is in Documentation/powerpc/syscall64-abi.txt
1597 *
1598 * For hypercalls, the register convention is as follows:
1599 * r0 volatile
1600 * r1-2 nonvolatile
1601 * r3 volatile parameter and return value for status
1602 * r4-r10 volatile input and output value
1603 * r11 volatile hypercall number and output value
76fc0cfc 1604 * r12 volatile input and output value
acd7d8ce
NP
1605 * r13-r31 nonvolatile
1606 * LR nonvolatile
1607 * CTR volatile
1608 * XER volatile
1609 * CR0-1 CR5-7 volatile
1610 * CR2-4 nonvolatile
1611 * Other registers nonvolatile
1612 *
1613 * The intersection of volatile registers that don't contain possible
76fc0cfc
NP
1614 * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
1615 * without saving, though xer is not a good idea to use, as hardware may
1616 * interpret some bits so it may be costly to change them.
acd7d8ce 1617 */
bc355125 1618#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
acd7d8ce
NP
1619 /*
1620 * There is a little bit of juggling to get syscall and hcall
76fc0cfc
NP
1621 * working well. Save r13 in ctr to avoid using SPRG scratch
1622 * register.
acd7d8ce
NP
1623 *
1624 * Userspace syscalls have already saved the PPR, hcalls must save
1625 * it before setting HMT_MEDIUM.
1626 */
bc355125 1627#define SYSCALL_KVMTEST \
76fc0cfc 1628 mtctr r13; \
bc355125 1629 GET_PACA(r13); \
76fc0cfc 1630 std r10,PACA_EXGEN+EX_R10(r13); \
a048a07d 1631 INTERRUPT_TO_KERNEL; \
a7c1ca19 1632 KVMTEST EXC_STD 0xc00 ; /* uses r10, branch to do_kvm_0xc00_system_call */ \
bc355125 1633 HMT_MEDIUM; \
76fc0cfc 1634 mfctr r9;
bc355125
PM
1635
1636#else
1637#define SYSCALL_KVMTEST \
acd7d8ce
NP
1638 HMT_MEDIUM; \
1639 mr r9,r13; \
a048a07d
NP
1640 GET_PACA(r13); \
1641 INTERRUPT_TO_KERNEL;
bc355125
PM
1642#endif
1643
fb479e44
NP
1644#define LOAD_SYSCALL_HANDLER(reg) \
1645 __LOAD_HANDLER(reg, system_call_common)
d807ad37 1646
acd7d8ce
NP
1647/*
1648 * After SYSCALL_KVMTEST, we reach here with PACA in r13, r13 in r9,
1649 * and HMT_MEDIUM.
1650 */
1651#define SYSCALL_REAL \
1652 mfspr r11,SPRN_SRR0 ; \
d807ad37
NP
1653 mfspr r12,SPRN_SRR1 ; \
1654 LOAD_SYSCALL_HANDLER(r10) ; \
1655 mtspr SPRN_SRR0,r10 ; \
1656 ld r10,PACAKMSR(r13) ; \
1657 mtspr SPRN_SRR1,r10 ; \
222f20f1 1658 RFI_TO_KERNEL ; \
d807ad37
NP
1659 b . ; /* prevent speculative execution */
1660
727f1361 1661#ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH
5c2511bf
ME
1662#define SYSCALL_FASTENDIAN_TEST \
1663BEGIN_FTR_SECTION \
1664 cmpdi r0,0x1ebe ; \
1665 beq- 1f ; \
1666END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
1667
acd7d8ce 1668#define SYSCALL_FASTENDIAN \
d807ad37
NP
1669 /* Fast LE/BE switch system call */ \
16701: mfspr r12,SPRN_SRR1 ; \
1671 xori r12,r12,MSR_LE ; \
1672 mtspr SPRN_SRR1,r12 ; \
acd7d8ce 1673 mr r13,r9 ; \
222f20f1 1674 RFI_TO_USER ; /* return to userspace */ \
d807ad37 1675 b . ; /* prevent speculative execution */
727f1361
ME
1676#else
1677#define SYSCALL_FASTENDIAN_TEST
1678#define SYSCALL_FASTENDIAN
1679#endif /* CONFIG_PPC_FAST_ENDIAN_SWITCH */
d807ad37
NP
1680
1681#if defined(CONFIG_RELOCATABLE)
1682 /*
1683 * We can't branch directly so we do it via the CTR which
1684 * is volatile across system calls.
1685 */
acd7d8ce
NP
1686#define SYSCALL_VIRT \
1687 LOAD_SYSCALL_HANDLER(r10) ; \
1688 mtctr r10 ; \
1689 mfspr r11,SPRN_SRR0 ; \
d807ad37
NP
1690 mfspr r12,SPRN_SRR1 ; \
1691 li r10,MSR_RI ; \
1692 mtmsrd r10,1 ; \
1693 bctr ;
1694#else
1695 /* We can branch directly */
acd7d8ce
NP
1696#define SYSCALL_VIRT \
1697 mfspr r11,SPRN_SRR0 ; \
d807ad37
NP
1698 mfspr r12,SPRN_SRR1 ; \
1699 li r10,MSR_RI ; \
1700 mtmsrd r10,1 ; /* Set RI (EE=0) */ \
1701 b system_call_common ;
1702#endif
1703
1a6822d1 1704EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
acd7d8ce
NP
1705 SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
1706 SYSCALL_FASTENDIAN_TEST
1707 SYSCALL_REAL
1708 SYSCALL_FASTENDIAN
1a6822d1 1709EXC_REAL_END(system_call, 0xc00, 0x100)
da2bc464 1710
1a6822d1 1711EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
acd7d8ce
NP
1712 SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
1713 SYSCALL_FASTENDIAN_TEST
1714 SYSCALL_VIRT
1715 SYSCALL_FASTENDIAN
1a6822d1 1716EXC_VIRT_END(system_call, 0x4c00, 0x100)
d807ad37 1717
acd7d8ce
NP
1718#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1719 /*
1720 * This is a hcall, so register convention is as above, with these
1721 * differences:
1722 * r13 = PACA
76fc0cfc
NP
1723 * ctr = orig r13
1724 * orig r10 saved in PACA
acd7d8ce
NP
1725 */
1726TRAMP_KVM_BEGIN(do_kvm_0xc00)
1727 /*
1728 * Save the PPR (on systems that support it) before changing to
1729 * HMT_MEDIUM. That allows the KVM code to save that value into the
1730 * guest state (it is the guest's PPR value).
1731 */
76fc0cfc 1732 OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
acd7d8ce 1733 HMT_MEDIUM
76fc0cfc 1734 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
acd7d8ce 1735 mfctr r10
76fc0cfc 1736 SET_SCRATCH0(r10)
acd7d8ce
NP
1737 std r9,PACA_EXGEN+EX_R9(r13)
1738 mfcr r9
17bdc064 1739 KVM_HANDLER PACA_EXGEN, EXC_STD, 0xc00, 0
acd7d8ce 1740#endif
da2bc464 1741
d807ad37 1742
1a6822d1
NP
1743EXC_REAL(single_step, 0xd00, 0x100)
1744EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
da2bc464 1745TRAMP_KVM(PACA_EXGEN, 0xd00)
bc6675c6 1746EXC_COMMON(single_step_common, 0xd00, single_step_exception)
b01c8b54 1747
1a6822d1 1748EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
da0e7e62 1749EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
f5c32c1d
NP
1750TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
1751EXC_COMMON_BEGIN(h_data_storage_common)
1752 mfspr r10,SPRN_HDAR
1753 std r10,PACA_EXGEN+EX_DAR(r13)
1754 mfspr r10,SPRN_HDSISR
1755 stw r10,PACA_EXGEN+EX_DSISR(r13)
1756 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
1757 bl save_nvgprs
1758 RECONCILE_IRQ_STATE(r10, r11)
1759 addi r3,r1,STACK_FRAME_OVERHEAD
d7b45615
SJS
1760BEGIN_MMU_FTR_SECTION
1761 ld r4,PACA_EXGEN+EX_DAR(r13)
1762 lwz r5,PACA_EXGEN+EX_DSISR(r13)
1763 std r4,_DAR(r1)
1764 std r5,_DSISR(r1)
1765 li r5,SIGSEGV
1766 bl bad_page_fault
1767MMU_FTR_SECTION_ELSE
f5c32c1d 1768 bl unknown_exception
d7b45615 1769ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_TYPE_RADIX)
f5c32c1d 1770 b ret_from_except
f5c32c1d 1771
1707dd16 1772
1a6822d1 1773EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
da0e7e62 1774EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
82517cab
NP
1775TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
1776EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
1777
1707dd16 1778
1a6822d1
NP
1779EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
1780EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
031b4026
NP
1781TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
1782EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
1783
1707dd16 1784
e0319829
NP
1785/*
1786 * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
1787 * first, and then eventaully from there to the trampoline to get into virtual
1788 * mode.
1789 */
1a6822d1 1790__EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
f14e953b 1791__TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60, IRQS_DISABLED)
1a6822d1 1792EXC_VIRT_NONE(0x4e60, 0x20)
62f9b03b
NP
1793TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
1794TRAMP_REAL_BEGIN(hmi_exception_early)
fa4cf6b7 1795 EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0xe60, 0
a4087a4d
NP
1796 mr r10,r1 /* Save r1 */
1797 ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */
62f9b03b 1798 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
62f9b03b 1799 mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
a4087a4d
NP
1800 mfspr r12,SPRN_HSRR1 /* Save HSRR1 */
1801 EXCEPTION_PROLOG_COMMON_1()
890274c2 1802 /* We don't touch AMR here, we never go to virtual mode */
62f9b03b
NP
1803 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
1804 EXCEPTION_PROLOG_COMMON_3(0xe60)
1805 addi r3,r1,STACK_FRAME_OVERHEAD
505a314f 1806 BRANCH_LINK_TO_FAR(DOTSYM(hmi_exception_realmode)) /* Function call ABI */
5080332c
MN
1807 cmpdi cr0,r3,0
1808
62f9b03b
NP
1809 /* Windup the stack. */
1810 /* Move original HSRR0 and HSRR1 into the respective regs */
1811 ld r9,_MSR(r1)
1812 mtspr SPRN_HSRR1,r9
1813 ld r3,_NIP(r1)
1814 mtspr SPRN_HSRR0,r3
1815 ld r9,_CTR(r1)
1816 mtctr r9
1817 ld r9,_XER(r1)
1818 mtxer r9
1819 ld r9,_LINK(r1)
1820 mtlr r9
1821 REST_GPR(0, r1)
1822 REST_8GPRS(2, r1)
1823 REST_GPR(10, r1)
1824 ld r11,_CCR(r1)
5080332c
MN
1825 REST_2GPRS(12, r1)
1826 bne 1f
62f9b03b
NP
1827 mtcr r11
1828 REST_GPR(11, r1)
5080332c 1829 ld r1,GPR1(r1)
222f20f1 1830 HRFI_TO_USER_OR_KERNEL
5080332c
MN
1831
18321: mtcr r11
1833 REST_GPR(11, r1)
62f9b03b
NP
1834 ld r1,GPR1(r1)
1835
1836 /*
1837 * Go to virtual mode and pull the HMI event information from
1838 * firmware.
1839 */
1840 .globl hmi_exception_after_realmode
1841hmi_exception_after_realmode:
1842 SET_SCRATCH0(r13)
5dba1d50 1843 EXCEPTION_PROLOG_0 PACA_EXGEN
62f9b03b
NP
1844 b tramp_real_hmi_exception
1845
5080332c 1846EXC_COMMON_BEGIN(hmi_exception_common)
47169fba
NP
1847 EXCEPTION_COMMON(PACA_EXGEN, 0xe60)
1848 FINISH_NAP
1849 bl save_nvgprs
1850 RECONCILE_IRQ_STATE(r10, r11)
1851 RUNLATCH_ON
c06075f3
NP
1852 addi r3,r1,STACK_FRAME_OVERHEAD
1853 bl handle_hmi_exception
1854 b ret_from_except
1707dd16 1855
f14e953b
MS
1856EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20, IRQS_DISABLED)
1857EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80, IRQS_DISABLED)
9bcb81bf
NP
1858TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
1859#ifdef CONFIG_PPC_DOORBELL
1860EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
1861#else
1862EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
1863#endif
1864
0ebc4cda 1865
f14e953b
MS
1866EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20, IRQS_DISABLED)
1867EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0, IRQS_DISABLED)
74408776
NP
1868TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
1869EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
1870
9baaef0a 1871
1a6822d1
NP
1872EXC_REAL_NONE(0xec0, 0x20)
1873EXC_VIRT_NONE(0x4ec0, 0x20)
1874EXC_REAL_NONE(0xee0, 0x20)
1875EXC_VIRT_NONE(0x4ee0, 0x20)
bda7fea2 1876
0ebc4cda 1877
f442d004
MS
1878EXC_REAL_OOL_MASKABLE(performance_monitor, 0xf00, 0x20, IRQS_PMI_DISABLED)
1879EXC_VIRT_OOL_MASKABLE(performance_monitor, 0x4f00, 0x20, 0xf00, IRQS_PMI_DISABLED)
b1c7f150
NP
1880TRAMP_KVM(PACA_EXGEN, 0xf00)
1881EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
1882
0ebc4cda 1883
1a6822d1
NP
1884EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
1885EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
d1a0ca9c
NP
1886TRAMP_KVM(PACA_EXGEN, 0xf20)
1887EXC_COMMON_BEGIN(altivec_unavailable_common)
1888 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1889#ifdef CONFIG_ALTIVEC
1890BEGIN_FTR_SECTION
1891 beq 1f
1892#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1893 BEGIN_FTR_SECTION_NESTED(69)
1894 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1895 * transaction), go do TM stuff
1896 */
1897 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1898 bne- 2f
1899 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1900#endif
1901 bl load_up_altivec
1902 b fast_exception_return
1903#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
19042: /* User process was in a transaction */
1905 bl save_nvgprs
1906 RECONCILE_IRQ_STATE(r10, r11)
1907 addi r3,r1,STACK_FRAME_OVERHEAD
1908 bl altivec_unavailable_tm
1909 b ret_from_except
1910#endif
19111:
1912END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1913#endif
1914 bl save_nvgprs
1915 RECONCILE_IRQ_STATE(r10, r11)
1916 addi r3,r1,STACK_FRAME_OVERHEAD
1917 bl altivec_unavailable_exception
1918 b ret_from_except
1919
0ebc4cda 1920
1a6822d1
NP
1921EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
1922EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
792cbddd
NP
1923TRAMP_KVM(PACA_EXGEN, 0xf40)
1924EXC_COMMON_BEGIN(vsx_unavailable_common)
1925 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1926#ifdef CONFIG_VSX
1927BEGIN_FTR_SECTION
1928 beq 1f
1929#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1930 BEGIN_FTR_SECTION_NESTED(69)
1931 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1932 * transaction), go do TM stuff
1933 */
1934 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1935 bne- 2f
1936 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1937#endif
1938 b load_up_vsx
1939#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
19402: /* User process was in a transaction */
1941 bl save_nvgprs
1942 RECONCILE_IRQ_STATE(r10, r11)
1943 addi r3,r1,STACK_FRAME_OVERHEAD
1944 bl vsx_unavailable_tm
1945 b ret_from_except
1946#endif
19471:
1948END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1949#endif
1950 bl save_nvgprs
1951 RECONCILE_IRQ_STATE(r10, r11)
1952 addi r3,r1,STACK_FRAME_OVERHEAD
1953 bl vsx_unavailable_exception
1954 b ret_from_except
1955
da2bc464 1956
1a6822d1
NP
1957EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
1958EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
1134713c
NP
1959TRAMP_KVM(PACA_EXGEN, 0xf60)
1960EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
1961
da2bc464 1962
1a6822d1
NP
1963EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
1964EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
14b0072c
NP
1965TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
1966EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
1967
da2bc464 1968
1a6822d1
NP
1969EXC_REAL_NONE(0xfa0, 0x20)
1970EXC_VIRT_NONE(0x4fa0, 0x20)
1971EXC_REAL_NONE(0xfc0, 0x20)
1972EXC_VIRT_NONE(0x4fc0, 0x20)
1973EXC_REAL_NONE(0xfe0, 0x20)
1974EXC_VIRT_NONE(0x4fe0, 0x20)
1975
1976EXC_REAL_NONE(0x1000, 0x100)
1977EXC_VIRT_NONE(0x5000, 0x100)
1978EXC_REAL_NONE(0x1100, 0x100)
1979EXC_VIRT_NONE(0x5100, 0x100)
d0c0c9a1 1980
0ebc4cda 1981#ifdef CONFIG_CBE_RAS
1a6822d1
NP
1982EXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
1983EXC_VIRT_NONE(0x5200, 0x100)
da2bc464 1984TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
ff1b3206 1985EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
da2bc464 1986#else /* CONFIG_CBE_RAS */
1a6822d1
NP
1987EXC_REAL_NONE(0x1200, 0x100)
1988EXC_VIRT_NONE(0x5200, 0x100)
da2bc464 1989#endif
b01c8b54 1990
ff1b3206 1991
1a6822d1
NP
1992EXC_REAL(instruction_breakpoint, 0x1300, 0x100)
1993EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
da2bc464 1994TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
4e96dbbf
NP
1995EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
1996
1a6822d1
NP
1997EXC_REAL_NONE(0x1400, 0x100)
1998EXC_VIRT_NONE(0x5400, 0x100)
da2bc464 1999
1a6822d1 2000EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
b92a66a6 2001 mtspr SPRN_SPRG_HSCRATCH0,r13
5dba1d50 2002 EXCEPTION_PROLOG_0 PACA_EXGEN
fa4cf6b7 2003 EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 0, 0x1500, 0
b92a66a6
MN
2004
2005#ifdef CONFIG_PPC_DENORMALISATION
2006 mfspr r10,SPRN_HSRR1
afcf0095 2007 andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
afcf0095
NP
2008 bne+ denorm_assist
2009#endif
1e9b4507 2010
a7c1ca19 2011 KVMTEST EXC_HV 0x1500
2d046308 2012 EXCEPTION_PROLOG_2_REAL denorm_common, EXC_HV, 1
1a6822d1 2013EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
a74599a5 2014
d7e89849 2015#ifdef CONFIG_PPC_DENORMALISATION
1a6822d1 2016EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
d7e89849 2017 b exc_real_0x1500_denorm_exception_hv
1a6822d1 2018EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
d7e89849 2019#else
1a6822d1 2020EXC_VIRT_NONE(0x5500, 0x100)
afcf0095
NP
2021#endif
2022
4bb3c7a0 2023TRAMP_KVM_HV(PACA_EXGEN, 0x1500)
b01c8b54 2024
b92a66a6 2025#ifdef CONFIG_PPC_DENORMALISATION
da2bc464 2026TRAMP_REAL_BEGIN(denorm_assist)
b92a66a6
MN
2027BEGIN_FTR_SECTION
2028/*
2029 * To denormalise we need to move a copy of the register to itself.
2030 * For POWER6 do that here for all FP regs.
2031 */
2032 mfmsr r10
2033 ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
2034 xori r10,r10,(MSR_FE0|MSR_FE1)
2035 mtmsrd r10
2036 sync
d7c67fb1
MN
2037
2038#define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
2039#define FMR4(n) FMR2(n) ; FMR2(n+2)
2040#define FMR8(n) FMR4(n) ; FMR4(n+4)
2041#define FMR16(n) FMR8(n) ; FMR8(n+8)
2042#define FMR32(n) FMR16(n) ; FMR16(n+16)
2043 FMR32(0)
2044
b92a66a6
MN
2045FTR_SECTION_ELSE
2046/*
2047 * To denormalise we need to move a copy of the register to itself.
2048 * For POWER7 do that here for the first 32 VSX registers only.
2049 */
2050 mfmsr r10
2051 oris r10,r10,MSR_VSX@h
2052 mtmsrd r10
2053 sync
d7c67fb1
MN
2054
2055#define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
2056#define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
2057#define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
2058#define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
2059#define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
2060 XVCPSGNDP32(0)
2061
b92a66a6 2062ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
fb0fce3e
MN
2063
2064BEGIN_FTR_SECTION
2065 b denorm_done
2066END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
2067/*
2068 * To denormalise we need to move a copy of the register to itself.
2069 * For POWER8 we need to do that for all 64 VSX registers
2070 */
2071 XVCPSGNDP32(32)
2072denorm_done:
f14040bc
MN
2073 mfspr r11,SPRN_HSRR0
2074 subi r11,r11,4
b92a66a6
MN
2075 mtspr SPRN_HSRR0,r11
2076 mtcrf 0x80,r9
2077 ld r9,PACA_EXGEN+EX_R9(r13)
44e9309f 2078 RESTORE_PPR_PACA(PACA_EXGEN, r10)
630573c1
PM
2079BEGIN_FTR_SECTION
2080 ld r10,PACA_EXGEN+EX_CFAR(r13)
2081 mtspr SPRN_CFAR,r10
2082END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
b92a66a6
MN
2083 ld r10,PACA_EXGEN+EX_R10(r13)
2084 ld r11,PACA_EXGEN+EX_R11(r13)
2085 ld r12,PACA_EXGEN+EX_R12(r13)
2086 ld r13,PACA_EXGEN+EX_R13(r13)
222f20f1 2087 HRFI_TO_UNKNOWN
b92a66a6
MN
2088 b .
2089#endif
2090
872e2ae4 2091EXC_COMMON(denorm_common, 0x1500, unknown_exception)
d7e89849
NP
2092
2093
2094#ifdef CONFIG_CBE_RAS
1a6822d1
NP
2095EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
2096EXC_VIRT_NONE(0x5600, 0x100)
d7e89849 2097TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
69a79344 2098EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
d7e89849 2099#else /* CONFIG_CBE_RAS */
1a6822d1
NP
2100EXC_REAL_NONE(0x1600, 0x100)
2101EXC_VIRT_NONE(0x5600, 0x100)
d7e89849
NP
2102#endif
2103
69a79344 2104
1a6822d1
NP
2105EXC_REAL(altivec_assist, 0x1700, 0x100)
2106EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
d7e89849 2107TRAMP_KVM(PACA_EXGEN, 0x1700)
b51c079e
NP
2108#ifdef CONFIG_ALTIVEC
2109EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
2110#else
2111EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
2112#endif
2113
d7e89849
NP
2114
2115#ifdef CONFIG_CBE_RAS
1a6822d1
NP
2116EXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
2117EXC_VIRT_NONE(0x5800, 0x100)
d7e89849 2118TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
3965f8ab 2119EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
d7e89849 2120#else /* CONFIG_CBE_RAS */
1a6822d1
NP
2121EXC_REAL_NONE(0x1800, 0x100)
2122EXC_VIRT_NONE(0x5800, 0x100)
d7e89849
NP
2123#endif
2124
75eb767e 2125#ifdef CONFIG_PPC_WATCHDOG
2104180a
NP
2126
2127#define MASKED_DEC_HANDLER_LABEL 3f
2128
2129#define MASKED_DEC_HANDLER(_H) \
21303: /* soft-nmi */ \
2131 std r12,PACA_EXGEN+EX_R12(r13); \
2132 GET_SCRATCH0(r10); \
2133 std r10,PACA_EXGEN+EX_R13(r13); \
2d046308 2134 EXCEPTION_PROLOG_2_REAL soft_nmi_common, _H, 1
2104180a 2135
cc491f1d
NP
2136/*
2137 * Branch to soft_nmi_interrupt using the emergency stack. The emergency
2138 * stack is one that is usable by maskable interrupts so long as MSR_EE
2139 * remains off. It is used for recovery when something has corrupted the
2140 * normal kernel stack, for example. The "soft NMI" must not use the process
2141 * stack because we want irq disabled sections to avoid touching the stack
2142 * at all (other than PMU interrupts), so use the emergency stack for this,
2143 * and run it entirely with interrupts hard disabled.
2144 */
2104180a
NP
2145EXC_COMMON_BEGIN(soft_nmi_common)
2146 mr r10,r1
2147 ld r1,PACAEMERGSP(r13)
2104180a 2148 subi r1,r1,INT_FRAME_SIZE
47169fba
NP
2149 EXCEPTION_COMMON_STACK(PACA_EXGEN, 0x900)
2150 bl save_nvgprs
2151 RECONCILE_IRQ_STATE(r10, r11)
c06075f3
NP
2152 addi r3,r1,STACK_FRAME_OVERHEAD
2153 bl soft_nmi_interrupt
2104180a
NP
2154 b ret_from_except
2155
75eb767e 2156#else /* CONFIG_PPC_WATCHDOG */
2104180a
NP
2157#define MASKED_DEC_HANDLER_LABEL 2f /* normal return */
2158#define MASKED_DEC_HANDLER(_H)
75eb767e 2159#endif /* CONFIG_PPC_WATCHDOG */
d7e89849 2160
0ebc4cda 2161/*
fe9e1d54
IM
2162 * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
2163 * - If it was a decrementer interrupt, we bump the dec to max and and return.
2164 * - If it was a doorbell we return immediately since doorbells are edge
2165 * triggered and won't automatically refire.
0869b6fd
MS
2166 * - If it was a HMI we return immediately since we handled it in realmode
2167 * and it won't refire.
6cc3f91b 2168 * - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return.
fe9e1d54 2169 * This is called with r10 containing the value to OR to the paca field.
0ebc4cda 2170 */
4508a74a
NP
2171.macro MASKED_INTERRUPT hsrr
2172 .if \hsrr
2173masked_Hinterrupt:
2174 .else
2175masked_interrupt:
2176 .endif
2177 std r11,PACA_EXGEN+EX_R11(r13)
2178 lbz r11,PACAIRQHAPPENED(r13)
2179 or r11,r11,r10
2180 stb r11,PACAIRQHAPPENED(r13)
2181 cmpwi r10,PACA_IRQ_DEC
2182 bne 1f
2183 lis r10,0x7fff
2184 ori r10,r10,0xffff
2185 mtspr SPRN_DEC,r10
2186 b MASKED_DEC_HANDLER_LABEL
21871: andi. r10,r10,PACA_IRQ_MUST_HARD_MASK
2188 beq 2f
2189 .if \hsrr
2190 mfspr r10,SPRN_HSRR1
2191 xori r10,r10,MSR_EE /* clear MSR_EE */
2192 mtspr SPRN_HSRR1,r10
2193 .else
2194 mfspr r10,SPRN_SRR1
2195 xori r10,r10,MSR_EE /* clear MSR_EE */
2196 mtspr SPRN_SRR1,r10
2197 .endif
2198 ori r11,r11,PACA_IRQ_HARD_DIS
2199 stb r11,PACAIRQHAPPENED(r13)
22002: /* done */
2201 mtcrf 0x80,r9
2202 std r1,PACAR1(r13)
2203 ld r9,PACA_EXGEN+EX_R9(r13)
2204 ld r10,PACA_EXGEN+EX_R10(r13)
2205 ld r11,PACA_EXGEN+EX_R11(r13)
2206 /* returns to kernel where r13 must be set up, so don't restore it */
2207 .if \hsrr
2208 HRFI_TO_KERNEL
2209 .else
2210 RFI_TO_KERNEL
2211 .endif
2212 b .
2213 MASKED_DEC_HANDLER(\hsrr\())
2214.endm
57f26649 2215
a048a07d
NP
2216TRAMP_REAL_BEGIN(stf_barrier_fallback)
2217 std r9,PACA_EXRFI+EX_R9(r13)
2218 std r10,PACA_EXRFI+EX_R10(r13)
2219 sync
2220 ld r9,PACA_EXRFI+EX_R9(r13)
2221 ld r10,PACA_EXRFI+EX_R10(r13)
2222 ori 31,31,0
2223 .rept 14
2224 b 1f
22251:
2226 .endr
2227 blr
2228
aa8a5e00
ME
2229TRAMP_REAL_BEGIN(rfi_flush_fallback)
2230 SET_SCRATCH0(r13);
2231 GET_PACA(r13);
78ee9946
ME
2232 std r1,PACA_EXRFI+EX_R12(r13)
2233 ld r1,PACAKSAVE(r13)
aa8a5e00
ME
2234 std r9,PACA_EXRFI+EX_R9(r13)
2235 std r10,PACA_EXRFI+EX_R10(r13)
2236 std r11,PACA_EXRFI+EX_R11(r13)
aa8a5e00
ME
2237 mfctr r9
2238 ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
bdcb1aef
NP
2239 ld r11,PACA_L1D_FLUSH_SIZE(r13)
2240 srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
aa8a5e00 2241 mtctr r11
15a3204d 2242 DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
aa8a5e00
ME
2243
2244 /* order ld/st prior to dcbt stop all streams with flushing */
2245 sync
bdcb1aef
NP
2246
2247 /*
2248 * The load adresses are at staggered offsets within cachelines,
2249 * which suits some pipelines better (on others it should not
2250 * hurt).
2251 */
22521:
2253 ld r11,(0x80 + 8)*0(r10)
2254 ld r11,(0x80 + 8)*1(r10)
2255 ld r11,(0x80 + 8)*2(r10)
2256 ld r11,(0x80 + 8)*3(r10)
2257 ld r11,(0x80 + 8)*4(r10)
2258 ld r11,(0x80 + 8)*5(r10)
2259 ld r11,(0x80 + 8)*6(r10)
2260 ld r11,(0x80 + 8)*7(r10)
2261 addi r10,r10,0x80*8
aa8a5e00
ME
2262 bdnz 1b
2263
2264 mtctr r9
2265 ld r9,PACA_EXRFI+EX_R9(r13)
2266 ld r10,PACA_EXRFI+EX_R10(r13)
2267 ld r11,PACA_EXRFI+EX_R11(r13)
78ee9946 2268 ld r1,PACA_EXRFI+EX_R12(r13)
aa8a5e00
ME
2269 GET_SCRATCH0(r13);
2270 rfid
2271
2272TRAMP_REAL_BEGIN(hrfi_flush_fallback)
2273 SET_SCRATCH0(r13);
2274 GET_PACA(r13);
78ee9946
ME
2275 std r1,PACA_EXRFI+EX_R12(r13)
2276 ld r1,PACAKSAVE(r13)
aa8a5e00
ME
2277 std r9,PACA_EXRFI+EX_R9(r13)
2278 std r10,PACA_EXRFI+EX_R10(r13)
2279 std r11,PACA_EXRFI+EX_R11(r13)
aa8a5e00
ME
2280 mfctr r9
2281 ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
bdcb1aef
NP
2282 ld r11,PACA_L1D_FLUSH_SIZE(r13)
2283 srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
aa8a5e00 2284 mtctr r11
15a3204d 2285 DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
aa8a5e00
ME
2286
2287 /* order ld/st prior to dcbt stop all streams with flushing */
2288 sync
bdcb1aef
NP
2289
2290 /*
2291 * The load adresses are at staggered offsets within cachelines,
2292 * which suits some pipelines better (on others it should not
2293 * hurt).
2294 */
22951:
2296 ld r11,(0x80 + 8)*0(r10)
2297 ld r11,(0x80 + 8)*1(r10)
2298 ld r11,(0x80 + 8)*2(r10)
2299 ld r11,(0x80 + 8)*3(r10)
2300 ld r11,(0x80 + 8)*4(r10)
2301 ld r11,(0x80 + 8)*5(r10)
2302 ld r11,(0x80 + 8)*6(r10)
2303 ld r11,(0x80 + 8)*7(r10)
2304 addi r10,r10,0x80*8
aa8a5e00
ME
2305 bdnz 1b
2306
2307 mtctr r9
2308 ld r9,PACA_EXRFI+EX_R9(r13)
2309 ld r10,PACA_EXRFI+EX_R10(r13)
2310 ld r11,PACA_EXRFI+EX_R11(r13)
78ee9946 2311 ld r1,PACA_EXRFI+EX_R12(r13)
aa8a5e00
ME
2312 GET_SCRATCH0(r13);
2313 hrfid
2314
57f26649
NP
2315/*
2316 * Real mode exceptions actually use this too, but alternate
2317 * instruction code patches (which end up in the common .text area)
2318 * cannot reach these if they are put there.
2319 */
2320USE_FIXED_SECTION(virt_trampolines)
4508a74a
NP
2321 MASKED_INTERRUPT EXC_STD
2322 MASKED_INTERRUPT EXC_HV
0ebc4cda 2323
4f6c11db 2324#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
da2bc464 2325TRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
4f6c11db
PM
2326 /*
2327 * Here all GPRs are unchanged from when the interrupt happened
2328 * except for r13, which is saved in SPRG_SCRATCH0.
2329 */
2330 mfspr r13, SPRN_SRR0
2331 addi r13, r13, 4
2332 mtspr SPRN_SRR0, r13
2333 GET_SCRATCH0(r13)
222f20f1 2334 RFI_TO_KERNEL
4f6c11db
PM
2335 b .
2336
da2bc464 2337TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
4f6c11db
PM
2338 /*
2339 * Here all GPRs are unchanged from when the interrupt happened
2340 * except for r13, which is saved in SPRG_SCRATCH0.
2341 */
2342 mfspr r13, SPRN_HSRR0
2343 addi r13, r13, 4
2344 mtspr SPRN_HSRR0, r13
2345 GET_SCRATCH0(r13)
222f20f1 2346 HRFI_TO_KERNEL
4f6c11db
PM
2347 b .
2348#endif
2349
0ebc4cda 2350/*
057b6d7e
HB
2351 * Ensure that any handlers that get invoked from the exception prologs
2352 * above are below the first 64KB (0x10000) of the kernel image because
2353 * the prologs assemble the addresses of these handlers using the
2354 * LOAD_HANDLER macro, which uses an ori instruction.
0ebc4cda
BH
2355 */
2356
2357/*** Common interrupt handlers ***/
2358
0ebc4cda 2359
c1fb6816
MN
2360 /*
2361 * Relocation-on interrupts: A subset of the interrupts can be delivered
2362 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
2363 * it. Addresses are the same as the original interrupt addresses, but
2364 * offset by 0xc000000000004000.
2365 * It's impossible to receive interrupts below 0x300 via this mechanism.
2366 * KVM: None of these traps are from the guest ; anything that escalated
2367 * to HV=1 from HV=0 is delivered via real mode handlers.
2368 */
2369
2370 /*
2371 * This uses the standard macro, since the original 0x300 vector
2372 * only has extra guff for STAB-based processors -- which never
2373 * come here.
2374 */
da2bc464 2375
57f26649 2376EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
b1576fec 2377 b __ppc64_runlatch_on
fe1952fc 2378
57f26649 2379USE_FIXED_SECTION(virt_trampolines)
8ed8ab40
HB
2380 /*
2381 * The __end_interrupts marker must be past the out-of-line (OOL)
2382 * handlers, so that they are copied to real address 0x100 when running
2383 * a relocatable kernel. This ensures they can be reached from the short
2384 * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
2385 * directly, without using LOAD_HANDLER().
2386 */
2387 .align 7
2388 .globl __end_interrupts
2389__end_interrupts:
57f26649 2390DEFINE_FIXED_SYMBOL(__end_interrupts)
61383407 2391
087aa036 2392#ifdef CONFIG_PPC_970_NAP
7c8cb4b5 2393EXC_COMMON_BEGIN(power4_fixup_nap)
087aa036
CG
2394 andc r9,r9,r10
2395 std r9,TI_LOCAL_FLAGS(r11)
2396 ld r10,_LINK(r1) /* make idle task do the */
2397 std r10,_NIP(r1) /* equivalent of a blr */
2398 blr
2399#endif
2400
57f26649
NP
2401CLOSE_FIXED_SECTION(real_vectors);
2402CLOSE_FIXED_SECTION(real_trampolines);
2403CLOSE_FIXED_SECTION(virt_vectors);
2404CLOSE_FIXED_SECTION(virt_trampolines);
2405
2406USE_TEXT_SECTION()
2407
0ebc4cda
BH
2408/*
2409 * Hash table stuff
2410 */
f4329f2e 2411 .balign IFETCH_ALIGN_BYTES
6a3bab90 2412do_hash_page:
4e003747 2413#ifdef CONFIG_PPC_BOOK3S_64
e6c2a479 2414 lis r0,(DSISR_BAD_FAULT_64S | DSISR_DABRMATCH | DSISR_KEYFAULT)@h
398a719d
BH
2415 ori r0,r0,DSISR_BAD_FAULT_64S@l
2416 and. r0,r4,r0 /* weird error? */
0ebc4cda 2417 bne- handle_page_fault /* if not, try to insert a HPTE */
c911d2e1 2418 ld r11, PACA_THREAD_INFO(r13)
9c1e1052
PM
2419 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
2420 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
2421 bne 77f /* then don't call hash_page now */
0ebc4cda
BH
2422
2423 /*
2424 * r3 contains the faulting address
106713a1 2425 * r4 msr
0ebc4cda 2426 * r5 contains the trap number
aefa5688 2427 * r6 contains dsisr
0ebc4cda 2428 *
7230c564 2429 * at return r3 = 0 for success, 1 for page fault, negative for error
0ebc4cda 2430 */
106713a1 2431 mr r4,r12
aefa5688 2432 ld r6,_DSISR(r1)
106713a1
AK
2433 bl __hash_page /* build HPTE if possible */
2434 cmpdi r3,0 /* see if __hash_page succeeded */
0ebc4cda 2435
7230c564 2436 /* Success */
0ebc4cda 2437 beq fast_exc_return_irq /* Return from exception on success */
0ebc4cda 2438
7230c564
BH
2439 /* Error */
2440 blt- 13f
d89ba535
NR
2441
2442 /* Reload DSISR into r4 for the DABR check below */
2443 ld r4,_DSISR(r1)
4e003747 2444#endif /* CONFIG_PPC_BOOK3S_64 */
9c7cc234 2445
0ebc4cda
BH
2446/* Here we have a page fault that hash_page can't handle. */
2447handle_page_fault:
d89ba535
NR
244811: andis. r0,r4,DSISR_DABRMATCH@h
2449 bne- handle_dabr_fault
2450 ld r4,_DAR(r1)
0ebc4cda
BH
2451 ld r5,_DSISR(r1)
2452 addi r3,r1,STACK_FRAME_OVERHEAD
b1576fec 2453 bl do_page_fault
0ebc4cda 2454 cmpdi r3,0
f474c28f 2455 beq+ ret_from_except_lite
b1576fec 2456 bl save_nvgprs
0ebc4cda
BH
2457 mr r5,r3
2458 addi r3,r1,STACK_FRAME_OVERHEAD
2459 lwz r4,_DAR(r1)
b1576fec
AB
2460 bl bad_page_fault
2461 b ret_from_except
0ebc4cda 2462
a546498f
BH
2463/* We have a data breakpoint exception - handle it */
2464handle_dabr_fault:
b1576fec 2465 bl save_nvgprs
a546498f
BH
2466 ld r4,_DAR(r1)
2467 ld r5,_DSISR(r1)
2468 addi r3,r1,STACK_FRAME_OVERHEAD
b1576fec 2469 bl do_break
f474c28f
RB
2470 /*
2471 * do_break() may have changed the NV GPRS while handling a breakpoint.
2472 * If so, we need to restore them with their updated values. Don't use
2473 * ret_from_except_lite here.
2474 */
2475 b ret_from_except
a546498f 2476
0ebc4cda 2477
4e003747 2478#ifdef CONFIG_PPC_BOOK3S_64
0ebc4cda
BH
2479/* We have a page fault that hash_page could handle but HV refused
2480 * the PTE insertion
2481 */
b1576fec 248213: bl save_nvgprs
0ebc4cda
BH
2483 mr r5,r3
2484 addi r3,r1,STACK_FRAME_OVERHEAD
2485 ld r4,_DAR(r1)
b1576fec
AB
2486 bl low_hash_fault
2487 b ret_from_except
caca285e 2488#endif
0ebc4cda 2489
9c1e1052
PM
2490/*
2491 * We come here as a result of a DSI at a point where we don't want
2492 * to call hash_page, such as when we are accessing memory (possibly
2493 * user memory) inside a PMU interrupt that occurred while interrupts
2494 * were soft-disabled. We want to invoke the exception handler for
2495 * the access, or panic if there isn't a handler.
2496 */
b1576fec 249777: bl save_nvgprs
9c1e1052
PM
2498 mr r4,r3
2499 addi r3,r1,STACK_FRAME_OVERHEAD
2500 li r5,SIGSEGV
b1576fec
AB
2501 bl bad_page_fault
2502 b ret_from_except
4e2bf01b
ME
2503
2504/*
2505 * Here we have detected that the kernel stack pointer is bad.
2506 * R9 contains the saved CR, r13 points to the paca,
2507 * r10 contains the (bad) kernel stack pointer,
2508 * r11 and r12 contain the saved SRR0 and SRR1.
2509 * We switch to using an emergency stack, save the registers there,
2510 * and call kernel_bad_stack(), which panics.
2511 */
2512bad_stack:
2513 ld r1,PACAEMERGSP(r13)
2514 subi r1,r1,64+INT_FRAME_SIZE
2515 std r9,_CCR(r1)
2516 std r10,GPR1(r1)
2517 std r11,_NIP(r1)
2518 std r12,_MSR(r1)
2519 mfspr r11,SPRN_DAR
2520 mfspr r12,SPRN_DSISR
2521 std r11,_DAR(r1)
2522 std r12,_DSISR(r1)
2523 mflr r10
2524 mfctr r11
2525 mfxer r12
2526 std r10,_LINK(r1)
2527 std r11,_CTR(r1)
2528 std r12,_XER(r1)
2529 SAVE_GPR(0,r1)
2530 SAVE_GPR(2,r1)
2531 ld r10,EX_R3(r3)
2532 std r10,GPR3(r1)
2533 SAVE_GPR(4,r1)
2534 SAVE_4GPRS(5,r1)
2535 ld r9,EX_R9(r3)
2536 ld r10,EX_R10(r3)
2537 SAVE_2GPRS(9,r1)
2538 ld r9,EX_R11(r3)
2539 ld r10,EX_R12(r3)
2540 ld r11,EX_R13(r3)
2541 std r9,GPR11(r1)
2542 std r10,GPR12(r1)
2543 std r11,GPR13(r1)
2544BEGIN_FTR_SECTION
2545 ld r10,EX_CFAR(r3)
2546 std r10,ORIG_GPR3(r1)
2547END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
2548 SAVE_8GPRS(14,r1)
2549 SAVE_10GPRS(22,r1)
2550 lhz r12,PACA_TRAP_SAVE(r13)
2551 std r12,_TRAP(r1)
2552 addi r11,r1,INT_FRAME_SIZE
2553 std r11,0(r1)
2554 li r12,0
2555 std r12,0(r11)
2556 ld r2,PACATOC(r13)
2557 ld r11,exception_marker@toc(r2)
2558 std r12,RESULT(r1)
2559 std r11,STACK_FRAME_OVERHEAD-16(r1)
25601: addi r3,r1,STACK_FRAME_OVERHEAD
2561 bl kernel_bad_stack
2562 b 1b
15770a13 2563_ASM_NOKPROBE_SYMBOL(bad_stack);
0f0c6ca1 2564
a9af97aa
NP
2565/*
2566 * When doorbell is triggered from system reset wakeup, the message is
2567 * not cleared, so it would fire again when EE is enabled.
2568 *
2569 * When coming from local_irq_enable, there may be the same problem if
2570 * we were hard disabled.
2571 *
2572 * Execute msgclr to clear pending exceptions before handling it.
2573 */
2574h_doorbell_common_msgclr:
2575 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
2576 PPC_MSGCLR(3)
2577 b h_doorbell_common
2578
2579doorbell_super_common_msgclr:
2580 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
2581 PPC_MSGCLRP(3)
2582 b doorbell_super_common
2583
0f0c6ca1
NP
2584/*
2585 * Called from arch_local_irq_enable when an interrupt needs
2586 * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
2587 * which kind of interrupt. MSR:EE is already off. We generate a
2588 * stackframe like if a real interrupt had happened.
2589 *
2590 * Note: While MSR:EE is off, we need to make sure that _MSR
2591 * in the generated frame has EE set to 1 or the exception
2592 * handler will not properly re-enable them.
b48bbb82
NP
2593 *
2594 * Note that we don't specify LR as the NIP (return address) for
2595 * the interrupt because that would unbalance the return branch
2596 * predictor.
0f0c6ca1
NP
2597 */
2598_GLOBAL(__replay_interrupt)
2599 /* We are going to jump to the exception common code which
2600 * will retrieve various register values from the PACA which
2601 * we don't give a damn about, so we don't bother storing them.
2602 */
2603 mfmsr r12
3e23a12b 2604 LOAD_REG_ADDR(r11, replay_interrupt_return)
0f0c6ca1
NP
2605 mfcr r9
2606 ori r12,r12,MSR_EE
2607 cmpwi r3,0x900
2608 beq decrementer_common
2609 cmpwi r3,0x500
e6c1203d
NP
2610BEGIN_FTR_SECTION
2611 beq h_virt_irq_common
2612FTR_SECTION_ELSE
0f0c6ca1 2613 beq hardware_interrupt_common
e6c1203d 2614ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300)
f442d004
MS
2615 cmpwi r3,0xf00
2616 beq performance_monitor_common
0f0c6ca1 2617BEGIN_FTR_SECTION
d6f73fc6 2618 cmpwi r3,0xa00
a9af97aa 2619 beq h_doorbell_common_msgclr
0f0c6ca1
NP
2620 cmpwi r3,0xe60
2621 beq hmi_exception_common
2622FTR_SECTION_ELSE
2623 cmpwi r3,0xa00
a9af97aa 2624 beq doorbell_super_common_msgclr
0f0c6ca1 2625ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
3e23a12b 2626replay_interrupt_return:
0f0c6ca1 2627 blr
b48bbb82 2628
15770a13 2629_ASM_NOKPROBE_SYMBOL(__replay_interrupt)