From b0ae5c46407a9474494019206c491e0d942eb864 Mon Sep 17 00:00:00 2001
Message-Id: <b0ae5c46407a9474494019206c491e0d942eb864.1344844502.git.minovotn@redhat.com>
In-Reply-To: <0c740d356f8d30310bcff2b06cfefad0e72769e2.1344844502.git.minovotn@redhat.com>
References: <0c740d356f8d30310bcff2b06cfefad0e72769e2.1344844502.git.minovotn@redhat.com>
From: Alex Williamson <alex.williamson@redhat.com>
Date: Tue, 7 Aug 2012 19:41:38 +0200
Subject: [PATCH 5/5] acpi: explicitly account for >1 device per slot

RH-Author: Alex Williamson <alex.williamson@redhat.com>
Message-id: <20120807194138.6021.10612.stgit@bling.home>
Patchwork-id: 40609
O-Subject: [RHEL6.4 qemu-kvm PATCH 5/5] acpi: explicitly account for >1 device per slot
Bugzilla: 807391
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
RH-Acked-by: Don Dutile <ddutile@redhat.com>

From: Michael S. Tsirkin <mst@redhat.com>

Bugzilla: 807391
Upstream commit: 54bfa546a0b5af335128ef5c477f8af9834df498

Slot present bit is cleared apparently for each device. Hotplug and non
hotplug devices should not mix normally, and we only set the bit when we
add a device so it should all work out, but it's more robust to
explicitly account for more than one device per slot.

Acked-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---

 hw/acpi.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 hw/acpi.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index e1d8288..8501f3e 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -569,6 +569,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
     DeviceState *qdev, *next;
     BusState *bus = qdev_get_parent_bus(&s->dev.qdev);
     int slot = ffs(slots) - 1;
+    bool slot_free = true;
 
     /* Mark request as complete */
     s->pci0_status.down &= ~(1U << slot);
@@ -576,11 +577,17 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
     QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
         PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
         PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev);
-        if (PCI_SLOT(dev->devfn) == slot && !info->no_hotplug) {
-            s->pci0_slot_device_present &= ~(1U << slot);
-            qdev_free(qdev);
+        if (PCI_SLOT(dev->devfn) == slot) {
+            if (info->no_hotplug) {
+                slot_free = false;
+            } else {
+                qdev_free(qdev);
+            }
         }
     }
+    if (slot_free) {
+        s->pci0_slot_device_present &= ~(1U << slot);
+    }
 
 }
 
-- 
1.7.11.2

