]> git.proxmox.com Git - mirror_qemu.git/blame - hw/virtio/virtio-pci.h
usb-mtp: replace the homebrew write with qemu_write_full
[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"
b307d308 20
085bccb7
FK
21typedef struct VirtIOPCIProxy VirtIOPCIProxy;
22
0a2acf5e
FK
23/* virtio-pci-bus */
24
25typedef struct VirtioBusState VirtioPCIBusState;
26typedef struct VirtioBusClass VirtioPCIBusClass;
27
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)
9fe1ebeb 35
fc1769b7
MA
36enum {
37 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
38 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
fc1769b7
MA
39 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
40 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
41 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
d9997d89 42 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
615c4ed2 43 VIRTIO_PCI_FLAG_ATS_BIT,
c2cabb34 44 VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
d584f1b9 45 VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
27ce0f3a 46 VIRTIO_PCI_FLAG_INIT_PM_BIT,
fc1769b7
MA
47};
48
68a27b20 49/* Need to activate work-arounds for buggy guests at vmstate load. */
68a27b20
MT
50#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
51 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
52
5745e38a
AK
53/* Performance improves when virtqueue kick processing is decoupled from the
54 * vcpu thread using ioeventfd for some devices. */
5745e38a
AK
55#define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
56
e266d421 57/* virtio version flags */
1811e64c 58#define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
e266d421 59
a6df8adf 60/* migrate extra state */
a6df8adf
JW
61#define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
62
9824d2a3 63/* have pio notification for modern device ? */
9824d2a3
JW
64#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
65 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
66
d9997d89
MA
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)
70
615c4ed2
JW
71/* address space translation service */
72#define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
73
c2cabb34
MA
74/* Init error enabling flags */
75#define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
76
d584f1b9
MA
77/* Init Link Control register */
78#define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
79
27ce0f3a
MA
80/* Init Power Management */
81#define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
82
7d37d351 83typedef struct {
774345f9 84 MSIMessage msg;
7d37d351
JK
85 int virq;
86 unsigned int users;
87} VirtIOIRQFD;
88
085bccb7
FK
89/*
90 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
91 */
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)
99
100typedef struct VirtioPCIClass {
101 PCIDeviceClass parent_class;
0560b0e9 102 DeviceRealize parent_dc_realize;
fc079951 103 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
085bccb7
FK
104} VirtioPCIClass;
105
588255ad
GH
106typedef struct VirtIOPCIRegion {
107 MemoryRegion mr;
a3cc2e81 108 uint32_t offset;
b6ce27a5 109 uint32_t size;
fc004905 110 uint32_t type;
588255ad
GH
111} VirtIOPCIRegion;
112
a6df8adf
JW
113typedef 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;
120
085bccb7 121struct VirtIOPCIProxy {
9fe1ebeb 122 PCIDevice pci_dev;
da146d0a 123 MemoryRegion bar;
a93c8d82
AK
124 union {
125 struct {
126 VirtIOPCIRegion common;
127 VirtIOPCIRegion isr;
128 VirtIOPCIRegion device;
129 VirtIOPCIRegion notify;
130 VirtIOPCIRegion notify_pio;
131 };
132 VirtIOPCIRegion regs[5];
133 };
dfb8e184 134 MemoryRegion modern_bar;
9824d2a3 135 MemoryRegion io_bar;
7a25126d
CF
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;
ada434cd 140 int config_cap;
9fe1ebeb 141 uint32_t flags;
9a4c0e22 142 bool disable_modern;
66d1c4c1 143 bool ignore_backend_features;
9a4c0e22 144 OnOffAuto disable_legacy;
9fe1ebeb
AK
145 uint32_t class_code;
146 uint32_t nvectors;
dfb8e184
MT
147 uint32_t dfselect;
148 uint32_t gfselect;
149 uint32_t guest_features[2];
a6df8adf 150 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
dfb8e184 151
7d37d351 152 VirtIOIRQFD *vector_irqfd;
2d620f59 153 int nvqs_with_notifiers;
085bccb7
FK
154 VirtioBusState bus;
155};
9fe1ebeb 156
9a4c0e22
MA
157static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
158{
159 return !proxy->disable_modern;
160}
161
162static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
163{
164 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
165}
166
167static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
168{
169 proxy->disable_modern = false;
170 proxy->disable_legacy = ON_OFF_AUTO_ON;
171}
bc7b90a0 172
d1b4259f
MC
173static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
174{
175 proxy->disable_modern = true;
176}
177
f958c8aa
GH
178/*
179 * virtio-input-pci: This extends VirtioPCIProxy.
180 */
181#define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
710e2d90 182
befeac45
MT
183/* Virtio ABI version, if we increment this, we break the guest driver. */
184#define VIRTIO_PCI_ABI_VERSION 0
185
a4ee4c8b
EH
186/* Input for virtio_pci_types_register() */
187typedef struct VirtioPCIDeviceTypeInfo {
188 /*
189 * Common base class for the subclasses below.
190 *
191 * Required only if transitional_name or non_transitional_name is set.
192 *
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.
199 */
200 const char *base_name;
201 /*
202 * Generic device type. Optional.
203 *
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.
208 *
209 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
210 * but PCI Express is supported only in non-transitional mode.
211 *
212 * The only type implemented by QEMU 3.1 and older.
213 */
214 const char *generic_name;
215 /*
216 * The transitional device type. Optional.
217 *
218 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
219 */
220 const char *transitional_name;
221 /*
222 * The non-transitional device type. Optional.
223 *
224 * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
225 */
226 const char *non_transitional_name;
227
228 /* Parent type. If NULL, TYPE_VIRTIO_PCI is used */
229 const char *parent;
230
231 /* Same as TypeInfo fields: */
232 size_t instance_size;
233 void (*instance_init)(Object *obj);
234 void (*class_init)(ObjectClass *klass, void *data);
235} VirtioPCIDeviceTypeInfo;
236
237/* Register virtio-pci type(s). @t must be static. */
238void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
239
9fe1ebeb 240#endif