linux/include/asm-generic/hyperv-tlfs.h

/* SPDX-License-Identifier: GPL-2.0 */

/*
 * This file contains definitions from Hyper-V Hypervisor Top-Level Functional
 * Specification (TLFS):
 * https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs
 */

#ifndef _ASM_GENERIC_HYPERV_TLFS_H
#define _ASM_GENERIC_HYPERV_TLFS_H

#include <linux/types.h>
#include <linux/bits.h>
#include <linux/time64.h>

/*
 * While not explicitly listed in the TLFS, Hyper-V always runs with a page size
 * of 4096. These definitions are used when communicating with Hyper-V using
 * guest physical pages and guest physical page addresses, since the guest page
 * size may not be 4096 on all architectures.
 */
#define HV_HYP_PAGE_SHIFT
#define HV_HYP_PAGE_SIZE
#define HV_HYP_PAGE_MASK

/*
 * Hyper-V provides two categories of flags relevant to guest VMs.  The
 * "Features" category indicates specific functionality that is available
 * to guests on this particular instance of Hyper-V. The "Features"
 * are presented in four groups, each of which is 32 bits. The group A
 * and B definitions are common across architectures and are listed here.
 * However, not all flags are relevant on all architectures.
 *
 * Groups C and D vary across architectures and are listed in the
 * architecture specific portion of hyperv-tlfs.h. Some of these flags exist
 * on multiple architectures, but the bit positions are different so they
 * cannot appear in the generic portion of hyperv-tlfs.h.
 *
 * The "Enlightenments" category provides recommendations on whether to use
 * specific enlightenments that are available. The Enlighenments are a single
 * group of 32 bits, but they vary across architectures and are listed in
 * the architecture specific portion of hyperv-tlfs.h.
 */

/*
 * Group A Features.
 */

/* VP Runtime register available */
#define HV_MSR_VP_RUNTIME_AVAILABLE
/* Partition Reference Counter available*/
#define HV_MSR_TIME_REF_COUNT_AVAILABLE
/* Basic SynIC register available */
#define HV_MSR_SYNIC_AVAILABLE
/* Synthetic Timer registers available */
#define HV_MSR_SYNTIMER_AVAILABLE
/* Virtual APIC assist and VP assist page registers available */
#define HV_MSR_APIC_ACCESS_AVAILABLE
/* Hypercall and Guest OS ID registers available*/
#define HV_MSR_HYPERCALL_AVAILABLE
/* Access virtual processor index register available*/
#define HV_MSR_VP_INDEX_AVAILABLE
/* Virtual system reset register available*/
#define HV_MSR_RESET_AVAILABLE
/* Access statistics page registers available */
#define HV_MSR_STAT_PAGES_AVAILABLE
/* Partition reference TSC register is available */
#define HV_MSR_REFERENCE_TSC_AVAILABLE
/* Partition Guest IDLE register is available */
#define HV_MSR_GUEST_IDLE_AVAILABLE
/* Partition local APIC and TSC frequency registers available */
#define HV_ACCESS_FREQUENCY_MSRS
/* AccessReenlightenmentControls privilege */
#define HV_ACCESS_REENLIGHTENMENT
/* AccessTscInvariantControls privilege */
#define HV_ACCESS_TSC_INVARIANT

/*
 * Group B features.
 */
#define HV_CREATE_PARTITIONS
#define HV_ACCESS_PARTITION_ID
#define HV_ACCESS_MEMORY_POOL
#define HV_ADJUST_MESSAGE_BUFFERS
#define HV_POST_MESSAGES
#define HV_SIGNAL_EVENTS
#define HV_CREATE_PORT
#define HV_CONNECT_PORT
#define HV_ACCESS_STATS
#define HV_DEBUGGING
#define HV_CPU_MANAGEMENT
#define HV_ENABLE_EXTENDED_HYPERCALLS
#define HV_ISOLATION

/*
 * TSC page layout.
 */
struct ms_hyperv_tsc_page {} __packed;

hv_reference_tsc_msr;

