master
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
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
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 */
64struct 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
71CTASSERT(sizeof(struct hyperv_reftsc) == PAGE_SIZE);
72#endif
73
74#ifdef _KERNEL
75
76struct hyperv_guid {
77 uint8_t hv_guid[16];
78} __packed;
79
80#define HYPERV_GUID_STRLEN 40
81
82typedef uint64_t (*hyperv_tc64_t)(void);
83
84int hyperv_guid2str(const struct hyperv_guid *, char *,
85 size_t);
86
87void hyperv_init_tc(void);
88int hypercall_page_setup(vm_paddr_t);
89void hypercall_disable(void);
90bool hyperv_identify_features(void);
91
92/*
93 * hyperv_tc64 could be NULL, if there were no suitable Hyper-V
94 * specific timecounter.
95 */
96extern hyperv_tc64_t hyperv_tc64;
97extern u_int hyperv_features; /* CPUID_HV_MSR_ */
98extern u_int hyperv_ver_major;
99
100/*
101 * Vmbus version after negotiation with host.
102 */
103extern uint32_t vmbus_current_version;
104
105#endif /* _KERNEL */
106
107#endif /* _HYPERV_H_ */