Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 #ifndef _LINUX_VHOST_H
0003 #define _LINUX_VHOST_H
0004 /* Userspace interface for in-kernel virtio accelerators. */
0005 
0006 /* vhost is used to reduce the number of system calls involved in virtio.
0007  *
0008  * Existing virtio net code is used in the guest without modification.
0009  *
0010  * This header includes interface used by userspace hypervisor for
0011  * device configuration.
0012  */
0013 
0014 #include <linux/vhost_types.h>
0015 #include <linux/types.h>
0016 #include <linux/ioctl.h>
0017 
0018 #define VHOST_FILE_UNBIND -1
0019 
0020 /* ioctls */
0021 
0022 #define VHOST_VIRTIO 0xAF
0023 
0024 /* Features bitmask for forward compatibility.  Transport bits are used for
0025  * vhost specific features. */
0026 #define VHOST_GET_FEATURES  _IOR(VHOST_VIRTIO, 0x00, __u64)
0027 #define VHOST_SET_FEATURES  _IOW(VHOST_VIRTIO, 0x00, __u64)
0028 
0029 /* Set current process as the (exclusive) owner of this file descriptor.  This
0030  * must be called before any other vhost command.  Further calls to
0031  * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
0032 #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
0033 /* Give up ownership, and reset the device to default values.
0034  * Allows subsequent call to VHOST_OWNER_SET to succeed. */
0035 #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
0036 
0037 /* Set up/modify memory layout */
0038 #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
0039 
0040 /* Write logging setup. */
0041 /* Memory writes can optionally be logged by setting bit at an offset
0042  * (calculated from the physical address) from specified log base.
0043  * The bit is set using an atomic 32 bit operation. */
0044 /* Set base address for logging. */
0045 #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
0046 /* Specify an eventfd file descriptor to signal on log write. */
0047 #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
0048 
0049 /* Ring setup. */
0050 /* Set number of descriptors in ring. This parameter can not
0051  * be modified while ring is running (bound to a device). */
0052 #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
0053 /* Set addresses for the ring. */
0054 #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
0055 /* Base value where queue looks for available descriptors */
0056 #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
0057 /* Get accessor: reads index, writes value in num */
0058 #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
0059 
0060 /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN
0061  * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL).
0062  * The byte order cannot be changed while the device is active: trying to do so
0063  * returns -EBUSY.
0064  * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is
0065  * set.
0066  * Not all kernel configurations support this ioctl, but all configurations that
0067  * support SET also support GET.
0068  */
0069 #define VHOST_VRING_LITTLE_ENDIAN 0
0070 #define VHOST_VRING_BIG_ENDIAN 1
0071 #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state)
0072 #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state)
0073 
0074 /* The following ioctls use eventfd file descriptors to signal and poll
0075  * for events. */
0076 
0077 /* Set eventfd to poll for added buffers */
0078 #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
0079 /* Set eventfd to signal when buffers have beed used */
0080 #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
0081 /* Set eventfd to signal an error */
0082 #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
0083 /* Set busy loop timeout (in us) */
0084 #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23,   \
0085                      struct vhost_vring_state)
0086 /* Get busy loop timeout (in us) */
0087 #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24,   \
0088                      struct vhost_vring_state)
0089 
0090 /* Set or get vhost backend capability */
0091 
0092 #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)
0093 #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64)
0094 
0095 /* VHOST_NET specific defines */
0096 
0097 /* Attach virtio net ring to a raw socket, or tap device.
0098  * The socket must be already bound to an ethernet device, this device will be
0099  * used for transmit.  Pass fd -1 to unbind from the socket and the transmit
0100  * device.  This can be used to stop the ring (e.g. for migration). */
0101 #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
0102 
0103 /* VHOST_SCSI specific defines */
0104 
0105 #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
0106 #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
0107 /* Changing this breaks userspace. */
0108 #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
0109 /* Set and get the events missed flag */
0110 #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
0111 #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
0112 
0113 /* VHOST_VSOCK specific defines */
0114 
0115 #define VHOST_VSOCK_SET_GUEST_CID   _IOW(VHOST_VIRTIO, 0x60, __u64)
0116 #define VHOST_VSOCK_SET_RUNNING     _IOW(VHOST_VIRTIO, 0x61, int)
0117 
0118 /* VHOST_VDPA specific defines */
0119 
0120 /* Get the device id. The device ids follow the same definition of
0121  * the device id defined in virtio-spec.
0122  */
0123 #define VHOST_VDPA_GET_DEVICE_ID    _IOR(VHOST_VIRTIO, 0x70, __u32)
0124 /* Get and set the status. The status bits follow the same definition
0125  * of the device status defined in virtio-spec.
0126  */
0127 #define VHOST_VDPA_GET_STATUS       _IOR(VHOST_VIRTIO, 0x71, __u8)
0128 #define VHOST_VDPA_SET_STATUS       _IOW(VHOST_VIRTIO, 0x72, __u8)
0129 /* Get and set the device config. The device config follows the same
0130  * definition of the device config defined in virtio-spec.
0131  */
0132 #define VHOST_VDPA_GET_CONFIG       _IOR(VHOST_VIRTIO, 0x73, \
0133                          struct vhost_vdpa_config)
0134 #define VHOST_VDPA_SET_CONFIG       _IOW(VHOST_VIRTIO, 0x74, \
0135                          struct vhost_vdpa_config)
0136 /* Enable/disable the ring. */
0137 #define VHOST_VDPA_SET_VRING_ENABLE _IOW(VHOST_VIRTIO, 0x75, \
0138                          struct vhost_vring_state)
0139 /* Get the max ring size. */
0140 #define VHOST_VDPA_GET_VRING_NUM    _IOR(VHOST_VIRTIO, 0x76, __u16)
0141 
0142 /* Set event fd for config interrupt*/
0143 #define VHOST_VDPA_SET_CONFIG_CALL  _IOW(VHOST_VIRTIO, 0x77, int)
0144 
0145 /* Get the valid iova range */
0146 #define VHOST_VDPA_GET_IOVA_RANGE   _IOR(VHOST_VIRTIO, 0x78, \
0147                          struct vhost_vdpa_iova_range)
0148 /* Get the config size */
0149 #define VHOST_VDPA_GET_CONFIG_SIZE  _IOR(VHOST_VIRTIO, 0x79, __u32)
0150 
0151 /* Get the count of all virtqueues */
0152 #define VHOST_VDPA_GET_VQS_COUNT    _IOR(VHOST_VIRTIO, 0x80, __u32)
0153 
0154 /* Get the number of virtqueue groups. */
0155 #define VHOST_VDPA_GET_GROUP_NUM    _IOR(VHOST_VIRTIO, 0x81, __u32)
0156 
0157 /* Get the number of address spaces. */
0158 #define VHOST_VDPA_GET_AS_NUM       _IOR(VHOST_VIRTIO, 0x7A, unsigned int)
0159 
0160 /* Get the group for a virtqueue: read index, write group in num,
0161  * The virtqueue index is stored in the index field of
0162  * vhost_vring_state. The group for this specific virtqueue is
0163  * returned via num field of vhost_vring_state.
0164  */
0165 #define VHOST_VDPA_GET_VRING_GROUP  _IOWR(VHOST_VIRTIO, 0x7B,   \
0166                           struct vhost_vring_state)
0167 /* Set the ASID for a virtqueue group. The group index is stored in
0168  * the index field of vhost_vring_state, the ASID associated with this
0169  * group is stored at num field of vhost_vring_state.
0170  */
0171 #define VHOST_VDPA_SET_GROUP_ASID   _IOW(VHOST_VIRTIO, 0x7C, \
0172                          struct vhost_vring_state)
0173 
0174 /* Suspend a device so it does not process virtqueue requests anymore
0175  *
0176  * After the return of ioctl the device must preserve all the necessary state
0177  * (the virtqueue vring base plus the possible device specific states) that is
0178  * required for restoring in the future. The device must not change its
0179  * configuration after that point.
0180  */
0181 #define VHOST_VDPA_SUSPEND      _IO(VHOST_VIRTIO, 0x7D)
0182 
0183 #endif