Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 #ifndef _LINUX_VHOST_TYPES_H
0003 #define _LINUX_VHOST_TYPES_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/types.h>
0015 #include <linux/compiler.h>
0016 #include <linux/virtio_config.h>
0017 #include <linux/virtio_ring.h>
0018 
0019 struct vhost_vring_state {
0020     unsigned int index;
0021     unsigned int num;
0022 };
0023 
0024 struct vhost_vring_file {
0025     unsigned int index;
0026     int fd; /* Pass -1 to unbind from file. */
0027 
0028 };
0029 
0030 struct vhost_vring_addr {
0031     unsigned int index;
0032     /* Option flags. */
0033     unsigned int flags;
0034     /* Flag values: */
0035     /* Whether log address is valid. If set enables logging. */
0036 #define VHOST_VRING_F_LOG 0
0037 
0038     /* Start of array of descriptors (virtually contiguous) */
0039     __u64 desc_user_addr;
0040     /* Used structure address. Must be 32 bit aligned */
0041     __u64 used_user_addr;
0042     /* Available structure address. Must be 16 bit aligned */
0043     __u64 avail_user_addr;
0044     /* Logging support. */
0045     /* Log writes to used structure, at offset calculated from specified
0046      * address. Address must be 32 bit aligned. */
0047     __u64 log_guest_addr;
0048 };
0049 
0050 /* no alignment requirement */
0051 struct vhost_iotlb_msg {
0052     __u64 iova;
0053     __u64 size;
0054     __u64 uaddr;
0055 #define VHOST_ACCESS_RO      0x1
0056 #define VHOST_ACCESS_WO      0x2
0057 #define VHOST_ACCESS_RW      0x3
0058     __u8 perm;
0059 #define VHOST_IOTLB_MISS           1
0060 #define VHOST_IOTLB_UPDATE         2
0061 #define VHOST_IOTLB_INVALIDATE     3
0062 #define VHOST_IOTLB_ACCESS_FAIL    4
0063 /*
0064  * VHOST_IOTLB_BATCH_BEGIN and VHOST_IOTLB_BATCH_END allow modifying
0065  * multiple mappings in one go: beginning with
0066  * VHOST_IOTLB_BATCH_BEGIN, followed by any number of
0067  * VHOST_IOTLB_UPDATE messages, and ending with VHOST_IOTLB_BATCH_END.
0068  * When one of these two values is used as the message type, the rest
0069  * of the fields in the message are ignored. There's no guarantee that
0070  * these changes take place automatically in the device.
0071  */
0072 #define VHOST_IOTLB_BATCH_BEGIN    5
0073 #define VHOST_IOTLB_BATCH_END      6
0074     __u8 type;
0075 };
0076 
0077 #define VHOST_IOTLB_MSG 0x1
0078 #define VHOST_IOTLB_MSG_V2 0x2
0079 
0080 struct vhost_msg {
0081     int type;
0082     union {
0083         struct vhost_iotlb_msg iotlb;
0084         __u8 padding[64];
0085     };
0086 };
0087 
0088 struct vhost_msg_v2 {
0089     __u32 type;
0090     __u32 asid;
0091     union {
0092         struct vhost_iotlb_msg iotlb;
0093         __u8 padding[64];
0094     };
0095 };
0096 
0097 struct vhost_memory_region {
0098     __u64 guest_phys_addr;
0099     __u64 memory_size; /* bytes */
0100     __u64 userspace_addr;
0101     __u64 flags_padding; /* No flags are currently specified. */
0102 };
0103 
0104 /* All region addresses and sizes must be 4K aligned. */
0105 #define VHOST_PAGE_SIZE 0x1000
0106 
0107 struct vhost_memory {
0108     __u32 nregions;
0109     __u32 padding;
0110     struct vhost_memory_region regions[];
0111 };
0112 
0113 /* VHOST_SCSI specific definitions */
0114 
0115 /*
0116  * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
0117  *
0118  * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
0119  *            RFC-v2 vhost-scsi userspace.  Add GET_ABI_VERSION ioctl usage
0120  * ABI Rev 1: January 2013. Ignore vhost_tpgt field in struct vhost_scsi_target.
0121  *            All the targets under vhost_wwpn can be seen and used by guset.
0122  */
0123 
0124 #define VHOST_SCSI_ABI_VERSION  1
0125 
0126 struct vhost_scsi_target {
0127     int abi_version;
0128     char vhost_wwpn[224]; /* TRANSPORT_IQN_LEN */
0129     unsigned short vhost_tpgt;
0130     unsigned short reserved;
0131 };
0132 
0133 /* VHOST_VDPA specific definitions */
0134 
0135 struct vhost_vdpa_config {
0136     __u32 off;
0137     __u32 len;
0138     __u8 buf[];
0139 };
0140 
0141 /* vhost vdpa IOVA range
0142  * @first: First address that can be mapped by vhost-vDPA
0143  * @last: Last address that can be mapped by vhost-vDPA
0144  */
0145 struct vhost_vdpa_iova_range {
0146     __u64 first;
0147     __u64 last;
0148 };
0149 
0150 /* Feature bits */
0151 /* Log all write descriptors. Can be changed while device is active. */
0152 #define VHOST_F_LOG_ALL 26
0153 /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
0154 #define VHOST_NET_F_VIRTIO_NET_HDR 27
0155 
0156 /* Use message type V2 */
0157 #define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1
0158 /* IOTLB can accept batching hints */
0159 #define VHOST_BACKEND_F_IOTLB_BATCH  0x2
0160 /* IOTLB can accept address space identifier through V2 type of IOTLB
0161  * message
0162  */
0163 #define VHOST_BACKEND_F_IOTLB_ASID  0x3
0164 /* Device can be suspended */
0165 #define VHOST_BACKEND_F_SUSPEND  0x4
0166 
0167 #endif