[POWERPC] Allow pSeries to build without CONFIG_PCI
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / powerpc / kernel / prom.c
index c18dbe77fdc29863eb5a4f3e57c2f5f62e0f93dc..ef6bfb70b24add4f87b7eb654c4753c7fbb012d9 100644 (file)
@@ -719,6 +719,7 @@ static int __init early_init_dt_scan_chosen(unsigned long node,
                                            const char *uname, int depth, void *data)
 {
        unsigned long *lprop;
+       u32 *prop;
        unsigned long l;
        char *p;
 
@@ -760,6 +761,22 @@ static int __init early_init_dt_scan_chosen(unsigned long node,
                crashk_res.end = crashk_res.start + *lprop - 1;
 #endif
 
+#ifdef CONFIG_BLK_DEV_INITRD
+       DBG("Looking for initrd properties... ");
+       prop = of_get_flat_dt_prop(node, "linux,initrd-start", &l);
+       if (prop) {
+               initrd_start = (unsigned long)__va(of_read_ulong(prop, l/4));
+               prop = of_get_flat_dt_prop(node, "linux,initrd-end", &l);
+               if (prop) {
+                       initrd_end = (unsigned long)__va(of_read_ulong(prop, l/4));
+                       initrd_below_start_ok = 1;
+               } else {
+                       initrd_start = 0;
+               }
+       }
+       DBG("initrd_start=0x%lx  initrd_end=0x%lx\n", initrd_start, initrd_end);
+#endif /* CONFIG_BLK_DEV_INITRD */
+
        /* Retreive command line */
        p = of_get_flat_dt_prop(node, "bootargs", &l);
        if (p != NULL && l > 0)
@@ -804,6 +821,56 @@ static unsigned long __init dt_mem_next_cell(int s, cell_t **cellp)
        return of_read_ulong(p, s);
 }
 
+#ifdef CONFIG_PPC_PSERIES
+/*
+ * Interpret the ibm,dynamic-memory property in the
+ * /ibm,dynamic-reconfiguration-memory node.
+ * This contains a list of memory blocks along with NUMA affinity
+ * information.
+ */
+static int __init early_init_dt_scan_drconf_memory(unsigned long node)
+{
+       cell_t *dm, *ls;
+       unsigned long l, n;
+       unsigned long base, size, lmb_size, flags;
+
+       ls = (cell_t *)of_get_flat_dt_prop(node, "ibm,lmb-size", &l);
+       if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t))
+               return 0;
+       lmb_size = dt_mem_next_cell(dt_root_size_cells, &ls);
+
+       dm = (cell_t *)of_get_flat_dt_prop(node, "ibm,dynamic-memory", &l);
+       if (dm == NULL || l < sizeof(cell_t))
+               return 0;
+
+       n = *dm++;      /* number of entries */
+       if (l < (n * (dt_root_addr_cells + 4) + 1) * sizeof(cell_t))
+               return 0;
+
+       for (; n != 0; --n) {
+               base = dt_mem_next_cell(dt_root_addr_cells, &dm);
+               flags = dm[3];
+               /* skip DRC index, pad, assoc. list index, flags */
+               dm += 4;
+               /* skip this block if the reserved bit is set in flags (0x80)
+                  or if the block is not assigned to this partition (0x8) */
+               if ((flags & 0x80) || !(flags & 0x8))
+                       continue;
+               size = lmb_size;
+               if (iommu_is_off) {
+                       if (base >= 0x80000000ul)
+                               continue;
+                       if ((base + size) > 0x80000000ul)
+                               size = 0x80000000ul - base;
+               }
+               lmb_add(base, size);
+       }
+       lmb_dump_all();
+       return 0;
+}
+#else
+#define early_init_dt_scan_drconf_memory(node) 0
+#endif /* CONFIG_PPC_PSERIES */
 
 static int __init early_init_dt_scan_memory(unsigned long node,
                                            const char *uname, int depth, void *data)
