2 * Procedures for creating, accessing and interpreting the device tree.
4 * Paul Mackerras August 1996.
5 * Copyright (C) 1996-2005 Paul Mackerras.
7 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
8 * {engebret|bergner}@us.ibm.com
10 * Adapted for sparc64 by David S. Miller davem@davemloft.net
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
18 #include <linux/kernel.h>
19 #include <linux/types.h>
20 #include <linux/string.h>
22 #include <linux/bootmem.h>
23 #include <linux/module.h>
26 #include <asm/of_device.h>
27 #include <asm/oplib.h>
33 extern struct device_node *allnodes; /* temporary while merging */
35 extern rwlock_t devtree_lock; /* temporary while merging */
37 struct device_node *of_find_node_by_phandle(phandle handle)
39 struct device_node *np;
41 for (np = allnodes; np != 0; np = np->allnext)
42 if (np->node == handle)
47 EXPORT_SYMBOL(of_find_node_by_phandle);
49 int of_getintprop_default(struct device_node *np, const char *name, int def)
51 struct property *prop;
54 prop = of_find_property(np, name, &len);
55 if (!prop || len != 4)
58 return *(int *) prop->value;
60 EXPORT_SYMBOL(of_getintprop_default);
62 int of_set_property(struct device_node *dp, const char *name, void *val, int len)
64 struct property **prevp;
68 new_val = kmalloc(len, GFP_KERNEL);
72 memcpy(new_val, val, len);
76 write_lock(&devtree_lock);
77 prevp = &dp->properties;
79 struct property *prop = *prevp;
81 if (!strcasecmp(prop->name, name)) {
82 void *old_val = prop->value;
85 ret = prom_setprop(dp->node, name, val, len);
88 prop->value = new_val;
91 if (OF_IS_DYNAMIC(prop))
94 OF_MARK_DYNAMIC(prop);
100 prevp = &(*prevp)->next;
102 write_unlock(&devtree_lock);
104 /* XXX Upate procfs if necessary... */
108 EXPORT_SYMBOL(of_set_property);
110 int of_find_in_proplist(const char *list, const char *match, int len)
115 if (!strcmp(list, match))
117 l = strlen(list) + 1;
123 EXPORT_SYMBOL(of_find_in_proplist);
125 static unsigned int prom_early_allocated;
127 static void * __init prom_early_alloc(unsigned long size)
131 ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
133 memset(ret, 0, size);
135 prom_early_allocated += size;
141 /* PSYCHO interrupt mapping support. */
142 #define PSYCHO_IMAP_A_SLOT0 0x0c00UL
143 #define PSYCHO_IMAP_B_SLOT0 0x0c20UL
144 static unsigned long psycho_pcislot_imap_offset(unsigned long ino)
146 unsigned int bus = (ino & 0x10) >> 4;
147 unsigned int slot = (ino & 0x0c) >> 2;
150 return PSYCHO_IMAP_A_SLOT0 + (slot * 8);
152 return PSYCHO_IMAP_B_SLOT0 + (slot * 8);
155 #define PSYCHO_IMAP_SCSI 0x1000UL
156 #define PSYCHO_IMAP_ETH 0x1008UL
157 #define PSYCHO_IMAP_BPP 0x1010UL
158 #define PSYCHO_IMAP_AU_REC 0x1018UL
159 #define PSYCHO_IMAP_AU_PLAY 0x1020UL
160 #define PSYCHO_IMAP_PFAIL 0x1028UL
161 #define PSYCHO_IMAP_KMS 0x1030UL
162 #define PSYCHO_IMAP_FLPY 0x1038UL
163 #define PSYCHO_IMAP_SHW 0x1040UL
164 #define PSYCHO_IMAP_KBD 0x1048UL
165 #define PSYCHO_IMAP_MS 0x1050UL
166 #define PSYCHO_IMAP_SER 0x1058UL
167 #define PSYCHO_IMAP_TIM0 0x1060UL
168 #define PSYCHO_IMAP_TIM1 0x1068UL
169 #define PSYCHO_IMAP_UE 0x1070UL
170 #define PSYCHO_IMAP_CE 0x1078UL
171 #define PSYCHO_IMAP_A_ERR 0x1080UL
172 #define PSYCHO_IMAP_B_ERR 0x1088UL
173 #define PSYCHO_IMAP_PMGMT 0x1090UL
174 #define PSYCHO_IMAP_GFX 0x1098UL
175 #define PSYCHO_IMAP_EUPA 0x10a0UL
177 static unsigned long __psycho_onboard_imap_off[] = {
178 /*0x20*/ PSYCHO_IMAP_SCSI,
179 /*0x21*/ PSYCHO_IMAP_ETH,
180 /*0x22*/ PSYCHO_IMAP_BPP,
181 /*0x23*/ PSYCHO_IMAP_AU_REC,
182 /*0x24*/ PSYCHO_IMAP_AU_PLAY,
183 /*0x25*/ PSYCHO_IMAP_PFAIL,
184 /*0x26*/ PSYCHO_IMAP_KMS,
185 /*0x27*/ PSYCHO_IMAP_FLPY,
186 /*0x28*/ PSYCHO_IMAP_SHW,
187 /*0x29*/ PSYCHO_IMAP_KBD,
188 /*0x2a*/ PSYCHO_IMAP_MS,
189 /*0x2b*/ PSYCHO_IMAP_SER,
190 /*0x2c*/ PSYCHO_IMAP_TIM0,
191 /*0x2d*/ PSYCHO_IMAP_TIM1,
192 /*0x2e*/ PSYCHO_IMAP_UE,
193 /*0x2f*/ PSYCHO_IMAP_CE,
194 /*0x30*/ PSYCHO_IMAP_A_ERR,
195 /*0x31*/ PSYCHO_IMAP_B_ERR,
196 /*0x32*/ PSYCHO_IMAP_PMGMT,
197 /*0x33*/ PSYCHO_IMAP_GFX,
198 /*0x34*/ PSYCHO_IMAP_EUPA,
200 #define PSYCHO_ONBOARD_IRQ_BASE 0x20
201 #define PSYCHO_ONBOARD_IRQ_LAST 0x34
202 #define psycho_onboard_imap_offset(__ino) \
203 __psycho_onboard_imap_off[(__ino) - PSYCHO_ONBOARD_IRQ_BASE]
205 #define PSYCHO_ICLR_A_SLOT0 0x1400UL
206 #define PSYCHO_ICLR_SCSI 0x1800UL
208 #define psycho_iclr_offset(ino) \
209 ((ino & 0x20) ? (PSYCHO_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
210 (PSYCHO_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
212 static unsigned int psycho_irq_build(struct device_node *dp,
216 unsigned long controller_regs = (unsigned long) _data;
217 unsigned long imap, iclr;
218 unsigned long imap_off, iclr_off;
222 if (ino < PSYCHO_ONBOARD_IRQ_BASE) {
224 imap_off = psycho_pcislot_imap_offset(ino);
227 if (ino > PSYCHO_ONBOARD_IRQ_LAST) {
228 prom_printf("psycho_irq_build: Wacky INO [%x]\n", ino);
231 imap_off = psycho_onboard_imap_offset(ino);
234 /* Now build the IRQ bucket. */
235 imap = controller_regs + imap_off;
237 iclr_off = psycho_iclr_offset(ino);
238 iclr = controller_regs + iclr_off;
240 if ((ino & 0x20) == 0)
241 inofixup = ino & 0x03;
243 return build_irq(inofixup, iclr, imap);
246 static void __init psycho_irq_trans_init(struct device_node *dp)
248 const struct linux_prom64_registers *regs;
250 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
251 dp->irq_trans->irq_build = psycho_irq_build;
253 regs = of_get_property(dp, "reg", NULL);
254 dp->irq_trans->data = (void *) regs[2].phys_addr;
257 #define sabre_read(__reg) \
259 __asm__ __volatile__("ldxa [%1] %2, %0" \
261 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
266 struct sabre_irq_data {
267 unsigned long controller_regs;
268 unsigned int pci_first_busno;
270 #define SABRE_CONFIGSPACE 0x001000000UL
271 #define SABRE_WRSYNC 0x1c20UL
273 #define SABRE_CONFIG_BASE(CONFIG_SPACE) \
274 (CONFIG_SPACE | (1UL << 24))
275 #define SABRE_CONFIG_ENCODE(BUS, DEVFN, REG) \
276 (((unsigned long)(BUS) << 16) | \
277 ((unsigned long)(DEVFN) << 8) | \
278 ((unsigned long)(REG)))
280 /* When a device lives behind a bridge deeper in the PCI bus topology
281 * than APB, a special sequence must run to make sure all pending DMA
282 * transfers at the time of IRQ delivery are visible in the coherency
283 * domain by the cpu. This sequence is to perform a read on the far
284 * side of the non-APB bridge, then perform a read of Sabre's DMA
285 * write-sync register.
287 static void sabre_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
289 unsigned int phys_hi = (unsigned int) (unsigned long) _arg1;
290 struct sabre_irq_data *irq_data = _arg2;
291 unsigned long controller_regs = irq_data->controller_regs;
292 unsigned long sync_reg = controller_regs + SABRE_WRSYNC;
293 unsigned long config_space = controller_regs + SABRE_CONFIGSPACE;
294 unsigned int bus, devfn;
297 config_space = SABRE_CONFIG_BASE(config_space);
299 bus = (phys_hi >> 16) & 0xff;
300 devfn = (phys_hi >> 8) & 0xff;
302 config_space |= SABRE_CONFIG_ENCODE(bus, devfn, 0x00);
304 __asm__ __volatile__("membar #Sync\n\t"
305 "lduha [%1] %2, %0\n\t"
308 : "r" ((u16 *) config_space),
309 "i" (ASI_PHYS_BYPASS_EC_E_L)
312 sabre_read(sync_reg);
315 #define SABRE_IMAP_A_SLOT0 0x0c00UL
316 #define SABRE_IMAP_B_SLOT0 0x0c20UL
317 #define SABRE_IMAP_SCSI 0x1000UL
318 #define SABRE_IMAP_ETH 0x1008UL
319 #define SABRE_IMAP_BPP 0x1010UL
320 #define SABRE_IMAP_AU_REC 0x1018UL
321 #define SABRE_IMAP_AU_PLAY 0x1020UL
322 #define SABRE_IMAP_PFAIL 0x1028UL
323 #define SABRE_IMAP_KMS 0x1030UL
324 #define SABRE_IMAP_FLPY 0x1038UL
325 #define SABRE_IMAP_SHW 0x1040UL
326 #define SABRE_IMAP_KBD 0x1048UL
327 #define SABRE_IMAP_MS 0x1050UL
328 #define SABRE_IMAP_SER 0x1058UL
329 #define SABRE_IMAP_UE 0x1070UL
330 #define SABRE_IMAP_CE 0x1078UL
331 #define SABRE_IMAP_PCIERR 0x1080UL
332 #define SABRE_IMAP_GFX 0x1098UL
333 #define SABRE_IMAP_EUPA 0x10a0UL
334 #define SABRE_ICLR_A_SLOT0 0x1400UL
335 #define SABRE_ICLR_B_SLOT0 0x1480UL
336 #define SABRE_ICLR_SCSI 0x1800UL
337 #define SABRE_ICLR_ETH 0x1808UL
338 #define SABRE_ICLR_BPP 0x1810UL
339 #define SABRE_ICLR_AU_REC 0x1818UL
340 #define SABRE_ICLR_AU_PLAY 0x1820UL
341 #define SABRE_ICLR_PFAIL 0x1828UL
342 #define SABRE_ICLR_KMS 0x1830UL
343 #define SABRE_ICLR_FLPY 0x1838UL
344 #define SABRE_ICLR_SHW 0x1840UL
345 #define SABRE_ICLR_KBD 0x1848UL
346 #define SABRE_ICLR_MS 0x1850UL
347 #define SABRE_ICLR_SER 0x1858UL
348 #define SABRE_ICLR_UE 0x1870UL
349 #define SABRE_ICLR_CE 0x1878UL
350 #define SABRE_ICLR_PCIERR 0x1880UL
352 static unsigned long sabre_pcislot_imap_offset(unsigned long ino)
354 unsigned int bus = (ino & 0x10) >> 4;
355 unsigned int slot = (ino & 0x0c) >> 2;
358 return SABRE_IMAP_A_SLOT0 + (slot * 8);
360 return SABRE_IMAP_B_SLOT0 + (slot * 8);
363 static unsigned long __sabre_onboard_imap_off[] = {
364 /*0x20*/ SABRE_IMAP_SCSI,
365 /*0x21*/ SABRE_IMAP_ETH,
366 /*0x22*/ SABRE_IMAP_BPP,
367 /*0x23*/ SABRE_IMAP_AU_REC,
368 /*0x24*/ SABRE_IMAP_AU_PLAY,
369 /*0x25*/ SABRE_IMAP_PFAIL,
370 /*0x26*/ SABRE_IMAP_KMS,
371 /*0x27*/ SABRE_IMAP_FLPY,
372 /*0x28*/ SABRE_IMAP_SHW,
373 /*0x29*/ SABRE_IMAP_KBD,
374 /*0x2a*/ SABRE_IMAP_MS,
375 /*0x2b*/ SABRE_IMAP_SER,
376 /*0x2c*/ 0 /* reserved */,
377 /*0x2d*/ 0 /* reserved */,
378 /*0x2e*/ SABRE_IMAP_UE,
379 /*0x2f*/ SABRE_IMAP_CE,
380 /*0x30*/ SABRE_IMAP_PCIERR,
381 /*0x31*/ 0 /* reserved */,
382 /*0x32*/ 0 /* reserved */,
383 /*0x33*/ SABRE_IMAP_GFX,
384 /*0x34*/ SABRE_IMAP_EUPA,
386 #define SABRE_ONBOARD_IRQ_BASE 0x20
387 #define SABRE_ONBOARD_IRQ_LAST 0x30
388 #define sabre_onboard_imap_offset(__ino) \
389 __sabre_onboard_imap_off[(__ino) - SABRE_ONBOARD_IRQ_BASE]
391 #define sabre_iclr_offset(ino) \
392 ((ino & 0x20) ? (SABRE_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
393 (SABRE_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
395 static int sabre_device_needs_wsync(struct device_node *dp)
397 struct device_node *parent = dp->parent;
398 const char *parent_model, *parent_compat;
400 /* This traversal up towards the root is meant to
403 * 1) non-PCI bus sitting under PCI, such as 'ebus'
404 * 2) the PCI controller interrupts themselves, which
405 * will use the sabre_irq_build but do not need
406 * the DMA synchronization handling
409 if (!strcmp(parent->type, "pci"))
411 parent = parent->parent;
417 parent_model = of_get_property(parent,
420 (!strcmp(parent_model, "SUNW,sabre") ||
421 !strcmp(parent_model, "SUNW,simba")))
424 parent_compat = of_get_property(parent,
427 (!strcmp(parent_compat, "pci108e,a000") ||
428 !strcmp(parent_compat, "pci108e,a001")))
434 static unsigned int sabre_irq_build(struct device_node *dp,
438 struct sabre_irq_data *irq_data = _data;
439 unsigned long controller_regs = irq_data->controller_regs;
440 const struct linux_prom_pci_registers *regs;
441 unsigned long imap, iclr;
442 unsigned long imap_off, iclr_off;
447 if (ino < SABRE_ONBOARD_IRQ_BASE) {
449 imap_off = sabre_pcislot_imap_offset(ino);
452 if (ino > SABRE_ONBOARD_IRQ_LAST) {
453 prom_printf("sabre_irq_build: Wacky INO [%x]\n", ino);
456 imap_off = sabre_onboard_imap_offset(ino);
459 /* Now build the IRQ bucket. */
460 imap = controller_regs + imap_off;
462 iclr_off = sabre_iclr_offset(ino);
463 iclr = controller_regs + iclr_off;
465 if ((ino & 0x20) == 0)
466 inofixup = ino & 0x03;
468 virt_irq = build_irq(inofixup, iclr, imap);
470 /* If the parent device is a PCI<->PCI bridge other than
471 * APB, we have to install a pre-handler to ensure that
472 * all pending DMA is drained before the interrupt handler
475 regs = of_get_property(dp, "reg", NULL);
476 if (regs && sabre_device_needs_wsync(dp)) {
477 irq_install_pre_handler(virt_irq,
479 (void *) (long) regs->phys_hi,
486 static void __init sabre_irq_trans_init(struct device_node *dp)
488 const struct linux_prom64_registers *regs;
489 struct sabre_irq_data *irq_data;
492 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
493 dp->irq_trans->irq_build = sabre_irq_build;
495 irq_data = prom_early_alloc(sizeof(struct sabre_irq_data));
497 regs = of_get_property(dp, "reg", NULL);
498 irq_data->controller_regs = regs[0].phys_addr;
500 busrange = of_get_property(dp, "bus-range", NULL);
501 irq_data->pci_first_busno = busrange[0];
503 dp->irq_trans->data = irq_data;
506 /* SCHIZO interrupt mapping support. Unlike Psycho, for this controller the
507 * imap/iclr registers are per-PBM.
509 #define SCHIZO_IMAP_BASE 0x1000UL
510 #define SCHIZO_ICLR_BASE 0x1400UL
512 static unsigned long schizo_imap_offset(unsigned long ino)
514 return SCHIZO_IMAP_BASE + (ino * 8UL);
517 static unsigned long schizo_iclr_offset(unsigned long ino)
519 return SCHIZO_ICLR_BASE + (ino * 8UL);
522 static unsigned long schizo_ino_to_iclr(unsigned long pbm_regs,
526 return pbm_regs + schizo_iclr_offset(ino);
529 static unsigned long schizo_ino_to_imap(unsigned long pbm_regs,
532 return pbm_regs + schizo_imap_offset(ino);
535 #define schizo_read(__reg) \
537 __asm__ __volatile__("ldxa [%1] %2, %0" \
539 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
543 #define schizo_write(__reg, __val) \
544 __asm__ __volatile__("stxa %0, [%1] %2" \
546 : "r" (__val), "r" (__reg), \
547 "i" (ASI_PHYS_BYPASS_EC_E) \
550 static void tomatillo_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
552 unsigned long sync_reg = (unsigned long) _arg2;
553 u64 mask = 1UL << (ino & IMAP_INO);
557 schizo_write(sync_reg, mask);
562 val = schizo_read(sync_reg);
567 printk("tomatillo_wsync_handler: DMA won't sync [%lx:%lx]\n",
572 static unsigned char cacheline[64]
573 __attribute__ ((aligned (64)));
575 __asm__ __volatile__("rd %%fprs, %0\n\t"
577 "wr %1, 0x0, %%fprs\n\t"
578 "stda %%f0, [%5] %6\n\t"
579 "wr %0, 0x0, %%fprs\n\t"
581 : "=&r" (mask), "=&r" (val)
582 : "0" (mask), "1" (val),
583 "i" (FPRS_FEF), "r" (&cacheline[0]),
584 "i" (ASI_BLK_COMMIT_P));
588 struct schizo_irq_data {
589 unsigned long pbm_regs;
590 unsigned long sync_reg;
595 static unsigned int schizo_irq_build(struct device_node *dp,
599 struct schizo_irq_data *irq_data = _data;
600 unsigned long pbm_regs = irq_data->pbm_regs;
601 unsigned long imap, iclr;
608 /* Now build the IRQ bucket. */
609 imap = schizo_ino_to_imap(pbm_regs, ino);
610 iclr = schizo_ino_to_iclr(pbm_regs, ino);
612 /* On Schizo, no inofixup occurs. This is because each
613 * INO has it's own IMAP register. On Psycho and Sabre
614 * there is only one IMAP register for each PCI slot even
615 * though four different INOs can be generated by each
618 * But, for JBUS variants (essentially, Tomatillo), we have
619 * to fixup the lowest bit of the interrupt group number.
623 is_tomatillo = (irq_data->sync_reg != 0UL);
626 if (irq_data->portid & 1)
627 ign_fixup = (1 << 6);
630 virt_irq = build_irq(ign_fixup, iclr, imap);
633 irq_install_pre_handler(virt_irq,
634 tomatillo_wsync_handler,
635 ((irq_data->chip_version <= 4) ?
636 (void *) 1 : (void *) 0),
637 (void *) irq_data->sync_reg);
643 static void __init __schizo_irq_trans_init(struct device_node *dp,
646 const struct linux_prom64_registers *regs;
647 struct schizo_irq_data *irq_data;
649 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
650 dp->irq_trans->irq_build = schizo_irq_build;
652 irq_data = prom_early_alloc(sizeof(struct schizo_irq_data));
654 regs = of_get_property(dp, "reg", NULL);
655 dp->irq_trans->data = irq_data;
657 irq_data->pbm_regs = regs[0].phys_addr;
659 irq_data->sync_reg = regs[3].phys_addr + 0x1a18UL;
661 irq_data->sync_reg = 0UL;
662 irq_data->portid = of_getintprop_default(dp, "portid", 0);
663 irq_data->chip_version = of_getintprop_default(dp, "version#", 0);
666 static void __init schizo_irq_trans_init(struct device_node *dp)
668 __schizo_irq_trans_init(dp, 0);
671 static void __init tomatillo_irq_trans_init(struct device_node *dp)
673 __schizo_irq_trans_init(dp, 1);
676 static unsigned int pci_sun4v_irq_build(struct device_node *dp,
680 u32 devhandle = (u32) (unsigned long) _data;
682 return sun4v_build_irq(devhandle, devino);
685 static void __init pci_sun4v_irq_trans_init(struct device_node *dp)
687 const struct linux_prom64_registers *regs;
689 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
690 dp->irq_trans->irq_build = pci_sun4v_irq_build;
692 regs = of_get_property(dp, "reg", NULL);
693 dp->irq_trans->data = (void *) (unsigned long)
694 ((regs->phys_addr >> 32UL) & 0x0fffffff);
697 struct fire_irq_data {
698 unsigned long pbm_regs;
702 #define FIRE_IMAP_BASE 0x001000
703 #define FIRE_ICLR_BASE 0x001400
705 static unsigned long fire_imap_offset(unsigned long ino)
707 return FIRE_IMAP_BASE + (ino * 8UL);
710 static unsigned long fire_iclr_offset(unsigned long ino)
712 return FIRE_ICLR_BASE + (ino * 8UL);
715 static unsigned long fire_ino_to_iclr(unsigned long pbm_regs,
718 return pbm_regs + fire_iclr_offset(ino);
721 static unsigned long fire_ino_to_imap(unsigned long pbm_regs,
724 return pbm_regs + fire_imap_offset(ino);
727 static unsigned int fire_irq_build(struct device_node *dp,
731 struct fire_irq_data *irq_data = _data;
732 unsigned long pbm_regs = irq_data->pbm_regs;
733 unsigned long imap, iclr;
734 unsigned long int_ctrlr;
738 /* Now build the IRQ bucket. */
739 imap = fire_ino_to_imap(pbm_regs, ino);
740 iclr = fire_ino_to_iclr(pbm_regs, ino);
742 /* Set the interrupt controller number. */
744 upa_writeq(int_ctrlr, imap);
746 /* The interrupt map registers do not have an INO field
747 * like other chips do. They return zero in the INO
748 * field, and the interrupt controller number is controlled
749 * in bits 6 to 9. So in order for build_irq() to get
750 * the INO right we pass it in as part of the fixup
751 * which will get added to the map register zero value
752 * read by build_irq().
754 ino |= (irq_data->portid << 6);
756 return build_irq(ino, iclr, imap);
759 static void __init fire_irq_trans_init(struct device_node *dp)
761 const struct linux_prom64_registers *regs;
762 struct fire_irq_data *irq_data;
764 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
765 dp->irq_trans->irq_build = fire_irq_build;
767 irq_data = prom_early_alloc(sizeof(struct fire_irq_data));
769 regs = of_get_property(dp, "reg", NULL);
770 dp->irq_trans->data = irq_data;
772 irq_data->pbm_regs = regs[0].phys_addr;
773 irq_data->portid = of_getintprop_default(dp, "portid", 0);
775 #endif /* CONFIG_PCI */
778 /* INO number to IMAP register offset for SYSIO external IRQ's.
779 * This should conform to both Sunfire/Wildfire server and Fusion
782 #define SYSIO_IMAP_SLOT0 0x2c00UL
783 #define SYSIO_IMAP_SLOT1 0x2c08UL
784 #define SYSIO_IMAP_SLOT2 0x2c10UL
785 #define SYSIO_IMAP_SLOT3 0x2c18UL
786 #define SYSIO_IMAP_SCSI 0x3000UL
787 #define SYSIO_IMAP_ETH 0x3008UL
788 #define SYSIO_IMAP_BPP 0x3010UL
789 #define SYSIO_IMAP_AUDIO 0x3018UL
790 #define SYSIO_IMAP_PFAIL 0x3020UL
791 #define SYSIO_IMAP_KMS 0x3028UL
792 #define SYSIO_IMAP_FLPY 0x3030UL
793 #define SYSIO_IMAP_SHW 0x3038UL
794 #define SYSIO_IMAP_KBD 0x3040UL
795 #define SYSIO_IMAP_MS 0x3048UL
796 #define SYSIO_IMAP_SER 0x3050UL
797 #define SYSIO_IMAP_TIM0 0x3060UL
798 #define SYSIO_IMAP_TIM1 0x3068UL
799 #define SYSIO_IMAP_UE 0x3070UL
800 #define SYSIO_IMAP_CE 0x3078UL
801 #define SYSIO_IMAP_SBERR 0x3080UL
802 #define SYSIO_IMAP_PMGMT 0x3088UL
803 #define SYSIO_IMAP_GFX 0x3090UL
804 #define SYSIO_IMAP_EUPA 0x3098UL
806 #define bogon ((unsigned long) -1)
807 static unsigned long sysio_irq_offsets[] = {
808 /* SBUS Slot 0 --> 3, level 1 --> 7 */
809 SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
810 SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
811 SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
812 SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
813 SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
814 SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
815 SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
816 SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
818 /* Onboard devices (not relevant/used on SunFire). */
849 #define NUM_SYSIO_OFFSETS ARRAY_SIZE(sysio_irq_offsets)
851 /* Convert Interrupt Mapping register pointer to associated
852 * Interrupt Clear register pointer, SYSIO specific version.
854 #define SYSIO_ICLR_UNUSED0 0x3400UL
855 #define SYSIO_ICLR_SLOT0 0x3408UL
856 #define SYSIO_ICLR_SLOT1 0x3448UL
857 #define SYSIO_ICLR_SLOT2 0x3488UL
858 #define SYSIO_ICLR_SLOT3 0x34c8UL
859 static unsigned long sysio_imap_to_iclr(unsigned long imap)
861 unsigned long diff = SYSIO_ICLR_UNUSED0 - SYSIO_IMAP_SLOT0;
865 static unsigned int sbus_of_build_irq(struct device_node *dp,
869 unsigned long reg_base = (unsigned long) _data;
870 const struct linux_prom_registers *regs;
871 unsigned long imap, iclr;
877 regs = of_get_property(dp, "reg", NULL);
879 sbus_slot = regs->which_io;
882 ino += (sbus_slot * 8);
884 imap = sysio_irq_offsets[ino];
885 if (imap == ((unsigned long)-1)) {
886 prom_printf("get_irq_translations: Bad SYSIO INO[%x]\n",
892 /* SYSIO inconsistency. For external SLOTS, we have to select
893 * the right ICLR register based upon the lower SBUS irq level
897 iclr = sysio_imap_to_iclr(imap);
899 sbus_level = ino & 0x7;
903 iclr = reg_base + SYSIO_ICLR_SLOT0;
906 iclr = reg_base + SYSIO_ICLR_SLOT1;
909 iclr = reg_base + SYSIO_ICLR_SLOT2;
913 iclr = reg_base + SYSIO_ICLR_SLOT3;
917 iclr += ((unsigned long)sbus_level - 1UL) * 8UL;
919 return build_irq(sbus_level, iclr, imap);
922 static void __init sbus_irq_trans_init(struct device_node *dp)
924 const struct linux_prom64_registers *regs;
926 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
927 dp->irq_trans->irq_build = sbus_of_build_irq;
929 regs = of_get_property(dp, "reg", NULL);
930 dp->irq_trans->data = (void *) (unsigned long) regs->phys_addr;
932 #endif /* CONFIG_SBUS */
935 static unsigned int central_build_irq(struct device_node *dp,
939 struct device_node *central_dp = _data;
940 struct of_device *central_op = of_find_device_by_node(central_dp);
941 struct resource *res;
942 unsigned long imap, iclr;
945 if (!strcmp(dp->name, "eeprom")) {
946 res = ¢ral_op->resource[5];
947 } else if (!strcmp(dp->name, "zs")) {
948 res = ¢ral_op->resource[4];
949 } else if (!strcmp(dp->name, "clock-board")) {
950 res = ¢ral_op->resource[3];
955 imap = res->start + 0x00UL;
956 iclr = res->start + 0x10UL;
958 /* Set the INO state to idle, and disable. */
962 tmp = upa_readl(imap);
964 upa_writel(tmp, imap);
966 return build_irq(0, iclr, imap);
969 static void __init central_irq_trans_init(struct device_node *dp)
971 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
972 dp->irq_trans->irq_build = central_build_irq;
974 dp->irq_trans->data = dp;
979 void (*init)(struct device_node *);
983 static struct irq_trans __initdata pci_irq_trans_table[] = {
984 { "SUNW,sabre", sabre_irq_trans_init },
985 { "pci108e,a000", sabre_irq_trans_init },
986 { "pci108e,a001", sabre_irq_trans_init },
987 { "SUNW,psycho", psycho_irq_trans_init },
988 { "pci108e,8000", psycho_irq_trans_init },
989 { "SUNW,schizo", schizo_irq_trans_init },
990 { "pci108e,8001", schizo_irq_trans_init },
991 { "SUNW,schizo+", schizo_irq_trans_init },
992 { "pci108e,8002", schizo_irq_trans_init },
993 { "SUNW,tomatillo", tomatillo_irq_trans_init },
994 { "pci108e,a801", tomatillo_irq_trans_init },
995 { "SUNW,sun4v-pci", pci_sun4v_irq_trans_init },
996 { "pciex108e,80f0", fire_irq_trans_init },
1000 static unsigned int sun4v_vdev_irq_build(struct device_node *dp,
1001 unsigned int devino,
1004 u32 devhandle = (u32) (unsigned long) _data;
1006 return sun4v_build_irq(devhandle, devino);
1009 static void __init sun4v_vdev_irq_trans_init(struct device_node *dp)
1011 const struct linux_prom64_registers *regs;
1013 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
1014 dp->irq_trans->irq_build = sun4v_vdev_irq_build;
1016 regs = of_get_property(dp, "reg", NULL);
1017 dp->irq_trans->data = (void *) (unsigned long)
1018 ((regs->phys_addr >> 32UL) & 0x0fffffff);
1021 static void __init irq_trans_init(struct device_node *dp)
1029 model = of_get_property(dp, "model", NULL);
1031 model = of_get_property(dp, "compatible", NULL);
1033 for (i = 0; i < ARRAY_SIZE(pci_irq_trans_table); i++) {
1034 struct irq_trans *t = &pci_irq_trans_table[i];
1036 if (!strcmp(model, t->name))
1042 if (!strcmp(dp->name, "sbus") ||
1043 !strcmp(dp->name, "sbi"))
1044 return sbus_irq_trans_init(dp);
1046 if (!strcmp(dp->name, "fhc") &&
1047 !strcmp(dp->parent->name, "central"))
1048 return central_irq_trans_init(dp);
1049 if (!strcmp(dp->name, "virtual-devices"))
1050 return sun4v_vdev_irq_trans_init(dp);
1053 static int is_root_node(const struct device_node *dp)
1058 return (dp->parent == NULL);
1061 /* The following routines deal with the black magic of fully naming a
1064 * Certain well known named nodes are just the simple name string.
1066 * Actual devices have an address specifier appended to the base name
1067 * string, like this "foo@addr". The "addr" can be in any number of
1068 * formats, and the platform plus the type of the node determine the
1069 * format and how it is constructed.
1071 * For children of the ROOT node, the naming convention is fixed and
1072 * determined by whether this is a sun4u or sun4v system.
1074 * For children of other nodes, it is bus type specific. So
1075 * we walk up the tree until we discover a "device_type" property
1076 * we recognize and we go from there.
1078 * As an example, the boot device on my workstation has a full path:
1080 * /pci@1e,600000/ide@d/disk@0,0:c
1082 static void __init sun4v_path_component(struct device_node *dp, char *tmp_buf)
1084 struct linux_prom64_registers *regs;
1085 struct property *rprop;
1086 u32 high_bits, low_bits, type;
1088 rprop = of_find_property(dp, "reg", NULL);
1092 regs = rprop->value;
1093 if (!is_root_node(dp->parent)) {
1094 sprintf(tmp_buf, "%s@%x,%x",
1096 (unsigned int) (regs->phys_addr >> 32UL),
1097 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1101 type = regs->phys_addr >> 60UL;
1102 high_bits = (regs->phys_addr >> 32UL) & 0x0fffffffUL;
1103 low_bits = (regs->phys_addr & 0xffffffffUL);
1105 if (type == 0 || type == 8) {
1106 const char *prefix = (type == 0) ? "m" : "i";
1109 sprintf(tmp_buf, "%s@%s%x,%x",
1111 high_bits, low_bits);
1113 sprintf(tmp_buf, "%s@%s%x",
1117 } else if (type == 12) {
1118 sprintf(tmp_buf, "%s@%x",
1119 dp->name, high_bits);
1123 static void __init sun4u_path_component(struct device_node *dp, char *tmp_buf)
1125 struct linux_prom64_registers *regs;
1126 struct property *prop;
1128 prop = of_find_property(dp, "reg", NULL);
1133 if (!is_root_node(dp->parent)) {
1134 sprintf(tmp_buf, "%s@%x,%x",
1136 (unsigned int) (regs->phys_addr >> 32UL),
1137 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1141 prop = of_find_property(dp, "upa-portid", NULL);
1143 prop = of_find_property(dp, "portid", NULL);
1145 unsigned long mask = 0xffffffffUL;
1147 if (tlb_type >= cheetah)
1150 sprintf(tmp_buf, "%s@%x,%x",
1152 *(u32 *)prop->value,
1153 (unsigned int) (regs->phys_addr & mask));
1157 /* "name@slot,offset" */
1158 static void __init sbus_path_component(struct device_node *dp, char *tmp_buf)
1160 struct linux_prom_registers *regs;
1161 struct property *prop;
1163 prop = of_find_property(dp, "reg", NULL);
1168 sprintf(tmp_buf, "%s@%x,%x",
1174 /* "name@devnum[,func]" */
1175 static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
1177 struct linux_prom_pci_registers *regs;
1178 struct property *prop;
1181 prop = of_find_property(dp, "reg", NULL);
1186 devfn = (regs->phys_hi >> 8) & 0xff;
1188 sprintf(tmp_buf, "%s@%x,%x",
1193 sprintf(tmp_buf, "%s@%x",
1199 /* "name@UPA_PORTID,offset" */
1200 static void __init upa_path_component(struct device_node *dp, char *tmp_buf)
1202 struct linux_prom64_registers *regs;
1203 struct property *prop;
1205 prop = of_find_property(dp, "reg", NULL);
1211 prop = of_find_property(dp, "upa-portid", NULL);
1215 sprintf(tmp_buf, "%s@%x,%x",
1217 *(u32 *) prop->value,
1218 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1222 static void __init vdev_path_component(struct device_node *dp, char *tmp_buf)
1224 struct property *prop;
1227 prop = of_find_property(dp, "reg", NULL);
1233 sprintf(tmp_buf, "%s@%x", dp->name, *regs);
1236 /* "name@addrhi,addrlo" */
1237 static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
1239 struct linux_prom64_registers *regs;
1240 struct property *prop;
1242 prop = of_find_property(dp, "reg", NULL);
1248 sprintf(tmp_buf, "%s@%x,%x",
1250 (unsigned int) (regs->phys_addr >> 32UL),
1251 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1254 /* "name@bus,addr" */
1255 static void __init i2c_path_component(struct device_node *dp, char *tmp_buf)
1257 struct property *prop;
1260 prop = of_find_property(dp, "reg", NULL);
1266 /* This actually isn't right... should look at the #address-cells
1267 * property of the i2c bus node etc. etc.
1269 sprintf(tmp_buf, "%s@%x,%x",
1270 dp->name, regs[0], regs[1]);
1273 /* "name@reg0[,reg1]" */
1274 static void __init usb_path_component(struct device_node *dp, char *tmp_buf)
1276 struct property *prop;
1279 prop = of_find_property(dp, "reg", NULL);
1285 if (prop->length == sizeof(u32) || regs[1] == 1) {
1286 sprintf(tmp_buf, "%s@%x",
1289 sprintf(tmp_buf, "%s@%x,%x",
1290 dp->name, regs[0], regs[1]);
1294 /* "name@reg0reg1[,reg2reg3]" */
1295 static void __init ieee1394_path_component(struct device_node *dp, char *tmp_buf)
1297 struct property *prop;
1300 prop = of_find_property(dp, "reg", NULL);
1306 if (regs[2] || regs[3]) {
1307 sprintf(tmp_buf, "%s@%08x%08x,%04x%08x",
1308 dp->name, regs[0], regs[1], regs[2], regs[3]);
1310 sprintf(tmp_buf, "%s@%08x%08x",
1311 dp->name, regs[0], regs[1]);
1315 static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
1317 struct device_node *parent = dp->parent;
1319 if (parent != NULL) {
1320 if (!strcmp(parent->type, "pci") ||
1321 !strcmp(parent->type, "pciex"))
1322 return pci_path_component(dp, tmp_buf);
1323 if (!strcmp(parent->type, "sbus"))
1324 return sbus_path_component(dp, tmp_buf);
1325 if (!strcmp(parent->type, "upa"))
1326 return upa_path_component(dp, tmp_buf);
1327 if (!strcmp(parent->type, "ebus"))
1328 return ebus_path_component(dp, tmp_buf);
1329 if (!strcmp(parent->name, "usb") ||
1330 !strcmp(parent->name, "hub"))
1331 return usb_path_component(dp, tmp_buf);
1332 if (!strcmp(parent->type, "i2c"))
1333 return i2c_path_component(dp, tmp_buf);
1334 if (!strcmp(parent->type, "firewire"))
1335 return ieee1394_path_component(dp, tmp_buf);
1336 if (!strcmp(parent->type, "virtual-devices"))
1337 return vdev_path_component(dp, tmp_buf);
1339 /* "isa" is handled with platform naming */
1342 /* Use platform naming convention. */
1343 if (tlb_type == hypervisor)
1344 return sun4v_path_component(dp, tmp_buf);
1346 return sun4u_path_component(dp, tmp_buf);
1349 static char * __init build_path_component(struct device_node *dp)
1351 char tmp_buf[64], *n;
1354 __build_path_component(dp, tmp_buf);
1355 if (tmp_buf[0] == '\0')
1356 strcpy(tmp_buf, dp->name);
1358 n = prom_early_alloc(strlen(tmp_buf) + 1);
1364 static char * __init build_full_name(struct device_node *dp)
1366 int len, ourlen, plen;
1369 plen = strlen(dp->parent->full_name);
1370 ourlen = strlen(dp->path_component_name);
1371 len = ourlen + plen + 2;
1373 n = prom_early_alloc(len);
1374 strcpy(n, dp->parent->full_name);
1375 if (!is_root_node(dp->parent)) {
1376 strcpy(n + plen, "/");
1379 strcpy(n + plen, dp->path_component_name);
1384 static unsigned int unique_id;
1386 static struct property * __init build_one_prop(phandle node, char *prev, char *special_name, void *special_val, int special_len)
1388 static struct property *tmp = NULL;
1393 memset(p, 0, sizeof(*p) + 32);
1396 p = prom_early_alloc(sizeof(struct property) + 32);
1397 p->unique_id = unique_id++;
1400 p->name = (char *) (p + 1);
1402 strcpy(p->name, special_name);
1403 p->length = special_len;
1404 p->value = prom_early_alloc(special_len);
1405 memcpy(p->value, special_val, special_len);
1408 prom_firstprop(node, p->name);
1410 prom_nextprop(node, prev, p->name);
1412 if (strlen(p->name) == 0) {
1416 p->length = prom_getproplen(node, p->name);
1417 if (p->length <= 0) {
1420 p->value = prom_early_alloc(p->length + 1);
1421 prom_getproperty(node, p->name, p->value, p->length);
1422 ((unsigned char *)p->value)[p->length] = '\0';
1428 static struct property * __init build_prop_list(phandle node)
1430 struct property *head, *tail;
1432 head = tail = build_one_prop(node, NULL,
1433 ".node", &node, sizeof(node));
1435 tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
1438 tail->next = build_one_prop(node, tail->name,
1446 static char * __init get_one_property(phandle node, const char *name)
1448 char *buf = "<NULL>";
1451 len = prom_getproplen(node, name);
1453 buf = prom_early_alloc(len);
1454 prom_getproperty(node, name, buf, len);
1460 static struct device_node * __init create_node(phandle node, struct device_node *parent)
1462 struct device_node *dp;
1467 dp = prom_early_alloc(sizeof(*dp));
1468 dp->unique_id = unique_id++;
1469 dp->parent = parent;
1471 kref_init(&dp->kref);
1473 dp->name = get_one_property(node, "name");
1474 dp->type = get_one_property(node, "device_type");
1477 dp->properties = build_prop_list(node);
1484 static struct device_node * __init build_tree(struct device_node *parent, phandle node, struct device_node ***nextp)
1486 struct device_node *ret = NULL, *prev_sibling = NULL;
1487 struct device_node *dp;
1490 dp = create_node(node, parent);
1495 prev_sibling->sibling = dp;
1502 *nextp = &dp->allnext;
1504 dp->path_component_name = build_path_component(dp);
1505 dp->full_name = build_full_name(dp);
1507 dp->child = build_tree(dp, prom_getchild(node), nextp);
1509 node = prom_getsibling(node);
1515 static const char *get_mid_prop(void)
1517 return (tlb_type == spitfire ? "upa-portid" : "portid");
1520 struct device_node *of_find_node_by_cpuid(int cpuid)
1522 struct device_node *dp;
1523 const char *mid_prop = get_mid_prop();
1525 for_each_node_by_type(dp, "cpu") {
1526 int id = of_getintprop_default(dp, mid_prop, -1);
1527 const char *this_mid_prop = mid_prop;
1530 this_mid_prop = "cpuid";
1531 id = of_getintprop_default(dp, this_mid_prop, -1);
1535 prom_printf("OF: Serious problem, cpu lacks "
1536 "%s property", this_mid_prop);
1545 static void __init of_fill_in_cpu_data(void)
1547 struct device_node *dp;
1548 const char *mid_prop = get_mid_prop();
1551 for_each_node_by_type(dp, "cpu") {
1552 int cpuid = of_getintprop_default(dp, mid_prop, -1);
1553 const char *this_mid_prop = mid_prop;
1554 struct device_node *portid_parent;
1557 portid_parent = NULL;
1559 this_mid_prop = "cpuid";
1560 cpuid = of_getintprop_default(dp, this_mid_prop, -1);
1566 portid_parent = portid_parent->parent;
1569 portid = of_getintprop_default(portid_parent,
1578 prom_printf("OF: Serious problem, cpu lacks "
1579 "%s property", this_mid_prop);
1586 if (cpuid >= NR_CPUS)
1589 /* On uniprocessor we only want the values for the
1590 * real physical cpu the kernel booted onto, however
1591 * cpu_data() only has one entry at index 0.
1593 if (cpuid != real_hard_smp_processor_id())
1598 cpu_data(cpuid).clock_tick =
1599 of_getintprop_default(dp, "clock-frequency", 0);
1601 if (portid_parent) {
1602 cpu_data(cpuid).dcache_size =
1603 of_getintprop_default(dp, "l1-dcache-size",
1605 cpu_data(cpuid).dcache_line_size =
1606 of_getintprop_default(dp, "l1-dcache-line-size",
1608 cpu_data(cpuid).icache_size =
1609 of_getintprop_default(dp, "l1-icache-size",
1611 cpu_data(cpuid).icache_line_size =
1612 of_getintprop_default(dp, "l1-icache-line-size",
1614 cpu_data(cpuid).ecache_size =
1615 of_getintprop_default(dp, "l2-cache-size", 0);
1616 cpu_data(cpuid).ecache_line_size =
1617 of_getintprop_default(dp, "l2-cache-line-size", 0);
1618 if (!cpu_data(cpuid).ecache_size ||
1619 !cpu_data(cpuid).ecache_line_size) {
1620 cpu_data(cpuid).ecache_size =
1621 of_getintprop_default(portid_parent,
1624 cpu_data(cpuid).ecache_line_size =
1625 of_getintprop_default(portid_parent,
1626 "l2-cache-line-size", 64);
1629 cpu_data(cpuid).core_id = portid + 1;
1630 cpu_data(cpuid).proc_id = portid;
1632 sparc64_multi_core = 1;
1635 cpu_data(cpuid).dcache_size =
1636 of_getintprop_default(dp, "dcache-size", 16 * 1024);
1637 cpu_data(cpuid).dcache_line_size =
1638 of_getintprop_default(dp, "dcache-line-size", 32);
1640 cpu_data(cpuid).icache_size =
1641 of_getintprop_default(dp, "icache-size", 16 * 1024);
1642 cpu_data(cpuid).icache_line_size =
1643 of_getintprop_default(dp, "icache-line-size", 32);
1645 cpu_data(cpuid).ecache_size =
1646 of_getintprop_default(dp, "ecache-size",
1648 cpu_data(cpuid).ecache_line_size =
1649 of_getintprop_default(dp, "ecache-line-size", 64);
1651 cpu_data(cpuid).core_id = 0;
1652 cpu_data(cpuid).proc_id = -1;
1656 cpu_set(cpuid, cpu_present_map);
1657 cpu_set(cpuid, cpu_possible_map);
1661 smp_fill_in_sib_core_maps();
1664 struct device_node *of_console_device;
1665 EXPORT_SYMBOL(of_console_device);
1667 char *of_console_path;
1668 EXPORT_SYMBOL(of_console_path);
1670 char *of_console_options;
1671 EXPORT_SYMBOL(of_console_options);
1673 static void __init of_console_init(void)
1675 char *msg = "OF stdout device is: %s\n";
1676 struct device_node *dp;
1680 of_console_path = prom_early_alloc(256);
1681 if (prom_ihandle2path(prom_stdout, of_console_path, 256) < 0) {
1682 prom_printf("Cannot obtain path of stdout.\n");
1685 of_console_options = strrchr(of_console_path, ':');
1686 if (of_console_options) {
1687 of_console_options++;
1688 if (*of_console_options == '\0')
1689 of_console_options = NULL;
1692 node = prom_inst2pkg(prom_stdout);
1694 prom_printf("Cannot resolve stdout node from "
1695 "instance %08x.\n", prom_stdout);
1699 dp = of_find_node_by_phandle(node);
1700 type = of_get_property(dp, "device_type", NULL);
1702 prom_printf("Console stdout lacks device_type property.\n");
1706 if (strcmp(type, "display") && strcmp(type, "serial")) {
1707 prom_printf("Console device_type is neither display "
1712 of_console_device = dp;
1714 prom_printf(msg, of_console_path);
1715 printk(msg, of_console_path);
1718 void __init prom_build_devicetree(void)
1720 struct device_node **nextp;
1722 allnodes = create_node(prom_root_node, NULL);
1723 allnodes->path_component_name = "";
1724 allnodes->full_name = "/";
1726 nextp = &allnodes->allnext;
1727 allnodes->child = build_tree(allnodes,
1728 prom_getchild(allnodes->node),
1732 printk("PROM: Built device tree with %u bytes of memory.\n",
1733 prom_early_allocated);
1735 if (tlb_type != hypervisor)
1736 of_fill_in_cpu_data();