*/
#include <linux/kernel.h>
-#include <linux/lmb.h>
#include <linux/initrd.h>
#include <linux/of.h>
#include <linux/of_fdt.h>
-
+#include <linux/string.h>
+#include <linux/errno.h>
#ifdef CONFIG_PPC
#include <asm/machdep.h>
#endif /* CONFIG_PPC */
+#include <asm/page.h>
+
int __initdata dt_root_addr_cells;
int __initdata dt_root_size_cells;
char *find_flat_dt_string(u32 offset)
{
return ((char *)initial_boot_params) +
- initial_boot_params->off_dt_strings + offset;
+ be32_to_cpu(initial_boot_params->off_dt_strings) + offset;
}
/**
void *data)
{
unsigned long p = ((unsigned long)initial_boot_params) +
- initial_boot_params->off_dt_struct;
+ be32_to_cpu(initial_boot_params->off_dt_struct);
int rc = 0;
int depth = -1;
do {
- u32 tag = *((u32 *)p);
+ u32 tag = be32_to_cpup((__be32 *)p);
char *pathp;
p += 4;
if (tag == OF_DT_END)
break;
if (tag == OF_DT_PROP) {
- u32 sz = *((u32 *)p);
+ u32 sz = be32_to_cpup((__be32 *)p);
p += 8;
- if (initial_boot_params->version < 0x10)
+ if (be32_to_cpu(initial_boot_params->version) < 0x10)
p = _ALIGN(p, sz >= 8 ? 8 : 4);
p += sz;
p = _ALIGN(p, 4);
unsigned long __init of_get_flat_dt_root(void)
{
unsigned long p = ((unsigned long)initial_boot_params) +
- initial_boot_params->off_dt_struct;
+ be32_to_cpu(initial_boot_params->off_dt_struct);
- while (*((u32 *)p) == OF_DT_NOP)
+ while (be32_to_cpup((__be32 *)p) == OF_DT_NOP)
p += 4;
- BUG_ON(*((u32 *)p) != OF_DT_BEGIN_NODE);
+ BUG_ON(be32_to_cpup((__be32 *)p) != OF_DT_BEGIN_NODE);
p += 4;
return _ALIGN(p + strlen((char *)p) + 1, 4);
}
unsigned long p = node;
do {
- u32 tag = *((u32 *)p);
+ u32 tag = be32_to_cpup((__be32 *)p);
u32 sz, noff;
const char *nstr;
if (tag != OF_DT_PROP)
return NULL;
- sz = *((u32 *)p);
- noff = *((u32 *)(p + 4));
+ sz = be32_to_cpup((__be32 *)p);
+ noff = be32_to_cpup((__be32 *)(p + 4));
p += 8;
- if (initial_boot_params->version < 0x10)
+ if (be32_to_cpu(initial_boot_params->version) < 0x10)
p = _ALIGN(p, sz >= 8 ? 8 : 4);
nstr = find_flat_dt_string(noff);
int has_name = 0;
int new_format = 0;
- tag = *((u32 *)(*p));
+ tag = be32_to_cpup((__be32 *)(*p));
if (tag != OF_DT_BEGIN_NODE) {
pr_err("Weird tag at start of node: %x\n", tag);
return mem;
u32 sz, noff;
char *pname;
- tag = *((u32 *)(*p));
+ tag = be32_to_cpup((__be32 *)(*p));
if (tag == OF_DT_NOP) {
*p += 4;
continue;
if (tag != OF_DT_PROP)
break;
*p += 4;
- sz = *((u32 *)(*p));
- noff = *((u32 *)((*p) + 4));
+ sz = be32_to_cpup((__be32 *)(*p));
+ noff = be32_to_cpup((__be32 *)((*p) + 4));
*p += 8;
- if (initial_boot_params->version < 0x10)
+ if (be32_to_cpu(initial_boot_params->version) < 0x10)
*p = _ALIGN(*p, sz >= 8 ? 8 : 4);
pname = find_flat_dt_string(noff);
pp = unflatten_dt_alloc(&mem, sizeof(struct property),
__alignof__(struct property));
if (allnextpp) {
- if (strcmp(pname, "linux,phandle") == 0) {
+ /* We accept flattened tree phandles either in
+ * ePAPR-style "phandle" properties, or the
+ * legacy "linux,phandle" properties. If both
+ * appear and have different values, things
+ * will get weird. Don't do that. */
+ if ((strcmp(pname, "phandle") == 0) ||
+ (strcmp(pname, "linux,phandle") == 0)) {
if (np->phandle == 0)
np->phandle = *((u32 *)*p);
}
+ /* And we process the "ibm,phandle" property
+ * used in pSeries dynamic device tree
+ * stuff */
if (strcmp(pname, "ibm,phandle") == 0)
np->phandle = *((u32 *)*p);
pp->name = pname;
if (!np->type)
np->type = "<NULL>";
}
- while (tag == OF_DT_BEGIN_NODE) {
- mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize);
- tag = *((u32 *)(*p));
+ while (tag == OF_DT_BEGIN_NODE || tag == OF_DT_NOP) {
+ if (tag == OF_DT_NOP)
+ *p += 4;
+ else
+ mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize);
+ tag = be32_to_cpup((__be32 *)(*p));
}
if (tag != OF_DT_END_NODE) {
pr_err("Weird tag at end of node: %x\n", tag);
void __init early_init_dt_check_for_initrd(unsigned long node)
{
unsigned long start, end, len;
- u32 *prop;
+ __be32 *prop;
pr_debug("Looking for initrd properties... ");
int __init early_init_dt_scan_root(unsigned long node, const char *uname,
int depth, void *data)
{
- u32 *prop;
+ __be32 *prop;
if (depth != 0)
return 0;
+ dt_root_size_cells = OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
+ dt_root_addr_cells = OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
+
prop = of_get_flat_dt_prop(node, "#size-cells", NULL);
- dt_root_size_cells = prop ? *prop : OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
+ if (prop)
+ dt_root_size_cells = be32_to_cpup(prop);
pr_debug("dt_root_size_cells = %x\n", dt_root_size_cells);
prop = of_get_flat_dt_prop(node, "#address-cells", NULL);
- dt_root_addr_cells = prop ? *prop : OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
+ if (prop)
+ dt_root_addr_cells = be32_to_cpup(prop);
pr_debug("dt_root_addr_cells = %x\n", dt_root_addr_cells);
/* break now */
return 1;
}
-u64 __init dt_mem_next_cell(int s, u32 **cellp)
+u64 __init dt_mem_next_cell(int s, __be32 **cellp)
{
- u32 *p = *cellp;
+ __be32 *p = *cellp;
*cellp = p + s;
return of_read_number(p, s);
/* First pass, scan for size */
start = ((unsigned long)initial_boot_params) +
- 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 = (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 = early_init_dt_alloc_memory_arch(size + 4,
+ __alignof__(struct device_node));
mem = (unsigned long) __va(mem);
- ((u32 *)mem)[size / 4] = 0xdeadbeef;
+ ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef);
pr_debug(" unflattening %lx...\n", mem);
/* Second pass, do actual unflattening */
start = ((unsigned long)initial_boot_params) +
- initial_boot_params->off_dt_struct;
+ be32_to_cpu(initial_boot_params->off_dt_struct);
unflatten_dt_node(mem, &start, NULL, &allnextp, 0);
- if (*((u32 *)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));
- if (((u32 *)mem)[size / 4] != 0xdeadbeef)
+ if (be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeef)
pr_warning("End of tree marker overwritten: %08x\n",
- ((u32 *)mem)[size / 4]);
+ be32_to_cpu(((__be32 *)mem)[size / 4]));
*allnextp = NULL;
/* Get pointer to OF "/chosen" node for use everywhere */