public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: "Frank Li" <Frank.Li@nxp.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Richard Zhu" <hongxing.zhu@nxp.com>,
	"Lucas Stach" <l.stach@pengutronix.de>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
	"Rob Herring" <robh@kernel.org>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Fabio Estevam" <festevam@gmail.com>
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
Subject: Re: [PATCH v2 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges
Date: Thu, 3 Oct 2024 11:30:58 +0100	[thread overview]
Message-ID: <a96794e0-76f6-4091-b4d4-d88d084ed2c2@arm.com> (raw)
In-Reply-To: <20240930-imx95_lut-v2-1-3b6467ba539a@nxp.com>

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 <Frank.Li@nxp.com>
> ---
> 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 */
> 



  parent reply	other threads:[~2024-10-03 10:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-30 19:42 [PATCH v2 0/2] PCI: add enabe(disable)_device() hook for bridge Frank Li
2024-09-30 19:42 ` [PATCH v2 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges Frank Li
2024-10-02 22:46   ` Bjorn Helgaas
2024-10-03 10:30   ` Robin Murphy [this message]
2024-09-30 19:42 ` [PATCH v2 2/2] PCI: imx6: Add IOMMU and ITS MSI support for i.MX95 Frank Li
2024-10-03 11:16   ` Robin Murphy
2024-10-03 21:12     ` Frank Li
2024-10-02 22:24 ` [PATCH v2 0/2] PCI: add enabe(disable)_device() hook for bridge Bjorn Helgaas
2024-10-03  5:15 ` Manivannan Sadhasivam
2024-10-03 19:18   ` Frank Li
2024-10-06 17:50     ` Manivannan Sadhasivam
2024-10-07 15:19       ` Frank Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a96794e0-76f6-4091-b4d4-d88d084ed2c2@arm.com \
    --to=robin.murphy@arm.com \
    --cc=Frank.Li@nxp.com \
    --cc=alyssa@rosenzweig.io \
    --cc=bhelgaas@google.com \
    --cc=bpf@vger.kernel.org \
    --cc=broonie@kernel.org \
    --cc=festevam@gmail.com \
    --cc=hongxing.zhu@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=kernel@pengutronix.de \
    --cc=kw@linux.com \
    --cc=l.stach@pengutronix.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=maz@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox