1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
5 #ifndef _VIRTIO_USER_VHOST_H
6 #define _VIRTIO_USER_VHOST_H
9 #include <linux/types.h>
10 #include <linux/ioctl.h>
12 #include <rte_errno.h>
14 #include "../virtio.h"
15 #include "../virtio_logs.h"
16 #include "../virtqueue.h"
18 struct vhost_vring_state {
23 struct vhost_vring_file {
28 struct vhost_vring_addr {
33 /* Whether log address is valid. If set enables logging. */
34 #define VHOST_VRING_F_LOG 0
36 /* Start of array of descriptors (virtually contiguous) */
37 uint64_t desc_user_addr;
38 /* Used structure address. Must be 32 bit aligned */
39 uint64_t used_user_addr;
40 /* Available structure address. Must be 16 bit aligned */
41 uint64_t avail_user_addr;
42 /* Logging support. */
43 /* Log writes to used structure, at offset calculated from specified
44 * address. Address must be 32 bit aligned.
46 uint64_t log_guest_addr;
49 #ifndef VHOST_USER_F_PROTOCOL_FEATURES
50 #define VHOST_USER_F_PROTOCOL_FEATURES 30
53 /** Protocol features. */
54 #ifndef VHOST_USER_PROTOCOL_F_MQ
55 #define VHOST_USER_PROTOCOL_F_MQ 0
58 #ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK
59 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
62 #ifndef VHOST_USER_PROTOCOL_F_STATUS
63 #define VHOST_USER_PROTOCOL_F_STATUS 16
66 enum vhost_user_request {
68 VHOST_USER_GET_FEATURES = 1,
69 VHOST_USER_SET_FEATURES = 2,
70 VHOST_USER_SET_OWNER = 3,
71 VHOST_USER_RESET_OWNER = 4,
72 VHOST_USER_SET_MEM_TABLE = 5,
73 VHOST_USER_SET_LOG_BASE = 6,
74 VHOST_USER_SET_LOG_FD = 7,
75 VHOST_USER_SET_VRING_NUM = 8,
76 VHOST_USER_SET_VRING_ADDR = 9,
77 VHOST_USER_SET_VRING_BASE = 10,
78 VHOST_USER_GET_VRING_BASE = 11,
79 VHOST_USER_SET_VRING_KICK = 12,
80 VHOST_USER_SET_VRING_CALL = 13,
81 VHOST_USER_SET_VRING_ERR = 14,
82 VHOST_USER_GET_PROTOCOL_FEATURES = 15,
83 VHOST_USER_SET_PROTOCOL_FEATURES = 16,
84 VHOST_USER_GET_QUEUE_NUM = 17,
85 VHOST_USER_SET_VRING_ENABLE = 18,
86 VHOST_USER_SET_STATUS = 39,
87 VHOST_USER_GET_STATUS = 40,
91 #ifndef VHOST_BACKEND_F_IOTLB_MSG_V2
92 #define VHOST_BACKEND_F_IOTLB_MSG_V2 1
95 #ifndef VHOST_BACKEND_F_IOTLB_BATCH
96 #define VHOST_BACKEND_F_IOTLB_BATCH 2
99 extern const char * const vhost_msg_strings[VHOST_USER_MAX];
101 struct vhost_memory_region {
102 uint64_t guest_phys_addr;
103 uint64_t memory_size; /* bytes */
104 uint64_t userspace_addr;
105 uint64_t mmap_offset;
108 struct virtio_user_dev;
110 struct virtio_user_backend_ops {
111 int (*setup)(struct virtio_user_dev *dev);
112 int (*set_owner)(struct virtio_user_dev *dev);
113 int (*get_features)(struct virtio_user_dev *dev, uint64_t *features);
114 int (*set_features)(struct virtio_user_dev *dev, uint64_t features);
115 int (*get_protocol_features)(struct virtio_user_dev *dev, uint64_t *features);
116 int (*set_protocol_features)(struct virtio_user_dev *dev, uint64_t features);
117 int (*set_memory_table)(struct virtio_user_dev *dev);
118 int (*set_vring_num)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
119 int (*set_vring_base)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
120 int (*get_vring_base)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
121 int (*send_request)(struct virtio_user_dev *dev,
122 enum vhost_user_request req,
124 int (*enable_qp)(struct virtio_user_dev *dev,
127 int (*dma_map)(struct virtio_user_dev *dev, void *addr,
128 uint64_t iova, size_t len);
129 int (*dma_unmap)(struct virtio_user_dev *dev, void *addr,
130 uint64_t iova, size_t len);
133 extern struct virtio_user_backend_ops virtio_ops_user;
134 extern struct virtio_user_backend_ops virtio_ops_kernel;
135 extern struct virtio_user_backend_ops virtio_ops_vdpa;