ACPI / NUMA: add a stub function for node_to_pxm()
[linux-block.git] / include / asm-generic / hyperv-tlfs.h
CommitLineData
c55a844f
MK
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)
8f1d14cb 91#define HV_CPU_MANAGEMENT BIT(12)
a6c76bb0 92#define HV_ISOLATION BIT(22)
c55a844f
MK
93
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
99a0f46a 145#define HVCALL_GET_PARTITION_ID 0x0046
88b42da6
MK
146#define HVCALL_GET_VP_REGISTERS 0x0050
147#define HVCALL_SET_VP_REGISTERS 0x0051
c55a844f
MK
148#define HVCALL_POST_MESSAGE 0x005c
149#define HVCALL_SIGNAL_EVENT 0x005d
039aeb9d
LT
150#define HVCALL_POST_DEBUG_DATA 0x0069
151#define HVCALL_RETRIEVE_DEBUG_DATA 0x006a
152#define HVCALL_RESET_DEBUG_SESSION 0x006b
c55a844f
MK
153#define HVCALL_RETARGET_INTERRUPT 0x007e
154#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af
155#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0
156
157#define HV_FLUSH_ALL_PROCESSORS BIT(0)
158#define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES BIT(1)
159#define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY BIT(2)
160#define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT BIT(3)
161
162enum HV_GENERIC_SET_FORMAT {
163 HV_GENERIC_SET_SPARSE_4K,
164 HV_GENERIC_SET_ALL,
165};
166
167#define HV_PARTITION_ID_SELF ((u64)-1)
168#define HV_VP_INDEX_SELF ((u32)-2)
169
170#define HV_HYPERCALL_RESULT_MASK GENMASK_ULL(15, 0)
171#define HV_HYPERCALL_FAST_BIT BIT(16)
172#define HV_HYPERCALL_VARHEAD_OFFSET 17
173#define HV_HYPERCALL_REP_COMP_OFFSET 32
174#define HV_HYPERCALL_REP_COMP_1 BIT_ULL(32)
175#define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32)
176#define HV_HYPERCALL_REP_START_OFFSET 48
177#define HV_HYPERCALL_REP_START_MASK GENMASK_ULL(59, 48)
178
179/* hypercall status code */
180#define HV_STATUS_SUCCESS 0
181#define HV_STATUS_INVALID_HYPERCALL_CODE 2
182#define HV_STATUS_INVALID_HYPERCALL_INPUT 3
183#define HV_STATUS_INVALID_ALIGNMENT 4
184#define HV_STATUS_INVALID_PARAMETER 5
039aeb9d 185#define HV_STATUS_OPERATION_DENIED 8
c55a844f
MK
186#define HV_STATUS_INSUFFICIENT_MEMORY 11
187#define HV_STATUS_INVALID_PORT_ID 17
188#define HV_STATUS_INVALID_CONNECTION_ID 18
189#define HV_STATUS_INSUFFICIENT_BUFFERS 19
190
191/*
192 * The Hyper-V TimeRefCount register and the TSC
193 * page provide a guest VM clock with 100ns tick rate
194 */
195#define HV_CLOCK_HZ (NSEC_PER_SEC/100)
196
197/* Define the number of synthetic interrupt sources. */
198#define HV_SYNIC_SINT_COUNT (16)
199/* Define the expected SynIC version. */
200#define HV_SYNIC_VERSION_1 (0x1)
201/* Valid SynIC vectors are 16-255. */
202#define HV_SYNIC_FIRST_VALID_VECTOR (16)
203
204#define HV_SYNIC_CONTROL_ENABLE (1ULL << 0)
205#define HV_SYNIC_SIMP_ENABLE (1ULL << 0)
206#define HV_SYNIC_SIEFP_ENABLE (1ULL << 0)
207#define HV_SYNIC_SINT_MASKED (1ULL << 16)
208#define HV_SYNIC_SINT_AUTO_EOI (1ULL << 17)
209#define HV_SYNIC_SINT_VECTOR_MASK (0xFF)
210
211#define HV_SYNIC_STIMER_COUNT (4)
212
213/* Define synthetic interrupt controller message constants. */
214#define HV_MESSAGE_SIZE (256)
215#define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240)
216#define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30)
217
218/* Define synthetic interrupt controller message flags. */
219union hv_message_flags {
220 __u8 asu8;
221 struct {
222 __u8 msg_pending:1;
223 __u8 reserved:7;
224 } __packed;
225};
226
227/* Define port identifier type. */
228union hv_port_id {
229 __u32 asu32;
230 struct {
231 __u32 id:24;
232 __u32 reserved:8;
233 } __packed u;
234};
235
236/* Define synthetic interrupt controller message header. */
237struct hv_message_header {
238 __u32 message_type;
239 __u8 payload_size;
240 union hv_message_flags message_flags;
241 __u8 reserved[2];
242 union {
243 __u64 sender;
244 union hv_port_id port;
245 };
246} __packed;
247
248/* Define synthetic interrupt controller message format. */
249struct hv_message {
250 struct hv_message_header header;
251 union {
252 __u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
253 } u;
254} __packed;
255
256/* Define the synthetic interrupt message page layout. */
257struct hv_message_page {
258 struct hv_message sint_message[HV_SYNIC_SINT_COUNT];
259} __packed;
260
261/* Define timer message payload structure. */
262struct hv_timer_message_payload {
263 __u32 timer_index;
264 __u32 reserved;
265 __u64 expiration_time; /* When the timer expired */
266 __u64 delivery_time; /* When the message was delivered */
267} __packed;
268
269
270/* Define synthetic interrupt controller flag constants. */
271#define HV_EVENT_FLAGS_COUNT (256 * 8)
272#define HV_EVENT_FLAGS_LONG_COUNT (256 / sizeof(unsigned long))
273
274/*
275 * Synthetic timer configuration.
276 */
277union hv_stimer_config {
278 u64 as_uint64;
279 struct {
280 u64 enable:1;
281 u64 periodic:1;
282 u64 lazy:1;
283 u64 auto_enable:1;
284 u64 apic_vector:8;
285 u64 direct_mode:1;
286 u64 reserved_z0:3;
287 u64 sintx:4;
288 u64 reserved_z1:44;
289 } __packed;
290};
291
292
293/* Define the synthetic interrupt controller event flags format. */
294union hv_synic_event_flags {
295 unsigned long flags[HV_EVENT_FLAGS_LONG_COUNT];
296};
297
298/* Define SynIC control register. */
299union hv_synic_scontrol {
300 u64 as_uint64;
301 struct {
302 u64 enable:1;
303 u64 reserved:63;
304 } __packed;
305};
306
307/* Define synthetic interrupt source. */
308union hv_synic_sint {
309 u64 as_uint64;
310 struct {
311 u64 vector:8;
312 u64 reserved1:8;
313 u64 masked:1;
314 u64 auto_eoi:1;
315 u64 polling:1;
316 u64 reserved2:45;
317 } __packed;
318};
319
320/* Define the format of the SIMP register */
321union hv_synic_simp {
322 u64 as_uint64;
323 struct {
324 u64 simp_enabled:1;
325 u64 preserved:11;
326 u64 base_simp_gpa:52;
327 } __packed;
328};
329
330/* Define the format of the SIEFP register */
331union hv_synic_siefp {
332 u64 as_uint64;
333 struct {
334 u64 siefp_enabled:1;
335 u64 preserved:11;
336 u64 base_siefp_gpa:52;
337 } __packed;
338};
339
340struct hv_vpset {
341 u64 format;
342 u64 valid_bank_mask;
343 u64 bank_contents[];
344} __packed;
345
346/* HvCallSendSyntheticClusterIpi hypercall */
347struct hv_send_ipi {
348 u32 vector;
349 u32 reserved;
350 u64 cpu_mask;
351} __packed;
352
353/* HvCallSendSyntheticClusterIpiEx hypercall */
354struct hv_send_ipi_ex {
355 u32 vector;
356 u32 reserved;
357 struct hv_vpset vp_set;
358} __packed;
359
360/* HvFlushGuestPhysicalAddressSpace hypercalls */
361struct hv_guest_mapping_flush {
362 u64 address_space;
363 u64 flags;
364} __packed;
365
366/*
367 * HV_MAX_FLUSH_PAGES = "additional_pages" + 1. It's limited
368 * by the bitwidth of "additional_pages" in union hv_gpa_page_range.
369 */
370#define HV_MAX_FLUSH_PAGES (2048)
371
372/* HvFlushGuestPhysicalAddressList hypercall */
373union hv_gpa_page_range {
374 u64 address_space;
375 struct {
376 u64 additional_pages:11;
377 u64 largepage:1;
378 u64 basepfn:52;
379 } page;
380};
381
382/*
383 * All input flush parameters should be in single page. The max flush
384 * count is equal with how many entries of union hv_gpa_page_range can
385 * be populated into the input parameter page.
386 */
387#define HV_MAX_FLUSH_REP_COUNT ((HV_HYP_PAGE_SIZE - 2 * sizeof(u64)) / \
388 sizeof(union hv_gpa_page_range))
389
390struct hv_guest_mapping_flush_list {
391 u64 address_space;
392 u64 flags;
393 union hv_gpa_page_range gpa_list[HV_MAX_FLUSH_REP_COUNT];
394};
395
396/* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */
397struct hv_tlb_flush {
398 u64 address_space;
399 u64 flags;
400 u64 processor_mask;
401 u64 gva_list[];
402} __packed;
403
404/* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */
405struct hv_tlb_flush_ex {
406 u64 address_space;
407 u64 flags;
408 struct hv_vpset hv_vp_set;
409 u64 gva_list[];
410} __packed;
411
99a0f46a
WL
412/* HvGetPartitionId hypercall (output only) */
413struct hv_get_partition_id {
414 u64 partition_id;
415} __packed;
416
c55a844f
MK
417/* HvRetargetDeviceInterrupt hypercall */
418union hv_msi_entry {
419 u64 as_uint64;
420 struct {
421 u32 address;
422 u32 data;
423 } __packed;
424};
425
426struct hv_interrupt_entry {
427 u32 source; /* 1 for MSI(-X) */
428 u32 reserved1;
429 union hv_msi_entry msi_entry;
430} __packed;
431
432/*
433 * flags for hv_device_interrupt_target.flags
434 */
435#define HV_DEVICE_INTERRUPT_TARGET_MULTICAST 1
436#define HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET 2
437
438struct hv_device_interrupt_target {
439 u32 vector;
440 u32 flags;
441 union {
442 u64 vp_mask;
443 struct hv_vpset vp_set;
444 };
445} __packed;
446
447struct hv_retarget_device_interrupt {
448 u64 partition_id; /* use "self" */
449 u64 device_id;
450 struct hv_interrupt_entry int_entry;
451 u64 reserved2;
452 struct hv_device_interrupt_target int_target;
453} __packed __aligned(8);
454
88b42da6
MK
455
456/* HvGetVpRegisters hypercall input with variable size reg name list*/
457struct hv_get_vp_registers_input {
458 struct {
459 u64 partitionid;
460 u32 vpindex;
461 u8 inputvtl;
462 u8 padding[3];
463 } header;
464 struct input {
465 u32 name0;
466 u32 name1;
467 } element[];
468} __packed;
469
470
471/* HvGetVpRegisters returns an array of these output elements */
472struct hv_get_vp_registers_output {
473 union {
474 struct {
475 u32 a;
476 u32 b;
477 u32 c;
478 u32 d;
479 } as32 __packed;
480 struct {
481 u64 low;
482 u64 high;
483 } as64 __packed;
484 };
485};
486
487/* HvSetVpRegisters hypercall with variable size reg name/value list*/
488struct hv_set_vp_registers_input {
489 struct {
490 u64 partitionid;
491 u32 vpindex;
492 u8 inputvtl;
493 u8 padding[3];
494 } header;
495 struct {
496 u32 name;
497 u32 padding1;
498 u64 padding2;
499 u64 valuelow;
500 u64 valuehigh;
501 } element[];
502} __packed;
503
c55a844f 504#endif