blob: 057a7f34ee36b2aec3fdfad395b0f7c4323796ec [file] [log] [blame]
Avi Kivity6aa8b732006-12-10 02:21:36 -08001#ifndef __LINUX_KVM_H
2#define __LINUX_KVM_H
3
4/*
5 * Userspace interface for /dev/kvm - kernel based virtual machine
6 *
Rusty Russelldea8cae2007-07-17 23:12:26 +10007 * Note: you must update KVM_API_VERSION if you change this interface.
Avi Kivity6aa8b732006-12-10 02:21:36 -08008 */
9
10#include <asm/types.h>
11#include <linux/ioctl.h>
12
Avi Kivity2ff81f72007-04-29 16:25:49 +030013#define KVM_API_VERSION 12
Avi Kivity0b76e202006-12-22 01:06:02 -080014
Rusty Russell9eb829c2007-07-18 13:05:58 +100015/* Architectural interrupt line count. */
Avi Kivity6aa8b732006-12-10 02:21:36 -080016#define KVM_NR_INTERRUPTS 256
Avi Kivity6aa8b732006-12-10 02:21:36 -080017
18/* for KVM_CREATE_MEMORY_REGION */
19struct 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
Avi Kivitye8207542007-03-30 16:54:30 +030029struct 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};
Avi Kivity6aa8b732006-12-10 02:21:36 -080036
Eddie Dong97222cc2007-09-12 10:58:04 +030037/* for KVM_IRQ_LINE */
Eddie Dong85f455f2007-07-06 12:20:49 +030038struct 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
He, Qing6bf9e962007-08-05 10:49:16 +030048/* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */
He, Qing6ceb9d72007-07-26 11:05:18 +030049struct kvm_pic_state {
50 __u8 last_irr; /* edge detection */
51 __u8 irr; /* interrupt request register */
52 __u8 imr; /* interrupt mask register */
53 __u8 isr; /* interrupt service register */
54 __u8 priority_add; /* highest irq priority */
55 __u8 irq_base;
56 __u8 read_reg_select;
57 __u8 poll;
58 __u8 special_mask;
59 __u8 init_state;
60 __u8 auto_eoi;
61 __u8 rotate_on_auto_eoi;
62 __u8 special_fully_nested_mode;
63 __u8 init4; /* true if 4 byte init */
64 __u8 elcr; /* PIIX edge/trigger selection */
65 __u8 elcr_mask;
66};
67
He, Qing6bf9e962007-08-05 10:49:16 +030068#define KVM_IOAPIC_NUM_PINS 24
69struct kvm_ioapic_state {
70 __u64 base_address;
71 __u32 ioregsel;
72 __u32 id;
73 __u32 irr;
74 __u32 pad;
75 union {
76 __u64 bits;
77 struct {
78 __u8 vector;
79 __u8 delivery_mode:3;
80 __u8 dest_mode:1;
81 __u8 delivery_status:1;
82 __u8 polarity:1;
83 __u8 remote_irr:1;
84 __u8 trig_mode:1;
85 __u8 mask:1;
86 __u8 reserve:7;
87 __u8 reserved[4];
88 __u8 dest_id;
89 } fields;
90 } redirtbl[KVM_IOAPIC_NUM_PINS];
91};
92
Avi Kivity8a454502007-10-10 14:03:16 +020093#define KVM_IRQCHIP_PIC_MASTER 0
94#define KVM_IRQCHIP_PIC_SLAVE 1
95#define KVM_IRQCHIP_IOAPIC 2
He, Qing6ceb9d72007-07-26 11:05:18 +030096
97struct kvm_irqchip {
98 __u32 chip_id;
99 __u32 pad;
100 union {
101 char dummy[512]; /* reserving space */
102 struct kvm_pic_state pic;
He, Qing6bf9e962007-08-05 10:49:16 +0300103 struct kvm_ioapic_state ioapic;
He, Qing6ceb9d72007-07-26 11:05:18 +0300104 } chip;
105};
106
Avi Kivity8a454502007-10-10 14:03:16 +0200107#define KVM_EXIT_UNKNOWN 0
108#define KVM_EXIT_EXCEPTION 1
109#define KVM_EXIT_IO 2
110#define KVM_EXIT_HYPERCALL 3
111#define KVM_EXIT_DEBUG 4
112#define KVM_EXIT_HLT 5
113#define KVM_EXIT_MMIO 6
114#define KVM_EXIT_IRQ_WINDOW_OPEN 7
115#define KVM_EXIT_SHUTDOWN 8
116#define KVM_EXIT_FAIL_ENTRY 9
117#define KVM_EXIT_INTR 10
118#define KVM_EXIT_SET_TPR 11
Avi Kivity6aa8b732006-12-10 02:21:36 -0800119
Avi Kivity9a2bb7f2007-02-22 12:58:31 +0200120/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800121struct kvm_run {
122 /* in */
Dor Laorc1150d82007-01-05 16:36:24 -0800123 __u8 request_interrupt_window;
Avi Kivity02c83202007-04-29 15:02:17 +0300124 __u8 padding1[7];
Avi Kivity6aa8b732006-12-10 02:21:36 -0800125
126 /* out */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800127 __u32 exit_reason;
Dor Laorc1150d82007-01-05 16:36:24 -0800128 __u8 ready_for_interrupt_injection;
129 __u8 if_flag;
Avi Kivity2ff81f72007-04-29 16:25:49 +0300130 __u8 padding2[2];
Dor Laor54810342007-02-12 00:54:39 -0800131
132 /* in (pre_kvm_run), out (post_kvm_run) */
Dor Laorc1150d82007-01-05 16:36:24 -0800133 __u64 cr8;
134 __u64 apic_base;
135
Avi Kivity6aa8b732006-12-10 02:21:36 -0800136 union {
137 /* KVM_EXIT_UNKNOWN */
138 struct {
Avi Kivity8eb7d332007-03-04 14:17:08 +0200139 __u64 hardware_exit_reason;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800140 } hw;
Avi Kivity8eb7d332007-03-04 14:17:08 +0200141 /* KVM_EXIT_FAIL_ENTRY */
142 struct {
143 __u64 hardware_entry_failure_reason;
144 } fail_entry;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800145 /* KVM_EXIT_EXCEPTION */
146 struct {
147 __u32 exception;
148 __u32 error_code;
149 } ex;
150 /* KVM_EXIT_IO */
Avi Kivity46fc1472007-02-22 19:39:30 +0200151 struct kvm_io {
Avi Kivity6aa8b732006-12-10 02:21:36 -0800152#define KVM_EXIT_IO_IN 0
153#define KVM_EXIT_IO_OUT 1
154 __u8 direction;
155 __u8 size; /* bytes */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800156 __u16 port;
Avi Kivity039576c2007-03-20 12:46:50 +0200157 __u32 count;
158 __u64 data_offset; /* relative to kvm_run start */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800159 } io;
160 struct {
161 } debug;
162 /* KVM_EXIT_MMIO */
163 struct {
164 __u64 phys_addr;
165 __u8 data[8];
166 __u32 len;
167 __u8 is_write;
168 } mmio;
Avi Kivityb4e63f52007-03-04 13:59:30 +0200169 /* KVM_EXIT_HYPERCALL */
170 struct {
Jeff Dike519ef352007-07-16 15:24:47 -0400171 __u64 nr;
Avi Kivityb4e63f52007-03-04 13:59:30 +0200172 __u64 args[6];
173 __u64 ret;
174 __u32 longmode;
175 __u32 pad;
176 } hypercall;
Avi Kivity24cbc7e2007-07-17 11:45:55 +0300177 /* Fix the size of the union. */
178 char padding[256];
Avi Kivity6aa8b732006-12-10 02:21:36 -0800179 };
180};
181
182/* for KVM_GET_REGS and KVM_SET_REGS */
183struct kvm_regs {
Avi Kivity6aa8b732006-12-10 02:21:36 -0800184 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
185 __u64 rax, rbx, rcx, rdx;
186 __u64 rsi, rdi, rsp, rbp;
187 __u64 r8, r9, r10, r11;
188 __u64 r12, r13, r14, r15;
189 __u64 rip, rflags;
190};
191
Avi Kivityb8836732007-04-01 16:34:31 +0300192/* for KVM_GET_FPU and KVM_SET_FPU */
193struct kvm_fpu {
194 __u8 fpr[8][16];
195 __u16 fcw;
196 __u16 fsw;
197 __u8 ftwx; /* in fxsave format */
198 __u8 pad1;
199 __u16 last_opcode;
200 __u64 last_ip;
201 __u64 last_dp;
202 __u8 xmm[16][16];
203 __u32 mxcsr;
204 __u32 pad2;
205};
206
Eddie Dong96ad2cc2007-09-06 12:22:56 +0300207/* for KVM_GET_LAPIC and KVM_SET_LAPIC */
208#define KVM_APIC_REG_SIZE 0x400
209struct kvm_lapic_state {
210 char regs[KVM_APIC_REG_SIZE];
211};
212
Avi Kivity6aa8b732006-12-10 02:21:36 -0800213struct kvm_segment {
214 __u64 base;
215 __u32 limit;
216 __u16 selector;
217 __u8 type;
218 __u8 present, dpl, db, s, l, g, avl;
219 __u8 unusable;
220 __u8 padding;
221};
222
223struct kvm_dtable {
224 __u64 base;
225 __u16 limit;
226 __u16 padding[3];
227};
228
229/* for KVM_GET_SREGS and KVM_SET_SREGS */
230struct kvm_sregs {
Avi Kivity6aa8b732006-12-10 02:21:36 -0800231 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
232 struct kvm_segment cs, ds, es, fs, gs, ss;
233 struct kvm_segment tr, ldt;
234 struct kvm_dtable gdt, idt;
235 __u64 cr0, cr2, cr3, cr4, cr8;
236 __u64 efer;
237 __u64 apic_base;
Rusty Russell9eb829c2007-07-18 13:05:58 +1000238 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
Avi Kivity6aa8b732006-12-10 02:21:36 -0800239};
240
241struct kvm_msr_entry {
242 __u32 index;
243 __u32 reserved;
244 __u64 data;
245};
246
247/* for KVM_GET_MSRS and KVM_SET_MSRS */
248struct kvm_msrs {
Avi Kivity6aa8b732006-12-10 02:21:36 -0800249 __u32 nmsrs; /* number of msrs in entries */
Avi Kivitybccf2152007-02-21 18:04:26 +0200250 __u32 pad;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800251
252 struct kvm_msr_entry entries[0];
253};
254
255/* for KVM_GET_MSR_INDEX_LIST */
256struct kvm_msr_list {
257 __u32 nmsrs; /* number of msrs in entries */
258 __u32 indices[0];
259};
260
261/* for KVM_TRANSLATE */
262struct kvm_translation {
263 /* in */
264 __u64 linear_address;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800265
266 /* out */
267 __u64 physical_address;
268 __u8 valid;
269 __u8 writeable;
270 __u8 usermode;
Avi Kivity8cd13302007-02-12 00:54:41 -0800271 __u8 pad[5];
Avi Kivity6aa8b732006-12-10 02:21:36 -0800272};
273
274/* for KVM_INTERRUPT */
275struct kvm_interrupt {
276 /* in */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800277 __u32 irq;
278};
279
280struct kvm_breakpoint {
281 __u32 enabled;
282 __u32 padding;
283 __u64 address;
284};
285
286/* for KVM_DEBUG_GUEST */
287struct kvm_debug_guest {
288 /* int */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800289 __u32 enabled;
Avi Kivitybccf2152007-02-21 18:04:26 +0200290 __u32 pad;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800291 struct kvm_breakpoint breakpoints[4];
292 __u32 singlestep;
293};
294
295/* for KVM_GET_DIRTY_LOG */
296struct kvm_dirty_log {
297 __u32 slot;
298 __u32 padding;
299 union {
300 void __user *dirty_bitmap; /* one bit per page */
301 __u64 padding;
302 };
303};
304
Avi Kivity06465c52007-02-28 20:46:53 +0200305struct kvm_cpuid_entry {
306 __u32 function;
307 __u32 eax;
308 __u32 ebx;
309 __u32 ecx;
310 __u32 edx;
311 __u32 padding;
312};
313
314/* for KVM_SET_CPUID */
315struct kvm_cpuid {
316 __u32 nent;
317 __u32 padding;
318 struct kvm_cpuid_entry entries[0];
319};
320
Avi Kivity1961d272007-03-05 19:46:05 +0200321/* for KVM_SET_SIGNAL_MASK */
322struct kvm_signal_mask {
323 __u32 len;
324 __u8 sigset[0];
325};
326
Avi Kivity6aa8b732006-12-10 02:21:36 -0800327#define KVMIO 0xAE
328
Avi Kivityf17abe92007-02-21 19:28:04 +0200329/*
330 * ioctls for /dev/kvm fds:
331 */
Avi Kivity739872c2007-03-01 17:20:13 +0200332#define KVM_GET_API_VERSION _IO(KVMIO, 0x00)
333#define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */
334#define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)
Avi Kivity5d308f42007-03-01 17:56:20 +0200335/*
336 * Check if a kvm extension is available. Argument is extension number,
337 * return is 1 (yes) or 0 (no, sorry).
338 */
339#define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
Avi Kivity07c45a32007-03-07 13:05:38 +0200340/*
341 * Get size for mmap(vcpu_fd)
342 */
343#define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */
Avi Kivityf17abe92007-02-21 19:28:04 +0200344
345/*
Eddie Dong85f455f2007-07-06 12:20:49 +0300346 * Extension capability list.
347 */
348#define KVM_CAP_IRQCHIP 0
Eddie Dongb6958ce2007-07-18 12:15:21 +0300349#define KVM_CAP_HLT 1
Eddie Dong85f455f2007-07-06 12:20:49 +0300350
351/*
Avi Kivityf17abe92007-02-21 19:28:04 +0200352 * ioctls for VM fds
353 */
Avi Kivity739872c2007-03-01 17:20:13 +0200354#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
Avi Kivitybccf2152007-02-21 18:04:26 +0200355/*
356 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
357 * a vcpu fd.
358 */
Avi Kivity739872c2007-03-01 17:20:13 +0200359#define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
360#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
Avi Kivitye8207542007-03-30 16:54:30 +0300361#define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
Eddie Dong85f455f2007-07-06 12:20:49 +0300362/* Device model IOC */
363#define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60)
Eddie Dong97222cc2007-09-12 10:58:04 +0300364#define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level)
He, Qing6ceb9d72007-07-26 11:05:18 +0300365#define KVM_GET_IRQCHIP _IOWR(KVMIO, 0x62, struct kvm_irqchip)
366#define KVM_SET_IRQCHIP _IOR(KVMIO, 0x63, struct kvm_irqchip)
Avi Kivitybccf2152007-02-21 18:04:26 +0200367
368/*
369 * ioctls for vcpu fds
370 */
Avi Kivity739872c2007-03-01 17:20:13 +0200371#define KVM_RUN _IO(KVMIO, 0x80)
372#define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
373#define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs)
374#define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs)
375#define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
376#define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
377#define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
378#define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest)
379#define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
380#define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
381#define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
Avi Kivity1961d272007-03-05 19:46:05 +0200382#define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)
Avi Kivityb8836732007-04-01 16:34:31 +0300383#define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu)
384#define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)
Eddie Dong96ad2cc2007-09-06 12:22:56 +0300385#define KVM_GET_LAPIC _IOR(KVMIO, 0x8e, struct kvm_lapic_state)
386#define KVM_SET_LAPIC _IOW(KVMIO, 0x8f, struct kvm_lapic_state)
Avi Kivity6aa8b732006-12-10 02:21:36 -0800387
388#endif