xref: /qemu/include/hw/virtio/vhost-backend.h (revision 940bb5fa)
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_FRONTEND = 0,
26     VHOST_SET_CONFIG_TYPE_MIGRATION = 1,
27 } VhostSetConfigType;
28 
29 typedef enum VhostDeviceStateDirection {
30     /* Transfer state from back-end (device) to front-end */
31     VHOST_TRANSFER_STATE_DIRECTION_SAVE = 0,
32     /* Transfer state from front-end to back-end (device) */
33     VHOST_TRANSFER_STATE_DIRECTION_LOAD = 1,
34 } VhostDeviceStateDirection;
35 
36 typedef enum VhostDeviceStatePhase {
37     /* The device (and all its vrings) is stopped */
38     VHOST_TRANSFER_STATE_PHASE_STOPPED = 0,
39 } VhostDeviceStatePhase;
40 
41 struct vhost_inflight;
42 struct vhost_dev;
43 struct vhost_log;
44 struct vhost_memory;
45 struct vhost_vring_file;
46 struct vhost_vring_state;
47 struct vhost_vring_addr;
48 struct vhost_scsi_target;
49 struct vhost_iotlb_msg;
50 struct vhost_virtqueue;
51 
52 typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque,
53                                   Error **errp);
54 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
55 typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev);
56 
57 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev,
58                                 struct vhost_vring_file *file);
59 typedef int (*vhost_net_set_mtu_op)(struct vhost_dev *dev, uint16_t mtu);
60 typedef int (*vhost_scsi_set_endpoint_op)(struct vhost_dev *dev,
61                                   struct vhost_scsi_target *target);
62 typedef int (*vhost_scsi_clear_endpoint_op)(struct vhost_dev *dev,
63                                     struct vhost_scsi_target *target);
64 typedef int (*vhost_scsi_get_abi_version_op)(struct vhost_dev *dev,
65                                              int *version);
66 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base,
67                                      struct vhost_log *log);
68 typedef int (*vhost_set_mem_table_op)(struct vhost_dev *dev,
69                                       struct vhost_memory *mem);
70 typedef int (*vhost_set_vring_addr_op)(struct vhost_dev *dev,
71                                        struct vhost_vring_addr *addr);
72 typedef int (*vhost_set_vring_endian_op)(struct vhost_dev *dev,
73                                          struct vhost_vring_state *ring);
74 typedef int (*vhost_set_vring_num_op)(struct vhost_dev *dev,
75                                       struct vhost_vring_state *ring);
76 typedef int (*vhost_set_vring_base_op)(struct vhost_dev *dev,
77                                        struct vhost_vring_state *ring);
78 typedef int (*vhost_get_vring_base_op)(struct vhost_dev *dev,
79                                        struct vhost_vring_state *ring);
80 typedef int (*vhost_set_vring_kick_op)(struct vhost_dev *dev,
81                                        struct vhost_vring_file *file);
82 typedef int (*vhost_set_vring_call_op)(struct vhost_dev *dev,
83                                        struct vhost_vring_file *file);
84 typedef int (*vhost_set_vring_err_op)(struct vhost_dev *dev,
85                                       struct vhost_vring_file *file);
86 typedef int (*vhost_set_vring_busyloop_timeout_op)(struct vhost_dev *dev,
87                                                    struct vhost_vring_state *r);
88 typedef int (*vhost_set_features_op)(struct vhost_dev *dev,
89                                      uint64_t features);
90 typedef int (*vhost_get_features_op)(struct vhost_dev *dev,
91                                      uint64_t *features);
92 typedef int (*vhost_set_backend_cap_op)(struct vhost_dev *dev);
93 typedef int (*vhost_set_owner_op)(struct vhost_dev *dev);
94 typedef int (*vhost_reset_device_op)(struct vhost_dev *dev);
95 typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx);
96 typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev,
97                                          int enable);
98 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev);
99 typedef int (*vhost_migration_done_op)(struct vhost_dev *dev,
100                                        char *mac_addr);
101 typedef int (*vhost_vsock_set_guest_cid_op)(struct vhost_dev *dev,
102                                             uint64_t guest_cid);
103 typedef int (*vhost_vsock_set_running_op)(struct vhost_dev *dev, int start);
104 typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev,
105                                            int enabled);
106 typedef int (*vhost_send_device_iotlb_msg_op)(struct vhost_dev *dev,
107                                               struct vhost_iotlb_msg *imsg);
108 typedef int (*vhost_set_config_op)(struct vhost_dev *dev, const uint8_t *data,
109                                    uint32_t offset, uint32_t size,
110                                    uint32_t flags);
111 typedef int (*vhost_get_config_op)(struct vhost_dev *dev, uint8_t *config,
112                                    uint32_t config_len, Error **errp);
113 
114 typedef int (*vhost_crypto_create_session_op)(struct vhost_dev *dev,
115                                               void *session_info,
116                                               uint64_t *session_id);
117 typedef int (*vhost_crypto_close_session_op)(struct vhost_dev *dev,
118                                              uint64_t session_id);
119 
120 typedef bool (*vhost_backend_no_private_memslots_op)(struct vhost_dev *dev);
121 
122 typedef int (*vhost_get_inflight_fd_op)(struct vhost_dev *dev,
123                                         uint16_t queue_size,
124                                         struct vhost_inflight *inflight);
125 
126 typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev,
127                                         struct vhost_inflight *inflight);
128 
129 typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started);
130 
131 typedef int (*vhost_vq_get_addr_op)(struct vhost_dev *dev,
132                     struct vhost_vring_addr *addr,
133                     struct vhost_virtqueue *vq);
134 
135 typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id);
136 
137 typedef bool (*vhost_force_iommu_op)(struct vhost_dev *dev);
138 
139 typedef int (*vhost_set_config_call_op)(struct vhost_dev *dev,
140                                        int fd);
141 
142 typedef void (*vhost_reset_status_op)(struct vhost_dev *dev);
143 
144 typedef bool (*vhost_supports_device_state_op)(struct vhost_dev *dev);
145 typedef int (*vhost_set_device_state_fd_op)(struct vhost_dev *dev,
146                                             VhostDeviceStateDirection direction,
147                                             VhostDeviceStatePhase phase,
148                                             int fd,
149                                             int *reply_fd,
150                                             Error **errp);
151 typedef int (*vhost_check_device_state_op)(struct vhost_dev *dev, Error **errp);
152 
153 typedef struct VhostOps {
154     VhostBackendType backend_type;
155     vhost_backend_init vhost_backend_init;
156     vhost_backend_cleanup vhost_backend_cleanup;
157     vhost_backend_memslots_limit vhost_backend_memslots_limit;
158     vhost_backend_no_private_memslots_op vhost_backend_no_private_memslots;
159     vhost_net_set_backend_op vhost_net_set_backend;
160     vhost_net_set_mtu_op vhost_net_set_mtu;
161     vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint;
162     vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint;
163     vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version;
164     vhost_set_log_base_op vhost_set_log_base;
165     vhost_set_mem_table_op vhost_set_mem_table;
166     vhost_set_vring_addr_op vhost_set_vring_addr;
167     vhost_set_vring_endian_op vhost_set_vring_endian;
168     vhost_set_vring_num_op vhost_set_vring_num;
169     vhost_set_vring_base_op vhost_set_vring_base;
170     vhost_get_vring_base_op vhost_get_vring_base;
171     vhost_set_vring_kick_op vhost_set_vring_kick;
172     vhost_set_vring_call_op vhost_set_vring_call;
173     vhost_set_vring_err_op vhost_set_vring_err;
174     vhost_set_vring_busyloop_timeout_op vhost_set_vring_busyloop_timeout;
175     vhost_set_features_op vhost_set_features;
176     vhost_get_features_op vhost_get_features;
177     vhost_set_backend_cap_op vhost_set_backend_cap;
178     vhost_set_owner_op vhost_set_owner;
179     vhost_reset_device_op vhost_reset_device;
180     vhost_get_vq_index_op vhost_get_vq_index;
181     vhost_set_vring_enable_op vhost_set_vring_enable;
182     vhost_requires_shm_log_op vhost_requires_shm_log;
183     vhost_migration_done_op vhost_migration_done;
184     vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid;
185     vhost_vsock_set_running_op vhost_vsock_set_running;
186     vhost_set_iotlb_callback_op vhost_set_iotlb_callback;
187     vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg;
188     vhost_get_config_op vhost_get_config;
189     vhost_set_config_op vhost_set_config;
190     vhost_crypto_create_session_op vhost_crypto_create_session;
191     vhost_crypto_close_session_op vhost_crypto_close_session;
192     vhost_get_inflight_fd_op vhost_get_inflight_fd;
193     vhost_set_inflight_fd_op vhost_set_inflight_fd;
194     vhost_dev_start_op vhost_dev_start;
195     vhost_vq_get_addr_op  vhost_vq_get_addr;
196     vhost_get_device_id_op vhost_get_device_id;
197     vhost_force_iommu_op vhost_force_iommu;
198     vhost_set_config_call_op vhost_set_config_call;
199     vhost_reset_status_op vhost_reset_status;
200     vhost_supports_device_state_op vhost_supports_device_state;
201     vhost_set_device_state_fd_op vhost_set_device_state_fd;
202     vhost_check_device_state_op vhost_check_device_state;
203 } VhostOps;
204 
205 int vhost_backend_update_device_iotlb(struct vhost_dev *dev,
206                                              uint64_t iova, uint64_t uaddr,
207                                              uint64_t len,
208                                              IOMMUAccessFlags perm);
209 
210 int vhost_backend_invalidate_device_iotlb(struct vhost_dev *dev,
211                                                  uint64_t iova, uint64_t len);
212 
213 int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev,
214                                           struct vhost_iotlb_msg *imsg);
215 
216 int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd);
217 
218 int vhost_user_get_shared_object(struct vhost_dev *dev, unsigned char *uuid,
219                                         int *dmabuf_fd);
220 
221 #endif /* VHOST_BACKEND_H */
222