Skip to content

Commit

Permalink
hw/virtio: Add PCIe capability to virtio devices
Browse files Browse the repository at this point in the history
The virtio devices are converted to PCI-Express
if they are plugged into a PCI-Express bus and
the 'modern' protocol is enabled.

Devices plugged directly into the Root Complex as
Integrated Endpoints remain PCI.

Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
marcel-apf authored and mstsirkin committed Nov 12, 2015
1 parent 3a12f32 commit 1811e64
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hw/virtio/virtio-pci.c
Expand Up @@ -1814,6 +1814,26 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)

address_space_init(&proxy->modern_as, &proxy->modern_cfg, "virtio-pci-cfg-as");

if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE)
&& !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN)
&& pci_bus_is_express(pci_dev->bus)
&& !pci_bus_is_root(pci_dev->bus)) {
int pos;

pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;
pos = pcie_endpoint_cap_init(pci_dev, 0);
assert(pos > 0);

pos = pci_add_capability(pci_dev, PCI_CAP_ID_PM, 0, PCI_PM_SIZEOF);
assert(pos > 0);

/*
* Indicates that this function complies with revision 1.2 of the
* PCI Power Management Interface Specification.
*/
pci_set_word(pci_dev->config + pos + PCI_PM_PMC, 0x3);
}

virtio_pci_bus_new(&proxy->bus, sizeof(proxy->bus), proxy);
if (k->realize) {
k->realize(proxy, errp);
Expand Down Expand Up @@ -1854,6 +1874,8 @@ static Property virtio_pci_properties[] = {
VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT, true),
DEFINE_PROP_BIT("modern-pio-notify", VirtIOPCIProxy, flags,
VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT, false),
DEFINE_PROP_BIT("x-disable-pcie", VirtIOPCIProxy, flags,
VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT, false),
DEFINE_PROP_END_OF_LIST(),
};

Expand Down
2 changes: 2 additions & 0 deletions hw/virtio/virtio-pci.h
Expand Up @@ -72,8 +72,10 @@ typedef struct VirtioBusClass VirtioPCIBusClass;
/* virtio version flags */
#define VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT 2
#define VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT 3
#define VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT 4
#define VIRTIO_PCI_FLAG_DISABLE_LEGACY (1 << VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT)
#define VIRTIO_PCI_FLAG_DISABLE_MODERN (1 << VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT)
#define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)

/* migrate extra state */
#define VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT 4
Expand Down
4 changes: 4 additions & 0 deletions include/hw/compat.h
Expand Up @@ -6,6 +6,10 @@
.driver = "virtio-blk-device",\
.property = "scsi",\
.value = "true",\
},{\
.driver = "virtio-pci",\
.property = "x-disable-pcie",\
.value = "on",\
},{\
.driver = "virtio-pci",\
.property = "migrate-extra",\
Expand Down

0 comments on commit 1811e64

Please sign in to comment.