From nobody Tue Dec 2 02:05:00 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7669832E697; Thu, 20 Nov 2025 11:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763638637; cv=none; b=RZjzlIORkCbH+fh9PkoO0Mq72AgmhhmK+EytAC6yPoav8hoa8qm/r29xAifJKQLqVrjimQ6Jpc0Ky9LE4P147R9agWM8kTz4PJi3LG30PMG+n6l9Vs19nRDrGjgqDB/ETdjfJz/92BR7wW2Bo075h3EG/hXSHjIkaCXGy1GXyjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763638637; c=relaxed/simple; bh=RrpUxwlBxKhJ94bRnqangTKZ1qMlkCMgwAyjW/+afBM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=P5ZvkRB7jYHLUb+gsA4Nsh4d0qTVhZaLVND1UN0SlkDeWhekq2ohlWMLFPv6LwJixoxGqfUnb9vkudwWPW1GGvNpGp5S/SyjN8wwD5g2Sk0lf6RMapTAVpZS1WT9gVqFaxU5grhxhT2hjBBpAacOUB7+t/5IGZd54OC03r7JY+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WZXRD80a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WZXRD80a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F19D4C4CEF1; Thu, 20 Nov 2025 11:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763638637; bh=RrpUxwlBxKhJ94bRnqangTKZ1qMlkCMgwAyjW/+afBM=; h=From:To:Cc:Subject:Date:From; b=WZXRD80aP88NiIaZ79MOFF2VCZePCpW+tdSqFzcVIWdpzUH6lTMI50kHoomCs5PG+ a0rvejtM4w3iIfB00Cakw52U7Po8fO9j8KxXn3YWBOU/8CeafQQEy6fd3iAFs4mbXZ VAkX05CMtQuUPLXUXfsmDuCw9Ga73Lim4j+ghC0q2o36N9JHXRA5WbHxEwqVp3yDpF fTyzh/SZdJEVTHCiTQNHPh4bI4RQ23KQxo05iCjla3bqJo0WGAddcQT4RoTR0cMAWW 8TylQ7rlvi2BjgpV42WPBN8blvu9G+Z4lKefiNnGFyPBMllk99dxLEvzTd+lTEcVaq t24EPhRww7G3w== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vM2yQ-00000006rX7-35N8; Thu, 20 Nov 2025 11:37:14 +0000 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Radu Rendec , Bjorn Helgaas , Manivannan Sadhasivam , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Lorenzo Pieralisi Subject: [PATCH] PCI: host-generic: Move bridge allocation outside of pci_host_common_init() Date: Thu, 20 Nov 2025 11:36:30 +0000 Message-ID: <20251120113630.2036078-1-maz@kernel.org> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, rrendec@redhat.com, bhelgaas@google.com, mani@kernel.org, robh@kernel.org, kwilczynski@kernel.org, lpieralisi@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Having the host bridge allocation inside pci_host_common_init() results in a lot of complexity in the pcie-apple driver (the only direct user of this function outside of code PCI code). It forces the allocation of driver-specific tracking structures outside of the bridge allocation, which in turns requires it to use inneficient data structures to match the bridge and the private structre as needed. Instead, let the bridge structure be passed to pci_host_common_init(), allowing the driver to allocate it together with the private data, as it is usually intended. The driver can then retrieve the bridge via the owning device attached to the PCI config window structure. This allows the pcie-apple driver to be significantly simplified. Both core and driver code are changed in one go to avoid going via a transitional interface. Link: https://lore.kernel.org/r/86jyzms036.wl-maz@kernel.org Signed-off-by: Marc Zyngier Cc: Radu Rendec Cc: Bjorn Helgaas Cc: Manivannan Sadhasivam Cc: Rob Herring Cc: Krzysztof Wilczy=C5=84ski Cc: Lorenzo Pieralisi Reviewed-by: Radu Rendec --- drivers/pci/controller/pci-host-common.c | 13 ++++---- drivers/pci/controller/pci-host-common.h | 1 + drivers/pci/controller/pcie-apple.c | 42 ++++-------------------- 3 files changed, 14 insertions(+), 42 deletions(-) diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/control= ler/pci-host-common.c index 810d1c8de24e9..c473e7c03baca 100644 --- a/drivers/pci/controller/pci-host-common.c +++ b/drivers/pci/controller/pci-host-common.c @@ -53,16 +53,12 @@ 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, + struct pci_host_bridge *bridge, const struct pci_ecam_ops *ops) { struct device *dev =3D &pdev->dev; - struct pci_host_bridge *bridge; struct pci_config_window *cfg; =20 - bridge =3D devm_pci_alloc_host_bridge(dev, 0); - if (!bridge) - return -ENOMEM; - of_pci_check_probe_only(); =20 platform_set_drvdata(pdev, bridge); @@ -85,12 +81,17 @@ EXPORT_SYMBOL_GPL(pci_host_common_init); 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 devm_pci_alloc_host_bridge(&pdev->dev, 0); + if (!bridge) + return -ENOMEM; + + return pci_host_common_init(pdev, bridge, ops); } EXPORT_SYMBOL_GPL(pci_host_common_probe); =20 diff --git a/drivers/pci/controller/pci-host-common.h b/drivers/pci/control= ler/pci-host-common.h index 51c35ec0cf37d..b5075d4bd7eb3 100644 --- a/drivers/pci/controller/pci-host-common.h +++ b/drivers/pci/controller/pci-host-common.h @@ -14,6 +14,7 @@ struct pci_ecam_ops; =20 int pci_host_common_probe(struct platform_device *pdev); int pci_host_common_init(struct platform_device *pdev, + struct pci_host_bridge *bridge, const struct pci_ecam_ops *ops); void pci_host_common_remove(struct platform_device *pdev); =20 diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/p= cie-apple.c index 0380d300adca6..a902aa81a497e 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -206,9 +206,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,32 +721,9 @@ 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; + return pci_host_bridge_priv(dev_get_drvdata(dev)); } =20 static struct apple_pcie_port *apple_pcie_get_port(struct pci_dev *pdev) @@ -875,13 +849,15 @@ static const struct pci_ecam_ops apple_pcie_cfg_ecam_= ops =3D { static int apple_pcie_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; + struct pci_host_bridge *bridge; struct apple_pcie *pcie; int ret; =20 - pcie =3D devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); - if (!pcie) + bridge =3D devm_pci_alloc_host_bridge(dev, sizeof(*pcie)); + if (!bridge) return -ENOMEM; =20 + pcie =3D pci_host_bridge_priv(bridge); pcie->dev =3D dev; pcie->hw =3D of_device_get_match_data(dev); if (!pcie->hw) @@ -897,13 +873,7 @@ static int apple_pcie_probe(struct platform_device *pd= ev) if (ret) return ret; =20 - apple_pcie_register(pcie); - - ret =3D pci_host_common_init(pdev, &apple_pcie_cfg_ecam_ops); - if (ret) - apple_pcie_unregister(pcie); - - return ret; + return pci_host_common_init(pdev, bridge, &apple_pcie_cfg_ecam_ops); } =20 static const struct of_device_id apple_pcie_of_match[] =3D { --=20 2.47.3