sun4u: expose fw_cfg and NVRAM on ebus PCI IO address space
[qemu/ar7.git] / hw / virtio / virtio-pci.h
blob69f5959623d1572a1c672e822f07f9bc03537c3b
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 #include "hw/virtio/virtio-crypto.h"
29 #include "hw/virtio/vhost-user-scsi.h"
31 #ifdef CONFIG_VIRTFS
32 #include "hw/9pfs/virtio-9p.h"
33 #endif
34 #ifdef CONFIG_VHOST_SCSI
35 #include "hw/virtio/vhost-scsi.h"
36 #endif
37 #ifdef CONFIG_VHOST_VSOCK
38 #include "hw/virtio/vhost-vsock.h"
39 #endif
41 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
42 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
43 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
44 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
45 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
46 typedef struct VirtIONetPCI VirtIONetPCI;
47 typedef struct VHostSCSIPCI VHostSCSIPCI;
48 typedef struct VHostUserSCSIPCI VHostUserSCSIPCI;
49 typedef struct VirtIORngPCI VirtIORngPCI;
50 typedef struct VirtIOInputPCI VirtIOInputPCI;
51 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
52 typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
53 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
54 typedef struct VHostVSockPCI VHostVSockPCI;
55 typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
57 /* virtio-pci-bus */
59 typedef struct VirtioBusState VirtioPCIBusState;
60 typedef struct VirtioBusClass VirtioPCIBusClass;
62 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
63 #define VIRTIO_PCI_BUS(obj) \
64 OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
65 #define VIRTIO_PCI_BUS_GET_CLASS(obj) \
66 OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
67 #define VIRTIO_PCI_BUS_CLASS(klass) \
68 OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
70 enum {
71 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
72 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
73 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
74 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
75 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
76 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
77 VIRTIO_PCI_FLAG_ATS_BIT,
78 VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
79 VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
80 VIRTIO_PCI_FLAG_INIT_PM_BIT,
83 /* Need to activate work-arounds for buggy guests at vmstate load. */
84 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
85 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
87 /* Performance improves when virtqueue kick processing is decoupled from the
88 * vcpu thread using ioeventfd for some devices. */
89 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
91 /* virtio version flags */
92 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
94 /* migrate extra state */
95 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
97 /* have pio notification for modern device ? */
98 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
99 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
101 /* page per vq flag to be used by split drivers within guests */
102 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
103 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
105 /* address space translation service */
106 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
108 /* Init error enabling flags */
109 #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
111 /* Init Link Control register */
112 #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
114 /* Init Power Management */
115 #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
117 typedef struct {
118 MSIMessage msg;
119 int virq;
120 unsigned int users;
121 } VirtIOIRQFD;
124 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
126 #define TYPE_VIRTIO_PCI "virtio-pci"
127 #define VIRTIO_PCI_GET_CLASS(obj) \
128 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
129 #define VIRTIO_PCI_CLASS(klass) \
130 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
131 #define VIRTIO_PCI(obj) \
132 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
134 typedef struct VirtioPCIClass {
135 PCIDeviceClass parent_class;
136 DeviceRealize parent_dc_realize;
137 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
138 } VirtioPCIClass;
140 typedef struct VirtIOPCIRegion {
141 MemoryRegion mr;
142 uint32_t offset;
143 uint32_t size;
144 uint32_t type;
145 } VirtIOPCIRegion;
147 typedef struct VirtIOPCIQueue {
148 uint16_t num;
149 bool enabled;
150 uint32_t desc[2];
151 uint32_t avail[2];
152 uint32_t used[2];
153 } VirtIOPCIQueue;
155 struct VirtIOPCIProxy {
156 PCIDevice pci_dev;
157 MemoryRegion bar;
158 VirtIOPCIRegion common;
159 VirtIOPCIRegion isr;
160 VirtIOPCIRegion device;
161 VirtIOPCIRegion notify;
162 VirtIOPCIRegion notify_pio;
163 MemoryRegion modern_bar;
164 MemoryRegion io_bar;
165 MemoryRegion modern_cfg;
166 AddressSpace modern_as;
167 uint32_t legacy_io_bar_idx;
168 uint32_t msix_bar_idx;
169 uint32_t modern_io_bar_idx;
170 uint32_t modern_mem_bar_idx;
171 int config_cap;
172 uint32_t flags;
173 bool disable_modern;
174 bool ignore_backend_features;
175 OnOffAuto disable_legacy;
176 uint32_t class_code;
177 uint32_t nvectors;
178 uint32_t dfselect;
179 uint32_t gfselect;
180 uint32_t guest_features[2];
181 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
183 VirtIOIRQFD *vector_irqfd;
184 int nvqs_with_notifiers;
185 VirtioBusState bus;
188 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
190 return !proxy->disable_modern;
193 static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
195 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
198 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
200 proxy->disable_modern = false;
201 proxy->disable_legacy = ON_OFF_AUTO_ON;
204 static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
206 proxy->disable_modern = true;
210 * virtio-scsi-pci: This extends VirtioPCIProxy.
212 #define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci"
213 #define VIRTIO_SCSI_PCI(obj) \
214 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI)
216 struct VirtIOSCSIPCI {
217 VirtIOPCIProxy parent_obj;
218 VirtIOSCSI vdev;
221 #ifdef CONFIG_VHOST_SCSI
223 * vhost-scsi-pci: This extends VirtioPCIProxy.
225 #define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci"
226 #define VHOST_SCSI_PCI(obj) \
227 OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
229 struct VHostSCSIPCI {
230 VirtIOPCIProxy parent_obj;
231 VHostSCSI vdev;
233 #endif
235 #define TYPE_VHOST_USER_SCSI_PCI "vhost-user-scsi-pci"
236 #define VHOST_USER_SCSI_PCI(obj) \
237 OBJECT_CHECK(VHostUserSCSIPCI, (obj), TYPE_VHOST_USER_SCSI_PCI)
239 struct VHostUserSCSIPCI {
240 VirtIOPCIProxy parent_obj;
241 VHostUserSCSI vdev;
245 * virtio-blk-pci: This extends VirtioPCIProxy.
247 #define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
248 #define VIRTIO_BLK_PCI(obj) \
249 OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
251 struct VirtIOBlkPCI {
252 VirtIOPCIProxy parent_obj;
253 VirtIOBlock vdev;
257 * virtio-balloon-pci: This extends VirtioPCIProxy.
259 #define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
260 #define VIRTIO_BALLOON_PCI(obj) \
261 OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
263 struct VirtIOBalloonPCI {
264 VirtIOPCIProxy parent_obj;
265 VirtIOBalloon vdev;
269 * virtio-serial-pci: This extends VirtioPCIProxy.
271 #define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci"
272 #define VIRTIO_SERIAL_PCI(obj) \
273 OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
275 struct VirtIOSerialPCI {
276 VirtIOPCIProxy parent_obj;
277 VirtIOSerial vdev;
281 * virtio-net-pci: This extends VirtioPCIProxy.
283 #define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
284 #define VIRTIO_NET_PCI(obj) \
285 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
287 struct VirtIONetPCI {
288 VirtIOPCIProxy parent_obj;
289 VirtIONet vdev;
293 * virtio-9p-pci: This extends VirtioPCIProxy.
296 #ifdef CONFIG_VIRTFS
298 #define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
299 #define VIRTIO_9P_PCI(obj) \
300 OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
302 typedef struct V9fsPCIState {
303 VirtIOPCIProxy parent_obj;
304 V9fsVirtioState vdev;
305 } V9fsPCIState;
307 #endif
310 * virtio-rng-pci: This extends VirtioPCIProxy.
312 #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
313 #define VIRTIO_RNG_PCI(obj) \
314 OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
316 struct VirtIORngPCI {
317 VirtIOPCIProxy parent_obj;
318 VirtIORNG vdev;
322 * virtio-input-pci: This extends VirtioPCIProxy.
324 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
325 #define VIRTIO_INPUT_PCI(obj) \
326 OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
328 struct VirtIOInputPCI {
329 VirtIOPCIProxy parent_obj;
330 VirtIOInput vdev;
333 #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
334 #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci"
335 #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
336 #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci"
337 #define VIRTIO_INPUT_HID_PCI(obj) \
338 OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI)
340 struct VirtIOInputHIDPCI {
341 VirtIOPCIProxy parent_obj;
342 VirtIOInputHID vdev;
345 #ifdef CONFIG_LINUX
347 #define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
348 #define VIRTIO_INPUT_HOST_PCI(obj) \
349 OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
351 struct VirtIOInputHostPCI {
352 VirtIOPCIProxy parent_obj;
353 VirtIOInputHost vdev;
356 #endif
359 * virtio-gpu-pci: This extends VirtioPCIProxy.
361 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
362 #define VIRTIO_GPU_PCI(obj) \
363 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
365 struct VirtIOGPUPCI {
366 VirtIOPCIProxy parent_obj;
367 VirtIOGPU vdev;
370 #ifdef CONFIG_VHOST_VSOCK
372 * vhost-vsock-pci: This extends VirtioPCIProxy.
374 #define TYPE_VHOST_VSOCK_PCI "vhost-vsock-pci"
375 #define VHOST_VSOCK_PCI(obj) \
376 OBJECT_CHECK(VHostVSockPCI, (obj), TYPE_VHOST_VSOCK_PCI)
378 struct VHostVSockPCI {
379 VirtIOPCIProxy parent_obj;
380 VHostVSock vdev;
382 #endif
385 * virtio-crypto-pci: This extends VirtioPCIProxy.
387 #define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
388 #define VIRTIO_CRYPTO_PCI(obj) \
389 OBJECT_CHECK(VirtIOCryptoPCI, (obj), TYPE_VIRTIO_CRYPTO_PCI)
391 struct VirtIOCryptoPCI {
392 VirtIOPCIProxy parent_obj;
393 VirtIOCrypto vdev;
396 /* Virtio ABI version, if we increment this, we break the guest driver. */
397 #define VIRTIO_PCI_ABI_VERSION 0
399 #endif