xref: /illumos-kvm/linux/include/linux/kvm.h (revision 44f65dde)
1 #ifndef KVM_UNIFDEF_H
2 #define KVM_UNIFDEF_H
3 
4 #ifdef __i386__
5 #ifndef CONFIG_X86_32
6 #define CONFIG_X86_32 1
7 #endif
8 #endif
9 
10 #ifdef __x86_64__
11 #ifndef CONFIG_X86_64
12 #define CONFIG_X86_64 1
13 #endif
14 #endif
15 
16 #if defined(__i386__) || defined (__x86_64__)
17 #ifndef CONFIG_X86
18 #define CONFIG_X86 1
19 #endif
20 #endif
21 
22 #ifdef __ia64__
23 #ifndef CONFIG_IA64
24 #define CONFIG_IA64 1
25 #endif
26 #endif
27 
28 #ifdef __PPC__
29 #ifndef CONFIG_PPC
30 #define CONFIG_PPC 1
31 #endif
32 #endif
33 
34 #ifdef __s390__
35 #ifndef CONFIG_S390
36 #define CONFIG_S390 1
37 #endif
38 #endif
39 
40 #endif
41 #ifndef __LINUX_KVM_H
42 #define __LINUX_KVM_H
43 
44 /*
45  * Userspace interface for /dev/kvm - kernel based virtual machine
46  *
47  * Note: you must update KVM_API_VERSION if you change this interface.
48  */
49 
50 #include <asm/types.h>
51 
52 #include <linux/ioctl.h>
53 #include <asm/kvm.h>
54 
55 #define KVM_API_VERSION 12
56 
57 /* *** Deprecated interfaces *** */
58 
59 #define KVM_TRC_SHIFT           16
60 
61 #define KVM_TRC_ENTRYEXIT       (1 << KVM_TRC_SHIFT)
62 #define KVM_TRC_HANDLER         (1 << (KVM_TRC_SHIFT + 1))
63 
64 #define KVM_TRC_VMENTRY         (KVM_TRC_ENTRYEXIT + 0x01)
65 #define KVM_TRC_VMEXIT          (KVM_TRC_ENTRYEXIT + 0x02)
66 #define KVM_TRC_PAGE_FAULT      (KVM_TRC_HANDLER + 0x01)
67 
68 #define KVM_TRC_HEAD_SIZE       12
69 #define KVM_TRC_CYCLE_SIZE      8
70 #define KVM_TRC_EXTRA_MAX       7
71 
72 #define KVM_TRC_INJ_VIRQ         (KVM_TRC_HANDLER + 0x02)
73 #define KVM_TRC_REDELIVER_EVT    (KVM_TRC_HANDLER + 0x03)
74 #define KVM_TRC_PEND_INTR        (KVM_TRC_HANDLER + 0x04)
75 #define KVM_TRC_IO_READ          (KVM_TRC_HANDLER + 0x05)
76 #define KVM_TRC_IO_WRITE         (KVM_TRC_HANDLER + 0x06)
77 #define KVM_TRC_CR_READ          (KVM_TRC_HANDLER + 0x07)
78 #define KVM_TRC_CR_WRITE         (KVM_TRC_HANDLER + 0x08)
79 #define KVM_TRC_DR_READ          (KVM_TRC_HANDLER + 0x09)
80 #define KVM_TRC_DR_WRITE         (KVM_TRC_HANDLER + 0x0A)
81 #define KVM_TRC_MSR_READ         (KVM_TRC_HANDLER + 0x0B)
82 #define KVM_TRC_MSR_WRITE        (KVM_TRC_HANDLER + 0x0C)
83 #define KVM_TRC_CPUID            (KVM_TRC_HANDLER + 0x0D)
84 #define KVM_TRC_INTR             (KVM_TRC_HANDLER + 0x0E)
85 #define KVM_TRC_NMI              (KVM_TRC_HANDLER + 0x0F)
86 #define KVM_TRC_VMMCALL          (KVM_TRC_HANDLER + 0x10)
87 #define KVM_TRC_HLT              (KVM_TRC_HANDLER + 0x11)
88 #define KVM_TRC_CLTS             (KVM_TRC_HANDLER + 0x12)
89 #define KVM_TRC_LMSW             (KVM_TRC_HANDLER + 0x13)
90 #define KVM_TRC_APIC_ACCESS      (KVM_TRC_HANDLER + 0x14)
91 #define KVM_TRC_TDP_FAULT        (KVM_TRC_HANDLER + 0x15)
92 #define KVM_TRC_GTLB_WRITE       (KVM_TRC_HANDLER + 0x16)
93 #define KVM_TRC_STLB_WRITE       (KVM_TRC_HANDLER + 0x17)
94 #define KVM_TRC_STLB_INVAL       (KVM_TRC_HANDLER + 0x18)
95 #define KVM_TRC_PPC_INSTR        (KVM_TRC_HANDLER + 0x19)
96 
97 struct kvm_user_trace_setup {
98 	__u32 buf_size;
99 	__u32 buf_nr;
100 };
101 
102 #define __KVM_DEPRECATED_MAIN_W_0x06 \
103 	_IOW(KVMIO, 0x06, struct kvm_user_trace_setup)
104 #define __KVM_DEPRECATED_MAIN_0x07 _IO(KVMIO, 0x07)
105 #define __KVM_DEPRECATED_MAIN_0x08 _IO(KVMIO, 0x08)
106 
107 #define __KVM_DEPRECATED_VM_R_0x70 _IOR(KVMIO, 0x70, struct kvm_assigned_irq)
108 
109 struct kvm_breakpoint {
110 	__u32 enabled;
111 	__u32 padding;
112 	__u64 address;
113 };
114 
115 struct kvm_debug_guest {
116 	__u32 enabled;
117 	__u32 pad;
118 	struct kvm_breakpoint breakpoints[4];
119 	__u32 singlestep;
120 };
121 
122 #define __KVM_DEPRECATED_VCPU_W_0x87 _IOW(KVMIO, 0x87, struct kvm_debug_guest)
123 
124 /* *** End of deprecated interfaces *** */
125 
126 
127 /* for KVM_CREATE_MEMORY_REGION */
128 struct kvm_memory_region {
129 	__u32 slot;
130 	__u32 flags;
131 	__u64 guest_phys_addr;
132 	__u64 memory_size; /* bytes */
133 };
134 
135 /* for KVM_SET_USER_MEMORY_REGION */
136 struct kvm_userspace_memory_region {
137 	__u32 slot;
138 	__u32 flags;
139 	__u64 guest_phys_addr;
140 	__u64 memory_size; /* bytes */
141 	__u64 userspace_addr; /* start of the userspace allocated memory */
142 };
143 
144 /* for kvm_memory_region::flags */
145 #define KVM_MEM_LOG_DIRTY_PAGES  1UL
146 #define KVM_MEMSLOT_INVALID      (1UL << 1)
147 
148 /* for KVM_IRQ_LINE */
149 struct kvm_irq_level {
150 	/*
151 	 * ACPI gsi notion of irq.
152 	 * For IA-64 (APIC model) IOAPIC0: irq 0-23; IOAPIC1: irq 24-47..
153 	 * For X86 (standard AT mode) PIC0/1: irq 0-15. IOAPIC0: 0-23..
154 	 */
155 	union {
156 		__u32 irq;
157 		__s32 status;
158 	};
159 	__u32 level;
160 };
161 
162 
163 struct kvm_irqchip {
164 	__u32 chip_id;
165 	__u32 pad;
166         union {
167 		char dummy[512];  /* reserving space */
168 #ifdef __KVM_HAVE_PIT
169 		struct kvm_pic_state pic;
170 #endif
171 #ifdef __KVM_HAVE_IOAPIC
172 		struct kvm_ioapic_state ioapic;
173 #endif
174 	} chip;
175 };
176 
177 /* for KVM_CREATE_PIT2 */
178 struct kvm_pit_config {
179 	__u32 flags;
180 	__u32 pad[15];
181 };
182 
183 #define KVM_PIT_SPEAKER_DUMMY     1
184 
185 #define KVM_EXIT_UNKNOWN          0
186 #define KVM_EXIT_EXCEPTION        1
187 #define KVM_EXIT_IO               2
188 #define KVM_EXIT_HYPERCALL        3
189 #define KVM_EXIT_DEBUG            4
190 #define KVM_EXIT_HLT              5
191 #define KVM_EXIT_MMIO             6
192 #define KVM_EXIT_IRQ_WINDOW_OPEN  7
193 #define KVM_EXIT_SHUTDOWN         8
194 #define KVM_EXIT_FAIL_ENTRY       9
195 #define KVM_EXIT_INTR             10
196 #define KVM_EXIT_SET_TPR          11
197 #define KVM_EXIT_TPR_ACCESS       12
198 #define KVM_EXIT_S390_SIEIC       13
199 #define KVM_EXIT_S390_RESET       14
200 #define KVM_EXIT_DCR              15
201 #define KVM_EXIT_NMI              16
202 #define KVM_EXIT_INTERNAL_ERROR   17
203 
204 /* For KVM_EXIT_INTERNAL_ERROR */
205 #define KVM_INTERNAL_ERROR_EMULATION 1
206 #define KVM_INTERNAL_ERROR_SIMUL_EX 2
207 
208 /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
209 struct kvm_run {
210 	/* in */
211 	__u8 request_interrupt_window;
212 	__u8 padding1[7];
213 
214 	/* out */
215 	__u32 exit_reason;
216 	__u8 ready_for_interrupt_injection;
217 	__u8 if_flag;
218 	__u8 padding2[2];
219 
220 	/* in (pre_kvm_run), out (post_kvm_run) */
221 	__u64 cr8;
222 	__u64 apic_base;
223 
224 #ifdef __KVM_S390
225 	/* the processor status word for s390 */
226 	__u64 psw_mask; /* psw upper half */
227 	__u64 psw_addr; /* psw lower half */
228 #endif
229 	union {
230 		/* KVM_EXIT_UNKNOWN */
231 		struct {
232 			__u64 hardware_exit_reason;
233 		} hw;
234 		/* KVM_EXIT_FAIL_ENTRY */
235 		struct {
236 			__u64 hardware_entry_failure_reason;
237 		} fail_entry;
238 		/* KVM_EXIT_EXCEPTION */
239 		struct {
240 			__u32 exception;
241 			__u32 error_code;
242 		} ex;
243 		/* KVM_EXIT_IO */
244 		struct {
245 #define KVM_EXIT_IO_IN  0
246 #define KVM_EXIT_IO_OUT 1
247 			__u8 direction;
248 			__u8 size; /* bytes */
249 			__u16 port;
250 			__u32 count;
251 			__u64 data_offset; /* relative to kvm_run start */
252 		} io;
253 		struct {
254 			struct kvm_debug_exit_arch arch;
255 		} debug;
256 		/* KVM_EXIT_MMIO */
257 		struct {
258 			__u64 phys_addr;
259 			__u8  data[8];
260 			__u32 len;
261 			__u8  is_write;
262 		} mmio;
263 		/* KVM_EXIT_HYPERCALL */
264 		struct {
265 			__u64 nr;
266 			__u64 args[6];
267 			__u64 ret;
268 			__u32 longmode;
269 			__u32 pad;
270 		} hypercall;
271 		/* KVM_EXIT_TPR_ACCESS */
272 		struct {
273 			__u64 rip;
274 			__u32 is_write;
275 			__u32 pad;
276 		} tpr_access;
277 		/* KVM_EXIT_S390_SIEIC */
278 		struct {
279 			__u8 icptcode;
280 			__u16 ipa;
281 			__u32 ipb;
282 		} s390_sieic;
283 		/* KVM_EXIT_S390_RESET */
284 #define KVM_S390_RESET_POR       1
285 #define KVM_S390_RESET_CLEAR     2
286 #define KVM_S390_RESET_SUBSYSTEM 4
287 #define KVM_S390_RESET_CPU_INIT  8
288 #define KVM_S390_RESET_IPL       16
289 		__u64 s390_reset_flags;
290 		/* KVM_EXIT_DCR */
291 		struct {
292 			__u32 dcrn;
293 			__u32 data;
294 			__u8  is_write;
295 		} dcr;
296 		struct {
297 			__u32 suberror;
298 			/* Available with KVM_CAP_INTERNAL_ERROR_DATA: */
299 			__u32 ndata;
300 			__u64 data[16];
301 		} internal;
302 		/* Fix the size of the union. */
303 		char padding[256];
304 	};
305 };
306 
307 /* for KVM_REGISTER_COALESCED_MMIO / KVM_UNREGISTER_COALESCED_MMIO */
308 
309 struct kvm_coalesced_mmio_zone {
310 	__u64 addr;
311 	__u32 size;
312 	__u32 pad;
313 };
314 
315 struct kvm_coalesced_mmio {
316 	__u64 phys_addr;
317 	__u32 len;
318 	__u32 pad;
319 	__u8  data[8];
320 };
321 
322 struct kvm_coalesced_mmio_ring {
323 	__u32 first, last;
324 	struct kvm_coalesced_mmio coalesced_mmio[0];
325 };
326 
327 #define KVM_COALESCED_MMIO_MAX \
328 	((PAGE_SIZE - sizeof(struct kvm_coalesced_mmio_ring)) / \
329 	 sizeof(struct kvm_coalesced_mmio))
330 
331 /* for KVM_TRANSLATE */
332 struct kvm_translation {
333 	/* in */
334 	__u64 linear_address;
335 
336 	/* out */
337 	__u64 physical_address;
338 	__u8  valid;
339 	__u8  writeable;
340 	__u8  usermode;
341 	__u8  pad[5];
342 };
343 
344 /* for KVM_INTERRUPT */
345 struct kvm_interrupt {
346 	/* in */
347 	__u32 irq;
348 };
349 
350 /* for KVM_GET_DIRTY_LOG */
351 struct kvm_dirty_log {
352 	__u32 slot;
353 	__u32 padding1;
354 	union {
355 		void   *dirty_bitmap; /* one bit per page */
356 		__u64 padding2;
357 	};
358 };
359 
360 /* for KVM_SET_SIGNAL_MASK */
361 struct kvm_signal_mask {
362 	__u32 len;
363 	__u8  sigset[0];
364 };
365 
366 /* for KVM_TPR_ACCESS_REPORTING */
367 struct kvm_tpr_access_ctl {
368 	__u32 enabled;
369 	__u32 flags;
370 	__u32 reserved[8];
371 };
372 
373 /* for KVM_SET_VAPIC_ADDR */
374 struct kvm_vapic_addr {
375 	__u64 vapic_addr;
376 };
377 
378 /* for KVM_SET_MPSTATE */
379 
380 #define KVM_MP_STATE_RUNNABLE          0
381 #define KVM_MP_STATE_UNINITIALIZED     1
382 #define KVM_MP_STATE_INIT_RECEIVED     2
383 #define KVM_MP_STATE_HALTED            3
384 #define KVM_MP_STATE_SIPI_RECEIVED     4
385 
386 struct kvm_mp_state {
387 	__u32 mp_state;
388 };
389 
390 struct kvm_s390_psw {
391 	__u64 mask;
392 	__u64 addr;
393 };
394 
395 /* valid values for type in kvm_s390_interrupt */
396 #define KVM_S390_SIGP_STOP		0xfffe0000u
397 #define KVM_S390_PROGRAM_INT		0xfffe0001u
398 #define KVM_S390_SIGP_SET_PREFIX	0xfffe0002u
399 #define KVM_S390_RESTART		0xfffe0003u
400 #define KVM_S390_INT_VIRTIO		0xffff2603u
401 #define KVM_S390_INT_SERVICE		0xffff2401u
402 #define KVM_S390_INT_EMERGENCY		0xffff1201u
403 
404 struct kvm_s390_interrupt {
405 	__u32 type;
406 	__u32 parm;
407 	__u64 parm64;
408 };
409 
410 /* for KVM_SET_GUEST_DEBUG */
411 
412 #define KVM_GUESTDBG_ENABLE		0x00000001
413 #define KVM_GUESTDBG_SINGLESTEP		0x00000002
414 
415 struct kvm_guest_debug {
416 	__u32 control;
417 	__u32 pad;
418 	struct kvm_guest_debug_arch arch;
419 };
420 
421 enum {
422 	kvm_ioeventfd_flag_nr_datamatch,
423 	kvm_ioeventfd_flag_nr_pio,
424 	kvm_ioeventfd_flag_nr_deassign,
425 	kvm_ioeventfd_flag_nr_max,
426 };
427 
428 #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
429 #define KVM_IOEVENTFD_FLAG_PIO       (1 << kvm_ioeventfd_flag_nr_pio)
430 #define KVM_IOEVENTFD_FLAG_DEASSIGN  (1 << kvm_ioeventfd_flag_nr_deassign)
431 
432 #define KVM_IOEVENTFD_VALID_FLAG_MASK  ((1 << kvm_ioeventfd_flag_nr_max) - 1)
433 
434 struct kvm_ioeventfd {
435 	__u64 datamatch;
436 	__u64 addr;        /* legal pio/mmio address */
437 	__u32 len;         /* 1, 2, 4, or 8 bytes    */
438 	__s32 fd;
439 	__u32 flags;
440 	__u8  pad[36];
441 };
442 
443 #define KVMIO 0xAE
444 
445 /*
446  * ioctls for /dev/kvm fds:
447  */
448 #define KVM_GET_API_VERSION       _IO(KVMIO,   0x00)
449 #define KVM_CREATE_VM             _IO(KVMIO,   0x01) /* returns a VM fd */
450 #define KVM_GET_MSR_INDEX_LIST    _IOWR(KVMIO, 0x02, struct kvm_msr_list)
451 
452 #define KVM_S390_ENABLE_SIE       _IO(KVMIO,   0x06)
453 /*
454  * Check if a kvm extension is available.  Argument is extension number,
455  * return is 1 (yes) or 0 (no, sorry).
456  */
457 #define KVM_CHECK_EXTENSION       _IO(KVMIO,   0x03)
458 /*
459  * Get size for mmap(vcpu_fd)
460  */
461 #define KVM_GET_VCPU_MMAP_SIZE    _IO(KVMIO,   0x04) /* in bytes */
462 #define KVM_GET_SUPPORTED_CPUID   _IOWR(KVMIO, 0x05, struct kvm_cpuid2)
463 #define KVM_TRACE_ENABLE          __KVM_DEPRECATED_MAIN_W_0x06
464 #define KVM_TRACE_PAUSE           __KVM_DEPRECATED_MAIN_0x07
465 #define KVM_TRACE_DISABLE         __KVM_DEPRECATED_MAIN_0x08
466 
467 /*
468  * Extension capability list.
469  */
470 #define KVM_CAP_IRQCHIP	  0
471 #define KVM_CAP_HLT	  1
472 #define KVM_CAP_MMU_SHADOW_CACHE_CONTROL 2
473 #define KVM_CAP_USER_MEMORY 3
474 #define KVM_CAP_SET_TSS_ADDR 4
475 #define KVM_CAP_VAPIC 6
476 #define KVM_CAP_EXT_CPUID 7
477 #define KVM_CAP_CLOCKSOURCE 8
478 #define KVM_CAP_NR_VCPUS 9       /* returns max vcpus per vm */
479 #define KVM_CAP_NR_MEMSLOTS 10   /* returns max memory slots per vm */
480 #define KVM_CAP_PIT 11
481 #define KVM_CAP_NOP_IO_DELAY 12
482 #define KVM_CAP_PV_MMU 13
483 #define KVM_CAP_MP_STATE 14
484 #define KVM_CAP_COALESCED_MMIO 15
485 #define KVM_CAP_SYNC_MMU 16  /* Changes to host mmap are reflected in guest */
486 #ifdef __KVM_HAVE_DEVICE_ASSIGNMENT
487 #define KVM_CAP_DEVICE_ASSIGNMENT 17
488 #endif
489 #define KVM_CAP_IOMMU 18
490 #ifdef __KVM_HAVE_MSI
491 #define KVM_CAP_DEVICE_MSI 20
492 #endif
493 /* Bug in KVM_SET_USER_MEMORY_REGION fixed: */
494 #define KVM_CAP_DESTROY_MEMORY_REGION_WORKS 21
495 #ifdef __KVM_HAVE_USER_NMI
496 #define KVM_CAP_USER_NMI 22
497 #endif
498 #ifdef __KVM_HAVE_GUEST_DEBUG
499 #define KVM_CAP_SET_GUEST_DEBUG 23
500 #endif
501 #ifdef __KVM_HAVE_PIT
502 #define KVM_CAP_REINJECT_CONTROL 24
503 #endif
504 #ifdef __KVM_HAVE_IOAPIC
505 #define KVM_CAP_IRQ_ROUTING 25
506 #endif
507 #define KVM_CAP_IRQ_INJECT_STATUS 26
508 #ifdef __KVM_HAVE_DEVICE_ASSIGNMENT
509 #define KVM_CAP_DEVICE_DEASSIGNMENT 27
510 #endif
511 #ifdef __KVM_HAVE_MSIX
512 #define KVM_CAP_DEVICE_MSIX 28
513 #endif
514 #define KVM_CAP_ASSIGN_DEV_IRQ 29
515 /* Another bug in KVM_SET_USER_MEMORY_REGION fixed: */
516 #define KVM_CAP_JOIN_MEMORY_REGIONS_WORKS 30
517 #ifdef __KVM_HAVE_MCE
518 #define KVM_CAP_MCE 31
519 #endif
520 #define KVM_CAP_IRQFD 32
521 #ifdef __KVM_HAVE_PIT
522 #define KVM_CAP_PIT2 33
523 #endif
524 #define KVM_CAP_SET_BOOT_CPU_ID 34
525 #ifdef __KVM_HAVE_PIT_STATE2
526 #define KVM_CAP_PIT_STATE2 35
527 #endif
528 #define KVM_CAP_IOEVENTFD 36
529 #define KVM_CAP_SET_IDENTITY_MAP_ADDR 37
530 #ifdef __KVM_HAVE_XEN_HVM
531 #define KVM_CAP_XEN_HVM 38
532 #endif
533 #define KVM_CAP_ADJUST_CLOCK 39
534 #define KVM_CAP_INTERNAL_ERROR_DATA 40
535 #ifdef __KVM_HAVE_VCPU_EVENTS
536 #define KVM_CAP_VCPU_EVENTS 41
537 #endif
538 #define KVM_CAP_S390_PSW 42
539 #define KVM_CAP_PPC_SEGSTATE 43
540 #define KVM_CAP_HYPERV 44
541 #define KVM_CAP_HYPERV_VAPIC 45
542 #define KVM_CAP_HYPERV_SPIN 46
543 #define KVM_CAP_PCI_SEGMENT 47
544 #define KVM_CAP_X86_ROBUST_SINGLESTEP 51
545 
546 #ifdef KVM_CAP_IRQ_ROUTING
547 
548 struct kvm_irq_routing_irqchip {
549 	__u32 irqchip;
550 	__u32 pin;
551 };
552 
553 struct kvm_irq_routing_msi {
554 	__u32 address_lo;
555 	__u32 address_hi;
556 	__u32 data;
557 	__u32 pad;
558 };
559 
560 /* gsi routing entry types */
561 #define KVM_IRQ_ROUTING_IRQCHIP 1
562 #define KVM_IRQ_ROUTING_MSI 2
563 
564 struct kvm_irq_routing_entry {
565 	__u32 gsi;
566 	__u32 type;
567 	__u32 flags;
568 	__u32 pad;
569 	union {
570 		struct kvm_irq_routing_irqchip irqchip;
571 		struct kvm_irq_routing_msi msi;
572 		__u32 pad[8];
573 	} u;
574 };
575 
576 struct kvm_irq_routing {
577 	__u32 nr;
578 	__u32 flags;
579 	struct kvm_irq_routing_entry entries[0];
580 };
581 
582 #endif
583 
584 #ifdef KVM_CAP_MCE
585 /* x86 MCE */
586 struct kvm_x86_mce {
587 	__u64 status;
588 	__u64 addr;
589 	__u64 misc;
590 	__u64 mcg_status;
591 	__u8 bank;
592 	__u8 pad1[7];
593 	__u64 pad2[3];
594 };
595 #endif
596 
597 #ifdef KVM_CAP_XEN_HVM
598 struct kvm_xen_hvm_config {
599 	__u32 flags;
600 	__u32 msr;
601 	__u64 blob_addr_32;
602 	__u64 blob_addr_64;
603 	__u8 blob_size_32;
604 	__u8 blob_size_64;
605 	__u8 pad2[30];
606 };
607 #endif
608 
609 #define KVM_IRQFD_FLAG_DEASSIGN (1 << 0)
610 
611 struct kvm_irqfd {
612 	__u32 fd;
613 	__u32 gsi;
614 	__u32 flags;
615 	__u8  pad[20];
616 };
617 
618 struct kvm_clock_data {
619 	__u64 clock;
620 	__u32 flags;
621 	__u32 pad[9];
622 };
623 
624 /*
625  * ioctls for VM fds
626  */
627 #define KVM_SET_MEMORY_REGION     _IOW(KVMIO,  0x40, struct kvm_memory_region)
628 /*
629  * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns
630  * a vcpu fd.
631  */
632 #define KVM_CREATE_VCPU           _IO(KVMIO,   0x41)
633 #define KVM_GET_DIRTY_LOG         _IOW(KVMIO,  0x42, struct kvm_dirty_log)
634 #define KVM_SET_MEMORY_ALIAS      _IOW(KVMIO,  0x43, struct kvm_memory_alias)
635 #define KVM_SET_NR_MMU_PAGES      _IO(KVMIO,   0x44)
636 #define KVM_GET_NR_MMU_PAGES      _IO(KVMIO,   0x45)
637 #define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46, \
638 					struct kvm_userspace_memory_region)
639 #define KVM_SET_TSS_ADDR          _IO(KVMIO,   0x47)
640 #define KVM_SET_IDENTITY_MAP_ADDR _IOW(KVMIO,  0x48, __u64)
641 /* Device model IOC */
642 #define KVM_CREATE_IRQCHIP        _IO(KVMIO,   0x60)
643 #define KVM_IRQ_LINE              _IOW(KVMIO,  0x61, struct kvm_irq_level)
644 #define KVM_GET_IRQCHIP           _IOWR(KVMIO, 0x62, struct kvm_irqchip)
645 #define KVM_SET_IRQCHIP           _IOR(KVMIO,  0x63, struct kvm_irqchip)
646 #define KVM_CREATE_PIT            _IO(KVMIO,   0x64)
647 #define KVM_GET_PIT               _IOWR(KVMIO, 0x65, struct kvm_pit_state)
648 #define KVM_SET_PIT               _IOR(KVMIO,  0x66, struct kvm_pit_state)
649 #define KVM_IRQ_LINE_STATUS       _IOWR(KVMIO, 0x67, struct kvm_irq_level)
650 #define KVM_REGISTER_COALESCED_MMIO \
651 			_IOW(KVMIO,  0x67, struct kvm_coalesced_mmio_zone)
652 #define KVM_UNREGISTER_COALESCED_MMIO \
653 			_IOW(KVMIO,  0x68, struct kvm_coalesced_mmio_zone)
654 #define KVM_ASSIGN_PCI_DEVICE     _IOR(KVMIO,  0x69, \
655 				       struct kvm_assigned_pci_dev)
656 #define KVM_SET_GSI_ROUTING       _IOW(KVMIO,  0x6a, struct kvm_irq_routing)
657 /* deprecated, replaced by KVM_ASSIGN_DEV_IRQ */
658 #define KVM_ASSIGN_IRQ            __KVM_DEPRECATED_VM_R_0x70
659 #define KVM_ASSIGN_DEV_IRQ        _IOW(KVMIO,  0x70, struct kvm_assigned_irq)
660 #define KVM_REINJECT_CONTROL      _IO(KVMIO,   0x71)
661 #define KVM_DEASSIGN_PCI_DEVICE   _IOW(KVMIO,  0x72, \
662 				       struct kvm_assigned_pci_dev)
663 #define KVM_ASSIGN_SET_MSIX_NR    _IOW(KVMIO,  0x73, \
664 				       struct kvm_assigned_msix_nr)
665 #define KVM_ASSIGN_SET_MSIX_ENTRY _IOW(KVMIO,  0x74, \
666 				       struct kvm_assigned_msix_entry)
667 #define KVM_DEASSIGN_DEV_IRQ      _IOW(KVMIO,  0x75, struct kvm_assigned_irq)
668 #define KVM_IRQFD                 _IOW(KVMIO,  0x76, struct kvm_irqfd)
669 #define KVM_CREATE_PIT2		  _IOW(KVMIO,  0x77, struct kvm_pit_config)
670 #define KVM_SET_BOOT_CPU_ID       _IO(KVMIO,   0x78)
671 #define KVM_IOEVENTFD             _IOW(KVMIO,  0x79, struct kvm_ioeventfd)
672 #define KVM_XEN_HVM_CONFIG        _IOW(KVMIO,  0x7a, struct kvm_xen_hvm_config)
673 #define KVM_SET_CLOCK             _IOW(KVMIO,  0x7b, struct kvm_clock_data)
674 #define KVM_GET_CLOCK             _IOR(KVMIO,  0x7c, struct kvm_clock_data)
675 /* Available with KVM_CAP_PIT_STATE2 */
676 #define KVM_GET_PIT2              _IOR(KVMIO,  0x9f, struct kvm_pit_state2)
677 #define KVM_SET_PIT2              _IOW(KVMIO,  0xa0, struct kvm_pit_state2)
678 
679 /*
680  * ioctls for vcpu fds
681  */
682 #define KVM_RUN                   _IO(KVMIO,   0x80)
683 #define KVM_GET_REGS              _IOR(KVMIO,  0x81, struct kvm_regs)
684 #define KVM_SET_REGS              _IOW(KVMIO,  0x82, struct kvm_regs)
685 #define KVM_GET_SREGS             _IOR(KVMIO,  0x83, struct kvm_sregs)
686 #define KVM_SET_SREGS             _IOW(KVMIO,  0x84, struct kvm_sregs)
687 #define KVM_TRANSLATE             _IOWR(KVMIO, 0x85, struct kvm_translation)
688 #define KVM_INTERRUPT             _IOW(KVMIO,  0x86, struct kvm_interrupt)
689 /* KVM_DEBUG_GUEST is no longer supported, use KVM_SET_GUEST_DEBUG instead */
690 #define KVM_DEBUG_GUEST           __KVM_DEPRECATED_VCPU_W_0x87
691 #define KVM_GET_MSRS              _IOWR(KVMIO, 0x88, struct kvm_msrs)
692 #define KVM_SET_MSRS              _IOW(KVMIO,  0x89, struct kvm_msrs)
693 #define KVM_SET_CPUID             _IOW(KVMIO,  0x8a, struct kvm_cpuid)
694 #define KVM_SET_SIGNAL_MASK       _IOW(KVMIO,  0x8b, struct kvm_signal_mask)
695 #define KVM_GET_FPU               _IOR(KVMIO,  0x8c, struct kvm_fpu)
696 #define KVM_SET_FPU               _IOW(KVMIO,  0x8d, struct kvm_fpu)
697 #define KVM_GET_LAPIC             _IOR(KVMIO,  0x8e, struct kvm_lapic_state)
698 #define KVM_SET_LAPIC             _IOW(KVMIO,  0x8f, struct kvm_lapic_state)
699 #define KVM_SET_CPUID2            _IOW(KVMIO,  0x90, struct kvm_cpuid2)
700 #define KVM_GET_CPUID2            _IOWR(KVMIO, 0x91, struct kvm_cpuid2)
701 /* Available with KVM_CAP_VAPIC */
702 #define KVM_TPR_ACCESS_REPORTING  _IOWR(KVMIO, 0x92, struct kvm_tpr_access_ctl)
703 /* Available with KVM_CAP_VAPIC */
704 #define KVM_SET_VAPIC_ADDR        _IOW(KVMIO,  0x93, struct kvm_vapic_addr)
705 /* valid for virtual machine (for floating interrupt)_and_ vcpu */
706 #define KVM_S390_INTERRUPT        _IOW(KVMIO,  0x94, struct kvm_s390_interrupt)
707 /* store status for s390 */
708 #define KVM_S390_STORE_STATUS_NOADDR    (-1ul)
709 #define KVM_S390_STORE_STATUS_PREFIXED  (-2ul)
710 #define KVM_S390_STORE_STATUS	  _IOW(KVMIO,  0x95, unsigned long)
711 /* initial ipl psw for s390 */
712 #define KVM_S390_SET_INITIAL_PSW  _IOW(KVMIO,  0x96, struct kvm_s390_psw)
713 /* initial reset for s390 */
714 #define KVM_S390_INITIAL_RESET    _IO(KVMIO,   0x97)
715 #define KVM_GET_MP_STATE          _IOR(KVMIO,  0x98, struct kvm_mp_state)
716 #define KVM_SET_MP_STATE          _IOW(KVMIO,  0x99, struct kvm_mp_state)
717 /* Available with KVM_CAP_NMI */
718 #define KVM_NMI                   _IO(KVMIO,   0x9a)
719 /* Available with KVM_CAP_SET_GUEST_DEBUG */
720 #define KVM_SET_GUEST_DEBUG       _IOW(KVMIO,  0x9b, struct kvm_guest_debug)
721 /* MCE for x86 */
722 #define KVM_X86_SETUP_MCE         _IOW(KVMIO,  0x9c, __u64)
723 #define KVM_X86_GET_MCE_CAP_SUPPORTED _IOR(KVMIO,  0x9d, __u64)
724 #define KVM_X86_SET_MCE           _IOW(KVMIO,  0x9e, struct kvm_x86_mce)
725 /* IA64 stack access */
726 #define KVM_IA64_VCPU_GET_STACK   _IOR(KVMIO,  0x9a, void *)
727 #define KVM_IA64_VCPU_SET_STACK   _IOW(KVMIO,  0x9b, void *)
728 /* Available with KVM_CAP_VCPU_EVENTS */
729 #define KVM_GET_VCPU_EVENTS       _IOR(KVMIO,  0x9f, struct kvm_vcpu_events)
730 #define KVM_SET_VCPU_EVENTS       _IOW(KVMIO,  0xa0, struct kvm_vcpu_events)
731 
732 #define KVM_DEV_ASSIGN_ENABLE_IOMMU	(1 << 0)
733 
734 struct kvm_assigned_pci_dev {
735 	__u32 assigned_dev_id;
736 	__u32 busnr;
737 	__u32 devfn;
738 	__u32 flags;
739 	__u32 segnr;
740 	union {
741 		__u32 reserved[11];
742 	};
743 };
744 
745 #define KVM_DEV_IRQ_HOST_INTX    (1 << 0)
746 #define KVM_DEV_IRQ_HOST_MSI     (1 << 1)
747 #define KVM_DEV_IRQ_HOST_MSIX    (1 << 2)
748 
749 #define KVM_DEV_IRQ_GUEST_INTX   (1 << 8)
750 #define KVM_DEV_IRQ_GUEST_MSI    (1 << 9)
751 #define KVM_DEV_IRQ_GUEST_MSIX   (1 << 10)
752 
753 #define KVM_DEV_IRQ_HOST_MASK	 0x00ff
754 #define KVM_DEV_IRQ_GUEST_MASK   0xff00
755 
756 struct kvm_assigned_irq {
757 	__u32 assigned_dev_id;
758 	__u32 host_irq;
759 	__u32 guest_irq;
760 	__u32 flags;
761 	union {
762 		struct {
763 			__u32 addr_lo;
764 			__u32 addr_hi;
765 			__u32 data;
766 		} guest_msi;
767 		__u32 reserved[12];
768 	};
769 };
770 
771 
772 struct kvm_assigned_msix_nr {
773 	__u32 assigned_dev_id;
774 	__u16 entry_nr;
775 	__u16 padding;
776 };
777 
778 #define KVM_MAX_MSIX_PER_DEV		256
779 struct kvm_assigned_msix_entry {
780 	__u32 assigned_dev_id;
781 	__u32 gsi;
782 	__u16 entry; /* The index of entry in the MSI-X table */
783 	__u16 padding[3];
784 };
785 
786 #endif /* __LINUX_KVM_H */
787