qapi/misc.json: Remove superfluous words in CpuModelExpansionType
[qemu/armbru.git] / target / arm / kvm_arm.h
blob5948e8b56027b167bbc7439fcf71a23aa9a593f4
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 /**
19 * kvm_arm_vcpu_init:
20 * @cs: CPUState
22 * Initialize (or reinitialize) the VCPU by invoking the
23 * KVM_ARM_VCPU_INIT ioctl with the CPU type and feature
24 * bitmask specified in the CPUState.
26 * Returns: 0 if success else < 0 error code
28 int kvm_arm_vcpu_init(CPUState *cs);
30 /**
31 * kvm_arm_register_device:
32 * @mr: memory region for this device
33 * @devid: the KVM device ID
34 * @group: device control API group for setting addresses
35 * @attr: device control API address type
36 * @dev_fd: device control device file descriptor (or -1 if not supported)
37 * @addr_ormask: value to be OR'ed with resolved address
39 * Remember the memory region @mr, and when it is mapped by the
40 * machine model, tell the kernel that base address using the
41 * KVM_ARM_SET_DEVICE_ADDRESS ioctl or the newer device control API. @devid
42 * should be the ID of the device as defined by KVM_ARM_SET_DEVICE_ADDRESS or
43 * the arm-vgic device in the device control API.
44 * The machine model may map
45 * and unmap the device multiple times; the kernel will only be told the final
46 * address at the point where machine init is complete.
48 void kvm_arm_register_device(MemoryRegion *mr, uint64_t devid, uint64_t group,
49 uint64_t attr, int dev_fd, uint64_t addr_ormask);
51 /**
52 * kvm_arm_init_cpreg_list:
53 * @cpu: ARMCPU
55 * Initialize the ARMCPU cpreg list according to the kernel's
56 * definition of what CPU registers it knows about (and throw away
57 * the previous TCG-created cpreg list).
59 * Returns: 0 if success, else < 0 error code
61 int kvm_arm_init_cpreg_list(ARMCPU *cpu);
63 /**
64 * kvm_arm_reg_syncs_via_cpreg_list
65 * regidx: KVM register index
67 * Return true if this KVM register should be synchronized via the
68 * cpreg list of arbitrary system registers, false if it is synchronized
69 * by hand using code in kvm_arch_get/put_registers().
71 bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx);
73 /**
74 * kvm_arm_cpreg_level
75 * regidx: KVM register index
77 * Return the level of this coprocessor/system register. Return value is
78 * either KVM_PUT_RUNTIME_STATE, KVM_PUT_RESET_STATE, or KVM_PUT_FULL_STATE.
80 int kvm_arm_cpreg_level(uint64_t regidx);
82 /**
83 * write_list_to_kvmstate:
84 * @cpu: ARMCPU
85 * @level: the state level to sync
87 * For each register listed in the ARMCPU cpreg_indexes list, write
88 * its value from the cpreg_values list into the kernel (via ioctl).
89 * This updates KVM's working data structures from TCG data or
90 * from incoming migration state.
92 * Returns: true if all register values were updated correctly,
93 * false if some register was unknown to the kernel or could not
94 * be written (eg constant register with the wrong value).
95 * Note that we do not stop early on failure -- we will attempt
96 * writing all registers in the list.
98 bool write_list_to_kvmstate(ARMCPU *cpu, int level);
101 * write_kvmstate_to_list:
102 * @cpu: ARMCPU
104 * For each register listed in the ARMCPU cpreg_indexes list, write
105 * its value from the kernel into the cpreg_values list. This is used to
106 * copy info from KVM's working data structures into TCG or
107 * for outbound migration.
109 * Returns: true if all register values were read correctly,
110 * false if some register was unknown or could not be read.
111 * Note that we do not stop early on failure -- we will attempt
112 * reading all registers in the list.
114 bool write_kvmstate_to_list(ARMCPU *cpu);
117 * kvm_arm_reset_vcpu:
118 * @cpu: ARMCPU
120 * Called at reset time to kernel registers to their initial values.
122 void kvm_arm_reset_vcpu(ARMCPU *cpu);
124 #ifdef CONFIG_KVM
126 * kvm_arm_create_scratch_host_vcpu:
127 * @cpus_to_try: array of QEMU_KVM_ARM_TARGET_* values (terminated with
128 * QEMU_KVM_ARM_TARGET_NONE) to try as fallback if the kernel does not
129 * know the PREFERRED_TARGET ioctl. Passing NULL is the same as passing
130 * an empty array.
131 * @fdarray: filled in with kvmfd, vmfd, cpufd file descriptors in that order
132 * @init: filled in with the necessary values for creating a host
133 * vcpu. If NULL is provided, will not init the vCPU (though the cpufd
134 * will still be set up).
136 * Create a scratch vcpu in its own VM of the type preferred by the host
137 * kernel (as would be used for '-cpu host'), for purposes of probing it
138 * for capabilities.
140 * Returns: true on success (and fdarray and init are filled in),
141 * false on failure (and fdarray and init are not valid).
143 bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
144 int *fdarray,
145 struct kvm_vcpu_init *init);
148 * kvm_arm_destroy_scratch_host_vcpu:
149 * @fdarray: array of fds as set up by kvm_arm_create_scratch_host_vcpu
151 * Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu.
153 void kvm_arm_destroy_scratch_host_vcpu(int *fdarray);
155 #define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU
158 * ARMHostCPUFeatures: information about the host CPU (identified
159 * by asking the host kernel)
161 typedef struct ARMHostCPUFeatures {
162 uint64_t features;
163 uint32_t target;
164 const char *dtb_compatible;
165 } ARMHostCPUFeatures;
168 * kvm_arm_get_host_cpu_features:
169 * @ahcc: ARMHostCPUClass to fill in
171 * Probe the capabilities of the host kernel's preferred CPU and fill
172 * in the ARMHostCPUClass struct accordingly.
174 bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf);
177 * kvm_arm_set_cpu_features_from_host:
178 * @cpu: ARMCPU to set the features for
180 * Set up the ARMCPU struct fields up to match the information probed
181 * from the host CPU.
183 void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu);
186 * kvm_arm_sync_mpstate_to_kvm
187 * @cpu: ARMCPU
189 * If supported set the KVM MP_STATE based on QEMU's model.
191 int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu);
194 * kvm_arm_sync_mpstate_to_qemu
195 * @cpu: ARMCPU
197 * If supported get the MP_STATE from KVM and store in QEMU's model.
199 int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu);
201 int kvm_arm_vgic_probe(void);
203 void kvm_arm_pmu_set_irq(CPUState *cs, int irq);
204 void kvm_arm_pmu_init(CPUState *cs);
206 #else
208 static inline void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu)
210 /* This should never actually be called in the "not KVM" case,
211 * but set up the fields to indicate an error anyway.
213 cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
214 cpu->host_cpu_probe_failed = true;
217 static inline int kvm_arm_vgic_probe(void)
219 return 0;
222 static inline void kvm_arm_pmu_set_irq(CPUState *cs, int irq) {}
223 static inline void kvm_arm_pmu_init(CPUState *cs) {}
225 #endif
227 static inline const char *gic_class_name(void)
229 return kvm_irqchip_in_kernel() ? "kvm-arm-gic" : "arm_gic";
233 * gicv3_class_name
235 * Return name of GICv3 class to use depending on whether KVM acceleration is
236 * in use. May throw an error if the chosen implementation is not available.
238 * Returns: class name to use
240 static inline const char *gicv3_class_name(void)
242 if (kvm_irqchip_in_kernel()) {
243 #ifdef TARGET_AARCH64
244 return "kvm-arm-gicv3";
245 #else
246 error_report("KVM GICv3 acceleration is not supported on this "
247 "platform");
248 exit(1);
249 #endif
250 } else {
251 if (kvm_enabled()) {
252 error_report("Userspace GICv3 is not supported with KVM");
253 exit(1);
255 return "arm-gicv3";
260 * kvm_arm_handle_debug:
261 * @cs: CPUState
262 * @debug_exit: debug part of the KVM exit structure
264 * Returns: TRUE if the debug exception was handled.
266 bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit);
269 * kvm_arm_hw_debug_active:
270 * @cs: CPU State
272 * Return: TRUE if any hardware breakpoints in use.
275 bool kvm_arm_hw_debug_active(CPUState *cs);
278 * kvm_arm_copy_hw_debug_data:
280 * @ptr: kvm_guest_debug_arch structure
282 * Copy the architecture specific debug registers into the
283 * kvm_guest_debug ioctl structure.
285 struct kvm_guest_debug_arch;
287 void kvm_arm_copy_hw_debug_data(struct kvm_guest_debug_arch *ptr);
290 * its_class_name
292 * Return the ITS class name to use depending on whether KVM acceleration
293 * and KVM CAP_SIGNAL_MSI are supported
295 * Returns: class name to use or NULL
297 static inline const char *its_class_name(void)
299 if (kvm_irqchip_in_kernel()) {
300 /* KVM implementation requires this capability */
301 return kvm_direct_msi_enabled() ? "arm-its-kvm" : NULL;
302 } else {
303 /* Software emulation is not implemented yet */
304 return NULL;
308 #endif