aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjorn Andersson <bjorn.andersson@linaro.org>2017-10-11 01:08:54 -0400
committerAndy Gross <andy.gross@linaro.org>2017-10-22 06:06:33 -0400
commiteb297bc716ec2cb3147e6e99002e37058c65cba3 (patch)
tree680bcfbebfe7be6feab741dea7d3c41108330dbc
parenta50ff19d0658d8a09026158448894f06a4521f33 (diff)
of: reserved_mem: Accessor for acquiring reserved_mem
In some cases drivers referencing a reserved-memory region might want to remap the entire region, but when defining the reserved-memory by "size" the client driver has no means to know the associated base address of the reserved memory region. This patch adds an accessor for such drivers to acquire a handle to their associated reserved-memory for this purpose. A complicating factor for the implementation is that the reserved_mem objects are created from the flattened DeviceTree, as such we can't use the device_node address for comparison. Fortunately the name of the node will be used as "name" of the reserved_mem and will be used when building the full_name, so we can compare the "name" with the basename of the full_name to find the match. Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Andy Gross <andy.gross@linaro.org>
-rw-r--r--drivers/of/of_reserved_mem.c26
-rw-r--r--include/linux/of_reserved_mem.h5
2 files changed, 31 insertions, 0 deletions
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index d507c3569a88..b108c7a1f74c 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -397,3 +397,29 @@ void of_reserved_mem_device_release(struct device *dev)
397 rmem->ops->device_release(rmem, dev); 397 rmem->ops->device_release(rmem, dev);
398} 398}
399EXPORT_SYMBOL_GPL(of_reserved_mem_device_release); 399EXPORT_SYMBOL_GPL(of_reserved_mem_device_release);
400
401/**
402 * of_reserved_mem_lookup() - acquire reserved_mem from a device node
403 * @np: node pointer of the desired reserved-memory region
404 *
405 * This function allows drivers to acquire a reference to the reserved_mem
406 * struct based on a device node handle.
407 *
408 * Returns a reserved_mem reference, or NULL on error.
409 */
410struct reserved_mem *of_reserved_mem_lookup(struct device_node *np)
411{
412 const char *name;
413 int i;
414
415 if (!np->full_name)
416 return NULL;
417
418 name = kbasename(np->full_name);
419 for (i = 0; i < reserved_mem_count; i++)
420 if (!strcmp(reserved_mem[i].name, name))
421 return &reserved_mem[i];
422
423 return NULL;
424}
425EXPORT_SYMBOL_GPL(of_reserved_mem_lookup);
diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h
index f8e1992d6423..c58f780104f9 100644
--- a/include/linux/of_reserved_mem.h
+++ b/include/linux/of_reserved_mem.h
@@ -44,6 +44,7 @@ int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,
44void fdt_init_reserved_mem(void); 44void fdt_init_reserved_mem(void);
45void fdt_reserved_mem_save_node(unsigned long node, const char *uname, 45void fdt_reserved_mem_save_node(unsigned long node, const char *uname,
46 phys_addr_t base, phys_addr_t size); 46 phys_addr_t base, phys_addr_t size);
47struct reserved_mem *of_reserved_mem_lookup(struct device_node *np);
47#else 48#else
48static inline int of_reserved_mem_device_init_by_idx(struct device *dev, 49static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
49 struct device_node *np, int idx) 50 struct device_node *np, int idx)
@@ -55,6 +56,10 @@ static inline void of_reserved_mem_device_release(struct device *pdev) { }
55static inline void fdt_init_reserved_mem(void) { } 56static inline void fdt_init_reserved_mem(void) { }
56static inline void fdt_reserved_mem_save_node(unsigned long node, 57static inline void fdt_reserved_mem_save_node(unsigned long node,
57 const char *uname, phys_addr_t base, phys_addr_t size) { } 58 const char *uname, phys_addr_t base, phys_addr_t size) { }
59static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np)
60{
61 return NULL;
62}
58#endif 63#endif
59 64
60/** 65/**