Skip to content

Commit

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

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Reviewed-by: Wolfram Sang <w.sang@pengutronix.de>
Tested-by: Michal Simek <monstr@monstr.eu>
  • Loading branch information
Grant Likely committed Nov 24, 2009
1 parent bbd3393 commit 41f8800
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 104 deletions.
1 change: 0 additions & 1 deletion arch/microblaze/include/asm/prom.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ extern struct device_node *of_chosen;

#define HAVE_ARCH_DEVTREE_FIXUPS

extern struct device_node *allnodes; /* temporary while merging */
extern rwlock_t devtree_lock; /* temporary while merging */

/* For updating the device tree at runtime */
Expand Down
49 changes: 0 additions & 49 deletions arch/microblaze/kernel/prom.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,55 +50,6 @@ typedef u32 cell_t;
/* export that to outside world */
struct device_node *of_chosen;

/**
* unflattens the device-tree passed by the firmware, creating the
* tree of struct device_node. It also fills the "name" and "type"
* pointers of the nodes so the normal device-tree walking functions
* can be used (this used to be done by finish_device_tree)
*/
void __init unflatten_device_tree(void)
{
unsigned long start, mem, size;
struct device_node **allnextp = &allnodes;

pr_debug(" -> unflatten_device_tree()\n");

/* First pass, scan for size */
start = ((unsigned long)initial_boot_params) +
initial_boot_params->off_dt_struct;
size = unflatten_dt_node(0, &start, NULL, NULL, 0);
size = (size | 3) + 1;

pr_debug(" size is %lx, allocating...\n", size);

/* Allocate memory for the expanded device tree */
mem = lmb_alloc(size + 4, __alignof__(struct device_node));
mem = (unsigned long) __va(mem);

((u32 *)mem)[size / 4] = 0xdeadbeef;

pr_debug(" unflattening %lx...\n", mem);

/* Second pass, do actual unflattening */
start = ((unsigned long)initial_boot_params) +
initial_boot_params->off_dt_struct;
unflatten_dt_node(mem, &start, NULL, &allnextp, 0);
if (*((u32 *)start) != OF_DT_END)
printk(KERN_WARNING "Weird tag at end of tree: %08x\n",
*((u32 *)start));
if (((u32 *)mem)[size / 4] != 0xdeadbeef)
printk(KERN_WARNING "End of tree marker overwritten: %08x\n",
((u32 *)mem)[size / 4]);
*allnextp = NULL;

/* Get pointer to OF "/chosen" node for use everywhere */
of_chosen = of_find_node_by_path("/chosen");
if (of_chosen == NULL)
of_chosen = of_find_node_by_path("/chosen@0");

pr_debug(" <- unflatten_device_tree()\n");
}

#define early_init_dt_scan_drconf_memory(node) 0

static int __init early_init_dt_scan_cpus(unsigned long node,
Expand Down
50 changes: 0 additions & 50 deletions arch/powerpc/kernel/prom.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ unsigned long tce_alloc_start, tce_alloc_end;

typedef u32 cell_t;

extern struct device_node *allnodes; /* temporary while merging */

extern rwlock_t devtree_lock; /* temporary while merging */

/* export that to outside world */
Expand Down Expand Up @@ -119,54 +117,6 @@ static void __init move_device_tree(void)
DBG("<- move_device_tree\n");
}