/*
 * The guest OS needs to register the guest ID with the hypervisor.
 * The guest ID is a 64 bit entity and the structure of this ID is
 * specified in the Hyper-V specification:
 *
 * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
 *
 * While the current guideline does not specify how Linux guest ID(s)
 * need to be generated, our plan is to publish the guidelines for
 * Linux and other guest operating systems that currently are hosted
 * on Hyper-V. The implementation here conforms to this yet
 * unpublished guidelines.
 *
 *
 * Bit(s)
 * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
 * 62:56 - Os Type; Linux is 0x100
 * 55:48 - Distro specific identification
 * 47:16 - Linux kernel version number
 * 15:0  - Distro specific identification
 *
 *
 */

#define HV_LINUX_VENDOR_ID

/*
 * Crash notification flags.
 */
#define HV_CRASH_CTL_CRASH_NOTIFY_MSG
#define HV_CRASH_CTL_CRASH_NOTIFY

/* Declare the various hypercall operations. */
#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE
#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST
#define HVCALL_ENABLE_VP_VTL
#define HVCALL_NOTIFY_LONG_SPIN_WAIT
#define HVCALL_SEND_IPI
#define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX
#define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX
#define HVCALL_SEND_IPI_EX
#define HVCALL_GET_PARTITION_ID
#define HVCALL_DEPOSIT_MEMORY
#define HVCALL_CREATE_VP
#define HVCALL_GET_VP_REGISTERS
#define HVCALL_SET_VP_REGISTERS
#define HVCALL_POST_MESSAGE
#define HVCALL_SIGNAL_EVENT
#define HVCALL_POST_DEBUG_DATA
#define HVCALL_RETRIEVE_DEBUG_DATA
#define HVCALL_RESET_DEBUG_SESSION
#define HVCALL_ADD_LOGICAL_PROCESSOR
#define HVCALL_MAP_DEVICE_INTERRUPT
#define HVCALL_UNMAP_DEVICE_INTERRUPT
#define HVCALL_RETARGET_INTERRUPT
#define HVCALL_START_VP
#define HVCALL_GET_VP_ID_FROM_APIC_ID
#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE
#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST
#define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY
#define HVCALL_MMIO_READ
#define HVCALL_MMIO_WRITE

/* Extended hypercalls */
#define HV_EXT_CALL_QUERY_CAPABILITIES
#define HV_EXT_CALL_MEMORY_HEAT_HINT

#define HV_FLUSH_ALL_PROCESSORS
#define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES
#define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY
#define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT

/* Extended capability bits */
#define HV_EXT_CAPABILITY_MEMORY_COLD_DISCARD_HINT

enum HV_GENERIC_SET_FORMAT {};

#define HV_PARTITION_ID_SELF
#define HV_VP_INDEX_SELF

#define HV_HYPERCALL_RESULT_MASK
#define HV_HYPERCALL_FAST_BIT
#define HV_HYPERCALL_VARHEAD_OFFSET
#define HV_HYPERCALL_VARHEAD_MASK
#define HV_HYPERCALL_RSVD0_MASK
#define HV_HYPERCALL_NESTED
#define HV_HYPERCALL_REP_COMP_OFFSET
#define HV_HYPERCALL_REP_COMP_1
#define HV_HYPERCALL_REP_COMP_MASK
#define HV_HYPERCALL_RSVD1_MASK
#define HV_HYPERCALL_REP_START_OFFSET
#define HV_HYPERCALL_REP_START_MASK
#define HV_HYPERCALL_RSVD2_MASK
#define HV_HYPERCALL_RSVD_MASK

/* hypercall status code */
#define HV_STATUS_SUCCESS
#define HV_STATUS_INVALID_HYPERCALL_CODE
#define HV_STATUS_INVALID_HYPERCALL_INPUT
#define HV_STATUS_INVALID_ALIGNMENT
#define HV_STATUS_INVALID_PARAMETER
#define HV_STATUS_ACCESS_DENIED
#define HV_STATUS_OPERATION_DENIED
#define HV_STATUS_INSUFFICIENT_MEMORY
#define HV_STATUS_INVALID_PORT_ID
#define HV_STATUS_INVALID_CONNECTION_ID
#define HV_STATUS_INSUFFICIENT_BUFFERS
#define HV_STATUS_TIME_OUT
#define HV_STATUS_VTL_ALREADY_ENABLED

