xref: /freebsd/sys/dev/hyperv/include/hyperv.h (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
5  * Copyright (c) 2012 NetApp Inc.
6  * Copyright (c) 2012 Citrix Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice unmodified, this list of conditions, and the following
14  *    disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 #ifndef _HYPERV_H_
34 #define _HYPERV_H_
35 
36 #ifdef _KERNEL
37 
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 
41 #define MSR_HV_TIME_REF_COUNT		0x40000020
42 
43 #define CPUID_HV_MSR_TIME_REFCNT	0x0002	/* MSR_HV_TIME_REF_COUNT */
44 #define CPUID_HV_MSR_SYNIC		0x0004	/* MSRs for SynIC */
45 #define CPUID_HV_MSR_SYNTIMER		0x0008	/* MSRs for SynTimer */
46 #define CPUID_HV_MSR_APIC		0x0010	/* MSR_HV_{EOI,ICR,TPR} */
47 #define CPUID_HV_MSR_HYPERCALL		0x0020	/* MSR_HV_GUEST_OS_ID
48 						 * MSR_HV_HYPERCALL */
49 #define CPUID_HV_MSR_VP_INDEX		0x0040	/* MSR_HV_VP_INDEX */
50 #define CPUID_HV_MSR_REFERENCE_TSC	0x0200	/* MSR_HV_REFERENCE_TSC */
51 #define CPUID_HV_MSR_GUEST_IDLE		0x0400	/* MSR_HV_GUEST_IDLE */
52 
53 #ifndef NANOSEC
54 #define NANOSEC				1000000000ULL
55 #endif
56 #define HYPERV_TIMER_NS_FACTOR		100ULL
57 #define HYPERV_TIMER_FREQ		(NANOSEC / HYPERV_TIMER_NS_FACTOR)
58 
59 #endif	/* _KERNEL */
60 
61 #define HYPERV_REFTSC_DEVNAME		"hv_tsc"
62 
63 /*
64  * Hyper-V Reference TSC
65  */
66 struct hyperv_reftsc {
67 	volatile uint32_t		tsc_seq;
68 	volatile uint32_t		tsc_rsvd1;
69 	volatile uint64_t		tsc_scale;
70 	volatile int64_t		tsc_ofs;
71 } __packed __aligned(PAGE_SIZE);
72 #ifdef CTASSERT
73 CTASSERT(sizeof(struct hyperv_reftsc) == PAGE_SIZE);
74 #endif
75 
76 #ifdef _KERNEL
77 
78 struct hyperv_guid {
79 	uint8_t				hv_guid[16];
80 } __packed;
81 
82 #define HYPERV_GUID_STRLEN		40
83 
84 typedef uint64_t			(*hyperv_tc64_t)(void);
85 
86 int			hyperv_guid2str(const struct hyperv_guid *, char *,
87 			    size_t);
88 
89 /*
90  * hyperv_tc64 could be NULL, if there were no suitable Hyper-V
91  * specific timecounter.
92  */
93 extern hyperv_tc64_t	hyperv_tc64;
94 extern u_int		hyperv_features;	/* CPUID_HV_MSR_ */
95 extern u_int		hyperv_ver_major;
96 
97 /*
98  * Vmbus version after negotiation with host.
99  */
100 extern uint32_t		vmbus_current_version;
101 
102 #endif	/* _KERNEL */
103 
104 #endif  /* _HYPERV_H_ */
105