virtio: split virtio net bits from virtio-pci
[qemu/ar7.git] / hw / virtio / virtio-pci.h
blob8bfd4b9601f053eaefdbcc7d1c293dcace646dfa
1 /*
2 * Virtio PCI Bindings
4 * Copyright IBM, Corp. 2007
5 * Copyright (c) 2009 CodeSourcery
7 * Authors:
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Paul Brook <paul@codesourcery.com>
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
15 #ifndef QEMU_VIRTIO_PCI_H
16 #define QEMU_VIRTIO_PCI_H
18 #include "hw/pci/msi.h"
19 #include "hw/virtio/virtio-serial.h"
20 #include "hw/virtio/virtio-bus.h"
21 #include "hw/virtio/virtio-gpu.h"
22 #include "hw/virtio/virtio-crypto.h"
24 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
25 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
26 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
27 typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
29 /* virtio-pci-bus */
31 typedef struct VirtioBusState VirtioPCIBusState;
32 typedef struct VirtioBusClass VirtioPCIBusClass;
34 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
35 #define VIRTIO_PCI_BUS(obj) \
36 OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
37 #define VIRTIO_PCI_BUS_GET_CLASS(obj) \
38 OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
39 #define VIRTIO_PCI_BUS_CLASS(klass) \
40 OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
42 enum {
43 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
44 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
45 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
46 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
47 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
48 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
49 VIRTIO_PCI_FLAG_ATS_BIT,
50 VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
51 VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
52 VIRTIO_PCI_FLAG_INIT_PM_BIT,
55 /* Need to activate work-arounds for buggy guests at vmstate load. */
56 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
57 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
59 /* Performance improves when virtqueue kick processing is decoupled from the
60 * vcpu thread using ioeventfd for some devices. */
61 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
63 /* virtio version flags */
64 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
66 /* migrate extra state */
67 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
69 /* have pio notification for modern device ? */
70 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
71 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
73 /* page per vq flag to be used by split drivers within guests */
74 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
75 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
77 /* address space translation service */
78 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
80 /* Init error enabling flags */
81 #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
83 /* Init Link Control register */
84 #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
86 /* Init Power Management */
87 #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
89 typedef struct {
90 MSIMessage msg;
91 int virq;
92 unsigned int users;
93 } VirtIOIRQFD;
96 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
98 #define TYPE_VIRTIO_PCI "virtio-pci"
99 #define VIRTIO_PCI_GET_CLASS(obj) \
100 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
101 #define VIRTIO_PCI_CLASS(klass) \
102 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
103 #define VIRTIO_PCI(obj) \
104 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
106 typedef struct VirtioPCIClass {
107 PCIDeviceClass parent_class;
108 DeviceRealize parent_dc_realize;
109 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
110 } VirtioPCIClass;
112 typedef struct VirtIOPCIRegion {
113 MemoryRegion mr;
114 uint32_t offset;
115 uint32_t size;
116 uint32_t type;
117 } VirtIOPCIRegion;
119 typedef struct VirtIOPCIQueue {
120 uint16_t num;
121 bool enabled;
122 uint32_t desc[2];
123 uint32_t avail[2];
124 uint32_t used[2];
125 } VirtIOPCIQueue;
127 struct VirtIOPCIProxy {
128 PCIDevice pci_dev;
129 MemoryRegion bar;
130 union {
131 struct {
132 VirtIOPCIRegion common;
133 VirtIOPCIRegion isr;
134 VirtIOPCIRegion device;
135 VirtIOPCIRegion notify;
136 VirtIOPCIRegion notify_pio;
138 VirtIOPCIRegion regs[5];
140 MemoryRegion modern_bar;
141 MemoryRegion io_bar;
142 uint32_t legacy_io_bar_idx;
143 uint32_t msix_bar_idx;
144 uint32_t modern_io_bar_idx;
145 uint32_t modern_mem_bar_idx;
146 int config_cap;
147 uint32_t flags;
148 bool disable_modern;
149 bool ignore_backend_features;
150 OnOffAuto disable_legacy;
151 uint32_t class_code;
152 uint32_t nvectors;
153 uint32_t dfselect;
154 uint32_t gfselect;
155 uint32_t guest_features[2];
156 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
158 VirtIOIRQFD *vector_irqfd;
159 int nvqs_with_notifiers;
160 VirtioBusState bus;
163 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
165 return !proxy->disable_modern;
168 static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
170 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
173 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
175 proxy->disable_modern = false;
176 proxy->disable_legacy = ON_OFF_AUTO_ON;
179 static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
181 proxy->disable_modern = true;
185 * virtio-serial-pci: This extends VirtioPCIProxy.
187 #define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci-base"
188 #define VIRTIO_SERIAL_PCI(obj) \
189 OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
191 struct VirtIOSerialPCI {
192 VirtIOPCIProxy parent_obj;
193 VirtIOSerial vdev;
197 * virtio-input-pci: This extends VirtioPCIProxy.
199 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
202 * virtio-gpu-pci: This extends VirtioPCIProxy.
204 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
205 #define VIRTIO_GPU_PCI(obj) \
206 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
208 struct VirtIOGPUPCI {
209 VirtIOPCIProxy parent_obj;
210 VirtIOGPU vdev;
214 * virtio-crypto-pci: This extends VirtioPCIProxy.
216 #define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
217 #define VIRTIO_CRYPTO_PCI(obj) \
218 OBJECT_CHECK(VirtIOCryptoPCI, (obj), TYPE_VIRTIO_CRYPTO_PCI)
220 struct VirtIOCryptoPCI {
221 VirtIOPCIProxy parent_obj;
222 VirtIOCrypto vdev;
225 /* Virtio ABI version, if we increment this, we break the guest driver. */
226 #define VIRTIO_PCI_ABI_VERSION 0
228 /* Input for virtio_pci_types_register() */
229 typedef struct VirtioPCIDeviceTypeInfo {
231 * Common base class for the subclasses below.
233 * Required only if transitional_name or non_transitional_name is set.
235 * We need a separate base type instead of making all types
236 * inherit from generic_name for two reasons:
237 * 1) generic_name implements INTERFACE_PCIE_DEVICE, but
238 * transitional_name does not.
239 * 2) generic_name has the "disable-legacy" and "disable-modern"
240 * properties, transitional_name and non_transitional name don't.
242 const char *base_name;
244 * Generic device type. Optional.
246 * Supports both transitional and non-transitional modes,
247 * using the disable-legacy and disable-modern properties.
248 * If disable-legacy=auto, (non-)transitional mode is selected
249 * depending on the bus where the device is plugged.
251 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
252 * but PCI Express is supported only in non-transitional mode.
254 * The only type implemented by QEMU 3.1 and older.
256 const char *generic_name;
258 * The transitional device type. Optional.
260 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
262 const char *transitional_name;
264 * The non-transitional device type. Optional.
266 * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
268 const char *non_transitional_name;
270 /* Parent type. If NULL, TYPE_VIRTIO_PCI is used */
271 const char *parent;
273 /* Same as TypeInfo fields: */
274 size_t instance_size;
275 void (*instance_init)(Object *obj);
276 void (*class_init)(ObjectClass *klass, void *data);
277 } VirtioPCIDeviceTypeInfo;
279 /* Register virtio-pci type(s). @t must be static. */
280 void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
282 #endif