Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / arch / powerpc / kernel / prom_init.c
index 1e95a9f..97d4bd9 100644 (file)
 #include <asm/sections.h>
 #include <asm/machdep.h>
 
-#ifdef CONFIG_LOGO_LINUX_CLUT224
 #include <linux/linux_logo.h>
-extern const struct linux_logo logo_linux_clut224;
-#endif
 
 /*
  * Properties whose value is longer than this get excluded from our
@@ -173,8 +170,8 @@ static unsigned long __initdata dt_string_start, dt_string_end;
 static unsigned long __initdata prom_initrd_start, prom_initrd_end;
 
 #ifdef CONFIG_PPC64
-static int __initdata iommu_force_on;
-static int __initdata ppc64_iommu_off;
+static int __initdata prom_iommu_force_on;
+static int __initdata prom_iommu_off;
 static unsigned long __initdata prom_tce_alloc_start;
 static unsigned long __initdata prom_tce_alloc_end;
 #endif
@@ -193,6 +190,8 @@ static int __initdata of_platform;
 
 static char __initdata prom_cmd_line[COMMAND_LINE_SIZE];
 
+static unsigned long __initdata prom_memory_limit;
+
 static unsigned long __initdata alloc_top;
 static unsigned long __initdata alloc_top_high;
 static unsigned long __initdata alloc_bottom;
@@ -205,8 +204,6 @@ static int __initdata mem_reserve_cnt;
 static cell_t __initdata regbuf[1024];
 
 
-#define MAX_CPU_THREADS 2
-
 /*
  * Error results ... some OF calls will return "-1" on error, some
  * will return 0, some will return either. To simplify, here are
@@ -558,6 +555,7 @@ static void __init early_cmdline_parse(void)
 {
        struct prom_t *_prom = &RELOC(prom);
        const char *opt;
+
        char *p;
        int l = 0;
 
@@ -580,11 +578,20 @@ static void __init early_cmdline_parse(void)
                while (*opt && *opt == ' ')
                        opt++;
                if (!strncmp(opt, RELOC("off"), 3))
-                       RELOC(ppc64_iommu_off) = 1;
+                       RELOC(prom_iommu_off) = 1;
                else if (!strncmp(opt, RELOC("force"), 5))
-                       RELOC(iommu_force_on) = 1;
+                       RELOC(prom_iommu_force_on) = 1;
        }
 #endif
+       opt = strstr(RELOC(prom_cmd_line), RELOC("mem="));
+       if (opt) {
+               opt += 4;
+               RELOC(prom_memory_limit) = prom_memparse(opt, (const char **)&opt);
+#ifdef CONFIG_PPC64
+               /* Align to 16 MB == size of ppc64 large page */
+               RELOC(prom_memory_limit) = ALIGN(RELOC(prom_memory_limit), 0x1000000);
+#endif
+       }
 }
 
 #ifdef CONFIG_PPC_PSERIES
@@ -618,6 +625,7 @@ static void __init early_cmdline_parse(void)
 #define OV1_PPC_2_03           0x10    /* set if we support PowerPC 2.03 */
 #define OV1_PPC_2_04           0x08    /* set if we support PowerPC 2.04 */
 #define OV1_PPC_2_05           0x04    /* set if we support PowerPC 2.05 */
+#define OV1_PPC_2_06           0x02    /* set if we support PowerPC 2.06 */
 
 /* Option vector 2: Open Firmware options supported */
 #define OV2_REAL_MODE          0x20    /* set if we want OF in real mode */
@@ -625,6 +633,7 @@ static void __init early_cmdline_parse(void)
 /* Option vector 3: processor options supported */
 #define OV3_FP                 0x80    /* floating point */
 #define OV3_VMX                        0x40    /* VMX/Altivec */
+#define OV3_DFP                        0x20    /* decimal FP */
 
 /* Option vector 5: PAPR/OF options supported */
 #define OV5_LPAR               0x80    /* logical partitioning supported */
@@ -632,6 +641,22 @@ static void __init early_cmdline_parse(void)
 /* ibm,dynamic-reconfiguration-memory property supported */
 #define OV5_DRCONF_MEMORY      0x20
 #define OV5_LARGE_PAGES                0x10    /* large pages supported */
+#define OV5_DONATE_DEDICATE_CPU 0x02   /* donate dedicated CPU support */
+/* PCIe/MSI support.  Without MSI full PCIe is not supported */
+#ifdef CONFIG_PCI_MSI
+#define OV5_MSI                        0x01    /* PCIe/MSI support */
+#else
+#define OV5_MSI                        0x00
+#endif /* CONFIG_PCI_MSI */
+#ifdef CONFIG_PPC_SMLPAR
+#define OV5_CMO                        0x80    /* Cooperative Memory Overcommitment */
+#else
+#define OV5_CMO                        0x00
+#endif
+#define OV5_TYPE1_AFFINITY     0x80    /* Type 1 NUMA affinity */
+
+/* Option Vector 6: IBM PAPR hints */
+#define OV6_LINUX              0x02    /* Linux is our OS */
 
 /*
  * The architecture vector has an array of PVR mask/value pairs,
@@ -640,17 +665,20 @@ static void __init early_cmdline_parse(void)
 static unsigned char ibm_architecture_vec[] = {
        W(0xfffe0000), W(0x003a0000),   /* POWER5/POWER5+ */
        W(0xffff0000), W(0x003e0000),   /* POWER6 */
+       W(0xffff0000), W(0x003f0000),   /* POWER7 */
+       W(0xffffffff), W(0x0f000003),   /* all 2.06-compliant */
+       W(0xffffffff), W(0x0f000002),   /* all 2.05-compliant */
        W(0xfffffffe), W(0x0f000001),   /* all 2.04-compliant and earlier */
-       5 - 1,                          /* 5 option vectors */
+       6 - 1,                          /* 6 option vectors */
 
        /* option vector 1: processor architectures supported */
-       3 - 1,                          /* length */
+       3 - 2,                          /* length */
        0,                              /* don't ignore, don't halt */
        OV1_PPC_2_00 | OV1_PPC_2_01 | OV1_PPC_2_02 | OV1_PPC_2_03 |
-       OV1_PPC_2_04 | OV1_PPC_2_05,
+       OV1_PPC_2_04 | OV1_PPC_2_05 | OV1_PPC_2_06,
 
        /* option vector 2: Open Firmware options supported */
-       34 - 1,                         /* length */
+       34 - 2,                         /* length */
        OV2_REAL_MODE,
        0, 0,
        W(0xffffffff),                  /* real_base */
@@ -658,24 +686,44 @@ static unsigned char ibm_architecture_vec[] = {
        W(0xffffffff),                  /* virt_base */
        W(0xffffffff),                  /* virt_size */
        W(0xffffffff),                  /* load_base */
-       W(64),                          /* 128MB min RMA */
+       W(64),                          /* 64MB min RMA */
        W(0xffffffff),                  /* full client load */
        0,                              /* min RMA percentage of total RAM */
        48,                             /* max log_2(hash table size) */
 
        /* option vector 3: processor options supported */
-       3 - 1,                          /* length */
+       3 - 2,                          /* length */
        0,                              /* don't ignore, don't halt */
-       OV3_FP | OV3_VMX,
+       OV3_FP | OV3_VMX | OV3_DFP,
 
        /* option vector 4: IBM PAPR implementation */
-       2 - 1,                          /* length */
+       2 - 2,                          /* length */
        0,                              /* don't halt */
 
        /* option vector 5: PAPR/OF options */
-       3 - 1,                          /* length */
+       13 - 2,                         /* length */
        0,                              /* don't ignore, don't halt */
-       OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES,
+       OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES | OV5_DRCONF_MEMORY |
+       OV5_DONATE_DEDICATE_CPU | OV5_MSI,
+       0,
+       OV5_CMO,
+       OV5_TYPE1_AFFINITY,
+       0,
+       0,
+       0,
+       /* WARNING: The offset of the "number of cores" field below
+        * must match by the macro below. Update the definition if
+        * the structure layout changes.
+        */
+#define IBM_ARCH_VEC_NRCORES_OFFSET    100
+       W(NR_CPUS),                     /* number of cores supported */
+
+       /* option vector 6: IBM PAPR hints */
+       4 - 2,                          /* length */
+       0,
+       0,
+       OV6_LINUX,
+
 };
 
 /* Old method - ELF header with PT_NOTE sections */
@@ -765,26 +813,86 @@ static struct fake_elf {
        }
 };
 
