qdev-properties: add UUID property type
[qemu.git] / linux-headers / linux / vhost.h
blob1e86a3dd0d5a4ffac8057ac9fa7641af047ee2d3
1 #ifndef _LINUX_VHOST_H
2 #define _LINUX_VHOST_H
3 /* Userspace interface for in-kernel virtio accelerators. */
5 /* vhost is used to reduce the number of system calls involved in virtio.
7 * Existing virtio net code is used in the guest without modification.
9 * This header includes interface used by userspace hypervisor for
10 * device configuration.
13 #include <linux/types.h>
15 #include <linux/ioctl.h>
16 #include <linux/virtio_config.h>
17 #include <linux/virtio_ring.h>
19 struct vhost_vring_state {
20 unsigned int index;
21 unsigned int num;
24 struct vhost_vring_file {
25 unsigned int index;
26 int fd; /* Pass -1 to unbind from file. */
30 struct vhost_vring_addr {
31 unsigned int index;
32 /* Option flags. */
33 unsigned int flags;
34 /* Flag values: */
35 /* Whether log address is valid. If set enables logging. */
36 #define VHOST_VRING_F_LOG 0
38 /* Start of array of descriptors (virtually contiguous) */
39 __u64 desc_user_addr;
40 /* Used structure address. Must be 32 bit aligned */
41 __u64 used_user_addr;
42 /* Available structure address. Must be 16 bit aligned */
43 __u64 avail_user_addr;
44 /* Logging support. */
45 /* Log writes to used structure, at offset calculated from specified
46 * address. Address must be 32 bit aligned. */
47 __u64 log_guest_addr;
50 /* no alignment requirement */
51 struct vhost_iotlb_msg {
52 __u64 iova;
53 __u64 size;
54 __u64 uaddr;
55 #define VHOST_ACCESS_RO 0x1
56 #define VHOST_ACCESS_WO 0x2
57 #define VHOST_ACCESS_RW 0x3
58 __u8 perm;
59 #define VHOST_IOTLB_MISS 1
60 #define VHOST_IOTLB_UPDATE 2
61 #define VHOST_IOTLB_INVALIDATE 3
62 #define VHOST_IOTLB_ACCESS_FAIL 4
63 __u8 type;
66 #define VHOST_IOTLB_MSG 0x1
68 struct vhost_msg {
69 int type;
70 union {
71 struct vhost_iotlb_msg iotlb;
72 __u8 padding[64];
76 struct vhost_memory_region {
77 __u64 guest_phys_addr;
78 __u64 memory_size; /* bytes */
79 __u64 userspace_addr;
80 __u64 flags_padding; /* No flags are currently specified. */
83 /* All region addresses and sizes must be 4K aligned. */
84 #define VHOST_PAGE_SIZE 0x1000
86 struct vhost_memory {
87 __u32 nregions;
88 __u32 padding;
89 struct vhost_memory_region regions[0];
92 /* ioctls */
94 #define VHOST_VIRTIO 0xAF
96 /* Features bitmask for forward compatibility. Transport bits are used for
97 * vhost specific features. */
98 #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64)
99 #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64)
101 /* Set current process as the (exclusive) owner of this file descriptor. This
102 * must be called before any other vhost command. Further calls to
103 * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
104 #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
105 /* Give up ownership, and reset the device to default values.
106 * Allows subsequent call to VHOST_OWNER_SET to succeed. */
107 #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
109 /* Set up/modify memory layout */
110 #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
112 /* Write logging setup. */
113 /* Memory writes can optionally be logged by setting bit at an offset
114 * (calculated from the physical address) from specified log base.
115 * The bit is set using an atomic 32 bit operation. */
116 /* Set base address for logging. */
117 #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
118 /* Specify an eventfd file descriptor to signal on log write. */
119 #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
121 /* Ring setup. */
122 /* Set number of descriptors in ring. This parameter can not
123 * be modified while ring is running (bound to a device). */
124 #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
125 /* Set addresses for the ring. */
126 #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
127 /* Base value where queue looks for available descriptors */
128 #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
129 /* Get accessor: reads index, writes value in num */
130 #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
132 /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN
133 * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL).
134 * The byte order cannot be changed while the device is active: trying to do so
135 * returns -EBUSY.
136 * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is
137 * set.
138 * Not all kernel configurations support this ioctl, but all configurations that
139 * support SET also support GET.
141 #define VHOST_VRING_LITTLE_ENDIAN 0
142 #define VHOST_VRING_BIG_ENDIAN 1
143 #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state)
144 #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state)
146 /* The following ioctls use eventfd file descriptors to signal and poll
147 * for events. */
149 /* Set eventfd to poll for added buffers */
150 #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
151 /* Set eventfd to signal when buffers have beed used */
152 #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
153 /* Set eventfd to signal an error */
154 #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
155 /* Set busy loop timeout (in us) */
156 #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23, \
157 struct vhost_vring_state)
158 /* Get busy loop timeout (in us) */
159 #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \
160 struct vhost_vring_state)
162 /* VHOST_NET specific defines */
164 /* Attach virtio net ring to a raw socket, or tap device.
165 * The socket must be already bound to an ethernet device, this device will be
166 * used for transmit. Pass fd -1 to unbind from the socket and the transmit
167 * device. This can be used to stop the ring (e.g. for migration). */
168 #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
170 /* Feature bits */
171 /* Log all write descriptors. Can be changed while device is active. */
172 #define VHOST_F_LOG_ALL 26
173 /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
174 #define VHOST_NET_F_VIRTIO_NET_HDR 27
176 /* VHOST_SCSI specific definitions */
179 * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
181 * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
182 * RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl usage
183 * ABI Rev 1: January 2013. Ignore vhost_tpgt filed in struct vhost_scsi_target.
184 * All the targets under vhost_wwpn can be seen and used by guset.
187 #define VHOST_SCSI_ABI_VERSION 1
189 struct vhost_scsi_target {
190 int abi_version;
191 char vhost_wwpn[224]; /* TRANSPORT_IQN_LEN */
192 unsigned short vhost_tpgt;
193 unsigned short reserved;
196 #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
197 #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
198 /* Changing this breaks userspace. */
199 #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
200 /* Set and get the events missed flag */
201 #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
202 #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
204 /* VHOST_VSOCK specific defines */
206 #define VHOST_VSOCK_SET_GUEST_CID _IOW(VHOST_VIRTIO, 0x60, __u64)
207 #define VHOST_VSOCK_SET_RUNNING _IOW(VHOST_VIRTIO, 0x61, int)
209 #endif