2 * Copyright (c) 2016 Microsoft Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/param.h>
33 #include <dev/hyperv/vmbus/hyperv_reg.h>
34 #include <dev/hyperv/include/hyperv.h> /* XXX for hyperv_guid */
37 * Hyper-V SynIC message format.
40 #define VMBUS_MSG_DSIZE_MAX 240
41 #define VMBUS_MSG_SIZE 256
43 struct vmbus_message {
44 uint32_t msg_type; /* HYPERV_MSGTYPE_ */
45 uint8_t msg_dsize; /* data size */
46 uint8_t msg_flags; /* VMBUS_MSGFLAG_ */
49 uint8_t msg_data[VMBUS_MSG_DSIZE_MAX];
51 CTASSERT(sizeof(struct vmbus_message) == VMBUS_MSG_SIZE);
53 #define VMBUS_MSGFLAG_PENDING 0x01
56 * Hyper-V SynIC event flags
60 #define VMBUS_EVTFLAGS_MAX 32
61 #define VMBUS_EVTFLAG_SHIFT 6
63 #define VMBUS_EVTFLAGS_MAX 64
64 #define VMBUS_EVTFLAG_SHIFT 5
66 #define VMBUS_EVTFLAG_LEN (1 << VMBUS_EVTFLAG_SHIFT)
67 #define VMBUS_EVTFLAG_MASK (VMBUS_EVTFLAG_LEN - 1)
68 #define VMBUS_EVTFLAGS_SIZE 256
70 struct vmbus_evtflags {
71 u_long evt_flags[VMBUS_EVTFLAGS_MAX];
73 CTASSERT(sizeof(struct vmbus_evtflags) == VMBUS_EVTFLAGS_SIZE);
76 * Hyper-V Monitor Notification Facility
79 struct vmbus_mon_trig {
84 #define VMBUS_MONTRIGS_MAX 4
85 #define VMBUS_MONTRIG_LEN 32
91 struct vmbus_mon_trig mnf_trigs[VMBUS_MONTRIGS_MAX];
92 uint8_t mnf_rsvd2[536];
94 uint16_t mnf_lat[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN];
95 uint8_t mnf_rsvd3[256];
97 struct hyperv_mon_param
98 mnf_param[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN];
99 uint8_t mnf_rsvd4[1984];
101 CTASSERT(sizeof(struct vmbus_mnf) == PAGE_SIZE);
107 #define VMBUS_CHAN_MAX_COMPAT 256
108 #define VMBUS_CHAN_MAX (VMBUS_EVTFLAG_LEN * VMBUS_EVTFLAGS_MAX)
113 struct vmbus_gpa_range {
123 #define VMBUS_CHANPKT_SIZE_SHIFT 3
124 #define VMBUS_CHANPKT_SIZE_ALIGN (1 << VMBUS_CHANPKT_SIZE_SHIFT)
126 struct vmbus_chanpkt_hdr {
128 uint16_t cph_data_ofs; /* in 8 bytes */
129 uint16_t cph_len; /* in 8 bytes */
134 struct vmbus_chanpkt {
135 struct vmbus_chanpkt_hdr cp_hdr;
140 * - Embedded in vmbus_message.msg_data, e.g. response and notification.
141 * - Embedded in hypercall_postmsg_in.hc_data, e.g. request.
144 #define VMBUS_CHANMSG_TYPE_CHOFFER 1 /* NOTE */
145 #define VMBUS_CHANMSG_TYPE_CHRESCIND 2 /* NOTE */
146 #define VMBUS_CHANMSG_TYPE_CHREQUEST 3 /* REQ */
147 #define VMBUS_CHANMSG_TYPE_CHOFFER_DONE 4 /* NOTE */
148 #define VMBUS_CHANMSG_TYPE_CHOPEN 5 /* REQ */
149 #define VMBUS_CHANMSG_TYPE_CHOPEN_RESP 6 /* RESP */
150 #define VMBUS_CHANMSG_TYPE_CHCLOSE 7 /* REQ */
151 #define VMBUS_CHANMSG_TYPE_GPADL_CONN 8 /* REQ */
152 #define VMBUS_CHANMSG_TYPE_GPADL_SUBCONN 9 /* REQ */
153 #define VMBUS_CHANMSG_TYPE_GPADL_CONNRESP 10 /* RESP */
154 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONN 11 /* REQ */
155 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONNRESP 12 /* RESP */
156 #define VMBUS_CHANMSG_TYPE_CHFREE 13 /* REQ */
157 #define VMBUS_CHANMSG_TYPE_CONNECT 14 /* REQ */
158 #define VMBUS_CHANMSG_TYPE_CONNECT_RESP 15 /* RESP */
159 #define VMBUS_CHANMSG_TYPE_DISCONNECT 16 /* REQ */
160 #define VMBUS_CHANMSG_TYPE_MAX 22
162 struct vmbus_chanmsg_hdr {
163 uint32_t chm_type; /* VMBUS_CHANMSG_TYPE_ */
167 /* VMBUS_CHANMSG_TYPE_CONNECT */
168 struct vmbus_chanmsg_connect {
169 struct vmbus_chanmsg_hdr chm_hdr;
172 uint64_t chm_evtflags;
177 /* VMBUS_CHANMSG_TYPE_CONNECT_RESP */
178 struct vmbus_chanmsg_connect_resp {
179 struct vmbus_chanmsg_hdr chm_hdr;
183 /* VMBUS_CHANMSG_TYPE_CHREQUEST */
184 struct vmbus_chanmsg_chrequest {
185 struct vmbus_chanmsg_hdr chm_hdr;
188 /* VMBUS_CHANMSG_TYPE_DISCONNECT */
189 struct vmbus_chanmsg_disconnect {
190 struct vmbus_chanmsg_hdr chm_hdr;
193 /* VMBUS_CHANMSG_TYPE_CHOPEN */
194 struct vmbus_chanmsg_chopen {
195 struct vmbus_chanmsg_hdr chm_hdr;
200 uint32_t chm_rxbr_pgofs;
201 #define VMBUS_CHANMSG_CHOPEN_UDATA_SIZE 120
202 uint8_t chm_udata[VMBUS_CHANMSG_CHOPEN_UDATA_SIZE];
205 /* VMBUS_CHANMSG_TYPE_CHOPEN_RESP */
206 struct vmbus_chanmsg_chopen_resp {
207 struct vmbus_chanmsg_hdr chm_hdr;
213 /* VMBUS_CHANMSG_TYPE_GPADL_CONN */
214 struct vmbus_chanmsg_gpadl_conn {
215 struct vmbus_chanmsg_hdr chm_hdr;
218 uint16_t chm_range_len;
219 uint16_t chm_range_cnt;
220 struct vmbus_gpa_range chm_range;
223 #define VMBUS_CHANMSG_GPADL_CONN_PGMAX 26
224 CTASSERT(__offsetof(struct vmbus_chanmsg_gpadl_conn,
225 chm_range.gpa_page[VMBUS_CHANMSG_GPADL_CONN_PGMAX]) <=
226 HYPERCALL_POSTMSGIN_DSIZE_MAX);
228 /* VMBUS_CHANMSG_TYPE_GPADL_SUBCONN */
229 struct vmbus_chanmsg_gpadl_subconn {
230 struct vmbus_chanmsg_hdr chm_hdr;
233 uint64_t chm_gpa_page[];
236 #define VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX 28
237 CTASSERT(__offsetof(struct vmbus_chanmsg_gpadl_subconn,
238 chm_gpa_page[VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX]) <=
239 HYPERCALL_POSTMSGIN_DSIZE_MAX);
241 /* VMBUS_CHANMSG_TYPE_GPADL_CONNRESP */
242 struct vmbus_chanmsg_gpadl_connresp {
243 struct vmbus_chanmsg_hdr chm_hdr;
249 /* VMBUS_CHANMSG_TYPE_CHCLOSE */
250 struct vmbus_chanmsg_chclose {
251 struct vmbus_chanmsg_hdr chm_hdr;
255 /* VMBUS_CHANMSG_TYPE_GPADL_DISCONN */
256 struct vmbus_chanmsg_gpadl_disconn {
257 struct vmbus_chanmsg_hdr chm_hdr;
262 /* VMBUS_CHANMSG_TYPE_CHFREE */
263 struct vmbus_chanmsg_chfree {
264 struct vmbus_chanmsg_hdr chm_hdr;
268 /* VMBUS_CHANMSG_TYPE_CHRESCIND */
269 struct vmbus_chanmsg_chrescind {
270 struct vmbus_chanmsg_hdr chm_hdr;
274 /* VMBUS_CHANMSG_TYPE_CHOFFER */
275 struct vmbus_chanmsg_choffer {
276 struct vmbus_chanmsg_hdr chm_hdr;
277 struct hyperv_guid chm_chtype;
278 struct hyperv_guid chm_chinst;
279 uint64_t chm_chlat; /* unit: 100ns */
281 uint32_t chm_svrctx_sz;
282 uint16_t chm_chflags;
283 uint16_t chm_mmio_sz; /* unit: MB */
284 uint8_t chm_udata[120];
289 uint8_t chm_flags1; /* VMBUS_CHOFFER_FLAG1_ */
293 CTASSERT(sizeof(struct vmbus_chanmsg_choffer) <= VMBUS_MSG_DSIZE_MAX);
295 #define VMBUS_CHOFFER_FLAG1_HASMNF 0x01
297 #endif /* !_VMBUS_REG_H_ */