Blame SOURCES/kvm-hw-acpi-Move-acpi_set_pci_info-to-pcihp.patch

9bac43
From acb06b5ca2ea9f30a7b14c34674b930f0e8a1a60 Mon Sep 17 00:00:00 2001
9bac43
From: Marcel Apfelbaum <marcel@redhat.com>
9bac43
Date: Tue, 16 Jan 2018 14:15:34 +0100
9bac43
Subject: [PATCH 02/21] hw/acpi: Move acpi_set_pci_info to pcihp
9bac43
9bac43
RH-Author: Marcel Apfelbaum <marcel@redhat.com>
9bac43
Message-id: <20180116141534.100478-1-marcel@redhat.com>
9bac43
Patchwork-id: 78628
9bac43
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH V2] hw/acpi: Move acpi_set_pci_info to pcihp
9bac43
Bugzilla: 1507693
9bac43
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
9bac43
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9bac43
9bac43
From: Anthony PERARD <anthony.perard@citrix.com>
9bac43
9bac43
RHEL Note:
9bac43
    rhel6 machine types don't generate their ACPI payload
9bac43
    (pcmc->has_acpi_build = false), SeaBIOS does it for them
9bac43
    (m->default_machine_opts = "firmware=bios.bin"). In turn, before the
9bac43
    patch, these machine types never call acpi_setup() ->
9bac43
    acpi_set_pci_info(), and never set BSEL. After the patch, BSEL is set in
9bac43
    all i440fx-based machine types, via piix4_reset() -> acpi_pcihp_reset()
9bac43
    -> acpi_set_pci_info().
9bac43
9bac43
HW part of ACPI PCI hotplug in QEMU depends on ACPI_PCIHP_PROP_BSEL
9bac43
being set on a PCI bus that supports ACPI hotplug. It should work
9bac43
regardless of the source of ACPI tables (QEMU generator/legacy SeaBIOS/Xen).
9bac43
So move ACPI_PCIHP_PROP_BSEL initialization into HW ACPI implementation
9bac43
part from QEMU's ACPI table generator.
9bac43
9bac43
To do PCI passthrough with Xen, the property ACPI_PCIHP_PROP_BSEL needs
9bac43
to be set, but this was done only when ACPI tables are built which is
9bac43
not needed for a Xen guest. The need for the property starts with commit
9bac43
"pc: pcihp: avoid adding ACPI_PCIHP_PROP_BSEL twice"
9bac43
(f0c9d64a68b776374ec4732424a3e27753ce37b6).
9bac43
9bac43
Adding find_i440fx into stubs so that mips-softmmu target can be built.
9bac43
9bac43
Reported-by: Sander Eikelenboom <linux@eikelenboom.it>
9bac43
Signed-off-by: Anthony PERARD <anthony.perard@citrix.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 ab938ae43f8a3a71a3525566edf586081b7a7452)
9bac43
Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
9bac43
9bac43
 Conflicts:
9bac43
	stubs/Makefile.objs
9bac43
   (some stubs were added before it)
9bac43
9bac43
Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
9bac43
---
9bac43
9bac43
V1 -> V2:
9bac43
   Added the RHEL Note (Laszlo)
9bac43
9bac43
 hw/acpi/pcihp.c       | 38 ++++++++++++++++++++++++++++++++++++++
9bac43
 hw/i386/acpi-build.c  | 32 --------------------------------
9bac43
 stubs/Makefile.objs   |  1 +
9bac43
 stubs/pci-host-piix.c |  6 ++++++
9bac43
 4 files changed, 45 insertions(+), 32 deletions(-)
9bac43
 create mode 100644 stubs/pci-host-piix.c
9bac43
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 hw/acpi/pcihp.c       | 38 ++++++++++++++++++++++++++++++++++++++
9bac43
 hw/i386/acpi-build.c  | 32 --------------------------------
9bac43
 stubs/Makefile.objs   |  1 +
9bac43
 stubs/pci-host-piix.c |  6 ++++++
9bac43
 4 files changed, 45 insertions(+), 32 deletions(-)
9bac43
 create mode 100644 stubs/pci-host-piix.c
9bac43
9bac43
diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
9bac43
index c420a38..9ad5edc 100644
9bac43
--- a/hw/acpi/pcihp.c
9bac43
+++ b/hw/acpi/pcihp.c
9bac43
@@ -75,6 +75,43 @@ static int acpi_pcihp_get_bsel(PCIBus *bus)
9bac43
     }
9bac43
 }
9bac43
 