/*
 * The Hyper-V TimeRefCount register and the TSC
 * page provide a guest VM clock with 100ns tick rate
 */
#define HV_CLOCK_HZ

/* Define the number of synthetic interrupt sources. */
#define HV_SYNIC_SINT_COUNT
/* Define the expected SynIC version. */
#define HV_SYNIC_VERSION_1
/* Valid SynIC vectors are 16-255. */
#define HV_SYNIC_FIRST_VALID_VECTOR

#define HV_SYNIC_CONTROL_ENABLE
#define HV_SYNIC_SIMP_ENABLE
#define HV_SYNIC_SIEFP_ENABLE
#define HV_SYNIC_SINT_MASKED
#define HV_SYNIC_SINT_AUTO_EOI
#define HV_SYNIC_SINT_VECTOR_MASK

#define HV_SYNIC_STIMER_COUNT

/* Define synthetic interrupt controller message constants. */
#define HV_MESSAGE_SIZE
#define HV_MESSAGE_PAYLOAD_BYTE_COUNT
#define HV_MESSAGE_PAYLOAD_QWORD_COUNT

/*
 * Define hypervisor message types. Some of the message types
 * are x86/x64 specific, but there's no good way to separate
 * them out into the arch-specific version of hyperv-tlfs.h
 * because C doesn't provide a way to extend enum types.
 * Keeping them all in the arch neutral hyperv-tlfs.h seems
 * the least messy compromise.
 */
enum hv_message_type {};

/* Define synthetic interrupt controller message flags. */
hv_message_flags;

/* Define port identifier type. */
hv_port_id;

/* Define synthetic interrupt controller message header. */
struct hv_message_header {} __packed;

/* Define synthetic interrupt controller message format. */
struct hv_message {} __packed;

/* Define the synthetic interrupt message page layout. */
struct hv_message_page {} __packed;

/* Define timer message payload structure. */
struct hv_timer_message_payload {} __packed;


/* Define synthetic interrupt controller flag constants. */
#define HV_EVENT_FLAGS_COUNT
#define HV_EVENT_FLAGS_LONG_COUNT

/*
 * Synthetic timer configuration.
 */
hv_stimer_config;


/* Define the synthetic interrupt controller event flags format. */
hv_synic_event_flags;

/* Define SynIC control register. */
hv_synic_scontrol;

/* Define synthetic interrupt source. */
hv_synic_sint;

/* Define the format of the SIMP register */
hv_synic_simp;

/* Define the format of the SIEFP register */
hv_synic_siefp;

struct hv_vpset {} __packed;

/* The maximum number of sparse vCPU banks which can be encoded by 'struct hv_vpset' */
#define HV_MAX_SPARSE_VCPU_BANKS
/* The number of vCPUs in one sparse bank */
#define HV_VCPUS_PER_SPARSE_BANK

/* HvCallSendSyntheticClusterIpi hypercall */
struct hv_send_ipi {} __packed;

/* HvCallSendSyntheticClusterIpiEx hypercall */
struct hv_send_ipi_ex {} __packed;

/* HvFlushGuestPhysicalAddressSpace hypercalls */
struct hv_guest_mapping_flush {} __packed;

/*
 *  HV_MAX_FLUSH_PAGES = "additional_pages" + 1. It's limited
 *  by the bitwidth of "additional_pages" in union hv_gpa_page_range.
 */
#define HV_MAX_FLUSH_PAGES
#define HV_GPA_PAGE_RANGE_PAGE_SIZE_2MB
#define HV_GPA_PAGE_RANGE_PAGE_SIZE_1GB

/* HvFlushGuestPhysicalAddressList, HvExtCallMemoryHeatHint hypercall */
hv_gpa_page_range;

/*
 * All input flush parameters should be in single page. The max flush
 * count is equal with how many entries of union hv_gpa_page_range can
 * be populated into the input parameter page.
 */
#define HV_MAX_FLUSH_REP_COUNT

struct hv_guest_mapping_flush_list {};

/* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */
struct hv_tlb_flush {} __packed;

/* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */
struct hv_tlb_flush_ex {} __packed;

/* HvGetPartitionId hypercall (output only) */
struct hv_get_partition_id {} __packed;

/* HvDepositMemory hypercall */
struct hv_deposit_memory {} __packed;

struct hv_proximity_domain_flags {} __packed;

struct hv_proximity_domain_info {} __packed;

struct hv_lp_startup_status {} __packed;

/* HvAddLogicalProcessor hypercall */
struct hv_input_add_logical_processor {} __packed;

struct hv_output_add_logical_processor {} __packed;

enum HV_SUBNODE_TYPE
{};

/* HvCreateVp hypercall */
struct hv_create_vp {} __packed;

enum hv_interrupt_source {};

hv_ioapic_rte __packed;

struct hv_interrupt_entry {} __packed;

/*
 * flags for hv_device_interrupt_target.flags
 */
#define HV_DEVICE_INTERRUPT_TARGET_MULTICAST
#define HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET

struct hv_device_interrupt_target {} __packed;

struct hv_retarget_device_interrupt {} __packed __aligned();

/*
 * These Hyper-V registers provide information equivalent to the CPUID
 * instruction on x86/x64.
 */
#define HV_REGISTER_HYPERVISOR_VERSION
#define HV_REGISTER_FEATURES
#define HV_REGISTER_ENLIGHTENMENTS

/*
 * Synthetic register definitions equivalent to MSRs on x86/x64
 */
#define HV_REGISTER_GUEST_CRASH_P0
#define HV_REGISTER_GUEST_CRASH_P1
#define HV_REGISTER_GUEST_CRASH_P2
#define HV_REGISTER_GUEST_CRASH_P3
#define HV_REGISTER_GUEST_CRASH_P4
#define HV_REGISTER_GUEST_CRASH_CTL

#define HV_REGISTER_GUEST_OS_ID
#define HV_REGISTER_VP_INDEX
#define HV_REGISTER_TIME_REF_COUNT
#define HV_REGISTER_REFERENCE_TSC

#define HV_REGISTER_SINT0
#define HV_REGISTER_SCONTROL
#define HV_REGISTER_SIEFP
#define HV_REGISTER_SIMP
#define HV_REGISTER_EOM

#define HV_REGISTER_STIMER0_CONFIG
#define HV_REGISTER_STIMER0_COUNT

/* HvGetVpRegisters hypercall input with variable size reg name list*/
struct hv_get_vp_registers_input {} __packed;

/* HvGetVpRegisters returns an array of these output elements */
struct hv_get_vp_registers_output {};

/* HvSetVpRegisters hypercall with variable size reg name/value list*/
struct hv_set_vp_registers_input {} __packed;

enum hv_device_type {};

hv_pci_rid;
hv_pci_segment;
hv_logical_device_id;
hv_pci_bdf __packed;

hv_pci_bus_range __packed;

hv_device_id __packed;

enum hv_interrupt_trigger_mode {};

struct hv_device_interrupt_descriptor {} __packed;

struct hv_input_map_device_interrupt {} __packed;

struct hv_output_map_device_interrupt {} __packed;

struct hv_input_unmap_device_interrupt {} __packed;

#define HV_SOURCE_SHADOW_NONE
#define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE

/*
 * Version info reported by hypervisor
 */
hv_hypervisor_version_info;

/*
 * The whole argument should fit in a page to be able to pass to the hypervisor
 * in one hypercall.
 */
#define HV_MEMORY_HINT_MAX_GPA_PAGE_RANGES

/* HvExtCallMemoryHeatHint hypercall */
#define HV_EXT_MEMORY_HEAT_HINT_TYPE_COLD_DISCARD
struct hv_memory_hint {} __packed;

/* Data structures for HVCALL_MMIO_READ and HVCALL_MMIO_WRITE */
#define HV_HYPERCALL_MMIO_MAX_DATA_LENGTH

struct hv_mmio_read_input {} __packed;

struct hv_mmio_read_output {} __packed;

struct hv_mmio_write_input {} __packed;

#endif