From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34884E677FC for ; Sat, 2 Nov 2024 12:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BWY+lS6jDhtKzKAleckngjLpLeBfYwo+SP3KVQ7G+K0=; b=tAMN3HHMg4WW8IhVrv82tkTW/w rL7uFc9t2pye6sEO1NaGQnQyiyw6lIF+msrfU23ZNc7ZjMuZa3o0zp/vGlxTlg8djNd7e3lJ3UzBe JIysJcxwhr238I7FRVZUt0EqbmM3jBtBzqpD0vPcWOC/On0r5kA9ftAmYIXPGRy+hEBlCXHbpWGi7 O3z17H+FYFuPzigsUmDEgsom3Ur0W5CYmGqt1h0zx/Aj7Wi1uirakxdkgF+RJ6OyyuJeZn2bTxrwe SUtSq0zs/hQ7g+c0aUy7CY43hl46E3xPHYeQlocmU9BGEd2dZV1h88kwfSiy+v23ztiUiT6Msecp3 B0cyH5Tw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t7DD4-00000009h99-1ETb; Sat, 02 Nov 2024 12:26:30 +0000 Received: from nyc.source.kernel.org ([147.75.193.91]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t7DBO-00000009h1K-3xLa for linux-arm-kernel@lists.infradead.org; Sat, 02 Nov 2024 12:24:48 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 48E81A4011F; Sat, 2 Nov 2024 12:22:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E5BEC4CEC3; Sat, 2 Nov 2024 12:24:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730550285; bh=lFxlMfCCfbEYFC0V+aROouND/5okVB9WvHg6q+rZHF4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=mGTDfj4iNlTIaOrnos5WbcOSLa3/dQ/q+NRiQggyBjNwVaN67twdnQJ1pN4v9Oj8K HffClJSbfyDHxPTN2G4bW4ANurMzhYTf7C9IReQtZ+Qs8iLyuslNEd8LJTjSBL6iGP +ZhHHK/2XqnYPziPNvEzbMPKlab6NIJhBQrWHMbgbNdrW/G9Wz9c++A71cdt8axis2 YsX9T0LaLXHWgs6zBoyqk5GaUKxyTwaV1+5zqVgjpR63hS2JJ/lAPJszueGGkcudyh OCRdaiC7jaGk5uPg1CAOD1HmGBxYSymmEftDbD8s3m/dvNL001fJtKITlfem9V0Fnv qGfEKmUU2y0gg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1t7DBK-0096Wz-Su; Sat, 02 Nov 2024 12:24:42 +0000 Date: Sat, 02 Nov 2024 12:24:42 +0000 Message-ID: <86ikt52585.wl-maz@kernel.org> From: Marc Zyngier To: Manivannan Sadhasivam Cc: Frank Li , Bjorn Helgaas , Richard Zhu , Lucas Stach , Lorenzo Pieralisi , Krzysztof =?UTF-8?B?V2lsY3p5?= =?UTF-8?B?xYRza2k=?= , Rob Herring , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, alyssa@rosenzweig.io, bpf@vger.kernel.org, broonie@kernel.org, jgg@ziepe.ca, joro@8bytes.org, lgirdwood@gmail.com, p.zabel@pengutronix.de, robin.murphy@arm.com, will@kernel.org Subject: Re: [PATCH v3 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges In-Reply-To: <20241102115435.s7oycrh2pjkfhpsu@thinkpad> References: <20241024-imx95_lut-v3-0-7509c9bbab86@nxp.com> <20241024-imx95_lut-v3-1-7509c9bbab86@nxp.com> <20241102111012.23zwz4et2qkafyca@thinkpad> <86jzdl27my.wl-maz@kernel.org> <20241102115435.s7oycrh2pjkfhpsu@thinkpad> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: manivannan.sadhasivam@linaro.org, Frank.Li@nxp.com, bhelgaas@google.com, hongxing.zhu@nxp.com, l.stach@pengutronix.de, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, alyssa@rosenzweig.io, bpf@vger.kernel.org, broonie@kernel.org, jgg@ziepe.ca, joro@8bytes.org, lgirdwood@gmail.com, p.zabel@pengutronix.de, robin.murphy@arm.com, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241102_052447_142889_295A65C4 X-CRM114-Status: GOOD ( 44.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sat, 02 Nov 2024 11:54:35 +0000, Manivannan Sadhasivam wrote: > > On Sat, Nov 02, 2024 at 11:32:37AM +0000, Marc Zyngier wrote: > > On Sat, 02 Nov 2024 11:10:12 +0000, > > Manivannan Sadhasivam wrote: > > > > > > On Thu, Oct 24, 2024 at 06:34:44PM -0400, Frank Li wrote: > > > > Some PCIe host bridges require special handling when enabling or disabling > > > > PCIe Endpoints. For example, the i.MX95 platform has a lookup table to map > > > > Requester IDs to StreamIDs, which are used by the SMMU and MSI controller > > > > to identify the source of DMA accesses. > > > > > > > > Without this mapping, DMA accesses may target unintended memory, which > > > > would corrupt memory or read the wrong data. > > > > > > > > Add a host bridge .enable_device() hook the imx6 driver can use to > > > > configure the Requester ID to StreamID mapping. The hardware table isn't > > > > big enough to map all possible Requester IDs, so this hook may fail if no > > > > table space is available. In that case, return failure from > > > > pci_enable_device(). > > > > > > > > It might make more sense to make pci_set_master() decline to enable bus > > > > mastering and return failure, but it currently doesn't have a way to return > > > > failure. > > > > > > > > Signed-off-by: Frank Li > > > > --- > > > > Change from v2 to v3 > > > > - use Bjorn suggest's commit message. > > > > - call disable_device() when error happen. > > > > > > > > Change from v1 to v2 > > > > - move enable(disable)device ops to pci_host_bridge > > > > --- > > > > drivers/pci/pci.c | 23 ++++++++++++++++++++++- > > > > include/linux/pci.h | 2 ++ > > > > 2 files changed, 24 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > > > index 7d85c04fbba2a..5e0cb9b6f4d4f 100644 > > > > --- a/drivers/pci/pci.c > > > > +++ b/drivers/pci/pci.c > > > > @@ -2056,6 +2056,7 @@ int __weak pcibios_enable_device(struct pci_dev *dev, int bars) > > > > static int do_pci_enable_device(struct pci_dev *dev, int bars) > > > > { > > > > int err; > > > > + struct pci_host_bridge *host_bridge; > > > > struct pci_dev *bridge; > > > > u16 cmd; > > > > u8 pin; > > > > @@ -2068,9 +2069,16 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) > > > > if (bridge) > > > > pcie_aspm_powersave_config_link(bridge); > > > > > > > > + host_bridge = pci_find_host_bridge(dev->bus); > > > > + if (host_bridge && host_bridge->enable_device) { > > > > + err = host_bridge->enable_device(host_bridge, dev); > > > > + if (err) > > > > + return err; > > > > + } > > > > > > How about wrapping the enable/disable part in a helper? > > > > > > int pci_host_bridge_enable_device(dev); > > > void pci_host_bridge_disable_device(dev); > > > > > > The definition could be placed in drivers/pci/pci.h as an inline > > > function. > > > > What does it bring? I would see the point if there was another user. > > But this is very much core infrastructure which doesn't lend itself to > > duplication. > > > > Unless you have something in mind? > > > > IMO, it adds a nice encapsulation to help readers understand what this piece of > code is all about and also keeps the callers short. Plus the disable helper is > reused in both error and pci_disable_device() (if that matters). Having an *internal* helper for disable definitely has its use. But moving these helpers outside of pci.c opens the door to all sort of abuse by making it look like an internal API drivers can use, which is absolutely isn't. M. -- Without deviation from the norm, progress is not possible.