9
0
Fork 0

OF: base: sync of_find_node_by_path with linux OF API

Barebox of_find_node_by_path requires a node to be passed as start node
to start searching. Linux OF API does not pass this node and no current
user of it in barebox is passing anything else than the root node.
Therefore, we rename current function to of_find_node_by_path_from and
introduce a Linux OF API compatible of_find_node_by_path that always
passes the current root_node. Also, all current users of that function
are updated to reflect the API change.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sebastian Hesselbarth 2013-06-13 18:06:44 +02:00 committed by Sascha Hauer
parent 905f3ee7fb
commit 0b79c3bb64
8 changed files with 51 additions and 42 deletions

View File

@ -53,7 +53,7 @@ static int hb_fixup(struct device_node *root)
if ((opp_table[0] >> 16) != HB_OPP_VERSION)
return 0;
node = of_find_node_by_path(root, "/cpus/cpu@0");
node = of_find_node_by_path("/cpus/cpu@0");
if (!node)
return 0;
@ -89,7 +89,7 @@ static int highbank_mem_init(void)
of_set_root_node(root);
np = of_find_node_by_path(root, "/memory");
np = of_find_node_by_path("/memory");
if (!np) {
pr_warn("no memory node use default configuration\n");
goto not_found;

View File

@ -83,7 +83,7 @@ static int of_mpc5200_fixup(struct device_node *root)
int div = in_8((void*)CFG_MBAR + 0x204) & 0x0020 ? 8 : 4;
node = of_find_node_by_path(root, "/cpus/PowerPC,5200@0");
node = of_find_node_by_path("/cpus/PowerPC,5200@0");
if (!node)
return -EINVAL;
@ -91,7 +91,7 @@ static int of_mpc5200_fixup(struct device_node *root)
of_property_write_u32(node, "bus-frequency", get_bus_clock());
of_property_write_u32(node, "clock-frequency", get_cpu_clock());
node = of_find_node_by_path(root, "/soc5200@f0000000");
node = of_find_node_by_path("/soc5200@f0000000");
if (!node)
return -EINVAL;

View File

@ -81,7 +81,7 @@ static int do_of_node(int argc, char *argv[])
if (!path)
return COMMAND_ERROR_USAGE;
node = of_find_node_by_path(root, path);
node = of_find_node_by_path(path);
if (!node) {
printf("Cannot find nodepath %s\n", path);
return -ENOENT;

View File

@ -175,7 +175,7 @@ static int do_of_property(int argc, char *argv[])
int set = 0;
int ret;
char *path = NULL, *propname = NULL;
struct device_node *root, *node = NULL;
struct device_node *node = NULL;
struct property *pp = NULL;
while ((opt = getopt(argc, argv, "ds")) > 0) {
@ -194,15 +194,9 @@ static int do_of_property(int argc, char *argv[])
if (optind == argc)
return COMMAND_ERROR_USAGE;
root = of_get_root_node();
if (!root) {
printf("root node not set\n");
return -ENOENT;
}
if (optind < argc) {
path = argv[optind];
node = of_find_node_by_path(root, path);
node = of_find_node_by_path(path);
if (!node) {
printf("Cannot find nodepath %s\n", path);
return -ENOENT;

View File

@ -164,16 +164,7 @@ static int do_oftree(int argc, char *argv[])
of_print_nodes(root, 0);
of_free(root);
} else {
struct device_node *root, *n;
root = of_get_root_node();
if (!root) {
ret = -ENOENT;
goto out;
}
n = of_find_node_by_path(root, node);
struct device_node *n = of_find_node_by_path(node);
if (!n) {
ret = -ENOENT;
goto out;

View File

@ -100,7 +100,7 @@ void of_print_property(const void *data, int len)
void of_print_cmdline(struct device_node *root)
{
struct device_node *node = of_find_node_by_path(root, "/chosen");
struct device_node *node = of_find_node_by_path("/chosen");
const char *cmdline;
if (!node) {

View File

@ -153,7 +153,7 @@ void of_alias_scan(void)
if (!root_node)
return;
of_aliases = of_find_node_by_path(root_node, "/aliases");
of_aliases = of_find_node_by_path("/aliases");
if (!of_aliases)
return;
@ -170,7 +170,7 @@ void of_alias_scan(void)
!of_prop_cmp(pp->name, "linux,phandle"))
continue;
np = of_find_node_by_path(root_node, pp->value);
np = of_find_node_by_path(pp->value);
if (!np)
continue;
@ -556,19 +556,18 @@ int of_machine_is_compatible(const char *compat)
EXPORT_SYMBOL(of_machine_is_compatible);
/**
* of_find_node_by_path - Find a node matching a full OF path
* @root: The root node of this tree
* of_find_node_by_path_from - Find a node matching a full OF path
* relative to a given root node.
* @path: The full path to match
*
* Returns a node pointer with refcount incremented, use
* of_node_put() on it when done.
* Returns a pointer to the node found or NULL.
*/
struct device_node *of_find_node_by_path(struct device_node *root, const char *path)
struct device_node *of_find_node_by_path_from(struct device_node *from,
const char *path)
{
char *slash, *p, *freep;
struct device_node *dn = root;
if (*path != '/')
if (!from || !path || *path != '/')
return NULL;
path++;
@ -583,8 +582,8 @@ struct device_node *of_find_node_by_path(struct device_node *root, const char *p
if (slash)
*slash = 0;
dn = of_find_child_by_name(dn, p);
if (!dn)
from = of_find_child_by_name(from, p);
if (!from)
goto out;
if (!slash)
@ -595,7 +594,19 @@ struct device_node *of_find_node_by_path(struct device_node *root, const char *p
out:
free(freep);
return dn;
return from;
}
EXPORT_SYMBOL(of_find_node_by_path_from);
/**
* of_find_node_by_path - Find a node matching a full OF path
* @path: The full path to match
*
* Returns a pointer to the node found or NULL.
*/
struct device_node *of_find_node_by_path(const char *path)
{
return of_find_node_by_path_from(root_node, path);
}
EXPORT_SYMBOL(of_find_node_by_path);
@ -1156,12 +1167,12 @@ int of_probe(void)
if(!root_node)
return -ENODEV;
of_chosen = of_find_node_by_path(root_node, "/chosen");
of_chosen = of_find_node_by_path("/chosen");
of_property_read_string(root_node, "model", &of_model);
__of_parse_phandles(root_node);
memory = of_find_node_by_path(root_node, "/memory");
memory = of_find_node_by_path("/memory");
if (memory)
of_add_memory(memory, false);
@ -1234,8 +1245,8 @@ int of_device_is_stdout_path(struct device_d *dev)
name = of_get_property(of_chosen, "linux,stdout-path", NULL);
if (name == NULL)
return 0;
dn = of_find_node_by_path(root_node, name);
dn = of_find_node_by_path(name);
if (!dn)
return 0;
@ -1264,7 +1275,7 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
struct device_node *chosen;
__be32 buf[2];
chosen = of_find_node_by_path(root, "/chosen");
chosen = of_find_node_by_path("/chosen");
if (!chosen)
return -EINVAL;

View File

@ -67,8 +67,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
int of_n_addr_cells(struct device_node *np);
int of_n_size_cells(struct device_node *np);
struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
struct fdt_header *fdt_get_tree(void);
@ -184,6 +182,10 @@ struct cdev;
extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
extern struct device_node *of_find_node_by_path_from(struct device_node *from,
const char *path);
extern struct device_node *of_find_node_by_path(const char *path);
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@ -235,6 +237,17 @@ static inline struct property *of_find_property(const struct device_node *np,
return NULL;
}
static inline struct device_node *of_find_node_by_path_from(
struct device_node *from, const char *path)
{
return NULL;
}
static inline struct device_node *of_find_node_by_path(const char *path)
{
return NULL;
}
static inline void of_alias_scan(void)
{
}