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