1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2016 Intel Corporation 3 */ 4 5 #ifndef _VIRTIO_USER_VHOST_H 6 #define _VIRTIO_USER_VHOST_H 7 8 #include <stdint.h> 9 #include <linux/types.h> 10 #include <linux/ioctl.h> 11 12 #include "../virtio_pci.h" 13 #include "../virtio_logs.h" 14 #include "../virtqueue.h" 15 16 struct vhost_vring_state { 17 unsigned int index; 18 unsigned int num; 19 }; 20 21 struct vhost_vring_file { 22 unsigned int index; 23 int fd; 24 }; 25 26 struct vhost_vring_addr { 27 unsigned int index; 28 /* Option flags. */ 29 unsigned int flags; 30 /* Flag values: */ 31 /* Whether log address is valid. If set enables logging. */ 32 #define VHOST_VRING_F_LOG 0 33 34 /* Start of array of descriptors (virtually contiguous) */ 35 uint64_t desc_user_addr; 36 /* Used structure address. Must be 32 bit aligned */ 37 uint64_t used_user_addr; 38 /* Available structure address. Must be 16 bit aligned */ 39 uint64_t avail_user_addr; 40 /* Logging support. */ 41 /* Log writes to used structure, at offset calculated from specified 42 * address. Address must be 32 bit aligned. 43 */ 44 uint64_t log_guest_addr; 45 }; 46 47 #ifndef VHOST_USER_F_PROTOCOL_FEATURES 48 #define VHOST_USER_F_PROTOCOL_FEATURES 30 49 #endif 50 51 /** Protocol features. */ 52 #ifndef VHOST_USER_PROTOCOL_F_MQ 53 #define VHOST_USER_PROTOCOL_F_MQ 0 54 #endif 55 56 #ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK 57 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 58 #endif 59 60 #ifndef VHOST_USER_PROTOCOL_F_STATUS 61 #define VHOST_USER_PROTOCOL_F_STATUS 16 62 #endif 63 64 enum vhost_user_request { 65 VHOST_USER_NONE = 0, 66 VHOST_USER_GET_FEATURES = 1, 67 VHOST_USER_SET_FEATURES = 2, 68 VHOST_USER_SET_OWNER = 3, 69 VHOST_USER_RESET_OWNER = 4, 70 VHOST_USER_SET_MEM_TABLE = 5, 71 VHOST_USER_SET_LOG_BASE = 6, 72 VHOST_USER_SET_LOG_FD = 7, 73 VHOST_USER_SET_VRING_NUM = 8, 74 VHOST_USER_SET_VRING_ADDR = 9, 75 VHOST_USER_SET_VRING_BASE = 10, 76 VHOST_USER_GET_VRING_BASE = 11, 77 VHOST_USER_SET_VRING_KICK = 12, 78 VHOST_USER_SET_VRING_CALL = 13, 79 VHOST_USER_SET_VRING_ERR = 14, 80 VHOST_USER_GET_PROTOCOL_FEATURES = 15, 81 VHOST_USER_SET_PROTOCOL_FEATURES = 16, 82 VHOST_USER_GET_QUEUE_NUM = 17, 83 VHOST_USER_SET_VRING_ENABLE = 18, 84 VHOST_USER_SET_STATUS = 39, 85 VHOST_USER_GET_STATUS = 40, 86 VHOST_USER_MAX 87 }; 88 89 extern const char * const vhost_msg_strings[VHOST_USER_MAX]; 90 91 struct vhost_memory_region { 92 uint64_t guest_phys_addr; 93 uint64_t memory_size; /* bytes */ 94 uint64_t userspace_addr; 95 uint64_t mmap_offset; 96 }; 97 98 struct virtio_user_dev; 99 100 struct virtio_user_backend_ops { 101 int (*setup)(struct virtio_user_dev *dev); 102 int (*send_request)(struct virtio_user_dev *dev, 103 enum vhost_user_request req, 104 void *arg); 105 int (*enable_qp)(struct virtio_user_dev *dev, 106 uint16_t pair_idx, 107 int enable); 108 int (*dma_map)(struct virtio_user_dev *dev, void *addr, 109 uint64_t iova, size_t len); 110 int (*dma_unmap)(struct virtio_user_dev *dev, void *addr, 111 uint64_t iova, size_t len); 112 }; 113 114 extern struct virtio_user_backend_ops virtio_ops_user; 115 extern struct virtio_user_backend_ops virtio_ops_kernel; 116 extern struct virtio_user_backend_ops virtio_ops_vdpa; 117 118 #endif 119