sparc: Move core of OF device tree building code into prom_common.c
authorDavid S. Miller <davem@davemloft.net>
Fri, 5 Dec 2008 09:21:41 +0000 (01:21 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sat, 6 Dec 2008 02:15:03 +0000 (18:15 -0800)
Signed-off-by: David S. Miller <davem@davemloft.net>
arch/sparc/kernel/prom.h
arch/sparc/kernel/prom_32.c
arch/sparc/kernel/prom_64.c
arch/sparc/kernel/prom_common.c

index d14b4ae4fc579c2216e72fe9cdba1b0be2ceb7a9..dea8b91b6960f35e408f49b00ce6fa60f77153ad 100644 (file)
@@ -15,7 +15,20 @@ extern void irq_trans_init(struct device_node *dp);
 
 extern unsigned int prom_unique_id;
 
-extern struct device_node * __init create_node(phandle node,
-                                              struct device_node *parent);
+static inline int is_root_node(const struct device_node *dp)
+{
+       if (!dp)
+               return 0;
 
+       return (dp->parent == NULL);
+}
+
+extern char *build_path_component(struct device_node *dp);
+
+extern struct device_node * __init prom_create_node(phandle node,
+                                                   struct device_node *parent);
+
+extern struct device_node * __init prom_build_tree(struct device_node *parent,
+                                                  phandle node,
+                                                  struct device_node ***nextp);
 #endif /* __PROM_H */
index 35cb4c74252427c82cf734cf7af9344e4bddd774..75eb40be5e8a6103ace059d038dedcd3f0a84178 100644 (file)
@@ -42,14 +42,6 @@ void * __init prom_early_alloc(unsigned long size)
        return ret;
 }
 
