hypervvar.h revision 1.6 1 1.6 nonaka /* $NetBSD: hypervvar.h,v 1.6 2022/05/20 13:55:17 nonaka Exp $ */
2 1.1 nonaka
3 1.1 nonaka /*-
4 1.1 nonaka * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 1.1 nonaka *
6 1.1 nonaka * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
7 1.1 nonaka * Copyright (c) 2012 NetApp Inc.
8 1.1 nonaka * Copyright (c) 2012 Citrix Inc.
9 1.1 nonaka * All rights reserved.
10 1.1 nonaka *
11 1.1 nonaka * Redistribution and use in source and binary forms, with or without
12 1.1 nonaka * modification, are permitted provided that the following conditions
13 1.1 nonaka * are met:
14 1.1 nonaka * 1. Redistributions of source code must retain the above copyright
15 1.1 nonaka * notice unmodified, this list of conditions, and the following
16 1.1 nonaka * disclaimer.
17 1.1 nonaka * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 nonaka * notice, this list of conditions and the following disclaimer in the
19 1.1 nonaka * documentation and/or other materials provided with the distribution.
20 1.1 nonaka *
21 1.1 nonaka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 nonaka * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 nonaka * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 nonaka * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 nonaka * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 nonaka * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 nonaka * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 nonaka * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 nonaka * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 nonaka * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 nonaka *
32 1.1 nonaka * $FreeBSD: head/sys/dev/hyperv/include/hyperv.h 326255 2017-11-27 14:52:40Z pfg $
33 1.1 nonaka */
34 1.1 nonaka
35 1.1 nonaka #ifndef _HYPERVVAR_H_
36 1.1 nonaka #define _HYPERVVAR_H_
37 1.1 nonaka
38 1.1 nonaka #if defined(_KERNEL)
39 1.1 nonaka
40 1.1 nonaka #include <sys/bus.h>
41 1.1 nonaka #include <sys/timex.h>
42 1.1 nonaka
43 1.1 nonaka #define HYPERV_TIMER_NS_FACTOR 100ULL
44 1.1 nonaka #define HYPERV_TIMER_FREQ (NANOSECOND / HYPERV_TIMER_NS_FACTOR)
45 1.1 nonaka
46 1.1 nonaka #endif /* _KERNEL */
47 1.1 nonaka
48 1.1 nonaka /*
49 1.1 nonaka * Hyper-V Reference TSC
50 1.1 nonaka */
51 1.1 nonaka struct hyperv_reftsc {
52 1.1 nonaka volatile uint32_t tsc_seq;
53 1.1 nonaka volatile uint32_t tsc_rsvd1;
54 1.1 nonaka volatile uint64_t tsc_scale;
55 1.1 nonaka volatile int64_t tsc_ofs;
56 1.1 nonaka } __packed __aligned(PAGE_SIZE);
57 1.1 nonaka #ifdef __CTASSERT
58 1.1 nonaka __CTASSERT(sizeof(struct hyperv_reftsc) == PAGE_SIZE);
59 1.1 nonaka #endif
60 1.1 nonaka
61 1.1 nonaka #if defined(_KERNEL)
62 1.6 nonaka extern u_int hyperv_ver_major;
63 1.1 nonaka
64 1.1 nonaka int hyperv_hypercall_enabled(void);
65 1.1 nonaka int hyperv_synic_supported(void);
66 1.2 nonaka int hyperv_is_gen1(void);
67 1.1 nonaka void hyperv_send_eom(void);
68 1.1 nonaka void hyperv_intr(void);
69 1.3 nonaka uint32_t hyperv_get_vcpuid(cpuid_t);
70 1.1 nonaka
71 1.1 nonaka struct vmbus_softc;
72 1.5 yamaguch void vmbus_init_interrupts_md(struct vmbus_softc *, cpuid_t);
73 1.5 yamaguch void vmbus_deinit_interrupts_md(struct vmbus_softc *, cpuid_t);
74 1.1 nonaka void vmbus_init_synic_md(struct vmbus_softc *, cpuid_t);
75 1.1 nonaka void vmbus_deinit_synic_md(struct vmbus_softc *, cpuid_t);
76 1.1 nonaka
77 1.1 nonaka #define HYPERV_GUID_STRLEN 40
78 1.1 nonaka struct hyperv_guid;
79 1.1 nonaka int hyperv_guid2str(const struct hyperv_guid *, char *, size_t);
80 1.1 nonaka
81 1.1 nonaka /*
82 1.1 nonaka * hyperv_tc64 could be NULL, if there were no suitable Hyper-V
83 1.1 nonaka * specific timecounter.
84 1.1 nonaka */
85 1.1 nonaka typedef uint64_t (*hyperv_tc64_t)(void);
86 1.1 nonaka extern hyperv_tc64_t hyperv_tc64;
87 1.1 nonaka
88 1.1 nonaka uint64_t hyperv_hypercall(uint64_t, paddr_t, paddr_t);
89 1.1 nonaka uint64_t hyperv_hypercall_post_message(paddr_t);
90 1.1 nonaka uint64_t hyperv_hypercall_signal_event(paddr_t);
91 1.1 nonaka
92 1.1 nonaka typedef void (*hyperv_proc_t)(void *, struct cpu_info *);
93 1.1 nonaka void hyperv_set_event_proc(hyperv_proc_t, void *);
94 1.1 nonaka void hyperv_set_message_proc(hyperv_proc_t, void *);
95 1.1 nonaka
96 1.1 nonaka /*
97 1.1 nonaka * Hyper-V bus_dma utilities.
98 1.1 nonaka */
99 1.1 nonaka struct hyperv_dma {
100 1.1 nonaka bus_dmamap_t map;
101 1.1 nonaka bus_dma_segment_t *segs;
102 1.1 nonaka void *addr;
103 1.1 nonaka int nsegs;
104 1.1 nonaka };
105 1.1 nonaka
106 1.1 nonaka static __inline bus_addr_t
107 1.1 nonaka hyperv_dma_get_paddr(struct hyperv_dma *dma)
108 1.1 nonaka {
109 1.1 nonaka return dma->map->dm_segs[0].ds_addr;
110 1.1 nonaka }
111 1.1 nonaka
112 1.1 nonaka void *hyperv_dma_alloc(bus_dma_tag_t, struct hyperv_dma *, bus_size_t,
113 1.6 nonaka bus_size_t, bus_size_t, int);
114 1.1 nonaka void hyperv_dma_free(bus_dma_tag_t, struct hyperv_dma *);
115 1.1 nonaka
116 1.1 nonaka #endif /* _KERNEL */
117 1.1 nonaka
118 1.1 nonaka #endif /* _HYPERVVAR_H_ */
119