KVM: Add method to check for backwards-compatible API extensions
[deliverable/linux.git] / include / linux / kvm.h
CommitLineData
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 *
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
46fc1477 14#define KVM_API_VERSION 6
0b76e20b 15
6aa8b732
AK
16/*
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,
6aa8b732
AK
44 KVM_EXIT_DEBUG = 4,
45 KVM_EXIT_HLT = 5,
46 KVM_EXIT_MMIO = 6,
c1150d8c 47 KVM_EXIT_IRQ_WINDOW_OPEN = 7,
46fe4ddd 48 KVM_EXIT_SHUTDOWN = 8,
6aa8b732
AK
49};
50
9a2bb7f4 51/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
6aa8b732
AK
52struct kvm_run {
53 /* in */
46fc1477 54 __u32 io_completed; /* mmio/pio request completed */
c1150d8c 55 __u8 request_interrupt_window;
106b552b 56 __u8 padding1[3];
6aa8b732
AK
57
58 /* out */
59 __u32 exit_type;
60 __u32 exit_reason;
61 __u32 instruction_length;
c1150d8c
DL
62 __u8 ready_for_interrupt_injection;
63 __u8 if_flag;
64 __u16 padding2;
54810342
DL
65
66 /* in (pre_kvm_run), out (post_kvm_run) */
c1150d8c
DL
67 __u64 cr8;
68 __u64 apic_base;
69
6aa8b732
AK
70 union {
71 /* KVM_EXIT_UNKNOWN */
72 struct {
73 __u32 hardware_exit_reason;
74 } hw;
75 /* KVM_EXIT_EXCEPTION */
76 struct {
77 __u32 exception;
78 __u32 error_code;
79 } ex;
80 /* KVM_EXIT_IO */
46fc1477 81 struct kvm_io {
6aa8b732
AK
82#define KVM_EXIT_IO_IN 0
83#define KVM_EXIT_IO_OUT 1
84 __u8 direction;
85 __u8 size; /* bytes */
86 __u8 string;
87 __u8 string_down;
88 __u8 rep;
89 __u8 pad;
90 __u16 port;
91 __u64 count;
92 union {
93 __u64 address;
94 __u32 value;
95 };
96 } io;
97 struct {
98 } debug;
99 /* KVM_EXIT_MMIO */
100 struct {
101 __u64 phys_addr;
102 __u8 data[8];
103 __u32 len;
104 __u8 is_write;
105 } mmio;
106 };
107};
108
109/* for KVM_GET_REGS and KVM_SET_REGS */
110struct kvm_regs {
6aa8b732
AK
111 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
112 __u64 rax, rbx, rcx, rdx;
113 __u64 rsi, rdi, rsp, rbp;
114 __u64 r8, r9, r10, r11;
115 __u64 r12, r13, r14, r15;
116 __u64 rip, rflags;
117};
118
119struct kvm_segment {
120 __u64 base;
121 __u32 limit;
122 __u16 selector;
123 __u8 type;
124 __u8 present, dpl, db, s, l, g, avl;
125 __u8 unusable;
126 __u8 padding;
127};
128
129struct kvm_dtable {
130 __u64 base;
131 __u16 limit;
132 __u16 padding[3];
133};
134
135/* for KVM_GET_SREGS and KVM_SET_SREGS */
136struct kvm_sregs {
6aa8b732
AK
137 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
138 struct kvm_segment cs, ds, es, fs, gs, ss;
139 struct kvm_segment tr, ldt;
140 struct kvm_dtable gdt, idt;
141 __u64 cr0, cr2, cr3, cr4, cr8;
142 __u64 efer;
143 __u64 apic_base;
144 __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)];
145};
146
147struct kvm_msr_entry {
148 __u32 index;
149 __u32 reserved;
150 __u64 data;
151};
152
153/* for KVM_GET_MSRS and KVM_SET_MSRS */
154struct kvm_msrs {
6aa8b732 155 __u32 nmsrs; /* number of msrs in entries */
bccf2150 156 __u32 pad;
6aa8b732
AK
157
158 struct kvm_msr_entry entries[0];
159};
160
161/* for KVM_GET_MSR_INDEX_LIST */
162struct kvm_msr_list {
163 __u32 nmsrs; /* number of msrs in entries */
164 __u32 indices[0];
165};
166
167/* for KVM_TRANSLATE */
168struct kvm_translation {
169 /* in */
170 __u64 linear_address;
6aa8b732
AK
171
172 /* out */
173 __u64 physical_address;
174 __u8 valid;
175 __u8 writeable;
176 __u8 usermode;
8cd13307 177 __u8 pad[5];
6aa8b732
AK
178};
179
180/* for KVM_INTERRUPT */
181struct kvm_interrupt {
182 /* in */
6aa8b732
AK
183 __u32 irq;
184};
185
186struct kvm_breakpoint {
187 __u32 enabled;
188 __u32 padding;
189 __u64 address;
190};
191
192/* for KVM_DEBUG_GUEST */
193struct kvm_debug_guest {
194 /* int */
6aa8b732 195 __u32 enabled;
bccf2150 196 __u32 pad;
6aa8b732
AK
197 struct kvm_breakpoint breakpoints[4];
198 __u32 singlestep;
199};
200
201/* for KVM_GET_DIRTY_LOG */
202struct kvm_dirty_log {
203 __u32 slot;
204 __u32 padding;
205 union {
206 void __user *dirty_bitmap; /* one bit per page */
207 __u64 padding;
208 };
209};
210
06465c5a
AK
211struct kvm_cpuid_entry {
212 __u32 function;
213 __u32 eax;
214 __u32 ebx;
215 __u32 ecx;
216 __u32 edx;
217 __u32 padding;
218};
219
220/* for KVM_SET_CPUID */
221struct kvm_cpuid {
222 __u32 nent;
223 __u32 padding;
224 struct kvm_cpuid_entry entries[0];
225};
226
6aa8b732
AK
227#define KVMIO 0xAE
228
f17abe9a
AK
229/*
230 * ioctls for /dev/kvm fds:
231 */
739872c5
AK
232#define KVM_GET_API_VERSION _IO(KVMIO, 0x00)
233#define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */
234#define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)
5d308f45
AK
235/*
236 * Check if a kvm extension is available. Argument is extension number,
237 * return is 1 (yes) or 0 (no, sorry).
238 */
239#define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
f17abe9a
AK
240
241/*
242 * ioctls for VM fds
243 */
739872c5 244#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
bccf2150
AK
245/*
246 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
247 * a vcpu fd.
248 */
739872c5
AK
249#define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
250#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
bccf2150
AK
251
252/*
253 * ioctls for vcpu fds
254 */
739872c5
AK
255#define KVM_RUN _IO(KVMIO, 0x80)
256#define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
257#define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs)
258#define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs)
259#define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
260#define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
261#define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
262#define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest)
263#define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
264#define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
265#define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
6aa8b732
AK
266
267#endif
This page took 0.080183 seconds and 5 git commands to generate.