[PATCH v3 3/4] PCI: of: introduce of_pci_verify_node()
From: Alex Elder
Date: Mon Aug 31 2026 - 21:15:56 EST
Commit 407d1a51921e9 ("PCI: Create device tree node for bridge") linked
the PCI enumeration process together with devicetree, creating a devicetree
node for discovered PCI bridges. Its successor commit ae9813db1dc5a ("PCI:
Add quirks to generate device tree node for Xilinx Alveo U50") shows how
to use a PCI final fixup quirk to also create a devicetree node for a
non-bridge PCI device. These changes allowed devicetree overlays to
describe components downstream of a PCI device, by providing a place to
attach the overlay.
Note that the dynamic devicetree node is only created if the device didn't
already have an assigned node.
Later, commit aa7b4bbcb3a1d ("arm64: dts: qcom: qcs6490-rb3gen2: Add
TC9563 PCIe switch node") *pre-defined* devicetree nodes to represent the
PCI device nodes that would (also) be discovered via the PCI enumeration
process. The devicetree node in this case is created with the content
from the DTS file. So when a (host) bridge is done being initialized
during PCI enumeration, no node is dynamically created (the commits
mentioned above do not apply).
Ideally, any pre-defined PCI devicetree node would contain exactly the
same information as whatever the dynamic creation process would produce
(though it could include more).
However that is not the case for the pre-defined Qualcomm RB3gen2 nodes.
And in particular, the endpoint (function) nodes include this property:
device_type = "pci";
This is simply wrong; that property is meant only for bridge nodes.
Rob Herring requested that a runtime check to be added to spot this
specific error, only for non-bridge PCI devices. Herve Codina further
suggested we ensure that bridge PCI devices *do* define the device_type
property, with value "pci".
Signed-off-by: Alex Elder <elder@xxxxxxxxxxxx>
---
v3: - Switch a function header to use kernel-doc format
- Add a warning if a PCI bridge node has no device_type property
drivers/pci/bus.c | 1 +
drivers/pci/of.c | 31 +++++++++++++++++++++++++++++++
drivers/pci/pci.h | 3 +++
3 files changed, 35 insertions(+)
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 655ed53436d3e..679afbc6d3109 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -351,6 +351,7 @@ void pci_bus_add_device(struct pci_dev *dev)
* are not assigned yet for some devices.
*/
pcibios_bus_add_device(dev);
+ of_pci_verify_node(dev);
pci_fixup_device(pci_fixup_final, dev);
if (pci_is_bridge(dev))
of_pci_make_dev_node(dev);
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index a51dff91b196d..1838a3109514c 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -1085,3 +1085,34 @@ int of_pci_get_equalization_presets(struct device *dev,
return 0;
}
EXPORT_SYMBOL_GPL(of_pci_get_equalization_presets);
+
+/**
+ * of_pci_verify_node - Sanity check some PCI device node properties
+ * @pdev: The PCI device whose device node is checked
+ *
+ * PCI enumeration authoritatively discovers what we need to know about
+ * a PCI device. A devicetree-based platform will represent a PCI root
+ * bridge with a node, but otherwise devicetree doesn't typically include
+ * many PCI nodes. Where such nodes do exist, experience has shown that
+ * the "device_type" property is sometimes wrong, so warn about that.
+ */
+void of_pci_verify_node(struct pci_dev *pdev)
+{
+ struct device_node *np = pci_device_to_OF_node(pdev);
+ bool device_is_bridge;
+ bool device_type_pci;
+
+ /* Nothing to check if there's no pre-existing devicetree node */
+ if (!np)
+ return;
+
+ device_is_bridge = pci_is_bridge(pdev);
+ device_type_pci = of_node_is_type(np, "pci");
+
+ /* Bridges should have device type "pci"; endpoints should not */
+ if (device_is_bridge == device_type_pci)
+ return;
+
+ dev_err(&pdev->dev, "PCI %s have \"pci\" device_type property\n",
+ device_is_bridge ? "bridge should" : "endpoint should not");
+}
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index ba3c3fddddc23..2e33d3bd4b0ba 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -1253,6 +1253,7 @@ bool of_pci_supply_present(struct device_node *np);
int of_pci_get_equalization_presets(struct device *dev,
struct pci_eq_presets *presets,
int num_lanes);
+void of_pci_verify_node(struct pci_dev *pdev);
#else
static inline int
of_get_pci_domain_nr(struct device_node *node)
@@ -1308,6 +1309,8 @@ static inline int of_pci_get_equalization_presets(struct device *dev,
return 0;
}
+
+static inline void of_pci_verify_node(struct pci_dev *pdev) { }
#endif /* CONFIG_OF */
struct of_changeset;
--
2.53.0