Skip to content

Commit ea47dd1

Browse files
npigginmpe
authored andcommitted
of/fdt: introduce of_scan_flat_dt_subnodes and of_get_flat_dt_phandle
Introduce primitives for FDT parsing. These will be used for powerpc cpufeatures node scanning, which has quite complex structure but should be processed early. Cc: [email protected] Acked-by: Rob Herring <[email protected]> Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 0b382fb commit ea47dd1

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

drivers/of/fdt.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,36 @@ int __init of_scan_flat_dt(int (*it)(unsigned long node,
753753
return rc;
754754
}
755755

756+
/**
757+
* of_scan_flat_dt_subnodes - scan sub-nodes of a node call callback on each.
758+
* @it: callback function
759+
* @data: context data pointer
760+
*
761+
* This function is used to scan sub-nodes of a node.
762+
*/
763+
int __init of_scan_flat_dt_subnodes(unsigned long parent,
764+
int (*it)(unsigned long node,
765+
const char *uname,
766+
void *data),
767+
void *data)
768+
{
769+
const void *blob = initial_boot_params;
770+
int node;
771+
772+
fdt_for_each_subnode(node, blob, parent) {
773+
const char *pathp;
774+
int rc;
775+
776+
pathp = fdt_get_name(blob, node, NULL);
777+
if (*pathp == '/')
778+
pathp = kbasename(pathp);
779+
rc = it(node, pathp, data);
780+
if (rc)
781+
return rc;
782+
}
783+
return 0;
784+
}
785+
756786
/**
757787
* of_get_flat_dt_subnode_by_name - get the subnode by given name
758788
*
@@ -812,6 +842,14 @@ int __init of_flat_dt_match(unsigned long node, const char *const *compat)
812842
return of_fdt_match(initial_boot_params, node, compat);
813843
}
814844

845+
/**
846+
* of_get_flat_dt_prop - Given a node in the flat blob, return the phandle
847+
*/
848+
uint32_t __init of_get_flat_dt_phandle(unsigned long node)
849+
{
850+
return fdt_get_phandle(initial_boot_params, node);
851+
}
852+
815853
struct fdt_scan_status {
816854
const char *name;
817855
int namelen;

include/linux/of_fdt.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ extern char __dtb_end[];
5454
extern int of_scan_flat_dt(int (*it)(unsigned long node, const char *uname,
5555
int depth, void *data),
5656
void *data);
57+
extern int of_scan_flat_dt_subnodes(unsigned long node,
58+
int (*it)(unsigned long node,
59+
const char *uname,
60+
void *data),
61+
void *data);
5762
extern int of_get_flat_dt_subnode_by_name(unsigned long node,
5863
const char *uname);
5964
extern const void *of_get_flat_dt_prop(unsigned long node, const char *name,
@@ -62,6 +67,7 @@ extern int of_flat_dt_is_compatible(unsigned long node, const char *name);
6267
extern int of_flat_dt_match(unsigned long node, const char *const *matches);
6368
extern unsigned long of_get_flat_dt_root(void);
6469
extern int of_get_flat_dt_size(void);
70+
extern uint32_t of_get_flat_dt_phandle(unsigned long node);
6571

6672
extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
6773
int depth, void *data);

0 commit comments

Comments
 (0)