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-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"
30 #include "hw/9pfs/virtio-9p.h"
32 #ifdef CONFIG_VHOST_SCSI
33 #include "hw/virtio/vhost-scsi.h"
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
;
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_LEGACY (1 << VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT)
76 #define VIRTIO_PCI_FLAG_DISABLE_MODERN (1 << VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT)
85 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
87 #define TYPE_VIRTIO_PCI "virtio-pci"
88 #define VIRTIO_PCI_GET_CLASS(obj) \
89 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
90 #define VIRTIO_PCI_CLASS(klass) \
91 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
92 #define VIRTIO_PCI(obj) \
93 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
95 typedef struct VirtioPCIClass
{
96 PCIDeviceClass parent_class
;
97 void (*realize
)(VirtIOPCIProxy
*vpci_dev
, Error
**errp
);
100 typedef struct VirtIOPCIRegion
{
107 struct VirtIOPCIProxy
{
110 VirtIOPCIRegion common
;
112 VirtIOPCIRegion device
;
113 VirtIOPCIRegion notify
;
114 MemoryRegion modern_bar
;
115 MemoryRegion modern_cfg
;
116 AddressSpace modern_as
;
117 uint32_t legacy_io_bar
;
119 uint32_t modern_mem_bar
;
126 uint32_t guest_features
[2];
133 } vqs
[VIRTIO_QUEUE_MAX
];
135 bool ioeventfd_disabled
;
136 bool ioeventfd_started
;
137 VirtIOIRQFD
*vector_irqfd
;
138 int nvqs_with_notifiers
;
144 * virtio-scsi-pci: This extends VirtioPCIProxy.
146 #define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci"
147 #define VIRTIO_SCSI_PCI(obj) \
148 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI)
150 struct VirtIOSCSIPCI
{
151 VirtIOPCIProxy parent_obj
;
155 #ifdef CONFIG_VHOST_SCSI
157 * vhost-scsi-pci: This extends VirtioPCIProxy.
159 #define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci"
160 #define VHOST_SCSI_PCI(obj) \
161 OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
163 struct VHostSCSIPCI
{
164 VirtIOPCIProxy parent_obj
;
170 * virtio-blk-pci: This extends VirtioPCIProxy.
172 #define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
173 #define VIRTIO_BLK_PCI(obj) \
174 OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
176 struct VirtIOBlkPCI
{
177 VirtIOPCIProxy parent_obj
;
182 * virtio-balloon-pci: This extends VirtioPCIProxy.
184 #define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
185 #define VIRTIO_BALLOON_PCI(obj) \
186 OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
188 struct VirtIOBalloonPCI
{
189 VirtIOPCIProxy parent_obj
;
194 * virtio-serial-pci: This extends VirtioPCIProxy.
196 #define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci"
197 #define VIRTIO_SERIAL_PCI(obj) \
198 OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
200 struct VirtIOSerialPCI
{
201 VirtIOPCIProxy parent_obj
;
206 * virtio-net-pci: This extends VirtioPCIProxy.
208 #define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
209 #define VIRTIO_NET_PCI(obj) \
210 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
212 struct VirtIONetPCI
{
213 VirtIOPCIProxy parent_obj
;
218 * virtio-9p-pci: This extends VirtioPCIProxy.
223 #define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
224 #define VIRTIO_9P_PCI(obj) \
225 OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
227 typedef struct V9fsPCIState
{
228 VirtIOPCIProxy parent_obj
;
235 * virtio-rng-pci: This extends VirtioPCIProxy.
237 #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
238 #define VIRTIO_RNG_PCI(obj) \
239 OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
241 struct VirtIORngPCI
{
242 VirtIOPCIProxy parent_obj
;
247 * virtio-input-pci: This extends VirtioPCIProxy.
249 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
250 #define VIRTIO_INPUT_PCI(obj) \
251 OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
253 struct VirtIOInputPCI
{
254 VirtIOPCIProxy parent_obj
;
258 #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
259 #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci"
260 #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
261 #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci"
262 #define VIRTIO_INPUT_HID_PCI(obj) \
263 OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI)
265 struct VirtIOInputHIDPCI
{
266 VirtIOPCIProxy parent_obj
;
272 #define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
273 #define VIRTIO_INPUT_HOST_PCI(obj) \
274 OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
276 struct VirtIOInputHostPCI
{
277 VirtIOPCIProxy parent_obj
;
278 VirtIOInputHost vdev
;
284 * virtio-gpu-pci: This extends VirtioPCIProxy.
286 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
287 #define VIRTIO_GPU_PCI(obj) \
288 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
290 struct VirtIOGPUPCI
{
291 VirtIOPCIProxy parent_obj
;
295 /* Virtio ABI version, if we increment this, we break the guest driver. */
296 #define VIRTIO_PCI_ABI_VERSION 0