vhost.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef VHOST_H
  2. #define VHOST_H
  3. #include "hw/hw.h"
  4. #include "hw/virtio.h"
  5. #include "exec/memory.h"
  6. /* Generic structures common for any vhost based device. */
  7. struct vhost_virtqueue {
  8. int kick;
  9. int call;
  10. void *desc;
  11. void *avail;
  12. void *used;
  13. int num;
  14. unsigned long long used_phys;
  15. unsigned used_size;
  16. void *ring;
  17. unsigned long long ring_phys;
  18. unsigned ring_size;
  19. EventNotifier masked_notifier;
  20. };
  21. typedef unsigned long vhost_log_chunk_t;
  22. #define VHOST_LOG_PAGE 0x1000
  23. #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t))
  24. #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS)
  25. struct vhost_memory;
  26. struct vhost_dev {
  27. MemoryListener memory_listener;
  28. int control;
  29. struct vhost_memory *mem;
  30. int n_mem_sections;
  31. MemoryRegionSection *mem_sections;
  32. struct vhost_virtqueue *vqs;
  33. int nvqs;
  34. /* the first virtuque which would be used by this vhost dev */
  35. int vq_index;
  36. unsigned long long features;
  37. unsigned long long acked_features;
  38. unsigned long long backend_features;
  39. bool started;
  40. bool log_enabled;
  41. vhost_log_chunk_t *log;
  42. unsigned long long log_size;
  43. bool force;
  44. };
  45. int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath,
  46. bool force);
  47. void vhost_dev_cleanup(struct vhost_dev *hdev);
  48. bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev);
  49. int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev);
  50. void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev);
  51. int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev);
  52. void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev);
  53. /* Test and clear masked event pending status.
  54. * Should be called after unmask to avoid losing events.
  55. */
  56. bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n);
  57. /* Mask/unmask events from this vq.
  58. */
  59. void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n,
  60. bool mask);
  61. #endif