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