4 * Copyright IBM, Corp. 2007
5 * Copyright (c) 2009 CodeSourcery
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"
20 #include "qom/object.h"
25 typedef struct VirtioBusState VirtioPCIBusState
;
26 typedef struct VirtioBusClass VirtioPCIBusClass
;
28 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
29 DECLARE_OBJ_CHECKERS(VirtioPCIBusState
, VirtioPCIBusClass
,
30 VIRTIO_PCI_BUS
, TYPE_VIRTIO_PCI_BUS
)
33 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT
,
34 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT
,
35 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT
,
36 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT
,
37 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT
,
38 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT
,
39 VIRTIO_PCI_FLAG_ATS_BIT
,
40 VIRTIO_PCI_FLAG_INIT_DEVERR_BIT
,
41 VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT
,
42 VIRTIO_PCI_FLAG_INIT_PM_BIT
,
43 VIRTIO_PCI_FLAG_INIT_FLR_BIT
,
46 /* Need to activate work-arounds for buggy guests at vmstate load. */
47 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
48 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
50 /* Performance improves when virtqueue kick processing is decoupled from the
51 * vcpu thread using ioeventfd for some devices. */
52 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
54 /* virtio version flags */
55 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
57 /* migrate extra state */
58 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
60 /* have pio notification for modern device ? */
61 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
62 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
64 /* page per vq flag to be used by split drivers within guests */
65 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
66 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
68 /* address space translation service */
69 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
71 /* Init error enabling flags */
72 #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
74 /* Init Link Control register */
75 #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
77 /* Init Power Management */
78 #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
80 /* Init Function Level Reset capability */
81 #define VIRTIO_PCI_FLAG_INIT_FLR (1 << VIRTIO_PCI_FLAG_INIT_FLR_BIT)
90 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
92 #define TYPE_VIRTIO_PCI "virtio-pci"
93 OBJECT_DECLARE_TYPE(VirtIOPCIProxy
, VirtioPCIClass
, VIRTIO_PCI
)
95 struct VirtioPCIClass
{
96 PCIDeviceClass parent_class
;
97 DeviceRealize parent_dc_realize
;
98 void (*realize
)(VirtIOPCIProxy
*vpci_dev
, Error
**errp
);
101 typedef struct VirtIOPCIRegion
{
108 typedef struct VirtIOPCIQueue
{
116 struct VirtIOPCIProxy
{
121 VirtIOPCIRegion common
;
123 VirtIOPCIRegion device
;
124 VirtIOPCIRegion notify
;
125 VirtIOPCIRegion notify_pio
;
127 VirtIOPCIRegion regs
[5];
129 MemoryRegion modern_bar
;
131 uint32_t legacy_io_bar_idx
;
132 uint32_t msix_bar_idx
;
133 uint32_t modern_io_bar_idx
;
134 uint32_t modern_mem_bar_idx
;
138 bool ignore_backend_features
;
139 OnOffAuto disable_legacy
;
144 uint32_t guest_features
[2];
145 VirtIOPCIQueue vqs
[VIRTIO_QUEUE_MAX
];
147 VirtIOIRQFD
*vector_irqfd
;
148 int nvqs_with_notifiers
;
152 static inline bool virtio_pci_modern(VirtIOPCIProxy
*proxy
)
154 return !proxy
->disable_modern
;
157 static inline bool virtio_pci_legacy(VirtIOPCIProxy
*proxy
)
159 return proxy
->disable_legacy
== ON_OFF_AUTO_OFF
;
162 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy
*proxy
)
164 proxy
->disable_modern
= false;
165 proxy
->disable_legacy
= ON_OFF_AUTO_ON
;
168 static inline void virtio_pci_disable_modern(VirtIOPCIProxy
*proxy
)
170 proxy
->disable_modern
= true;
174 * virtio-input-pci: This extends VirtioPCIProxy.
176 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
178 /* Virtio ABI version, if we increment this, we break the guest driver. */
179 #define VIRTIO_PCI_ABI_VERSION 0
181 /* Input for virtio_pci_types_register() */
182 typedef struct VirtioPCIDeviceTypeInfo
{
184 * Common base class for the subclasses below.
186 * Required only if transitional_name or non_transitional_name is set.
188 * We need a separate base type instead of making all types
189 * inherit from generic_name for two reasons:
190 * 1) generic_name implements INTERFACE_PCIE_DEVICE, but
191 * transitional_name does not.
192 * 2) generic_name has the "disable-legacy" and "disable-modern"
193 * properties, transitional_name and non_transitional name don't.
195 const char *base_name
;
197 * Generic device type. Optional.
199 * Supports both transitional and non-transitional modes,
200 * using the disable-legacy and disable-modern properties.
201 * If disable-legacy=auto, (non-)transitional mode is selected
202 * depending on the bus where the device is plugged.
204 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
205 * but PCI Express is supported only in non-transitional mode.
207 * The only type implemented by QEMU 3.1 and older.
209 const char *generic_name
;
211 * The transitional device type. Optional.
213 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
215 const char *transitional_name
;
217 * The non-transitional device type. Optional.
219 * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
221 const char *non_transitional_name
;
223 /* Parent type. If NULL, TYPE_VIRTIO_PCI is used */
226 /* Same as TypeInfo fields: */
227 size_t instance_size
;
229 void (*instance_init
)(Object
*obj
);
230 void (*class_init
)(ObjectClass
*klass
, void *data
);
231 InterfaceInfo
*interfaces
;
232 } VirtioPCIDeviceTypeInfo
;
234 /* Register virtio-pci type(s). @t must be static. */
235 void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo
*t
);
238 * virtio_pci_optimal_num_queues:
239 * @fixed_queues: number of queues that are always present
241 * Returns: The optimal number of queues for a multi-queue device, excluding
244 unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues
);