]> git.proxmox.com Git - mirror_qemu.git/blob - target/arm/kvm_arm.h
target/arm/kvm: Unexport kvm_arm_init_cpreg_list
[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 /**
102 * kvm_arm_init_serror_injection:
103 * @cs: CPUState
104 *
105 * Check whether KVM can set guest SError syndrome.
106 */
107 void kvm_arm_init_serror_injection(CPUState *cs);
108
109 /**
110 * kvm_get_vcpu_events:
111 * @cpu: ARMCPU
112 *
113 * Get VCPU related state from kvm.
114 *
115 * Returns: 0 if success else < 0 error code
116 */
117 int kvm_get_vcpu_events(ARMCPU *cpu);
118
119 /**
120 * kvm_put_vcpu_events:
121 * @cpu: ARMCPU
122 *
123 * Put VCPU related state to kvm.
124 *
125 * Returns: 0 if success else < 0 error code
126 */
127 int kvm_put_vcpu_events(ARMCPU *cpu);
128
129 #ifdef CONFIG_KVM
130 /**
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
135 * an empty array.
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).
140 *
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
143 * for capabilities.
144 *
145 * Returns: true on success (and fdarray and init are filled in),
146 * false on failure (and fdarray and init are not valid).
147 */
148 bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
149 int *fdarray,
150 struct kvm_vcpu_init *init);
151
152 /**
153 * kvm_arm_destroy_scratch_host_vcpu:
154 * @fdarray: array of fds as set up by kvm_arm_create_scratch_host_vcpu
155 *
156 * Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu.
157 */
158 void kvm_arm_destroy_scratch_host_vcpu(int *fdarray);
159
160 /**
161 * kvm_arm_sve_get_vls:
162 * @cs: CPUState
163 *
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.
167 */
168 uint32_t kvm_arm_sve_get_vls(CPUState *cs);
169
170 /**
171 * kvm_arm_set_cpu_features_from_host:
172 * @cpu: ARMCPU to set the features for
173 *
174 * Set up the ARMCPU struct fields up to match the information probed
175 * from the host CPU.
176 */
177 void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu);
178
179 /**
180 * kvm_arm_add_vcpu_properties:
181 * @obj: The CPU object to add the properties to
182 *
183 * Add all KVM specific CPU properties to the CPU object. These
184 * are the CPU properties with "kvm-" prefixed names.
185 */
186 void kvm_arm_add_vcpu_properties(Object *obj);
187
188 /**
189 * kvm_arm_steal_time_finalize:
190 * @cpu: ARMCPU for which to finalize kvm-steal-time
191 * @errp: Pointer to Error* for error propagation
192 *
193 * Validate the kvm-steal-time property selection and set its default
194 * based on KVM support and guest configuration.
195 */
196 void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp);
197
198 /**
199 * kvm_arm_aarch32_supported:
200 *
201 * Returns: true if KVM can enable AArch32 mode
202 * and false otherwise.
203 */
204 bool kvm_arm_aarch32_supported(void);
205
206 /**
207 * kvm_arm_pmu_supported:
208 *
209 * Returns: true if KVM can enable the PMU
210 * and false otherwise.
211 */
212 bool kvm_arm_pmu_supported(void);
213
214 /**
215 * kvm_arm_sve_supported:
216 *
217 * Returns true if KVM can enable SVE and false otherwise.
218 */
219 bool kvm_arm_sve_supported(void);
220
221 /**
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
225 * for legacy KVM.
226 *
227 * Returns the number of bits in the IPA address space supported by KVM
228 */
229 int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa);
230
231 /**
232 * kvm_arm_sync_mpstate_to_kvm:
233 * @cpu: ARMCPU
234 *
235 * If supported set the KVM MP_STATE based on QEMU's model.
236 *
237 * Returns 0 on success and -1 on failure.
238 */
239 int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu);
240
241 /**
242 * kvm_arm_sync_mpstate_to_qemu:
243 * @cpu: ARMCPU
244 *
245 * If supported get the MP_STATE from KVM and store in QEMU's model.
246 *
247 * Returns 0 on success and aborts on failure.
248 */
249 int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu);
250
251 void kvm_arm_vm_state_change(void *opaque, bool running, RunState state);
252
253 int kvm_arm_vgic_probe(void);
254
255 void kvm_arm_pmu_set_irq(CPUState *cs, int irq);
256 void kvm_arm_pmu_init(CPUState *cs);
257
258 /**
259 * kvm_arm_pvtime_init:
260 * @cs: CPUState
261 * @ipa: Per-vcpu guest physical base address of the pvtime structures
262 *
263 * Initializes PVTIME for the VCPU, setting the PVTIME IPA to @ipa.
264 */
265 void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa);
266
267 int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level);
268
269 #else
270
271 /*
272 * It's safe to call these functions without KVM support.
273 * They should either do nothing or return "not supported".
274 */
275 static inline bool kvm_arm_aarch32_supported(void)
276 {
277 return false;
278 }
279
280 static inline bool kvm_arm_pmu_supported(void)
281 {
282 return false;
283 }
284
285 static inline bool kvm_arm_sve_supported(void)
286 {
287 return false;
288 }
289
290 /*
291 * These functions should never actually be called without KVM support.
292 */
293 static inline void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu)
294 {
295 g_assert_not_reached();
296 }
297
298 static inline void kvm_arm_add_vcpu_properties(Object *obj)
299 {
300 g_assert_not_reached();
301 }
302
303 static inline int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa)
304 {
305 g_assert_not_reached();
306 }
307
308 static inline int kvm_arm_vgic_probe(void)
309 {
310 g_assert_not_reached();
311 }
312
313 static inline void kvm_arm_pmu_set_irq(CPUState *cs, int irq)
314 {
315 g_assert_not_reached();
316 }
317
318 static inline void kvm_arm_pmu_init(CPUState *cs)
319 {
320 g_assert_not_reached();
321 }
322
323 static inline void kvm_arm_pvtime_init(CPUState *cs, uint64_t ipa)
324 {
325 g_assert_not_reached();
326 }
327
328 static inline void kvm_arm_steal_time_finalize(ARMCPU *cpu, Error **errp)
329 {
330 g_assert_not_reached();
331 }
332
333 static inline uint32_t kvm_arm_sve_get_vls(CPUState *cs)
334 {
335 g_assert_not_reached();
336 }
337
338 #endif
339
340 #endif