xref: /openbmc/qemu/include/hw/virtio/vhost-backend.h (revision f7160f32)
1 /*
2  * vhost-backend
3  *
4  * Copyright (c) 2013 Virtual Open Systems Sarl.
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  *
9  */
10 
11 #ifndef VHOST_BACKEND_H
12 #define VHOST_BACKEND_H
13 
14 #include "exec/memory.h"
15 
16 typedef enum VhostBackendType {
17     VHOST_BACKEND_TYPE_NONE = 0,
18     VHOST_BACKEND_TYPE_KERNEL = 1,
19     VHOST_BACKEND_TYPE_USER = 2,
20     VHOST_BACKEND_TYPE_VDPA = 3,
21     VHOST_BACKEND_TYPE_MAX = 4,
22 } VhostBackendType;
23 
24 typedef enum VhostSetConfigType {
25     VHOST_SET_CONFIG_TYPE_MASTER = 0,
26     VHOST_SET_CONFIG_TYPE_MIGRATION = 1,
27 } VhostSetConfigType;
28 
29 struct vhost_inflight;
30 struct vhost_dev;
31 struct vhost_log;
32 struct vhost_memory;
33 struct vhost_vring_file;
34 struct vhost_vring_state;
35 struct vhost_vring_addr;
36 struct vhost_scsi_target;
37 struct vhost_iotlb_msg;
38 struct vhost_virtqueue;
39 
40 typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque);
41 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
42 typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev);
43 
44 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev,
45                                 struct vhost_vring_file *file);
46 typedef int (*vhost_net_set_mtu_op)(struct vhost_dev *dev, uint16_t mtu);
47 typedef int (*vhost_scsi_set_endpoint_op)(struct vhost_dev *dev,
48                                   struct vhost_scsi_target *target);
49 typedef int (*vhost_scsi_clear_endpoint_op)(struct vhost_dev *dev,
50                                     struct vhost_scsi_target *target);
51 typedef int (*vhost_scsi_get_abi_version_op)(struct vhost_dev *dev,
52                                              int *version);
53 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base,
54                                      struct vhost_log *log);
55 typedef int (*vhost_set_mem_table_op)(struct vhost_dev *dev,
56                                       struct vhost_memory *mem);
57 typedef int (*vhost_set_vring_addr_op)(struct vhost_dev *dev,
58                                        struct vhost_vring_addr *addr);
59 typedef int (*vhost_set_vring_endian_op)(struct vhost_dev *dev,
60                                          struct vhost_vring_state *ring);
61 typedef int (*vhost_set_vring_num_op)(struct vhost_dev *dev,
62                                       struct vhost_vring_state *ring);
63 typedef int (*vhost_set_vring_base_op)(struct vhost_dev *dev,
64                                        struct vhost_vring_state *ring);
65 typedef int (*vhost_get_vring_base_op)(struct vhost_dev *dev,
66                                        struct vhost_vring_state *ring);
67 typedef int (*vhost_set_vring_kick_op)(struct vhost_dev *dev,
68                                        struct vhost_vring_file *file);
69 typedef int (*vhost_set_vring_call_op)(struct vhost_dev *dev,
70                                        struct vhost_vring_file *file);
71 typedef int (*vhost_set_vring_busyloop_timeout_op)(struct vhost_dev *dev,
72                                                    struct vhost_vring_state *r);
73 typedef int (*vhost_set_features_op)(struct vhost_dev *dev,
74                                      uint64_t features);
75 typedef int (*vhost_get_features_op)(struct vhost_dev *dev,
76                                      uint64_t *features);
77 typedef int (*vhost_set_owner_op)(struct vhost_dev *dev);
78 typedef int (*vhost_reset_device_op)(struct vhost_dev *dev);
79 typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx);
80 typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev,
81                                          int enable);
82 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev);
83 typedef int (*vhost_migration_done_op)(struct vhost_dev *dev,
84                                        char *mac_addr);
85 typedef bool (*vhost_backend_can_merge_op)(struct vhost_dev *dev,
86                                            uint64_t start1, uint64_t size1,
87                                            uint64_t start2, uint64_t size2);
88 typedef int (*vhost_vsock_set_guest_cid_op)(struct vhost_dev *dev,
89                                             uint64_t guest_cid);
90 typedef int (*vhost_vsock_set_running_op)(struct vhost_dev *dev, int start);
91 typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev,
92                                            int enabled);
93 typedef int (*vhost_send_device_iotlb_msg_op)(struct vhost_dev *dev,
94                                               struct vhost_iotlb_msg *imsg);
95 typedef int (*vhost_set_config_op)(struct vhost_dev *dev, const uint8_t *data,
96                                    uint32_t offset, uint32_t size,
97                                    uint32_t flags);
98 typedef int (*vhost_get_config_op)(struct vhost_dev *dev, uint8_t *config,
99                                    uint32_t config_len);
100 
101 typedef int (*vhost_crypto_create_session_op)(struct vhost_dev *dev,
102                                               void *session_info,
103                                               uint64_t *session_id);
104 typedef int (*vhost_crypto_close_session_op)(struct vhost_dev *dev,
105                                              uint64_t session_id);
106 
107 typedef bool (*vhost_backend_mem_section_filter_op)(struct vhost_dev *dev,
108                                                 MemoryRegionSection *section);
109 
110 typedef int (*vhost_get_inflight_fd_op)(struct vhost_dev *dev,
111                                         uint16_t queue_size,
112                                         struct vhost_inflight *inflight);
113 
114 typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev,
115                                         struct vhost_inflight *inflight);
116 
117 typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started);
118 
119 typedef int (*vhost_vq_get_addr_op)(struct vhost_dev *dev,
120                     struct vhost_vring_addr *addr,
121                     struct vhost_virtqueue *vq);
122 
123 typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id);
124 
125 typedef bool (*vhost_force_iommu_op)(struct vhost_dev *dev);
126 
127 typedef struct VhostOps {
128     VhostBackendType backend_type;
129     vhost_backend_init vhost_backend_init;
130     vhost_backend_cleanup vhost_backend_cleanup;
131     vhost_backend_memslots_limit vhost_backend_memslots_limit;
132     vhost_net_set_backend_op vhost_net_set_backend;
133     vhost_net_set_mtu_op vhost_net_set_mtu;
134     vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint;
135     vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint;
136     vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version;
137     vhost_set_log_base_op vhost_set_log_base;
138     vhost_set_mem_table_op vhost_set_mem_table;
139     vhost_set_vring_addr_op vhost_set_vring_addr;
140     vhost_set_vring_endian_op vhost_set_vring_endian;
141     vhost_set_vring_num_op vhost_set_vring_num;
142     vhost_set_vring_base_op vhost_set_vring_base;
143     vhost_get_vring_base_op vhost_get_vring_base;
144     vhost_set_vring_kick_op vhost_set_vring_kick;
145     vhost_set_vring_call_op vhost_set_vring_call;
146     vhost_set_vring_busyloop_timeout_op vhost_set_vring_busyloop_timeout;
147     vhost_set_features_op vhost_set_features;
148     vhost_get_features_op vhost_get_features;
149     vhost_set_owner_op vhost_set_owner;
150     vhost_reset_device_op vhost_reset_device;
151     vhost_get_vq_index_op vhost_get_vq_index;
152     vhost_set_vring_enable_op vhost_set_vring_enable;
153     vhost_requires_shm_log_op vhost_requires_shm_log;
154     vhost_migration_done_op vhost_migration_done;
155     vhost_backend_can_merge_op vhost_backend_can_merge;
156     vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid;
157     vhost_vsock_set_running_op vhost_vsock_set_running;
158     vhost_set_iotlb_callback_op vhost_set_iotlb_callback;
159     vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg;
160     vhost_get_config_op vhost_get_config;
161     vhost_set_config_op vhost_set_config;
162     vhost_crypto_create_session_op vhost_crypto_create_session;
163     vhost_crypto_close_session_op vhost_crypto_close_session;
164     vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter;
165     vhost_get_inflight_fd_op vhost_get_inflight_fd;
166     vhost_set_inflight_fd_op vhost_set_inflight_fd;
167     vhost_dev_start_op vhost_dev_start;
168     vhost_vq_get_addr_op  vhost_vq_get_addr;
169     vhost_get_device_id_op vhost_get_device_id;
170     vhost_force_iommu_op vhost_force_iommu;
171 } VhostOps;
172 
173 extern const VhostOps user_ops;
174 extern const VhostOps vdpa_ops;
175 
176 int vhost_set_backend_type(struct vhost_dev *dev,
177                            VhostBackendType backend_type);
178 
179 int vhost_backend_update_device_iotlb(struct vhost_dev *dev,
180                                              uint64_t iova, uint64_t uaddr,
181                                              uint64_t len,
182                                              IOMMUAccessFlags perm);
183 
184 int vhost_backend_invalidate_device_iotlb(struct vhost_dev *dev,
185                                                  uint64_t iova, uint64_t len);
186 
187 int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev,
188                                           struct vhost_iotlb_msg *imsg);
189 
190 int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd);
191 
192 #endif /* VHOST_BACKEND_H */
193