GNU Linux-libre 4.19.286-gnu1
[releases.git] / virt / kvm / arm / hyp / timer-sr.c
1 /*
2  * Copyright (C) 2012-2015 - ARM Ltd
3  * Author: Marc Zyngier <marc.zyngier@arm.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <clocksource/arm_arch_timer.h>
19 #include <linux/compiler.h>
20 #include <linux/kvm_host.h>
21
22 #include <asm/kvm_hyp.h>
23
24 void __hyp_text __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high)
25 {
26         u64 cntvoff = (u64)cntvoff_high << 32 | cntvoff_low;
27         write_sysreg(cntvoff, cntvoff_el2);
28 }
29
30 /*
31  * Should only be called on non-VHE systems.
32  * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
33  */
34 void __hyp_text __timer_disable_traps(struct kvm_vcpu *vcpu)
35 {
36         u64 val;
37
38         /* Allow physical timer/counter access for the host */
39         val = read_sysreg(cnthctl_el2);
40         val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN;
41         write_sysreg(val, cnthctl_el2);
42 }
43
44 /*
45  * Should only be called on non-VHE systems.
46  * VHE systems use EL2 timers and configure EL1 timers in kvm_timer_init_vhe().
47  */
48 void __hyp_text __timer_enable_traps(struct kvm_vcpu *vcpu)
49 {
50         u64 val;
51
52         /*
53          * Disallow physical timer access for the guest
54          * Physical counter access is allowed
55          */
56         val = read_sysreg(cnthctl_el2);
57         val &= ~CNTHCTL_EL1PCEN;
58         val |= CNTHCTL_EL1PCTEN;
59         write_sysreg(val, cnthctl_el2);
60 }