Linux Audio

Check our new training course

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