qapi: Rename target.json to misc-target.json
[qemu/kevin.git] / hw / virtio / virtio-pci.h
blobbfea2892a540160d6144ebdf6c16fae89f7904be
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 "qapi/error.h"
19 #include "hw/pci/msi.h"
20 #include "hw/virtio/virtio-bus.h"
22 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
24 /* virtio-pci-bus */
26 typedef struct VirtioBusState VirtioPCIBusState;
27 typedef struct VirtioBusClass VirtioPCIBusClass;
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)
37 enum {
38 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
39 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
40 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
41 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
42 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
43 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
44 VIRTIO_PCI_FLAG_ATS_BIT,
45 VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
46 VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
47 VIRTIO_PCI_FLAG_INIT_PM_BIT,
50 /* Need to activate work-arounds for buggy guests at vmstate load. */
51 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
52 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
54 /* Performance improves when virtqueue kick processing is decoupled from the
55 * vcpu thread using ioeventfd for some devices. */
56 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
58 /* virtio version flags */
59 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
61 /* migrate extra state */
62 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
64 /* have pio notification for modern device ? */
65 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
66 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
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)
72 /* address space translation service */
73 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
75 /* Init error enabling flags */
76 #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
78 /* Init Link Control register */
79 #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
81 /* Init Power Management */
82 #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
84 typedef struct {
85 MSIMessage msg;
86 int virq;
87 unsigned int users;
88 } VirtIOIRQFD;
91 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
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)
101 typedef struct VirtioPCIClass {
102 PCIDeviceClass parent_class;
103 DeviceRealize parent_dc_realize;
104 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
105 } VirtioPCIClass;
107 typedef struct VirtIOPCIRegion {
108 MemoryRegion mr;
109 uint32_t offset;
110 uint32_t size;
111 uint32_t type;
112 } VirtIOPCIRegion;
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;
122 typedef enum {
123 VIRTIO_PCI_MODE_LEGACY,
124 VIRTIO_PCI_MODE_TRANSITIONAL,
125 VIRTIO_PCI_MODE_MODERN,
126 } VirtIOPCIMode;
128 struct VirtIOPCIProxy {
129 PCIDevice pci_dev;
130 MemoryRegion bar;
131 union {
132 struct {
133 VirtIOPCIRegion common;
134 VirtIOPCIRegion isr;
135 VirtIOPCIRegion device;
136 VirtIOPCIRegion notify;
137 VirtIOPCIRegion notify_pio;
139 VirtIOPCIRegion regs[5];
141 MemoryRegion modern_bar;
142 MemoryRegion io_bar;
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;
147 int config_cap;
148 uint32_t flags;
149 bool disable_modern;
150 bool ignore_backend_features;
151 OnOffAuto disable_legacy;
152 VirtIOPCIMode mode;
153 uint32_t class_code;
154 uint32_t nvectors;
155 uint32_t dfselect;
156 uint32_t gfselect;
157 uint32_t guest_features[2];
158 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
160 VirtIOIRQFD *vector_irqfd;
161 int nvqs_with_notifiers;
162 VirtioBusState bus;
165 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
167 return proxy->mode != VIRTIO_PCI_MODE_LEGACY;
170 static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
172 return proxy->mode != VIRTIO_PCI_MODE_MODERN;
175 static inline bool virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy,
176 Error **errp)
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;
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;
188 proxy->mode = VIRTIO_PCI_MODE_MODERN;
189 return true;
192 static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
194 proxy->mode = VIRTIO_PCI_MODE_LEGACY;
198 * virtio-input-pci: This extends VirtioPCIProxy.
200 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
202 /* Virtio ABI version, if we increment this, we break the guest driver. */
203 #define VIRTIO_PCI_ABI_VERSION 0
205 /* Input for virtio_pci_types_register() */
206 typedef struct VirtioPCIDeviceTypeInfo {
208 * Common base class for the subclasses below.
210 * Required only if transitional_name or non_transitional_name is set.
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.
219 const char *base_name;
221 * Generic device type. Optional.
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.
228 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
229 * but PCI Express is supported only in non-transitional mode.
231 * The only type implemented by QEMU 3.1 and older.
233 const char *generic_name;
235 * The transitional device type. Optional.
237 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
239 const char *transitional_name;
241 * The non-transitional device type. Optional.
243 * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
245 const char *non_transitional_name;
247 /* Parent type. If NULL, TYPE_VIRTIO_PCI is used */
248 const char *parent;
250 /* Same as TypeInfo fields: */
251 size_t instance_size;
252 size_t class_size;
253 void (*instance_init)(Object *obj);
254 void (*class_init)(ObjectClass *klass, void *data);
255 } VirtioPCIDeviceTypeInfo;
257 /* Register virtio-pci type(s). @t must be static. */
258 void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
260 #endif