util/qemu-config: Add loadparm to qemu machine_opts
[qemu.git] / hw / virtio / virtio-pci.h
blobb095dfc6d9e7cea0dc511fed361da7e5036db30f
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"
30 #ifdef CONFIG_VIRTFS
31 #include "hw/9pfs/virtio-9p.h"
32 #endif
33 #ifdef CONFIG_VHOST_SCSI
34 #include "hw/virtio/vhost-scsi.h"
35 #endif
36 #ifdef CONFIG_VHOST_VSOCK
37 #include "hw/virtio/vhost-vsock.h"
38 #endif
40 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
41 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
42 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
43 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
44 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
45 typedef struct VirtIONetPCI VirtIONetPCI;
46 typedef struct VHostSCSIPCI VHostSCSIPCI;
47 typedef struct VirtIORngPCI VirtIORngPCI;
48 typedef struct VirtIOInputPCI VirtIOInputPCI;
49 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
50 typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
51 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
52 typedef struct VHostVSockPCI VHostVSockPCI;
53 typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
55 /* virtio-pci-bus */
57 typedef struct VirtioBusState VirtioPCIBusState;
58 typedef struct VirtioBusClass VirtioPCIBusClass;
60 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
61 #define VIRTIO_PCI_BUS(obj) \
62 OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
63 #define VIRTIO_PCI_BUS_GET_CLASS(obj) \
64 OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
65 #define VIRTIO_PCI_BUS_CLASS(klass) \
66 OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
68 enum {
69 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
70 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
71 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
72 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
73 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
74 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
75 VIRTIO_PCI_FLAG_ATS_BIT,
76 VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
77 VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
78 VIRTIO_PCI_FLAG_INIT_PM_BIT,
81 /* Need to activate work-arounds for buggy guests at vmstate load. */
82 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
83 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
85 /* Performance improves when virtqueue kick processing is decoupled from the
86 * vcpu thread using ioeventfd for some devices. */
87 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
89 /* virtio version flags */
90 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
92 /* migrate extra state */
93 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
95 /* have pio notification for modern device ? */
96 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
97 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
99 /* page per vq flag to be used by split drivers within guests */
100 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
101 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
103 /* address space translation service */
104 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
106 /* Init error enabling flags */
107 #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
109 /* Init Link Control register */
110 #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
112 /* Init Power Management */
113 #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
115 typedef struct {
116 MSIMessage msg;
117 int virq;
118 unsigned int users;
119 } VirtIOIRQFD;
122 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
124 #define TYPE_VIRTIO_PCI "virtio-pci"
125 #define VIRTIO_PCI_GET_CLASS(obj) \
126 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
127 #define VIRTIO_PCI_CLASS(klass) \
128 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
129 #define VIRTIO_PCI(obj) \
130 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
132 typedef struct VirtioPCIClass {
133 PCIDeviceClass parent_class;
134 DeviceRealize parent_dc_realize;
135 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
136 } VirtioPCIClass;
138 typedef struct VirtIOPCIRegion {
139 MemoryRegion mr;
140 uint32_t offset;
141 uint32_t size;
142 uint32_t type;
143 } VirtIOPCIRegion;
145 typedef struct VirtIOPCIQueue {
146 uint16_t num;
147 bool enabled;
148 uint32_t desc[2];
149 uint32_t avail[2];
150 uint32_t used[2];
151 } VirtIOPCIQueue;
153 struct VirtIOPCIProxy {
154 PCIDevice pci_dev;
155 MemoryRegion bar;
156 VirtIOPCIRegion common;
157 VirtIOPCIRegion isr;
158 VirtIOPCIRegion device;
159 VirtIOPCIRegion notify;
160 VirtIOPCIRegion notify_pio;
161 MemoryRegion modern_bar;
162 MemoryRegion io_bar;
163 MemoryRegion modern_cfg;
164 AddressSpace modern_as;
165 uint32_t legacy_io_bar_idx;
166 uint32_t msix_bar_idx;
167 uint32_t modern_io_bar_idx;
168 uint32_t modern_mem_bar_idx;
169 int config_cap;
170 uint32_t flags;
171 bool disable_modern;
172 bool ignore_backend_features;
173 OnOffAuto disable_legacy;
174 uint32_t class_code;
175 uint32_t nvectors;
176 uint32_t dfselect;
177 uint32_t gfselect;
178 uint32_t guest_features[2];
179 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
181 VirtIOIRQFD *vector_irqfd;
182 int nvqs_with_notifiers;
183 VirtioBusState bus;
186 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
188 return !proxy->disable_modern;
191 static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
193 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
196 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
198 proxy->disable_modern = false;
199 proxy->disable_legacy = ON_OFF_AUTO_ON;
202 static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
204 proxy->disable_modern = true;
208 * virtio-scsi-pci: This extends VirtioPCIProxy.
210 #define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci"
211 #define VIRTIO_SCSI_PCI(obj) \
212 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI)
214 struct VirtIOSCSIPCI {
215 VirtIOPCIProxy parent_obj;
216 VirtIOSCSI vdev;
219 #ifdef CONFIG_VHOST_SCSI
221 * vhost-scsi-pci: This extends VirtioPCIProxy.
223 #define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci"
224 #define VHOST_SCSI_PCI(obj) \
225 OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
227 struct VHostSCSIPCI {
228 VirtIOPCIProxy parent_obj;
229 VHostSCSI vdev;
231 #endif
234 * virtio-blk-pci: This extends VirtioPCIProxy.
236 #define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
237 #define VIRTIO_BLK_PCI(obj) \
238 OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
240 struct VirtIOBlkPCI {
241 VirtIOPCIProxy parent_obj;
242 VirtIOBlock vdev;
246 * virtio-balloon-pci: This extends VirtioPCIProxy.
248 #define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
249 #define VIRTIO_BALLOON_PCI(obj) \
250 OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
252 struct VirtIOBalloonPCI {
253 VirtIOPCIProxy parent_obj;
254 VirtIOBalloon vdev;
258 * virtio-serial-pci: This extends VirtioPCIProxy.
260 #define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci"
261 #define VIRTIO_SERIAL_PCI(obj) \
262 OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
264 struct VirtIOSerialPCI {
265 VirtIOPCIProxy parent_obj;
266 VirtIOSerial vdev;
270 * virtio-net-pci: This extends VirtioPCIProxy.
272 #define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
273 #define VIRTIO_NET_PCI(obj) \
274 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
276 struct VirtIONetPCI {
277 VirtIOPCIProxy parent_obj;
278 VirtIONet vdev;
282 * virtio-9p-pci: This extends VirtioPCIProxy.
285 #ifdef CONFIG_VIRTFS
287 #define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
288 #define VIRTIO_9P_PCI(obj) \
289 OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
291 typedef struct V9fsPCIState {
292 VirtIOPCIProxy parent_obj;
293 V9fsVirtioState vdev;
294 } V9fsPCIState;
296 #endif
299 * virtio-rng-pci: This extends VirtioPCIProxy.
301 #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
302 #define VIRTIO_RNG_PCI(obj) \
303 OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
305 struct VirtIORngPCI {
306 VirtIOPCIProxy parent_obj;
307 VirtIORNG vdev;
311 * virtio-input-pci: This extends VirtioPCIProxy.
313 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
314 #define VIRTIO_INPUT_PCI(obj) \
315 OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
317 struct VirtIOInputPCI {
318 VirtIOPCIProxy parent_obj;
319 VirtIOInput vdev;
322 #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
323 #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci"
324 #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
325 #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci"
326 #define VIRTIO_INPUT_HID_PCI(obj) \
327 OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI)
329 struct VirtIOInputHIDPCI {
330 VirtIOPCIProxy parent_obj;
331 VirtIOInputHID vdev;
334 #ifdef CONFIG_LINUX
336 #define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
337 #define VIRTIO_INPUT_HOST_PCI(obj) \
338 OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
340 struct VirtIOInputHostPCI {
341 VirtIOPCIProxy parent_obj;
342 VirtIOInputHost vdev;
345 #endif
348 * virtio-gpu-pci: This extends VirtioPCIProxy.
350 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
351 #define VIRTIO_GPU_PCI(obj) \
352 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
354 struct VirtIOGPUPCI {
355 VirtIOPCIProxy parent_obj;
356 VirtIOGPU vdev;
359 #ifdef CONFIG_VHOST_VSOCK
361 * vhost-vsock-pci: This extends VirtioPCIProxy.
363 #define TYPE_VHOST_VSOCK_PCI "vhost-vsock-pci"
364 #define VHOST_VSOCK_PCI(obj) \
365 OBJECT_CHECK(VHostVSockPCI, (obj), TYPE_VHOST_VSOCK_PCI)
367 struct VHostVSockPCI {
368 VirtIOPCIProxy parent_obj;
369 VHostVSock vdev;
371 #endif
374 * virtio-crypto-pci: This extends VirtioPCIProxy.
376 #define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
377 #define VIRTIO_CRYPTO_PCI(obj) \
378 OBJECT_CHECK(VirtIOCryptoPCI, (obj), TYPE_VIRTIO_CRYPTO_PCI)
380 struct VirtIOCryptoPCI {
381 VirtIOPCIProxy parent_obj;
382 VirtIOCrypto vdev;
385 /* Virtio ABI version, if we increment this, we break the guest driver. */
386 #define VIRTIO_PCI_ABI_VERSION 0
388 #endif