1 /* SPDX-License-Identifier: GPL-2.0 */
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
9 #ifndef _ASM_GENERIC_HYPERV_TLFS_H
10 #define _ASM_GENERIC_HYPERV_TLFS_H
12 #include <linux/types.h>
13 #include <linux/bits.h>
14 #include <linux/time64.h>
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.
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))
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.
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.
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.
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)
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)
98 struct ms_hyperv_tsc_page {
99 volatile u32 tsc_sequence;
101 volatile u64 tsc_scale;
102 volatile s64 tsc_offset;
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:
110 * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
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.
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
129 #define HV_LINUX_VENDOR_ID 0x8100
132 * Crash notification flags.
134 #define HV_CRASH_CTL_CRASH_NOTIFY_MSG BIT_ULL(62)
135 #define HV_CRASH_CTL_CRASH_NOTIFY BIT_ULL(63)
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 #define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db
163 /* Extended hypercalls */
164 #define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001
165 #define HV_EXT_CALL_MEMORY_HEAT_HINT 0x8003
167 #define HV_FLUSH_ALL_PROCESSORS BIT(0)
168 #define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES BIT(1)
169 #define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY BIT(2)
170 #define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT BIT(3)
172 /* Extended capability bits */
173 #define HV_EXT_CAPABILITY_MEMORY_COLD_DISCARD_HINT BIT(8)
175 enum HV_GENERIC_SET_FORMAT {
176 HV_GENERIC_SET_SPARSE_4K,
180 #define HV_PARTITION_ID_SELF ((u64)-1)
181 #define HV_VP_INDEX_SELF ((u32)-2)
183 #define HV_HYPERCALL_RESULT_MASK GENMASK_ULL(15, 0)
184 #define HV_HYPERCALL_FAST_BIT BIT(16)
185 #define HV_HYPERCALL_VARHEAD_OFFSET 17
186 #define HV_HYPERCALL_VARHEAD_MASK GENMASK_ULL(26, 17)
187 #define HV_HYPERCALL_RSVD0_MASK GENMASK_ULL(31, 27)
188 #define HV_HYPERCALL_REP_COMP_OFFSET 32
189 #define HV_HYPERCALL_REP_COMP_1 BIT_ULL(32)
190 #define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32)
191 #define HV_HYPERCALL_RSVD1_MASK GENMASK_ULL(47, 44)
192 #define HV_HYPERCALL_REP_START_OFFSET 48
193 #define HV_HYPERCALL_REP_START_MASK GENMASK_ULL(59, 48)
194 #define HV_HYPERCALL_RSVD2_MASK GENMASK_ULL(63, 60)
195 #define HV_HYPERCALL_RSVD_MASK (HV_HYPERCALL_RSVD0_MASK | \
196 HV_HYPERCALL_RSVD1_MASK | \
197 HV_HYPERCALL_RSVD2_MASK)
199 /* hypercall status code */
200 #define HV_STATUS_SUCCESS 0
201 #define HV_STATUS_INVALID_HYPERCALL_CODE 2
202 #define HV_STATUS_INVALID_HYPERCALL_INPUT 3
203 #define HV_STATUS_INVALID_ALIGNMENT 4
204 #define HV_STATUS_INVALID_PARAMETER 5
205 #define HV_STATUS_ACCESS_DENIED 6
206 #define HV_STATUS_OPERATION_DENIED 8
207 #define HV_STATUS_INSUFFICIENT_MEMORY 11
208 #define HV_STATUS_INVALID_PORT_ID 17
209 #define HV_STATUS_INVALID_CONNECTION_ID 18
210 #define HV_STATUS_INSUFFICIENT_BUFFERS 19
213 * The Hyper-V TimeRefCount register and the TSC
214 * page provide a guest VM clock with 100ns tick rate
216 #define HV_CLOCK_HZ (NSEC_PER_SEC/100)
218 /* Define the number of synthetic interrupt sources. */
219 #define HV_SYNIC_SINT_COUNT (16)
220 /* Define the expected SynIC version. */
221 #define HV_SYNIC_VERSION_1 (0x1)
222 /* Valid SynIC vectors are 16-255. */
223 #define HV_SYNIC_FIRST_VALID_VECTOR (16)
225 #define HV_SYNIC_CONTROL_ENABLE (1ULL << 0)
226 #define HV_SYNIC_SIMP_ENABLE (1ULL << 0)
227 #define HV_SYNIC_SIEFP_ENABLE (1ULL << 0)
228 #define HV_SYNIC_SINT_MASKED (1ULL << 16)
229 #define HV_SYNIC_SINT_AUTO_EOI (1ULL << 17)
230 #define HV_SYNIC_SINT_VECTOR_MASK (0xFF)
232 #define HV_SYNIC_STIMER_COUNT (4)
234 /* Define synthetic interrupt controller message constants. */
235 #define HV_MESSAGE_SIZE (256)
236 #define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240)
237 #define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30)
240 * Define hypervisor message types. Some of the message types
241 * are x86/x64 specific, but there's no good way to separate
242 * them out into the arch-specific version of hyperv-tlfs.h
243 * because C doesn't provide a way to extend enum types.
244 * Keeping them all in the arch neutral hyperv-tlfs.h seems
245 * the least messy compromise.
247 enum hv_message_type {
248 HVMSG_NONE = 0x00000000,
250 /* Memory access messages. */
251 HVMSG_UNMAPPED_GPA = 0x80000000,
252 HVMSG_GPA_INTERCEPT = 0x80000001,
254 /* Timer notification messages. */
255 HVMSG_TIMER_EXPIRED = 0x80000010,
257 /* Error messages. */
258 HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020,
259 HVMSG_UNRECOVERABLE_EXCEPTION = 0x80000021,
260 HVMSG_UNSUPPORTED_FEATURE = 0x80000022,
262 /* Trace buffer complete messages. */
263 HVMSG_EVENTLOG_BUFFERCOMPLETE = 0x80000040,
265 /* Platform-specific processor intercept messages. */
266 HVMSG_X64_IOPORT_INTERCEPT = 0x80010000,
267 HVMSG_X64_MSR_INTERCEPT = 0x80010001,
268 HVMSG_X64_CPUID_INTERCEPT = 0x80010002,
269 HVMSG_X64_EXCEPTION_INTERCEPT = 0x80010003,
270 HVMSG_X64_APIC_EOI = 0x80010004,
271 HVMSG_X64_LEGACY_FP_ERROR = 0x80010005
274 /* Define synthetic interrupt controller message flags. */
275 union hv_message_flags {
283 /* Define port identifier type. */
292 /* Define synthetic interrupt controller message header. */
293 struct hv_message_header {
296 union hv_message_flags message_flags;
300 union hv_port_id port;
304 /* Define synthetic interrupt controller message format. */
306 struct hv_message_header header;
308 __u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
312 /* Define the synthetic interrupt message page layout. */
313 struct hv_message_page {
314 struct hv_message sint_message[HV_SYNIC_SINT_COUNT];
317 /* Define timer message payload structure. */
318 struct hv_timer_message_payload {
321 __u64 expiration_time; /* When the timer expired */
322 __u64 delivery_time; /* When the message was delivered */
326 /* Define synthetic interrupt controller flag constants. */
327 #define HV_EVENT_FLAGS_COUNT (256 * 8)
328 #define HV_EVENT_FLAGS_LONG_COUNT (256 / sizeof(unsigned long))
331 * Synthetic timer configuration.
333 union hv_stimer_config {
349 /* Define the synthetic interrupt controller event flags format. */
350 union hv_synic_event_flags {
351 unsigned long flags[HV_EVENT_FLAGS_LONG_COUNT];
354 /* Define SynIC control register. */
355 union hv_synic_scontrol {
363 /* Define synthetic interrupt source. */
364 union hv_synic_sint {
376 /* Define the format of the SIMP register */
377 union hv_synic_simp {
382 u64 base_simp_gpa:52;
386 /* Define the format of the SIEFP register */
387 union hv_synic_siefp {
392 u64 base_siefp_gpa:52;
402 /* HvCallSendSyntheticClusterIpi hypercall */
409 /* HvCallSendSyntheticClusterIpiEx hypercall */
410 struct hv_send_ipi_ex {
413 struct hv_vpset vp_set;
416 /* HvFlushGuestPhysicalAddressSpace hypercalls */
417 struct hv_guest_mapping_flush {
423 * HV_MAX_FLUSH_PAGES = "additional_pages" + 1. It's limited
424 * by the bitwidth of "additional_pages" in union hv_gpa_page_range.
426 #define HV_MAX_FLUSH_PAGES (2048)
427 #define HV_GPA_PAGE_RANGE_PAGE_SIZE_2MB 0
428 #define HV_GPA_PAGE_RANGE_PAGE_SIZE_1GB 1
430 /* HvFlushGuestPhysicalAddressList, HvExtCallMemoryHeatHint hypercall */
431 union hv_gpa_page_range {
434 u64 additional_pages:11;
442 u64 base_large_pfn:43;
447 * All input flush parameters should be in single page. The max flush
448 * count is equal with how many entries of union hv_gpa_page_range can
449 * be populated into the input parameter page.
451 #define HV_MAX_FLUSH_REP_COUNT ((HV_HYP_PAGE_SIZE - 2 * sizeof(u64)) / \
452 sizeof(union hv_gpa_page_range))
454 struct hv_guest_mapping_flush_list {
457 union hv_gpa_page_range gpa_list[HV_MAX_FLUSH_REP_COUNT];
460 /* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */
461 struct hv_tlb_flush {
468 /* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */
469 struct hv_tlb_flush_ex {
472 struct hv_vpset hv_vp_set;
476 /* HvGetPartitionId hypercall (output only) */
477 struct hv_get_partition_id {
481 /* HvDepositMemory hypercall */
482 struct hv_deposit_memory {
487 struct hv_proximity_domain_flags {
488 u32 proximity_preferred : 1;
490 u32 proximity_info_valid : 1;
493 /* Not a union in windows but useful for zeroing */
494 union hv_proximity_domain_info {
497 struct hv_proximity_domain_flags flags;
502 struct hv_lp_startup_status {
512 /* HvAddLogicalProcessor hypercall */
513 struct hv_add_logical_processor_in {
516 union hv_proximity_domain_info proximity_domain_info;
520 struct hv_add_logical_processor_out {
521 struct hv_lp_startup_status startup_status;
528 HvSubnodeAmdNode = 2,
531 HvSubnodeInvalid = -1
534 /* HvCreateVp hypercall */
535 struct hv_create_vp {
541 union hv_proximity_domain_info proximity_domain_info;
545 enum hv_interrupt_source {
546 HV_INTERRUPT_SOURCE_MSI = 1, /* MSI and MSI-X */
547 HV_INTERRUPT_SOURCE_IOAPIC,
550 union hv_ioapic_rte {
556 u32 destination_mode:1;
557 u32 delivery_status:1;
558 u32 interrupt_polarity:1;
561 u32 interrupt_mask:1;
565 u32 destination_id:8;
574 struct hv_interrupt_entry {
578 union hv_msi_entry msi_entry;
579 union hv_ioapic_rte ioapic_rte;
584 * flags for hv_device_interrupt_target.flags
586 #define HV_DEVICE_INTERRUPT_TARGET_MULTICAST 1
587 #define HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET 2
589 struct hv_device_interrupt_target {
594 struct hv_vpset vp_set;
598 struct hv_retarget_device_interrupt {
599 u64 partition_id; /* use "self" */
601 struct hv_interrupt_entry int_entry;
603 struct hv_device_interrupt_target int_target;
604 } __packed __aligned(8);
607 /* HvGetVpRegisters hypercall input with variable size reg name list*/
608 struct hv_get_vp_registers_input {
622 /* HvGetVpRegisters returns an array of these output elements */
623 struct hv_get_vp_registers_output {
638 /* HvSetVpRegisters hypercall with variable size reg name/value list*/
639 struct hv_set_vp_registers_input {
655 enum hv_device_type {
656 HV_DEVICE_TYPE_LOGICAL = 0,
657 HV_DEVICE_TYPE_PCI = 1,
658 HV_DEVICE_TYPE_IOAPIC = 2,
659 HV_DEVICE_TYPE_ACPI = 3,
662 typedef u16 hv_pci_rid;
663 typedef u16 hv_pci_segment;
664 typedef u64 hv_logical_device_id;
675 union hv_pci_bus_range {
692 /* HV_DEVICE_TYPE_LOGICAL */
698 /* HV_DEVICE_TYPE_PCI */
702 union hv_pci_bdf bdf;
705 hv_pci_segment segment;
706 union hv_pci_bus_range shadow_bus_range;
708 u16 phantom_function_bits:2;
715 /* HV_DEVICE_TYPE_IOAPIC */
726 /* HV_DEVICE_TYPE_ACPI */
728 u32 input_mapping_base;
729 u32 input_mapping_count:30;
734 enum hv_interrupt_trigger_mode {
735 HV_INTERRUPT_TRIGGER_MODE_EDGE = 0,
736 HV_INTERRUPT_TRIGGER_MODE_LEVEL = 1,
739 struct hv_device_interrupt_descriptor {
744 struct hv_device_interrupt_target target;
747 struct hv_input_map_device_interrupt {
751 struct hv_interrupt_entry logical_interrupt_entry;
752 struct hv_device_interrupt_descriptor interrupt_descriptor;
755 struct hv_output_map_device_interrupt {
756 struct hv_interrupt_entry interrupt_entry;
759 struct hv_input_unmap_device_interrupt {
762 struct hv_interrupt_entry interrupt_entry;
765 #define HV_SOURCE_SHADOW_NONE 0x0
766 #define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE 0x1
769 * The whole argument should fit in a page to be able to pass to the hypervisor
772 #define HV_MEMORY_HINT_MAX_GPA_PAGE_RANGES \
773 ((HV_HYP_PAGE_SIZE - sizeof(struct hv_memory_hint)) / \
774 sizeof(union hv_gpa_page_range))
776 /* HvExtCallMemoryHeatHint hypercall */
777 #define HV_EXT_MEMORY_HEAT_HINT_TYPE_COLD_DISCARD 2
778 struct hv_memory_hint {
781 union hv_gpa_page_range ranges[];