1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * Copyright SUSE Linux Products GmbH 2009
6 * Authors: Alexander Graf <agraf@suse.de>
9 #include <asm/ppc_asm.h>
10 #include <asm/kvm_asm.h>
14 #include <asm/asm-offsets.h>
15 #include <asm/asm-compat.h>
17 #ifdef CONFIG_PPC_BOOK3S_64
18 #include <asm/exception-64s.h>
21 /*****************************************************************************
23 * Real Mode handlers that need to be in low physical memory *
25 ****************************************************************************/
27 #if defined(CONFIG_PPC_BOOK3S_64)
29 #ifdef PPC64_ELF_ABI_v2
30 #define FUNC(name) name
32 #define FUNC(name) GLUE(.,name)
35 #elif defined(CONFIG_PPC_BOOK3S_32)
37 #define FUNC(name) name
39 #define RFI_TO_KERNEL rfi
40 #define RFI_TO_GUEST rfi
42 .macro INTERRUPT_TRAMPOLINE intno
44 .global kvmppc_trampoline_\intno
45 kvmppc_trampoline_\intno:
47 mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
50 * First thing to do is to find out if we're coming
51 * from a KVM guest or a Linux process.
53 * To distinguish, we check a magic byte in the PACA/current
55 mfspr r13, SPRN_SPRG_THREAD
56 lwz r13, THREAD_KVM_SVCPU(r13)
57 /* PPC32 can have a NULL pointer - let's check for that */
58 mtspr SPRN_SPRG_SCRATCH1, r12 /* Save r12 */
63 mfspr r12, SPRN_SPRG_SCRATCH1
64 mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
65 b kvmppc_resume_\intno /* Get back original handler */
68 stw r12, HSTATE_SCRATCH1(r13)
69 mfspr r12, SPRN_SPRG_SCRATCH1
70 stw r12, HSTATE_SCRATCH0(r13)
71 lbz r12, HSTATE_IN_GUEST(r13)
72 cmpwi r12, KVM_GUEST_MODE_NONE
73 bne ..kvmppc_handler_hasmagic_\intno
74 /* No KVM guest? Then jump back to the Linux handler! */
75 lwz r12, HSTATE_SCRATCH1(r13)
78 /* Now we know we're handling a KVM guest */
79 ..kvmppc_handler_hasmagic_\intno:
81 /* Should we just skip the faulting instruction? */
82 cmpwi r12, KVM_GUEST_MODE_SKIP
83 beq kvmppc_handler_skip_ins
85 /* Let's store which interrupt we're handling */
88 /* Jump into the SLB exit code that goes to the highmem handler */
89 b kvmppc_handler_trampoline_exit
93 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
94 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
95 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
96 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
97 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
98 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
99 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
100 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
101 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
102 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
103 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
104 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
105 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
108 * Bring us back to the faulting code, but skip the
109 * faulting instruction.
111 * This is a generic exit path from the interrupt
117 * R13 = Shadow VCPU (PACA)
118 * HSTATE.SCRATCH0 = guest R12
119 * HSTATE.SCRATCH1 = guest CR
120 * SPRG_SCRATCH0 = guest R13
123 kvmppc_handler_skip_ins:
125 /* Patch the IP to the next instruction */
130 /* Clean up all state */
131 lwz r12, HSTATE_SCRATCH1(r13)
133 PPC_LL r12, HSTATE_SCRATCH0(r13)
136 /* And get back into the code */
141 * Call kvmppc_handler_trampoline_enter in real mode
143 * On entry, r4 contains the guest shadow MSR
144 * MSR.EE has to be 0 when calling this function
146 _GLOBAL_TOC(kvmppc_entry_trampoline)
148 LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
151 li r6, MSR_IR | MSR_DR
152 andc r6, r5, r6 /* Clear DR and IR in MSR value */
154 * Set EE in HOST_MSR so that it's enabled when we get into our
155 * C exit handler function.
162 #include "book3s_segment.S"