Commit | Line | Data |
---|---|---|
6aa8b732 AK |
1 | #ifndef __LINUX_KVM_H |
2 | #define __LINUX_KVM_H | |
3 | ||
4 | /* | |
5 | * Userspace interface for /dev/kvm - kernel based virtual machine | |
6 | * | |
dea8caee | 7 | * Note: you must update KVM_API_VERSION if you change this interface. |
6aa8b732 AK |
8 | */ |
9 | ||
10 | #include <asm/types.h> | |
11 | #include <linux/ioctl.h> | |
12 | ||
2ff81f70 | 13 | #define KVM_API_VERSION 12 |
0b76e20b | 14 | |
9eb829ce | 15 | /* Architectural interrupt line count. */ |
6aa8b732 | 16 | #define KVM_NR_INTERRUPTS 256 |
6aa8b732 AK |
17 | |
18 | /* for KVM_CREATE_MEMORY_REGION */ | |
19 | struct kvm_memory_region { | |
20 | __u32 slot; | |
21 | __u32 flags; | |
22 | __u64 guest_phys_addr; | |
23 | __u64 memory_size; /* bytes */ | |
24 | }; | |
25 | ||
26 | /* for kvm_memory_region::flags */ | |
27 | #define KVM_MEM_LOG_DIRTY_PAGES 1UL | |
28 | ||
e8207547 AK |
29 | struct kvm_memory_alias { |
30 | __u32 slot; /* this has a different namespace than memory slots */ | |
31 | __u32 flags; | |
32 | __u64 guest_phys_addr; | |
33 | __u64 memory_size; | |
34 | __u64 target_phys_addr; | |
35 | }; | |
6aa8b732 | 36 | |
97222cc8 | 37 | /* for KVM_IRQ_LINE */ |
85f455f7 ED |
38 | struct kvm_irq_level { |
39 | /* | |
40 | * ACPI gsi notion of irq. | |
41 | * For IA-64 (APIC model) IOAPIC0: irq 0-23; IOAPIC1: irq 24-47.. | |
42 | * For X86 (standard AT mode) PIC0/1: irq 0-15. IOAPIC0: 0-23.. | |
43 | */ | |
44 | __u32 irq; | |
45 | __u32 level; | |
46 | }; | |
47 | ||
6aa8b732 AK |
48 | enum kvm_exit_reason { |
49 | KVM_EXIT_UNKNOWN = 0, | |
50 | KVM_EXIT_EXCEPTION = 1, | |
51 | KVM_EXIT_IO = 2, | |
b4e63f56 | 52 | KVM_EXIT_HYPERCALL = 3, |
6aa8b732 AK |
53 | KVM_EXIT_DEBUG = 4, |
54 | KVM_EXIT_HLT = 5, | |
55 | KVM_EXIT_MMIO = 6, | |
c1150d8c | 56 | KVM_EXIT_IRQ_WINDOW_OPEN = 7, |
46fe4ddd | 57 | KVM_EXIT_SHUTDOWN = 8, |
8eb7d334 | 58 | KVM_EXIT_FAIL_ENTRY = 9, |
1b19f3e6 | 59 | KVM_EXIT_INTR = 10, |
253abdee | 60 | KVM_EXIT_SET_TPR = 11 |
6aa8b732 AK |
61 | }; |
62 | ||
9a2bb7f4 | 63 | /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */ |
6aa8b732 AK |
64 | struct kvm_run { |
65 | /* in */ | |
c1150d8c | 66 | __u8 request_interrupt_window; |
02c83209 | 67 | __u8 padding1[7]; |
6aa8b732 AK |
68 | |
69 | /* out */ | |
6aa8b732 | 70 | __u32 exit_reason; |
c1150d8c DL |
71 | __u8 ready_for_interrupt_injection; |
72 | __u8 if_flag; | |
2ff81f70 | 73 | __u8 padding2[2]; |
54810342 DL |
74 | |
75 | /* in (pre_kvm_run), out (post_kvm_run) */ | |
c1150d8c DL |
76 | __u64 cr8; |
77 | __u64 apic_base; | |
78 | ||
6aa8b732 AK |
79 | union { |
80 | /* KVM_EXIT_UNKNOWN */ | |
81 | struct { | |
8eb7d334 | 82 | __u64 hardware_exit_reason; |
6aa8b732 | 83 | } hw; |
8eb7d334 AK |
84 | /* KVM_EXIT_FAIL_ENTRY */ |
85 | struct { | |
86 | __u64 hardware_entry_failure_reason; | |
87 | } fail_entry; | |
6aa8b732 AK |
88 | /* KVM_EXIT_EXCEPTION */ |
89 | struct { | |
90 | __u32 exception; | |
91 | __u32 error_code; | |
92 | } ex; | |
93 | /* KVM_EXIT_IO */ | |
46fc1477 | 94 | struct kvm_io { |
6aa8b732 AK |
95 | #define KVM_EXIT_IO_IN 0 |
96 | #define KVM_EXIT_IO_OUT 1 | |
97 | __u8 direction; | |
98 | __u8 size; /* bytes */ | |
6aa8b732 | 99 | __u16 port; |
039576c0 AK |
100 | __u32 count; |
101 | __u64 data_offset; /* relative to kvm_run start */ | |
6aa8b732 AK |
102 | } io; |
103 | struct { | |
104 | } debug; | |
105 | /* KVM_EXIT_MMIO */ | |
106 | struct { | |
107 | __u64 phys_addr; | |
108 | __u8 data[8]; | |
109 | __u32 len; | |
110 | __u8 is_write; | |
111 | } mmio; | |
b4e63f56 AK |
112 | /* KVM_EXIT_HYPERCALL */ |
113 | struct { | |
519ef353 | 114 | __u64 nr; |
b4e63f56 AK |
115 | __u64 args[6]; |
116 | __u64 ret; | |
117 | __u32 longmode; | |
118 | __u32 pad; | |
119 | } hypercall; | |
24cbc7e9 AK |
120 | /* Fix the size of the union. */ |
121 | char padding[256]; | |
6aa8b732 AK |
122 | }; |
123 | }; | |
124 | ||
125 | /* for KVM_GET_REGS and KVM_SET_REGS */ | |
126 | struct kvm_regs { | |
6aa8b732 AK |
127 | /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ |
128 | __u64 rax, rbx, rcx, rdx; | |
129 | __u64 rsi, rdi, rsp, rbp; | |
130 | __u64 r8, r9, r10, r11; | |
131 | __u64 r12, r13, r14, r15; | |
132 | __u64 rip, rflags; | |
133 | }; | |
134 | ||
b8836737 AK |
135 | /* for KVM_GET_FPU and KVM_SET_FPU */ |
136 | struct kvm_fpu { | |
137 | __u8 fpr[8][16]; | |
138 | __u16 fcw; | |
139 | __u16 fsw; | |
140 | __u8 ftwx; /* in fxsave format */ | |
141 | __u8 pad1; | |
142 | __u16 last_opcode; | |
143 | __u64 last_ip; | |
144 | __u64 last_dp; | |
145 | __u8 xmm[16][16]; | |
146 | __u32 mxcsr; | |
147 | __u32 pad2; | |
148 | }; | |
149 | ||
6aa8b732 AK |
150 | struct kvm_segment { |
151 | __u64 base; | |
152 | __u32 limit; | |
153 | __u16 selector; | |
154 | __u8 type; | |
155 | __u8 present, dpl, db, s, l, g, avl; | |
156 | __u8 unusable; | |
157 | __u8 padding; | |
158 | }; | |
159 | ||
160 | struct kvm_dtable { | |
161 | __u64 base; | |
162 | __u16 limit; | |
163 | __u16 padding[3]; | |
164 | }; | |
165 | ||
166 | /* for KVM_GET_SREGS and KVM_SET_SREGS */ | |
167 | struct kvm_sregs { | |
6aa8b732 AK |
168 | /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */ |
169 | struct kvm_segment cs, ds, es, fs, gs, ss; | |
170 | struct kvm_segment tr, ldt; | |
171 | struct kvm_dtable gdt, idt; | |
172 | __u64 cr0, cr2, cr3, cr4, cr8; | |
173 | __u64 efer; | |
174 | __u64 apic_base; | |
9eb829ce | 175 | __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64]; |
6aa8b732 AK |
176 | }; |
177 | ||
178 | struct kvm_msr_entry { | |
179 | __u32 index; | |
180 | __u32 reserved; | |
181 | __u64 data; | |
182 | }; | |
183 | ||
184 | /* for KVM_GET_MSRS and KVM_SET_MSRS */ | |
185 | struct kvm_msrs { | |
6aa8b732 | 186 | __u32 nmsrs; /* number of msrs in entries */ |
bccf2150 | 187 | __u32 pad; |
6aa8b732 AK |
188 | |
189 | struct kvm_msr_entry entries[0]; | |
190 | }; | |
191 | ||
192 | /* for KVM_GET_MSR_INDEX_LIST */ | |
193 | struct kvm_msr_list { | |
194 | __u32 nmsrs; /* number of msrs in entries */ | |
195 | __u32 indices[0]; | |
196 | }; | |
197 | ||
198 | /* for KVM_TRANSLATE */ | |
199 | struct kvm_translation { | |
200 | /* in */ | |
201 | __u64 linear_address; | |
6aa8b732 AK |
202 | |
203 | /* out */ | |
204 | __u64 physical_address; | |
205 | __u8 valid; | |
206 | __u8 writeable; | |
207 | __u8 usermode; | |
8cd13307 | 208 | __u8 pad[5]; |
6aa8b732 AK |
209 | }; |
210 | ||
211 | /* for KVM_INTERRUPT */ | |
212 | struct kvm_interrupt { | |
213 | /* in */ | |
6aa8b732 AK |
214 | __u32 irq; |
215 | }; | |
216 | ||
217 | struct kvm_breakpoint { | |
218 | __u32 enabled; | |
219 | __u32 padding; | |
220 | __u64 address; | |
221 | }; | |
222 | ||
223 | /* for KVM_DEBUG_GUEST */ | |
224 | struct kvm_debug_guest { | |
225 | /* int */ | |
6aa8b732 | 226 | __u32 enabled; |
bccf2150 | 227 | __u32 pad; |
6aa8b732 AK |
228 | struct kvm_breakpoint breakpoints[4]; |
229 | __u32 singlestep; | |
230 | }; | |
231 | ||
232 | /* for KVM_GET_DIRTY_LOG */ | |
233 | struct kvm_dirty_log { | |
234 | __u32 slot; | |
235 | __u32 padding; | |
236 | union { | |
237 | void __user *dirty_bitmap; /* one bit per page */ | |
238 | __u64 padding; | |
239 | }; | |
240 | }; | |
241 | ||
06465c5a AK |
242 | struct kvm_cpuid_entry { |
243 | __u32 function; | |
244 | __u32 eax; | |
245 | __u32 ebx; | |
246 | __u32 ecx; | |
247 | __u32 edx; | |
248 | __u32 padding; | |
249 | }; | |
250 | ||
251 | /* for KVM_SET_CPUID */ | |
252 | struct kvm_cpuid { | |
253 | __u32 nent; | |
254 | __u32 padding; | |
255 | struct kvm_cpuid_entry entries[0]; | |
256 | }; | |
257 | ||
1961d276 AK |
258 | /* for KVM_SET_SIGNAL_MASK */ |
259 | struct kvm_signal_mask { | |
260 | __u32 len; | |
261 | __u8 sigset[0]; | |
262 | }; | |
263 | ||
6aa8b732 AK |
264 | #define KVMIO 0xAE |
265 | ||
f17abe9a AK |
266 | /* |
267 | * ioctls for /dev/kvm fds: | |
268 | */ | |
739872c5 AK |
269 | #define KVM_GET_API_VERSION _IO(KVMIO, 0x00) |
270 | #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */ | |
271 | #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list) | |
5d308f45 AK |
272 | /* |
273 | * Check if a kvm extension is available. Argument is extension number, | |
274 | * return is 1 (yes) or 0 (no, sorry). | |
275 | */ | |
276 | #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03) | |
07c45a36 AK |
277 | /* |
278 | * Get size for mmap(vcpu_fd) | |
279 | */ | |
280 | #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */ | |
f17abe9a | 281 | |
85f455f7 ED |
282 | /* |
283 | * Extension capability list. | |
284 | */ | |
285 | #define KVM_CAP_IRQCHIP 0 | |
b6958ce4 | 286 | #define KVM_CAP_HLT 1 |
85f455f7 | 287 | |
f17abe9a AK |
288 | /* |
289 | * ioctls for VM fds | |
290 | */ | |
739872c5 | 291 | #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region) |
bccf2150 AK |
292 | /* |
293 | * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns | |
294 | * a vcpu fd. | |
295 | */ | |
739872c5 AK |
296 | #define KVM_CREATE_VCPU _IO(KVMIO, 0x41) |
297 | #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log) | |
e8207547 | 298 | #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias) |
85f455f7 ED |
299 | /* Device model IOC */ |
300 | #define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60) | |
97222cc8 | 301 | #define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level) |
bccf2150 AK |
302 | |
303 | /* | |
304 | * ioctls for vcpu fds | |
305 | */ | |
739872c5 AK |
306 | #define KVM_RUN _IO(KVMIO, 0x80) |
307 | #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs) | |
308 | #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs) | |
309 | #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs) | |
310 | #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs) | |
311 | #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation) | |
312 | #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt) | |
313 | #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest) | |
314 | #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs) | |
315 | #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs) | |
316 | #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid) | |
1961d276 | 317 | #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask) |
b8836737 AK |
318 | #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu) |
319 | #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu) | |
6aa8b732 AK |
320 | |
321 | #endif |