]> git.proxmox.com Git - mirror_qemu.git/blob - target/arm/kvm_arm.h
target/arm/kvm: Unexport kvm_{get,put}_vcpu_events
[mirror_qemu.git] / target / arm / kvm_arm.h
1 /*
2 * QEMU KVM support -- ARM specific functions.
3 *
4 * Copyright (c) 2012 Linaro Limited
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 *
9 */
10
11 #ifndef QEMU_KVM_ARM_H
12 #define QEMU_KVM_ARM_H
13
14 #include "sysemu/kvm.h"
15 #include "exec/memory.h"
16 #include "qemu/error-report.h"
17
18 #define KVM_ARM_VGIC_V2 (1 << 0)
19 #define KVM_ARM_VGIC_V3 (1 << 1)
20
21 /**
22 * kvm_arm_register_device:
23 * @mr: memory region for this device
24 * @devid: the KVM device ID
25 * @group: device control API group for setting addresses
26 * @attr: device control API address type
27 * @dev_fd: device control device file descriptor (or -1 if not supported)
28 * @addr_ormask: value to be OR'ed with resolved address
29 *
30 * Remember the memory region @mr, and when it is mapped by the
31 * machine model, tell the kernel that base address using the
32 * KVM_ARM_SET_DEVICE_ADDRESS ioctl or the newer device control API. @devid
33 * should be the ID of the device as defined by KVM_ARM_SET_DEVICE_ADDRESS or
34 * the arm-vgic device in the device control API.
35 * The machine model may map
36 * and unmap the device multiple times; the kernel will only be told the final
37 * address at the point where machine init is complete.
38 */
39 void kvm_arm_register_device(MemoryRegion *mr, uint64_t devid, uint64_t group,
40 uint64_t attr, int dev_fd, uint64_t addr_ormask);
41
42 /**
43 * write_list_to_kvmstate:
44 * @cpu: ARMCPU
45 * @level: the state level to sync
46 *
47 * For each register listed in the ARMCPU cpreg_indexes list, write
48 * its value from the cpreg_values list into the kernel (via ioctl).
49 * This updates KVM's working data structures from TCG data or
50 * from incoming migration state.
51 *
52 * Returns: true if all register values were updated correctly,
53 * false if some register was unknown to the kernel or could not
54 * be written (eg constant register with the wrong value).
55 * Note that we do not stop early on failure -- we will attempt
56 * writing all registers in the list.
57 */
58 bool write_list_to_kvmstate(ARMCPU *cpu, int level);
59
60 /**
61 * write_kvmstate_to_list:
62 * @cpu: ARMCPU
63 *
64 * For each register listed in the ARMCPU cpreg_indexes list, write
65 * its value from the kernel into the cpreg_values list. This is used to
66 * copy info from KVM's working data structures into TCG or
67 * for outbound migration.
68 *
69 * Returns: true if all register values were read correctly,
70 * false if some register was unknown or could not be read.
71 * Note that we do not stop early on failure -- we will attempt
72 * reading all registers in the list.
73 */
74 bool write_kvmstate_to_list(ARMCPU *cpu);
75
76 /**
77 * kvm_arm_cpu_pre_save:
78 * @cpu: ARMCPU
79 *
80 * Called after write_kvmstate_to_list() from cpu_pre_save() to update
81 * the cpreg list with KVM CPU state.
82 */
83 void kvm_arm_cpu_pre_save(ARMCPU *cpu);
84
85 /**
86 * kvm_arm_cpu_post_load:
87 * @cpu: ARMCPU
88 *
89 * Called from cpu_post_load() to update KVM CPU state from the cpreg list.
90 */
91 void kvm_arm_cpu_post_load(ARMCPU *cpu);
92
93 /**
94 * kvm_arm_reset_vcpu:
95 * @cpu: ARMCPU
96 *
97 * Called at reset time to kernel registers to their initial values.
98 */
99 void kvm_arm_reset_vcpu(ARMCPU *cpu);
100
101 #ifdef CONFIG_KVM
102 /**
103 * kvm_arm_create_scratch_host_vcpu:
104 * @cpus_to_try: array of QEMU_KVM_ARM_TARGET_* values (terminated with
105 * QEMU_KVM_ARM_TARGET_NONE) to try as fallback if the kernel does not
106 * know the PREFERRED_TARGET ioctl. Passing NULL is the same as passing
107 * an empty array.
108 * @fdarray: filled in with kvmfd, vmfd, cpufd file descriptors in that order
109 * @init: filled in with the necessary values for creating a host
110 * vcpu. If NULL is provided, will not init the vCPU (though the cpufd
111 * will still be set up).
112 *
113 * Create a scratch vcpu in its own VM of the type preferred by the host
114 * kernel (as would be used for '-cpu host'), for purposes of probing it
115 * for capabilities.
116 *
117 * Returns: true on success (and fdarray and init are filled in),
118 * false on failure (and fdarray and init are not valid).
119 */
120 bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
121 int *fdarray,
122 struct kvm_vcpu_init *init);
123
124 /**
125 * kvm_arm_destroy_scratch_host_vcpu:
126 * @fdarray: array of fds as set up by kvm_arm_create_scratch_host_vcpu
127 *
128 * Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu.
129 */
130 void kvm_arm_destroy_scratch_host_vcpu(int *fdarray);
131
132 /**
133 * kvm_arm_sve_get_vls:
134 * @cs: CPUState
135 *
136 * Get all the SVE vector lengths supported by the KVM host, setting
137 * the bits corresponding to their length in quadwords minus one
138 * (vq - 1) up to ARM_MAX_VQ. Return the resulting map.
139 */
140 uint32_t kvm_arm_sve_get_vls(CPUState *cs);
141
142 /**
143 * kvm_arm_set_cpu_features_from_host:
144 * @cpu: ARMCPU to set the features for
145 *
146 * Set up the ARMCPU struct fields up to match the information probed
147 * from the host CPU.
148 */
149 void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu);
150
151 /**
152 * kvm_arm_add_vcpu_properties:
153 * @obj: The CPU object to add the properties to
154 *
155 * Add all KVM specific CPU properties to the CPU object. These
156 * are the CPU properties with "kvm-" prefixed names.
157 */
158 void kvm_arm_add_vcpu_properties(Object *obj);
159
160 /**
161 * kvm_arm_steal_time_finalize:
162 * @cpu: ARMCPU for which to finalize kvm-steal-time
163 * @errp: Pointer to Error* for error propagation
164 *
165 * Validate the kvm-steal-time property selection and set its default
166 * based on KVM support and guest configuration.
167 */
168 void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp);
169
170 /**
171 * kvm_arm_aarch32_supported:
172 *
173 * Returns: true if KVM can enable AArch32 mode
174 * and false otherwise.
175 */
176 bool kvm_arm_aarch32_supported(void);
177
178 /**
179 * kvm_arm_pmu_supported:
180 *
181 * Returns: true if KVM can enable the PMU
182 * and false otherwise.
183 */
184 bool kvm_arm_pmu_supported(void);
185
186 /**
187 * kvm_arm_sve_supported:
188 *
189 * Returns true if KVM can enable SVE and false otherwise.
190 */
191 bool kvm_arm_sve_supported(void);
192
193 /**
194 * kvm_arm_get_max_vm_ipa_size:
195 * @ms: Machine state handle
196 * @fixed_ipa: True when the IPA limit is fixed at 40. This is the case
197 * for legacy KVM.
198 *
199 * Returns the number of bits in the IPA address space supported by KVM
200 */
201 int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa);
202
203 /**
204 * kvm_arm_sync_mpstate_to_kvm:
205 * @cpu: ARMCPU
206 *
207 * If supported set the KVM MP_STATE based on QEMU's model.
208 *
209 * Returns 0 on success and -1 on failure.
210 */
211 int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu);
212
213 /**
214 * kvm_arm_sync_mpstate_to_qemu:
215 * @cpu: ARMCPU
216 *
217 * If supported get the MP_STATE from KVM and store in QEMU's model.
218 *
219 * Returns 0 on success and aborts on failure.
220 */
221 int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu);
222
223 void kvm_arm_vm_state_change(void *opaque, bool running, RunState state);
224
225 int kvm_arm_vgic_probe(void);
226
227 void kvm_arm_pmu_set_irq(CPUState *cs, int irq);
228 void kvm_arm_pmu_init(CPUState *cs);
229
230 /**
231 * kvm_arm_pvtime_init:
232 * @cs: CPUState
233 * @ipa: Per-vcpu guest physical base address of the pvtime structures
234 *
235 * Initializes PVTIME for the VCPU, setting the PVTIME IPA to @ipa.
236 */
237 void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa);
238
239 int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level);
240
241 #else
242
243 /*
244 * It's safe to call these functions without KVM support.
245 * They should either do nothing or return "not supported".
246 */
247 static inline bool kvm_arm_aarch32_supported(void)
248 {
249 return false;
250 }
251
252 static inline bool kvm_arm_pmu_supported(void)
253 {
254 return false;
255 }
256
257 static inline bool kvm_arm_sve_supported(void)
258 {
259 return false;
260 }
261
262 /*
263 * These functions should never actually be called without KVM support.
264 */
265 static inline void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu)
266 {
267 g_assert_not_reached();
268 }
269
270 static inline void kvm_arm_add_vcpu_properties(Object *obj)
271 {
272 g_assert_not_reached();
273 }
274
275 static inline int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa)
276 {
277 g_assert_not_reached();
278 }
279
280 static inline int kvm_arm_vgic_probe(void)
281 {
282 g_assert_not_reached();
283 }
284
285 static inline void kvm_arm_pmu_set_irq(CPUState *cs, int irq)
286 {
287 g_assert_not_reached();
288 }
289
290 static inline void kvm_arm_pmu_init(CPUState *cs)
291 {
292 g_assert_not_reached();
293 }
294
295 static inline void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa)
296 {
297 g_assert_not_reached();
298 }
299
300 static inline void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp)
301 {
302 g_assert_not_reached();
303 }
304
305 static inline uint32_t kvm_arm_sve_get_vls(CPUState *cs)
306 {
307 g_assert_not_reached();
308 }
309
310 #endif
311
312 #endif