@@ -812,6 +879,11 @@ static int __init early_init_dt_scan_memory(unsigned long node,
        cell_t *reg, *endp;
        unsigned long l;
 
+       /* Look for the ibm,dynamic-reconfiguration-memory node */
+       if (depth == 1 &&
+           strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0)
+               return early_init_dt_scan_drconf_memory(node);
+
        /* We are scanning "memory" nodes only */
        if (type == NULL) {
                /*
@@ -871,6 +943,12 @@ static void __init early_reserve_mem(void)
        self_size = initial_boot_params->totalsize;
        lmb_reserve(self_base, self_size);
 
+#ifdef CONFIG_BLK_DEV_INITRD
+       /* then reserve the initrd, if any */
+       if (initrd_start && (initrd_end > initrd_start))
+               lmb_reserve(__pa(initrd_start), initrd_end - initrd_start);
+#endif /* CONFIG_BLK_DEV_INITRD */
+
 #ifdef CONFIG_PPC32
        /* 
         * Handle the case where we might be booting from an old kexec
@@ -899,9 +977,6 @@ static void __init early_reserve_mem(void)
                size = *(reserve_map++);
                if (size == 0)
                        break;
-               /* skip if the reservation is for the blob */
-               if (base == self_base && size == self_size)
-                       continue;
                DBG("reserving: %llx -> %llx\n", base, size);
                lmb_reserve(base, size);
        }
@@ -936,7 +1011,7 @@ void __init early_init_devtree(void *params)
        of_scan_flat_dt(early_init_dt_scan_memory, NULL);
 
        /* Save command line for /proc/cmdline and then parse parameters */
-       strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
+       strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
        parse_early_param();
 
        /* Reserve LMB regions used by kernel, initrd, dt, etc... */
@@ -1166,8 +1241,7 @@ struct device_node *of_find_node_by_name(struct device_node *from,
                if (np->name != NULL && strcasecmp(np->name, name) == 0
                    && of_node_get(np))
                        break;
-       if (from)
-               of_node_put(from);
+       of_node_put(from);
        read_unlock(&devtree_lock);
        return np;
 }
@@ -1195,8 +1269,7 @@ struct device_node *of_find_node_by_type(struct device_node *from,
                if (np->type != 0 && strcasecmp(np->type, type) == 0
                    && of_node_get(np))
                        break;
-       if (from)
-               of_node_put(from);
+       of_node_put(from);
        read_unlock(&devtree_lock);
        return np;
 }
@@ -1230,8 +1303,7 @@ struct device_node *of_find_compatible_node(struct device_node *from,
                if (device_is_compatible(np, compatible) && of_node_get(np))
                        break;
        }
-       if (from)
-               of_node_put(from);
+       of_node_put(from);
        read_unlock(&devtree_lock);
        return np;
 }
@@ -1274,8 +1346,7 @@ struct device_node *of_find_node_by_phandle(phandle handle)
        for (np = allnodes; np != 0; np = np->allnext)
                if (np->linux_phandle == handle)
                        break;
-       if (np)
-               of_node_get(np);
+       of_node_get(np);
        read_unlock(&devtree_lock);
        return np;
 }
@@ -1298,8 +1369,7 @@ struct device_node *of_find_all_nodes(struct device_node *prev)
        for (; np != 0; np = np->allnext)
                if (of_node_get(np))
                        break;
-       if (prev)
-               of_node_put(prev);
+       of_node_put(prev);
        read_unlock(&devtree_lock);
        return np;
 }
@@ -1344,8 +1414,7 @@ struct device_node *of_get_next_child(const struct device_node *node,
        for (; next != 0; next = next->sibling)
                if (of_node_get(next))
                        break;
-       if (prev)
-               of_node_put(prev);
+       of_node_put(prev);
        read_unlock(&devtree_lock);
        return next;
 }
@@ -1550,6 +1619,7 @@ struct property *of_find_property(const struct device_node *np,
 
        return pp;
 }
+EXPORT_SYMBOL(of_find_property);
 
 /*
  * Find a property with a given name for a given node