Commit 3cfc535c5df8122af1258ae05aaf2770c033425d

Authored by Andres Salomon
Committed by Grant Likely
1 parent 9bdf6bab4e

of/promtree: make drivers/of/pdt.c no longer sparc-only

Clean up pdt.c:
 - make build dependent upon config OF_PROMTREE
 - #ifdef out the sparc-specific stuff
 - create pdt-specific header

Signed-off-by: Andres Salomon <dilinger@queued.net>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

Showing 8 changed files with 81 additions and 25 deletions Side-by-side Diff

... ... @@ -19,6 +19,7 @@
19 19 bool
20 20 default y
21 21 select OF
  22 + select OF_PROMTREE
22 23 select HAVE_IDE
23 24 select HAVE_OPROFILE
24 25 select HAVE_ARCH_KGDB if !SMP || SPARC64
arch/sparc/include/asm/prom.h
... ... @@ -18,6 +18,7 @@
18 18 * 2 of the License, or (at your option) any later version.
19 19 */
20 20 #include <linux/types.h>
  21 +#include <linux/of_pdt.h>
21 22 #include <linux/proc_fs.h>
22 23 #include <linux/mutex.h>
23 24 #include <asm/atomic.h>
... ... @@ -67,8 +68,8 @@
67 68 extern char *of_console_path;
68 69 extern char *of_console_options;
69 70  
70   -extern void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
71   -extern char *build_full_name(struct device_node *dp);
  71 +extern void irq_trans_init(struct device_node *dp);
  72 +extern char *build_path_component(struct device_node *dp);
72 73  
73 74 #endif /* __KERNEL__ */
74 75 #endif /* _SPARC_PROM_H */
arch/sparc/kernel/prom.h
... ... @@ -4,12 +4,6 @@
4 4 #include <linux/spinlock.h>
5 5 #include <asm/prom.h>
6 6  
7   -extern void * prom_early_alloc(unsigned long size);
8   -extern void irq_trans_init(struct device_node *dp);
9   -
10   -extern unsigned int prom_unique_id;
11   -
12   -extern char *build_path_component(struct device_node *dp);
13 7 extern void of_console_init(void);
14 8  
15 9 extern unsigned int prom_early_allocated;
arch/sparc/kernel/prom_common.c
... ... @@ -20,6 +20,7 @@
20 20 #include <linux/mutex.h>
21 21 #include <linux/slab.h>
22 22 #include <linux/of.h>
  23 +#include <linux/of_pdt.h>
23 24 #include <asm/prom.h>
24 25 #include <asm/oplib.h>
25 26 #include <asm/leon.h>
... ... @@ -119,5 +120,12 @@
119 120  
120 121 unsigned int prom_early_allocated __initdata;
121 122  
122   -#include "../../../drivers/of/pdt.c"
  123 +void __init prom_build_devicetree(void)
  124 +{
  125 + of_pdt_build_devicetree(prom_root_node);
  126 + of_console_init();
  127 +
  128 + pr_info("PROM: Built device tree with %u bytes of memory.\n",
  129 + prom_early_allocated);
  130 +}
... ... @@ -4,7 +4,7 @@
4 4 config OF
5 5 bool
6 6  
7   -menu "Flattened Device Tree and Open Firmware support"
  7 +menu "Device Tree and Open Firmware support"
8 8 depends on OF
9 9  
10 10 config PROC_DEVICETREE
... ... @@ -18,6 +18,9 @@
18 18 config OF_FLATTREE
19 19 bool
20 20 select DTC
  21 +
  22 +config OF_PROMTREE
  23 + bool
21 24  
22 25 config OF_DYNAMIC
23 26 def_bool y
1 1 obj-y = base.o
2 2 obj-$(CONFIG_OF_FLATTREE) += fdt.o
  3 +obj-$(CONFIG_OF_PROMTREE) += pdt.o
3 4 obj-$(CONFIG_OF_ADDRESS) += address.o
4 5 obj-$(CONFIG_OF_IRQ) += irq.o
5 6 obj-$(CONFIG_OF_DEVICE) += device.o platform.o
1   -/* prom_common.c: OF device tree support common code.
  1 +/* pdt.c: OF PROM device tree support code.
2 2 *
3 3 * Paul Mackerras August 1996.
4 4 * Copyright (C) 1996-2005 Paul Mackerras.
... ... @@ -7,6 +7,7 @@
7 7 * {engebret|bergner}@us.ibm.com
8 8 *
9 9 * Adapted for sparc by David S. Miller davem@davemloft.net
  10 + * Adapted for multiple architectures by Andres Salomon <dilinger@queued.net>
10 11 *
11 12 * This program is free software; you can redistribute it and/or
12 13 * modify it under the terms of the GNU General Public License
13 14  
14 15  
15 16  
16 17  
... ... @@ -20,14 +21,37 @@
20 21 #include <linux/mutex.h>
21 22 #include <linux/slab.h>
22 23 #include <linux/of.h>
  24 +#include <linux/of_pdt.h>
23 25 #include <asm/prom.h>
24 26 #include <asm/oplib.h>
25   -#include <asm/leon.h>
26 27  
27   -void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
  28 +void __initdata (*prom_build_more)(struct device_node *dp,
  29 + struct device_node ***nextp);
28 30  
29   -unsigned int prom_unique_id;
  31 +#if defined(CONFIG_SPARC)
  32 +unsigned int of_pdt_unique_id __initdata;
30 33  
  34 +#define of_pdt_incr_unique_id(p) do { \
  35 + (p)->unique_id = of_pdt_unique_id++; \
  36 +} while (0)
  37 +
  38 +static inline const char *of_pdt_node_name(struct device_node *dp)
  39 +{
  40 + return dp->path_component_name;
  41 +}
  42 +
  43 +#else
  44 +
  45 +static inline void of_pdt_incr_unique_id(void *p) { }
  46 +static inline void irq_trans_init(struct device_node *dp) { }
  47 +
  48 +static inline const char *of_pdt_node_name(struct device_node *dp)
  49 +{
  50 + return dp->name;
  51 +}
  52 +
  53 +#endif /* !CONFIG_SPARC */
  54 +
