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