Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 1 | #ifndef __LINUX_KVM_H |
| 2 | #define __LINUX_KVM_H |
| 3 | |
| 4 | /* |
| 5 | * Userspace interface for /dev/kvm - kernel based virtual machine |
| 6 | * |
Rusty Russell | dea8cae | 2007-07-17 23:12:26 +1000 | [diff] [blame] | 7 | * Note: you must update KVM_API_VERSION if you change this interface. |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <asm/types.h> |
| 11 | #include <linux/ioctl.h> |
Jerone Young | f6a40e3 | 2007-11-19 17:06:31 -0600 | [diff] [blame] | 12 | #include <asm/kvm.h> |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 13 | |
Avi Kivity | 2ff81f7 | 2007-04-29 16:25:49 +0300 | [diff] [blame] | 14 | #define KVM_API_VERSION 12 |
Avi Kivity | 0b76e20 | 2006-12-22 01:06:02 -0800 | [diff] [blame] | 15 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 16 | /* for KVM_CREATE_MEMORY_REGION */ |
| 17 | struct kvm_memory_region { |
| 18 | __u32 slot; |
| 19 | __u32 flags; |
| 20 | __u64 guest_phys_addr; |
| 21 | __u64 memory_size; /* bytes */ |
| 22 | }; |
| 23 | |
Izik Eidus | 6fc138d | 2007-10-09 19:20:39 +0200 | [diff] [blame] | 24 | /* for KVM_SET_USER_MEMORY_REGION */ |
| 25 | struct kvm_userspace_memory_region { |
| 26 | __u32 slot; |
| 27 | __u32 flags; |
| 28 | __u64 guest_phys_addr; |
| 29 | __u64 memory_size; /* bytes */ |
| 30 | __u64 userspace_addr; /* start of the userspace allocated memory */ |
| 31 | }; |
| 32 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 33 | /* for kvm_memory_region::flags */ |
| 34 | #define KVM_MEM_LOG_DIRTY_PAGES 1UL |
| 35 | |
| 36 | |
Eddie Dong | 97222cc | 2007-09-12 10:58:04 +0300 | [diff] [blame] | 37 | /* for KVM_IRQ_LINE */ |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 38 | struct kvm_irq_level { |
| 39 | /* |
| 40 | * ACPI gsi notion of irq. |
| 41 | * For IA-64 (APIC model) IOAPIC0: irq 0-23; IOAPIC1: irq 24-47.. |
| 42 | * For X86 (standard AT mode) PIC0/1: irq 0-15. IOAPIC0: 0-23.. |
| 43 | */ |
| 44 | __u32 irq; |
| 45 | __u32 level; |
| 46 | }; |
| 47 | |
He, Qing | 6ceb9d7 | 2007-07-26 11:05:18 +0300 | [diff] [blame] | 48 | |
| 49 | struct kvm_irqchip { |
| 50 | __u32 chip_id; |
| 51 | __u32 pad; |
| 52 | union { |
| 53 | char dummy[512]; /* reserving space */ |
Jerone Young | 51e2962 | 2007-11-26 08:33:53 -0600 | [diff] [blame] | 54 | #ifdef CONFIG_X86 |
He, Qing | 6ceb9d7 | 2007-07-26 11:05:18 +0300 | [diff] [blame] | 55 | struct kvm_pic_state pic; |
Zhang Xiantao | ec10f47 | 2007-12-17 20:27:27 +0800 | [diff] [blame] | 56 | #endif |
| 57 | #if defined(CONFIG_X86) || defined(CONFIG_IA64) |
He, Qing | 6bf9e96 | 2007-08-05 10:49:16 +0300 | [diff] [blame] | 58 | struct kvm_ioapic_state ioapic; |
Jerone Young | 51e2962 | 2007-11-26 08:33:53 -0600 | [diff] [blame] | 59 | #endif |
He, Qing | 6ceb9d7 | 2007-07-26 11:05:18 +0300 | [diff] [blame] | 60 | } chip; |
| 61 | }; |
| 62 | |
Avi Kivity | 8a45450 | 2007-10-10 14:03:16 +0200 | [diff] [blame] | 63 | #define KVM_EXIT_UNKNOWN 0 |
| 64 | #define KVM_EXIT_EXCEPTION 1 |
| 65 | #define KVM_EXIT_IO 2 |
| 66 | #define KVM_EXIT_HYPERCALL 3 |
| 67 | #define KVM_EXIT_DEBUG 4 |
| 68 | #define KVM_EXIT_HLT 5 |
| 69 | #define KVM_EXIT_MMIO 6 |
| 70 | #define KVM_EXIT_IRQ_WINDOW_OPEN 7 |
| 71 | #define KVM_EXIT_SHUTDOWN 8 |
| 72 | #define KVM_EXIT_FAIL_ENTRY 9 |
| 73 | #define KVM_EXIT_INTR 10 |
| 74 | #define KVM_EXIT_SET_TPR 11 |
Avi Kivity | b209749f | 2007-10-22 16:50:39 +0200 | [diff] [blame] | 75 | #define KVM_EXIT_TPR_ACCESS 12 |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 76 | |
Avi Kivity | 9a2bb7f | 2007-02-22 12:58:31 +0200 | [diff] [blame] | 77 | /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 78 | struct kvm_run { |
| 79 | /* in */ |
Dor Laor | c1150d8 | 2007-01-05 16:36:24 -0800 | [diff] [blame] | 80 | __u8 request_interrupt_window; |
Avi Kivity | 02c8320 | 2007-04-29 15:02:17 +0300 | [diff] [blame] | 81 | __u8 padding1[7]; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 82 | |
| 83 | /* out */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 84 | __u32 exit_reason; |
Dor Laor | c1150d8 | 2007-01-05 16:36:24 -0800 | [diff] [blame] | 85 | __u8 ready_for_interrupt_injection; |
| 86 | __u8 if_flag; |
Avi Kivity | 2ff81f7 | 2007-04-29 16:25:49 +0300 | [diff] [blame] | 87 | __u8 padding2[2]; |
Dor Laor | 5481034 | 2007-02-12 00:54:39 -0800 | [diff] [blame] | 88 | |
| 89 | /* in (pre_kvm_run), out (post_kvm_run) */ |
Dor Laor | c1150d8 | 2007-01-05 16:36:24 -0800 | [diff] [blame] | 90 | __u64 cr8; |
| 91 | __u64 apic_base; |
| 92 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 93 | union { |
| 94 | /* KVM_EXIT_UNKNOWN */ |
| 95 | struct { |
Avi Kivity | 8eb7d33 | 2007-03-04 14:17:08 +0200 | [diff] [blame] | 96 | __u64 hardware_exit_reason; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 97 | } hw; |
Avi Kivity | 8eb7d33 | 2007-03-04 14:17:08 +0200 | [diff] [blame] | 98 | /* KVM_EXIT_FAIL_ENTRY */ |
| 99 | struct { |
| 100 | __u64 hardware_entry_failure_reason; |
| 101 | } fail_entry; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 102 | /* KVM_EXIT_EXCEPTION */ |
| 103 | struct { |
| 104 | __u32 exception; |
| 105 | __u32 error_code; |
| 106 | } ex; |
| 107 | /* KVM_EXIT_IO */ |
Avi Kivity | 46fc147 | 2007-02-22 19:39:30 +0200 | [diff] [blame] | 108 | struct kvm_io { |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 109 | #define KVM_EXIT_IO_IN 0 |
| 110 | #define KVM_EXIT_IO_OUT 1 |
| 111 | __u8 direction; |
| 112 | __u8 size; /* bytes */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 113 | __u16 port; |
Avi Kivity | 039576c | 2007-03-20 12:46:50 +0200 | [diff] [blame] | 114 | __u32 count; |
| 115 | __u64 data_offset; /* relative to kvm_run start */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 116 | } io; |
| 117 | struct { |
| 118 | } debug; |
| 119 | /* KVM_EXIT_MMIO */ |
| 120 | struct { |
| 121 | __u64 phys_addr; |
| 122 | __u8 data[8]; |
| 123 | __u32 len; |
| 124 | __u8 is_write; |
| 125 | } mmio; |
Avi Kivity | b4e63f5 | 2007-03-04 13:59:30 +0200 | [diff] [blame] | 126 | /* KVM_EXIT_HYPERCALL */ |
| 127 | struct { |
Jeff Dike | 519ef35 | 2007-07-16 15:24:47 -0400 | [diff] [blame] | 128 | __u64 nr; |
Avi Kivity | b4e63f5 | 2007-03-04 13:59:30 +0200 | [diff] [blame] | 129 | __u64 args[6]; |
| 130 | __u64 ret; |
| 131 | __u32 longmode; |
| 132 | __u32 pad; |
| 133 | } hypercall; |
Avi Kivity | b209749f | 2007-10-22 16:50:39 +0200 | [diff] [blame] | 134 | /* KVM_EXIT_TPR_ACCESS */ |
| 135 | struct { |
| 136 | __u64 rip; |
| 137 | __u32 is_write; |
| 138 | __u32 pad; |
| 139 | } tpr_access; |
Avi Kivity | 24cbc7e | 2007-07-17 11:45:55 +0300 | [diff] [blame] | 140 | /* Fix the size of the union. */ |
| 141 | char padding[256]; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 142 | }; |
| 143 | }; |
| 144 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 145 | /* for KVM_TRANSLATE */ |
| 146 | struct kvm_translation { |
| 147 | /* in */ |
| 148 | __u64 linear_address; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 149 | |
| 150 | /* out */ |
| 151 | __u64 physical_address; |
| 152 | __u8 valid; |
| 153 | __u8 writeable; |
| 154 | __u8 usermode; |
Avi Kivity | 8cd1330 | 2007-02-12 00:54:41 -0800 | [diff] [blame] | 155 | __u8 pad[5]; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | /* for KVM_INTERRUPT */ |
| 159 | struct kvm_interrupt { |
| 160 | /* in */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 161 | __u32 irq; |
| 162 | }; |
| 163 | |
| 164 | struct kvm_breakpoint { |
| 165 | __u32 enabled; |
| 166 | __u32 padding; |
| 167 | __u64 address; |
| 168 | }; |
| 169 | |
| 170 | /* for KVM_DEBUG_GUEST */ |
| 171 | struct kvm_debug_guest { |
| 172 | /* int */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 173 | __u32 enabled; |
Avi Kivity | bccf215 | 2007-02-21 18:04:26 +0200 | [diff] [blame] | 174 | __u32 pad; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 175 | struct kvm_breakpoint breakpoints[4]; |
| 176 | __u32 singlestep; |
| 177 | }; |
| 178 | |
| 179 | /* for KVM_GET_DIRTY_LOG */ |
| 180 | struct kvm_dirty_log { |
| 181 | __u32 slot; |
| 182 | __u32 padding; |
| 183 | union { |
| 184 | void __user *dirty_bitmap; /* one bit per page */ |
| 185 | __u64 padding; |
| 186 | }; |
| 187 | }; |
| 188 | |
Avi Kivity | 1961d27 | 2007-03-05 19:46:05 +0200 | [diff] [blame] | 189 | /* for KVM_SET_SIGNAL_MASK */ |
| 190 | struct kvm_signal_mask { |
| 191 | __u32 len; |
| 192 | __u8 sigset[0]; |
| 193 | }; |
| 194 | |
Avi Kivity | b209749f | 2007-10-22 16:50:39 +0200 | [diff] [blame] | 195 | /* for KVM_TPR_ACCESS_REPORTING */ |
| 196 | struct kvm_tpr_access_ctl { |
| 197 | __u32 enabled; |
| 198 | __u32 flags; |
| 199 | __u32 reserved[8]; |
| 200 | }; |
| 201 | |
Avi Kivity | b93463a | 2007-10-25 16:52:32 +0200 | [diff] [blame] | 202 | /* for KVM_SET_VAPIC_ADDR */ |
| 203 | struct kvm_vapic_addr { |
| 204 | __u64 vapic_addr; |
| 205 | }; |
| 206 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 207 | #define KVMIO 0xAE |
| 208 | |
Avi Kivity | f17abe9 | 2007-02-21 19:28:04 +0200 | [diff] [blame] | 209 | /* |
| 210 | * ioctls for /dev/kvm fds: |
| 211 | */ |
Avi Kivity | 739872c | 2007-03-01 17:20:13 +0200 | [diff] [blame] | 212 | #define KVM_GET_API_VERSION _IO(KVMIO, 0x00) |
| 213 | #define KVM_CREATE_VM _IO(KVMIO, 0x01) /* returns a VM fd */ |
| 214 | #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list) |
Avi Kivity | 5d308f4 | 2007-03-01 17:56:20 +0200 | [diff] [blame] | 215 | /* |
| 216 | * Check if a kvm extension is available. Argument is extension number, |
| 217 | * return is 1 (yes) or 0 (no, sorry). |
| 218 | */ |
| 219 | #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03) |
Avi Kivity | 07c45a3 | 2007-03-07 13:05:38 +0200 | [diff] [blame] | 220 | /* |
| 221 | * Get size for mmap(vcpu_fd) |
| 222 | */ |
| 223 | #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */ |
Avi Kivity | 674eea0 | 2008-02-11 18:37:23 +0200 | [diff] [blame] | 224 | #define KVM_GET_SUPPORTED_CPUID _IOWR(KVMIO, 0x05, struct kvm_cpuid2) |
Avi Kivity | f17abe9 | 2007-02-21 19:28:04 +0200 | [diff] [blame] | 225 | |
| 226 | /* |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 227 | * Extension capability list. |
| 228 | */ |
| 229 | #define KVM_CAP_IRQCHIP 0 |
Eddie Dong | b6958ce | 2007-07-18 12:15:21 +0300 | [diff] [blame] | 230 | #define KVM_CAP_HLT 1 |
Izik Eidus | 82ce2c9 | 2007-10-02 18:52:55 +0200 | [diff] [blame] | 231 | #define KVM_CAP_MMU_SHADOW_CACHE_CONTROL 2 |
Izik Eidus | 6fc138d | 2007-10-09 19:20:39 +0200 | [diff] [blame] | 232 | #define KVM_CAP_USER_MEMORY 3 |
Izik Eidus | cbc9402 | 2007-10-25 00:29:55 +0200 | [diff] [blame] | 233 | #define KVM_CAP_SET_TSS_ADDR 4 |
Avi Kivity | b209749f | 2007-10-22 16:50:39 +0200 | [diff] [blame] | 234 | #define KVM_CAP_VAPIC 6 |
Avi Kivity | 674eea0 | 2008-02-11 18:37:23 +0200 | [diff] [blame] | 235 | #define KVM_CAP_EXT_CPUID 7 |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 236 | |
| 237 | /* |
Avi Kivity | f17abe9 | 2007-02-21 19:28:04 +0200 | [diff] [blame] | 238 | * ioctls for VM fds |
| 239 | */ |
Avi Kivity | 739872c | 2007-03-01 17:20:13 +0200 | [diff] [blame] | 240 | #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region) |
Izik Eidus | 82ce2c9 | 2007-10-02 18:52:55 +0200 | [diff] [blame] | 241 | #define KVM_SET_NR_MMU_PAGES _IO(KVMIO, 0x44) |
| 242 | #define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45) |
Izik Eidus | 6fc138d | 2007-10-09 19:20:39 +0200 | [diff] [blame] | 243 | #define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46,\ |
| 244 | struct kvm_userspace_memory_region) |
Izik Eidus | cbc9402 | 2007-10-25 00:29:55 +0200 | [diff] [blame] | 245 | #define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47) |
Avi Kivity | bccf215 | 2007-02-21 18:04:26 +0200 | [diff] [blame] | 246 | /* |
| 247 | * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns |
| 248 | * a vcpu fd. |
| 249 | */ |
Avi Kivity | 739872c | 2007-03-01 17:20:13 +0200 | [diff] [blame] | 250 | #define KVM_CREATE_VCPU _IO(KVMIO, 0x41) |
| 251 | #define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log) |
Avi Kivity | e820754 | 2007-03-30 16:54:30 +0300 | [diff] [blame] | 252 | #define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias) |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 253 | /* Device model IOC */ |
| 254 | #define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60) |
Eddie Dong | 97222cc | 2007-09-12 10:58:04 +0300 | [diff] [blame] | 255 | #define KVM_IRQ_LINE _IOW(KVMIO, 0x61, struct kvm_irq_level) |
He, Qing | 6ceb9d7 | 2007-07-26 11:05:18 +0300 | [diff] [blame] | 256 | #define KVM_GET_IRQCHIP _IOWR(KVMIO, 0x62, struct kvm_irqchip) |
| 257 | #define KVM_SET_IRQCHIP _IOR(KVMIO, 0x63, struct kvm_irqchip) |
Avi Kivity | bccf215 | 2007-02-21 18:04:26 +0200 | [diff] [blame] | 258 | |
| 259 | /* |
| 260 | * ioctls for vcpu fds |
| 261 | */ |
Avi Kivity | 739872c | 2007-03-01 17:20:13 +0200 | [diff] [blame] | 262 | #define KVM_RUN _IO(KVMIO, 0x80) |
| 263 | #define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs) |
| 264 | #define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs) |
| 265 | #define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs) |
| 266 | #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs) |
| 267 | #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation) |
| 268 | #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt) |
| 269 | #define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest) |
| 270 | #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs) |
| 271 | #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs) |
| 272 | #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid) |
Avi Kivity | 1961d27 | 2007-03-05 19:46:05 +0200 | [diff] [blame] | 273 | #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask) |
Avi Kivity | b883673 | 2007-04-01 16:34:31 +0300 | [diff] [blame] | 274 | #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu) |
| 275 | #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu) |
Eddie Dong | 96ad2cc | 2007-09-06 12:22:56 +0300 | [diff] [blame] | 276 | #define KVM_GET_LAPIC _IOR(KVMIO, 0x8e, struct kvm_lapic_state) |
| 277 | #define KVM_SET_LAPIC _IOW(KVMIO, 0x8f, struct kvm_lapic_state) |
Dan Kenigsberg | 0771671 | 2007-11-21 17:10:04 +0200 | [diff] [blame] | 278 | #define KVM_SET_CPUID2 _IOW(KVMIO, 0x90, struct kvm_cpuid2) |
| 279 | #define KVM_GET_CPUID2 _IOWR(KVMIO, 0x91, struct kvm_cpuid2) |
Avi Kivity | b209749f | 2007-10-22 16:50:39 +0200 | [diff] [blame] | 280 | /* Available with KVM_CAP_VAPIC */ |
| 281 | #define KVM_TPR_ACCESS_REPORTING _IOWR(KVMIO, 0x92, struct kvm_tpr_access_ctl) |
Avi Kivity | b93463a | 2007-10-25 16:52:32 +0200 | [diff] [blame] | 282 | /* Available with KVM_CAP_VAPIC */ |
| 283 | #define KVM_SET_VAPIC_ADDR _IOW(KVMIO, 0x93, struct kvm_vapic_addr) |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 284 | |
| 285 | #endif |