1 #ifndef VHOST_H 2 #define VHOST_H 3 4 #include "hw/hw.h" 5 #include "hw/virtio/virtio.h" 6 #include "exec/memory.h" 7 8 /* Generic structures common for any vhost based device. */ 9 struct vhost_virtqueue { 10 int kick; 11 int call; 12 void *desc; 13 void *avail; 14 void *used; 15 int num; 16 unsigned long long used_phys; 17 unsigned used_size; 18 void *ring; 19 unsigned long long ring_phys; 20 unsigned ring_size; 21 EventNotifier masked_notifier; 22 }; 23 24 typedef unsigned long vhost_log_chunk_t; 25 #define VHOST_LOG_PAGE 0x1000 26 #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t)) 27 #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS) 28 #define VHOST_INVALID_FEATURE_BIT (0xff) 29 30 struct vhost_memory; 31 struct vhost_dev { 32 MemoryListener memory_listener; 33 int control; 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 bool force; 49 bool memory_changed; 50 hwaddr mem_changed_start_addr; 51 hwaddr mem_changed_end_addr; 52 }; 53 54 int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath, 55 bool force); 56 void vhost_dev_cleanup(struct vhost_dev *hdev); 57 bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev); 58 int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); 59 void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); 60 int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); 61 void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); 62 63 /* Test and clear masked event pending status. 64 * Should be called after unmask to avoid losing events. 65 */ 66 bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n); 67 68 /* Mask/unmask events from this vq. 69 */ 70 void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, 71 bool mask); 72 unsigned vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, 73 unsigned features); 74 void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, 75 unsigned features); 76 #endif 77