]> git.proxmox.com Git - mirror_qemu.git/blame - hw/virtio/virtio-pci.h
Use DECLARE_*CHECKER* macros
[mirror_qemu.git] / hw / virtio / virtio-pci.h
CommitLineData
9fe1ebeb
AK
1/*
2 * Virtio PCI Bindings
3 *
4 * Copyright IBM, Corp. 2007
5 * Copyright (c) 2009 CodeSourcery
6 *
7 * Authors:
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Paul Brook <paul@codesourcery.com>
10 *
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
13 */
14
15#ifndef QEMU_VIRTIO_PCI_H
16#define QEMU_VIRTIO_PCI_H
17
cf7c3f0c 18#include "hw/pci/msi.h"
0d09e41a 19#include "hw/virtio/virtio-bus.h"
db1015e9 20#include "qom/object.h"
b307d308 21
085bccb7
FK
22typedef struct VirtIOPCIProxy VirtIOPCIProxy;
23
0a2acf5e
FK
24/* virtio-pci-bus */
25
26typedef struct VirtioBusState VirtioPCIBusState;
27typedef struct VirtioBusClass VirtioPCIBusClass;
28
29#define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
8110fa1d
EH
30DECLARE_OBJ_CHECKERS(VirtioPCIBusState, VirtioPCIBusClass,
31 VIRTIO_PCI_BUS, TYPE_VIRTIO_PCI_BUS)
9fe1ebeb 32
fc1769b7
MA
33enum {
34 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
35 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
fc1769b7
MA
36 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
37 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
38 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
d9997d89 39 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
615c4ed2 40 VIRTIO_PCI_FLAG_ATS_BIT,
c2cabb34 41 VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
d584f1b9 42 VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
27ce0f3a 43 VIRTIO_PCI_FLAG_INIT_PM_BIT,
eb1556c4 44 VIRTIO_PCI_FLAG_INIT_FLR_BIT,
fc1769b7
MA
45};
46
68a27b20 47/* Need to activate work-arounds for buggy guests at vmstate load. */
68a27b20
MT
48#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
49 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
50
5745e38a
AK
51/* Performance improves when virtqueue kick processing is decoupled from the
52 * vcpu thread using ioeventfd for some devices. */
5745e38a
AK
53#define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
54
e266d421 55/* virtio version flags */
1811e64c 56#define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
e266d421 57
a6df8adf 58/* migrate extra state */
a6df8adf
JW
59#define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
60
9824d2a3 61/* have pio notification for modern device ? */
9824d2a3
JW
62#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
63 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
64
d9997d89
MA
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)
68
615c4ed2
JW
69/* address space translation service */
70#define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
71
c2cabb34
MA
72/* Init error enabling flags */
73#define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
74
d584f1b9
MA
75/* Init Link Control register */
76#define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
77
27ce0f3a
MA
78/* Init Power Management */
79#define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
80
eb1556c4
JS
81/* Init Function Level Reset capability */
82#define VIRTIO_PCI_FLAG_INIT_FLR (1 << VIRTIO_PCI_FLAG_INIT_FLR_BIT)
83
7d37d351 84typedef struct {
774345f9 85 MSIMessage msg;
7d37d351
JK
86 int virq;
87 unsigned int users;
88} VirtIOIRQFD;
89
085bccb7
FK
90/*
91 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
92 */
93#define TYPE_VIRTIO_PCI "virtio-pci"
db1015e9 94typedef struct VirtioPCIClass VirtioPCIClass;
8110fa1d
EH
95DECLARE_OBJ_CHECKERS(VirtIOPCIProxy, VirtioPCIClass,
96 VIRTIO_PCI, TYPE_VIRTIO_PCI)
085bccb7 97
db1015e9 98struct VirtioPCIClass {
085bccb7 99 PCIDeviceClass parent_class;
0560b0e9 100 DeviceRealize parent_dc_realize;
fc079951 101 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
db1015e9 102};
085bccb7 103
588255ad
GH
104typedef struct VirtIOPCIRegion {
105 MemoryRegion mr;
a3cc2e81 106 uint32_t offset;
b6ce27a5 107 uint32_t size;
fc004905 108 uint32_t type;
588255ad
GH
109} VirtIOPCIRegion;
110
a6df8adf
JW
111typedef struct VirtIOPCIQueue {
112 uint16_t num;
113 bool enabled;
114 uint32_t desc[2];
115 uint32_t avail[2];
116 uint32_t used[2];
117} VirtIOPCIQueue;
118
085bccb7 119struct VirtIOPCIProxy {
9fe1ebeb 120 PCIDevice pci_dev;
da146d0a 121 MemoryRegion bar;
a93c8d82
AK
122 union {
123 struct {
124 VirtIOPCIRegion common;
125 VirtIOPCIRegion isr;
126 VirtIOPCIRegion device;
127 VirtIOPCIRegion notify;
128 VirtIOPCIRegion notify_pio;
129 };
130 VirtIOPCIRegion regs[5];
131 };
dfb8e184 132 MemoryRegion modern_bar;
9824d2a3 133 MemoryRegion io_bar;
7a25126d
CF
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;
ada434cd 138 int config_cap;
9fe1ebeb 139 uint32_t flags;
9a4c0e22 140 bool disable_modern;
66d1c4c1 141 bool ignore_backend_features;
9a4c0e22 142 OnOffAuto disable_legacy;
9fe1ebeb
AK
143 uint32_t class_code;
144 uint32_t nvectors;
dfb8e184
MT
145 uint32_t dfselect;
146 uint32_t gfselect;
147 uint32_t guest_features[2];
a6df8adf 148 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
dfb8e184 149
7d37d351 150 VirtIOIRQFD *vector_irqfd;
2d620f59 151 int nvqs_with_notifiers;
085bccb7
FK
152 VirtioBusState bus;
153};
9fe1ebeb 154
9a4c0e22
MA
155static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
156{
dd56040d 157 return !proxy->disable_modern;
9a4c0e22
MA
158}
159
160static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
161{
dd56040d 162 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
9a4c0e22
MA
163}
164
dd56040d 165static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
9a4c0e22 166{
dd56040d
DDAG
167 proxy->disable_modern = false;
168 proxy->disable_legacy = ON_OFF_AUTO_ON;
9a4c0e22 169}
bc7b90a0 170
d1b4259f
MC
171static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
172{
dd56040d 173 proxy->disable_modern = true;
d1b4259f
MC
174}
175
f958c8aa
GH
176/*
177 * virtio-input-pci: This extends VirtioPCIProxy.
178 */
179#define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
710e2d90 180
befeac45
MT
181/* Virtio ABI version, if we increment this, we break the guest driver. */
182#define VIRTIO_PCI_ABI_VERSION 0
183
a4ee4c8b
EH
184/* Input for virtio_pci_types_register() */
185typedef struct VirtioPCIDeviceTypeInfo {
186 /*
187 * Common base class for the subclasses below.
188 *
189 * Required only if transitional_name or non_transitional_name is set.
190 *
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.
197 */
198 const char *base_name;
199 /*
200 * Generic device type. Optional.
201 *
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.
206 *
207 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
208 * but PCI Express is supported only in non-transitional mode.
209 *
210 * The only type implemented by QEMU 3.1 and older.
211 */
212 const char *generic_name;
213 /*
214 * The transitional device type. Optional.
215 *
216 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
217 */
218 const char *transitional_name;
219 /*
220 * The non-transitional device type. Optional.
221 *
222 * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
223 */
224 const char *non_transitional_name;
225
226 /* Parent type. If NULL, TYPE_VIRTIO_PCI is used */
227 const char *parent;
228
229 /* Same as TypeInfo fields: */
230 size_t instance_size;
8ea90ee6 231 size_t class_size;
a4ee4c8b
EH
232 void (*instance_init)(Object *obj);
233 void (*class_init)(ObjectClass *klass, void *data);
1e33b513 234 InterfaceInfo *interfaces;
a4ee4c8b
EH
235} VirtioPCIDeviceTypeInfo;
236
237/* Register virtio-pci type(s). @t must be static. */
238void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
239
1436f32a
SH
240/**
241 * virtio_pci_optimal_num_queues:
242 * @fixed_queues: number of queues that are always present
243 *
244 * Returns: The optimal number of queues for a multi-queue device, excluding
245 * @fixed_queues.
246 */
247unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues);
248
9fe1ebeb 249#endif