[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240926-imx95_lut-v1-1-d0c62087dbab@nxp.com>
Date: Thu, 26 Sep 2024 18:07:47 -0400
From: Frank Li <Frank.Li@....com>
To: Bjorn Helgaas <bhelgaas@...gle.com>, Richard Zhu <hongxing.zhu@....com>,
Lucas Stach <l.stach@...gutronix.de>,
Lorenzo Pieralisi <lpieralisi@...nel.org>,
Krzysztof WilczyĆski <kw@...ux.com>,
Manivannan Sadhasivam <manivannan.sadhasivam@...aro.org>,
Rob Herring <robh@...nel.org>, Shawn Guo <shawnguo@...nel.org>,
Sascha Hauer <s.hauer@...gutronix.de>,
Pengutronix Kernel Team <kernel@...gutronix.de>,
Fabio Estevam <festevam@...il.com>
Cc: linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, imx@...ts.linux.dev, Frank.li@....com,
alyssa@...enzweig.io, bpf@...r.kernel.org, broonie@...nel.org, jgg@...pe.ca,
joro@...tes.org, l.stach@...gutronix.de, lgirdwood@...il.com,
maz@...nel.org, p.zabel@...gutronix.de, robin.murphy@....com,
will@...nel.org, Frank Li <Frank.Li@....com>
Subject: [PATCH 1/2] PCI: Add enable_device() and disable_device()
callbacks for bridges
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@....com>
---
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
Powered by blists - more mailing lists