blob: de9f28d96ced301e8094c3572660ef957db73c76 [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>
Jerone Youngf6a40e32007-11-19 17:06:31 -060012#include <asm/kvm.h>
Avi Kivity6aa8b732006-12-10 02:21:36 -080013
Avi Kivity2ff81f72007-04-29 16:25:49 +030014#define KVM_API_VERSION 12
Avi Kivity0b76e202006-12-22 01:06:02 -080015
Avi Kivity6aa8b732006-12-10 02:21:36 -080016/* for KVM_CREATE_MEMORY_REGION */
17struct kvm_memory_region {
18 __u32 slot;
19 __u32 flags;
20 __u64 guest_phys_addr;
21 __u64 memory_size; /* bytes */
22};
23
Izik Eidus6fc138d2007-10-09 19:20:39 +020024/* for KVM_SET_USER_MEMORY_REGION */
25struct kvm_userspace_memory_region {
26 __u32 slot;
27 __u32 flags;
28 __u64 guest_phys_addr;
29 __u64 memory_size; /* bytes */
30 __u64 userspace_addr; /* start of the userspace allocated memory */
31};
32
Avi Kivity6aa8b732006-12-10 02:21:36 -080033/* for kvm_memory_region::flags */
34#define KVM_MEM_LOG_DIRTY_PAGES 1UL
35
36
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, Qing6ceb9d72007-07-26 11:05:18 +030048
49struct kvm_irqchip {
50 __u32 chip_id;
51 __u32 pad;
52 union {
53 char dummy[512]; /* reserving space */
Jerone Young51e29622007-11-26 08:33:53 -060054#ifdef CONFIG_X86
He, Qing6ceb9d72007-07-26 11:05:18 +030055 struct kvm_pic_state pic;
Zhang Xiantaoec10f472007-12-17 20:27:27 +080056#endif
57#if defined(CONFIG_X86) || defined(CONFIG_IA64)
He, Qing6bf9e962007-08-05 10:49:16 +030058 struct kvm_ioapic_state ioapic;
Jerone Young51e29622007-11-26 08:33:53 -060059#endif
He, Qing6ceb9d72007-07-26 11:05:18 +030060 } chip;
61};
62
Avi Kivity8a454502007-10-10 14:03:16 +020063#define KVM_EXIT_UNKNOWN 0
64#define KVM_EXIT_EXCEPTION 1
65#define KVM_EXIT_IO 2
66#define KVM_EXIT_HYPERCALL 3
67#define KVM_EXIT_DEBUG 4
68#define KVM_EXIT_HLT 5
69#define KVM_EXIT_MMIO 6
70#define KVM_EXIT_IRQ_WINDOW_OPEN 7
71#define KVM_EXIT_SHUTDOWN 8
72#define KVM_EXIT_FAIL_ENTRY 9
73#define KVM_EXIT_INTR 10
74#define KVM_EXIT_SET_TPR 11
Avi Kivity6aa8b732006-12-10 02:21:36 -080075
Avi Kivity9a2bb7f2007-02-22 12:58:31 +020076/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
Avi Kivity6aa8b732006-12-10 02:21:36 -080077struct kvm_run {
78 /* in */
Dor Laorc1150d82007-01-05 16:36:24 -080079 __u8 request_interrupt_window;
Avi Kivity02c83202007-04-29 15:02:17 +030080 __u8 padding1[7];
Avi Kivity6aa8b732006-12-10 02:21:36 -080081
82 /* out */
Avi Kivity6aa8b732006-12-10 02:21:36 -080083 __u32 exit_reason;
Dor Laorc1150d82007-01-05 16:36:24 -080084 __u8 ready_for_interrupt_injection;
85 __u8 if_flag;
Avi Kivity2ff81f72007-04-29 16:25:49 +030086 __u8 padding2[2];
Dor Laor54810342007-02-12 00:54:39 -080087
88 /* in (pre_kvm_run), out (post_kvm_run) */
Dor Laorc1150d82007-01-05 16:36:24 -080089 __u64 cr8;
90 __u64 apic_base;
91
Avi Kivity6aa8b732006-12-10 02:21:36 -080092 union {
93 /* KVM_EXIT_UNKNOWN */
94 struct {
Avi Kivity8eb7d332007-03-04 14:17:08 +020095 __u64 hardware_exit_reason;
Avi Kivity6aa8b732006-12-10 02:21:36 -080096 } hw;
Avi Kivity8eb7d332007-03-04 14:17:08 +020097 /* KVM_EXIT_FAIL_ENTRY */
98 struct {
99 __u64 hardware_entry_failure_reason;
100 } fail_entry;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800101 /* KVM_EXIT_EXCEPTION */
102 struct {
103 __u32 exception;
104 __u32 error_code;
105 } ex;
106 /* KVM_EXIT_IO */
Avi Kivity46fc1472007-02-22 19:39:30 +0200107 struct kvm_io {
Avi Kivity6aa8b732006-12-10 02:21:36 -0800108#define KVM_EXIT_IO_IN 0
109#define KVM_EXIT_IO_OUT 1
110 __u8 direction;
111 __u8 size; /* bytes */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800112 __u16 port;
Avi Kivity039576c2007-03-20 12:46:50 +0200113 __u32 count;
114 __u64 data_offset; /* relative to kvm_run start */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800115 } io;
116 struct {
117 } debug;
118 /* KVM_EXIT_MMIO */
119 struct {
120 __u64 phys_addr;
121 __u8 data[8];
122 __u32 len;
123 __u8 is_write;
124 } mmio;
Avi Kivityb4e63f52007-03-04 13:59:30 +0200125 /* KVM_EXIT_HYPERCALL */
126 struct {
Jeff Dike519ef352007-07-16 15:24:47 -0400127 __u64 nr;
Avi Kivityb4e63f52007-03-04 13:59:30 +0200128 __u64 args[6];
129 __u64 ret;
130 __u32 longmode;
131 __u32 pad;
132 } hypercall;
Avi Kivity24cbc7e2007-07-17 11:45:55 +0300133 /* Fix the size of the union. */
134 char padding[256];
Avi Kivity6aa8b732006-12-10 02:21:36 -0800135 };
136};
137
Avi Kivity6aa8b732006-12-10 02:21:36 -0800138
Avi Kivityb8836732007-04-01 16:34:31 +0300139/* for KVM_GET_FPU and KVM_SET_FPU */
140struct kvm_fpu {
141 __u8 fpr[8][16];
142 __u16 fcw;
143 __u16 fsw;
144 __u8 ftwx; /* in fxsave format */
145 __u8 pad1;
146 __u16 last_opcode;
147 __u64 last_ip;
148 __u64 last_dp;
149 __u8 xmm[16][16];
150 __u32 mxcsr;
151 __u32 pad2;
152};
153
Eddie Dong96ad2cc2007-09-06 12:22:56 +0300154
Avi Kivity6aa8b732006-12-10 02:21:36 -0800155/* for KVM_TRANSLATE */
156struct kvm_translation {
157 /* in */
158 __u64 linear_address;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800159
160 /* out */
161 __u64 physical_address;
162 __u8 valid;
163 __u8 writeable;
164 __u8 usermode;
Avi Kivity8cd13302007-02-12 00:54:41 -0800165 __u8 pad[5];
Avi Kivity6aa8b732006-12-10 02:21:36 -0800166};
167
168/* for KVM_INTERRUPT */
169struct kvm_interrupt {
170 /* in */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800171 __u32 irq;
172};
173
174struct kvm_breakpoint {
175 __u32 enabled;
176 __u32 padding;
177 __u64 address;
178};
179
180/* for KVM_DEBUG_GUEST */
181struct kvm_debug_guest {
182 /* int */
Avi Kivity6aa8b732006-12-10 02:21:36 -0800183 __u32 enabled;
Avi Kivitybccf2152007-02-21 18:04:26 +0200184 __u32 pad;
Avi Kivity6aa8b732006-12-10 02:21:36 -0800185 struct kvm_breakpoint breakpoints[4];
186 __u32 singlestep;
187};
188
189/* for KVM_GET_DIRTY_LOG */
190struct kvm_dirty_log {
191 __u32 slot;
192 __u32 padding;
193 union {
194 void __user *dirty_bitmap; /* one bit per page */
195 __u64 padding;
196 };
197};
198
Avi Kivity1961d272007-03-05 19:46:05 +0200199/* for KVM_SET_SIGNAL_MASK */
200struct kvm_signal_mask {
201 __u32 len;
202 __u8 sigset[0];
203};
204
Avi Kivity6aa8b732006-12-10 02:21:36 -0800205#define KVMIO 0xAE
206
Avi Kivityf17abe92007-02-21 19:28:04 +0200207/*
208 * ioctls for /dev/kvm fds:
209 */
Avi Kivity739872c2007-03-01 17:20:13 +0200210#define KVM_GET_API_VERSION _IO(KVMIO, 0x00)
211#define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */
212#define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)
Avi Kivity5d308f42007-03-01 17:56:20 +0200213/*
214 * Check if a kvm extension is available. Argument is extension number,
215 * return is 1 (yes) or 0 (no, sorry).
216 */
217#define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
Avi Kivity07c45a32007-03-07 13:05:38 +0200218/*
219 * Get size for mmap(vcpu_fd)
220 */
221#define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */
Avi Kivityf17abe92007-02-21 19:28:04 +0200222
223/*
Eddie Dong85f455f2007-07-06 12:20:49 +0300224 * Extension capability list.
225 */
226#define KVM_CAP_IRQCHIP 0
Eddie Dongb6958ce2007-07-18 12:15:21 +0300227#define KVM_CAP_HLT 1
Izik Eidus82ce2c92007-10-02 18:52:55 +0200228#define KVM_CAP_MMU_SHADOW_CACHE_CONTROL 2
Izik Eidus6fc138d2007-10-09 19:20:39 +0200229#define KVM_CAP_USER_MEMORY 3
Izik Eiduscbc94022007-10-25 00:29:55 +0200230#define KVM_CAP_SET_TSS_ADDR 4
Dan Kenigsberg07716712007-11-21 17:10:04 +0200231#define KVM_CAP_EXT_CPUID 5
Eddie Dong85f455f2007-07-06 12:20:49 +0300232
233/*
Avi Kivityf17abe92007-02-21 19:28:04 +0200234 * ioctls for VM fds
235 */
Avi Kivity739872c2007-03-01 17:20:13 +0200236#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
Izik Eidus82ce2c92007-10-02 18:52:55 +0200237#define KVM_SET_NR_MMU_PAGES _IO(KVMIO, 0x44)
238#define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45)
Izik Eidus6fc138d2007-10-09 19:20:39 +0200239#define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46,\
240 struct kvm_userspace_memory_region)
Izik Eiduscbc94022007-10-25 00:29:55 +0200241#define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47)
Avi Kivitybccf2152007-02-21 18:04:26 +0200242/*
243 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
244 * a vcpu fd.
245 */
Avi Kivity739872c2007-03-01 17:20:13 +0200246#define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
247#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
Avi Kivitye8207542007-03-30 16:54:30 +0300248#define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
Dan Kenigsberg07716712007-11-21 17:10:04 +0200249#define KVM_GET_SUPPORTED_CPUID _IOWR(KVMIO, 0x48, struct kvm_cpuid2)
Eddie Dong85f455f2007-07-06 12:20:49 +0300250/* Device model IOC */
251#define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60)
Eddie Dong97222cc2007-09-12 10:58:04 +0300252#define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level)
He, Qing6ceb9d72007-07-26 11:05:18 +0300253#define KVM_GET_IRQCHIP _IOWR(KVMIO, 0x62, struct kvm_irqchip)
254#define KVM_SET_IRQCHIP _IOR(KVMIO, 0x63, struct kvm_irqchip)
Avi Kivitybccf2152007-02-21 18:04:26 +0200255
256/*
257 * ioctls for vcpu fds
258 */
Avi Kivity739872c2007-03-01 17:20:13 +0200259#define KVM_RUN _IO(KVMIO, 0x80)
260#define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
261#define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs)
262#define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs)
263#define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
264#define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
265#define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
266#define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest)
267#define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
268#define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
269#define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
Avi Kivity1961d272007-03-05 19:46:05 +0200270#define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)
Avi Kivityb8836732007-04-01 16:34:31 +0300271#define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu)
272#define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)
Eddie Dong96ad2cc2007-09-06 12:22:56 +0300273#define KVM_GET_LAPIC _IOR(KVMIO, 0x8e, struct kvm_lapic_state)
274#define KVM_SET_LAPIC _IOW(KVMIO, 0x8f, struct kvm_lapic_state)
Dan Kenigsberg07716712007-11-21 17:10:04 +0200275#define KVM_SET_CPUID2 _IOW(KVMIO, 0x90, struct kvm_cpuid2)
276#define KVM_GET_CPUID2 _IOWR(KVMIO, 0x91, struct kvm_cpuid2)
Avi Kivity6aa8b732006-12-10 02:21:36 -0800277
278#endif