Skip to content

Commit 7a3860c

Browse files
rmurphy-armvijayanandjitta-oss
authored andcommitted
FROMLIST: of: Add convenience wrappers for of_map_id()
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. Link: https://lore.kernel.org/all/20260408-parse_iommu_cells-v13-1-fa921e92661b@oss.qualcomm.com/ 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> [Conflict: irq-gic-its-msi-parent.c was refactored to split of_pmsi_get_msi_info() into of_pmsi_get_dev_id() and of_v5_pmsi_get_msi_info(); updated both of_map_id() calls.] Signed-off-by: Vijayanand Jitta <vijayanand.jitta@oss.qualcomm.com>
1 parent 2e8db98 commit 7a3860c

9 files changed

Lines changed: 65 additions & 17 deletions

File tree

drivers/cdx/cdx_msi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ static int cdx_msi_prepare(struct irq_domain *msi_domain,
128128
int ret;
129129

130130
/* Retrieve device ID from requestor ID using parent device */
131-
ret = of_map_id(parent->of_node, cdx_dev->msi_dev_id, "msi-map", "msi-map-mask",
132-
NULL, &dev_id);
131+
ret = of_map_msi_id(parent->of_node, cdx_dev->msi_dev_id, NULL, &dev_id);
133132
if (ret) {
134133
dev_err(dev, "of_map_id failed for MSI: %d\n", ret);
135134
return ret;

drivers/iommu/of_iommu.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ static int of_iommu_configure_dev_id(struct device_node *master_np,
4848
struct of_phandle_args iommu_spec = { .args_count = 1 };
4949
int err;
5050

51-
err = of_map_id(master_np, *id, "iommu-map",
52-
"iommu-map-mask", &iommu_spec.np,
53-
iommu_spec.args);
51+
err = of_map_iommu_id(master_np, *id, &iommu_spec.np, iommu_spec.args);
5452
if (err)
5553
return err;
5654

drivers/irqchip/irq-gic-its-msi-parent.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static int of_pmsi_get_dev_id(struct irq_domain *domain, struct device *dev,
166166
if (ret) {
167167
struct device_node *np = NULL;
168168

169-
ret = of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &np, dev_id);
169+
ret = of_map_msi_id(dev->of_node, dev->id, &np, dev_id);
170170
if (np)
171171
of_node_put(np);
172172
}
@@ -211,7 +211,7 @@ static int of_v5_pmsi_get_msi_info(struct irq_domain *domain, struct device *dev
211211
if (ret) {
212212
struct device_node *np = NULL;
213213

214-
ret = of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &np, dev_id);
214+
ret = of_map_msi_id(dev->of_node, dev->id, &np, dev_id);
215215
if (np) {
216216
ret = its_translate_frame_address(np, pa);
217217
of_node_put(np);

drivers/of/base.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,3 +2154,41 @@ int of_map_id(const struct device_node *np, u32 id,
21542154
return 0;
21552155
}
21562156
EXPORT_SYMBOL_GPL(of_map_id);
2157+
2158+
/**
2159+
* of_map_iommu_id - Translate an ID using "iommu-map" bindings.
2160+
* @np: root complex device node.
2161+
* @id: Requester ID of the device (e.g. PCI RID/BDF or a platform
2162+
* stream/device ID) used as the lookup key in the iommu-map table.
2163+
* @target: optional pointer to a target device node.
2164+
* @id_out: optional pointer to receive the translated ID.
2165+
*
2166+
* Convenience wrapper around of_map_id() using "iommu-map" and "iommu-map-mask".
2167+
*
2168+
* Return: 0 on success or a standard error code on failure.
2169+
*/
2170+
int of_map_iommu_id(const struct device_node *np, u32 id,
2171+
struct device_node **target, u32 *id_out)
2172+
{
2173+
return of_map_id(np, id, "iommu-map", "iommu-map-mask", target, id_out);
2174+
}
2175+
EXPORT_SYMBOL_GPL(of_map_iommu_id);
2176+
2177+
/**
2178+
* of_map_msi_id - Translate an ID using "msi-map" bindings.
2179+
* @np: root complex device node.
2180+
* @id: Requester ID of the device (e.g. PCI RID/BDF or a platform
2181+
* stream/device ID) used as the lookup key in the msi-map table.
2182+
* @target: optional pointer to a target device node.
2183+
* @id_out: optional pointer to receive the translated ID.
2184+
*
2185+
* Convenience wrapper around of_map_id() using "msi-map" and "msi-map-mask".
2186+
*
2187+
* Return: 0 on success or a standard error code on failure.
2188+
*/
2189+
int of_map_msi_id(const struct device_node *np, u32 id,
2190+
struct device_node **target, u32 *id_out)
2191+
{
2192+
return of_map_id(np, id, "msi-map", "msi-map-mask", target, id_out);
2193+
}
2194+
EXPORT_SYMBOL_GPL(of_map_msi_id);

drivers/of/irq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,7 @@ u32 of_msi_xlate(struct device *dev, struct device_node **msi_np, u32 id_in)
725725
* "msi-map" or an "msi-parent" property.
726726
*/
727727
for (parent_dev = dev; parent_dev; parent_dev = parent_dev->parent) {
728-
if (!of_map_id(parent_dev->of_node, id_in, "msi-map",
729-
"msi-map-mask", msi_np, &id_out))
728+
if (!of_map_msi_id(parent_dev->of_node, id_in, msi_np, &id_out))
730729
break;
731730
if (!of_check_msi_parent(parent_dev->of_node, msi_np))
732731
break;

drivers/pci/controller/dwc/pci-imx6.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,8 +1125,7 @@ static int imx_pcie_add_lut_by_rid(struct imx_pcie *imx_pcie, u32 rid)
11251125
u32 sid = 0;
11261126

11271127
target = NULL;
1128-
err_i = of_map_id(dev->of_node, rid, "iommu-map", "iommu-map-mask",
1129-
&target, &sid_i);
1128+
err_i = of_map_iommu_id(dev->of_node, rid, &target, &sid_i);
11301129
if (target) {
11311130
of_node_put(target);
11321131
} else {
@@ -1139,8 +1138,7 @@ static int imx_pcie_add_lut_by_rid(struct imx_pcie *imx_pcie, u32 rid)
11391138
}
11401139

11411140
target = NULL;
1142-
err_m = of_map_id(dev->of_node, rid, "msi-map", "msi-map-mask",
1143-
&target, &sid_m);
1141+
err_m = of_map_msi_id(dev->of_node, rid, &target, &sid_m);
11441142

11451143
/*
11461144
* err_m target

drivers/pci/controller/pcie-apple.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,7 @@ static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_d
791791
dev_dbg(&pdev->dev, "added to bus %s, index %d\n",
792792
pci_name(pdev->bus->self), port->idx);
793793

794-
err = of_map_id(port->pcie->dev->of_node, rid, "iommu-map",
795-
"iommu-map-mask", NULL, &sid);
794+
err = of_map_iommu_id(port->pcie->dev->of_node, rid, NULL, &sid);
796795
if (err)
797796
return err;
798797

drivers/xen/grant-dma-ops.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ static int xen_dt_grant_init_backend_domid(struct device *dev,
321321
struct pci_dev *pdev = to_pci_dev(dev);
322322
u32 rid = PCI_DEVID(pdev->bus->number, pdev->devfn);
323323

324-
if (of_map_id(np, rid, "iommu-map", "iommu-map-mask", &iommu_spec.np,
325-
iommu_spec.args)) {
324+
if (of_map_iommu_id(np, rid, &iommu_spec.np, iommu_spec.args)) {
326325
dev_dbg(dev, "Cannot translate ID\n");
327326
return -ESRCH;
328327
}

include/linux/of.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,12 @@ int of_map_id(const struct device_node *np, u32 id,
460460
const char *map_name, const char *map_mask_name,
461461
struct device_node **target, u32 *id_out);
462462

463+
int of_map_iommu_id(const struct device_node *np, u32 id,
464+
struct device_node **target, u32 *id_out);
465+
466+
int of_map_msi_id(const struct device_node *np, u32 id,
467+
struct device_node **target, u32 *id_out);
468+
463469
phys_addr_t of_dma_get_max_cpu_address(struct device_node *np);
464470

465471
struct kimage;
@@ -912,6 +918,18 @@ static inline int of_map_id(const struct device_node *np, u32 id,
912918
return -EINVAL;
913919
}
914920

921+
static inline int of_map_iommu_id(const struct device_node *np, u32 id,
922+
struct device_node **target, u32 *id_out)
923+
{
924+
return -EINVAL;
925+
}
926+
927+
static inline int of_map_msi_id(const struct device_node *np, u32 id,
928+
struct device_node **target, u32 *id_out)
929+
{
930+
return -EINVAL;
931+
}
932+
915933
static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np)
916934
{
917935
return PHYS_ADDR_MAX;

0 commit comments

Comments
 (0)