]>
Commit | Line | Data |
---|---|---|
9fe1ebeb AK |
1 | /* |
2 | * Virtio PCI Bindings | |
3 | * | |
4 | * Copyright IBM, Corp. 2007 | |
5 | * Copyright (c) 2009 CodeSourcery | |
6 | * | |
7 | * Authors: | |
8 | * Anthony Liguori <[email protected]> | |
9 | * Paul Brook <[email protected]> | |
10 | * | |
11 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
12 | * the COPYING file in the top-level directory. | |
13 | */ | |
14 | ||
15 | #ifndef QEMU_VIRTIO_PCI_H | |
16 | #define QEMU_VIRTIO_PCI_H | |
17 | ||
f2784eed | 18 | #include "qapi/error.h" |
cf7c3f0c | 19 | #include "hw/pci/msi.h" |
0d09e41a | 20 | #include "hw/virtio/virtio-bus.h" |
b307d308 | 21 | |
085bccb7 FK |
22 | typedef struct VirtIOPCIProxy VirtIOPCIProxy; |
23 | ||
0a2acf5e FK |
24 | /* virtio-pci-bus */ |
25 | ||
26 | typedef struct VirtioBusState VirtioPCIBusState; | |
27 | typedef struct VirtioBusClass VirtioPCIBusClass; | |
28 | ||
29 | #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus" | |
30 | #define VIRTIO_PCI_BUS(obj) \ | |
31 | OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS) | |
32 | #define VIRTIO_PCI_BUS_GET_CLASS(obj) \ | |
33 | OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS) | |
34 | #define VIRTIO_PCI_BUS_CLASS(klass) \ | |
35 | OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS) | |
9fe1ebeb | 36 | |
fc1769b7 MA |
37 | enum { |
38 | VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT, | |
39 | VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, | |
fc1769b7 MA |
40 | VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT, |
41 | VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT, | |
42 | VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT, | |
d9997d89 | 43 | VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT, |
615c4ed2 | 44 | VIRTIO_PCI_FLAG_ATS_BIT, |
c2cabb34 | 45 | VIRTIO_PCI_FLAG_INIT_DEVERR_BIT, |
d584f1b9 | 46 | VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT, |
27ce0f3a | 47 | VIRTIO_PCI_FLAG_INIT_PM_BIT, |
fc1769b7 MA |
48 | }; |
49 | ||
68a27b20 | 50 | /* Need to activate work-arounds for buggy guests at vmstate load. */ |
68a27b20 MT |
51 | #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \ |
52 | (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT) | |
53 | ||
5745e38a AK |
54 | /* Performance improves when virtqueue kick processing is decoupled from the |
55 | * vcpu thread using ioeventfd for some devices. */ | |
5745e38a AK |
56 | #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT) |
57 | ||
e266d421 | 58 | /* virtio version flags */ |
1811e64c | 59 | #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT) |
e266d421 | 60 | |
a6df8adf | 61 | /* migrate extra state */ |
a6df8adf JW |
62 | #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT) |
63 | ||
9824d2a3 | 64 | /* have pio notification for modern device ? */ |
9824d2a3 JW |
65 | #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \ |
66 | (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT) | |
67 | ||
d9997d89 MA |
68 | /* page per vq flag to be used by split drivers within guests */ |
69 | #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \ | |
70 | (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT) | |
71 | ||
615c4ed2 JW |
72 | /* address space translation service */ |
73 | #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT) | |
74 | ||
c2cabb34 MA |
75 | /* Init error enabling flags */ |
76 | #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT) | |
77 | ||
d584f1b9 MA |
78 | /* Init Link Control register */ |
79 | #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT) | |
80 | ||
27ce0f3a MA |
81 | /* Init Power Management */ |
82 | #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT) | |
83 | ||
7d37d351 | 84 | typedef struct { |
774345f9 | 85 | MSIMessage msg; |
7d37d351 JK |
86 | int virq; |
87 | unsigned int users; | |
88 | } VirtIOIRQFD; | |
89 | ||
085bccb7 FK |
90 | /* |
91 | * virtio-pci: This is the PCIDevice which has a virtio-pci-bus. | |
92 | */ | |
93 | #define TYPE_VIRTIO_PCI "virtio-pci" | |
94 | #define VIRTIO_PCI_GET_CLASS(obj) \ | |
95 | OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI) | |
96 | #define VIRTIO_PCI_CLASS(klass) \ | |
97 | OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI) | |
98 | #define VIRTIO_PCI(obj) \ | |
99 | OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI) | |
100 | ||
101 | typedef struct VirtioPCIClass { | |
102 | PCIDeviceClass parent_class; | |
0560b0e9 | 103 | DeviceRealize parent_dc_realize; |
fc079951 | 104 | void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp); |
085bccb7 FK |
105 | } VirtioPCIClass; |
106 | ||
588255ad GH |
107 | typedef struct VirtIOPCIRegion { |
108 | MemoryRegion mr; | |
a3cc2e81 | 109 | uint32_t offset; |
b6ce27a5 | 110 | uint32_t size; |
fc004905 | 111 | uint32_t type; |
588255ad GH |
112 | } VirtIOPCIRegion; |
113 | ||
a6df8adf JW |
114 | typedef struct VirtIOPCIQueue { |
115 | uint16_t num; | |
116 | bool enabled; | |
117 | uint32_t desc[2]; | |
118 | uint32_t avail[2]; | |
119 | uint32_t used[2]; | |
120 | } VirtIOPCIQueue; | |
121 | ||
f2784eed DB |
122 | typedef enum { |
123 | VIRTIO_PCI_MODE_LEGACY, | |
124 | VIRTIO_PCI_MODE_TRANSITIONAL, | |
125 | VIRTIO_PCI_MODE_MODERN, | |
126 | } VirtIOPCIMode; | |
127 | ||
085bccb7 | 128 | struct VirtIOPCIProxy { |
9fe1ebeb | 129 | PCIDevice pci_dev; |
da146d0a | 130 | MemoryRegion bar; |
a93c8d82 AK |
131 | union { |
132 | struct { | |
133 | VirtIOPCIRegion common; | |
134 | VirtIOPCIRegion isr; | |
135 | VirtIOPCIRegion device; | |
136 | VirtIOPCIRegion notify; | |
137 | VirtIOPCIRegion notify_pio; | |
138 | }; | |
139 | VirtIOPCIRegion regs[5]; | |
140 | }; | |
dfb8e184 | 141 | MemoryRegion modern_bar; |
9824d2a3 | 142 | MemoryRegion io_bar; |
7a25126d CF |
143 | uint32_t legacy_io_bar_idx; |
144 | uint32_t msix_bar_idx; | |
145 | uint32_t modern_io_bar_idx; | |
146 | uint32_t modern_mem_bar_idx; | |
ada434cd | 147 | int config_cap; |
9fe1ebeb | 148 | uint32_t flags; |
9a4c0e22 | 149 | bool disable_modern; |
66d1c4c1 | 150 | bool ignore_backend_features; |
9a4c0e22 | 151 | OnOffAuto disable_legacy; |
f2784eed | 152 | VirtIOPCIMode mode; |
9fe1ebeb AK |
153 | uint32_t class_code; |
154 | uint32_t nvectors; | |
dfb8e184 MT |
155 | uint32_t dfselect; |
156 | uint32_t gfselect; | |
157 | uint32_t guest_features[2]; | |
a6df8adf | 158 | VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX]; |
dfb8e184 | 159 | |
7d37d351 | 160 | VirtIOIRQFD *vector_irqfd; |
2d620f59 | 161 | int nvqs_with_notifiers; |
085bccb7 FK |
162 | VirtioBusState bus; |
163 | }; | |
9fe1ebeb | 164 | |
9a4c0e22 MA |
165 | static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy) |
166 | { | |
f2784eed | 167 | return proxy->mode != VIRTIO_PCI_MODE_LEGACY; |
9a4c0e22 MA |
168 | } |
169 | ||
170 | static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy) | |
171 | { | |
f2784eed | 172 | return proxy->mode != VIRTIO_PCI_MODE_MODERN; |
9a4c0e22 MA |
173 | } |
174 | ||
f2784eed DB |
175 | static inline bool virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy, |
176 | Error **errp) | |
9a4c0e22 | 177 | { |
f2784eed DB |
178 | if (proxy->disable_legacy == ON_OFF_AUTO_OFF) { |
179 | error_setg(errp, "Unable to set disable-legacy=off on a virtio-1.0 " | |
180 | "only device"); | |
181 | return false; | |
182 | } | |
183 | if (proxy->disable_modern == true) { | |
184 | error_setg(errp, "Unable to set disable-modern=on on a virtio-1.0 " | |
185 | "only device"); | |
186 | return false; | |
187 | } | |
188 | proxy->mode = VIRTIO_PCI_MODE_MODERN; | |
189 | return true; | |
9a4c0e22 | 190 | } |
bc7b90a0 | 191 | |
d1b4259f MC |
192 | static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy) |
193 | { | |
f2784eed | 194 | proxy->mode = VIRTIO_PCI_MODE_LEGACY; |
d1b4259f MC |
195 | } |
196 | ||
f958c8aa GH |
197 | /* |
198 | * virtio-input-pci: This extends VirtioPCIProxy. | |
199 | */ | |
200 | #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci" | |
710e2d90 | 201 | |
befeac45 MT |
202 | /* Virtio ABI version, if we increment this, we break the guest driver. */ |
203 | #define VIRTIO_PCI_ABI_VERSION 0 | |
204 | ||
a4ee4c8b EH |
205 | /* Input for virtio_pci_types_register() */ |
206 | typedef struct VirtioPCIDeviceTypeInfo { | |
207 | /* | |
208 | * Common base class for the subclasses below. | |
209 | * | |
210 | * Required only if transitional_name or non_transitional_name is set. | |
211 | * | |
212 | * We need a separate base type instead of making all types | |
213 | * inherit from generic_name for two reasons: | |
214 | * 1) generic_name implements INTERFACE_PCIE_DEVICE, but | |
215 | * transitional_name does not. | |
216 | * 2) generic_name has the "disable-legacy" and "disable-modern" | |
217 | * properties, transitional_name and non_transitional name don't. | |
218 | */ | |
219 | const char *base_name; | |
220 | /* | |
221 | * Generic device type. Optional. | |
222 | * | |
223 | * Supports both transitional and non-transitional modes, | |
224 | * using the disable-legacy and disable-modern properties. | |
225 | * If disable-legacy=auto, (non-)transitional mode is selected | |
226 | * depending on the bus where the device is plugged. | |
227 | * | |
228 | * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE, | |
229 | * but PCI Express is supported only in non-transitional mode. | |
230 | * | |
231 | * The only type implemented by QEMU 3.1 and older. | |
232 | */ | |
233 | const char *generic_name; | |
234 | /* | |
235 | * The transitional device type. Optional. | |
236 | * | |
237 | * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE. | |
238 | */ | |
239 | const char *transitional_name; | |
240 | /* | |
241 | * The non-transitional device type. Optional. | |
242 | * | |
243 | * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only. | |
244 | */ | |
245 | const char *non_transitional_name; | |
246 | ||
247 | /* Parent type. If NULL, TYPE_VIRTIO_PCI is used */ | |
248 | const char *parent; | |
249 | ||
250 | /* Same as TypeInfo fields: */ | |
251 | size_t instance_size; | |
8ea90ee6 | 252 | size_t class_size; |
a4ee4c8b EH |
253 | void (*instance_init)(Object *obj); |
254 | void (*class_init)(ObjectClass *klass, void *data); | |
1e33b513 | 255 | InterfaceInfo *interfaces; |
a4ee4c8b EH |
256 | } VirtioPCIDeviceTypeInfo; |
257 | ||
258 | /* Register virtio-pci type(s). @t must be static. */ | |
259 | void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t); | |
260 | ||
9fe1ebeb | 261 | #endif |