Skip to content

Commit

Permalink
of/flattree: merge of_scan_flat_dt
Browse files Browse the repository at this point in the history
Merge common code between PowerPC and Microblaze

Signed-off-by: Grant Likely <[email protected]>
Reviewed-by: Wolfram Sang <[email protected]>
Tested-by: Michal Simek <[email protected]>
  • Loading branch information
glikely committed Nov 24, 2009
1 parent e169cfb commit c8cb7a5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 122 deletions.
61 changes: 0 additions & 61 deletions arch/microblaze/kernel/prom.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,67 +50,6 @@ typedef u32 cell_t;
/* export that to outside world */
struct device_node *of_chosen;

/**
* This function is used to scan the flattened device-tree, it is
* used to extract the memory informations at boot before we can
* unflatten the tree
*/
int __init of_scan_flat_dt(int (*it)(unsigned long node,
const char *uname, int depth,
void *data),
void *data)
{
unsigned long p = ((unsigned long)initial_boot_params) +
initial_boot_params->off_dt_struct;
int rc = 0;
int depth = -1;

do {
u32 tag = *((u32 *)p);
char *pathp;

p += 4;
if (tag == OF_DT_END_NODE) {
depth--;
continue;
}
if (tag == OF_DT_NOP)
continue;
if (tag == OF_DT_END)
break;
if (tag == OF_DT_PROP) {
u32 sz = *((u32 *)p);
p += 8;
if (initial_boot_params->version < 0x10)
p = _ALIGN(p, sz >= 8 ? 8 : 4);
p += sz;
p = _ALIGN(p, 4);
continue;
}
if (tag != OF_DT_BEGIN_NODE) {
printk(KERN_WARNING "Invalid tag %x scanning flattened"
" device tree !\n", tag);
return -EINVAL;
}
depth++;
pathp = (char *)p;
p = _ALIGN(p + strlen(pathp) + 1, 4);
if ((*pathp) == '/') {
char *lp, *np;
for (lp = NULL, np = pathp; *np; np++)
if ((*np) == '/')
lp = np+1;
if (lp != NULL)
pathp = lp;
}
rc = it(p, pathp, depth, data);
if (rc != 0)
break;
} while (1);

return rc;
}

unsigned long __init of_get_flat_dt_root(void)
{
unsigned long p = ((unsigned long)initial_boot_params) +
Expand Down
61 changes: 0 additions & 61 deletions arch/powerpc/kernel/prom.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,67 +80,6 @@ extern rwlock_t devtree_lock; /* temporary while merging */
/* export that to outside world */
struct device_node *of_chosen;

/**
* This function is used to scan the flattened device-tree, it is
* used to extract the memory informations at boot before we can
* unflatten the tree
*/
int __init of_scan_flat_dt(int (*it)(unsigned long node,
const char *uname, int depth,
void *data),
void *data)
{
unsigned long p = ((unsigned long)initial_boot_params) +
initial_boot_params->off_dt_struct;
int rc = 0;
int depth = -1;

do {
u32 tag = *((u32 *)p);
char *pathp;

p += 4;
if (tag == OF_DT_END_NODE) {
depth --;
continue;
}
if (tag == OF_DT_NOP)
continue;
if (tag == OF_DT_END)
break;
if (tag == OF_DT_PROP) {
u32 sz = *((u32 *)p);
p += 8;
if (initial_boot_params->version < 0x10)
p = _ALIGN(p, sz >= 8 ? 8 : 4);
p += sz;
p = _ALIGN(p, 4);
continue;
}
if (tag != OF_DT_BEGIN_NODE) {
printk(KERN_WARNING "Invalid tag %x scanning flattened"
" device tree !\n", tag);
return -EINVAL;
}
depth++;
pathp = (char *)p;
p = _ALIGN(p + strlen(pathp) + 1, 4);
if ((*pathp) == '/') {
char *lp, *np;
for (lp = NULL, np = pathp; *np; np++)
if ((*np) == '/')
lp = np+1;
if (lp != NULL)
pathp = lp;
}
rc = it(p, pathp, depth, data);
if (rc != 0)
break;
} while(1);

return rc;
}

unsigned long __init of_get_flat_dt_root(void)
{
unsigned long p = ((unsigned long)initial_boot_params) +
Expand Down
64 changes: 64 additions & 0 deletions drivers/of/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,67 @@ char *find_flat_dt_string(u32 offset)
return ((char *)initial_boot_params) +
initial_boot_params->off_dt_strings + offset;
}

/**
* of_scan_flat_dt - scan flattened tree blob and call callback on each.
* @it: callback function
* @data: context data pointer
*
* This function is used to scan the flattened device-tree, it is
* used to extract the memory information at boot before we can
* unflatten the tree
*/
int __init of_scan_flat_dt(int (*it)(unsigned long node,
const char *uname, int depth,
void *data),
void *data)
{
unsigned long p = ((unsigned long)initial_boot_params) +
initial_boot_params->off_dt_struct;
int rc = 0;
int depth = -1;

do {
u32 tag = *((u32 *)p);
char *pathp;

p += 4;
if (tag == OF_DT_END_NODE) {
depth--;
continue;
}
if (tag == OF_DT_NOP)
continue;
if (tag == OF_DT_END)
break;
if (tag == OF_DT_PROP) {
u32 sz = *((u32 *)p);
p += 8;
if (initial_boot_params->version < 0x10)
p = _ALIGN(p, sz >= 8 ? 8 : 4);
p += sz;
p = _ALIGN(p, 4);
continue;
}
if (tag != OF_DT_BEGIN_NODE) {
pr_err("Invalid tag %x in flat device tree!\n", tag);
return -EINVAL;
}
depth++;
pathp = (char *)p;
p = _ALIGN(p + strlen(pathp) + 1, 4);
if ((*pathp) == '/') {
char *lp, *np;
for (lp = NULL, np = pathp; *np; np++)
if ((*np) == '/')
lp = np+1;
if (lp != NULL)
pathp = lp;
}
rc = it(p, pathp, depth, data);
if (rc != 0)
break;
} while (1);

return rc;
}

0 comments on commit c8cb7a5

Please sign in to comment.