Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
[qemu/ar7.git] / hw / virtio / virtio-pci.h
blobffb74bb908dadb747eb2ccb074997ccb0f900f9b
1 /*
2 * Virtio PCI Bindings
4 * Copyright IBM, Corp. 2007
5 * Copyright (c) 2009 CodeSourcery
7 * Authors:
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-blk.h"
20 #include "hw/virtio/virtio-net.h"
21 #include "hw/virtio/virtio-rng.h"
22 #include "hw/virtio/virtio-serial.h"
23 #include "hw/virtio/virtio-scsi.h"
24 #include "hw/virtio/virtio-balloon.h"
25 #include "hw/virtio/virtio-bus.h"
26 #include "hw/virtio/virtio-9p.h"
27 #include "hw/virtio/virtio-input.h"
28 #include "hw/virtio/virtio-gpu.h"
29 #ifdef CONFIG_VIRTFS
30 #include "hw/9pfs/virtio-9p.h"
31 #endif
32 #ifdef CONFIG_VHOST_SCSI
33 #include "hw/virtio/vhost-scsi.h"
34 #endif
36 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
37 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
38 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
39 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
40 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
41 typedef struct VirtIONetPCI VirtIONetPCI;
42 typedef struct VHostSCSIPCI VHostSCSIPCI;
43 typedef struct VirtIORngPCI VirtIORngPCI;
44 typedef struct VirtIOInputPCI VirtIOInputPCI;
45 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
46 typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
47 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
49 /* virtio-pci-bus */
51 typedef struct VirtioBusState VirtioPCIBusState;
52 typedef struct VirtioBusClass VirtioPCIBusClass;
54 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
55 #define VIRTIO_PCI_BUS(obj) \
56 OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
57 #define VIRTIO_PCI_BUS_GET_CLASS(obj) \
58 OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
59 #define VIRTIO_PCI_BUS_CLASS(klass) \
60 OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
62 /* Need to activate work-arounds for buggy guests at vmstate load. */
63 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT 0
64 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
65 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
67 /* Performance improves when virtqueue kick processing is decoupled from the
68 * vcpu thread using ioeventfd for some devices. */
69 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1
70 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
72 /* virtio version flags */
73 #define VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT 2
74 #define VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT 3
75 #define VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT 4
76 #define VIRTIO_PCI_FLAG_DISABLE_LEGACY (1 << VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT)
77 #define VIRTIO_PCI_FLAG_DISABLE_MODERN (1 << VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT)
78 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
80 /* migrate extra state */
81 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT 4
82 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
84 /* have pio notification for modern device ? */
85 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT 5
86 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
87 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
89 typedef struct {
90 MSIMessage msg;
91 int virq;
92 unsigned int users;
93 } VirtIOIRQFD;
96 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
98 #define TYPE_VIRTIO_PCI "virtio-pci"
99 #define VIRTIO_PCI_GET_CLASS(obj) \
100 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
101 #define VIRTIO_PCI_CLASS(klass) \
102 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
103 #define VIRTIO_PCI(obj) \
104 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
106 typedef struct VirtioPCIClass {
107 PCIDeviceClass parent_class;
108 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
109 } VirtioPCIClass;
111 typedef struct VirtIOPCIRegion {
112 MemoryRegion mr;
113 uint32_t offset;
114 uint32_t size;
115 uint32_t type;
116 } VirtIOPCIRegion;
118 typedef struct VirtIOPCIQueue {
119 uint16_t num;
120 bool enabled;
121 uint32_t desc[2];
122 uint32_t avail[2];
123 uint32_t used[2];
124 } VirtIOPCIQueue;
126 struct VirtIOPCIProxy {
127 PCIDevice pci_dev;
128 MemoryRegion bar;
129 VirtIOPCIRegion common;
130 VirtIOPCIRegion isr;
131 VirtIOPCIRegion device;
132 VirtIOPCIRegion notify;
133 VirtIOPCIRegion notify_pio;
134 MemoryRegion modern_bar;
135 MemoryRegion io_bar;
136 MemoryRegion modern_cfg;
137 AddressSpace modern_as;
138 uint32_t legacy_io_bar;
139 uint32_t msix_bar;
140 uint32_t modern_io_bar;
141 uint32_t modern_mem_bar;
142 int config_cap;
143 uint32_t flags;
144 uint32_t class_code;
145 uint32_t nvectors;
146 uint32_t dfselect;
147 uint32_t gfselect;
148 uint32_t guest_features[2];
149 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
151 bool ioeventfd_disabled;
152 bool ioeventfd_started;
153 VirtIOIRQFD *vector_irqfd;
154 int nvqs_with_notifiers;
155 VirtioBusState bus;
160 * virtio-scsi-pci: This extends VirtioPCIProxy.
162 #define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci"
163 #define VIRTIO_SCSI_PCI(obj) \
164 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI)
166 struct VirtIOSCSIPCI {
167 VirtIOPCIProxy parent_obj;
168 VirtIOSCSI vdev;
171 #ifdef CONFIG_VHOST_SCSI
173 * vhost-scsi-pci: This extends VirtioPCIProxy.
175 #define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci"
176 #define VHOST_SCSI_PCI(obj) \
177 OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
179 struct VHostSCSIPCI {
180 VirtIOPCIProxy parent_obj;
181 VHostSCSI vdev;
183 #endif
186 * virtio-blk-pci: This extends VirtioPCIProxy.
188 #define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
189 #define VIRTIO_BLK_PCI(obj) \
190 OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
192 struct VirtIOBlkPCI {
193 VirtIOPCIProxy parent_obj;
194 VirtIOBlock vdev;
198 * virtio-balloon-pci: This extends VirtioPCIProxy.
200 #define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
201 #define VIRTIO_BALLOON_PCI(obj) \
202 OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
204 struct VirtIOBalloonPCI {
205 VirtIOPCIProxy parent_obj;
206 VirtIOBalloon vdev;
210 * virtio-serial-pci: This extends VirtioPCIProxy.
212 #define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci"
213 #define VIRTIO_SERIAL_PCI(obj) \
214 OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
216 struct VirtIOSerialPCI {
217 VirtIOPCIProxy parent_obj;
218 VirtIOSerial vdev;
222 * virtio-net-pci: This extends VirtioPCIProxy.
224 #define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
225 #define VIRTIO_NET_PCI(obj) \
226 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
228 struct VirtIONetPCI {
229 VirtIOPCIProxy parent_obj;
230 VirtIONet vdev;
234 * virtio-9p-pci: This extends VirtioPCIProxy.
237 #ifdef CONFIG_VIRTFS
239 #define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
240 #define VIRTIO_9P_PCI(obj) \
241 OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
243 typedef struct V9fsPCIState {
244 VirtIOPCIProxy parent_obj;
245 V9fsState vdev;
246 } V9fsPCIState;
248 #endif
251 * virtio-rng-pci: This extends VirtioPCIProxy.
253 #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
254 #define VIRTIO_RNG_PCI(obj) \
255 OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
257 struct VirtIORngPCI {
258 VirtIOPCIProxy parent_obj;
259 VirtIORNG vdev;
263 * virtio-input-pci: This extends VirtioPCIProxy.
265 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
266 #define VIRTIO_INPUT_PCI(obj) \
267 OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
269 struct VirtIOInputPCI {
270 VirtIOPCIProxy parent_obj;
271 VirtIOInput vdev;
274 #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
275 #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci"
276 #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
277 #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci"
278 #define VIRTIO_INPUT_HID_PCI(obj) \
279 OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI)
281 struct VirtIOInputHIDPCI {
282 VirtIOPCIProxy parent_obj;
283 VirtIOInputHID vdev;
286 #ifdef CONFIG_LINUX
288 #define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
289 #define VIRTIO_INPUT_HOST_PCI(obj) \
290 OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
292 struct VirtIOInputHostPCI {
293 VirtIOPCIProxy parent_obj;
294 VirtIOInputHost vdev;
297 #endif
300 * virtio-gpu-pci: This extends VirtioPCIProxy.
302 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
303 #define VIRTIO_GPU_PCI(obj) \
304 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
306 struct VirtIOGPUPCI {
307 VirtIOPCIProxy parent_obj;
308 VirtIOGPU vdev;
311 /* Virtio ABI version, if we increment this, we break the guest driver. */
312 #define VIRTIO_PCI_ABI_VERSION 0
314 #endif