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 struct vhost_dev; 24 struct vhost_log; 25 struct vhost_memory; 26 struct vhost_vring_file; 27 struct vhost_vring_state; 28 struct vhost_vring_addr; 29 struct vhost_scsi_target; 30 struct vhost_iotlb_msg; 31 32 typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque); 33 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); 34 typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev); 35 36 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev, 37 struct vhost_vring_file *file); 38 typedef int (*vhost_net_set_mtu_op)(struct vhost_dev *dev, uint16_t mtu); 39 typedef int (*vhost_scsi_set_endpoint_op)(struct vhost_dev *dev, 40 struct vhost_scsi_target *target); 41 typedef int (*vhost_scsi_clear_endpoint_op)(struct vhost_dev *dev, 42 struct vhost_scsi_target *target); 43 typedef int (*vhost_scsi_get_abi_version_op)(struct vhost_dev *dev, 44 int *version); 45 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base, 46 struct vhost_log *log); 47 typedef int (*vhost_set_mem_table_op)(struct vhost_dev *dev, 48 struct vhost_memory *mem); 49 typedef int (*vhost_set_vring_addr_op)(struct vhost_dev *dev, 50 struct vhost_vring_addr *addr); 51 typedef int (*vhost_set_vring_endian_op)(struct vhost_dev *dev, 52 struct vhost_vring_state *ring); 53 typedef int (*vhost_set_vring_num_op)(struct vhost_dev *dev, 54 struct vhost_vring_state *ring); 55 typedef int (*vhost_set_vring_base_op)(struct vhost_dev *dev, 56 struct vhost_vring_state *ring); 57 typedef int (*vhost_get_vring_base_op)(struct vhost_dev *dev, 58 struct vhost_vring_state *ring); 59 typedef int (*vhost_set_vring_kick_op)(struct vhost_dev *dev, 60 struct vhost_vring_file *file); 61 typedef int (*vhost_set_vring_call_op)(struct vhost_dev *dev, 62 struct vhost_vring_file *file); 63 typedef int (*vhost_set_vring_busyloop_timeout_op)(struct vhost_dev *dev, 64 struct vhost_vring_state *r); 65 typedef int (*vhost_set_features_op)(struct vhost_dev *dev, 66 uint64_t features); 67 typedef int (*vhost_get_features_op)(struct vhost_dev *dev, 68 uint64_t *features); 69 typedef int (*vhost_set_owner_op)(struct vhost_dev *dev); 70 typedef int (*vhost_reset_device_op)(struct vhost_dev *dev); 71 typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx); 72 typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev, 73 int enable); 74 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev); 75 typedef int (*vhost_migration_done_op)(struct vhost_dev *dev, 76 char *mac_addr); 77 typedef bool (*vhost_backend_can_merge_op)(struct vhost_dev *dev, 78 uint64_t start1, uint64_t size1, 79 uint64_t start2, uint64_t size2); 80 typedef int (*vhost_vsock_set_guest_cid_op)(struct vhost_dev *dev, 81 uint64_t guest_cid); 82 typedef int (*vhost_vsock_set_running_op)(struct vhost_dev *dev, int start); 83 typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev, 84 int enabled); 85 typedef int (*vhost_send_device_iotlb_msg_op)(struct vhost_dev *dev, 86 struct vhost_iotlb_msg *imsg); 87 88 typedef struct VhostOps { 89 VhostBackendType backend_type; 90 vhost_backend_init vhost_backend_init; 91 vhost_backend_cleanup vhost_backend_cleanup; 92 vhost_backend_memslots_limit vhost_backend_memslots_limit; 93 vhost_net_set_backend_op vhost_net_set_backend; 94 vhost_net_set_mtu_op vhost_net_set_mtu; 95 vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint; 96 vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint; 97 vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version; 98 vhost_set_log_base_op vhost_set_log_base; 99 vhost_set_mem_table_op vhost_set_mem_table; 100 vhost_set_vring_addr_op vhost_set_vring_addr; 101 vhost_set_vring_endian_op vhost_set_vring_endian; 102 vhost_set_vring_num_op vhost_set_vring_num; 103 vhost_set_vring_base_op vhost_set_vring_base; 104 vhost_get_vring_base_op vhost_get_vring_base; 105 vhost_set_vring_kick_op vhost_set_vring_kick; 106 vhost_set_vring_call_op vhost_set_vring_call; 107 vhost_set_vring_busyloop_timeout_op vhost_set_vring_busyloop_timeout; 108 vhost_set_features_op vhost_set_features; 109 vhost_get_features_op vhost_get_features; 110 vhost_set_owner_op vhost_set_owner; 111 vhost_reset_device_op vhost_reset_device; 112 vhost_get_vq_index_op vhost_get_vq_index; 113 vhost_set_vring_enable_op vhost_set_vring_enable; 114 vhost_requires_shm_log_op vhost_requires_shm_log; 115 vhost_migration_done_op vhost_migration_done; 116 vhost_backend_can_merge_op vhost_backend_can_merge; 117 vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid; 118 vhost_vsock_set_running_op vhost_vsock_set_running; 119 vhost_set_iotlb_callback_op vhost_set_iotlb_callback; 120 vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg; 121 } VhostOps; 122 123 extern const VhostOps user_ops; 124 125 int vhost_set_backend_type(struct vhost_dev *dev, 126 VhostBackendType backend_type); 127 128 int vhost_backend_update_device_iotlb(struct vhost_dev *dev, 129 uint64_t iova, uint64_t uaddr, 130 uint64_t len, 131 IOMMUAccessFlags perm); 132 133 int vhost_backend_invalidate_device_iotlb(struct vhost_dev *dev, 134 uint64_t iova, uint64_t len); 135 136 int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, 137 struct vhost_iotlb_msg *imsg); 138 139 #endif /* VHOST_BACKEND_H */ 140