target/riscv: deprecate the 'any' CPU type
[qemu/ar7.git] / target / arm / kvm_arm.h
blob051a0da41c4929c178134f2b2a67622e84ef42b5
1 /*
2 * QEMU KVM support -- ARM specific functions.
4 * Copyright (c) 2012 Linaro Limited
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.
9 */
11 #ifndef QEMU_KVM_ARM_H
12 #define QEMU_KVM_ARM_H
14 #include "sysemu/kvm.h"
15 #include "exec/memory.h"
16 #include "qemu/error-report.h"
18 #define KVM_ARM_VGIC_V2 (1 << 0)
19 #define KVM_ARM_VGIC_V3 (1 << 1)
21 /**
22 * kvm_arm_init_debug() - initialize guest debug capabilities
23 * @s: KVMState
25 * Should be called only once before using guest debug capabilities.
27 void kvm_arm_init_debug(KVMState *s);
29 /**
30 * kvm_arm_vcpu_init:
31 * @cs: CPUState
33 * Initialize (or reinitialize) the VCPU by invoking the
34 * KVM_ARM_VCPU_INIT ioctl with the CPU type and feature
35 * bitmask specified in the CPUState.
37 * Returns: 0 if success else < 0 error code
39 int kvm_arm_vcpu_init(CPUState *cs);
41 /**
42 * kvm_arm_vcpu_finalize:
43 * @cs: CPUState
44 * @feature: feature to finalize
46 * Finalizes the configuration of the specified VCPU feature by
47 * invoking the KVM_ARM_VCPU_FINALIZE ioctl. Features requiring
48 * this are documented in the "KVM_ARM_VCPU_FINALIZE" section of
49 * KVM's API documentation.
51 * Returns: 0 if success else < 0 error code
53 int kvm_arm_vcpu_finalize(CPUState *cs, int feature);
55 /**
56 * kvm_arm_register_device:
57 * @mr: memory region for this device
58 * @devid: the KVM device ID
59 * @group: device control API group for setting addresses
60 * @attr: device control API address type
61 * @dev_fd: device control device file descriptor (or -1 if not supported)
62 * @addr_ormask: value to be OR'ed with resolved address
64 * Remember the memory region @mr, and when it is mapped by the
65 * machine model, tell the kernel that base address using the
66 * KVM_ARM_SET_DEVICE_ADDRESS ioctl or the newer device control API. @devid
67 * should be the ID of the device as defined by KVM_ARM_SET_DEVICE_ADDRESS or
68 * the arm-vgic device in the device control API.
69 * The machine model may map
70 * and unmap the device multiple times; the kernel will only be told the final
71 * address at the point where machine init is complete.
73 void kvm_arm_register_device(MemoryRegion *mr, uint64_t devid, uint64_t group,
74 uint64_t attr, int dev_fd, uint64_t addr_ormask);
76 /**
77 * kvm_arm_init_cpreg_list:
78 * @cpu: ARMCPU
80 * Initialize the ARMCPU cpreg list according to the kernel's
81 * definition of what CPU registers it knows about (and throw away
82 * the previous TCG-created cpreg list).
84 * Returns: 0 if success, else < 0 error code
86 int kvm_arm_init_cpreg_list(ARMCPU *cpu);
88 /**
89 * kvm_arm_reg_syncs_via_cpreg_list:
90 * @regidx: KVM register index
92 * Return true if this KVM register should be synchronized via the
93 * cpreg list of arbitrary system registers, false if it is synchronized
94 * by hand using code in kvm_arch_get/put_registers().
96 bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx);
98 /**
99 * kvm_arm_cpreg_level:
100 * @regidx: KVM register index
102 * Return the level of this coprocessor/system register. Return value is
103 * either KVM_PUT_RUNTIME_STATE, KVM_PUT_RESET_STATE, or KVM_PUT_FULL_STATE.
105 int kvm_arm_cpreg_level(uint64_t regidx);
108 * write_list_to_kvmstate:
109 * @cpu: ARMCPU
110 * @level: the state level to sync
112 * For each register listed in the ARMCPU cpreg_indexes list, write
113 * its value from the cpreg_values list into the kernel (via ioctl).
114 * This updates KVM's working data structures from TCG data or
115 * from incoming migration state.
117 * Returns: true if all register values were updated correctly,
118 * false if some register was unknown to the kernel or could not
119 * be written (eg constant register with the wrong value).
120 * Note that we do not stop early on failure -- we will attempt
121 * writing all registers in the list.
123 bool write_list_to_kvmstate(ARMCPU *cpu, int level);
126 * write_kvmstate_to_list:
127 * @cpu: ARMCPU
129 * For each register listed in the ARMCPU cpreg_indexes list, write
130 * its value from the kernel into the cpreg_values list. This is used to
131 * copy info from KVM's working data structures into TCG or
132 * for outbound migration.
134 * Returns: true if all register values were read correctly,
135 * false if some register was unknown or could not be read.
136 * Note that we do not stop early on failure -- we will attempt
137 * reading all registers in the list.
139 bool write_kvmstate_to_list(ARMCPU *cpu);
142 * kvm_arm_cpu_pre_save:
143 * @cpu: ARMCPU
145 * Called after write_kvmstate_to_list() from cpu_pre_save() to update
146 * the cpreg list with KVM CPU state.
148 void kvm_arm_cpu_pre_save(ARMCPU *cpu);
151 * kvm_arm_cpu_post_load:
152 * @cpu: ARMCPU
154 * Called from cpu_post_load() to update KVM CPU state from the cpreg list.
156 void kvm_arm_cpu_post_load(ARMCPU *cpu);
159 * kvm_arm_reset_vcpu:
160 * @cpu: ARMCPU
162 * Called at reset time to kernel registers to their initial values.
164 void kvm_arm_reset_vcpu(ARMCPU *cpu);
167 * kvm_arm_init_serror_injection:
168 * @cs: CPUState
170 * Check whether KVM can set guest SError syndrome.
172 void kvm_arm_init_serror_injection(CPUState *cs);
175 * kvm_get_vcpu_events:
176 * @cpu: ARMCPU
178 * Get VCPU related state from kvm.
180 * Returns: 0 if success else < 0 error code
182 int kvm_get_vcpu_events(ARMCPU *cpu);
185 * kvm_put_vcpu_events:
186 * @cpu: ARMCPU
188 * Put VCPU related state to kvm.
190 * Returns: 0 if success else < 0 error code
192 int kvm_put_vcpu_events(ARMCPU *cpu);
194 #ifdef CONFIG_KVM
196 * kvm_arm_create_scratch_host_vcpu:
197 * @cpus_to_try: array of QEMU_KVM_ARM_TARGET_* values (terminated with
198 * QEMU_KVM_ARM_TARGET_NONE) to try as fallback if the kernel does not
199 * know the PREFERRED_TARGET ioctl. Passing NULL is the same as passing
200 * an empty array.
201 * @fdarray: filled in with kvmfd, vmfd, cpufd file descriptors in that order
202 * @init: filled in with the necessary values for creating a host
203 * vcpu. If NULL is provided, will not init the vCPU (though the cpufd
204 * will still be set up).
206 * Create a scratch vcpu in its own VM of the type preferred by the host
207 * kernel (as would be used for '-cpu host'), for purposes of probing it
208 * for capabilities.
210 * Returns: true on success (and fdarray and init are filled in),
211 * false on failure (and fdarray and init are not valid).
213 bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
214 int *fdarray,
215 struct kvm_vcpu_init *init);
218 * kvm_arm_destroy_scratch_host_vcpu:
219 * @fdarray: array of fds as set up by kvm_arm_create_scratch_host_vcpu
221 * Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu.
223 void kvm_arm_destroy_scratch_host_vcpu(int *fdarray);
226 * ARMHostCPUFeatures: information about the host CPU (identified
227 * by asking the host kernel)
229 typedef struct ARMHostCPUFeatures {
230 ARMISARegisters isar;
231 uint64_t features;
232 uint32_t target;
233 const char *dtb_compatible;
234 } ARMHostCPUFeatures;
237 * kvm_arm_get_host_cpu_features:
238 * @ahcf: ARMHostCPUClass to fill in
240 * Probe the capabilities of the host kernel's preferred CPU and fill
241 * in the ARMHostCPUClass struct accordingly.
243 * Returns true on success and false otherwise.
245 bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf);
248 * kvm_arm_sve_get_vls:
249 * @cs: CPUState
251 * Get all the SVE vector lengths supported by the KVM host, setting
252 * the bits corresponding to their length in quadwords minus one
253 * (vq - 1) up to ARM_MAX_VQ. Return the resulting map.
255 uint32_t kvm_arm_sve_get_vls(CPUState *cs);
258 * kvm_arm_set_cpu_features_from_host:
259 * @cpu: ARMCPU to set the features for
261 * Set up the ARMCPU struct fields up to match the information probed
262 * from the host CPU.
264 void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu);
267 * kvm_arm_add_vcpu_properties:
268 * @obj: The CPU object to add the properties to
270 * Add all KVM specific CPU properties to the CPU object. These
271 * are the CPU properties with "kvm-" prefixed names.
273 void kvm_arm_add_vcpu_properties(Object *obj);
276 * kvm_arm_steal_time_finalize:
277 * @cpu: ARMCPU for which to finalize kvm-steal-time
278 * @errp: Pointer to Error* for error propagation
280 * Validate the kvm-steal-time property selection and set its default
281 * based on KVM support and guest configuration.
283 void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp);
286 * kvm_arm_steal_time_supported:
288 * Returns: true if KVM can enable steal time reporting
289 * and false otherwise.
291 bool kvm_arm_steal_time_supported(void);
294 * kvm_arm_aarch32_supported:
296 * Returns: true if KVM can enable AArch32 mode
297 * and false otherwise.
299 bool kvm_arm_aarch32_supported(void);
302 * kvm_arm_pmu_supported:
304 * Returns: true if KVM can enable the PMU
305 * and false otherwise.
307 bool kvm_arm_pmu_supported(void);
310 * kvm_arm_sve_supported:
312 * Returns true if KVM can enable SVE and false otherwise.
314 bool kvm_arm_sve_supported(void);
317 * kvm_arm_get_max_vm_ipa_size:
318 * @ms: Machine state handle
319 * @fixed_ipa: True when the IPA limit is fixed at 40. This is the case
320 * for legacy KVM.
322 * Returns the number of bits in the IPA address space supported by KVM
324 int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa);
327 * kvm_arm_sync_mpstate_to_kvm:
328 * @cpu: ARMCPU
330 * If supported set the KVM MP_STATE based on QEMU's model.
332 * Returns 0 on success and -1 on failure.
334 int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu);
337 * kvm_arm_sync_mpstate_to_qemu:
338 * @cpu: ARMCPU
340 * If supported get the MP_STATE from KVM and store in QEMU's model.
342 * Returns 0 on success and aborts on failure.
344 int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu);
347 * kvm_arm_get_virtual_time:
348 * @cs: CPUState
350 * Gets the VCPU's virtual counter and stores it in the KVM CPU state.
352 void kvm_arm_get_virtual_time(CPUState *cs);
355 * kvm_arm_put_virtual_time:
356 * @cs: CPUState
358 * Sets the VCPU's virtual counter to the value stored in the KVM CPU state.
360 void kvm_arm_put_virtual_time(CPUState *cs);
362 void kvm_arm_vm_state_change(void *opaque, bool running, RunState state);
364 int kvm_arm_vgic_probe(void);
366 void kvm_arm_pmu_set_irq(CPUState *cs, int irq);
367 void kvm_arm_pmu_init(CPUState *cs);
370 * kvm_arm_pvtime_init:
371 * @cs: CPUState
372 * @ipa: Per-vcpu guest physical base address of the pvtime structures
374 * Initializes PVTIME for the VCPU, setting the PVTIME IPA to @ipa.
376 void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa);
378 int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level);
380 #else
383 * It's safe to call these functions without KVM support.
384 * They should either do nothing or return "not supported".
386 static inline bool kvm_arm_aarch32_supported(void)
388 return false;
391 static inline bool kvm_arm_pmu_supported(void)
393 return false;
396 static inline bool kvm_arm_sve_supported(void)
398 return false;
401 static inline bool kvm_arm_steal_time_supported(void)
403 return false;
407 * These functions should never actually be called without KVM support.
409 static inline void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu)
411 g_assert_not_reached();
414 static inline void kvm_arm_add_vcpu_properties(Object *obj)
416 g_assert_not_reached();
419 static inline int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa)
421 g_assert_not_reached();
424 static inline int kvm_arm_vgic_probe(void)
426 g_assert_not_reached();
429 static inline void kvm_arm_pmu_set_irq(CPUState *cs, int irq)
431 g_assert_not_reached();
434 static inline void kvm_arm_pmu_init(CPUState *cs)
436 g_assert_not_reached();
439 static inline void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa)
441 g_assert_not_reached();
444 static inline void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp)
446 g_assert_not_reached();
449 static inline uint32_t kvm_arm_sve_get_vls(CPUState *cs)
451 g_assert_not_reached();
454 #endif
457 * kvm_arm_handle_debug:
458 * @cs: CPUState
459 * @debug_exit: debug part of the KVM exit structure
461 * Returns: TRUE if the debug exception was handled.
463 bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit);
466 * kvm_arm_hw_debug_active:
467 * @cs: CPU State
469 * Return: TRUE if any hardware breakpoints in use.
471 bool kvm_arm_hw_debug_active(CPUState *cs);
474 * kvm_arm_copy_hw_debug_data:
475 * @ptr: kvm_guest_debug_arch structure
477 * Copy the architecture specific debug registers into the
478 * kvm_guest_debug ioctl structure.
480 struct kvm_guest_debug_arch;
481 void kvm_arm_copy_hw_debug_data(struct kvm_guest_debug_arch *ptr);
484 * kvm_arm_verify_ext_dabt_pending:
485 * @cs: CPUState
487 * Verify the fault status code wrt the Ext DABT injection
489 * Returns: true if the fault status code is as expected, false otherwise
491 bool kvm_arm_verify_ext_dabt_pending(CPUState *cs);
493 #endif