1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef VIRTIO_BUS_H
26#define VIRTIO_BUS_H
27
28#include "hw/qdev.h"
29#include "sysemu/sysemu.h"
30#include "hw/virtio/virtio.h"
31
32#define TYPE_VIRTIO_BUS "virtio-bus"
33#define VIRTIO_BUS_GET_CLASS(obj) \
34 OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_BUS)
35#define VIRTIO_BUS_CLASS(klass) \
36 OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_BUS)
37#define VIRTIO_BUS(obj) OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_BUS)
38
39typedef struct VirtioBusState VirtioBusState;
40
41typedef struct VirtioBusClass {
42
43 BusClass parent;
44 void (*notify)(DeviceState *d, uint16_t vector);
45 void (*save_config)(DeviceState *d, QEMUFile *f);
46 void (*save_queue)(DeviceState *d, int n, QEMUFile *f);
47 void (*save_extra_state)(DeviceState *d, QEMUFile *f);
48 int (*load_config)(DeviceState *d, QEMUFile *f);
49 int (*load_queue)(DeviceState *d, int n, QEMUFile *f);
50 int (*load_done)(DeviceState *d, QEMUFile *f);
51 int (*load_extra_state)(DeviceState *d, QEMUFile *f);
52 bool (*has_extra_state)(DeviceState *d);
53 bool (*query_guest_notifiers)(DeviceState *d);
54 int (*set_guest_notifiers)(DeviceState *d, int nvqs, bool assign);
55 int (*set_host_notifier_mr)(DeviceState *d, int n,
56 MemoryRegion *mr, bool assign);
57 void (*vmstate_change)(DeviceState *d, bool running);
58
59
60
61
62 void (*pre_plugged)(DeviceState *d, Error **errp);
63
64
65
66
67 void (*device_plugged)(DeviceState *d, Error **errp);
68
69
70
71
72 void (*device_unplugged)(DeviceState *d);
73 int (*query_nvectors)(DeviceState *d);
74
75
76
77
78
79 bool (*ioeventfd_enabled)(DeviceState *d);
80
81
82
83
84
85 int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier,
86 int n, bool assign);
87
88
89
90
91
92 bool has_variable_vring_alignment;
93 AddressSpace *(*get_dma_as)(DeviceState *d);
94} VirtioBusClass;
95
96struct VirtioBusState {
97 BusState parent_obj;
98
99
100
101
102 bool ioeventfd_started;
103
104
105
106
107
108
109
110
111
112 int ioeventfd_grabbed;
113};
114
115void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp);
116void virtio_bus_reset(VirtioBusState *bus);
117void virtio_bus_device_unplugged(VirtIODevice *bus);
118
119uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus);
120
121size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);
122
123uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus);
124
125void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config);
126
127void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config);
128
129static inline VirtIODevice *virtio_bus_get_device(VirtioBusState *bus)
130{
131 BusState *qbus = &bus->parent_obj;
132 BusChild *kid = QTAILQ_FIRST(&qbus->children);
133 DeviceState *qdev = kid ? kid->child : NULL;
134
135
136
137
138 return (VirtIODevice *)qdev;
139}
140
141
142bool virtio_bus_ioeventfd_enabled(VirtioBusState *bus);
143
144int virtio_bus_start_ioeventfd(VirtioBusState *bus);
145
146void virtio_bus_stop_ioeventfd(VirtioBusState *bus);
147
148int virtio_bus_grab_ioeventfd(VirtioBusState *bus);
149
150void virtio_bus_release_ioeventfd(VirtioBusState *bus);
151
152int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign);
153
154void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n);
155
156#endif
157