blob: b6c442f522823927ff61ccedabe538f6699bb3eb [file] [log] [blame]
Aneesh Kumar K.V9fe1ebe2011-06-01 12:35:13 +05301/*
2 * Virtio PCI Bindings
3 *
4 * Copyright IBM, Corp. 2007
5 * Copyright (c) 2009 CodeSourcery
6 *
7 * Authors:
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Paul Brook <paul@codesourcery.com>
10 *
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
13 */
14
15#ifndef QEMU_VIRTIO_PCI_H
16#define QEMU_VIRTIO_PCI_H
17
KONRAD Fredericcf7c3f02013-01-14 22:52:02 +010018#include "hw/pci/msi.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010019#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"
Gerd Hoffmannf958c8a2015-06-04 12:34:41 +020027#include "hw/virtio/virtio-input.h"
Gerd Hoffmann9eafb622014-09-10 14:20:34 +020028#include "hw/virtio/virtio-gpu.h"
KONRAD Frederic234a3362013-04-23 11:08:41 +020029#ifdef CONFIG_VIRTFS
30#include "hw/9pfs/virtio-9p.h"
31#endif
Nicholas Bellinger50787622013-03-29 01:08:16 +000032#ifdef CONFIG_VHOST_SCSI
33#include "hw/virtio/vhost-scsi.h"
34#endif
KONRAD Frederic0a2acf52013-01-15 00:08:03 +010035
KONRAD Frederic085bccb2013-01-15 00:08:04 +010036typedef struct VirtIOPCIProxy VirtIOPCIProxy;
KONRAD Frederic653ced02013-03-18 17:37:23 +010037typedef struct VirtIOBlkPCI VirtIOBlkPCI;
KONRAD Fredericbc7b90a2013-03-21 15:15:15 +010038typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
KONRAD Frederice378e882013-03-27 10:49:11 +010039typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
KONRAD Fredericf7f74642013-04-09 14:53:31 +020040typedef struct VirtIOSerialPCI VirtIOSerialPCI;
KONRAD Frederice37da392013-04-11 16:29:58 +020041typedef struct VirtIONetPCI VirtIONetPCI;
Nicholas Bellinger50787622013-03-29 01:08:16 +000042typedef struct VHostSCSIPCI VHostSCSIPCI;
KONRAD Frederic59ccd202013-04-24 10:07:56 +020043typedef struct VirtIORngPCI VirtIORngPCI;
Gerd Hoffmannf958c8a2015-06-04 12:34:41 +020044typedef struct VirtIOInputPCI VirtIOInputPCI;
Gerd Hoffmann710e2d92015-06-04 12:34:42 +020045typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
Gerd Hoffmann006a5ed2014-03-28 09:18:47 +010046typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
Gerd Hoffmann9eafb622014-09-10 14:20:34 +020047typedef struct VirtIOGPUPCI VirtIOGPUPCI;
KONRAD Frederic085bccb2013-01-15 00:08:04 +010048
KONRAD Frederic0a2acf52013-01-15 00:08:03 +010049/* virtio-pci-bus */
50
51typedef struct VirtioBusState VirtioPCIBusState;
52typedef struct VirtioBusClass VirtioPCIBusClass;
53
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)
Aneesh Kumar K.V9fe1ebe2011-06-01 12:35:13 +053061
Michael S. Tsirkin68a27b22014-10-14 19:40:06 +030062/* 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)
66
Aneesh Kumar K.V5745e382011-10-12 19:11:23 +053067/* 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)
71
Gerd Hoffmanne266d422015-06-04 12:34:26 +020072/* 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)
77
Aneesh Kumar K.V9fe1ebe2011-06-01 12:35:13 +053078typedef struct {
Michael S. Tsirkin774345f2012-12-21 00:27:54 +020079 MSIMessage msg;
Jan Kiszka7d37d352012-05-17 10:32:39 -030080 int virq;
81 unsigned int users;
82} VirtIOIRQFD;
83
KONRAD Frederic085bccb2013-01-15 00:08:04 +010084/*
85 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
86 */
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)
94
95typedef struct VirtioPCIClass {
96 PCIDeviceClass parent_class;
Markus Armbrusterfc079952015-02-27 14:52:14 +010097 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
KONRAD Frederic085bccb2013-01-15 00:08:04 +010098} VirtioPCIClass;
99
Gerd Hoffmann588255a2015-06-04 12:34:33 +0200100typedef struct VirtIOPCIRegion {
101 MemoryRegion mr;
Gerd Hoffmanna3cc2e82015-06-04 12:34:35 +0200102 uint32_t offset;
Gerd Hoffmannb6ce27a2015-06-04 12:34:39 +0200103 uint32_t size;
Gerd Hoffmannfc004902015-06-04 12:34:37 +0200104 uint32_t type;
Gerd Hoffmann588255a2015-06-04 12:34:33 +0200105} VirtIOPCIRegion;
106
KONRAD Frederic085bccb2013-01-15 00:08:04 +0100107struct VirtIOPCIProxy {
Aneesh Kumar K.V9fe1ebe2011-06-01 12:35:13 +0530108 PCIDevice pci_dev;
Avi Kivityda146d02011-08-08 16:09:13 +0300109 MemoryRegion bar;
Gerd Hoffmann588255a2015-06-04 12:34:33 +0200110 VirtIOPCIRegion common;
111 VirtIOPCIRegion isr;
112 VirtIOPCIRegion device;
113 VirtIOPCIRegion notify;
Michael S. Tsirkindfb8e182015-06-04 12:34:22 +0200114 MemoryRegion modern_bar;
Michael S. Tsirkinada434c2015-07-02 14:59:49 +0200115 MemoryRegion modern_cfg;
116 AddressSpace modern_as;
Gerd Hoffmannb6ce27a2015-06-04 12:34:39 +0200117 uint32_t legacy_io_bar;
118 uint32_t msix_bar;
119 uint32_t modern_mem_bar;
Michael S. Tsirkinada434c2015-07-02 14:59:49 +0200120 int config_cap;
Aneesh Kumar K.V9fe1ebe2011-06-01 12:35:13 +0530121 uint32_t flags;
Aneesh Kumar K.V9fe1ebe2011-06-01 12:35:13 +0530122 uint32_t class_code;
123 uint32_t nvectors;
Michael S. Tsirkindfb8e182015-06-04 12:34:22 +0200124 uint32_t dfselect;
125 uint32_t gfselect;
126 uint32_t guest_features[2];
127 struct {
128 uint16_t num;
129 bool enabled;
130 uint32_t desc[2];
131 uint32_t avail[2];
132 uint32_t used[2];
133 } vqs[VIRTIO_QUEUE_MAX];
134
Aneesh Kumar K.V9fe1ebe2011-06-01 12:35:13 +0530135 bool ioeventfd_disabled;
136 bool ioeventfd_started;
Jan Kiszka7d37d352012-05-17 10:32:39 -0300137 VirtIOIRQFD *vector_irqfd;
Michael S. Tsirkin2d620f52012-12-20 14:28:58 +0200138 int nvqs_with_notifiers;
KONRAD Frederic085bccb2013-01-15 00:08:04 +0100139 VirtioBusState bus;
140};
Aneesh Kumar K.V9fe1ebe2011-06-01 12:35:13 +0530141
KONRAD Fredericbc7b90a2013-03-21 15:15:15 +0100142
143/*
144 * virtio-scsi-pci: This extends VirtioPCIProxy.
145 */
146#define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci"
147#define VIRTIO_SCSI_PCI(obj) \
148 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI)
149
150struct VirtIOSCSIPCI {
151 VirtIOPCIProxy parent_obj;
152 VirtIOSCSI vdev;
153};
154
Nicholas Bellinger50787622013-03-29 01:08:16 +0000155#ifdef CONFIG_VHOST_SCSI
156/*
157 * vhost-scsi-pci: This extends VirtioPCIProxy.
158 */
159#define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci"
160#define VHOST_SCSI_PCI(obj) \
161 OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
162
163struct VHostSCSIPCI {
164 VirtIOPCIProxy parent_obj;
165 VHostSCSI vdev;
166};
167#endif
168
KONRAD Frederic653ced02013-03-18 17:37:23 +0100169/*
170 * virtio-blk-pci: This extends VirtioPCIProxy.
171 */
172#define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
173#define VIRTIO_BLK_PCI(obj) \
174 OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
175
176struct VirtIOBlkPCI {
177 VirtIOPCIProxy parent_obj;
178 VirtIOBlock vdev;
KONRAD Frederic653ced02013-03-18 17:37:23 +0100179};
180
KONRAD Frederice378e882013-03-27 10:49:11 +0100181/*
182 * virtio-balloon-pci: This extends VirtioPCIProxy.
183 */
184#define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
185#define VIRTIO_BALLOON_PCI(obj) \
186 OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
187
188struct VirtIOBalloonPCI {
189 VirtIOPCIProxy parent_obj;
190 VirtIOBalloon vdev;
191};
192
KONRAD Fredericf7f74642013-04-09 14:53:31 +0200193/*
194 * virtio-serial-pci: This extends VirtioPCIProxy.
195 */
196#define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci"
197#define VIRTIO_SERIAL_PCI(obj) \
198 OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
199
200struct VirtIOSerialPCI {
201 VirtIOPCIProxy parent_obj;
202 VirtIOSerial vdev;
203};
204
KONRAD Frederice37da392013-04-11 16:29:58 +0200205/*
206 * virtio-net-pci: This extends VirtioPCIProxy.
207 */
208#define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
209#define VIRTIO_NET_PCI(obj) \
210 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
211
212struct VirtIONetPCI {
213 VirtIOPCIProxy parent_obj;
214 VirtIONet vdev;
215};
216
KONRAD Frederic234a3362013-04-23 11:08:41 +0200217/*
218 * virtio-9p-pci: This extends VirtioPCIProxy.
219 */
220
221#ifdef CONFIG_VIRTFS
222
223#define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
224#define VIRTIO_9P_PCI(obj) \
225 OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
226
227typedef struct V9fsPCIState {
228 VirtIOPCIProxy parent_obj;
229 V9fsState vdev;
230} V9fsPCIState;
231
232#endif
233
KONRAD Frederic59ccd202013-04-24 10:07:56 +0200234/*
235 * virtio-rng-pci: This extends VirtioPCIProxy.
236 */
237#define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
238#define VIRTIO_RNG_PCI(obj) \
239 OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
240
241struct VirtIORngPCI {
242 VirtIOPCIProxy parent_obj;
243 VirtIORNG vdev;
244};
245
Gerd Hoffmannf958c8a2015-06-04 12:34:41 +0200246/*
247 * virtio-input-pci: This extends VirtioPCIProxy.
248 */
249#define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
250#define VIRTIO_INPUT_PCI(obj) \
251 OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
252
253struct VirtIOInputPCI {
254 VirtIOPCIProxy parent_obj;
255 VirtIOInput vdev;
256};
257
Gerd Hoffmann710e2d92015-06-04 12:34:42 +0200258#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)
264
265struct VirtIOInputHIDPCI {
266 VirtIOPCIProxy parent_obj;
267 VirtIOInputHID vdev;
268};
269
Gerd Hoffmann006a5ed2014-03-28 09:18:47 +0100270#define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
271#define VIRTIO_INPUT_HOST_PCI(obj) \
272 OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
273
274struct VirtIOInputHostPCI {
275 VirtIOPCIProxy parent_obj;
276 VirtIOInputHost vdev;
277};
278
Gerd Hoffmann9eafb622014-09-10 14:20:34 +0200279/*
280 * virtio-gpu-pci: This extends VirtioPCIProxy.
281 */
282#define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
283#define VIRTIO_GPU_PCI(obj) \
284 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
285
286struct VirtIOGPUPCI {
287 VirtIOPCIProxy parent_obj;
288 VirtIOGPU vdev;
289};
290
Michael S. Tsirkinbefeac42011-06-14 17:51:11 +0300291/* Virtio ABI version, if we increment this, we break the guest driver. */
292#define VIRTIO_PCI_ABI_VERSION 0
293
Aneesh Kumar K.V9fe1ebe2011-06-01 12:35:13 +0530294#endif