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