hvhdk_mini.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Type definitions for the Microsoft Hypervisor.
  4. */
  5. #ifndef _HV_HVHDK_MINI_H
  6. #define _HV_HVHDK_MINI_H
  7. #include "hvgdk_mini.h"
  8. #define HV_MAX_CONTIGUOUS_ALLOCATION_PAGES 8
  9. /*
  10. * Doorbell connection_info flags.
  11. */
  12. #define HV_DOORBELL_FLAG_TRIGGER_SIZE_MASK 0x00000007
  13. #define HV_DOORBELL_FLAG_TRIGGER_SIZE_ANY 0x00000000
  14. #define HV_DOORBELL_FLAG_TRIGGER_SIZE_BYTE 0x00000001
  15. #define HV_DOORBELL_FLAG_TRIGGER_SIZE_WORD 0x00000002
  16. #define HV_DOORBELL_FLAG_TRIGGER_SIZE_DWORD 0x00000003
  17. #define HV_DOORBELL_FLAG_TRIGGER_SIZE_QWORD 0x00000004
  18. #define HV_DOORBELL_FLAG_TRIGGER_ANY_VALUE 0x80000000
  19. /* Each generic set contains 64 elements */
  20. #define HV_GENERIC_SET_SHIFT (6)
  21. #define HV_GENERIC_SET_MASK (63)
  22. enum hv_generic_set_format {
  23. HV_GENERIC_SET_SPARSE_4K,
  24. HV_GENERIC_SET_ALL,
  25. };
  26. #define HV_GENERIC_SET_FORMAT hv_generic_set_format
  27. enum hv_scheduler_type {
  28. HV_SCHEDULER_TYPE_LP = 1, /* Classic scheduler w/o SMT */
  29. HV_SCHEDULER_TYPE_LP_SMT = 2, /* Classic scheduler w/ SMT */
  30. HV_SCHEDULER_TYPE_CORE_SMT = 3, /* Core scheduler */
  31. HV_SCHEDULER_TYPE_ROOT = 4, /* Root / integrated scheduler */
  32. HV_SCHEDULER_TYPE_MAX
  33. };
  34. /* HV_STATS_AREA_TYPE */
  35. enum hv_stats_area_type {
  36. HV_STATS_AREA_SELF = 0,
  37. HV_STATS_AREA_PARENT = 1,
  38. HV_STATS_AREA_INTERNAL = 2,
  39. HV_STATS_AREA_COUNT
  40. };
  41. enum hv_stats_object_type {
  42. HV_STATS_OBJECT_HYPERVISOR = 0x00000001,
  43. HV_STATS_OBJECT_LOGICAL_PROCESSOR = 0x00000002,
  44. HV_STATS_OBJECT_PARTITION = 0x00010001,
  45. HV_STATS_OBJECT_VP = 0x00010002
  46. };
  47. union hv_stats_object_identity {
  48. /* hv_stats_hypervisor */
  49. struct {
  50. u8 reserved[15];
  51. u8 stats_area_type;
  52. } __packed hv;
  53. /* hv_stats_logical_processor */
  54. struct {
  55. u32 lp_index;
  56. u8 reserved[11];
  57. u8 stats_area_type;
  58. } __packed lp;
  59. /* hv_stats_partition */
  60. struct {
  61. u64 partition_id;
  62. u8 reserved[7];
  63. u8 stats_area_type;
  64. } __packed partition;
  65. /* hv_stats_vp */
  66. struct {
  67. u64 partition_id;
  68. u32 vp_index;
  69. u16 flags;
  70. u8 reserved;
  71. u8 stats_area_type;
  72. } __packed vp;
  73. };
  74. enum hv_partition_property_code {
  75. /* Privilege properties */
  76. HV_PARTITION_PROPERTY_PRIVILEGE_FLAGS = 0x00010000,
  77. HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES = 0x00010001,
  78. /* Integrated scheduling properties */
  79. HV_PARTITION_PROPERTY_INTEGRATED_SCHEDULER_ENABLED = 0x00020005,
  80. /* Resource properties */
  81. HV_PARTITION_PROPERTY_GPA_PAGE_ACCESS_TRACKING = 0x00050005,
  82. HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION = 0x00050017,
  83. /* Compatibility properties */
  84. HV_PARTITION_PROPERTY_PROCESSOR_XSAVE_FEATURES = 0x00060002,
  85. HV_PARTITION_PROPERTY_XSAVE_STATES = 0x00060007,
  86. HV_PARTITION_PROPERTY_MAX_XSAVE_DATA_SIZE = 0x00060008,
  87. HV_PARTITION_PROPERTY_PROCESSOR_CLOCK_FREQUENCY = 0x00060009,
  88. /* Extended properties with larger property values */
  89. HV_PARTITION_PROPERTY_VMM_CAPABILITIES = 0x00090007,
  90. };
  91. #define HV_PARTITION_VMM_CAPABILITIES_BANK_COUNT 1
  92. #define HV_PARTITION_VMM_CAPABILITIES_RESERVED_BITFIELD_COUNT 57
  93. struct hv_partition_property_vmm_capabilities {
  94. u16 bank_count;
  95. u16 reserved[3];
  96. union {
  97. u64 as_uint64[HV_PARTITION_VMM_CAPABILITIES_BANK_COUNT];
  98. struct {
  99. u64 map_gpa_preserve_adjustable: 1;
  100. u64 vmm_can_provide_overlay_gpfn: 1;
  101. u64 vp_affinity_property: 1;
  102. #if IS_ENABLED(CONFIG_ARM64)
  103. u64 vmm_can_provide_gic_overlay_locations: 1;
  104. #else
  105. u64 reservedbit3: 1;
  106. #endif
  107. u64 assignable_synthetic_proc_features: 1;
  108. u64 reservedbit5: 1;
  109. u64 vmm_enable_integrated_scheduler : 1;
  110. u64 reserved0: HV_PARTITION_VMM_CAPABILITIES_RESERVED_BITFIELD_COUNT;
  111. } __packed;
  112. };
  113. } __packed;
  114. enum hv_snp_status {
  115. HV_SNP_STATUS_NONE = 0,
  116. HV_SNP_STATUS_AVAILABLE = 1,
  117. HV_SNP_STATUS_INCOMPATIBLE = 2,
  118. HV_SNP_STATUS_PSP_UNAVAILABLE = 3,
  119. HV_SNP_STATUS_PSP_INIT_FAILED = 4,
  120. HV_SNP_STATUS_PSP_BAD_FW_VERSION = 5,
  121. HV_SNP_STATUS_BAD_CONFIGURATION = 6,
  122. HV_SNP_STATUS_PSP_FW_UPDATE_IN_PROGRESS = 7,
  123. HV_SNP_STATUS_PSP_RB_INIT_FAILED = 8,
  124. HV_SNP_STATUS_PSP_PLATFORM_STATUS_FAILED = 9,
  125. HV_SNP_STATUS_PSP_INIT_LATE_FAILED = 10,
  126. };
  127. enum hv_system_property {
  128. /* Add more values when needed */
  129. HV_SYSTEM_PROPERTY_SLEEP_STATE = 3,
  130. HV_SYSTEM_PROPERTY_SCHEDULER_TYPE = 15,
  131. HV_DYNAMIC_PROCESSOR_FEATURE_PROPERTY = 21,
  132. HV_SYSTEM_PROPERTY_CRASHDUMPAREA = 47,
  133. };
  134. #define HV_PFN_RANGE_PGBITS 24 /* HV_SPA_PAGE_RANGE_ADDITIONAL_PAGES_BITS */
  135. union hv_pfn_range { /* HV_SPA_PAGE_RANGE */
  136. u64 as_uint64;
  137. struct {
  138. /* 39:0: base pfn. 63:40: additional pages */
  139. u64 base_pfn : 64 - HV_PFN_RANGE_PGBITS;
  140. u64 add_pfns : HV_PFN_RANGE_PGBITS;
  141. } __packed;
  142. };
  143. enum hv_sleep_state {
  144. HV_SLEEP_STATE_S1 = 1,
  145. HV_SLEEP_STATE_S2 = 2,
  146. HV_SLEEP_STATE_S3 = 3,
  147. HV_SLEEP_STATE_S4 = 4,
  148. HV_SLEEP_STATE_S5 = 5,
  149. /*
  150. * After hypervisor has received this, any follow up sleep
  151. * state registration requests will be rejected.
  152. */
  153. HV_SLEEP_STATE_LOCK = 6
  154. };
  155. enum hv_dynamic_processor_feature_property {
  156. /* Add more values when needed */
  157. HV_X64_DYNAMIC_PROCESSOR_FEATURE_MAX_ENCRYPTED_PARTITIONS = 13,
  158. HV_X64_DYNAMIC_PROCESSOR_FEATURE_SNP_STATUS = 16,
  159. };
  160. struct hv_input_get_system_property {
  161. u32 property_id; /* enum hv_system_property */
  162. union {
  163. u32 as_uint32;
  164. #if IS_ENABLED(CONFIG_X86)
  165. /* enum hv_dynamic_processor_feature_property */
  166. u32 hv_processor_feature;
  167. #endif
  168. /* More fields to be filled in when needed */
  169. };
  170. } __packed;
  171. struct hv_output_get_system_property {
  172. union {
  173. u32 scheduler_type; /* enum hv_scheduler_type */
  174. #if IS_ENABLED(CONFIG_X86)
  175. u64 hv_processor_feature_value;
  176. #endif
  177. union hv_pfn_range hv_cda_info; /* CrashdumpAreaAddress */
  178. u64 hv_tramp_pa; /* CrashdumpTrampolineAddress */
  179. };
  180. } __packed;
  181. struct hv_sleep_state_info {
  182. u32 sleep_state; /* enum hv_sleep_state */
  183. u8 pm1a_slp_typ;
  184. u8 pm1b_slp_typ;
  185. } __packed;
  186. struct hv_input_set_system_property {
  187. u32 property_id; /* enum hv_system_property */
  188. u32 reserved;
  189. union {
  190. /* More fields to be filled in when needed */
  191. struct hv_sleep_state_info set_sleep_state_info;
  192. /*
  193. * Add a reserved field to ensure the union is 8-byte aligned as
  194. * existing members may not be. This is a temporary measure
  195. * until all remaining members are added.
  196. */
  197. u64 reserved0[8];
  198. };
  199. } __packed;
  200. struct hv_input_enter_sleep_state { /* HV_INPUT_ENTER_SLEEP_STATE */
  201. u32 sleep_state; /* enum hv_sleep_state */
  202. } __packed;
  203. struct hv_input_map_stats_page {
  204. u32 type; /* enum hv_stats_object_type */
  205. u32 padding;
  206. union hv_stats_object_identity identity;
  207. } __packed;
  208. struct hv_input_map_stats_page2 {
  209. u32 type; /* enum hv_stats_object_type */
  210. u32 padding;
  211. union hv_stats_object_identity identity;
  212. u64 map_location;
  213. } __packed;
  214. struct hv_output_map_stats_page {
  215. u64 map_location;
  216. } __packed;
  217. struct hv_input_unmap_stats_page {
  218. u32 type; /* enum hv_stats_object_type */
  219. u32 padding;
  220. union hv_stats_object_identity identity;
  221. } __packed;
  222. struct hv_proximity_domain_flags {
  223. u32 proximity_preferred : 1;
  224. u32 reserved : 30;
  225. u32 proximity_info_valid : 1;
  226. } __packed;
  227. struct hv_proximity_domain_info {
  228. u32 domain_id;
  229. struct hv_proximity_domain_flags flags;
  230. } __packed;
  231. /* HvDepositMemory hypercall */
  232. struct hv_deposit_memory { /* HV_INPUT_DEPOSIT_MEMORY */
  233. u64 partition_id;
  234. u64 gpa_page_list[];
  235. } __packed;
  236. struct hv_input_withdraw_memory {
  237. u64 partition_id;
  238. struct hv_proximity_domain_info proximity_domain_info;
  239. } __packed;
  240. struct hv_output_withdraw_memory {
  241. DECLARE_FLEX_ARRAY(u64, gpa_page_list);
  242. } __packed;
  243. /* HV Map GPA (Guest Physical Address) Flags */
  244. #define HV_MAP_GPA_PERMISSIONS_NONE 0x0
  245. #define HV_MAP_GPA_READABLE 0x1
  246. #define HV_MAP_GPA_WRITABLE 0x2
  247. #define HV_MAP_GPA_KERNEL_EXECUTABLE 0x4
  248. #define HV_MAP_GPA_USER_EXECUTABLE 0x8
  249. #define HV_MAP_GPA_EXECUTABLE 0xC
  250. #define HV_MAP_GPA_PERMISSIONS_MASK 0xF
  251. #define HV_MAP_GPA_ADJUSTABLE 0x8000
  252. #define HV_MAP_GPA_NO_ACCESS 0x10000
  253. #define HV_MAP_GPA_NOT_CACHED 0x200000
  254. #define HV_MAP_GPA_LARGE_PAGE 0x80000000
  255. struct hv_input_map_gpa_pages {
  256. u64 target_partition_id;
  257. u64 target_gpa_base;
  258. u32 map_flags;
  259. u32 padding;
  260. u64 source_gpa_page_list[];
  261. } __packed;
  262. union hv_gpa_page_access_state_flags {
  263. struct {
  264. u64 clear_accessed : 1;
  265. u64 set_accessed : 1;
  266. u64 clear_dirty : 1;
  267. u64 set_dirty : 1;
  268. u64 reserved : 60;
  269. } __packed;
  270. u64 as_uint64;
  271. };
  272. struct hv_input_get_gpa_pages_access_state {
  273. u64 partition_id;
  274. union hv_gpa_page_access_state_flags flags;
  275. u64 hv_gpa_page_number;
  276. } __packed;
  277. union hv_gpa_page_access_state {
  278. struct {
  279. u8 accessed : 1;
  280. u8 dirty : 1;
  281. u8 reserved: 6;
  282. };
  283. u8 as_uint8;
  284. } __packed;
  285. enum hv_crashdump_action {
  286. HV_CRASHDUMP_NONE = 0,
  287. HV_CRASHDUMP_SUSPEND_ALL_VPS,
  288. HV_CRASHDUMP_PREPARE_FOR_STATE_SAVE,
  289. HV_CRASHDUMP_STATE_SAVED,
  290. HV_CRASHDUMP_ENTRY,
  291. };
  292. struct hv_partition_event_root_crashdump_input {
  293. u32 crashdump_action; /* enum hv_crashdump_action */
  294. } __packed;
  295. struct hv_input_disable_hyp_ex { /* HV_X64_INPUT_DISABLE_HYPERVISOR_EX */
  296. u64 rip;
  297. u64 arg;
  298. } __packed;
  299. struct hv_crashdump_area { /* HV_CRASHDUMP_AREA */
  300. u32 version;
  301. union {
  302. u32 flags_as_uint32;
  303. struct {
  304. u32 cda_valid : 1;
  305. u32 cda_unused : 31;
  306. } __packed;
  307. };
  308. /* more unused fields */
  309. } __packed;
  310. union hv_partition_event_input {
  311. struct hv_partition_event_root_crashdump_input crashdump_input;
  312. };
  313. enum hv_partition_event {
  314. HV_PARTITION_EVENT_ROOT_CRASHDUMP = 2,
  315. };
  316. struct hv_input_notify_partition_event {
  317. u32 event; /* enum hv_partition_event */
  318. union hv_partition_event_input input;
  319. } __packed;
  320. struct hv_lp_startup_status {
  321. u64 hv_status;
  322. u64 substatus1;
  323. u64 substatus2;
  324. u64 substatus3;
  325. u64 substatus4;
  326. u64 substatus5;
  327. u64 substatus6;
  328. } __packed;
  329. struct hv_input_add_logical_processor {
  330. u32 lp_index;
  331. u32 apic_id;
  332. struct hv_proximity_domain_info proximity_domain_info;
  333. } __packed;
  334. struct hv_output_add_logical_processor {
  335. struct hv_lp_startup_status startup_status;
  336. } __packed;
  337. enum { /* HV_SUBNODE_TYPE */
  338. HV_SUBNODE_ANY = 0,
  339. HV_SUBNODE_SOCKET,
  340. HV_SUBNODE_CLUSTER,
  341. HV_SUBNODE_L3,
  342. HV_SUBNODE_COUNT,
  343. HV_SUBNODE_INVALID = -1
  344. };
  345. struct hv_create_vp { /* HV_INPUT_CREATE_VP */
  346. u64 partition_id;
  347. u32 vp_index;
  348. u8 padding[3];
  349. u8 subnode_type;
  350. u64 subnode_id;
  351. struct hv_proximity_domain_info proximity_domain_info;
  352. u64 flags;
  353. } __packed;
  354. /* HV_INTERRUPT_TRIGGER_MODE */
  355. enum hv_interrupt_trigger_mode {
  356. HV_INTERRUPT_TRIGGER_MODE_EDGE = 0,
  357. HV_INTERRUPT_TRIGGER_MODE_LEVEL = 1,
  358. };
  359. /* HV_DEVICE_INTERRUPT_DESCRIPTOR */
  360. struct hv_device_interrupt_descriptor {
  361. u32 interrupt_type;
  362. u32 trigger_mode;
  363. u32 vector_count;
  364. u32 reserved;
  365. struct hv_device_interrupt_target target;
  366. } __packed;
  367. /* HV_INPUT_MAP_DEVICE_INTERRUPT */
  368. struct hv_input_map_device_interrupt {
  369. u64 partition_id;
  370. u64 device_id;
  371. u32 flags;
  372. u32 base_irt_idx;
  373. struct hv_interrupt_entry logical_interrupt_entry;
  374. struct hv_device_interrupt_descriptor interrupt_descriptor;
  375. } __packed;
  376. /* HV_OUTPUT_MAP_DEVICE_INTERRUPT */
  377. struct hv_output_map_device_interrupt {
  378. struct hv_interrupt_entry interrupt_entry;
  379. u64 ext_status_deprecated[5];
  380. } __packed;
  381. /* HV_INPUT_UNMAP_DEVICE_INTERRUPT */
  382. struct hv_input_unmap_device_interrupt {
  383. u64 partition_id;
  384. u64 device_id;
  385. struct hv_interrupt_entry interrupt_entry;
  386. u32 flags;
  387. } __packed;
  388. #define HV_SOURCE_SHADOW_NONE 0x0
  389. #define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE 0x1
  390. struct hv_send_ipi_ex { /* HV_INPUT_SEND_SYNTHETIC_CLUSTER_IPI_EX */
  391. u32 vector;
  392. u32 reserved;
  393. struct hv_vpset vp_set;
  394. } __packed;
  395. typedef u16 hv_pci_rid; /* HV_PCI_RID */
  396. typedef u16 hv_pci_segment; /* HV_PCI_SEGMENT */
  397. typedef u64 hv_logical_device_id;
  398. union hv_pci_bdf { /* HV_PCI_BDF */
  399. u16 as_uint16;
  400. struct {
  401. u8 function : 3;
  402. u8 device : 5;
  403. u8 bus;
  404. };
  405. } __packed;
  406. union hv_pci_bus_range {
  407. u16 as_uint16;
  408. struct {
  409. u8 subordinate_bus;
  410. u8 secondary_bus;
  411. };
  412. } __packed;
  413. enum hv_device_type { /* HV_DEVICE_TYPE */
  414. HV_DEVICE_TYPE_LOGICAL = 0,
  415. HV_DEVICE_TYPE_PCI = 1,
  416. HV_DEVICE_TYPE_IOAPIC = 2,
  417. HV_DEVICE_TYPE_ACPI = 3,
  418. };
  419. union hv_device_id { /* HV_DEVICE_ID */
  420. u64 as_uint64;
  421. struct {
  422. u64 reserved0 : 62;
  423. u64 device_type : 2;
  424. };
  425. /* HV_DEVICE_TYPE_LOGICAL */
  426. struct {
  427. u64 id : 62;
  428. u64 device_type : 2;
  429. } logical;
  430. /* HV_DEVICE_TYPE_PCI */
  431. struct {
  432. union {
  433. hv_pci_rid rid;
  434. union hv_pci_bdf bdf;
  435. };
  436. hv_pci_segment segment;
  437. union hv_pci_bus_range shadow_bus_range;
  438. u16 phantom_function_bits : 2;
  439. u16 source_shadow : 1;
  440. u16 rsvdz0 : 11;
  441. u16 device_type : 2;
  442. } pci;
  443. /* HV_DEVICE_TYPE_IOAPIC */
  444. struct {
  445. u8 ioapic_id;
  446. u8 rsvdz0;
  447. u16 rsvdz1;
  448. u16 rsvdz2;
  449. u16 rsvdz3 : 14;
  450. u16 device_type : 2;
  451. } ioapic;
  452. /* HV_DEVICE_TYPE_ACPI */
  453. struct {
  454. u32 input_mapping_base;
  455. u32 input_mapping_count : 30;
  456. u32 device_type : 2;
  457. } acpi;
  458. } __packed;
  459. #endif /* _HV_HVHDK_MINI_H */