1d5970055SMichael S. Tsirkin #ifndef VHOST_H 2d5970055SMichael S. Tsirkin #define VHOST_H 3d5970055SMichael S. Tsirkin 4d5970055SMichael S. Tsirkin #include "hw/hw.h" 5*0d09e41aSPaolo Bonzini #include "hw/virtio/virtio.h" 6022c62cbSPaolo Bonzini #include "exec/memory.h" 7d5970055SMichael S. Tsirkin 8d5970055SMichael S. Tsirkin /* Generic structures common for any vhost based device. */ 9d5970055SMichael S. Tsirkin struct vhost_virtqueue { 10d5970055SMichael S. Tsirkin int kick; 11d5970055SMichael S. Tsirkin int call; 12d5970055SMichael S. Tsirkin void *desc; 13d5970055SMichael S. Tsirkin void *avail; 14d5970055SMichael S. Tsirkin void *used; 15d5970055SMichael S. Tsirkin int num; 16d5970055SMichael S. Tsirkin unsigned long long used_phys; 17d5970055SMichael S. Tsirkin unsigned used_size; 18d5970055SMichael S. Tsirkin void *ring; 19d5970055SMichael S. Tsirkin unsigned long long ring_phys; 20d5970055SMichael S. Tsirkin unsigned ring_size; 21f56a1247SMichael S. Tsirkin EventNotifier masked_notifier; 22d5970055SMichael S. Tsirkin }; 23d5970055SMichael S. Tsirkin 24d5970055SMichael S. Tsirkin typedef unsigned long vhost_log_chunk_t; 25d5970055SMichael S. Tsirkin #define VHOST_LOG_PAGE 0x1000 26d5970055SMichael S. Tsirkin #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t)) 27d5970055SMichael S. Tsirkin #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS) 28d5970055SMichael S. Tsirkin 29d5970055SMichael S. Tsirkin struct vhost_memory; 30d5970055SMichael S. Tsirkin struct vhost_dev { 3104097f7cSAvi Kivity MemoryListener memory_listener; 32d5970055SMichael S. Tsirkin int control; 33d5970055SMichael S. Tsirkin struct vhost_memory *mem; 342817b260SAvi Kivity int n_mem_sections; 352817b260SAvi Kivity MemoryRegionSection *mem_sections; 36d5970055SMichael S. Tsirkin struct vhost_virtqueue *vqs; 37d5970055SMichael S. Tsirkin int nvqs; 38a9f98bb5SJason Wang /* the first virtuque which would be used by this vhost dev */ 39a9f98bb5SJason Wang int vq_index; 40d5970055SMichael S. Tsirkin unsigned long long features; 41d5970055SMichael S. Tsirkin unsigned long long acked_features; 42d5970055SMichael S. Tsirkin unsigned long long backend_features; 43d5970055SMichael S. Tsirkin bool started; 44d5970055SMichael S. Tsirkin bool log_enabled; 45d5970055SMichael S. Tsirkin vhost_log_chunk_t *log; 46d5970055SMichael S. Tsirkin unsigned long long log_size; 475430a28fSmst@redhat.com bool force; 48d5970055SMichael S. Tsirkin }; 49d5970055SMichael S. Tsirkin 501241ed94SStefan Hajnoczi int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath, 511241ed94SStefan Hajnoczi bool force); 52d5970055SMichael S. Tsirkin void vhost_dev_cleanup(struct vhost_dev *hdev); 535430a28fSmst@redhat.com bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev); 54d5970055SMichael S. Tsirkin int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); 55d5970055SMichael S. Tsirkin void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); 56b0b3db79SMichael S. Tsirkin int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); 57b0b3db79SMichael S. Tsirkin void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); 58d5970055SMichael S. Tsirkin 59f56a1247SMichael S. Tsirkin /* Test and clear masked event pending status. 60f56a1247SMichael S. Tsirkin * Should be called after unmask to avoid losing events. 61f56a1247SMichael S. Tsirkin */ 62f56a1247SMichael S. Tsirkin bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n); 63f56a1247SMichael S. Tsirkin 64f56a1247SMichael S. Tsirkin /* Mask/unmask events from this vq. 65f56a1247SMichael S. Tsirkin */ 66f56a1247SMichael S. Tsirkin void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, 67f56a1247SMichael S. Tsirkin bool mask); 68d5970055SMichael S. Tsirkin #endif 69