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
,
44 VIRTIO_PCI_FLAG_AER_BIT
,
45 VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT
,
48 /* Need to activate work-arounds for buggy guests at vmstate load. */
49 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
50 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
52 /* Performance improves when virtqueue kick processing is decoupled from the
53 * vcpu thread using ioeventfd for some devices. */
54 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
56 /* virtio version flags */
57 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
59 /* migrate extra state */
60 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
62 /* have pio notification for modern device ? */
63 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
64 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
66 /* page per vq flag to be used by split drivers within guests */
67 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
68 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
70 /* address space translation service */
71 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
73 /* Init error enabling flags */
74 #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
76 /* Init Link Control register */
77 #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
79 /* Init Power Management */
80 #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
82 /* Init Function Level Reset capability */
83 #define VIRTIO_PCI_FLAG_INIT_FLR (1 << VIRTIO_PCI_FLAG_INIT_FLR_BIT)
85 /* Advanced Error Reporting capability */
86 #define VIRTIO_PCI_FLAG_AER (1 << VIRTIO_PCI_FLAG_AER_BIT)
88 /* Page Aligned Address space Translation Service */
89 #define VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED \
90 (1 << VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT)
99 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
101 #define TYPE_VIRTIO_PCI "virtio-pci"
102 OBJECT_DECLARE_TYPE(VirtIOPCIProxy
, VirtioPCIClass
, VIRTIO_PCI
)
104 struct VirtioPCIClass
{
105 PCIDeviceClass parent_class
;
106 DeviceRealize parent_dc_realize
;
107 void (*realize
)(VirtIOPCIProxy
*vpci_dev
, Error
**errp
);
110 typedef struct VirtIOPCIRegion
{
117 typedef struct VirtIOPCIQueue
{
125 struct VirtIOPCIProxy
{
130 VirtIOPCIRegion common
;
132 VirtIOPCIRegion device
;
133 VirtIOPCIRegion notify
;
134 VirtIOPCIRegion notify_pio
;
136 VirtIOPCIRegion regs
[5];
138 MemoryRegion modern_bar
;
140 uint32_t legacy_io_bar_idx
;
141 uint32_t msix_bar_idx
;
142 uint32_t modern_io_bar_idx
;
143 uint32_t modern_mem_bar_idx
;
147 bool ignore_backend_features
;
148 OnOffAuto disable_legacy
;
153 uint32_t guest_features
[2];
154 VirtIOPCIQueue vqs
[VIRTIO_QUEUE_MAX
];
156 VirtIOIRQFD
*vector_irqfd
;
157 int nvqs_with_notifiers
;
161 static inline bool virtio_pci_modern(VirtIOPCIProxy
*proxy
)
163 return !proxy
->disable_modern
;
166 static inline bool virtio_pci_legacy(VirtIOPCIProxy
*proxy
)
168 return proxy
->disable_legacy
== ON_OFF_AUTO_OFF
;
171 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy
*proxy
)
173 proxy
->disable_modern
= false;
174 proxy
->disable_legacy
= ON_OFF_AUTO_ON
;
177 static inline void virtio_pci_disable_modern(VirtIOPCIProxy
*proxy
)
179 proxy
->disable_modern
= true;
183 * virtio-input-pci: This extends VirtioPCIProxy.
185 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
187 /* Virtio ABI version, if we increment this, we break the guest driver. */
188 #define VIRTIO_PCI_ABI_VERSION 0
190 /* Input for virtio_pci_types_register() */
191 typedef struct VirtioPCIDeviceTypeInfo
{
193 * Common base class for the subclasses below.
195 * Required only if transitional_name or non_transitional_name is set.
197 * We need a separate base type instead of making all types
198 * inherit from generic_name for two reasons:
199 * 1) generic_name implements INTERFACE_PCIE_DEVICE, but
200 * transitional_name does not.
201 * 2) generic_name has the "disable-legacy" and "disable-modern"
202 * properties, transitional_name and non_transitional name don't.
204 const char *base_name
;
206 * Generic device type. Optional.
208 * Supports both transitional and non-transitional modes,
209 * using the disable-legacy and disable-modern properties.
210 * If disable-legacy=auto, (non-)transitional mode is selected
211 * depending on the bus where the device is plugged.
213 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
214 * but PCI Express is supported only in non-transitional mode.
216 * The only type implemented by QEMU 3.1 and older.
218 const char *generic_name
;
220 * The transitional device type. Optional.
222 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
224 const char *transitional_name
;
226 * The non-transitional device type. Optional.
228 * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
230 const char *non_transitional_name
;
232 /* Parent type. If NULL, TYPE_VIRTIO_PCI is used */
235 /* Same as TypeInfo fields: */
236 size_t instance_size
;
238 void (*instance_init
)(Object
*obj
);
239 void (*class_init
)(ObjectClass
*klass
, void *data
);
240 InterfaceInfo
*interfaces
;
241 } VirtioPCIDeviceTypeInfo
;
243 /* Register virtio-pci type(s). @t must be static. */
244 void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo
*t
);
247 * virtio_pci_optimal_num_queues:
248 * @fixed_queues: number of queues that are always present
250 * Returns: The optimal number of queues for a multi-queue device, excluding
253 unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues
);