Fix Maple PATA IRQ assignment.
[sfrench/cifs-2.6.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 2
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         KVM_EXIT_IRQ_WINDOW_OPEN  = 7,
49 };
50
51 /* for KVM_RUN */
52 struct kvm_run {
53         /* in */
54         __u32 vcpu;
55         __u32 emulated;  /* skip current instruction */
56         __u32 mmio_completed; /* mmio request completed */
57         __u8 request_interrupt_window;
58         __u8 padding1[3];
59
60         /* out */
61         __u32 exit_type;
62         __u32 exit_reason;
63         __u32 instruction_length;
64         __u8 ready_for_interrupt_injection;
65         __u8 if_flag;
66         __u16 padding2;
67         __u64 cr8;
68         __u64 apic_base;
69
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 */
81                 struct {
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 */
110 struct kvm_regs {
111         /* in */
112         __u32 vcpu;
113         __u32 padding;
114
115         /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
116         __u64 rax, rbx, rcx, rdx;
117         __u64 rsi, rdi, rsp, rbp;
118         __u64 r8,  r9,  r10, r11;
119         __u64 r12, r13, r14, r15;
120         __u64 rip, rflags;
121 };
122
123 struct kvm_segment {
124         __u64 base;
125         __u32 limit;
126         __u16 selector;
127         __u8  type;
128         __u8  present, dpl, db, s, l, g, avl;
129         __u8  unusable;
130         __u8  padding;
131 };
132
133 struct kvm_dtable {
134         __u64 base;
135         __u16 limit;
136         __u16 padding[3];
137 };
138
139 /* for KVM_GET_SREGS and KVM_SET_SREGS */
140 struct kvm_sregs {
141         /* in */
142         __u32 vcpu;
143         __u32 padding;
144
145         /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
146         struct kvm_segment cs, ds, es, fs, gs, ss;
147         struct kvm_segment tr, ldt;
148         struct kvm_dtable gdt, idt;
149         __u64 cr0, cr2, cr3, cr4, cr8;
150         __u64 efer;
151         __u64 apic_base;
152         __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)];
153 };
154
155 struct kvm_msr_entry {
156         __u32 index;
157         __u32 reserved;
158         __u64 data;
159 };
160
161 /* for KVM_GET_MSRS and KVM_SET_MSRS */
162 struct kvm_msrs {
163         __u32 vcpu;
164         __u32 nmsrs; /* number of msrs in entries */
165
166         struct kvm_msr_entry entries[0];
167 };
168
169 /* for KVM_GET_MSR_INDEX_LIST */
170 struct kvm_msr_list {
171         __u32 nmsrs; /* number of msrs in entries */
172         __u32 indices[0];
173 };
174
175 /* for KVM_TRANSLATE */
176 struct kvm_translation {
177         /* in */
178         __u64 linear_address;
179         __u32 vcpu;
180         __u32 padding;
181
182         /* out */
183         __u64 physical_address;
184         __u8  valid;
185         __u8  writeable;
186         __u8  usermode;
187 };
188
189 /* for KVM_INTERRUPT */
190 struct kvm_interrupt {
191         /* in */
192         __u32 vcpu;
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 */
205         __u32 vcpu;
206         __u32 enabled;
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
221 #define KVMIO 0xAE
222
223 #define KVM_GET_API_VERSION       _IO(KVMIO, 1)
224 #define KVM_RUN                   _IOWR(KVMIO, 2, struct kvm_run)
225 #define KVM_GET_REGS              _IOWR(KVMIO, 3, struct kvm_regs)
226 #define KVM_SET_REGS              _IOW(KVMIO, 4, struct kvm_regs)
227 #define KVM_GET_SREGS             _IOWR(KVMIO, 5, struct kvm_sregs)
228 #define KVM_SET_SREGS             _IOW(KVMIO, 6, struct kvm_sregs)
229 #define KVM_TRANSLATE             _IOWR(KVMIO, 7, struct kvm_translation)
230 #define KVM_INTERRUPT             _IOW(KVMIO, 8, struct kvm_interrupt)
231 #define KVM_DEBUG_GUEST           _IOW(KVMIO, 9, struct kvm_debug_guest)
232 #define KVM_SET_MEMORY_REGION     _IOW(KVMIO, 10, struct kvm_memory_region)
233 #define KVM_CREATE_VCPU           _IOW(KVMIO, 11, int /* vcpu_slot */)
234 #define KVM_GET_DIRTY_LOG         _IOW(KVMIO, 12, struct kvm_dirty_log)
235 #define KVM_GET_MSRS              _IOWR(KVMIO, 13, struct kvm_msrs)
236 #define KVM_SET_MSRS              _IOWR(KVMIO, 14, struct kvm_msrs)
237 #define KVM_GET_MSR_INDEX_LIST    _IOWR(KVMIO, 15, struct kvm_msr_list)
238
239 #endif