Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: devicetree@vger.kernel.org
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Nicholas Piggin and committed by
Michael Ellerman
ea47dd19 0b382fb3

+44
+38
drivers/of/fdt.c
··· 754 754 } 755 755 756 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 + 786 + /** 757 787 * of_get_flat_dt_subnode_by_name - get the subnode by given name 758 788 * 759 789 * @node: the parent node ··· 840 810 int __init of_flat_dt_match(unsigned long node, const char *const *compat) 841 811 { 842 812 return of_fdt_match(initial_boot_params, node, compat); 813 + } 814 + 815 + /** 816 + * of_get_flat_dt_prop - Given a node in the flat blob, return the phandle 817 + */ 818 + uint32_t __init of_get_flat_dt_phandle(unsigned long node) 819 + { 820 + return fdt_get_phandle(initial_boot_params, node); 843 821 } 844 822 845 823 struct fdt_scan_status {
+6
include/linux/of_fdt.h
··· 54 54 extern int of_scan_flat_dt(int (*it)(unsigned long node, const char *uname, 55 55 int depth, void *data), 56 56 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); 57 62 extern int of_get_flat_dt_subnode_by_name(unsigned long node, 58 63 const char *uname); 59 64 extern const void *of_get_flat_dt_prop(unsigned long node, const char *name, ··· 67 62 extern int of_flat_dt_match(unsigned long node, const char *const *matches); 68 63 extern unsigned long of_get_flat_dt_root(void); 69 64 extern int of_get_flat_dt_size(void); 65 + extern uint32_t of_get_flat_dt_phandle(unsigned long node); 70 66 71 67 extern int early_init_dt_scan_chosen(unsigned long node, const char *uname, 72 68 int depth, void *data);