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>
24 #include <asm/asm-offsets.h>
25 #include <asm/exception-64s.h>
27 /*****************************************************************************
29 * Real Mode handlers that need to be in low physical memory *
31 ****************************************************************************/
34 .macro INTERRUPT_TRAMPOLINE intno
36 .global kvmppc_trampoline_\intno
37 kvmppc_trampoline_\intno:
39 mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
42 * First thing to do is to find out if we're coming
43 * from a KVM guest or a Linux process.
45 * To distinguish, we check a magic byte in the PACA
47 mfspr r13, SPRN_SPRG_PACA /* r13 = PACA */
48 std r12, PACA_KVM_SCRATCH0(r13)
50 stw r12, PACA_KVM_SCRATCH1(r13)
51 lbz r12, PACA_KVM_IN_GUEST(r13)
52 cmpwi r12, KVM_GUEST_MODE_NONE
53 bne ..kvmppc_handler_hasmagic_\intno
54 /* No KVM guest? Then jump back to the Linux handler! */
55 lwz r12, PACA_KVM_SCRATCH1(r13)
57 ld r12, PACA_KVM_SCRATCH0(r13)
58 mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
59 b kvmppc_resume_\intno /* Get back original handler */
61 /* Now we know we're handling a KVM guest */
62 ..kvmppc_handler_hasmagic_\intno:
64 /* Should we just skip the faulting instruction? */
65 cmpwi r12, KVM_GUEST_MODE_SKIP
66 beq kvmppc_handler_skip_ins
68 /* Let's store which interrupt we're handling */
71 /* Jump into the SLB exit code that goes to the highmem handler */
72 b kvmppc_handler_trampoline_exit
76 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
77 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
78 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
79 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_SEGMENT
80 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
81 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_SEGMENT
82 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
83 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
84 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
85 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
86 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
87 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
88 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
89 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
90 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
91 INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_VSX
94 * Bring us back to the faulting code, but skip the
95 * faulting instruction.
97 * This is a generic exit path from the interrupt
104 * PACA.KVM.SCRATCH0 = guest R12
105 * PACA.KVM.SCRATCH1 = guest CR
106 * SPRG_SCRATCH0 = guest R13
109 kvmppc_handler_skip_ins:
111 /* Patch the IP to the next instruction */
116 /* Clean up all state */
117 lwz r12, PACA_KVM_SCRATCH1(r13)
119 ld r12, PACA_KVM_SCRATCH0(r13)
120 mfspr r13, SPRN_SPRG_SCRATCH0
122 /* And get back into the code */
126 * This trampoline brings us back to a real mode handler
135 .global kvmppc_handler_lowmem_trampoline
136 kvmppc_handler_lowmem_trampoline:
141 kvmppc_handler_lowmem_trampoline_end:
144 * Call a function in real mode
153 _GLOBAL(kvmppc_rmcall)
154 mtmsr r4 /* Disable relocation, so mtsrr
155 doesn't get interrupted */
162 * Activate current's external feature (FPU/Altivec/VSX)
164 #define define_load_up(what) \
166 _GLOBAL(kvmppc_load_up_ ## what); \
167 subi r1, r1, INT_FRAME_SIZE; \
174 oris r5, r5, MSR_EE@h; \
178 bl .load_up_ ## what; \
183 addi r1, r1, INT_FRAME_SIZE; \
188 #ifdef CONFIG_ALTIVEC
189 define_load_up(altivec)
195 .global kvmppc_trampoline_lowmem
196 kvmppc_trampoline_lowmem:
197 .long kvmppc_handler_lowmem_trampoline - _stext
199 .global kvmppc_trampoline_enter
200 kvmppc_trampoline_enter:
201 .long kvmppc_handler_trampoline_enter - _stext
203 #include "book3s_64_slb.S"