virtio-pci: initial virtio 1.0 support
[qemu/ar7.git] / hw / virtio / virtio-pci.h
blob7a6481f96d37a7f5ff011581da74063ffc0eea50
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-9p.h"
27 #ifdef CONFIG_VIRTFS
28 #include "hw/9pfs/virtio-9p.h"
29 #endif
30 #ifdef CONFIG_VHOST_SCSI
31 #include "hw/virtio/vhost-scsi.h"
32 #endif
34 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
35 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
36 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
37 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
38 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
39 typedef struct VirtIONetPCI VirtIONetPCI;
40 typedef struct VHostSCSIPCI VHostSCSIPCI;
41 typedef struct VirtIORngPCI VirtIORngPCI;
43 /* virtio-pci-bus */
45 typedef struct VirtioBusState VirtioPCIBusState;
46 typedef struct VirtioBusClass VirtioPCIBusClass;
48 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
49 #define VIRTIO_PCI_BUS(obj) \
50 OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
51 #define VIRTIO_PCI_BUS_GET_CLASS(obj) \
52 OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
53 #define VIRTIO_PCI_BUS_CLASS(klass) \
54 OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
56 /* Need to activate work-arounds for buggy guests at vmstate load. */
57 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT 0
58 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
59 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
61 /* Performance improves when virtqueue kick processing is decoupled from the
62 * vcpu thread using ioeventfd for some devices. */
63 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1
64 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
66 typedef struct {
67 MSIMessage msg;
68 int virq;
69 unsigned int users;
70 } VirtIOIRQFD;
73 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
75 #define TYPE_VIRTIO_PCI "virtio-pci"
76 #define VIRTIO_PCI_GET_CLASS(obj) \
77 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
78 #define VIRTIO_PCI_CLASS(klass) \
79 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
80 #define VIRTIO_PCI(obj) \
81 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
83 typedef struct VirtioPCIClass {
84 PCIDeviceClass parent_class;
85 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
86 } VirtioPCIClass;
88 struct VirtIOPCIProxy {
89 PCIDevice pci_dev;
90 MemoryRegion bar;
91 MemoryRegion common;
92 MemoryRegion isr;
93 MemoryRegion device;
94 MemoryRegion notify;
95 MemoryRegion modern_bar;
96 uint32_t flags;
97 uint32_t class_code;
98 uint32_t nvectors;
99 uint32_t dfselect;
100 uint32_t gfselect;
101 uint32_t guest_features[2];
102 struct {
103 uint16_t num;
104 bool enabled;
105 uint32_t desc[2];
106 uint32_t avail[2];
107 uint32_t used[2];
108 } vqs[VIRTIO_QUEUE_MAX];
110 bool ioeventfd_disabled;
111 bool ioeventfd_started;
112 VirtIOIRQFD *vector_irqfd;
113 int nvqs_with_notifiers;
114 VirtioBusState bus;
119 * virtio-scsi-pci: This extends VirtioPCIProxy.
121 #define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci"
122 #define VIRTIO_SCSI_PCI(obj) \
123 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI)
125 struct VirtIOSCSIPCI {
126 VirtIOPCIProxy parent_obj;
127 VirtIOSCSI vdev;
130 #ifdef CONFIG_VHOST_SCSI
132 * vhost-scsi-pci: This extends VirtioPCIProxy.
134 #define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci"
135 #define VHOST_SCSI_PCI(obj) \
136 OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
138 struct VHostSCSIPCI {
139 VirtIOPCIProxy parent_obj;
140 VHostSCSI vdev;
142 #endif
145 * virtio-blk-pci: This extends VirtioPCIProxy.
147 #define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
148 #define VIRTIO_BLK_PCI(obj) \
149 OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
151 struct VirtIOBlkPCI {
152 VirtIOPCIProxy parent_obj;
153 VirtIOBlock vdev;
157 * virtio-balloon-pci: This extends VirtioPCIProxy.
159 #define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
160 #define VIRTIO_BALLOON_PCI(obj) \
161 OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
163 struct VirtIOBalloonPCI {
164 VirtIOPCIProxy parent_obj;
165 VirtIOBalloon vdev;
169 * virtio-serial-pci: This extends VirtioPCIProxy.
171 #define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci"
172 #define VIRTIO_SERIAL_PCI(obj) \
173 OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
175 struct VirtIOSerialPCI {
176 VirtIOPCIProxy parent_obj;
177 VirtIOSerial vdev;
181 * virtio-net-pci: This extends VirtioPCIProxy.
183 #define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
184 #define VIRTIO_NET_PCI(obj) \
185 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
187 struct VirtIONetPCI {
188 VirtIOPCIProxy parent_obj;
189 VirtIONet vdev;
193 * virtio-9p-pci: This extends VirtioPCIProxy.
196 #ifdef CONFIG_VIRTFS
198 #define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
199 #define VIRTIO_9P_PCI(obj) \
200 OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
202 typedef struct V9fsPCIState {
203 VirtIOPCIProxy parent_obj;
204 V9fsState vdev;
205 } V9fsPCIState;
207 #endif
210 * virtio-rng-pci: This extends VirtioPCIProxy.
212 #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
213 #define VIRTIO_RNG_PCI(obj) \
214 OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
216 struct VirtIORngPCI {
217 VirtIOPCIProxy parent_obj;
218 VirtIORNG vdev;
221 /* Virtio ABI version, if we increment this, we break the guest driver. */
222 #define VIRTIO_PCI_ABI_VERSION 0
224 #endif