kvm.h 6.8 KB

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