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 used_phys; 18 unsigned used_size; 19 void *ring; 20 unsigned long long ring_phys; 21 unsigned ring_size; 22 EventNotifier masked_notifier; 23 }; 24 25 typedef unsigned long vhost_log_chunk_t; 26 #define VHOST_LOG_PAGE 0x1000 27 #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t)) 28 #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS) 29 #define VHOST_INVALID_FEATURE_BIT (0xff) 30 31 struct vhost_memory; 32 struct vhost_dev { 33 MemoryListener memory_listener; 34 struct vhost_memory *mem; 35 int n_mem_sections; 36 MemoryRegionSection *mem_sections; 37 struct vhost_virtqueue *vqs; 38 int nvqs; 39 /* the first virtuque which would be used by this vhost dev */ 40 int vq_index; 41 unsigned long long features; 42 unsigned long long acked_features; 43 unsigned long long backend_features; 44 bool started; 45 bool log_enabled; 46 vhost_log_chunk_t *log; 47 unsigned long long log_size; 48 Error *migration_blocker; 49 bool force; 50 bool memory_changed; 51 hwaddr mem_changed_start_addr; 52 hwaddr mem_changed_end_addr; 53 const VhostOps *vhost_ops; 54 void *opaque; 55 }; 56 57 int vhost_dev_init(struct vhost_dev *hdev, void *opaque, 58 VhostBackendType backend_type, bool force); 59 void vhost_dev_cleanup(struct vhost_dev *hdev); 60 bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev); 61 int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); 62 void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); 63 int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); 64 void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); 65 66 /* Test and clear masked event pending status. 67 * Should be called after unmask to avoid losing events. 68 */ 69 bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n); 70 71 /* Mask/unmask events from this vq. 72 */ 73 void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, 74 bool mask); 75 unsigned vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, 76 unsigned features); 77 void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, 78 unsigned features); 79 #endif 80