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 E9F55CF6491 for ; Sat, 28 Sep 2024 00:09:22 +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=NsRc2cupkL43JJV8gvrRjo+2BANcFbLuhBrsms6txyM=; b=3pSCN0h07uXSIX LMtwUzYsCKeq4w5NI8lzmXsieTKlYlqoZ5tHR/IZgE0xy68zVYJ6VqVGs+M1e5n9bWK4es9JEN75M tTJ3LZwHlIaGKrIyF0jCz2FYW8j44KijsQr7on34Opj2ExfS5145Exnt0FIQqKYcLodsDkllc5WJP QaVJJMRPsxLFgXa2a66LeOkN3LvjjmiLaEALzKzdU/FWKUf/MhNzp6HBpf1p/enYDZnbal7Vljm/k cLs2pY2s+g9Jz6Y94b8AYPMBQxqhRiB50AQLEtjJqH7xcsPL1dkhgXSsCORj8IX47DFXtmglnsHTS YFGICneo+XTy0XApzT7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1suL1I-0000000CMnd-2H2E; Sat, 28 Sep 2024 00:09:08 +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 1suL06-0000000CMd7-39Bj for linux-arm-kernel@lists.infradead.org; Sat, 28 Sep 2024 00:07:56 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 22C8C5C47D9; Sat, 28 Sep 2024 00:07:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86AC5C4CEC4; Sat, 28 Sep 2024 00:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727482073; bh=8kgpRAnyuvL767vg5X6HGRKePibuTGJqlt0etUFXi18=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=eCIJibGNojkstz62stalir/kMXNicMt/VFQmt//hAZ9q/WEyHQApOEtUiL305EaMQ YjRqk7dhAecURr5JLz1UHFdXMFLv9q6cV5Kglo5OTTgP2/v9ECzq2q5RQVuihHVPMC pfn+zjNLsGU2uHbKfC6xHCmOSCGd+rd8rN8yCxNNnFTbtteD4GrbouZwrP2aoPlNJG h59y7fBIcIP8jQa0TxjxMiAZUyCnZ7UP9J4Y2u2Dn7uhtcydTVT44v0i/lHeem+a+S Nq0gEbhLCIcqrrvddYKQ6UVlxaRE5sLxh4p2XBaSC2/XH286Zg2mnkV04IjFQvai2q HIegvrWIDXvOw== Date: Fri, 27 Sep 2024 19:07:52 -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 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges Message-ID: <20240928000752.GA99095@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240926-imx95_lut-v1-1-d0c62087dbab@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240927_170755_065246_60505976 X-CRM114-Status: GOOD ( 21.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, Sep 26, 2024 at 06:07:47PM -0400, Frank Li wrote: > Some PCIe bridges require special handling when enabling or disabling > PCIe devices. For example, on the i.MX95 platform, a lookup table must be > configured to inform the hardware how to convert pci_device_id to stream > (bus master) ID, which is used by the IOMMU and MSI controller to identify > bus master device. I don't think you're talking about PCI-to-PCI bridges (including PCIe Root Ports and Switch Ports). Those are all standardized and don't do anything with Requester IDs or Stream IDs. A PCI host bridge, e.g., a PCIe Root Complex, might have to deal with Stream IDs, and I think that's what you're enabling here. If so, I think the hooks should be in struct pci_host_bridge instead of pci_ops. > Enablement will be failure when there is not enough lookup table resource. > Avoid DMA write to wrong position. That is the reason why pci_fixup_enable > can't work since not return value for fixup function. > > Signed-off-by: Frank Li > --- > drivers/pci/pci.c | 19 +++++++++++++++++++ > include/linux/pci.h | 2 ++ > 2 files changed, 21 insertions(+) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 7d85c04fbba2a..e0f83ed53d964 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -2057,6 +2057,7 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) > { > int err; > struct pci_dev *bridge; > + struct pci_bus *bus; > u16 cmd; > u8 pin; > > @@ -2068,6 +2069,15 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) > if (bridge) > pcie_aspm_powersave_config_link(bridge); > > + bus = dev->bus; > + while (bus) { > + if (bus->ops->enable_device) > + err = bus->ops->enable_device(bus, dev); > + if (err) > + return err; > + bus = bus->parent; > + } > + > err = pcibios_enable_device(dev, bars); > if (err < 0) > return err; > @@ -2262,12 +2272,21 @@ void pci_disable_enabled_device(struct pci_dev *dev) > */ > void pci_disable_device(struct pci_dev *dev) > { > + struct pci_bus *bus; > + > dev_WARN_ONCE(&dev->dev, atomic_read(&dev->enable_cnt) <= 0, > "disabling already-disabled device"); > > if (atomic_dec_return(&dev->enable_cnt) != 0) > return; > > + bus = dev->bus; > + while (bus) { > + if (bus->ops->disable_device) > + bus->ops->disable_device(bus, dev); > + bus = bus->parent; > + } > + > do_pci_disable_device(dev); > > dev->is_busmaster = 0; > diff --git a/include/linux/pci.h b/include/linux/pci.h > index 573b4c4c2be61..42c25b8efd538 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -803,6 +803,8 @@ static inline int pcibios_err_to_errno(int err) > struct pci_ops { > int (*add_bus)(struct pci_bus *bus); > void (*remove_bus)(struct pci_bus *bus); > + int (*enable_device)(struct pci_bus *bus, struct pci_dev *dev); > + void (*disable_device)(struct pci_bus *bus, struct pci_dev *dev); > void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where); > int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val); > int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val); > > -- > 2.34.1 >