]> git.ipfire.org Git - thirdparty/qemu.git/blob - include/hw/virtio/vhost.h
vhost: add vhost_net_set_backend()
[thirdparty/qemu.git] / include / hw / virtio / vhost.h
1 #ifndef VHOST_H
2 #define VHOST_H
3
4 #include "hw/hw.h"
5 #include "hw/virtio/vhost-backend.h"
6 #include "hw/virtio/virtio.h"
7 #include "exec/memory.h"
8
9 /* Generic structures common for any vhost based device. */
10 struct vhost_virtqueue {
11 int kick;
12 int call;
13 void *desc;
14 void *avail;
15 void *used;
16 int num;
17 unsigned long long used_phys;
18 unsigned used_size;
19 void *ring;
20 unsigned long long ring_phys;
21 unsigned ring_size;
22 EventNotifier masked_notifier;
23 };
24
25 typedef unsigned long vhost_log_chunk_t;
26 #define VHOST_LOG_PAGE 0x1000
27 #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t))
28 #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS)
29 #define VHOST_INVALID_FEATURE_BIT (0xff)
30
31 struct vhost_log {
32 unsigned long long size;
33 int refcnt;
34 int fd;
35 vhost_log_chunk_t *log;
36 };
37
38 struct vhost_memory;
39 struct vhost_dev {
40 MemoryListener memory_listener;
41 struct vhost_memory *mem;
42 int n_mem_sections;
43 MemoryRegionSection *mem_sections;
44 struct vhost_virtqueue *vqs;
45 int nvqs;
46 /* the first virtqueue which would be used by this vhost dev */
47 int vq_index;
48 uint64_t features;
49 uint64_t acked_features;
50 uint64_t backend_features;
51 uint64_t protocol_features;
52 uint64_t max_queues;
53 bool started;
54 bool log_enabled;
55 uint64_t log_size;
56 Error *migration_blocker;
57 bool memory_changed;
58 hwaddr mem_changed_start_addr;
59 hwaddr mem_changed_end_addr;
60 const VhostOps *vhost_ops;
61 void *opaque;
62 struct vhost_log *log;
63 QLIST_ENTRY(vhost_dev) entry;
64 };
65
66 int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
67 VhostBackendType backend_type,
68 uint32_t busyloop_timeout);
69 void vhost_dev_cleanup(struct vhost_dev *hdev);
70 int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev);
71 void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev);
72 int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev);
73 void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev);
74
75 /* Test and clear masked event pending status.
76 * Should be called after unmask to avoid losing events.
77 */
78 bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n);
79
80 /* Mask/unmask events from this vq.
81 */
82 void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n,
83 bool mask);
84 uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits,
85 uint64_t features);
86 void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits,
87 uint64_t features);
88 bool vhost_has_free_slot(void);
89
90 int vhost_net_set_backend(struct vhost_dev *hdev,
91 struct vhost_vring_file *file);
92
93 #endif