xref: /qemu/hw/vfio-user/protocol.h (revision 36227628d824f563fda95f9344176ca7263c7eaf)
10b3d881aSJohn Levon #ifndef VFIO_USER_PROTOCOL_H
20b3d881aSJohn Levon #define VFIO_USER_PROTOCOL_H
30b3d881aSJohn Levon 
40b3d881aSJohn Levon /*
50b3d881aSJohn Levon  * vfio protocol over a UNIX socket.
60b3d881aSJohn Levon  *
70b3d881aSJohn Levon  * Copyright © 2018, 2021 Oracle and/or its affiliates.
80b3d881aSJohn Levon  *
90b3d881aSJohn Levon  * Each message has a standard header that describes the command
100b3d881aSJohn Levon  * being sent, which is almost always a VFIO ioctl().
110b3d881aSJohn Levon  *
120b3d881aSJohn Levon  * The header may be followed by command-specific data, such as the
130b3d881aSJohn Levon  * region and offset info for read and write commands.
140b3d881aSJohn Levon  *
150b3d881aSJohn Levon  * SPDX-License-Identifier: GPL-2.0-or-later
160b3d881aSJohn Levon  */
170b3d881aSJohn Levon 
180b3d881aSJohn Levon typedef struct {
190b3d881aSJohn Levon     uint16_t id;
200b3d881aSJohn Levon     uint16_t command;
210b3d881aSJohn Levon     uint32_t size;
220b3d881aSJohn Levon     uint32_t flags;
230b3d881aSJohn Levon     uint32_t error_reply;
240b3d881aSJohn Levon } VFIOUserHdr;
250b3d881aSJohn Levon 
260b3d881aSJohn Levon /* VFIOUserHdr commands */
270b3d881aSJohn Levon enum vfio_user_command {
280b3d881aSJohn Levon     VFIO_USER_VERSION                   = 1,
290b3d881aSJohn Levon     VFIO_USER_DMA_MAP                   = 2,
300b3d881aSJohn Levon     VFIO_USER_DMA_UNMAP                 = 3,
310b3d881aSJohn Levon     VFIO_USER_DEVICE_GET_INFO           = 4,
320b3d881aSJohn Levon     VFIO_USER_DEVICE_GET_REGION_INFO    = 5,
330b3d881aSJohn Levon     VFIO_USER_DEVICE_GET_REGION_IO_FDS  = 6,
340b3d881aSJohn Levon     VFIO_USER_DEVICE_GET_IRQ_INFO       = 7,
350b3d881aSJohn Levon     VFIO_USER_DEVICE_SET_IRQS           = 8,
360b3d881aSJohn Levon     VFIO_USER_REGION_READ               = 9,
370b3d881aSJohn Levon     VFIO_USER_REGION_WRITE              = 10,
380b3d881aSJohn Levon     VFIO_USER_DMA_READ                  = 11,
390b3d881aSJohn Levon     VFIO_USER_DMA_WRITE                 = 12,
400b3d881aSJohn Levon     VFIO_USER_DEVICE_RESET              = 13,
410b3d881aSJohn Levon     VFIO_USER_DIRTY_PAGES               = 14,
420b3d881aSJohn Levon     VFIO_USER_MAX,
430b3d881aSJohn Levon };
440b3d881aSJohn Levon 
450b3d881aSJohn Levon /* VFIOUserHdr flags */
460b3d881aSJohn Levon #define VFIO_USER_REQUEST       0x0
470b3d881aSJohn Levon #define VFIO_USER_REPLY         0x1
480b3d881aSJohn Levon #define VFIO_USER_TYPE          0xF
490b3d881aSJohn Levon 
500b3d881aSJohn Levon #define VFIO_USER_NO_REPLY      0x10
510b3d881aSJohn Levon #define VFIO_USER_ERROR         0x20
520b3d881aSJohn Levon 
53*36227628SJohn Levon 
54*36227628SJohn Levon /*
55*36227628SJohn Levon  * VFIO_USER_VERSION
56*36227628SJohn Levon  */
57*36227628SJohn Levon typedef struct {
58*36227628SJohn Levon     VFIOUserHdr hdr;
59*36227628SJohn Levon     uint16_t major;
60*36227628SJohn Levon     uint16_t minor;
61*36227628SJohn Levon     char capabilities[];
62*36227628SJohn Levon } VFIOUserVersion;
63*36227628SJohn Levon 
64*36227628SJohn Levon #define VFIO_USER_MAJOR_VER     0
65*36227628SJohn Levon #define VFIO_USER_MINOR_VER     0
66*36227628SJohn Levon 
67*36227628SJohn Levon #define VFIO_USER_CAP           "capabilities"
68*36227628SJohn Levon 
69*36227628SJohn Levon /* "capabilities" members */
70*36227628SJohn Levon #define VFIO_USER_CAP_MAX_FDS   "max_msg_fds"
71*36227628SJohn Levon #define VFIO_USER_CAP_MAX_XFER  "max_data_xfer_size"
72*36227628SJohn Levon #define VFIO_USER_CAP_PGSIZES   "pgsizes"
73*36227628SJohn Levon #define VFIO_USER_CAP_MAP_MAX   "max_dma_maps"
74*36227628SJohn Levon #define VFIO_USER_CAP_MIGR      "migration"
75*36227628SJohn Levon 
76*36227628SJohn Levon /* "migration" members */
77*36227628SJohn Levon #define VFIO_USER_CAP_PGSIZE            "pgsize"
78*36227628SJohn Levon #define VFIO_USER_CAP_MAX_BITMAP        "max_bitmap_size"
79*36227628SJohn Levon 
80*36227628SJohn Levon /*
81*36227628SJohn Levon  * Max FDs mainly comes into play when a device supports multiple interrupts
82*36227628SJohn Levon  * where each ones uses an eventfd to inject it into the guest.
83*36227628SJohn Levon  * It is clamped by the the number of FDs the qio channel supports in a
84*36227628SJohn Levon  * single message.
85*36227628SJohn Levon  */
86*36227628SJohn Levon #define VFIO_USER_DEF_MAX_FDS   8
87*36227628SJohn Levon #define VFIO_USER_MAX_MAX_FDS   16
88*36227628SJohn Levon 
89*36227628SJohn Levon /*
90*36227628SJohn Levon  * Max transfer limits the amount of data in region and DMA messages.
91*36227628SJohn Levon  * Region R/W will be very small (limited by how much a single instruction
92*36227628SJohn Levon  * can process) so just use a reasonable limit here.
93*36227628SJohn Levon  */
94*36227628SJohn Levon #define VFIO_USER_DEF_MAX_XFER  (1024 * 1024)
95*36227628SJohn Levon #define VFIO_USER_MAX_MAX_XFER  (64 * 1024 * 1024)
96*36227628SJohn Levon 
97*36227628SJohn Levon /*
98*36227628SJohn Levon  * Default pagesizes supported is 4k.
99*36227628SJohn Levon  */
100*36227628SJohn Levon #define VFIO_USER_DEF_PGSIZE    4096
101*36227628SJohn Levon 
102*36227628SJohn Levon /*
103*36227628SJohn Levon  * Default max number of DMA mappings is stolen from the
104*36227628SJohn Levon  * linux kernel "dma_entry_limit"
105*36227628SJohn Levon  */
106*36227628SJohn Levon #define VFIO_USER_DEF_MAP_MAX   65535
107*36227628SJohn Levon 
108*36227628SJohn Levon /*
109*36227628SJohn Levon  * Default max bitmap size is also take from the linux kernel,
110*36227628SJohn Levon  * where usage of signed ints limits the VA range to 2^31 bytes.
111*36227628SJohn Levon  * Dividing that by the number of bits per byte yields 256MB
112*36227628SJohn Levon  */
113*36227628SJohn Levon #define VFIO_USER_DEF_MAX_BITMAP (256 * 1024 * 1024)
114*36227628SJohn Levon 
1150b3d881aSJohn Levon #endif /* VFIO_USER_PROTOCOL_H */
116