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

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