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
|
#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_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"
/* "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_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;
#endif /* VFIO_USER_PROTOCOL_H */
|