4 * Copyright (c) 2013 Virtual Open Systems Sarl.
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.
11 #ifndef VHOST_BACKEND_H
12 #define VHOST_BACKEND_H
14 #include "exec/memory.h"
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,
24 typedef enum VhostSetConfigType
{
25 VHOST_SET_CONFIG_TYPE_FRONTEND
= 0,
26 VHOST_SET_CONFIG_TYPE_MIGRATION
= 1,
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
;
36 typedef enum VhostDeviceStatePhase
{
37 /* The device (and all its vrings) is stopped */
38 VHOST_TRANSFER_STATE_PHASE_STOPPED
= 0,
39 } VhostDeviceStatePhase
;
41 struct vhost_inflight
;
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
;
54 typedef int (*vhost_backend_init
)(struct vhost_dev
*dev
, void *opaque
,
56 typedef int (*vhost_backend_cleanup
)(struct vhost_dev
*dev
);
57 typedef int (*vhost_backend_memslots_limit
)(struct vhost_dev
*dev
);
59 typedef int (*vhost_net_set_backend_op
)(struct vhost_dev
*dev
,
60 struct vhost_vring_file
*file
);
61 typedef int (*vhost_net_set_mtu_op
)(struct vhost_dev
*dev
, uint16_t mtu
);
62 typedef int (*vhost_scsi_set_endpoint_op
)(struct vhost_dev
*dev
,
63 struct vhost_scsi_target
*target
);
64 typedef int (*vhost_scsi_clear_endpoint_op
)(struct vhost_dev
*dev
,
65 struct vhost_scsi_target
*target
);
66 typedef int (*vhost_scsi_get_abi_version_op
)(struct vhost_dev
*dev
,
68 typedef int (*vhost_set_log_base_op
)(struct vhost_dev
*dev
, uint64_t base
,
69 struct vhost_log
*log
);
70 typedef int (*vhost_set_mem_table_op
)(struct vhost_dev
*dev
,
71 struct vhost_memory
*mem
);
72 typedef int (*vhost_set_vring_addr_op
)(struct vhost_dev
*dev
,
73 struct vhost_vring_addr
*addr
);
74 typedef int (*vhost_set_vring_endian_op
)(struct vhost_dev
*dev
,
75 struct vhost_vring_state
*ring
);
76 typedef int (*vhost_set_vring_num_op
)(struct vhost_dev
*dev
,
77 struct vhost_vring_state
*ring
);
78 typedef int (*vhost_set_vring_base_op
)(struct vhost_dev
*dev
,
79 struct vhost_vring_state
*ring
);
80 typedef int (*vhost_get_vring_base_op
)(struct vhost_dev
*dev
,
81 struct vhost_vring_state
*ring
);
82 typedef int (*vhost_set_vring_kick_op
)(struct vhost_dev
*dev
,
83 struct vhost_vring_file
*file
);
84 typedef int (*vhost_set_vring_call_op
)(struct vhost_dev
*dev
,
85 struct vhost_vring_file
*file
);
86 typedef int (*vhost_set_vring_err_op
)(struct vhost_dev
*dev
,
87 struct vhost_vring_file
*file
);
88 typedef int (*vhost_set_vring_busyloop_timeout_op
)(struct vhost_dev
*dev
,
89 struct vhost_vring_state
*r
);
90 typedef int (*vhost_attach_vring_worker_op
)(struct vhost_dev
*dev
,
91 struct vhost_vring_worker
*worker
);
92 typedef int (*vhost_get_vring_worker_op
)(struct vhost_dev
*dev
,
93 struct vhost_vring_worker
*worker
);
94 typedef int (*vhost_new_worker_op
)(struct vhost_dev
*dev
,
95 struct vhost_worker_state
*worker
);
96 typedef int (*vhost_free_worker_op
)(struct vhost_dev
*dev
,
97 struct vhost_worker_state
*worker
);
98 typedef int (*vhost_set_features_op
)(struct vhost_dev
*dev
,
100 typedef int (*vhost_get_features_op
)(struct vhost_dev
*dev
,
102 typedef int (*vhost_set_backend_cap_op
)(struct vhost_dev
*dev
);
103 typedef int (*vhost_set_owner_op
)(struct vhost_dev
*dev
);
104 typedef int (*vhost_reset_device_op
)(struct vhost_dev
*dev
);
105 typedef int (*vhost_get_vq_index_op
)(struct vhost_dev
*dev
, int idx
);
106 typedef int (*vhost_set_vring_enable_op
)(struct vhost_dev
*dev
,
108 typedef bool (*vhost_requires_shm_log_op
)(struct vhost_dev
*dev
);
109 typedef int (*vhost_migration_done_op
)(struct vhost_dev
*dev
,
111 typedef int (*vhost_vsock_set_guest_cid_op
)(struct vhost_dev
*dev
,
113 typedef int (*vhost_vsock_set_running_op
)(struct vhost_dev
*dev
, int start
);
114 typedef void (*vhost_set_iotlb_callback_op
)(struct vhost_dev
*dev
,
116 typedef int (*vhost_send_device_iotlb_msg_op
)(struct vhost_dev
*dev
,
117 struct vhost_iotlb_msg
*imsg
);
118 typedef int (*vhost_set_config_op
)(struct vhost_dev
*dev
, const uint8_t *data
,
119 uint32_t offset
, uint32_t size
,
121 typedef int (*vhost_get_config_op
)(struct vhost_dev
*dev
, uint8_t *config
,
122 uint32_t config_len
, Error
**errp
);
124 typedef int (*vhost_crypto_create_session_op
)(struct vhost_dev
*dev
,
126 uint64_t *session_id
);
127 typedef int (*vhost_crypto_close_session_op
)(struct vhost_dev
*dev
,
128 uint64_t session_id
);
130 typedef bool (*vhost_backend_no_private_memslots_op
)(struct vhost_dev
*dev
);
132 typedef int (*vhost_get_inflight_fd_op
)(struct vhost_dev
*dev
,
134 struct vhost_inflight
*inflight
);
136 typedef int (*vhost_set_inflight_fd_op
)(struct vhost_dev
*dev
,
137 struct vhost_inflight
*inflight
);
139 typedef int (*vhost_dev_start_op
)(struct vhost_dev
*dev
, bool started
);
141 typedef int (*vhost_vq_get_addr_op
)(struct vhost_dev
*dev
,
142 struct vhost_vring_addr
*addr
,
143 struct vhost_virtqueue
*vq
);
145 typedef int (*vhost_get_device_id_op
)(struct vhost_dev
*dev
, uint32_t *dev_id
);
147 typedef bool (*vhost_force_iommu_op
)(struct vhost_dev
*dev
);
149 typedef int (*vhost_set_config_call_op
)(struct vhost_dev
*dev
,
152 typedef void (*vhost_reset_status_op
)(struct vhost_dev
*dev
);
154 typedef bool (*vhost_supports_device_state_op
)(struct vhost_dev
*dev
);
155 typedef int (*vhost_set_device_state_fd_op
)(struct vhost_dev
*dev
,
156 VhostDeviceStateDirection direction
,
157 VhostDeviceStatePhase phase
,
161 typedef int (*vhost_check_device_state_op
)(struct vhost_dev
*dev
, Error
**errp
);
163 typedef struct VhostOps
{
164 VhostBackendType backend_type
;
165 vhost_backend_init vhost_backend_init
;
166 vhost_backend_cleanup vhost_backend_cleanup
;
167 vhost_backend_memslots_limit vhost_backend_memslots_limit
;
168 vhost_backend_no_private_memslots_op vhost_backend_no_private_memslots
;
169 vhost_net_set_backend_op vhost_net_set_backend
;
170 vhost_net_set_mtu_op vhost_net_set_mtu
;
171 vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint
;
172 vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint
;
173 vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version
;
174 vhost_set_log_base_op vhost_set_log_base
;
175 vhost_set_mem_table_op vhost_set_mem_table
;
176 vhost_set_vring_addr_op vhost_set_vring_addr
;
177 vhost_set_vring_endian_op vhost_set_vring_endian
;
178 vhost_set_vring_num_op vhost_set_vring_num
;
179 vhost_set_vring_base_op vhost_set_vring_base
;
180 vhost_get_vring_base_op vhost_get_vring_base
;
181 vhost_set_vring_kick_op vhost_set_vring_kick
;
182 vhost_set_vring_call_op vhost_set_vring_call
;
183 vhost_set_vring_err_op vhost_set_vring_err
;
184 vhost_set_vring_busyloop_timeout_op vhost_set_vring_busyloop_timeout
;
185 vhost_new_worker_op vhost_new_worker
;
186 vhost_free_worker_op vhost_free_worker
;
187 vhost_get_vring_worker_op vhost_get_vring_worker
;
188 vhost_attach_vring_worker_op vhost_attach_vring_worker
;
189 vhost_set_features_op vhost_set_features
;
190 vhost_get_features_op vhost_get_features
;
191 vhost_set_backend_cap_op vhost_set_backend_cap
;
192 vhost_set_owner_op vhost_set_owner
;
193 vhost_reset_device_op vhost_reset_device
;
194 vhost_get_vq_index_op vhost_get_vq_index
;
195 vhost_set_vring_enable_op vhost_set_vring_enable
;
196 vhost_requires_shm_log_op vhost_requires_shm_log
;
197 vhost_migration_done_op vhost_migration_done
;
198 vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid
;
199 vhost_vsock_set_running_op vhost_vsock_set_running
;
200 vhost_set_iotlb_callback_op vhost_set_iotlb_callback
;
201 vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg
;
202 vhost_get_config_op vhost_get_config
;
203 vhost_set_config_op vhost_set_config
;
204 vhost_crypto_create_session_op vhost_crypto_create_session
;
205 vhost_crypto_close_session_op vhost_crypto_close_session
;
206 vhost_get_inflight_fd_op vhost_get_inflight_fd
;
207 vhost_set_inflight_fd_op vhost_set_inflight_fd
;
208 vhost_dev_start_op vhost_dev_start
;
209 vhost_vq_get_addr_op vhost_vq_get_addr
;
210 vhost_get_device_id_op vhost_get_device_id
;
211 vhost_force_iommu_op vhost_force_iommu
;
212 vhost_set_config_call_op vhost_set_config_call
;
213 vhost_reset_status_op vhost_reset_status
;
214 vhost_supports_device_state_op vhost_supports_device_state
;
215 vhost_set_device_state_fd_op vhost_set_device_state_fd
;
216 vhost_check_device_state_op vhost_check_device_state
;
219 int vhost_backend_update_device_iotlb(struct vhost_dev
*dev
,
220 uint64_t iova
, uint64_t uaddr
,
222 IOMMUAccessFlags perm
);
224 int vhost_backend_invalidate_device_iotlb(struct vhost_dev
*dev
,
225 uint64_t iova
, uint64_t len
);
227 int vhost_backend_handle_iotlb_msg(struct vhost_dev
*dev
,
228 struct vhost_iotlb_msg
*imsg
);
230 int vhost_user_gpu_set_socket(struct vhost_dev
*dev
, int fd
);
232 int vhost_user_get_shared_object(struct vhost_dev
*dev
, unsigned char *uuid
,
235 #endif /* VHOST_BACKEND_H */