Blame SOURCES/kvm-hw-pci-add-QEMU-specific-PCI-capability-to-the-Gener.patch

4a2fec
From e624b4d9b2fcc27ce36cb2a37009d8083ee3ca9e Mon Sep 17 00:00:00 2001
4a2fec
From: Marcel Apfelbaum <marcel@redhat.com>
4a2fec
Date: Mon, 13 Nov 2017 15:59:40 +0100
4a2fec
Subject: [PATCH 02/30] hw/pci: add QEMU-specific PCI capability to the Generic
4a2fec
 PCI Express Root Port
4a2fec
4a2fec
RH-Author: Marcel Apfelbaum <marcel@redhat.com>
4a2fec
Message-id: <20171113155940.50793-3-marcel@redhat.com>
4a2fec
Patchwork-id: 77663
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 2/2] hw/pci: add QEMU-specific PCI capability to the Generic PCI Express Root Port
4a2fec
Bugzilla: 1437113
4a2fec
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
4a2fec
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
4a2fec
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
4a2fec
4a2fec
From: Aleksandr Bezzubikov <zuban32s@gmail.com>
4a2fec
4a2fec
To enable hotplugging of a newly created pcie-pci-bridge,
4a2fec
we need to tell firmware (e.g. SeaBIOS) to reserve
4a2fec
additional buses or IO/MEM/PREF space for pcie-root-port.
4a2fec
Additional bus reservation allows us to hotplug pcie-pci-bridge into this root port.
4a2fec
The number of buses and IO/MEM/PREF space to reserve are provided to the device via
4a2fec
a corresponding property, and to the firmware via new PCI capability.
4a2fec
The properties' default values are -1 to keep default behavior unchanged.
4a2fec
4a2fec
Signed-off-by: Aleksandr Bezzubikov <zuban32s@gmail.com>
4a2fec
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
4a2fec
Tested-by: Marcel Apfelbaum <marcel@redhat.com>
4a2fec
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
4a2fec
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
4a2fec
(cherry picked from commit 226263fb5cdaa4a4a95f1680fabbc9dd2123fd67)
4a2fec
Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/pci-bridge/gen_pcie_root_port.c | 36 ++++++++++++++++++++++++++++++++++++
4a2fec
 include/hw/pci/pcie_port.h         |  1 +
4a2fec
 2 files changed, 37 insertions(+)
4a2fec
4a2fec
diff --git a/hw/pci-bridge/gen_pcie_root_port.c b/hw/pci-bridge/gen_pcie_root_port.c
4a2fec
index cb694d6..ed03ffc 100644
4a2fec
--- a/hw/pci-bridge/gen_pcie_root_port.c
4a2fec
+++ b/hw/pci-bridge/gen_pcie_root_port.c
4a2fec
@@ -16,6 +16,8 @@
4a2fec
 #include "hw/pci/pcie_port.h"
4a2fec
 
4a2fec
 #define TYPE_GEN_PCIE_ROOT_PORT                "pcie-root-port"
4a2fec
+#define GEN_PCIE_ROOT_PORT(obj) \
4a2fec
+        OBJECT_CHECK(GenPCIERootPort, (obj), TYPE_GEN_PCIE_ROOT_PORT)
4a2fec
 
4a2fec
 #define GEN_PCIE_ROOT_PORT_AER_OFFSET           0x100
4a2fec
 #define GEN_PCIE_ROOT_PORT_MSIX_NR_VECTOR       1
4a2fec
@@ -26,6 +28,13 @@ typedef struct GenPCIERootPort {
4a2fec
     /*< public >*/
4a2fec
 
4a2fec
     bool migrate_msix;
4a2fec
+
4a2fec
+    /* additional resources to reserve on firmware init */
4a2fec
+    uint32_t bus_reserve;
4a2fec
+    uint64_t io_reserve;
4a2fec
+    uint64_t mem_reserve;
4a2fec
+    uint64_t pref32_reserve;
4a2fec
+    uint64_t pref64_reserve;
4a2fec
 } GenPCIERootPort;
4a2fec
 
