1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
/*
*
* Copyright (c) 2009, Microsoft Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307 USA.
*
* Authors:
* Haiyang Zhang <haiyangz@microsoft.com>
* Hank Janssen <hjanssen@microsoft.com>
*
*/
#pragma once
/* #ifndef PAGE_SIZE */
/* #if defined(_IA64_) */
/* #error This does not work for IA64 */
/* #else */
/* #define PAGE_SIZE 0x1000 */
/* #endif */
/* #endif */
/* allow nameless unions */
/* #pragma warning(disable : 4201) */
typedef struct
{
union
{
struct
{
volatile u32 In; /* Offset in bytes from the ring base */
volatile u32 Out; /* Offset in bytes from the ring base */
};
volatile long long InOut;
};
/* If the receiving endpoint sets this to some non-zero value, the sending */
/* endpoint should not send any interrupts. */
volatile u32 InterruptMask;
} VMRCB, *PVMRCB;
typedef struct
{
union
{
struct
{
VMRCB Control;
};
u8 Reserved[PAGE_SIZE];
};
/* Beginning of the ring data. Note: It must be guaranteed that */
/* this data does not share a page with the control structure. */
u8 Data[1];
} VMRING, *PVMRING;
#pragma pack(push, 1)
typedef struct
{
u16 Type;
u16 DataOffset8;
u16 Length8;
u16 Flags;
u64 TransactionId;
} VMPACKET_DESCRIPTOR, *PVMPACKET_DESCRIPTOR;
typedef u32 PREVIOUS_PACKET_OFFSET, *PPREVIOUS_PACKET_OFFSET;
typedef struct
{
PREVIOUS_PACKET_OFFSET PreviousPacketStartOffset;
VMPACKET_DESCRIPTOR Descriptor;
} VMPACKET_HEADER, *PVMPACKET_HEADER;
typedef struct
{
u32 ByteCount;
u32 ByteOffset;
} VMTRANSFER_PAGE_RANGE, *PVMTRANSFER_PAGE_RANGE;
#ifdef __cplusplus
typedef struct _VMTRANSFER_PAGE_PACKET_HEADER : VMPACKET_DESCRIPTOR {
#else
typedef struct VMTRANSFER_PAGE_PACKET_HEADER {
VMPACKET_DESCRIPTOR d;
#endif
u16 TransferPageSetId;
bool SenderOwnsSet;
u8 Reserved;
u32 RangeCount;
VMTRANSFER_PAGE_RANGE Ranges[1];
} VMTRANSFER_PAGE_PACKET_HEADER, *PVMTRANSFER_PAGE_PACKET_HEADER;
#ifdef __cplusplus
typedef struct _VMGPADL_PACKET_HEADER : VMPACKET_DESCRIPTOR {
#else
typedef struct _VMGPADL_PACKET_HEADER {
VMPACKET_DESCRIPTOR d;
#endif
u32 Gpadl;
u32 Reserved;
} VMGPADL_PACKET_HEADER, *PVMGPADL_PACKET_HEADER;
#ifdef __cplusplus
typedef struct _VMADD_REMOVE_TRANSFER_PAGE_SET : VMPACKET_DESCRIPTOR {
#else
typedef struct _VMADD_REMOVE_TRANSFER_PAGE_SET {
VMPACKET_DESCRIPTOR d;
#endif
u32 Gpadl;
u16 TransferPageSetId;
u16 Reserved;
} VMADD_REMOVE_TRANSFER_PAGE_SET, *PVMADD_REMOVE_TRANSFER_PAGE_SET;
#pragma pack(pop)
/* This structure defines a range in guest physical space that can be made */
/* to look virtually contiguous. */
typedef struct _GPA_RANGE {
u32 ByteCount;
u32 ByteOffset;
u64 PfnArray[0];
} GPA_RANGE, *PGPA_RANGE;
#pragma pack(push, 1)
/* This is the format for an Establish Gpadl packet, which contains a handle */
/* by which this GPADL will be known and a set of GPA ranges associated with */
/* it. This can be converted to a MDL by the guest OS. If there are multiple */
/* GPA ranges, then the resulting MDL will be "chained," representing multiple */
/* VA ranges. */
#ifdef __cplusplus
typedef struct _VMESTABLISH_GPADL : VMPACKET_DESCRIPTOR {
#else
typedef struct _VMESTABLISH_GPADL {
VMPACKET_DESCRIPTOR d;
#endif
u32 Gpadl;
u32 RangeCount;
GPA_RANGE Range[1];
} VMESTABLISH_GPADL, *PVMESTABLISH_GPADL;
/* This is the format for a Teardown Gpadl packet, which indicates that the */
/* GPADL handle in the Establish Gpadl packet will never be referenced again. */
#ifdef __cplusplus
typedef struct _VMTEARDOWN_GPADL : VMPACKET_DESCRIPTOR {
#else
typedef struct _VMTEARDOWN_GPADL {
VMPACKET_DESCRIPTOR d;
#endif
u32 Gpadl;
u32 Reserved; /* for alignment to a 8-byte boundary */
} VMTEARDOWN_GPADL, *PVMTEARDOWN_GPADL;
/* This is the format for a GPA-Direct packet, which contains a set of GPA */
/* ranges, in addition to commands and/or data. */
#ifdef __cplusplus
typedef struct _VMDATA_GPA_DIRECT : VMPACKET_DESCRIPTOR {
#else
typedef struct _VMDATA_GPA_DIRECT {
VMPACKET_DESCRIPTOR d;
#endif
u32 Reserved;
u32 RangeCount;
GPA_RANGE Range[1];
} VMDATA_GPA_DIRECT, *PVMDATA_GPA_DIRECT;
/* This is the format for a Additional Data Packet. */
#ifdef __cplusplus
typedef struct _VMADDITIONAL_DATA : VMPACKET_DESCRIPTOR {
#else
typedef struct _VMADDITIONAL_DATA {
VMPACKET_DESCRIPTOR d;
#endif
u64 TotalBytes;
u32 ByteOffset;
u32 ByteCount;
unsigned char Data[1];
} VMADDITIONAL_DATA, *PVMADDITIONAL_DATA;
#pragma pack(pop)
typedef union {
VMPACKET_DESCRIPTOR SimpleHeader;
VMTRANSFER_PAGE_PACKET_HEADER TransferPageHeader;
VMGPADL_PACKET_HEADER GpadlHeader;
VMADD_REMOVE_TRANSFER_PAGE_SET AddRemoveTransferPageHeader;
VMESTABLISH_GPADL EstablishGpadlHeader;
VMTEARDOWN_GPADL TeardownGpadlHeader;
VMDATA_GPA_DIRECT DataGpaDirectHeader;
} VMPACKET_LARGEST_POSSIBLE_HEADER, *PVMPACKET_LARGEST_POSSIBLE_HEADER;
#define VMPACKET_DATA_START_ADDRESS(__packet) \
(void *)(((unsigned char *)__packet) + ((PVMPACKET_DESCRIPTOR)__packet)->DataOffset8 * 8)
#define VMPACKET_DATA_LENGTH(__packet) \
((((PVMPACKET_DESCRIPTOR)__packet)->Length8 - ((PVMPACKET_DESCRIPTOR)__packet)->DataOffset8) * 8)
#define VMPACKET_TRANSFER_MODE(__packet) ((PVMPACKET_DESCRIPTOR)__packet)->Type
typedef enum {
VmbusServerEndpoint = 0,
VmbusClientEndpoint,
VmbusEndpointMaximum
} ENDPOINT_TYPE, *PENDPOINT_TYPE;
typedef enum {
VmbusPacketTypeInvalid = 0x0,
VmbusPacketTypeSynch = 0x1,
VmbusPacketTypeAddTransferPageSet = 0x2,
VmbusPacketTypeRemoveTransferPageSet = 0x3,
VmbusPacketTypeEstablishGpadl = 0x4,
VmbusPacketTypeTearDownGpadl = 0x5,
VmbusPacketTypeDataInBand = 0x6,
VmbusPacketTypeDataUsingTransferPages = 0x7,
VmbusPacketTypeDataUsingGpadl = 0x8,
VmbusPacketTypeDataUsingGpaDirect = 0x9,
VmbusPacketTypeCancelRequest = 0xa,
VmbusPacketTypeCompletion = 0xb,
VmbusPacketTypeDataUsingAdditionalPackets = 0xc,
VmbusPacketTypeAdditionalData = 0xd
} VMBUS_PACKET_TYPE, *PVMBUS_PACKET_TYPE;
#define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
|