aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kvm
diff options
context:
space:
mode:
authorAlexander Graf <agraf@suse.de>2009-10-30 01:47:09 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2009-11-05 00:49:54 -0500
commitc862125c8ae4c261ecbb096ab12b1fa55fcfce8d (patch)
treec7c54cbbcdd71ceb45c57685b1ef0f3ae6650c9a /arch/powerpc/kvm
parent5126ed37603ae3a5ec764d99d77430a179021699 (diff)
Add interrupt handling code
Getting from host state to the guest is only half the story. We also need to return to our host context and handle whatever happened to get us out of the guest. On PowerPC every guest exit is an interrupt. So all we need to do is trap the host's interrupt handlers and get into our #VMEXIT code to handle it. PowerPCs also have a register that can add an offset to the interrupt handlers' adresses which is what the booke KVM code uses. Unfortunately that is a hypervisor ressource and we also want to be able to run KVM when we're running in an LPAR. So we have to hook into the Linux interrupt handlers. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc/kvm')
-rw-r--r--arch/powerpc/kvm/book3s_64_rmhandlers.S131
1 files changed, 131 insertions, 0 deletions
diff --git a/arch/powerpc/kvm/book3s_64_rmhandlers.S b/arch/powerpc/kvm/book3s_64_rmhandlers.S
new file mode 100644
index 000000000000..fb7dd2e9ac88
--- /dev/null
+++ b/arch/powerpc/kvm/book3s_64_rmhandlers.S
@@ -0,0 +1,131 @@
1/*
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.
5 *
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.
10 *
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.
14 *
15 * Copyright SUSE Linux Products GmbH 2009
16 *
17 * Authors: Alexander Graf <agraf@suse.de>
18 */
19
20#include <asm/ppc_asm.h>
21#include <asm/kvm_asm.h>
22#include <asm/reg.h>
23#include <asm/page.h>
24#include <asm/asm-offsets.h>
25#include <asm/exception-64s.h>
26
27/*****************************************************************************
28 * *
29 * Real Mode handlers that need to be in low physical memory *
30 * *
31 ****************************************************************************/
32
33
34.macro INTERRUPT_TRAMPOLINE intno
35
36.global kvmppc_trampoline_\intno
37kvmppc_trampoline_\intno:
38
39 mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
40
41 /*
42 * First thing to do is to find out if we're coming
43 * from a KVM guest or a Linux process.
44 *
45 * To distinguish, we check a magic byte in the PACA
46 */
47 mfspr r13, SPRN_SPRG_PACA /* r13 = PACA */
48 std r12, (PACA_EXMC + EX_R12)(r13)
49 mfcr r12
50 stw r12, (PACA_EXMC + EX_CCR)(r13)
51 lbz r12, PACA_KVM_IN_GUEST(r13)
52 cmpwi r12, 0
53 bne ..kvmppc_handler_hasmagic_\intno
54 /* No KVM guest? Then jump back to the Linux handler! */
55 lwz r12, (PACA_EXMC + EX_CCR)(r13)
56 mtcr r12
57 ld r12, (PACA_EXMC + EX_R12)(r13)
58 mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
59 b kvmppc_resume_\intno /* Get back original handler */
60
61 /* Now we know we're handling a KVM guest */
62..kvmppc_handler_hasmagic_\intno:
63 /* Unset guest state */
64 li r12, 0
65 stb r12, PACA_KVM_IN_GUEST(r13)
66
67 std r1, (PACA_EXMC+EX_R9)(r13)
68 std r10, (PACA_EXMC+EX_R10)(r13)
69 std r11, (PACA_EXMC+EX_R11)(r13)
70 std r2, (PACA_EXMC+EX_R13)(r13)
71
72 mfsrr0 r10
73 mfsrr1 r11
74
75 /* Restore R1/R2 so we can handle faults */
76 ld r1, PACAR1(r13)
77 ld r2, (PACA_EXMC+EX_SRR0)(r13)
78
79 /* Let's store which interrupt we're handling */
80 li r12, \intno
81
82 /* Jump into the SLB exit code that goes to the highmem handler */
83 b kvmppc_handler_trampoline_exit
84
85.endm
86
87INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
88INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
89INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
90INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_SEGMENT
91INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
92INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_SEGMENT
93INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
94INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
95INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
96INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
97INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
98INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
99INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
100INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
101INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
102INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_VSX
103
104/*
105 * This trampoline brings us back to a real mode handler
106 *
107 * Input Registers:
108 *
109 * R6 = SRR0
110 * R7 = SRR1
111 * LR = real-mode IP
112 *
113 */
114.global kvmppc_handler_lowmem_trampoline
115kvmppc_handler_lowmem_trampoline:
116
117 mtsrr0 r6
118 mtsrr1 r7
119 blr
120kvmppc_handler_lowmem_trampoline_end:
121
122.global kvmppc_trampoline_lowmem
123kvmppc_trampoline_lowmem:
124 .long kvmppc_handler_lowmem_trampoline - _stext
125
126.global kvmppc_trampoline_enter
127kvmppc_trampoline_enter:
128 .long kvmppc_handler_trampoline_enter - _stext
129
130#include "book3s_64_slb.S"
131