2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
5 * Copyright (c) 2012 NetApp Inc.
6 * Copyright (c) 2012 Citrix Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice unmodified, this list of conditions, and the following
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.
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.
38 #include <sys/param.h>
39 #include <sys/systm.h>
41 #define MSR_HV_TIME_REF_COUNT 0x40000020
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
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 */
54 #define NANOSEC 1000000000ULL
56 #define HYPERV_TIMER_NS_FACTOR 100ULL
57 #define HYPERV_TIMER_FREQ (NANOSEC / HYPERV_TIMER_NS_FACTOR)
61 #define HYPERV_REFTSC_DEVNAME "hv_tsc"
64 * Hyper-V Reference TSC
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);
73 CTASSERT(sizeof(struct hyperv_reftsc) == PAGE_SIZE);
82 #define HYPERV_GUID_STRLEN 40
84 typedef uint64_t (*hyperv_tc64_t)(void);
86 int hyperv_guid2str(const struct hyperv_guid *, char *,
90 * hyperv_tc64 could be NULL, if there were no suitable Hyper-V
91 * specific timecounter.
93 extern hyperv_tc64_t hyperv_tc64;
94 extern u_int hyperv_features; /* CPUID_HV_MSR_ */
95 extern u_int hyperv_ver_major;
99 #endif /* _HYPERV_H_ */