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 51001D6B6DA for ; Wed, 30 Oct 2024 21:02: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:In-Reply-To:Content-Type: MIME-Version:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Owner; bh=zANkc38Ko2VLsqL6AeQn5y6AjfvfXRieZXZrZonhzRE=; b=dLOhdDaa5M9wAw RyP014TEOdQNJy6j8/VRSE8PEfG6V25YPFO/LxDsGOPnwjayt29dYz9GR9gZwlRmCytmzwZegfo1E SmeSTRHEzu6w3AeJChtjTRdAl3Cs6u9wTqzMpKSnP5FUu3+Sjc2emxRAIp5niJcFDQayQe6vV7ecg 3c6czxh4ed332RmpVSb+K0NXnVdjdp7Z7qfrCiC/mcYx17Ep/hc3Zg0U9xA05HnvAsee9GEf/N0Gn uZnLZycl5wXNzXnCDVSBLd37F8r3w7TnFpkkWB23c4lHs51jKSgc8wCXrINJV6T6D5TpBB7ga7HQI KHNZUBE0XvZfkbRW52TA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t6Fpt-00000001m04-1qoO; Wed, 30 Oct 2024 21:02:37 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t6Fo6-00000001lXK-1KwW for linux-arm-kernel@lists.infradead.org; Wed, 30 Oct 2024 21:00:47 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9F3025C5819; Wed, 30 Oct 2024 21:00:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F75BC4CECE; Wed, 30 Oct 2024 21:00:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730322045; bh=FHc9+KsxE68/8fdivXFFQsEHjN13LEf/vY7D0utn2FA=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=qFfJy+OMGQrOb+k6n1c1u5MbGgkiFxUSjKubuKO6WLqUbu2qO7nLbKTyGoAL/i7Qt mwUhPYhfw292eCbD1ittEJQpHQiV/zAQplZ442uK0Lyk9y7t2zrytbRz8Gycvezm5B 70X0FkVCsGYSF+wF4S1bkpqi2Ta81VNWDcz5DAxFhkHMforHIoKPFhsu3zejZNACgO OQUdcVvBTyEZnMt4nbclw/nUH+iZ8eD4FAJrvh7xaGhjy4SGjPV7OyrEVTivyy7CuA SYncyaOl28ufAKn78+j2q/cAitYQk3BbgswI+OcOKJdC5xKwHPKwj90J/YAhUg0Tvy TqE372wKyueFg== Date: Wed, 30 Oct 2024 16:00:43 -0500 From: Bjorn Helgaas To: Frank Li Cc: Bjorn Helgaas , Richard Zhu , Lucas Stach , Lorenzo Pieralisi , 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 v3 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges Message-ID: <20241030210043.GA1219525@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241024-imx95_lut-v3-1-7509c9bbab86@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241030_140046_470646_A36E9575 X-CRM114-Status: GOOD ( 29.42 ) 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 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 Acked-by: Bjorn Helgaas Merge along with the imx6 change. > --- > 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; > + } > + > err = pcibios_enable_device(dev, bars); > if (err < 0) > - return err; > + goto err_enable; > pci_fixup_device(pci_fixup_enable, dev); > > if (dev->msi_enabled || dev->msix_enabled) > @@ -2085,6 +2093,13 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) > } > > return 0; > + > +err_enable: > + if (host_bridge && host_bridge->disable_device) > + host_bridge->disable_device(host_bridge, dev); > + > + return err; > + > } > > /** > @@ -2262,12 +2277,18 @@ void pci_disable_enabled_device(struct pci_dev *dev) > */ > void pci_disable_device(struct pci_dev *dev) > { > + struct pci_host_bridge *host_bridge; > + > dev_WARN_ONCE(&dev->dev, atomic_read(&dev->enable_cnt) <= 0, > "disabling already-disabled device"); > > if (atomic_dec_return(&dev->enable_cnt) != 0) > return; > > + host_bridge = pci_find_host_bridge(dev->bus); > + if (host_bridge && host_bridge->disable_device) > + host_bridge->disable_device(host_bridge, dev); > + > do_pci_disable_device(dev); > > dev->is_busmaster = 0; > diff --git a/include/linux/pci.h b/include/linux/pci.h > index 573b4c4c2be61..ac15b02e14ddd 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -578,6 +578,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 >