H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_KVM_H |
| 2 | #define _ASM_X86_KVM_H |
Jerone Young | f6a40e3 | 2007-11-19 17:06:31 -0600 | [diff] [blame] | 3 | |
| 4 | /* |
| 5 | * KVM x86 specific structures and definitions |
| 6 | * |
| 7 | */ |
| 8 | |
Jaswinder Singh Rajput | cef3767 | 2009-01-30 22:46:08 +0530 | [diff] [blame] | 9 | #include <linux/types.h> |
Jerone Young | f6a40e3 | 2007-11-19 17:06:31 -0600 | [diff] [blame] | 10 | #include <linux/ioctl.h> |
| 11 | |
Xiao Guangrong | 26bf264 | 2012-09-17 16:31:13 +0800 | [diff] [blame] | 12 | #define DE_VECTOR 0 |
| 13 | #define DB_VECTOR 1 |
| 14 | #define BP_VECTOR 3 |
| 15 | #define OF_VECTOR 4 |
| 16 | #define BR_VECTOR 5 |
| 17 | #define UD_VECTOR 6 |
| 18 | #define NM_VECTOR 7 |
| 19 | #define DF_VECTOR 8 |
| 20 | #define TS_VECTOR 10 |
| 21 | #define NP_VECTOR 11 |
| 22 | #define SS_VECTOR 12 |
| 23 | #define GP_VECTOR 13 |
| 24 | #define PF_VECTOR 14 |
| 25 | #define MF_VECTOR 16 |
Nadav Amit | c9cdd08 | 2014-07-21 14:37:24 +0300 | [diff] [blame] | 26 | #define AC_VECTOR 17 |
Xiao Guangrong | 26bf264 | 2012-09-17 16:31:13 +0800 | [diff] [blame] | 27 | #define MC_VECTOR 18 |
Nadav Amit | c9cdd08 | 2014-07-21 14:37:24 +0300 | [diff] [blame] | 28 | #define XM_VECTOR 19 |
| 29 | #define VE_VECTOR 20 |
Xiao Guangrong | 26bf264 | 2012-09-17 16:31:13 +0800 | [diff] [blame] | 30 | |
Avi Kivity | 7a0eb19 | 2009-01-19 14:57:52 +0200 | [diff] [blame] | 31 | /* Select x86 specific features in <linux/kvm.h> */ |
| 32 | #define __KVM_HAVE_PIT |
| 33 | #define __KVM_HAVE_IOAPIC |
Christoffer Dall | a1e4ccb | 2012-06-15 15:07:13 -0400 | [diff] [blame] | 34 | #define __KVM_HAVE_IRQ_LINE |
Avi Kivity | 7a0eb19 | 2009-01-19 14:57:52 +0200 | [diff] [blame] | 35 | #define __KVM_HAVE_MSI |
| 36 | #define __KVM_HAVE_USER_NMI |
Avi Kivity | 91b2ae7 | 2009-01-19 14:57:52 +0200 | [diff] [blame] | 37 | #define __KVM_HAVE_GUEST_DEBUG |
Sheng Yang | d510d6c | 2009-02-25 17:22:28 +0800 | [diff] [blame] | 38 | #define __KVM_HAVE_MSIX |
Huang Ying | 890ca9a | 2009-05-11 16:48:15 +0800 | [diff] [blame] | 39 | #define __KVM_HAVE_MCE |
Beth Kon | e9f4275 | 2009-07-07 11:50:38 -0400 | [diff] [blame] | 40 | #define __KVM_HAVE_PIT_STATE2 |
Ed Swierk | ffde22a | 2009-10-15 15:21:43 -0700 | [diff] [blame] | 41 | #define __KVM_HAVE_XEN_HVM |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 42 | #define __KVM_HAVE_VCPU_EVENTS |
Jan Kiszka | a1efbe7 | 2010-02-15 10:45:43 +0100 | [diff] [blame] | 43 | #define __KVM_HAVE_DEBUGREGS |
Sheng Yang | 2d5b5a6 | 2010-06-13 17:29:39 +0800 | [diff] [blame] | 44 | #define __KVM_HAVE_XSAVE |
| 45 | #define __KVM_HAVE_XCRS |
Xiao Guangrong | 4d8b81a | 2012-08-21 11:02:51 +0800 | [diff] [blame] | 46 | #define __KVM_HAVE_READONLY_MEM |
Avi Kivity | 7a0eb19 | 2009-01-19 14:57:52 +0200 | [diff] [blame] | 47 | |
Jerone Young | 244d57e | 2007-11-19 17:06:36 -0600 | [diff] [blame] | 48 | /* Architectural interrupt line count. */ |
| 49 | #define KVM_NR_INTERRUPTS 256 |
| 50 | |
Jerone Young | f6a40e3 | 2007-11-19 17:06:31 -0600 | [diff] [blame] | 51 | struct kvm_memory_alias { |
| 52 | __u32 slot; /* this has a different namespace than memory slots */ |
| 53 | __u32 flags; |
| 54 | __u64 guest_phys_addr; |
| 55 | __u64 memory_size; |
| 56 | __u64 target_phys_addr; |
| 57 | }; |
| 58 | |
Jerone Young | da1386a | 2007-11-19 17:06:32 -0600 | [diff] [blame] | 59 | /* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */ |
| 60 | struct kvm_pic_state { |
| 61 | __u8 last_irr; /* edge detection */ |
| 62 | __u8 irr; /* interrupt request register */ |
| 63 | __u8 imr; /* interrupt mask register */ |
| 64 | __u8 isr; /* interrupt service register */ |
| 65 | __u8 priority_add; /* highest irq priority */ |
| 66 | __u8 irq_base; |
| 67 | __u8 read_reg_select; |
| 68 | __u8 poll; |
| 69 | __u8 special_mask; |
| 70 | __u8 init_state; |
| 71 | __u8 auto_eoi; |
| 72 | __u8 rotate_on_auto_eoi; |
| 73 | __u8 special_fully_nested_mode; |
| 74 | __u8 init4; /* true if 4 byte init */ |
| 75 | __u8 elcr; /* PIIX edge/trigger selection */ |
| 76 | __u8 elcr_mask; |
| 77 | }; |
| 78 | |
| 79 | #define KVM_IOAPIC_NUM_PINS 24 |
| 80 | struct kvm_ioapic_state { |
| 81 | __u64 base_address; |
| 82 | __u32 ioregsel; |
| 83 | __u32 id; |
| 84 | __u32 irr; |
| 85 | __u32 pad; |
| 86 | union { |
| 87 | __u64 bits; |
| 88 | struct { |
| 89 | __u8 vector; |
| 90 | __u8 delivery_mode:3; |
| 91 | __u8 dest_mode:1; |
| 92 | __u8 delivery_status:1; |
| 93 | __u8 polarity:1; |
| 94 | __u8 remote_irr:1; |
| 95 | __u8 trig_mode:1; |
| 96 | __u8 mask:1; |
| 97 | __u8 reserve:7; |
| 98 | __u8 reserved[4]; |
| 99 | __u8 dest_id; |
| 100 | } fields; |
| 101 | } redirtbl[KVM_IOAPIC_NUM_PINS]; |
| 102 | }; |
| 103 | |
| 104 | #define KVM_IRQCHIP_PIC_MASTER 0 |
| 105 | #define KVM_IRQCHIP_PIC_SLAVE 1 |
| 106 | #define KVM_IRQCHIP_IOAPIC 2 |
Gleb Natapov | 3e71f88 | 2009-08-24 11:54:21 +0300 | [diff] [blame] | 107 | #define KVM_NR_IRQCHIPS 3 |
Jerone Young | da1386a | 2007-11-19 17:06:32 -0600 | [diff] [blame] | 108 | |
Paolo Bonzini | f077825 | 2015-04-01 15:06:40 +0200 | [diff] [blame] | 109 | #define KVM_RUN_X86_SMM (1 << 0) |
| 110 | |
Jerone Young | 19d30b1 | 2007-11-19 17:06:33 -0600 | [diff] [blame] | 111 | /* for KVM_GET_REGS and KVM_SET_REGS */ |
| 112 | struct kvm_regs { |
| 113 | /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ |
| 114 | __u64 rax, rbx, rcx, rdx; |
| 115 | __u64 rsi, rdi, rsp, rbp; |
| 116 | __u64 r8, r9, r10, r11; |
| 117 | __u64 r12, r13, r14, r15; |
| 118 | __u64 rip, rflags; |
| 119 | }; |
| 120 | |
Jerone Young | d9ecf92 | 2007-11-19 17:06:34 -0600 | [diff] [blame] | 121 | /* for KVM_GET_LAPIC and KVM_SET_LAPIC */ |
| 122 | #define KVM_APIC_REG_SIZE 0x400 |
| 123 | struct kvm_lapic_state { |
| 124 | char regs[KVM_APIC_REG_SIZE]; |
| 125 | }; |
| 126 | |
Jerone Young | 3a56b20 | 2007-11-19 17:06:35 -0600 | [diff] [blame] | 127 | struct kvm_segment { |
| 128 | __u64 base; |
| 129 | __u32 limit; |
| 130 | __u16 selector; |
| 131 | __u8 type; |
| 132 | __u8 present, dpl, db, s, l, g, avl; |
| 133 | __u8 unusable; |
| 134 | __u8 padding; |
| 135 | }; |
| 136 | |
| 137 | struct kvm_dtable { |
| 138 | __u64 base; |
| 139 | __u16 limit; |
| 140 | __u16 padding[3]; |
| 141 | }; |
| 142 | |
| 143 | |
Jerone Young | 244d57e | 2007-11-19 17:06:36 -0600 | [diff] [blame] | 144 | /* for KVM_GET_SREGS and KVM_SET_SREGS */ |
| 145 | struct kvm_sregs { |
| 146 | /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */ |
| 147 | struct kvm_segment cs, ds, es, fs, gs, ss; |
| 148 | struct kvm_segment tr, ldt; |
| 149 | struct kvm_dtable gdt, idt; |
| 150 | __u64 cr0, cr2, cr3, cr4, cr8; |
| 151 | __u64 efer; |
| 152 | __u64 apic_base; |
| 153 | __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64]; |
| 154 | }; |
| 155 | |
Christian Ehrhardt | 6f723c7 | 2008-01-08 08:04:50 +0100 | [diff] [blame] | 156 | /* for KVM_GET_FPU and KVM_SET_FPU */ |
| 157 | struct kvm_fpu { |
| 158 | __u8 fpr[8][16]; |
| 159 | __u16 fcw; |
| 160 | __u16 fsw; |
| 161 | __u8 ftwx; /* in fxsave format */ |
| 162 | __u8 pad1; |
| 163 | __u16 last_opcode; |
| 164 | __u64 last_ip; |
| 165 | __u64 last_dp; |
| 166 | __u8 xmm[16][16]; |
| 167 | __u32 mxcsr; |
| 168 | __u32 pad2; |
| 169 | }; |
| 170 | |
Jerone Young | 244d57e | 2007-11-19 17:06:36 -0600 | [diff] [blame] | 171 | struct kvm_msr_entry { |
| 172 | __u32 index; |
| 173 | __u32 reserved; |
| 174 | __u64 data; |
| 175 | }; |
| 176 | |
| 177 | /* for KVM_GET_MSRS and KVM_SET_MSRS */ |
| 178 | struct kvm_msrs { |
| 179 | __u32 nmsrs; /* number of msrs in entries */ |
| 180 | __u32 pad; |
| 181 | |
| 182 | struct kvm_msr_entry entries[0]; |
| 183 | }; |
| 184 | |
| 185 | /* for KVM_GET_MSR_INDEX_LIST */ |
| 186 | struct kvm_msr_list { |
| 187 | __u32 nmsrs; /* number of msrs in entries */ |
| 188 | __u32 indices[0]; |
| 189 | }; |
| 190 | |
| 191 | |
Jerone Young | a162dd5 | 2007-11-19 17:06:37 -0600 | [diff] [blame] | 192 | struct kvm_cpuid_entry { |
| 193 | __u32 function; |
| 194 | __u32 eax; |
| 195 | __u32 ebx; |
| 196 | __u32 ecx; |
| 197 | __u32 edx; |
| 198 | __u32 padding; |
| 199 | }; |
| 200 | |
| 201 | /* for KVM_SET_CPUID */ |
| 202 | struct kvm_cpuid { |
| 203 | __u32 nent; |
| 204 | __u32 padding; |
| 205 | struct kvm_cpuid_entry entries[0]; |
| 206 | }; |
| 207 | |
Dan Kenigsberg | 0771671 | 2007-11-21 17:10:04 +0200 | [diff] [blame] | 208 | struct kvm_cpuid_entry2 { |
| 209 | __u32 function; |
| 210 | __u32 index; |
| 211 | __u32 flags; |
| 212 | __u32 eax; |
| 213 | __u32 ebx; |
| 214 | __u32 ecx; |
| 215 | __u32 edx; |
| 216 | __u32 padding[3]; |
| 217 | }; |
| 218 | |
Borislav Petkov | 3dbe345 | 2016-05-05 10:18:23 +0200 | [diff] [blame^] | 219 | #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX (1 << 0) |
| 220 | #define KVM_CPUID_FLAG_STATEFUL_FUNC (1 << 1) |
| 221 | #define KVM_CPUID_FLAG_STATE_READ_NEXT (1 << 2) |
Dan Kenigsberg | 0771671 | 2007-11-21 17:10:04 +0200 | [diff] [blame] | 222 | |
| 223 | /* for KVM_SET_CPUID2 */ |
| 224 | struct kvm_cpuid2 { |
| 225 | __u32 nent; |
| 226 | __u32 padding; |
| 227 | struct kvm_cpuid_entry2 entries[0]; |
| 228 | }; |
Jerone Young | a162dd5 | 2007-11-19 17:06:37 -0600 | [diff] [blame] | 229 | |
Sheng Yang | e0f63cb | 2008-03-04 00:50:59 +0800 | [diff] [blame] | 230 | /* for KVM_GET_PIT and KVM_SET_PIT */ |
| 231 | struct kvm_pit_channel_state { |
| 232 | __u32 count; /* can be 65536 */ |
| 233 | __u16 latched_count; |
| 234 | __u8 count_latched; |
| 235 | __u8 status_latched; |
| 236 | __u8 status; |
| 237 | __u8 read_state; |
| 238 | __u8 write_state; |
| 239 | __u8 write_latch; |
| 240 | __u8 rw_mode; |
| 241 | __u8 mode; |
| 242 | __u8 bcd; |
| 243 | __u8 gate; |
| 244 | __s64 count_load_time; |
| 245 | }; |
| 246 | |
Jan Kiszka | d0bfb94 | 2008-12-15 13:52:10 +0100 | [diff] [blame] | 247 | struct kvm_debug_exit_arch { |
| 248 | __u32 exception; |
| 249 | __u32 pad; |
| 250 | __u64 pc; |
| 251 | __u64 dr6; |
| 252 | __u64 dr7; |
| 253 | }; |
| 254 | |
| 255 | #define KVM_GUESTDBG_USE_SW_BP 0x00010000 |
| 256 | #define KVM_GUESTDBG_USE_HW_BP 0x00020000 |
| 257 | #define KVM_GUESTDBG_INJECT_DB 0x00040000 |
| 258 | #define KVM_GUESTDBG_INJECT_BP 0x00080000 |
| 259 | |
| 260 | /* for KVM_SET_GUEST_DEBUG */ |
| 261 | struct kvm_guest_debug_arch { |
| 262 | __u64 debugreg[8]; |
| 263 | }; |
| 264 | |
Sheng Yang | e0f63cb | 2008-03-04 00:50:59 +0800 | [diff] [blame] | 265 | struct kvm_pit_state { |
| 266 | struct kvm_pit_channel_state channels[3]; |
| 267 | }; |
Marcelo Tosatti | 52d939a | 2008-12-30 15:55:06 -0200 | [diff] [blame] | 268 | |
Beth Kon | e9f4275 | 2009-07-07 11:50:38 -0400 | [diff] [blame] | 269 | #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001 |
| 270 | |
| 271 | struct kvm_pit_state2 { |
| 272 | struct kvm_pit_channel_state channels[3]; |
| 273 | __u32 flags; |
| 274 | __u32 reserved[9]; |
| 275 | }; |
| 276 | |
Marcelo Tosatti | 52d939a | 2008-12-30 15:55:06 -0200 | [diff] [blame] | 277 | struct kvm_reinject_control { |
| 278 | __u8 pit_reinject; |
| 279 | __u8 reserved[31]; |
| 280 | }; |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 281 | |
Jan Kiszka | dab4b91 | 2009-12-06 18:24:15 +0100 | [diff] [blame] | 282 | /* When set in flags, include corresponding fields on KVM_SET_VCPU_EVENTS */ |
| 283 | #define KVM_VCPUEVENT_VALID_NMI_PENDING 0x00000001 |
| 284 | #define KVM_VCPUEVENT_VALID_SIPI_VECTOR 0x00000002 |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 285 | #define KVM_VCPUEVENT_VALID_SHADOW 0x00000004 |
Paolo Bonzini | f077825 | 2015-04-01 15:06:40 +0200 | [diff] [blame] | 286 | #define KVM_VCPUEVENT_VALID_SMM 0x00000008 |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 287 | |
| 288 | /* Interrupt shadow states */ |
| 289 | #define KVM_X86_SHADOW_INT_MOV_SS 0x01 |
| 290 | #define KVM_X86_SHADOW_INT_STI 0x02 |
Jan Kiszka | dab4b91 | 2009-12-06 18:24:15 +0100 | [diff] [blame] | 291 | |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 292 | /* for KVM_GET/SET_VCPU_EVENTS */ |
| 293 | struct kvm_vcpu_events { |
| 294 | struct { |
| 295 | __u8 injected; |
| 296 | __u8 nr; |
| 297 | __u8 has_error_code; |
| 298 | __u8 pad; |
| 299 | __u32 error_code; |
| 300 | } exception; |
| 301 | struct { |
| 302 | __u8 injected; |
| 303 | __u8 nr; |
| 304 | __u8 soft; |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 305 | __u8 shadow; |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 306 | } interrupt; |
| 307 | struct { |
| 308 | __u8 injected; |
| 309 | __u8 pending; |
| 310 | __u8 masked; |
| 311 | __u8 pad; |
| 312 | } nmi; |
| 313 | __u32 sipi_vector; |
| 314 | __u32 flags; |
Paolo Bonzini | f077825 | 2015-04-01 15:06:40 +0200 | [diff] [blame] | 315 | struct { |
| 316 | __u8 smm; |
| 317 | __u8 pending; |
| 318 | __u8 smm_inside_nmi; |
| 319 | __u8 latched_init; |
| 320 | } smi; |
| 321 | __u32 reserved[9]; |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 322 | }; |
| 323 | |
Jan Kiszka | a1efbe7 | 2010-02-15 10:45:43 +0100 | [diff] [blame] | 324 | /* for KVM_GET/SET_DEBUGREGS */ |
| 325 | struct kvm_debugregs { |
| 326 | __u64 db[4]; |
| 327 | __u64 dr6; |
| 328 | __u64 dr7; |
| 329 | __u64 flags; |
| 330 | __u64 reserved[9]; |
| 331 | }; |
| 332 | |
Sheng Yang | 2d5b5a6 | 2010-06-13 17:29:39 +0800 | [diff] [blame] | 333 | /* for KVM_CAP_XSAVE */ |
| 334 | struct kvm_xsave { |
| 335 | __u32 region[1024]; |
| 336 | }; |
| 337 | |
| 338 | #define KVM_MAX_XCRS 16 |
| 339 | |
| 340 | struct kvm_xcr { |
| 341 | __u32 xcr; |
| 342 | __u32 reserved; |
| 343 | __u64 value; |
| 344 | }; |
| 345 | |
| 346 | struct kvm_xcrs { |
| 347 | __u32 nr_xcrs; |
| 348 | __u32 flags; |
| 349 | struct kvm_xcr xcrs[KVM_MAX_XCRS]; |
| 350 | __u64 padding[16]; |
| 351 | }; |
| 352 | |
Christian Borntraeger | b9e5dc8 | 2012-01-11 11:20:30 +0100 | [diff] [blame] | 353 | /* definition of registers in kvm_run */ |
| 354 | struct kvm_sync_regs { |
| 355 | }; |
| 356 | |
Paolo Bonzini | 0da029e | 2015-07-23 08:24:42 +0200 | [diff] [blame] | 357 | #define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0) |
| 358 | #define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1) |
Nadav Amit | 90de4a1 | 2015-04-13 01:53:41 +0300 | [diff] [blame] | 359 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 360 | #endif /* _ASM_X86_KVM_H */ |