s390/css: handle CCW_FLAG_SKIP
[qemu/ar7.git] / hw / virtio / virtio-pci.h
blob18581854cae139e4db21796c7fd7539dc8141691
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-bus.h"
21 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
23 /* virtio-pci-bus */
25 typedef struct VirtioBusState VirtioPCIBusState;
26 typedef struct VirtioBusClass VirtioPCIBusClass;
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)
36 enum {
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,
49 /* Need to activate work-arounds for buggy guests at vmstate load. */
50 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
51 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
53 /* Performance improves when virtqueue kick processing is decoupled from the
54 * vcpu thread using ioeventfd for some devices. */
55 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
57 /* virtio version flags */
58 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
60 /* migrate extra state */
61 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
63 /* have pio notification for modern device ? */
64 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
65 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
67 /* page per vq flag to be used by split drivers within guests */
68 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
69 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
71 /* address space translation service */
72 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
74 /* Init error enabling flags */
75 #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
77 /* Init Link Control register */
78 #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
80 /* Init Power Management */
81 #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
83 typedef struct {
84 MSIMessage msg;
85 int virq;
86 unsigned int users;
87 } VirtIOIRQFD;
90 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
92 #define TYPE_VIRTIO_PCI "virtio-pci"
93 #define VIRTIO_PCI_GET_CLASS(obj) \
94 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
95 #define VIRTIO_PCI_CLASS(klass) \
96 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
97 #define VIRTIO_PCI(obj) \
98 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
100 typedef struct VirtioPCIClass {
101 PCIDeviceClass parent_class;
102 DeviceRealize parent_dc_realize;
103 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
104 } VirtioPCIClass;
106 typedef struct VirtIOPCIRegion {
107 MemoryRegion mr;
108 uint32_t offset;
109 uint32_t size;
110 uint32_t type;
111 } VirtIOPCIRegion;
113 typedef struct VirtIOPCIQueue {
114 uint16_t num;
115 bool enabled;
116 uint32_t desc[2];
117 uint32_t avail[2];
118 uint32_t used[2];
119 } VirtIOPCIQueue;
121 struct VirtIOPCIProxy {
122 PCIDevice pci_dev;
123 MemoryRegion bar;
124 union {
125 struct {
126 VirtIOPCIRegion common;
127 VirtIOPCIRegion isr;
128 VirtIOPCIRegion device;
129 VirtIOPCIRegion notify;
130 VirtIOPCIRegion notify_pio;
132 VirtIOPCIRegion regs[5];
134 MemoryRegion modern_bar;
135 MemoryRegion io_bar;
136 uint32_t legacy_io_bar_idx;
137 uint32_t msix_bar_idx;
138 uint32_t modern_io_bar_idx;
139 uint32_t modern_mem_bar_idx;
140 int config_cap;
141 uint32_t flags;
142 bool disable_modern;
143 bool ignore_backend_features;
144 OnOffAuto disable_legacy;
145 uint32_t class_code;
146 uint32_t nvectors;
147 uint32_t dfselect;
148 uint32_t gfselect;
149 uint32_t guest_features[2];
150 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
152 VirtIOIRQFD *vector_irqfd;
153 int nvqs_with_notifiers;
154 VirtioBusState bus;
157 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
159 return !proxy->disable_modern;
162 static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
164 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
167 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
169 proxy->disable_modern = false;
170 proxy->disable_legacy = ON_OFF_AUTO_ON;
173 static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
175 proxy->disable_modern = true;
179 * virtio-input-pci: This extends VirtioPCIProxy.
181 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
183 /* Virtio ABI version, if we increment this, we break the guest driver. */
184 #define VIRTIO_PCI_ABI_VERSION 0
186 /* Input for virtio_pci_types_register() */
187 typedef struct VirtioPCIDeviceTypeInfo {
189 * Common base class for the subclasses below.
191 * Required only if transitional_name or non_transitional_name is set.
193 * We need a separate base type instead of making all types
194 * inherit from generic_name for two reasons:
195 * 1) generic_name implements INTERFACE_PCIE_DEVICE, but
196 * transitional_name does not.
197 * 2) generic_name has the "disable-legacy" and "disable-modern"
198 * properties, transitional_name and non_transitional name don't.
200 const char *base_name;
202 * Generic device type. Optional.
204 * Supports both transitional and non-transitional modes,
205 * using the disable-legacy and disable-modern properties.
206 * If disable-legacy=auto, (non-)transitional mode is selected
207 * depending on the bus where the device is plugged.
209 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
210 * but PCI Express is supported only in non-transitional mode.
212 * The only type implemented by QEMU 3.1 and older.
214 const char *generic_name;
216 * The transitional device type. Optional.
218 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
220 const char *transitional_name;
222 * The non-transitional device type. Optional.
224 * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
226 const char *non_transitional_name;
228 /* Parent type. If NULL, TYPE_VIRTIO_PCI is used */
229 const char *parent;
231 /* Same as TypeInfo fields: */
232 size_t instance_size;
233 size_t class_size;
234 void (*instance_init)(Object *obj);
235 void (*class_init)(ObjectClass *klass, void *data);
236 } VirtioPCIDeviceTypeInfo;
238 /* Register virtio-pci type(s). @t must be static. */
239 void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
241 #endif