Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2012-2015 - ARM Ltd
0004  * Author: Marc Zyngier <marc.zyngier@arm.com>
0005  */
0006 
0007 #include <clocksource/arm_arch_timer.h>
0008 #include <linux/compiler.h>
0009 #include <linux/kvm_host.h>
0010 
0011 #include <asm/kvm_hyp.h>
0012 
0013 void __kvm_timer_set_cntvoff(u64 cntvoff)
0014 {
0015     write_sysreg(cntvoff, cntvoff_el2);
0016 }
0017 
0018 /*
0019  * Should only be called on non-VHE systems.
0020  * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
0021  */
0022 void __timer_disable_traps(struct kvm_vcpu *vcpu)
0023 {
0024     u64 val;
0025 
0026     /* Allow physical timer/counter access for the host */
0027     val = read_sysreg(cnthctl_el2);
0028     val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN;
0029     write_sysreg(val, cnthctl_el2);
0030 }
0031 
0032 /*
0033  * Should only be called on non-VHE systems.
0034  * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
0035  */
0036 void __timer_enable_traps(struct kvm_vcpu *vcpu)
0037 {
0038     u64 val;
0039 
0040     /*
0041      * Disallow physical timer access for the guest
0042      * Physical counter access is allowed
0043      */
0044     val = read_sysreg(cnthctl_el2);
0045     val &= ~CNTHCTL_EL1PCEN;
0046     val |= CNTHCTL_EL1PCTEN;
0047     write_sysreg(val, cnthctl_el2);
0048 }