hyperv-tlfs.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * This file contains definitions from Hyper-V Hypervisor Top-Level Functional
  4. * Specification (TLFS):
  5. * https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs
  6. */
  7. #ifndef _ASM_GENERIC_HYPERV_TLFS_H
  8. #define _ASM_GENERIC_HYPERV_TLFS_H
  9. #include <linux/types.h>
  10. #include <linux/bits.h>
  11. #include <linux/time64.h>
  12. /*
  13. * While not explicitly listed in the TLFS, Hyper-V always runs with a page size
  14. * of 4096. These definitions are used when communicating with Hyper-V using
  15. * guest physical pages and guest physical page addresses, since the guest page
  16. * size may not be 4096 on all architectures.
  17. */
  18. #define HV_HYP_PAGE_SHIFT 12
  19. #define HV_HYP_PAGE_SIZE BIT(HV_HYP_PAGE_SHIFT)
  20. #define HV_HYP_PAGE_MASK (~(HV_HYP_PAGE_SIZE - 1))
  21. /*
  22. * Hyper-V provides two categories of flags relevant to guest VMs. The
  23. * "Features" category indicates specific functionality that is available
  24. * to guests on this particular instance of Hyper-V. The "Features"
  25. * are presented in four groups, each of which is 32 bits. The group A
  26. * and B definitions are common across architectures and are listed here.
  27. * However, not all flags are relevant on all architectures.
  28. *
  29. * Groups C and D vary across architectures and are listed in the
  30. * architecture specific portion of hyperv-tlfs.h. Some of these flags exist
  31. * on multiple architectures, but the bit positions are different so they
  32. * cannot appear in the generic portion of hyperv-tlfs.h.
  33. *
  34. * The "Enlightenments" category provides recommendations on whether to use
  35. * specific enlightenments that are available. The Enlighenments are a single
  36. * group of 32 bits, but they vary across architectures and are listed in
  37. * the architecture specific portion of hyperv-tlfs.h.
  38. */
  39. /*
  40. * Group A Features.
  41. */
  42. /* VP Runtime register available */
  43. #define HV_MSR_VP_RUNTIME_AVAILABLE BIT(0)
  44. /* Partition Reference Counter available*/
  45. #define HV_MSR_TIME_REF_COUNT_AVAILABLE BIT(1)
  46. /* Basic SynIC register available */
  47. #define HV_MSR_SYNIC_AVAILABLE BIT(2)
  48. /* Synthetic Timer registers available */
  49. #define HV_MSR_SYNTIMER_AVAILABLE BIT(3)
  50. /* Virtual APIC assist and VP assist page registers available */
  51. #define HV_MSR_APIC_ACCESS_AVAILABLE BIT(4)
  52. /* Hypercall and Guest OS ID registers available*/
  53. #define HV_MSR_HYPERCALL_AVAILABLE BIT(5)
  54. /* Access virtual processor index register available*/
  55. #define HV_MSR_VP_INDEX_AVAILABLE BIT(6)
  56. /* Virtual system reset register available*/
  57. #define HV_MSR_RESET_AVAILABLE BIT(7)
  58. /* Access statistics page registers available */
  59. #define HV_MSR_STAT_PAGES_AVAILABLE BIT(8)
  60. /* Partition reference TSC register is available */
  61. #define HV_MSR_REFERENCE_TSC_AVAILABLE BIT(9)
  62. /* Partition Guest IDLE register is available */
  63. #define HV_MSR_GUEST_IDLE_AVAILABLE BIT(10)
  64. /* Partition local APIC and TSC frequency registers available */
  65. #define HV_ACCESS_FREQUENCY_MSRS BIT(11)
  66. /* AccessReenlightenmentControls privilege */
  67. #define HV_ACCESS_REENLIGHTENMENT BIT(13)
  68. /* AccessTscInvariantControls privilege */
  69. #define HV_ACCESS_TSC_INVARIANT BIT(15)
  70. /*
  71. * Group B features.
  72. */
  73. #define HV_CREATE_PARTITIONS BIT(0)
  74. #define HV_ACCESS_PARTITION_ID BIT(1)
  75. #define HV_ACCESS_MEMORY_POOL BIT(2)
  76. #define HV_ADJUST_MESSAGE_BUFFERS BIT(3)
  77. #define HV_POST_MESSAGES BIT(4)
  78. #define HV_SIGNAL_EVENTS BIT(5)
  79. #define HV_CREATE_PORT BIT(6)
  80. #define HV_CONNECT_PORT BIT(7)
  81. #define HV_ACCESS_STATS BIT(8)
  82. #define HV_DEBUGGING BIT(11)
  83. #define HV_CPU_MANAGEMENT BIT(12)
  84. #define HV_ENABLE_EXTENDED_HYPERCALLS BIT(20)
  85. #define HV_ISOLATION BIT(22)
  86. /*
  87. * TSC page layout.
  88. */
  89. struct ms_hyperv_tsc_page {
  90. volatile u32 tsc_sequence;
  91. u32 reserved1;
  92. volatile u64 tsc_scale;
  93. volatile s64 tsc_offset;
  94. } __packed;
  95. union hv_reference_tsc_msr {
  96. u64 as_uint64;
  97. struct {
  98. u64 enable:1;
  99. u64 reserved:11;
  100. u64 pfn:52;
  101. } __packed;
  102. };
  103. /*
  104. * The guest OS needs to register the guest ID with the hypervisor.
  105. * The guest ID is a 64 bit entity and the structure of this ID is
  106. * specified in the Hyper-V specification:
  107. *
  108. * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
  109. *
  110. * While the current guideline does not specify how Linux guest ID(s)
  111. * need to be generated, our plan is to publish the guidelines for
  112. * Linux and other guest operating systems that currently are hosted
  113. * on Hyper-V. The implementation here conforms to this yet
  114. * unpublished guidelines.
  115. *
  116. *
  117. * Bit(s)
  118. * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
  119. * 62:56 - Os Type; Linux is 0x100
  120. * 55:48 - Distro specific identification
  121. * 47:16 - Linux kernel version number
  122. * 15:0 - Distro specific identification
  123. *
  124. *
  125. */
  126. #define HV_LINUX_VENDOR_ID 0x8100
  127. /*
  128. * Crash notification flags.
  129. */
  130. #define HV_CRASH_CTL_CRASH_NOTIFY_MSG BIT_ULL(62)
  131. #define HV_CRASH_CTL_CRASH_NOTIFY BIT_ULL(63)
  132. /* Declare the various hypercall operations. */
  133. #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002
  134. #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003
  135. #define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008
  136. #define HVCALL_SEND_IPI 0x000b
  137. #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013
  138. #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014
  139. #define HVCALL_SEND_IPI_EX 0x0015
  140. #define HVCALL_GET_PARTITION_ID 0x0046
  141. #define HVCALL_DEPOSIT_MEMORY 0x0048
  142. #define HVCALL_CREATE_VP 0x004e
  143. #define HVCALL_GET_VP_REGISTERS 0x0050
  144. #define HVCALL_SET_VP_REGISTERS 0x0051
  145. #define HVCALL_POST_MESSAGE 0x005c
  146. #define HVCALL_SIGNAL_EVENT 0x005d
  147. #define HVCALL_POST_DEBUG_DATA 0x0069
  148. #define HVCALL_RETRIEVE_DEBUG_DATA 0x006a
  149. #define HVCALL_RESET_DEBUG_SESSION 0x006b
  150. #define HVCALL_ADD_LOGICAL_PROCESSOR 0x0076
  151. #define HVCALL_MAP_DEVICE_INTERRUPT 0x007c
  152. #define HVCALL_UNMAP_DEVICE_INTERRUPT 0x007d
  153. #define HVCALL_RETARGET_INTERRUPT 0x007e
  154. #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af
  155. #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0
  156. #define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db
  157. /* Extended hypercalls */
  158. #define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001
  159. #define HV_EXT_CALL_MEMORY_HEAT_HINT 0x8003
  160. #define HV_FLUSH_ALL_PROCESSORS BIT(0)
  161. #define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES BIT(1)
  162. #define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY BIT(2)
  163. #define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT BIT(3)
  164. /* Extended capability bits */
  165. #define HV_EXT_CAPABILITY_MEMORY_COLD_DISCARD_HINT BIT(8)
  166. enum HV_GENERIC_SET_FORMAT {
  167. HV_GENERIC_SET_SPARSE_4K,
  168. HV_GENERIC_SET_ALL,
  169. };
  170. #define HV_PARTITION_ID_SELF ((u64)-1)
  171. #define HV_VP_INDEX_SELF ((u32)-2)
  172. #define HV_HYPERCALL_RESULT_MASK GENMASK_ULL(15, 0)
  173. #define HV_HYPERCALL_FAST_BIT BIT(16)
  174. #define HV_HYPERCALL_VARHEAD_OFFSET 17
  175. #define HV_HYPERCALL_VARHEAD_MASK GENMASK_ULL(26, 17)
  176. #define HV_HYPERCALL_RSVD0_MASK GENMASK_ULL(31, 27)
  177. #define HV_HYPERCALL_REP_COMP_OFFSET 32
  178. #define HV_HYPERCALL_REP_COMP_1 BIT_ULL(32)
  179. #define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32)
  180. #define HV_HYPERCALL_RSVD1_MASK GENMASK_ULL(47, 44)
  181. #define HV_HYPERCALL_REP_START_OFFSET 48
  182. #define HV_HYPERCALL_REP_START_MASK GENMASK_ULL(59, 48)
  183. #define HV_HYPERCALL_RSVD2_MASK GENMASK_ULL(63, 60)
  184. #define HV_HYPERCALL_RSVD_MASK (HV_HYPERCALL_RSVD0_MASK | \
  185. HV_HYPERCALL_RSVD1_MASK | \
  186. HV_HYPERCALL_RSVD2_MASK)
  187. /* hypercall status code */
  188. #define HV_STATUS_SUCCESS 0
  189. #define HV_STATUS_INVALID_HYPERCALL_CODE 2
  190. #define HV_STATUS_INVALID_HYPERCALL_INPUT 3
  191. #define HV_STATUS_INVALID_ALIGNMENT 4
  192. #define HV_STATUS_INVALID_PARAMETER 5
  193. #define HV_STATUS_ACCESS_DENIED 6
  194. #define HV_STATUS_OPERATION_DENIED 8
  195. #define HV_STATUS_INSUFFICIENT_MEMORY 11
  196. #define HV_STATUS_INVALID_PORT_ID 17
  197. #define HV_STATUS_INVALID_CONNECTION_ID 18
  198. #define HV_STATUS_INSUFFICIENT_BUFFERS 19
  199. /*
  200. * The Hyper-V TimeRefCount register and the TSC
  201. * page provide a guest VM clock with 100ns tick rate
  202. */
  203. #define HV_CLOCK_HZ (NSEC_PER_SEC/100)
  204. /* Define the number of synthetic interrupt sources. */
  205. #define HV_SYNIC_SINT_COUNT (16)
  206. /* Define the expected SynIC version. */
  207. #define HV_SYNIC_VERSION_1 (0x1)
  208. /* Valid SynIC vectors are 16-255. */
  209. #define HV_SYNIC_FIRST_VALID_VECTOR (16)
  210. #define HV_SYNIC_CONTROL_ENABLE (1ULL << 0)
  211. #define HV_SYNIC_SIMP_ENABLE (1ULL << 0)
  212. #define HV_SYNIC_SIEFP_ENABLE (1ULL << 0)
  213. #define HV_SYNIC_SINT_MASKED (1ULL << 16)
  214. #define HV_SYNIC_SINT_AUTO_EOI (1ULL << 17)
  215. #define HV_SYNIC_SINT_VECTOR_MASK (0xFF)
  216. #define HV_SYNIC_STIMER_COUNT (4)
  217. /* Define synthetic interrupt controller message constants. */
  218. #define HV_MESSAGE_SIZE (256)
  219. #define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240)
  220. #define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30)
  221. /*
  222. * Define hypervisor message types. Some of the message types
  223. * are x86/x64 specific, but there's no good way to separate
  224. * them out into the arch-specific version of hyperv-tlfs.h
  225. * because C doesn't provide a way to extend enum types.
  226. * Keeping them all in the arch neutral hyperv-tlfs.h seems
  227. * the least messy compromise.
  228. */
  229. enum hv_message_type {
  230. HVMSG_NONE = 0x00000000,
  231. /* Memory access messages. */
  232. HVMSG_UNMAPPED_GPA = 0x80000000,
  233. HVMSG_GPA_INTERCEPT = 0x80000001,
  234. /* Timer notification messages. */
  235. HVMSG_TIMER_EXPIRED = 0x80000010,
  236. /* Error messages. */
  237. HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020,
  238. HVMSG_UNRECOVERABLE_EXCEPTION = 0x80000021,
  239. HVMSG_UNSUPPORTED_FEATURE = 0x80000022,
  240. /* Trace buffer complete messages. */
  241. HVMSG_EVENTLOG_BUFFERCOMPLETE = 0x80000040,
  242. /* Platform-specific processor intercept messages. */
  243. HVMSG_X64_IOPORT_INTERCEPT = 0x80010000,
  244. HVMSG_X64_MSR_INTERCEPT = 0x80010001,
  245. HVMSG_X64_CPUID_INTERCEPT = 0x80010002,
  246. HVMSG_X64_EXCEPTION_INTERCEPT = 0x80010003,
  247. HVMSG_X64_APIC_EOI = 0x80010004,
  248. HVMSG_X64_LEGACY_FP_ERROR = 0x80010005
  249. };
  250. /* Define synthetic interrupt controller message flags. */
  251. union hv_message_flags {
  252. __u8 asu8;
  253. struct {
  254. __u8 msg_pending:1;
  255. __u8 reserved:7;
  256. } __packed;
  257. };
  258. /* Define port identifier type. */
  259. union hv_port_id {
  260. __u32 asu32;
  261. struct {
  262. __u32 id:24;
  263. __u32 reserved:8;
  264. } __packed u;
  265. };
  266. /* Define synthetic interrupt controller message header. */
  267. struct hv_message_header {
  268. __u32 message_type;
  269. __u8 payload_size;
  270. union hv_message_flags message_flags;
  271. __u8 reserved[2];
  272. union {
  273. __u64 sender;
  274. union hv_port_id port;
  275. };
  276. } __packed;
  277. /* Define synthetic interrupt controller message format. */
  278. struct hv_message {
  279. struct hv_message_header header;
  280. union {
  281. __u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
  282. } u;
  283. } __packed;
  284. /* Define the synthetic interrupt message page layout. */
  285. struct hv_message_page {
  286. struct hv_message sint_message[HV_SYNIC_SINT_COUNT];
  287. } __packed;
  288. /* Define timer message payload structure. */
  289. struct hv_timer_message_payload {
  290. __u32 timer_index;
  291. __u32 reserved;
  292. __u64 expiration_time; /* When the timer expired */
  293. __u64 delivery_time; /* When the message was delivered */
  294. } __packed;
  295. /* Define synthetic interrupt controller flag constants. */
  296. #define HV_EVENT_FLAGS_COUNT (256 * 8)
  297. #define HV_EVENT_FLAGS_LONG_COUNT (256 / sizeof(unsigned long))
  298. /*
  299. * Synthetic timer configuration.
  300. */
  301. union hv_stimer_config {
  302. u64 as_uint64;
  303. struct {
  304. u64 enable:1;
  305. u64 periodic:1;
  306. u64 lazy:1;
  307. u64 auto_enable:1;
  308. u64 apic_vector:8;
  309. u64 direct_mode:1;
  310. u64 reserved_z0:3;
  311. u64 sintx:4;
  312. u64 reserved_z1:44;
  313. } __packed;
  314. };
  315. /* Define the synthetic interrupt controller event flags format. */
  316. union hv_synic_event_flags {
  317. unsigned long flags[HV_EVENT_FLAGS_LONG_COUNT];
  318. };
  319. /* Define SynIC control register. */
  320. union hv_synic_scontrol {
  321. u64 as_uint64;
  322. struct {
  323. u64 enable:1;
  324. u64 reserved:63;
  325. } __packed;
  326. };
  327. /* Define synthetic interrupt source. */
  328. union hv_synic_sint {
  329. u64 as_uint64;
  330. struct {
  331. u64 vector:8;
  332. u64 reserved1:8;
  333. u64 masked:1;
  334. u64 auto_eoi:1;
  335. u64 polling:1;
  336. u64 reserved2:45;
  337. } __packed;
  338. };
  339. /* Define the format of the SIMP register */
  340. union hv_synic_simp {
  341. u64 as_uint64;
  342. struct {
  343. u64 simp_enabled:1;
  344. u64 preserved:11;
  345. u64 base_simp_gpa:52;
  346. } __packed;
  347. };
  348. /* Define the format of the SIEFP register */
  349. union hv_synic_siefp {
  350. u64 as_uint64;
  351. struct {
  352. u64 siefp_enabled:1;
  353. u64 preserved:11;
  354. u64 base_siefp_gpa:52;
  355. } __packed;
  356. };
  357. struct hv_vpset {
  358. u64 format;
  359. u64 valid_bank_mask;
  360. u64 bank_contents[];
  361. } __packed;
  362. /* HvCallSendSyntheticClusterIpi hypercall */
  363. struct hv_send_ipi {
  364. u32 vector;
  365. u32 reserved;
  366. u64 cpu_mask;
  367. } __packed;
  368. /* HvCallSendSyntheticClusterIpiEx hypercall */
  369. struct hv_send_ipi_ex {
  370. u32 vector;
  371. u32 reserved;
  372. struct hv_vpset vp_set;
  373. } __packed;
  374. /* HvFlushGuestPhysicalAddressSpace hypercalls */
  375. struct hv_guest_mapping_flush {
  376. u64 address_space;
  377. u64 flags;
  378. } __packed;
  379. /*
  380. * HV_MAX_FLUSH_PAGES = "additional_pages" + 1. It's limited
  381. * by the bitwidth of "additional_pages" in union hv_gpa_page_range.
  382. */
  383. #define HV_MAX_FLUSH_PAGES (2048)
  384. #define HV_GPA_PAGE_RANGE_PAGE_SIZE_2MB 0
  385. #define HV_GPA_PAGE_RANGE_PAGE_SIZE_1GB 1
  386. /* HvFlushGuestPhysicalAddressList, HvExtCallMemoryHeatHint hypercall */
  387. union hv_gpa_page_range {
  388. u64 address_space;
  389. struct {
  390. u64 additional_pages:11;
  391. u64 largepage:1;
  392. u64 basepfn:52;
  393. } page;
  394. struct {
  395. u64 reserved:12;
  396. u64 page_size:1;
  397. u64 reserved1:8;
  398. u64 base_large_pfn:43;
  399. };
  400. };
  401. /*
  402. * All input flush parameters should be in single page. The max flush
  403. * count is equal with how many entries of union hv_gpa_page_range can
  404. * be populated into the input parameter page.
  405. */
  406. #define HV_MAX_FLUSH_REP_COUNT ((HV_HYP_PAGE_SIZE - 2 * sizeof(u64)) / \
  407. sizeof(union hv_gpa_page_range))
  408. struct hv_guest_mapping_flush_list {
  409. u64 address_space;
  410. u64 flags;
  411. union hv_gpa_page_range gpa_list[HV_MAX_FLUSH_REP_COUNT];
  412. };
  413. /* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */
  414. struct hv_tlb_flush {
  415. u64 address_space;
  416. u64 flags;
  417. u64 processor_mask;
  418. u64 gva_list[];
  419. } __packed;
  420. /* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */
  421. struct hv_tlb_flush_ex {
  422. u64 address_space;
  423. u64 flags;
  424. struct hv_vpset hv_vp_set;
  425. u64 gva_list[];
  426. } __packed;
  427. /* HvGetPartitionId hypercall (output only) */
  428. struct hv_get_partition_id {
  429. u64 partition_id;
  430. } __packed;
  431. /* HvDepositMemory hypercall */
  432. struct hv_deposit_memory {
  433. u64 partition_id;
  434. u64 gpa_page_list[];
  435. } __packed;
  436. struct hv_proximity_domain_flags {
  437. u32 proximity_preferred : 1;
  438. u32 reserved : 30;
  439. u32 proximity_info_valid : 1;
  440. } __packed;
  441. /* Not a union in windows but useful for zeroing */
  442. union hv_proximity_domain_info {
  443. struct {
  444. u32 domain_id;
  445. struct hv_proximity_domain_flags flags;
  446. };
  447. u64 as_uint64;
  448. } __packed;
  449. struct hv_lp_startup_status {
  450. u64 hv_status;
  451. u64 substatus1;
  452. u64 substatus2;
  453. u64 substatus3;
  454. u64 substatus4;
  455. u64 substatus5;
  456. u64 substatus6;
  457. } __packed;
  458. /* HvAddLogicalProcessor hypercall */
  459. struct hv_add_logical_processor_in {
  460. u32 lp_index;
  461. u32 apic_id;
  462. union hv_proximity_domain_info proximity_domain_info;
  463. u64 flags;
  464. } __packed;
  465. struct hv_add_logical_processor_out {
  466. struct hv_lp_startup_status startup_status;
  467. } __packed;
  468. enum HV_SUBNODE_TYPE
  469. {
  470. HvSubnodeAny = 0,
  471. HvSubnodeSocket = 1,
  472. HvSubnodeAmdNode = 2,
  473. HvSubnodeL3 = 3,
  474. HvSubnodeCount = 4,
  475. HvSubnodeInvalid = -1
  476. };
  477. /* HvCreateVp hypercall */
  478. struct hv_create_vp {
  479. u64 partition_id;
  480. u32 vp_index;
  481. u8 padding[3];
  482. u8 subnode_type;
  483. u64 subnode_id;
  484. union hv_proximity_domain_info proximity_domain_info;
  485. u64 flags;
  486. } __packed;
  487. enum hv_interrupt_source {
  488. HV_INTERRUPT_SOURCE_MSI = 1, /* MSI and MSI-X */
  489. HV_INTERRUPT_SOURCE_IOAPIC,
  490. };
  491. union hv_ioapic_rte {
  492. u64 as_uint64;
  493. struct {
  494. u32 vector:8;
  495. u32 delivery_mode:3;
  496. u32 destination_mode:1;
  497. u32 delivery_status:1;
  498. u32 interrupt_polarity:1;
  499. u32 remote_irr:1;
  500. u32 trigger_mode:1;
  501. u32 interrupt_mask:1;
  502. u32 reserved1:15;
  503. u32 reserved2:24;
  504. u32 destination_id:8;
  505. };
  506. struct {
  507. u32 low_uint32;
  508. u32 high_uint32;
  509. };
  510. } __packed;
  511. struct hv_interrupt_entry {
  512. u32 source;
  513. u32 reserved1;
  514. union {
  515. union hv_msi_entry msi_entry;
  516. union hv_ioapic_rte ioapic_rte;
  517. };
  518. } __packed;
  519. /*
  520. * flags for hv_device_interrupt_target.flags
  521. */
  522. #define HV_DEVICE_INTERRUPT_TARGET_MULTICAST 1
  523. #define HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET 2
  524. struct hv_device_interrupt_target {
  525. u32 vector;
  526. u32 flags;
  527. union {
  528. u64 vp_mask;
  529. struct hv_vpset vp_set;
  530. };
  531. } __packed;
  532. struct hv_retarget_device_interrupt {
  533. u64 partition_id; /* use "self" */
  534. u64 device_id;
  535. struct hv_interrupt_entry int_entry;
  536. u64 reserved2;
  537. struct hv_device_interrupt_target int_target;
  538. } __packed __aligned(8);
  539. /* HvGetVpRegisters hypercall input with variable size reg name list*/
  540. struct hv_get_vp_registers_input {
  541. struct {
  542. u64 partitionid;
  543. u32 vpindex;
  544. u8 inputvtl;
  545. u8 padding[3];
  546. } header;
  547. struct input {
  548. u32 name0;
  549. u32 name1;
  550. } element[];
  551. } __packed;
  552. /* HvGetVpRegisters returns an array of these output elements */
  553. struct hv_get_vp_registers_output {
  554. union {
  555. struct {
  556. u32 a;
  557. u32 b;
  558. u32 c;
  559. u32 d;
  560. } as32 __packed;
  561. struct {
  562. u64 low;
  563. u64 high;
  564. } as64 __packed;
  565. };
  566. };
  567. /* HvSetVpRegisters hypercall with variable size reg name/value list*/
  568. struct hv_set_vp_registers_input {
  569. struct {
  570. u64 partitionid;
  571. u32 vpindex;
  572. u8 inputvtl;
  573. u8 padding[3];
  574. } header;
  575. struct {
  576. u32 name;
  577. u32 padding1;
  578. u64 padding2;
  579. u64 valuelow;
  580. u64 valuehigh;
  581. } element[];
  582. } __packed;
  583. enum hv_device_type {
  584. HV_DEVICE_TYPE_LOGICAL = 0,
  585. HV_DEVICE_TYPE_PCI = 1,
  586. HV_DEVICE_TYPE_IOAPIC = 2,
  587. HV_DEVICE_TYPE_ACPI = 3,
  588. };
  589. typedef u16 hv_pci_rid;
  590. typedef u16 hv_pci_segment;
  591. typedef u64 hv_logical_device_id;
  592. union hv_pci_bdf {
  593. u16 as_uint16;
  594. struct {
  595. u8 function:3;
  596. u8 device:5;
  597. u8 bus;
  598. };
  599. } __packed;
  600. union hv_pci_bus_range {
  601. u16 as_uint16;
  602. struct {
  603. u8 subordinate_bus;
  604. u8 secondary_bus;
  605. };
  606. } __packed;
  607. union hv_device_id {
  608. u64 as_uint64;
  609. struct {
  610. u64 reserved0:62;
  611. u64 device_type:2;
  612. };
  613. /* HV_DEVICE_TYPE_LOGICAL */
  614. struct {
  615. u64 id:62;
  616. u64 device_type:2;
  617. } logical;
  618. /* HV_DEVICE_TYPE_PCI */
  619. struct {
  620. union {
  621. hv_pci_rid rid;
  622. union hv_pci_bdf bdf;
  623. };
  624. hv_pci_segment segment;
  625. union hv_pci_bus_range shadow_bus_range;
  626. u16 phantom_function_bits:2;
  627. u16 source_shadow:1;
  628. u16 rsvdz0:11;
  629. u16 device_type:2;
  630. } pci;
  631. /* HV_DEVICE_TYPE_IOAPIC */
  632. struct {
  633. u8 ioapic_id;
  634. u8 rsvdz0;
  635. u16 rsvdz1;
  636. u16 rsvdz2;
  637. u16 rsvdz3:14;
  638. u16 device_type:2;
  639. } ioapic;
  640. /* HV_DEVICE_TYPE_ACPI */
  641. struct {
  642. u32 input_mapping_base;
  643. u32 input_mapping_count:30;
  644. u32 device_type:2;
  645. } acpi;
  646. } __packed;
  647. enum hv_interrupt_trigger_mode {
  648. HV_INTERRUPT_TRIGGER_MODE_EDGE = 0,
  649. HV_INTERRUPT_TRIGGER_MODE_LEVEL = 1,
  650. };
  651. struct hv_device_interrupt_descriptor {
  652. u32 interrupt_type;
  653. u32 trigger_mode;
  654. u32 vector_count;
  655. u32 reserved;
  656. struct hv_device_interrupt_target target;
  657. } __packed;
  658. struct hv_input_map_device_interrupt {
  659. u64 partition_id;
  660. u64 device_id;
  661. u64 flags;
  662. struct hv_interrupt_entry logical_interrupt_entry;
  663. struct hv_device_interrupt_descriptor interrupt_descriptor;
  664. } __packed;
  665. struct hv_output_map_device_interrupt {
  666. struct hv_interrupt_entry interrupt_entry;
  667. } __packed;
  668. struct hv_input_unmap_device_interrupt {
  669. u64 partition_id;
  670. u64 device_id;
  671. struct hv_interrupt_entry interrupt_entry;
  672. } __packed;
  673. #define HV_SOURCE_SHADOW_NONE 0x0
  674. #define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE 0x1
  675. /*
  676. * The whole argument should fit in a page to be able to pass to the hypervisor
  677. * in one hypercall.
  678. */
  679. #define HV_MEMORY_HINT_MAX_GPA_PAGE_RANGES \
  680. ((HV_HYP_PAGE_SIZE - sizeof(struct hv_memory_hint)) / \
  681. sizeof(union hv_gpa_page_range))
  682. /* HvExtCallMemoryHeatHint hypercall */
  683. #define HV_EXT_MEMORY_HEAT_HINT_TYPE_COLD_DISCARD 2
  684. struct hv_memory_hint {
  685. u64 type:2;
  686. u64 reserved:62;
  687. union hv_gpa_page_range ranges[];
  688. } __packed;
  689. #endif