2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 * Copyright SUSE Linux Products GmbH 2009
17 * Authors: Alexander Graf <agraf@suse.de>
20 #include <asm/ppc_asm.h>
21 #include <asm/kvm_asm.h>
25 #include <asm/asm-offsets.h>
27 #ifdef CONFIG_PPC_BOOK3S_64
28 #include <asm/exception-64s.h>
31 /*****************************************************************************
33 * Real Mode handlers that need to be in low physical memory *
35 ****************************************************************************/
37 #if defined(CONFIG_PPC_BOOK3S_64)
39 #define FUNC(name) GLUE(.,name)
40 #define MTMSR_EERI(reg) mtmsrd (reg),1
42 .globl kvmppc_skip_interrupt
43 kvmppc_skip_interrupt:
45 * Here all GPRs are unchanged from when the interrupt happened
46 * except for r13, which is saved in SPRG_SCRATCH0.
55 .globl kvmppc_skip_Hinterrupt
56 kvmppc_skip_Hinterrupt:
58 * Here all GPRs are unchanged from when the interrupt happened
59 * except for r13, which is saved in SPRG_SCRATCH0.
68 #elif defined(CONFIG_PPC_BOOK3S_32)
70 #define FUNC(name) name
71 #define MTMSR_EERI(reg) mtmsr (reg)
73 .macro INTERRUPT_TRAMPOLINE intno
75 .global kvmppc_trampoline_\intno
76 kvmppc_trampoline_\intno:
78 mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
81 * First thing to do is to find out if we're coming
82 * from a KVM guest or a Linux process.
84 * To distinguish, we check a magic byte in the PACA/current
86 mfspr r13, SPRN_SPRG_THREAD
87 lwz r13, THREAD_KVM_SVCPU(r13)
88 /* PPC32 can have a NULL pointer - let's check for that */
89 mtspr SPRN_SPRG_SCRATCH1, r12 /* Save r12 */
94 mfspr r12, SPRN_SPRG_SCRATCH1
95 mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
96 b kvmppc_resume_\intno /* Get back original handler */
99 stw r12, HSTATE_SCRATCH1(r13)
100 mfspr r12, SPRN_SPRG_SCRATCH1
101 stw r12, HSTATE_SCRATCH0(r13)
102 lbz r12, HSTATE_IN_GUEST(r13)
103 cmpwi r12, KVM_GUEST_MODE_NONE
104 bne ..kvmppc_handler_hasmagic_\intno
105 /* No KVM guest? Then jump back to the Linux handler! */
106 lwz r12, HSTATE_SCRATCH1(r13)
109 /* Now we know we're handling a KVM guest */
110 ..kvmppc_handler_hasmagic_\intno:
112 /* Should we just skip the faulting instruction? */
113 cmpwi r12, KVM_GUEST_MODE_SKIP
114 beq kvmppc_handler_skip_ins
116 /* Let's store which interrupt we're handling */
119 /* Jump into the SLB exit code that goes to the highmem handler */
120 b kvmppc_handler_trampoline_exit
124 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
125 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
126 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
127 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
128 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
129 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
130 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
131 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
132 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
133 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
134 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
135 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
136 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
139 * Bring us back to the faulting code, but skip the
140 * faulting instruction.
142 * This is a generic exit path from the interrupt
148 * R13 = Shadow VCPU (PACA)
149 * HSTATE.SCRATCH0 = guest R12
150 * HSTATE.SCRATCH1 = guest CR
151 * SPRG_SCRATCH0 = guest R13
154 kvmppc_handler_skip_ins:
156 /* Patch the IP to the next instruction */
161 /* Clean up all state */
162 lwz r12, HSTATE_SCRATCH1(r13)
164 PPC_LL r12, HSTATE_SCRATCH0(r13)
167 /* And get back into the code */
172 * Call kvmppc_handler_trampoline_enter in real mode
174 * On entry, r4 contains the guest shadow MSR
176 _GLOBAL(kvmppc_entry_trampoline)
178 LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
183 andc r9, r5, r9 /* Clear EE and RI in MSR value */
184 li r6, MSR_IR | MSR_DR
186 andc r6, r5, r6 /* Clear EE, DR and IR in MSR value */
187 MTMSR_EERI(r9) /* Clear EE and RI in MSR */
188 mtsrr0 r7 /* before we set srr0/1 */
192 #if defined(CONFIG_PPC_BOOK3S_32)
193 #define STACK_LR INT_FRAME_SIZE+4
195 /* load_up_xxx have to run with MSR_DR=0 on Book3S_32 */
196 #define MSR_EXT_START \
197 PPC_STL r20, _NIP(r1); \
199 LOAD_REG_IMMEDIATE(r3, MSR_DR|MSR_EE); \
200 andc r3,r20,r3; /* Disable DR,EE */ \
204 #define MSR_EXT_END \
205 mtmsr r20; /* Enable DR,EE */ \
209 #elif defined(CONFIG_PPC_BOOK3S_64)
210 #define STACK_LR _LINK
211 #define MSR_EXT_START
216 * Activate current's external feature (FPU/Altivec/VSX)
218 #define define_load_up(what) \
220 _GLOBAL(kvmppc_load_up_ ## what); \
221 PPC_STLU r1, -INT_FRAME_SIZE(r1); \
223 PPC_STL r3, STACK_LR(r1); \
226 bl FUNC(load_up_ ## what); \
229 PPC_LL r3, STACK_LR(r1); \
231 addi r1, r1, INT_FRAME_SIZE; \
235 #ifdef CONFIG_ALTIVEC
236 define_load_up(altivec)
242 #include "book3s_segment.S"