2011-06-01 09:05:13 +02:00
|
|
|
/*
|
|
|
|
* Virtio PCI Bindings
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2007
|
|
|
|
* Copyright (c) 2009 CodeSourcery
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
* Paul Brook <paul@codesourcery.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QEMU_VIRTIO_PCI_H
|
|
|
|
#define QEMU_VIRTIO_PCI_H
|
|
|
|
|
2019-02-15 11:32:38 +01:00
|
|
|
#include "qapi/error.h"
|
2013-01-14 22:52:02 +01:00
|
|
|
#include "hw/pci/msi.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/virtio/virtio-bus.h"
|
2016-10-28 10:33:25 +02:00
|
|
|
|
2013-01-15 00:08:04 +01:00
|
|
|
typedef struct VirtIOPCIProxy VirtIOPCIProxy;
|
|
|
|
|
2013-01-15 00:08:03 +01:00
|
|
|
/* virtio-pci-bus */
|
|
|
|
|
|
|
|
typedef struct VirtioBusState VirtioPCIBusState;
|
|
|
|
typedef struct VirtioBusClass VirtioPCIBusClass;
|
|
|
|
|
|
|
|
#define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
|
|
|
|
#define VIRTIO_PCI_BUS(obj) \
|
|
|
|
OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
|
|
|
|
#define VIRTIO_PCI_BUS_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
|
|
|
|
#define VIRTIO_PCI_BUS_CLASS(klass) \
|
|
|
|
OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
|
2011-06-01 09:05:13 +02:00
|
|
|
|
2016-02-10 14:31:13 +01:00
|
|
|
enum {
|
|
|
|
VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
|
|
|
|
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
|
|
|
|
VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
|
|
|
|
VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
|
|
|
|
VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
|
2016-09-07 17:02:25 +02:00
|
|
|
VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
|
2016-12-30 11:09:15 +01:00
|
|
|
VIRTIO_PCI_FLAG_ATS_BIT,
|
2017-02-20 21:43:11 +01:00
|
|
|
VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
|
2017-02-20 21:43:12 +01:00
|
|
|
VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
|
2017-02-20 21:43:13 +01:00
|
|
|
VIRTIO_PCI_FLAG_INIT_PM_BIT,
|
2016-02-10 14:31:13 +01:00
|
|
|
};
|
|
|
|
|
2014-10-14 18:40:06 +02:00
|
|
|
/* Need to activate work-arounds for buggy guests at vmstate load. */
|
|
|
|
#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
|
|
|
|
(1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
|
|
|
|
|
2011-10-12 15:41:23 +02:00
|
|
|
/* Performance improves when virtqueue kick processing is decoupled from the
|
|
|
|
* vcpu thread using ioeventfd for some devices. */
|
|
|
|
#define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
|
|
|
|
|
2015-06-04 12:34:26 +02:00
|
|
|
/* virtio version flags */
|
2015-11-10 12:41:29 +01:00
|
|
|
#define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
|
2015-06-04 12:34:26 +02:00
|
|
|
|
2015-11-06 09:02:44 +01:00
|
|
|
/* migrate extra state */
|
|
|
|
#define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
|
|
|
|
|
2015-11-06 09:02:48 +01:00
|
|
|
/* have pio notification for modern device ? */
|
|
|
|
#define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
|
|
|
|
(1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
|
|
|
|
|
2016-09-07 17:02:25 +02:00
|
|
|
/* page per vq flag to be used by split drivers within guests */
|
|
|
|
#define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
|
|
|
|
(1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
|
|
|
|
|
2016-12-30 11:09:15 +01:00
|
|
|
/* address space translation service */
|
|
|
|
#define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
|
|
|
|
|
2017-02-20 21:43:11 +01:00
|
|
|
/* Init error enabling flags */
|
|
|
|
#define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
|
|
|
|
|
2017-02-20 21:43:12 +01:00
|
|
|
/* Init Link Control register */
|
|
|
|
#define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
|
|
|
|
|
2017-02-20 21:43:13 +01:00
|
|
|
/* Init Power Management */
|
|
|
|
#define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
|
|
|
|
|
2012-05-17 15:32:39 +02:00
|
|
|
typedef struct {
|
2012-12-20 23:27:54 +01:00
|
|
|
MSIMessage msg;
|
2012-05-17 15:32:39 +02:00
|
|
|
int virq;
|
|
|
|
unsigned int users;
|
|
|
|
} VirtIOIRQFD;
|
|
|
|
|
2013-01-15 00:08:04 +01:00
|
|
|
/*
|
|
|
|
* virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
|
|
|
|
*/
|
|
|
|
#define TYPE_VIRTIO_PCI "virtio-pci"
|
|
|
|
#define VIRTIO_PCI_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
|
|
|
|
#define VIRTIO_PCI_CLASS(klass) \
|
|
|
|
OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
|
|
|
|
#define VIRTIO_PCI(obj) \
|
|
|
|
OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
|
|
|
|
|
|
|
|
typedef struct VirtioPCIClass {
|
|
|
|
PCIDeviceClass parent_class;
|
2015-12-02 18:49:07 +01:00
|
|
|
DeviceRealize parent_dc_realize;
|
2015-02-27 14:52:14 +01:00
|
|
|
void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
|
2013-01-15 00:08:04 +01:00
|
|
|
} VirtioPCIClass;
|
|
|
|
|
2015-06-04 12:34:33 +02:00
|
|
|
typedef struct VirtIOPCIRegion {
|
|
|
|
MemoryRegion mr;
|
2015-06-04 12:34:35 +02:00
|
|
|
uint32_t offset;
|
2015-06-04 12:34:39 +02:00
|
|
|
uint32_t size;
|
2015-06-04 12:34:37 +02:00
|
|
|
uint32_t type;
|
2015-06-04 12:34:33 +02:00
|
|
|
} VirtIOPCIRegion;
|
|
|
|
|
2015-11-06 09:02:44 +01:00
|
|
|
typedef struct VirtIOPCIQueue {
|
|
|
|
uint16_t num;
|
|
|
|
bool enabled;
|
|
|
|
uint32_t desc[2];
|
|
|
|
uint32_t avail[2];
|
|
|
|
uint32_t used[2];
|
|
|
|
} VirtIOPCIQueue;
|
|
|
|
|
2019-02-15 11:32:38 +01:00
|
|
|
typedef enum {
|
|
|
|
VIRTIO_PCI_MODE_LEGACY,
|
|
|
|
VIRTIO_PCI_MODE_TRANSITIONAL,
|
|
|
|
VIRTIO_PCI_MODE_MODERN,
|
|
|
|
} VirtIOPCIMode;
|
|
|
|
|
2013-01-15 00:08:04 +01:00
|
|
|
struct VirtIOPCIProxy {
|
2011-06-01 09:05:13 +02:00
|
|
|
PCIDevice pci_dev;
|
2011-08-08 15:09:13 +02:00
|
|
|
MemoryRegion bar;
|
2017-10-09 05:19:41 +02:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
VirtIOPCIRegion common;
|
|
|
|
VirtIOPCIRegion isr;
|
|
|
|
VirtIOPCIRegion device;
|
|
|
|
VirtIOPCIRegion notify;
|
|
|
|
VirtIOPCIRegion notify_pio;
|
|
|
|
};
|
|
|
|
VirtIOPCIRegion regs[5];
|
|
|
|
};
|
2015-06-04 12:34:22 +02:00
|
|
|
MemoryRegion modern_bar;
|
2015-11-06 09:02:48 +01:00
|
|
|
MemoryRegion io_bar;
|
2016-09-29 06:04:40 +02:00
|
|
|
uint32_t legacy_io_bar_idx;
|
|
|
|
uint32_t msix_bar_idx;
|
|
|
|
uint32_t modern_io_bar_idx;
|
|
|
|
uint32_t modern_mem_bar_idx;
|
2015-07-02 14:59:49 +02:00
|
|
|
int config_cap;
|
2011-06-01 09:05:13 +02:00
|
|
|
uint32_t flags;
|
2016-07-20 17:28:21 +02:00
|
|
|
bool disable_modern;
|
2016-12-14 17:30:35 +01:00
|
|
|
bool ignore_backend_features;
|
2016-07-20 17:28:21 +02:00
|
|
|
OnOffAuto disable_legacy;
|
2019-02-15 11:32:38 +01:00
|
|
|
VirtIOPCIMode mode;
|
2011-06-01 09:05:13 +02:00
|
|
|
uint32_t class_code;
|
|
|
|
uint32_t nvectors;
|
2015-06-04 12:34:22 +02:00
|
|
|
uint32_t dfselect;
|
|
|
|
uint32_t gfselect;
|
|
|
|
uint32_t guest_features[2];
|
2015-11-06 09:02:44 +01:00
|
|
|
VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
|
2015-06-04 12:34:22 +02:00
|
|
|
|
2012-05-17 15:32:39 +02:00
|
|
|
VirtIOIRQFD *vector_irqfd;
|
2012-12-20 13:28:58 +01:00
|
|
|
int nvqs_with_notifiers;
|
2013-01-15 00:08:04 +01:00
|
|
|
VirtioBusState bus;
|
|
|
|
};
|
2011-06-01 09:05:13 +02:00
|
|
|
|
2016-07-20 17:28:21 +02:00
|
|
|
static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
|
|
|
|
{
|
2019-02-15 11:32:38 +01:00
|
|
|
return proxy->mode != VIRTIO_PCI_MODE_LEGACY;
|
2016-07-20 17:28:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
|
|
|
|
{
|
2019-02-15 11:32:38 +01:00
|
|
|
return proxy->mode != VIRTIO_PCI_MODE_MODERN;
|
2016-07-20 17:28:21 +02:00
|
|
|
}
|
|
|
|
|
2019-02-15 11:32:38 +01:00
|
|
|
static inline bool virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy,
|
|
|
|
Error **errp)
|
2016-07-20 17:28:21 +02:00
|
|
|
{
|
2019-02-15 11:32:38 +01:00
|
|
|
if (proxy->disable_legacy == ON_OFF_AUTO_OFF) {
|
|
|
|
error_setg(errp, "Unable to set disable-legacy=off on a virtio-1.0 "
|
|
|
|
"only device");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (proxy->disable_modern == true) {
|
|
|
|
error_setg(errp, "Unable to set disable-modern=on on a virtio-1.0 "
|
|
|
|
"only device");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
proxy->mode = VIRTIO_PCI_MODE_MODERN;
|
|
|
|
return true;
|
2016-07-20 17:28:21 +02:00
|
|
|
}
|
2013-03-21 15:15:15 +01:00
|
|
|
|
2016-09-13 15:30:30 +02:00
|
|
|
static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
|
|
|
|
{
|
2019-02-15 11:32:38 +01:00
|
|
|
proxy->mode = VIRTIO_PCI_MODE_LEGACY;
|
2016-09-13 15:30:30 +02:00
|
|
|
}
|
|
|
|
|
2015-06-04 12:34:41 +02:00
|
|
|
/*
|
|
|
|
* virtio-input-pci: This extends VirtioPCIProxy.
|
|
|
|
*/
|
|
|
|
#define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
|
2015-06-04 12:34:42 +02:00
|
|
|
|
2011-06-14 16:51:11 +02:00
|
|
|
/* Virtio ABI version, if we increment this, we break the guest driver. */
|
|
|
|
#define VIRTIO_PCI_ABI_VERSION 0
|
|
|
|
|
2018-12-05 20:57:03 +01:00
|
|
|
/* Input for virtio_pci_types_register() */
|
|
|
|
typedef struct VirtioPCIDeviceTypeInfo {
|
|
|
|
/*
|
|
|
|
* Common base class for the subclasses below.
|
|
|
|
*
|
|
|
|
* Required only if transitional_name or non_transitional_name is set.
|
|
|
|
*
|
|
|
|
* We need a separate base type instead of making all types
|
|
|
|
* inherit from generic_name for two reasons:
|
|
|
|
* 1) generic_name implements INTERFACE_PCIE_DEVICE, but
|
|
|
|
* transitional_name does not.
|
|
|
|
* 2) generic_name has the "disable-legacy" and "disable-modern"
|
|
|
|
* properties, transitional_name and non_transitional name don't.
|
|
|
|
*/
|
|
|
|
const char *base_name;
|
|
|
|
/*
|
|
|
|
* Generic device type. Optional.
|
|
|
|
*
|
|
|
|
* Supports both transitional and non-transitional modes,
|
|
|
|
* using the disable-legacy and disable-modern properties.
|
|
|
|
* If disable-legacy=auto, (non-)transitional mode is selected
|
|
|
|
* depending on the bus where the device is plugged.
|
|
|
|
*
|
|
|
|
* Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
|
|
|
|
* but PCI Express is supported only in non-transitional mode.
|
|
|
|
*
|
|
|
|
* The only type implemented by QEMU 3.1 and older.
|
|
|
|
*/
|
|
|
|
const char *generic_name;
|
|
|
|
/*
|
|
|
|
* The transitional device type. Optional.
|
|
|
|
*
|
|
|
|
* Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
|
|
|
|
*/
|
|
|
|
const char *transitional_name;
|
|
|
|
/*
|
|
|
|
* The non-transitional device type. Optional.
|
|
|
|
*
|
|
|
|
* Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
|
|
|
|
*/
|
|
|
|
const char *non_transitional_name;
|
|
|
|
|
|
|
|
/* Parent type. If NULL, TYPE_VIRTIO_PCI is used */
|
|
|
|
const char *parent;
|
|
|
|
|
|
|
|
/* Same as TypeInfo fields: */
|
|
|
|
size_t instance_size;
|
2019-03-07 09:02:42 +01:00
|
|
|
size_t class_size;
|
2018-12-05 20:57:03 +01:00
|
|
|
void (*instance_init)(Object *obj);
|
|
|
|
void (*class_init)(ObjectClass *klass, void *data);
|
|
|
|
} VirtioPCIDeviceTypeInfo;
|
|
|
|
|
|
|
|
/* Register virtio-pci type(s). @t must be static. */
|
|
|
|
void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
|
|
|
|
|
2011-06-01 09:05:13 +02:00
|
|
|
#endif
|