aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMarc Zyngier <marc.zyngier@arm.com>2013-01-23 13:21:59 -0500
committerMarc Zyngier <marc.zyngier@arm.com>2013-02-11 14:05:38 -0500
commitc7e3ba64ba16eddfbfc66ec099860f40e808e124 (patch)
tree42050cb8efe5233629efaabc3917bad4a22741c8 /arch
parent53e724067a4ee9373972079e225d0d5f683b9c5a (diff)
ARM: KVM: arch_timers: Add timer world switch
Do the necessary save/restore dance for the timers in the world switch code. In the process, allow the guest to read the physical counter, which is useful for its own clock_event_device. Reviewed-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/include/asm/kvm_asm.h3
-rw-r--r--arch/arm/kernel/asm-offsets.c6
-rw-r--r--arch/arm/kvm/arm.c3
-rw-r--r--arch/arm/kvm/coproc.c4
-rw-r--r--arch/arm/kvm/interrupts_head.S59
5 files changed, 74 insertions, 1 deletions
diff --git a/arch/arm/include/asm/kvm_asm.h b/arch/arm/include/asm/kvm_asm.h
index 5e06e8177784..e4956f4e23e1 100644
--- a/arch/arm/include/asm/kvm_asm.h
+++ b/arch/arm/include/asm/kvm_asm.h
@@ -45,7 +45,8 @@
45#define c13_TID_URW 23 /* Thread ID, User R/W */ 45#define c13_TID_URW 23 /* Thread ID, User R/W */
46#define c13_TID_URO 24 /* Thread ID, User R/O */ 46#define c13_TID_URO 24 /* Thread ID, User R/O */
47#define c13_TID_PRIV 25 /* Thread ID, Privileged */ 47#define c13_TID_PRIV 25 /* Thread ID, Privileged */
48#define NR_CP15_REGS 26 /* Number of regs (incl. invalid) */ 48#define c14_CNTKCTL 26 /* Timer Control Register (PL1) */
49#define NR_CP15_REGS 27 /* Number of regs (incl. invalid) */
49 50
50#define ARM_EXCEPTION_RESET 0 51#define ARM_EXCEPTION_RESET 0
51#define ARM_EXCEPTION_UNDEFINED 1 52#define ARM_EXCEPTION_UNDEFINED 1
diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c
index 17cea2e78d88..5ce738b43508 100644
--- a/arch/arm/kernel/asm-offsets.c
+++ b/arch/arm/kernel/asm-offsets.c
@@ -179,6 +179,12 @@ int main(void)
179 DEFINE(VGIC_CPU_APR, offsetof(struct vgic_cpu, vgic_apr)); 179 DEFINE(VGIC_CPU_APR, offsetof(struct vgic_cpu, vgic_apr));
180 DEFINE(VGIC_CPU_LR, offsetof(struct vgic_cpu, vgic_lr)); 180 DEFINE(VGIC_CPU_LR, offsetof(struct vgic_cpu, vgic_lr));
181 DEFINE(VGIC_CPU_NR_LR, offsetof(struct vgic_cpu, nr_lr)); 181 DEFINE(VGIC_CPU_NR_LR, offsetof(struct vgic_cpu, nr_lr));
182#ifdef CONFIG_KVM_ARM_TIMER
183 DEFINE(VCPU_TIMER_CNTV_CTL, offsetof(struct kvm_vcpu, arch.timer_cpu.cntv_ctl));
184 DEFINE(VCPU_TIMER_CNTV_CVAL, offsetof(struct kvm_vcpu, arch.timer_cpu.cntv_cval));
185 DEFINE(KVM_TIMER_CNTVOFF, offsetof(struct kvm, arch.timer.cntvoff));
186 DEFINE(KVM_TIMER_ENABLED, offsetof(struct kvm, arch.timer.enabled));
187#endif
182 DEFINE(KVM_VGIC_VCTRL, offsetof(struct kvm, arch.vgic.vctrl_base)); 188 DEFINE(KVM_VGIC_VCTRL, offsetof(struct kvm, arch.vgic.vctrl_base));
183#endif 189#endif
184 DEFINE(KVM_VTTBR, offsetof(struct kvm, arch.vttbr)); 190 DEFINE(KVM_VTTBR, offsetof(struct kvm, arch.vttbr));
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index ea7383293ed0..800b2cd804d3 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -718,6 +718,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
718 vcpu_pause(vcpu); 718 vcpu_pause(vcpu);
719 719
720 kvm_vgic_flush_hwstate(vcpu); 720 kvm_vgic_flush_hwstate(vcpu);
721 kvm_timer_flush_hwstate(vcpu);
721 722
722 local_irq_disable(); 723 local_irq_disable();
723 724
@@ -731,6 +732,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
731 732
732 if (ret <= 0 || need_new_vmid_gen(vcpu->kvm)) { 733 if (ret <= 0 || need_new_vmid_gen(vcpu->kvm)) {
733 local_irq_enable(); 734 local_irq_enable();
735 kvm_timer_sync_hwstate(vcpu);
734 kvm_vgic_sync_hwstate(vcpu); 736 kvm_vgic_sync_hwstate(vcpu);
735 continue; 737 continue;
736 } 738 }
@@ -764,6 +766,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
764 * Back from guest 766 * Back from guest
765 *************************************************************/ 767 *************************************************************/
766 768
769 kvm_timer_sync_hwstate(vcpu);
767 kvm_vgic_sync_hwstate(vcpu); 770 kvm_vgic_sync_hwstate(vcpu);
768 771
769 ret = handle_exit(vcpu, run, ret); 772 ret = handle_exit(vcpu, run, ret);
diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c
index d782638c7ec0..4ea9a982269c 100644
--- a/arch/arm/kvm/coproc.c
+++ b/arch/arm/kvm/coproc.c
@@ -222,6 +222,10 @@ static const struct coproc_reg cp15_regs[] = {
222 NULL, reset_unknown, c13_TID_URO }, 222 NULL, reset_unknown, c13_TID_URO },
223 { CRn(13), CRm( 0), Op1( 0), Op2( 4), is32, 223 { CRn(13), CRm( 0), Op1( 0), Op2( 4), is32,
224 NULL, reset_unknown, c13_TID_PRIV }, 224 NULL, reset_unknown, c13_TID_PRIV },
225
226 /* CNTKCTL: swapped by interrupt.S. */
227 { CRn(14), CRm( 1), Op1( 0), Op2( 0), is32,
228 NULL, reset_val, c14_CNTKCTL, 0x00000000 },
225}; 229};
226 230
227/* Target specific emulation tables */ 231/* Target specific emulation tables */
diff --git a/arch/arm/kvm/interrupts_head.S b/arch/arm/kvm/interrupts_head.S
index 06f251395bec..3c8f2f0b4c5e 100644
--- a/arch/arm/kvm/interrupts_head.S
+++ b/arch/arm/kvm/interrupts_head.S
@@ -300,6 +300,14 @@ vcpu .req r0 @ vcpu pointer always in r0
300 str r11, [vcpu, #CP15_OFFSET(c6_IFAR)] 300 str r11, [vcpu, #CP15_OFFSET(c6_IFAR)]
301 str r12, [vcpu, #CP15_OFFSET(c12_VBAR)] 301 str r12, [vcpu, #CP15_OFFSET(c12_VBAR)]
302 .endif 302 .endif
303
304 mrc p15, 0, r2, c14, c1, 0 @ CNTKCTL
305
306 .if \store_to_vcpu == 0
307 push {r2}
308 .else
309 str r2, [vcpu, #CP15_OFFSET(c14_CNTKCTL)]
310 .endif
303.endm 311.endm
304 312
305/* 313/*
@@ -311,6 +319,14 @@ vcpu .req r0 @ vcpu pointer always in r0
311 */ 319 */
312.macro write_cp15_state read_from_vcpu 320.macro write_cp15_state read_from_vcpu
313 .if \read_from_vcpu == 0 321 .if \read_from_vcpu == 0
322 pop {r2}
323 .else
324 ldr r2, [vcpu, #CP15_OFFSET(c14_CNTKCTL)]
325 .endif
326
327 mcr p15, 0, r2, c14, c1, 0 @ CNTKCTL
328
329 .if \read_from_vcpu == 0
314 pop {r2-r12} 330 pop {r2-r12}
315 .else 331 .else
316 ldr r2, [vcpu, #CP15_OFFSET(c13_CID)] 332 ldr r2, [vcpu, #CP15_OFFSET(c13_CID)]
@@ -461,8 +477,28 @@ vcpu .req r0 @ vcpu pointer always in r0
461 * for the host. 477 * for the host.
462 * 478 *
463 * Assumes vcpu pointer in vcpu reg 479 * Assumes vcpu pointer in vcpu reg
480 * Clobbers r2-r5
464 */ 481 */
465.macro save_timer_state 482.macro save_timer_state
483#ifdef CONFIG_KVM_ARM_TIMER
484 ldr r4, [vcpu, #VCPU_KVM]
485 ldr r2, [r4, #KVM_TIMER_ENABLED]
486 cmp r2, #0
487 beq 1f
488
489 mrc p15, 0, r2, c14, c3, 1 @ CNTV_CTL
490 str r2, [vcpu, #VCPU_TIMER_CNTV_CTL]
491 bic r2, #1 @ Clear ENABLE
492 mcr p15, 0, r2, c14, c3, 1 @ CNTV_CTL
493 isb
494
495 mrrc p15, 3, r2, r3, c14 @ CNTV_CVAL
496 ldr r4, =VCPU_TIMER_CNTV_CVAL
497 add r5, vcpu, r4
498 strd r2, r3, [r5]
499
5001:
501#endif
466 @ Allow physical timer/counter access for the host 502 @ Allow physical timer/counter access for the host
467 mrc p15, 4, r2, c14, c1, 0 @ CNTHCTL 503 mrc p15, 4, r2, c14, c1, 0 @ CNTHCTL
468 orr r2, r2, #(CNTHCTL_PL1PCEN | CNTHCTL_PL1PCTEN) 504 orr r2, r2, #(CNTHCTL_PL1PCEN | CNTHCTL_PL1PCTEN)
@@ -474,6 +510,7 @@ vcpu .req r0 @ vcpu pointer always in r0
474 * for the host. 510 * for the host.
475 * 511 *
476 * Assumes vcpu pointer in vcpu reg 512 * Assumes vcpu pointer in vcpu reg
513 * Clobbers r2-r5
477 */ 514 */
478.macro restore_timer_state 515.macro restore_timer_state
479 @ Disallow physical timer access for the guest 516 @ Disallow physical timer access for the guest
@@ -482,6 +519,28 @@ vcpu .req r0 @ vcpu pointer always in r0
482 orr r2, r2, #CNTHCTL_PL1PCTEN 519 orr r2, r2, #CNTHCTL_PL1PCTEN
483 bic r2, r2, #CNTHCTL_PL1PCEN 520 bic r2, r2, #CNTHCTL_PL1PCEN
484 mcr p15, 4, r2, c14, c1, 0 @ CNTHCTL 521 mcr p15, 4, r2, c14, c1, 0 @ CNTHCTL
522
523#ifdef CONFIG_KVM_ARM_TIMER
524 ldr r4, [vcpu, #VCPU_KVM]
525 ldr r2, [r4, #KVM_TIMER_ENABLED]
526 cmp r2, #0
527 beq 1f
528
529 ldr r2, [r4, #KVM_TIMER_CNTVOFF]
530 ldr r3, [r4, #(KVM_TIMER_CNTVOFF + 4)]
531 mcrr p15, 4, r2, r3, c14 @ CNTVOFF
532
533 ldr r4, =VCPU_TIMER_CNTV_CVAL
534 add r5, vcpu, r4
535 ldrd r2, r3, [r5]
536 mcrr p15, 3, r2, r3, c14 @ CNTV_CVAL
537 isb
538
539 ldr r2, [vcpu, #VCPU_TIMER_CNTV_CTL]
540 and r2, r2, #3
541 mcr p15, 0, r2, c14, c3, 1 @ CNTV_CTL
5421:
543#endif
485.endm 544.endm
486 545
487.equ vmentry, 0 546.equ vmentry, 0