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_POWER_MANAGEMENT BIT(12)
97 struct ms_hyperv_tsc_page
{
98 volatile u32 tsc_sequence
;
100 volatile u64 tsc_scale
;
101 volatile s64 tsc_offset
;
105 * The guest OS needs to register the guest ID with the hypervisor.
106 * The guest ID is a 64 bit entity and the structure of this ID is
107 * specified in the Hyper-V specification:
109 * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
111 * While the current guideline does not specify how Linux guest ID(s)
112 * need to be generated, our plan is to publish the guidelines for
113 * Linux and other guest operating systems that currently are hosted
114 * on Hyper-V. The implementation here conforms to this yet
115 * unpublished guidelines.
119 * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
120 * 62:56 - Os Type; Linux is 0x100
121 * 55:48 - Distro specific identification
122 * 47:16 - Linux kernel version number
123 * 15:0 - Distro specific identification
128 #define HV_LINUX_VENDOR_ID 0x8100
131 * Crash notification flags.
133 #define HV_CRASH_CTL_CRASH_NOTIFY_MSG BIT_ULL(62)
134 #define HV_CRASH_CTL_CRASH_NOTIFY BIT_ULL(63)
136 /* Declare the various hypercall operations. */
137 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002
138 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003
139 #define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008
140 #define HVCALL_SEND_IPI 0x000b
141 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013
142 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014
143 #define HVCALL_SEND_IPI_EX 0x0015
144 #define HVCALL_GET_VP_REGISTERS 0x0050
145 #define HVCALL_SET_VP_REGISTERS 0x0051
146 #define HVCALL_POST_MESSAGE 0x005c
147 #define HVCALL_SIGNAL_EVENT 0x005d
148 #define HVCALL_POST_DEBUG_DATA 0x0069
149 #define HVCALL_RETRIEVE_DEBUG_DATA 0x006a
150 #define HVCALL_RESET_DEBUG_SESSION 0x006b
151 #define HVCALL_RETARGET_INTERRUPT 0x007e
152 #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af
153 #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0
155 #define HV_FLUSH_ALL_PROCESSORS BIT(0)
156 #define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES BIT(1)
157 #define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY BIT(2)
158 #define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT BIT(3)
160 enum HV_GENERIC_SET_FORMAT
{
161 HV_GENERIC_SET_SPARSE_4K
,
165 #define HV_PARTITION_ID_SELF ((u64)-1)
166 #define HV_VP_INDEX_SELF ((u32)-2)
168 #define HV_HYPERCALL_RESULT_MASK GENMASK_ULL(15, 0)
169 #define HV_HYPERCALL_FAST_BIT BIT(16)
170 #define HV_HYPERCALL_VARHEAD_OFFSET 17
171 #define HV_HYPERCALL_REP_COMP_OFFSET 32
172 #define HV_HYPERCALL_REP_COMP_1 BIT_ULL(32)
173 #define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32)
174 #define HV_HYPERCALL_REP_START_OFFSET 48
175 #define HV_HYPERCALL_REP_START_MASK GENMASK_ULL(59, 48)
177 /* hypercall status code */
178 #define HV_STATUS_SUCCESS 0
179 #define HV_STATUS_INVALID_HYPERCALL_CODE 2
180 #define HV_STATUS_INVALID_HYPERCALL_INPUT 3
181 #define HV_STATUS_INVALID_ALIGNMENT 4
182 #define HV_STATUS_INVALID_PARAMETER 5
183 #define HV_STATUS_OPERATION_DENIED 8
184 #define HV_STATUS_INSUFFICIENT_MEMORY 11
185 #define HV_STATUS_INVALID_PORT_ID 17
186 #define HV_STATUS_INVALID_CONNECTION_ID 18
187 #define HV_STATUS_INSUFFICIENT_BUFFERS 19
190 * The Hyper-V TimeRefCount register and the TSC
191 * page provide a guest VM clock with 100ns tick rate
193 #define HV_CLOCK_HZ (NSEC_PER_SEC/100)
195 /* Define the number of synthetic interrupt sources. */
196 #define HV_SYNIC_SINT_COUNT (16)
197 /* Define the expected SynIC version. */
198 #define HV_SYNIC_VERSION_1 (0x1)
199 /* Valid SynIC vectors are 16-255. */
200 #define HV_SYNIC_FIRST_VALID_VECTOR (16)
202 #define HV_SYNIC_CONTROL_ENABLE (1ULL << 0)
203 #define HV_SYNIC_SIMP_ENABLE (1ULL << 0)
204 #define HV_SYNIC_SIEFP_ENABLE (1ULL << 0)
205 #define HV_SYNIC_SINT_MASKED (1ULL << 16)
206 #define HV_SYNIC_SINT_AUTO_EOI (1ULL << 17)
207 #define HV_SYNIC_SINT_VECTOR_MASK (0xFF)
209 #define HV_SYNIC_STIMER_COUNT (4)
211 /* Define synthetic interrupt controller message constants. */
212 #define HV_MESSAGE_SIZE (256)
213 #define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240)
214 #define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30)
216 /* Define synthetic interrupt controller message flags. */
217 union hv_message_flags
{
225 /* Define port identifier type. */
234 /* Define synthetic interrupt controller message header. */
235 struct hv_message_header
{
238 union hv_message_flags message_flags
;
242 union hv_port_id port
;
246 /* Define synthetic interrupt controller message format. */
248 struct hv_message_header header
;
250 __u64 payload
[HV_MESSAGE_PAYLOAD_QWORD_COUNT
];
254 /* Define the synthetic interrupt message page layout. */
255 struct hv_message_page
{
256 struct hv_message sint_message
[HV_SYNIC_SINT_COUNT
];
259 /* Define timer message payload structure. */
260 struct hv_timer_message_payload
{
263 __u64 expiration_time
; /* When the timer expired */
264 __u64 delivery_time
; /* When the message was delivered */
268 /* Define synthetic interrupt controller flag constants. */
269 #define HV_EVENT_FLAGS_COUNT (256 * 8)
270 #define HV_EVENT_FLAGS_LONG_COUNT (256 / sizeof(unsigned long))
273 * Synthetic timer configuration.
275 union hv_stimer_config
{
291 /* Define the synthetic interrupt controller event flags format. */
292 union hv_synic_event_flags
{
293 unsigned long flags
[HV_EVENT_FLAGS_LONG_COUNT
];
296 /* Define SynIC control register. */
297 union hv_synic_scontrol
{
305 /* Define synthetic interrupt source. */
306 union hv_synic_sint
{
318 /* Define the format of the SIMP register */
319 union hv_synic_simp
{
324 u64 base_simp_gpa
:52;
328 /* Define the format of the SIEFP register */
329 union hv_synic_siefp
{
334 u64 base_siefp_gpa
:52;
344 /* HvCallSendSyntheticClusterIpi hypercall */
351 /* HvCallSendSyntheticClusterIpiEx hypercall */
352 struct hv_send_ipi_ex
{
355 struct hv_vpset vp_set
;
358 /* HvFlushGuestPhysicalAddressSpace hypercalls */
359 struct hv_guest_mapping_flush
{
365 * HV_MAX_FLUSH_PAGES = "additional_pages" + 1. It's limited
366 * by the bitwidth of "additional_pages" in union hv_gpa_page_range.
368 #define HV_MAX_FLUSH_PAGES (2048)
370 /* HvFlushGuestPhysicalAddressList hypercall */
371 union hv_gpa_page_range
{
374 u64 additional_pages
:11;
381 * All input flush parameters should be in single page. The max flush
382 * count is equal with how many entries of union hv_gpa_page_range can
383 * be populated into the input parameter page.
385 #define HV_MAX_FLUSH_REP_COUNT ((HV_HYP_PAGE_SIZE - 2 * sizeof(u64)) / \
386 sizeof(union hv_gpa_page_range))
388 struct hv_guest_mapping_flush_list
{
391 union hv_gpa_page_range gpa_list
[HV_MAX_FLUSH_REP_COUNT
];
394 /* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */
395 struct hv_tlb_flush
{
402 /* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */
403 struct hv_tlb_flush_ex
{
406 struct hv_vpset hv_vp_set
;
410 /* HvRetargetDeviceInterrupt hypercall */
419 struct hv_interrupt_entry
{
420 u32 source
; /* 1 for MSI(-X) */
422 union hv_msi_entry msi_entry
;
426 * flags for hv_device_interrupt_target.flags
428 #define HV_DEVICE_INTERRUPT_TARGET_MULTICAST 1
429 #define HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET 2
431 struct hv_device_interrupt_target
{
436 struct hv_vpset vp_set
;
440 struct hv_retarget_device_interrupt
{
441 u64 partition_id
; /* use "self" */
443 struct hv_interrupt_entry int_entry
;
445 struct hv_device_interrupt_target int_target
;
446 } __packed
__aligned(8);
449 /* HvGetVpRegisters hypercall input with variable size reg name list*/
450 struct hv_get_vp_registers_input
{
464 /* HvGetVpRegisters returns an array of these output elements */
465 struct hv_get_vp_registers_output
{
480 /* HvSetVpRegisters hypercall with variable size reg name/value list*/
481 struct hv_set_vp_registers_input
{