Skip to content

Commit 5589576

Browse files
anderssonAndy Gross
authored andcommitted
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>
1 parent 193d175 commit 5589576

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

drivers/of/of_reserved_mem.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,29 @@ void of_reserved_mem_device_release(struct device *dev)
397397
rmem->ops->device_release(rmem, dev);
398398
}
399399
EXPORT_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+
*/
410+
struct 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+
}
425+
EXPORT_SYMBOL_GPL(of_reserved_mem_lookup);

include/linux/of_reserved_mem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,
4444
void fdt_init_reserved_mem(void);
4545
void fdt_reserved_mem_save_node(unsigned long node, const char *uname,
4646
phys_addr_t base, phys_addr_t size);
47+
struct reserved_mem *of_reserved_mem_lookup(struct device_node *np);
4748
#else
4849
static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
4950
struct device_node *np, int idx)
@@ -55,6 +56,10 @@ static inline void of_reserved_mem_device_release(struct device *pdev) { }
5556
static inline void fdt_init_reserved_mem(void) { }
5657
static inline void fdt_reserved_mem_save_node(unsigned long node,
5758
const char *uname, phys_addr_t base, phys_addr_t size) { }
59+
static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np)
60+
{
61+
return NULL;
62+
}
5863
#endif
5964

6065
/**

0 commit comments

Comments
 (0)