In case user regret when hot-add multi-function, we should roll back,
device_del the function added but still not worked.

Signed-off-by: Cao jin <caoj.f...@cn.fujitsu.com>
---
 hw/pci/pcie.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 89bf61b..497f390 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -265,9 +265,27 @@ void pcie_cap_slot_hot_unplug_request_cb(HotplugHandler 
*hotplug_dev,
                                          DeviceState *dev, Error **errp)
 {
     uint8_t *exp_cap;
+    PCIDevice *pci_dev = PCI_DEVICE(dev);
+    PCIBus *bus = pci_dev->bus;
 
     pcie_cap_slot_hotplug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp);
 
+    /* handle the condition: user hot-add multi function, but regret before
+     * finish it, and want to delete the added but not worked function. Fake
+     * the condition: the slot is polulated, power indicator is off and power
+     * controller is off, so device can be detached when OS write config space.
+     */
+    if (PCI_FUNC(pci_dev->devfn) > 0 &&
+            bus->devices[PCI_DEVFN(0, 0)] == NULL) {
+        pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA,
+                PCI_EXP_SLTSTA_PDS);
+
+        pcie_cap_slot_event(PCI_DEVICE(hotplug_dev),
+                PCI_EXP_HP_EV_PDC | PCI_EXP_HP_EV_ABP);
+
+        return;
+    }
+
     pcie_cap_slot_push_attention_button(PCI_DEVICE(hotplug_dev));
 }
 
-- 
2.1.0


Reply via email to