summaryrefslogtreecommitdiff
path: root/drivers/pci
diff options
context:
space:
mode:
authorCharan Teja Kalla <charan.kalla@oss.qualcomm.com>2026-06-03 12:43:13 +0530
committerRob Herring (Arm) <robh@kernel.org>2026-06-12 10:25:39 -0500
commitf71f07bee9b56b94f7828cf3082ea19ec590de36 (patch)
tree0fd9749888bfa250e92eb91eaef45b678cafe415 /drivers/pci
parentd4b52f83f198310c871aa71816a26152eb3898c2 (diff)
of: Factor arguments passed to of_map_id() into a struct
Change of_map_id() to take a pointer to struct of_phandle_args instead of passing target device node and translated IDs separately. Update all callers accordingly. Add an explicit filter_np parameter to of_map_id() and of_map_msi_id() to separate the filter input from the output. Previously, the target parameter served dual purpose: as an input filter (if non-NULL, only match entries targeting that node) and as an output (receiving the matched node with a reference held). Now filter_np is the explicit input filter and arg->np is the pure output. Previously, of_map_id() would call of_node_put() on the matched node when a filter was provided, making reference ownership inconsistent. Remove this internal of_node_put() call so that of_map_id() now always transfers ownership of the matched node reference to the caller via arg->np. Callers are now consistently responsible for releasing this reference with of_node_put(arg->np) when done. Acked-by: Frank Li <Frank.Li@nxp.com> Suggested-by: Rob Herring (Arm) <robh@kernel.org> Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Signed-off-by: Charan Teja Kalla <charan.kalla@oss.qualcomm.com> Signed-off-by: Vijayanand Jitta <vijayanand.jitta@oss.qualcomm.com> Link: https://patch.msgid.link/20260603-parse_iommu_cells-v16-2-dc509dacb19a@oss.qualcomm.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/controller/dwc/pci-imx6.c53
-rw-r--r--drivers/pci/controller/pcie-apple.c5
2 files changed, 31 insertions, 27 deletions
diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index da7bfda5e95d..f972c760deee 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -1126,41 +1126,42 @@ static void imx_pcie_remove_lut(struct imx_pcie *imx_pcie, u16 rid)
static int imx_pcie_add_lut_by_rid(struct imx_pcie *imx_pcie, u32 rid)
{
+ struct of_phandle_args iommu_spec = {};
+ struct of_phandle_args msi_spec = {};
struct device *dev = imx_pcie->pci->dev;
- struct device_node *target;
+ struct device_node *msi_filter = NULL;
u32 sid_i, sid_m;
int err_i, err_m;
u32 sid = 0;
- target = NULL;
- err_i = of_map_iommu_id(dev->of_node, rid, &target, &sid_i);
- if (target) {
- of_node_put(target);
- } else {
- /*
- * "target == NULL && err_i == 0" means RID out of map range.
- * Use 1:1 map RID to streamID. Hardware can't support this
- * because the streamID is only 6 bits
- */
- err_i = -EINVAL;
+ err_i = of_map_iommu_id(dev->of_node, rid, &iommu_spec);
+ if (!err_i) {
+ if (!iommu_spec.np)
+ /*
+ * "iommu_spec.np == NULL && err_i == 0" means RID out of map
+ * range. Use 1:1 map RID to streamID. Hardware can't support
+ * this because the streamID is only 6 bits.
+ */
+ err_i = -EINVAL;
+ else
+ sid_i = iommu_spec.args[0];
}
+ of_node_put(iommu_spec.np);
- target = NULL;
- err_m = of_map_msi_id(dev->of_node, rid, &target, &sid_m);
-
+ err_m = of_map_msi_id(dev->of_node, rid, &msi_filter, &msi_spec);
/*
- * err_m target
- * 0 NULL RID out of range. Use 1:1 map RID to
- * streamID, Current hardware can't
- * support it, so return -EINVAL.
- * != 0 NULL msi-map does not exist, use built-in MSI
- * 0 != NULL Get correct streamID from RID
- * != 0 != NULL Invalid combination
+ * err_m msi_spec.np
+ * 0 != NULL Got correct streamID from RID via msi-map
+ * 0 NULL msi-map present but RID out of range
+ * -ENODEV NULL msi-map absent, use built-in MSI controller
*/
- if (!err_m && !target)
- return -EINVAL;
- else if (target)
- of_node_put(target); /* Find streamID map entry for RID in msi-map */
+ if (!err_m) {
+ if (!msi_spec.np)
+ /* msi-map present but RID out of range */
+ return -EINVAL;
+ sid_m = msi_spec.args[0];
+ }
+ of_node_put(msi_spec.np);
/*
* msi-map iommu-map
diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
index a0937b7b3c4d..c2cffc0659f4 100644
--- a/drivers/pci/controller/pcie-apple.c
+++ b/drivers/pci/controller/pcie-apple.c
@@ -755,6 +755,7 @@ static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_d
{
u32 sid, rid = pci_dev_id(pdev);
struct apple_pcie_port *port;
+ struct of_phandle_args iommu_spec = {};
int idx, err;
port = apple_pcie_get_port(pdev);
@@ -764,10 +765,12 @@ static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_d
dev_dbg(&pdev->dev, "added to bus %s, index %d\n",
pci_name(pdev->bus->self), port->idx);
- err = of_map_iommu_id(port->pcie->dev->of_node, rid, NULL, &sid);
+ err = of_map_iommu_id(port->pcie->dev->of_node, rid, &iommu_spec);
if (err)
return err;
+ of_node_put(iommu_spec.np);
+ sid = iommu_spec.args[0];
mutex_lock(&port->pcie->lock);
idx = bitmap_find_free_region(port->sid_map, port->sid_map_sz, 0);