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 enum vhost_user_request { 48 VHOST_USER_NONE = 0, 49 VHOST_USER_GET_FEATURES = 1, 50 VHOST_USER_SET_FEATURES = 2, 51 VHOST_USER_SET_OWNER = 3, 52 VHOST_USER_RESET_OWNER = 4, 53 VHOST_USER_SET_MEM_TABLE = 5, 54 VHOST_USER_SET_LOG_BASE = 6, 55 VHOST_USER_SET_LOG_FD = 7, 56 VHOST_USER_SET_VRING_NUM = 8, 57 VHOST_USER_SET_VRING_ADDR = 9, 58 VHOST_USER_SET_VRING_BASE = 10, 59 VHOST_USER_GET_VRING_BASE = 11, 60 VHOST_USER_SET_VRING_KICK = 12, 61 VHOST_USER_SET_VRING_CALL = 13, 62 VHOST_USER_SET_VRING_ERR = 14, 63 VHOST_USER_GET_PROTOCOL_FEATURES = 15, 64 VHOST_USER_SET_PROTOCOL_FEATURES = 16, 65 VHOST_USER_GET_QUEUE_NUM = 17, 66 VHOST_USER_SET_VRING_ENABLE = 18, 67 VHOST_USER_MAX 68 }; 69 70 const char * const vhost_msg_strings[VHOST_USER_MAX]; 71 72 struct vhost_memory_region { 73 uint64_t guest_phys_addr; 74 uint64_t memory_size; /* bytes */ 75 uint64_t userspace_addr; 76 uint64_t mmap_offset; 77 }; 78 79 struct virtio_user_dev; 80 81 struct virtio_user_backend_ops { 82 int (*setup)(struct virtio_user_dev *dev); 83 int (*send_request)(struct virtio_user_dev *dev, 84 enum vhost_user_request req, 85 void *arg); 86 int (*enable_qp)(struct virtio_user_dev *dev, 87 uint16_t pair_idx, 88 int enable); 89 }; 90 91 extern struct virtio_user_backend_ops virtio_ops_user; 92 extern struct virtio_user_backend_ops virtio_ops_kernel; 93 94 #endif 95