1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __ARM_KVM_HOST_H__
20#define __ARM_KVM_HOST_H__
21
22#include <linux/types.h>
23#include <linux/kvm_types.h>
24#include <asm/kvm.h>
25#include <asm/kvm_asm.h>
26#include <asm/kvm_mmio.h>
27#include <asm/fpstate.h>
28#include <kvm/arm_arch_timer.h>
29
30#define __KVM_HAVE_ARCH_INTC_INITIALIZED
31
32#define KVM_USER_MEM_SLOTS 32
33#define KVM_PRIVATE_MEM_SLOTS 4
34#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
35#define KVM_HAVE_ONE_REG
36#define KVM_HALT_POLL_NS_DEFAULT 500000
37
38#define KVM_VCPU_MAX_FEATURES 2
39
40#include <kvm/arm_vgic.h>
41
42
43#ifdef CONFIG_ARM_GIC_V3
44#define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS
45#else
46#define KVM_MAX_VCPUS VGIC_V2_MAX_CPUS
47#endif
48
49#define KVM_REQ_VCPU_EXIT 8
50
51u32 *kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode);
52int __attribute_const__ kvm_target_cpu(void);
53int kvm_reset_vcpu(struct kvm_vcpu *vcpu);
54void kvm_reset_coprocs(struct kvm_vcpu *vcpu);
55
56struct kvm_arch {
57
58 u64 vttbr;
59
60
61 int __percpu *last_vcpu_ran;
62
63
64 struct arch_timer_kvm timer;
65
66
67
68
69
70
71
72 u64 vmid_gen;
73 u32 vmid;
74
75
76 pgd_t *pgd;
77
78
79 struct vgic_dist vgic;
80 int max_vcpus;
81};
82
83#define KVM_NR_MEM_OBJS 40
84
85
86
87
88
89struct kvm_mmu_memory_cache {
90 int nobjs;
91 void *objects[KVM_NR_MEM_OBJS];
92};
93
94struct kvm_vcpu_fault_info {
95 u32 hsr;
96 u32 hxfar;
97 u32 hpfar;
98};
99
100
101
102
103
104enum vcpu_sysreg {
105 __INVALID_SYSREG__,
106 c0_MPIDR,
107 c0_CSSELR,
108 c1_SCTLR,
109 c1_ACTLR,
110 c1_CPACR,
111 c2_TTBR0,
112 c2_TTBR0_high,
113 c2_TTBR1,
114 c2_TTBR1_high,
115 c2_TTBCR,
116 c3_DACR,
117 c5_DFSR,
118 c5_IFSR,
119 c5_ADFSR,
120 c5_AIFSR,
121 c6_DFAR,
122 c6_IFAR,
123 c7_PAR,
124 c7_PAR_high,
125 c9_L2CTLR,
126 c10_PRRR,
127 c10_NMRR,
128 c12_VBAR,
129 c13_CID,
130 c13_TID_URW,
131 c13_TID_URO,
132 c13_TID_PRIV,
133 c14_CNTKCTL,
134 c10_AMAIR0,
135 c10_AMAIR1,
136 NR_CP15_REGS
137};
138
139struct kvm_cpu_context {
140 struct kvm_regs gp_regs;
141 struct vfp_hard_struct vfp;
142 u32 cp15[NR_CP15_REGS];
143};
144
145typedef struct kvm_cpu_context kvm_cpu_context_t;
146
147struct kvm_vcpu_arch {
148 struct kvm_cpu_context ctxt;
149
150 int target;
151 DECLARE_BITMAP(features, KVM_VCPU_MAX_FEATURES);
152
153
154 u32 midr;
155
156
157 u32 hcr;
158
159
160 u32 irq_lines;
161
162
163 struct kvm_vcpu_fault_info fault;
164
165
166 kvm_cpu_context_t *host_cpu_context;
167
168
169 struct vgic_cpu vgic_cpu;
170 struct arch_timer_cpu timer_cpu;
171
172
173
174
175
176
177
178 bool power_off;
179
180
181 bool pause;
182
183
184 struct kvm_decode mmio_decode;
185
186
187 struct kvm_mmu_memory_cache mmu_page_cache;
188
189
190 bool has_run_once;
191};
192
193struct kvm_vm_stat {
194 ulong remote_tlb_flush;
195};
196
197struct kvm_vcpu_stat {
198 u64 halt_successful_poll;
199 u64 halt_attempted_poll;
200 u64 halt_poll_invalid;
201 u64 halt_wakeup;
202 u64 hvc_exit_stat;
203 u64 wfe_exit_stat;
204 u64 wfi_exit_stat;
205 u64 mmio_exit_user;
206 u64 mmio_exit_kernel;
207 u64 exits;
208};
209
210#define vcpu_cp15(v,r) (v)->arch.ctxt.cp15[r]
211
212int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
213unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
214int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
215int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
216int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
217unsigned long kvm_call_hyp(void *hypfn, ...);
218void force_vm_exit(const cpumask_t *mask);
219
220#define KVM_ARCH_WANT_MMU_NOTIFIER
221int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
222int kvm_unmap_hva_range(struct kvm *kvm,
223 unsigned long start, unsigned long end);
224void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
225
226unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
227int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
228int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
229int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
230
231
232static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
233 unsigned long address)
234{
235}
236
237struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
238struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
239void kvm_arm_halt_guest(struct kvm *kvm);
240void kvm_arm_resume_guest(struct kvm *kvm);
241void kvm_arm_halt_vcpu(struct kvm_vcpu *vcpu);
242void kvm_arm_resume_vcpu(struct kvm_vcpu *vcpu);
243
244int kvm_arm_copy_coproc_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
245unsigned long kvm_arm_num_coproc_regs(struct kvm_vcpu *vcpu);
246int kvm_arm_coproc_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
247int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
248
249int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
250 int exception_index);
251
252static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr,
253 unsigned long hyp_stack_ptr,
254 unsigned long vector_ptr)
255{
256
257
258
259
260
261
262
263
264
265
266
267
268
269 kvm_call_hyp((void*)hyp_stack_ptr, vector_ptr, pgd_ptr);
270}
271
272static inline void __cpu_init_stage2(void)
273{
274 kvm_call_hyp(__init_stage2_translation);
275}
276
277static inline void __cpu_reset_hyp_mode(unsigned long vector_ptr,
278 phys_addr_t phys_idmap_start)
279{
280 kvm_call_hyp((void *)virt_to_idmap(__kvm_hyp_reset), vector_ptr);
281}
282
283static inline int kvm_arch_dev_ioctl_check_extension(struct kvm *kvm, long ext)
284{
285 return 0;
286}
287
288int kvm_perf_init(void);
289int kvm_perf_teardown(void);
290
291void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
292
293struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
294
295static inline void kvm_arch_hardware_unsetup(void) {}
296static inline void kvm_arch_sync_events(struct kvm *kvm) {}
297static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {}
298static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
299static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {}
300
301static inline void kvm_arm_init_debug(void) {}
302static inline void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) {}
303static inline void kvm_arm_clear_debug(struct kvm_vcpu *vcpu) {}
304static inline void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu) {}
305static inline int kvm_arm_vcpu_arch_set_attr(struct kvm_vcpu *vcpu,
306 struct kvm_device_attr *attr)
307{
308 return -ENXIO;
309}
310static inline int kvm_arm_vcpu_arch_get_attr(struct kvm_vcpu *vcpu,
311 struct kvm_device_attr *attr)
312{
313 return -ENXIO;
314}
315static inline int kvm_arm_vcpu_arch_has_attr(struct kvm_vcpu *vcpu,
316 struct kvm_device_attr *attr)
317{
318 return -ENXIO;
319}
320
321#endif
322