Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 67298
b: refs/heads/master
c: 21f3fe2
h: refs/heads/master
v: v3
  • Loading branch information
Scott Wood authored and Paul Mackerras committed Sep 13, 2007
1 parent 17a0906 commit b05c17e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9de782770b84768e1aa2e6454223ef30768de84e
refs/heads/master: 21f3fe2f7ab57832ea1fc7f719ec7e167b7ad80e
59 changes: 59 additions & 0 deletions trunk/arch/powerpc/boot/flatdevtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,3 +975,62 @@ void *ft_create_node(struct ft_cxt *cxt, const void *parent, const char *name)
}
return NULL;
}

/* Returns the start of the path within the provided buffer, or NULL on
* error.
*/
char *ft_get_path(struct ft_cxt *cxt, const void *phandle,
char *buf, int len)
{
const char *path_comp[FT_MAX_DEPTH];
struct ft_atom atom;
char *p, *next, *pos;
int depth = 0, i;
void *node;

node = ft_node_ph2node(cxt, phandle);
if (node == NULL)
return NULL;

p = ft_root_node(cxt);

while ((next = ft_next(cxt, p, &atom)) != NULL) {
switch (atom.tag) {
case OF_DT_BEGIN_NODE:
path_comp[depth++] = atom.name;
if (p == node)
goto found;

break;

case OF_DT_END_NODE:
if (--depth == 0)
return NULL;
}

p = next;
}

found:
pos = buf;
for (i = 1; i < depth; i++) {
int this_len;

if (len <= 1)
return NULL;

*pos++ = '/';
len--;

strncpy(pos, path_comp[i], len);

if (pos[len - 1] != 0)
return NULL;

this_len = strlen(pos);
len -= this_len;
pos += this_len;
}

return buf;
}
1 change: 1 addition & 0 deletions trunk/arch/powerpc/boot/flatdevtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ void *ft_find_node_by_prop_value(struct ft_cxt *cxt, const void *prev,
const char *propname, const char *propval,
int proplen);
void *ft_create_node(struct ft_cxt *cxt, const void *parent, const char *name);
char *ft_get_path(struct ft_cxt *cxt, const void *phandle, char *buf, int len);

#endif /* FLATDEVTREE_H */
6 changes: 6 additions & 0 deletions trunk/arch/powerpc/boot/flatdevtree_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ static unsigned long fdtm_finalize(void)
return (unsigned long)cxt.bph;
}

static char *fdtm_get_path(const void *phandle, char *buf, int len)
{
return ft_get_path(&cxt, phandle, buf, len);
}

int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device)
{
dt_ops.finddevice = fdtm_finddevice;
Expand All @@ -67,6 +72,7 @@ int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device)
dt_ops.create_node = fdtm_create_node;
dt_ops.find_node_by_prop_value = fdtm_find_node_by_prop_value;
dt_ops.finalize = fdtm_finalize;
dt_ops.get_path = fdtm_get_path;

return ft_open(&cxt, dt_blob, max_size, max_find_device,
platform_ops.realloc);
Expand Down
9 changes: 9 additions & 0 deletions trunk/arch/powerpc/boot/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct dt_ops {
const char *propname,
const char *propval, int proplen);
unsigned long (*finalize)(void);
char *(*get_path)(const void *phandle, char *buf, int len);
};
extern struct dt_ops dt_ops;

Expand Down Expand Up @@ -170,6 +171,14 @@ static inline void *find_node_by_linuxphandle(const u32 linuxphandle)
(char *)&linuxphandle, sizeof(u32));
}

static inline char *get_path(const void *phandle, char *buf, int len)
{
if (dt_ops.get_path)
return dt_ops.get_path(phandle, buf, len);

return NULL;
}

static inline void *malloc(unsigned long size)
{
return (platform_ops.malloc) ? platform_ops.malloc(size) : NULL;
Expand Down

0 comments on commit b05c17e

Please sign in to comment.