summaryrefslogtreecommitdiffstats
path: root/drivers/of/address.c
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2023-03-28 15:15:57 -0500
committerRob Herring <robh@kernel.org>2023-04-13 17:46:35 -0500
commitc75a79491835c50ca61938ae1ebd3ba5598f7410 (patch)
treea87517b093f73b412725b461af721e76d58946e8 /drivers/of/address.c
parent6d32dadb11a6480be62c6ada901bbdcbda1775c9 (diff)
downloadlinux-stable-c75a79491835c50ca61938ae1ebd3ba5598f7410.tar.gz
linux-stable-c75a79491835c50ca61938ae1ebd3ba5598f7410.tar.bz2
linux-stable-c75a79491835c50ca61938ae1ebd3ba5598f7410.zip
of/address: Add of_range_to_resource() helper
A few users need to convert a specific "ranges" entry into a struct resource. Add a helper to similar to of_address_to_resource(). The existing of_pci_range_to_resource() helper isn't really PCI specific, so it can be used with the CONFIG_PCI check dropped. Link: https://lore.kernel.org/r/20230328-dt-address-helpers-v1-2-e2456c3e77ab@kernel.org Signed-off-by: Rob Herring <robh@kernel.org>
Diffstat (limited to 'drivers/of/address.c')
-rw-r--r--drivers/of/address.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 4c0b169ef9bf..b79f005834fc 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -229,9 +229,6 @@ int of_pci_range_to_resource(struct of_pci_range *range,
res->parent = res->child = res->sibling = NULL;
res->name = np->full_name;
- if (!IS_ENABLED(CONFIG_PCI))
- return -ENOSYS;
-
if (res->flags & IORESOURCE_IO) {
unsigned long port;
err = pci_register_io_range(&np->fwnode, range->cpu_addr,
@@ -264,6 +261,34 @@ invalid_range:
EXPORT_SYMBOL(of_pci_range_to_resource);
/*
+ * of_range_to_resource - Create a resource from a ranges entry
+ * @np: device node where the range belongs to
+ * @index: the 'ranges' index to convert to a resource
+ * @res: pointer to a valid resource that will be updated to
+ * reflect the values contained in the range.
+ *
+ * Returns ENOENT if the entry is not found or EINVAL if the range cannot be
+ * converted to resource.
+ */
+int of_range_to_resource(struct device_node *np, int index, struct resource *res)
+{
+ int ret, i = 0;
+ struct of_range_parser parser;
+ struct of_range range;
+
+ ret = of_range_parser_init(&parser, np);
+ if (ret)
+ return ret;
+
+ for_each_of_range(&parser, &range)
+ if (i++ == index)
+ return of_pci_range_to_resource(&range, np, res);
+
+ return -ENOENT;
+}
+EXPORT_SYMBOL(of_range_to_resource);
+
+/*
* ISA bus specific translator
*/