From nobody Tue Dec 2 02:33:07 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EEB83093B2 for ; Tue, 18 Nov 2025 22:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763504018; cv=none; b=kjVfKCkW7YgYoqbowwayGmUourBJZmTZMANv28EqC0l2UkV1FznK14wJg2s3gvaO9crPQqtXTnAxQmG2HaUHM19Wp41VtSgnAs5G0DJuaWdybmFT98mnCXpI4SgUl0PGet/Vb8KogUhtXD2Uyc13lKQcWvudv2027axJIJgIdnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763504018; c=relaxed/simple; bh=nemxYTaxgz18cpW0AyxrnvFOgq9KjnE+stmhda3X/Q8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HCRNtwfBJRgU/gOvKZboNXymG5ogdsCej7qhGpyEvlbnS7onLedtwXs2OmuywbIG/OukovLNrnrqaJRG/cD7jD+bBI7/Mnemvt9Yt65THhvfo0SryknVn7eiU6xsw3NgwKAG+ZBy0fXdTPTkftUrDBFgwmIZLMkyIguWdVXGGaM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CGhHofK5; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CGhHofK5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763504015; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+GQmSWJXWqWL3qxm9AX9CXgB8VtCo4TJcQ8Q4ntTz+0=; b=CGhHofK5BUVPV3NyEFUnc8qdKQa/WpRrU/Cs2TDf/EoEad9FxGRZM/DwkfrkK4LfYuLeOf slpjpUVJvTjjdBac8Gffm75WepYd1tysxI761jhQQUhNRjMUDyyeLdttJuz6hNN5FLZMMX iBgbr6BIW2OKV7Su5BwSu9gaYgzxxKY= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-aIUV0x0aMsyvzeu3_78doQ-1; Tue, 18 Nov 2025 17:13:29 -0500 X-MC-Unique: aIUV0x0aMsyvzeu3_78doQ-1 X-Mimecast-MFC-AGG-ID: aIUV0x0aMsyvzeu3_78doQ_1763504008 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2C958195608A; Tue, 18 Nov 2025 22:13:28 +0000 (UTC) Received: from thinkpad-p1.kanata.rendec.net (unknown [10.22.88.100]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 42675180049F; Tue, 18 Nov 2025 22:13:26 +0000 (UTC) From: Radu Rendec To: Marc Zyngier , Bjorn Helgaas , Manivannan Sadhasivam Cc: Will Deacon , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Lorenzo Pieralisi , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] PCI: host-common: Do not set drvdata in pci_host_common_init() Date: Tue, 18 Nov 2025 17:12:43 -0500 Message-ID: <20251118221244.372423-2-rrendec@redhat.com> In-Reply-To: <20251118221244.372423-1-rrendec@redhat.com> References: <20251118221244.372423-1-rrendec@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" Currently pci_host_common_init() uses the platform device's drvdata to store the pointer to the allocated struct pci_host_bridge. This makes sense for drivers that use pci_host_common_{probe,remove}() directly as the platform probe/remove functions, but leaves no option for more complex drivers to store a pointer to their own private data. Change pci_host_common_init() to return the pointer to the allocated struct pci_host_bridge, and move the platform_set_drvdata() call to pci_host_common_probe(). This way, drivers that implement their own probe function can still use pci_host_common_init() but store their own pointer in the platform device's drvdata. For symmetry, move the release code to a new function that takes a pointer to struct pci_host_bridge, and make pci_host_common_release() a wrapper to it that extracts the pointer from the platform device's drvdata. This way, drivers that store their own private pointer in the platform device's drvdata can still use the library release code. No functional change to the existing users of pci-host-common is intended, with the exception of the pcie-apple driver, which is modified in a subsequent patch. Signed-off-by: Radu Rendec --- drivers/pci/controller/pci-host-common.c | 36 ++++++++++++++++-------- drivers/pci/controller/pci-host-common.h | 6 ++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/control= ler/pci-host-common.c index 810d1c8de24e9..86002195c93ac 100644 --- a/drivers/pci/controller/pci-host-common.c +++ b/drivers/pci/controller/pci-host-common.c @@ -52,25 +52,24 @@ struct pci_config_window *pci_host_common_ecam_create(s= truct device *dev, } EXPORT_SYMBOL_GPL(pci_host_common_ecam_create); =20 -int pci_host_common_init(struct platform_device *pdev, - const struct pci_ecam_ops *ops) +struct pci_host_bridge *pci_host_common_init(struct platform_device *pdev, + const struct pci_ecam_ops *ops) { struct device *dev =3D &pdev->dev; struct pci_host_bridge *bridge; struct pci_config_window *cfg; + int rc; =20 bridge =3D devm_pci_alloc_host_bridge(dev, 0); if (!bridge) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 of_pci_check_probe_only(); =20 - platform_set_drvdata(pdev, bridge); - /* Parse and map our Configuration Space windows */ cfg =3D pci_host_common_ecam_create(dev, bridge, ops); if (IS_ERR(cfg)) - return PTR_ERR(cfg); + return (struct pci_host_bridge *)cfg; =20 bridge->sysdata =3D cfg; bridge->ops =3D (struct pci_ops *)&ops->pci_ops; @@ -78,31 +77,46 @@ int pci_host_common_init(struct platform_device *pdev, bridge->disable_device =3D ops->disable_device; bridge->msi_domain =3D true; =20 - return pci_host_probe(bridge); + rc =3D pci_host_probe(bridge); + if (rc) + return ERR_PTR(rc); + + return bridge; } EXPORT_SYMBOL_GPL(pci_host_common_init); =20 int pci_host_common_probe(struct platform_device *pdev) { const struct pci_ecam_ops *ops; + struct pci_host_bridge *bridge; =20 ops =3D of_device_get_match_data(&pdev->dev); if (!ops) return -ENODEV; =20 - return pci_host_common_init(pdev, ops); + bridge =3D pci_host_common_init(pdev, ops); + if (IS_ERR(bridge)) + return PTR_ERR(bridge); + + platform_set_drvdata(pdev, bridge); + + return 0; } EXPORT_SYMBOL_GPL(pci_host_common_probe); =20 -void pci_host_common_remove(struct platform_device *pdev) +void pci_host_common_release(struct pci_host_bridge *bridge) { - struct pci_host_bridge *bridge =3D platform_get_drvdata(pdev); - pci_lock_rescan_remove(); pci_stop_root_bus(bridge->bus); pci_remove_root_bus(bridge->bus); pci_unlock_rescan_remove(); } +EXPORT_SYMBOL_GPL(pci_host_common_release); + +void pci_host_common_remove(struct platform_device *pdev) +{ + pci_host_common_release(platform_get_drvdata(pdev)); +} EXPORT_SYMBOL_GPL(pci_host_common_remove); =20 MODULE_DESCRIPTION("Common library for PCI host controller drivers"); diff --git a/drivers/pci/controller/pci-host-common.h b/drivers/pci/control= ler/pci-host-common.h index 51c35ec0cf37d..018e593bafe47 100644 --- a/drivers/pci/controller/pci-host-common.h +++ b/drivers/pci/controller/pci-host-common.h @@ -11,11 +11,13 @@ #define _PCI_HOST_COMMON_H =20 struct pci_ecam_ops; +struct pci_host_bridge; =20 int pci_host_common_probe(struct platform_device *pdev); -int pci_host_common_init(struct platform_device *pdev, - const struct pci_ecam_ops *ops); +struct pci_host_bridge *pci_host_common_init(struct platform_device *pdev, + const struct pci_ecam_ops *ops); void pci_host_common_remove(struct platform_device *pdev); +void pci_host_common_release(struct pci_host_bridge *bridge); =20 struct pci_config_window *pci_host_common_ecam_create(struct device *dev, struct pci_host_bridge *bridge, const struct pci_ecam_ops *ops); --=20 2.51.1 From nobody Tue Dec 2 02:33:07 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9ECFA3093B2 for ; Tue, 18 Nov 2025 22:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763504025; cv=none; b=co3aNl8F7V0qJkcS9GE/B0zF4dUatLUGN6G2VJFCWPvFBaaxMPSIsu7kXvHQTaD8aHRK3DM1DTWMH4KBCOU62E0NOuTieguKJ6FXh92Q1vCmmEUSC+PbXn3X5z56LNWo6NLE1K4oLYevPbIls8nkXGdmSsjcHyhFdPtvMorcO4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763504025; c=relaxed/simple; bh=a8bm08VYDcj/mmKPSImss1GDHgm0WbCyVNwe1Vw3XsQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kR7Id0sjPnmnlUK1RNcLtZqSBAgHBuZc/nM64ycmrWzj5NfnHekgDeg6kAlEjaE3Wnit/x25IafWBKIHK7ZhOKFeRxOntoq1o1EXL+DyAMKraqPqOf0Qlle1aYaTzdxtLRecZ5fL0nR+WEDgfQ+Zd/eCExiBSuctRlzo0G1ueVs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=G9qPNszc; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="G9qPNszc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763504022; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gsSQ2wAGK0+ES4Vvtmq8MIPX2CBajCXRr5JRuygk4SM=; b=G9qPNszc2QH+9TEUHn/XsiWmkPM7SE56LvhIMHp6gRuakRWmVdXyO8SGbsyUBGrNGh7BhB GYRn1UvC6krfhlG8ballZ01cB/Pwh7MDgoNoZhGCqU0es6JxatMD5VzNHFSdbfL6UsaA0t EXl2FU8J6tG7qHawcZWtp+unGKKWxJk= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-468-aPMkPPLCP_CZDDwSlMrQIg-1; Tue, 18 Nov 2025 17:13:38 -0500 X-MC-Unique: aPMkPPLCP_CZDDwSlMrQIg-1 X-Mimecast-MFC-AGG-ID: aPMkPPLCP_CZDDwSlMrQIg_1763504017 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E89091956096; Tue, 18 Nov 2025 22:13:36 +0000 (UTC) Received: from thinkpad-p1.kanata.rendec.net (unknown [10.22.88.100]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9FB90180047F; Tue, 18 Nov 2025 22:13:34 +0000 (UTC) From: Radu Rendec To: Marc Zyngier , Bjorn Helgaas , Manivannan Sadhasivam Cc: Will Deacon , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Lorenzo Pieralisi , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] PCI: apple: Store private pointer in platform device's drvdata Date: Tue, 18 Nov 2025 17:12:44 -0500 Message-ID: <20251118221244.372423-3-rrendec@redhat.com> In-Reply-To: <20251118221244.372423-1-rrendec@redhat.com> References: <20251118221244.372423-1-rrendec@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" Now pci_host_common_init() no longer uses the platform device's drvdata to store the pointer to the allocated struct pci_host_bridge. Use the drvdata to store the pointer to the driver's private data, which is the struct apple_pcie allocated in apple_pcie_probe(). This eliminates the need to store these pointers in a separate mapping table. This reverts most of the changes in commit 643c0c9d0496 ("PCI: apple: Add tracking of probed root ports"). No "Fixes" tag is added because nothing is broken in that commit. This is just a simplification. Signed-off-by: Radu Rendec --- drivers/pci/controller/pcie-apple.c | 53 ++++------------------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/p= cie-apple.c index 0380d300adca6..75bb6d51d31c2 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -187,7 +187,6 @@ struct apple_pcie { const struct hw_info *hw; unsigned long *bitmap; struct list_head ports; - struct list_head entry; struct completion event; struct irq_fwspec fwspec; u32 nvecs; @@ -206,9 +205,6 @@ struct apple_pcie_port { int idx; }; =20 -static LIST_HEAD(pcie_list); -static DEFINE_MUTEX(pcie_list_lock); - static void rmw_set(u32 set, void __iomem *addr) { writel_relaxed(readl_relaxed(addr) | set, addr); @@ -724,45 +720,13 @@ static int apple_msi_init(struct apple_pcie *pcie) return 0; } =20 -static void apple_pcie_register(struct apple_pcie *pcie) -{ - guard(mutex)(&pcie_list_lock); - - list_add_tail(&pcie->entry, &pcie_list); -} - -static void apple_pcie_unregister(struct apple_pcie *pcie) -{ - guard(mutex)(&pcie_list_lock); - - list_del(&pcie->entry); -} - -static struct apple_pcie *apple_pcie_lookup(struct device *dev) -{ - struct apple_pcie *pcie; - - guard(mutex)(&pcie_list_lock); - - list_for_each_entry(pcie, &pcie_list, entry) { - if (pcie->dev =3D=3D dev) - return pcie; - } - - return NULL; -} - static struct apple_pcie_port *apple_pcie_get_port(struct pci_dev *pdev) { struct pci_config_window *cfg =3D pdev->sysdata; - struct apple_pcie *pcie; + struct apple_pcie *pcie =3D platform_get_drvdata(to_platform_device(cfg->= parent)); struct pci_dev *port_pdev; struct apple_pcie_port *port; =20 - pcie =3D apple_pcie_lookup(cfg->parent); - if (WARN_ON(!pcie)) - return NULL; - /* Find the root port this device is on */ port_pdev =3D pcie_find_root_port(pdev); =20 @@ -843,13 +807,9 @@ static void apple_pcie_disable_device(struct pci_host_= bridge *bridge, struct pci static int apple_pcie_init(struct pci_config_window *cfg) { struct device *dev =3D cfg->parent; - struct apple_pcie *pcie; + struct apple_pcie *pcie =3D platform_get_drvdata(to_platform_device(dev)); int ret; =20 - pcie =3D apple_pcie_lookup(dev); - if (WARN_ON(!pcie)) - return -ENOENT; - for_each_available_child_of_node_scoped(dev->of_node, of_port) { ret =3D apple_pcie_setup_port(pcie, of_port); if (ret) { @@ -876,6 +836,7 @@ static int apple_pcie_probe(struct platform_device *pde= v) { struct device *dev =3D &pdev->dev; struct apple_pcie *pcie; + struct pci_host_bridge *bridge; int ret; =20 pcie =3D devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); @@ -897,11 +858,11 @@ static int apple_pcie_probe(struct platform_device *p= dev) if (ret) return ret; =20 - apple_pcie_register(pcie); + bridge =3D pci_host_common_init(pdev, &apple_pcie_cfg_ecam_ops); + if (IS_ERR(bridge)) + return PTR_ERR(bridge); =20 - ret =3D pci_host_common_init(pdev, &apple_pcie_cfg_ecam_ops); - if (ret) - apple_pcie_unregister(pcie); + platform_set_drvdata(pdev, pcie); =20 return ret; } --=20 2.51.1