]> git.proxmox.com Git - mirror_qemu.git/blob - kvm.h
kvm: Decouple 'MSI routing via irqfds' from 'kernel irqchip'
[mirror_qemu.git] / kvm.h
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
17 #include <errno.h>
18 #include "config-host.h"
19 #include "qemu-queue.h"
20
21 #ifdef CONFIG_KVM
22 #include <linux/kvm.h>
23 #endif
24
25 extern int kvm_allowed;
26 extern bool kvm_kernel_irqchip;
27 extern bool kvm_async_interrupts_allowed;
28 extern bool kvm_irqfds_allowed;
29 extern bool kvm_msi_via_irqfd_allowed;
30
31 #if defined CONFIG_KVM || !defined NEED_CPU_H
32 #define kvm_enabled() (kvm_allowed)
33 #define kvm_irqchip_in_kernel() (kvm_kernel_irqchip)
34
35 /**
36 * kvm_async_interrupts_enabled:
37 *
38 * Returns: true if we can deliver interrupts to KVM
39 * asynchronously (ie by ioctl from any thread at any time)
40 * rather than having to do interrupt delivery synchronously
41 * (where the vcpu must be stopped at a suitable point first).
42 */
43 #define kvm_async_interrupts_enabled() (kvm_async_interrupts_allowed)
44
45 /**
46 * kvm_irqfds_enabled:
47 *
48 * Returns: true if we can use irqfds to inject interrupts into
49 * a KVM CPU (ie the kernel supports irqfds and we are running
50 * with a configuration where it is meaningful to use them).
51 */
52 #define kvm_irqfds_enabled() (kvm_irqfds_allowed)
53
54 /**
55 * kvm_msi_via_irqfd_enabled:
56 *
57 * Returns: true if we can route a PCI MSI (Message Signaled Interrupt)
58 * to a KVM CPU via an irqfd. This requires that the kernel supports
59 * this and that we're running in a configuration that permits it.
60 */
61 #define kvm_msi_via_irqfd_enabled() (kvm_msi_via_irqfd_allowed)
62
63 #else
64 #define kvm_enabled() (0)
65 #define kvm_irqchip_in_kernel() (false)
66 #define kvm_async_interrupts_enabled() (false)
67 #define kvm_irqfds_enabled() (false)
68 #define kvm_msi_via_irqfd_enabled() (false)
69 #endif
70
71 struct kvm_run;
72 struct kvm_lapic_state;
73
74 typedef struct KVMCapabilityInfo {
75 const char *name;
76 int value;
77 } KVMCapabilityInfo;
78
79 #define KVM_CAP_INFO(CAP) { "KVM_CAP_" stringify(CAP), KVM_CAP_##CAP }
80 #define KVM_CAP_LAST_INFO { NULL, 0 }
81
82 struct KVMState;
83 typedef struct KVMState KVMState;
84 extern KVMState *kvm_state;
85
86 /* external API */
87
88 int kvm_init(void);
89
90 int kvm_has_sync_mmu(void);
91 int kvm_has_vcpu_events(void);
92 int kvm_has_robust_singlestep(void);
93 int kvm_has_debugregs(void);
94 int kvm_has_xsave(void);
95 int kvm_has_xcrs(void);
96 int kvm_has_pit_state2(void);
97 int kvm_has_many_ioeventfds(void);
98 int kvm_has_gsi_routing(void);
99
100 #ifdef NEED_CPU_H
101 int kvm_init_vcpu(CPUArchState *env);
102
103 int kvm_cpu_exec(CPUArchState *env);
104
105 #if !defined(CONFIG_USER_ONLY)
106 void *kvm_vmalloc(ram_addr_t size);
107 void *kvm_arch_vmalloc(ram_addr_t size);
108 void kvm_setup_guest_memory(void *start, size_t size);
109
110 int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);
111 int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);
112 void kvm_flush_coalesced_mmio_buffer(void);
113 #endif
114
115 int kvm_insert_breakpoint(CPUArchState *current_env, target_ulong addr,
116 target_ulong len, int type);
117 int kvm_remove_breakpoint(CPUArchState *current_env, target_ulong addr,
118 target_ulong len, int type);
119 void kvm_remove_all_breakpoints(CPUArchState *current_env);
120 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
121 #ifndef _WIN32
122 int kvm_set_signal_mask(CPUArchState *env, const sigset_t *sigset);
123 #endif
124
125 int kvm_on_sigbus_vcpu(CPUArchState *env, int code, void *addr);
126 int kvm_on_sigbus(int code, void *addr);
127
128 /* internal API */
129
130 int kvm_ioctl(KVMState *s, int type, ...);
131
132 int kvm_vm_ioctl(KVMState *s, int type, ...);
133
134 int kvm_vcpu_ioctl(CPUArchState *env, int type, ...);
135
136 /* Arch specific hooks */
137
138 extern const KVMCapabilityInfo kvm_arch_required_capabilities[];
139
140 void kvm_arch_pre_run(CPUArchState *env, struct kvm_run *run);
141 void kvm_arch_post_run(CPUArchState *env, struct kvm_run *run);
142
143 int kvm_arch_handle_exit(CPUArchState *env, struct kvm_run *run);
144
145 int kvm_arch_process_async_events(CPUArchState *env);
146
147 int kvm_arch_get_registers(CPUArchState *env);
148
149 /* state subset only touched by the VCPU itself during runtime */
150 #define KVM_PUT_RUNTIME_STATE 1
151 /* state subset modified during VCPU reset */
152 #define KVM_PUT_RESET_STATE 2
153 /* full state set, modified during initialization or on vmload */
154 #define KVM_PUT_FULL_STATE 3
155
156 int kvm_arch_put_registers(CPUArchState *env, int level);
157
158 int kvm_arch_init(KVMState *s);
159
160 int kvm_arch_init_vcpu(CPUArchState *env);
161
162 void kvm_arch_reset_vcpu(CPUArchState *env);
163
164 int kvm_arch_on_sigbus_vcpu(CPUArchState *env, int code, void *addr);
165 int kvm_arch_on_sigbus(int code, void *addr);
166
167 void kvm_arch_init_irq_routing(KVMState *s);
168
169 int kvm_set_irq(KVMState *s, int irq, int level);
170 int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg);
171
172 void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin);
173
174 void kvm_put_apic_state(DeviceState *d, struct kvm_lapic_state *kapic);
175 void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic);
176
177 struct kvm_guest_debug;
178 struct kvm_debug_exit_arch;
179
180 struct kvm_sw_breakpoint {
181 target_ulong pc;
182 target_ulong saved_insn;
183 int use_count;
184 QTAILQ_ENTRY(kvm_sw_breakpoint) entry;
185 };
186
187 QTAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint);
188
189 struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUArchState *env,
190 target_ulong pc);
191
192 int kvm_sw_breakpoints_active(CPUArchState *env);
193
194 int kvm_arch_insert_sw_breakpoint(CPUArchState *current_env,
195 struct kvm_sw_breakpoint *bp);
196 int kvm_arch_remove_sw_breakpoint(CPUArchState *current_env,
197 struct kvm_sw_breakpoint *bp);
198 int kvm_arch_insert_hw_breakpoint(target_ulong addr,
199 target_ulong len, int type);
200 int kvm_arch_remove_hw_breakpoint(target_ulong addr,
201 target_ulong len, int type);
202 void kvm_arch_remove_all_hw_breakpoints(void);
203
204 void kvm_arch_update_guest_debug(CPUArchState *env, struct kvm_guest_debug *dbg);
205
206 bool kvm_arch_stop_on_emulation_error(CPUArchState *env);
207
208 int kvm_check_extension(KVMState *s, unsigned int extension);
209
210 uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
211 uint32_t index, int reg);
212 void kvm_cpu_synchronize_state(CPUArchState *env);
213 void kvm_cpu_synchronize_post_reset(CPUArchState *env);
214 void kvm_cpu_synchronize_post_init(CPUArchState *env);
215
216 /* generic hooks - to be moved/refactored once there are more users */
217
218 static inline void cpu_synchronize_state(CPUArchState *env)
219 {
220 if (kvm_enabled()) {
221 kvm_cpu_synchronize_state(env);
222 }
223 }
224
225 static inline void cpu_synchronize_post_reset(CPUArchState *env)
226 {
227 if (kvm_enabled()) {
228 kvm_cpu_synchronize_post_reset(env);
229 }
230 }
231
232 static inline void cpu_synchronize_post_init(CPUArchState *env)
233 {
234 if (kvm_enabled()) {
235 kvm_cpu_synchronize_post_init(env);
236 }
237 }
238
239
240 #if !defined(CONFIG_USER_ONLY)
241 int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
242 target_phys_addr_t *phys_addr);
243 #endif
244
245 #endif
246 int kvm_set_ioeventfd_mmio(int fd, uint32_t adr, uint32_t val, bool assign,
247 uint32_t size);
248
249 int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign);
250
251 int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg);
252 void kvm_irqchip_release_virq(KVMState *s, int virq);
253
254 int kvm_irqchip_add_irqfd(KVMState *s, int fd, int virq);
255 int kvm_irqchip_remove_irqfd(KVMState *s, int fd, int virq);
256 int kvm_irqchip_add_irq_notifier(KVMState *s, EventNotifier *n, int virq);
257 int kvm_irqchip_remove_irq_notifier(KVMState *s, EventNotifier *n, int virq);
258 #endif