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 "../virtio_pci.h"
13 #include "../virtio_logs.h"
14 #include "../virtqueue.h"
16 struct vhost_vring_state {
21 struct vhost_vring_file {
26 struct vhost_vring_addr {
31 /* Whether log address is valid. If set enables logging. */
32 #define VHOST_VRING_F_LOG 0
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.
44 uint64_t log_guest_addr;
47 #ifndef VHOST_USER_F_PROTOCOL_FEATURES
48 #define VHOST_USER_F_PROTOCOL_FEATURES 30
51 /** Protocol features. */
52 #ifndef VHOST_USER_PROTOCOL_F_MQ
53 #define VHOST_USER_PROTOCOL_F_MQ 0
56 #ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK
57 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
60 #ifndef VHOST_USER_PROTOCOL_F_STATUS
61 #define VHOST_USER_PROTOCOL_F_STATUS 16
64 enum vhost_user_request {
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,
89 extern const char * const vhost_msg_strings[VHOST_USER_MAX];
91 struct vhost_memory_region {
92 uint64_t guest_phys_addr;
93 uint64_t memory_size; /* bytes */
94 uint64_t userspace_addr;
98 struct virtio_user_dev;
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,
105 int (*enable_qp)(struct virtio_user_dev *dev,
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);
114 extern struct virtio_user_backend_ops virtio_ops_user;
115 extern struct virtio_user_backend_ops virtio_ops_kernel;