/**
* unflattens the device-tree passed by the firmware, creating the
* tree of struct device_node. It also fills the "name" and "type"
* pointers of the nodes so the normal device-tree walking functions
* can be used (this used to be done by finish_device_tree)
*/
void __init unflatten_device_tree(void)
{
unsigned long start, mem, size;
struct device_node **allnextp = &allnodes;

DBG(" -> unflatten_device_tree()\n");

/* First pass, scan for size */
start = ((unsigned long)initial_boot_params) +
initial_boot_params->off_dt_struct;
size = unflatten_dt_node(0, &start, NULL, NULL, 0);
size = (size | 3) + 1;

DBG(" size is %lx, allocating...\n", size);

/* Allocate memory for the expanded device tree */
mem = lmb_alloc(size + 4, __alignof__(struct device_node));
mem = (unsigned long) __va(mem);

((u32 *)mem)[size / 4] = 0xdeadbeef;

DBG(" unflattening %lx...\n", mem);

/* Second pass, do actual unflattening */
start = ((unsigned long)initial_boot_params) +
initial_boot_params->off_dt_struct;
unflatten_dt_node(mem, &start, NULL, &allnextp, 0);
if (*((u32 *)start) != OF_DT_END)
printk(KERN_WARNING "Weird tag at end of tree: %08x\n", *((u32 *)start));
if (((u32 *)mem)[size / 4] != 0xdeadbeef)
printk(KERN_WARNING "End of tree marker overwritten: %08x\n",
((u32 *)mem)[size / 4] );
*allnextp = NULL;

/* Get pointer to OF "/chosen" node for use everywhere */
of_chosen = of_find_node_by_path("/chosen");
if (of_chosen == NULL)
of_chosen = of_find_node_by_path("/chosen@0");

DBG(" <- unflatten_device_tree()\n");
}

/*
* ibm,pa-features is a per-cpu property that contains a string of
* attribute descriptors, each of which has a 2 byte header plus up
Expand Down
52 changes: 52 additions & 0 deletions drivers/of/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* version 2 as published by the Free Software Foundation.
*/

#include <linux/kernel.h>
#include <linux/lmb.h>
#include <linux/of.h>
#include <linux/of_fdt.h>

Expand Down Expand Up @@ -366,3 +368,53 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
*p += 4;
return mem;
}

/**
* unflatten_device_tree - create tree of device_nodes from flat blob
*
* unflattens the device-tree passed by the firmware, creating the
* tree of struct device_node. It also fills the "name" and "type"
* pointers of the nodes so the normal device-tree walking functions
* can be used.
*/
void __init unflatten_device_tree(void)
{
unsigned long start, mem, size;
struct device_node **allnextp = &allnodes;

pr_debug(" -> unflatten_device_tree()\n");

/* First pass, scan for size */
start = ((unsigned long)initial_boot_params) +
initial_boot_params->off_dt_struct;
size = unflatten_dt_node(0, &start, NULL, NULL, 0);
size = (size | 3) + 1;

pr_debug(" size is %lx, allocating...\n", size);

/* Allocate memory for the expanded device tree */
mem = lmb_alloc(size + 4, __alignof__(struct device_node));
mem = (unsigned long) __va(mem);

((u32 *)mem)[size / 4] = 0xdeadbeef;

pr_debug(" unflattening %lx...\n", mem);

/* Second pass, do actual unflattening */
start = ((unsigned long)initial_boot_params) +
initial_boot_params->off_dt_struct;
unflatten_dt_node(mem, &start, NULL, &allnextp, 0);
if (*((u32 *)start) != OF_DT_END)
pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start));
if (((u32 *)mem)[size / 4] != 0xdeadbeef)
pr_warning("End of tree marker overwritten: %08x\n",
((u32 *)mem)[size / 4]);
*allnextp = NULL;

/* Get pointer to OF "/chosen" node for use everywhere */
of_chosen = of_find_node_by_path("/chosen");
if (of_chosen == NULL)
of_chosen = of_find_node_by_path("/chosen@0");

pr_debug(" <- unflatten_device_tree()\n");
}
3 changes: 3 additions & 0 deletions include/linux/of.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ struct device_node {
#endif
};

/* Pointer for first entry in chain of all nodes. */
extern struct device_node *allnodes;

static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
{
return test_bit(flag, &n->_flags);
Expand Down
4 changes: 0 additions & 4 deletions include/linux/of_fdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ extern void *of_get_flat_dt_prop(unsigned long node, const char *name,
unsigned long *size);
extern int of_flat_dt_is_compatible(unsigned long node, const char *name);
extern unsigned long of_get_flat_dt_root(void);
extern unsigned long unflatten_dt_node(unsigned long mem, unsigned long *p,
struct device_node *dad,
struct device_node ***allnextpp,
unsigned long fpsize);

/* Other Prototypes */
extern void finish_device_tree(void);
Expand Down

0 comments on commit 41f8800

Please sign in to comment.