Aneesh Kumar K.V | 9fe1ebe | 2011-06-01 12:35:13 +0530 | [diff] [blame] | 1 | /* |
| 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 Frederic | cf7c3f0 | 2013-01-14 22:52:02 +0100 | [diff] [blame] | 18 | #include "hw/pci/msi.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 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" |
Gerd Hoffmann | f958c8a | 2015-06-04 12:34:41 +0200 | [diff] [blame] | 27 | #include "hw/virtio/virtio-input.h" |
Gerd Hoffmann | 9eafb62 | 2014-09-10 14:20:34 +0200 | [diff] [blame] | 28 | #include "hw/virtio/virtio-gpu.h" |
KONRAD Frederic | 234a336 | 2013-04-23 11:08:41 +0200 | [diff] [blame] | 29 | #ifdef CONFIG_VIRTFS |
| 30 | #include "hw/9pfs/virtio-9p.h" |
| 31 | #endif |
Nicholas Bellinger | 5078762 | 2013-03-29 01:08:16 +0000 | [diff] [blame] | 32 | #ifdef CONFIG_VHOST_SCSI |
| 33 | #include "hw/virtio/vhost-scsi.h" |
| 34 | #endif |
KONRAD Frederic | 0a2acf5 | 2013-01-15 00:08:03 +0100 | [diff] [blame] | 35 | |
KONRAD Frederic | 085bccb | 2013-01-15 00:08:04 +0100 | [diff] [blame] | 36 | typedef struct VirtIOPCIProxy VirtIOPCIProxy; |
KONRAD Frederic | 653ced0 | 2013-03-18 17:37:23 +0100 | [diff] [blame] | 37 | typedef struct VirtIOBlkPCI VirtIOBlkPCI; |
KONRAD Frederic | bc7b90a | 2013-03-21 15:15:15 +0100 | [diff] [blame] | 38 | typedef struct VirtIOSCSIPCI VirtIOSCSIPCI; |
KONRAD Frederic | e378e88 | 2013-03-27 10:49:11 +0100 | [diff] [blame] | 39 | typedef struct VirtIOBalloonPCI VirtIOBalloonPCI; |
KONRAD Frederic | f7f7464 | 2013-04-09 14:53:31 +0200 | [diff] [blame] | 40 | typedef struct VirtIOSerialPCI VirtIOSerialPCI; |
KONRAD Frederic | e37da39 | 2013-04-11 16:29:58 +0200 | [diff] [blame] | 41 | typedef struct VirtIONetPCI VirtIONetPCI; |
Nicholas Bellinger | 5078762 | 2013-03-29 01:08:16 +0000 | [diff] [blame] | 42 | typedef struct VHostSCSIPCI VHostSCSIPCI; |
KONRAD Frederic | 59ccd20 | 2013-04-24 10:07:56 +0200 | [diff] [blame] | 43 | typedef struct VirtIORngPCI VirtIORngPCI; |
Gerd Hoffmann | f958c8a | 2015-06-04 12:34:41 +0200 | [diff] [blame] | 44 | typedef struct VirtIOInputPCI VirtIOInputPCI; |
Gerd Hoffmann | 710e2d9 | 2015-06-04 12:34:42 +0200 | [diff] [blame] | 45 | typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI; |
Gerd Hoffmann | 006a5ed | 2014-03-28 09:18:47 +0100 | [diff] [blame] | 46 | typedef struct VirtIOInputHostPCI VirtIOInputHostPCI; |
Gerd Hoffmann | 9eafb62 | 2014-09-10 14:20:34 +0200 | [diff] [blame] | 47 | typedef struct VirtIOGPUPCI VirtIOGPUPCI; |
KONRAD Frederic | 085bccb | 2013-01-15 00:08:04 +0100 | [diff] [blame] | 48 | |
KONRAD Frederic | 0a2acf5 | 2013-01-15 00:08:03 +0100 | [diff] [blame] | 49 | /* virtio-pci-bus */ |
| 50 | |
| 51 | typedef struct VirtioBusState VirtioPCIBusState; |
| 52 | typedef 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.V | 9fe1ebe | 2011-06-01 12:35:13 +0530 | [diff] [blame] | 61 | |
Michael S. Tsirkin | 68a27b2 | 2014-10-14 19:40:06 +0300 | [diff] [blame] | 62 | /* 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.V | 5745e38 | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 67 | /* 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 Hoffmann | e266d42 | 2015-06-04 12:34:26 +0200 | [diff] [blame] | 72 | /* 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.V | 9fe1ebe | 2011-06-01 12:35:13 +0530 | [diff] [blame] | 78 | typedef struct { |
Michael S. Tsirkin | 774345f | 2012-12-21 00:27:54 +0200 | [diff] [blame] | 79 | MSIMessage msg; |
Jan Kiszka | 7d37d35 | 2012-05-17 10:32:39 -0300 | [diff] [blame] | 80 | int virq; |
| 81 | unsigned int users; |
| 82 | } VirtIOIRQFD; |
| 83 | |
KONRAD Frederic | 085bccb | 2013-01-15 00:08:04 +0100 | [diff] [blame] | 84 | /* |
| 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 | |
| 95 | typedef struct VirtioPCIClass { |
| 96 | PCIDeviceClass parent_class; |
Markus Armbruster | fc07995 | 2015-02-27 14:52:14 +0100 | [diff] [blame] | 97 | void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp); |
KONRAD Frederic | 085bccb | 2013-01-15 00:08:04 +0100 | [diff] [blame] | 98 | } VirtioPCIClass; |
| 99 | |
Gerd Hoffmann | 588255a | 2015-06-04 12:34:33 +0200 | [diff] [blame] | 100 | typedef struct VirtIOPCIRegion { |
| 101 | MemoryRegion mr; |
Gerd Hoffmann | a3cc2e8 | 2015-06-04 12:34:35 +0200 | [diff] [blame] | 102 | uint32_t offset; |
Gerd Hoffmann | b6ce27a | 2015-06-04 12:34:39 +0200 | [diff] [blame] | 103 | uint32_t size; |
Gerd Hoffmann | fc00490 | 2015-06-04 12:34:37 +0200 | [diff] [blame] | 104 | uint32_t type; |
Gerd Hoffmann | 588255a | 2015-06-04 12:34:33 +0200 | [diff] [blame] | 105 | } VirtIOPCIRegion; |
| 106 | |
KONRAD Frederic | 085bccb | 2013-01-15 00:08:04 +0100 | [diff] [blame] | 107 | struct VirtIOPCIProxy { |
Aneesh Kumar K.V | 9fe1ebe | 2011-06-01 12:35:13 +0530 | [diff] [blame] | 108 | PCIDevice pci_dev; |
Avi Kivity | da146d0 | 2011-08-08 16:09:13 +0300 | [diff] [blame] | 109 | MemoryRegion bar; |
Gerd Hoffmann | 588255a | 2015-06-04 12:34:33 +0200 | [diff] [blame] | 110 | VirtIOPCIRegion common; |
| 111 | VirtIOPCIRegion isr; |
| 112 | VirtIOPCIRegion device; |
| 113 | VirtIOPCIRegion notify; |
Michael S. Tsirkin | dfb8e18 | 2015-06-04 12:34:22 +0200 | [diff] [blame] | 114 | MemoryRegion modern_bar; |
Michael S. Tsirkin | ada434c | 2015-07-02 14:59:49 +0200 | [diff] [blame] | 115 | MemoryRegion modern_cfg; |
| 116 | AddressSpace modern_as; |
Gerd Hoffmann | b6ce27a | 2015-06-04 12:34:39 +0200 | [diff] [blame] | 117 | uint32_t legacy_io_bar; |
| 118 | uint32_t msix_bar; |
| 119 | uint32_t modern_mem_bar; |
Michael S. Tsirkin | ada434c | 2015-07-02 14:59:49 +0200 | [diff] [blame] | 120 | int config_cap; |
Aneesh Kumar K.V | 9fe1ebe | 2011-06-01 12:35:13 +0530 | [diff] [blame] | 121 | uint32_t flags; |
Aneesh Kumar K.V | 9fe1ebe | 2011-06-01 12:35:13 +0530 | [diff] [blame] | 122 | uint32_t class_code; |
| 123 | uint32_t nvectors; |
Michael S. Tsirkin | dfb8e18 | 2015-06-04 12:34:22 +0200 | [diff] [blame] | 124 | 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.V | 9fe1ebe | 2011-06-01 12:35:13 +0530 | [diff] [blame] | 135 | bool ioeventfd_disabled; |
| 136 | bool ioeventfd_started; |
Jan Kiszka | 7d37d35 | 2012-05-17 10:32:39 -0300 | [diff] [blame] | 137 | VirtIOIRQFD *vector_irqfd; |
Michael S. Tsirkin | 2d620f5 | 2012-12-20 14:28:58 +0200 | [diff] [blame] | 138 | int nvqs_with_notifiers; |
KONRAD Frederic | 085bccb | 2013-01-15 00:08:04 +0100 | [diff] [blame] | 139 | VirtioBusState bus; |
| 140 | }; |
Aneesh Kumar K.V | 9fe1ebe | 2011-06-01 12:35:13 +0530 | [diff] [blame] | 141 | |
KONRAD Frederic | bc7b90a | 2013-03-21 15:15:15 +0100 | [diff] [blame] | 142 | |
| 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 | |
| 150 | struct VirtIOSCSIPCI { |
| 151 | VirtIOPCIProxy parent_obj; |
| 152 | VirtIOSCSI vdev; |
| 153 | }; |
| 154 | |
Nicholas Bellinger | 5078762 | 2013-03-29 01:08:16 +0000 | [diff] [blame] | 155 | #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 | |
| 163 | struct VHostSCSIPCI { |
| 164 | VirtIOPCIProxy parent_obj; |
| 165 | VHostSCSI vdev; |
| 166 | }; |
| 167 | #endif |
| 168 | |
KONRAD Frederic | 653ced0 | 2013-03-18 17:37:23 +0100 | [diff] [blame] | 169 | /* |
| 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 | |
| 176 | struct VirtIOBlkPCI { |
| 177 | VirtIOPCIProxy parent_obj; |
| 178 | VirtIOBlock vdev; |
KONRAD Frederic | 653ced0 | 2013-03-18 17:37:23 +0100 | [diff] [blame] | 179 | }; |
| 180 | |
KONRAD Frederic | e378e88 | 2013-03-27 10:49:11 +0100 | [diff] [blame] | 181 | /* |
| 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 | |
| 188 | struct VirtIOBalloonPCI { |
| 189 | VirtIOPCIProxy parent_obj; |
| 190 | VirtIOBalloon vdev; |
| 191 | }; |
| 192 | |
KONRAD Frederic | f7f7464 | 2013-04-09 14:53:31 +0200 | [diff] [blame] | 193 | /* |
| 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 | |
| 200 | struct VirtIOSerialPCI { |
| 201 | VirtIOPCIProxy parent_obj; |
| 202 | VirtIOSerial vdev; |
| 203 | }; |
| 204 | |
KONRAD Frederic | e37da39 | 2013-04-11 16:29:58 +0200 | [diff] [blame] | 205 | /* |
| 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 | |
| 212 | struct VirtIONetPCI { |
| 213 | VirtIOPCIProxy parent_obj; |
| 214 | VirtIONet vdev; |
| 215 | }; |
| 216 | |
KONRAD Frederic | 234a336 | 2013-04-23 11:08:41 +0200 | [diff] [blame] | 217 | /* |
| 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 | |
| 227 | typedef struct V9fsPCIState { |
| 228 | VirtIOPCIProxy parent_obj; |
| 229 | V9fsState vdev; |
| 230 | } V9fsPCIState; |
| 231 | |
| 232 | #endif |
| 233 | |
KONRAD Frederic | 59ccd20 | 2013-04-24 10:07:56 +0200 | [diff] [blame] | 234 | /* |
| 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 | |
| 241 | struct VirtIORngPCI { |
| 242 | VirtIOPCIProxy parent_obj; |
| 243 | VirtIORNG vdev; |
| 244 | }; |
| 245 | |
Gerd Hoffmann | f958c8a | 2015-06-04 12:34:41 +0200 | [diff] [blame] | 246 | /* |
| 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 | |
| 253 | struct VirtIOInputPCI { |
| 254 | VirtIOPCIProxy parent_obj; |
| 255 | VirtIOInput vdev; |
| 256 | }; |
| 257 | |
Gerd Hoffmann | 710e2d9 | 2015-06-04 12:34:42 +0200 | [diff] [blame] | 258 | #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 | |
| 265 | struct VirtIOInputHIDPCI { |
| 266 | VirtIOPCIProxy parent_obj; |
| 267 | VirtIOInputHID vdev; |
| 268 | }; |
| 269 | |
Gerd Hoffmann | 006a5ed | 2014-03-28 09:18:47 +0100 | [diff] [blame] | 270 | #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 | |
| 274 | struct VirtIOInputHostPCI { |
| 275 | VirtIOPCIProxy parent_obj; |
| 276 | VirtIOInputHost vdev; |
| 277 | }; |
| 278 | |
Gerd Hoffmann | 9eafb62 | 2014-09-10 14:20:34 +0200 | [diff] [blame] | 279 | /* |
| 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 | |
| 286 | struct VirtIOGPUPCI { |
| 287 | VirtIOPCIProxy parent_obj; |
| 288 | VirtIOGPU vdev; |
| 289 | }; |
| 290 | |
Michael S. Tsirkin | befeac4 | 2011-06-14 17:51:11 +0300 | [diff] [blame] | 291 | /* Virtio ABI version, if we increment this, we break the guest driver. */ |
| 292 | #define VIRTIO_PCI_ABI_VERSION 0 |
| 293 | |
Aneesh Kumar K.V | 9fe1ebe | 2011-06-01 12:35:13 +0530 | [diff] [blame] | 294 | #endif |