From nobody Thu Nov 6 08:22:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540376523194794.8780820205924; Wed, 24 Oct 2018 03:22:03 -0700 (PDT) Received: from localhost ([::1]:47288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGIW-0005jq-Or for importer@patchew.org; Wed, 24 Oct 2018 06:21:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGGT-0004VD-8m for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:19:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFGGS-0008QB-9u for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:19:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47356) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFGGS-0008Px-01; Wed, 24 Oct 2018 06:19:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4DF412D6E78; Wed, 24 Oct 2018 10:19:47 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-178.ams2.redhat.com [10.36.117.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17E445C1B2; Wed, 24 Oct 2018 10:19:40 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 24 Oct 2018 12:19:24 +0200 Message-Id: <20181024101930.20674-2-david@redhat.com> In-Reply-To: <20181024101930.20674-1-david@redhat.com> References: <20181024101930.20674-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 24 Oct 2018 10:19:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 1/7] pcihp: perform check for bus capability in pre_plug handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Alexander Graf , "Dr . David Alan Gilbert" , qemu-ppc@nongnu.org, Igor Mammedov , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Perform the check in the pre_plug handler. In addition, we need the capability only if the device is actually hotplugged (and not created during machine initialization). This is a preparation for coldplugging devices via that hotplug handler. Signed-off-by: David Hildenbrand Reviewed-by: Igor Mammedov --- hw/acpi/pcihp.c | 21 +++++++++++++++------ hw/acpi/piix4.c | 16 ++++++++++++++-- include/hw/acpi/pcihp.h | 2 ++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 80d42e12ff..5e7cef173c 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -217,17 +217,24 @@ void acpi_pcihp_reset(AcpiPciHpState *s) acpi_pcihp_update(s); } =20 -void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState= *s, - DeviceState *dev, Error **errp) +void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) { - PCIDevice *pdev =3D PCI_DEVICE(dev); - int slot =3D PCI_SLOT(pdev->devfn); - int bsel =3D acpi_pcihp_get_bsel(pci_get_bus(pdev)); - if (bsel < 0) { + /* Only hotplugged devices need the hotplug capability. */ + if (dev->hotplugged && + acpi_pcihp_get_bsel(pci_get_bus(PCI_DEVICE(dev))) < 0) { error_setg(errp, "Unsupported bus. Bus doesn't have property '" ACPI_PCIHP_PROP_BSEL "' set"); return; } +} + +void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState= *s, + DeviceState *dev, Error **errp) +{ + PCIDevice *pdev =3D PCI_DEVICE(dev); + int slot =3D PCI_SLOT(pdev->devfn); + int bsel; =20 /* Don't send event when device is enabled during qemu machine creatio= n: * it is present on boot, no hotplug event is necessary. We do send an @@ -236,6 +243,8 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_= dev, AcpiPciHpState *s, return; } =20 + bsel =3D acpi_pcihp_get_bsel(pci_get_bus(pdev)); + g_assert(bsel >=3D 0); s->acpi_pcihp_pci_status[bsel].up |=3D (1U << slot); acpi_send_event(DEVICE(hotplug_dev), ACPI_PCI_HOTPLUG_STATUS); } diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index e330f24c71..167afe2cea 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -370,6 +370,18 @@ static void piix4_pm_powerdown_req(Notifier *n, void *= opaque) acpi_pm1_evt_power_down(&s->ar); } =20 +static void piix4_device_pre_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + acpi_pcihp_device_pre_plug_cb(hotplug_dev, dev, errp); + } else if (!object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) && + !object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + error_setg(errp, "acpi: device plug request for not supported devi= ce" + " type: %s", object_get_typename(OBJECT(dev))); + } +} + static void piix4_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -392,8 +404,7 @@ static void piix4_device_plug_cb(HotplugHandler *hotplu= g_dev, acpi_cpu_plug_cb(hotplug_dev, &s->cpuhp_state, dev, errp); } } else { - error_setg(errp, "acpi: device plug request for not supported devi= ce" - " type: %s", object_get_typename(OBJECT(dev))); + g_assert_not_reached(); } } =20 @@ -702,6 +713,7 @@ static void piix4_pm_class_init(ObjectClass *klass, voi= d *data) */ dc->user_creatable =3D false; dc->hotpluggable =3D false; + hc->pre_plug =3D piix4_device_pre_plug_cb; hc->plug =3D piix4_device_plug_cb; hc->unplug_request =3D piix4_device_unplug_request_cb; hc->unplug =3D piix4_device_unplug_cb; diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h index 8a65f99fc8..ce31625850 100644 --- a/include/hw/acpi/pcihp.h +++ b/include/hw/acpi/pcihp.h @@ -56,6 +56,8 @@ typedef struct AcpiPciHpState { void acpi_pcihp_init(Object *owner, AcpiPciHpState *, PCIBus *root, MemoryRegion *address_space_io, bool bridges_enabled); =20 +void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp); void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState= *s, DeviceState *dev, Error **errp); void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpSta= te *s, --=20 2.17.2 From nobody Thu Nov 6 08:22:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540376676505723.6551429491941; Wed, 24 Oct 2018 03:24:36 -0700 (PDT) Received: from localhost ([::1]:47301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGL5-0000cs-GQ for importer@patchew.org; Wed, 24 Oct 2018 06:24:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGGg-0004fi-56 for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:20:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFGGd-00005a-Hv for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:20:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46904) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFGGb-0008Tw-7r; Wed, 24 Oct 2018 06:19:58 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36F80308FF0D; Wed, 24 Oct 2018 10:19:53 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-178.ams2.redhat.com [10.36.117.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DB3A1715C; Wed, 24 Oct 2018 10:19:47 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 24 Oct 2018 12:19:25 +0200 Message-Id: <20181024101930.20674-3-david@redhat.com> In-Reply-To: <20181024101930.20674-1-david@redhat.com> References: <20181024101930.20674-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 24 Oct 2018 10:19:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 2/7] pcihp: overwrite hotplug handler recursively from the start X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Alexander Graf , "Dr . David Alan Gilbert" , qemu-ppc@nongnu.org, Igor Mammedov , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For now, the hotplug handler is not called for devices that are being cold plugged. The hotplug handler is setup when the machine initialization is fully done. Only bridges that were cold plugged are considered. Set the hotplug handler for the root piix bus directly when realizing. Overwrite the hotplug handler of bridges when hotplugging/coldplugging them. This will now make sure that the ACPI PCI hotplug handler is also called for cold-plugged devices (also on bridges) and for bridges that were hotplugged. When trying to hotplug a device to a hotplugged bridge, we now correctly get the error message "Unsupported bus. Bus doesn't have property 'acpi-pcihp-bsel' set" Insted of going via the standard PCI hotplug handler. Signed-off-by: David Hildenbrand --- hw/acpi/pcihp.c | 10 ++++++++++ hw/acpi/piix4.c | 16 +--------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 5e7cef173c..647b5e8d82 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -30,6 +30,7 @@ #include "hw/hw.h" #include "hw/i386/pc.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bridge.h" #include "hw/acpi/acpi.h" #include "sysemu/sysemu.h" #include "exec/address-spaces.h" @@ -236,6 +237,15 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug= _dev, AcpiPciHpState *s, int slot =3D PCI_SLOT(pdev->devfn); int bsel; =20 + if (!s->legacy_piix && object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDG= E)) { + PCIBus *sec =3D pci_bridge_get_sec_bus(PCI_BRIDGE(pdev)); + + /* Overwrite the default hotplug handler with the ACPI PCI one. */ + qbus_set_hotplug_handler(BUS(sec), DEVICE(hotplug_dev), &error_abo= rt); + /* No need to do it recursively */ + assert(QLIST_EMPTY(&sec->child)); + } + /* Don't send event when device is enabled during qemu machine creatio= n: * it is present on boot, no hotplug event is necessary. We do send an * event when the device is disabled later. */ diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 167afe2cea..e611778daf 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -446,15 +446,6 @@ static void piix4_device_unplug_cb(HotplugHandler *hot= plug_dev, } } =20 -static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque) -{ - PIIX4PMState *s =3D opaque; - - /* pci_bus cannot outlive PIIX4PMState, because /machine keeps it alive - * and it's not hot-unpluggable */ - qbus_set_hotplug_handler(BUS(pci_bus), DEVICE(s), &error_abort); -} - static void piix4_pm_machine_ready(Notifier *n, void *opaque) { PIIX4PMState *s =3D container_of(n, PIIX4PMState, machine_ready); @@ -468,12 +459,6 @@ static void piix4_pm_machine_ready(Notifier *n, void *= opaque) pci_conf[0x63] =3D 0x60; pci_conf[0x67] =3D (memory_region_present(io_as, 0x3f8) ? 0x08 : 0) | (memory_region_present(io_as, 0x2f8) ? 0x90 : 0); - - if (s->use_acpi_pci_hotplug) { - pci_for_each_bus(pci_get_bus(d), piix4_update_bus_hotplug, s); - } else { - piix4_update_bus_hotplug(pci_get_bus(d), s); - } } =20 static void piix4_pm_add_propeties(PIIX4PMState *s) @@ -547,6 +532,7 @@ static void piix4_pm_realize(PCIDevice *dev, Error **er= rp) =20 piix4_acpi_system_hot_add_init(pci_address_space_io(dev), pci_get_bus(dev), s); + qbus_set_hotplug_handler(BUS(pci_get_bus(dev)), DEVICE(s), &error_abor= t); =20 piix4_pm_add_propeties(s); } --=20 2.17.2 From nobody Thu Nov 6 08:22:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540376673099973.8567897642251; Wed, 24 Oct 2018 03:24:33 -0700 (PDT) Received: from localhost ([::1]:47299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGKx-0000Vj-QI for importer@patchew.org; Wed, 24 Oct 2018 06:24:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGGl-0004hU-6u for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:20:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFGGk-00009E-9Z for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:20:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51104) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFGGj-00006l-Vo; Wed, 24 Oct 2018 06:20:06 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD9B9C057E06; Wed, 24 Oct 2018 10:20:01 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-178.ams2.redhat.com [10.36.117.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id F04D75C1B2; Wed, 24 Oct 2018 10:19:53 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 24 Oct 2018 12:19:26 +0200 Message-Id: <20181024101930.20674-4-david@redhat.com> In-Reply-To: <20181024101930.20674-1-david@redhat.com> References: <20181024101930.20674-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 24 Oct 2018 10:20:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 3/7] pcihp: route unplug via the hotplug handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Alexander Graf , "Dr . David Alan Gilbert" , qemu-ppc@nongnu.org, Igor Mammedov , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Preparation for multi-stage hotplug handlers. Signed-off-by: David Hildenbrand --- hw/acpi/pcihp.c | 11 ++++++++++- hw/acpi/piix4.c | 7 +++++-- include/hw/acpi/pcihp.h | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 647b5e8d82..062f3c9091 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -154,6 +154,7 @@ static bool acpi_pcihp_pc_no_hotplug(AcpiPciHpState *s,= PCIDevice *dev) =20 static void acpi_pcihp_eject_slot(AcpiPciHpState *s, unsigned bsel, unsign= ed slots) { + HotplugHandler *hotplug_ctrl; BusChild *kid, *next; int slot =3D ctz32(slots); PCIBus *bus =3D acpi_pcihp_find_hotplug_bus(s, bsel); @@ -171,7 +172,8 @@ static void acpi_pcihp_eject_slot(AcpiPciHpState *s, un= signed bsel, unsigned slo PCIDevice *dev =3D PCI_DEVICE(qdev); if (PCI_SLOT(dev->devfn) =3D=3D slot) { if (!acpi_pcihp_pc_no_hotplug(s, dev)) { - object_unparent(OBJECT(qdev)); + hotplug_ctrl =3D qdev_get_hotplug_handler(qdev); + hotplug_handler_unplug(hotplug_ctrl, qdev, &error_abort); } } } @@ -261,6 +263,13 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug= _dev, AcpiPciHpState *s, =20 void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpSta= te *s, DeviceState *dev, Error **errp) +{ + object_unparent(OBJECT(dev)); +} + +void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev, + AcpiPciHpState *s, DeviceState *d= ev, + Error **errp) { PCIDevice *pdev =3D PCI_DEVICE(dev); int slot =3D PCI_SLOT(pdev->devfn); diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index e611778daf..ba5632becc 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -418,8 +418,8 @@ static void piix4_device_unplug_request_cb(HotplugHandl= er *hotplug_dev, acpi_memory_unplug_request_cb(hotplug_dev, &s->acpi_memory_hotplug, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { - acpi_pcihp_device_unplug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev, - errp); + acpi_pcihp_device_unplug_request_cb(hotplug_dev, &s->acpi_pci_hotp= lug, + dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) && !s->cpu_hotplug_legacy) { acpi_cpu_unplug_request_cb(hotplug_dev, &s->cpuhp_state, dev, errp= ); @@ -437,6 +437,9 @@ static void piix4_device_unplug_cb(HotplugHandler *hotp= lug_dev, if (s->acpi_memory_hotplug.is_enabled && object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { acpi_memory_unplug_cb(&s->acpi_memory_hotplug, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + acpi_pcihp_device_unplug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev, + errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) && !s->cpu_hotplug_legacy) { acpi_cpu_unplug_cb(&s->cpuhp_state, dev, errp); diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h index ce31625850..8bc4a4c01d 100644 --- a/include/hw/acpi/pcihp.h +++ b/include/hw/acpi/pcihp.h @@ -62,6 +62,9 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_de= v, AcpiPciHpState *s, DeviceState *dev, Error **errp); void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpSta= te *s, DeviceState *dev, Error **errp); +void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev, + AcpiPciHpState *s, DeviceState *d= ev, + Error **errp); =20 /* Called on reset */ void acpi_pcihp_reset(AcpiPciHpState *s); --=20 2.17.2 From nobody Thu Nov 6 08:22:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540376793873563.6054452794659; Wed, 24 Oct 2018 03:26:33 -0700 (PDT) Received: from localhost ([::1]:47322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGMy-00021F-Ns for importer@patchew.org; Wed, 24 Oct 2018 06:26:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGGn-0004ji-LP for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:20:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFGGm-0000B3-QO for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:20:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33532) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFGGm-0000AX-KU; Wed, 24 Oct 2018 06:20:08 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BEC94308FBB1; Wed, 24 Oct 2018 10:20:07 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-178.ams2.redhat.com [10.36.117.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id 993EA5C888; Wed, 24 Oct 2018 10:20:02 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 24 Oct 2018 12:19:27 +0200 Message-Id: <20181024101930.20674-5-david@redhat.com> In-Reply-To: <20181024101930.20674-1-david@redhat.com> References: <20181024101930.20674-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 24 Oct 2018 10:20:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 4/7] pci/pcie: route unplug via the hotplug handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Alexander Graf , "Dr . David Alan Gilbert" , qemu-ppc@nongnu.org, Igor Mammedov , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Preparation for multi-stage hotplug handlers. Signed-off-by: David Hildenbrand --- hw/pci/pcie.c | 10 +++++++++- hw/pci/pcie_port.c | 1 + include/hw/pci/pcie.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 02a7bf3af5..744727dc0b 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -364,11 +364,19 @@ void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug= _dev, DeviceState *dev, } } =20 -static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque) +void pcie_cap_slot_hot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState = *dev, + Error **errp) { object_unparent(OBJECT(dev)); } =20 +static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque) +{ + HotplugHandler *hotplug_ctrl =3D qdev_get_hotplug_handler(DEVICE(dev)); + + hotplug_handler_unplug(hotplug_ctrl, DEVICE(dev), &error_abort); +} + void pcie_cap_slot_hot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c index 13fe6c6945..6e993da603 100644 --- a/hw/pci/pcie_port.c +++ b/hw/pci/pcie_port.c @@ -156,6 +156,7 @@ static void pcie_slot_class_init(ObjectClass *oc, void = *data) dc->props =3D pcie_slot_props; hc->pre_plug =3D pcie_cap_slot_pre_plug_cb; hc->plug =3D pcie_cap_slot_hotplug_cb; + hc->unplug =3D pcie_cap_slot_hot_unplug_cb; hc->unplug_request =3D pcie_cap_slot_hot_unplug_request_cb; } =20 diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h index 001d230d7d..b6f05a0e43 100644 --- a/include/hw/pci/pcie.h +++ b/include/hw/pci/pcie.h @@ -135,6 +135,8 @@ void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_= dev, DeviceState *dev, Error **errp); void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *de= v, Error **errp); +void pcie_cap_slot_hot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState = *dev, + Error **errp); void pcie_cap_slot_hot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); #endif /* QEMU_PCIE_H */ --=20 2.17.2 From nobody Thu Nov 6 08:22:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540376887285751.1934511608738; Wed, 24 Oct 2018 03:28:07 -0700 (PDT) Received: from localhost ([::1]:47332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGOU-00046U-1g for importer@patchew.org; Wed, 24 Oct 2018 06:28:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51490) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGH1-0004wp-RA for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:20:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFGGw-0000JQ-CV for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:20:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47574) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFGGw-0000I3-4A; Wed, 24 Oct 2018 06:20:18 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BEAA90C9F; Wed, 24 Oct 2018 10:20:15 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-178.ams2.redhat.com [10.36.117.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80CB25C1B2; Wed, 24 Oct 2018 10:20:08 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 24 Oct 2018 12:19:28 +0200 Message-Id: <20181024101930.20674-6-david@redhat.com> In-Reply-To: <20181024101930.20674-1-david@redhat.com> References: <20181024101930.20674-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 24 Oct 2018 10:20:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 5/7] pci/shpc: move hotplug checks to preplug handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Alexander Graf , "Dr . David Alan Gilbert" , qemu-ppc@nongnu.org, Igor Mammedov , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move the checks to the pre_plug handler. I don't see a reason to check for the PCI slot when unplugging. Signed-off-by: David Hildenbrand --- hw/pci-bridge/pci_bridge_dev.c | 11 ++++++++-- hw/pci-bridge/pcie_pci_bridge.c | 11 ++++++++-- hw/pci/shpc.c | 36 ++++++++++++++------------------- include/hw/pci/shpc.h | 2 ++ 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c index 97a8e8b6a4..2362dcbc64 100644 --- a/hw/pci-bridge/pci_bridge_dev.c +++ b/hw/pci-bridge/pci_bridge_dev.c @@ -206,8 +206,8 @@ static const VMStateDescription pci_bridge_dev_vmstate = =3D { } }; =20 -static void pci_bridge_dev_hotplug_cb(HotplugHandler *hotplug_dev, - DeviceState *dev, Error **errp) +static void pci_bridge_dev_pre_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) { PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); =20 @@ -216,6 +216,12 @@ static void pci_bridge_dev_hotplug_cb(HotplugHandler *= hotplug_dev, "this %s", TYPE_PCI_BRIDGE_DEV); return; } + shpc_device_pre_plug_cb(hotplug_dev, dev, errp); +} + +static void pci_bridge_dev_hotplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ shpc_device_hotplug_cb(hotplug_dev, dev, errp); } =20 @@ -251,6 +257,7 @@ static void pci_bridge_dev_class_init(ObjectClass *klas= s, void *data) dc->props =3D pci_bridge_dev_properties; dc->vmsd =3D &pci_bridge_dev_vmstate; set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + hc->pre_plug =3D pci_bridge_dev_pre_plug_cb; hc->plug =3D pci_bridge_dev_hotplug_cb; hc->unplug_request =3D pci_bridge_dev_hot_unplug_request_cb; } diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridg= e.c index 04cf5a6a92..cde8af0a4e 100644 --- a/hw/pci-bridge/pcie_pci_bridge.c +++ b/hw/pci-bridge/pcie_pci_bridge.c @@ -137,8 +137,8 @@ static const VMStateDescription pcie_pci_bridge_dev_vms= tate =3D { } }; =20 -static void pcie_pci_bridge_hotplug_cb(HotplugHandler *hotplug_dev, - DeviceState *dev, Error **errp) +static void pcie_pci_bridge_pre_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) { PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); =20 @@ -147,6 +147,12 @@ static void pcie_pci_bridge_hotplug_cb(HotplugHandler = *hotplug_dev, "this %s", TYPE_PCIE_PCI_BRIDGE_DEV); return; } + shpc_device_pre_plug_cb(hotplug_dev, dev, errp); +} + +static void pcie_pci_bridge_hotplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ shpc_device_hotplug_cb(hotplug_dev, dev, errp); } =20 @@ -180,6 +186,7 @@ static void pcie_pci_bridge_class_init(ObjectClass *kla= ss, void *data) dc->props =3D pcie_pci_bridge_dev_properties; dc->reset =3D &pcie_pci_bridge_reset; set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + hc->pre_plug =3D pcie_pci_bridge_pre_plug_cb; hc->plug =3D pcie_pci_bridge_hotplug_cb; hc->unplug_request =3D pcie_pci_bridge_hot_unplug_request_cb; } diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index a8462d48bb..1caf4a7ee9 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -482,13 +482,21 @@ static const MemoryRegionOps shpc_mmio_ops =3D { .max_access_size =3D 4, }, }; -static void shpc_device_hotplug_common(PCIDevice *affected_dev, int *slot, - SHPCDevice *shpc, Error **errp) + +static inline int shpc_device_get_slot(PCIDevice *dev) +{ + return SHPC_PCI_TO_IDX(dev->devfn); +} + +void shpc_device_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, + Error **errp) { - int pci_slot =3D PCI_SLOT(affected_dev->devfn); - *slot =3D SHPC_PCI_TO_IDX(pci_slot); + SHPCDevice *shpc =3D PCI_DEVICE(hotplug_dev)->shpc; + PCIDevice *pdev =3D PCI_DEVICE(dev); + int pci_slot =3D PCI_SLOT(pdev->devfn); + int slot =3D shpc_device_get_slot(pdev); =20 - if (pci_slot < SHPC_IDX_TO_PCI(0) || *slot >=3D shpc->nslots) { + if (pci_slot < SHPC_IDX_TO_PCI(0) || slot >=3D shpc->nslots) { error_setg(errp, "Unsupported PCI slot %d for standard hotplug " "controller. Valid slots are between %d and %d.", pci_slot, SHPC_IDX_TO_PCI(0), @@ -500,16 +508,9 @@ static void shpc_device_hotplug_common(PCIDevice *affe= cted_dev, int *slot, void shpc_device_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { - Error *local_err =3D NULL; PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); SHPCDevice *shpc =3D pci_hotplug_dev->shpc; - int slot; - - shpc_device_hotplug_common(PCI_DEVICE(dev), &slot, shpc, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } + int slot =3D shpc_device_get_slot(PCI_DEVICE(dev)); =20 /* Don't send event when device is enabled during qemu machine creatio= n: * it is present on boot, no hotplug event is necessary. We do send an @@ -543,18 +544,11 @@ void shpc_device_hotplug_cb(HotplugHandler *hotplug_d= ev, DeviceState *dev, void shpc_device_hot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { - Error *local_err =3D NULL; PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); SHPCDevice *shpc =3D pci_hotplug_dev->shpc; + int slot =3D shpc_device_get_slot(PCI_DEVICE(dev)); uint8_t state; uint8_t led; - int slot; - - shpc_device_hotplug_common(PCI_DEVICE(dev), &slot, shpc, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } =20 shpc->config[SHPC_SLOT_EVENT_LATCH(slot)] |=3D SHPC_SLOT_EVENT_BUTTON; state =3D shpc_get_status(shpc, slot, SHPC_SLOT_STATE_MASK); diff --git a/include/hw/pci/shpc.h b/include/hw/pci/shpc.h index ee19fecf61..82eacf8e96 100644 --- a/include/hw/pci/shpc.h +++ b/include/hw/pci/shpc.h @@ -45,6 +45,8 @@ void shpc_free(PCIDevice *dev); void shpc_cap_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int = len); =20 =20 +void shpc_device_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, + Error **errp); void shpc_device_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); void shpc_device_hot_unplug_request_cb(HotplugHandler *hotplug_dev, --=20 2.17.2 From nobody Thu Nov 6 08:22:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540376797823636.6883862334786; Wed, 24 Oct 2018 03:26:37 -0700 (PDT) Received: from localhost ([::1]:47323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGN2-00024W-Kj for importer@patchew.org; Wed, 24 Oct 2018 06:26:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGHL-0005Am-Pl for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:20:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFGHK-0000ha-U3 for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:20:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37548) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFGHK-0000hS-MP; Wed, 24 Oct 2018 06:20:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 01A883001DD6; Wed, 24 Oct 2018 10:20:42 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-178.ams2.redhat.com [10.36.117.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47E945C1B2; Wed, 24 Oct 2018 10:20:15 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 24 Oct 2018 12:19:29 +0200 Message-Id: <20181024101930.20674-7-david@redhat.com> In-Reply-To: <20181024101930.20674-1-david@redhat.com> References: <20181024101930.20674-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 24 Oct 2018 10:20:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 6/7] pci/shpc: route unplug via the hotplug handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Alexander Graf , "Dr . David Alan Gilbert" , qemu-ppc@nongnu.org, Igor Mammedov , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Preparation for multi-stage hotplug handlers. Signed-off-by: David Hildenbrand --- hw/pci-bridge/pci_bridge_dev.c | 14 ++++++++++++++ hw/pci-bridge/pcie_pci_bridge.c | 14 ++++++++++++++ hw/pci/shpc.c | 11 ++++++++++- include/hw/pci/shpc.h | 2 ++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c index 2362dcbc64..978ab2a896 100644 --- a/hw/pci-bridge/pci_bridge_dev.c +++ b/hw/pci-bridge/pci_bridge_dev.c @@ -225,6 +225,19 @@ static void pci_bridge_dev_hotplug_cb(HotplugHandler *= hotplug_dev, shpc_device_hotplug_cb(hotplug_dev, dev, errp); } =20 +static void pci_bridge_dev_hot_unplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); + + if (!shpc_present(pci_hotplug_dev)) { + error_setg(errp, "standard hotplug controller has been disabled fo= r " + "this %s", TYPE_PCI_BRIDGE_DEV); + return; + } + shpc_device_hot_unplug_cb(hotplug_dev, dev, errp); +} + static void pci_bridge_dev_hot_unplug_request_cb(HotplugHandler *hotplug_d= ev, DeviceState *dev, Error **errp) @@ -259,6 +272,7 @@ static void pci_bridge_dev_class_init(ObjectClass *klas= s, void *data) set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); hc->pre_plug =3D pci_bridge_dev_pre_plug_cb; hc->plug =3D pci_bridge_dev_hotplug_cb; + hc->unplug =3D pci_bridge_dev_hot_unplug_cb; hc->unplug_request =3D pci_bridge_dev_hot_unplug_request_cb; } =20 diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridg= e.c index cde8af0a4e..6ca711210e 100644 --- a/hw/pci-bridge/pcie_pci_bridge.c +++ b/hw/pci-bridge/pcie_pci_bridge.c @@ -156,6 +156,19 @@ static void pcie_pci_bridge_hotplug_cb(HotplugHandler = *hotplug_dev, shpc_device_hotplug_cb(hotplug_dev, dev, errp); } =20 +static void pcie_pci_bridge_hot_unplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + PCIDevice *pci_hotplug_dev =3D PCI_DEVICE(hotplug_dev); + + if (!shpc_present(pci_hotplug_dev)) { + error_setg(errp, "standard hotplug controller has been disabled fo= r " + "this %s", TYPE_PCIE_PCI_BRIDGE_DEV); + return; + } + shpc_device_hot_unplug_cb(hotplug_dev, dev, errp); +} + static void pcie_pci_bridge_hot_unplug_request_cb(HotplugHandler *hotplug_= dev, DeviceState *dev, Error **errp) @@ -188,6 +201,7 @@ static void pcie_pci_bridge_class_init(ObjectClass *kla= ss, void *data) set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); hc->pre_plug =3D pcie_pci_bridge_pre_plug_cb; hc->plug =3D pcie_pci_bridge_hotplug_cb; + hc->unplug =3D pcie_pci_bridge_hot_unplug_cb; hc->unplug_request =3D pcie_pci_bridge_hot_unplug_request_cb; } =20 diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 1caf4a7ee9..591f5189c5 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -238,6 +238,7 @@ static void shpc_invalid_command(SHPCDevice *shpc) =20 static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot) { + HotplugHandler *hotplug_ctrl; int devfn; int pci_slot =3D SHPC_IDX_TO_PCI(slot); for (devfn =3D PCI_DEVFN(pci_slot, 0); @@ -245,7 +246,9 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc,= int slot) ++devfn) { PCIDevice *affected_dev =3D shpc->sec_bus->devices[devfn]; if (affected_dev) { - object_unparent(OBJECT(affected_dev)); + hotplug_ctrl =3D qdev_get_hotplug_handler(DEVICE(affected_dev)= ); + hotplug_handler_unplug(hotplug_ctrl, DEVICE(affected_dev), + &error_abort); } } } @@ -541,6 +544,12 @@ void shpc_device_hotplug_cb(HotplugHandler *hotplug_de= v, DeviceState *dev, shpc_interrupt_update(pci_hotplug_dev); } =20 +void shpc_device_hot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *d= ev, + Error **errp) +{ + object_unparent(OBJECT(dev)); +} + void shpc_device_hot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { diff --git a/include/hw/pci/shpc.h b/include/hw/pci/shpc.h index 82eacf8e96..40c5ac9bfe 100644 --- a/include/hw/pci/shpc.h +++ b/include/hw/pci/shpc.h @@ -49,6 +49,8 @@ void shpc_device_pre_plug_cb(HotplugHandler *hotplug_dev,= DeviceState *dev, Error **errp); void shpc_device_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); +void shpc_device_hot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *d= ev, + Error **errp); void shpc_device_hot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); =20 --=20 2.17.2 From nobody Thu Nov 6 08:22:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540376608823345.1513393150316; Wed, 24 Oct 2018 03:23:28 -0700 (PDT) Received: from localhost ([::1]:47296 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGJz-0008D7-Mg for importer@patchew.org; Wed, 24 Oct 2018 06:23:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFGIF-00062G-5w for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:21:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFGID-000153-FW for qemu-devel@nongnu.org; Wed, 24 Oct 2018 06:21:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38127) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFGIB-0000sC-8Q; Wed, 24 Oct 2018 06:21:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EA791393FA; Wed, 24 Oct 2018 10:21:08 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-178.ams2.redhat.com [10.36.117.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE60E5C1B2; Wed, 24 Oct 2018 10:20:42 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 24 Oct 2018 12:19:30 +0200 Message-Id: <20181024101930.20674-8-david@redhat.com> In-Reply-To: <20181024101930.20674-1-david@redhat.com> References: <20181024101930.20674-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 24 Oct 2018 10:21:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 7/7] spapr_pci: route unplug via the hotplug handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Alexander Graf , "Dr . David Alan Gilbert" , qemu-ppc@nongnu.org, Igor Mammedov , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Preparation for multi-stage hotplug handlers. Signed-off-by: David Hildenbrand Reviewed-by: Greg Kurz --- hw/ppc/spapr_pci.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 58afa46204..64b8591023 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1370,18 +1370,9 @@ static int spapr_create_pci_child_dt(sPAPRPHBState *= phb, PCIDevice *dev, /* Callback to be called during DRC release. */ void spapr_phb_remove_pci_device_cb(DeviceState *dev) { - /* some version guests do not wait for completion of a device - * cleanup (generally done asynchronously by the kernel) before - * signaling to QEMU that the device is safe, but instead sleep - * for some 'safe' period of time. unfortunately on a busy host - * this sleep isn't guaranteed to be long enough, resulting in - * bad things like IRQ lines being left asserted during final - * device removal. to deal with this we call reset just prior - * to finalizing the device, which will put the device back into - * an 'idle' state, as the device cleanup code expects. - */ - pci_device_reset(PCI_DEVICE(dev)); - object_unparent(OBJECT(dev)); + HotplugHandler *hotplug_ctrl =3D qdev_get_hotplug_handler(dev); + + hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); } =20 static sPAPRDRConnector *spapr_phb_get_pci_func_drc(sPAPRPHBState *phb, @@ -1490,6 +1481,23 @@ out: } } =20 +static void spapr_pci_unplug(HotplugHandler *plug_handler, + DeviceState *plugged_dev, Error **errp) +{ + /* some version guests do not wait for completion of a device + * cleanup (generally done asynchronously by the kernel) before + * signaling to QEMU that the device is safe, but instead sleep + * for some 'safe' period of time. unfortunately on a busy host + * this sleep isn't guaranteed to be long enough, resulting in + * bad things like IRQ lines being left asserted during final + * device removal. to deal with this we call reset just prior + * to finalizing the device, which will put the device back into + * an 'idle' state, as the device cleanup code expects. + */ + pci_device_reset(PCI_DEVICE(plugged_dev)); + object_unparent(OBJECT(plugged_dev)); +} + static void spapr_pci_unplug_request(HotplugHandler *plug_handler, DeviceState *plugged_dev, Error **err= p) { @@ -1965,6 +1973,7 @@ static void spapr_phb_class_init(ObjectClass *klass, = void *data) dc->user_creatable =3D true; set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); hp->plug =3D spapr_pci_plug; + hp->unplug =3D spapr_pci_unplug; hp->unplug_request =3D spapr_pci_unplug_request; } =20 --=20 2.17.2