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 | ||
6fc138d2 IE |
26 | /* for KVM_SET_USER_MEMORY_REGION */ |
27 | struct kvm_userspace_memory_region { | |
28 | __u32 slot; | |
29 | __u32 flags; | |
30 | __u64 guest_phys_addr; | |
31 | __u64 memory_size; /* bytes */ | |
32 | __u64 userspace_addr; /* start of the userspace allocated memory */ | |
33 | }; | |
34 | ||
6aa8b732 AK |
35 | /* for kvm_memory_region::flags */ |
36 | #define KVM_MEM_LOG_DIRTY_PAGES 1UL | |
37 | ||
e8207547 AK |
38 | struct kvm_memory_alias { |
39 | __u32 slot; /* this has a different namespace than memory slots */ | |
40 | __u32 flags; | |
41 | __u64 guest_phys_addr; | |
42 | __u64 memory_size; | |
43 | __u64 target_phys_addr; | |
44 | }; | |
6aa8b732 | 45 | |
97222cc8 | 46 | /* for KVM_IRQ_LINE */ |
85f455f7 ED |
47 | struct kvm_irq_level { |
48 | /* | |
49 | * ACPI gsi notion of irq. | |
50 | * For IA-64 (APIC model) IOAPIC0: irq 0-23; IOAPIC1: irq 24-47.. | |
51 | * For X86 (standard AT mode) PIC0/1: irq 0-15. IOAPIC0: 0-23.. | |
52 | */ | |
53 | __u32 irq; | |
54 | __u32 level; | |
55 | }; | |
56 | ||
6bf9e962 | 57 | /* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */ |
6ceb9d79 HQ |
58 | struct kvm_pic_state { |
59 | __u8 last_irr; /* edge detection */ | |
60 | __u8 irr; /* interrupt request register */ | |
61 | __u8 imr; /* interrupt mask register */ | |
62 | __u8 isr; /* interrupt service register */ | |
63 | __u8 priority_add; /* highest irq priority */ | |
64 | __u8 irq_base; | |
65 | __u8 read_reg_select; | |
66 | __u8 poll; | |
67 | __u8 special_mask; | |
68 | __u8 init_state; | |
69 | __u8 auto_eoi; | |
70 | __u8 rotate_on_auto_eoi; | |
71 | __u8 special_fully_nested_mode; | |
72 | __u8 init4; /* true if 4 byte init */ | |
73 | __u8 elcr; /* PIIX edge/trigger selection */ | |
74 | __u8 elcr_mask; | |
75 | }; | |
76 | ||
6bf9e962 HQ |
77 | #define KVM_IOAPIC_NUM_PINS 24 |
78 | struct kvm_ioapic_state { | |
79 | __u64 base_address; | |
80 | __u32 ioregsel; | |
81 | __u32 id; | |
82 | __u32 irr; | |
83 | __u32 pad; | |
84 | union { | |
85 | __u64 bits; | |
86 | struct { | |
87 | __u8 vector; | |
88 | __u8 delivery_mode:3; | |
89 | __u8 dest_mode:1; | |
90 | __u8 delivery_status:1; | |
91 | __u8 polarity:1; | |
92 | __u8 remote_irr:1; | |
93 | __u8 trig_mode:1; | |
94 | __u8 mask:1; | |
95 | __u8 reserve:7; | |
96 | __u8 reserved[4]; | |
97 | __u8 dest_id; | |
98 | } fields; | |
99 | } redirtbl[KVM_IOAPIC_NUM_PINS]; | |
100 | }; | |
101 | ||
8a45450d AK |
102 | #define KVM_IRQCHIP_PIC_MASTER 0 |
103 | #define KVM_IRQCHIP_PIC_SLAVE 1 | |
104 | #define KVM_IRQCHIP_IOAPIC 2 | |
6ceb9d79 HQ |
105 | |
106 | struct kvm_irqchip { | |
107 | __u32 chip_id; | |
108 | __u32 pad; | |
109 | union { | |
110 | char dummy[512]; /* reserving space */ | |
111 | struct kvm_pic_state pic; | |
6bf9e962 | 112 | struct kvm_ioapic_state ioapic; |
6ceb9d79 HQ |
113 | } chip; |
114 | }; | |
115 | ||
8a45450d AK |
116 | #define KVM_EXIT_UNKNOWN 0 |
117 | #define KVM_EXIT_EXCEPTION 1 | |
118 | #define KVM_EXIT_IO 2 | |
119 | #define KVM_EXIT_HYPERCALL 3 | |
120 | #define KVM_EXIT_DEBUG 4 | |
121 | #define KVM_EXIT_HLT 5 | |
122 | #define KVM_EXIT_MMIO 6 | |
123 | #define KVM_EXIT_IRQ_WINDOW_OPEN 7 | |
124 | #define KVM_EXIT_SHUTDOWN 8 | |
125 | #define KVM_EXIT_FAIL_ENTRY 9 | |
126 | #define KVM_EXIT_INTR 10 | |
127 | #define KVM_EXIT_SET_TPR 11 | |
6aa8b732 | 128 | |
9a2bb7f4 | 129 | /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */ |
6aa8b732 AK |
130 | struct kvm_run { |
131 | /* in */ | |
c1150d8c | 132 | __u8 request_interrupt_window; |
02c83209 | 133 | __u8 padding1[7]; |
6aa8b732 AK |
134 | |
135 | /* out */ | |
6aa8b732 | 136 | __u32 exit_reason; |
c1150d8c DL |
137 | __u8 ready_for_interrupt_injection; |
138 | __u8 if_flag; | |
2ff81f70 | 139 | __u8 padding2[2]; |
54810342 DL |
140 | |
141 | /* in (pre_kvm_run), out (post_kvm_run) */ | |
c1150d8c DL |
142 | __u64 cr8; |
143 | __u64 apic_base; | |
144 | ||
6aa8b732 AK |
145 | union { |
146 | /* KVM_EXIT_UNKNOWN */ | |
147 | struct { | |
8eb7d334 | 148 | __u64 hardware_exit_reason; |
6aa8b732 | 149 | } hw; |
8eb7d334 AK |
150 | /* KVM_EXIT_FAIL_ENTRY */ |
151 | struct { | |
152 | __u64 hardware_entry_failure_reason; | |
153 | } fail_entry; | |
6aa8b732 AK |
154 | /* KVM_EXIT_EXCEPTION */ |
155 | struct { | |
156 | __u32 exception; | |
157 | __u32 error_code; | |
158 | } ex; | |
159 | /* KVM_EXIT_IO */ | |
46fc1477 | 160 | struct kvm_io { |
6aa8b732 AK |
161 | #define KVM_EXIT_IO_IN 0 |
162 | #define KVM_EXIT_IO_OUT 1 | |
163 | __u8 direction; | |
164 | __u8 size; /* bytes */ | |
6aa8b732 | 165 | __u16 port; |
039576c0 AK |
166 | __u32 count; |
167 | __u64 data_offset; /* relative to kvm_run start */ | |
6aa8b732 AK |
168 | } io; |
169 | struct { | |
170 | } debug; | |
171 | /* KVM_EXIT_MMIO */ | |
172 | struct { | |
173 | __u64 phys_addr; | |
174 | __u8 data[8]; | |
175 | __u32 len; | |
176 | __u8 is_write; | |
177 | } mmio; | |
b4e63f56 AK |
178 | /* KVM_EXIT_HYPERCALL */ |
179 | struct { | |
519ef353 | 180 | __u64 nr; |
b4e63f56 AK |
181 | __u64 args[6]; |
182 | __u64 ret; | |
183 | __u32 longmode; | |
184 | __u32 pad; | |
185 | } hypercall; | |
24cbc7e9 AK |
186 | /* Fix the size of the union. */ |
187 | char padding[256]; | |
6aa8b732 AK |
188 | }; |
189 | }; | |
190 | ||
191 | /* for KVM_GET_REGS and KVM_SET_REGS */ | |
192 | struct kvm_regs { | |
6aa8b732 AK |
193 | /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ |
194 | __u64 rax, rbx, rcx, rdx; | |
195 | __u64 rsi, rdi, rsp, rbp; | |
196 | __u64 r8, r9, r10, r11; | |
197 | __u64 r12, r13, r14, r15; | |
198 | __u64 rip, rflags; | |
199 | }; | |
200 | ||
b8836737 AK |
201 | /* for KVM_GET_FPU and KVM_SET_FPU */ |
202 | struct kvm_fpu { | |
203 | __u8 fpr[8][16]; | |
204 | __u16 fcw; | |
205 | __u16 fsw; | |
206 | __u8 ftwx; /* in fxsave format */ | |
207 | __u8 pad1; | |
208 | __u16 last_opcode; | |
209 | __u64 last_ip; | |
210 | __u64 last_dp; | |
211 | __u8 xmm[16][16]; | |
212 | __u32 mxcsr; | |
213 | __u32 pad2; | |
214 | }; | |
215 | ||
96ad2cc6 ED |
216 | /* for KVM_GET_LAPIC and KVM_SET_LAPIC */ |
217 | #define KVM_APIC_REG_SIZE 0x400 | |
218 | struct kvm_lapic_state { | |
219 | char regs[KVM_APIC_REG_SIZE]; | |
220 | }; | |
221 | ||
6aa8b732 AK |
222 | struct kvm_segment { |
223 | __u64 base; | |
224 | __u32 limit; | |
225 | __u16 selector; | |
226 | __u8 type; | |
227 | __u8 present, dpl, db, s, l, g, avl; | |
228 | __u8 unusable; | |
229 | __u8 padding; | |
230 | }; | |
231 | ||
232 | struct kvm_dtable { | |
233 | __u64 base; | |
234 | __u16 limit; | |
235 | __u16 padding[3]; | |
236 | }; | |
237 | ||
238 | /* for KVM_GET_SREGS and KVM_SET_SREGS */ | |
239 | struct kvm_sregs { | |
6aa8b732 AK |
240 | /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */ |
241 | struct kvm_segment cs, ds, es, fs, gs, ss; | |
242 | struct kvm_segment tr, ldt; | |
243 | struct kvm_dtable gdt, idt; | |
244 | __u64 cr0, cr2, cr3, cr4, cr8; | |
245 | __u64 efer; | |
246 | __u64 apic_base; | |
9eb829ce | 247 | __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64]; |
6aa8b732 AK |
248 | }; |
249 | ||
250 | struct kvm_msr_entry { | |
251 | __u32 index; | |
252 | __u32 reserved; | |
253 | __u64 data; | |
254 | }; | |
255 | ||
256 | /* for KVM_GET_MSRS and KVM_SET_MSRS */ | |
257 | struct kvm_msrs { | |
6aa8b732 | 258 | __u32 nmsrs; /* number of msrs in entries */ |
bccf2150 | 259 | __u32 pad; |
6aa8b732 AK |
260 | |
261 | struct kvm_msr_entry entries[0]; | |
262 | }; | |
263 | ||
264 | /* for KVM_GET_MSR_INDEX_LIST */ | |
265 | struct kvm_msr_list { | |
266 | __u32 nmsrs; /* number of msrs in entries */ | |
267 | __u32 indices[0]; | |
268 | }; | |
269 | ||
270 | /* for KVM_TRANSLATE */ | |
271 | struct kvm_translation { | |
272 | /* in */ | |
273 | __u64 linear_address; | |
6aa8b732 AK |
274 | |
275 | /* out */ | |
276 | __u64 physical_address; | |
277 | __u8 valid; | |
278 | __u8 writeable; | |
279 | __u8 usermode; | |
8cd13307 | 280 | __u8 pad[5]; |
6aa8b732 AK |
281 | }; |
282 | ||
283 | /* for KVM_INTERRUPT */ | |
284 | struct kvm_interrupt { | |
285 | /* in */ | |
6aa8b732 AK |
286 | __u32 irq; |
287 | }; | |
288 | ||
289 | struct kvm_breakpoint { | |
290 | __u32 enabled; | |
291 | __u32 padding; | |
292 | __u64 address; | |
293 | }; | |
294 | ||
295 | /* for KVM_DEBUG_GUEST */ | |
296 | struct kvm_debug_guest { | |
297 | /* int */ | |
6aa8b732 | 298 | __u32 enabled; |
bccf2150 | 299 | __u32 pad; |
6aa8b732 AK |
300 | struct kvm_breakpoint breakpoints[4]; |
301 | __u32 singlestep; | |
302 | }; | |
303 | ||
304 | /* for KVM_GET_DIRTY_LOG */ | |
305 | struct kvm_dirty_log { | |
306 | __u32 slot; | |
307 | __u32 padding; | |
308 | union { | |
309 | void __user *dirty_bitmap; /* one bit per page */ | |
310 | __u64 padding; | |
311 | }; | |
312 | }; | |
313 | ||
06465c5a AK |
314 | struct kvm_cpuid_entry { |
315 | __u32 function; | |
316 | __u32 eax; | |
317 | __u32 ebx; | |
318 | __u32 ecx; | |
319 | __u32 edx; | |
320 | __u32 padding; | |
321 | }; | |
322 | ||
323 | /* for KVM_SET_CPUID */ | |
324 | struct kvm_cpuid { | |
325 | __u32 nent; | |
326 | __u32 padding; | |
327 | struct kvm_cpuid_entry entries[0]; | |
328 | }; | |
329 | ||
1961d276 AK |
330 | /* for KVM_SET_SIGNAL_MASK */ |
331 | struct kvm_signal_mask { | |
332 | __u32 len; | |
333 | __u8 sigset[0]; | |
334 | }; | |
335 | ||
6aa8b732 AK |
336 | #define KVMIO 0xAE |
337 | ||
f17abe9a AK |
338 | /* |
339 | * ioctls for /dev/kvm fds: | |
340 | */ | |
739872c5 AK |
341 | #define KVM_GET_API_VERSION _IO(KVMIO, 0x00) |
342 | #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */ | |
343 | #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list) | |
5d308f45 AK |
344 | /* |
345 | * Check if a kvm extension is available. Argument is extension number, | |
346 | * return is 1 (yes) or 0 (no, sorry). | |
347 | */ | |
348 | #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03) | |
07c45a36 AK |
349 | /* |
350 | * Get size for mmap(vcpu_fd) | |
351 | */ | |
352 | #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */ | |
f17abe9a | 353 | |
85f455f7 ED |
354 | /* |
355 | * Extension capability list. | |
356 | */ | |
357 | #define KVM_CAP_IRQCHIP 0 | |
b6958ce4 | 358 | #define KVM_CAP_HLT 1 |
82ce2c96 | 359 | #define KVM_CAP_MMU_SHADOW_CACHE_CONTROL 2 |
6fc138d2 | 360 | #define KVM_CAP_USER_MEMORY 3 |
cbc94022 | 361 | #define KVM_CAP_SET_TSS_ADDR 4 |
85f455f7 | 362 | |
f17abe9a AK |
363 | /* |
364 | * ioctls for VM fds | |
365 | */ | |
739872c5 | 366 | #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region) |
82ce2c96 IE |
367 | #define KVM_SET_NR_MMU_PAGES _IO(KVMIO, 0x44) |
368 | #define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45) | |
6fc138d2 IE |
369 | #define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46,\ |
370 | struct kvm_userspace_memory_region) | |
cbc94022 | 371 | #define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47) |
bccf2150 AK |
372 | /* |
373 | * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns | |
374 | * a vcpu fd. | |
375 | */ | |
739872c5 AK |
376 | #define KVM_CREATE_VCPU _IO(KVMIO, 0x41) |
377 | #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log) | |
e8207547 | 378 | #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias) |
85f455f7 ED |
379 | /* Device model IOC */ |
380 | #define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60) | |
97222cc8 | 381 | #define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level) |
6ceb9d79 HQ |
382 | #define KVM_GET_IRQCHIP _IOWR(KVMIO, 0x62, struct kvm_irqchip) |
383 | #define KVM_SET_IRQCHIP _IOR(KVMIO, 0x63, struct kvm_irqchip) | |
bccf2150 AK |
384 | |
385 | /* | |
386 | * ioctls for vcpu fds | |
387 | */ | |
739872c5 AK |
388 | #define KVM_RUN _IO(KVMIO, 0x80) |
389 | #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs) | |
390 | #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs) | |
391 | #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs) | |
392 | #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs) | |
393 | #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation) | |
394 | #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt) | |
395 | #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest) | |
396 | #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs) | |
397 | #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs) | |
398 | #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid) | |
1961d276 | 399 | #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask) |
b8836737 AK |
400 | #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu) |
401 | #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu) | |
96ad2cc6 ED |
402 | #define KVM_GET_LAPIC _IOR(KVMIO, 0x8e, struct kvm_lapic_state) |
403 | #define KVM_SET_LAPIC _IOW(KVMIO, 0x8f, struct kvm_lapic_state) | |
6aa8b732 AK |
404 | |
405 | #endif |