2e83913
This makes it possible to build vhost support
2e83913
on systems which do not have this header.
2e83913
2e83913
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2e83913
---
2e83913
 kvm/include/linux/vhost.h |  130 +++++++++++++++++++++++++++++++++++++++++++++
2e83913
 1 files changed, 130 insertions(+), 0 deletions(-)
2e83913
 create mode 100644 kvm/include/linux/vhost.h
2e83913
2e83913
diff --git a/kvm/include/linux/vhost.h b/kvm/include/linux/vhost.h
2e83913
new file mode 100644
2e83913
index 0000000..165a484
2e83913
--- /dev/null
2e83913
+++ b/kvm/include/linux/vhost.h
2e83913
@@ -0,0 +1,130 @@
2e83913
+#ifndef _LINUX_VHOST_H
2e83913
+#define _LINUX_VHOST_H
2e83913
+/* Userspace interface for in-kernel virtio accelerators. */
2e83913
+
2e83913
+/* vhost is used to reduce the number of system calls involved in virtio.
2e83913
+ *
2e83913
+ * Existing virtio net code is used in the guest without modification.
2e83913
+ *
2e83913
+ * This header includes interface used by userspace hypervisor for
2e83913
+ * device configuration.
2e83913
+ */
2e83913
+
2e83913
+#include <linux/types.h>
2e83913
+
2e83913
+#include <linux/ioctl.h>
2e83913
+#include <linux/virtio_config.h>
2e83913
+#include <linux/virtio_ring.h>
2e83913
+
2e83913
+struct vhost_vring_state {
2e83913
+	unsigned int index;
2e83913
+	unsigned int num;
2e83913
+};
2e83913
+
2e83913
+struct vhost_vring_file {
2e83913
+	unsigned int index;
2e83913
+	int fd; /* Pass -1 to unbind from file. */
2e83913
+
2e83913
+};
2e83913
+
2e83913
+struct vhost_vring_addr {
2e83913
+	unsigned int index;
2e83913
+	/* Option flags. */
2e83913
+	unsigned int flags;
2e83913
+	/* Flag values: */
2e83913
+	/* Whether log address is valid. If set enables logging. */
2e83913
+#define VHOST_VRING_F_LOG 0
2e83913
+
2e83913
+	/* Start of array of descriptors (virtually contiguous) */
2e83913
+	__u64 desc_user_addr;
2e83913
+	/* Used structure address. Must be 32 bit aligned */
2e83913
+	__u64 used_user_addr;
2e83913
+	/* Available structure address. Must be 16 bit aligned */
2e83913
+	__u64 avail_user_addr;
2e83913
+	/* Logging support. */
2e83913
+	/* Log writes to used structure, at offset calculated from specified
2e83913
+	 * address. Address must be 32 bit aligned. */
2e83913
+	__u64 log_guest_addr;
2e83913
+};
2e83913
+
2e83913
+struct vhost_memory_region {
2e83913
+	__u64 guest_phys_addr;
2e83913
+	__u64 memory_size; /* bytes */
2e83913
+	__u64 userspace_addr;
2e83913
+	__u64 flags_padding; /* No flags are currently specified. */
2e83913
+};
2e83913
+
2e83913
+/* All region addresses and sizes must be 4K aligned. */
2e83913
+#define VHOST_PAGE_SIZE 0x1000
2e83913
+
2e83913
+struct vhost_memory {
2e83913
+	__u32 nregions;
2e83913
+	__u32 padding;
2e83913
+	struct vhost_memory_region regions[0];
2e83913
+};
2e83913
+
2e83913
+/* ioctls */
2e83913
+
2e83913
+#define VHOST_VIRTIO 0xAF
2e83913
+
2e83913
+/* Features bitmask for forward compatibility.  Transport bits are used for
2e83913
+ * vhost specific features. */
2e83913
+#define VHOST_GET_FEATURES	_IOR(VHOST_VIRTIO, 0x00, __u64)
2e83913
+#define VHOST_SET_FEATURES	_IOW(VHOST_VIRTIO, 0x00, __u64)
2e83913
+
2e83913
+/* Set current process as the (exclusive) owner of this file descriptor.  This
2e83913
+ * must be called before any other vhost command.  Further calls to
2e83913
+ * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
2e83913
+#define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
2e83913
+/* Give up ownership, and reset the device to default values.
2e83913
+ * Allows subsequent call to VHOST_OWNER_SET to succeed. */
2e83913
+#define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
2e83913
+
2e83913
+/* Set up/modify memory layout */
2e83913
+#define VHOST_SET_MEM_TABLE	_IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
2e83913
+
2e83913
+/* Write logging setup. */
2e83913
+/* Memory writes can optionally be logged by setting bit at an offset
2e83913
+ * (calculated from the physical address) from specified log base.
2e83913
+ * The bit is set using an atomic 32 bit operation. */
2e83913
+/* Set base address for logging. */
2e83913
+#define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
2e83913
+/* Specify an eventfd file descriptor to signal on log write. */
2e83913
+#define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
2e83913
+
2e83913
+/* Ring setup. */
2e83913
+/* Set number of descriptors in ring. This parameter can not
2e83913
+ * be modified while ring is running (bound to a device). */
2e83913
+#define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
2e83913
+/* Set addresses for the ring. */
2e83913
+#define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
2e83913
+/* Base value where queue looks for available descriptors */
2e83913
+#define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
2e83913
+/* Get accessor: reads index, writes value in num */
2e83913
+#define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
2e83913
+
2e83913
+/* The following ioctls use eventfd file descriptors to signal and poll
2e83913
+ * for events. */
2e83913
+
2e83913
+/* Set eventfd to poll for added buffers */
2e83913
+#define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
2e83913
+/* Set eventfd to signal when buffers have beed used */
2e83913
+#define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
2e83913
+/* Set eventfd to signal an error */
2e83913
+#define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
2e83913
+
2e83913
+/* VHOST_NET specific defines */
2e83913
+
2e83913
+/* Attach virtio net ring to a raw socket, or tap device.
2e83913
+ * The socket must be already bound to an ethernet device, this device will be
2e83913
+ * used for transmit.  Pass fd -1 to unbind from the socket and the transmit
2e83913
+ * device.  This can be used to stop the ring (e.g. for migration). */
2e83913
+#define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
2e83913
+
2e83913
+/* Feature bits */
2e83913
+/* Log all write descriptors. Can be changed while device is active. */
2e83913
+#define VHOST_F_LOG_ALL 26
2e83913
+/* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
2e83913
+#define VHOST_NET_F_VIRTIO_NET_HDR 27
2e83913
+
2e83913
+#endif
2e83913
-- 
2e83913
1.6.6.144.g5c3af