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