diff options
author | David S. Miller <davem@davemloft.net> | 2008-12-05 04:21:41 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-12-05 21:15:03 -0500 |
commit | 6524036a1e5736a07466208362d83ddf31aae3ac (patch) | |
tree | dea250164424676bd19505adcbf6ae260559c403 /arch/sparc | |
parent | 4aef8c53fe517542d8185b7d771f291865b49177 (diff) |
sparc: Move core of OF device tree building code into prom_common.c
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc')
-rw-r--r-- | arch/sparc/kernel/prom.h | 17 | ||||
-rw-r--r-- | arch/sparc/kernel/prom_32.c | 69 | ||||
-rw-r--r-- | arch/sparc/kernel/prom_64.c | 69 | ||||
-rw-r--r-- | arch/sparc/kernel/prom_common.c | 57 |
4 files changed, 80 insertions, 132 deletions
diff --git a/arch/sparc/kernel/prom.h b/arch/sparc/kernel/prom.h index d14b4ae4fc57..dea8b91b6960 100644 --- a/arch/sparc/kernel/prom.h +++ b/arch/sparc/kernel/prom.h | |||
@@ -15,7 +15,20 @@ extern void irq_trans_init(struct device_node *dp); | |||
15 | 15 | ||
16 | extern unsigned int prom_unique_id; | 16 | extern unsigned int prom_unique_id; |
17 | 17 | ||
18 | extern struct device_node * __init create_node(phandle node, | 18 | static inline int is_root_node(const struct device_node *dp) |
19 | struct device_node *parent); | 19 | { |
20 | if (!dp) | ||
21 | return 0; | ||
20 | 22 | ||
23 | return (dp->parent == NULL); | ||
24 | } | ||
25 | |||
26 | extern char *build_path_component(struct device_node *dp); | ||
27 | |||
28 | extern struct device_node * __init prom_create_node(phandle node, | ||
29 | struct device_node *parent); | ||
30 | |||
31 | extern struct device_node * __init prom_build_tree(struct device_node *parent, | ||
32 | phandle node, | ||
33 | struct device_node ***nextp); | ||
21 | #endif /* __PROM_H */ | 34 | #endif /* __PROM_H */ |
diff --git a/arch/sparc/kernel/prom_32.c b/arch/sparc/kernel/prom_32.c index 35cb4c742524..75eb40be5e8a 100644 --- a/arch/sparc/kernel/prom_32.c +++ b/arch/sparc/kernel/prom_32.c | |||
@@ -42,14 +42,6 @@ void * __init prom_early_alloc(unsigned long size) | |||
42 | return ret; | 42 | return ret; |
43 | } | 43 | } |
44 | 44 | ||
45 | static int is_root_node(const struct device_node *dp) | ||
46 | { | ||
47 | if (!dp) | ||
48 | return 0; | ||
49 | |||
50 | return (dp->parent == NULL); | ||
51 | } | ||
52 | |||
53 | /* The following routines deal with the black magic of fully naming a | 45 | /* The following routines deal with the black magic of fully naming a |
54 | * node. | 46 | * node. |
55 | * | 47 | * |
@@ -161,7 +153,7 @@ static void __init __build_path_component(struct device_node *dp, char *tmp_buf) | |||
161 | return sparc32_path_component(dp, tmp_buf); | 153 | return sparc32_path_component(dp, tmp_buf); |
162 | } | 154 | } |
163 | 155 | ||
164 | static char * __init build_path_component(struct device_node *dp) | 156 | char * __init build_path_component(struct device_node *dp) |
165 | { | 157 | { |
166 | char tmp_buf[64], *n; | 158 | char tmp_buf[64], *n; |
167 | 159 | ||
@@ -176,57 +168,6 @@ static char * __init build_path_component(struct device_node *dp) | |||
176 | return n; | 168 | return n; |
177 | } | 169 | } |
178 | 170 | ||
179 | static char * __init build_full_name(struct device_node *dp) | ||
180 | { | ||
181 | int len, ourlen, plen; | ||
182 | char *n; | ||
183 | |||
184 | plen = strlen(dp->parent->full_name); | ||
185 | ourlen = strlen(dp->path_component_name); | ||
186 | len = ourlen + plen + 2; | ||
187 | |||
188 | n = prom_early_alloc(len); | ||
189 | strcpy(n, dp->parent->full_name); | ||
190 | if (!is_root_node(dp->parent)) { | ||
191 | strcpy(n + plen, "/"); | ||
192 | plen++; | ||
193 | } | ||
194 | strcpy(n + plen, dp->path_component_name); | ||
195 | |||
196 | return n; | ||
197 | } | ||
198 | |||
199 | static struct device_node * __init build_tree(struct device_node *parent, phandle node, struct device_node ***nextp) | ||
200 | { | ||
201 | struct device_node *ret = NULL, *prev_sibling = NULL; | ||
202 | struct device_node *dp; | ||
203 | |||
204 | while (1) { | ||
205 | dp = create_node(node, parent); | ||
206 | if (!dp) | ||
207 | break; | ||
208 | |||
209 | if (prev_sibling) | ||
210 | prev_sibling->sibling = dp; | ||
211 | |||
212 | if (!ret) | ||
213 | ret = dp; | ||
214 | prev_sibling = dp; | ||
215 | |||
216 | *(*nextp) = dp; | ||
217 | *nextp = &dp->allnext; | ||
218 | |||
219 | dp->path_component_name = build_path_component(dp); | ||
220 | dp->full_name = build_full_name(dp); | ||
221 | |||
222 | dp->child = build_tree(dp, prom_getchild(node), nextp); | ||
223 | |||
224 | node = prom_getsibling(node); | ||
225 | } | ||
226 | |||
227 | return ret; | ||
228 | } | ||
229 | |||
230 | struct device_node *of_console_device; | 171 | struct device_node *of_console_device; |
231 | EXPORT_SYMBOL(of_console_device); | 172 | EXPORT_SYMBOL(of_console_device); |
232 | 173 | ||
@@ -360,14 +301,14 @@ void __init prom_build_devicetree(void) | |||
360 | { | 301 | { |
361 | struct device_node **nextp; | 302 | struct device_node **nextp; |
362 | 303 | ||
363 | allnodes = create_node(prom_root_node, NULL); | 304 | allnodes = prom_create_node(prom_root_node, NULL); |
364 | allnodes->path_component_name = ""; | 305 | allnodes->path_component_name = ""; |
365 | allnodes->full_name = "/"; | 306 | allnodes->full_name = "/"; |
366 | 307 | ||
367 | nextp = &allnodes->allnext; | 308 | nextp = &allnodes->allnext; |
368 | allnodes->child = build_tree(allnodes, | 309 | allnodes->child = prom_build_tree(allnodes, |
369 | prom_getchild(allnodes->node), | 310 | prom_getchild(allnodes->node), |
370 | &nextp); | 311 | &nextp); |
371 | of_console_init(); | 312 | of_console_init(); |
372 | 313 | ||
373 | printk("PROM: Built device tree with %u bytes of memory.\n", | 314 | printk("PROM: Built device tree with %u bytes of memory.\n", |
diff --git a/arch/sparc/kernel/prom_64.c b/arch/sparc/kernel/prom_64.c index c1ce987b8429..0279811d17bc 100644 --- a/arch/sparc/kernel/prom_64.c +++ b/arch/sparc/kernel/prom_64.c | |||
@@ -51,14 +51,6 @@ void * __init prom_early_alloc(unsigned long size) | |||
51 | return ret; | 51 | return ret; |
52 | } | 52 | } |
53 | 53 | ||
54 | static int is_root_node(const struct device_node *dp) | ||
55 | { | ||
56 | if (!dp) | ||
57 | return 0; | ||
58 | |||
59 | return (dp->parent == NULL); | ||
60 | } | ||
61 | |||
62 | /* The following routines deal with the black magic of fully naming a | 54 | /* The following routines deal with the black magic of fully naming a |
63 | * node. | 55 | * node. |
64 | * | 56 | * |
@@ -364,7 +356,7 @@ static void __init __build_path_component(struct device_node *dp, char *tmp_buf) | |||
364 | } | 356 | } |
365 | } | 357 | } |
366 | 358 | ||
367 | static char * __init build_path_component(struct device_node *dp) | 359 | char * __init build_path_component(struct device_node *dp) |
368 | { | 360 | { |
369 | char tmp_buf[64], *n; | 361 | char tmp_buf[64], *n; |
370 | 362 | ||
@@ -379,57 +371,6 @@ static char * __init build_path_component(struct device_node *dp) | |||
379 | return n; | 371 | return n; |
380 | } | 372 | } |
381 | 373 | ||
382 | static char * __init build_full_name(struct device_node *dp) | ||
383 | { | ||
384 | int len, ourlen, plen; | ||
385 | char *n; | ||
386 | |||
387 | plen = strlen(dp->parent->full_name); | ||
388 | ourlen = strlen(dp->path_component_name); | ||
389 | len = ourlen + plen + 2; | ||
390 | |||
391 | n = prom_early_alloc(len); | ||
392 | strcpy(n, dp->parent->full_name); | ||
393 | if (!is_root_node(dp->parent)) { | ||
394 | strcpy(n + plen, "/"); | ||
395 | plen++; | ||
396 | } | ||
397 | strcpy(n + plen, dp->path_component_name); | ||
398 | |||
399 | return n; | ||
400 | } | ||
401 | |||
402 | static struct device_node * __init build_tree(struct device_node *parent, phandle node, struct device_node ***nextp) | ||
403 | { | ||
404 | struct device_node *ret = NULL, *prev_sibling = NULL; | ||
405 | struct device_node *dp; | ||
406 | |||
407 | while (1) { | ||
408 | dp = create_node(node, parent); | ||
409 | if (!dp) | ||
410 | break; | ||
411 | |||
412 | if (prev_sibling) | ||
413 | prev_sibling->sibling = dp; | ||
414 | |||
415 | if (!ret) | ||
416 | ret = dp; | ||
417 | prev_sibling = dp; | ||
418 | |||
419 | *(*nextp) = dp; | ||
420 | *nextp = &dp->allnext; | ||
421 | |||
422 | dp->path_component_name = build_path_component(dp); | ||
423 | dp->full_name = build_full_name(dp); | ||
424 | |||
425 | dp->child = build_tree(dp, prom_getchild(node), nextp); | ||
426 | |||
427 | node = prom_getsibling(node); | ||
428 | } | ||
429 | |||
430 | return ret; | ||
431 | } | ||
432 | |||
433 | static const char *get_mid_prop(void) | 374 | static const char *get_mid_prop(void) |
434 | { | 375 | { |
435 | return (tlb_type == spitfire ? "upa-portid" : "portid"); | 376 | return (tlb_type == spitfire ? "upa-portid" : "portid"); |
@@ -640,14 +581,14 @@ void __init prom_build_devicetree(void) | |||
640 | { | 581 | { |
641 | struct device_node **nextp; | 582 | struct device_node **nextp; |
642 | 583 | ||
643 | allnodes = create_node(prom_root_node, NULL); | 584 | allnodes = prom_create_node(prom_root_node, NULL); |
644 | allnodes->path_component_name = ""; | 585 | allnodes->path_component_name = ""; |
645 | allnodes->full_name = "/"; | 586 | allnodes->full_name = "/"; |
646 | 587 | ||
647 | nextp = &allnodes->allnext; | 588 | nextp = &allnodes->allnext; |
648 | allnodes->child = build_tree(allnodes, | 589 | allnodes->child = prom_build_tree(allnodes, |
649 | prom_getchild(allnodes->node), | 590 | prom_getchild(allnodes->node), |
650 | &nextp); | 591 | &nextp); |
651 | of_console_init(); | 592 | of_console_init(); |
652 | 593 | ||
653 | printk("PROM: Built device tree with %u bytes of memory.\n", | 594 | printk("PROM: Built device tree with %u bytes of memory.\n", |
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c index d3eddc76763d..3b5de2f3fcd1 100644 --- a/arch/sparc/kernel/prom_common.c +++ b/arch/sparc/kernel/prom_common.c | |||
@@ -216,8 +216,8 @@ static char * __init get_one_property(phandle node, const char *name) | |||
216 | return buf; | 216 | return buf; |
217 | } | 217 | } |
218 | 218 | ||
219 | struct device_node * __init create_node(phandle node, | 219 | struct device_node * __init prom_create_node(phandle node, |
220 | struct device_node *parent) | 220 | struct device_node *parent) |
221 | { | 221 | { |
222 | struct device_node *dp; | 222 | struct device_node *dp; |
223 | 223 | ||
@@ -240,3 +240,56 @@ struct device_node * __init create_node(phandle node, | |||
240 | 240 | ||
241 | return dp; | 241 | return dp; |
242 | } | 242 | } |
243 | |||
244 | static char * __init build_full_name(struct device_node *dp) | ||
245 | { | ||
246 | int len, ourlen, plen; | ||
247 | char *n; | ||
248 | |||
249 | plen = strlen(dp->parent->full_name); | ||
250 | ourlen = strlen(dp->path_component_name); | ||
251 | len = ourlen + plen + 2; | ||
252 | |||
253 | n = prom_early_alloc(len); | ||
254 | strcpy(n, dp->parent->full_name); | ||
255 | if (!is_root_node(dp->parent)) { | ||
256 | strcpy(n + plen, "/"); | ||
257 | plen++; | ||
258 | } | ||
259 | strcpy(n + plen, dp->path_component_name); | ||
260 | |||
261 | return n; | ||
262 | } | ||
263 | |||
264 | struct device_node * __init prom_build_tree(struct device_node *parent, | ||
265 | phandle node, | ||
266 | struct device_node ***nextp) | ||
267 | { | ||
268 | struct device_node *ret = NULL, *prev_sibling = NULL; | ||
269 | struct device_node *dp; | ||
270 | |||
271 | while (1) { | ||
272 | dp = prom_create_node(node, parent); | ||
273 | if (!dp) | ||
274 | break; | ||
275 | |||
276 | if (prev_sibling) | ||
277 | prev_sibling->sibling = dp; | ||
278 | |||
279 | if (!ret) | ||
280 | ret = dp; | ||
281 | prev_sibling = dp; | ||
282 | |||
283 | *(*nextp) = dp; | ||
284 | *nextp = &dp->allnext; | ||
285 | |||
286 | dp->path_component_name = build_path_component(dp); | ||
287 | dp->full_name = build_full_name(dp); | ||
288 | |||
289 | dp->child = prom_build_tree(dp, prom_getchild(node), nextp); | ||
290 | |||
291 | node = prom_getsibling(node); | ||
292 | } | ||
293 | |||
294 | return ret; | ||
295 | } | ||