提交 a40d6c4c 编写于 作者: S Stephen Neuendorffer 提交者: Grant Likely

of/flattree: Refactor unflatten_dt_node

unflatten_dt_node is a helper function that does most of the work to
convert a device tree blob into tree of device nodes.  This code
now uses a passed-in blob instead of using the single boot-time blob,
allowing it to be called in more contexts.
Signed-off-by: NStephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Signed-off-by: NGrant Likely <grant.likely@secretlab.ca>
上级 9706a36e
...@@ -206,7 +206,7 @@ int __init of_flat_dt_is_compatible(unsigned long node, const char *compat) ...@@ -206,7 +206,7 @@ int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
return of_fdt_is_compatible(initial_boot_params, node, compat); return of_fdt_is_compatible(initial_boot_params, node, compat);
} }
static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size, static void *unflatten_dt_alloc(unsigned long *mem, unsigned long size,
unsigned long align) unsigned long align)
{ {
void *res; void *res;
...@@ -220,16 +220,18 @@ static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size, ...@@ -220,16 +220,18 @@ static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size,
/** /**
* unflatten_dt_node - Alloc and populate a device_node from the flat tree * unflatten_dt_node - Alloc and populate a device_node from the flat tree
* @blob: The parent device tree blob
* @p: pointer to node in flat tree * @p: pointer to node in flat tree
* @dad: Parent struct device_node * @dad: Parent struct device_node
* @allnextpp: pointer to ->allnext from last allocated device_node * @allnextpp: pointer to ->allnext from last allocated device_node
* @fpsize: Size of the node path up at the current depth. * @fpsize: Size of the node path up at the current depth.
*/ */
unsigned long __init unflatten_dt_node(unsigned long mem, unsigned long unflatten_dt_node(struct boot_param_header *blob,
unsigned long *p, unsigned long mem,
struct device_node *dad, unsigned long *p,
struct device_node ***allnextpp, struct device_node *dad,
unsigned long fpsize) struct device_node ***allnextpp,
unsigned long fpsize)
{ {
struct device_node *np; struct device_node *np;
struct property *pp, **prev_pp = NULL; struct property *pp, **prev_pp = NULL;
...@@ -325,10 +327,10 @@ unsigned long __init unflatten_dt_node(unsigned long mem, ...@@ -325,10 +327,10 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
sz = be32_to_cpup((__be32 *)(*p)); sz = be32_to_cpup((__be32 *)(*p));
noff = be32_to_cpup((__be32 *)((*p) + 4)); noff = be32_to_cpup((__be32 *)((*p) + 4));
*p += 8; *p += 8;
if (be32_to_cpu(initial_boot_params->version) < 0x10) if (be32_to_cpu(blob->version) < 0x10)
*p = ALIGN(*p, sz >= 8 ? 8 : 4); *p = ALIGN(*p, sz >= 8 ? 8 : 4);
pname = of_fdt_get_string(initial_boot_params, noff); pname = of_fdt_get_string(blob, noff);
if (pname == NULL) { if (pname == NULL) {
pr_info("Can't find property name in list !\n"); pr_info("Can't find property name in list !\n");
break; break;
...@@ -407,7 +409,8 @@ unsigned long __init unflatten_dt_node(unsigned long mem, ...@@ -407,7 +409,8 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
if (tag == OF_DT_NOP) if (tag == OF_DT_NOP)
*p += 4; *p += 4;
else else
mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize); mem = unflatten_dt_node(blob, mem, p, np, allnextpp,
fpsize);
tag = be32_to_cpup((__be32 *)(*p)); tag = be32_to_cpup((__be32 *)(*p));
} }
if (tag != OF_DT_END_NODE) { if (tag != OF_DT_END_NODE) {
...@@ -599,7 +602,8 @@ void __init unflatten_device_tree(void) ...@@ -599,7 +602,8 @@ void __init unflatten_device_tree(void)
/* First pass, scan for size */ /* First pass, scan for size */
start = ((unsigned long)initial_boot_params) + start = ((unsigned long)initial_boot_params) +
be32_to_cpu(initial_boot_params->off_dt_struct); be32_to_cpu(initial_boot_params->off_dt_struct);
size = unflatten_dt_node(0, &start, NULL, NULL, 0); size = unflatten_dt_node(initial_boot_params, 0, &start,
NULL, NULL, 0);
size = (size | 3) + 1; size = (size | 3) + 1;
pr_debug(" size is %lx, allocating...\n", size); pr_debug(" size is %lx, allocating...\n", size);
...@@ -616,7 +620,8 @@ void __init unflatten_device_tree(void) ...@@ -616,7 +620,8 @@ void __init unflatten_device_tree(void)
/* Second pass, do actual unflattening */ /* Second pass, do actual unflattening */
start = ((unsigned long)initial_boot_params) + start = ((unsigned long)initial_boot_params) +
be32_to_cpu(initial_boot_params->off_dt_struct); be32_to_cpu(initial_boot_params->off_dt_struct);
unflatten_dt_node(mem, &start, NULL, &allnextp, 0); unflatten_dt_node(initial_boot_params, mem, &start,
NULL, &allnextp, 0);
if (be32_to_cpup((__be32 *)start) != OF_DT_END) if (be32_to_cpup((__be32 *)start) != OF_DT_END)
pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start)); pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start));
if (be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeef) if (be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeef)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册