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. */
11 struct vhost_inflight
{
19 struct vhost_virtqueue
{
26 unsigned long long desc_phys
;
28 unsigned long long avail_phys
;
30 unsigned long long used_phys
;
32 EventNotifier masked_notifier
;
33 struct vhost_dev
*dev
;
36 typedef unsigned long vhost_log_chunk_t
;
37 #define VHOST_LOG_PAGE 0x1000
38 #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t))
39 #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS)
40 #define VHOST_INVALID_FEATURE_BIT (0xff)
43 unsigned long long size
;
46 vhost_log_chunk_t
*log
;
51 struct vhost_dev
*hdev
;
55 QLIST_ENTRY(vhost_iommu
) iommu_next
;
58 typedef struct VhostDevConfigOps
{
59 /* Vhost device config space changed callback
61 int (*vhost_dev_config_notifier
)(struct vhost_dev
*dev
);
67 MemoryListener memory_listener
;
68 MemoryListener iommu_listener
;
69 struct vhost_memory
*mem
;
71 MemoryRegionSection
*mem_sections
;
73 MemoryRegionSection
*tmp_sections
;
74 struct vhost_virtqueue
*vqs
;
76 /* the first virtqueue which would be used by this vhost dev */
79 uint64_t acked_features
;
80 uint64_t backend_features
;
81 uint64_t protocol_features
;
86 Error
*migration_blocker
;
87 const VhostOps
*vhost_ops
;
89 struct vhost_log
*log
;
90 QLIST_ENTRY(vhost_dev
) entry
;
91 QLIST_HEAD(, vhost_iommu
) iommu_list
;
93 const VhostDevConfigOps
*config_ops
;
96 int vhost_dev_init(struct vhost_dev
*hdev
, void *opaque
,
97 VhostBackendType backend_type
,
98 uint32_t busyloop_timeout
);
99 void vhost_dev_cleanup(struct vhost_dev
*hdev
);
100 int vhost_dev_start(struct vhost_dev
*hdev
, VirtIODevice
*vdev
);
101 void vhost_dev_stop(struct vhost_dev
*hdev
, VirtIODevice
*vdev
);
102 int vhost_dev_enable_notifiers(struct vhost_dev
*hdev
, VirtIODevice
*vdev
);
103 void vhost_dev_disable_notifiers(struct vhost_dev
*hdev
, VirtIODevice
*vdev
);
105 /* Test and clear masked event pending status.
106 * Should be called after unmask to avoid losing events.
108 bool vhost_virtqueue_pending(struct vhost_dev
*hdev
, int n
);
110 /* Mask/unmask events from this vq.
112 void vhost_virtqueue_mask(struct vhost_dev
*hdev
, VirtIODevice
*vdev
, int n
,
114 uint64_t vhost_get_features(struct vhost_dev
*hdev
, const int *feature_bits
,
116 void vhost_ack_features(struct vhost_dev
*hdev
, const int *feature_bits
,
118 bool vhost_has_free_slot(void);
120 int vhost_net_set_backend(struct vhost_dev
*hdev
,
121 struct vhost_vring_file
*file
);
123 int vhost_device_iotlb_miss(struct vhost_dev
*dev
, uint64_t iova
, int write
);
124 int vhost_dev_get_config(struct vhost_dev
*dev
, uint8_t *config
,
125 uint32_t config_len
);
126 int vhost_dev_set_config(struct vhost_dev
*dev
, const uint8_t *data
,
127 uint32_t offset
, uint32_t size
, uint32_t flags
);
128 /* notifier callback in case vhost device config space changed
130 void vhost_dev_set_config_notifier(struct vhost_dev
*dev
,
131 const VhostDevConfigOps
*ops
);
133 void vhost_dev_reset_inflight(struct vhost_inflight
*inflight
);
134 void vhost_dev_free_inflight(struct vhost_inflight
*inflight
);
135 void vhost_dev_save_inflight(struct vhost_inflight
*inflight
, QEMUFile
*f
);
136 int vhost_dev_load_inflight(struct vhost_inflight
*inflight
, QEMUFile
*f
);
137 int vhost_dev_set_inflight(struct vhost_dev
*dev
,
138 struct vhost_inflight
*inflight
);
139 int vhost_dev_get_inflight(struct vhost_dev
*dev
, uint16_t queue_size
,
140 struct vhost_inflight
*inflight
);