xref: /openbmc/qemu/linux-headers/linux/vhost.h (revision b3c818a4)
1dd873966SEric Auger /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
251b24e34SJan Kiszka #ifndef _LINUX_VHOST_H
351b24e34SJan Kiszka #define _LINUX_VHOST_H
451b24e34SJan Kiszka /* Userspace interface for in-kernel virtio accelerators. */
551b24e34SJan Kiszka 
651b24e34SJan Kiszka /* vhost is used to reduce the number of system calls involved in virtio.
751b24e34SJan Kiszka  *
851b24e34SJan Kiszka  * Existing virtio net code is used in the guest without modification.
951b24e34SJan Kiszka  *
1051b24e34SJan Kiszka  * This header includes interface used by userspace hypervisor for
1151b24e34SJan Kiszka  * device configuration.
1251b24e34SJan Kiszka  */
1351b24e34SJan Kiszka 
14da054c64SPaolo Bonzini #include <linux/vhost_types.h>
1551b24e34SJan Kiszka #include <linux/types.h>
1651b24e34SJan Kiszka #include <linux/ioctl.h>
1751b24e34SJan Kiszka 
18f76b348eSCornelia Huck #define VHOST_FILE_UNBIND -1
19f76b348eSCornelia Huck 
2051b24e34SJan Kiszka /* ioctls */
2151b24e34SJan Kiszka 
2251b24e34SJan Kiszka #define VHOST_VIRTIO 0xAF
2351b24e34SJan Kiszka 
2451b24e34SJan Kiszka /* Features bitmask for forward compatibility.  Transport bits are used for
2551b24e34SJan Kiszka  * vhost specific features. */
2651b24e34SJan Kiszka #define VHOST_GET_FEATURES	_IOR(VHOST_VIRTIO, 0x00, __u64)
2751b24e34SJan Kiszka #define VHOST_SET_FEATURES	_IOW(VHOST_VIRTIO, 0x00, __u64)
2851b24e34SJan Kiszka 
2951b24e34SJan Kiszka /* Set current process as the (exclusive) owner of this file descriptor.  This
3051b24e34SJan Kiszka  * must be called before any other vhost command.  Further calls to
3151b24e34SJan Kiszka  * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
3251b24e34SJan Kiszka #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
3351b24e34SJan Kiszka /* Give up ownership, and reset the device to default values.
3451b24e34SJan Kiszka  * Allows subsequent call to VHOST_OWNER_SET to succeed. */
3560915dc4SYuanhan Liu #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
3651b24e34SJan Kiszka 
3751b24e34SJan Kiszka /* Set up/modify memory layout */
3851b24e34SJan Kiszka #define VHOST_SET_MEM_TABLE	_IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
3951b24e34SJan Kiszka 
4051b24e34SJan Kiszka /* Write logging setup. */
4151b24e34SJan Kiszka /* Memory writes can optionally be logged by setting bit at an offset
4251b24e34SJan Kiszka  * (calculated from the physical address) from specified log base.
4351b24e34SJan Kiszka  * The bit is set using an atomic 32 bit operation. */
4451b24e34SJan Kiszka /* Set base address for logging. */
4551b24e34SJan Kiszka #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
4651b24e34SJan Kiszka /* Specify an eventfd file descriptor to signal on log write. */
4751b24e34SJan Kiszka #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
4851b24e34SJan Kiszka 
4951b24e34SJan Kiszka /* Ring setup. */
5051b24e34SJan Kiszka /* Set number of descriptors in ring. This parameter can not
5151b24e34SJan Kiszka  * be modified while ring is running (bound to a device). */
5251b24e34SJan Kiszka #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
5351b24e34SJan Kiszka /* Set addresses for the ring. */
5451b24e34SJan Kiszka #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
5551b24e34SJan Kiszka /* Base value where queue looks for available descriptors */
5651b24e34SJan Kiszka #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
5751b24e34SJan Kiszka /* Get accessor: reads index, writes value in num */
5851b24e34SJan Kiszka #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
5951b24e34SJan Kiszka 
60332f6407SGreg Kurz /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN
61332f6407SGreg Kurz  * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL).
62332f6407SGreg Kurz  * The byte order cannot be changed while the device is active: trying to do so
63332f6407SGreg Kurz  * returns -EBUSY.
64332f6407SGreg Kurz  * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is
65332f6407SGreg Kurz  * set.
66332f6407SGreg Kurz  * Not all kernel configurations support this ioctl, but all configurations that
67332f6407SGreg Kurz  * support SET also support GET.
68332f6407SGreg Kurz  */
69332f6407SGreg Kurz #define VHOST_VRING_LITTLE_ENDIAN 0
70332f6407SGreg Kurz #define VHOST_VRING_BIG_ENDIAN 1
71332f6407SGreg Kurz #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state)
72332f6407SGreg Kurz #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state)
73332f6407SGreg Kurz 
7451b24e34SJan Kiszka /* The following ioctls use eventfd file descriptors to signal and poll
7551b24e34SJan Kiszka  * for events. */
7651b24e34SJan Kiszka 
7751b24e34SJan Kiszka /* Set eventfd to poll for added buffers */
7851b24e34SJan Kiszka #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
7951b24e34SJan Kiszka /* Set eventfd to signal when buffers have beed used */
8051b24e34SJan Kiszka #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
8151b24e34SJan Kiszka /* Set eventfd to signal an error */
8251b24e34SJan Kiszka #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
83b89485a5SPaolo Bonzini /* Set busy loop timeout (in us) */
84b89485a5SPaolo Bonzini #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23,	\
85b89485a5SPaolo Bonzini 					 struct vhost_vring_state)
86b89485a5SPaolo Bonzini /* Get busy loop timeout (in us) */
87b89485a5SPaolo Bonzini #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24,	\
88b89485a5SPaolo Bonzini 					 struct vhost_vring_state)
8951b24e34SJan Kiszka 
90d36f7de8SCornelia Huck /* Set or get vhost backend capability */
91d36f7de8SCornelia Huck 
92d36f7de8SCornelia Huck /* Use message type V2 */
93d36f7de8SCornelia Huck #define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1
94e6546342SJason Wang /* IOTLB can accept batching hints */
95e6546342SJason Wang #define VHOST_BACKEND_F_IOTLB_BATCH  0x2
96d36f7de8SCornelia Huck 
97d36f7de8SCornelia Huck #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)
988f3cd250SCornelia Huck #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64)
99d36f7de8SCornelia Huck 
10051b24e34SJan Kiszka /* VHOST_NET specific defines */
10151b24e34SJan Kiszka 
10251b24e34SJan Kiszka /* Attach virtio net ring to a raw socket, or tap device.
10351b24e34SJan Kiszka  * The socket must be already bound to an ethernet device, this device will be
10451b24e34SJan Kiszka  * used for transmit.  Pass fd -1 to unbind from the socket and the transmit
10551b24e34SJan Kiszka  * device.  This can be used to stop the ring (e.g. for migration). */
10651b24e34SJan Kiszka #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
10751b24e34SJan Kiszka 
108da054c64SPaolo Bonzini /* VHOST_SCSI specific defines */
109e098b453SAlexey Kardashevskiy 
110e098b453SAlexey Kardashevskiy #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
111e098b453SAlexey Kardashevskiy #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
112e098b453SAlexey Kardashevskiy /* Changing this breaks userspace. */
113e098b453SAlexey Kardashevskiy #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
114e098b453SAlexey Kardashevskiy /* Set and get the events missed flag */
115e098b453SAlexey Kardashevskiy #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
116e098b453SAlexey Kardashevskiy #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
117e098b453SAlexey Kardashevskiy 
118dbdfea92SCornelia Huck /* VHOST_VSOCK specific defines */
119dbdfea92SCornelia Huck 
120dbdfea92SCornelia Huck #define VHOST_VSOCK_SET_GUEST_CID	_IOW(VHOST_VIRTIO, 0x60, __u64)
121dbdfea92SCornelia Huck #define VHOST_VSOCK_SET_RUNNING		_IOW(VHOST_VIRTIO, 0x61, int)
122dbdfea92SCornelia Huck 
123dc6f8d45SCornelia Huck /* VHOST_VDPA specific defines */
124dc6f8d45SCornelia Huck 
125dc6f8d45SCornelia Huck /* Get the device id. The device ids follow the same definition of
126dc6f8d45SCornelia Huck  * the device id defined in virtio-spec.
127dc6f8d45SCornelia Huck  */
128dc6f8d45SCornelia Huck #define VHOST_VDPA_GET_DEVICE_ID	_IOR(VHOST_VIRTIO, 0x70, __u32)
129dc6f8d45SCornelia Huck /* Get and set the status. The status bits follow the same definition
130dc6f8d45SCornelia Huck  * of the device status defined in virtio-spec.
131dc6f8d45SCornelia Huck  */
132dc6f8d45SCornelia Huck #define VHOST_VDPA_GET_STATUS		_IOR(VHOST_VIRTIO, 0x71, __u8)
133dc6f8d45SCornelia Huck #define VHOST_VDPA_SET_STATUS		_IOW(VHOST_VIRTIO, 0x72, __u8)
134dc6f8d45SCornelia Huck /* Get and set the device config. The device config follows the same
135dc6f8d45SCornelia Huck  * definition of the device config defined in virtio-spec.
136dc6f8d45SCornelia Huck  */
137dc6f8d45SCornelia Huck #define VHOST_VDPA_GET_CONFIG		_IOR(VHOST_VIRTIO, 0x73, \
138dc6f8d45SCornelia Huck 					     struct vhost_vdpa_config)
139dc6f8d45SCornelia Huck #define VHOST_VDPA_SET_CONFIG		_IOW(VHOST_VIRTIO, 0x74, \
140dc6f8d45SCornelia Huck 					     struct vhost_vdpa_config)
141dc6f8d45SCornelia Huck /* Enable/disable the ring. */
142dc6f8d45SCornelia Huck #define VHOST_VDPA_SET_VRING_ENABLE	_IOW(VHOST_VIRTIO, 0x75, \
143dc6f8d45SCornelia Huck 					     struct vhost_vring_state)
144dc6f8d45SCornelia Huck /* Get the max ring size. */
145dc6f8d45SCornelia Huck #define VHOST_VDPA_GET_VRING_NUM	_IOR(VHOST_VIRTIO, 0x76, __u16)
146dc6f8d45SCornelia Huck 
147f76b348eSCornelia Huck /* Set event fd for config interrupt*/
148f76b348eSCornelia Huck #define VHOST_VDPA_SET_CONFIG_CALL	_IOW(VHOST_VIRTIO, 0x77, int)
149*b3c818a4SEric Farman 
150*b3c818a4SEric Farman /* Get the valid iova range */
151*b3c818a4SEric Farman #define VHOST_VDPA_GET_IOVA_RANGE	_IOR(VHOST_VIRTIO, 0x78, \
152*b3c818a4SEric Farman 					     struct vhost_vdpa_iova_range)
15351b24e34SJan Kiszka #endif
154