31 55 static struct property * __init build_one_prop(phandle node, char *prev,
32 56 char *special_name,
33 57 void *special_val,
... ... @@ -43,7 +67,7 @@
43 67 tmp = NULL;
44 68 } else {
45 69 p = prom_early_alloc(sizeof(struct property) + 32);
46   - p->unique_id = prom_unique_id++;
  70 + of_pdt_incr_unique_id(p);
47 71 }
48 72  
49 73 p->name = (char *) (p + 1);
... ... @@ -124,7 +148,7 @@
124 148 return NULL;
125 149  
126 150 dp = prom_early_alloc(sizeof(*dp));
127   - dp->unique_id = prom_unique_id++;
  151 + of_pdt_incr_unique_id(dp);
128 152 dp->parent = parent;
129 153  
130 154 kref_init(&dp->kref);
131 155  
... ... @@ -140,13 +164,13 @@
140 164 return dp;
141 165 }
142 166  
143   -char * __init build_full_name(struct device_node *dp)
  167 +static char * __init build_full_name(struct device_node *dp)
144 168 {
145 169 int len, ourlen, plen;
146 170 char *n;
147 171  
148 172 plen = strlen(dp->parent->full_name);
149   - ourlen = strlen(dp->path_component_name);
  173 + ourlen = strlen(of_pdt_node_name(dp));
150 174 len = ourlen + plen + 2;
151 175  
152 176 n = prom_early_alloc(len);
... ... @@ -155,7 +179,7 @@
155 179 strcpy(n + plen, "/");
156 180 plen++;
157 181 }
158   - strcpy(n + plen, dp->path_component_name);
  182 + strcpy(n + plen, of_pdt_node_name(dp));
159 183  
160 184 return n;
161 185 }
162 186  
... ... @@ -182,7 +206,9 @@
182 206 *(*nextp) = dp;
183 207 *nextp = &dp->allnext;
184 208  
  209 +#if defined(CONFIG_SPARC)
185 210 dp->path_component_name = build_path_component(dp);
  211 +#endif
186 212 dp->full_name = build_full_name(dp);
187 213  
188 214 dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
189 215  
190 216  
191 217  
... ... @@ -196,21 +222,19 @@
196 222 return ret;
197 223 }
198 224  
199   -void __init prom_build_devicetree(void)
  225 +void __init of_pdt_build_devicetree(phandle root_node)
200 226 {
201 227 struct device_node **nextp;
202 228  
203   - allnodes = prom_create_node(prom_root_node, NULL);
  229 + allnodes = prom_create_node(root_node, NULL);
  230 +#if defined(CONFIG_SPARC)
204 231 allnodes->path_component_name = "";
  232 +#endif
205 233 allnodes->full_name = "/";
206 234  
207 235 nextp = &allnodes->allnext;
208 236 allnodes->child = prom_build_tree(allnodes,
209 237 prom_getchild(allnodes->phandle),
210 238 &nextp);
211   - of_console_init();
212   -
213   - printk("PROM: Built device tree with %u bytes of memory.\n",
214   - prom_early_allocated);
215 239 }
include/linux/of_pdt.h
  1 +/*
  2 + * Definitions for building a device tree by calling into the
  3 + * Open Firmware PROM.
  4 + *
  5 + * Copyright (C) 2010 Andres Salomon <dilinger@queued.net>
  6 + *
  7 + * This program is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU General Public License
  9 + * as published by the Free Software Foundation; either version
  10 + * 2 of the License, or (at your option) any later version.
  11 + */
  12 +
  13 +#ifndef _LINUX_OF_PDT_H
  14 +#define _LINUX_OF_PDT_H
  15 +
  16 +extern void *prom_early_alloc(unsigned long size);
  17 +
  18 +/* for building the device tree */
  19 +extern void of_pdt_build_devicetree(phandle root_node);
  20 +
  21 +extern void (*prom_build_more)(struct device_node *dp,
  22 + struct device_node ***nextp);
  23 +
  24 +#endif /* _LINUX_OF_PDT_H */