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