Greg Kroah-Hartman | 6f52b16 | 2017-11-01 15:08:43 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
Michael S. Tsirkin | 3a4d5c9 | 2010-01-14 06:17:27 +0000 | [diff] [blame] | 2 | #ifndef _LINUX_VHOST_H |
| 3 | #define _LINUX_VHOST_H |
| 4 | /* Userspace interface for in-kernel virtio accelerators. */ |
| 5 | |
| 6 | /* vhost is used to reduce the number of system calls involved in virtio. |
| 7 | * |
| 8 | * Existing virtio net code is used in the guest without modification. |
| 9 | * |
| 10 | * This header includes interface used by userspace hypervisor for |
| 11 | * device configuration. |
| 12 | */ |
| 13 | |
Paolo Bonzini | 4b86713 | 2018-12-17 18:35:09 +0100 | [diff] [blame] | 14 | #include <linux/vhost_types.h> |
Michael S. Tsirkin | 3a4d5c9 | 2010-01-14 06:17:27 +0000 | [diff] [blame] | 15 | #include <linux/types.h> |
Michael S. Tsirkin | 3a4d5c9 | 2010-01-14 06:17:27 +0000 | [diff] [blame] | 16 | #include <linux/ioctl.h> |
Michael S. Tsirkin | 3a4d5c9 | 2010-01-14 06:17:27 +0000 | [diff] [blame] | 17 | |
| 18 | /* ioctls */ |
| 19 | |
| 20 | #define VHOST_VIRTIO 0xAF |
| 21 | |
| 22 | /* Features bitmask for forward compatibility. Transport bits are used for |
| 23 | * vhost specific features. */ |
| 24 | #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64) |
| 25 | #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64) |
| 26 | |
| 27 | /* Set current process as the (exclusive) owner of this file descriptor. This |
| 28 | * must be called before any other vhost command. Further calls to |
| 29 | * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */ |
| 30 | #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01) |
| 31 | /* Give up ownership, and reset the device to default values. |
| 32 | * Allows subsequent call to VHOST_OWNER_SET to succeed. */ |
| 33 | #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) |
| 34 | |
| 35 | /* Set up/modify memory layout */ |
| 36 | #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory) |
| 37 | |
| 38 | /* Write logging setup. */ |
| 39 | /* Memory writes can optionally be logged by setting bit at an offset |
| 40 | * (calculated from the physical address) from specified log base. |
| 41 | * The bit is set using an atomic 32 bit operation. */ |
| 42 | /* Set base address for logging. */ |
| 43 | #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64) |
| 44 | /* Specify an eventfd file descriptor to signal on log write. */ |
| 45 | #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int) |
| 46 | |
| 47 | /* Ring setup. */ |
| 48 | /* Set number of descriptors in ring. This parameter can not |
| 49 | * be modified while ring is running (bound to a device). */ |
| 50 | #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state) |
| 51 | /* Set addresses for the ring. */ |
| 52 | #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr) |
| 53 | /* Base value where queue looks for available descriptors */ |
| 54 | #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state) |
| 55 | /* Get accessor: reads index, writes value in num */ |
| 56 | #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state) |
| 57 | |
Greg Kurz | 2751c98 | 2015-04-24 14:27:24 +0200 | [diff] [blame] | 58 | /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN |
| 59 | * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL). |
| 60 | * The byte order cannot be changed while the device is active: trying to do so |
| 61 | * returns -EBUSY. |
| 62 | * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is |
| 63 | * set. |
| 64 | * Not all kernel configurations support this ioctl, but all configurations that |
| 65 | * support SET also support GET. |
| 66 | */ |
| 67 | #define VHOST_VRING_LITTLE_ENDIAN 0 |
| 68 | #define VHOST_VRING_BIG_ENDIAN 1 |
| 69 | #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state) |
| 70 | #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state) |
| 71 | |
Michael S. Tsirkin | 3a4d5c9 | 2010-01-14 06:17:27 +0000 | [diff] [blame] | 72 | /* The following ioctls use eventfd file descriptors to signal and poll |
| 73 | * for events. */ |
| 74 | |
| 75 | /* Set eventfd to poll for added buffers */ |
| 76 | #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file) |
| 77 | /* Set eventfd to signal when buffers have beed used */ |
| 78 | #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file) |
| 79 | /* Set eventfd to signal an error */ |
| 80 | #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) |
Jason Wang | 0308813 | 2016-03-04 06:24:53 -0500 | [diff] [blame] | 81 | /* Set busy loop timeout (in us) */ |
| 82 | #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23, \ |
| 83 | struct vhost_vring_state) |
| 84 | /* Get busy loop timeout (in us) */ |
| 85 | #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \ |
| 86 | struct vhost_vring_state) |
Michael S. Tsirkin | 3a4d5c9 | 2010-01-14 06:17:27 +0000 | [diff] [blame] | 87 | |
Jason Wang | 429711a | 2018-08-06 11:17:47 +0800 | [diff] [blame] | 88 | /* Set or get vhost backend capability */ |
| 89 | |
| 90 | /* Use message type V2 */ |
| 91 | #define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1 |
| 92 | |
| 93 | #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64) |
Gleb Fotengauer-Malinovskiy | c48300c | 2018-09-03 20:59:13 +0300 | [diff] [blame] | 94 | #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64) |
Jason Wang | 429711a | 2018-08-06 11:17:47 +0800 | [diff] [blame] | 95 | |
Michael S. Tsirkin | 3a4d5c9 | 2010-01-14 06:17:27 +0000 | [diff] [blame] | 96 | /* VHOST_NET specific defines */ |
| 97 | |
| 98 | /* Attach virtio net ring to a raw socket, or tap device. |
| 99 | * The socket must be already bound to an ethernet device, this device will be |
| 100 | * used for transmit. Pass fd -1 to unbind from the socket and the transmit |
| 101 | * device. This can be used to stop the ring (e.g. for migration). */ |
| 102 | #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file) |
| 103 | |
Paolo Bonzini | 4b86713 | 2018-12-17 18:35:09 +0100 | [diff] [blame] | 104 | /* VHOST_SCSI specific defines */ |
Michael S. Tsirkin | 5012a3a | 2013-05-02 03:50:34 +0300 | [diff] [blame] | 105 | |
| 106 | #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target) |
| 107 | #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target) |
| 108 | /* Changing this breaks userspace. */ |
| 109 | #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int) |
| 110 | /* Set and get the events missed flag */ |
| 111 | #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32) |
| 112 | #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32) |
| 113 | |
Asias He | 433fc58 | 2016-07-28 15:36:34 +0100 | [diff] [blame] | 114 | /* VHOST_VSOCK specific defines */ |
| 115 | |
| 116 | #define VHOST_VSOCK_SET_GUEST_CID _IOW(VHOST_VIRTIO, 0x60, __u64) |
| 117 | #define VHOST_VSOCK_SET_RUNNING _IOW(VHOST_VIRTIO, 0x61, int) |
| 118 | |
Tiwei Bie | 4c8cf31 | 2020-03-26 22:01:23 +0800 | [diff] [blame^] | 119 | /* VHOST_VDPA specific defines */ |
| 120 | |
| 121 | /* Get the device id. The device ids follow the same definition of |
| 122 | * the device id defined in virtio-spec. |
| 123 | */ |
| 124 | #define VHOST_VDPA_GET_DEVICE_ID _IOR(VHOST_VIRTIO, 0x70, __u32) |
| 125 | /* Get and set the status. The status bits follow the same definition |
| 126 | * of the device status defined in virtio-spec. |
| 127 | */ |
| 128 | #define VHOST_VDPA_GET_STATUS _IOR(VHOST_VIRTIO, 0x71, __u8) |
| 129 | #define VHOST_VDPA_SET_STATUS _IOW(VHOST_VIRTIO, 0x72, __u8) |
| 130 | /* Get and set the device config. The device config follows the same |
| 131 | * definition of the device config defined in virtio-spec. |
| 132 | */ |
| 133 | #define VHOST_VDPA_GET_CONFIG _IOR(VHOST_VIRTIO, 0x73, \ |
| 134 | struct vhost_vdpa_config) |
| 135 | #define VHOST_VDPA_SET_CONFIG _IOW(VHOST_VIRTIO, 0x74, \ |
| 136 | struct vhost_vdpa_config) |
| 137 | /* Enable/disable the ring. */ |
| 138 | #define VHOST_VDPA_SET_VRING_ENABLE _IOW(VHOST_VIRTIO, 0x75, \ |
| 139 | struct vhost_vring_state) |
| 140 | /* Get the max ring size. */ |
| 141 | #define VHOST_VDPA_GET_VRING_NUM _IOR(VHOST_VIRTIO, 0x76, __u16) |
| 142 | |
Michael S. Tsirkin | 3a4d5c9 | 2010-01-14 06:17:27 +0000 | [diff] [blame] | 143 | #endif |