Re: [PATCH V11 2/5] PCI: Create device tree node for bridge

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 7/25/23 16:04, Rob Herring wrote:
On Tue, Jul 25, 2023 at 4:15 PM Lizhi Hou <lizhi.hou@xxxxxxx> wrote:
The PCI endpoint device such as Xilinx Alveo PCI card maps the register
spaces from multiple hardware peripherals to its PCI BAR. Normally,
the PCI core discovers devices and BARs using the PCI enumeration process.
There is no infrastructure to discover the hardware peripherals that are
present in a PCI device, and which can be accessed through the PCI BARs.

Apparently, the device tree framework requires a device tree node for the
PCI device. Thus, it can generate the device tree nodes for hardware
peripherals underneath. Because PCI is self discoverable bus, there might
not be a device tree node created for PCI devices. Furthermore, if the PCI
device is hot pluggable, when it is plugged in, the device tree nodes for
its parent bridges are required. Add support to generate device tree node
for PCI bridges.

Add an of_pci_make_dev_node() interface that can be used to create device
tree node for PCI devices.

Add a PCI_DYNAMIC_OF_NODES config option. When the option is turned on,
the kernel will generate device tree nodes for PCI bridges unconditionally.

Initially, add the basic properties for the dynamically generated device
tree nodes which include #address-cells, #size-cells, device_type,
compatible, ranges, reg.

Acked-by: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
Signed-off-by: Lizhi Hou <lizhi.hou@xxxxxxx>
---
  drivers/pci/Kconfig       |  12 ++
  drivers/pci/Makefile      |   1 +
  drivers/pci/bus.c         |   2 +
  drivers/pci/of.c          |  96 +++++++++++++++-
  drivers/pci/of_property.c | 232 ++++++++++++++++++++++++++++++++++++++
  drivers/pci/pci.h         |  12 ++
  drivers/pci/remove.c      |   1 +
  7 files changed, 354 insertions(+), 2 deletions(-)
  create mode 100644 drivers/pci/of_property.c

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 3c07d8d214b3..49bd09c7dd0a 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -194,6 +194,18 @@ config PCI_HYPERV
           The PCI device frontend driver allows the kernel to import arbitrary
           PCI devices from a PCI backend to support PCI driver domains.

+config PCI_DYNAMIC_OF_NODES
+       bool "Create device tree nodes for PCI devices"
+       depends on OF
+       select OF_DYNAMIC
+       help
+         This option enables support for generating device tree nodes for some
+         PCI devices. Thus, the driver of this kind can load and overlay
+         flattened device tree for its downstream devices.
+
+         Once this option is selected, the device tree nodes will be generated
+         for all PCI bridges.
+
  choice
         prompt "PCI Express hierarchy optimization setting"
         default PCIE_BUS_DEFAULT
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 2680e4c92f0a..cc8b4e01e29d 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -32,6 +32,7 @@ obj-$(CONFIG_PCI_P2PDMA)      += p2pdma.o
  obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o
  obj-$(CONFIG_VGA_ARB)          += vgaarb.o
  obj-$(CONFIG_PCI_DOE)          += doe.o
+obj-$(CONFIG_PCI_DYNAMIC_OF_NODES) += of_property.o

  # Endpoint library must be initialized before its users
  obj-$(CONFIG_PCI_ENDPOINT)     += endpoint/
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 5bc81cc0a2de..ab7d06cd0099 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -340,6 +340,8 @@ void pci_bus_add_device(struct pci_dev *dev)
          */
         pcibios_bus_add_device(dev);
         pci_fixup_device(pci_fixup_final, dev);
+       if (pci_is_bridge(dev))
+               of_pci_make_dev_node(dev);
         pci_create_sysfs_dev_files(dev);
         pci_proc_attach_device(dev);
         pci_bridge_d3_update(dev);
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index e51219f9f523..11d3be165e32 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -495,8 +495,21 @@ static int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *
                  * to rely on this function (you ship a firmware that doesn't
                  * create device nodes for all PCI devices).
                  */
-               if (ppnode)
-                       break;
+               if (ppnode) {
+                       /*
+                        * When PCI_DYNAMIC_OF_NODES is on, a device tree
+                        * node will be generated for PCI bridge. For the
+                        * dynamically generated node, interrupt mapping is
+                        * not supported. Thus, it needs to check interrupt-map
+                        * property and set ppnode to NULL to do standard
+                        * swizzling if interrupt-map does not present.
+                        */
+                       if (IS_ENABLED(CONFIG_PCI_DYNAMIC_OF_NODES) &&
+                           !of_property_present(ppnode, "interrupt-map"))
+                               ppnode = NULL;
We cannot use a kconfig option to determine behavior. You don't get to
decide the value of the kconfig option. The OS distro does. As I've
said in the past, the kconfig option is not a long term solution. You
need things to work the same way whether PCI nodes were populated
before the kernel runs or dynamically.

Perhaps what you need to do is read PCI_INTERRUPT_PIN and if it's
non-zero for a device, populate 'interrupts' property using the value.
Then the standard DT interrupt parsing code should work. That code
will walk up nodes until it finds the host bridge interrupt-map.

of_irq_parse_pci() already has the code to read PCI_INTERRUPT_PIN for the device which does not have device tree node.

Because the device tree node is generated, the standard swizzling is skipped. Thus the code walking up to host bridge interrupt-map does not work. What is missing here is actually 'interrupt-map' for bridge nodes. It sounds to me we need to generate 'interrupt-map' for every bridge node (similar to powerpc)?


Lizhi


Rob



[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux