blob: f24404b3c8dff8016c358c9339655465a0468ee7 [file] [log] [blame]
Marc Zyngier1431af32015-10-19 16:32:20 +01001/*
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
Marc Zyngier13720a52016-01-28 13:44:07 +000022#include <asm/kvm_hyp.h>
Marc Zyngier1431af32015-10-19 16:32:20 +010023
Christoffer Dall688c50a2017-01-04 16:10:28 +010024void __hyp_text __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high)
Marc Zyngier1431af32015-10-19 16:32:20 +010025{
Christoffer Dall688c50a2017-01-04 16:10:28 +010026 u64 cntvoff = (u64)cntvoff_high << 32 | cntvoff_low;
27 write_sysreg(cntvoff, cntvoff_el2);
28}
29
Christoffer Dall688c50a2017-01-04 16:10:28 +010030void __hyp_text __timer_disable_traps(struct kvm_vcpu *vcpu)
31{
32 /*
Jintack Lim488f94d2016-12-01 14:32:05 -050033 * We don't need to do this for VHE since the host kernel runs in EL2
34 * with HCR_EL2.TGE ==1, which makes those bits have no impact.
35 */
Christoffer Dallec6449a2017-11-20 12:10:15 +010036 if (!has_vhe()) {
37 u64 val;
38
39 /* Allow physical timer/counter access for the host */
40 val = read_sysreg(cnthctl_el2);
41 val |= CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN;
42 write_sysreg(val, cnthctl_el2);
43 }
Marc Zyngier1431af32015-10-19 16:32:20 +010044}
45
Christoffer Dall688c50a2017-01-04 16:10:28 +010046void __hyp_text __timer_enable_traps(struct kvm_vcpu *vcpu)
Marc Zyngier1431af32015-10-19 16:32:20 +010047{
Christoffer Dallec6449a2017-11-20 12:10:15 +010048 if (!has_vhe()) {
49 u64 val;
50
51 /*
52 * Disallow physical timer access for the guest
53 * Physical counter access is allowed
54 */
55 val = read_sysreg(cnthctl_el2);
56 val &= ~CNTHCTL_EL1PCEN;
57 val |= CNTHCTL_EL1PCTEN;
58 write_sysreg(val, cnthctl_el2);
59 }
Marc Zyngier1431af32015-10-19 16:32:20 +010060}