KVM: s390: arch backend for the kvm kernel module
[safe/jmp/linux-2.6] / 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: you must update KVM_API_VERSION if you change this interface.
8  */
9
10 #include <asm/types.h>
11 #include <linux/compiler.h>
12 #include <linux/ioctl.h>
13 #include <asm/kvm.h>
14
15 #define KVM_API_VERSION 12
16
17 /* for KVM_CREATE_MEMORY_REGION */
18 struct kvm_memory_region {
19         __u32 slot;
20         __u32 flags;
21         __u64 guest_phys_addr;
22         __u64 memory_size; /* bytes */
23 };
24
25 /* for KVM_SET_USER_MEMORY_REGION */
26 struct kvm_userspace_memory_region {
27         __u32 slot;
28         __u32 flags;
29         __u64 guest_phys_addr;
30         __u64 memory_size; /* bytes */
31         __u64 userspace_addr; /* start of the userspace allocated memory */
32 };
33
34 /* for kvm_memory_region::flags */
35 #define KVM_MEM_LOG_DIRTY_PAGES  1UL
36
37
38 /* for KVM_IRQ_LINE */
39 struct kvm_irq_level {
40         /*
41          * ACPI gsi notion of irq.
42          * For IA-64 (APIC model) IOAPIC0: irq 0-23; IOAPIC1: irq 24-47..
43          * For X86 (standard AT mode) PIC0/1: irq 0-15. IOAPIC0: 0-23..
44          */
45         __u32 irq;
46         __u32 level;
47 };
48
49
50 struct kvm_irqchip {
51         __u32 chip_id;
52         __u32 pad;
53         union {
54                 char dummy[512];  /* reserving space */
55 #ifdef CONFIG_X86
56                 struct kvm_pic_state pic;
57 #endif
58 #if defined(CONFIG_X86) || defined(CONFIG_IA64)
59                 struct kvm_ioapic_state ioapic;
60 #endif
61         } chip;
62 };
63
64 #define KVM_EXIT_UNKNOWN          0
65 #define KVM_EXIT_EXCEPTION        1
66 #define KVM_EXIT_IO               2
67 #define KVM_EXIT_HYPERCALL        3
68 #define KVM_EXIT_DEBUG            4
69 #define KVM_EXIT_HLT              5
70 #define KVM_EXIT_MMIO             6
71 #define KVM_EXIT_IRQ_WINDOW_OPEN  7
72 #define KVM_EXIT_SHUTDOWN         8
73 #define KVM_EXIT_FAIL_ENTRY       9
74 #define KVM_EXIT_INTR             10
75 #define KVM_EXIT_SET_TPR          11
76 #define KVM_EXIT_TPR_ACCESS       12
77
78 /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
79 struct kvm_run {
80         /* in */
81         __u8 request_interrupt_window;
82         __u8 padding1[7];
83
84         /* out */
85         __u32 exit_reason;
86         __u8 ready_for_interrupt_injection;
87         __u8 if_flag;
88         __u8 padding2[2];
89
90         /* in (pre_kvm_run), out (post_kvm_run) */
91         __u64 cr8;
92         __u64 apic_base;
93
94         union {
95                 /* KVM_EXIT_UNKNOWN */
96                 struct {
97                         __u64 hardware_exit_reason;
98                 } hw;
99                 /* KVM_EXIT_FAIL_ENTRY */
100                 struct {
101                         __u64 hardware_entry_failure_reason;
102                 } fail_entry;
103                 /* KVM_EXIT_EXCEPTION */
104                 struct {
105                         __u32 exception;
106                         __u32 error_code;
107                 } ex;
108                 /* KVM_EXIT_IO */
109                 struct kvm_io {
110 #define KVM_EXIT_IO_IN  0
111 #define KVM_EXIT_IO_OUT 1
112                         __u8 direction;
113                         __u8 size; /* bytes */
114                         __u16 port;
115                         __u32 count;
116                         __u64 data_offset; /* relative to kvm_run start */
117                 } io;
118                 struct {
119                 } debug;
120                 /* KVM_EXIT_MMIO */
121                 struct {
122                         __u64 phys_addr;
123                         __u8  data[8];
124                         __u32 len;
125                         __u8  is_write;
126                 } mmio;
127                 /* KVM_EXIT_HYPERCALL */
128                 struct {
129                         __u64 nr;
130                         __u64 args[6];
131                         __u64 ret;
132                         __u32 longmode;
133                         __u32 pad;
134                 } hypercall;
135                 /* KVM_EXIT_TPR_ACCESS */
136                 struct {
137                         __u64 rip;
138                         __u32 is_write;
139                         __u32 pad;
140                 } tpr_access;
141                 /* Fix the size of the union. */
142                 char padding[256];
143         };
144 };
145
146 /* for KVM_TRANSLATE */
147 struct kvm_translation {
148         /* in */
149         __u64 linear_address;
150
151         /* out */
152         __u64 physical_address;
153         __u8  valid;
154         __u8  writeable;
155         __u8  usermode;
156         __u8  pad[5];
157 };
158
159 /* for KVM_INTERRUPT */
160 struct kvm_interrupt {
161         /* in */
162         __u32 irq;
163 };
164
165 struct kvm_breakpoint {
166         __u32 enabled;
167         __u32 padding;
168         __u64 address;
169 };
170
171 /* for KVM_DEBUG_GUEST */
172 struct kvm_debug_guest {
173         /* int */
174         __u32 enabled;
175         __u32 pad;
176         struct kvm_breakpoint breakpoints[4];
177         __u32 singlestep;
178 };
179
180 /* for KVM_GET_DIRTY_LOG */
181 struct kvm_dirty_log {
182         __u32 slot;
183         __u32 padding;
184         union {
185                 void __user *dirty_bitmap; /* one bit per page */
186                 __u64 padding;
187         };
188 };
189
190 /* for KVM_SET_SIGNAL_MASK */
191 struct kvm_signal_mask {
192         __u32 len;
193         __u8  sigset[0];
194 };
195
196 /* for KVM_TPR_ACCESS_REPORTING */
197 struct kvm_tpr_access_ctl {
198         __u32 enabled;
199         __u32 flags;
200         __u32 reserved[8];
201 };
202
203 /* for KVM_SET_VAPIC_ADDR */
204 struct kvm_vapic_addr {
205         __u64 vapic_addr;
206 };
207
208 struct kvm_s390_psw {
209         __u64 mask;
210         __u64 addr;
211 };
212
213 #define KVMIO 0xAE
214
215 /*
216  * ioctls for /dev/kvm fds:
217  */
218 #define KVM_GET_API_VERSION       _IO(KVMIO,   0x00)
219 #define KVM_CREATE_VM             _IO(KVMIO,   0x01) /* returns a VM fd */
220 #define KVM_GET_MSR_INDEX_LIST    _IOWR(KVMIO, 0x02, struct kvm_msr_list)
221
222 #define KVM_S390_ENABLE_SIE       _IO(KVMIO,   0x06)
223 /*
224  * Check if a kvm extension is available.  Argument is extension number,
225  * return is 1 (yes) or 0 (no, sorry).
226  */
227 #define KVM_CHECK_EXTENSION       _IO(KVMIO,   0x03)
228 /*
229  * Get size for mmap(vcpu_fd)
230  */
231 #define KVM_GET_VCPU_MMAP_SIZE    _IO(KVMIO,   0x04) /* in bytes */
232 #define KVM_GET_SUPPORTED_CPUID   _IOWR(KVMIO, 0x05, struct kvm_cpuid2)
233
234 /*
235  * Extension capability list.
236  */
237 #define KVM_CAP_IRQCHIP   0
238 #define KVM_CAP_HLT       1
239 #define KVM_CAP_MMU_SHADOW_CACHE_CONTROL 2
240 #define KVM_CAP_USER_MEMORY 3
241 #define KVM_CAP_SET_TSS_ADDR 4
242 #define KVM_CAP_VAPIC 6
243 #define KVM_CAP_EXT_CPUID 7
244 #define KVM_CAP_CLOCKSOURCE 8
245 #define KVM_CAP_NR_VCPUS 9       /* returns max vcpus per vm */
246 #define KVM_CAP_NR_MEMSLOTS 10   /* returns max memory slots per vm */
247 #define KVM_CAP_PIT 11
248 #define KVM_CAP_NOP_IO_DELAY 12
249 #define KVM_CAP_PV_MMU 13
250
251 /*
252  * ioctls for VM fds
253  */
254 #define KVM_SET_MEMORY_REGION     _IOW(KVMIO, 0x40, struct kvm_memory_region)
255 #define KVM_SET_NR_MMU_PAGES      _IO(KVMIO, 0x44)
256 #define KVM_GET_NR_MMU_PAGES      _IO(KVMIO, 0x45)
257 #define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46,\
258                                         struct kvm_userspace_memory_region)
259 #define KVM_SET_TSS_ADDR          _IO(KVMIO, 0x47)
260 /*
261  * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
262  * a vcpu fd.
263  */
264 #define KVM_CREATE_VCPU           _IO(KVMIO,  0x41)
265 #define KVM_GET_DIRTY_LOG         _IOW(KVMIO, 0x42, struct kvm_dirty_log)
266 #define KVM_SET_MEMORY_ALIAS      _IOW(KVMIO, 0x43, struct kvm_memory_alias)
267 /* Device model IOC */
268 #define KVM_CREATE_IRQCHIP        _IO(KVMIO,  0x60)
269 #define KVM_IRQ_LINE              _IOW(KVMIO, 0x61, struct kvm_irq_level)
270 #define KVM_GET_IRQCHIP           _IOWR(KVMIO, 0x62, struct kvm_irqchip)
271 #define KVM_SET_IRQCHIP           _IOR(KVMIO,  0x63, struct kvm_irqchip)
272 #define KVM_CREATE_PIT            _IO(KVMIO,  0x64)
273 #define KVM_GET_PIT               _IOWR(KVMIO, 0x65, struct kvm_pit_state)
274 #define KVM_SET_PIT               _IOR(KVMIO,  0x66, struct kvm_pit_state)
275
276 /*
277  * ioctls for vcpu fds
278  */
279 #define KVM_RUN                   _IO(KVMIO,   0x80)
280 #define KVM_GET_REGS              _IOR(KVMIO,  0x81, struct kvm_regs)
281 #define KVM_SET_REGS              _IOW(KVMIO,  0x82, struct kvm_regs)
282 #define KVM_GET_SREGS             _IOR(KVMIO,  0x83, struct kvm_sregs)
283 #define KVM_SET_SREGS             _IOW(KVMIO,  0x84, struct kvm_sregs)
284 #define KVM_TRANSLATE             _IOWR(KVMIO, 0x85, struct kvm_translation)
285 #define KVM_INTERRUPT             _IOW(KVMIO,  0x86, struct kvm_interrupt)
286 #define KVM_DEBUG_GUEST           _IOW(KVMIO,  0x87, struct kvm_debug_guest)
287 #define KVM_GET_MSRS              _IOWR(KVMIO, 0x88, struct kvm_msrs)
288 #define KVM_SET_MSRS              _IOW(KVMIO,  0x89, struct kvm_msrs)
289 #define KVM_SET_CPUID             _IOW(KVMIO,  0x8a, struct kvm_cpuid)
290 #define KVM_SET_SIGNAL_MASK       _IOW(KVMIO,  0x8b, struct kvm_signal_mask)
291 #define KVM_GET_FPU               _IOR(KVMIO,  0x8c, struct kvm_fpu)
292 #define KVM_SET_FPU               _IOW(KVMIO,  0x8d, struct kvm_fpu)
293 #define KVM_GET_LAPIC             _IOR(KVMIO,  0x8e, struct kvm_lapic_state)
294 #define KVM_SET_LAPIC             _IOW(KVMIO,  0x8f, struct kvm_lapic_state)
295 #define KVM_SET_CPUID2            _IOW(KVMIO,  0x90, struct kvm_cpuid2)
296 #define KVM_GET_CPUID2            _IOWR(KVMIO, 0x91, struct kvm_cpuid2)
297 /* Available with KVM_CAP_VAPIC */
298 #define KVM_TPR_ACCESS_REPORTING  _IOWR(KVMIO,  0x92, struct kvm_tpr_access_ctl)
299 /* Available with KVM_CAP_VAPIC */
300 #define KVM_SET_VAPIC_ADDR        _IOW(KVMIO,  0x93, struct kvm_vapic_addr)
301 /* store status for s390 */
302 #define KVM_S390_STORE_STATUS_NOADDR    (-1ul)
303 #define KVM_S390_STORE_STATUS_PREFIXED  (-2ul)
304 #define KVM_S390_STORE_STATUS     _IOW(KVMIO,  0x95, unsigned long)
305 /* initial ipl psw for s390 */
306 #define KVM_S390_SET_INITIAL_PSW  _IOW(KVMIO,  0x96, struct kvm_s390_psw)
307 /* initial reset for s390 */
308 #define KVM_S390_INITIAL_RESET    _IO(KVMIO,  0x97)
309
310 #endif