18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci/*
48c2ecf20Sopenharmony_ci * This file contains definitions from Hyper-V Hypervisor Top-Level Functional
58c2ecf20Sopenharmony_ci * Specification (TLFS):
68c2ecf20Sopenharmony_ci * https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef _ASM_GENERIC_HYPERV_TLFS_H
108c2ecf20Sopenharmony_ci#define _ASM_GENERIC_HYPERV_TLFS_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/types.h>
138c2ecf20Sopenharmony_ci#include <linux/bits.h>
148c2ecf20Sopenharmony_ci#include <linux/time64.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/*
178c2ecf20Sopenharmony_ci * While not explicitly listed in the TLFS, Hyper-V always runs with a page size
188c2ecf20Sopenharmony_ci * of 4096. These definitions are used when communicating with Hyper-V using
198c2ecf20Sopenharmony_ci * guest physical pages and guest physical page addresses, since the guest page
208c2ecf20Sopenharmony_ci * size may not be 4096 on all architectures.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci#define HV_HYP_PAGE_SHIFT      12
238c2ecf20Sopenharmony_ci#define HV_HYP_PAGE_SIZE       BIT(HV_HYP_PAGE_SHIFT)
248c2ecf20Sopenharmony_ci#define HV_HYP_PAGE_MASK       (~(HV_HYP_PAGE_SIZE - 1))
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/*
278c2ecf20Sopenharmony_ci * Hyper-V provides two categories of flags relevant to guest VMs.  The
288c2ecf20Sopenharmony_ci * "Features" category indicates specific functionality that is available
298c2ecf20Sopenharmony_ci * to guests on this particular instance of Hyper-V. The "Features"
308c2ecf20Sopenharmony_ci * are presented in four groups, each of which is 32 bits. The group A
318c2ecf20Sopenharmony_ci * and B definitions are common across architectures and are listed here.
328c2ecf20Sopenharmony_ci * However, not all flags are relevant on all architectures.
338c2ecf20Sopenharmony_ci *
348c2ecf20Sopenharmony_ci * Groups C and D vary across architectures and are listed in the
358c2ecf20Sopenharmony_ci * architecture specific portion of hyperv-tlfs.h. Some of these flags exist
368c2ecf20Sopenharmony_ci * on multiple architectures, but the bit positions are different so they
378c2ecf20Sopenharmony_ci * cannot appear in the generic portion of hyperv-tlfs.h.
388c2ecf20Sopenharmony_ci *
398c2ecf20Sopenharmony_ci * The "Enlightenments" category provides recommendations on whether to use
408c2ecf20Sopenharmony_ci * specific enlightenments that are available. The Enlighenments are a single
418c2ecf20Sopenharmony_ci * group of 32 bits, but they vary across architectures and are listed in
428c2ecf20Sopenharmony_ci * the architecture specific portion of hyperv-tlfs.h.
438c2ecf20Sopenharmony_ci */
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/*
468c2ecf20Sopenharmony_ci * Group A Features.
478c2ecf20Sopenharmony_ci */
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/* VP Runtime register available */
508c2ecf20Sopenharmony_ci#define HV_MSR_VP_RUNTIME_AVAILABLE		BIT(0)
518c2ecf20Sopenharmony_ci/* Partition Reference Counter available*/
528c2ecf20Sopenharmony_ci#define HV_MSR_TIME_REF_COUNT_AVAILABLE		BIT(1)
538c2ecf20Sopenharmony_ci/* Basic SynIC register available */
548c2ecf20Sopenharmony_ci#define HV_MSR_SYNIC_AVAILABLE			BIT(2)
558c2ecf20Sopenharmony_ci/* Synthetic Timer registers available */
568c2ecf20Sopenharmony_ci#define HV_MSR_SYNTIMER_AVAILABLE		BIT(3)
578c2ecf20Sopenharmony_ci/* Virtual APIC assist and VP assist page registers available */
588c2ecf20Sopenharmony_ci#define HV_MSR_APIC_ACCESS_AVAILABLE		BIT(4)
598c2ecf20Sopenharmony_ci/* Hypercall and Guest OS ID registers available*/
608c2ecf20Sopenharmony_ci#define HV_MSR_HYPERCALL_AVAILABLE		BIT(5)
618c2ecf20Sopenharmony_ci/* Access virtual processor index register available*/
628c2ecf20Sopenharmony_ci#define HV_MSR_VP_INDEX_AVAILABLE		BIT(6)
638c2ecf20Sopenharmony_ci/* Virtual system reset register available*/
648c2ecf20Sopenharmony_ci#define HV_MSR_RESET_AVAILABLE			BIT(7)
658c2ecf20Sopenharmony_ci/* Access statistics page registers available */
668c2ecf20Sopenharmony_ci#define HV_MSR_STAT_PAGES_AVAILABLE		BIT(8)
678c2ecf20Sopenharmony_ci/* Partition reference TSC register is available */
688c2ecf20Sopenharmony_ci#define HV_MSR_REFERENCE_TSC_AVAILABLE		BIT(9)
698c2ecf20Sopenharmony_ci/* Partition Guest IDLE register is available */
708c2ecf20Sopenharmony_ci#define HV_MSR_GUEST_IDLE_AVAILABLE		BIT(10)
718c2ecf20Sopenharmony_ci/* Partition local APIC and TSC frequency registers available */
728c2ecf20Sopenharmony_ci#define HV_ACCESS_FREQUENCY_MSRS		BIT(11)
738c2ecf20Sopenharmony_ci/* AccessReenlightenmentControls privilege */
748c2ecf20Sopenharmony_ci#define HV_ACCESS_REENLIGHTENMENT		BIT(13)
758c2ecf20Sopenharmony_ci/* AccessTscInvariantControls privilege */
768c2ecf20Sopenharmony_ci#define HV_ACCESS_TSC_INVARIANT			BIT(15)
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/*
798c2ecf20Sopenharmony_ci * Group B features.
808c2ecf20Sopenharmony_ci */
818c2ecf20Sopenharmony_ci#define HV_CREATE_PARTITIONS			BIT(0)
828c2ecf20Sopenharmony_ci#define HV_ACCESS_PARTITION_ID			BIT(1)
838c2ecf20Sopenharmony_ci#define HV_ACCESS_MEMORY_POOL			BIT(2)
848c2ecf20Sopenharmony_ci#define HV_ADJUST_MESSAGE_BUFFERS		BIT(3)
858c2ecf20Sopenharmony_ci#define HV_POST_MESSAGES			BIT(4)
868c2ecf20Sopenharmony_ci#define HV_SIGNAL_EVENTS			BIT(5)
878c2ecf20Sopenharmony_ci#define HV_CREATE_PORT				BIT(6)
888c2ecf20Sopenharmony_ci#define HV_CONNECT_PORT				BIT(7)
898c2ecf20Sopenharmony_ci#define HV_ACCESS_STATS				BIT(8)
908c2ecf20Sopenharmony_ci#define HV_DEBUGGING				BIT(11)
918c2ecf20Sopenharmony_ci#define HV_CPU_POWER_MANAGEMENT			BIT(12)
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/*
958c2ecf20Sopenharmony_ci * TSC page layout.
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_cistruct ms_hyperv_tsc_page {
988c2ecf20Sopenharmony_ci	volatile u32 tsc_sequence;
998c2ecf20Sopenharmony_ci	u32 reserved1;
1008c2ecf20Sopenharmony_ci	volatile u64 tsc_scale;
1018c2ecf20Sopenharmony_ci	volatile s64 tsc_offset;
1028c2ecf20Sopenharmony_ci} __packed;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/*
1058c2ecf20Sopenharmony_ci * The guest OS needs to register the guest ID with the hypervisor.
1068c2ecf20Sopenharmony_ci * The guest ID is a 64 bit entity and the structure of this ID is
1078c2ecf20Sopenharmony_ci * specified in the Hyper-V specification:
1088c2ecf20Sopenharmony_ci *
1098c2ecf20Sopenharmony_ci * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
1108c2ecf20Sopenharmony_ci *
1118c2ecf20Sopenharmony_ci * While the current guideline does not specify how Linux guest ID(s)
1128c2ecf20Sopenharmony_ci * need to be generated, our plan is to publish the guidelines for
1138c2ecf20Sopenharmony_ci * Linux and other guest operating systems that currently are hosted
1148c2ecf20Sopenharmony_ci * on Hyper-V. The implementation here conforms to this yet
1158c2ecf20Sopenharmony_ci * unpublished guidelines.
1168c2ecf20Sopenharmony_ci *
1178c2ecf20Sopenharmony_ci *
1188c2ecf20Sopenharmony_ci * Bit(s)
1198c2ecf20Sopenharmony_ci * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
1208c2ecf20Sopenharmony_ci * 62:56 - Os Type; Linux is 0x100
1218c2ecf20Sopenharmony_ci * 55:48 - Distro specific identification
1228c2ecf20Sopenharmony_ci * 47:16 - Linux kernel version number
1238c2ecf20Sopenharmony_ci * 15:0  - Distro specific identification
1248c2ecf20Sopenharmony_ci *
1258c2ecf20Sopenharmony_ci *
1268c2ecf20Sopenharmony_ci */
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define HV_LINUX_VENDOR_ID              0x8100
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci/*
1318c2ecf20Sopenharmony_ci * Crash notification flags.
1328c2ecf20Sopenharmony_ci */
1338c2ecf20Sopenharmony_ci#define HV_CRASH_CTL_CRASH_NOTIFY_MSG		BIT_ULL(62)
1348c2ecf20Sopenharmony_ci#define HV_CRASH_CTL_CRASH_NOTIFY		BIT_ULL(63)
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci/* Declare the various hypercall operations. */
1378c2ecf20Sopenharmony_ci#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE	0x0002
1388c2ecf20Sopenharmony_ci#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST	0x0003
1398c2ecf20Sopenharmony_ci#define HVCALL_NOTIFY_LONG_SPIN_WAIT		0x0008
1408c2ecf20Sopenharmony_ci#define HVCALL_SEND_IPI				0x000b
1418c2ecf20Sopenharmony_ci#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX	0x0013
1428c2ecf20Sopenharmony_ci#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX	0x0014
1438c2ecf20Sopenharmony_ci#define HVCALL_SEND_IPI_EX			0x0015
1448c2ecf20Sopenharmony_ci#define HVCALL_GET_VP_REGISTERS			0x0050
1458c2ecf20Sopenharmony_ci#define HVCALL_SET_VP_REGISTERS			0x0051
1468c2ecf20Sopenharmony_ci#define HVCALL_POST_MESSAGE			0x005c
1478c2ecf20Sopenharmony_ci#define HVCALL_SIGNAL_EVENT			0x005d
1488c2ecf20Sopenharmony_ci#define HVCALL_POST_DEBUG_DATA			0x0069
1498c2ecf20Sopenharmony_ci#define HVCALL_RETRIEVE_DEBUG_DATA		0x006a
1508c2ecf20Sopenharmony_ci#define HVCALL_RESET_DEBUG_SESSION		0x006b
1518c2ecf20Sopenharmony_ci#define HVCALL_RETARGET_INTERRUPT		0x007e
1528c2ecf20Sopenharmony_ci#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af
1538c2ecf20Sopenharmony_ci#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#define HV_FLUSH_ALL_PROCESSORS			BIT(0)
1568c2ecf20Sopenharmony_ci#define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES	BIT(1)
1578c2ecf20Sopenharmony_ci#define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY	BIT(2)
1588c2ecf20Sopenharmony_ci#define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT	BIT(3)
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cienum HV_GENERIC_SET_FORMAT {
1618c2ecf20Sopenharmony_ci	HV_GENERIC_SET_SPARSE_4K,
1628c2ecf20Sopenharmony_ci	HV_GENERIC_SET_ALL,
1638c2ecf20Sopenharmony_ci};
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci#define HV_PARTITION_ID_SELF		((u64)-1)
1668c2ecf20Sopenharmony_ci#define HV_VP_INDEX_SELF		((u32)-2)
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci#define HV_HYPERCALL_RESULT_MASK	GENMASK_ULL(15, 0)
1698c2ecf20Sopenharmony_ci#define HV_HYPERCALL_FAST_BIT		BIT(16)
1708c2ecf20Sopenharmony_ci#define HV_HYPERCALL_VARHEAD_OFFSET	17
1718c2ecf20Sopenharmony_ci#define HV_HYPERCALL_REP_COMP_OFFSET	32
1728c2ecf20Sopenharmony_ci#define HV_HYPERCALL_REP_COMP_1		BIT_ULL(32)
1738c2ecf20Sopenharmony_ci#define HV_HYPERCALL_REP_COMP_MASK	GENMASK_ULL(43, 32)
1748c2ecf20Sopenharmony_ci#define HV_HYPERCALL_REP_START_OFFSET	48
1758c2ecf20Sopenharmony_ci#define HV_HYPERCALL_REP_START_MASK	GENMASK_ULL(59, 48)
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci/* hypercall status code */
1788c2ecf20Sopenharmony_ci#define HV_STATUS_SUCCESS			0
1798c2ecf20Sopenharmony_ci#define HV_STATUS_INVALID_HYPERCALL_CODE	2
1808c2ecf20Sopenharmony_ci#define HV_STATUS_INVALID_HYPERCALL_INPUT	3
1818c2ecf20Sopenharmony_ci#define HV_STATUS_INVALID_ALIGNMENT		4
1828c2ecf20Sopenharmony_ci#define HV_STATUS_INVALID_PARAMETER		5
1838c2ecf20Sopenharmony_ci#define HV_STATUS_OPERATION_DENIED		8
1848c2ecf20Sopenharmony_ci#define HV_STATUS_INSUFFICIENT_MEMORY		11
1858c2ecf20Sopenharmony_ci#define HV_STATUS_INVALID_PORT_ID		17
1868c2ecf20Sopenharmony_ci#define HV_STATUS_INVALID_CONNECTION_ID		18
1878c2ecf20Sopenharmony_ci#define HV_STATUS_INSUFFICIENT_BUFFERS		19
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci/*
1908c2ecf20Sopenharmony_ci * The Hyper-V TimeRefCount register and the TSC
1918c2ecf20Sopenharmony_ci * page provide a guest VM clock with 100ns tick rate
1928c2ecf20Sopenharmony_ci */
1938c2ecf20Sopenharmony_ci#define HV_CLOCK_HZ (NSEC_PER_SEC/100)
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/* Define the number of synthetic interrupt sources. */
1968c2ecf20Sopenharmony_ci#define HV_SYNIC_SINT_COUNT		(16)
1978c2ecf20Sopenharmony_ci/* Define the expected SynIC version. */
1988c2ecf20Sopenharmony_ci#define HV_SYNIC_VERSION_1		(0x1)
1998c2ecf20Sopenharmony_ci/* Valid SynIC vectors are 16-255. */
2008c2ecf20Sopenharmony_ci#define HV_SYNIC_FIRST_VALID_VECTOR	(16)
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci#define HV_SYNIC_CONTROL_ENABLE		(1ULL << 0)
2038c2ecf20Sopenharmony_ci#define HV_SYNIC_SIMP_ENABLE		(1ULL << 0)
2048c2ecf20Sopenharmony_ci#define HV_SYNIC_SIEFP_ENABLE		(1ULL << 0)
2058c2ecf20Sopenharmony_ci#define HV_SYNIC_SINT_MASKED		(1ULL << 16)
2068c2ecf20Sopenharmony_ci#define HV_SYNIC_SINT_AUTO_EOI		(1ULL << 17)
2078c2ecf20Sopenharmony_ci#define HV_SYNIC_SINT_VECTOR_MASK	(0xFF)
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci#define HV_SYNIC_STIMER_COUNT		(4)
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci/* Define synthetic interrupt controller message constants. */
2128c2ecf20Sopenharmony_ci#define HV_MESSAGE_SIZE			(256)
2138c2ecf20Sopenharmony_ci#define HV_MESSAGE_PAYLOAD_BYTE_COUNT	(240)
2148c2ecf20Sopenharmony_ci#define HV_MESSAGE_PAYLOAD_QWORD_COUNT	(30)
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci/* Define synthetic interrupt controller message flags. */
2178c2ecf20Sopenharmony_ciunion hv_message_flags {
2188c2ecf20Sopenharmony_ci	__u8 asu8;
2198c2ecf20Sopenharmony_ci	struct {
2208c2ecf20Sopenharmony_ci		__u8 msg_pending:1;
2218c2ecf20Sopenharmony_ci		__u8 reserved:7;
2228c2ecf20Sopenharmony_ci	} __packed;
2238c2ecf20Sopenharmony_ci};
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci/* Define port identifier type. */
2268c2ecf20Sopenharmony_ciunion hv_port_id {
2278c2ecf20Sopenharmony_ci	__u32 asu32;
2288c2ecf20Sopenharmony_ci	struct {
2298c2ecf20Sopenharmony_ci		__u32 id:24;
2308c2ecf20Sopenharmony_ci		__u32 reserved:8;
2318c2ecf20Sopenharmony_ci	} __packed u;
2328c2ecf20Sopenharmony_ci};
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci/* Define synthetic interrupt controller message header. */
2358c2ecf20Sopenharmony_cistruct hv_message_header {
2368c2ecf20Sopenharmony_ci	__u32 message_type;
2378c2ecf20Sopenharmony_ci	__u8 payload_size;
2388c2ecf20Sopenharmony_ci	union hv_message_flags message_flags;
2398c2ecf20Sopenharmony_ci	__u8 reserved[2];
2408c2ecf20Sopenharmony_ci	union {
2418c2ecf20Sopenharmony_ci		__u64 sender;
2428c2ecf20Sopenharmony_ci		union hv_port_id port;
2438c2ecf20Sopenharmony_ci	};
2448c2ecf20Sopenharmony_ci} __packed;
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci/* Define synthetic interrupt controller message format. */
2478c2ecf20Sopenharmony_cistruct hv_message {
2488c2ecf20Sopenharmony_ci	struct hv_message_header header;
2498c2ecf20Sopenharmony_ci	union {
2508c2ecf20Sopenharmony_ci		__u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
2518c2ecf20Sopenharmony_ci	} u;
2528c2ecf20Sopenharmony_ci} __packed;
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci/* Define the synthetic interrupt message page layout. */
2558c2ecf20Sopenharmony_cistruct hv_message_page {
2568c2ecf20Sopenharmony_ci	struct hv_message sint_message[HV_SYNIC_SINT_COUNT];
2578c2ecf20Sopenharmony_ci} __packed;
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci/* Define timer message payload structure. */
2608c2ecf20Sopenharmony_cistruct hv_timer_message_payload {
2618c2ecf20Sopenharmony_ci	__u32 timer_index;
2628c2ecf20Sopenharmony_ci	__u32 reserved;
2638c2ecf20Sopenharmony_ci	__u64 expiration_time;	/* When the timer expired */
2648c2ecf20Sopenharmony_ci	__u64 delivery_time;	/* When the message was delivered */
2658c2ecf20Sopenharmony_ci} __packed;
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci/* Define synthetic interrupt controller flag constants. */
2698c2ecf20Sopenharmony_ci#define HV_EVENT_FLAGS_COUNT		(256 * 8)
2708c2ecf20Sopenharmony_ci#define HV_EVENT_FLAGS_LONG_COUNT	(256 / sizeof(unsigned long))
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci/*
2738c2ecf20Sopenharmony_ci * Synthetic timer configuration.
2748c2ecf20Sopenharmony_ci */
2758c2ecf20Sopenharmony_ciunion hv_stimer_config {
2768c2ecf20Sopenharmony_ci	u64 as_uint64;
2778c2ecf20Sopenharmony_ci	struct {
2788c2ecf20Sopenharmony_ci		u64 enable:1;
2798c2ecf20Sopenharmony_ci		u64 periodic:1;
2808c2ecf20Sopenharmony_ci		u64 lazy:1;
2818c2ecf20Sopenharmony_ci		u64 auto_enable:1;
2828c2ecf20Sopenharmony_ci		u64 apic_vector:8;
2838c2ecf20Sopenharmony_ci		u64 direct_mode:1;
2848c2ecf20Sopenharmony_ci		u64 reserved_z0:3;
2858c2ecf20Sopenharmony_ci		u64 sintx:4;
2868c2ecf20Sopenharmony_ci		u64 reserved_z1:44;
2878c2ecf20Sopenharmony_ci	} __packed;
2888c2ecf20Sopenharmony_ci};
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci/* Define the synthetic interrupt controller event flags format. */
2928c2ecf20Sopenharmony_ciunion hv_synic_event_flags {
2938c2ecf20Sopenharmony_ci	unsigned long flags[HV_EVENT_FLAGS_LONG_COUNT];
2948c2ecf20Sopenharmony_ci};
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci/* Define SynIC control register. */
2978c2ecf20Sopenharmony_ciunion hv_synic_scontrol {
2988c2ecf20Sopenharmony_ci	u64 as_uint64;
2998c2ecf20Sopenharmony_ci	struct {
3008c2ecf20Sopenharmony_ci		u64 enable:1;
3018c2ecf20Sopenharmony_ci		u64 reserved:63;
3028c2ecf20Sopenharmony_ci	} __packed;
3038c2ecf20Sopenharmony_ci};
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci/* Define synthetic interrupt source. */
3068c2ecf20Sopenharmony_ciunion hv_synic_sint {
3078c2ecf20Sopenharmony_ci	u64 as_uint64;
3088c2ecf20Sopenharmony_ci	struct {
3098c2ecf20Sopenharmony_ci		u64 vector:8;
3108c2ecf20Sopenharmony_ci		u64 reserved1:8;
3118c2ecf20Sopenharmony_ci		u64 masked:1;
3128c2ecf20Sopenharmony_ci		u64 auto_eoi:1;
3138c2ecf20Sopenharmony_ci		u64 polling:1;
3148c2ecf20Sopenharmony_ci		u64 reserved2:45;
3158c2ecf20Sopenharmony_ci	} __packed;
3168c2ecf20Sopenharmony_ci};
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci/* Define the format of the SIMP register */
3198c2ecf20Sopenharmony_ciunion hv_synic_simp {
3208c2ecf20Sopenharmony_ci	u64 as_uint64;
3218c2ecf20Sopenharmony_ci	struct {
3228c2ecf20Sopenharmony_ci		u64 simp_enabled:1;
3238c2ecf20Sopenharmony_ci		u64 preserved:11;
3248c2ecf20Sopenharmony_ci		u64 base_simp_gpa:52;
3258c2ecf20Sopenharmony_ci	} __packed;
3268c2ecf20Sopenharmony_ci};
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci/* Define the format of the SIEFP register */
3298c2ecf20Sopenharmony_ciunion hv_synic_siefp {
3308c2ecf20Sopenharmony_ci	u64 as_uint64;
3318c2ecf20Sopenharmony_ci	struct {
3328c2ecf20Sopenharmony_ci		u64 siefp_enabled:1;
3338c2ecf20Sopenharmony_ci		u64 preserved:11;
3348c2ecf20Sopenharmony_ci		u64 base_siefp_gpa:52;
3358c2ecf20Sopenharmony_ci	} __packed;
3368c2ecf20Sopenharmony_ci};
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_cistruct hv_vpset {
3398c2ecf20Sopenharmony_ci	u64 format;
3408c2ecf20Sopenharmony_ci	u64 valid_bank_mask;
3418c2ecf20Sopenharmony_ci	u64 bank_contents[];
3428c2ecf20Sopenharmony_ci} __packed;
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci/* HvCallSendSyntheticClusterIpi hypercall */
3458c2ecf20Sopenharmony_cistruct hv_send_ipi {
3468c2ecf20Sopenharmony_ci	u32 vector;
3478c2ecf20Sopenharmony_ci	u32 reserved;
3488c2ecf20Sopenharmony_ci	u64 cpu_mask;
3498c2ecf20Sopenharmony_ci} __packed;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci/* HvCallSendSyntheticClusterIpiEx hypercall */
3528c2ecf20Sopenharmony_cistruct hv_send_ipi_ex {
3538c2ecf20Sopenharmony_ci	u32 vector;
3548c2ecf20Sopenharmony_ci	u32 reserved;
3558c2ecf20Sopenharmony_ci	struct hv_vpset vp_set;
3568c2ecf20Sopenharmony_ci} __packed;
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci/* HvFlushGuestPhysicalAddressSpace hypercalls */
3598c2ecf20Sopenharmony_cistruct hv_guest_mapping_flush {
3608c2ecf20Sopenharmony_ci	u64 address_space;
3618c2ecf20Sopenharmony_ci	u64 flags;
3628c2ecf20Sopenharmony_ci} __packed;
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci/*
3658c2ecf20Sopenharmony_ci *  HV_MAX_FLUSH_PAGES = "additional_pages" + 1. It's limited
3668c2ecf20Sopenharmony_ci *  by the bitwidth of "additional_pages" in union hv_gpa_page_range.
3678c2ecf20Sopenharmony_ci */
3688c2ecf20Sopenharmony_ci#define HV_MAX_FLUSH_PAGES (2048)
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci/* HvFlushGuestPhysicalAddressList hypercall */
3718c2ecf20Sopenharmony_ciunion hv_gpa_page_range {
3728c2ecf20Sopenharmony_ci	u64 address_space;
3738c2ecf20Sopenharmony_ci	struct {
3748c2ecf20Sopenharmony_ci		u64 additional_pages:11;
3758c2ecf20Sopenharmony_ci		u64 largepage:1;
3768c2ecf20Sopenharmony_ci		u64 basepfn:52;
3778c2ecf20Sopenharmony_ci	} page;
3788c2ecf20Sopenharmony_ci};
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci/*
3818c2ecf20Sopenharmony_ci * All input flush parameters should be in single page. The max flush
3828c2ecf20Sopenharmony_ci * count is equal with how many entries of union hv_gpa_page_range can
3838c2ecf20Sopenharmony_ci * be populated into the input parameter page.
3848c2ecf20Sopenharmony_ci */
3858c2ecf20Sopenharmony_ci#define HV_MAX_FLUSH_REP_COUNT ((HV_HYP_PAGE_SIZE - 2 * sizeof(u64)) /	\
3868c2ecf20Sopenharmony_ci				sizeof(union hv_gpa_page_range))
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_cistruct hv_guest_mapping_flush_list {
3898c2ecf20Sopenharmony_ci	u64 address_space;
3908c2ecf20Sopenharmony_ci	u64 flags;
3918c2ecf20Sopenharmony_ci	union hv_gpa_page_range gpa_list[HV_MAX_FLUSH_REP_COUNT];
3928c2ecf20Sopenharmony_ci};
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci/* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */
3958c2ecf20Sopenharmony_cistruct hv_tlb_flush {
3968c2ecf20Sopenharmony_ci	u64 address_space;
3978c2ecf20Sopenharmony_ci	u64 flags;
3988c2ecf20Sopenharmony_ci	u64 processor_mask;
3998c2ecf20Sopenharmony_ci	u64 gva_list[];
4008c2ecf20Sopenharmony_ci} __packed;
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci/* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */
4038c2ecf20Sopenharmony_cistruct hv_tlb_flush_ex {
4048c2ecf20Sopenharmony_ci	u64 address_space;
4058c2ecf20Sopenharmony_ci	u64 flags;
4068c2ecf20Sopenharmony_ci	struct hv_vpset hv_vp_set;
4078c2ecf20Sopenharmony_ci	u64 gva_list[];
4088c2ecf20Sopenharmony_ci} __packed;
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci/* HvRetargetDeviceInterrupt hypercall */
4118c2ecf20Sopenharmony_ciunion hv_msi_entry {
4128c2ecf20Sopenharmony_ci	u64 as_uint64;
4138c2ecf20Sopenharmony_ci	struct {
4148c2ecf20Sopenharmony_ci		u32 address;
4158c2ecf20Sopenharmony_ci		u32 data;
4168c2ecf20Sopenharmony_ci	} __packed;
4178c2ecf20Sopenharmony_ci};
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_cistruct hv_interrupt_entry {
4208c2ecf20Sopenharmony_ci	u32 source;			/* 1 for MSI(-X) */
4218c2ecf20Sopenharmony_ci	u32 reserved1;
4228c2ecf20Sopenharmony_ci	union hv_msi_entry msi_entry;
4238c2ecf20Sopenharmony_ci} __packed;
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci/*
4268c2ecf20Sopenharmony_ci * flags for hv_device_interrupt_target.flags
4278c2ecf20Sopenharmony_ci */
4288c2ecf20Sopenharmony_ci#define HV_DEVICE_INTERRUPT_TARGET_MULTICAST		1
4298c2ecf20Sopenharmony_ci#define HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET	2
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_cistruct hv_device_interrupt_target {
4328c2ecf20Sopenharmony_ci	u32 vector;
4338c2ecf20Sopenharmony_ci	u32 flags;
4348c2ecf20Sopenharmony_ci	union {
4358c2ecf20Sopenharmony_ci		u64 vp_mask;
4368c2ecf20Sopenharmony_ci		struct hv_vpset vp_set;
4378c2ecf20Sopenharmony_ci	};
4388c2ecf20Sopenharmony_ci} __packed;
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_cistruct hv_retarget_device_interrupt {
4418c2ecf20Sopenharmony_ci	u64 partition_id;		/* use "self" */
4428c2ecf20Sopenharmony_ci	u64 device_id;
4438c2ecf20Sopenharmony_ci	struct hv_interrupt_entry int_entry;
4448c2ecf20Sopenharmony_ci	u64 reserved2;
4458c2ecf20Sopenharmony_ci	struct hv_device_interrupt_target int_target;
4468c2ecf20Sopenharmony_ci} __packed __aligned(8);
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci/* HvGetVpRegisters hypercall input with variable size reg name list*/
4508c2ecf20Sopenharmony_cistruct hv_get_vp_registers_input {
4518c2ecf20Sopenharmony_ci	struct {
4528c2ecf20Sopenharmony_ci		u64 partitionid;
4538c2ecf20Sopenharmony_ci		u32 vpindex;
4548c2ecf20Sopenharmony_ci		u8  inputvtl;
4558c2ecf20Sopenharmony_ci		u8  padding[3];
4568c2ecf20Sopenharmony_ci	} header;
4578c2ecf20Sopenharmony_ci	struct input {
4588c2ecf20Sopenharmony_ci		u32 name0;
4598c2ecf20Sopenharmony_ci		u32 name1;
4608c2ecf20Sopenharmony_ci	} element[];
4618c2ecf20Sopenharmony_ci} __packed;
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci/* HvGetVpRegisters returns an array of these output elements */
4658c2ecf20Sopenharmony_cistruct hv_get_vp_registers_output {
4668c2ecf20Sopenharmony_ci	union {
4678c2ecf20Sopenharmony_ci		struct {
4688c2ecf20Sopenharmony_ci			u32 a;
4698c2ecf20Sopenharmony_ci			u32 b;
4708c2ecf20Sopenharmony_ci			u32 c;
4718c2ecf20Sopenharmony_ci			u32 d;
4728c2ecf20Sopenharmony_ci		} as32 __packed;
4738c2ecf20Sopenharmony_ci		struct {
4748c2ecf20Sopenharmony_ci			u64 low;
4758c2ecf20Sopenharmony_ci			u64 high;
4768c2ecf20Sopenharmony_ci		} as64 __packed;
4778c2ecf20Sopenharmony_ci	};
4788c2ecf20Sopenharmony_ci};
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci/* HvSetVpRegisters hypercall with variable size reg name/value list*/
4818c2ecf20Sopenharmony_cistruct hv_set_vp_registers_input {
4828c2ecf20Sopenharmony_ci	struct {
4838c2ecf20Sopenharmony_ci		u64 partitionid;
4848c2ecf20Sopenharmony_ci		u32 vpindex;
4858c2ecf20Sopenharmony_ci		u8  inputvtl;
4868c2ecf20Sopenharmony_ci		u8  padding[3];
4878c2ecf20Sopenharmony_ci	} header;
4888c2ecf20Sopenharmony_ci	struct {
4898c2ecf20Sopenharmony_ci		u32 name;
4908c2ecf20Sopenharmony_ci		u32 padding1;
4918c2ecf20Sopenharmony_ci		u64 padding2;
4928c2ecf20Sopenharmony_ci		u64 valuelow;
4938c2ecf20Sopenharmony_ci		u64 valuehigh;
4948c2ecf20Sopenharmony_ci	} element[];
4958c2ecf20Sopenharmony_ci} __packed;
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci#endif
498