vhost.h 2.9 KB
Newer Older
M
Michael S. Tsirkin 已提交
1 2 3 4
#ifndef VHOST_H
#define VHOST_H

#include "hw/hw.h"
5
#include "hw/virtio/vhost-backend.h"
P
Paolo Bonzini 已提交
6
#include "hw/virtio/virtio.h"
7
#include "exec/memory.h"
M
Michael S. Tsirkin 已提交
8 9 10 11 12 13 14 15 16

/* Generic structures common for any vhost based device. */
struct vhost_virtqueue {
    int kick;
    int call;
    void *desc;
    void *avail;
    void *used;
    int num;
17 18 19 20
    unsigned long long desc_phys;
    unsigned desc_size;
    unsigned long long avail_phys;
    unsigned avail_size;
M
Michael S. Tsirkin 已提交
21 22
    unsigned long long used_phys;
    unsigned used_size;
23
    EventNotifier masked_notifier;
J
Jason Wang 已提交
24
    struct vhost_dev *dev;
M
Michael S. Tsirkin 已提交
25 26 27 28 29 30
};

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)
31
#define VHOST_INVALID_FEATURE_BIT   (0xff)
M
Michael S. Tsirkin 已提交
32

J
Jason Wang 已提交
33 34 35
struct vhost_log {
    unsigned long long size;
    int refcnt;
M
Marc-André Lureau 已提交
36 37
    int fd;
    vhost_log_chunk_t *log;
J
Jason Wang 已提交
38 39
};

M
Michael S. Tsirkin 已提交
40 41
struct vhost_memory;
struct vhost_dev {
J
Jason Wang 已提交
42
    VirtIODevice *vdev;
A
Avi Kivity 已提交
43
    MemoryListener memory_listener;
M
Michael S. Tsirkin 已提交
44
    struct vhost_memory *mem;
45 46
    int n_mem_sections;
    MemoryRegionSection *mem_sections;
M
Michael S. Tsirkin 已提交
47 48
    struct vhost_virtqueue *vqs;
    int nvqs;
49
    /* the first virtqueue which would be used by this vhost dev */
J
Jason Wang 已提交
50
    int vq_index;
51 52 53 54 55
    uint64_t features;
    uint64_t acked_features;
    uint64_t backend_features;
    uint64_t protocol_features;
    uint64_t max_queues;
M
Michael S. Tsirkin 已提交
56 57
    bool started;
    bool log_enabled;
58
    uint64_t log_size;
59
    Error *migration_blocker;
60 61 62
    bool memory_changed;
    hwaddr mem_changed_start_addr;
    hwaddr mem_changed_end_addr;
63
    const VhostOps *vhost_ops;
64
    void *opaque;
J
Jason Wang 已提交
65
    struct vhost_log *log;
66
    QLIST_ENTRY(vhost_dev) entry;
J
Jason Wang 已提交
67
    IOMMUNotifier n;
M
Michael S. Tsirkin 已提交
68 69
};

70
int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
J
Jason Wang 已提交
71 72
                   VhostBackendType backend_type,
                   uint32_t busyloop_timeout);
M
Michael S. Tsirkin 已提交
73 74 75
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);
76 77
int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev);
void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev);
M
Michael S. Tsirkin 已提交
78

79 80 81 82 83 84 85 86 87
/* 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);
C
Cornelia Huck 已提交
88 89
uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits,
                            uint64_t features);
90
void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits,
C
Cornelia Huck 已提交
91
                        uint64_t features);
92
bool vhost_has_free_slot(void);
93 94 95 96

int vhost_net_set_backend(struct vhost_dev *hdev,
                          struct vhost_vring_file *file);

J
Jason Wang 已提交
97
void vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write);
M
Michael S. Tsirkin 已提交
98
#endif