xref: /qemu/hw/vfio-user/protocol.h (revision 3bdb738b734c77f93f93f8119c8f6ba8a9c5947c)
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 
5336227628SJohn Levon 
5436227628SJohn Levon /*
5536227628SJohn Levon  * VFIO_USER_VERSION
5636227628SJohn Levon  */
5736227628SJohn Levon typedef struct {
5836227628SJohn Levon     VFIOUserHdr hdr;
5936227628SJohn Levon     uint16_t major;
6036227628SJohn Levon     uint16_t minor;
6136227628SJohn Levon     char capabilities[];
6236227628SJohn Levon } VFIOUserVersion;
6336227628SJohn Levon 
6436227628SJohn Levon #define VFIO_USER_MAJOR_VER     0
6536227628SJohn Levon #define VFIO_USER_MINOR_VER     0
6636227628SJohn Levon 
6736227628SJohn Levon #define VFIO_USER_CAP           "capabilities"
6836227628SJohn Levon 
6936227628SJohn Levon /* "capabilities" members */
7036227628SJohn Levon #define VFIO_USER_CAP_MAX_FDS   "max_msg_fds"
7136227628SJohn Levon #define VFIO_USER_CAP_MAX_XFER  "max_data_xfer_size"
7236227628SJohn Levon #define VFIO_USER_CAP_PGSIZES   "pgsizes"
7336227628SJohn Levon #define VFIO_USER_CAP_MAP_MAX   "max_dma_maps"
7436227628SJohn Levon #define VFIO_USER_CAP_MIGR      "migration"
7536227628SJohn Levon 
7636227628SJohn Levon /* "migration" members */
7736227628SJohn Levon #define VFIO_USER_CAP_PGSIZE            "pgsize"
7836227628SJohn Levon #define VFIO_USER_CAP_MAX_BITMAP        "max_bitmap_size"
7936227628SJohn Levon 
8036227628SJohn Levon /*
8136227628SJohn Levon  * Max FDs mainly comes into play when a device supports multiple interrupts
8236227628SJohn Levon  * where each ones uses an eventfd to inject it into the guest.
8336227628SJohn Levon  * It is clamped by the the number of FDs the qio channel supports in a
8436227628SJohn Levon  * single message.
8536227628SJohn Levon  */
8636227628SJohn Levon #define VFIO_USER_DEF_MAX_FDS   8
8736227628SJohn Levon #define VFIO_USER_MAX_MAX_FDS   16
8836227628SJohn Levon 
8936227628SJohn Levon /*
9036227628SJohn Levon  * Max transfer limits the amount of data in region and DMA messages.
9136227628SJohn Levon  * Region R/W will be very small (limited by how much a single instruction
9236227628SJohn Levon  * can process) so just use a reasonable limit here.
9336227628SJohn Levon  */
9436227628SJohn Levon #define VFIO_USER_DEF_MAX_XFER  (1024 * 1024)
9536227628SJohn Levon #define VFIO_USER_MAX_MAX_XFER  (64 * 1024 * 1024)
9636227628SJohn Levon 
9736227628SJohn Levon /*
9836227628SJohn Levon  * Default pagesizes supported is 4k.
9936227628SJohn Levon  */
10036227628SJohn Levon #define VFIO_USER_DEF_PGSIZE    4096
10136227628SJohn Levon 
10236227628SJohn Levon /*
10336227628SJohn Levon  * Default max number of DMA mappings is stolen from the
10436227628SJohn Levon  * linux kernel "dma_entry_limit"
10536227628SJohn Levon  */
10636227628SJohn Levon #define VFIO_USER_DEF_MAP_MAX   65535
10736227628SJohn Levon 
10836227628SJohn Levon /*
10936227628SJohn Levon  * Default max bitmap size is also take from the linux kernel,
11036227628SJohn Levon  * where usage of signed ints limits the VA range to 2^31 bytes.
11136227628SJohn Levon  * Dividing that by the number of bits per byte yields 256MB
11236227628SJohn Levon  */
11336227628SJohn Levon #define VFIO_USER_DEF_MAX_BITMAP (256 * 1024 * 1024)
11436227628SJohn Levon 
115*3bdb738bSJohn Levon /*
116*3bdb738bSJohn Levon  * VFIO_USER_DEVICE_GET_INFO
117*3bdb738bSJohn Levon  * imported from struct vfio_device_info
118*3bdb738bSJohn Levon  */
119*3bdb738bSJohn Levon typedef struct {
120*3bdb738bSJohn Levon     VFIOUserHdr hdr;
121*3bdb738bSJohn Levon     uint32_t argsz;
122*3bdb738bSJohn Levon     uint32_t flags;
123*3bdb738bSJohn Levon     uint32_t num_regions;
124*3bdb738bSJohn Levon     uint32_t num_irqs;
125*3bdb738bSJohn Levon } VFIOUserDeviceInfo;
126*3bdb738bSJohn Levon 
1270b3d881aSJohn Levon #endif /* VFIO_USER_PROTOCOL_H */
128