1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include <clocksource/arm_arch_timer.h>
- #include <linux/compiler.h>
- #include <linux/kvm_host.h>
- #include <asm/kvm_hyp.h>
- void __hyp_text __timer_save_state(struct kvm_vcpu *vcpu)
- {
- struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
- u64 val;
- if (timer->enabled) {
- timer->cntv_ctl = read_sysreg_el0(cntv_ctl);
- timer->cntv_cval = read_sysreg_el0(cntv_cval);
- }
-
- write_sysreg_el0(0, cntv_ctl);
-
- val = read_sysreg(cnthctl_el2);
- val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN;
- write_sysreg(val, cnthctl_el2);
-
- write_sysreg(0, cntvoff_el2);
- }
- void __hyp_text __timer_restore_state(struct kvm_vcpu *vcpu)
- {
- struct kvm *kvm = kern_hyp_va(vcpu->kvm);
- struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
- u64 val;
-
- val = read_sysreg(cnthctl_el2);
- val &= ~CNTHCTL_EL1PCEN;
- val |= CNTHCTL_EL1PCTEN;
- write_sysreg(val, cnthctl_el2);
- if (timer->enabled) {
- write_sysreg(kvm->arch.timer.cntvoff, cntvoff_el2);
- write_sysreg_el0(timer->cntv_cval, cntv_cval);
- isb();
- write_sysreg_el0(timer->cntv_ctl, cntv_ctl);
- }
- }
|