blob: f3604593fb76ded7fe359da2eea2e2ee640bd5b5 [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 *
7 * Note: this interface is considered experimental and may change without
8 * notice.
9 */
10
11#include <asm/types.h>
12#include <linux/ioctl.h>
13
Avi Kivity8cd13302007-02-12 00:54:41 -080014#define KVM_API_VERSION 3
Avi Kivity0b76e202006-12-22 01:06:02 -080015
Avi Kivity6aa8b732006-12-10 02:21:36 -080016/*
17 * Architectural interrupt line count, and the size of the bitmap needed
18 * to hold them.
19 */
20#define KVM_NR_INTERRUPTS 256
21#define KVM_IRQ_BITMAP_SIZE_BYTES ((KVM_NR_INTERRUPTS + 7) / 8)
22#define KVM_IRQ_BITMAP_SIZE(type) (KVM_IRQ_BITMAP_SIZE_BYTES / sizeof(type))
23
24
25/* for KVM_CREATE_MEMORY_REGION */
26struct kvm_memory_region {
27 __u32 slot;
28 __u32 flags;
29 __u64 guest_phys_addr;
30 __u64 memory_size; /* bytes */
31};
32
33/* for kvm_memory_region::flags */
34#define KVM_MEM_LOG_DIRTY_PAGES 1UL
35
36
37#define KVM_EXIT_TYPE_FAIL_ENTRY 1
38#define KVM_EXIT_TYPE_VM_EXIT 2
39
40enum kvm_exit_reason {
41 KVM_EXIT_UNKNOWN = 0,
42 KVM_EXIT_EXCEPTION = 1,
43 KVM_EXIT_IO = 2,
44 KVM_EXIT_CPUID = 3,
45 KVM_EXIT_DEBUG = 4,
46 KVM_EXIT_HLT = 5,
47 KVM_EXIT_MMIO = 6,
Dor Laorc1150d82007-01-05 16:36:24 -080048 KVM_EXIT_IRQ_WINDOW_OPEN = 7,
Joerg Roedel46fe4dd2007-01-26 00:56:42 -080049 KVM_EXIT_SHUTDOWN = 8,
Avi Kivity6aa8b732006-12-10 02:21:36 -080050};
51
52/* for KVM_RUN */
53struct kvm_run {
54 /* in */
55 __u32 vcpu;
56 __u32 emulated; /* skip current instruction */
57 __u32 mmio_completed; /* mmio request completed */
Dor Laorc1150d82007-01-05 16:36:24 -080058 __u8 request_interrupt_window;
59 __u8 padding1[3];
Avi Kivity6aa8b732006-12-10 02:21:36 -080060
61 /* out */
62 __u32 exit_type;
63 __u32 exit_reason;
64 __u32 instruction_length;
Dor Laorc1150d82007-01-05 16:36:24 -080065 __u8 ready_for_interrupt_injection;
66 __u8 if_flag;
67 __u16 padding2;
Dor Laor54810342007-02-12 00:54:39 -080068
69 /* in (pre_kvm_run), out (post_kvm_run) */
Dor Laorc1150d82007-01-05 16:36:24 -080070 __u64 cr8;
71 __u64 apic_base;
72
Avi Kivity6aa8b732006-12-10 02:21:36 -080073 union {
74 /* KVM_EXIT_UNKNOWN */
75 struct {
76 __u32 hardware_exit_reason;
77 } hw;
78 /* KVM_EXIT_EXCEPTION */
79 struct {
80 __u32 exception;
81 __u32 error_code;
82 } ex;
83 /* KVM_EXIT_IO */
84 struct {
85#define KVM_EXIT_IO_IN 0
86#define KVM_EXIT_IO_OUT 1
87 __u8 direction;
88 __u8 size; /* bytes */
89 __u8 string;
90 __u8 string_down;
91 __u8 rep;
92 __u8 pad;
93 __u16 port;
94 __u64 count;
95 union {
96 __u64 address;
97 __u32 value;
98 };
99 } io;
100 struct {
101 } debug;
102 /* KVM_EXIT_MMIO */
103 struct {
104 __u64 phys_addr;
105 __u8 data[8];
106 __u32 len;
107 __u8 is_write;
108 } mmio;
109 };
110};
111
112/* for KVM_GET_REGS and KVM_SET_REGS */
113struct kvm_regs {
114 /* in */
115 __u32 vcpu;
116 __u32 padding;
117
118 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
119 __u64 rax, rbx, rcx, rdx;
120 __u64 rsi, rdi, rsp, rbp;
121 __u64 r8, r9, r10, r11;
122 __u64 r12, r13, r14, r15;
123 __u64 rip, rflags;
124};
125
126struct kvm_segment {
127 __u64 base;
128 __u32 limit;
129 __u16 selector;
130 __u8 type;
131 __u8 present, dpl, db, s, l, g, avl;
132 __u8 unusable;
133 __u8 padding;
134};
135
136struct kvm_dtable {
137 __u64 base;
138 __u16 limit;
139 __u16 padding[3];
140};
141
142/* for KVM_GET_SREGS and KVM_SET_SREGS */
143struct kvm_sregs {
144 /* in */
145 __u32 vcpu;
146 __u32 padding;
147
148 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
149 struct kvm_segment cs, ds, es, fs, gs, ss;
150 struct kvm_segment tr, ldt;
151 struct kvm_dtable gdt, idt;
152 __u64 cr0, cr2, cr3, cr4, cr8;
153 __u64 efer;
154 __u64 apic_base;
155 __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)];
156};
157
158struct kvm_msr_entry {
159 __u32 index;
160 __u32 reserved;
161 __u64 data;
162};
163
164/* for KVM_GET_MSRS and KVM_SET_MSRS */
165struct kvm_msrs {
166 __u32 vcpu;
167 __u32 nmsrs; /* number of msrs in entries */
168
169 struct kvm_msr_entry entries[0];
170};
171
172/* for KVM_GET_MSR_INDEX_LIST */
173struct kvm_msr_list {
174 __u32 nmsrs; /* number of msrs in entries */
175 __u32 indices[0];
176};
177
178/* for KVM_TRANSLATE */
179struct kvm_translation {
180 /* in */
181 __u64 linear_address;
182 __u32 vcpu;
183 __u32 padding;
184
185 /* out */
186 __u64 physical_address;
187 __u8 valid;
188 __u8 writeable;
189 __u8 usermode;
Avi Kivity8cd13302007-02-12 00:54:41 -0800190 __u8 pad[5];
Avi Kivity6aa8b732006-12-10 02:21:36 -0800191};
192
193/* for KVM_INTERRUPT */
194struct kvm_interrupt {
195 /* in */
196 __u32 vcpu;
197 __u32 irq;
198};
199
200struct kvm_breakpoint {
201 __u32 enabled;
202 __u32 padding;
203 __u64 address;
204};
205
206/* for KVM_DEBUG_GUEST */
207struct kvm_debug_guest {
208 /* int */
209 __u32 vcpu;
210 __u32 enabled;
211 struct kvm_breakpoint breakpoints[4];
212 __u32 singlestep;
213};
214
215/* for KVM_GET_DIRTY_LOG */
216struct kvm_dirty_log {
217 __u32 slot;
218 __u32 padding;
219 union {
220 void __user *dirty_bitmap; /* one bit per page */
221 __u64 padding;
222 };
223};
224
225#define KVMIO 0xAE
226
Avi Kivity0b76e202006-12-22 01:06:02 -0800227#define KVM_GET_API_VERSION _IO(KVMIO, 1)
Avi Kivity6aa8b732006-12-10 02:21:36 -0800228#define KVM_RUN _IOWR(KVMIO, 2, struct kvm_run)
229#define KVM_GET_REGS _IOWR(KVMIO, 3, struct kvm_regs)
230#define KVM_SET_REGS _IOW(KVMIO, 4, struct kvm_regs)
231#define KVM_GET_SREGS _IOWR(KVMIO, 5, struct kvm_sregs)
232#define KVM_SET_SREGS _IOW(KVMIO, 6, struct kvm_sregs)
233#define KVM_TRANSLATE _IOWR(KVMIO, 7, struct kvm_translation)
234#define KVM_INTERRUPT _IOW(KVMIO, 8, struct kvm_interrupt)
235#define KVM_DEBUG_GUEST _IOW(KVMIO, 9, struct kvm_debug_guest)
236#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 10, struct kvm_memory_region)
237#define KVM_CREATE_VCPU _IOW(KVMIO, 11, int /* vcpu_slot */)
238#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 12, struct kvm_dirty_log)
239#define KVM_GET_MSRS _IOWR(KVMIO, 13, struct kvm_msrs)
240#define KVM_SET_MSRS _IOWR(KVMIO, 14, struct kvm_msrs)
241#define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 15, struct kvm_msr_list)
242
243#endif