V4L/DVB (5857): Use msecs_to_jiffies instead of HZ on radio drivers
[linux-2.6/mini2440.git] / include / linux / kvm.h
blobe6edca81ab847f54ff920b2b4b346e3ec60400c1
1 #ifndef __LINUX_KVM_H
2 #define __LINUX_KVM_H
4 /*
5 * Userspace interface for /dev/kvm - kernel based virtual machine
7 * Note: this interface is considered experimental and may change without
8 * notice.
9 */
11 #include <asm/types.h>
12 #include <linux/ioctl.h>
14 #define KVM_API_VERSION 12
17 * Architectural interrupt line count, and the size of the bitmap needed
18 * to hold them.
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))
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 */
33 /* for kvm_memory_region::flags */
34 #define KVM_MEM_LOG_DIRTY_PAGES 1UL
36 struct kvm_memory_alias {
37 __u32 slot; /* this has a different namespace than memory slots */
38 __u32 flags;
39 __u64 guest_phys_addr;
40 __u64 memory_size;
41 __u64 target_phys_addr;
44 enum kvm_exit_reason {
45 KVM_EXIT_UNKNOWN = 0,
46 KVM_EXIT_EXCEPTION = 1,
47 KVM_EXIT_IO = 2,
48 KVM_EXIT_HYPERCALL = 3,
49 KVM_EXIT_DEBUG = 4,
50 KVM_EXIT_HLT = 5,
51 KVM_EXIT_MMIO = 6,
52 KVM_EXIT_IRQ_WINDOW_OPEN = 7,
53 KVM_EXIT_SHUTDOWN = 8,
54 KVM_EXIT_FAIL_ENTRY = 9,
55 KVM_EXIT_INTR = 10,
58 /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
59 struct kvm_run {
60 /* in */
61 __u8 request_interrupt_window;
62 __u8 padding1[7];
64 /* out */
65 __u32 exit_reason;
66 __u8 ready_for_interrupt_injection;
67 __u8 if_flag;
68 __u8 padding2[2];
70 /* in (pre_kvm_run), out (post_kvm_run) */
71 __u64 cr8;
72 __u64 apic_base;
74 union {
75 /* KVM_EXIT_UNKNOWN */
76 struct {
77 __u64 hardware_exit_reason;
78 } hw;
79 /* KVM_EXIT_FAIL_ENTRY */
80 struct {
81 __u64 hardware_entry_failure_reason;
82 } fail_entry;
83 /* KVM_EXIT_EXCEPTION */
84 struct {
85 __u32 exception;
86 __u32 error_code;
87 } ex;
88 /* KVM_EXIT_IO */
89 struct kvm_io {
90 #define KVM_EXIT_IO_IN 0
91 #define KVM_EXIT_IO_OUT 1
92 __u8 direction;
93 __u8 size; /* bytes */
94 __u16 port;
95 __u32 count;
96 __u64 data_offset; /* relative to kvm_run start */
97 } io;
98 struct {
99 } debug;
100 /* KVM_EXIT_MMIO */
101 struct {
102 __u64 phys_addr;
103 __u8 data[8];
104 __u32 len;
105 __u8 is_write;
106 } mmio;
107 /* KVM_EXIT_HYPERCALL */
108 struct {
109 __u64 args[6];
110 __u64 ret;
111 __u32 longmode;
112 __u32 pad;
113 } hypercall;
117 /* for KVM_GET_REGS and KVM_SET_REGS */
118 struct kvm_regs {
119 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
120 __u64 rax, rbx, rcx, rdx;
121 __u64 rsi, rdi, rsp, rbp;
122 __u64 r8, r9, r10, r11;
123 __u64 r12, r13, r14, r15;
124 __u64 rip, rflags;
127 /* for KVM_GET_FPU and KVM_SET_FPU */
128 struct kvm_fpu {
129 __u8 fpr[8][16];
130 __u16 fcw;
131 __u16 fsw;
132 __u8 ftwx; /* in fxsave format */
133 __u8 pad1;
134 __u16 last_opcode;
135 __u64 last_ip;
136 __u64 last_dp;
137 __u8 xmm[16][16];
138 __u32 mxcsr;
139 __u32 pad2;
142 struct kvm_segment {
143 __u64 base;
144 __u32 limit;
145 __u16 selector;
146 __u8 type;
147 __u8 present, dpl, db, s, l, g, avl;
148 __u8 unusable;
149 __u8 padding;
152 struct kvm_dtable {
153 __u64 base;
154 __u16 limit;
155 __u16 padding[3];
158 /* for KVM_GET_SREGS and KVM_SET_SREGS */
159 struct kvm_sregs {
160 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
161 struct kvm_segment cs, ds, es, fs, gs, ss;
162 struct kvm_segment tr, ldt;
163 struct kvm_dtable gdt, idt;
164 __u64 cr0, cr2, cr3, cr4, cr8;
165 __u64 efer;
166 __u64 apic_base;
167 __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)];
170 struct kvm_msr_entry {
171 __u32 index;
172 __u32 reserved;
173 __u64 data;
176 /* for KVM_GET_MSRS and KVM_SET_MSRS */
177 struct kvm_msrs {
178 __u32 nmsrs; /* number of msrs in entries */
179 __u32 pad;
181 struct kvm_msr_entry entries[0];
184 /* for KVM_GET_MSR_INDEX_LIST */
185 struct kvm_msr_list {
186 __u32 nmsrs; /* number of msrs in entries */
187 __u32 indices[0];
190 /* for KVM_TRANSLATE */
191 struct kvm_translation {
192 /* in */
193 __u64 linear_address;
195 /* out */
196 __u64 physical_address;
197 __u8 valid;
198 __u8 writeable;
199 __u8 usermode;
200 __u8 pad[5];
203 /* for KVM_INTERRUPT */
204 struct kvm_interrupt {
205 /* in */
206 __u32 irq;
209 struct kvm_breakpoint {
210 __u32 enabled;
211 __u32 padding;
212 __u64 address;
215 /* for KVM_DEBUG_GUEST */
216 struct kvm_debug_guest {
217 /* int */
218 __u32 enabled;
219 __u32 pad;
220 struct kvm_breakpoint breakpoints[4];
221 __u32 singlestep;
224 /* for KVM_GET_DIRTY_LOG */
225 struct kvm_dirty_log {
226 __u32 slot;
227 __u32 padding;
228 union {
229 void __user *dirty_bitmap; /* one bit per page */
230 __u64 padding;
234 struct kvm_cpuid_entry {
235 __u32 function;
236 __u32 eax;
237 __u32 ebx;
238 __u32 ecx;
239 __u32 edx;
240 __u32 padding;
243 /* for KVM_SET_CPUID */
244 struct kvm_cpuid {
245 __u32 nent;
246 __u32 padding;
247 struct kvm_cpuid_entry entries[0];
250 /* for KVM_SET_SIGNAL_MASK */
251 struct kvm_signal_mask {
252 __u32 len;
253 __u8 sigset[0];
256 #define KVMIO 0xAE
259 * ioctls for /dev/kvm fds:
261 #define KVM_GET_API_VERSION _IO(KVMIO, 0x00)
262 #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */
263 #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)
265 * Check if a kvm extension is available. Argument is extension number,
266 * return is 1 (yes) or 0 (no, sorry).
268 #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)
270 * Get size for mmap(vcpu_fd)
272 #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */
275 * ioctls for VM fds
277 #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
279 * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
280 * a vcpu fd.
282 #define KVM_CREATE_VCPU _IO(KVMIO, 0x41)
283 #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)
284 #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)
287 * ioctls for vcpu fds
289 #define KVM_RUN _IO(KVMIO, 0x80)
290 #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs)
291 #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs)
292 #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs)
293 #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
294 #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
295 #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
296 #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest)
297 #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
298 #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
299 #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
300 #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)
301 #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu)
302 #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu)
304 #endif