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 #define SHADOW_SLB_ESID(num) (SLBSHADOW_SAVEAREA + (num * 0x10))
21 #define SHADOW_SLB_VSID(num) (SLBSHADOW_SAVEAREA + (num * 0x10) + 0x8)
22 #define UNBOLT_SLB_ENTRY(num) \
23 ld r9, SHADOW_SLB_ESID(num)(r12); \
24 /* Invalid? Skip. */; \
25 rldicl. r0, r9, 37, 63; \
26 beq slb_entry_skip_ ## num; \
27 xoris r9, r9, SLB_ESID_V@h; \
28 std r9, SHADOW_SLB_ESID(num)(r12); \
29 slb_entry_skip_ ## num:
31 #define REBOLT_SLB_ENTRY(num) \
32 ld r10, SHADOW_SLB_ESID(num)(r11); \
34 beq slb_exit_skip_ ## num; \
35 oris r10, r10, SLB_ESID_V@h; \
36 ld r9, SHADOW_SLB_VSID(num)(r11); \
38 std r10, SHADOW_SLB_ESID(num)(r11); \
39 slb_exit_skip_ ## num:
41 /******************************************************************************
45 *****************************************************************************/
47 .global kvmppc_handler_trampoline_enter
48 kvmppc_handler_trampoline_enter:
58 * all other GPRS = free
59 * PACA[KVM_CR] = guest CR
60 * PACA[KVM_XER] = guest XER
66 /* Activate guest mode, so faults get handled by KVM */
67 li r11, KVM_GUEST_MODE_GUEST
68 stb r11, PACA_KVM_IN_GUEST(r13)
70 /* Remove LPAR shadow entries */
72 #if SLB_NUM_BOLTED == 3
74 ld r12, PACA_SLBSHADOWPTR(r13)
76 /* Save off the first entry so we can slbie it later */
77 ld r10, SHADOW_SLB_ESID(0)(r12)
78 ld r11, SHADOW_SLB_VSID(0)(r12)
80 /* Remove bolted entries */
86 #error unknown number of bolted entries
93 /* r0 = esid & ESID_MASK */
94 rldicr r10, r10, 0, 35
95 /* r0 |= CLASS_BIT(VSID) */
96 rldic r12, r11, 56 - 36, 36
102 /* Fill SLB with our shadow */
104 lbz r12, PACA_KVM_SLB_MAX(r13)
106 addi r12, r12, PACA_KVM_SLB
109 /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
117 rldicl. r0, r10, 37, 63
118 beq slb_loop_enter_skip
132 ld r0, (PACA_KVM_R0)(r13)
133 ld r1, (PACA_KVM_R1)(r13)
134 ld r2, (PACA_KVM_R2)(r13)
135 ld r3, (PACA_KVM_R3)(r13)
136 ld r4, (PACA_KVM_R4)(r13)
137 ld r5, (PACA_KVM_R5)(r13)
138 ld r6, (PACA_KVM_R6)(r13)
139 ld r7, (PACA_KVM_R7)(r13)
140 ld r8, (PACA_KVM_R8)(r13)
141 ld r9, (PACA_KVM_R9)(r13)
142 ld r10, (PACA_KVM_R10)(r13)
143 ld r12, (PACA_KVM_R12)(r13)
145 lwz r11, (PACA_KVM_CR)(r13)
148 ld r11, (PACA_KVM_XER)(r13)
151 ld r11, (PACA_KVM_R11)(r13)
152 ld r13, (PACA_KVM_R13)(r13)
155 kvmppc_handler_trampoline_enter_end:
159 /******************************************************************************
163 *****************************************************************************/
165 .global kvmppc_handler_trampoline_exit
166 kvmppc_handler_trampoline_exit:
168 /* Register usage at this point:
170 * SPRG_SCRATCH0 = guest R13
171 * R12 = exit handler id
173 * PACA.KVM.SCRATCH0 = guest R12
174 * PACA.KVM.SCRATCH1 = guest CR
180 std r0, PACA_KVM_R0(r13)
181 std r1, PACA_KVM_R1(r13)
182 std r2, PACA_KVM_R2(r13)
183 std r3, PACA_KVM_R3(r13)
184 std r4, PACA_KVM_R4(r13)
185 std r5, PACA_KVM_R5(r13)
186 std r6, PACA_KVM_R6(r13)
187 std r7, PACA_KVM_R7(r13)
188 std r8, PACA_KVM_R8(r13)
189 std r9, PACA_KVM_R9(r13)
190 std r10, PACA_KVM_R10(r13)
191 std r11, PACA_KVM_R11(r13)
193 /* Restore R1/R2 so we can handle faults */
194 ld r1, PACA_KVM_HOST_R1(r13)
195 ld r2, PACA_KVM_HOST_R2(r13)
197 /* Save guest PC and MSR in GPRs */
201 /* Get scratch'ed off registers */
202 mfspr r9, SPRN_SPRG_SCRATCH0
203 std r9, PACA_KVM_R13(r13)
205 ld r8, PACA_KVM_SCRATCH0(r13)
206 std r8, PACA_KVM_R12(r13)
208 lwz r7, PACA_KVM_SCRATCH1(r13)
209 stw r7, PACA_KVM_CR(r13)
211 /* Save more register state */
214 stw r6, PACA_KVM_XER(r13)
220 * In order for us to easily get the last instruction,
221 * we got the #vmexit at, we exploit the fact that the
222 * virtual layout is still the same here, so we can just
223 * ld from the guest's PC address
226 /* We only load the last instruction when it's safe */
227 cmpwi r12, BOOK3S_INTERRUPT_DATA_STORAGE
229 cmpwi r12, BOOK3S_INTERRUPT_PROGRAM
235 /* Save off the guest instruction we're at */
237 /* Set guest mode to 'jump over instruction' so if lwz faults
238 * we'll just continue at the next IP. */
239 li r9, KVM_GUEST_MODE_SKIP
240 stb r9, PACA_KVM_IN_GUEST(r13)
242 /* 1) enable paging for data */
244 ori r11, r9, MSR_DR /* Enable paging for data */
246 /* 2) fetch the instruction */
247 li r0, KVM_INST_FETCH_FAILED /* In case lwz faults */
249 /* 3) disable paging again */
254 /* Unset guest mode */
255 li r9, KVM_GUEST_MODE_NONE
256 stb r9, PACA_KVM_IN_GUEST(r13)
258 /* Restore bolted entries from the shadow and fix it along the way */
260 /* We don't store anything in entry 0, so we don't need to take care of it */
264 #if SLB_NUM_BOLTED == 3
266 ld r11, PACA_SLBSHADOWPTR(r13)
273 #error unknown number of bolted entries
278 /* Register usage at this point:
280 * R0 = guest last inst
287 * R12 = exit handler id
289 * PACA.KVM.* = guest *
293 /* RFI into the highmem handler */
295 ori r7, r7, MSR_IR|MSR_DR|MSR_RI /* Enable paging */
297 ld r8, PACA_KVM_VMHANDLER(r13) /* Highmem handler address */
301 kvmppc_handler_trampoline_exit_end: