1
2
3
4
5
6
7
8
9
10
11 #include <asm/asm-compat.h>
12 #include <asm/feature-fixups.h>
13
14 #if defined(CONFIG_PPC_BOOK3S_64)
15
16 #define GET_SHADOW_VCPU(reg) \
17 mr reg, r13
18
19 #elif defined(CONFIG_PPC_BOOK3S_32)
20
21 #define GET_SHADOW_VCPU(reg) \
22 tophys(reg, r2); \
23 lwz reg, (THREAD + THREAD_KVM_SVCPU)(reg); \
24 tophys(reg, reg)
25
26 #endif
27
28
29 #define USE_QUICK_LAST_INST
30
31
32
33
34 #if defined(CONFIG_PPC_BOOK3S_64)
35 #include "book3s_64_slb.S"
36 #elif defined(CONFIG_PPC_BOOK3S_32)
37 #include "book3s_32_sr.S"
38 #endif
39
40
41
42
43
44
45
46 .global kvmppc_handler_trampoline_enter
47 kvmppc_handler_trampoline_enter:
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 GET_SHADOW_VCPU(r3)
67
68
69 mflr r0
70 PPC_STL r0, HSTATE_VMHANDLER(r3)
71 PPC_STL r5, HSTATE_HOST_MSR(r3)
72
73
74 PPC_STL r1, HSTATE_HOST_R1(r3)
75 PPC_STL r2, HSTATE_HOST_R2(r3)
76
77
78 li r11, KVM_GUEST_MODE_GUEST
79 stb r11, HSTATE_IN_GUEST(r3)
80
81
82 LOAD_GUEST_SEGMENTS
83
84 #ifdef CONFIG_PPC_BOOK3S_64
85 BEGIN_FTR_SECTION
86
87 mfspr r8, SPRN_FSCR
88 std r8, HSTATE_HOST_FSCR(r13)
89
90 ld r9, SVCPU_SHADOW_FSCR(r13)
91 mtspr SPRN_FSCR, r9
92 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
93
94
95
96
97
98
99
100
101
102 lbz r0, HSTATE_RESTORE_HID5(r3)
103 cmpwi r0, 0
104 beq no_dcbz32_on
105
106 mfspr r0,SPRN_HID5
107 ori r0, r0, 0x80
108 mtspr SPRN_HID5,r0
109 no_dcbz32_on:
110
111 #endif
112
113
114
115 PPC_LL r8, SVCPU_CTR(r3)
116 PPC_LL r9, SVCPU_LR(r3)
117 lwz r10, SVCPU_CR(r3)
118 PPC_LL r11, SVCPU_XER(r3)
119
120 mtctr r8
121 mtlr r9
122 mtcr r10
123 mtxer r11
124
125
126 PPC_LL r9, SVCPU_PC(r3)
127
128 li r0, MSR_RI
129 andc r6, r6, r0
130
131 PPC_LL r0, SVCPU_R0(r3)
132 PPC_LL r1, SVCPU_R1(r3)
133 PPC_LL r2, SVCPU_R2(r3)
134 PPC_LL r5, SVCPU_R5(r3)
135 PPC_LL r7, SVCPU_R7(r3)
136 PPC_LL r8, SVCPU_R8(r3)
137 PPC_LL r10, SVCPU_R10(r3)
138 PPC_LL r11, SVCPU_R11(r3)
139 PPC_LL r12, SVCPU_R12(r3)
140 PPC_LL r13, SVCPU_R13(r3)
141
142 MTMSR_EERI(r6)
143 mtsrr0 r9
144 mtsrr1 r4
145
146 PPC_LL r4, SVCPU_R4(r3)
147 PPC_LL r6, SVCPU_R6(r3)
148 PPC_LL r9, SVCPU_R9(r3)
149 PPC_LL r3, (SVCPU_R3)(r3)
150
151 RFI_TO_GUEST
152 kvmppc_handler_trampoline_enter_end:
153
154
155
156
157
158
159
160
161
162 .global kvmppc_interrupt_pr
163 kvmppc_interrupt_pr:
164
165
166
167
168
169
170
171
172 #ifdef CONFIG_PPC64
173
174 #ifdef CONFIG_RELOCATABLE
175 std r9, HSTATE_SCRATCH2(r13)
176 ld r9, HSTATE_SCRATCH1(r13)
177 mtctr r9
178 ld r9, HSTATE_SCRATCH2(r13)
179 #endif
180 rotldi r12, r12, 32
181 stw r12, HSTATE_SCRATCH1(r13)
182 srdi r12, r12, 32
183 #endif
184
185 .global kvmppc_handler_trampoline_exit
186 kvmppc_handler_trampoline_exit:
187
188
189
190
191
192
193
194
195
196
197
198 PPC_STL r0, SVCPU_R0(r13)
199 PPC_STL r1, SVCPU_R1(r13)
200 PPC_STL r2, SVCPU_R2(r13)
201 PPC_STL r3, SVCPU_R3(r13)
202 PPC_STL r4, SVCPU_R4(r13)
203 PPC_STL r5, SVCPU_R5(r13)
204 PPC_STL r6, SVCPU_R6(r13)
205 PPC_STL r7, SVCPU_R7(r13)
206 PPC_STL r8, SVCPU_R8(r13)
207 PPC_STL r9, SVCPU_R9(r13)
208 PPC_STL r10, SVCPU_R10(r13)
209 PPC_STL r11, SVCPU_R11(r13)
210
211
212 PPC_LL r1, HSTATE_HOST_R1(r13)
213 PPC_LL r2, HSTATE_HOST_R2(r13)
214
215
216 #ifdef CONFIG_PPC64
217 BEGIN_FTR_SECTION
218 andi. r0, r12, 0x2
219 cmpwi cr1, r0, 0
220 beq 1f
221 mfspr r3,SPRN_HSRR0
222 mfspr r4,SPRN_HSRR1
223 andi. r12,r12,0x3ffd
224 b 2f
225 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
226 #endif
227 1: mfsrr0 r3
228 mfsrr1 r4
229 2:
230 PPC_STL r3, SVCPU_PC(r13)
231 PPC_STL r4, SVCPU_SHADOW_SRR1(r13)
232
233
234 GET_SCRATCH0(r9)
235 PPC_LL r8, HSTATE_SCRATCH0(r13)
236 lwz r7, HSTATE_SCRATCH1(r13)
237
238 PPC_STL r9, SVCPU_R13(r13)
239 PPC_STL r8, SVCPU_R12(r13)
240 stw r7, SVCPU_CR(r13)
241
242
243
244 mfxer r5
245 mfdar r6
246 mfdsisr r7
247 mfctr r8
248 mflr r9
249
250 PPC_STL r5, SVCPU_XER(r13)
251 PPC_STL r6, SVCPU_FAULT_DAR(r13)
252 stw r7, SVCPU_FAULT_DSISR(r13)
253 PPC_STL r8, SVCPU_CTR(r13)
254 PPC_STL r9, SVCPU_LR(r13)
255
256
257
258
259
260
261
262
263
264 cmpwi r12, BOOK3S_INTERRUPT_DATA_STORAGE
265 beq ld_last_inst
266 cmpwi r12, BOOK3S_INTERRUPT_PROGRAM
267 beq ld_last_inst
268 cmpwi r12, BOOK3S_INTERRUPT_SYSCALL
269 beq ld_last_prev_inst
270 cmpwi r12, BOOK3S_INTERRUPT_ALIGNMENT
271 beq- ld_last_inst
272 #ifdef CONFIG_PPC64
273 BEGIN_FTR_SECTION
274 cmpwi r12, BOOK3S_INTERRUPT_H_EMUL_ASSIST
275 beq- ld_last_inst
276 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
277 BEGIN_FTR_SECTION
278 cmpwi r12, BOOK3S_INTERRUPT_FAC_UNAVAIL
279 beq- ld_last_inst
280 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
281 #endif
282
283 b no_ld_last_inst
284
285 ld_last_prev_inst:
286 addi r3, r3, -4
287
288 ld_last_inst:
289
290
291
292 li r0, KVM_INST_FETCH_FAILED
293
294 #ifdef USE_QUICK_LAST_INST
295
296
297
298 li r9, KVM_GUEST_MODE_SKIP
299 stb r9, HSTATE_IN_GUEST(r13)
300
301
302 mfmsr r9
303 ori r11, r9, MSR_DR
304 mtmsr r11
305 sync
306
307 lwz r0, 0(r3)
308
309 mtmsr r9
310 sync
311
312 #endif
313 stw r0, SVCPU_LAST_INST(r13)
314
315 no_ld_last_inst:
316
317
318 li r9, KVM_GUEST_MODE_NONE
319 stb r9, HSTATE_IN_GUEST(r13)
320
321
322 LOAD_HOST_SEGMENTS
323
324 #ifdef CONFIG_PPC_BOOK3S_64
325
326 lbz r5, HSTATE_RESTORE_HID5(r13)
327 cmpwi r5, 0
328 beq no_dcbz32_off
329
330 li r4, 0
331 mfspr r5,SPRN_HID5
332 rldimi r5,r4,6,56
333 mtspr SPRN_HID5,r5
334
335 no_dcbz32_off:
336
337 BEGIN_FTR_SECTION
338
339 cmpwi r12, BOOK3S_INTERRUPT_FAC_UNAVAIL
340 bne+ no_fscr_save
341 mfspr r7, SPRN_FSCR
342 std r7, SVCPU_SHADOW_FSCR(r13)
343 no_fscr_save:
344
345 ld r8, HSTATE_HOST_FSCR(r13)
346 mtspr SPRN_FSCR, r8
347 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
348
349 #endif
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377 PPC_LL r6, HSTATE_HOST_MSR(r13)
378 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
379
380
381
382
383
384
385
386
387 mfmsr r7
388 rldicl r7, r7, 64 - MSR_TS_S_LG, 62
389 rldimi r6, r7, MSR_TS_S_LG, 63 - MSR_TS_T_LG
390 #endif
391 PPC_LL r8, HSTATE_VMHANDLER(r13)
392
393 #ifdef CONFIG_PPC64
394 BEGIN_FTR_SECTION
395 beq cr1, 1f
396 mtspr SPRN_HSRR1, r6
397 mtspr SPRN_HSRR0, r8
398 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
399 #endif
400 1:
401 mtsrr1 r6
402
403 mtsrr0 r8
404
405
406 cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL
407 beqa BOOK3S_INTERRUPT_EXTERNAL
408 cmpwi r12, BOOK3S_INTERRUPT_DECREMENTER
409 beqa BOOK3S_INTERRUPT_DECREMENTER
410 cmpwi r12, BOOK3S_INTERRUPT_PERFMON
411 beqa BOOK3S_INTERRUPT_PERFMON
412 cmpwi r12, BOOK3S_INTERRUPT_DOORBELL
413 beqa BOOK3S_INTERRUPT_DOORBELL
414
415 RFI_TO_KERNEL
416 kvmppc_handler_trampoline_exit_end: