qemu

FORK: QEMU emulator
git clone https://git.neptards.moe/neptards/qemu.git
Log | Files | Refs | Submodules | LICENSE

vhost_types.h (4453B)


      1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
      2 #ifndef _LINUX_VHOST_TYPES_H
      3 #define _LINUX_VHOST_TYPES_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 
     14 #include "standard-headers/linux/types.h"
     15 
     16 #include "standard-headers/linux/virtio_config.h"
     17 #include "standard-headers/linux/virtio_ring.h"
     18 
     19 struct vhost_vring_state {
     20 	unsigned int index;
     21 	unsigned int num;
     22 };
     23 
     24 struct vhost_vring_file {
     25 	unsigned int index;
     26 	int fd; /* Pass -1 to unbind from file. */
     27 
     28 };
     29 
     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
     37 
     38 	/* Start of array of descriptors (virtually contiguous) */
     39 	uint64_t desc_user_addr;
     40 	/* Used structure address. Must be 32 bit aligned */
     41 	uint64_t used_user_addr;
     42 	/* Available structure address. Must be 16 bit aligned */
     43 	uint64_t 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 	uint64_t log_guest_addr;
     48 };
     49 
     50 /* no alignment requirement */
     51 struct vhost_iotlb_msg {
     52 	uint64_t iova;
     53 	uint64_t size;
     54 	uint64_t uaddr;
     55 #define VHOST_ACCESS_RO      0x1
     56 #define VHOST_ACCESS_WO      0x2
     57 #define VHOST_ACCESS_RW      0x3
     58 	uint8_t 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 /*
     64  * VHOST_IOTLB_BATCH_BEGIN and VHOST_IOTLB_BATCH_END allow modifying
     65  * multiple mappings in one go: beginning with
     66  * VHOST_IOTLB_BATCH_BEGIN, followed by any number of
     67  * VHOST_IOTLB_UPDATE messages, and ending with VHOST_IOTLB_BATCH_END.
     68  * When one of these two values is used as the message type, the rest
     69  * of the fields in the message are ignored. There's no guarantee that
     70  * these changes take place automatically in the device.
     71  */
     72 #define VHOST_IOTLB_BATCH_BEGIN    5
     73 #define VHOST_IOTLB_BATCH_END      6
     74 	uint8_t type;
     75 };
     76 
     77 #define VHOST_IOTLB_MSG 0x1
     78 #define VHOST_IOTLB_MSG_V2 0x2
     79 
     80 struct vhost_msg {
     81 	int type;
     82 	union {
     83 		struct vhost_iotlb_msg iotlb;
     84 		uint8_t padding[64];
     85 	};
     86 };
     87 
     88 struct vhost_msg_v2 {
     89 	uint32_t type;
     90 	uint32_t asid;
     91 	union {
     92 		struct vhost_iotlb_msg iotlb;
     93 		uint8_t padding[64];
     94 	};
     95 };
     96 
     97 struct vhost_memory_region {
     98 	uint64_t guest_phys_addr;
     99 	uint64_t memory_size; /* bytes */
    100 	uint64_t userspace_addr;
    101 	uint64_t flags_padding; /* No flags are currently specified. */
    102 };
    103 
    104 /* All region addresses and sizes must be 4K aligned. */
    105 #define VHOST_PAGE_SIZE 0x1000
    106 
    107 struct vhost_memory {
    108 	uint32_t nregions;
    109 	uint32_t padding;
    110 	struct vhost_memory_region regions[];
    111 };
    112 
    113 /* VHOST_SCSI specific definitions */
    114 
    115 /*
    116  * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
    117  *
    118  * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
    119  *            RFC-v2 vhost-scsi userspace.  Add GET_ABI_VERSION ioctl usage
    120  * ABI Rev 1: January 2013. Ignore vhost_tpgt field in struct vhost_scsi_target.
    121  *            All the targets under vhost_wwpn can be seen and used by guset.
    122  */
    123 
    124 #define VHOST_SCSI_ABI_VERSION	1
    125 
    126 struct vhost_scsi_target {
    127 	int abi_version;
    128 	char vhost_wwpn[224]; /* TRANSPORT_IQN_LEN */
    129 	unsigned short vhost_tpgt;
    130 	unsigned short reserved;
    131 };
    132 
    133 /* VHOST_VDPA specific definitions */
    134 
    135 struct vhost_vdpa_config {
    136 	uint32_t off;
    137 	uint32_t len;
    138 	uint8_t buf[];
    139 };
    140 
    141 /* vhost vdpa IOVA range
    142  * @first: First address that can be mapped by vhost-vDPA
    143  * @last: Last address that can be mapped by vhost-vDPA
    144  */
    145 struct vhost_vdpa_iova_range {
    146 	uint64_t first;
    147 	uint64_t last;
    148 };
    149 
    150 /* Feature bits */
    151 /* Log all write descriptors. Can be changed while device is active. */
    152 #define VHOST_F_LOG_ALL 26
    153 /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
    154 #define VHOST_NET_F_VIRTIO_NET_HDR 27
    155 
    156 /* Use message type V2 */
    157 #define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1
    158 /* IOTLB can accept batching hints */
    159 #define VHOST_BACKEND_F_IOTLB_BATCH  0x2
    160 /* IOTLB can accept address space identifier through V2 type of IOTLB
    161  * message
    162  */
    163 #define VHOST_BACKEND_F_IOTLB_ASID  0x3
    164 /* Device can be suspended */
    165 #define VHOST_BACKEND_F_SUSPEND  0x4
    166 
    167 #endif