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
|
#ifndef VFIO_USER_PROTOCOL_H
#define VFIO_USER_PROTOCOL_H
/*
* vfio protocol over a UNIX socket.
*
* Copyright © 2018, 2021 Oracle and/or its affiliates.
*
* Each message has a standard header that describes the command
* being sent, which is almost always a VFIO ioctl().
*
* The header may be followed by command-specific data, such as the
* region and offset info for read and write commands.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
typedef struct {
uint16_t id;
uint16_t command;
uint32_t size;
uint32_t flags;
uint32_t error_reply;
} VFIOUserHdr;
/* VFIOUserHdr commands */
enum vfio_user_command {
VFIO_USER_VERSION = 1,
VFIO_USER_DMA_MAP = 2,
VFIO_USER_DMA_UNMAP = 3,
VFIO_USER_DEVICE_GET_INFO = 4,
VFIO_USER_DEVICE_GET_REGION_INFO = 5,
VFIO_USER_DEVICE_GET_REGION_IO_FDS = 6,
VFIO_USER_DEVICE_GET_IRQ_INFO = 7,
VFIO_USER_DEVICE_SET_IRQS = 8,
VFIO_USER_REGION_READ = 9,
VFIO_USER_REGION_WRITE = 10,
VFIO_USER_DMA_READ = 11,
VFIO_USER_DMA_WRITE = 12,
VFIO_USER_DEVICE_RESET = 13,
VFIO_USER_DIRTY_PAGES = 14,
VFIO_USER_REGION_WRITE_MULTI = 15,
VFIO_USER_MAX,
};
/* VFIOUserHdr flags */
#define VFIO_USER_REQUEST 0x0
#define VFIO_USER_REPLY 0x1
#define VFIO_USER_TYPE 0xF
#define VFIO_USER_NO_REPLY 0x10
#define VFIO_USER_ERROR 0x20
/*
* VFIO_USER_VERSION
*/
typedef struct {
VFIOUserHdr hdr;
uint16_t major;
uint16_t minor;
char capabilities[];
} VFIOUserVersion;
#define VFIO_USER_MAJOR_VER 0
#define VFIO_USER_MINOR_VER 0
#define VFIO_USER_CAP "capabilities"
/* "capabilities" members */
#define VFIO_USER_CAP_MAX_FDS "max_msg_fds"
#define VFIO_USER_CAP_MAX_XFER "max_data_xfer_size"
#define VFIO_USER_CAP_PGSIZES "pgsizes"
#define VFIO_USER_CAP_MAP_MAX "max_dma_maps"
#define VFIO_USER_CAP_MIGR "migration"
#define VFIO_USER_CAP_MULTI "write_multiple"
/* "migration" members */
#define VFIO_USER_CAP_PGSIZE "pgsize"
#define VFIO_USER_CAP_MAX_BITMAP "max_bitmap_size"
/*
* Max FDs mainly comes into play when a device supports multiple interrupts
* where each ones uses an eventfd to inject it into the guest.
* It is clamped by the the number of FDs the qio channel supports in a
* single message.
*/
#define VFIO_USER_DEF_MAX_FDS 8
#define VFIO_USER_MAX_MAX_FDS 16
/*
* Max transfer limits the amount of data in region and DMA messages.
* Region R/W will be very small (limited by how much a single instruction
* can process) so just use a reasonable limit here.
*/
#define VFIO_USER_DEF_MAX_XFER (1024 * 1024)
#define VFIO_USER_MAX_MAX_XFER (64 * 1024 * 1024)
/*
* Default pagesizes supported is 4k.
*/
#define VFIO_USER_DEF_PGSIZE 4096
/*
* Default max number of DMA mappings is stolen from the
* linux kernel "dma_entry_limit"
*/
#define VFIO_USER_DEF_MAP_MAX 65535
/*
* Default max bitmap size is also take from the linux kernel,
* where usage of signed ints limits the VA range to 2^31 bytes.
* Dividing that by the number of bits per byte yields 256MB
*/
#define VFIO_USER_DEF_MAX_BITMAP (256 * 1024 * 1024)
/*
* VFIO_USER_DMA_MAP
* imported from struct vfio_iommu_type1_dma_map
*/
typedef struct {
VFIOUserHdr hdr;
uint32_t argsz;
uint32_t flags;
uint64_t offset; /* FD offset */
uint64_t iova;
uint64_t size;
} VFIOUserDMAMap;
/*
* VFIO_USER_DMA_UNMAP
* imported from struct vfio_iommu_type1_dma_unmap
*/
typedef struct {
VFIOUserHdr hdr;
uint32_t argsz;
uint32_t flags;
uint64_t iova;
uint64_t size;
} VFIOUserDMAUnmap;
/*
* VFIO_USER_DEVICE_GET_INFO
* imported from struct vfio_device_info
*/
typedef struct {
VFIOUserHdr hdr;
uint32_t argsz;
uint32_t flags;
uint32_t num_regions;
uint32_t num_irqs;
} VFIOUserDeviceInfo;
/*
* VFIO_USER_DEVICE_GET_REGION_INFO
* imported from struct vfio_region_info
*/
typedef struct {
VFIOUserHdr hdr;
uint32_t argsz;
uint32_t flags;
uint32_t index;
uint32_t cap_offset;
uint64_t size;
uint64_t offset;
} VFIOUserRegionInfo;
/*
* VFIO_USER_DEVICE_GET_IRQ_INFO
* imported from struct vfio_irq_info
*/
typedef struct {
VFIOUserHdr hdr;
uint32_t argsz;
uint32_t flags;
uint32_t index;
uint32_t count;
} VFIOUserIRQInfo;
/*
* VFIO_USER_DEVICE_SET_IRQS
* imported from struct vfio_irq_set
*/
typedef struct {
VFIOUserHdr hdr;
uint32_t argsz;
uint32_t flags;
uint32_t index;
uint32_t start;
uint32_t count;
} VFIOUserIRQSet;
/*
* VFIO_USER_REGION_READ
* VFIO_USER_REGION_WRITE
*/
typedef struct {
VFIOUserHdr hdr;
uint64_t offset;
uint32_t region;
uint32_t count;
char data[];
} VFIOUserRegionRW;
/*
* VFIO_USER_DMA_READ
* VFIO_USER_DMA_WRITE
*/
typedef struct {
VFIOUserHdr hdr;
uint64_t offset;
uint32_t count;
char data[];
} VFIOUserDMARW;
/* imported from struct vfio_bitmap */
typedef struct {
uint64_t pgsize;
uint64_t size;
char data[];
} VFIOUserBitmap;
/*
* VFIO_USER_REGION_WRITE_MULTI
*/
#define VFIO_USER_MULTI_DATA 8
#define VFIO_USER_MULTI_MAX 200
typedef struct {
uint64_t offset;
uint32_t region;
uint32_t count;
char data[VFIO_USER_MULTI_DATA];
} VFIOUserWROne;
typedef struct {
VFIOUserHdr hdr;
uint64_t wr_cnt;
VFIOUserWROne wrs[VFIO_USER_MULTI_MAX];
} VFIOUserWRMulti;
#endif /* VFIO_USER_PROTOCOL_H */
|