tests: Ignore test executables
[qemu/kevin.git] / hw / virtio / virtio-pci.h
blob541cbdbc2bd1d5341ec5c8512c727e32d65d7126
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-input.h"
27 #include "hw/virtio/virtio-gpu.h"
28 #ifdef CONFIG_VIRTFS
29 #include "hw/9pfs/virtio-9p.h"
30 #endif
31 #ifdef CONFIG_VHOST_SCSI
32 #include "hw/virtio/vhost-scsi.h"
33 #endif
34 #ifdef CONFIG_VHOST_VSOCK
35 #include "hw/virtio/vhost-vsock.h"
36 #endif
38 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
39 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
40 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
41 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
42 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
43 typedef struct VirtIONetPCI VirtIONetPCI;
44 typedef struct VHostSCSIPCI VHostSCSIPCI;
45 typedef struct VirtIORngPCI VirtIORngPCI;
46 typedef struct VirtIOInputPCI VirtIOInputPCI;
47 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
48 typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
49 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
50 typedef struct VHostVSockPCI VHostVSockPCI;
52 /* virtio-pci-bus */
54 typedef struct VirtioBusState VirtioPCIBusState;
55 typedef struct VirtioBusClass VirtioPCIBusClass;
57 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
58 #define VIRTIO_PCI_BUS(obj) \
59 OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
60 #define VIRTIO_PCI_BUS_GET_CLASS(obj) \
61 OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
62 #define VIRTIO_PCI_BUS_CLASS(klass) \
63 OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
65 enum {
66 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
67 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
68 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
69 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
70 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
71 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
74 /* Need to activate work-arounds for buggy guests at vmstate load. */
75 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
76 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
78 /* Performance improves when virtqueue kick processing is decoupled from the
79 * vcpu thread using ioeventfd for some devices. */
80 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
82 /* virtio version flags */
83 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
85 /* migrate extra state */
86 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
88 /* have pio notification for modern device ? */
89 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
90 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
92 /* page per vq flag to be used by split drivers within guests */
93 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
94 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
96 typedef struct {
97 MSIMessage msg;
98 int virq;
99 unsigned int users;
100 } VirtIOIRQFD;
103 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
105 #define TYPE_VIRTIO_PCI "virtio-pci"
106 #define VIRTIO_PCI_GET_CLASS(obj) \
107 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
108 #define VIRTIO_PCI_CLASS(klass) \
109 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
110 #define VIRTIO_PCI(obj) \
111 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
113 typedef struct VirtioPCIClass {
114 PCIDeviceClass parent_class;
115 DeviceRealize parent_dc_realize;
116 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
117 } VirtioPCIClass;
119 typedef struct VirtIOPCIRegion {
120 MemoryRegion mr;
121 uint32_t offset;
122 uint32_t size;
123 uint32_t type;
124 } VirtIOPCIRegion;
126 typedef struct VirtIOPCIQueue {
127 uint16_t num;
128 bool enabled;
129 uint32_t desc[2];
130 uint32_t avail[2];
131 uint32_t used[2];
132 } VirtIOPCIQueue;
134 struct VirtIOPCIProxy {
135 PCIDevice pci_dev;
136 MemoryRegion bar;
137 VirtIOPCIRegion common;
138 VirtIOPCIRegion isr;
139 VirtIOPCIRegion device;
140 VirtIOPCIRegion notify;
141 VirtIOPCIRegion notify_pio;
142 MemoryRegion modern_bar;
143 MemoryRegion io_bar;
144 MemoryRegion modern_cfg;
145 AddressSpace modern_as;
146 uint32_t legacy_io_bar;
147 uint32_t msix_bar;
148 uint32_t modern_io_bar;
149 uint32_t modern_mem_bar;
150 int config_cap;
151 uint32_t flags;
152 bool disable_modern;
153 OnOffAuto disable_legacy;
154 uint32_t class_code;
155 uint32_t nvectors;
156 uint32_t dfselect;
157 uint32_t gfselect;
158 uint32_t guest_features[2];
159 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
161 bool ioeventfd_disabled;
162 bool ioeventfd_started;
163 VirtIOIRQFD *vector_irqfd;
164 int nvqs_with_notifiers;
165 VirtioBusState bus;
168 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
170 return !proxy->disable_modern;
173 static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
175 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
178 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
180 proxy->disable_modern = false;
181 proxy->disable_legacy = ON_OFF_AUTO_ON;
184 static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
186 proxy->disable_modern = true;
190 * virtio-scsi-pci: This extends VirtioPCIProxy.
192 #define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci"
193 #define VIRTIO_SCSI_PCI(obj) \
194 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI)
196 struct VirtIOSCSIPCI {
197 VirtIOPCIProxy parent_obj;
198 VirtIOSCSI vdev;
201 #ifdef CONFIG_VHOST_SCSI
203 * vhost-scsi-pci: This extends VirtioPCIProxy.
205 #define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci"
206 #define VHOST_SCSI_PCI(obj) \
207 OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
209 struct VHostSCSIPCI {
210 VirtIOPCIProxy parent_obj;
211 VHostSCSI vdev;
213 #endif
216 * virtio-blk-pci: This extends VirtioPCIProxy.
218 #define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
219 #define VIRTIO_BLK_PCI(obj) \
220 OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
222 struct VirtIOBlkPCI {
223 VirtIOPCIProxy parent_obj;
224 VirtIOBlock vdev;
228 * virtio-balloon-pci: This extends VirtioPCIProxy.
230 #define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
231 #define VIRTIO_BALLOON_PCI(obj) \
232 OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
234 struct VirtIOBalloonPCI {
235 VirtIOPCIProxy parent_obj;
236 VirtIOBalloon vdev;
240 * virtio-serial-pci: This extends VirtioPCIProxy.
242 #define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci"
243 #define VIRTIO_SERIAL_PCI(obj) \
244 OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
246 struct VirtIOSerialPCI {
247 VirtIOPCIProxy parent_obj;
248 VirtIOSerial vdev;
252 * virtio-net-pci: This extends VirtioPCIProxy.
254 #define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
255 #define VIRTIO_NET_PCI(obj) \
256 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
258 struct VirtIONetPCI {
259 VirtIOPCIProxy parent_obj;
260 VirtIONet vdev;
264 * virtio-9p-pci: This extends VirtioPCIProxy.
267 #ifdef CONFIG_VIRTFS
269 #define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
270 #define VIRTIO_9P_PCI(obj) \
271 OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
273 typedef struct V9fsPCIState {
274 VirtIOPCIProxy parent_obj;
275 V9fsVirtioState vdev;
276 } V9fsPCIState;
278 #endif
281 * virtio-rng-pci: This extends VirtioPCIProxy.
283 #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
284 #define VIRTIO_RNG_PCI(obj) \
285 OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
287 struct VirtIORngPCI {
288 VirtIOPCIProxy parent_obj;
289 VirtIORNG vdev;
293 * virtio-input-pci: This extends VirtioPCIProxy.
295 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
296 #define VIRTIO_INPUT_PCI(obj) \
297 OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
299 struct VirtIOInputPCI {
300 VirtIOPCIProxy parent_obj;
301 VirtIOInput vdev;
304 #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
305 #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci"
306 #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
307 #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci"
308 #define VIRTIO_INPUT_HID_PCI(obj) \
309 OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI)
311 struct VirtIOInputHIDPCI {
312 VirtIOPCIProxy parent_obj;
313 VirtIOInputHID vdev;
316 #ifdef CONFIG_LINUX
318 #define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
319 #define VIRTIO_INPUT_HOST_PCI(obj) \
320 OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
322 struct VirtIOInputHostPCI {
323 VirtIOPCIProxy parent_obj;
324 VirtIOInputHost vdev;
327 #endif
330 * virtio-gpu-pci: This extends VirtioPCIProxy.
332 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
333 #define VIRTIO_GPU_PCI(obj) \
334 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
336 struct VirtIOGPUPCI {
337 VirtIOPCIProxy parent_obj;
338 VirtIOGPU vdev;
341 #ifdef CONFIG_VHOST_VSOCK
343 * vhost-vsock-pci: This extends VirtioPCIProxy.
345 #define TYPE_VHOST_VSOCK_PCI "vhost-vsock-pci"
346 #define VHOST_VSOCK_PCI(obj) \
347 OBJECT_CHECK(VHostVSockPCI, (obj), TYPE_VHOST_VSOCK_PCI)
349 struct VHostVSockPCI {
350 VirtIOPCIProxy parent_obj;
351 VHostVSock vdev;
353 #endif
355 /* Virtio ABI version, if we increment this, we break the guest driver. */
356 #define VIRTIO_PCI_ABI_VERSION 0
358 #endif