/* SPDX-License-Identifier: GPL-2.0 */1/*2* This file contains the 64-bit "server" PowerPC variant3* of the low level exception handling including exception4* vectors, exception return, part of the slb and stab5* handling and other fixed offset specific things.6*7* This file is meant to be #included from head_64.S due to8* position dependent assembly.9*10* Most of this originates from head_64.S and thus has the same11* copyright history.12*13*/1415#include <linux/linkage.h>16#include <asm/hw_irq.h>17#include <asm/exception-64s.h>18#include <asm/ptrace.h>19#include <asm/cpuidle.h>20#include <asm/head-64.h>21#include <asm/feature-fixups.h>22#include <asm/kup.h>2324/*25* Following are fixed section helper macros.26*27* EXC_REAL_BEGIN/END - real, unrelocated exception vectors28* EXC_VIRT_BEGIN/END - virt (AIL), unrelocated exception vectors29* TRAMP_REAL_BEGIN - real, unrelocated helpers (virt may call these)30* TRAMP_VIRT_BEGIN - virt, unreloc helpers (in practice, real can use)31* EXC_COMMON - After switching to virtual, relocated mode.32*/3334#define EXC_REAL_BEGIN(name, start, size) \35FIXED_SECTION_ENTRY_BEGIN_LOCATION(real_vectors, exc_real_##start##_##name, start, size)3637#define EXC_REAL_END(name, start, size) \38FIXED_SECTION_ENTRY_END_LOCATION(real_vectors, exc_real_##start##_##name, start, size)3940#define EXC_VIRT_BEGIN(name, start, size) \41FIXED_SECTION_ENTRY_BEGIN_LOCATION(virt_vectors, exc_virt_##start##_##name, start, size)4243#define EXC_VIRT_END(name, start, size) \44FIXED_SECTION_ENTRY_END_LOCATION(virt_vectors, exc_virt_##start##_##name, start, size)4546#define EXC_COMMON_BEGIN(name) \47USE_TEXT_SECTION(); \48.balign IFETCH_ALIGN_BYTES; \49.global name; \50_ASM_NOKPROBE_SYMBOL(name); \51DEFINE_FIXED_SYMBOL(name, text); \52name:5354#define TRAMP_REAL_BEGIN(name) \55FIXED_SECTION_ENTRY_BEGIN(real_trampolines, name)5657#define TRAMP_VIRT_BEGIN(name) \58FIXED_SECTION_ENTRY_BEGIN(virt_trampolines, name)5960#define EXC_REAL_NONE(start, size) \61FIXED_SECTION_ENTRY_BEGIN_LOCATION(real_vectors, exc_real_##start##_##unused, start, size); \62FIXED_SECTION_ENTRY_END_LOCATION(real_vectors, exc_real_##start##_##unused, start, size)6364#define EXC_VIRT_NONE(start, size) \65FIXED_SECTION_ENTRY_BEGIN_LOCATION(virt_vectors, exc_virt_##start##_##unused, start, size); \66FIXED_SECTION_ENTRY_END_LOCATION(virt_vectors, exc_virt_##start##_##unused, start, size)6768/*69* We're short on space and time in the exception prolog, so we can't70* use the normal LOAD_REG_IMMEDIATE macro to load the address of label.71* Instead we get the base of the kernel from paca->kernelbase and or in the low72* part of label. This requires that the label be within 64KB of kernelbase, and73* that kernelbase be 64K aligned.74*/75#define LOAD_HANDLER(reg, label) \76ld reg,PACAKBASE(r13); /* get high part of &label */ \77ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label)7879#define __LOAD_HANDLER(reg, label, section) \80ld reg,PACAKBASE(r13); \81ori reg,reg,(ABS_ADDR(label, section))@l8283/*84* Branches from unrelocated code (e.g., interrupts) to labels outside85* head-y require >64K offsets.86*/87#define __LOAD_FAR_HANDLER(reg, label, section) \88ld reg,PACAKBASE(r13); \89ori reg,reg,(ABS_ADDR(label, section))@l; \90addis reg,reg,(ABS_ADDR(label, section))@h9192/*93* Interrupt code generation macros94*/95#define IVEC .L_IVEC_\name\() /* Interrupt vector address */96#define IHSRR .L_IHSRR_\name\() /* Sets SRR or HSRR registers */97#define IHSRR_IF_HVMODE .L_IHSRR_IF_HVMODE_\name\() /* HSRR if HV else SRR */98#define IAREA .L_IAREA_\name\() /* PACA save area */99#define IVIRT .L_IVIRT_\name\() /* Has virt mode entry point */100#define IISIDE .L_IISIDE_\name\() /* Uses SRR0/1 not DAR/DSISR */101#define ICFAR .L_ICFAR_\name\() /* Uses CFAR */102#define ICFAR_IF_HVMODE .L_ICFAR_IF_HVMODE_\name\() /* Uses CFAR if HV */103#define IDAR .L_IDAR_\name\() /* Uses DAR (or SRR0) */104#define IDSISR .L_IDSISR_\name\() /* Uses DSISR (or SRR1) */105#define IBRANCH_TO_COMMON .L_IBRANCH_TO_COMMON_\name\() /* ENTRY branch to common */106#define IREALMODE_COMMON .L_IREALMODE_COMMON_\name\() /* Common runs in realmode */107#define IMASK .L_IMASK_\name\() /* IRQ soft-mask bit */108#define IKVM_REAL .L_IKVM_REAL_\name\() /* Real entry tests KVM */109#define __IKVM_REAL(name) .L_IKVM_REAL_ ## name110#define IKVM_VIRT .L_IKVM_VIRT_\name\() /* Virt entry tests KVM */111#define ISTACK .L_ISTACK_\name\() /* Set regular kernel stack */112#define __ISTACK(name) .L_ISTACK_ ## name113#define IKUAP .L_IKUAP_\name\() /* Do KUAP lock */114#define IMSR_R12 .L_IMSR_R12_\name\() /* Assumes MSR saved to r12 */115116#define INT_DEFINE_BEGIN(n) \117.macro int_define_ ## n name118119#define INT_DEFINE_END(n) \120.endm ; \121int_define_ ## n n ; \122do_define_int n123124.macro do_define_int name125.ifndef IVEC126.error "IVEC not defined"127.endif128.ifndef IHSRR129IHSRR=0130.endif131.ifndef IHSRR_IF_HVMODE132IHSRR_IF_HVMODE=0133.endif134.ifndef IAREA135IAREA=PACA_EXGEN136.endif137.ifndef IVIRT138IVIRT=1139.endif140.ifndef IISIDE141IISIDE=0142.endif143.ifndef ICFAR144ICFAR=1145.endif146.ifndef ICFAR_IF_HVMODE147ICFAR_IF_HVMODE=0148.endif149.ifndef IDAR150IDAR=0151.endif152.ifndef IDSISR153IDSISR=0154.endif155.ifndef IBRANCH_TO_COMMON156IBRANCH_TO_COMMON=1157.endif158.ifndef IREALMODE_COMMON159IREALMODE_COMMON=0160.else161.if ! IBRANCH_TO_COMMON162.error "IREALMODE_COMMON=1 but IBRANCH_TO_COMMON=0"163.endif164.endif165.ifndef IMASK166IMASK=0167.endif168.ifndef IKVM_REAL169IKVM_REAL=0170.endif171.ifndef IKVM_VIRT172IKVM_VIRT=0173.endif174.ifndef ISTACK175ISTACK=1176.endif177.ifndef IKUAP178IKUAP=1179.endif180.ifndef IMSR_R12181IMSR_R12=0182.endif183.endm184185/*186* All interrupts which set HSRR registers, as well as SRESET and MCE and187* syscall when invoked with "sc 1" switch to MSR[HV]=1 (HVMODE) to be taken,188* so they all generally need to test whether they were taken in guest context.189*190* Note: SRESET and MCE may also be sent to the guest by the hypervisor, and be191* taken with MSR[HV]=0.192*193* Interrupts which set SRR registers (with the above exceptions) do not194* elevate to MSR[HV]=1 mode, though most can be taken when running with195* MSR[HV]=1 (e.g., bare metal kernel and userspace). So these interrupts do196* not need to test whether a guest is running because they get delivered to197* the guest directly, including nested HV KVM guests.198*199* The exception is PR KVM, where the guest runs with MSR[PR]=1 and the host200* runs with MSR[HV]=0, so the host takes all interrupts on behalf of the201* guest. PR KVM runs with LPCR[AIL]=0 which causes interrupts to always be202* delivered to the real-mode entry point, therefore such interrupts only test203* KVM in their real mode handlers, and only when PR KVM is possible.204*205* Interrupts that are taken in MSR[HV]=0 and escalate to MSR[HV]=1 are always206* delivered in real-mode when the MMU is in hash mode because the MMU207* registers are not set appropriately to translate host addresses. In nested208* radix mode these can be delivered in virt-mode as the host translations are209* used implicitly (see: effective LPID, effective PID).210*/211212/*213* If an interrupt is taken while a guest is running, it is immediately routed214* to KVM to handle.215*/216217.macro KVMTEST name handler218#ifdef CONFIG_KVM_BOOK3S_64_HANDLER219lbz r10,HSTATE_IN_GUEST(r13)220cmpwi r10,0221/* HSRR variants have the 0x2 bit added to their trap number */222.if IHSRR_IF_HVMODE223BEGIN_FTR_SECTION224li r10,(IVEC + 0x2)225FTR_SECTION_ELSE226li r10,(IVEC)227ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)228.elseif IHSRR229li r10,(IVEC + 0x2)230.else231li r10,(IVEC)232.endif233bne \handler234#endif235.endm236237/*238* This is the BOOK3S interrupt entry code macro.239*240* This can result in one of several things happening:241* - Branch to the _common handler, relocated, in virtual mode.242* These are normal interrupts (synchronous and asynchronous) handled by243* the kernel.244* - Branch to KVM, relocated but real mode interrupts remain in real mode.245* These occur when HSTATE_IN_GUEST is set. The interrupt may be caused by246* / intended for host or guest kernel, but KVM must always be involved247* because the machine state is set for guest execution.248* - Branch to the masked handler, unrelocated.249* These occur when maskable asynchronous interrupts are taken with the250* irq_soft_mask set.251* - Branch to an "early" handler in real mode but relocated.252* This is done if early=1. MCE and HMI use these to handle errors in real253* mode.254* - Fall through and continue executing in real, unrelocated mode.255* This is done if early=2.256*/257258.macro GEN_BRANCH_TO_COMMON name, virt259.if IREALMODE_COMMON260LOAD_HANDLER(r10, \name\()_common)261mtctr r10262bctr263.else264.if \virt265#ifndef CONFIG_RELOCATABLE266b \name\()_common_virt267#else268LOAD_HANDLER(r10, \name\()_common_virt)269mtctr r10270bctr271#endif272.else273LOAD_HANDLER(r10, \name\()_common_real)274mtctr r10275bctr276.endif277.endif278.endm279280.macro GEN_INT_ENTRY name, virt, ool=0281SET_SCRATCH0(r13) /* save r13 */282GET_PACA(r13)283std r9,IAREA+EX_R9(r13) /* save r9 */284BEGIN_FTR_SECTION285mfspr r9,SPRN_PPR286END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)287HMT_MEDIUM288std r10,IAREA+EX_R10(r13) /* save r10 */289.if ICFAR290BEGIN_FTR_SECTION291mfspr r10,SPRN_CFAR292END_FTR_SECTION_IFSET(CPU_FTR_CFAR)293.elseif ICFAR_IF_HVMODE294BEGIN_FTR_SECTION295BEGIN_FTR_SECTION_NESTED(69)296mfspr r10,SPRN_CFAR297END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 69)298FTR_SECTION_ELSE299BEGIN_FTR_SECTION_NESTED(69)300li r10,0301END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 69)302ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)303.endif304.if \ool305.if !\virt306b tramp_real_\name307.pushsection .text308TRAMP_REAL_BEGIN(tramp_real_\name)309.else310b tramp_virt_\name311.pushsection .text312TRAMP_VIRT_BEGIN(tramp_virt_\name)313.endif314.endif315316BEGIN_FTR_SECTION317std r9,IAREA+EX_PPR(r13)318END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)319.if ICFAR || ICFAR_IF_HVMODE320BEGIN_FTR_SECTION321std r10,IAREA+EX_CFAR(r13)322END_FTR_SECTION_IFSET(CPU_FTR_CFAR)323.endif324INTERRUPT_TO_KERNEL325mfctr r10326std r10,IAREA+EX_CTR(r13)327mfcr r9328std r11,IAREA+EX_R11(r13) /* save r11 - r12 */329std r12,IAREA+EX_R12(r13)330331/*332* DAR/DSISR, SCRATCH0 must be read before setting MSR[RI],333* because a d-side MCE will clobber those registers so is334* not recoverable if they are live.335*/336GET_SCRATCH0(r10)337std r10,IAREA+EX_R13(r13)338.if IDAR && !IISIDE339.if IHSRR340mfspr r10,SPRN_HDAR341.else342mfspr r10,SPRN_DAR343.endif344std r10,IAREA+EX_DAR(r13)345.endif346.if IDSISR && !IISIDE347.if IHSRR348mfspr r10,SPRN_HDSISR349.else350mfspr r10,SPRN_DSISR351.endif352stw r10,IAREA+EX_DSISR(r13)353.endif354355.if IHSRR_IF_HVMODE356BEGIN_FTR_SECTION357mfspr r11,SPRN_HSRR0 /* save HSRR0 */358mfspr r12,SPRN_HSRR1 /* and HSRR1 */359FTR_SECTION_ELSE360mfspr r11,SPRN_SRR0 /* save SRR0 */361mfspr r12,SPRN_SRR1 /* and SRR1 */362ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)363.elseif IHSRR364mfspr r11,SPRN_HSRR0 /* save HSRR0 */365mfspr r12,SPRN_HSRR1 /* and HSRR1 */366.else367mfspr r11,SPRN_SRR0 /* save SRR0 */368mfspr r12,SPRN_SRR1 /* and SRR1 */369.endif370371.if IBRANCH_TO_COMMON372GEN_BRANCH_TO_COMMON \name \virt373.endif374375.if \ool376.popsection377.endif378.endm379380/*381* __GEN_COMMON_ENTRY is required to receive the branch from interrupt382* entry, except in the case of the real-mode handlers which require383* __GEN_REALMODE_COMMON_ENTRY.384*385* This switches to virtual mode and sets MSR[RI].386*/387.macro __GEN_COMMON_ENTRY name388DEFINE_FIXED_SYMBOL(\name\()_common_real, text)389\name\()_common_real:390.if IKVM_REAL391KVMTEST \name kvm_interrupt392.endif393394ld r10,PACAKMSR(r13) /* get MSR value for kernel */395/* MSR[RI] is clear iff using SRR regs */396.if IHSRR_IF_HVMODE397BEGIN_FTR_SECTION398xori r10,r10,MSR_RI399END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)400.elseif ! IHSRR401xori r10,r10,MSR_RI402.endif403mtmsrd r10404405.if IVIRT406.if IKVM_VIRT407b 1f /* skip the virt test coming from real */408.endif409410.balign IFETCH_ALIGN_BYTES411DEFINE_FIXED_SYMBOL(\name\()_common_virt, text)412\name\()_common_virt:413.if IKVM_VIRT414KVMTEST \name kvm_interrupt4151:416.endif417.endif /* IVIRT */418.endm419420/*421* Don't switch to virt mode. Used for early MCE and HMI handlers that422* want to run in real mode.423*/424.macro __GEN_REALMODE_COMMON_ENTRY name425DEFINE_FIXED_SYMBOL(\name\()_common_real, text)426\name\()_common_real:427.if IKVM_REAL428KVMTEST \name kvm_interrupt429.endif430.endm431432.macro __GEN_COMMON_BODY name433.if IMASK434.if ! ISTACK435.error "No support for masked interrupt to use custom stack"436.endif437438/* If coming from user, skip soft-mask tests. */439andi. r10,r12,MSR_PR440bne 3f441442/*443* Kernel code running below __end_soft_masked may be444* implicitly soft-masked if it is within the regions445* in the soft mask table.446*/447LOAD_HANDLER(r10, __end_soft_masked)448cmpld r11,r10449bge+ 1f450451/* SEARCH_SOFT_MASK_TABLE clobbers r9,r10,r12 */452mtctr r12453stw r9,PACA_EXGEN+EX_CCR(r13)454SEARCH_SOFT_MASK_TABLE455cmpdi r12,0456mfctr r12 /* Restore r12 to SRR1 */457lwz r9,PACA_EXGEN+EX_CCR(r13)458beq 1f /* Not in soft-mask table */459li r10,IMASK460b 2f /* In soft-mask table, always mask */461462/* Test the soft mask state against our interrupt's bit */4631: lbz r10,PACAIRQSOFTMASK(r13)4642: andi. r10,r10,IMASK465/* Associate vector numbers with bits in paca->irq_happened */466.if IVEC == 0x500 || IVEC == 0xea0467li r10,PACA_IRQ_EE468.elseif IVEC == 0x900469li r10,PACA_IRQ_DEC470.elseif IVEC == 0xa00 || IVEC == 0xe80471li r10,PACA_IRQ_DBELL472.elseif IVEC == 0xe60473li r10,PACA_IRQ_HMI474.elseif IVEC == 0xf00475li r10,PACA_IRQ_PMI476.else477.abort "Bad maskable vector"478.endif479480.if IHSRR_IF_HVMODE481BEGIN_FTR_SECTION482bne masked_Hinterrupt483FTR_SECTION_ELSE484bne masked_interrupt485ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)486.elseif IHSRR487bne masked_Hinterrupt488.else489bne masked_interrupt490.endif491.endif492493.if ISTACK494andi. r10,r12,MSR_PR /* See if coming from user */4953: mr r10,r1 /* Save r1 */496subi r1,r1,INT_FRAME_SIZE /* alloc frame on kernel stack */497beq- 100f498ld r1,PACAKSAVE(r13) /* kernel stack to use */499100: tdgei r1,-INT_FRAME_SIZE /* trap if r1 is in userspace */500EMIT_BUG_ENTRY 100b,__FILE__,__LINE__,0501.endif502503std r9,_CCR(r1) /* save CR in stackframe */504std r11,_NIP(r1) /* save SRR0 in stackframe */505std r12,_MSR(r1) /* save SRR1 in stackframe */506std r10,0(r1) /* make stack chain pointer */507std r0,GPR0(r1) /* save r0 in stackframe */508std r10,GPR1(r1) /* save r1 in stackframe */509SANITIZE_GPR(0)510511/* Mark our [H]SRRs valid for return */512li r10,1513.if IHSRR_IF_HVMODE514BEGIN_FTR_SECTION515stb r10,PACAHSRR_VALID(r13)516FTR_SECTION_ELSE517stb r10,PACASRR_VALID(r13)518ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)519.elseif IHSRR520stb r10,PACAHSRR_VALID(r13)521.else522stb r10,PACASRR_VALID(r13)523.endif524525.if ISTACK526.if IKUAP527kuap_save_amr_and_lock r9, r10, cr1, cr0528.endif529beq 101f /* if from kernel mode */530BEGIN_FTR_SECTION531ld r9,IAREA+EX_PPR(r13) /* Read PPR from paca */532std r9,_PPR(r1)533END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)534101:535.else536.if IKUAP537kuap_save_amr_and_lock r9, r10, cr1538.endif539.endif540541/* Save original regs values from save area to stack frame. */542ld r9,IAREA+EX_R9(r13) /* move r9, r10 to stackframe */543ld r10,IAREA+EX_R10(r13)544std r9,GPR9(r1)545std r10,GPR10(r1)546ld r9,IAREA+EX_R11(r13) /* move r11 - r13 to stackframe */547ld r10,IAREA+EX_R12(r13)548ld r11,IAREA+EX_R13(r13)549std r9,GPR11(r1)550std r10,GPR12(r1)551std r11,GPR13(r1)552.if !IMSR_R12553SANITIZE_GPRS(9, 12)554.else555SANITIZE_GPRS(9, 11)556.endif557558SAVE_NVGPRS(r1)559SANITIZE_NVGPRS()560561.if IDAR562.if IISIDE563ld r10,_NIP(r1)564.else565ld r10,IAREA+EX_DAR(r13)566.endif567std r10,_DAR(r1)568.endif569570.if IDSISR571.if IISIDE572ld r10,_MSR(r1)573lis r11,DSISR_SRR1_MATCH_64S@h574and r10,r10,r11575.else576lwz r10,IAREA+EX_DSISR(r13)577.endif578std r10,_DSISR(r1)579.endif580581BEGIN_FTR_SECTION582.if ICFAR || ICFAR_IF_HVMODE583ld r10,IAREA+EX_CFAR(r13)584.else585li r10,0586.endif587std r10,ORIG_GPR3(r1)588END_FTR_SECTION_IFSET(CPU_FTR_CFAR)589ld r10,IAREA+EX_CTR(r13)590std r10,_CTR(r1)591SAVE_GPRS(2, 8, r1) /* save r2 - r8 in stackframe */592SANITIZE_GPRS(2, 8)593mflr r9 /* Get LR, later save to stack */594LOAD_PACA_TOC() /* get kernel TOC into r2 */595std r9,_LINK(r1)596lbz r10,PACAIRQSOFTMASK(r13)597mfspr r11,SPRN_XER /* save XER in stackframe */598std r10,SOFTE(r1)599std r11,_XER(r1)600li r9,IVEC601std r9,_TRAP(r1) /* set trap number */602li r10,0603LOAD_REG_IMMEDIATE(r11, STACK_FRAME_REGS_MARKER)604std r10,RESULT(r1) /* clear regs->result */605std r11,STACK_INT_FRAME_MARKER(r1) /* mark the frame */606.endm607608/*609* On entry r13 points to the paca, r9-r13 are saved in the paca,610* r9 contains the saved CR, r11 and r12 contain the saved SRR0 and611* SRR1, and relocation is on.612*613* If stack=0, then the stack is already set in r1, and r1 is saved in r10.614* PPR save and CPU accounting is not done for the !stack case (XXX why not?)615*/616.macro GEN_COMMON name617__GEN_COMMON_ENTRY \name618__GEN_COMMON_BODY \name619.endm620621.macro SEARCH_RESTART_TABLE622#ifdef CONFIG_RELOCATABLE623mr r12,r2624LOAD_PACA_TOC()625LOAD_REG_ADDR(r9, __start___restart_table)626LOAD_REG_ADDR(r10, __stop___restart_table)627mr r2,r12628#else629LOAD_REG_IMMEDIATE_SYM(r9, r12, __start___restart_table)630LOAD_REG_IMMEDIATE_SYM(r10, r12, __stop___restart_table)631#endif632300:633cmpd r9,r10634beq 302f635ld r12,0(r9)636cmpld r11,r12637blt 301f638ld r12,8(r9)639cmpld r11,r12640bge 301f641ld r12,16(r9)642b 303f643301:644addi r9,r9,24645b 300b646302:647li r12,0648303:649.endm650651.macro SEARCH_SOFT_MASK_TABLE652#ifdef CONFIG_RELOCATABLE653mr r12,r2654LOAD_PACA_TOC()655LOAD_REG_ADDR(r9, __start___soft_mask_table)656LOAD_REG_ADDR(r10, __stop___soft_mask_table)657mr r2,r12658#else659LOAD_REG_IMMEDIATE_SYM(r9, r12, __start___soft_mask_table)660LOAD_REG_IMMEDIATE_SYM(r10, r12, __stop___soft_mask_table)661#endif662300:663cmpd r9,r10664beq 302f665ld r12,0(r9)666cmpld r11,r12667blt 301f668ld r12,8(r9)669cmpld r11,r12670bge 301f671li r12,1672b 303f673301:674addi r9,r9,16675b 300b676302:677li r12,0678303:679.endm680681/*682* Restore all registers including H/SRR0/1 saved in a stack frame of a683* standard exception.684*/685.macro EXCEPTION_RESTORE_REGS hsrr=0686/* Move original SRR0 and SRR1 into the respective regs */687ld r9,_MSR(r1)688li r10,0689.if \hsrr690mtspr SPRN_HSRR1,r9691stb r10,PACAHSRR_VALID(r13)692.else693mtspr SPRN_SRR1,r9694stb r10,PACASRR_VALID(r13)695.endif696ld r9,_NIP(r1)697.if \hsrr698mtspr SPRN_HSRR0,r9699.else700mtspr SPRN_SRR0,r9701.endif702ld r9,_CTR(r1)703mtctr r9704ld r9,_XER(r1)705mtxer r9706ld r9,_LINK(r1)707mtlr r9708ld r9,_CCR(r1)709mtcr r9710SANITIZE_RESTORE_NVGPRS()711REST_GPRS(2, 13, r1)712REST_GPR(0, r1)713/* restore original r1. */714ld r1,GPR1(r1)715.endm716717/*718* EARLY_BOOT_FIXUP - Fix real-mode interrupt with wrong endian in early boot.719*720* There's a short window during boot where although the kernel is running721* little endian, any exceptions will cause the CPU to switch back to big722* endian. For example a WARN() boils down to a trap instruction, which will723* cause a program check, and we end up here but with the CPU in big endian724* mode. The first instruction of the program check handler (in GEN_INT_ENTRY725* below) is an mtsprg, which when executed in the wrong endian is an lhzu with726* a ~3GB displacement from r3. The content of r3 is random, so that is a load727* from some random location, and depending on the system can easily lead to a728* checkstop, or an infinitely recursive page fault.729*730* So to handle that case we have a trampoline here that can detect we are in731* the wrong endian and flip us back to the correct endian. We can't flip732* MSR[LE] using mtmsr, so we have to use rfid. That requires backing up SRR0/1733* as well as a GPR. To do that we use SPRG0/2/3, as SPRG1 is already used for734* the paca. SPRG3 is user readable, but this trampoline is only active very735* early in boot, and SPRG3 will be reinitialised in vdso_getcpu_init() before736* userspace starts.737*/738.macro EARLY_BOOT_FIXUP739BEGIN_FTR_SECTION740#ifdef CONFIG_CPU_LITTLE_ENDIAN741tdi 0,0,0x48 // Trap never, or in reverse endian: b . + 8742b 2f // Skip trampoline if endian is correct743.long 0xa643707d // mtsprg 0, r11 Backup r11744.long 0xa6027a7d // mfsrr0 r11745.long 0xa643727d // mtsprg 2, r11 Backup SRR0 in SPRG2746.long 0xa6027b7d // mfsrr1 r11747.long 0xa643737d // mtsprg 3, r11 Backup SRR1 in SPRG3748.long 0xa600607d // mfmsr r11749.long 0x01006b69 // xori r11, r11, 1 Invert MSR[LE]750.long 0xa6037b7d // mtsrr1 r11751/*752* This is 'li r11,1f' where 1f is the absolute address of that753* label, byteswapped into the SI field of the instruction.754*/755.long 0x00006039 | \756((ABS_ADDR(1f, real_vectors) & 0x00ff) << 24) | \757((ABS_ADDR(1f, real_vectors) & 0xff00) << 8)758.long 0xa6037a7d // mtsrr0 r11759.long 0x2400004c // rfid7601:761mfsprg r11, 3762mtsrr1 r11 // Restore SRR1763mfsprg r11, 2764mtsrr0 r11 // Restore SRR0765mfsprg r11, 0 // Restore r117662:767#endif768/*769* program check could hit at any time, and pseries can not block770* MSR[ME] in early boot. So check if there is anything useful in r13771* yet, and spin forever if not.772*/773mtsprg 0, r11774mfcr r11775cmpdi r13, 0776beq .777mtcr r11778mfsprg r11, 0779END_FTR_SECTION(0, 1) // nop out after boot780.endm781782/*783* There are a few constraints to be concerned with.784* - Real mode exceptions code/data must be located at their physical location.785* - Virtual mode exceptions must be mapped at their 0xc000... location.786* - Fixed location code must not call directly beyond the __end_interrupts787* area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence788* must be used.789* - LOAD_HANDLER targets must be within first 64K of physical 0 /790* virtual 0xc00...791* - Conditional branch targets must be within +/-32K of caller.792*793* "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and794* therefore don't have to run in physically located code or rfid to795* virtual mode kernel code. However on relocatable kernels they do have796* to branch to KERNELBASE offset because the rest of the kernel (outside797* the exception vectors) may be located elsewhere.798*799* Virtual exceptions correspond with physical, except their entry points800* are offset by 0xc000000000000000 and also tend to get an added 0x4000801* offset applied. Virtual exceptions are enabled with the Alternate802* Interrupt Location (AIL) bit set in the LPCR. However this does not803* guarantee they will be delivered virtually. Some conditions (see the ISA)804* cause exceptions to be delivered in real mode.805*806* The scv instructions are a special case. They get a 0x3000 offset applied.807* scv exceptions have unique reentrancy properties, see below.808*809* It's impossible to receive interrupts below 0x300 via AIL.810*811* KVM: None of the virtual exceptions are from the guest. Anything that812* escalated to HV=1 from HV=0 is delivered via real mode handlers.813*814*815* We layout physical memory as follows:816* 0x0000 - 0x00ff : Secondary processor spin code817* 0x0100 - 0x18ff : Real mode pSeries interrupt vectors818* 0x1900 - 0x2fff : Real mode trampolines819* 0x3000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors820* 0x5900 - 0x6fff : Relon mode trampolines821* 0x7000 - 0x7fff : FWNMI data area822* 0x8000 - .... : Common interrupt handlers, remaining early823* setup code, rest of kernel.824*825* We could reclaim 0x4000-0x42ff for real mode trampolines if the space826* is necessary. Until then it's more consistent to explicitly put VIRT_NONE827* vectors there.828*/829OPEN_FIXED_SECTION(real_vectors, 0x0100, 0x1900)830OPEN_FIXED_SECTION(real_trampolines, 0x1900, 0x3000)831OPEN_FIXED_SECTION(virt_vectors, 0x3000, 0x5900)832OPEN_FIXED_SECTION(virt_trampolines, 0x5900, 0x7000)833834#ifdef CONFIG_PPC_POWERNV835.globl start_real_trampolines836.globl end_real_trampolines837.globl start_virt_trampolines838.globl end_virt_trampolines839#endif840841#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)842/*843* Data area reserved for FWNMI option.844* This address (0x7000) is fixed by the RPA.845* pseries and powernv need to keep the whole page from846* 0x7000 to 0x8000 free for use by the firmware847*/848ZERO_FIXED_SECTION(fwnmi_page, 0x7000, 0x8000)849OPEN_TEXT_SECTION(0x8000)850#else851OPEN_TEXT_SECTION(0x7000)852#endif853854USE_FIXED_SECTION(real_vectors)855856/*857* This is the start of the interrupt handlers for pSeries858* This code runs with relocation off.859* Code from here to __end_interrupts gets copied down to real860* address 0x100 when we are running a relocatable kernel.861* Therefore any relative branches in this section must only862* branch to labels in this section.863*/864.globl __start_interrupts865__start_interrupts:866867/**868* Interrupt 0x3000 - System Call Vectored Interrupt (syscall).869* This is a synchronous interrupt invoked with the "scv" instruction. The870* system call does not alter the HV bit, so it is directed to the OS.871*872* Handling:873* scv instructions enter the kernel without changing EE, RI, ME, or HV.874* In particular, this means we can take a maskable interrupt at any point875* in the scv handler, which is unlike any other interrupt. This is solved876* by treating the instruction addresses in the handler as being soft-masked,877* by adding a SOFT_MASK_TABLE entry for them.878*879* AIL-0 mode scv exceptions go to 0x17000-0x17fff, but we set AIL-3 and880* ensure scv is never executed with relocation off, which means AIL-0881* should never happen.882*883* Before leaving the following inside-__end_soft_masked text, at least of the884* following must be true:885* - MSR[PR]=1 (i.e., return to userspace)886* - MSR_EE|MSR_RI is clear (no reentrant exceptions)887* - Standard kernel environment is set up (stack, paca, etc)888*889* KVM:890* These interrupts do not elevate HV 0->1, so HV is not involved. PR KVM891* ensures that FSCR[SCV] is disabled whenever it has to force AIL off.892*893* Call convention:894*895* syscall register convention is in Documentation/arch/powerpc/syscall64-abi.rst896*/897EXC_VIRT_BEGIN(system_call_vectored, 0x3000, 0x1000)898/* SCV 0 */899mr r9,r13900GET_PACA(r13)901mflr r11902mfctr r12903li r10,IRQS_ALL_DISABLED904stb r10,PACAIRQSOFTMASK(r13)905#ifdef CONFIG_RELOCATABLE906b system_call_vectored_tramp907#else908b system_call_vectored_common909#endif910nop911912/* SCV 1 - 127 */913.rept 127914mr r9,r13915GET_PACA(r13)916mflr r11917mfctr r12918li r10,IRQS_ALL_DISABLED919stb r10,PACAIRQSOFTMASK(r13)920li r0,-1 /* cause failure */921#ifdef CONFIG_RELOCATABLE922b system_call_vectored_sigill_tramp923#else924b system_call_vectored_sigill925#endif926.endr927EXC_VIRT_END(system_call_vectored, 0x3000, 0x1000)928929// Treat scv vectors as soft-masked, see comment above.930// Use absolute values rather than labels here, so they don't get relocated,931// because this code runs unrelocated.932SOFT_MASK_TABLE(0xc000000000003000, 0xc000000000004000)933934#ifdef CONFIG_RELOCATABLE935TRAMP_VIRT_BEGIN(system_call_vectored_tramp)936__LOAD_HANDLER(r10, system_call_vectored_common, virt_trampolines)937mtctr r10938bctr939940TRAMP_VIRT_BEGIN(system_call_vectored_sigill_tramp)941__LOAD_HANDLER(r10, system_call_vectored_sigill, virt_trampolines)942mtctr r10943bctr944#endif945946947/* No virt vectors corresponding with 0x0..0x100 */948EXC_VIRT_NONE(0x4000, 0x100)949950951/**952* Interrupt 0x100 - System Reset Interrupt (SRESET aka NMI).953* This is a non-maskable, asynchronous interrupt always taken in real-mode.954* It is caused by:955* - Wake from power-saving state, on powernv.956* - An NMI from another CPU, triggered by firmware or hypercall.957* - As crash/debug signal injected from BMC, firmware or hypervisor.958*959* Handling:960* Power-save wakeup is the only performance critical path, so this is961* determined quickly as possible first. In this case volatile registers962* can be discarded and SPRs like CFAR don't need to be read.963*964* If not a powersave wakeup, then it's run as a regular interrupt, however965* it uses its own stack and PACA save area to preserve the regular kernel966* environment for debugging.967*968* This interrupt is not maskable, so triggering it when MSR[RI] is clear,969* or SCRATCH0 is in use, etc. may cause a crash. It's also not entirely970* correct to switch to virtual mode to run the regular interrupt handler971* because it might be interrupted when the MMU is in a bad state (e.g., SLB972* is clear).973*974* FWNMI:975* PAPR specifies a "fwnmi" facility which sends the sreset to a different976* entry point with a different register set up. Some hypervisors will977* send the sreset to 0x100 in the guest if it is not fwnmi capable.978*979* KVM:980* Unlike most SRR interrupts, this may be taken by the host while executing981* in a guest, so a KVM test is required. KVM will pull the CPU out of guest982* mode and then raise the sreset.983*/984INT_DEFINE_BEGIN(system_reset)985IVEC=0x100986IAREA=PACA_EXNMI987IVIRT=0 /* no virt entry point */988ISTACK=0989IKVM_REAL=1990INT_DEFINE_END(system_reset)991992EXC_REAL_BEGIN(system_reset, 0x100, 0x100)993#ifdef CONFIG_PPC_P7_NAP994/*995* If running native on arch 2.06 or later, check if we are waking up996* from nap/sleep/winkle, and branch to idle handler. This tests SRR1997* bits 46:47. A non-0 value indicates that we are coming from a power998* saving state. The idle wakeup handler initially runs in real mode,999* but we branch to the 0xc000... address so we can turn on relocation1000* with mtmsrd later, after SPRs are restored.1001*1002* Careful to minimise cost for the fast path (idle wakeup) while1003* also avoiding clobbering CFAR for the debug path (non-idle).1004*1005* For the idle wake case volatile registers can be clobbered, which1006* is why we use those initially. If it turns out to not be an idle1007* wake, carefully put everything back the way it was, so we can use1008* common exception macros to handle it.1009*/1010BEGIN_FTR_SECTION1011SET_SCRATCH0(r13)1012GET_PACA(r13)1013std r3,PACA_EXNMI+0*8(r13)1014std r4,PACA_EXNMI+1*8(r13)1015std r5,PACA_EXNMI+2*8(r13)1016mfspr r3,SPRN_SRR11017mfocrf r4,0x801018rlwinm. r5,r3,47-31,30,311019bne+ system_reset_idle_wake1020/* Not powersave wakeup. Restore regs for regular interrupt handler. */1021mtocrf 0x80,r41022ld r3,PACA_EXNMI+0*8(r13)1023ld r4,PACA_EXNMI+1*8(r13)1024ld r5,PACA_EXNMI+2*8(r13)1025GET_SCRATCH0(r13)1026END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)1027#endif10281029GEN_INT_ENTRY system_reset, virt=01030/*1031* In theory, we should not enable relocation here if it was disabled1032* in SRR1, because the MMU may not be configured to support it (e.g.,1033* SLB may have been cleared). In practice, there should only be a few1034* small windows where that's the case, and sreset is considered to1035* be dangerous anyway.1036*/1037EXC_REAL_END(system_reset, 0x100, 0x100)1038EXC_VIRT_NONE(0x4100, 0x100)10391040#ifdef CONFIG_PPC_P7_NAP1041TRAMP_REAL_BEGIN(system_reset_idle_wake)1042/* We are waking up from idle, so may clobber any volatile register */1043cmpwi cr1,r5,21044bltlr cr1 /* no state loss, return to idle caller with r3=SRR1 */1045__LOAD_FAR_HANDLER(r12, DOTSYM(idle_return_gpr_loss), real_trampolines)1046mtctr r121047bctr1048#endif10491050#ifdef CONFIG_PPC_PSERIES1051/*1052* Vectors for the FWNMI option. Share common code.1053*/1054TRAMP_REAL_BEGIN(system_reset_fwnmi)1055GEN_INT_ENTRY system_reset, virt=010561057#endif /* CONFIG_PPC_PSERIES */10581059EXC_COMMON_BEGIN(system_reset_common)1060__GEN_COMMON_ENTRY system_reset1061/*1062* Increment paca->in_nmi. When the interrupt entry wrapper later1063* enable MSR_RI, then SLB or MCE will be able to recover, but a nested1064* NMI will notice in_nmi and not recover because of the use of the NMI1065* stack. in_nmi reentrancy is tested in system_reset_exception.1066*/1067lhz r10,PACA_IN_NMI(r13)1068addi r10,r10,11069sth r10,PACA_IN_NMI(r13)10701071mr r10,r11072ld r1,PACA_NMI_EMERG_SP(r13)1073subi r1,r1,INT_FRAME_SIZE1074__GEN_COMMON_BODY system_reset10751076addi r3,r1,STACK_INT_FRAME_REGS1077bl CFUNC(system_reset_exception)10781079/* Clear MSR_RI before setting SRR0 and SRR1. */1080li r9,01081mtmsrd r9,110821083/*1084* MSR_RI is clear, now we can decrement paca->in_nmi.1085*/1086lhz r10,PACA_IN_NMI(r13)1087subi r10,r10,11088sth r10,PACA_IN_NMI(r13)10891090kuap_kernel_restore r9, r101091EXCEPTION_RESTORE_REGS1092RFI_TO_USER_OR_KERNEL109310941095/**1096* Interrupt 0x200 - Machine Check Interrupt (MCE).1097* This is a non-maskable interrupt always taken in real-mode. It can be1098* synchronous or asynchronous, caused by hardware or software, and it may be1099* taken in a power-saving state.1100*1101* Handling:1102* Similarly to system reset, this uses its own stack and PACA save area,1103* the difference is re-entrancy is allowed on the machine check stack.1104*1105* machine_check_early is run in real mode, and carefully decodes the1106* machine check and tries to handle it (e.g., flush the SLB if there was an1107* error detected there), determines if it was recoverable and logs the1108* event.1109*1110* This early code does not "reconcile" irq soft-mask state like SRESET or1111* regular interrupts do, so irqs_disabled() among other things may not work1112* properly (irq disable/enable already doesn't work because irq tracing can1113* not work in real mode).1114*1115* Then, depending on the execution context when the interrupt is taken, there1116* are 3 main actions:1117* - Executing in kernel mode. The event is queued with irq_work, which means1118* it is handled when it is next safe to do so (i.e., the kernel has enabled1119* interrupts), which could be immediately when the interrupt returns. This1120* avoids nasty issues like switching to virtual mode when the MMU is in a1121* bad state, or when executing OPAL code. (SRESET is exposed to such issues,1122* but it has different priorities). Check to see if the CPU was in power1123* save, and return via the wake up code if it was.1124*1125* - Executing in user mode. machine_check_exception is run like a normal1126* interrupt handler, which processes the data generated by the early handler.1127*1128* - Executing in guest mode. The interrupt is run with its KVM test, and1129* branches to KVM to deal with. KVM may queue the event for the host1130* to report later.1131*1132* This interrupt is not maskable, so if it triggers when MSR[RI] is clear,1133* or SCRATCH0 is in use, it may cause a crash.1134*1135* KVM:1136* See SRESET.1137*/1138INT_DEFINE_BEGIN(machine_check_early)1139IVEC=0x2001140IAREA=PACA_EXMC1141IVIRT=0 /* no virt entry point */1142IREALMODE_COMMON=11143ISTACK=01144IDAR=11145IDSISR=11146IKUAP=0 /* We don't touch AMR here, we never go to virtual mode */1147INT_DEFINE_END(machine_check_early)11481149INT_DEFINE_BEGIN(machine_check)1150IVEC=0x2001151IAREA=PACA_EXMC1152IVIRT=0 /* no virt entry point */1153IDAR=11154IDSISR=11155IKVM_REAL=11156INT_DEFINE_END(machine_check)11571158EXC_REAL_BEGIN(machine_check, 0x200, 0x100)1159EARLY_BOOT_FIXUP1160GEN_INT_ENTRY machine_check_early, virt=01161EXC_REAL_END(machine_check, 0x200, 0x100)1162EXC_VIRT_NONE(0x4200, 0x100)11631164#ifdef CONFIG_PPC_PSERIES1165TRAMP_REAL_BEGIN(machine_check_fwnmi)1166/* See comment at machine_check exception, don't turn on RI */1167GEN_INT_ENTRY machine_check_early, virt=01168#endif11691170#define MACHINE_CHECK_HANDLER_WINDUP \1171/* Clear MSR_RI before setting SRR0 and SRR1. */\1172li r9,0; \1173mtmsrd r9,1; /* Clear MSR_RI */ \1174/* Decrement paca->in_mce now RI is clear. */ \1175lhz r12,PACA_IN_MCE(r13); \1176subi r12,r12,1; \1177sth r12,PACA_IN_MCE(r13); \1178EXCEPTION_RESTORE_REGS11791180EXC_COMMON_BEGIN(machine_check_early_common)1181__GEN_REALMODE_COMMON_ENTRY machine_check_early11821183/*1184* Switch to mc_emergency stack and handle re-entrancy (we limit1185* the nested MCE upto level 4 to avoid stack overflow).1186* Save MCE registers srr1, srr0, dar and dsisr and then set ME=11187*1188* We use paca->in_mce to check whether this is the first entry or1189* nested machine check. We increment paca->in_mce to track nested1190* machine checks.1191*1192* If this is the first entry then set stack pointer to1193* paca->mc_emergency_sp, otherwise r1 is already pointing to1194* stack frame on mc_emergency stack.1195*1196* NOTE: We are here with MSR_ME=0 (off), which means we risk a1197* checkstop if we get another machine check exception before we do1198* rfid with MSR_ME=1.1199*1200* This interrupt can wake directly from idle. If that is the case,1201* the machine check is handled then the idle wakeup code is called1202* to restore state.1203*/1204lhz r10,PACA_IN_MCE(r13)1205cmpwi r10,0 /* Are we in nested machine check */1206cmpwi cr1,r10,MAX_MCE_DEPTH /* Are we at maximum nesting */1207addi r10,r10,1 /* increment paca->in_mce */1208sth r10,PACA_IN_MCE(r13)12091210mr r10,r1 /* Save r1 */1211bne 1f1212/* First machine check entry */1213ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */12141: /* Limit nested MCE to level 4 to avoid stack overflow */1215bgt cr1,unrecoverable_mce /* Check if we hit limit of 4 */1216subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */12171218__GEN_COMMON_BODY machine_check_early12191220BEGIN_FTR_SECTION1221bl enable_machine_check1222END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)1223addi r3,r1,STACK_INT_FRAME_REGS1224BEGIN_FTR_SECTION1225bl CFUNC(machine_check_early_boot)1226END_FTR_SECTION(0, 1) // nop out after boot1227bl CFUNC(machine_check_early)1228std r3,RESULT(r1) /* Save result */1229ld r12,_MSR(r1)12301231#ifdef CONFIG_PPC_P7_NAP1232/*1233* Check if thread was in power saving mode. We come here when any1234* of the following is true:1235* a. thread wasn't in power saving mode1236* b. thread was in power saving mode with no state loss,1237* supervisor state loss or hypervisor state loss.1238*1239* Go back to nap/sleep/winkle mode again if (b) is true.1240*/1241BEGIN_FTR_SECTION1242rlwinm. r11,r12,47-31,30,311243bne machine_check_idle_common1244END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)1245#endif12461247#ifdef CONFIG_KVM_BOOK3S_64_HANDLER1248/*1249* Check if we are coming from guest. If yes, then run the normal1250* exception handler which will take the1251* machine_check_kvm->kvm_interrupt branch to deliver the MC event1252* to guest.1253*/1254lbz r11,HSTATE_IN_GUEST(r13)1255cmpwi r11,0 /* Check if coming from guest */1256bne mce_deliver /* continue if we are. */1257#endif12581259/*1260* Check if we are coming from userspace. If yes, then run the normal1261* exception handler which will deliver the MC event to this kernel.1262*/1263andi. r11,r12,MSR_PR /* See if coming from user. */1264bne mce_deliver /* continue in V mode if we are. */12651266/*1267* At this point we are coming from kernel context.1268* Queue up the MCE event and return from the interrupt.1269* But before that, check if this is an un-recoverable exception.1270* If yes, then stay on emergency stack and panic.1271*/1272andi. r11,r12,MSR_RI1273beq unrecoverable_mce12741275/*1276* Check if we have successfully handled/recovered from error, if not1277* then stay on emergency stack and panic.1278*/1279ld r3,RESULT(r1) /* Load result */1280cmpdi r3,0 /* see if we handled MCE successfully */1281beq unrecoverable_mce /* if !handled then panic */12821283/*1284* Return from MC interrupt.1285* Queue up the MCE event so that we can log it later, while1286* returning from kernel or opal call.1287*/1288bl CFUNC(machine_check_queue_event)1289MACHINE_CHECK_HANDLER_WINDUP1290RFI_TO_KERNEL12911292mce_deliver:1293/*1294* This is a host user or guest MCE. Restore all registers, then1295* run the "late" handler. For host user, this will run the1296* machine_check_exception handler in virtual mode like a normal1297* interrupt handler. For guest, this will trigger the KVM test1298* and branch to the KVM interrupt similarly to other interrupts.1299*/1300BEGIN_FTR_SECTION1301ld r10,ORIG_GPR3(r1)1302mtspr SPRN_CFAR,r101303END_FTR_SECTION_IFSET(CPU_FTR_CFAR)1304MACHINE_CHECK_HANDLER_WINDUP1305GEN_INT_ENTRY machine_check, virt=013061307EXC_COMMON_BEGIN(machine_check_common)1308/*1309* Machine check is different because we use a different1310* save area: PACA_EXMC instead of PACA_EXGEN.1311*/1312GEN_COMMON machine_check1313addi r3,r1,STACK_INT_FRAME_REGS1314bl CFUNC(machine_check_exception_async)1315b interrupt_return_srr131613171318#ifdef CONFIG_PPC_P7_NAP1319/*1320* This is an idle wakeup. Low level machine check has already been1321* done. Queue the event then call the idle code to do the wake up.1322*/1323EXC_COMMON_BEGIN(machine_check_idle_common)1324bl CFUNC(machine_check_queue_event)13251326/*1327* GPR-loss wakeups are relatively straightforward, because the1328* idle sleep code has saved all non-volatile registers on its1329* own stack, and r1 in PACAR1.1330*1331* For no-loss wakeups the r1 and lr registers used by the1332* early machine check handler have to be restored first. r2 is1333* the kernel TOC, so no need to restore it.1334*1335* Then decrement MCE nesting after finishing with the stack.1336*/1337ld r3,_MSR(r1)1338ld r4,_LINK(r1)1339ld r1,GPR1(r1)13401341lhz r11,PACA_IN_MCE(r13)1342subi r11,r11,11343sth r11,PACA_IN_MCE(r13)13441345mtlr r41346rlwinm r10,r3,47-31,30,311347cmpwi cr1,r10,21348bltlr cr1 /* no state loss, return to idle caller with r3=SRR1 */1349b idle_return_gpr_loss1350#endif13511352EXC_COMMON_BEGIN(unrecoverable_mce)1353/*1354* We are going down. But there are chances that we might get hit by1355* another MCE during panic path and we may run into unstable state1356* with no way out. Hence, turn ME bit off while going down, so that1357* when another MCE is hit during panic path, system will checkstop1358* and hypervisor will get restarted cleanly by SP.1359*/1360BEGIN_FTR_SECTION1361li r10,0 /* clear MSR_RI */1362mtmsrd r10,11363bl CFUNC(disable_machine_check)1364END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)1365ld r10,PACAKMSR(r13)1366li r3,MSR_ME1367andc r10,r10,r31368mtmsrd r1013691370lhz r12,PACA_IN_MCE(r13)1371subi r12,r12,11372sth r12,PACA_IN_MCE(r13)13731374/*1375* Invoke machine_check_exception to print MCE event and panic.1376* This is the NMI version of the handler because we are called from1377* the early handler which is a true NMI.1378*/1379addi r3,r1,STACK_INT_FRAME_REGS1380bl CFUNC(machine_check_exception)13811382/*1383* We will not reach here. Even if we did, there is no way out.1384* Call unrecoverable_exception and die.1385*/1386addi r3,r1,STACK_INT_FRAME_REGS1387bl CFUNC(unrecoverable_exception)1388b .138913901391/**1392* Interrupt 0x300 - Data Storage Interrupt (DSI).1393* This is a synchronous interrupt generated due to a data access exception,1394* e.g., a load orstore which does not have a valid page table entry with1395* permissions. DAWR matches also fault here, as do RC updates, and minor misc1396* errors e.g., copy/paste, AMO, certain invalid CI accesses, etc.1397*1398* Handling:1399* - Hash MMU1400* Go to do_hash_fault, which attempts to fill the HPT from an entry in the1401* Linux page table. Hash faults can hit in kernel mode in a fairly1402* arbitrary state (e.g., interrupts disabled, locks held) when accessing1403* "non-bolted" regions, e.g., vmalloc space. However these should always be1404* backed by Linux page table entries.1405*1406* If no entry is found the Linux page fault handler is invoked (by1407* do_hash_fault). Linux page faults can happen in kernel mode due to user1408* copy operations of course.1409*1410* KVM: The KVM HDSI handler may perform a load with MSR[DR]=1 in guest1411* MMU context, which may cause a DSI in the host, which must go to the1412* KVM handler. MSR[IR] is not enabled, so the real-mode handler will1413* always be used regardless of AIL setting.1414*1415* - Radix MMU1416* The hardware loads from the Linux page table directly, so a fault goes1417* immediately to Linux page fault.1418*1419* Conditions like DAWR match are handled on the way in to Linux page fault.1420*/1421INT_DEFINE_BEGIN(data_access)1422IVEC=0x3001423IDAR=11424IDSISR=11425IKVM_REAL=11426INT_DEFINE_END(data_access)14271428EXC_REAL_BEGIN(data_access, 0x300, 0x80)1429GEN_INT_ENTRY data_access, virt=01430EXC_REAL_END(data_access, 0x300, 0x80)1431EXC_VIRT_BEGIN(data_access, 0x4300, 0x80)1432GEN_INT_ENTRY data_access, virt=11433EXC_VIRT_END(data_access, 0x4300, 0x80)1434EXC_COMMON_BEGIN(data_access_common)1435GEN_COMMON data_access1436ld r4,_DSISR(r1)1437addi r3,r1,STACK_INT_FRAME_REGS1438andis. r0,r4,DSISR_DABRMATCH@h1439bne- 1f1440#ifdef CONFIG_PPC_64S_HASH_MMU1441BEGIN_MMU_FTR_SECTION1442bl CFUNC(do_hash_fault)1443MMU_FTR_SECTION_ELSE1444bl CFUNC(do_page_fault)1445ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)1446#else1447bl CFUNC(do_page_fault)1448#endif1449b interrupt_return_srr145014511: bl CFUNC(do_break)1452/*1453* do_break() may have changed the NV GPRS while handling a breakpoint.1454* If so, we need to restore them with their updated values.1455*/1456HANDLER_RESTORE_NVGPRS()1457b interrupt_return_srr145814591460/**1461* Interrupt 0x380 - Data Segment Interrupt (DSLB).1462* This is a synchronous interrupt in response to an MMU fault missing SLB1463* entry for HPT, or an address outside RPT translation range.1464*1465* Handling:1466* - HPT:1467* This refills the SLB, or reports an access fault similarly to a bad page1468* fault. When coming from user-mode, the SLB handler may access any kernel1469* data, though it may itself take a DSLB. When coming from kernel mode,1470* recursive faults must be avoided so access is restricted to the kernel1471* image text/data, kernel stack, and any data allocated below1472* ppc64_bolted_size (first segment). The kernel handler must avoid stomping1473* on user-handler data structures.1474*1475* KVM: Same as 0x300, DSLB must test for KVM guest.1476*/1477INT_DEFINE_BEGIN(data_access_slb)1478IVEC=0x3801479IDAR=11480IKVM_REAL=11481INT_DEFINE_END(data_access_slb)14821483EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)1484GEN_INT_ENTRY data_access_slb, virt=01485EXC_REAL_END(data_access_slb, 0x380, 0x80)1486EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)1487GEN_INT_ENTRY data_access_slb, virt=11488EXC_VIRT_END(data_access_slb, 0x4380, 0x80)1489EXC_COMMON_BEGIN(data_access_slb_common)1490GEN_COMMON data_access_slb1491#ifdef CONFIG_PPC_64S_HASH_MMU1492BEGIN_MMU_FTR_SECTION1493/* HPT case, do SLB fault */1494addi r3,r1,STACK_INT_FRAME_REGS1495bl CFUNC(do_slb_fault)1496cmpdi r3,01497bne- 1f1498b fast_interrupt_return_srr14991: /* Error case */1500MMU_FTR_SECTION_ELSE1501/* Radix case, access is outside page table range */1502li r3,-EFAULT1503ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)1504#else1505li r3,-EFAULT1506#endif1507std r3,RESULT(r1)1508addi r3,r1,STACK_INT_FRAME_REGS1509bl CFUNC(do_bad_segment_interrupt)1510b interrupt_return_srr151115121513/**1514* Interrupt 0x400 - Instruction Storage Interrupt (ISI).1515* This is a synchronous interrupt in response to an MMU fault due to an1516* instruction fetch.1517*1518* Handling:1519* Similar to DSI, though in response to fetch. The faulting address is found1520* in SRR0 (rather than DAR), and status in SRR1 (rather than DSISR).1521*/1522INT_DEFINE_BEGIN(instruction_access)1523IVEC=0x4001524IISIDE=11525IDAR=11526IDSISR=11527#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE1528IKVM_REAL=11529#endif1530INT_DEFINE_END(instruction_access)15311532EXC_REAL_BEGIN(instruction_access, 0x400, 0x80)1533GEN_INT_ENTRY instruction_access, virt=01534EXC_REAL_END(instruction_access, 0x400, 0x80)1535EXC_VIRT_BEGIN(instruction_access, 0x4400, 0x80)1536GEN_INT_ENTRY instruction_access, virt=11537EXC_VIRT_END(instruction_access, 0x4400, 0x80)1538EXC_COMMON_BEGIN(instruction_access_common)1539GEN_COMMON instruction_access1540addi r3,r1,STACK_INT_FRAME_REGS1541#ifdef CONFIG_PPC_64S_HASH_MMU1542BEGIN_MMU_FTR_SECTION1543bl CFUNC(do_hash_fault)1544MMU_FTR_SECTION_ELSE1545bl CFUNC(do_page_fault)1546ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)1547#else1548bl CFUNC(do_page_fault)1549#endif1550b interrupt_return_srr155115521553/**1554* Interrupt 0x480 - Instruction Segment Interrupt (ISLB).1555* This is a synchronous interrupt in response to an MMU fault due to an1556* instruction fetch.1557*1558* Handling:1559* Similar to DSLB, though in response to fetch. The faulting address is found1560* in SRR0 (rather than DAR).1561*/1562INT_DEFINE_BEGIN(instruction_access_slb)1563IVEC=0x4801564IISIDE=11565IDAR=11566#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE1567IKVM_REAL=11568#endif1569INT_DEFINE_END(instruction_access_slb)15701571EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80)1572GEN_INT_ENTRY instruction_access_slb, virt=01573EXC_REAL_END(instruction_access_slb, 0x480, 0x80)1574EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)1575GEN_INT_ENTRY instruction_access_slb, virt=11576EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80)1577EXC_COMMON_BEGIN(instruction_access_slb_common)1578GEN_COMMON instruction_access_slb1579#ifdef CONFIG_PPC_64S_HASH_MMU1580BEGIN_MMU_FTR_SECTION1581/* HPT case, do SLB fault */1582addi r3,r1,STACK_INT_FRAME_REGS1583bl CFUNC(do_slb_fault)1584cmpdi r3,01585bne- 1f1586b fast_interrupt_return_srr15871: /* Error case */1588MMU_FTR_SECTION_ELSE1589/* Radix case, access is outside page table range */1590li r3,-EFAULT1591ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)1592#else1593li r3,-EFAULT1594#endif1595std r3,RESULT(r1)1596addi r3,r1,STACK_INT_FRAME_REGS1597bl CFUNC(do_bad_segment_interrupt)1598b interrupt_return_srr159916001601/**1602* Interrupt 0x500 - External Interrupt.1603* This is an asynchronous maskable interrupt in response to an "external1604* exception" from the interrupt controller or hypervisor (e.g., device1605* interrupt). It is maskable in hardware by clearing MSR[EE], and1606* soft-maskable with IRQS_DISABLED mask (i.e., local_irq_disable()).1607*1608* When running in HV mode, Linux sets up the LPCR[LPES] bit such that1609* interrupts are delivered with HSRR registers, guests use SRRs, which1610* reqiures IHSRR_IF_HVMODE.1611*1612* On bare metal POWER9 and later, Linux sets the LPCR[HVICE] bit such that1613* external interrupts are delivered as Hypervisor Virtualization Interrupts1614* rather than External Interrupts.1615*1616* Handling:1617* This calls into Linux IRQ handler. NVGPRs are not saved to reduce overhead,1618* because registers at the time of the interrupt are not so important as it is1619* asynchronous.1620*1621* If soft masked, the masked handler will note the pending interrupt for1622* replay, and clear MSR[EE] in the interrupted context.1623*1624* CFAR is not required because this is an asynchronous interrupt that in1625* general won't have much bearing on the state of the CPU, with the possible1626* exception of crash/debug IPIs, but those are generally moving to use SRESET1627* IPIs. Unless this is an HV interrupt and KVM HV is possible, in which case1628* it may be exiting the guest and need CFAR to be saved.1629*/1630INT_DEFINE_BEGIN(hardware_interrupt)1631IVEC=0x5001632IHSRR_IF_HVMODE=11633IMASK=IRQS_DISABLED1634IKVM_REAL=11635IKVM_VIRT=11636ICFAR=01637#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE1638ICFAR_IF_HVMODE=11639#endif1640INT_DEFINE_END(hardware_interrupt)16411642EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)1643GEN_INT_ENTRY hardware_interrupt, virt=01644EXC_REAL_END(hardware_interrupt, 0x500, 0x100)1645EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)1646GEN_INT_ENTRY hardware_interrupt, virt=11647EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)1648EXC_COMMON_BEGIN(hardware_interrupt_common)1649GEN_COMMON hardware_interrupt1650addi r3,r1,STACK_INT_FRAME_REGS1651bl CFUNC(do_IRQ)1652BEGIN_FTR_SECTION1653b interrupt_return_hsrr1654FTR_SECTION_ELSE1655b interrupt_return_srr1656ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)165716581659/**1660* Interrupt 0x600 - Alignment Interrupt1661* This is a synchronous interrupt in response to data alignment fault.1662*/1663INT_DEFINE_BEGIN(alignment)1664IVEC=0x6001665IDAR=11666IDSISR=11667#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE1668IKVM_REAL=11669#endif1670INT_DEFINE_END(alignment)16711672EXC_REAL_BEGIN(alignment, 0x600, 0x100)1673GEN_INT_ENTRY alignment, virt=01674EXC_REAL_END(alignment, 0x600, 0x100)1675EXC_VIRT_BEGIN(alignment, 0x4600, 0x100)1676GEN_INT_ENTRY alignment, virt=11677EXC_VIRT_END(alignment, 0x4600, 0x100)1678EXC_COMMON_BEGIN(alignment_common)1679GEN_COMMON alignment1680addi r3,r1,STACK_INT_FRAME_REGS1681bl CFUNC(alignment_exception)1682HANDLER_RESTORE_NVGPRS() /* instruction emulation may change GPRs */1683b interrupt_return_srr168416851686/**1687* Interrupt 0x700 - Program Interrupt (program check).1688* This is a synchronous interrupt in response to various instruction faults:1689* traps, privilege errors, TM errors, floating point exceptions.1690*1691* Handling:1692* This interrupt may use the "emergency stack" in some cases when being taken1693* from kernel context, which complicates handling.1694*/1695INT_DEFINE_BEGIN(program_check)1696IVEC=0x7001697#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE1698IKVM_REAL=11699#endif1700INT_DEFINE_END(program_check)17011702EXC_REAL_BEGIN(program_check, 0x700, 0x100)1703EARLY_BOOT_FIXUP1704GEN_INT_ENTRY program_check, virt=01705EXC_REAL_END(program_check, 0x700, 0x100)1706EXC_VIRT_BEGIN(program_check, 0x4700, 0x100)1707GEN_INT_ENTRY program_check, virt=11708EXC_VIRT_END(program_check, 0x4700, 0x100)1709EXC_COMMON_BEGIN(program_check_common)1710__GEN_COMMON_ENTRY program_check17111712/*1713* It's possible to receive a TM Bad Thing type program check with1714* userspace register values (in particular r1), but with SRR1 reporting1715* that we came from the kernel. Normally that would confuse the bad1716* stack logic, and we would report a bad kernel stack pointer. Instead1717* we switch to the emergency stack if we're taking a TM Bad Thing from1718* the kernel.1719*/17201721andi. r10,r12,MSR_PR1722bne .Lnormal_stack /* If userspace, go normal path */17231724andis. r10,r12,(SRR1_PROGTM)@h1725bne .Lemergency_stack /* If TM, emergency */17261727cmpdi r1,-INT_FRAME_SIZE /* check if r1 is in userspace */1728blt .Lnormal_stack /* normal path if not */17291730/* Use the emergency stack */1731.Lemergency_stack:1732andi. r10,r12,MSR_PR /* Set CR0 correctly for label */1733/* 3 in EXCEPTION_PROLOG_COMMON */1734mr r10,r1 /* Save r1 */1735ld r1,PACAEMERGSP(r13) /* Use emergency stack */1736subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */1737__ISTACK(program_check)=01738__GEN_COMMON_BODY program_check1739b .Ldo_program_check17401741.Lnormal_stack:1742__ISTACK(program_check)=11743__GEN_COMMON_BODY program_check17441745.Ldo_program_check:1746addi r3,r1,STACK_INT_FRAME_REGS1747bl CFUNC(program_check_exception)1748HANDLER_RESTORE_NVGPRS() /* instruction emulation may change GPRs */1749b interrupt_return_srr175017511752/*1753* Interrupt 0x800 - Floating-Point Unavailable Interrupt.1754* This is a synchronous interrupt in response to executing an fp instruction1755* with MSR[FP]=0.1756*1757* Handling:1758* This will load FP registers and enable the FP bit if coming from userspace,1759* otherwise report a bad kernel use of FP.1760*/1761INT_DEFINE_BEGIN(fp_unavailable)1762IVEC=0x8001763#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE1764IKVM_REAL=11765#endif1766IMSR_R12=11767INT_DEFINE_END(fp_unavailable)17681769EXC_REAL_BEGIN(fp_unavailable, 0x800, 0x100)1770GEN_INT_ENTRY fp_unavailable, virt=01771EXC_REAL_END(fp_unavailable, 0x800, 0x100)1772EXC_VIRT_BEGIN(fp_unavailable, 0x4800, 0x100)1773GEN_INT_ENTRY fp_unavailable, virt=11774EXC_VIRT_END(fp_unavailable, 0x4800, 0x100)1775EXC_COMMON_BEGIN(fp_unavailable_common)1776GEN_COMMON fp_unavailable1777bne 1f /* if from user, just load it up */1778addi r3,r1,STACK_INT_FRAME_REGS1779bl CFUNC(kernel_fp_unavailable_exception)17800: trap1781EMIT_BUG_ENTRY 0b, __FILE__, __LINE__, 017821:1783#ifdef CONFIG_PPC_TRANSACTIONAL_MEM1784BEGIN_FTR_SECTION1785/* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in1786* transaction), go do TM stuff1787*/1788rldicl. r0, r12, (64-MSR_TS_LG), (64-2)1789bne- 2f1790END_FTR_SECTION_IFSET(CPU_FTR_TM)1791#endif1792bl CFUNC(load_up_fpu)1793b fast_interrupt_return_srr1794#ifdef CONFIG_PPC_TRANSACTIONAL_MEM17952: /* User process was in a transaction */1796addi r3,r1,STACK_INT_FRAME_REGS1797bl CFUNC(fp_unavailable_tm)1798b interrupt_return_srr1799#endif180018011802/**1803* Interrupt 0x900 - Decrementer Interrupt.1804* This is an asynchronous interrupt in response to a decrementer exception1805* (e.g., DEC has wrapped below zero). It is maskable in hardware by clearing1806* MSR[EE], and soft-maskable with IRQS_DISABLED mask (i.e.,1807* local_irq_disable()).1808*1809* Handling:1810* This calls into Linux timer handler. NVGPRs are not saved (see 0x500).1811*1812* If soft masked, the masked handler will note the pending interrupt for1813* replay, and bump the decrementer to a high value, leaving MSR[EE] enabled1814* in the interrupted context.1815* If PPC_WATCHDOG is configured, the soft masked handler will actually set1816* things back up to run soft_nmi_interrupt as a regular interrupt handler1817* on the emergency stack.1818*1819* CFAR is not required because this is asynchronous (see hardware_interrupt).1820* A watchdog interrupt may like to have CFAR, but usually the interesting1821* branch is long gone by that point (e.g., infinite loop).1822*/1823INT_DEFINE_BEGIN(decrementer)1824IVEC=0x9001825IMASK=IRQS_DISABLED1826#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE1827IKVM_REAL=11828#endif1829ICFAR=01830INT_DEFINE_END(decrementer)18311832EXC_REAL_BEGIN(decrementer, 0x900, 0x80)1833GEN_INT_ENTRY decrementer, virt=01834EXC_REAL_END(decrementer, 0x900, 0x80)1835EXC_VIRT_BEGIN(decrementer, 0x4900, 0x80)1836GEN_INT_ENTRY decrementer, virt=11837EXC_VIRT_END(decrementer, 0x4900, 0x80)1838EXC_COMMON_BEGIN(decrementer_common)1839GEN_COMMON decrementer1840addi r3,r1,STACK_INT_FRAME_REGS1841bl CFUNC(timer_interrupt)1842b interrupt_return_srr184318441845/**1846* Interrupt 0x980 - Hypervisor Decrementer Interrupt.1847* This is an asynchronous interrupt, similar to 0x900 but for the HDEC1848* register.1849*1850* Handling:1851* Linux does not use this outside KVM where it's used to keep a host timer1852* while the guest is given control of DEC. It should normally be caught by1853* the KVM test and routed there.1854*/1855INT_DEFINE_BEGIN(hdecrementer)1856IVEC=0x9801857IHSRR=11858ISTACK=01859IKVM_REAL=11860IKVM_VIRT=11861INT_DEFINE_END(hdecrementer)18621863EXC_REAL_BEGIN(hdecrementer, 0x980, 0x80)1864GEN_INT_ENTRY hdecrementer, virt=01865EXC_REAL_END(hdecrementer, 0x980, 0x80)1866EXC_VIRT_BEGIN(hdecrementer, 0x4980, 0x80)1867GEN_INT_ENTRY hdecrementer, virt=11868EXC_VIRT_END(hdecrementer, 0x4980, 0x80)1869EXC_COMMON_BEGIN(hdecrementer_common)1870__GEN_COMMON_ENTRY hdecrementer1871/*1872* Hypervisor decrementer interrupts not caught by the KVM test1873* shouldn't occur but are sometimes left pending on exit from a KVM1874* guest. We don't need to do anything to clear them, as they are1875* edge-triggered.1876*1877* Be careful to avoid touching the kernel stack.1878*/1879li r10,01880stb r10,PACAHSRR_VALID(r13)1881ld r10,PACA_EXGEN+EX_CTR(r13)1882mtctr r101883mtcrf 0x80,r91884ld r9,PACA_EXGEN+EX_R9(r13)1885ld r10,PACA_EXGEN+EX_R10(r13)1886ld r11,PACA_EXGEN+EX_R11(r13)1887ld r12,PACA_EXGEN+EX_R12(r13)1888ld r13,PACA_EXGEN+EX_R13(r13)1889HRFI_TO_KERNEL189018911892/**1893* Interrupt 0xa00 - Directed Privileged Doorbell Interrupt.1894* This is an asynchronous interrupt in response to a msgsndp doorbell.1895* It is maskable in hardware by clearing MSR[EE], and soft-maskable with1896* IRQS_DISABLED mask (i.e., local_irq_disable()).1897*1898* Handling:1899* Guests may use this for IPIs between threads in a core if the1900* hypervisor supports it. NVGPRS are not saved (see 0x500).1901*1902* If soft masked, the masked handler will note the pending interrupt for1903* replay, leaving MSR[EE] enabled in the interrupted context because the1904* doorbells are edge triggered.1905*1906* CFAR is not required, similarly to hardware_interrupt.1907*/1908INT_DEFINE_BEGIN(doorbell_super)1909IVEC=0xa001910IMASK=IRQS_DISABLED1911#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE1912IKVM_REAL=11913#endif1914ICFAR=01915INT_DEFINE_END(doorbell_super)19161917EXC_REAL_BEGIN(doorbell_super, 0xa00, 0x100)1918GEN_INT_ENTRY doorbell_super, virt=01919EXC_REAL_END(doorbell_super, 0xa00, 0x100)1920EXC_VIRT_BEGIN(doorbell_super, 0x4a00, 0x100)1921GEN_INT_ENTRY doorbell_super, virt=11922EXC_VIRT_END(doorbell_super, 0x4a00, 0x100)1923EXC_COMMON_BEGIN(doorbell_super_common)1924GEN_COMMON doorbell_super1925addi r3,r1,STACK_INT_FRAME_REGS1926#ifdef CONFIG_PPC_DOORBELL1927bl CFUNC(doorbell_exception)1928#else1929bl CFUNC(unknown_async_exception)1930#endif1931b interrupt_return_srr193219331934EXC_REAL_NONE(0xb00, 0x100)1935EXC_VIRT_NONE(0x4b00, 0x100)19361937/**1938* Interrupt 0xc00 - System Call Interrupt (syscall, hcall).1939* This is a synchronous interrupt invoked with the "sc" instruction. The1940* system call is invoked with "sc 0" and does not alter the HV bit, so it1941* is directed to the currently running OS. The hypercall is invoked with1942* "sc 1" and it sets HV=1, so it elevates to hypervisor.1943*1944* In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to1945* 0x4c00 virtual mode.1946*1947* Handling:1948* If the KVM test fires then it was due to a hypercall and is accordingly1949* routed to KVM. Otherwise this executes a normal Linux system call.1950*1951* Call convention:1952*1953* syscall and hypercalls register conventions are documented in1954* Documentation/arch/powerpc/syscall64-abi.rst and1955* Documentation/arch/powerpc/papr_hcalls.rst respectively.1956*1957* The intersection of volatile registers that don't contain possible1958* inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry1959* without saving, though xer is not a good idea to use, as hardware may1960* interpret some bits so it may be costly to change them.1961*/1962INT_DEFINE_BEGIN(system_call)1963IVEC=0xc001964IKVM_REAL=11965IKVM_VIRT=11966ICFAR=01967INT_DEFINE_END(system_call)19681969.macro SYSTEM_CALL virt1970#ifdef CONFIG_KVM_BOOK3S_64_HANDLER1971/*1972* There is a little bit of juggling to get syscall and hcall1973* working well. Save r13 in ctr to avoid using SPRG scratch1974* register.1975*1976* Userspace syscalls have already saved the PPR, hcalls must save1977* it before setting HMT_MEDIUM.1978*/1979mtctr r131980GET_PACA(r13)1981std r10,PACA_EXGEN+EX_R10(r13)1982INTERRUPT_TO_KERNEL1983KVMTEST system_call kvm_hcall /* uses r10, branch to kvm_hcall */1984mfctr r91985#else1986mr r9,r131987GET_PACA(r13)1988INTERRUPT_TO_KERNEL1989#endif19901991/* We reach here with PACA in r13, r13 in r9. */1992mfspr r11,SPRN_SRR01993mfspr r12,SPRN_SRR119941995HMT_MEDIUM19961997.if ! \virt1998__LOAD_HANDLER(r10, system_call_common_real, real_vectors)1999mtctr r102000bctr2001.else2002#ifdef CONFIG_RELOCATABLE2003__LOAD_HANDLER(r10, system_call_common, virt_vectors)2004mtctr r102005bctr2006#else2007b system_call_common2008#endif2009.endif2010.endm20112012EXC_REAL_BEGIN(system_call, 0xc00, 0x100)2013SYSTEM_CALL 02014EXC_REAL_END(system_call, 0xc00, 0x100)2015EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)2016SYSTEM_CALL 12017EXC_VIRT_END(system_call, 0x4c00, 0x100)20182019#ifdef CONFIG_KVM_BOOK3S_64_HANDLER2020TRAMP_REAL_BEGIN(kvm_hcall)2021std r9,PACA_EXGEN+EX_R9(r13)2022std r11,PACA_EXGEN+EX_R11(r13)2023std r12,PACA_EXGEN+EX_R12(r13)2024mfcr r92025mfctr r102026std r10,PACA_EXGEN+EX_R13(r13)2027li r10,02028std r10,PACA_EXGEN+EX_CFAR(r13)2029std r10,PACA_EXGEN+EX_CTR(r13)2030/*2031* Save the PPR (on systems that support it) before changing to2032* HMT_MEDIUM. That allows the KVM code to save that value into the2033* guest state (it is the guest's PPR value).2034*/2035BEGIN_FTR_SECTION2036mfspr r10,SPRN_PPR2037std r10,PACA_EXGEN+EX_PPR(r13)2038END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)20392040HMT_MEDIUM20412042#ifdef CONFIG_RELOCATABLE2043/*2044* Requires __LOAD_FAR_HANDLER beause kvmppc_hcall lives2045* outside the head section.2046*/2047__LOAD_FAR_HANDLER(r10, kvmppc_hcall, real_trampolines)2048mtctr r102049bctr2050#else2051b kvmppc_hcall2052#endif2053#endif20542055/**2056* Interrupt 0xd00 - Trace Interrupt.2057* This is a synchronous interrupt in response to instruction step or2058* breakpoint faults.2059*/2060INT_DEFINE_BEGIN(single_step)2061IVEC=0xd002062#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE2063IKVM_REAL=12064#endif2065INT_DEFINE_END(single_step)20662067EXC_REAL_BEGIN(single_step, 0xd00, 0x100)2068GEN_INT_ENTRY single_step, virt=02069EXC_REAL_END(single_step, 0xd00, 0x100)2070EXC_VIRT_BEGIN(single_step, 0x4d00, 0x100)2071GEN_INT_ENTRY single_step, virt=12072EXC_VIRT_END(single_step, 0x4d00, 0x100)2073EXC_COMMON_BEGIN(single_step_common)2074GEN_COMMON single_step2075addi r3,r1,STACK_INT_FRAME_REGS2076bl CFUNC(single_step_exception)2077b interrupt_return_srr207820792080/**2081* Interrupt 0xe00 - Hypervisor Data Storage Interrupt (HDSI).2082* This is a synchronous interrupt in response to an MMU fault caused by a2083* guest data access.2084*2085* Handling:2086* This should always get routed to KVM. In radix MMU mode, this is caused2087* by a guest nested radix access that can't be performed due to the2088* partition scope page table. In hash mode, this can be caused by guests2089* running with translation disabled (virtual real mode) or with VPM enabled.2090* KVM will update the page table structures or disallow the access.2091*/2092INT_DEFINE_BEGIN(h_data_storage)2093IVEC=0xe002094IHSRR=12095IDAR=12096IDSISR=12097IKVM_REAL=12098IKVM_VIRT=12099INT_DEFINE_END(h_data_storage)21002101EXC_REAL_BEGIN(h_data_storage, 0xe00, 0x20)2102GEN_INT_ENTRY h_data_storage, virt=0, ool=12103EXC_REAL_END(h_data_storage, 0xe00, 0x20)2104EXC_VIRT_BEGIN(h_data_storage, 0x4e00, 0x20)2105GEN_INT_ENTRY h_data_storage, virt=1, ool=12106EXC_VIRT_END(h_data_storage, 0x4e00, 0x20)2107EXC_COMMON_BEGIN(h_data_storage_common)2108GEN_COMMON h_data_storage2109addi r3,r1,STACK_INT_FRAME_REGS2110BEGIN_MMU_FTR_SECTION2111bl CFUNC(do_bad_page_fault_segv)2112MMU_FTR_SECTION_ELSE2113bl CFUNC(unknown_exception)2114ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_TYPE_RADIX)2115b interrupt_return_hsrr211621172118/**2119* Interrupt 0xe20 - Hypervisor Instruction Storage Interrupt (HISI).2120* This is a synchronous interrupt in response to an MMU fault caused by a2121* guest instruction fetch, similar to HDSI.2122*/2123INT_DEFINE_BEGIN(h_instr_storage)2124IVEC=0xe202125IHSRR=12126IKVM_REAL=12127IKVM_VIRT=12128INT_DEFINE_END(h_instr_storage)21292130EXC_REAL_BEGIN(h_instr_storage, 0xe20, 0x20)2131GEN_INT_ENTRY h_instr_storage, virt=0, ool=12132EXC_REAL_END(h_instr_storage, 0xe20, 0x20)2133EXC_VIRT_BEGIN(h_instr_storage, 0x4e20, 0x20)2134GEN_INT_ENTRY h_instr_storage, virt=1, ool=12135EXC_VIRT_END(h_instr_storage, 0x4e20, 0x20)2136EXC_COMMON_BEGIN(h_instr_storage_common)2137GEN_COMMON h_instr_storage2138addi r3,r1,STACK_INT_FRAME_REGS2139bl CFUNC(unknown_exception)2140b interrupt_return_hsrr214121422143/**2144* Interrupt 0xe40 - Hypervisor Emulation Assistance Interrupt.2145*/2146INT_DEFINE_BEGIN(emulation_assist)2147IVEC=0xe402148IHSRR=12149IKVM_REAL=12150IKVM_VIRT=12151INT_DEFINE_END(emulation_assist)21522153EXC_REAL_BEGIN(emulation_assist, 0xe40, 0x20)2154GEN_INT_ENTRY emulation_assist, virt=0, ool=12155EXC_REAL_END(emulation_assist, 0xe40, 0x20)2156EXC_VIRT_BEGIN(emulation_assist, 0x4e40, 0x20)2157GEN_INT_ENTRY emulation_assist, virt=1, ool=12158EXC_VIRT_END(emulation_assist, 0x4e40, 0x20)2159EXC_COMMON_BEGIN(emulation_assist_common)2160GEN_COMMON emulation_assist2161addi r3,r1,STACK_INT_FRAME_REGS2162bl CFUNC(emulation_assist_interrupt)2163HANDLER_RESTORE_NVGPRS() /* instruction emulation may change GPRs */2164b interrupt_return_hsrr216521662167/**2168* Interrupt 0xe60 - Hypervisor Maintenance Interrupt (HMI).2169* This is an asynchronous interrupt caused by a Hypervisor Maintenance2170* Exception. It is always taken in real mode but uses HSRR registers2171* unlike SRESET and MCE.2172*2173* It is maskable in hardware by clearing MSR[EE], and partially soft-maskable2174* with IRQS_DISABLED mask (i.e., local_irq_disable()).2175*2176* Handling:2177* This is a special case, this is handled similarly to machine checks, with an2178* initial real mode handler that is not soft-masked, which attempts to fix the2179* problem. Then a regular handler which is soft-maskable and reports the2180* problem.2181*2182* The emergency stack is used for the early real mode handler.2183*2184* XXX: unclear why MCE and HMI schemes could not be made common, e.g.,2185* either use soft-masking for the MCE, or use irq_work for the HMI.2186*2187* KVM:2188* Unlike MCE, this calls into KVM without calling the real mode handler2189* first.2190*/2191INT_DEFINE_BEGIN(hmi_exception_early)2192IVEC=0xe602193IHSRR=12194IREALMODE_COMMON=12195ISTACK=02196IKUAP=0 /* We don't touch AMR here, we never go to virtual mode */2197IKVM_REAL=12198INT_DEFINE_END(hmi_exception_early)21992200INT_DEFINE_BEGIN(hmi_exception)2201IVEC=0xe602202IHSRR=12203IMASK=IRQS_DISABLED2204IKVM_REAL=12205INT_DEFINE_END(hmi_exception)22062207EXC_REAL_BEGIN(hmi_exception, 0xe60, 0x20)2208GEN_INT_ENTRY hmi_exception_early, virt=0, ool=12209EXC_REAL_END(hmi_exception, 0xe60, 0x20)2210EXC_VIRT_NONE(0x4e60, 0x20)22112212EXC_COMMON_BEGIN(hmi_exception_early_common)2213__GEN_REALMODE_COMMON_ENTRY hmi_exception_early22142215mr r10,r1 /* Save r1 */2216ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */2217subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */22182219__GEN_COMMON_BODY hmi_exception_early22202221addi r3,r1,STACK_INT_FRAME_REGS2222bl CFUNC(hmi_exception_realmode)2223cmpdi cr0,r3,02224bne 1f22252226EXCEPTION_RESTORE_REGS hsrr=12227HRFI_TO_USER_OR_KERNEL222822291:2230/*2231* Go to virtual mode and pull the HMI event information from2232* firmware.2233*/2234EXCEPTION_RESTORE_REGS hsrr=12235GEN_INT_ENTRY hmi_exception, virt=022362237EXC_COMMON_BEGIN(hmi_exception_common)2238GEN_COMMON hmi_exception2239addi r3,r1,STACK_INT_FRAME_REGS2240bl CFUNC(handle_hmi_exception)2241b interrupt_return_hsrr224222432244/**2245* Interrupt 0xe80 - Directed Hypervisor Doorbell Interrupt.2246* This is an asynchronous interrupt in response to a msgsnd doorbell.2247* Similar to the 0xa00 doorbell but for host rather than guest.2248*2249* CFAR is not required (similar to doorbell_interrupt), unless KVM HV2250* is enabled, in which case it may be a guest exit. Most PowerNV kernels2251* include KVM support so it would be nice if this could be dynamically2252* patched out if KVM was not currently running any guests.2253*/2254INT_DEFINE_BEGIN(h_doorbell)2255IVEC=0xe802256IHSRR=12257IMASK=IRQS_DISABLED2258IKVM_REAL=12259IKVM_VIRT=12260#ifndef CONFIG_KVM_BOOK3S_HV_POSSIBLE2261ICFAR=02262#endif2263INT_DEFINE_END(h_doorbell)22642265EXC_REAL_BEGIN(h_doorbell, 0xe80, 0x20)2266GEN_INT_ENTRY h_doorbell, virt=0, ool=12267EXC_REAL_END(h_doorbell, 0xe80, 0x20)2268EXC_VIRT_BEGIN(h_doorbell, 0x4e80, 0x20)2269GEN_INT_ENTRY h_doorbell, virt=1, ool=12270EXC_VIRT_END(h_doorbell, 0x4e80, 0x20)2271EXC_COMMON_BEGIN(h_doorbell_common)2272GEN_COMMON h_doorbell2273addi r3,r1,STACK_INT_FRAME_REGS2274#ifdef CONFIG_PPC_DOORBELL2275bl CFUNC(doorbell_exception)2276#else2277bl CFUNC(unknown_async_exception)2278#endif2279b interrupt_return_hsrr228022812282/**2283* Interrupt 0xea0 - Hypervisor Virtualization Interrupt.2284* This is an asynchronous interrupt in response to an "external exception".2285* Similar to 0x500 but for host only.2286*2287* Like h_doorbell, CFAR is only required for KVM HV because this can be2288* a guest exit.2289*/2290INT_DEFINE_BEGIN(h_virt_irq)2291IVEC=0xea02292IHSRR=12293IMASK=IRQS_DISABLED2294IKVM_REAL=12295IKVM_VIRT=12296#ifndef CONFIG_KVM_BOOK3S_HV_POSSIBLE2297ICFAR=02298#endif2299INT_DEFINE_END(h_virt_irq)23002301EXC_REAL_BEGIN(h_virt_irq, 0xea0, 0x20)2302GEN_INT_ENTRY h_virt_irq, virt=0, ool=12303EXC_REAL_END(h_virt_irq, 0xea0, 0x20)2304EXC_VIRT_BEGIN(h_virt_irq, 0x4ea0, 0x20)2305GEN_INT_ENTRY h_virt_irq, virt=1, ool=12306EXC_VIRT_END(h_virt_irq, 0x4ea0, 0x20)2307EXC_COMMON_BEGIN(h_virt_irq_common)2308GEN_COMMON h_virt_irq2309addi r3,r1,STACK_INT_FRAME_REGS2310bl CFUNC(do_IRQ)2311b interrupt_return_hsrr231223132314EXC_REAL_NONE(0xec0, 0x20)2315EXC_VIRT_NONE(0x4ec0, 0x20)2316EXC_REAL_NONE(0xee0, 0x20)2317EXC_VIRT_NONE(0x4ee0, 0x20)231823192320/*2321* Interrupt 0xf00 - Performance Monitor Interrupt (PMI, PMU).2322* This is an asynchronous interrupt in response to a PMU exception.2323* It is maskable in hardware by clearing MSR[EE], and soft-maskable with2324* IRQS_PMI_DISABLED mask (NOTE: NOT local_irq_disable()).2325*2326* Handling:2327* This calls into the perf subsystem.2328*2329* Like the watchdog soft-nmi, it appears an NMI interrupt to Linux, in that it2330* runs under local_irq_disable. However it may be soft-masked in2331* powerpc-specific code.2332*2333* If soft masked, the masked handler will note the pending interrupt for2334* replay, and clear MSR[EE] in the interrupted context.2335*2336* CFAR is not used by perf interrupts so not required.2337*/2338INT_DEFINE_BEGIN(performance_monitor)2339IVEC=0xf002340IMASK=IRQS_PMI_DISABLED2341#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE2342IKVM_REAL=12343#endif2344ICFAR=02345INT_DEFINE_END(performance_monitor)23462347EXC_REAL_BEGIN(performance_monitor, 0xf00, 0x20)2348GEN_INT_ENTRY performance_monitor, virt=0, ool=12349EXC_REAL_END(performance_monitor, 0xf00, 0x20)2350EXC_VIRT_BEGIN(performance_monitor, 0x4f00, 0x20)2351GEN_INT_ENTRY performance_monitor, virt=1, ool=12352EXC_VIRT_END(performance_monitor, 0x4f00, 0x20)2353EXC_COMMON_BEGIN(performance_monitor_common)2354GEN_COMMON performance_monitor2355addi r3,r1,STACK_INT_FRAME_REGS2356lbz r4,PACAIRQSOFTMASK(r13)2357cmpdi r4,IRQS_ENABLED2358bne 1f2359bl CFUNC(performance_monitor_exception_async)2360b interrupt_return_srr23611:2362bl CFUNC(performance_monitor_exception_nmi)2363/* Clear MSR_RI before setting SRR0 and SRR1. */2364li r9,02365mtmsrd r9,123662367kuap_kernel_restore r9, r1023682369EXCEPTION_RESTORE_REGS hsrr=02370RFI_TO_KERNEL23712372/**2373* Interrupt 0xf20 - Vector Unavailable Interrupt.2374* This is a synchronous interrupt in response to2375* executing a vector (or altivec) instruction with MSR[VEC]=0.2376* Similar to FP unavailable.2377*/2378INT_DEFINE_BEGIN(altivec_unavailable)2379IVEC=0xf202380#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE2381IKVM_REAL=12382#endif2383IMSR_R12=12384INT_DEFINE_END(altivec_unavailable)23852386EXC_REAL_BEGIN(altivec_unavailable, 0xf20, 0x20)2387GEN_INT_ENTRY altivec_unavailable, virt=0, ool=12388EXC_REAL_END(altivec_unavailable, 0xf20, 0x20)2389EXC_VIRT_BEGIN(altivec_unavailable, 0x4f20, 0x20)2390GEN_INT_ENTRY altivec_unavailable, virt=1, ool=12391EXC_VIRT_END(altivec_unavailable, 0x4f20, 0x20)2392EXC_COMMON_BEGIN(altivec_unavailable_common)2393GEN_COMMON altivec_unavailable2394#ifdef CONFIG_ALTIVEC2395BEGIN_FTR_SECTION2396beq 1f2397#ifdef CONFIG_PPC_TRANSACTIONAL_MEM2398BEGIN_FTR_SECTION_NESTED(69)2399/* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in2400* transaction), go do TM stuff2401*/2402rldicl. r0, r12, (64-MSR_TS_LG), (64-2)2403bne- 2f2404END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)2405#endif2406bl CFUNC(load_up_altivec)2407b fast_interrupt_return_srr2408#ifdef CONFIG_PPC_TRANSACTIONAL_MEM24092: /* User process was in a transaction */2410addi r3,r1,STACK_INT_FRAME_REGS2411bl CFUNC(altivec_unavailable_tm)2412b interrupt_return_srr2413#endif24141:2415END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)2416#endif2417addi r3,r1,STACK_INT_FRAME_REGS2418bl CFUNC(altivec_unavailable_exception)2419b interrupt_return_srr242024212422/**2423* Interrupt 0xf40 - VSX Unavailable Interrupt.2424* This is a synchronous interrupt in response to2425* executing a VSX instruction with MSR[VSX]=0.2426* Similar to FP unavailable.2427*/2428INT_DEFINE_BEGIN(vsx_unavailable)2429IVEC=0xf402430#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE2431IKVM_REAL=12432#endif2433IMSR_R12=12434INT_DEFINE_END(vsx_unavailable)24352436EXC_REAL_BEGIN(vsx_unavailable, 0xf40, 0x20)2437GEN_INT_ENTRY vsx_unavailable, virt=0, ool=12438EXC_REAL_END(vsx_unavailable, 0xf40, 0x20)2439EXC_VIRT_BEGIN(vsx_unavailable, 0x4f40, 0x20)2440GEN_INT_ENTRY vsx_unavailable, virt=1, ool=12441EXC_VIRT_END(vsx_unavailable, 0x4f40, 0x20)2442EXC_COMMON_BEGIN(vsx_unavailable_common)2443GEN_COMMON vsx_unavailable2444#ifdef CONFIG_VSX2445BEGIN_FTR_SECTION2446beq 1f2447#ifdef CONFIG_PPC_TRANSACTIONAL_MEM2448BEGIN_FTR_SECTION_NESTED(69)2449/* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in2450* transaction), go do TM stuff2451*/2452rldicl. r0, r12, (64-MSR_TS_LG), (64-2)2453bne- 2f2454END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)2455#endif2456b load_up_vsx2457#ifdef CONFIG_PPC_TRANSACTIONAL_MEM24582: /* User process was in a transaction */2459addi r3,r1,STACK_INT_FRAME_REGS2460bl CFUNC(vsx_unavailable_tm)2461b interrupt_return_srr2462#endif24631:2464END_FTR_SECTION_IFSET(CPU_FTR_VSX)2465#endif2466addi r3,r1,STACK_INT_FRAME_REGS2467bl CFUNC(vsx_unavailable_exception)2468b interrupt_return_srr246924702471/**2472* Interrupt 0xf60 - Facility Unavailable Interrupt.2473* This is a synchronous interrupt in response to2474* executing an instruction without access to the facility that can be2475* resolved by the OS (e.g., FSCR, MSR).2476* Similar to FP unavailable.2477*/2478INT_DEFINE_BEGIN(facility_unavailable)2479IVEC=0xf602480#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE2481IKVM_REAL=12482#endif2483INT_DEFINE_END(facility_unavailable)24842485EXC_REAL_BEGIN(facility_unavailable, 0xf60, 0x20)2486GEN_INT_ENTRY facility_unavailable, virt=0, ool=12487EXC_REAL_END(facility_unavailable, 0xf60, 0x20)2488EXC_VIRT_BEGIN(facility_unavailable, 0x4f60, 0x20)2489GEN_INT_ENTRY facility_unavailable, virt=1, ool=12490EXC_VIRT_END(facility_unavailable, 0x4f60, 0x20)2491EXC_COMMON_BEGIN(facility_unavailable_common)2492GEN_COMMON facility_unavailable2493addi r3,r1,STACK_INT_FRAME_REGS2494bl CFUNC(facility_unavailable_exception)2495HANDLER_RESTORE_NVGPRS() /* instruction emulation may change GPRs */2496b interrupt_return_srr249724982499/**2500* Interrupt 0xf60 - Hypervisor Facility Unavailable Interrupt.2501* This is a synchronous interrupt in response to2502* executing an instruction without access to the facility that can only2503* be resolved in HV mode (e.g., HFSCR).2504* Similar to FP unavailable.2505*/2506INT_DEFINE_BEGIN(h_facility_unavailable)2507IVEC=0xf802508IHSRR=12509IKVM_REAL=12510IKVM_VIRT=12511INT_DEFINE_END(h_facility_unavailable)25122513EXC_REAL_BEGIN(h_facility_unavailable, 0xf80, 0x20)2514GEN_INT_ENTRY h_facility_unavailable, virt=0, ool=12515EXC_REAL_END(h_facility_unavailable, 0xf80, 0x20)2516EXC_VIRT_BEGIN(h_facility_unavailable, 0x4f80, 0x20)2517GEN_INT_ENTRY h_facility_unavailable, virt=1, ool=12518EXC_VIRT_END(h_facility_unavailable, 0x4f80, 0x20)2519EXC_COMMON_BEGIN(h_facility_unavailable_common)2520GEN_COMMON h_facility_unavailable2521addi r3,r1,STACK_INT_FRAME_REGS2522bl CFUNC(facility_unavailable_exception)2523/* XXX Shouldn't be necessary in practice */2524HANDLER_RESTORE_NVGPRS()2525b interrupt_return_hsrr252625272528EXC_REAL_NONE(0xfa0, 0x20)2529EXC_VIRT_NONE(0x4fa0, 0x20)2530EXC_REAL_NONE(0xfc0, 0x20)2531EXC_VIRT_NONE(0x4fc0, 0x20)2532EXC_REAL_NONE(0xfe0, 0x20)2533EXC_VIRT_NONE(0x4fe0, 0x20)25342535EXC_REAL_NONE(0x1000, 0x100)2536EXC_VIRT_NONE(0x5000, 0x100)2537EXC_REAL_NONE(0x1100, 0x100)2538EXC_VIRT_NONE(0x5100, 0x100)2539EXC_REAL_NONE(0x1200, 0x100)2540EXC_VIRT_NONE(0x5200, 0x100)25412542/**2543* Interrupt 0x1300 - Instruction Address Breakpoint Interrupt.2544* This has been removed from the ISA before 2.01, which is the earliest2545* 64-bit BookS ISA supported, however the G5 / 970 implements this2546* interrupt with a non-architected feature available through the support2547* processor interface.2548*/2549INT_DEFINE_BEGIN(instruction_breakpoint)2550IVEC=0x13002551#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE2552IKVM_REAL=12553#endif2554INT_DEFINE_END(instruction_breakpoint)25552556EXC_REAL_BEGIN(instruction_breakpoint, 0x1300, 0x100)2557GEN_INT_ENTRY instruction_breakpoint, virt=02558EXC_REAL_END(instruction_breakpoint, 0x1300, 0x100)2559EXC_VIRT_BEGIN(instruction_breakpoint, 0x5300, 0x100)2560GEN_INT_ENTRY instruction_breakpoint, virt=12561EXC_VIRT_END(instruction_breakpoint, 0x5300, 0x100)2562EXC_COMMON_BEGIN(instruction_breakpoint_common)2563GEN_COMMON instruction_breakpoint2564addi r3,r1,STACK_INT_FRAME_REGS2565bl CFUNC(instruction_breakpoint_exception)2566b interrupt_return_srr256725682569EXC_REAL_NONE(0x1400, 0x100)2570EXC_VIRT_NONE(0x5400, 0x100)25712572/**2573* Interrupt 0x1500 - Soft Patch Interrupt2574*2575* Handling:2576* This is an implementation specific interrupt which can be used for a2577* range of exceptions.2578*2579* This interrupt handler is unique in that it runs the denormal assist2580* code even for guests (and even in guest context) without going to KVM,2581* for speed. POWER9 does not raise denorm exceptions, so this special case2582* could be phased out in future to reduce special cases.2583*/2584INT_DEFINE_BEGIN(denorm_exception)2585IVEC=0x15002586IHSRR=12587IBRANCH_TO_COMMON=02588IKVM_REAL=12589INT_DEFINE_END(denorm_exception)25902591EXC_REAL_BEGIN(denorm_exception, 0x1500, 0x100)2592GEN_INT_ENTRY denorm_exception, virt=02593#ifdef CONFIG_PPC_DENORMALISATION2594andis. r10,r12,(HSRR1_DENORM)@h /* denorm? */2595bne+ denorm_assist2596#endif2597GEN_BRANCH_TO_COMMON denorm_exception, virt=02598EXC_REAL_END(denorm_exception, 0x1500, 0x100)2599#ifdef CONFIG_PPC_DENORMALISATION2600EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)2601GEN_INT_ENTRY denorm_exception, virt=12602andis. r10,r12,(HSRR1_DENORM)@h /* denorm? */2603bne+ denorm_assist2604GEN_BRANCH_TO_COMMON denorm_exception, virt=12605EXC_VIRT_END(denorm_exception, 0x5500, 0x100)2606#else2607EXC_VIRT_NONE(0x5500, 0x100)2608#endif26092610#ifdef CONFIG_PPC_DENORMALISATION2611TRAMP_REAL_BEGIN(denorm_assist)2612BEGIN_FTR_SECTION2613/*2614* To denormalise we need to move a copy of the register to itself.2615* For POWER6 do that here for all FP regs.2616*/2617mfmsr r102618ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)2619xori r10,r10,(MSR_FE0|MSR_FE1)2620mtmsrd r102621sync26222623.Lreg=02624.rept 322625fmr .Lreg,.Lreg2626.Lreg=.Lreg+12627.endr26282629FTR_SECTION_ELSE2630/*2631* To denormalise we need to move a copy of the register to itself.2632* For POWER7 do that here for the first 32 VSX registers only.2633*/2634mfmsr r102635oris r10,r10,MSR_VSX@h2636mtmsrd r102637sync26382639.Lreg=02640.rept 322641XVCPSGNDP(.Lreg,.Lreg,.Lreg)2642.Lreg=.Lreg+12643.endr26442645ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)26462647BEGIN_FTR_SECTION2648b denorm_done2649END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)2650/*2651* To denormalise we need to move a copy of the register to itself.2652* For POWER8 we need to do that for all 64 VSX registers2653*/2654.Lreg=322655.rept 322656XVCPSGNDP(.Lreg,.Lreg,.Lreg)2657.Lreg=.Lreg+12658.endr26592660denorm_done:2661mfspr r11,SPRN_HSRR02662subi r11,r11,42663mtspr SPRN_HSRR0,r112664mtcrf 0x80,r92665ld r9,PACA_EXGEN+EX_R9(r13)2666BEGIN_FTR_SECTION2667ld r10,PACA_EXGEN+EX_PPR(r13)2668mtspr SPRN_PPR,r102669END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)2670BEGIN_FTR_SECTION2671ld r10,PACA_EXGEN+EX_CFAR(r13)2672mtspr SPRN_CFAR,r102673END_FTR_SECTION_IFSET(CPU_FTR_CFAR)2674li r10,02675stb r10,PACAHSRR_VALID(r13)2676ld r10,PACA_EXGEN+EX_R10(r13)2677ld r11,PACA_EXGEN+EX_R11(r13)2678ld r12,PACA_EXGEN+EX_R12(r13)2679ld r13,PACA_EXGEN+EX_R13(r13)2680HRFI_TO_UNKNOWN2681b .2682#endif26832684EXC_COMMON_BEGIN(denorm_exception_common)2685GEN_COMMON denorm_exception2686addi r3,r1,STACK_INT_FRAME_REGS2687bl CFUNC(unknown_exception)2688b interrupt_return_hsrr268926902691EXC_REAL_NONE(0x1600, 0x100)2692EXC_VIRT_NONE(0x5600, 0x100)269326942695INT_DEFINE_BEGIN(altivec_assist)2696IVEC=0x17002697#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE2698IKVM_REAL=12699#endif2700INT_DEFINE_END(altivec_assist)27012702EXC_REAL_BEGIN(altivec_assist, 0x1700, 0x100)2703GEN_INT_ENTRY altivec_assist, virt=02704EXC_REAL_END(altivec_assist, 0x1700, 0x100)2705EXC_VIRT_BEGIN(altivec_assist, 0x5700, 0x100)2706GEN_INT_ENTRY altivec_assist, virt=12707EXC_VIRT_END(altivec_assist, 0x5700, 0x100)2708EXC_COMMON_BEGIN(altivec_assist_common)2709GEN_COMMON altivec_assist2710addi r3,r1,STACK_INT_FRAME_REGS2711#ifdef CONFIG_ALTIVEC2712bl CFUNC(altivec_assist_exception)2713HANDLER_RESTORE_NVGPRS() /* instruction emulation may change GPRs */2714#else2715bl CFUNC(unknown_exception)2716#endif2717b interrupt_return_srr271827192720EXC_REAL_NONE(0x1800, 0x100)2721EXC_VIRT_NONE(0x5800, 0x100)272227232724#ifdef CONFIG_PPC_WATCHDOG27252726INT_DEFINE_BEGIN(soft_nmi)2727IVEC=0x9002728ISTACK=02729ICFAR=02730INT_DEFINE_END(soft_nmi)27312732/*2733* Branch to soft_nmi_interrupt using the emergency stack. The emergency2734* stack is one that is usable by maskable interrupts so long as MSR_EE2735* remains off. It is used for recovery when something has corrupted the2736* normal kernel stack, for example. The "soft NMI" must not use the process2737* stack because we want irq disabled sections to avoid touching the stack2738* at all (other than PMU interrupts), so use the emergency stack for this,2739* and run it entirely with interrupts hard disabled.2740*/2741EXC_COMMON_BEGIN(soft_nmi_common)2742mr r10,r12743ld r1,PACAEMERGSP(r13)2744subi r1,r1,INT_FRAME_SIZE2745__GEN_COMMON_BODY soft_nmi27462747addi r3,r1,STACK_INT_FRAME_REGS2748bl CFUNC(soft_nmi_interrupt)27492750/* Clear MSR_RI before setting SRR0 and SRR1. */2751li r9,02752mtmsrd r9,127532754kuap_kernel_restore r9, r1027552756EXCEPTION_RESTORE_REGS hsrr=02757RFI_TO_KERNEL27582759#endif /* CONFIG_PPC_WATCHDOG */27602761/*2762* An interrupt came in while soft-disabled. We set paca->irq_happened, then:2763* - If it was a decrementer interrupt, we bump the dec to max and return.2764* - If it was a doorbell we return immediately since doorbells are edge2765* triggered and won't automatically refire.2766* - If it was a HMI we return immediately since we handled it in realmode2767* and it won't refire.2768* - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return.2769* This is called with r10 containing the value to OR to the paca field.2770*/2771.macro MASKED_INTERRUPT hsrr=02772.if \hsrr2773masked_Hinterrupt:2774.else2775masked_interrupt:2776.endif2777stw r9,PACA_EXGEN+EX_CCR(r13)2778#ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG2779/*2780* Ensure there was no previous MUST_HARD_MASK interrupt or2781* HARD_DIS setting. If this does fire, the interrupt is still2782* masked and MSR[EE] will be cleared on return, so no need to2783* panic, but somebody probably enabled MSR[EE] under2784* PACA_IRQ_HARD_DIS, mtmsr(mfmsr() | MSR_x) being a common2785* cause.2786*/2787lbz r9,PACAIRQHAPPENED(r13)2788andi. r9,r9,(PACA_IRQ_MUST_HARD_MASK|PACA_IRQ_HARD_DIS)27890: tdnei r9,02790EMIT_WARN_ENTRY 0b,__FILE__,__LINE__,(BUGFLAG_WARNING | BUGFLAG_ONCE)2791#endif2792lbz r9,PACAIRQHAPPENED(r13)2793or r9,r9,r102794stb r9,PACAIRQHAPPENED(r13)27952796.if ! \hsrr2797cmpwi r10,PACA_IRQ_DEC2798bne 1f2799LOAD_REG_IMMEDIATE(r9, 0x7fffffff)2800mtspr SPRN_DEC,r92801#ifdef CONFIG_PPC_WATCHDOG2802lwz r9,PACA_EXGEN+EX_CCR(r13)2803b soft_nmi_common2804#else2805b 2f2806#endif2807.endif280828091: andi. r10,r10,PACA_IRQ_MUST_HARD_MASK2810beq 2f2811xori r12,r12,MSR_EE /* clear MSR_EE */2812.if \hsrr2813mtspr SPRN_HSRR1,r122814.else2815mtspr SPRN_SRR1,r122816.endif2817ori r9,r9,PACA_IRQ_HARD_DIS2818stb r9,PACAIRQHAPPENED(r13)28192: /* done */2820li r9,02821.if \hsrr2822stb r9,PACAHSRR_VALID(r13)2823.else2824stb r9,PACASRR_VALID(r13)2825.endif28262827SEARCH_RESTART_TABLE2828cmpdi r12,02829beq 3f2830.if \hsrr2831mtspr SPRN_HSRR0,r122832.else2833mtspr SPRN_SRR0,r122834.endif28353:28362837ld r9,PACA_EXGEN+EX_CTR(r13)2838mtctr r92839lwz r9,PACA_EXGEN+EX_CCR(r13)2840mtcrf 0x80,r92841std r1,PACAR1(r13)2842ld r9,PACA_EXGEN+EX_R9(r13)2843ld r10,PACA_EXGEN+EX_R10(r13)2844ld r11,PACA_EXGEN+EX_R11(r13)2845ld r12,PACA_EXGEN+EX_R12(r13)2846ld r13,PACA_EXGEN+EX_R13(r13)2847/* May return to masked low address where r13 is not set up */2848.if \hsrr2849HRFI_TO_KERNEL2850.else2851RFI_TO_KERNEL2852.endif2853b .2854.endm28552856TRAMP_REAL_BEGIN(stf_barrier_fallback)2857std r9,PACA_EXRFI+EX_R9(r13)2858std r10,PACA_EXRFI+EX_R10(r13)2859sync2860ld r9,PACA_EXRFI+EX_R9(r13)2861ld r10,PACA_EXRFI+EX_R10(r13)2862ori 31,31,02863.rept 142864b 1f28651:2866.endr2867blr28682869/* Clobbers r10, r11, ctr */2870.macro L1D_DISPLACEMENT_FLUSH2871ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)2872ld r11,PACA_L1D_FLUSH_SIZE(r13)2873srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */2874mtctr r112875DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */28762877/* order ld/st prior to dcbt stop all streams with flushing */2878sync28792880/*2881* The load addresses are at staggered offsets within cachelines,2882* which suits some pipelines better (on others it should not2883* hurt).2884*/28851:2886ld r11,(0x80 + 8)*0(r10)2887ld r11,(0x80 + 8)*1(r10)2888ld r11,(0x80 + 8)*2(r10)2889ld r11,(0x80 + 8)*3(r10)2890ld r11,(0x80 + 8)*4(r10)2891ld r11,(0x80 + 8)*5(r10)2892ld r11,(0x80 + 8)*6(r10)2893ld r11,(0x80 + 8)*7(r10)2894addi r10,r10,0x80*82895bdnz 1b2896.endm28972898TRAMP_REAL_BEGIN(entry_flush_fallback)2899std r9,PACA_EXRFI+EX_R9(r13)2900std r10,PACA_EXRFI+EX_R10(r13)2901std r11,PACA_EXRFI+EX_R11(r13)2902mfctr r92903L1D_DISPLACEMENT_FLUSH2904mtctr r92905ld r9,PACA_EXRFI+EX_R9(r13)2906ld r10,PACA_EXRFI+EX_R10(r13)2907ld r11,PACA_EXRFI+EX_R11(r13)2908blr29092910/*2911* The SCV entry flush happens with interrupts enabled, so it must disable2912* to prevent EXRFI being clobbered by NMIs (e.g., soft_nmi_common). r102913* (containing LR) does not need to be preserved here because scv entry2914* puts 0 in the pt_regs, CTR can be clobbered for the same reason.2915*/2916TRAMP_REAL_BEGIN(scv_entry_flush_fallback)2917li r10,02918mtmsrd r10,12919lbz r10,PACAIRQHAPPENED(r13)2920ori r10,r10,PACA_IRQ_HARD_DIS2921stb r10,PACAIRQHAPPENED(r13)2922std r11,PACA_EXRFI+EX_R11(r13)2923L1D_DISPLACEMENT_FLUSH2924ld r11,PACA_EXRFI+EX_R11(r13)2925li r10,MSR_RI2926mtmsrd r10,12927blr29282929TRAMP_REAL_BEGIN(rfi_flush_fallback)2930SET_SCRATCH0(r13);2931GET_PACA(r13);2932std r1,PACA_EXRFI+EX_R12(r13)2933ld r1,PACAKSAVE(r13)2934std r9,PACA_EXRFI+EX_R9(r13)2935std r10,PACA_EXRFI+EX_R10(r13)2936std r11,PACA_EXRFI+EX_R11(r13)2937mfctr r92938L1D_DISPLACEMENT_FLUSH2939mtctr r92940ld r9,PACA_EXRFI+EX_R9(r13)2941ld r10,PACA_EXRFI+EX_R10(r13)2942ld r11,PACA_EXRFI+EX_R11(r13)2943ld r1,PACA_EXRFI+EX_R12(r13)2944GET_SCRATCH0(r13);2945rfid29462947TRAMP_REAL_BEGIN(hrfi_flush_fallback)2948SET_SCRATCH0(r13);2949GET_PACA(r13);2950std r1,PACA_EXRFI+EX_R12(r13)2951ld r1,PACAKSAVE(r13)2952std r9,PACA_EXRFI+EX_R9(r13)2953std r10,PACA_EXRFI+EX_R10(r13)2954std r11,PACA_EXRFI+EX_R11(r13)2955mfctr r92956L1D_DISPLACEMENT_FLUSH2957mtctr r92958ld r9,PACA_EXRFI+EX_R9(r13)2959ld r10,PACA_EXRFI+EX_R10(r13)2960ld r11,PACA_EXRFI+EX_R11(r13)2961ld r1,PACA_EXRFI+EX_R12(r13)2962GET_SCRATCH0(r13);2963hrfid29642965TRAMP_REAL_BEGIN(rfscv_flush_fallback)2966/* system call volatile */2967mr r7,r132968GET_PACA(r13);2969mr r8,r12970ld r1,PACAKSAVE(r13)2971mfctr r92972ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)2973ld r11,PACA_L1D_FLUSH_SIZE(r13)2974srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */2975mtctr r112976DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */29772978/* order ld/st prior to dcbt stop all streams with flushing */2979sync29802981/*2982* The load adresses are at staggered offsets within cachelines,2983* which suits some pipelines better (on others it should not2984* hurt).2985*/29861:2987ld r11,(0x80 + 8)*0(r10)2988ld r11,(0x80 + 8)*1(r10)2989ld r11,(0x80 + 8)*2(r10)2990ld r11,(0x80 + 8)*3(r10)2991ld r11,(0x80 + 8)*4(r10)2992ld r11,(0x80 + 8)*5(r10)2993ld r11,(0x80 + 8)*6(r10)2994ld r11,(0x80 + 8)*7(r10)2995addi r10,r10,0x80*82996bdnz 1b29972998mtctr r92999li r9,03000li r10,03001li r11,03002mr r1,r83003mr r13,r73004RFSCV30053006USE_TEXT_SECTION()30073008#ifdef CONFIG_KVM_BOOK3S_64_HANDLER3009kvm_interrupt:3010/*3011* The conditional branch in KVMTEST can't reach all the way,3012* make a stub.3013*/3014b kvmppc_interrupt3015#endif30163017_GLOBAL(do_uaccess_flush)3018UACCESS_FLUSH_FIXUP_SECTION3019nop3020nop3021nop3022blr3023L1D_DISPLACEMENT_FLUSH3024blr3025_ASM_NOKPROBE_SYMBOL(do_uaccess_flush)3026EXPORT_SYMBOL(do_uaccess_flush)302730283029MASKED_INTERRUPT3030MASKED_INTERRUPT hsrr=130313032USE_FIXED_SECTION(virt_trampolines)3033/*3034* All code below __end_soft_masked is treated as soft-masked. If3035* any code runs here with MSR[EE]=1, it must then cope with pending3036* soft interrupt being raised (i.e., by ensuring it is replayed).3037*3038* The __end_interrupts marker must be past the out-of-line (OOL)3039* handlers, so that they are copied to real address 0x100 when running3040* a relocatable kernel. This ensures they can be reached from the short3041* trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch3042* directly, without using LOAD_HANDLER().3043*/3044.align 73045.globl __end_interrupts3046__end_interrupts:3047DEFINE_FIXED_SYMBOL(__end_interrupts, virt_trampolines)30483049CLOSE_FIXED_SECTION(real_vectors);3050CLOSE_FIXED_SECTION(real_trampolines);3051CLOSE_FIXED_SECTION(virt_vectors);3052CLOSE_FIXED_SECTION(virt_trampolines);30533054USE_TEXT_SECTION()30553056/* MSR[RI] should be clear because this uses SRR[01] */3057_GLOBAL(enable_machine_check)3058mflr r03059bcl 20,31,$+430600: mflr r33061addi r3,r3,(1f - 0b)3062mtspr SPRN_SRR0,r33063mfmsr r33064ori r3,r3,MSR_ME3065mtspr SPRN_SRR1,r33066RFI_TO_KERNEL30671: mtlr r03068blr30693070/* MSR[RI] should be clear because this uses SRR[01] */3071SYM_FUNC_START_LOCAL(disable_machine_check)3072mflr r03073bcl 20,31,$+430740: mflr r33075addi r3,r3,(1f - 0b)3076mtspr SPRN_SRR0,r33077mfmsr r33078li r4,MSR_ME3079andc r3,r3,r43080mtspr SPRN_SRR1,r33081RFI_TO_KERNEL30821: mtlr r03083blr3084SYM_FUNC_END(disable_machine_check)308530863087