5 #include "hw/virtio/vhost-backend.h"
6 #include "hw/virtio/virtio.h"
7 #include "exec/memory.h"
9 /* Generic structures common for any vhost based device. */
10 struct vhost_virtqueue
{
17 unsigned long long desc_phys
;
19 unsigned long long avail_phys
;
21 unsigned long long used_phys
;
23 EventNotifier masked_notifier
;
24 struct vhost_dev
*dev
;
27 typedef unsigned long vhost_log_chunk_t
;
28 #define VHOST_LOG_PAGE 0x1000
29 #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t))
30 #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS)
31 #define VHOST_INVALID_FEATURE_BIT (0xff)
34 unsigned long long size
;
37 vhost_log_chunk_t
*log
;
42 struct vhost_dev
*hdev
;
46 QLIST_ENTRY(vhost_iommu
) iommu_next
;
49 typedef struct VhostDevConfigOps
{
50 /* Vhost device config space changed callback
52 int (*vhost_dev_config_notifier
)(struct vhost_dev
*dev
);
58 MemoryListener memory_listener
;
59 MemoryListener iommu_listener
;
60 struct vhost_memory
*mem
;
62 MemoryRegionSection
*mem_sections
;
64 MemoryRegionSection
*tmp_sections
;
65 struct vhost_virtqueue
*vqs
;
67 /* the first virtqueue which would be used by this vhost dev */
70 uint64_t acked_features
;
71 uint64_t backend_features
;
72 uint64_t protocol_features
;
77 Error
*migration_blocker
;
78 const VhostOps
*vhost_ops
;
80 struct vhost_log
*log
;
81 QLIST_ENTRY(vhost_dev
) entry
;
82 QLIST_HEAD(, vhost_iommu
) iommu_list
;
84 const VhostDevConfigOps
*config_ops
;
87 int vhost_dev_init(struct vhost_dev
*hdev
, void *opaque
,
88 VhostBackendType backend_type
,
89 uint32_t busyloop_timeout
);
90 void vhost_dev_cleanup(struct vhost_dev
*hdev
);
91 int vhost_dev_start(struct vhost_dev
*hdev
, VirtIODevice
*vdev
);
92 void vhost_dev_stop(struct vhost_dev
*hdev
, VirtIODevice
*vdev
);
93 int vhost_dev_enable_notifiers(struct vhost_dev
*hdev
, VirtIODevice
*vdev
);
94 void vhost_dev_disable_notifiers(struct vhost_dev
*hdev
, VirtIODevice
*vdev
);
96 /* Test and clear masked event pending status.
97 * Should be called after unmask to avoid losing events.
99 bool vhost_virtqueue_pending(struct vhost_dev
*hdev
, int n
);
101 /* Mask/unmask events from this vq.
103 void vhost_virtqueue_mask(struct vhost_dev
*hdev
, VirtIODevice
*vdev
, int n
,
105 uint64_t vhost_get_features(struct vhost_dev
*hdev
, const int *feature_bits
,
107 void vhost_ack_features(struct vhost_dev
*hdev
, const int *feature_bits
,
109 bool vhost_has_free_slot(void);
111 int vhost_net_set_backend(struct vhost_dev
*hdev
,
112 struct vhost_vring_file
*file
);
114 int vhost_device_iotlb_miss(struct vhost_dev
*dev
, uint64_t iova
, int write
);
115 int vhost_dev_get_config(struct vhost_dev
*dev
, uint8_t *config
,
116 uint32_t config_len
);
117 int vhost_dev_set_config(struct vhost_dev
*dev
, const uint8_t *data
,
118 uint32_t offset
, uint32_t size
, uint32_t flags
);
119 /* notifier callback in case vhost device config space changed
121 void vhost_dev_set_config_notifier(struct vhost_dev
*dev
,
122 const VhostDevConfigOps
*ops
);