/* SPDX-License-Identifier: GPL-2.0-only */1/*2*3* Copyright SUSE Linux Products GmbH 20094*5* Authors: Alexander Graf <[email protected]>6*/78#include <asm/ppc_asm.h>9#include <asm/kvm_asm.h>10#include <asm/reg.h>11#include <asm/mmu.h>12#include <asm/page.h>13#include <asm/asm-offsets.h>14#include <asm/asm-compat.h>1516#ifdef CONFIG_PPC_BOOK3S_6417#include <asm/exception-64s.h>18#endif1920/*****************************************************************************21* *22* Real Mode handlers that need to be in low physical memory *23* *24****************************************************************************/2526#if defined(CONFIG_PPC_BOOK3S_64)2728#ifdef CONFIG_PPC64_ELF_ABI_V229#define FUNC(name) name30#else31#define FUNC(name) GLUE(.,name)32#endif3334#elif defined(CONFIG_PPC_BOOK3S_32)3536#define FUNC(name) name3738#define RFI_TO_KERNEL rfi39#define RFI_TO_GUEST rfi4041.macro INTERRUPT_TRAMPOLINE intno4243.global kvmppc_trampoline_\intno44kvmppc_trampoline_\intno:4546mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */4748/*49* First thing to do is to find out if we're coming50* from a KVM guest or a Linux process.51*52* To distinguish, we check a magic byte in the PACA/current53*/54mfspr r13, SPRN_SPRG_THREAD55lwz r13, THREAD_KVM_SVCPU(r13)56/* PPC32 can have a NULL pointer - let's check for that */57mtspr SPRN_SPRG_SCRATCH1, r12 /* Save r12 */58mfcr r1259cmpwi r13, 060bne 1f612: mtcr r1262mfspr r12, SPRN_SPRG_SCRATCH163mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */64b kvmppc_resume_\intno /* Get back original handler */65661: tophys(r13, r13)67stw r12, HSTATE_SCRATCH1(r13)68mfspr r12, SPRN_SPRG_SCRATCH169stw r12, HSTATE_SCRATCH0(r13)70lbz r12, HSTATE_IN_GUEST(r13)71cmpwi r12, KVM_GUEST_MODE_NONE72bne ..kvmppc_handler_hasmagic_\intno73/* No KVM guest? Then jump back to the Linux handler! */74lwz r12, HSTATE_SCRATCH1(r13)75b 2b7677/* Now we know we're handling a KVM guest */78..kvmppc_handler_hasmagic_\intno:7980/* Should we just skip the faulting instruction? */81cmpwi r12, KVM_GUEST_MODE_SKIP82beq kvmppc_handler_skip_ins8384/* Let's store which interrupt we're handling */85li r12, \intno8687/* Jump into the SLB exit code that goes to the highmem handler */88b kvmppc_handler_trampoline_exit8990.endm9192INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET93INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK94INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE95INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE96INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL97INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT98INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM99INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL100INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER101INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL102INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE103INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON104INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC105106/*107* Bring us back to the faulting code, but skip the108* faulting instruction.109*110* This is a generic exit path from the interrupt111* trampolines above.112*113* Input Registers:114*115* R12 = free116* R13 = Shadow VCPU (PACA)117* HSTATE.SCRATCH0 = guest R12118* HSTATE.SCRATCH1 = guest CR119* SPRG_SCRATCH0 = guest R13120*121*/122kvmppc_handler_skip_ins:123124/* Patch the IP to the next instruction */125/* Note that prefixed instructions are disabled in PR KVM for now */126mfsrr0 r12127addi r12, r12, 4128mtsrr0 r12129130/* Clean up all state */131lwz r12, HSTATE_SCRATCH1(r13)132mtcr r12133PPC_LL r12, HSTATE_SCRATCH0(r13)134GET_SCRATCH0(r13)135136/* And get back into the code */137RFI_TO_KERNEL138#endif139140/*141* Call kvmppc_handler_trampoline_enter in real mode142*143* On entry, r4 contains the guest shadow MSR144* MSR.EE has to be 0 when calling this function145*/146_GLOBAL_TOC(kvmppc_entry_trampoline)147mfmsr r5148LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)149toreal(r7)150151li r6, MSR_IR | MSR_DR152andc r6, r5, r6 /* Clear DR and IR in MSR value */153/*154* Set EE in HOST_MSR so that it's enabled when we get into our155* C exit handler function.156*/157ori r5, r5, MSR_EE158mtsrr0 r7159mtsrr1 r6160RFI_TO_KERNEL161162#include "book3s_segment.S"163164165