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"
22 typedef struct VirtIOPCIProxy VirtIOPCIProxy
;
26 typedef struct VirtioBusState VirtioPCIBusState
;
27 typedef struct VirtioBusClass VirtioPCIBusClass
;
29 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
30 DECLARE_OBJ_CHECKERS(VirtioPCIBusState
, VirtioPCIBusClass
,
31 VIRTIO_PCI_BUS
, TYPE_VIRTIO_PCI_BUS
)
34 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT
,
35 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT
,
36 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT
,
37 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT
,
38 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT
,
39 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT
,
40 VIRTIO_PCI_FLAG_ATS_BIT
,
41 VIRTIO_PCI_FLAG_INIT_DEVERR_BIT
,
42 VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT
,
43 VIRTIO_PCI_FLAG_INIT_PM_BIT
,
44 VIRTIO_PCI_FLAG_INIT_FLR_BIT
,
47 /* Need to activate work-arounds for buggy guests at vmstate load. */
48 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
49 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
51 /* Performance improves when virtqueue kick processing is decoupled from the
52 * vcpu thread using ioeventfd for some devices. */
53 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
55 /* virtio version flags */
56 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
58 /* migrate extra state */
59 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
61 /* have pio notification for modern device ? */
62 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
63 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
65 /* page per vq flag to be used by split drivers within guests */
66 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
67 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
69 /* address space translation service */
70 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
72 /* Init error enabling flags */
73 #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
75 /* Init Link Control register */
76 #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
78 /* Init Power Management */
79 #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
81 /* Init Function Level Reset capability */
82 #define VIRTIO_PCI_FLAG_INIT_FLR (1 << VIRTIO_PCI_FLAG_INIT_FLR_BIT)
91 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
93 #define TYPE_VIRTIO_PCI "virtio-pci"
94 typedef struct VirtioPCIClass VirtioPCIClass
;
95 DECLARE_OBJ_CHECKERS(VirtIOPCIProxy
, VirtioPCIClass
,
96 VIRTIO_PCI
, TYPE_VIRTIO_PCI
)
98 struct VirtioPCIClass
{
99 PCIDeviceClass parent_class
;
100 DeviceRealize parent_dc_realize
;
101 void (*realize
)(VirtIOPCIProxy
*vpci_dev
, Error
**errp
);
104 typedef struct VirtIOPCIRegion
{
111 typedef struct VirtIOPCIQueue
{
119 struct VirtIOPCIProxy
{
124 VirtIOPCIRegion common
;
126 VirtIOPCIRegion device
;
127 VirtIOPCIRegion notify
;
128 VirtIOPCIRegion notify_pio
;
130 VirtIOPCIRegion regs
[5];
132 MemoryRegion modern_bar
;
134 uint32_t legacy_io_bar_idx
;
135 uint32_t msix_bar_idx
;
136 uint32_t modern_io_bar_idx
;
137 uint32_t modern_mem_bar_idx
;
141 bool ignore_backend_features
;
142 OnOffAuto disable_legacy
;
147 uint32_t guest_features
[2];
148 VirtIOPCIQueue vqs
[VIRTIO_QUEUE_MAX
];
150 VirtIOIRQFD
*vector_irqfd
;
151 int nvqs_with_notifiers
;
155 static inline bool virtio_pci_modern(VirtIOPCIProxy
*proxy
)
157 return !proxy
->disable_modern
;
160 static inline bool virtio_pci_legacy(VirtIOPCIProxy
*proxy
)
162 return proxy
->disable_legacy
== ON_OFF_AUTO_OFF
;
165 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy
*proxy
)
167 proxy
->disable_modern
= false;
168 proxy
->disable_legacy
= ON_OFF_AUTO_ON
;
171 static inline void virtio_pci_disable_modern(VirtIOPCIProxy
*proxy
)
173 proxy
->disable_modern
= true;
177 * virtio-input-pci: This extends VirtioPCIProxy.
179 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
181 /* Virtio ABI version, if we increment this, we break the guest driver. */
182 #define VIRTIO_PCI_ABI_VERSION 0
184 /* Input for virtio_pci_types_register() */
185 typedef struct VirtioPCIDeviceTypeInfo
{
187 * Common base class for the subclasses below.
189 * Required only if transitional_name or non_transitional_name is set.
191 * We need a separate base type instead of making all types
192 * inherit from generic_name for two reasons:
193 * 1) generic_name implements INTERFACE_PCIE_DEVICE, but
194 * transitional_name does not.
195 * 2) generic_name has the "disable-legacy" and "disable-modern"
196 * properties, transitional_name and non_transitional name don't.
198 const char *base_name
;
200 * Generic device type. Optional.
202 * Supports both transitional and non-transitional modes,
203 * using the disable-legacy and disable-modern properties.
204 * If disable-legacy=auto, (non-)transitional mode is selected
205 * depending on the bus where the device is plugged.
207 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
208 * but PCI Express is supported only in non-transitional mode.
210 * The only type implemented by QEMU 3.1 and older.
212 const char *generic_name
;
214 * The transitional device type. Optional.
216 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
218 const char *transitional_name
;
220 * The non-transitional device type. Optional.
222 * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
224 const char *non_transitional_name
;
226 /* Parent type. If NULL, TYPE_VIRTIO_PCI is used */
229 /* Same as TypeInfo fields: */
230 size_t instance_size
;
232 void (*instance_init
)(Object
*obj
);
233 void (*class_init
)(ObjectClass
*klass
, void *data
);
234 InterfaceInfo
*interfaces
;
235 } VirtioPCIDeviceTypeInfo
;
237 /* Register virtio-pci type(s). @t must be static. */
238 void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo
*t
);
241 * virtio_pci_optimal_num_queues:
242 * @fixed_queues: number of queues that are always present
244 * Returns: The optimal number of queues for a multi-queue device, excluding
247 unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues
);