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 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 Error **errp); 42 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); 43 typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev); 44 45 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev, 46 struct vhost_vring_file *file); 47 typedef int (*vhost_net_set_mtu_op)(struct vhost_dev *dev, uint16_t mtu); 48 typedef int (*vhost_scsi_set_endpoint_op)(struct vhost_dev *dev, 49 struct vhost_scsi_target *target); 50 typedef int (*vhost_scsi_clear_endpoint_op)(struct vhost_dev *dev, 51 struct vhost_scsi_target *target); 52 typedef int (*vhost_scsi_get_abi_version_op)(struct vhost_dev *dev, 53 int *version); 54 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base, 55 struct vhost_log *log); 56 typedef int (*vhost_set_mem_table_op)(struct vhost_dev *dev, 57 struct vhost_memory *mem); 58 typedef int (*vhost_set_vring_addr_op)(struct vhost_dev *dev, 59 struct vhost_vring_addr *addr); 60 typedef int (*vhost_set_vring_endian_op)(struct vhost_dev *dev, 61 struct vhost_vring_state *ring); 62 typedef int (*vhost_set_vring_num_op)(struct vhost_dev *dev, 63 struct vhost_vring_state *ring); 64 typedef int (*vhost_set_vring_base_op)(struct vhost_dev *dev, 65 struct vhost_vring_state *ring); 66 typedef int (*vhost_get_vring_base_op)(struct vhost_dev *dev, 67 struct vhost_vring_state *ring); 68 typedef int (*vhost_set_vring_kick_op)(struct vhost_dev *dev, 69 struct vhost_vring_file *file); 70 typedef int (*vhost_set_vring_call_op)(struct vhost_dev *dev, 71 struct vhost_vring_file *file); 72 typedef int (*vhost_set_vring_err_op)(struct vhost_dev *dev, 73 struct vhost_vring_file *file); 74 typedef int (*vhost_set_vring_busyloop_timeout_op)(struct vhost_dev *dev, 75 struct vhost_vring_state *r); 76 typedef int (*vhost_set_features_op)(struct vhost_dev *dev, 77 uint64_t features); 78 typedef int (*vhost_get_features_op)(struct vhost_dev *dev, 79 uint64_t *features); 80 typedef int (*vhost_set_backend_cap_op)(struct vhost_dev *dev); 81 typedef int (*vhost_set_owner_op)(struct vhost_dev *dev); 82 typedef int (*vhost_reset_device_op)(struct vhost_dev *dev); 83 typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx); 84 typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev, 85 int enable); 86 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev); 87 typedef int (*vhost_migration_done_op)(struct vhost_dev *dev, 88 char *mac_addr); 89 typedef int (*vhost_vsock_set_guest_cid_op)(struct vhost_dev *dev, 90 uint64_t guest_cid); 91 typedef int (*vhost_vsock_set_running_op)(struct vhost_dev *dev, int start); 92 typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev, 93 int enabled); 94 typedef int (*vhost_send_device_iotlb_msg_op)(struct vhost_dev *dev, 95 struct vhost_iotlb_msg *imsg); 96 typedef int (*vhost_set_config_op)(struct vhost_dev *dev, const uint8_t *data, 97 uint32_t offset, uint32_t size, 98 uint32_t flags); 99 typedef int (*vhost_get_config_op)(struct vhost_dev *dev, uint8_t *config, 100 uint32_t config_len, Error **errp); 101 102 typedef int (*vhost_crypto_create_session_op)(struct vhost_dev *dev, 103 void *session_info, 104 uint64_t *session_id); 105 typedef int (*vhost_crypto_close_session_op)(struct vhost_dev *dev, 106 uint64_t session_id); 107 108 typedef bool (*vhost_backend_no_private_memslots_op)(struct vhost_dev *dev); 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 int (*vhost_set_config_call_op)(struct vhost_dev *dev, 128 int fd); 129 130 typedef void (*vhost_reset_status_op)(struct vhost_dev *dev); 131 132 typedef struct VhostOps { 133 VhostBackendType backend_type; 134 vhost_backend_init vhost_backend_init; 135 vhost_backend_cleanup vhost_backend_cleanup; 136 vhost_backend_memslots_limit vhost_backend_memslots_limit; 137 vhost_backend_no_private_memslots_op vhost_backend_no_private_memslots; 138 vhost_net_set_backend_op vhost_net_set_backend; 139 vhost_net_set_mtu_op vhost_net_set_mtu; 140 vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint; 141 vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint; 142 vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version; 143 vhost_set_log_base_op vhost_set_log_base; 144 vhost_set_mem_table_op vhost_set_mem_table; 145 vhost_set_vring_addr_op vhost_set_vring_addr; 146 vhost_set_vring_endian_op vhost_set_vring_endian; 147 vhost_set_vring_num_op vhost_set_vring_num; 148 vhost_set_vring_base_op vhost_set_vring_base; 149 vhost_get_vring_base_op vhost_get_vring_base; 150 vhost_set_vring_kick_op vhost_set_vring_kick; 151 vhost_set_vring_call_op vhost_set_vring_call; 152 vhost_set_vring_err_op vhost_set_vring_err; 153 vhost_set_vring_busyloop_timeout_op vhost_set_vring_busyloop_timeout; 154 vhost_set_features_op vhost_set_features; 155 vhost_get_features_op vhost_get_features; 156 vhost_set_backend_cap_op vhost_set_backend_cap; 157 vhost_set_owner_op vhost_set_owner; 158 vhost_reset_device_op vhost_reset_device; 159 vhost_get_vq_index_op vhost_get_vq_index; 160 vhost_set_vring_enable_op vhost_set_vring_enable; 161 vhost_requires_shm_log_op vhost_requires_shm_log; 162 vhost_migration_done_op vhost_migration_done; 163 vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid; 164 vhost_vsock_set_running_op vhost_vsock_set_running; 165 vhost_set_iotlb_callback_op vhost_set_iotlb_callback; 166 vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg; 167 vhost_get_config_op vhost_get_config; 168 vhost_set_config_op vhost_set_config; 169 vhost_crypto_create_session_op vhost_crypto_create_session; 170 vhost_crypto_close_session_op vhost_crypto_close_session; 171 vhost_get_inflight_fd_op vhost_get_inflight_fd; 172 vhost_set_inflight_fd_op vhost_set_inflight_fd; 173 vhost_dev_start_op vhost_dev_start; 174 vhost_vq_get_addr_op vhost_vq_get_addr; 175 vhost_get_device_id_op vhost_get_device_id; 176 vhost_force_iommu_op vhost_force_iommu; 177 vhost_set_config_call_op vhost_set_config_call; 178 vhost_reset_status_op vhost_reset_status; 179 } VhostOps; 180 181 int vhost_backend_update_device_iotlb(struct vhost_dev *dev, 182 uint64_t iova, uint64_t uaddr, 183 uint64_t len, 184 IOMMUAccessFlags perm); 185 186 int vhost_backend_invalidate_device_iotlb(struct vhost_dev *dev, 187 uint64_t iova, uint64_t len); 188 189 int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, 190 struct vhost_iotlb_msg *imsg); 191 192 int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd); 193 194 int vhost_user_get_shared_object(struct vhost_dev *dev, unsigned char *uuid, 195 int *dmabuf_fd); 196 197 #endif /* VHOST_BACKEND_H */ 198