2011-06-01 11:05:13 +04: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
|
|
|
|
|
2013-01-15 01:52:02 +04:00
|
|
|
#include "hw/pci/msi.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/virtio/virtio-bus.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2016-10-28 11:33:25 +03:00
|
|
|
|
2013-01-15 03:08:04 +04:00
|
|
|
|
2013-01-15 03:08:03 +04:00
|
|
|
/* virtio-pci-bus */
|
|
|
|
|
|
|
|
typedef struct VirtioBusState VirtioPCIBusState;
|
|
|
|
typedef struct VirtioBusClass VirtioPCIBusClass;
|
|
|
|
|
|
|
|
#define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_OBJ_CHECKERS(VirtioPCIBusState, VirtioPCIBusClass,
|
|
|
|
VIRTIO_PCI_BUS, TYPE_VIRTIO_PCI_BUS)
|
2011-06-01 11:05:13 +04:00
|
|
|
|
2016-02-10 16:31:13 +03: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 18:02:25 +03:00
|
|
|
VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
|
2016-12-30 13:09:15 +03:00
|
|
|
VIRTIO_PCI_FLAG_ATS_BIT,
|
2017-02-20 23:43:11 +03:00
|
|
|
VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
|
2017-02-20 23:43:12 +03:00
|
|
|
VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
|
2017-02-20 23:43:13 +03:00
|
|
|
VIRTIO_PCI_FLAG_INIT_PM_BIT,
|
2019-08-20 19:30:05 +03:00
|
|
|
VIRTIO_PCI_FLAG_INIT_FLR_BIT,
|
2020-12-03 14:07:13 +03:00
|
|
|
VIRTIO_PCI_FLAG_AER_BIT,
|
2021-04-06 07:03:30 +03:00
|
|
|
VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT,
|
2024-06-06 13:22:05 +03:00
|
|
|
VIRTIO_PCI_FLAG_PM_NO_SOFT_RESET_BIT,
|
2016-02-10 16:31:13 +03:00
|
|
|
};
|
|
|
|
|
2014-10-14 20:40:06 +04: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 17:41:23 +04: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 13:34:26 +03:00
|
|
|
/* virtio version flags */
|
2015-11-10 14:41:29 +03:00
|
|
|
#define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
|
2015-06-04 13:34:26 +03:00
|
|
|
|
2015-11-06 11:02:44 +03:00
|
|
|
/* migrate extra state */
|
|
|
|
#define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
|
|
|
|
|
2015-11-06 11:02:48 +03: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 18:02:25 +03: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 13:09:15 +03:00
|
|
|
/* address space translation service */
|
|
|
|
#define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
|
|
|
|
|
2017-02-20 23:43:11 +03:00
|
|
|
/* Init error enabling flags */
|
|
|
|
#define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
|
|
|
|
|
2017-02-20 23:43:12 +03:00
|
|
|
/* Init Link Control register */
|
|
|
|
#define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
|
|
|
|
|
2017-02-20 23:43:13 +03:00
|
|
|
/* Init Power Management */
|
|
|
|
#define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
|
|
|
|
|
2024-06-06 13:22:05 +03:00
|
|
|
/* Init The No_Soft_Reset bit of Power Management */
|
|
|
|
#define VIRTIO_PCI_FLAG_PM_NO_SOFT_RESET \
|
|
|
|
(1 << VIRTIO_PCI_FLAG_PM_NO_SOFT_RESET_BIT)
|
|
|
|
|
2019-08-20 19:30:05 +03:00
|
|
|
/* Init Function Level Reset capability */
|
|
|
|
#define VIRTIO_PCI_FLAG_INIT_FLR (1 << VIRTIO_PCI_FLAG_INIT_FLR_BIT)
|
|
|
|
|
2020-12-03 14:07:13 +03:00
|
|
|
/* Advanced Error Reporting capability */
|
|
|
|
#define VIRTIO_PCI_FLAG_AER (1 << VIRTIO_PCI_FLAG_AER_BIT)
|
|
|
|
|
2021-04-06 07:03:30 +03:00
|
|
|
/* Page Aligned Address space Translation Service */
|
|
|
|
#define VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED \
|
|
|
|
(1 << VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT)
|
|
|
|
|
2012-05-17 17:32:39 +04:00
|
|
|
typedef struct {
|
2012-12-21 02:27:54 +04:00
|
|
|
MSIMessage msg;
|
2012-05-17 17:32:39 +04:00
|
|
|
int virq;
|
|
|
|
unsigned int users;
|
|
|
|
} VirtIOIRQFD;
|
|
|
|
|
2013-01-15 03:08:04 +04:00
|
|
|
/*
|
|
|
|
* virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
|
|
|
|
*/
|
|
|
|
#define TYPE_VIRTIO_PCI "virtio-pci"
|
2020-09-16 21:25:18 +03:00
|
|
|
OBJECT_DECLARE_TYPE(VirtIOPCIProxy, VirtioPCIClass, VIRTIO_PCI)
|
2013-01-15 03:08:04 +04:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct VirtioPCIClass {
|
2013-01-15 03:08:04 +04:00
|
|
|
PCIDeviceClass parent_class;
|
2015-12-02 20:49:07 +03:00
|
|
|
DeviceRealize parent_dc_realize;
|
2015-02-27 16:52:14 +03:00
|
|
|
void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2013-01-15 03:08:04 +04:00
|
|
|
|
2015-06-04 13:34:33 +03:00
|
|
|
typedef struct VirtIOPCIRegion {
|
|
|
|
MemoryRegion mr;
|
2015-06-04 13:34:35 +03:00
|
|
|
uint32_t offset;
|
2015-06-04 13:34:39 +03:00
|
|
|
uint32_t size;
|
2015-06-04 13:34:37 +03:00
|
|
|
uint32_t type;
|
2015-06-04 13:34:33 +03:00
|
|
|
} VirtIOPCIRegion;
|
|
|
|
|
2015-11-06 11:02:44 +03:00
|
|
|
typedef struct VirtIOPCIQueue {
|
|
|
|
uint16_t num;
|
|
|
|
bool enabled;
|
2022-10-17 12:25:48 +03:00
|
|
|
/*
|
|
|
|
* No need to migrate the reset status, because it is always 0
|
|
|
|
* when the migration starts.
|
|
|
|
*/
|
|
|
|
bool reset;
|
2015-11-06 11:02:44 +03:00
|
|
|
uint32_t desc[2];
|
|
|
|
uint32_t avail[2];
|
|
|
|
uint32_t used[2];
|
|
|
|
} VirtIOPCIQueue;
|
|
|
|
|
2013-01-15 03:08:04 +04:00
|
|
|
struct VirtIOPCIProxy {
|
2011-06-01 11:05:13 +04:00
|
|
|
PCIDevice pci_dev;
|
2011-08-08 17:09:13 +04:00
|
|
|
MemoryRegion bar;
|
2017-10-09 06:19:41 +03:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
VirtIOPCIRegion common;
|
|
|
|
VirtIOPCIRegion isr;
|
|
|
|
VirtIOPCIRegion device;
|
|
|
|
VirtIOPCIRegion notify;
|
|
|
|
VirtIOPCIRegion notify_pio;
|
|
|
|
};
|
|
|
|
VirtIOPCIRegion regs[5];
|
|
|
|
};
|
2015-06-04 13:34:22 +03:00
|
|
|
MemoryRegion modern_bar;
|
2015-11-06 11:02:48 +03:00
|
|
|
MemoryRegion io_bar;
|
2016-09-29 07:04:40 +03: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 15:59:49 +03:00
|
|
|
int config_cap;
|
2011-06-01 11:05:13 +04:00
|
|
|
uint32_t flags;
|
2016-07-20 18:28:21 +03:00
|
|
|
bool disable_modern;
|
2016-12-14 19:30:35 +03:00
|
|
|
bool ignore_backend_features;
|
2016-07-20 18:28:21 +03:00
|
|
|
OnOffAuto disable_legacy;
|
2022-12-15 16:49:40 +03:00
|
|
|
/* Transitional device id */
|
|
|
|
uint16_t trans_devid;
|
2011-06-01 11:05:13 +04:00
|
|
|
uint32_t class_code;
|
|
|
|
uint32_t nvectors;
|
2015-06-04 13:34:22 +03:00
|
|
|
uint32_t dfselect;
|
|
|
|
uint32_t gfselect;
|
|
|
|
uint32_t guest_features[2];
|
2015-11-06 11:02:44 +03:00
|
|
|
VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
|
2015-06-04 13:34:22 +03:00
|
|
|
|
2012-05-17 17:32:39 +04:00
|
|
|
VirtIOIRQFD *vector_irqfd;
|
2012-12-20 16:28:58 +04:00
|
|
|
int nvqs_with_notifiers;
|
2013-01-15 03:08:04 +04:00
|
|
|
VirtioBusState bus;
|
|
|
|
};
|
2011-06-01 11:05:13 +04:00
|
|
|
|
2016-07-20 18:28:21 +03:00
|
|
|
static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
|
|
|
|
{
|
2019-07-29 19:29:03 +03:00
|
|
|
return !proxy->disable_modern;
|
2016-07-20 18:28:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
|
|
|
|
{
|
2019-07-29 19:29:03 +03:00
|
|
|
return proxy->disable_legacy == ON_OFF_AUTO_OFF;
|
2016-07-20 18:28:21 +03:00
|
|
|
}
|
|
|
|
|
2019-07-29 19:29:03 +03:00
|
|
|
static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
|
2016-07-20 18:28:21 +03:00
|
|
|
{
|
2019-07-29 19:29:03 +03:00
|
|
|
proxy->disable_modern = false;
|
|
|
|
proxy->disable_legacy = ON_OFF_AUTO_ON;
|
2016-07-20 18:28:21 +03:00
|
|
|
}
|
2013-03-21 18:15:15 +04:00
|
|
|
|
2016-09-13 16:30:30 +03:00
|
|
|
static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
|
|
|
|
{
|
2019-07-29 19:29:03 +03:00
|
|
|
proxy->disable_modern = true;
|
2016-09-13 16:30:30 +03:00
|
|
|
}
|
|
|
|
|
2022-12-15 16:49:40 +03:00
|
|
|
uint16_t virtio_pci_get_trans_devid(uint16_t device_id);
|
|
|
|
uint16_t virtio_pci_get_class_id(uint16_t device_id);
|
|
|
|
|
2015-06-04 13:34:41 +03:00
|
|
|
/*
|
|
|
|
* virtio-input-pci: This extends VirtioPCIProxy.
|
|
|
|
*/
|
|
|
|
#define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
|
2015-06-04 13:34:42 +03:00
|
|
|
|
2011-06-14 18:51:11 +04:00
|
|
|
/* Virtio ABI version, if we increment this, we break the guest driver. */
|
|
|
|
#define VIRTIO_PCI_ABI_VERSION 0
|
|
|
|
|
2018-12-05 22:57:03 +03: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 11:02:42 +03:00
|
|
|
size_t class_size;
|
2018-12-05 22:57:03 +03:00
|
|
|
void (*instance_init)(Object *obj);
|
2023-11-21 20:40:46 +03:00
|
|
|
void (*instance_finalize)(Object *obj);
|
2018-12-05 22:57:03 +03:00
|
|
|
void (*class_init)(ObjectClass *klass, void *data);
|
2019-06-19 12:49:02 +03:00
|
|
|
InterfaceInfo *interfaces;
|
2018-12-05 22:57:03 +03:00
|
|
|
} VirtioPCIDeviceTypeInfo;
|
|
|
|
|
|
|
|
/* Register virtio-pci type(s). @t must be static. */
|
|
|
|
void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
|
|
|
|
|
2020-08-18 17:33:44 +03:00
|
|
|
/**
|
|
|
|
* virtio_pci_optimal_num_queues:
|
|
|
|
* @fixed_queues: number of queues that are always present
|
|
|
|
*
|
|
|
|
* Returns: The optimal number of queues for a multi-queue device, excluding
|
|
|
|
* @fixed_queues.
|
|
|
|
*/
|
|
|
|
unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues);
|
2022-12-22 10:04:51 +03:00
|
|
|
void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueue *vq,
|
|
|
|
int n, bool assign,
|
|
|
|
bool with_irqfd);
|
2023-05-04 22:12:42 +03:00
|
|
|
|
|
|
|
int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, uint8_t bar, uint64_t offset,
|
|
|
|
uint64_t length, uint8_t id);
|
|
|
|
|
2011-06-01 11:05:13 +04:00
|
|
|
#endif
|