From nobody Thu Nov 6 10:15:19 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