-static int is_root_node(const struct device_node *dp)
-{
-       if (!dp)
-               return 0;
-
-       return (dp->parent == NULL);
-}
-
 /* The following routines deal with the black magic of fully naming a
  * node.
  *
@@ -161,7 +153,7 @@ static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
        return sparc32_path_component(dp, tmp_buf);
 }
 
-static char * __init build_path_component(struct device_node *dp)
+char * __init build_path_component(struct device_node *dp)
 {
        char tmp_buf[64], *n;
 
@@ -176,57 +168,6 @@ static char * __init build_path_component(struct device_node *dp)
        return n;
 }
 
-static char * __init build_full_name(struct device_node *dp)
-{
-       int len, ourlen, plen;
-       char *n;
-
-       plen = strlen(dp->parent->full_name);
-       ourlen = strlen(dp->path_component_name);
-       len = ourlen + plen + 2;
-
-       n = prom_early_alloc(len);
-       strcpy(n, dp->parent->full_name);
-       if (!is_root_node(dp->parent)) {
-               strcpy(n + plen, "/");
-               plen++;
-       }
-       strcpy(n + plen, dp->path_component_name);
-
-       return n;
-}
-
-static struct device_node * __init build_tree(struct device_node *parent, phandle node, struct device_node ***nextp)
-{
-       struct device_node *ret = NULL, *prev_sibling = NULL;
-       struct device_node *dp;
-
-       while (1) {
-               dp = create_node(node, parent);
-               if (!dp)
-                       break;
-
-               if (prev_sibling)
-                       prev_sibling->sibling = dp;
-
-               if (!ret)
-                       ret = dp;
-               prev_sibling = dp;
-
-               *(*nextp) = dp;
-               *nextp = &dp->allnext;
-
-               dp->path_component_name = build_path_component(dp);
-               dp->full_name = build_full_name(dp);
-
-               dp->child = build_tree(dp, prom_getchild(node), nextp);
-
-               node = prom_getsibling(node);
-       }
-
-       return ret;
-}
-
 struct device_node *of_console_device;
 EXPORT_SYMBOL(of_console_device);
 
@@ -360,14 +301,14 @@ void __init prom_build_devicetree(void)
 {
        struct device_node **nextp;
 
-       allnodes = create_node(prom_root_node, NULL);
+       allnodes = prom_create_node(prom_root_node, NULL);
        allnodes->path_component_name = "";
        allnodes->full_name = "/";
 
        nextp = &allnodes->allnext;
-       allnodes->child = build_tree(allnodes,
-                                    prom_getchild(allnodes->node),
-                                    &nextp);
+       allnodes->child = prom_build_tree(allnodes,
+                                         prom_getchild(allnodes->node),
+                                         &nextp);
        of_console_init();
 
        printk("PROM: Built device tree with %u bytes of memory.\n",
index c1ce987b8429ad2a1420976d69040cbb680f6292..0279811d17bcc3ba2ed10c5bbeae2acf4b4972d3 100644 (file)
@@ -51,14 +51,6 @@ void * __init prom_early_alloc(unsigned long size)
        return ret;
 }
 
-static int is_root_node(const struct device_node *dp)
-{
-       if (!dp)
-               return 0;
-
-       return (dp->parent == NULL);
-}
-
 /* The following routines deal with the black magic of fully naming a
  * node.
  *
@@ -364,7 +356,7 @@ static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
        }
 }
 
-static char * __init build_path_component(struct device_node *dp)
+char * __init build_path_component(struct device_node *dp)
 {
        char tmp_buf[64], *n;
 
@@ -379,57 +371,6 @@ static char * __init build_path_component(struct device_node *dp)
        return n;
 }
 
-static char * __init build_full_name(struct device_node *dp)
-{
-       int len, ourlen, plen;
-       char *n;
-
-       plen = strlen(dp->parent->full_name);
-       ourlen = strlen(dp->path_component_name);
-       len = ourlen + plen + 2;
-
-       n = prom_early_alloc(len);
-       strcpy(n, dp->parent->full_name);
-       if (!is_root_node(dp->parent)) {
-               strcpy(n + plen, "/");
-               plen++;
-       }
-       strcpy(n + plen, dp->path_component_name);
-
-       return n;
-}
-
-static struct device_node * __init build_tree(struct device_node *parent, phandle node, struct device_node ***nextp)
-{
-       struct device_node *ret = NULL, *prev_sibling = NULL;
-       struct device_node *dp;
-
-       while (1) {
-               dp = create_node(node, parent);
-               if (!dp)
-                       break;
-
-               if (prev_sibling)
-                       prev_sibling->sibling = dp;
-
-               if (!ret)
-                       ret = dp;
-               prev_sibling = dp;
-
-               *(*nextp) = dp;
-               *nextp = &dp->allnext;
-
-               dp->path_component_name = build_path_component(dp);
-               dp->full_name = build_full_name(dp);
-
-               dp->child = build_tree(dp, prom_getchild(node), nextp);
-
-               node = prom_getsibling(node);
-       }
-
-       return ret;
-}
-
 static const char *get_mid_prop(void)
 {
        return (tlb_type == spitfire ? "upa-portid" : "portid");
@@ -640,14 +581,14 @@ void __init prom_build_devicetree(void)
 {
        struct device_node **nextp;
 
-       allnodes = create_node(prom_root_node, NULL);
+       allnodes = prom_create_node(prom_root_node, NULL);
        allnodes->path_component_name = "";
        allnodes->full_name = "/";
 
        nextp = &allnodes->allnext;
-       allnodes->child = build_tree(allnodes,
-                                    prom_getchild(allnodes->node),
-                                    &nextp);
+       allnodes->child = prom_build_tree(allnodes,
+                                         prom_getchild(allnodes->node),
+                                         &nextp);
        of_console_init();
 
        printk("PROM: Built device tree with %u bytes of memory.\n",
index d3eddc76763d049fd2a7b1773b37684d43b0897f..3b5de2f3fcd1db7290b03c72133d748ee7e873d7 100644 (file)
@@ -216,8 +216,8 @@ static char * __init get_one_property(phandle node, const char *name)
        return buf;
 }
 
-struct device_node * __init create_node(phandle node,
-                                       struct device_node *parent)
+struct device_node * __init prom_create_node(phandle node,
+                                            struct device_node *parent)
 {
        struct device_node *dp;
 
@@ -240,3 +240,56 @@ struct device_node * __init create_node(phandle node,
 
        return dp;
 }
+
+static char * __init build_full_name(struct device_node *dp)
+{
+       int len, ourlen, plen;
+       char *n;
+
+       plen = strlen(dp->parent->full_name);
+       ourlen = strlen(dp->path_component_name);
+       len = ourlen + plen + 2;
+
+       n = prom_early_alloc(len);
+       strcpy(n, dp->parent->full_name);
+       if (!is_root_node(dp->parent)) {
+               strcpy(n + plen, "/");
+               plen++;
+       }
+       strcpy(n + plen, dp->path_component_name);
+
+       return n;
+}
+
+struct device_node * __init prom_build_tree(struct device_node *parent,
+                                           phandle node,
+                                           struct device_node ***nextp)
+{
+       struct device_node *ret = NULL, *prev_sibling = NULL;
+       struct device_node *dp;
+
+       while (1) {
+               dp = prom_create_node(node, parent);
+               if (!dp)
+                       break;
+
+               if (prev_sibling)
+                       prev_sibling->sibling = dp;
+
+               if (!ret)
+                       ret = dp;
+               prev_sibling = dp;
+
+               *(*nextp) = dp;
+               *nextp = &dp->allnext;
+
+               dp->path_component_name = build_path_component(dp);
+               dp->full_name = build_full_name(dp);
+
+               dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
+
+               node = prom_getsibling(node);
+       }
+
+       return ret;
+}