4a2fec
 static uint8_t gen_rp_aer_vector(const PCIDevice *d)
4a2fec
@@ -60,6 +69,24 @@ static bool gen_rp_test_migrate_msix(void *opaque, int version_id)
4a2fec
     return rp->migrate_msix;
4a2fec
 }
4a2fec
 
4a2fec
+static void gen_rp_realize(DeviceState *dev, Error **errp)
4a2fec
+{
4a2fec
+    PCIDevice *d = PCI_DEVICE(dev);
4a2fec
+    GenPCIERootPort *grp = GEN_PCIE_ROOT_PORT(d);
4a2fec
+    PCIERootPortClass *rpc = PCIE_ROOT_PORT_GET_CLASS(d);
4a2fec
+
4a2fec
+    rpc->parent_realize(dev, errp);
4a2fec
+
4a2fec
+    int rc = pci_bridge_qemu_reserve_cap_init(d, 0, grp->bus_reserve,
4a2fec
+            grp->io_reserve, grp->mem_reserve, grp->pref32_reserve,
4a2fec
+            grp->pref64_reserve, errp);
4a2fec
+
4a2fec
+    if (rc < 0) {
4a2fec
+        rpc->parent_class.exit(d);
4a2fec
+        return;
4a2fec
+    }
4a2fec
+}
4a2fec
+
4a2fec
 static const VMStateDescription vmstate_rp_dev = {
4a2fec
     .name = "pcie-root-port",
4a2fec
     .version_id = 1,
4a2fec
@@ -78,6 +105,11 @@ static const VMStateDescription vmstate_rp_dev = {
4a2fec
 
4a2fec
 static Property gen_rp_props[] = {
4a2fec
     DEFINE_PROP_BOOL("x-migrate-msix", GenPCIERootPort, migrate_msix, true),
4a2fec
+    DEFINE_PROP_UINT32("bus-reserve", GenPCIERootPort, bus_reserve, -1),
4a2fec
+    DEFINE_PROP_SIZE("io-reserve", GenPCIERootPort, io_reserve, -1),
4a2fec
+    DEFINE_PROP_SIZE("mem-reserve", GenPCIERootPort, mem_reserve, -1),
4a2fec
+    DEFINE_PROP_SIZE("pref32-reserve", GenPCIERootPort, pref32_reserve, -1),
4a2fec
+    DEFINE_PROP_SIZE("pref64-reserve", GenPCIERootPort, pref64_reserve, -1),
4a2fec
     DEFINE_PROP_END_OF_LIST()
4a2fec
 };
4a2fec
 
4a2fec
@@ -92,6 +124,10 @@ static void gen_rp_dev_class_init(ObjectClass *klass, void *data)
4a2fec
     dc->desc = "PCI Express Root Port";
4a2fec
     dc->vmsd = &vmstate_rp_dev;
4a2fec
     dc->props = gen_rp_props;
4a2fec
+
4a2fec
+    rpc->parent_realize = dc->realize;
4a2fec
+    dc->realize = gen_rp_realize;
4a2fec
+
4a2fec
     rpc->aer_vector = gen_rp_aer_vector;
4a2fec
     rpc->interrupts_init = gen_rp_interrupts_init;
4a2fec
     rpc->interrupts_uninit = gen_rp_interrupts_uninit;
4a2fec
diff --git a/include/hw/pci/pcie_port.h b/include/hw/pci/pcie_port.h
4a2fec
index 1333266..0736014 100644
4a2fec
--- a/include/hw/pci/pcie_port.h
4a2fec
+++ b/include/hw/pci/pcie_port.h
4a2fec
@@ -65,6 +65,7 @@ void pcie_chassis_del_slot(PCIESlot *s);
4a2fec
 
4a2fec
 typedef struct PCIERootPortClass {
4a2fec
     PCIDeviceClass parent_class;
4a2fec
+    DeviceRealize parent_realize;
4a2fec
 
4a2fec
     uint8_t (*aer_vector)(const PCIDevice *dev);
4a2fec
     int (*interrupts_init)(PCIDevice *dev, Error **errp);
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec