[SCSI] libfc: fixes unnecessary seq id jump
[safe/jmp/linux-2.6] / drivers / of / fdt.c
index 5c5f03e..dee4fb5 100644 (file)
  */
 
 #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;
 
@@ -28,7 +30,7 @@ struct boot_param_header *initial_boot_params;
 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;
 }
 
 /**
@@ -46,7 +48,7 @@ int __init of_scan_flat_dt(int (*it)(unsigned long node,
                           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;
 
@@ -66,7 +68,7 @@ int __init of_scan_flat_dt(int (*it)(unsigned long node,
                if (tag == OF_DT_PROP) {
                        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);
@@ -101,7 +103,7 @@ int __init of_scan_flat_dt(int (*it)(unsigned long node,
 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 (be32_to_cpup((__be32 *)p) == OF_DT_NOP)
                p += 4;
@@ -135,7 +137,7 @@ void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
                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);
@@ -296,7 +298,7 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
                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);
@@ -310,10 +312,19 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
                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;
@@ -365,8 +376,11 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
                if (!np->type)
                        np->type = "<NULL>";
        }
-       while (tag == OF_DT_BEGIN_NODE) {
-               mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize);
+       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) {
@@ -544,14 +558,15 @@ void __init unflatten_device_tree(void)
 
        /* 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);
 
        ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef);
@@ -560,7 +575,7 @@ void __init unflatten_device_tree(void)
 
        /* 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 (be32_to_cpup((__be32 *)start) != OF_DT_END)
                pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start));