diff options
author | Marc Zyngier <marc.zyngier@arm.com> | 2012-12-07 12:54:54 -0500 |
---|---|---|
committer | Marc Zyngier <marc.zyngier@arm.com> | 2013-06-12 11:40:30 -0400 |
commit | 1f17f3b6044d8a81a74dc6c962b3b38a7336106b (patch) | |
tree | f3dc2ffd6dd82c7f2d546fcc2c18c18d3b59b53f /arch | |
parent | c4b1afd022e93eada6ee4b209be37101cd4b3494 (diff) |
arm64: KVM: Plug the VGIC
Add support for the in-kernel GIC emulation.
Reviewed-by: Christopher Covington <cov@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm64/kvm/hyp.S | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S index 0b18c2e1e043..8dc27a367d77 100644 --- a/arch/arm64/kvm/hyp.S +++ b/arch/arm64/kvm/hyp.S | |||
@@ -306,6 +306,90 @@ __kvm_hyp_code_start: | |||
306 | msr vttbr_el2, xzr | 306 | msr vttbr_el2, xzr |
307 | .endm | 307 | .endm |
308 | 308 | ||
309 | /* | ||
310 | * Save the VGIC CPU state into memory | ||
311 | * x0: Register pointing to VCPU struct | ||
312 | * Do not corrupt x1!!! | ||
313 | */ | ||
314 | .macro save_vgic_state | ||
315 | /* Get VGIC VCTRL base into x2 */ | ||
316 | ldr x2, [x0, #VCPU_KVM] | ||
317 | kern_hyp_va x2 | ||
318 | ldr x2, [x2, #KVM_VGIC_VCTRL] | ||
319 | kern_hyp_va x2 | ||
320 | cbz x2, 2f // disabled | ||
321 | |||
322 | /* Compute the address of struct vgic_cpu */ | ||
323 | add x3, x0, #VCPU_VGIC_CPU | ||
324 | |||
325 | /* Save all interesting registers */ | ||
326 | ldr w4, [x2, #GICH_HCR] | ||
327 | ldr w5, [x2, #GICH_VMCR] | ||
328 | ldr w6, [x2, #GICH_MISR] | ||
329 | ldr w7, [x2, #GICH_EISR0] | ||
330 | ldr w8, [x2, #GICH_EISR1] | ||
331 | ldr w9, [x2, #GICH_ELRSR0] | ||
332 | ldr w10, [x2, #GICH_ELRSR1] | ||
333 | ldr w11, [x2, #GICH_APR] | ||
334 | |||
335 | str w4, [x3, #VGIC_CPU_HCR] | ||
336 | str w5, [x3, #VGIC_CPU_VMCR] | ||
337 | str w6, [x3, #VGIC_CPU_MISR] | ||
338 | str w7, [x3, #VGIC_CPU_EISR] | ||
339 | str w8, [x3, #(VGIC_CPU_EISR + 4)] | ||
340 | str w9, [x3, #VGIC_CPU_ELRSR] | ||
341 | str w10, [x3, #(VGIC_CPU_ELRSR + 4)] | ||
342 | str w11, [x3, #VGIC_CPU_APR] | ||
343 | |||
344 | /* Clear GICH_HCR */ | ||
345 | str wzr, [x2, #GICH_HCR] | ||
346 | |||
347 | /* Save list registers */ | ||
348 | add x2, x2, #GICH_LR0 | ||
349 | ldr w4, [x3, #VGIC_CPU_NR_LR] | ||
350 | add x3, x3, #VGIC_CPU_LR | ||
351 | 1: ldr w5, [x2], #4 | ||
352 | str w5, [x3], #4 | ||
353 | sub w4, w4, #1 | ||
354 | cbnz w4, 1b | ||
355 | 2: | ||
356 | .endm | ||
357 | |||
358 | /* | ||
359 | * Restore the VGIC CPU state from memory | ||
360 | * x0: Register pointing to VCPU struct | ||
361 | */ | ||
362 | .macro restore_vgic_state | ||
363 | /* Get VGIC VCTRL base into x2 */ | ||
364 | ldr x2, [x0, #VCPU_KVM] | ||
365 | kern_hyp_va x2 | ||
366 | ldr x2, [x2, #KVM_VGIC_VCTRL] | ||
367 | kern_hyp_va x2 | ||
368 | cbz x2, 2f // disabled | ||
369 | |||
370 | /* Compute the address of struct vgic_cpu */ | ||
371 | add x3, x0, #VCPU_VGIC_CPU | ||
372 | |||
373 | /* We only restore a minimal set of registers */ | ||
374 | ldr w4, [x3, #VGIC_CPU_HCR] | ||
375 | ldr w5, [x3, #VGIC_CPU_VMCR] | ||
376 | ldr w6, [x3, #VGIC_CPU_APR] | ||
377 | |||
378 | str w4, [x2, #GICH_HCR] | ||
379 | str w5, [x2, #GICH_VMCR] | ||
380 | str w6, [x2, #GICH_APR] | ||
381 | |||
382 | /* Restore list registers */ | ||
383 | add x2, x2, #GICH_LR0 | ||
384 | ldr w4, [x3, #VGIC_CPU_NR_LR] | ||
385 | add x3, x3, #VGIC_CPU_LR | ||
386 | 1: ldr w5, [x3], #4 | ||
387 | str w5, [x2], #4 | ||
388 | sub w4, w4, #1 | ||
389 | cbnz w4, 1b | ||
390 | 2: | ||
391 | .endm | ||
392 | |||
309 | __save_sysregs: | 393 | __save_sysregs: |
310 | save_sysregs | 394 | save_sysregs |
311 | ret | 395 | ret |
@@ -348,6 +432,8 @@ ENTRY(__kvm_vcpu_run) | |||
348 | activate_traps | 432 | activate_traps |
349 | activate_vm | 433 | activate_vm |
350 | 434 | ||
435 | restore_vgic_state | ||
436 | |||
351 | // Guest context | 437 | // Guest context |
352 | add x2, x0, #VCPU_CONTEXT | 438 | add x2, x0, #VCPU_CONTEXT |
353 | 439 | ||
@@ -369,6 +455,8 @@ __kvm_vcpu_return: | |||
369 | bl __save_fpsimd | 455 | bl __save_fpsimd |
370 | bl __save_sysregs | 456 | bl __save_sysregs |
371 | 457 | ||
458 | save_vgic_state | ||
459 | |||
372 | deactivate_traps | 460 | deactivate_traps |
373 | deactivate_vm | 461 | deactivate_vm |
374 | 462 | ||