]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
of: Add convenience wrappers for of_map_id()
authorRobin Murphy <robin.murphy@arm.com>
Wed, 3 Jun 2026 07:13:12 +0000 (12:43 +0530)
committerRob Herring (Arm) <robh@kernel.org>
Fri, 12 Jun 2026 15:25:39 +0000 (10:25 -0500)
Since we now have quite a few users parsing "iommu-map" and "msi-map"
properties, give them some wrappers to conveniently encapsulate the
appropriate sets of property names. This will also make it easier to
then change of_map_id() to correctly account for specifier cells.

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Acked-by: Marc Zyngier <maz@kernel.org>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Vijayanand Jitta <vijayanand.jitta@oss.qualcomm.com>
Link: https://patch.msgid.link/20260603-parse_iommu_cells-v16-1-dc509dacb19a@oss.qualcomm.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
drivers/cdx/cdx_msi.c
drivers/iommu/of_iommu.c
drivers/irqchip/irq-gic-its-msi-parent.c
drivers/of/base.c
drivers/of/irq.c
drivers/pci/controller/dwc/pci-imx6.c
drivers/pci/controller/pcie-apple.c
drivers/xen/grant-dma-ops.c
include/linux/of.h

index 91b95422b2634e8cc631e6cbb028687d5c445e27..78edb7308856c6dee06ebcb6dfa900a25f698a11 100644 (file)
@@ -128,10 +128,9 @@ static int cdx_msi_prepare(struct irq_domain *msi_domain,
        int ret;
 
        /* Retrieve device ID from requestor ID using parent device */
-       ret = of_map_id(parent->of_node, cdx_dev->msi_dev_id, "msi-map", "msi-map-mask",
-                       NULL, &dev_id);
+       ret = of_map_msi_id(parent->of_node, cdx_dev->msi_dev_id, NULL, &dev_id);
        if (ret) {
-               dev_err(dev, "of_map_id failed for MSI: %d\n", ret);
+               dev_err(dev, "of_map_msi_id failed for MSI: %d\n", ret);
                return ret;
        }
 
index 6b989a62def20ecafd833f00a3a92ce8dca192e0..a511ecf21fcdfe71eaf28c9627d1454c96d859e3 100644 (file)
@@ -48,9 +48,7 @@ static int of_iommu_configure_dev_id(struct device_node *master_np,
        struct of_phandle_args iommu_spec = { .args_count = 1 };
        int err;
 
-       err = of_map_id(master_np, *id, "iommu-map",
-                        "iommu-map-mask", &iommu_spec.np,
-                        iommu_spec.args);
+       err = of_map_iommu_id(master_np, *id, &iommu_spec.np, iommu_spec.args);
        if (err)
                return err;
 
index a832cdb2e697840e97f683a92001e5d7ed3f789b..b30d0dc0a1aa3714e5799e748bcd49b7bf936e53 100644 (file)
@@ -179,7 +179,7 @@ static int of_pmsi_get_msi_info(struct irq_domain *domain, struct device *dev, u
 
        struct device_node *msi_ctrl __free(device_node) = NULL;
 
-       return of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &msi_ctrl, dev_id);
+       return of_map_msi_id(dev->of_node, dev->id, &msi_ctrl, dev_id);
 }
 
 static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev,
index f493a7a99a52e40b6e69f39bc5f954caef5a13ff..d936829ff2d287086b3e811f4a1b38ac8862112f 100644 (file)
@@ -2230,3 +2230,41 @@ int of_map_id(const struct device_node *np, u32 id,
        return 0;
 }
 EXPORT_SYMBOL_GPL(of_map_id);
+
+/**
+ * of_map_iommu_id - Translate an ID using "iommu-map" bindings.
+ * @np: root complex device node.
+ * @id: Requester ID of the device (e.g. PCI RID/BDF or a platform
+ *      stream/device ID) used as the lookup key in the iommu-map table.
+ * @target: optional pointer to a target device node.
+ * @id_out: optional pointer to receive the translated ID.
+ *
+ * Convenience wrapper around of_map_id() using "iommu-map" and "iommu-map-mask".
+ *
+ * Return: 0 on success or a standard error code on failure.
+ */
+int of_map_iommu_id(const struct device_node *np, u32 id,
+                   struct device_node **target, u32 *id_out)
+{
+       return of_map_id(np, id, "iommu-map", "iommu-map-mask", target, id_out);
+}
+EXPORT_SYMBOL_GPL(of_map_iommu_id);
+
+/**
+ * of_map_msi_id - Translate an ID using "msi-map" bindings.
+ * @np: root complex device node.
+ * @id: Requester ID of the device (e.g. PCI RID/BDF or a platform
+ *      stream/device ID) used as the lookup key in the msi-map table.
+ * @target: optional pointer to a target device node.
+ * @id_out: optional pointer to receive the translated ID.
+ *
+ * Convenience wrapper around of_map_id() using "msi-map" and "msi-map-mask".
+ *
+ * Return: 0 on success or a standard error code on failure.
+ */
+int of_map_msi_id(const struct device_node *np, u32 id,
+                 struct device_node **target, u32 *id_out)
+{
+       return of_map_id(np, id, "msi-map", "msi-map-mask", target, id_out);
+}
+EXPORT_SYMBOL_GPL(of_map_msi_id);
index 6367c67732d26e2d3092867d032032ac4201390e..e37c1b3f87362eca1df14f3d3a6cab8769a95af4 100644 (file)
@@ -817,8 +817,7 @@ u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_in)
         * "msi-map" or an "msi-parent" property.
         */
        for (parent_dev = dev; parent_dev; parent_dev = parent_dev->parent) {
-               if (!of_map_id(parent_dev->of_node, id_in, "msi-map",
-                               "msi-map-mask", msi_np, &id_out))
+               if (!of_map_msi_id(parent_dev->of_node, id_in, msi_np, &id_out))
                        break;
                if (!of_check_msi_parent(parent_dev->of_node, msi_np))
                        break;
index e35044cc52185ce884e2ec13a102cd827012a478..da7bfda5e95dcb354d60f2e1e511be6e71c2f723 100644 (file)
@@ -1133,8 +1133,7 @@ static int imx_pcie_add_lut_by_rid(struct imx_pcie *imx_pcie, u32 rid)
        u32 sid = 0;
 
        target = NULL;
-       err_i = of_map_id(dev->of_node, rid, "iommu-map", "iommu-map-mask",
-                         &target, &sid_i);
+       err_i = of_map_iommu_id(dev->of_node, rid, &target, &sid_i);
        if (target) {
                of_node_put(target);
        } else {
@@ -1147,8 +1146,7 @@ static int imx_pcie_add_lut_by_rid(struct imx_pcie *imx_pcie, u32 rid)
        }
 
        target = NULL;
-       err_m = of_map_id(dev->of_node, rid, "msi-map", "msi-map-mask",
-                         &target, &sid_m);
+       err_m = of_map_msi_id(dev->of_node, rid, &target, &sid_m);
 
        /*
         *   err_m      target
index 2d92fc79f6ddfa36e561ac0c109feec9eac7bee5..a0937b7b3c4d9ba22ca2448db9d19d61ba43b7d9 100644 (file)
@@ -764,8 +764,7 @@ 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_id(port->pcie->dev->of_node, rid, "iommu-map",
-                       "iommu-map-mask", NULL, &sid);
+       err = of_map_iommu_id(port->pcie->dev->of_node, rid, NULL, &sid);
        if (err)
                return err;
 
index c2603e700178637403d4cef040abc12f63a9c541..1b7696b2d762fc8890ca2f8603e238567f5727ee 100644 (file)
@@ -325,8 +325,7 @@ static int xen_dt_grant_init_backend_domid(struct device *dev,
                struct pci_dev *pdev = to_pci_dev(dev);
                u32 rid = PCI_DEVID(pdev->bus->number, pdev->devfn);
 
-               if (of_map_id(np, rid, "iommu-map", "iommu-map-mask", &iommu_spec.np,
-                               iommu_spec.args)) {
+               if (of_map_iommu_id(np, rid, &iommu_spec.np, iommu_spec.args)) {
                        dev_dbg(dev, "Cannot translate ID\n");
                        return -ESRCH;
                }
index 959786f8f1966247fdbaf4ac68d67dae5e2d4197..721525334b4bebc7472d87ca6813e6c938edf5a7 100644 (file)
@@ -468,6 +468,12 @@ int of_map_id(const struct device_node *np, u32 id,
               const char *map_name, const char *map_mask_name,
               struct device_node **target, u32 *id_out);
 
+int of_map_iommu_id(const struct device_node *np, u32 id,
+                   struct device_node **target, u32 *id_out);
+
+int of_map_msi_id(const struct device_node *np, u32 id,
+                 struct device_node **target, u32 *id_out);
+
 phys_addr_t of_dma_get_max_cpu_address(struct device_node *np);
 
 struct kimage;
@@ -948,6 +954,18 @@ static inline int of_map_id(const struct device_node *np, u32 id,
        return -EINVAL;
 }
 
+static inline int of_map_iommu_id(const struct device_node *np, u32 id,
+                                 struct device_node **target, u32 *id_out)
+{
+       return -EINVAL;
+}
+
+static inline int of_map_msi_id(const struct device_node *np, u32 id,
+                               struct device_node **target, u32 *id_out)
+{
+       return -EINVAL;
+}
+
 static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np)
 {
        return PHYS_ADDR_MAX;