Commit | Line | Data |
---|---|---|
c862125c AG |
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 | |
37 | kvmppc_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 */ | |
7e57cba0 | 48 | std r12, PACA_KVM_SCRATCH0(r13) |
c862125c | 49 | mfcr r12 |
7e57cba0 | 50 | stw r12, PACA_KVM_SCRATCH1(r13) |
c862125c | 51 | lbz r12, PACA_KVM_IN_GUEST(r13) |
b4433a7c | 52 | cmpwi r12, KVM_GUEST_MODE_NONE |
c862125c AG |
53 | bne ..kvmppc_handler_hasmagic_\intno |
54 | /* No KVM guest? Then jump back to the Linux handler! */ | |
7e57cba0 | 55 | lwz r12, PACA_KVM_SCRATCH1(r13) |
c862125c | 56 | mtcr r12 |
7e57cba0 | 57 | ld r12, PACA_KVM_SCRATCH0(r13) |
c862125c AG |
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: | |
b4433a7c AG |
63 | |
64 | /* Should we just skip the faulting instruction? */ | |
65 | cmpwi r12, KVM_GUEST_MODE_SKIP | |
66 | beq kvmppc_handler_skip_ins | |
67 | ||
c862125c AG |
68 | /* Let's store which interrupt we're handling */ |
69 | li r12, \intno | |
70 | ||
71 | /* Jump into the SLB exit code that goes to the highmem handler */ | |
72 | b kvmppc_handler_trampoline_exit | |
73 | ||
74 | .endm | |
75 | ||
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 | |
92 | ||
b4433a7c AG |
93 | /* |
94 | * Bring us back to the faulting code, but skip the | |
95 | * faulting instruction. | |
96 | * | |
97 | * This is a generic exit path from the interrupt | |
98 | * trampolines above. | |
99 | * | |
100 | * Input Registers: | |
101 | * | |
102 | * R12 = free | |
103 | * R13 = PACA | |
104 | * PACA.KVM.SCRATCH0 = guest R12 | |
105 | * PACA.KVM.SCRATCH1 = guest CR | |
106 | * SPRG_SCRATCH0 = guest R13 | |
107 | * | |
108 | */ | |
109 | kvmppc_handler_skip_ins: | |
110 | ||
111 | /* Patch the IP to the next instruction */ | |
112 | mfsrr0 r12 | |
113 | addi r12, r12, 4 | |
114 | mtsrr0 r12 | |
115 | ||
116 | /* Clean up all state */ | |
117 | lwz r12, PACA_KVM_SCRATCH1(r13) | |
118 | mtcr r12 | |
119 | ld r12, PACA_KVM_SCRATCH0(r13) | |
120 | mfspr r13, SPRN_SPRG_SCRATCH0 | |
121 | ||
122 | /* And get back into the code */ | |
123 | RFI | |
124 | ||
c862125c AG |
125 | /* |
126 | * This trampoline brings us back to a real mode handler | |
127 | * | |
128 | * Input Registers: | |
129 | * | |
7e57cba0 AG |
130 | * R5 = SRR0 |
131 | * R6 = SRR1 | |
c862125c AG |
132 | * LR = real-mode IP |
133 | * | |
134 | */ | |
135 | .global kvmppc_handler_lowmem_trampoline | |
136 | kvmppc_handler_lowmem_trampoline: | |
137 | ||
7e57cba0 AG |
138 | mtsrr0 r5 |
139 | mtsrr1 r6 | |
c862125c AG |
140 | blr |
141 | kvmppc_handler_lowmem_trampoline_end: | |
142 | ||
021ec9c6 AG |
143 | /* |
144 | * Call a function in real mode | |
145 | * | |
146 | * Input Registers: | |
147 | * | |
148 | * R3 = function | |
149 | * R4 = MSR | |
150 | * R5 = CTR | |
151 | * | |
152 | */ | |
153 | _GLOBAL(kvmppc_rmcall) | |
154 | mtmsr r4 /* Disable relocation, so mtsrr | |
155 | doesn't get interrupted */ | |
156 | mtctr r5 | |
157 | mtsrr0 r3 | |
158 | mtsrr1 r4 | |
159 | RFI | |
160 | ||
c862125c AG |
161 | .global kvmppc_trampoline_lowmem |
162 | kvmppc_trampoline_lowmem: | |
163 | .long kvmppc_handler_lowmem_trampoline - _stext | |
164 | ||
165 | .global kvmppc_trampoline_enter | |
166 | kvmppc_trampoline_enter: | |
167 | .long kvmppc_handler_trampoline_enter - _stext | |
168 | ||
169 | #include "book3s_64_slb.S" | |
170 |