OSDN Git Service

virtio: split virtio gpu bits from virtio-pci.h
[qmiga/qemu.git] / hw / virtio / virtio-pci.h
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
18 #include "hw/pci/msi.h"
19 #include "hw/virtio/virtio-bus.h"
20 #include "hw/virtio/virtio-crypto.h"
21
22 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
23 typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
24
25 /* virtio-pci-bus */
26
27 typedef struct VirtioBusState VirtioPCIBusState;
28 typedef struct VirtioBusClass VirtioPCIBusClass;
29
30 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
31 #define VIRTIO_PCI_BUS(obj) \
32         OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
33 #define VIRTIO_PCI_BUS_GET_CLASS(obj) \
34         OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
35 #define VIRTIO_PCI_BUS_CLASS(klass) \
36         OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
37
38 enum {
39     VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
40     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
41     VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
42     VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
43     VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
44     VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
45     VIRTIO_PCI_FLAG_ATS_BIT,
46     VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
47     VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
48     VIRTIO_PCI_FLAG_INIT_PM_BIT,
49 };
50
51 /* Need to activate work-arounds for buggy guests at vmstate load. */
52 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
53     (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
54
55 /* Performance improves when virtqueue kick processing is decoupled from the
56  * vcpu thread using ioeventfd for some devices. */
57 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD   (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
58
59 /* virtio version flags */
60 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
61
62 /* migrate extra state */
63 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
64
65 /* have pio notification for modern device ? */
66 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
67     (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
68
69 /* page per vq flag to be used by split drivers within guests */
70 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
71     (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
72
73 /* address space translation service */
74 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
75
76 /* Init error enabling flags */
77 #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
78
79 /* Init Link Control register */
80 #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
81
82 /* Init Power Management */
83 #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
84
85 typedef struct {
86     MSIMessage msg;
87     int virq;
88     unsigned int users;
89 } VirtIOIRQFD;
90
91 /*
92  * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
93  */
94 #define TYPE_VIRTIO_PCI "virtio-pci"
95 #define VIRTIO_PCI_GET_CLASS(obj) \
96         OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
97 #define VIRTIO_PCI_CLASS(klass) \
98         OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
99 #define VIRTIO_PCI(obj) \
100         OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
101
102 typedef struct VirtioPCIClass {
103     PCIDeviceClass parent_class;
104     DeviceRealize parent_dc_realize;
105     void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
106 } VirtioPCIClass;
107
108 typedef struct VirtIOPCIRegion {
109     MemoryRegion mr;
110     uint32_t offset;
111     uint32_t size;
112     uint32_t type;
113 } VirtIOPCIRegion;
114
115 typedef struct VirtIOPCIQueue {
116   uint16_t num;
117   bool enabled;
118   uint32_t desc[2];
119   uint32_t avail[2];
120   uint32_t used[2];
121 } VirtIOPCIQueue;
122
123 struct VirtIOPCIProxy {
124     PCIDevice pci_dev;
125     MemoryRegion bar;
126     union {
127         struct {
128             VirtIOPCIRegion common;
129             VirtIOPCIRegion isr;
130             VirtIOPCIRegion device;
131             VirtIOPCIRegion notify;
132             VirtIOPCIRegion notify_pio;
133         };
134         VirtIOPCIRegion regs[5];
135     };
136     MemoryRegion modern_bar;
137     MemoryRegion io_bar;
138     uint32_t legacy_io_bar_idx;
139     uint32_t msix_bar_idx;
140     uint32_t modern_io_bar_idx;
141     uint32_t modern_mem_bar_idx;
142     int config_cap;
143     uint32_t flags;
144     bool disable_modern;
145     bool ignore_backend_features;
146     OnOffAuto disable_legacy;
147     uint32_t class_code;
148     uint32_t nvectors;
149     uint32_t dfselect;
150     uint32_t gfselect;
151     uint32_t guest_features[2];
152     VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
153
154     VirtIOIRQFD *vector_irqfd;
155     int nvqs_with_notifiers;
156     VirtioBusState bus;
157 };
158
159 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
160 {
161     return !proxy->disable_modern;
162 }
163
164 static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
165 {
166     return proxy->disable_legacy == ON_OFF_AUTO_OFF;
167 }
168
169 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
170 {
171     proxy->disable_modern = false;
172     proxy->disable_legacy = ON_OFF_AUTO_ON;
173 }
174
175 static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
176 {
177     proxy->disable_modern = true;
178 }
179
180 /*
181  * virtio-input-pci: This extends VirtioPCIProxy.
182  */
183 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
184
185 /*
186  * virtio-crypto-pci: This extends VirtioPCIProxy.
187  */
188 #define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
189 #define VIRTIO_CRYPTO_PCI(obj) \
190         OBJECT_CHECK(VirtIOCryptoPCI, (obj), TYPE_VIRTIO_CRYPTO_PCI)
191
192 struct VirtIOCryptoPCI {
193     VirtIOPCIProxy parent_obj;
194     VirtIOCrypto vdev;
195 };
196
197 /* Virtio ABI version, if we increment this, we break the guest driver. */
198 #define VIRTIO_PCI_ABI_VERSION          0
199
200 /* Input for virtio_pci_types_register() */
201 typedef struct VirtioPCIDeviceTypeInfo {
202     /*
203      * Common base class for the subclasses below.
204      *
205      * Required only if transitional_name or non_transitional_name is set.
206      *
207      * We need a separate base type instead of making all types
208      * inherit from generic_name for two reasons:
209      * 1) generic_name implements INTERFACE_PCIE_DEVICE, but
210      *    transitional_name does not.
211      * 2) generic_name has the "disable-legacy" and "disable-modern"
212      *    properties, transitional_name and non_transitional name don't.
213      */
214     const char *base_name;
215     /*
216      * Generic device type.  Optional.
217      *
218      * Supports both transitional and non-transitional modes,
219      * using the disable-legacy and disable-modern properties.
220      * If disable-legacy=auto, (non-)transitional mode is selected
221      * depending on the bus where the device is plugged.
222      *
223      * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
224      * but PCI Express is supported only in non-transitional mode.
225      *
226      * The only type implemented by QEMU 3.1 and older.
227      */
228     const char *generic_name;
229     /*
230      * The transitional device type.  Optional.
231      *
232      * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
233      */
234     const char *transitional_name;
235     /*
236      * The non-transitional device type.  Optional.
237      *
238      * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
239      */
240     const char *non_transitional_name;
241
242     /* Parent type.  If NULL, TYPE_VIRTIO_PCI is used */
243     const char *parent;
244
245     /* Same as TypeInfo fields: */
246     size_t instance_size;
247     void (*instance_init)(Object *obj);
248     void (*class_init)(ObjectClass *klass, void *data);
249 } VirtioPCIDeviceTypeInfo;
250
251 /* Register virtio-pci type(s).  @t must be static. */
252 void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
253
254 #endif