File 0069-pcihp-fix-pcihp-for-1.6-machine-typ.patch of Package qemu.9835

From 3d435b9240205a58e21644fd31c84f9d4e3e8a84 Mon Sep 17 00:00:00 2001
From: Fei Li <fli@suse.com>
Date: Fri, 19 Jan 2018 13:42:51 +0800
Subject: [PATCH] pcihp: fix pcihp for 1.6 machine type and older

Commit id f0c9d64a avoids adding ACPI_PCIHP_PROP_BSEL twice for
machine type 1.7, but also removes the adding for 1.6 and older
and xen, which causes an error when hotplugging a pci device using
qemu v2.9.* and v2.10.0.

There are two chances for intializing ACPI_PCIHP_PROP_BSEL before
commit f0c9d64a, one is in acpi_pcihp_init and the other is in
acpi_set_bsel. This patch restores the first chance, and adds a check
for the second chance: if the property has already been intialized,
just skip.

[FL: BSC#1074572]
Signed-off-by: Fei Li <fli@suse.com>
---
 hw/acpi/pcihp.c      | 11 +++++++++++
 hw/i386/acpi-build.c |  4 +++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 2b0f3e1bfb..d957d1e30d 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -49,6 +49,7 @@
 
 #define ACPI_PCIHP_ADDR 0xae00
 #define ACPI_PCIHP_SIZE 0x0014
+#define ACPI_PCIHP_LEGACY_SIZE 0x000f
 #define PCI_UP_BASE 0x0000
 #define PCI_DOWN_BASE 0x0004
 #define PCI_EJ_BASE 0x0008
@@ -301,6 +302,16 @@ void acpi_pcihp_init(Object *owner, AcpiPciHpState *s, PCIBus *root_bus,
     s->root= root_bus;
     s->legacy_piix = !bridges_enabled;
 
+    if (s->legacy_piix) {
+        unsigned *bus_bsel = g_malloc(sizeof *bus_bsel);
+
+        s->io_len = ACPI_PCIHP_LEGACY_SIZE;
+
+        *bus_bsel = ACPI_PCIHP_BSEL_DEFAULT;
+        object_property_add_uint32_ptr(OBJECT(root_bus), ACPI_PCIHP_PROP_BSEL,
+                                       bus_bsel, NULL);
+    }
+
     memory_region_init_io(&s->io, owner, &acpi_pcihp_io_ops, s,
                           "acpi-pci-hotplug", s->io_len);
     memory_region_add_subregion(address_space_io, s->io_base, &s->io);
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 76fa4555bf..b40870c0f7 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -457,8 +457,10 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
 {
     unsigned *bsel_alloc = opaque;
     unsigned *bus_bsel;
+    int64_t bsel = object_property_get_int(OBJECT(bus),
+                                           ACPI_PCIHP_PROP_BSEL, NULL);
 
-    if (qbus_is_hotpluggable(BUS(bus))) {
+    if (qbus_is_hotpluggable(BUS(bus)) && bsel < 0) {
         bus_bsel = g_malloc(sizeof *bus_bsel);
 
         *bus_bsel = (*bsel_alloc)++;
openSUSE Build Service is sponsored by