]>
Commit | Line | Data |
---|---|---|
eb035b48 PM |
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 | ||
228d5e04 PS |
17 | /** |
18 | * kvm_arm_vcpu_init: | |
19 | * @cs: CPUState | |
20 | * | |
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. | |
24 | * | |
25 | * Returns: 0 if success else < 0 error code | |
26 | */ | |
27 | int kvm_arm_vcpu_init(CPUState *cs); | |
28 | ||
eb035b48 PM |
29 | /** |
30 | * kvm_arm_register_device: | |
31 | * @mr: memory region for this device | |
32 | * @devid: the KVM device ID | |
1da41cc1 CD |
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) | |
eb035b48 PM |
36 | * |
37 | * Remember the memory region @mr, and when it is mapped by the | |
38 | * machine model, tell the kernel that base address using the | |
1da41cc1 CD |
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. | |
eb035b48 | 45 | */ |
1da41cc1 CD |
46 | void kvm_arm_register_device(MemoryRegion *mr, uint64_t devid, uint64_t group, |
47 | uint64_t attr, int dev_fd); | |
eb035b48 | 48 | |
38df27c8 AB |
49 | /** |
50 | * kvm_arm_init_cpreg_list: | |
51 | * @cs: CPUState | |
52 | * | |
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). | |
56 | * | |
57 | * Returns: 0 if success, else < 0 error code | |
58 | */ | |
59 | int kvm_arm_init_cpreg_list(ARMCPU *cpu); | |
60 | ||
61 | /** | |
62 | * kvm_arm_reg_syncs_via_cpreg_list | |
63 | * regidx: KVM register index | |
64 | * | |
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(). | |
68 | */ | |
69 | bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx); | |
70 | ||
4b7a6bf4 CD |
71 | /** |
72 | * kvm_arm_cpreg_level | |
73 | * regidx: KVM register index | |
74 | * | |
75 | * Return the level of this coprocessor/system register. Return value is | |
76 | * either KVM_PUT_RUNTIME_STATE, KVM_PUT_RESET_STATE, or KVM_PUT_FULL_STATE. | |
77 | */ | |
78 | int kvm_arm_cpreg_level(uint64_t regidx); | |
79 | ||
ff047453 PM |
80 | /** |
81 | * write_list_to_kvmstate: | |
82 | * @cpu: ARMCPU | |
4b7a6bf4 | 83 | * @level: the state level to sync |
ff047453 PM |
84 | * |
85 | * For each register listed in the ARMCPU cpreg_indexes list, write | |
86 | * its value from the cpreg_values list into the kernel (via ioctl). | |
87 | * This updates KVM's working data structures from TCG data or | |
88 | * from incoming migration state. | |
89 | * | |
90 | * Returns: true if all register values were updated correctly, | |
91 | * false if some register was unknown to the kernel or could not | |
92 | * be written (eg constant register with the wrong value). | |
93 | * Note that we do not stop early on failure -- we will attempt | |
94 | * writing all registers in the list. | |
95 | */ | |
4b7a6bf4 | 96 | bool write_list_to_kvmstate(ARMCPU *cpu, int level); |
ff047453 PM |
97 | |
98 | /** | |
99 | * write_kvmstate_to_list: | |
100 | * @cpu: ARMCPU | |
101 | * | |
102 | * For each register listed in the ARMCPU cpreg_indexes list, write | |
103 | * its value from the kernel into the cpreg_values list. This is used to | |
104 | * copy info from KVM's working data structures into TCG or | |
105 | * for outbound migration. | |
106 | * | |
107 | * Returns: true if all register values were read correctly, | |
108 | * false if some register was unknown or could not be read. | |
109 | * Note that we do not stop early on failure -- we will attempt | |
110 | * reading all registers in the list. | |
111 | */ | |
112 | bool write_kvmstate_to_list(ARMCPU *cpu); | |
113 | ||
50a2c6e5 PB |
114 | /** |
115 | * kvm_arm_reset_vcpu: | |
116 | * @cpu: ARMCPU | |
117 | * | |
118 | * Called at reset time to kernel registers to their initial values. | |
119 | */ | |
120 | void kvm_arm_reset_vcpu(ARMCPU *cpu); | |
121 | ||
a96c0514 PM |
122 | #ifdef CONFIG_KVM |
123 | /** | |
124 | * kvm_arm_create_scratch_host_vcpu: | |
125 | * @cpus_to_try: array of QEMU_KVM_ARM_TARGET_* values (terminated with | |
126 | * QEMU_KVM_ARM_TARGET_NONE) to try as fallback if the kernel does not | |
127 | * know the PREFERRED_TARGET ioctl | |
128 | * @fdarray: filled in with kvmfd, vmfd, cpufd file descriptors in that order | |
129 | * @init: filled in with the necessary values for creating a host vcpu | |
130 | * | |
131 | * Create a scratch vcpu in its own VM of the type preferred by the host | |
132 | * kernel (as would be used for '-cpu host'), for purposes of probing it | |
133 | * for capabilities. | |
134 | * | |
135 | * Returns: true on success (and fdarray and init are filled in), | |
136 | * false on failure (and fdarray and init are not valid). | |
137 | */ | |
138 | bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, | |
139 | int *fdarray, | |
140 | struct kvm_vcpu_init *init); | |
141 | ||
142 | /** | |
143 | * kvm_arm_destroy_scratch_host_vcpu: | |
144 | * @fdarray: array of fds as set up by kvm_arm_create_scratch_host_vcpu | |
145 | * | |
146 | * Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu. | |
147 | */ | |
148 | void kvm_arm_destroy_scratch_host_vcpu(int *fdarray); | |
149 | ||
150 | #define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU | |
151 | #define ARM_HOST_CPU_CLASS(klass) \ | |
152 | OBJECT_CLASS_CHECK(ARMHostCPUClass, (klass), TYPE_ARM_HOST_CPU) | |
153 | #define ARM_HOST_CPU_GET_CLASS(obj) \ | |
154 | OBJECT_GET_CLASS(ARMHostCPUClass, (obj), TYPE_ARM_HOST_CPU) | |
155 | ||
156 | typedef struct ARMHostCPUClass { | |
157 | /*< private >*/ | |
158 | ARMCPUClass parent_class; | |
159 | /*< public >*/ | |
160 | ||
161 | uint64_t features; | |
162 | uint32_t target; | |
163 | const char *dtb_compatible; | |
164 | } ARMHostCPUClass; | |
165 | ||
166 | /** | |
167 | * kvm_arm_get_host_cpu_features: | |
168 | * @ahcc: ARMHostCPUClass to fill in | |
169 | * | |
170 | * Probe the capabilities of the host kernel's preferred CPU and fill | |
171 | * in the ARMHostCPUClass struct accordingly. | |
172 | */ | |
173 | bool kvm_arm_get_host_cpu_features(ARMHostCPUClass *ahcc); | |
174 | ||
1a1753f7 AB |
175 | |
176 | /** | |
177 | * kvm_arm_sync_mpstate_to_kvm | |
178 | * @cpu: ARMCPU | |
179 | * | |
180 | * If supported set the KVM MP_STATE based on QEMU's model. | |
181 | */ | |
182 | int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu); | |
183 | ||
184 | /** | |
185 | * kvm_arm_sync_mpstate_to_qemu | |
186 | * @cpu: ARMCPU | |
187 | * | |
188 | * If supported get the MP_STATE from KVM and store in QEMU's model. | |
189 | */ | |
190 | int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu); | |
191 | ||
34e85cd9 PF |
192 | int kvm_arm_vgic_probe(void); |
193 | ||
194 | #else | |
195 | ||
196 | static inline int kvm_arm_vgic_probe(void) | |
197 | { | |
198 | return 0; | |
199 | } | |
200 | ||
a96c0514 PM |
201 | #endif |
202 | ||
e6fbcbc4 PF |
203 | static inline const char *gic_class_name(void) |
204 | { | |
205 | return kvm_irqchip_in_kernel() ? "kvm-arm-gic" : "arm_gic"; | |
206 | } | |
207 | ||
a7bf3034 PF |
208 | /** |
209 | * gicv3_class_name | |
210 | * | |
211 | * Return name of GICv3 class to use depending on whether KVM acceleration is | |
212 | * in use. May throw an error if the chosen implementation is not available. | |
213 | * | |
214 | * Returns: class name to use | |
215 | */ | |
216 | const char *gicv3_class_name(void); | |
217 | ||
2ecb2027 AB |
218 | /** |
219 | * kvm_arm_handle_debug: | |
220 | * @cs: CPUState | |
221 | * @debug_exit: debug part of the KVM exit structure | |
222 | * | |
223 | * Returns: TRUE if the debug exception was handled. | |
224 | */ | |
225 | bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit); | |
226 | ||
e4482ab7 AB |
227 | /** |
228 | * kvm_arm_hw_debug_active: | |
229 | * @cs: CPU State | |
230 | * | |
231 | * Return: TRUE if any hardware breakpoints in use. | |
232 | */ | |
233 | ||
234 | bool kvm_arm_hw_debug_active(CPUState *cs); | |
235 | ||
236 | /** | |
237 | * kvm_arm_copy_hw_debug_data: | |
238 | * | |
239 | * @ptr: kvm_guest_debug_arch structure | |
240 | * | |
241 | * Copy the architecture specific debug registers into the | |
242 | * kvm_guest_debug ioctl structure. | |
243 | */ | |
244 | struct kvm_guest_debug_arch; | |
245 | ||
246 | void kvm_arm_copy_hw_debug_data(struct kvm_guest_debug_arch *ptr); | |
247 | ||
eb035b48 | 248 | #endif |