From mboxrd@z Thu Jan 1 00:00:00 1970 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 C881F192B99; Thu, 5 Dec 2024 10:30:45 +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=1733394645; cv=none; b=syH+g/WWcXC6AojHoHqIw/uaPVImKWxJ5LcfpvocF81syYoHyikar+k22w/oZCe1pPWbug8IU9CExmbAaVWojw2Slhl3Xck3DZaG+Unte7NhtIo63MzQGEq1cjf165BHD8vXEkY+JYfFw/JTkTZDaiaj2bIFTCKuYAulG0BNXEU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733394645; c=relaxed/simple; bh=FI6UYkSCZ6hPHYb64d6jRjQ640jUV6Orgx4R74ZtjbY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Pfds2HuUOY0Zjm6gknBJmlMrgi3byAmLE9IjnqiDxW5CDTNypvRABWXnmuLHS1GnQyn0OPUTIfnWkHQTz1nA97ZlT+uwArcRu3N4IXncfWdGN7g44sCq4QmBAVYlvl7Sbk+C3HZZtgLeAuWT5nDaqh5S+W0GV+t4ucr1tF/HKIc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aptJ9V03; 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="aptJ9V03" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9E31C4CED1; Thu, 5 Dec 2024 10:30:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733394645; bh=FI6UYkSCZ6hPHYb64d6jRjQ640jUV6Orgx4R74ZtjbY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aptJ9V03xMpXPdUljnOGsQXYqupX9KE4kvdJLvyemKaq4FEqzigvxUVLNUIeglBdq giaBOxhzO2kHp+LbklEWs51yxVa/yuClwvVS+ADH/E6AMHmttvxkVzzDAQjvsJsGRK /Yk+PFB5cVWozXkd1/7wR6oRBM/7pgS4yXu4fbpSxwvVD+2yyM66YAboJNlbg1NRVw Z+KaeSdY4qPo1wqD4trDR8bIlHbKoOYHcsYE/Wbfv2xsJlVawK9xuhK+aUK8pIUFl8 7obzUum+TeqhAz6QI2XEvMbRybDC89kQ8jbwkN2faaq8o+WVuOl5qkuPIG1Me991wl Bsx4nbTw0C46Q== Date: Thu, 5 Dec 2024 11:30:36 +0100 From: Lorenzo Pieralisi To: Frank Li Cc: Bjorn Helgaas , Richard Zhu , Lucas Stach , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Manivannan Sadhasivam , 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, maz@kernel.org, p.zabel@pengutronix.de, robin.murphy@arm.com, will@kernel.org Subject: Re: [PATCH v7 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges Message-ID: References: <20241203-imx95_lut-v7-0-d0cd6293225e@nxp.com> <20241203-imx95_lut-v7-1-d0cd6293225e@nxp.com> Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241203-imx95_lut-v7-1-d0cd6293225e@nxp.com> On Tue, Dec 03, 2024 at 06:27:15PM -0500, 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. > > Reviewed-by: Marc Zyngier > Tested-by: Marc Zyngier > Acked-by: Manivannan Sadhasivam > Signed-off-by: Frank Li > --- > Change from v5 to v6 > - Add Marc testedby and Reviewed-by tag > - Add Mani's acked tag > > Change from v4 to v5 > - Add two static help functions > int pci_host_bridge_enable_device(dev); > void pci_host_bridge_disable_device(dev); > - remove tags because big change > Acked-by: Bjorn Helgaas I can pick it up when Bjorn acks it. > Reviewed-by: Marc Zyngier > Tested-by: Marc Zyngier > > Change from v3 to v4 > - Add Bjorn's ack tag > > 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 | 36 +++++++++++++++++++++++++++++++++++- > include/linux/pci.h | 2 ++ > 2 files changed, 37 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 0b29ec6e8e5e2..773ca3cbd3221 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -2059,6 +2059,28 @@ int __weak pcibios_enable_device(struct pci_dev *dev, int bars) > return pci_enable_resources(dev, bars); > } > > +static int pci_host_bridge_enable_device(struct pci_dev *dev) > +{ > + struct pci_host_bridge *host_bridge = pci_find_host_bridge(dev->bus); > + int err; > + > + if (host_bridge && host_bridge->enable_device) { > + err = host_bridge->enable_device(host_bridge, dev); > + if (err) > + return err; > + } > + > + return 0; > +} > + > +static void pci_host_bridge_disable_device(struct pci_dev *dev) > +{ > + struct pci_host_bridge *host_bridge = pci_find_host_bridge(dev->bus); > + > + if (host_bridge && host_bridge->disable_device) > + host_bridge->disable_device(host_bridge, dev); > +} > + > static int do_pci_enable_device(struct pci_dev *dev, int bars) > { > int err; > @@ -2074,9 +2096,13 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) > if (bridge) > pcie_aspm_powersave_config_link(bridge); > > + err = pci_host_bridge_enable_device(dev); > + if (err) > + return err; > + > err = pcibios_enable_device(dev, bars); Next in line is removing pcibios_enable_device() arch callbacks and move that code into bridge callbacks to do the same, we can do it later. Lorenzo > if (err < 0) > - return err; > + goto err_enable; > pci_fixup_device(pci_fixup_enable, dev); > > if (dev->msi_enabled || dev->msix_enabled) > @@ -2091,6 +2117,12 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) > } > > return 0; > + > +err_enable: > + pci_host_bridge_disable_device(dev); > + > + return err; > + > } > > /** > @@ -2274,6 +2306,8 @@ void pci_disable_device(struct pci_dev *dev) > if (atomic_dec_return(&dev->enable_cnt) != 0) > return; > > + pci_host_bridge_disable_device(dev); > + > do_pci_disable_device(dev); > > dev->is_busmaster = 0; > diff --git a/include/linux/pci.h b/include/linux/pci.h > index db9b47ce3eefd..bcbef004dd561 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -595,6 +595,8 @@ struct pci_host_bridge { > u8 (*swizzle_irq)(struct pci_dev *, u8 *); /* Platform IRQ swizzler */ > int (*map_irq)(const struct pci_dev *, u8, u8); > void (*release_fn)(struct pci_host_bridge *); > + int (*enable_device)(struct pci_host_bridge *bridge, struct pci_dev *dev); > + void (*disable_device)(struct pci_host_bridge *bridge, struct pci_dev *dev); > void *release_data; > unsigned int ignore_reset_delay:1; /* For entire hierarchy */ > unsigned int no_ext_tags:1; /* No Extended Tags */ > > -- > 2.34.1 >