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 40DAECF8577 for ; Thu, 3 Oct 2024 10:32:44 +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-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kBU1jetFiG9wgfZtVMVMVy7Tdz2EWHJYkVB4tB9NJEg=; b=sX2UUoEh7bemCimNkw5EKxWEzm AxfyyvMd4A36TOH+1PvkoEmroC/GbfalCQXnV19AbQDLP+YCvSs8kbtuZt0zX8CPQ7lM/X3YB1qst QNCddAPGxWTuJL9fC9mpwq31Uk953pJVBad7o+mbCmvba5Gww0dLMU+FE7ywBQUFrqex6k8dsoPZ6 lLKh268tmcS+0jofuXOapHuppl0bocfzwrJfYwSiQ7et4eO8efJvapjNyZgOr9Lu03zXtGbZV2ylC t1Y+AEhED0dCCn59TUW+SB0jk3CRf5wpmQEUSiXkTvY9sC2HQKQh5/2d6Yt07+D45IN/kkMReEjif QRh3cNOg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1swJ8M-00000008n81-0fQV; Thu, 03 Oct 2024 10:32:34 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1swJ71-00000008mmt-3TnU for linux-arm-kernel@lists.infradead.org; Thu, 03 Oct 2024 10:31:13 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A5006339; Thu, 3 Oct 2024 03:31:38 -0700 (PDT) Received: from [10.57.85.26] (unknown [10.57.85.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7C2393F64C; Thu, 3 Oct 2024 03:31:03 -0700 (PDT) Message-ID: Date: Thu, 3 Oct 2024 11:30:58 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges To: Frank Li , Bjorn Helgaas , Richard Zhu , Lucas Stach , Lorenzo Pieralisi , =?UTF-8?Q?Krzysztof_Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: 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, will@kernel.org References: <20240930-imx95_lut-v2-0-3b6467ba539a@nxp.com> <20240930-imx95_lut-v2-1-3b6467ba539a@nxp.com> From: Robin Murphy Content-Language: en-GB In-Reply-To: <20240930-imx95_lut-v2-1-3b6467ba539a@nxp.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241003_033111_988507_62FFB192 X-CRM114-Status: GOOD ( 21.46 ) 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 2024-09-30 8:42 pm, 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. > > 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 > --- > Change from v1 to v2 > - move enable(disable)device ops to pci_host_bridge > --- > drivers/pci/pci.c | 14 ++++++++++++++ > include/linux/pci.h | 2 ++ > 2 files changed, 16 insertions(+) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 7d85c04fbba2a..fcdeb12622568 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,6 +2069,13 @@ 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 the intent is that this call may allocate host bridge resources, what about the existing error returns below? Should those now have a cleanup path to avoid a potential resource leak from here? Thanks, Robin. > + if (err) > + return err; > + } > + > err = pcibios_enable_device(dev, bars); > if (err < 0) > return err; > @@ -2262,12 +2270,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 */ >