1 /*- 2 * Copyright (c) 2016 Microsoft Corp. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * disclaimer. 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. 14 * 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. 25 * 26 * $FreeBSD$ 27 */ 28 29 #ifndef _VMBUS_REG_H_ 30 #define _VMBUS_REG_H_ 31 32 #include <sys/param.h> 33 #include <dev/hyperv/vmbus/hyperv_reg.h> 34 35 /* 36 * Hyper-V SynIC message format. 37 */ 38 39 #define VMBUS_MSG_DSIZE_MAX 240 40 #define VMBUS_MSG_SIZE 256 41 42 struct vmbus_message { 43 uint32_t msg_type; /* HYPERV_MSGTYPE_ */ 44 uint8_t msg_dsize; /* data size */ 45 uint8_t msg_flags; /* VMBUS_MSGFLAG_ */ 46 uint16_t msg_rsvd; 47 uint64_t msg_id; 48 uint8_t msg_data[VMBUS_MSG_DSIZE_MAX]; 49 } __packed; 50 CTASSERT(sizeof(struct vmbus_message) == VMBUS_MSG_SIZE); 51 52 #define VMBUS_MSGFLAG_PENDING 0x01 53 54 /* 55 * Hyper-V SynIC event flags 56 */ 57 58 #ifdef __LP64__ 59 #define VMBUS_EVTFLAGS_MAX 32 60 #define VMBUS_EVTFLAG_SHIFT 6 61 #else 62 #define VMBUS_EVTFLAGS_MAX 64 63 #define VMBUS_EVTFLAG_SHIFT 5 64 #endif 65 #define VMBUS_EVTFLAG_LEN (1 << VMBUS_EVTFLAG_SHIFT) 66 #define VMBUS_EVTFLAG_MASK (VMBUS_EVTFLAG_LEN - 1) 67 #define VMBUS_EVTFLAGS_SIZE 256 68 69 struct vmbus_evtflags { 70 u_long evt_flags[VMBUS_EVTFLAGS_MAX]; 71 } __packed; 72 CTASSERT(sizeof(struct vmbus_evtflags) == VMBUS_EVTFLAGS_SIZE); 73 74 /* 75 * Hyper-V Monitor Notification Facility 76 */ 77 78 struct vmbus_mon_trig { 79 uint32_t mt_pending; 80 uint32_t mt_armed; 81 } __packed; 82 83 #define VMBUS_MONTRIGS_MAX 4 84 #define VMBUS_MONTRIG_LEN 32 85 86 struct vmbus_mnf { 87 uint32_t mnf_state; 88 uint32_t mnf_rsvd1; 89 90 struct vmbus_mon_trig mnf_trigs[VMBUS_MONTRIGS_MAX]; 91 uint8_t mnf_rsvd2[536]; 92 93 uint16_t mnf_lat[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN]; 94 uint8_t mnf_rsvd3[256]; 95 96 struct hyperv_mon_param 97 mnf_param[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN]; 98 uint8_t mnf_rsvd4[1984]; 99 } __packed; 100 CTASSERT(sizeof(struct vmbus_mnf) == PAGE_SIZE); 101 102 /* 103 * Channel 104 */ 105 106 #define VMBUS_CHAN_MAX_COMPAT 256 107 #define VMBUS_CHAN_MAX (VMBUS_EVTFLAG_LEN * VMBUS_EVTFLAGS_MAX) 108 109 /* 110 * GPA range. 111 */ 112 struct vmbus_gpa_range { 113 uint32_t gpa_len; 114 uint32_t gpa_ofs; 115 uint64_t gpa_page[]; 116 } __packed; 117 118 /* 119 * Channel messages 120 * - Embedded in vmbus_message.msg_data, e.g. response and notification. 121 * - Embedded in hypercall_postmsg_in.hc_data, e.g. request. 122 */ 123 124 #define VMBUS_CHANMSG_TYPE_CHRESCIND 2 /* NOTE */ 125 #define VMBUS_CHANMSG_TYPE_CHREQUEST 3 /* REQ */ 126 #define VMBUS_CHANMSG_TYPE_CHOPEN 5 /* REQ */ 127 #define VMBUS_CHANMSG_TYPE_CHOPEN_RESP 6 /* RESP */ 128 #define VMBUS_CHANMSG_TYPE_CHCLOSE 7 /* REQ */ 129 #define VMBUS_CHANMSG_TYPE_GPADL_CONN 8 /* REQ */ 130 #define VMBUS_CHANMSG_TYPE_GPADL_SUBCONN 9 /* REQ */ 131 #define VMBUS_CHANMSG_TYPE_GPADL_CONNRESP 10 /* RESP */ 132 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONN 11 /* REQ */ 133 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONNRESP 12 /* RESP */ 134 #define VMBUS_CHANMSG_TYPE_CHFREE 13 /* REQ */ 135 #define VMBUS_CHANMSG_TYPE_CONNECT 14 /* REQ */ 136 #define VMBUS_CHANMSG_TYPE_CONNECT_RESP 15 /* RESP */ 137 #define VMBUS_CHANMSG_TYPE_DISCONNECT 16 /* REQ */ 138 139 struct vmbus_chanmsg_hdr { 140 uint32_t chm_type; /* VMBUS_CHANMSG_TYPE_ */ 141 uint32_t chm_rsvd; 142 } __packed; 143 144 /* VMBUS_CHANMSG_TYPE_CONNECT */ 145 struct vmbus_chanmsg_connect { 146 struct vmbus_chanmsg_hdr chm_hdr; 147 uint32_t chm_ver; 148 uint32_t chm_rsvd; 149 uint64_t chm_evtflags; 150 uint64_t chm_mnf1; 151 uint64_t chm_mnf2; 152 } __packed; 153 154 /* VMBUS_CHANMSG_TYPE_CONNECT_RESP */ 155 struct vmbus_chanmsg_connect_resp { 156 struct vmbus_chanmsg_hdr chm_hdr; 157 uint8_t chm_done; 158 } __packed; 159 160 /* VMBUS_CHANMSG_TYPE_CHREQUEST */ 161 struct vmbus_chanmsg_chrequest { 162 struct vmbus_chanmsg_hdr chm_hdr; 163 } __packed; 164 165 /* VMBUS_CHANMSG_TYPE_DISCONNECT */ 166 struct vmbus_chanmsg_disconnect { 167 struct vmbus_chanmsg_hdr chm_hdr; 168 } __packed; 169 170 /* VMBUS_CHANMSG_TYPE_CHOPEN */ 171 struct vmbus_chanmsg_chopen { 172 struct vmbus_chanmsg_hdr chm_hdr; 173 uint32_t chm_chanid; 174 uint32_t chm_openid; 175 uint32_t chm_gpadl; 176 uint32_t chm_vcpuid; 177 uint32_t chm_rxbr_pgofs; 178 #define VMBUS_CHANMSG_CHOPEN_UDATA_SIZE 120 179 uint8_t chm_udata[VMBUS_CHANMSG_CHOPEN_UDATA_SIZE]; 180 } __packed; 181 182 /* VMBUS_CHANMSG_TYPE_CHOPEN_RESP */ 183 struct vmbus_chanmsg_chopen_resp { 184 struct vmbus_chanmsg_hdr chm_hdr; 185 uint32_t chm_chanid; 186 uint32_t chm_openid; 187 uint32_t chm_status; 188 } __packed; 189 190 /* VMBUS_CHANMSG_TYPE_GPADL_CONN */ 191 struct vmbus_chanmsg_gpadl_conn { 192 struct vmbus_chanmsg_hdr chm_hdr; 193 uint32_t chm_chanid; 194 uint32_t chm_gpadl; 195 uint16_t chm_range_len; 196 uint16_t chm_range_cnt; 197 struct vmbus_gpa_range chm_range; 198 } __packed; 199 200 #define VMBUS_CHANMSG_GPADL_CONN_PGMAX 26 201 CTASSERT(__offsetof(struct vmbus_chanmsg_gpadl_conn, 202 chm_range.gpa_page[VMBUS_CHANMSG_GPADL_CONN_PGMAX]) <= 203 HYPERCALL_POSTMSGIN_DSIZE_MAX); 204 205 /* VMBUS_CHANMSG_TYPE_GPADL_SUBCONN */ 206 struct vmbus_chanmsg_gpadl_subconn { 207 struct vmbus_chanmsg_hdr chm_hdr; 208 uint32_t chm_msgno; 209 uint32_t chm_gpadl; 210 uint64_t chm_gpa_page[]; 211 } __packed; 212 213 #define VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX 28 214 CTASSERT(__offsetof(struct vmbus_chanmsg_gpadl_subconn, 215 chm_gpa_page[VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX]) <= 216 HYPERCALL_POSTMSGIN_DSIZE_MAX); 217 218 /* VMBUS_CHANMSG_TYPE_GPADL_CONNRESP */ 219 struct vmbus_chanmsg_gpadl_connresp { 220 struct vmbus_chanmsg_hdr chm_hdr; 221 uint32_t chm_chanid; 222 uint32_t chm_gpadl; 223 uint32_t chm_status; 224 } __packed; 225 226 /* VMBUS_CHANMSG_TYPE_CHCLOSE */ 227 struct vmbus_chanmsg_chclose { 228 struct vmbus_chanmsg_hdr chm_hdr; 229 uint32_t chm_chanid; 230 } __packed; 231 232 /* VMBUS_CHANMSG_TYPE_GPADL_DISCONN */ 233 struct vmbus_chanmsg_gpadl_disconn { 234 struct vmbus_chanmsg_hdr chm_hdr; 235 uint32_t chm_chanid; 236 uint32_t chm_gpadl; 237 } __packed; 238 239 /* VMBUS_CHANMSG_TYPE_CHFREE */ 240 struct vmbus_chanmsg_chfree { 241 struct vmbus_chanmsg_hdr chm_hdr; 242 uint32_t chm_chanid; 243 } __packed; 244 245 /* VMBUS_CHANMSG_TYPE_CHRESCIND */ 246 struct vmbus_chanmsg_chrescind { 247 struct vmbus_chanmsg_hdr chm_hdr; 248 uint32_t chm_chanid; 249 } __packed; 250 251 #endif /* !_VMBUS_REG_H_ */ 252