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

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