ppc/xics: Move SPAPR specific code to a separate file
[qemu.git] / hw / virtio / virtio-pci.h
blobe4548c2f9701da42fcd8039626cb074e81a2d24a
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
35 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
36 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
37 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
38 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
39 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
40 typedef struct VirtIONetPCI VirtIONetPCI;
41 typedef struct VHostSCSIPCI VHostSCSIPCI;
42 typedef struct VirtIORngPCI VirtIORngPCI;
43 typedef struct VirtIOInputPCI VirtIOInputPCI;
44 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
45 typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
46 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
48 /* virtio-pci-bus */
50 typedef struct VirtioBusState VirtioPCIBusState;
51 typedef struct VirtioBusClass VirtioPCIBusClass;
53 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
54 #define VIRTIO_PCI_BUS(obj) \
55 OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
56 #define VIRTIO_PCI_BUS_GET_CLASS(obj) \
57 OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
58 #define VIRTIO_PCI_BUS_CLASS(klass) \
59 OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
61 enum {
62 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
63 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
64 VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT,
65 VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT,
66 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
67 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
68 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
71 /* Need to activate work-arounds for buggy guests at vmstate load. */
72 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
73 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
75 /* Performance improves when virtqueue kick processing is decoupled from the
76 * vcpu thread using ioeventfd for some devices. */
77 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
79 /* virtio version flags */
80 #define VIRTIO_PCI_FLAG_DISABLE_LEGACY (1 << VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT)
81 #define VIRTIO_PCI_FLAG_DISABLE_MODERN (1 << VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT)
82 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
84 /* migrate extra state */
85 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
87 /* have pio notification for modern device ? */
88 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
89 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
91 typedef struct {
92 MSIMessage msg;
93 int virq;
94 unsigned int users;
95 } VirtIOIRQFD;
98 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
100 #define TYPE_VIRTIO_PCI "virtio-pci"
101 #define VIRTIO_PCI_GET_CLASS(obj) \
102 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
103 #define VIRTIO_PCI_CLASS(klass) \
104 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
105 #define VIRTIO_PCI(obj) \
106 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
108 typedef struct VirtioPCIClass {
109 PCIDeviceClass parent_class;
110 DeviceRealize parent_dc_realize;
111 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
112 } VirtioPCIClass;
114 typedef struct VirtIOPCIRegion {
115 MemoryRegion mr;
116 uint32_t offset;
117 uint32_t size;
118 uint32_t type;
119 } VirtIOPCIRegion;
121 typedef struct VirtIOPCIQueue {
122 uint16_t num;
123 bool enabled;
124 uint32_t desc[2];
125 uint32_t avail[2];
126 uint32_t used[2];
127 } VirtIOPCIQueue;
129 struct VirtIOPCIProxy {
130 PCIDevice pci_dev;
131 MemoryRegion bar;
132 VirtIOPCIRegion common;
133 VirtIOPCIRegion isr;
134 VirtIOPCIRegion device;
135 VirtIOPCIRegion notify;
136 VirtIOPCIRegion notify_pio;
137 MemoryRegion modern_bar;
138 MemoryRegion io_bar;
139 MemoryRegion modern_cfg;
140 AddressSpace modern_as;
141 uint32_t legacy_io_bar;
142 uint32_t msix_bar;
143 uint32_t modern_io_bar;
144 uint32_t modern_mem_bar;
145 int config_cap;
146 uint32_t flags;
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];
154 bool ioeventfd_disabled;
155 bool ioeventfd_started;
156 VirtIOIRQFD *vector_irqfd;
157 int nvqs_with_notifiers;
158 VirtioBusState bus;
163 * virtio-scsi-pci: This extends VirtioPCIProxy.
165 #define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci"
166 #define VIRTIO_SCSI_PCI(obj) \
167 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI)
169 struct VirtIOSCSIPCI {
170 VirtIOPCIProxy parent_obj;
171 VirtIOSCSI vdev;
174 #ifdef CONFIG_VHOST_SCSI
176 * vhost-scsi-pci: This extends VirtioPCIProxy.
178 #define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci"
179 #define VHOST_SCSI_PCI(obj) \
180 OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
182 struct VHostSCSIPCI {
183 VirtIOPCIProxy parent_obj;
184 VHostSCSI vdev;
186 #endif
189 * virtio-blk-pci: This extends VirtioPCIProxy.
191 #define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
192 #define VIRTIO_BLK_PCI(obj) \
193 OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
195 struct VirtIOBlkPCI {
196 VirtIOPCIProxy parent_obj;
197 VirtIOBlock vdev;
201 * virtio-balloon-pci: This extends VirtioPCIProxy.
203 #define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
204 #define VIRTIO_BALLOON_PCI(obj) \
205 OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
207 struct VirtIOBalloonPCI {
208 VirtIOPCIProxy parent_obj;
209 VirtIOBalloon vdev;
213 * virtio-serial-pci: This extends VirtioPCIProxy.
215 #define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci"
216 #define VIRTIO_SERIAL_PCI(obj) \
217 OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
219 struct VirtIOSerialPCI {
220 VirtIOPCIProxy parent_obj;
221 VirtIOSerial vdev;
225 * virtio-net-pci: This extends VirtioPCIProxy.
227 #define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
228 #define VIRTIO_NET_PCI(obj) \
229 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
231 struct VirtIONetPCI {
232 VirtIOPCIProxy parent_obj;
233 VirtIONet vdev;
237 * virtio-9p-pci: This extends VirtioPCIProxy.
240 #ifdef CONFIG_VIRTFS
242 #define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
243 #define VIRTIO_9P_PCI(obj) \
244 OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
246 typedef struct V9fsPCIState {
247 VirtIOPCIProxy parent_obj;
248 V9fsVirtioState vdev;
249 } V9fsPCIState;
251 #endif
254 * virtio-rng-pci: This extends VirtioPCIProxy.
256 #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
257 #define VIRTIO_RNG_PCI(obj) \
258 OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
260 struct VirtIORngPCI {
261 VirtIOPCIProxy parent_obj;
262 VirtIORNG vdev;
266 * virtio-input-pci: This extends VirtioPCIProxy.
268 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
269 #define VIRTIO_INPUT_PCI(obj) \
270 OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
272 struct VirtIOInputPCI {
273 VirtIOPCIProxy parent_obj;
274 VirtIOInput vdev;
277 #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
278 #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci"
279 #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
280 #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci"
281 #define VIRTIO_INPUT_HID_PCI(obj) \
282 OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI)
284 struct VirtIOInputHIDPCI {
285 VirtIOPCIProxy parent_obj;
286 VirtIOInputHID vdev;
289 #ifdef CONFIG_LINUX
291 #define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
292 #define VIRTIO_INPUT_HOST_PCI(obj) \
293 OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
295 struct VirtIOInputHostPCI {
296 VirtIOPCIProxy parent_obj;
297 VirtIOInputHost vdev;
300 #endif
303 * virtio-gpu-pci: This extends VirtioPCIProxy.
305 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
306 #define VIRTIO_GPU_PCI(obj) \
307 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
309 struct VirtIOGPUPCI {
310 VirtIOPCIProxy parent_obj;
311 VirtIOGPU vdev;
314 /* Virtio ABI version, if we increment this, we break the guest driver. */
315 #define VIRTIO_PCI_ABI_VERSION 0
317 #endif