target/arm/kvm: Unexport and tidy kvm_arm_sync_mpstate_to_{kvm, qemu}
[qemu/kevin.git] / target / arm / kvm_arm.h
blob8a44a6b762f9bcb825dd906836d4e0081469e84b
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_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);
42 /**
43 * write_list_to_kvmstate:
44 * @cpu: ARMCPU
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);
60 /**
61 * write_kvmstate_to_list:
62 * @cpu: ARMCPU
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);
76 /**
77 * kvm_arm_cpu_pre_save:
78 * @cpu: ARMCPU
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);
85 /**
86 * kvm_arm_cpu_post_load:
87 * @cpu: ARMCPU
89 * Called from cpu_post_load() to update KVM CPU state from the cpreg list.
91 void kvm_arm_cpu_post_load(ARMCPU *cpu);
93 /**
94 * kvm_arm_reset_vcpu:
95 * @cpu: ARMCPU
97 * Called at reset time to kernel registers to their initial values.
99 void kvm_arm_reset_vcpu(ARMCPU *cpu);
101 #ifdef CONFIG_KVM
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).
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.
117 * Returns: true on success (and fdarray and init are filled in),
118 * false on failure (and fdarray and init are not valid).
120 bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
121 int *fdarray,
122 struct kvm_vcpu_init *init);
125 * kvm_arm_destroy_scratch_host_vcpu:
126 * @fdarray: array of fds as set up by kvm_arm_create_scratch_host_vcpu
128 * Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu.
130 void kvm_arm_destroy_scratch_host_vcpu(int *fdarray);
133 * kvm_arm_sve_get_vls:
134 * @cs: CPUState
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.
140 uint32_t kvm_arm_sve_get_vls(CPUState *cs);
143 * kvm_arm_set_cpu_features_from_host:
144 * @cpu: ARMCPU to set the features for
146 * Set up the ARMCPU struct fields up to match the information probed
147 * from the host CPU.
149 void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu);
152 * kvm_arm_add_vcpu_properties:
153 * @obj: The CPU object to add the properties to
155 * Add all KVM specific CPU properties to the CPU object. These
156 * are the CPU properties with "kvm-" prefixed names.
158 void kvm_arm_add_vcpu_properties(Object *obj);
161 * kvm_arm_steal_time_finalize:
162 * @cpu: ARMCPU for which to finalize kvm-steal-time
163 * @errp: Pointer to Error* for error propagation
165 * Validate the kvm-steal-time property selection and set its default
166 * based on KVM support and guest configuration.
168 void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp);
171 * kvm_arm_aarch32_supported:
173 * Returns: true if KVM can enable AArch32 mode
174 * and false otherwise.
176 bool kvm_arm_aarch32_supported(void);
179 * kvm_arm_pmu_supported:
181 * Returns: true if KVM can enable the PMU
182 * and false otherwise.
184 bool kvm_arm_pmu_supported(void);
187 * kvm_arm_sve_supported:
189 * Returns true if KVM can enable SVE and false otherwise.
191 bool kvm_arm_sve_supported(void);
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.
199 * Returns the number of bits in the IPA address space supported by KVM
201 int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa);
203 void kvm_arm_vm_state_change(void *opaque, bool running, RunState state);
205 int kvm_arm_vgic_probe(void);
207 void kvm_arm_pmu_set_irq(CPUState *cs, int irq);
208 void kvm_arm_pmu_init(CPUState *cs);
211 * kvm_arm_pvtime_init:
212 * @cs: CPUState
213 * @ipa: Per-vcpu guest physical base address of the pvtime structures
215 * Initializes PVTIME for the VCPU, setting the PVTIME IPA to @ipa.
217 void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa);
219 int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level);
221 #else
224 * It's safe to call these functions without KVM support.
225 * They should either do nothing or return "not supported".
227 static inline bool kvm_arm_aarch32_supported(void)
229 return false;
232 static inline bool kvm_arm_pmu_supported(void)
234 return false;
237 static inline bool kvm_arm_sve_supported(void)
239 return false;
243 * These functions should never actually be called without KVM support.
245 static inline void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu)
247 g_assert_not_reached();
250 static inline void kvm_arm_add_vcpu_properties(Object *obj)
252 g_assert_not_reached();
255 static inline int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa)
257 g_assert_not_reached();
260 static inline int kvm_arm_vgic_probe(void)
262 g_assert_not_reached();
265 static inline void kvm_arm_pmu_set_irq(CPUState *cs, int irq)
267 g_assert_not_reached();
270 static inline void kvm_arm_pmu_init(CPUState *cs)
272 g_assert_not_reached();
275 static inline void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa)
277 g_assert_not_reached();
280 static inline void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp)
282 g_assert_not_reached();
285 static inline uint32_t kvm_arm_sve_get_vls(CPUState *cs)
287 g_assert_not_reached();
290 #endif
292 #endif