1 #ifndef VHOST_H 2 #define VHOST_H 3 4 #include "hw/hw.h" 5 #include "hw/virtio/vhost-backend.h" 6 #include "hw/virtio/virtio.h" 7 #include "exec/memory.h" 8 9 /* Generic structures common for any vhost based device. */ 10 struct vhost_virtqueue { 11 int kick; 12 int call; 13 void *desc; 14 void *avail; 15 void *used; 16 int num; 17 unsigned long long desc_phys; 18 unsigned desc_size; 19 unsigned long long avail_phys; 20 unsigned avail_size; 21 unsigned long long used_phys; 22 unsigned used_size; 23 void *ring; 24 unsigned long long ring_phys; 25 unsigned ring_size; 26 EventNotifier masked_notifier; 27 }; 28 29 typedef unsigned long vhost_log_chunk_t; 30 #define VHOST_LOG_PAGE 0x1000 31 #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t)) 32 #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS) 33 #define VHOST_INVALID_FEATURE_BIT (0xff) 34 35 struct vhost_log { 36 unsigned long long size; 37 int refcnt; 38 int fd; 39 vhost_log_chunk_t *log; 40 }; 41 42 struct vhost_memory; 43 struct vhost_dev { 44 MemoryListener memory_listener; 45 struct vhost_memory *mem; 46 int n_mem_sections; 47 MemoryRegionSection *mem_sections; 48 struct vhost_virtqueue *vqs; 49 int nvqs; 50 /* the first virtqueue which would be used by this vhost dev */ 51 int vq_index; 52 uint64_t features; 53 uint64_t acked_features; 54 uint64_t backend_features; 55 uint64_t protocol_features; 56 uint64_t max_queues; 57 bool started; 58 bool log_enabled; 59 uint64_t log_size; 60 Error *migration_blocker; 61 bool memory_changed; 62 hwaddr mem_changed_start_addr; 63 hwaddr mem_changed_end_addr; 64 const VhostOps *vhost_ops; 65 void *opaque; 66 struct vhost_log *log; 67 QLIST_ENTRY(vhost_dev) entry; 68 }; 69 70 int vhost_dev_init(struct vhost_dev *hdev, void *opaque, 71 VhostBackendType backend_type, 72 uint32_t busyloop_timeout); 73 void vhost_dev_cleanup(struct vhost_dev *hdev); 74 int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); 75 void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); 76 int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); 77 void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); 78 79 /* Test and clear masked event pending status. 80 * Should be called after unmask to avoid losing events. 81 */ 82 bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n); 83 84 /* Mask/unmask events from this vq. 85 */ 86 void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, 87 bool mask); 88 uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, 89 uint64_t features); 90 void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, 91 uint64_t features); 92 bool vhost_has_free_slot(void); 93 94 int vhost_net_set_backend(struct vhost_dev *hdev, 95 struct vhost_vring_file *file); 96 97 #endif 98