1*4d846d26SWarner Losh /*- SPDX-License-Identifier: BSD-2-Clause 2d16d0b6bSSouradeep Chakrabarti * Copyright (c) 2022 Microsoft Corp. 3d16d0b6bSSouradeep Chakrabarti * All rights reserved. 4d16d0b6bSSouradeep Chakrabarti * 5d16d0b6bSSouradeep Chakrabarti * Redistribution and use in source and binary forms, with or without 6d16d0b6bSSouradeep Chakrabarti * modification, are permitted provided that the following conditions 7d16d0b6bSSouradeep Chakrabarti * are met: 8d16d0b6bSSouradeep Chakrabarti * 1. Redistributions of source code must retain the above copyright 9d16d0b6bSSouradeep Chakrabarti * notice unmodified, this list of conditions, and the following 10d16d0b6bSSouradeep Chakrabarti * disclaimer. 11d16d0b6bSSouradeep Chakrabarti * 2. Redistributions in binary form must reproduce the above copyright 12d16d0b6bSSouradeep Chakrabarti * notice, this list of conditions and the following disclaimer in the 13d16d0b6bSSouradeep Chakrabarti * documentation and/or other materials provided with the distribution. 14d16d0b6bSSouradeep Chakrabarti * 15d16d0b6bSSouradeep Chakrabarti * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16d16d0b6bSSouradeep Chakrabarti * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17d16d0b6bSSouradeep Chakrabarti * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18d16d0b6bSSouradeep Chakrabarti * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19d16d0b6bSSouradeep Chakrabarti * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20d16d0b6bSSouradeep Chakrabarti * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21d16d0b6bSSouradeep Chakrabarti * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22d16d0b6bSSouradeep Chakrabarti * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23d16d0b6bSSouradeep Chakrabarti * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24d16d0b6bSSouradeep Chakrabarti * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25d16d0b6bSSouradeep Chakrabarti * 26d16d0b6bSSouradeep Chakrabarti * $FreeBSD$ 27d16d0b6bSSouradeep Chakrabarti */ 28d16d0b6bSSouradeep Chakrabarti 29d16d0b6bSSouradeep Chakrabarti #ifndef _HYPERV_COMMON_REG_H_ 30d16d0b6bSSouradeep Chakrabarti #define _HYPERV_COMMON_REG_H_ 31d16d0b6bSSouradeep Chakrabarti 32d16d0b6bSSouradeep Chakrabarti #include <sys/param.h> 33d16d0b6bSSouradeep Chakrabarti #include <sys/systm.h> 34d16d0b6bSSouradeep Chakrabarti 35d16d0b6bSSouradeep Chakrabarti #define MSR_HV_GUESTID_BUILD_MASK 0xffffULL 36d16d0b6bSSouradeep Chakrabarti #define MSR_HV_GUESTID_VERSION_MASK 0x0000ffffffff0000ULL 37d16d0b6bSSouradeep Chakrabarti #define MSR_HV_GUESTID_VERSION_SHIFT 16 38d16d0b6bSSouradeep Chakrabarti #define MSR_HV_GUESTID_OSID_MASK 0x00ff000000000000ULL 39d16d0b6bSSouradeep Chakrabarti #define MSR_HV_GUESTID_OSID_SHIFT 48 40d16d0b6bSSouradeep Chakrabarti #define MSR_HV_GUESTID_OSTYPE_MASK 0x7f00000000000000ULL 41d16d0b6bSSouradeep Chakrabarti #define MSR_HV_GUESTID_OSTYPE_SHIFT 56 42d16d0b6bSSouradeep Chakrabarti #define MSR_HV_GUESTID_OPENSRC 0x8000000000000000ULL 43d16d0b6bSSouradeep Chakrabarti #define MSR_HV_GUESTID_OSTYPE_LINUX \ 44d16d0b6bSSouradeep Chakrabarti ((0x01ULL << MSR_HV_GUESTID_OSTYPE_SHIFT) | MSR_HV_GUESTID_OPENSRC) 45d16d0b6bSSouradeep Chakrabarti #define MSR_HV_GUESTID_OSTYPE_FREEBSD \ 46d16d0b6bSSouradeep Chakrabarti ((0x02ULL << MSR_HV_GUESTID_OSTYPE_SHIFT) | MSR_HV_GUESTID_OPENSRC) 47d16d0b6bSSouradeep Chakrabarti 48d16d0b6bSSouradeep Chakrabarti #define MSR_HV_HYPERCALL 0x40000001 49d16d0b6bSSouradeep Chakrabarti #define MSR_HV_HYPERCALL_ENABLE 0x0001ULL 50d16d0b6bSSouradeep Chakrabarti #define MSR_HV_HYPERCALL_RSVD_MASK 0x0ffeULL 51d16d0b6bSSouradeep Chakrabarti #define MSR_HV_HYPERCALL_PGSHIFT 12 52d16d0b6bSSouradeep Chakrabarti 53d16d0b6bSSouradeep Chakrabarti #define MSR_HV_REFERENCE_TSC 0x40000021 54d16d0b6bSSouradeep Chakrabarti #define MSR_HV_REFTSC_ENABLE 0x0001ULL 55d16d0b6bSSouradeep Chakrabarti #define MSR_HV_REFTSC_RSVD_MASK 0x0ffeULL 56d16d0b6bSSouradeep Chakrabarti #define MSR_HV_REFTSC_PGSHIFT 12 57d16d0b6bSSouradeep Chakrabarti 58d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SCTRL_ENABLE 0x0001ULL 59d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SCTRL_RSVD_MASK 0xfffffffffffffffeULL 60d16d0b6bSSouradeep Chakrabarti 61d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SIEFP_ENABLE 0x0001ULL 62d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SIEFP_RSVD_MASK 0x0ffeULL 63d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SIEFP_PGSHIFT 12 64d16d0b6bSSouradeep Chakrabarti 65d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SIMP_ENABLE 0x0001ULL 66d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SIMP_RSVD_MASK 0x0ffeULL 67d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SIMP_PGSHIFT 12 68d16d0b6bSSouradeep Chakrabarti 69d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SINT_VECTOR_MASK 0x00ffULL 70d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SINT_RSVD1_MASK 0xff00ULL 71d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SINT_MASKED 0x00010000ULL 72d16d0b6bSSouradeep Chakrabarti 73d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SINT_RSVD2_MASK 0xfffffffffffc0000ULL 74d16d0b6bSSouradeep Chakrabarti #define MSR_HV_SINT_RSVD_MASK (MSR_HV_SINT_RSVD1_MASK | \ 75d16d0b6bSSouradeep Chakrabarti MSR_HV_SINT_RSVD2_MASK) 76d16d0b6bSSouradeep Chakrabarti 77d16d0b6bSSouradeep Chakrabarti #define MSR_HV_STIMER0_CONFIG 0x400000b0 78d16d0b6bSSouradeep Chakrabarti #define MSR_HV_STIMER_CFG_ENABLE 0x0001ULL 79d16d0b6bSSouradeep Chakrabarti #define MSR_HV_STIMER_CFG_PERIODIC 0x0002ULL 80d16d0b6bSSouradeep Chakrabarti #define MSR_HV_STIMER_CFG_LAZY 0x0004ULL 81d16d0b6bSSouradeep Chakrabarti #define MSR_HV_STIMER_CFG_AUTOEN 0x0008ULL 82d16d0b6bSSouradeep Chakrabarti #define MSR_HV_STIMER_CFG_SINT_MASK 0x000f0000ULL 83d16d0b6bSSouradeep Chakrabarti #define MSR_HV_STIMER_CFG_SINT_SHIFT 16 84d16d0b6bSSouradeep Chakrabarti 85d16d0b6bSSouradeep Chakrabarti #define MSR_HV_STIMER0_COUNT 0x400000b1 86d16d0b6bSSouradeep Chakrabarti 87d16d0b6bSSouradeep Chakrabarti /* 88d16d0b6bSSouradeep Chakrabarti * CPUID leaves 89d16d0b6bSSouradeep Chakrabarti */ 90d16d0b6bSSouradeep Chakrabarti 91d16d0b6bSSouradeep Chakrabarti #define CPUID_LEAF_HV_MAXLEAF 0x40000000 92d16d0b6bSSouradeep Chakrabarti 93d16d0b6bSSouradeep Chakrabarti #define CPUID_LEAF_HV_INTERFACE 0x40000001 94d16d0b6bSSouradeep Chakrabarti #define CPUID_HV_IFACE_HYPERV 0x31237648 /* HV#1 */ 95d16d0b6bSSouradeep Chakrabarti 96d16d0b6bSSouradeep Chakrabarti /* EAX: features include/hyperv.h CPUID_HV_MSR */ 97d16d0b6bSSouradeep Chakrabarti /* ECX: power management features */ 98d16d0b6bSSouradeep Chakrabarti #define CPUPM_HV_CSTATE_MASK 0x000f /* deepest C-state */ 99d16d0b6bSSouradeep Chakrabarti #define CPUPM_HV_C3_HPET 0x0010 /* C3 requires HPET */ 100d16d0b6bSSouradeep Chakrabarti #define CPUPM_HV_CSTATE(f) ((f) & CPUPM_HV_CSTATE_MASK) 101d16d0b6bSSouradeep Chakrabarti /* EDX: features3 */ 102d16d0b6bSSouradeep Chakrabarti #define CPUID3_HV_MWAIT 0x0001 /* MWAIT */ 103d16d0b6bSSouradeep Chakrabarti #define CPUID3_HV_XMM_HYPERCALL 0x0010 /* Hypercall input through 104d16d0b6bSSouradeep Chakrabarti * XMM regs */ 105d16d0b6bSSouradeep Chakrabarti #define CPUID3_HV_GUEST_IDLE 0x0020 /* guest idle */ 106d16d0b6bSSouradeep Chakrabarti #define CPUID3_HV_NUMA 0x0080 /* NUMA distance query */ 107d16d0b6bSSouradeep Chakrabarti #define CPUID3_HV_TIME_FREQ 0x0100 /* timer frequency query 108d16d0b6bSSouradeep Chakrabarti * (TSC, LAPIC) */ 109d16d0b6bSSouradeep Chakrabarti #define CPUID3_HV_MSR_CRASH 0x0400 /* MSRs for guest crash */ 110d16d0b6bSSouradeep Chakrabarti #define CPUID_LEAF_HV_LIMITS 0x40000005 111d16d0b6bSSouradeep Chakrabarti #define CPUID_LEAF_HV_HWFEATURES 0x40000006 112d16d0b6bSSouradeep Chakrabarti 113d16d0b6bSSouradeep Chakrabarti /* 114d16d0b6bSSouradeep Chakrabarti * Hyper-V Monitor Notification Facility 115d16d0b6bSSouradeep Chakrabarti */ 116d16d0b6bSSouradeep Chakrabarti struct hyperv_mon_param { 117d16d0b6bSSouradeep Chakrabarti uint32_t mp_connid; 118d16d0b6bSSouradeep Chakrabarti uint16_t mp_evtflag_ofs; 119d16d0b6bSSouradeep Chakrabarti uint16_t mp_rsvd; 120d16d0b6bSSouradeep Chakrabarti } __packed; 121d16d0b6bSSouradeep Chakrabarti 122d16d0b6bSSouradeep Chakrabarti /* 123d16d0b6bSSouradeep Chakrabarti * Hyper-V message types 124d16d0b6bSSouradeep Chakrabarti */ 125d16d0b6bSSouradeep Chakrabarti #define HYPERV_MSGTYPE_NONE 0 126d16d0b6bSSouradeep Chakrabarti #define HYPERV_MSGTYPE_CHANNEL 1 127d16d0b6bSSouradeep Chakrabarti #define HYPERV_MSGTYPE_TIMER_EXPIRED 0x80000010 128d16d0b6bSSouradeep Chakrabarti 129d16d0b6bSSouradeep Chakrabarti /* 130d16d0b6bSSouradeep Chakrabarti * Hypercall status codes 131d16d0b6bSSouradeep Chakrabarti */ 132d16d0b6bSSouradeep Chakrabarti #define HYPERCALL_STATUS_SUCCESS 0x0000 133d16d0b6bSSouradeep Chakrabarti 134d16d0b6bSSouradeep Chakrabarti /* 135d16d0b6bSSouradeep Chakrabarti * Hypercall input values 136d16d0b6bSSouradeep Chakrabarti */ 137d16d0b6bSSouradeep Chakrabarti #define HYPERCALL_POST_MESSAGE 0x005c 138d16d0b6bSSouradeep Chakrabarti #define HYPERCALL_SIGNAL_EVENT 0x005d 139d16d0b6bSSouradeep Chakrabarti 140d16d0b6bSSouradeep Chakrabarti /* 141d16d0b6bSSouradeep Chakrabarti * Hypercall input parameters 142d16d0b6bSSouradeep Chakrabarti */ 143d16d0b6bSSouradeep Chakrabarti #define HYPERCALL_PARAM_ALIGN 8 144d16d0b6bSSouradeep Chakrabarti #if 0 145d16d0b6bSSouradeep Chakrabarti /* 146d16d0b6bSSouradeep Chakrabarti * XXX 147d16d0b6bSSouradeep Chakrabarti * <<Hypervisor Top Level Functional Specification 4.0b>> requires 148d16d0b6bSSouradeep Chakrabarti * input parameters size to be multiple of 8, however, many post 149d16d0b6bSSouradeep Chakrabarti * message input parameters do _not_ meet this requirement. 150d16d0b6bSSouradeep Chakrabarti */ 151d16d0b6bSSouradeep Chakrabarti #define HYPERCALL_PARAM_SIZE_ALIGN 8 152d16d0b6bSSouradeep Chakrabarti #endif 153d16d0b6bSSouradeep Chakrabarti 154d16d0b6bSSouradeep Chakrabarti /* 155d16d0b6bSSouradeep Chakrabarti * HYPERCALL_POST_MESSAGE 156d16d0b6bSSouradeep Chakrabarti */ 157d16d0b6bSSouradeep Chakrabarti #define HYPERCALL_POSTMSGIN_DSIZE_MAX 240 158d16d0b6bSSouradeep Chakrabarti #define HYPERCALL_POSTMSGIN_SIZE 256 159d16d0b6bSSouradeep Chakrabarti 160d16d0b6bSSouradeep Chakrabarti struct hypercall_postmsg_in { 161d16d0b6bSSouradeep Chakrabarti uint32_t hc_connid; 162d16d0b6bSSouradeep Chakrabarti uint32_t hc_rsvd; 163d16d0b6bSSouradeep Chakrabarti uint32_t hc_msgtype; /* HYPERV_MSGTYPE_ */ 164d16d0b6bSSouradeep Chakrabarti uint32_t hc_dsize; 165d16d0b6bSSouradeep Chakrabarti uint8_t hc_data[HYPERCALL_POSTMSGIN_DSIZE_MAX]; 166d16d0b6bSSouradeep Chakrabarti } __packed; 167d16d0b6bSSouradeep Chakrabarti CTASSERT(sizeof(struct hypercall_postmsg_in) == HYPERCALL_POSTMSGIN_SIZE); 168d16d0b6bSSouradeep Chakrabarti 169d16d0b6bSSouradeep Chakrabarti /* 170d16d0b6bSSouradeep Chakrabarti * HYPERCALL_SIGNAL_EVENT 171d16d0b6bSSouradeep Chakrabarti * 172d16d0b6bSSouradeep Chakrabarti * struct hyperv_mon_param. 173d16d0b6bSSouradeep Chakrabarti */ 174d16d0b6bSSouradeep Chakrabarti 175d16d0b6bSSouradeep Chakrabarti #endif /* i!__HYPERV_COMMON_REG_H__ */ 176