2010-03-17 19:08:17 +08:00
|
|
|
#ifndef VHOST_H
|
|
|
|
#define VHOST_H
|
|
|
|
|
2014-05-27 20:05:35 +08:00
|
|
|
#include "hw/virtio/vhost-backend.h"
|
2013-02-06 00:06:20 +08:00
|
|
|
#include "hw/virtio/virtio.h"
|
2012-12-18 01:19:49 +08:00
|
|
|
#include "exec/memory.h"
|
2010-03-17 19:08:17 +08:00
|
|
|
|
|
|
|
/* Generic structures common for any vhost based device. */
|
2019-02-28 16:53:49 +08:00
|
|
|
|
|
|
|
struct vhost_inflight {
|
|
|
|
int fd;
|
|
|
|
void *addr;
|
|
|
|
uint64_t size;
|
|
|
|
uint64_t offset;
|
|
|
|
uint16_t queue_size;
|
|
|
|
};
|
|
|
|
|
2010-03-17 19:08:17 +08:00
|
|
|
struct vhost_virtqueue {
|
|
|
|
int kick;
|
|
|
|
int call;
|
|
|
|
void *desc;
|
|
|
|
void *avail;
|
|
|
|
void *used;
|
|
|
|
int num;
|
2016-11-04 16:39:15 +08:00
|
|
|
unsigned long long desc_phys;
|
|
|
|
unsigned desc_size;
|
|
|
|
unsigned long long avail_phys;
|
|
|
|
unsigned avail_size;
|
2010-03-17 19:08:17 +08:00
|
|
|
unsigned long long used_phys;
|
|
|
|
unsigned used_size;
|
2012-12-24 23:37:01 +08:00
|
|
|
EventNotifier masked_notifier;
|
2017-01-11 12:32:12 +08:00
|
|
|
struct vhost_dev *dev;
|
2010-03-17 19:08:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef unsigned long vhost_log_chunk_t;
|
|
|
|
#define VHOST_LOG_PAGE 0x1000
|
|
|
|
#define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t))
|
|
|
|
#define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS)
|
2014-05-27 20:04:42 +08:00
|
|
|
#define VHOST_INVALID_FEATURE_BIT (0xff)
|
2010-03-17 19:08:17 +08:00
|
|
|
|
2015-06-04 17:28:46 +08:00
|
|
|
struct vhost_log {
|
|
|
|
unsigned long long size;
|
|
|
|
int refcnt;
|
2015-10-09 23:17:25 +08:00
|
|
|
int fd;
|
|
|
|
vhost_log_chunk_t *log;
|
2015-06-04 17:28:46 +08:00
|
|
|
};
|
|
|
|
|
2017-03-29 12:10:04 +08:00
|
|
|
struct vhost_dev;
|
|
|
|
struct vhost_iommu {
|
|
|
|
struct vhost_dev *hdev;
|
|
|
|
MemoryRegion *mr;
|
|
|
|
hwaddr iommu_offset;
|
|
|
|
IOMMUNotifier n;
|
|
|
|
QLIST_ENTRY(vhost_iommu) iommu_next;
|
|
|
|
};
|
|
|
|
|
2018-01-04 09:53:31 +08:00
|
|
|
typedef struct VhostDevConfigOps {
|
|
|
|
/* Vhost device config space changed callback
|
|
|
|
*/
|
|
|
|
int (*vhost_dev_config_notifier)(struct vhost_dev *dev);
|
|
|
|
} VhostDevConfigOps;
|
|
|
|
|
2010-03-17 19:08:17 +08:00
|
|
|
struct vhost_memory;
|
|
|
|
struct vhost_dev {
|
2017-01-11 12:32:12 +08:00
|
|
|
VirtIODevice *vdev;
|
2011-12-18 20:06:05 +08:00
|
|
|
MemoryListener memory_listener;
|
2017-03-29 12:10:04 +08:00
|
|
|
MemoryListener iommu_listener;
|
2010-03-17 19:08:17 +08:00
|
|
|
struct vhost_memory *mem;
|
2011-12-19 19:18:13 +08:00
|
|
|
int n_mem_sections;
|
|
|
|
MemoryRegionSection *mem_sections;
|
2018-01-19 18:39:18 +08:00
|
|
|
int n_tmp_sections;
|
|
|
|
MemoryRegionSection *tmp_sections;
|
2010-03-17 19:08:17 +08:00
|
|
|
struct vhost_virtqueue *vqs;
|
|
|
|
int nvqs;
|
2015-03-26 19:10:29 +08:00
|
|
|
/* the first virtqueue which would be used by this vhost dev */
|
2013-01-30 19:12:35 +08:00
|
|
|
int vq_index;
|
2015-10-09 23:17:28 +08:00
|
|
|
uint64_t features;
|
|
|
|
uint64_t acked_features;
|
|
|
|
uint64_t backend_features;
|
|
|
|
uint64_t protocol_features;
|
|
|
|
uint64_t max_queues;
|
2010-03-17 19:08:17 +08:00
|
|
|
bool started;
|
|
|
|
bool log_enabled;
|
2015-10-09 23:17:28 +08:00
|
|
|
uint64_t log_size;
|
2014-06-18 22:20:42 +08:00
|
|
|
Error *migration_blocker;
|
2014-05-27 20:05:35 +08:00
|
|
|
const VhostOps *vhost_ops;
|
2014-05-27 20:05:49 +08:00
|
|
|
void *opaque;
|
2015-06-04 17:28:46 +08:00
|
|
|
struct vhost_log *log;
|
2015-10-06 16:37:27 +08:00
|
|
|
QLIST_ENTRY(vhost_dev) entry;
|
2017-03-29 12:10:04 +08:00
|
|
|
QLIST_HEAD(, vhost_iommu) iommu_list;
|
2017-01-11 12:32:12 +08:00
|
|
|
IOMMUNotifier n;
|
2018-01-04 09:53:31 +08:00
|
|
|
const VhostDevConfigOps *config_ops;
|
2010-03-17 19:08:17 +08:00
|
|
|
};
|
|
|
|
|
2020-07-01 22:55:37 +08:00
|
|
|
struct vhost_net {
|
|
|
|
struct vhost_dev dev;
|
|
|
|
struct vhost_virtqueue vqs[2];
|
|
|
|
int backend;
|
|
|
|
NetClientState *nc;
|
|
|
|
};
|
|
|
|
|
2014-05-27 20:05:22 +08:00
|
|
|
int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
|
2016-07-06 09:57:55 +08:00
|
|
|
VhostBackendType backend_type,
|
|
|
|
uint32_t busyloop_timeout);
|
2010-03-17 19:08:17 +08:00
|
|
|
void vhost_dev_cleanup(struct vhost_dev *hdev);
|
|
|
|
int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev);
|
|
|
|
void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev);
|
2011-08-11 15:21:18 +08:00
|
|
|
int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev);
|
|
|
|
void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev);
|
2010-03-17 19:08:17 +08:00
|
|
|
|
2012-12-24 23:37:01 +08:00
|
|
|
/* Test and clear masked event pending status.
|
|
|
|
* Should be called after unmask to avoid losing events.
|
|
|
|
*/
|
|
|
|
bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n);
|
|
|
|
|
|
|
|
/* Mask/unmask events from this vq.
|
|
|
|
*/
|
|
|
|
void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n,
|
|
|
|
bool mask);
|
2015-06-04 18:34:20 +08:00
|
|
|
uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits,
|
|
|
|
uint64_t features);
|
2014-05-27 20:04:42 +08:00
|
|
|
void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits,
|
2015-06-04 18:34:20 +08:00
|
|
|
uint64_t features);
|
2015-10-06 16:37:27 +08:00
|
|
|
bool vhost_has_free_slot(void);
|
2016-07-27 05:15:25 +08:00
|
|
|
|
|
|
|
int vhost_net_set_backend(struct vhost_dev *hdev,
|
|
|
|
struct vhost_vring_file *file);
|
|
|
|
|
2017-06-02 18:18:27 +08:00
|
|
|
int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write);
|
2018-01-04 09:53:31 +08:00
|
|
|
int vhost_dev_get_config(struct vhost_dev *dev, uint8_t *config,
|
|
|
|
uint32_t config_len);
|
|
|
|
int vhost_dev_set_config(struct vhost_dev *dev, const uint8_t *data,
|
|
|
|
uint32_t offset, uint32_t size, uint32_t flags);
|
|
|
|
/* notifier callback in case vhost device config space changed
|
|
|
|
*/
|
|
|
|
void vhost_dev_set_config_notifier(struct vhost_dev *dev,
|
|
|
|
const VhostDevConfigOps *ops);
|
2019-02-28 16:53:49 +08:00
|
|
|
|
|
|
|
void vhost_dev_reset_inflight(struct vhost_inflight *inflight);
|
|
|
|
void vhost_dev_free_inflight(struct vhost_inflight *inflight);
|
|
|
|
void vhost_dev_save_inflight(struct vhost_inflight *inflight, QEMUFile *f);
|
|
|
|
int vhost_dev_load_inflight(struct vhost_inflight *inflight, QEMUFile *f);
|
|
|
|
int vhost_dev_set_inflight(struct vhost_dev *dev,
|
|
|
|
struct vhost_inflight *inflight);
|
|
|
|
int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size,
|
|
|
|
struct vhost_inflight *inflight);
|
2010-03-17 19:08:17 +08:00
|
|
|
#endif
|