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

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

/* Generic structures common for any vhost based device. */
struct vhost_virtqueue {
    int kick;
    int call;
    void *desc;
    void *avail;
    void *used;
    int num;
    unsigned long long used_phys;
    unsigned used_size;
    void *ring;
    unsigned long long ring_phys;
    unsigned ring_size;
21
    EventNotifier masked_notifier;
M
Michael S. Tsirkin 已提交
22 23 24 25 26 27
};

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

struct vhost_memory;
struct vhost_dev {
A
Avi Kivity 已提交
32
    MemoryListener memory_listener;
M
Michael S. Tsirkin 已提交
33 34
    int control;
    struct vhost_memory *mem;
35 36
    int n_mem_sections;
    MemoryRegionSection *mem_sections;
M
Michael S. Tsirkin 已提交
37 38
    struct vhost_virtqueue *vqs;
    int nvqs;
J
Jason Wang 已提交
39 40
    /* the first virtuque which would be used by this vhost dev */
    int vq_index;
M
Michael S. Tsirkin 已提交
41 42 43 44 45 46 47
    unsigned long long features;
    unsigned long long acked_features;
    unsigned long long backend_features;
    bool started;
    bool log_enabled;
    vhost_log_chunk_t *log;
    unsigned long long log_size;
48
    bool force;
49 50 51
    bool memory_changed;
    hwaddr mem_changed_start_addr;
    hwaddr mem_changed_end_addr;
M
Michael S. Tsirkin 已提交
52 53
};

54
int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
55
                   bool force);
M
Michael S. Tsirkin 已提交
56
void vhost_dev_cleanup(struct vhost_dev *hdev);
57
bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev);
M
Michael S. Tsirkin 已提交
58 59
int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev);
void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev);
60 61
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 已提交
62

63 64 65 66 67 68 69 70 71
/* 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);
72 73 74 75
unsigned vhost_get_features(struct vhost_dev *hdev, const int *feature_bits,
        unsigned features);
void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits,
        unsigned features);
M
Michael S. Tsirkin 已提交
76
#endif