Add TTBR operator for kasan_init
[linux] / arch / arm / include / asm / kvm_hyp.h
1 /*
2  * Copyright (C) 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 #ifndef __ARM_KVM_HYP_H__
19 #define __ARM_KVM_HYP_H__
20
21 #include <linux/compiler.h>
22 #include <linux/kvm_host.h>
23 #include <asm/cp15.h>
24 #include <asm/vfp.h>
25
26 #define __hyp_text __section(.hyp.text) notrace
27
28 #define __ACCESS_VFP(CRn)                       \
29         "mrc", "mcr", __stringify(p10, 7, %0, CRn, cr0, 0), u32
30
31 #define write_special(v, r)                                     \
32         asm volatile("msr " __stringify(r) ", %0" : : "r" (v))
33 #define read_special(r) ({                                      \
34         u32 __val;      CNTVOFF                                 \
35         asm volatile("mrs %0, " __stringify(r) : "=r" (__val)); \
36         __val;                                                  \
37 })
38
39 #define CNTP_CVAL       __ACCESS_CP15_64(2, c14)
40 #define CNTP_CTL        __ACCESS_CP15(c14, 0, c2, 1)
41
42 #define VFP_FPEXC       __ACCESS_VFP(FPEXC)
43
44 /* AArch64 compatibility macros, only for the timer so far */
45 #define read_sysreg_el0(r)              read_sysreg(r##_el0)
46 #define write_sysreg_el0(v, r)          write_sysreg(v, r##_el0)
47
48 #define cntp_ctl_el0                    CNTP_CTL
49 #define cntp_cval_el0                   CNTP_CVAL
50 #define cntv_ctl_el0                    CNTV_CTL
51 #define cntv_cval_el0                   CNTV_CVAL
52 #define cntvoff_el2                     CNTVOFF
53 #define cnthctl_el2                     CNTHCTL
54
55 void __timer_enable_traps(struct kvm_vcpu *vcpu);
56 void __timer_disable_traps(struct kvm_vcpu *vcpu);
57
58 void __vgic_v2_save_state(struct kvm_vcpu *vcpu);
59 void __vgic_v2_restore_state(struct kvm_vcpu *vcpu);
60
61 void __sysreg_save_state(struct kvm_cpu_context *ctxt);
62 void __sysreg_restore_state(struct kvm_cpu_context *ctxt);
63
64 void __vgic_v3_save_state(struct kvm_vcpu *vcpu);
65 void __vgic_v3_restore_state(struct kvm_vcpu *vcpu);
66 void __vgic_v3_activate_traps(struct kvm_vcpu *vcpu);
67 void __vgic_v3_deactivate_traps(struct kvm_vcpu *vcpu);
68 void __vgic_v3_save_aprs(struct kvm_vcpu *vcpu);
69 void __vgic_v3_restore_aprs(struct kvm_vcpu *vcpu);
70
71 asmlinkage void __vfp_save_state(struct vfp_hard_struct *vfp);
72 asmlinkage void __vfp_restore_state(struct vfp_hard_struct *vfp);
73 static inline bool __vfp_enabled(void)
74 {
75         return !(read_sysreg(HCPTR) & (HCPTR_TCP(11) | HCPTR_TCP(10)));
76 }
77
78 void __hyp_text __banked_save_state(struct kvm_cpu_context *ctxt);
79 void __hyp_text __banked_restore_state(struct kvm_cpu_context *ctxt);
80
81 asmlinkage int __guest_enter(struct kvm_vcpu *vcpu,
82                              struct kvm_cpu_context *host);
83 asmlinkage int __hyp_do_panic(const char *, int, u32);
84
85 #endif /* __ARM_KVM_HYP_H__ */