1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2012-2015 - ARM Ltd
4 * Author: Marc Zyngier <marc.zyngier@arm.com>
7 #include <clocksource/arm_arch_timer.h>
8 #include <linux/compiler.h>
9 #include <linux/kvm_host.h>
11 #include <asm/kvm_hyp.h>
12 #include <asm/kvm_mmu.h>
14 void __kvm_timer_set_cntvoff(u64 cntvoff)
16 write_sysreg(cntvoff, cntvoff_el2);
20 * Should only be called on non-VHE or hVHE setups.
21 * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
23 void __timer_disable_traps(struct kvm_vcpu *vcpu)
30 /* Allow physical timer/counter access for the host */
31 val = read_sysreg(cnthctl_el2);
32 val |= (CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN) << shift;
33 write_sysreg(val, cnthctl_el2);
37 * Should only be called on non-VHE or hVHE setups.
38 * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
40 void __timer_enable_traps(struct kvm_vcpu *vcpu)
45 * Disallow physical timer access for the guest
46 * Physical counter access is allowed if no offset is enforced
47 * or running protected (we don't offset anything in this case).
49 clr = CNTHCTL_EL1PCEN;
50 if (is_protected_kvm_enabled() ||
51 !kern_hyp_va(vcpu->kvm)->arch.timer_data.poffset)
52 set |= CNTHCTL_EL1PCTEN;
54 clr |= CNTHCTL_EL1PCTEN;
61 sysreg_clear_set(cnthctl_el2, clr, set);