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 <stdbool.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 31 typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque); 32 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); 33 typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev); 34 35 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev, 36 struct vhost_vring_file *file); 37 typedef int (*vhost_scsi_set_endpoint_op)(struct vhost_dev *dev, 38 struct vhost_scsi_target *target); 39 typedef int (*vhost_scsi_clear_endpoint_op)(struct vhost_dev *dev, 40 struct vhost_scsi_target *target); 41 typedef int (*vhost_scsi_get_abi_version_op)(struct vhost_dev *dev, 42 int *version); 43 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base, 44 struct vhost_log *log); 45 typedef int (*vhost_set_mem_table_op)(struct vhost_dev *dev, 46 struct vhost_memory *mem); 47 typedef int (*vhost_set_vring_addr_op)(struct vhost_dev *dev, 48 struct vhost_vring_addr *addr); 49 typedef int (*vhost_set_vring_endian_op)(struct vhost_dev *dev, 50 struct vhost_vring_state *ring); 51 typedef int (*vhost_set_vring_num_op)(struct vhost_dev *dev, 52 struct vhost_vring_state *ring); 53 typedef int (*vhost_set_vring_base_op)(struct vhost_dev *dev, 54 struct vhost_vring_state *ring); 55 typedef int (*vhost_get_vring_base_op)(struct vhost_dev *dev, 56 struct vhost_vring_state *ring); 57 typedef int (*vhost_set_vring_kick_op)(struct vhost_dev *dev, 58 struct vhost_vring_file *file); 59 typedef int (*vhost_set_vring_call_op)(struct vhost_dev *dev, 60 struct vhost_vring_file *file); 61 typedef int (*vhost_set_features_op)(struct vhost_dev *dev, 62 uint64_t features); 63 typedef int (*vhost_get_features_op)(struct vhost_dev *dev, 64 uint64_t *features); 65 typedef int (*vhost_set_owner_op)(struct vhost_dev *dev); 66 typedef int (*vhost_reset_device_op)(struct vhost_dev *dev); 67 typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx); 68 typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev, 69 int enable); 70 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev); 71 typedef int (*vhost_migration_done_op)(struct vhost_dev *dev, 72 char *mac_addr); 73 74 typedef struct VhostOps { 75 VhostBackendType backend_type; 76 vhost_backend_init vhost_backend_init; 77 vhost_backend_cleanup vhost_backend_cleanup; 78 vhost_backend_memslots_limit vhost_backend_memslots_limit; 79 vhost_net_set_backend_op vhost_net_set_backend; 80 vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint; 81 vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint; 82 vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version; 83 vhost_set_log_base_op vhost_set_log_base; 84 vhost_set_mem_table_op vhost_set_mem_table; 85 vhost_set_vring_addr_op vhost_set_vring_addr; 86 vhost_set_vring_endian_op vhost_set_vring_endian; 87 vhost_set_vring_num_op vhost_set_vring_num; 88 vhost_set_vring_base_op vhost_set_vring_base; 89 vhost_get_vring_base_op vhost_get_vring_base; 90 vhost_set_vring_kick_op vhost_set_vring_kick; 91 vhost_set_vring_call_op vhost_set_vring_call; 92 vhost_set_features_op vhost_set_features; 93 vhost_get_features_op vhost_get_features; 94 vhost_set_owner_op vhost_set_owner; 95 vhost_reset_device_op vhost_reset_device; 96 vhost_get_vq_index_op vhost_get_vq_index; 97 vhost_set_vring_enable_op vhost_set_vring_enable; 98 vhost_requires_shm_log_op vhost_requires_shm_log; 99 vhost_migration_done_op vhost_migration_done; 100 } VhostOps; 101 102 extern const VhostOps user_ops; 103 104 int vhost_set_backend_type(struct vhost_dev *dev, 105 VhostBackendType backend_type); 106 107 #endif /* VHOST_BACKEND_H_ */ 108