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 | * | |
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 | ||
1b19f3e6 | 14 | #define KVM_API_VERSION 9 |
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 */ | |
26 | struct 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 | ||
6aa8b732 AK |
37 | enum kvm_exit_reason { |
38 | KVM_EXIT_UNKNOWN = 0, | |
39 | KVM_EXIT_EXCEPTION = 1, | |
40 | KVM_EXIT_IO = 2, | |
b4e63f56 | 41 | KVM_EXIT_HYPERCALL = 3, |
6aa8b732 AK |
42 | KVM_EXIT_DEBUG = 4, |
43 | KVM_EXIT_HLT = 5, | |
44 | KVM_EXIT_MMIO = 6, | |
c1150d8c | 45 | KVM_EXIT_IRQ_WINDOW_OPEN = 7, |
46fe4ddd | 46 | KVM_EXIT_SHUTDOWN = 8, |
8eb7d334 | 47 | KVM_EXIT_FAIL_ENTRY = 9, |
1b19f3e6 | 48 | KVM_EXIT_INTR = 10, |
6aa8b732 AK |
49 | }; |
50 | ||
9a2bb7f4 | 51 | /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */ |
6aa8b732 AK |
52 | struct 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 */ | |
6aa8b732 AK |
59 | __u32 exit_reason; |
60 | __u32 instruction_length; | |
c1150d8c DL |
61 | __u8 ready_for_interrupt_injection; |
62 | __u8 if_flag; | |
8eb7d334 | 63 | __u8 padding2[6]; |
54810342 DL |
64 | |
65 | /* in (pre_kvm_run), out (post_kvm_run) */ | |
c1150d8c DL |
66 | __u64 cr8; |
67 | __u64 apic_base; | |
68 | ||
6aa8b732 AK |
69 | union { |
70 | /* KVM_EXIT_UNKNOWN */ | |
71 | struct { | |
8eb7d334 | 72 | __u64 hardware_exit_reason; |
6aa8b732 | 73 | } hw; |
8eb7d334 AK |
74 | /* KVM_EXIT_FAIL_ENTRY */ |
75 | struct { | |
76 | __u64 hardware_entry_failure_reason; | |
77 | } fail_entry; | |
6aa8b732 AK |
78 | /* KVM_EXIT_EXCEPTION */ |
79 | struct { | |
80 | __u32 exception; | |
81 | __u32 error_code; | |
82 | } ex; | |
83 | /* KVM_EXIT_IO */ | |
46fc1477 | 84 | struct kvm_io { |
6aa8b732 AK |
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; | |
b4e63f56 AK |
109 | /* KVM_EXIT_HYPERCALL */ |
110 | struct { | |
111 | __u64 args[6]; | |
112 | __u64 ret; | |
113 | __u32 longmode; | |
114 | __u32 pad; | |
115 | } hypercall; | |
6aa8b732 AK |
116 | }; |
117 | }; | |
118 | ||
119 | /* for KVM_GET_REGS and KVM_SET_REGS */ | |
120 | struct kvm_regs { | |
6aa8b732 AK |
121 | /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ |
122 | __u64 rax, rbx, rcx, rdx; | |
123 | __u64 rsi, rdi, rsp, rbp; | |
124 | __u64 r8, r9, r10, r11; | |
125 | __u64 r12, r13, r14, r15; | |
126 | __u64 rip, rflags; | |
127 | }; | |
128 | ||
129 | struct kvm_segment { | |
130 | __u64 base; | |
131 | __u32 limit; | |
132 | __u16 selector; | |
133 | __u8 type; | |
134 | __u8 present, dpl, db, s, l, g, avl; | |
135 | __u8 unusable; | |
136 | __u8 padding; | |
137 | }; | |
138 | ||
139 | struct kvm_dtable { | |
140 | __u64 base; | |
141 | __u16 limit; | |
142 | __u16 padding[3]; | |
143 | }; | |
144 | ||
145 | /* for KVM_GET_SREGS and KVM_SET_SREGS */ | |
146 | struct kvm_sregs { | |
6aa8b732 AK |
147 | /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */ |
148 | struct kvm_segment cs, ds, es, fs, gs, ss; | |
149 | struct kvm_segment tr, ldt; | |
150 | struct kvm_dtable gdt, idt; | |
151 | __u64 cr0, cr2, cr3, cr4, cr8; | |
152 | __u64 efer; | |
153 | __u64 apic_base; | |
154 | __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)]; | |
155 | }; | |
156 | ||
157 | struct kvm_msr_entry { | |
158 | __u32 index; | |
159 | __u32 reserved; | |
160 | __u64 data; | |
161 | }; | |
162 | ||
163 | /* for KVM_GET_MSRS and KVM_SET_MSRS */ | |
164 | struct kvm_msrs { | |
6aa8b732 | 165 | __u32 nmsrs; /* number of msrs in entries */ |
bccf2150 | 166 | __u32 pad; |
6aa8b732 AK |
167 | |
168 | struct kvm_msr_entry entries[0]; | |
169 | }; | |
170 | ||
171 | /* for KVM_GET_MSR_INDEX_LIST */ | |
172 | struct kvm_msr_list { | |
173 | __u32 nmsrs; /* number of msrs in entries */ | |
174 | __u32 indices[0]; | |
175 | }; | |
176 | ||
177 | /* for KVM_TRANSLATE */ | |
178 | struct kvm_translation { | |
179 | /* in */ | |
180 | __u64 linear_address; | |
6aa8b732 AK |
181 | |
182 | /* out */ | |
183 | __u64 physical_address; | |
184 | __u8 valid; | |
185 | __u8 writeable; | |
186 | __u8 usermode; | |
8cd13307 | 187 | __u8 pad[5]; |
6aa8b732 AK |
188 | }; |
189 | ||
190 | /* for KVM_INTERRUPT */ | |
191 | struct kvm_interrupt { | |
192 | /* in */ | |
6aa8b732 AK |
193 | __u32 irq; |
194 | }; | |
195 | ||
196 | struct kvm_breakpoint { | |
197 | __u32 enabled; | |
198 | __u32 padding; | |
199 | __u64 address; | |
200 | }; | |
201 | ||
202 | /* for KVM_DEBUG_GUEST */ | |
203 | struct kvm_debug_guest { | |
204 | /* int */ | |
6aa8b732 | 205 | __u32 enabled; |
bccf2150 | 206 | __u32 pad; |
6aa8b732 AK |
207 | struct kvm_breakpoint breakpoints[4]; |
208 | __u32 singlestep; | |
209 | }; | |
210 | ||
211 | /* for KVM_GET_DIRTY_LOG */ | |
212 | struct kvm_dirty_log { | |
213 | __u32 slot; | |
214 | __u32 padding; | |
215 | union { | |
216 | void __user *dirty_bitmap; /* one bit per page */ | |
217 | __u64 padding; | |
218 | }; | |
219 | }; | |
220 | ||
06465c5a AK |
221 | struct kvm_cpuid_entry { |
222 | __u32 function; | |
223 | __u32 eax; | |
224 | __u32 ebx; | |
225 | __u32 ecx; | |
226 | __u32 edx; | |
227 | __u32 padding; | |
228 | }; | |
229 | ||
230 | /* for KVM_SET_CPUID */ | |
231 | struct kvm_cpuid { | |
232 | __u32 nent; | |
233 | __u32 padding; | |
234 | struct kvm_cpuid_entry entries[0]; | |
235 | }; | |
236 | ||
1961d276 AK |
237 | /* for KVM_SET_SIGNAL_MASK */ |
238 | struct kvm_signal_mask { | |
239 | __u32 len; | |
240 | __u8 sigset[0]; | |
241 | }; | |
242 | ||
6aa8b732 AK |
243 | #define KVMIO 0xAE |
244 | ||
f17abe9a AK |
245 | /* |
246 | * ioctls for /dev/kvm fds: | |
247 | */ | |
739872c5 AK |
248 | #define KVM_GET_API_VERSION _IO(KVMIO, 0x00) |
249 | #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */ | |
250 | #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list) | |
5d308f45 AK |
251 | /* |
252 | * Check if a kvm extension is available. Argument is extension number, | |
253 | * return is 1 (yes) or 0 (no, sorry). | |
254 | */ | |
255 | #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03) | |
07c45a36 AK |
256 | /* |
257 | * Get size for mmap(vcpu_fd) | |
258 | */ | |
259 | #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */ | |
f17abe9a AK |
260 | |
261 | /* | |
262 | * ioctls for VM fds | |
263 | */ | |
739872c5 | 264 | #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region) |
bccf2150 AK |
265 | /* |
266 | * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns | |
267 | * a vcpu fd. | |
268 | */ | |
739872c5 AK |
269 | #define KVM_CREATE_VCPU _IO(KVMIO, 0x41) |
270 | #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log) | |
bccf2150 AK |
271 | |
272 | /* | |
273 | * ioctls for vcpu fds | |
274 | */ | |
739872c5 AK |
275 | #define KVM_RUN _IO(KVMIO, 0x80) |
276 | #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs) | |
277 | #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs) | |
278 | #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs) | |
279 | #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs) | |
280 | #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation) | |
281 | #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt) | |
282 | #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest) | |
283 | #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs) | |
284 | #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs) | |
285 | #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid) | |
1961d276 | 286 | #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask) |
6aa8b732 AK |
287 | |
288 | #endif |