]>
Commit | Line | Data |
---|---|---|
05330448 AL |
1 | /* |
2 | * QEMU KVM support | |
3 | * | |
4 | * Copyright IBM, Corp. 2008 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <aliguori@us.ibm.com> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
10 | * See the COPYING file in the top-level directory. | |
11 | * | |
12 | */ | |
13 | ||
14 | #ifndef QEMU_KVM_H | |
15 | #define QEMU_KVM_H | |
16 | ||
ca821806 | 17 | #include <errno.h> |
1c14f162 | 18 | #include "config-host.h" |
72cf2d4f | 19 | #include "qemu-queue.h" |
05330448 | 20 | |
ca821806 MT |
21 | #ifdef CONFIG_KVM |
22 | #include <linux/kvm.h> | |
23 | #endif | |
05330448 | 24 | |
ca821806 | 25 | extern int kvm_allowed; |
3d4b2649 | 26 | extern bool kvm_kernel_irqchip; |
7ae26bd4 | 27 | extern bool kvm_async_interrupts_allowed; |
cc7e0ddf | 28 | extern bool kvm_irqfds_allowed; |
98c8573e PB |
29 | |
30 | #if defined CONFIG_KVM || !defined NEED_CPU_H | |
3d4b2649 JK |
31 | #define kvm_enabled() (kvm_allowed) |
32 | #define kvm_irqchip_in_kernel() (kvm_kernel_irqchip) | |
7ae26bd4 PM |
33 | |
34 | /** | |
35 | * kvm_async_interrupts_enabled: | |
36 | * | |
37 | * Returns: true if we can deliver interrupts to KVM | |
38 | * asynchronously (ie by ioctl from any thread at any time) | |
39 | * rather than having to do interrupt delivery synchronously | |
40 | * (where the vcpu must be stopped at a suitable point first). | |
41 | */ | |
42 | #define kvm_async_interrupts_enabled() (kvm_async_interrupts_allowed) | |
43 | ||
cc7e0ddf PM |
44 | /** |
45 | * kvm_irqfds_enabled: | |
46 | * | |
47 | * Returns: true if we can use irqfds to inject interrupts into | |
48 | * a KVM CPU (ie the kernel supports irqfds and we are running | |
49 | * with a configuration where it is meaningful to use them). | |
50 | */ | |
51 | #define kvm_irqfds_enabled() (kvm_irqfds_allowed) | |
52 | ||
05330448 | 53 | #else |
3d4b2649 JK |
54 | #define kvm_enabled() (0) |
55 | #define kvm_irqchip_in_kernel() (false) | |
7ae26bd4 | 56 | #define kvm_async_interrupts_enabled() (false) |
cc7e0ddf | 57 | #define kvm_irqfds_enabled() (false) |
05330448 AL |
58 | #endif |
59 | ||
60 | struct kvm_run; | |
680c1c6f | 61 | struct kvm_lapic_state; |
05330448 | 62 | |
94a8d39a JK |
63 | typedef struct KVMCapabilityInfo { |
64 | const char *name; | |
65 | int value; | |
66 | } KVMCapabilityInfo; | |
67 | ||
68 | #define KVM_CAP_INFO(CAP) { "KVM_CAP_" stringify(CAP), KVM_CAP_##CAP } | |
69 | #define KVM_CAP_LAST_INFO { NULL, 0 } | |
70 | ||
92b4e489 JK |
71 | struct KVMState; |
72 | typedef struct KVMState KVMState; | |
73 | extern KVMState *kvm_state; | |
74 | ||
05330448 AL |
75 | /* external API */ |
76 | ||
cad1e282 | 77 | int kvm_init(void); |
05330448 | 78 | |
00a1555e PB |
79 | int kvm_has_sync_mmu(void); |
80 | int kvm_has_vcpu_events(void); | |
81 | int kvm_has_robust_singlestep(void); | |
ff44f1a3 | 82 | int kvm_has_debugregs(void); |
f1665b21 SY |
83 | int kvm_has_xsave(void); |
84 | int kvm_has_xcrs(void); | |
8a7c7393 | 85 | int kvm_has_pit_state2(void); |
d2f2b8a7 | 86 | int kvm_has_many_ioeventfds(void); |
84b058d7 | 87 | int kvm_has_gsi_routing(void); |
00a1555e | 88 | |
1c14f162 | 89 | #ifdef NEED_CPU_H |
9349b4f9 | 90 | int kvm_init_vcpu(CPUArchState *env); |
05330448 | 91 | |
9349b4f9 | 92 | int kvm_cpu_exec(CPUArchState *env); |
05330448 | 93 | |
b3755a91 | 94 | #if !defined(CONFIG_USER_ONLY) |
fdec9918 CB |
95 | void *kvm_vmalloc(ram_addr_t size); |
96 | void *kvm_arch_vmalloc(ram_addr_t size); | |
6f0437e8 JK |
97 | void kvm_setup_guest_memory(void *start, size_t size); |
98 | ||
c227f099 AL |
99 | int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size); |
100 | int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size); | |
62a2744c | 101 | void kvm_flush_coalesced_mmio_buffer(void); |
b3755a91 | 102 | #endif |
f65ed4c1 | 103 | |
9349b4f9 | 104 | int kvm_insert_breakpoint(CPUArchState *current_env, target_ulong addr, |
e22a25c9 | 105 | target_ulong len, int type); |
9349b4f9 | 106 | int kvm_remove_breakpoint(CPUArchState *current_env, target_ulong addr, |
e22a25c9 | 107 | target_ulong len, int type); |
9349b4f9 AF |
108 | void kvm_remove_all_breakpoints(CPUArchState *current_env); |
109 | int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap); | |
20c20526 | 110 | #ifndef _WIN32 |
9349b4f9 | 111 | int kvm_set_signal_mask(CPUArchState *env, const sigset_t *sigset); |
20c20526 | 112 | #endif |
e22a25c9 | 113 | |
9349b4f9 | 114 | int kvm_on_sigbus_vcpu(CPUArchState *env, int code, void *addr); |
a1b87fe0 JK |
115 | int kvm_on_sigbus(int code, void *addr); |
116 | ||
05330448 AL |
117 | /* internal API */ |
118 | ||
984b5181 | 119 | int kvm_ioctl(KVMState *s, int type, ...); |
05330448 | 120 | |
984b5181 | 121 | int kvm_vm_ioctl(KVMState *s, int type, ...); |
05330448 | 122 | |
9349b4f9 | 123 | int kvm_vcpu_ioctl(CPUArchState *env, int type, ...); |
05330448 AL |
124 | |
125 | /* Arch specific hooks */ | |
126 | ||
94a8d39a JK |
127 | extern const KVMCapabilityInfo kvm_arch_required_capabilities[]; |
128 | ||
9349b4f9 AF |
129 | void kvm_arch_pre_run(CPUArchState *env, struct kvm_run *run); |
130 | void kvm_arch_post_run(CPUArchState *env, struct kvm_run *run); | |
05330448 | 131 | |
9349b4f9 | 132 | int kvm_arch_handle_exit(CPUArchState *env, struct kvm_run *run); |
05330448 | 133 | |
9349b4f9 | 134 | int kvm_arch_process_async_events(CPUArchState *env); |
0af691d7 | 135 | |
9349b4f9 | 136 | int kvm_arch_get_registers(CPUArchState *env); |
05330448 | 137 | |
ea375f9a JK |
138 | /* state subset only touched by the VCPU itself during runtime */ |
139 | #define KVM_PUT_RUNTIME_STATE 1 | |
140 | /* state subset modified during VCPU reset */ | |
141 | #define KVM_PUT_RESET_STATE 2 | |
142 | /* full state set, modified during initialization or on vmload */ | |
143 | #define KVM_PUT_FULL_STATE 3 | |
144 | ||
9349b4f9 | 145 | int kvm_arch_put_registers(CPUArchState *env, int level); |
05330448 | 146 | |
cad1e282 | 147 | int kvm_arch_init(KVMState *s); |
05330448 | 148 | |
9349b4f9 | 149 | int kvm_arch_init_vcpu(CPUArchState *env); |
05330448 | 150 | |
9349b4f9 | 151 | void kvm_arch_reset_vcpu(CPUArchState *env); |
caa5af0f | 152 | |
9349b4f9 | 153 | int kvm_arch_on_sigbus_vcpu(CPUArchState *env, int code, void *addr); |
a1b87fe0 | 154 | int kvm_arch_on_sigbus(int code, void *addr); |
c0532a76 | 155 | |
84b058d7 JK |
156 | void kvm_arch_init_irq_routing(KVMState *s); |
157 | ||
3889c3fa | 158 | int kvm_set_irq(KVMState *s, int irq, int level); |
04fa27f5 | 159 | int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg); |
84b058d7 | 160 | |
1df186df | 161 | void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin); |
84b058d7 | 162 | |
680c1c6f JK |
163 | void kvm_put_apic_state(DeviceState *d, struct kvm_lapic_state *kapic); |
164 | void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic); | |
165 | ||
e22a25c9 AL |
166 | struct kvm_guest_debug; |
167 | struct kvm_debug_exit_arch; | |
168 | ||
169 | struct kvm_sw_breakpoint { | |
170 | target_ulong pc; | |
171 | target_ulong saved_insn; | |
172 | int use_count; | |
72cf2d4f | 173 | QTAILQ_ENTRY(kvm_sw_breakpoint) entry; |
e22a25c9 AL |
174 | }; |
175 | ||
72cf2d4f | 176 | QTAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint); |
e22a25c9 | 177 | |
9349b4f9 | 178 | struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUArchState *env, |
e22a25c9 AL |
179 | target_ulong pc); |
180 | ||
9349b4f9 | 181 | int kvm_sw_breakpoints_active(CPUArchState *env); |
e22a25c9 | 182 | |
9349b4f9 | 183 | int kvm_arch_insert_sw_breakpoint(CPUArchState *current_env, |
e22a25c9 | 184 | struct kvm_sw_breakpoint *bp); |
9349b4f9 | 185 | int kvm_arch_remove_sw_breakpoint(CPUArchState *current_env, |
e22a25c9 AL |
186 | struct kvm_sw_breakpoint *bp); |
187 | int kvm_arch_insert_hw_breakpoint(target_ulong addr, | |
188 | target_ulong len, int type); | |
189 | int kvm_arch_remove_hw_breakpoint(target_ulong addr, | |
190 | target_ulong len, int type); | |
191 | void kvm_arch_remove_all_hw_breakpoints(void); | |
192 | ||
9349b4f9 | 193 | void kvm_arch_update_guest_debug(CPUArchState *env, struct kvm_guest_debug *dbg); |
e22a25c9 | 194 | |
9349b4f9 | 195 | bool kvm_arch_stop_on_emulation_error(CPUArchState *env); |
4513d923 | 196 | |
ad7b8b33 AL |
197 | int kvm_check_extension(KVMState *s, unsigned int extension); |
198 | ||
ba9bc59e | 199 | uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, |
c958a8bd | 200 | uint32_t index, int reg); |
9349b4f9 AF |
201 | void kvm_cpu_synchronize_state(CPUArchState *env); |
202 | void kvm_cpu_synchronize_post_reset(CPUArchState *env); | |
203 | void kvm_cpu_synchronize_post_init(CPUArchState *env); | |
b827df58 | 204 | |
e22a25c9 AL |
205 | /* generic hooks - to be moved/refactored once there are more users */ |
206 | ||
9349b4f9 | 207 | static inline void cpu_synchronize_state(CPUArchState *env) |
e22a25c9 AL |
208 | { |
209 | if (kvm_enabled()) { | |
4c0960c0 | 210 | kvm_cpu_synchronize_state(env); |
e22a25c9 AL |
211 | } |
212 | } | |
213 | ||
9349b4f9 | 214 | static inline void cpu_synchronize_post_reset(CPUArchState *env) |
ea375f9a JK |
215 | { |
216 | if (kvm_enabled()) { | |
217 | kvm_cpu_synchronize_post_reset(env); | |
218 | } | |
219 | } | |
220 | ||
9349b4f9 | 221 | static inline void cpu_synchronize_post_init(CPUArchState *env) |
ea375f9a JK |
222 | { |
223 | if (kvm_enabled()) { | |
224 | kvm_cpu_synchronize_post_init(env); | |
225 | } | |
226 | } | |
ca821806 | 227 | |
983dfc3b HY |
228 | |
229 | #if !defined(CONFIG_USER_ONLY) | |
9f213ed9 AK |
230 | int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr, |
231 | target_phys_addr_t *phys_addr); | |
983dfc3b HY |
232 | #endif |
233 | ||
ca821806 | 234 | #endif |
4b8f1c88 MT |
235 | int kvm_set_ioeventfd_mmio(int fd, uint32_t adr, uint32_t val, bool assign, |
236 | uint32_t size); | |
ca821806 | 237 | |
98c8573e | 238 | int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign); |
92b4e489 JK |
239 | |
240 | int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg); | |
1e2aa8be | 241 | void kvm_irqchip_release_virq(KVMState *s, int virq); |
39853bbc JK |
242 | |
243 | int kvm_irqchip_add_irqfd(KVMState *s, int fd, int virq); | |
244 | int kvm_irqchip_remove_irqfd(KVMState *s, int fd, int virq); | |
15b2bd18 PB |
245 | int kvm_irqchip_add_irq_notifier(KVMState *s, EventNotifier *n, int virq); |
246 | int kvm_irqchip_remove_irq_notifier(KVMState *s, EventNotifier *n, int virq); | |
05330448 | 247 | #endif |