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 * Channel 76 */ 77 78 #define VMBUS_CHAN_MAX_COMPAT 256 79 #define VMBUS_CHAN_MAX (VMBUS_EVTFLAG_LEN * VMBUS_EVTFLAGS_MAX) 80 81 /* 82 * GPA range. 83 */ 84 struct vmbus_gpa_range { 85 uint32_t gpa_len; 86 uint32_t gpa_ofs; 87 uint64_t gpa_page[]; 88 } __packed; 89 90 /* 91 * Channel messages 92 * - Embedded in vmbus_message.msg_data, e.g. response. 93 * - Embedded in hypercall_postmsg_in.hc_data, e.g. request. 94 */ 95 96 #define VMBUS_CHANMSG_TYPE_CHREQUEST 3 /* REQ */ 97 #define VMBUS_CHANMSG_TYPE_CHOPEN 5 /* REQ */ 98 #define VMBUS_CHANMSG_TYPE_CHOPEN_RESP 6 /* RESP */ 99 #define VMBUS_CHANMSG_TYPE_CHCLOSE 7 /* REQ */ 100 #define VMBUS_CHANMSG_TYPE_GPADL_CONN 8 /* REQ */ 101 #define VMBUS_CHANMSG_TYPE_GPADL_SUBCONN 9 /* REQ */ 102 #define VMBUS_CHANMSG_TYPE_GPADL_CONNRESP 10 /* RESP */ 103 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONN 11 /* REQ */ 104 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONNRESP 12 /* RESP */ 105 #define VMBUS_CHANMSG_TYPE_CHFREE 13 /* REQ */ 106 #define VMBUS_CHANMSG_TYPE_CONNECT 14 /* REQ */ 107 #define VMBUS_CHANMSG_TYPE_CONNECT_RESP 15 /* RESP */ 108 #define VMBUS_CHANMSG_TYPE_DISCONNECT 16 /* REQ */ 109 110 struct vmbus_chanmsg_hdr { 111 uint32_t chm_type; /* VMBUS_CHANMSG_TYPE_ */ 112 uint32_t chm_rsvd; 113 } __packed; 114 115 /* VMBUS_CHANMSG_TYPE_CONNECT */ 116 struct vmbus_chanmsg_connect { 117 struct vmbus_chanmsg_hdr chm_hdr; 118 uint32_t chm_ver; 119 uint32_t chm_rsvd; 120 uint64_t chm_evtflags; 121 uint64_t chm_mnf1; 122 uint64_t chm_mnf2; 123 } __packed; 124 125 /* VMBUS_CHANMSG_TYPE_CONNECT_RESP */ 126 struct vmbus_chanmsg_connect_resp { 127 struct vmbus_chanmsg_hdr chm_hdr; 128 uint8_t chm_done; 129 } __packed; 130 131 /* VMBUS_CHANMSG_TYPE_CHREQUEST */ 132 struct vmbus_chanmsg_chrequest { 133 struct vmbus_chanmsg_hdr chm_hdr; 134 } __packed; 135 136 /* VMBUS_CHANMSG_TYPE_DISCONNECT */ 137 struct vmbus_chanmsg_disconnect { 138 struct vmbus_chanmsg_hdr chm_hdr; 139 } __packed; 140 141 /* VMBUS_CHANMSG_TYPE_CHOPEN */ 142 struct vmbus_chanmsg_chopen { 143 struct vmbus_chanmsg_hdr chm_hdr; 144 uint32_t chm_chanid; 145 uint32_t chm_openid; 146 uint32_t chm_gpadl; 147 uint32_t chm_vcpuid; 148 uint32_t chm_rxbr_pgofs; 149 #define VMBUS_CHANMSG_CHOPEN_UDATA_SIZE 120 150 uint8_t chm_udata[VMBUS_CHANMSG_CHOPEN_UDATA_SIZE]; 151 } __packed; 152 153 /* VMBUS_CHANMSG_TYPE_CHOPEN_RESP */ 154 struct vmbus_chanmsg_chopen_resp { 155 struct vmbus_chanmsg_hdr chm_hdr; 156 uint32_t chm_chanid; 157 uint32_t chm_openid; 158 uint32_t chm_status; 159 } __packed; 160 161 /* VMBUS_CHANMSG_TYPE_GPADL_CONN */ 162 struct vmbus_chanmsg_gpadl_conn { 163 struct vmbus_chanmsg_hdr chm_hdr; 164 uint32_t chm_chanid; 165 uint32_t chm_gpadl; 166 uint16_t chm_range_len; 167 uint16_t chm_range_cnt; 168 struct vmbus_gpa_range chm_range; 169 } __packed; 170 171 #define VMBUS_CHANMSG_GPADL_CONN_PGMAX 26 172 CTASSERT(__offsetof(struct vmbus_chanmsg_gpadl_conn, 173 chm_range.gpa_page[VMBUS_CHANMSG_GPADL_CONN_PGMAX]) <= 174 HYPERCALL_POSTMSGIN_DSIZE_MAX); 175 176 /* VMBUS_CHANMSG_TYPE_GPADL_SUBCONN */ 177 struct vmbus_chanmsg_gpadl_subconn { 178 struct vmbus_chanmsg_hdr chm_hdr; 179 uint32_t chm_msgno; 180 uint32_t chm_gpadl; 181 uint64_t chm_gpa_page[]; 182 } __packed; 183 184 #define VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX 28 185 CTASSERT(__offsetof(struct vmbus_chanmsg_gpadl_subconn, 186 chm_gpa_page[VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX]) <= 187 HYPERCALL_POSTMSGIN_DSIZE_MAX); 188 189 /* VMBUS_CHANMSG_TYPE_GPADL_CONNRESP */ 190 struct vmbus_chanmsg_gpadl_connresp { 191 struct vmbus_chanmsg_hdr chm_hdr; 192 uint32_t chm_chanid; 193 uint32_t chm_gpadl; 194 uint32_t chm_status; 195 } __packed; 196 197 /* VMBUS_CHANMSG_TYPE_CHCLOSE */ 198 struct vmbus_chanmsg_chclose { 199 struct vmbus_chanmsg_hdr chm_hdr; 200 uint32_t chm_chanid; 201 } __packed; 202 203 /* VMBUS_CHANMSG_TYPE_GPADL_DISCONN */ 204 struct vmbus_chanmsg_gpadl_disconn { 205 struct vmbus_chanmsg_hdr chm_hdr; 206 uint32_t chm_chanid; 207 uint32_t chm_gpadl; 208 } __packed; 209 210 /* VMBUS_CHANMSG_TYPE_CHFREE */ 211 struct vmbus_chanmsg_chfree { 212 struct vmbus_chanmsg_hdr chm_hdr; 213 uint32_t chm_chanid; 214 } __packed; 215 216 #endif /* !_VMBUS_REG_H_ */ 217