Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[pandora-kernel.git] / include / linux / kvm.h
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
14 #define KVM_API_VERSION 1
15
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
37 #define KVM_EXIT_TYPE_FAIL_ENTRY 1
38 #define KVM_EXIT_TYPE_VM_EXIT    2
39
40 enum 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,
48 };
49
50 /* for KVM_RUN */
51 struct kvm_run {
52         /* in */
53         __u32 vcpu;
54         __u32 emulated;  /* skip current instruction */
55         __u32 mmio_completed; /* mmio request completed */
56
57         /* out */
58         __u32 exit_type;
59         __u32 exit_reason;
60         __u32 instruction_length;
61         union {
62                 /* KVM_EXIT_UNKNOWN */
63                 struct {
64                         __u32 hardware_exit_reason;
65                 } hw;
66                 /* KVM_EXIT_EXCEPTION */
67                 struct {
68                         __u32 exception;
69                         __u32 error_code;
70                 } ex;
71                 /* KVM_EXIT_IO */
72                 struct {
73 #define KVM_EXIT_IO_IN  0
74 #define KVM_EXIT_IO_OUT 1
75                         __u8 direction;
76                         __u8 size; /* bytes */
77                         __u8 string;
78                         __u8 string_down;
79                         __u8 rep;
80                         __u8 pad;
81                         __u16 port;
82                         __u64 count;
83                         union {
84                                 __u64 address;
85                                 __u32 value;
86                         };
87                 } io;
88                 struct {
89                 } debug;
90                 /* KVM_EXIT_MMIO */
91                 struct {
92                         __u64 phys_addr;
93                         __u8  data[8];
94                         __u32 len;
95                         __u8  is_write;
96                 } mmio;
97         };
98 };
99
100 /* for KVM_GET_REGS and KVM_SET_REGS */
101 struct kvm_regs {
102         /* in */
103         __u32 vcpu;
104         __u32 padding;
105
106         /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
107         __u64 rax, rbx, rcx, rdx;
108         __u64 rsi, rdi, rsp, rbp;
109         __u64 r8,  r9,  r10, r11;
110         __u64 r12, r13, r14, r15;
111         __u64 rip, rflags;
112 };
113
114 struct kvm_segment {
115         __u64 base;
116         __u32 limit;
117         __u16 selector;
118         __u8  type;
119         __u8  present, dpl, db, s, l, g, avl;
120         __u8  unusable;
121         __u8  padding;
122 };
123
124 struct kvm_dtable {
125         __u64 base;
126         __u16 limit;
127         __u16 padding[3];
128 };
129
130 /* for KVM_GET_SREGS and KVM_SET_SREGS */
131 struct kvm_sregs {
132         /* in */
133         __u32 vcpu;
134         __u32 padding;
135
136         /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
137         struct kvm_segment cs, ds, es, fs, gs, ss;
138         struct kvm_segment tr, ldt;
139         struct kvm_dtable gdt, idt;
140         __u64 cr0, cr2, cr3, cr4, cr8;
141         __u64 efer;
142         __u64 apic_base;
143         __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)];
144 };
145
146 struct kvm_msr_entry {
147         __u32 index;
148         __u32 reserved;
149         __u64 data;
150 };
151
152 /* for KVM_GET_MSRS and KVM_SET_MSRS */
153 struct kvm_msrs {
154         __u32 vcpu;
155         __u32 nmsrs; /* number of msrs in entries */
156
157         struct kvm_msr_entry entries[0];
158 };
159
160 /* for KVM_GET_MSR_INDEX_LIST */
161 struct kvm_msr_list {
162         __u32 nmsrs; /* number of msrs in entries */
163         __u32 indices[0];
164 };
165
166 /* for KVM_TRANSLATE */
167 struct kvm_translation {
168         /* in */
169         __u64 linear_address;
170         __u32 vcpu;
171         __u32 padding;
172
173         /* out */
174         __u64 physical_address;
175         __u8  valid;
176         __u8  writeable;
177         __u8  usermode;
178 };
179
180 /* for KVM_INTERRUPT */
181 struct kvm_interrupt {
182         /* in */
183         __u32 vcpu;
184         __u32 irq;
185 };
186
187 struct kvm_breakpoint {
188         __u32 enabled;
189         __u32 padding;
190         __u64 address;
191 };
192
193 /* for KVM_DEBUG_GUEST */
194 struct kvm_debug_guest {
195         /* int */
196         __u32 vcpu;
197         __u32 enabled;
198         struct kvm_breakpoint breakpoints[4];
199         __u32 singlestep;
200 };
201
202 /* for KVM_GET_DIRTY_LOG */
203 struct kvm_dirty_log {
204         __u32 slot;
205         __u32 padding;
206         union {
207                 void __user *dirty_bitmap; /* one bit per page */
208                 __u64 padding;
209         };
210 };
211
212 #define KVMIO 0xAE
213
214 #define KVM_GET_API_VERSION       _IO(KVMIO, 1)
215 #define KVM_RUN                   _IOWR(KVMIO, 2, struct kvm_run)
216 #define KVM_GET_REGS              _IOWR(KVMIO, 3, struct kvm_regs)
217 #define KVM_SET_REGS              _IOW(KVMIO, 4, struct kvm_regs)
218 #define KVM_GET_SREGS             _IOWR(KVMIO, 5, struct kvm_sregs)
219 #define KVM_SET_SREGS             _IOW(KVMIO, 6, struct kvm_sregs)
220 #define KVM_TRANSLATE             _IOWR(KVMIO, 7, struct kvm_translation)
221 #define KVM_INTERRUPT             _IOW(KVMIO, 8, struct kvm_interrupt)
222 #define KVM_DEBUG_GUEST           _IOW(KVMIO, 9, struct kvm_debug_guest)
223 #define KVM_SET_MEMORY_REGION     _IOW(KVMIO, 10, struct kvm_memory_region)
224 #define KVM_CREATE_VCPU           _IOW(KVMIO, 11, int /* vcpu_slot */)
225 #define KVM_GET_DIRTY_LOG         _IOW(KVMIO, 12, struct kvm_dirty_log)
226 #define KVM_GET_MSRS              _IOWR(KVMIO, 13, struct kvm_msrs)
227 #define KVM_SET_MSRS              _IOWR(KVMIO, 14, struct kvm_msrs)
228 #define KVM_GET_MSR_INDEX_LIST    _IOWR(KVMIO, 15, struct kvm_msr_list)
229
230 #endif