qmp: Simplify recognition of capability negotiation command
[qemu.git] / target-arm / kvm_arm.h
blob455dea3f3fe227133948b62d9605f745855d1469
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"
17 /**
18 * kvm_arm_vcpu_init:
19 * @cs: CPUState
21 * Initialize (or reinitialize) the VCPU by invoking the
22 * KVM_ARM_VCPU_INIT ioctl with the CPU type and feature
23 * bitmask specified in the CPUState.
25 * Returns: 0 if success else < 0 error code
27 int kvm_arm_vcpu_init(CPUState *cs);
29 /**
30 * kvm_arm_register_device:
31 * @mr: memory region for this device
32 * @devid: the KVM device ID
33 * @group: device control API group for setting addresses
34 * @attr: device control API address type
35 * @dev_fd: device control device file descriptor (or -1 if not supported)
37 * Remember the memory region @mr, and when it is mapped by the
38 * machine model, tell the kernel that base address using the
39 * KVM_ARM_SET_DEVICE_ADDRESS ioctl or the newer device control API. @devid
40 * should be the ID of the device as defined by KVM_ARM_SET_DEVICE_ADDRESS or
41 * the arm-vgic device in the device control API.
42 * The machine model may map
43 * and unmap the device multiple times; the kernel will only be told the final
44 * address at the point where machine init is complete.
46 void kvm_arm_register_device(MemoryRegion *mr, uint64_t devid, uint64_t group,
47 uint64_t attr, int dev_fd);
49 /**
50 * kvm_arm_init_cpreg_list:
51 * @cs: CPUState
53 * Initialize the CPUState's cpreg list according to the kernel's
54 * definition of what CPU registers it knows about (and throw away
55 * the previous TCG-created cpreg list).
57 * Returns: 0 if success, else < 0 error code
59 int kvm_arm_init_cpreg_list(ARMCPU *cpu);
61 /**
62 * kvm_arm_reg_syncs_via_cpreg_list
63 * regidx: KVM register index
65 * Return true if this KVM register should be synchronized via the
66 * cpreg list of arbitrary system registers, false if it is synchronized
67 * by hand using code in kvm_arch_get/put_registers().
69 bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx);
71 /**
72 * write_list_to_kvmstate:
73 * @cpu: ARMCPU
75 * For each register listed in the ARMCPU cpreg_indexes list, write
76 * its value from the cpreg_values list into the kernel (via ioctl).
77 * This updates KVM's working data structures from TCG data or
78 * from incoming migration state.
80 * Returns: true if all register values were updated correctly,
81 * false if some register was unknown to the kernel or could not
82 * be written (eg constant register with the wrong value).
83 * Note that we do not stop early on failure -- we will attempt
84 * writing all registers in the list.
86 bool write_list_to_kvmstate(ARMCPU *cpu);
88 /**
89 * write_kvmstate_to_list:
90 * @cpu: ARMCPU
92 * For each register listed in the ARMCPU cpreg_indexes list, write
93 * its value from the kernel into the cpreg_values list. This is used to
94 * copy info from KVM's working data structures into TCG or
95 * for outbound migration.
97 * Returns: true if all register values were read correctly,
98 * false if some register was unknown or could not be read.
99 * Note that we do not stop early on failure -- we will attempt
100 * reading all registers in the list.
102 bool write_kvmstate_to_list(ARMCPU *cpu);
105 * kvm_arm_reset_vcpu:
106 * @cpu: ARMCPU
108 * Called at reset time to kernel registers to their initial values.
110 void kvm_arm_reset_vcpu(ARMCPU *cpu);
112 #ifdef CONFIG_KVM
114 * kvm_arm_create_scratch_host_vcpu:
115 * @cpus_to_try: array of QEMU_KVM_ARM_TARGET_* values (terminated with
116 * QEMU_KVM_ARM_TARGET_NONE) to try as fallback if the kernel does not
117 * know the PREFERRED_TARGET ioctl
118 * @fdarray: filled in with kvmfd, vmfd, cpufd file descriptors in that order
119 * @init: filled in with the necessary values for creating a host vcpu
121 * Create a scratch vcpu in its own VM of the type preferred by the host
122 * kernel (as would be used for '-cpu host'), for purposes of probing it
123 * for capabilities.
125 * Returns: true on success (and fdarray and init are filled in),
126 * false on failure (and fdarray and init are not valid).
128 bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
129 int *fdarray,
130 struct kvm_vcpu_init *init);
133 * kvm_arm_destroy_scratch_host_vcpu:
134 * @fdarray: array of fds as set up by kvm_arm_create_scratch_host_vcpu
136 * Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu.
138 void kvm_arm_destroy_scratch_host_vcpu(int *fdarray);
140 #define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU
141 #define ARM_HOST_CPU_CLASS(klass) \
142 OBJECT_CLASS_CHECK(ARMHostCPUClass, (klass), TYPE_ARM_HOST_CPU)
143 #define ARM_HOST_CPU_GET_CLASS(obj) \
144 OBJECT_GET_CLASS(ARMHostCPUClass, (obj), TYPE_ARM_HOST_CPU)
146 typedef struct ARMHostCPUClass {
147 /*< private >*/
148 ARMCPUClass parent_class;
149 /*< public >*/
151 uint64_t features;
152 uint32_t target;
153 const char *dtb_compatible;
154 } ARMHostCPUClass;
157 * kvm_arm_get_host_cpu_features:
158 * @ahcc: ARMHostCPUClass to fill in
160 * Probe the capabilities of the host kernel's preferred CPU and fill
161 * in the ARMHostCPUClass struct accordingly.
163 bool kvm_arm_get_host_cpu_features(ARMHostCPUClass *ahcc);
165 #endif
167 #endif