+static int __init prom_count_smt_threads(void)
+{
+       phandle node;
+       char type[64];
+       unsigned int plen;
+
+       /* Pick up th first CPU node we can find */
+       for (node = 0; prom_next_node(&node); ) {
+               type[0] = 0;
+               prom_getprop(node, "device_type", type, sizeof(type));
+
+               if (strcmp(type, RELOC("cpu")))
+                       continue;
+               /*
+                * There is an entry for each smt thread, each entry being
+                * 4 bytes long.  All cpus should have the same number of
+                * smt threads, so return after finding the first.
+                */
+               plen = prom_getproplen(node, "ibm,ppc-interrupt-server#s");
+               if (plen == PROM_ERROR)
+                       break;
+               plen >>= 2;
+               prom_debug("Found 0x%x smt threads per core\n", (unsigned long)plen);
+
+               /* Sanity check */
+               if (plen < 1 || plen > 64) {
+                       prom_printf("Threads per core 0x%x out of bounds, assuming 1\n",
+                                   (unsigned long)plen);
+                       return 1;
+               }
+               return plen;
+       }
+       prom_debug("No threads found, assuming 1 per core\n");
+
+       return 1;
+
+}
+
+
 static void __init prom_send_capabilities(void)
 {
        ihandle elfloader, root;
        prom_arg_t ret;
+       u32 *cores;
 
        root = call_prom("open", 1, 1, ADDR("/"));
        if (root != 0) {
+               /* We need to tell the FW about the number of cores we support.
+                *
+                * To do that, we count the number of threads on the first core
+                * (we assume this is the same for all cores) and use it to
+                * divide NR_CPUS.
+                */
+               cores = (u32 *)PTRRELOC(&ibm_architecture_vec[IBM_ARCH_VEC_NRCORES_OFFSET]);
+               if (*cores != NR_CPUS) {
+                       prom_printf("WARNING ! "
+                                   "ibm_architecture_vec structure inconsistent: 0x%x !\n",
+                                   *cores);
+               } else {
+                       *cores = NR_CPUS / prom_count_smt_threads();
+                       prom_printf("Max number of cores passed to firmware: 0x%x\n",
+                                   (unsigned long)*cores);
+               }
+
                /* try calling the ibm,client-architecture-support method */
+               prom_printf("Calling ibm,client-architecture-support...");
                if (call_prom_ret("call-method", 3, 2, &ret,
                                  ADDR("ibm,client-architecture-support"),
                                  root,
                                  ADDR(ibm_architecture_vec)) == 0) {
                        /* the call exists... */
                        if (ret)
-                               prom_printf("WARNING: ibm,client-architecture"
+                               prom_printf("\nWARNING: ibm,client-architecture"
                                            "-support call FAILED!\n");
                        call_prom("close", 1, 0, root);
+                       prom_printf(" done\n");
                        return;
                }
                call_prom("close", 1, 0, root);
+               prom_printf(" not implemented\n");
        }
 
        /* no ibm,client-architecture-support call, try the old way */
@@ -963,7 +1071,7 @@ static unsigned long __init prom_next_cell(int s, cell_t **cellp)
  * If problems seem to show up, it would be a good start to track
  * them down.
  */
-static void reserve_mem(u64 base, u64 size)
+static void __init reserve_mem(u64 base, u64 size)
 {
        u64 top = base + size;
        unsigned long cnt = RELOC(mem_reserve_cnt);
@@ -1069,6 +1177,29 @@ static void __init prom_init_mem(void)
        }
 
        /*
+        * If prom_memory_limit is set we reduce the upper limits *except* for
+        * alloc_top_high. This must be the real top of RAM so we can put
+        * TCE's up there.
+        */
+
+       RELOC(alloc_top_high) = RELOC(ram_top);
+
+       if (RELOC(prom_memory_limit)) {
+               if (RELOC(prom_memory_limit) <= RELOC(alloc_bottom)) {
+                       prom_printf("Ignoring mem=%x <= alloc_bottom.\n",
+                               RELOC(prom_memory_limit));
+                       RELOC(prom_memory_limit) = 0;
+               } else if (RELOC(prom_memory_limit) >= RELOC(ram_top)) {
+                       prom_printf("Ignoring mem=%x >= ram_top.\n",
+                               RELOC(prom_memory_limit));
+                       RELOC(prom_memory_limit) = 0;
+               } else {
+                       RELOC(ram_top) = RELOC(prom_memory_limit);
+                       RELOC(rmo_top) = min(RELOC(rmo_top), RELOC(prom_memory_limit));
+               }
+       }
+
+       /*
         * Setup our top alloc point, that is top of RMO or top of
         * segment 0 when running non-LPAR.
         * Some RS64 machines have buggy firmware where claims up at
@@ -1083,6 +1214,7 @@ static void __init prom_init_mem(void)
        RELOC(alloc_top_high) = RELOC(ram_top);
 
        prom_printf("memory layout at init:\n");
+       prom_printf("  memory_limit : %x (16 MB aligned)\n", RELOC(prom_memory_limit));
        prom_printf("  alloc_bottom : %x\n", RELOC(alloc_bottom));
        prom_printf("  alloc_top    : %x\n", RELOC(alloc_top));
        prom_printf("  alloc_top_hi : %x\n", RELOC(alloc_top_high));
@@ -1124,7 +1256,7 @@ static void __init prom_instantiate_rtas(void)
                return;
        }
 
-       prom_printf("instantiating rtas at 0x%x ...", base);
+       prom_printf("instantiating rtas at 0x%x...", base);
 
        if (call_prom_ret("call-method", 3, 2, &entry,
                          ADDR("instantiate-rtas"),
@@ -1165,7 +1297,7 @@ static void __init prom_initialize_tce_table(void)
        u64 local_alloc_top, local_alloc_bottom;
        u64 i;
 
-       if (RELOC(ppc64_iommu_off))
+       if (RELOC(prom_iommu_off))
                return;
 
        prom_debug("starting prom_initialize_tce_table\n");
@@ -1187,7 +1319,7 @@ static void __init prom_initialize_tce_table(void)
                if ((type[0] == 0) || (strstr(type, RELOC("pci")) == NULL))
                        continue;
 
-               /* Keep the old logic in tack to avoid regression. */
+               /* Keep the old logic intact to avoid regression. */
                if (compatible[0] != 0) {
                        if ((strstr(compatible, RELOC("python")) == NULL) &&
                            (strstr(compatible, RELOC("Speedwagon")) == NULL) &&
@@ -1232,7 +1364,7 @@ static void __init prom_initialize_tce_table(void)
                        local_alloc_bottom = base;
 
                /* It seems OF doesn't null-terminate the path :-( */
-               memset(path, 0, sizeof(path));
+               memset(path, 0, PROM_SCRATCH_SIZE);
                /* Call OF to setup the TCE hardware */
                if (call_prom("package-to-path", 3, 1, node,
                              path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) {
@@ -1251,7 +1383,7 @@ static void __init prom_initialize_tce_table(void)
                /* Initialize the table to have a one-to-one mapping
                 * over the allocated size.
                 */
-               tce_entryp = (unsigned long *)base;
+               tce_entryp = (u64 *)base;
                for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) {
                        tce_entry = (i << PAGE_SHIFT);
                        tce_entry |= 0x3;
@@ -1301,10 +1433,6 @@ static void __init prom_initialize_tce_table(void)
  *
  * -- Cort
  */
-extern void __secondary_hold(void);
-extern unsigned long __secondary_hold_spinloop;
-extern unsigned long __secondary_hold_acknowledge;
-
 /*
  * We want to reference the copy of __secondary_hold_* in the
  * 0 - 0x100 address range
@@ -1317,22 +1445,12 @@ static void __init prom_hold_cpus(void)
        unsigned int reg;
        phandle node;
        char type[64];
-       int cpuid = 0;
-       unsigned int interrupt_server[MAX_CPU_THREADS];
-       unsigned int cpu_threads, hw_cpu_num;
-       int propsize;
        struct prom_t *_prom = &RELOC(prom);
        unsigned long *spinloop
                = (void *) LOW_ADDR(__secondary_hold_spinloop);
        unsigned long *acknowledge
                = (void *) LOW_ADDR(__secondary_hold_acknowledge);
-#ifdef CONFIG_PPC64
-       /* __secondary_hold is actually a descriptor, not the text address */
-       unsigned long secondary_hold
-               = __pa(*PTRRELOC((unsigned long *)__secondary_hold));
-#else
        unsigned long secondary_hold = LOW_ADDR(__secondary_hold);
-#endif
 
        prom_debug("prom_hold_cpus: start...\n");
        prom_debug("    1) spinloop       = 0x%x\n", (unsigned long)spinloop);
@@ -1364,7 +1482,6 @@ static void __init prom_hold_cpus(void)
                reg = -1;
                prom_getprop(node, "reg", &reg, sizeof(reg));
 
-               prom_debug("\ncpuid        = 0x%x\n", cpuid);
                prom_debug("cpu hw idx   = 0x%x\n", reg);
 
                /* Init the acknowledge var which will be reset by
@@ -1373,28 +1490,9 @@ static void __init prom_hold_cpus(void)
                 */
                *acknowledge = (unsigned long)-1;
 
-               propsize = prom_getprop(node, "ibm,ppc-interrupt-server#s",
-                                       &interrupt_server,
-                                       sizeof(interrupt_server));
-               if (propsize < 0) {
-                       /* no property.  old hardware has no SMT */
-                       cpu_threads = 1;
-                       interrupt_server[0] = reg; /* fake it with phys id */
-               } else {
-                       /* We have a threaded processor */
-                       cpu_threads = propsize / sizeof(u32);
-                       if (cpu_threads > MAX_CPU_THREADS) {
-                               prom_printf("SMT: too many threads!\n"
-                                           "SMT: found %x, max is %x\n",
-                                           cpu_threads, MAX_CPU_THREADS);
-                               cpu_threads = 1; /* ToDo: panic? */
-                       }
-               }
-
-               hw_cpu_num = interrupt_server[0];
-               if (hw_cpu_num != _prom->cpu) {
+               if (reg != _prom->cpu) {
                        /* Primary Thread of non-boot cpu */
-                       prom_printf("%x : starting cpu hw idx %x... ", cpuid, reg);
+                       prom_printf("starting cpu hw idx %x... ", reg);
                        call_prom("start-cpu", 3, 0, node,
                                  secondary_hold, reg);
 
@@ -1409,17 +1507,10 @@ static void __init prom_hold_cpus(void)
                }
 #ifdef CONFIG_SMP
                else
-                       prom_printf("%x : boot cpu     %x\n", cpuid, reg);
+                       prom_printf("boot cpu hw idx %x\n", reg);
 #endif /* CONFIG_SMP */
-
-               /* Reserve cpu #s for secondary threads.   They start later. */
-               cpuid += cpu_threads;
        }
 
-       if (cpuid > NR_CPUS)
-               prom_printf("WARNING: maximum CPUs (" __stringify(NR_CPUS)
-                           ") exceeded: ignoring extras\n");
-
        prom_debug("prom_hold_cpus: end...\n");
 }
 
@@ -1573,7 +1664,7 @@ static int __init prom_find_machine_type(void)
                return PLATFORM_GENERIC;
        x = prom_getproplen(rtas, "ibm,hypertas-functions");
        if (x != PROM_ERROR) {
-               prom_printf("Hypertas detected, assuming LPAR !\n");
+               prom_debug("Hypertas detected, assuming LPAR !\n");
                return PLATFORM_PSERIES_LPAR;
        }
        return PLATFORM_PSERIES;
@@ -1622,7 +1713,7 @@ static void __init prom_check_displays(void)
        };
        const unsigned char *clut;
 
-       prom_printf("Looking for displays\n");
+       prom_debug("Looking for displays\n");
        for (node = 0; prom_next_node(&node); ) {
                memset(type, 0, sizeof(type));
                prom_getprop(node, "device_type", type, sizeof(type));
@@ -1640,7 +1731,7 @@ static void __init prom_check_displays(void)
                if (call_prom("package-to-path", 3, 1, node, path,
                              PROM_SCRATCH_SIZE-10) == PROM_ERROR)
                        continue;
-               prom_printf("found display   : %s, opening ... ", path);
+               prom_printf("found display   : %s, opening... ", path);
                
                ih = call_prom("open", 1, 1, path);
                if (ih == 0) {
@@ -1990,12 +2081,22 @@ static void __init flatten_device_tree(void)
 static void __init fixup_device_tree_maple(void)
 {
        phandle isa;
+       u32 rloc = 0x01002000; /* IO space; PCI device = 4 */
        u32 isa_ranges[6];
-
-       isa = call_prom("finddevice", 1, 1, ADDR("/ht@0/isa@4"));
+       char *name;
+
+       name = "/ht@0/isa@4";
+       isa = call_prom("finddevice", 1, 1, ADDR(name));
+       if (!PHANDLE_VALID(isa)) {
+               name = "/ht@0/isa@6";
+               isa = call_prom("finddevice", 1, 1, ADDR(name));
+               rloc = 0x01003000; /* IO space; PCI device = 6 */
+       }
        if (!PHANDLE_VALID(isa))
                return;
 
+       if (prom_getproplen(isa, "ranges") != 12)
+               return;
        if (prom_getprop(isa, "ranges", isa_ranges, sizeof(isa_ranges))
                == PROM_ERROR)
                return;
@@ -2005,19 +2106,113 @@ static void __init fixup_device_tree_maple(void)
                isa_ranges[2] != 0x00010000)
                return;
 
-       prom_printf("fixing up bogus ISA range on Maple...\n");
+       prom_printf("Fixing up bogus ISA range on Maple/Apache...\n");
 
        isa_ranges[0] = 0x1;
        isa_ranges[1] = 0x0;
-       isa_ranges[2] = 0x01002000; /* IO space; PCI device = 4 */
+       isa_ranges[2] = rloc;
        isa_ranges[3] = 0x0;
        isa_ranges[4] = 0x0;
        isa_ranges[5] = 0x00010000;
-       prom_setprop(isa, "/ht@0/isa@4", "ranges",
+       prom_setprop(isa, name, "ranges",
                        isa_ranges, sizeof(isa_ranges));
 }
+
+#define CPC925_MC_START                0xf8000000
+#define CPC925_MC_LENGTH       0x1000000
+/* The values for memory-controller don't have right number of cells */
+static void __init fixup_device_tree_maple_memory_controller(void)
+{
+       phandle mc;
+       u32 mc_reg[4];
+       char *name = "/hostbridge@f8000000";
+       struct prom_t *_prom = &RELOC(prom);
+       u32 ac, sc;
+
+       mc = call_prom("finddevice", 1, 1, ADDR(name));
+       if (!PHANDLE_VALID(mc))
+               return;
+
+       if (prom_getproplen(mc, "reg") != 8)
+               return;
+
+       prom_getprop(_prom->root, "#address-cells", &ac, sizeof(ac));
+       prom_getprop(_prom->root, "#size-cells", &sc, sizeof(sc));
+       if ((ac != 2) || (sc != 2))
+               return;
+
+       if (prom_getprop(mc, "reg", mc_reg, sizeof(mc_reg)) == PROM_ERROR)
+               return;
+
+       if (mc_reg[0] != CPC925_MC_START || mc_reg[1] != CPC925_MC_LENGTH)
+               return;
+
+       prom_printf("Fixing up bogus hostbridge on Maple...\n");
+
+       mc_reg[0] = 0x0;
+       mc_reg[1] = CPC925_MC_START;
+       mc_reg[2] = 0x0;
+       mc_reg[3] = CPC925_MC_LENGTH;
+       prom_setprop(mc, name, "reg", mc_reg, sizeof(mc_reg));
+}
 #else
 #define fixup_device_tree_maple()
+#define fixup_device_tree_maple_memory_controller()
+#endif
+
+#ifdef CONFIG_PPC_CHRP
+/*
+ * Pegasos and BriQ lacks the "ranges" property in the isa node
+ * Pegasos needs decimal IRQ 14/15, not hexadecimal
+ * Pegasos has the IDE configured in legacy mode, but advertised as native
+ */
+static void __init fixup_device_tree_chrp(void)
+{
+       phandle ph;
+       u32 prop[6];
+       u32 rloc = 0x01006000; /* IO space; PCI device = 12 */
+       char *name;
+       int rc;
+
+       name = "/pci@80000000/isa@c";
+       ph = call_prom("finddevice", 1, 1, ADDR(name));
+       if (!PHANDLE_VALID(ph)) {
+               name = "/pci@ff500000/isa@6";
+               ph = call_prom("finddevice", 1, 1, ADDR(name));
+               rloc = 0x01003000; /* IO space; PCI device = 6 */
+       }
+       if (PHANDLE_VALID(ph)) {
+               rc = prom_getproplen(ph, "ranges");
+               if (rc == 0 || rc == PROM_ERROR) {
+                       prom_printf("Fixing up missing ISA range on Pegasos...\n");
+
+                       prop[0] = 0x1;
+                       prop[1] = 0x0;
+                       prop[2] = rloc;
+                       prop[3] = 0x0;
+                       prop[4] = 0x0;
+                       prop[5] = 0x00010000;
+                       prom_setprop(ph, name, "ranges", prop, sizeof(prop));
+               }
+       }
+
+       name = "/pci@80000000/ide@C,1";
+       ph = call_prom("finddevice", 1, 1, ADDR(name));
+       if (PHANDLE_VALID(ph)) {
+               prom_printf("Fixing up IDE interrupt on Pegasos...\n");
+               prop[0] = 14;
+               prop[1] = 0x0;
+               prom_setprop(ph, name, "interrupts", prop, 2*sizeof(u32));
+               prom_printf("Fixing up IDE class-code on Pegasos...\n");
+               rc = prom_getprop(ph, "class-code", prop, sizeof(u32));
+               if (rc == sizeof(u32)) {
+                       prop[0] &= ~0x5;
+                       prom_setprop(ph, name, "class-code", prop, sizeof(u32));
+               }
+       }
+}
+#else
+#define fixup_device_tree_chrp()
 #endif
 
 #if defined(CONFIG_PPC64) && defined(CONFIG_PPC_PMAC)
@@ -2064,15 +2259,154 @@ static void __init fixup_device_tree_pmac(void)
 #define fixup_device_tree_pmac()
 #endif
 
+#ifdef CONFIG_PPC_EFIKA
+/*
+ * The MPC5200 FEC driver requires an phy-handle property to tell it how
+ * to talk to the phy.  If the phy-handle property is missing, then this
+ * function is called to add the appropriate nodes and link it to the
+ * ethernet node.
+ */
+static void __init fixup_device_tree_efika_add_phy(void)
+{
+       u32 node;
+       char prop[64];
+       int rv;
+
+       /* Check if /builtin/ethernet exists - bail if it doesn't */
+       node = call_prom("finddevice", 1, 1, ADDR("/builtin/ethernet"));
+       if (!PHANDLE_VALID(node))
+               return;
+
+       /* Check if the phy-handle property exists - bail if it does */
+       rv = prom_getprop(node, "phy-handle", prop, sizeof(prop));
+       if (!rv)
+               return;
+
+       /*
+        * At this point the ethernet device doesn't have a phy described.
+        * Now we need to add the missing phy node and linkage
+        */
+
+       /* Check for an MDIO bus node - if missing then create one */
+       node = call_prom("finddevice", 1, 1, ADDR("/builtin/mdio"));
+       if (!PHANDLE_VALID(node)) {
+               prom_printf("Adding Ethernet MDIO node\n");
+               call_prom("interpret", 1, 1,
+                       " s\" /builtin\" find-device"
+                       " new-device"
+                               " 1 encode-int s\" #address-cells\" property"
+                               " 0 encode-int s\" #size-cells\" property"
+                               " s\" mdio\" device-name"
+                               " s\" fsl,mpc5200b-mdio\" encode-string"
+                               " s\" compatible\" property"
+                               " 0xf0003000 0x400 reg"
+                               " 0x2 encode-int"
+                               " 0x5 encode-int encode+"
+                               " 0x3 encode-int encode+"
+                               " s\" interrupts\" property"
+                       " finish-device");
+       };
+
+       /* Check for a PHY device node - if missing then create one and
+        * give it's phandle to the ethernet node */
+       node = call_prom("finddevice", 1, 1,
+                        ADDR("/builtin/mdio/ethernet-phy"));
+       if (!PHANDLE_VALID(node)) {
+               prom_printf("Adding Ethernet PHY node\n");
+               call_prom("interpret", 1, 1,
+                       " s\" /builtin/mdio\" find-device"
+                       " new-device"
+                               " s\" ethernet-phy\" device-name"
+                               " 0x10 encode-int s\" reg\" property"
+                               " my-self"
+                               " ihandle>phandle"
+                       " finish-device"
+                       " s\" /builtin/ethernet\" find-device"
+                               " encode-int"
+                               " s\" phy-handle\" property"
+                       " device-end");
+       }
+}
+
+static void __init fixup_device_tree_efika(void)
+{
+       int sound_irq[3] = { 2, 2, 0 };
+       int bcomm_irq[3*16] = { 3,0,0, 3,1,0, 3,2,0, 3,3,0,
+                               3,4,0, 3,5,0, 3,6,0, 3,7,0,
+                               3,8,0, 3,9,0, 3,10,0, 3,11,0,
+                               3,12,0, 3,13,0, 3,14,0, 3,15,0 };
+       u32 node;
+       char prop[64];
+       int rv, len;
+
+       /* Check if we're really running on a EFIKA */
+       node = call_prom("finddevice", 1, 1, ADDR("/"));
+       if (!PHANDLE_VALID(node))
+               return;
+
+       rv = prom_getprop(node, "model", prop, sizeof(prop));
+       if (rv == PROM_ERROR)
+               return;
+       if (strcmp(prop, "EFIKA5K2"))
+               return;
+
+       prom_printf("Applying EFIKA device tree fixups\n");
+
+       /* Claiming to be 'chrp' is death */
+       node = call_prom("finddevice", 1, 1, ADDR("/"));
+       rv = prom_getprop(node, "device_type", prop, sizeof(prop));
+       if (rv != PROM_ERROR && (strcmp(prop, "chrp") == 0))
+               prom_setprop(node, "/", "device_type", "efika", sizeof("efika"));
+
+       /* CODEGEN,description is exposed in /proc/cpuinfo so
+          fix that too */
+       rv = prom_getprop(node, "CODEGEN,description", prop, sizeof(prop));
+       if (rv != PROM_ERROR && (strstr(prop, "CHRP")))
+               prom_setprop(node, "/", "CODEGEN,description",
+                            "Efika 5200B PowerPC System",
+                            sizeof("Efika 5200B PowerPC System"));
+
+       /* Fixup bestcomm interrupts property */
+       node = call_prom("finddevice", 1, 1, ADDR("/builtin/bestcomm"));
+       if (PHANDLE_VALID(node)) {
+               len = prom_getproplen(node, "interrupts");
+               if (len == 12) {
+                       prom_printf("Fixing bestcomm interrupts property\n");
+                       prom_setprop(node, "/builtin/bestcom", "interrupts",
+                                    bcomm_irq, sizeof(bcomm_irq));
+               }
+       }
+
+       /* Fixup sound interrupts property */
+       node = call_prom("finddevice", 1, 1, ADDR("/builtin/sound"));
+       if (PHANDLE_VALID(node)) {
+               rv = prom_getprop(node, "interrupts", prop, sizeof(prop));
+               if (rv == PROM_ERROR) {
+                       prom_printf("Adding sound interrupts property\n");
+                       prom_setprop(node, "/builtin/sound", "interrupts",
+                                    sound_irq, sizeof(sound_irq));
+               }
+       }
+
+       /* Make sure ethernet phy-handle property exists */
+       fixup_device_tree_efika_add_phy();
+}
+#else
+#define fixup_device_tree_efika()
+#endif
+
 static void __init fixup_device_tree(void)
 {
        fixup_device_tree_maple();
+       fixup_device_tree_maple_memory_controller();
+       fixup_device_tree_chrp();
        fixup_device_tree_pmac();
+       fixup_device_tree_efika();
 }
 
 static void __init prom_find_boot_cpu(void)
 {
-               struct prom_t *_prom = &RELOC(prom);
+       struct prom_t *_prom = &RELOC(prom);
        u32 getprop_rval;
        ihandle prom_cpu;
        phandle cpu_pkg;
@@ -2092,7 +2426,7 @@ static void __init prom_find_boot_cpu(void)
 static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
 {
 #ifdef CONFIG_BLK_DEV_INITRD
-               struct prom_t *_prom = &RELOC(prom);
+       struct prom_t *_prom = &RELOC(prom);
 
        if (r3 && r4 && r4 != 0xdeadbeef) {
                unsigned long val;
@@ -2123,13 +2457,14 @@ static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
 
 unsigned long __init prom_init(unsigned long r3, unsigned long r4,
                               unsigned long pp,
-                              unsigned long r6, unsigned long r7)
+                              unsigned long r6, unsigned long r7,
+                              unsigned long kbase)
 {      
-               struct prom_t *_prom;
+       struct prom_t *_prom;
        unsigned long hdr;
-       unsigned long offset = reloc_offset();
 
 #ifdef CONFIG_PPC32
+       unsigned long offset = reloc_offset();
        reloc_got2(offset);
 #endif
 
@@ -2157,15 +2492,19 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
         */
        prom_init_stdout();
 
+       prom_printf("Preparing to boot %s", RELOC(linux_banner));
+
        /*
         * Get default machine type. At this point, we do not differentiate
         * between pSeries SMP and pSeries LPAR
         */
        RELOC(of_platform) = prom_find_machine_type();
 
+#ifndef CONFIG_RELOCATABLE
        /* Bail if this is a kdump kernel. */
        if (PHYSICAL_START > 0)
                prom_panic("Error: You can't boot a kdump kernel from OF!\n");
+#endif
 
        /*
         * Check for an initrd
@@ -2184,8 +2523,8 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
        /*
         * Copy the CPU hold code
         */
-               if (RELOC(of_platform) != PLATFORM_POWERMAC)
-                       copy_and_flush(0, KERNELBASE + offset, 0x100, 0);
+       if (RELOC(of_platform) != PLATFORM_POWERMAC)
+               copy_and_flush(0, kbase, 0x100, 0);
 
        /*
         * Do early parsing of command line
@@ -2230,12 +2569,16 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
        /*
         * Fill in some infos for use by the kernel later on
         */
+       if (RELOC(prom_memory_limit))
+               prom_setprop(_prom->chosen, "/chosen", "linux,memory-limit",
+                            &RELOC(prom_memory_limit),
+                            sizeof(prom_memory_limit));
 #ifdef CONFIG_PPC64
-       if (RELOC(ppc64_iommu_off))
+       if (RELOC(prom_iommu_off))
                prom_setprop(_prom->chosen, "/chosen", "linux,iommu-off",
                             NULL, 0);
 
-       if (RELOC(iommu_force_on))
+       if (RELOC(prom_iommu_force_on))
                prom_setprop(_prom->chosen, "/chosen", "linux,iommu-force-on",
                             NULL, 0);
 
@@ -2257,7 +2600,7 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
        /*
         * Now finally create the flattened device-tree
         */
-       prom_printf("copying OF device tree ...\n");
+       prom_printf("copying OF device tree...\n");
        flatten_device_tree();
 
        /*
@@ -2272,7 +2615,7 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
         * Call OF "quiesce" method to shut down pending DMA's from
         * devices etc...
         */
-       prom_printf("Calling quiesce ...\n");
+       prom_printf("Calling quiesce...\n");
        call_prom("quiesce", 0, 0);
 
        /*
@@ -2288,7 +2631,7 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
        reloc_got2(-offset);
 #endif
 
-       __start(hdr, KERNELBASE + offset, 0);
+       __start(hdr, kbase, 0);
 
        return 0;
 }