9bac43
+/* Assign BSEL property to all buses.  In the future, this can be changed
9bac43
+ * to only assign to buses that support hotplug.
9bac43
+ */
9bac43
+static void *acpi_set_bsel(PCIBus *bus, void *opaque)
9bac43
+{
9bac43
+    unsigned *bsel_alloc = opaque;
9bac43
+    unsigned *bus_bsel;
9bac43
+
9bac43
+    if (qbus_is_hotpluggable(BUS(bus))) {
9bac43
+        bus_bsel = g_malloc(sizeof *bus_bsel);
9bac43
+
9bac43
+        *bus_bsel = (*bsel_alloc)++;
9bac43
+        object_property_add_uint32_ptr(OBJECT(bus), ACPI_PCIHP_PROP_BSEL,
9bac43
+                                       bus_bsel, &error_abort);
9bac43
+    }
9bac43
+
9bac43
+    return bsel_alloc;
9bac43
+}
9bac43
+
9bac43
+static void acpi_set_pci_info(void)
9bac43
+{
9bac43
+    static bool bsel_is_set;
9bac43
+    PCIBus *bus;
9bac43
+    unsigned bsel_alloc = ACPI_PCIHP_BSEL_DEFAULT;
9bac43
+
9bac43
+    if (bsel_is_set) {
9bac43
+        return;
9bac43
+    }
9bac43
+    bsel_is_set = true;
9bac43
+
9bac43
+    bus = find_i440fx(); /* TODO: Q35 support */
9bac43
+    if (bus) {
9bac43
+        /* Scan all PCI buses. Set property to enable acpi based hotplug. */
9bac43
+        pci_for_each_bus_depth_first(bus, acpi_set_bsel, NULL, &bsel_alloc);
9bac43
+    }
9bac43
+}
9bac43
+
9bac43
 static void acpi_pcihp_test_hotplug_bus(PCIBus *bus, void *opaque)
9bac43
 {
9bac43
     AcpiPciHpFind *find = opaque;
9bac43
@@ -177,6 +214,7 @@ static void acpi_pcihp_update(AcpiPciHpState *s)
9bac43
 
9bac43
 void acpi_pcihp_reset(AcpiPciHpState *s)
9bac43
 {
9bac43
+    acpi_set_pci_info();
9bac43
     acpi_pcihp_update(s);
9bac43
 }
9bac43
 
9bac43
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
9bac43
index a61560f..8117321 100644
9bac43
--- a/hw/i386/acpi-build.c
9bac43
+++ b/hw/i386/acpi-build.c
9bac43
@@ -495,36 +495,6 @@ build_madt(GArray *table_data, BIOSLinker *linker, PCMachineState *pcms)
9bac43
                  table_data->len - madt_start, 1, NULL, NULL);
9bac43
 }
9bac43
 
9bac43
-/* Assign BSEL property to all buses.  In the future, this can be changed
9bac43
- * to only assign to buses that support hotplug.
9bac43
- */
9bac43
-static void *acpi_set_bsel(PCIBus *bus, void *opaque)
9bac43
-{
9bac43
-    unsigned *bsel_alloc = opaque;
9bac43
-    unsigned *bus_bsel;
9bac43
-
9bac43
-    if (qbus_is_hotpluggable(BUS(bus))) {
9bac43
-        bus_bsel = g_malloc(sizeof *bus_bsel);
9bac43
-
9bac43
-        *bus_bsel = (*bsel_alloc)++;
9bac43
-        object_property_add_uint32_ptr(OBJECT(bus), ACPI_PCIHP_PROP_BSEL,
9bac43
-                                       bus_bsel, &error_abort);
9bac43
-    }
9bac43
-
9bac43
-    return bsel_alloc;
9bac43
-}
9bac43
-
9bac43
-static void acpi_set_pci_info(void)
9bac43
-{
9bac43
-    PCIBus *bus = find_i440fx(); /* TODO: Q35 support */
9bac43
-    unsigned bsel_alloc = ACPI_PCIHP_BSEL_DEFAULT;
9bac43
-
9bac43
-    if (bus) {
9bac43
-        /* Scan all PCI buses. Set property to enable acpi based hotplug. */
9bac43
-        pci_for_each_bus_depth_first(bus, acpi_set_bsel, NULL, &bsel_alloc);
9bac43
-    }
9bac43
-}
9bac43
-
9bac43
 static void build_append_pcihp_notify_entry(Aml *method, int slot)
9bac43
 {
9bac43
     Aml *if_ctx;
9bac43
@@ -2890,8 +2860,6 @@ void acpi_setup(void)
9bac43
 
9bac43
     build_state = g_malloc0(sizeof *build_state);
9bac43
 
9bac43
-    acpi_set_pci_info();
9bac43
-
9bac43
     acpi_build_tables_init(&tables);
9bac43
     acpi_build(&tables, MACHINE(pcms));
9bac43
 
9bac43
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
9bac43
index 7e9f94d..e3b9e6b 100644
9bac43
--- a/stubs/Makefile.objs
9bac43
+++ b/stubs/Makefile.objs
9bac43
@@ -42,3 +42,4 @@ stub-obj-y += xen-common.o
9bac43
 stub-obj-y += xen-hvm.o
9bac43
 stub-obj-y += shadow-bios.o
9bac43
 stub-obj-y += ide-isa.o
9bac43
+stub-obj-y += pci-host-piix.o
9bac43
diff --git a/stubs/pci-host-piix.c b/stubs/pci-host-piix.c
9bac43
new file mode 100644
9bac43
index 0000000..6ed81b1
9bac43
--- /dev/null
9bac43
+++ b/stubs/pci-host-piix.c
9bac43
@@ -0,0 +1,6 @@
9bac43
+#include "qemu/osdep.h"
9bac43
+#include "hw/i386/pc.h"
9bac43
+PCIBus *find_i440fx(void)
9bac43
+{
9bac43
+    return NULL;
9bac43
+}
9bac43
-- 
9bac43
1.8.3.1
9bac43