[PATCH] powerpc: merge code values for identifying platforms
[pandora-kernel.git] / arch / powerpc / kernel / prom.c
index 2eccd0e..1bf3642 100644 (file)
@@ -48,9 +48,6 @@
 #include <asm/machdep.h>
 #include <asm/pSeries_reconfig.h>
 #include <asm/pci-bridge.h>
-#ifdef CONFIG_PPC64
-#include <asm/systemcfg.h>
-#endif
 
 #ifdef DEBUG
 #define DBG(fmt...) printk(KERN_ERR fmt)
@@ -391,7 +388,7 @@ static int __devinit finish_node_interrupts(struct device_node *np,
 
 #ifdef CONFIG_PPC64
                /* We offset irq numbers for the u3 MPIC by 128 in PowerMac */
-               if (systemcfg->platform == PLATFORM_POWERMAC && ic && ic->parent) {
+               if (_machine == PLATFORM_POWERMAC && ic && ic->parent) {
                        char *name = get_property(ic->parent, "name", NULL);
                        if (name && !strcmp(name, "u3"))
                                np->intrs[intrcount].line += 128;
@@ -724,10 +721,10 @@ static inline char *find_flat_dt_string(u32 offset)
  * used to extract the memory informations at boot before we can
  * unflatten the tree
  */
-static int __init scan_flat_dt(int (*it)(unsigned long node,
-                                        const char *uname, int depth,
-                                        void *data),
-                              void *data)
+int __init of_scan_flat_dt(int (*it)(unsigned long node,
+                                    const char *uname, int depth,
+                                    void *data),
+                          void *data)
 {
        unsigned long p = ((unsigned long)initial_boot_params) +
                initial_boot_params->off_dt_struct;
@@ -784,8 +781,8 @@ static int __init scan_flat_dt(int (*it)(unsigned long node,
  * This  function can be used within scan_flattened_dt callback to get
  * access to properties
  */
-static void* __init get_flat_dt_prop(unsigned long node, const char *name,
-                                    unsigned long *size)
+void* __init of_get_flat_dt_prop(unsigned long node, const char *name,
+                                unsigned long *size)
 {
        unsigned long p = node;
 
@@ -1087,7 +1084,7 @@ void __init unflatten_device_tree(void)
 static int __init early_init_dt_scan_cpus(unsigned long node,
                                          const char *uname, int depth, void *data)
 {
-       char *type = get_flat_dt_prop(node, "device_type", NULL);
+       char *type = of_get_flat_dt_prop(node, "device_type", NULL);
        u32 *prop;
        unsigned long size = 0;
 
@@ -1095,19 +1092,6 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
        if (type == NULL || strcmp(type, "cpu") != 0)
                return 0;
 
-#ifdef CONFIG_PPC_PSERIES
-       /* On LPAR, look for the first ibm,pft-size property for the  hash table size
-        */
-       if (systemcfg->platform == PLATFORM_PSERIES_LPAR && ppc64_pft_size == 0) {
-               u32 *pft_size;
-               pft_size = get_flat_dt_prop(node, "ibm,pft-size", NULL);
-               if (pft_size != NULL) {
-                       /* pft_size[0] is the NUMA CEC cookie */
-                       ppc64_pft_size = pft_size[1];
-               }
-       }
-#endif
-
        boot_cpuid = 0;
        boot_cpuid_phys = 0;
        if (initial_boot_params && initial_boot_params->version >= 2) {
@@ -1117,8 +1101,9 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
                boot_cpuid_phys = initial_boot_params->boot_cpuid_phys;
        } else {
                /* Check if it's the boot-cpu, set it's hw index now */
-               if (get_flat_dt_prop(node, "linux,boot-cpu", NULL) != NULL) {
-                       prop = get_flat_dt_prop(node, "reg", NULL);
+               if (of_get_flat_dt_prop(node,
+                                       "linux,boot-cpu", NULL) != NULL) {
+                       prop = of_get_flat_dt_prop(node, "reg", NULL);
                        if (prop != NULL)
                                boot_cpuid_phys = *prop;
                }
@@ -1127,14 +1112,14 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
 
 #ifdef CONFIG_ALTIVEC
        /* Check if we have a VMX and eventually update CPU features */
-       prop = (u32 *)get_flat_dt_prop(node, "ibm,vmx", &size);
+       prop = (u32 *)of_get_flat_dt_prop(node, "ibm,vmx", &size);
        if (prop && (*prop) > 0) {
                cur_cpu_spec->cpu_features |= CPU_FTR_ALTIVEC;
                cur_cpu_spec->cpu_user_features |= PPC_FEATURE_HAS_ALTIVEC;
        }
 
        /* Same goes for Apple's "altivec" property */
-       prop = (u32 *)get_flat_dt_prop(node, "altivec", NULL);
+       prop = (u32 *)of_get_flat_dt_prop(node, "altivec", NULL);
        if (prop) {
                cur_cpu_spec->cpu_features |= CPU_FTR_ALTIVEC;
                cur_cpu_spec->cpu_user_features |= PPC_FEATURE_HAS_ALTIVEC;
@@ -1147,7 +1132,7 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
         * this by looking at the size of the ibm,ppc-interrupt-server#s
         * property
         */
-       prop = (u32 *)get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s",
+       prop = (u32 *)of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s",
                                       &size);
        cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT;
        if (prop && ((size / sizeof(u32)) > 1))
@@ -1170,34 +1155,30 @@ static int __init early_init_dt_scan_chosen(unsigned long node,
                return 0;
 
        /* get platform type */
-       prop = (u32 *)get_flat_dt_prop(node, "linux,platform", NULL);
+       prop = (u32 *)of_get_flat_dt_prop(node, "linux,platform", NULL);
        if (prop == NULL)
                return 0;
-#ifdef CONFIG_PPC64
-       systemcfg->platform = *prop;
-#else
 #ifdef CONFIG_PPC_MULTIPLATFORM
        _machine = *prop;
 #endif
-#endif
 
 #ifdef CONFIG_PPC64
        /* check if iommu is forced on or off */
-       if (get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL)
+       if (of_get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL)
                iommu_is_off = 1;
-       if (get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL)
+       if (of_get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL)
                iommu_force_on = 1;
 #endif
 
-       lprop = get_flat_dt_prop(node, "linux,memory-limit", NULL);
+       lprop = of_get_flat_dt_prop(node, "linux,memory-limit", NULL);
        if (lprop)
                memory_limit = *lprop;
 
 #ifdef CONFIG_PPC64
-       lprop = get_flat_dt_prop(node, "linux,tce-alloc-start", NULL);
+       lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-start", NULL);
        if (lprop)
                tce_alloc_start = *lprop;
-       lprop = get_flat_dt_prop(node, "linux,tce-alloc-end", NULL);
+       lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-end", NULL);
        if (lprop)
                tce_alloc_end = *lprop;
 #endif
@@ -1209,9 +1190,9 @@ static int __init early_init_dt_scan_chosen(unsigned long node,
        {
                u64 *basep, *entryp;
 
-               basep = get_flat_dt_prop(node, "linux,rtas-base", NULL);
-               entryp = get_flat_dt_prop(node, "linux,rtas-entry", NULL);
-               prop = get_flat_dt_prop(node, "linux,rtas-size", NULL);
+               basep = of_get_flat_dt_prop(node, "linux,rtas-base", NULL);
+               entryp = of_get_flat_dt_prop(node, "linux,rtas-entry", NULL);
+               prop = of_get_flat_dt_prop(node, "linux,rtas-size", NULL);
                if (basep && entryp && prop) {
                        rtas.base = *basep;
                        rtas.entry = *entryp;
@@ -1232,11 +1213,11 @@ static int __init early_init_dt_scan_root(unsigned long node,
        if (depth != 0)
                return 0;
 
-       prop = get_flat_dt_prop(node, "#size-cells", NULL);
+       prop = of_get_flat_dt_prop(node, "#size-cells", NULL);
        dt_root_size_cells = (prop == NULL) ? 1 : *prop;
        DBG("dt_root_size_cells = %x\n", dt_root_size_cells);
 
-       prop = get_flat_dt_prop(node, "#address-cells", NULL);
+       prop = of_get_flat_dt_prop(node, "#address-cells", NULL);
        dt_root_addr_cells = (prop == NULL) ? 2 : *prop;
        DBG("dt_root_addr_cells = %x\n", dt_root_addr_cells);
        
@@ -1271,21 +1252,28 @@ static unsigned long __init dt_mem_next_cell(int s, cell_t **cellp)
 static int __init early_init_dt_scan_memory(unsigned long node,
                                            const char *uname, int depth, void *data)
 {
-       char *type = get_flat_dt_prop(node, "device_type", NULL);
+       char *type = of_get_flat_dt_prop(node, "device_type", NULL);
        cell_t *reg, *endp;
        unsigned long l;
 
        /* We are scanning "memory" nodes only */
-       if (type == NULL || strcmp(type, "memory") != 0)
+       if (type == NULL) {
+               /*
+                * The longtrail doesn't have a device_type on the
+                * /memory node, so look for the node called /memory@0.
+                */
+               if (depth != 1 || strcmp(uname, "memory@0") != 0)
+                       return 0;
+       } else if (strcmp(type, "memory") != 0)
                return 0;
 
-       reg = (cell_t *)get_flat_dt_prop(node, "reg", &l);
+       reg = (cell_t *)of_get_flat_dt_prop(node, "reg", &l);
        if (reg == NULL)
                return 0;
 
        endp = reg + (l / sizeof(cell_t));
 
-       DBG("memory scan node %s ..., reg size %ld, data: %x %x %x %x, ...\n",
+       DBG("memory scan node %s, reg size %ld, data: %x %x %x %x,\n",
            uname, l, reg[0], reg[1], reg[2], reg[3]);
 
        while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
@@ -1343,17 +1331,14 @@ void __init early_init_devtree(void *params)
         * device-tree, including the platform type, initrd location and
         * size, TCE reserve, and more ...
         */
-       scan_flat_dt(early_init_dt_scan_chosen, NULL);
+       of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
 
        /* Scan memory nodes and rebuild LMBs */
        lmb_init();
-       scan_flat_dt(early_init_dt_scan_root, NULL);
-       scan_flat_dt(early_init_dt_scan_memory, NULL);
+       of_scan_flat_dt(early_init_dt_scan_root, NULL);
+       of_scan_flat_dt(early_init_dt_scan_memory, NULL);
        lmb_enforce_memory_limit(memory_limit);
        lmb_analyze();
-#ifdef CONFIG_PPC64
-       systemcfg->physicalMemorySize = lmb_phys_mem_size();
-#endif
        lmb_reserve(0, __pa(klimit));
 
        DBG("Phys. mem: %lx\n", lmb_phys_mem_size());
@@ -1363,10 +1348,10 @@ void __init early_init_devtree(void *params)
 
        DBG("Scanning CPUs ...\n");
 
-       /* Retreive hash table size from flattened tree plus other
-        * CPU related informations (altivec support, boot CPU ID, ...)
+       /* Retreive CPU related informations from the flat tree
+        * (altivec support, boot CPU ID, ...)
         */
-       scan_flat_dt(early_init_dt_scan_cpus, NULL);
+       of_scan_flat_dt(early_init_dt_scan_cpus, NULL);
 
        DBG(" <- early_init_devtree()\n");
 }
@@ -1920,7 +1905,7 @@ static int of_finish_dynamic_node(struct device_node *node,
        /* We don't support that function on PowerMac, at least
         * not yet
         */
-       if (systemcfg->platform == PLATFORM_POWERMAC)
+       if (_machine == PLATFORM_POWERMAC)
                return -ENODEV;
 
        /* fix up new node's linux_phandle field */
@@ -1986,14 +1971,31 @@ EXPORT_SYMBOL(get_property);
 /*
  * Add a property to a node
  */
-void prom_add_property(struct device_node* np, struct property* prop)
+int prom_add_property(struct device_node* np, struct property* prop)
 {
-       struct property **next = &np->properties;
+       struct property **next;
 
        prop->next = NULL;      
-       while (*next)
+       write_lock(&devtree_lock);
+       next = &np->properties;
+       while (*next) {
+               if (strcmp(prop->name, (*next)->name) == 0) {
+                       /* duplicate ! don't insert it */
+                       write_unlock(&devtree_lock);
+                       return -1;
+               }
                next = &(*next)->next;
+       }
        *next = prop;
+       write_unlock(&devtree_lock);
+
+#ifdef CONFIG_PROC_DEVICETREE
+       /* try to add to proc as well if it was initialized */
+       if (np->pde)
+               proc_device_tree_add_prop(np->pde, prop);
+#endif /* CONFIG_PROC_DEVICETREE */
+
+       return 0;
 }
 
 /* I quickly hacked that one, check against spec ! */