diff options
author | Marc Zyngier <marc.zyngier@arm.com> | 2016-01-28 08:44:07 -0500 |
---|---|---|
committer | Marc Zyngier <marc.zyngier@arm.com> | 2016-02-29 13:34:18 -0500 |
commit | 13720a56edbd8164fbfa251067dea9776e09f54b (patch) | |
tree | f2c2c34b3c6fb97b72b0702edfa6ff54346eec4a /arch/arm64/kvm | |
parent | 1f364c8c48a0767885a18451ee074c64b454157a (diff) |
arm64: KVM: Move kvm/hyp/hyp.h to include/asm/kvm_hyp.h
In order to be able to move code outside of kvm/hyp, we need to make
the global hyp.h file accessible from a standard location.
include/asm/kvm_hyp.h seems good enough.
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'arch/arm64/kvm')
-rw-r--r-- | arch/arm64/kvm/hyp/debug-sr.c | 4 | ||||
-rw-r--r-- | arch/arm64/kvm/hyp/hyp.h | 180 | ||||
-rw-r--r-- | arch/arm64/kvm/hyp/s2-setup.c | 3 | ||||
-rw-r--r-- | arch/arm64/kvm/hyp/switch.c | 3 | ||||
-rw-r--r-- | arch/arm64/kvm/hyp/sysreg-sr.c | 4 | ||||
-rw-r--r-- | arch/arm64/kvm/hyp/timer-sr.c | 4 | ||||
-rw-r--r-- | arch/arm64/kvm/hyp/tlb.c | 2 | ||||
-rw-r--r-- | arch/arm64/kvm/hyp/vgic-v2-sr.c | 4 | ||||
-rw-r--r-- | arch/arm64/kvm/hyp/vgic-v3-sr.c | 4 |
9 files changed, 8 insertions, 200 deletions
diff --git a/arch/arm64/kvm/hyp/debug-sr.c b/arch/arm64/kvm/hyp/debug-sr.c index c9c1e97501a9..053cf8b057c1 100644 --- a/arch/arm64/kvm/hyp/debug-sr.c +++ b/arch/arm64/kvm/hyp/debug-sr.c | |||
@@ -19,9 +19,7 @@ | |||
19 | #include <linux/kvm_host.h> | 19 | #include <linux/kvm_host.h> |
20 | 20 | ||
21 | #include <asm/kvm_asm.h> | 21 | #include <asm/kvm_asm.h> |
22 | #include <asm/kvm_mmu.h> | 22 | #include <asm/kvm_hyp.h> |
23 | |||
24 | #include "hyp.h" | ||
25 | 23 | ||
26 | #define read_debug(r,n) read_sysreg(r##n##_el1) | 24 | #define read_debug(r,n) read_sysreg(r##n##_el1) |
27 | #define write_debug(v,r,n) write_sysreg(v, r##n##_el1) | 25 | #define write_debug(v,r,n) write_sysreg(v, r##n##_el1) |
diff --git a/arch/arm64/kvm/hyp/hyp.h b/arch/arm64/kvm/hyp/hyp.h deleted file mode 100644 index 44eaff70da6a..000000000000 --- a/arch/arm64/kvm/hyp/hyp.h +++ /dev/null | |||
@@ -1,180 +0,0 @@ | |||
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 __ARM64_KVM_HYP_H__ | ||
19 | #define __ARM64_KVM_HYP_H__ | ||
20 | |||
21 | #include <linux/compiler.h> | ||
22 | #include <linux/kvm_host.h> | ||
23 | #include <asm/kvm_mmu.h> | ||
24 | #include <asm/sysreg.h> | ||
25 | |||
26 | #define __hyp_text __section(.hyp.text) notrace | ||
27 | |||
28 | static inline unsigned long __kern_hyp_va(unsigned long v) | ||
29 | { | ||
30 | asm volatile(ALTERNATIVE("and %0, %0, %1", | ||
31 | "nop", | ||
32 | ARM64_HAS_VIRT_HOST_EXTN) | ||
33 | : "+r" (v) : "i" (HYP_PAGE_OFFSET_MASK)); | ||
34 | return v; | ||
35 | } | ||
36 | |||
37 | #define kern_hyp_va(v) (typeof(v))(__kern_hyp_va((unsigned long)(v))) | ||
38 | |||
39 | static inline unsigned long __hyp_kern_va(unsigned long v) | ||
40 | { | ||
41 | u64 offset = PAGE_OFFSET - HYP_PAGE_OFFSET; | ||
42 | asm volatile(ALTERNATIVE("add %0, %0, %1", | ||
43 | "nop", | ||
44 | ARM64_HAS_VIRT_HOST_EXTN) | ||
45 | : "+r" (v) : "r" (offset)); | ||
46 | return v; | ||
47 | } | ||
48 | |||
49 | #define hyp_kern_va(v) (typeof(v))(__hyp_kern_va((unsigned long)(v))) | ||
50 | |||
51 | #define read_sysreg_elx(r,nvh,vh) \ | ||
52 | ({ \ | ||
53 | u64 reg; \ | ||
54 | asm volatile(ALTERNATIVE("mrs %0, " __stringify(r##nvh),\ | ||
55 | "mrs_s %0, " __stringify(r##vh),\ | ||
56 | ARM64_HAS_VIRT_HOST_EXTN) \ | ||
57 | : "=r" (reg)); \ | ||
58 | reg; \ | ||
59 | }) | ||
60 | |||
61 | #define write_sysreg_elx(v,r,nvh,vh) \ | ||
62 | do { \ | ||
63 | u64 __val = (u64)(v); \ | ||
64 | asm volatile(ALTERNATIVE("msr " __stringify(r##nvh) ", %x0",\ | ||
65 | "msr_s " __stringify(r##vh) ", %x0",\ | ||
66 | ARM64_HAS_VIRT_HOST_EXTN) \ | ||
67 | : : "rZ" (__val)); \ | ||
68 | } while (0) | ||
69 | |||
70 | /* | ||
71 | * Unified accessors for registers that have a different encoding | ||
72 | * between VHE and non-VHE. They must be specified without their "ELx" | ||
73 | * encoding. | ||
74 | */ | ||
75 | #define read_sysreg_el2(r) \ | ||
76 | ({ \ | ||
77 | u64 reg; \ | ||
78 | asm volatile(ALTERNATIVE("mrs %0, " __stringify(r##_EL2),\ | ||
79 | "mrs %0, " __stringify(r##_EL1),\ | ||
80 | ARM64_HAS_VIRT_HOST_EXTN) \ | ||
81 | : "=r" (reg)); \ | ||
82 | reg; \ | ||
83 | }) | ||
84 | |||
85 | #define write_sysreg_el2(v,r) \ | ||
86 | do { \ | ||
87 | u64 __val = (u64)(v); \ | ||
88 | asm volatile(ALTERNATIVE("msr " __stringify(r##_EL2) ", %x0",\ | ||
89 | "msr " __stringify(r##_EL1) ", %x0",\ | ||
90 | ARM64_HAS_VIRT_HOST_EXTN) \ | ||
91 | : : "rZ" (__val)); \ | ||
92 | } while (0) | ||
93 | |||
94 | #define read_sysreg_el0(r) read_sysreg_elx(r, _EL0, _EL02) | ||
95 | #define write_sysreg_el0(v,r) write_sysreg_elx(v, r, _EL0, _EL02) | ||
96 | #define read_sysreg_el1(r) read_sysreg_elx(r, _EL1, _EL12) | ||
97 | #define write_sysreg_el1(v,r) write_sysreg_elx(v, r, _EL1, _EL12) | ||
98 | |||
99 | /* The VHE specific system registers and their encoding */ | ||
100 | #define sctlr_EL12 sys_reg(3, 5, 1, 0, 0) | ||
101 | #define cpacr_EL12 sys_reg(3, 5, 1, 0, 2) | ||
102 | #define ttbr0_EL12 sys_reg(3, 5, 2, 0, 0) | ||
103 | #define ttbr1_EL12 sys_reg(3, 5, 2, 0, 1) | ||
104 | #define tcr_EL12 sys_reg(3, 5, 2, 0, 2) | ||
105 | #define afsr0_EL12 sys_reg(3, 5, 5, 1, 0) | ||
106 | #define afsr1_EL12 sys_reg(3, 5, 5, 1, 1) | ||
107 | #define esr_EL12 sys_reg(3, 5, 5, 2, 0) | ||
108 | #define far_EL12 sys_reg(3, 5, 6, 0, 0) | ||
109 | #define mair_EL12 sys_reg(3, 5, 10, 2, 0) | ||
110 | #define amair_EL12 sys_reg(3, 5, 10, 3, 0) | ||
111 | #define vbar_EL12 sys_reg(3, 5, 12, 0, 0) | ||
112 | #define contextidr_EL12 sys_reg(3, 5, 13, 0, 1) | ||
113 | #define cntkctl_EL12 sys_reg(3, 5, 14, 1, 0) | ||
114 | #define cntp_tval_EL02 sys_reg(3, 5, 14, 2, 0) | ||
115 | #define cntp_ctl_EL02 sys_reg(3, 5, 14, 2, 1) | ||
116 | #define cntp_cval_EL02 sys_reg(3, 5, 14, 2, 2) | ||
117 | #define cntv_tval_EL02 sys_reg(3, 5, 14, 3, 0) | ||
118 | #define cntv_ctl_EL02 sys_reg(3, 5, 14, 3, 1) | ||
119 | #define cntv_cval_EL02 sys_reg(3, 5, 14, 3, 2) | ||
120 | #define spsr_EL12 sys_reg(3, 5, 4, 0, 0) | ||
121 | #define elr_EL12 sys_reg(3, 5, 4, 0, 1) | ||
122 | |||
123 | /** | ||
124 | * hyp_alternate_select - Generates patchable code sequences that are | ||
125 | * used to switch between two implementations of a function, depending | ||
126 | * on the availability of a feature. | ||
127 | * | ||
128 | * @fname: a symbol name that will be defined as a function returning a | ||
129 | * function pointer whose type will match @orig and @alt | ||
130 | * @orig: A pointer to the default function, as returned by @fname when | ||
131 | * @cond doesn't hold | ||
132 | * @alt: A pointer to the alternate function, as returned by @fname | ||
133 | * when @cond holds | ||
134 | * @cond: a CPU feature (as described in asm/cpufeature.h) | ||
135 | */ | ||
136 | #define hyp_alternate_select(fname, orig, alt, cond) \ | ||
137 | typeof(orig) * __hyp_text fname(void) \ | ||
138 | { \ | ||
139 | typeof(alt) *val = orig; \ | ||
140 | asm volatile(ALTERNATIVE("nop \n", \ | ||
141 | "mov %0, %1 \n", \ | ||
142 | cond) \ | ||
143 | : "+r" (val) : "r" (alt)); \ | ||
144 | return val; \ | ||
145 | } | ||
146 | |||
147 | void __vgic_v2_save_state(struct kvm_vcpu *vcpu); | ||
148 | void __vgic_v2_restore_state(struct kvm_vcpu *vcpu); | ||
149 | |||
150 | void __vgic_v3_save_state(struct kvm_vcpu *vcpu); | ||
151 | void __vgic_v3_restore_state(struct kvm_vcpu *vcpu); | ||
152 | |||
153 | void __timer_save_state(struct kvm_vcpu *vcpu); | ||
154 | void __timer_restore_state(struct kvm_vcpu *vcpu); | ||
155 | |||
156 | void __sysreg_save_host_state(struct kvm_cpu_context *ctxt); | ||
157 | void __sysreg_restore_host_state(struct kvm_cpu_context *ctxt); | ||
158 | void __sysreg_save_guest_state(struct kvm_cpu_context *ctxt); | ||
159 | void __sysreg_restore_guest_state(struct kvm_cpu_context *ctxt); | ||
160 | void __sysreg32_save_state(struct kvm_vcpu *vcpu); | ||
161 | void __sysreg32_restore_state(struct kvm_vcpu *vcpu); | ||
162 | |||
163 | void __debug_save_state(struct kvm_vcpu *vcpu, | ||
164 | struct kvm_guest_debug_arch *dbg, | ||
165 | struct kvm_cpu_context *ctxt); | ||
166 | void __debug_restore_state(struct kvm_vcpu *vcpu, | ||
167 | struct kvm_guest_debug_arch *dbg, | ||
168 | struct kvm_cpu_context *ctxt); | ||
169 | void __debug_cond_save_host_state(struct kvm_vcpu *vcpu); | ||
170 | void __debug_cond_restore_host_state(struct kvm_vcpu *vcpu); | ||
171 | |||
172 | void __fpsimd_save_state(struct user_fpsimd_state *fp_regs); | ||
173 | void __fpsimd_restore_state(struct user_fpsimd_state *fp_regs); | ||
174 | bool __fpsimd_enabled(void); | ||
175 | |||
176 | u64 __guest_enter(struct kvm_vcpu *vcpu, struct kvm_cpu_context *host_ctxt); | ||
177 | void __noreturn __hyp_do_panic(unsigned long, ...); | ||
178 | |||
179 | #endif /* __ARM64_KVM_HYP_H__ */ | ||
180 | |||
diff --git a/arch/arm64/kvm/hyp/s2-setup.c b/arch/arm64/kvm/hyp/s2-setup.c index 17e8cc09a1d8..bfc54fd82797 100644 --- a/arch/arm64/kvm/hyp/s2-setup.c +++ b/arch/arm64/kvm/hyp/s2-setup.c | |||
@@ -18,8 +18,7 @@ | |||
18 | #include <linux/types.h> | 18 | #include <linux/types.h> |
19 | #include <asm/kvm_arm.h> | 19 | #include <asm/kvm_arm.h> |
20 | #include <asm/kvm_asm.h> | 20 | #include <asm/kvm_asm.h> |
21 | 21 | #include <asm/kvm_hyp.h> | |
22 | #include "hyp.h" | ||
23 | 22 | ||
24 | void __hyp_text __init_stage2_translation(void) | 23 | void __hyp_text __init_stage2_translation(void) |
25 | { | 24 | { |
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index ecf5b05d1e16..7b81e56111ab 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c | |||
@@ -17,8 +17,7 @@ | |||
17 | 17 | ||
18 | #include <linux/types.h> | 18 | #include <linux/types.h> |
19 | #include <asm/kvm_asm.h> | 19 | #include <asm/kvm_asm.h> |
20 | 20 | #include <asm/kvm_hyp.h> | |
21 | #include "hyp.h" | ||
22 | 21 | ||
23 | static bool __hyp_text __fpsimd_enabled_nvhe(void) | 22 | static bool __hyp_text __fpsimd_enabled_nvhe(void) |
24 | { | 23 | { |
diff --git a/arch/arm64/kvm/hyp/sysreg-sr.c b/arch/arm64/kvm/hyp/sysreg-sr.c index 74b5f81678c2..0f7c40eb3f53 100644 --- a/arch/arm64/kvm/hyp/sysreg-sr.c +++ b/arch/arm64/kvm/hyp/sysreg-sr.c | |||
@@ -19,9 +19,7 @@ | |||
19 | #include <linux/kvm_host.h> | 19 | #include <linux/kvm_host.h> |
20 | 20 | ||
21 | #include <asm/kvm_asm.h> | 21 | #include <asm/kvm_asm.h> |
22 | #include <asm/kvm_mmu.h> | 22 | #include <asm/kvm_hyp.h> |
23 | |||
24 | #include "hyp.h" | ||
25 | 23 | ||
26 | /* Yes, this does nothing, on purpose */ | 24 | /* Yes, this does nothing, on purpose */ |
27 | static void __hyp_text __sysreg_do_nothing(struct kvm_cpu_context *ctxt) { } | 25 | static void __hyp_text __sysreg_do_nothing(struct kvm_cpu_context *ctxt) { } |
diff --git a/arch/arm64/kvm/hyp/timer-sr.c b/arch/arm64/kvm/hyp/timer-sr.c index f276d9e74411..ea00d69e7078 100644 --- a/arch/arm64/kvm/hyp/timer-sr.c +++ b/arch/arm64/kvm/hyp/timer-sr.c | |||
@@ -19,9 +19,7 @@ | |||
19 | #include <linux/compiler.h> | 19 | #include <linux/compiler.h> |
20 | #include <linux/kvm_host.h> | 20 | #include <linux/kvm_host.h> |
21 | 21 | ||
22 | #include <asm/kvm_mmu.h> | 22 | #include <asm/kvm_hyp.h> |
23 | |||
24 | #include "hyp.h" | ||
25 | 23 | ||
26 | /* vcpu is already in the HYP VA space */ | 24 | /* vcpu is already in the HYP VA space */ |
27 | void __hyp_text __timer_save_state(struct kvm_vcpu *vcpu) | 25 | void __hyp_text __timer_save_state(struct kvm_vcpu *vcpu) |
diff --git a/arch/arm64/kvm/hyp/tlb.c b/arch/arm64/kvm/hyp/tlb.c index 2a7e0d838698..be8177cdd3bf 100644 --- a/arch/arm64/kvm/hyp/tlb.c +++ b/arch/arm64/kvm/hyp/tlb.c | |||
@@ -15,7 +15,7 @@ | |||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "hyp.h" | 18 | #include <asm/kvm_hyp.h> |
19 | 19 | ||
20 | static void __hyp_text __tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) | 20 | static void __hyp_text __tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) |
21 | { | 21 | { |
diff --git a/arch/arm64/kvm/hyp/vgic-v2-sr.c b/arch/arm64/kvm/hyp/vgic-v2-sr.c index e71761238cfc..9514a7d90d71 100644 --- a/arch/arm64/kvm/hyp/vgic-v2-sr.c +++ b/arch/arm64/kvm/hyp/vgic-v2-sr.c | |||
@@ -19,9 +19,7 @@ | |||
19 | #include <linux/irqchip/arm-gic.h> | 19 | #include <linux/irqchip/arm-gic.h> |
20 | #include <linux/kvm_host.h> | 20 | #include <linux/kvm_host.h> |
21 | 21 | ||
22 | #include <asm/kvm_mmu.h> | 22 | #include <asm/kvm_hyp.h> |
23 | |||
24 | #include "hyp.h" | ||
25 | 23 | ||
26 | /* vcpu is already in the HYP VA space */ | 24 | /* vcpu is already in the HYP VA space */ |
27 | void __hyp_text __vgic_v2_save_state(struct kvm_vcpu *vcpu) | 25 | void __hyp_text __vgic_v2_save_state(struct kvm_vcpu *vcpu) |
diff --git a/arch/arm64/kvm/hyp/vgic-v3-sr.c b/arch/arm64/kvm/hyp/vgic-v3-sr.c index 5dd2a26444ec..0035b2d3fb6d 100644 --- a/arch/arm64/kvm/hyp/vgic-v3-sr.c +++ b/arch/arm64/kvm/hyp/vgic-v3-sr.c | |||
@@ -19,9 +19,7 @@ | |||
19 | #include <linux/irqchip/arm-gic-v3.h> | 19 | #include <linux/irqchip/arm-gic-v3.h> |
20 | #include <linux/kvm_host.h> | 20 | #include <linux/kvm_host.h> |
21 | 21 | ||
22 | #include <asm/kvm_mmu.h> | 22 | #include <asm/kvm_hyp.h> |
23 | |||
24 | #include "hyp.h" | ||
25 | 23 | ||
26 | #define vtr_to_max_lr_idx(v) ((v) & 0xf) | 24 | #define vtr_to_max_lr_idx(v) ((v) & 0xf) |
27 | #define vtr_to_nr_pri_bits(v) (((u32)(v) >> 29) + 1) | 25 | #define vtr_to_nr_pri_bits(v) (((u32)(v) >> 29) + 1) |