From b7bd94f1a8a63cd4f947036e0d42ee2e23852d64 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 6 Sep 2022 20:27:24 -0600 Subject: dm: core: Split ofnode_path_root() into two functions This function turns out to be a little confusing since it looks up a path and also registers the tree. Split it into two, one that gets the root node and one that looks up a path, so the purpose is clear. Registering the tree will happen in a function to be added in a later patch, called oftree_from_fdt(). Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) (limited to 'drivers/core/ofnode.c') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index b1ba8c5ab4c..7f6c47f0c07 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -18,6 +18,26 @@ #include #include +/** + * ofnode_from_tree_offset() - get an ofnode from a tree offset (flat tree) + * + * Looks up the tree and returns an ofnode with the correct of_offset + * + * If @offset is < 0 then this returns an ofnode with that offset + * + * @tree: tree to check + * @offset: offset within that tree (can be < 0) + * @return node for that offset + */ +static ofnode ofnode_from_tree_offset(oftree tree, int offset) +{ + ofnode node; + + node.of_offset = offset; + + return node; +} + bool ofnode_name_eq(ofnode node, const char *name) { const char *node_name; @@ -640,15 +660,27 @@ ofnode ofnode_path(const char *path) return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path)); } -ofnode ofnode_path_root(oftree tree, const char *path) +ofnode oftree_root(oftree tree) { - if (of_live_active()) + if (of_live_active()) { + return np_to_ofnode(tree.np); + } else { + return ofnode_from_tree_offset(tree, 0); + } +} + +ofnode oftree_path(oftree tree, const char *path) +{ + if (of_live_active()) { return np_to_ofnode(of_find_node_opts_by_path(tree.np, path, NULL)); - else if (*path != '/' && tree.fdt != gd->fdt_blob) + } else if (*path != '/' && tree.fdt != gd->fdt_blob) { return ofnode_null(); /* Aliases only on control FDT */ - else - return offset_to_ofnode(fdt_path_offset(tree.fdt, path)); + } else { + int offset = fdt_path_offset(tree.fdt, path); + + return ofnode_from_tree_offset(tree, offset); + } } const void *ofnode_read_chosen_prop(const char *propname, int *sizep) -- cgit v1.2.3