1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef QEMU_VIRTIO_PCI_H
16#define QEMU_VIRTIO_PCI_H
17
18#include "hw/pci/msi.h"
19#include "hw/virtio/virtio-bus.h"
20
21typedef struct VirtIOPCIProxy VirtIOPCIProxy;
22
23
24
25typedef struct VirtioBusState VirtioPCIBusState;
26typedef struct VirtioBusClass VirtioPCIBusClass;
27
28#define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
29#define VIRTIO_PCI_BUS(obj) \
30 OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
31#define VIRTIO_PCI_BUS_GET_CLASS(obj) \
32 OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
33#define VIRTIO_PCI_BUS_CLASS(klass) \
34 OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
35
36enum {
37 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
38 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
39 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
40 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
41 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
42 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
43 VIRTIO_PCI_FLAG_ATS_BIT,
44 VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
45 VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
46 VIRTIO_PCI_FLAG_INIT_PM_BIT,
47};
48
49
50#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
51 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
52
53
54
55#define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
56
57
58#define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
59
60
61#define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
62
63
64#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
65 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
66
67
68#define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
69 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
70
71
72#define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
73
74
75#define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
76
77
78#define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
79
80
81#define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
82
83typedef struct {
84 MSIMessage msg;
85 int virq;
86 unsigned int users;
87} VirtIOIRQFD;
88
89
90
91
92#define TYPE_VIRTIO_PCI "virtio-pci"
93#define VIRTIO_PCI_GET_CLASS(obj) \
94 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
95#define VIRTIO_PCI_CLASS(klass) \
96 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
97#define VIRTIO_PCI(obj) \
98 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
99
100typedef struct VirtioPCIClass {
101 PCIDeviceClass parent_class;
102 DeviceRealize parent_dc_realize;
103 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
104} VirtioPCIClass;
105
106typedef struct VirtIOPCIRegion {
107 MemoryRegion mr;
108 uint32_t offset;
109 uint32_t size;
110 uint32_t type;
111} VirtIOPCIRegion;
112
113typedef struct VirtIOPCIQueue {
114 uint16_t num;
115 bool enabled;
116 uint32_t desc[2];
117 uint32_t avail[2];
118 uint32_t used[2];
119} VirtIOPCIQueue;
120
121struct VirtIOPCIProxy {
122 PCIDevice pci_dev;
123 MemoryRegion bar;
124 union {
125 struct {
126 VirtIOPCIRegion common;
127 VirtIOPCIRegion isr;
128 VirtIOPCIRegion device;
129 VirtIOPCIRegion notify;
130 VirtIOPCIRegion notify_pio;
131 };
132 VirtIOPCIRegion regs[5];
133 };
134 MemoryRegion modern_bar;
135 MemoryRegion io_bar;
136 uint32_t legacy_io_bar_idx;
137 uint32_t msix_bar_idx;
138 uint32_t modern_io_bar_idx;
139 uint32_t modern_mem_bar_idx;
140 int config_cap;
141 uint32_t flags;
142 bool disable_modern;
143 bool ignore_backend_features;
144 OnOffAuto disable_legacy;
145 uint32_t class_code;
146 uint32_t nvectors;
147 uint32_t dfselect;
148 uint32_t gfselect;
149 uint32_t guest_features[2];
150 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
151
152 VirtIOIRQFD *vector_irqfd;
153 int nvqs_with_notifiers;
154 VirtioBusState bus;
155};
156
157static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
158{
159 return !proxy->disable_modern;
160}
161
162static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
163{
164 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
165}
166
167static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
168{
169 proxy->disable_modern = false;
170 proxy->disable_legacy = ON_OFF_AUTO_ON;
171}
172
173static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
174{
175 proxy->disable_modern = true;
176}
177
178
179
180
181#define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
182
183
184#define VIRTIO_PCI_ABI_VERSION 0
185
186
187typedef struct VirtioPCIDeviceTypeInfo {
188
189
190
191
192
193
194
195
196
197
198
199
200 const char *base_name;
201
202
203
204
205
206
207
208
209
210
211
212
213
214 const char *generic_name;
215
216
217
218
219
220 const char *transitional_name;
221
222
223
224
225
226 const char *non_transitional_name;
227
228
229 const char *parent;
230
231
232 size_t instance_size;
233 size_t class_size;
234 void (*instance_init)(Object *obj);
235 void (*class_init)(ObjectClass *klass, void *data);
236} VirtioPCIDeviceTypeInfo;
237
238
239void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
240
241#endif
242