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