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