]>
Commit | Line | Data |
---|---|---|
05330448 AL |
1 | /* |
2 | * QEMU KVM support | |
3 | * | |
4 | * Copyright IBM, Corp. 2008 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <[email protected]> | |
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; |
98c8573e PB |
27 | |
28 | #if defined CONFIG_KVM || !defined NEED_CPU_H | |
3d4b2649 JK |
29 | #define kvm_enabled() (kvm_allowed) |
30 | #define kvm_irqchip_in_kernel() (kvm_kernel_irqchip) | |
05330448 | 31 | #else |
3d4b2649 JK |
32 | #define kvm_enabled() (0) |
33 | #define kvm_irqchip_in_kernel() (false) | |
05330448 AL |
34 | #endif |
35 | ||
36 | struct kvm_run; | |
680c1c6f | 37 | struct kvm_lapic_state; |
05330448 | 38 | |
94a8d39a JK |
39 | typedef struct KVMCapabilityInfo { |
40 | const char *name; | |
41 | int value; | |
42 | } KVMCapabilityInfo; | |
43 | ||
44 | #define KVM_CAP_INFO(CAP) { "KVM_CAP_" stringify(CAP), KVM_CAP_##CAP } | |
45 | #define KVM_CAP_LAST_INFO { NULL, 0 } | |
46 | ||
05330448 AL |
47 | /* external API */ |
48 | ||
cad1e282 | 49 | int kvm_init(void); |
05330448 | 50 | |
00a1555e PB |
51 | int kvm_has_sync_mmu(void); |
52 | int kvm_has_vcpu_events(void); | |
53 | int kvm_has_robust_singlestep(void); | |
ff44f1a3 | 54 | int kvm_has_debugregs(void); |
f1665b21 SY |
55 | int kvm_has_xsave(void); |
56 | int kvm_has_xcrs(void); | |
d2f2b8a7 | 57 | int kvm_has_many_ioeventfds(void); |
84b058d7 | 58 | int kvm_has_gsi_routing(void); |
00a1555e | 59 | |
9b5b76d4 JK |
60 | int kvm_allows_irq0_override(void); |
61 | ||
1c14f162 | 62 | #ifdef NEED_CPU_H |
05330448 AL |
63 | int kvm_init_vcpu(CPUState *env); |
64 | ||
65 | int kvm_cpu_exec(CPUState *env); | |
66 | ||
b3755a91 | 67 | #if !defined(CONFIG_USER_ONLY) |
6f0437e8 JK |
68 | void kvm_setup_guest_memory(void *start, size_t size); |
69 | ||
c227f099 AL |
70 | int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size); |
71 | int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size); | |
62a2744c | 72 | void kvm_flush_coalesced_mmio_buffer(void); |
b3755a91 | 73 | #endif |
f65ed4c1 | 74 | |
e22a25c9 AL |
75 | int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr, |
76 | target_ulong len, int type); | |
77 | int kvm_remove_breakpoint(CPUState *current_env, target_ulong addr, | |
78 | target_ulong len, int type); | |
79 | void kvm_remove_all_breakpoints(CPUState *current_env); | |
80 | int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap); | |
20c20526 | 81 | #ifndef _WIN32 |
cc84de95 | 82 | int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset); |
20c20526 | 83 | #endif |
e22a25c9 | 84 | |
6f725c13 | 85 | int kvm_pit_in_kernel(void); |
6f725c13 | 86 | |
a1b87fe0 JK |
87 | int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr); |
88 | int kvm_on_sigbus(int code, void *addr); | |
89 | ||
05330448 AL |
90 | /* internal API */ |
91 | ||
92 | struct KVMState; | |
93 | typedef struct KVMState KVMState; | |
6a7af8cb | 94 | extern KVMState *kvm_state; |
05330448 | 95 | |
984b5181 | 96 | int kvm_ioctl(KVMState *s, int type, ...); |
05330448 | 97 | |
984b5181 | 98 | int kvm_vm_ioctl(KVMState *s, int type, ...); |
05330448 | 99 | |
984b5181 | 100 | int kvm_vcpu_ioctl(CPUState *env, int type, ...); |
05330448 AL |
101 | |
102 | /* Arch specific hooks */ | |
103 | ||
94a8d39a JK |
104 | extern const KVMCapabilityInfo kvm_arch_required_capabilities[]; |
105 | ||
7a39fe58 JK |
106 | void kvm_arch_pre_run(CPUState *env, struct kvm_run *run); |
107 | void kvm_arch_post_run(CPUState *env, struct kvm_run *run); | |
05330448 AL |
108 | |
109 | int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run); | |
110 | ||
99036865 | 111 | int kvm_arch_process_async_events(CPUState *env); |
0af691d7 | 112 | |
05330448 AL |
113 | int kvm_arch_get_registers(CPUState *env); |
114 | ||
ea375f9a JK |
115 | /* state subset only touched by the VCPU itself during runtime */ |
116 | #define KVM_PUT_RUNTIME_STATE 1 | |
117 | /* state subset modified during VCPU reset */ | |
118 | #define KVM_PUT_RESET_STATE 2 | |
119 | /* full state set, modified during initialization or on vmload */ | |
120 | #define KVM_PUT_FULL_STATE 3 | |
121 | ||
122 | int kvm_arch_put_registers(CPUState *env, int level); | |
05330448 | 123 | |
cad1e282 | 124 | int kvm_arch_init(KVMState *s); |
05330448 AL |
125 | |
126 | int kvm_arch_init_vcpu(CPUState *env); | |
127 | ||
caa5af0f JK |
128 | void kvm_arch_reset_vcpu(CPUState *env); |
129 | ||
a1b87fe0 JK |
130 | int kvm_arch_on_sigbus_vcpu(CPUState *env, int code, void *addr); |
131 | int kvm_arch_on_sigbus(int code, void *addr); | |
c0532a76 | 132 | |
84b058d7 JK |
133 | void kvm_arch_init_irq_routing(KVMState *s); |
134 | ||
135 | int kvm_irqchip_set_irq(KVMState *s, int irq, int level); | |
136 | ||
137 | void kvm_irqchip_add_route(KVMState *s, int gsi, int irqchip, int pin); | |
138 | int kvm_irqchip_commit_routes(KVMState *s); | |
139 | ||
680c1c6f JK |
140 | void kvm_put_apic_state(DeviceState *d, struct kvm_lapic_state *kapic); |
141 | void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic); | |
142 | ||
e22a25c9 AL |
143 | struct kvm_guest_debug; |
144 | struct kvm_debug_exit_arch; | |
145 | ||
146 | struct kvm_sw_breakpoint { | |
147 | target_ulong pc; | |
148 | target_ulong saved_insn; | |
149 | int use_count; | |
72cf2d4f | 150 | QTAILQ_ENTRY(kvm_sw_breakpoint) entry; |
e22a25c9 AL |
151 | }; |
152 | ||
72cf2d4f | 153 | QTAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint); |
e22a25c9 | 154 | |
e22a25c9 AL |
155 | struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env, |
156 | target_ulong pc); | |
157 | ||
158 | int kvm_sw_breakpoints_active(CPUState *env); | |
159 | ||
160 | int kvm_arch_insert_sw_breakpoint(CPUState *current_env, | |
161 | struct kvm_sw_breakpoint *bp); | |
162 | int kvm_arch_remove_sw_breakpoint(CPUState *current_env, | |
163 | struct kvm_sw_breakpoint *bp); | |
164 | int kvm_arch_insert_hw_breakpoint(target_ulong addr, | |
165 | target_ulong len, int type); | |
166 | int kvm_arch_remove_hw_breakpoint(target_ulong addr, | |
167 | target_ulong len, int type); | |
168 | void kvm_arch_remove_all_hw_breakpoints(void); | |
169 | ||
170 | void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg); | |
171 | ||
4513d923 GN |
172 | bool kvm_arch_stop_on_emulation_error(CPUState *env); |
173 | ||
ad7b8b33 AL |
174 | int kvm_check_extension(KVMState *s, unsigned int extension); |
175 | ||
ba9bc59e | 176 | uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, |
c958a8bd | 177 | uint32_t index, int reg); |
4c0960c0 | 178 | void kvm_cpu_synchronize_state(CPUState *env); |
ea375f9a JK |
179 | void kvm_cpu_synchronize_post_reset(CPUState *env); |
180 | void kvm_cpu_synchronize_post_init(CPUState *env); | |
b827df58 | 181 | |
e22a25c9 AL |
182 | /* generic hooks - to be moved/refactored once there are more users */ |
183 | ||
4c0960c0 | 184 | static inline void cpu_synchronize_state(CPUState *env) |
e22a25c9 AL |
185 | { |
186 | if (kvm_enabled()) { | |
4c0960c0 | 187 | kvm_cpu_synchronize_state(env); |
e22a25c9 AL |
188 | } |
189 | } | |
190 | ||
ea375f9a JK |
191 | static inline void cpu_synchronize_post_reset(CPUState *env) |
192 | { | |
193 | if (kvm_enabled()) { | |
194 | kvm_cpu_synchronize_post_reset(env); | |
195 | } | |
196 | } | |
197 | ||
198 | static inline void cpu_synchronize_post_init(CPUState *env) | |
199 | { | |
200 | if (kvm_enabled()) { | |
201 | kvm_cpu_synchronize_post_init(env); | |
202 | } | |
203 | } | |
ca821806 | 204 | |
983dfc3b HY |
205 | |
206 | #if !defined(CONFIG_USER_ONLY) | |
9f213ed9 AK |
207 | int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr, |
208 | target_phys_addr_t *phys_addr); | |
983dfc3b HY |
209 | #endif |
210 | ||
ca821806 | 211 | #endif |
44f1a3d8 | 212 | int kvm_set_ioeventfd_mmio_long(int fd, uint32_t adr, uint32_t val, bool assign); |
ca821806 | 213 | |
98c8573e | 214 | int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign); |
05330448 | 215 | #endif |