]>
git.proxmox.com Git - mirror_qemu.git/blob - target/arm/kvm_arm.h
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.
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)
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
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.
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
);
43 * write_list_to_kvmstate:
45 * @level: the state level to sync
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.
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.
58 bool write_list_to_kvmstate(ARMCPU
*cpu
, int level
);
61 * write_kvmstate_to_list:
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.
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.
74 bool write_kvmstate_to_list(ARMCPU
*cpu
);
77 * kvm_arm_cpu_pre_save:
80 * Called after write_kvmstate_to_list() from cpu_pre_save() to update
81 * the cpreg list with KVM CPU state.
83 void kvm_arm_cpu_pre_save(ARMCPU
*cpu
);
86 * kvm_arm_cpu_post_load:
89 * Called from cpu_post_load() to update KVM CPU state from the cpreg list.
91 void kvm_arm_cpu_post_load(ARMCPU
*cpu
);
97 * Called at reset time to kernel registers to their initial values.
99 void kvm_arm_reset_vcpu(ARMCPU
*cpu
);
102 * kvm_arm_init_serror_injection:
105 * Check whether KVM can set guest SError syndrome.
107 void kvm_arm_init_serror_injection(CPUState
*cs
);
110 * kvm_get_vcpu_events:
113 * Get VCPU related state from kvm.
115 * Returns: 0 if success else < 0 error code
117 int kvm_get_vcpu_events(ARMCPU
*cpu
);
120 * kvm_put_vcpu_events:
123 * Put VCPU related state to kvm.
125 * Returns: 0 if success else < 0 error code
127 int kvm_put_vcpu_events(ARMCPU
*cpu
);
131 * kvm_arm_create_scratch_host_vcpu:
132 * @cpus_to_try: array of QEMU_KVM_ARM_TARGET_* values (terminated with
133 * QEMU_KVM_ARM_TARGET_NONE) to try as fallback if the kernel does not
134 * know the PREFERRED_TARGET ioctl. Passing NULL is the same as passing
136 * @fdarray: filled in with kvmfd, vmfd, cpufd file descriptors in that order
137 * @init: filled in with the necessary values for creating a host
138 * vcpu. If NULL is provided, will not init the vCPU (though the cpufd
139 * will still be set up).
141 * Create a scratch vcpu in its own VM of the type preferred by the host
142 * kernel (as would be used for '-cpu host'), for purposes of probing it
145 * Returns: true on success (and fdarray and init are filled in),
146 * false on failure (and fdarray and init are not valid).
148 bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try
,
150 struct kvm_vcpu_init
*init
);
153 * kvm_arm_destroy_scratch_host_vcpu:
154 * @fdarray: array of fds as set up by kvm_arm_create_scratch_host_vcpu
156 * Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu.
158 void kvm_arm_destroy_scratch_host_vcpu(int *fdarray
);
161 * kvm_arm_sve_get_vls:
164 * Get all the SVE vector lengths supported by the KVM host, setting
165 * the bits corresponding to their length in quadwords minus one
166 * (vq - 1) up to ARM_MAX_VQ. Return the resulting map.
168 uint32_t kvm_arm_sve_get_vls(CPUState
*cs
);
171 * kvm_arm_set_cpu_features_from_host:
172 * @cpu: ARMCPU to set the features for
174 * Set up the ARMCPU struct fields up to match the information probed
177 void kvm_arm_set_cpu_features_from_host(ARMCPU
*cpu
);
180 * kvm_arm_add_vcpu_properties:
181 * @obj: The CPU object to add the properties to
183 * Add all KVM specific CPU properties to the CPU object. These
184 * are the CPU properties with "kvm-" prefixed names.
186 void kvm_arm_add_vcpu_properties(Object
*obj
);
189 * kvm_arm_steal_time_finalize:
190 * @cpu: ARMCPU for which to finalize kvm-steal-time
191 * @errp: Pointer to Error* for error propagation
193 * Validate the kvm-steal-time property selection and set its default
194 * based on KVM support and guest configuration.
196 void kvm_arm_steal_time_finalize(ARMCPU
*cpu
, Error
**errp
);
199 * kvm_arm_aarch32_supported:
201 * Returns: true if KVM can enable AArch32 mode
202 * and false otherwise.
204 bool kvm_arm_aarch32_supported(void);
207 * kvm_arm_pmu_supported:
209 * Returns: true if KVM can enable the PMU
210 * and false otherwise.
212 bool kvm_arm_pmu_supported(void);
215 * kvm_arm_sve_supported:
217 * Returns true if KVM can enable SVE and false otherwise.
219 bool kvm_arm_sve_supported(void);
222 * kvm_arm_get_max_vm_ipa_size:
223 * @ms: Machine state handle
224 * @fixed_ipa: True when the IPA limit is fixed at 40. This is the case
227 * Returns the number of bits in the IPA address space supported by KVM
229 int kvm_arm_get_max_vm_ipa_size(MachineState
*ms
, bool *fixed_ipa
);
232 * kvm_arm_sync_mpstate_to_kvm:
235 * If supported set the KVM MP_STATE based on QEMU's model.
237 * Returns 0 on success and -1 on failure.
239 int kvm_arm_sync_mpstate_to_kvm(ARMCPU
*cpu
);
242 * kvm_arm_sync_mpstate_to_qemu:
245 * If supported get the MP_STATE from KVM and store in QEMU's model.
247 * Returns 0 on success and aborts on failure.
249 int kvm_arm_sync_mpstate_to_qemu(ARMCPU
*cpu
);
251 void kvm_arm_vm_state_change(void *opaque
, bool running
, RunState state
);
253 int kvm_arm_vgic_probe(void);
255 void kvm_arm_pmu_set_irq(CPUState
*cs
, int irq
);
256 void kvm_arm_pmu_init(CPUState
*cs
);
259 * kvm_arm_pvtime_init:
261 * @ipa: Per-vcpu guest physical base address of the pvtime structures
263 * Initializes PVTIME for the VCPU, setting the PVTIME IPA to @ipa.
265 void kvm_arm_pvtime_init(CPUState
*cs
, uint64_t ipa
);
267 int kvm_arm_set_irq(int cpu
, int irqtype
, int irq
, int level
);
272 * It's safe to call these functions without KVM support.
273 * They should either do nothing or return "not supported".
275 static inline bool kvm_arm_aarch32_supported(void)
280 static inline bool kvm_arm_pmu_supported(void)
285 static inline bool kvm_arm_sve_supported(void)
291 * These functions should never actually be called without KVM support.
293 static inline void kvm_arm_set_cpu_features_from_host(ARMCPU
*cpu
)
295 g_assert_not_reached();
298 static inline void kvm_arm_add_vcpu_properties(Object
*obj
)
300 g_assert_not_reached();
303 static inline int kvm_arm_get_max_vm_ipa_size(MachineState
*ms
, bool *fixed_ipa
)
305 g_assert_not_reached();
308 static inline int kvm_arm_vgic_probe(void)
310 g_assert_not_reached();
313 static inline void kvm_arm_pmu_set_irq(CPUState
*cs
, int irq
)
315 g_assert_not_reached();
318 static inline void kvm_arm_pmu_init(CPUState
*cs
)
320 g_assert_not_reached();
323 static inline void kvm_arm_pvtime_init(CPUState
*cs
, uint64_t ipa
)
325 g_assert_not_reached();
328 static inline void kvm_arm_steal_time_finalize(ARMCPU
*cpu
, Error
**errp
)
330 g_assert_not_reached();
333 static inline uint32_t kvm_arm_sve_get_vls(CPUState
*cs
)
335 g_assert_not_reached();