master
h 240 lines 11.1 KB
Raw
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 "system/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_vring_worker;
49 struct vhost_worker_state;
50 struct vhost_scsi_target;
51 struct vhost_iotlb_msg;
52 struct vhost_virtqueue;
53
54 typedef int (*vhost_init)(struct vhost_dev *dev, void *opaque, Error **errp);
55 typedef int (*vhost_cleanup)(struct vhost_dev *dev);
56 typedef int (*vhost_memslots_limit)(struct vhost_dev *dev);
57
58 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev,
59 struct vhost_vring_file *file);
60 typedef int (*vhost_net_set_mtu_op)(struct vhost_dev *dev, uint16_t mtu);
61 typedef int (*vhost_scsi_set_endpoint_op)(struct vhost_dev *dev,
62 struct vhost_scsi_target *target);
63 typedef int (*vhost_scsi_clear_endpoint_op)(struct vhost_dev *dev,
64 struct vhost_scsi_target *target);
65 typedef int (*vhost_scsi_get_abi_version_op)(struct vhost_dev *dev,
66 int *version);
67 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base,
68 struct vhost_log *log);
69 typedef int (*vhost_set_mem_table_op)(struct vhost_dev *dev,
70 struct vhost_memory *mem);
71 typedef int (*vhost_set_vring_addr_op)(struct vhost_dev *dev,
72 struct vhost_vring_addr *addr);
73 typedef int (*vhost_set_vring_endian_op)(struct vhost_dev *dev,
74 struct vhost_vring_state *ring);
75 typedef int (*vhost_set_vring_num_op)(struct vhost_dev *dev,
76 struct vhost_vring_state *ring);
77 typedef int (*vhost_set_vring_base_op)(struct vhost_dev *dev,
78 struct vhost_vring_state *ring);
79 typedef int (*vhost_get_vring_base_op)(struct vhost_dev *dev,
80 struct vhost_vring_state *ring);
81 typedef int (*vhost_set_vring_kick_op)(struct vhost_dev *dev,
82 struct vhost_vring_file *file);
83 typedef int (*vhost_set_vring_call_op)(struct vhost_dev *dev,
84 struct vhost_vring_file *file);
85 typedef int (*vhost_set_vring_err_op)(struct vhost_dev *dev,
86 struct vhost_vring_file *file);
87 typedef int (*vhost_set_vring_busyloop_timeout_op)(struct vhost_dev *dev,
88 struct vhost_vring_state *r);
89 typedef int (*vhost_attach_vring_worker_op)(struct vhost_dev *dev,
90 struct vhost_vring_worker *worker);
91 typedef int (*vhost_get_vring_worker_op)(struct vhost_dev *dev,
92 struct vhost_vring_worker *worker);
93 typedef int (*vhost_new_worker_op)(struct vhost_dev *dev,
94 struct vhost_worker_state *worker);
95 typedef int (*vhost_free_worker_op)(struct vhost_dev *dev,
96 struct vhost_worker_state *worker);
97 typedef int (*vhost_set_features_ex_op)(struct vhost_dev *dev,
98 const uint64_t *features);
99 typedef int (*vhost_get_features_ex_op)(struct vhost_dev *dev,
100 uint64_t *features);
101 typedef int (*vhost_set_features_op)(struct vhost_dev *dev,
102 uint64_t features);
103 typedef int (*vhost_get_features_op)(struct vhost_dev *dev,
104 uint64_t *features);
105 typedef int (*vhost_set_backend_cap_op)(struct vhost_dev *dev);
106 typedef int (*vhost_set_owner_op)(struct vhost_dev *dev);
107 typedef int (*vhost_reset_device_op)(struct vhost_dev *dev);
108 typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx);
109 typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev,
110 int enable);
111 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev);
112 typedef int (*vhost_migration_done_op)(struct vhost_dev *dev,
113 char *mac_addr);
114 typedef int (*vhost_vsock_set_guest_cid_op)(struct vhost_dev *dev,
115 uint64_t guest_cid);
116 typedef int (*vhost_vsock_set_running_op)(struct vhost_dev *dev, int start);
117 typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev,
118 int enabled);
119 typedef int (*vhost_send_device_iotlb_msg_op)(struct vhost_dev *dev,
120 struct vhost_iotlb_msg *imsg);
121 typedef int (*vhost_set_config_op)(struct vhost_dev *dev, const uint8_t *data,
122 uint32_t offset, uint32_t size,
123 uint32_t flags);
124 typedef int (*vhost_get_config_op)(struct vhost_dev *dev, uint8_t *config,
125 uint32_t config_len, Error **errp);
126
127 typedef int (*vhost_crypto_create_session_op)(struct vhost_dev *dev,
128 void *session_info,
129 uint64_t *session_id);
130 typedef int (*vhost_crypto_close_session_op)(struct vhost_dev *dev,
131 uint64_t session_id);
132
133 typedef bool (*vhost_no_private_memslots_op)(struct vhost_dev *dev);
134
135 typedef int (*vhost_get_inflight_fd_op)(struct vhost_dev *dev,
136 uint16_t queue_size,
137 struct vhost_inflight *inflight);
138
139 typedef int (*vhost_set_inflight_fd_op)(struct vhost_dev *dev,
140 struct vhost_inflight *inflight);
141
142 typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started);
143
144 typedef bool (*vhost_phys_vring_addr_op)(struct vhost_dev *dev);
145
146 typedef bool (*vhost_phys_iotlb_msg_op)(struct vhost_dev *dev);
147
148 typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id);
149
150 typedef bool (*vhost_force_iommu_op)(struct vhost_dev *dev);
151
152 typedef int (*vhost_set_config_call_op)(struct vhost_dev *dev,
153 int fd);
154
155 typedef void (*vhost_reset_status_op)(struct vhost_dev *dev);
156
157 typedef bool (*vhost_supports_device_state_op)(struct vhost_dev *dev);
158 typedef int (*vhost_set_device_state_fd_op)(struct vhost_dev *dev,
159 VhostDeviceStateDirection direction,
160 VhostDeviceStatePhase phase,
161 int fd,
162 int *reply_fd,
163 Error **errp);
164 typedef int (*vhost_check_device_state_op)(struct vhost_dev *dev, Error **errp);
165 /*
166 * Max regions is VIRTIO_MAX_SHMEM_REGIONS, so that is the maximum
167 * number of memory_sizes that will be accepted.
168 */
169 typedef int (*vhost_get_shmem_config_op)(struct vhost_dev *dev,
170 int *nregions,
171 uint64_t *memory_sizes,
172 Error **errp);
173
174
175 typedef struct VhostOps {
176 VhostBackendType backend_type;
177 vhost_init vhost_init;
178 vhost_cleanup vhost_cleanup;
179 vhost_memslots_limit vhost_memslots_limit;
180 vhost_no_private_memslots_op vhost_no_private_memslots;
181 vhost_net_set_backend_op vhost_net_set_backend;
182 vhost_net_set_mtu_op vhost_net_set_mtu;
183 vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint;
184 vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint;
185 vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version;
186 vhost_set_log_base_op vhost_set_log_base;
187 vhost_set_mem_table_op vhost_set_mem_table;
188 vhost_set_vring_addr_op vhost_set_vring_addr;
189 vhost_set_vring_endian_op vhost_set_vring_endian;
190 vhost_set_vring_num_op vhost_set_vring_num;
191 vhost_set_vring_base_op vhost_set_vring_base;
192 vhost_get_vring_base_op vhost_get_vring_base;
193 vhost_set_vring_kick_op vhost_set_vring_kick;
194 vhost_set_vring_call_op vhost_set_vring_call;
195 vhost_set_vring_err_op vhost_set_vring_err;
196 vhost_set_vring_busyloop_timeout_op vhost_set_vring_busyloop_timeout;
197 vhost_new_worker_op vhost_new_worker;
198 vhost_free_worker_op vhost_free_worker;
199 vhost_get_vring_worker_op vhost_get_vring_worker;
200 vhost_attach_vring_worker_op vhost_attach_vring_worker;
201 vhost_set_features_ex_op vhost_set_features_ex;
202 vhost_get_features_ex_op vhost_get_features_ex;
203 vhost_set_features_op vhost_set_features;
204 vhost_get_features_op vhost_get_features;
205 vhost_set_backend_cap_op vhost_set_backend_cap;
206 vhost_set_owner_op vhost_set_owner;
207 vhost_reset_device_op vhost_reset_device;
208 vhost_get_vq_index_op vhost_get_vq_index;
209 vhost_set_vring_enable_op vhost_set_vring_enable;
210 vhost_requires_shm_log_op vhost_requires_shm_log;
211 vhost_migration_done_op vhost_migration_done;
212 vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid;
213 vhost_vsock_set_running_op vhost_vsock_set_running;
214 vhost_set_iotlb_callback_op vhost_set_iotlb_callback;
215 vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg;
216 vhost_get_config_op vhost_get_config;
217 vhost_set_config_op vhost_set_config;
218 vhost_crypto_create_session_op vhost_crypto_create_session;
219 vhost_crypto_close_session_op vhost_crypto_close_session;
220 vhost_get_inflight_fd_op vhost_get_inflight_fd;
221 vhost_set_inflight_fd_op vhost_set_inflight_fd;
222 vhost_dev_start_op vhost_dev_start;
223 vhost_phys_vring_addr_op vhost_phys_vring_addr;
224 vhost_phys_iotlb_msg_op vhost_phys_iotlb_msg;
225 vhost_get_device_id_op vhost_get_device_id;
226 vhost_force_iommu_op vhost_force_iommu;
227 vhost_set_config_call_op vhost_set_config_call;
228 vhost_reset_status_op vhost_reset_status;
229 vhost_supports_device_state_op vhost_supports_device_state;
230 vhost_set_device_state_fd_op vhost_set_device_state_fd;
231 vhost_check_device_state_op vhost_check_device_state;
232 vhost_get_shmem_config_op vhost_get_shmem_config;
233 } VhostOps;
234
235 int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd);
236
237 int vhost_user_get_shared_object(struct vhost_dev *dev, unsigned char *uuid,
238 int *dmabuf_fd);
239
240 #endif /* VHOST_BACKEND_H */