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 VIRTIO_PCI_FLAG_AER_BIT,
45 VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT,
46};
47
48
49#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
50 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
51
52
53
54#define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
55
56
57#define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
58
59
60#define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
61
62
63#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
64 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
65
66
67#define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
68 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
69
70
71#define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
72
73
74#define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
75
76
77#define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
78
79
80#define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
81
82
83#define VIRTIO_PCI_FLAG_INIT_FLR (1 << VIRTIO_PCI_FLAG_INIT_FLR_BIT)
84
85
86#define VIRTIO_PCI_FLAG_AER (1 << VIRTIO_PCI_FLAG_AER_BIT)
87
88
89#define VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED \
90 (1 << VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT)
91
92typedef struct {
93 MSIMessage msg;
94 int virq;
95 unsigned int users;
96} VirtIOIRQFD;
97
98
99
100
101#define TYPE_VIRTIO_PCI "virtio-pci"
102OBJECT_DECLARE_TYPE(VirtIOPCIProxy, VirtioPCIClass, VIRTIO_PCI)
103
104struct VirtioPCIClass {
105 PCIDeviceClass parent_class;
106 DeviceRealize parent_dc_realize;
107 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
108};
109
110typedef struct VirtIOPCIRegion {
111 MemoryRegion mr;
112 uint32_t offset;
113 uint32_t size;
114 uint32_t type;
115} VirtIOPCIRegion;
116
117typedef struct VirtIOPCIQueue {
118 uint16_t num;
119 bool enabled;
120
121
122
123
124 bool reset;
125 uint32_t desc[2];
126 uint32_t avail[2];
127 uint32_t used[2];
128} VirtIOPCIQueue;
129
130struct VirtIOPCIProxy {
131 PCIDevice pci_dev;
132 MemoryRegion bar;
133 union {
134 struct {
135 VirtIOPCIRegion common;
136 VirtIOPCIRegion isr;
137 VirtIOPCIRegion device;
138 VirtIOPCIRegion notify;
139 VirtIOPCIRegion notify_pio;
140 };
141 VirtIOPCIRegion regs[5];
142 };
143 MemoryRegion modern_bar;
144 MemoryRegion io_bar;
145 uint32_t legacy_io_bar_idx;
146 uint32_t msix_bar_idx;
147 uint32_t modern_io_bar_idx;
148 uint32_t modern_mem_bar_idx;
149 int config_cap;
150 uint32_t flags;
151 bool disable_modern;
152 bool ignore_backend_features;
153 OnOffAuto disable_legacy;
154
155 uint16_t trans_devid;
156 uint32_t class_code;
157 uint32_t nvectors;
158 uint32_t dfselect;
159 uint32_t gfselect;
160 uint32_t guest_features[2];
161 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
162
163 VirtIOIRQFD *vector_irqfd;
164 int nvqs_with_notifiers;
165 VirtioBusState bus;
166};
167
168static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
169{
170 return !proxy->disable_modern;
171}
172
173static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
174{
175 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
176}
177
178static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
179{
180 proxy->disable_modern = false;
181 proxy->disable_legacy = ON_OFF_AUTO_ON;
182}
183
184static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
185{
186 proxy->disable_modern = true;
187}
188
189uint16_t virtio_pci_get_trans_devid(uint16_t device_id);
190uint16_t virtio_pci_get_class_id(uint16_t device_id);
191
192
193
194
195#define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
196
197
198#define VIRTIO_PCI_ABI_VERSION 0
199
200
201typedef struct VirtioPCIDeviceTypeInfo {
202
203
204
205
206
207
208
209
210
211
212
213
214 const char *base_name;
215
216
217
218
219
220
221
222
223
224
225
226
227
228 const char *generic_name;
229
230
231
232
233
234 const char *transitional_name;
235
236
237
238
239
240 const char *non_transitional_name;
241
242
243 const char *parent;
244
245
246 size_t instance_size;
247 size_t class_size;
248 void (*instance_init)(Object *obj);
249 void (*class_init)(ObjectClass *klass, void *data);
250 InterfaceInfo *interfaces;
251} VirtioPCIDeviceTypeInfo;
252
253
254void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
255
256
257
258
259
260
261
262
263unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues);
264void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueue *vq,
265 int n, bool assign,
266 bool with_irqfd);
267#endif
268