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