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/module.h>
23 #include <linux/lmb.h>
24 #include <linux/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 DEFINE_MUTEX(of_set_property_mutex);
63 EXPORT_SYMBOL(of_set_property_mutex);
65 int of_set_property(struct device_node *dp, const char *name, void *val, int len)
67 struct property **prevp;
71 new_val = kmalloc(len, GFP_KERNEL);
75 memcpy(new_val, val, len);
79 write_lock(&devtree_lock);
80 prevp = &dp->properties;
82 struct property *prop = *prevp;
84 if (!strcasecmp(prop->name, name)) {
85 void *old_val = prop->value;
88 mutex_lock(&of_set_property_mutex);
89 ret = prom_setprop(dp->node, name, val, len);
90 mutex_unlock(&of_set_property_mutex);
94 prop->value = new_val;
97 if (OF_IS_DYNAMIC(prop))
100 OF_MARK_DYNAMIC(prop);
106 prevp = &(*prevp)->next;
108 write_unlock(&devtree_lock);
110 /* XXX Upate procfs if necessary... */
114 EXPORT_SYMBOL(of_set_property);
116 int of_find_in_proplist(const char *list, const char *match, int len)
121 if (!strcmp(list, match))
123 l = strlen(list) + 1;
129 EXPORT_SYMBOL(of_find_in_proplist);
131 static unsigned int prom_early_allocated __initdata;
133 static void * __init prom_early_alloc(unsigned long size)
135 unsigned long paddr = lmb_alloc(size, SMP_CACHE_BYTES);
139 prom_printf("prom_early_alloc(%lu) failed\n");
144 memset(ret, 0, size);
145 prom_early_allocated += size;
151 /* PSYCHO interrupt mapping support. */
152 #define PSYCHO_IMAP_A_SLOT0 0x0c00UL
153 #define PSYCHO_IMAP_B_SLOT0 0x0c20UL
154 static unsigned long psycho_pcislot_imap_offset(unsigned long ino)
156 unsigned int bus = (ino & 0x10) >> 4;
157 unsigned int slot = (ino & 0x0c) >> 2;
160 return PSYCHO_IMAP_A_SLOT0 + (slot * 8);
162 return PSYCHO_IMAP_B_SLOT0 + (slot * 8);
165 #define PSYCHO_IMAP_SCSI 0x1000UL
166 #define PSYCHO_IMAP_ETH 0x1008UL
167 #define PSYCHO_IMAP_BPP 0x1010UL
168 #define PSYCHO_IMAP_AU_REC 0x1018UL
169 #define PSYCHO_IMAP_AU_PLAY 0x1020UL
170 #define PSYCHO_IMAP_PFAIL 0x1028UL
171 #define PSYCHO_IMAP_KMS 0x1030UL
172 #define PSYCHO_IMAP_FLPY 0x1038UL
173 #define PSYCHO_IMAP_SHW 0x1040UL
174 #define PSYCHO_IMAP_KBD 0x1048UL
175 #define PSYCHO_IMAP_MS 0x1050UL
176 #define PSYCHO_IMAP_SER 0x1058UL
177 #define PSYCHO_IMAP_TIM0 0x1060UL
178 #define PSYCHO_IMAP_TIM1 0x1068UL
179 #define PSYCHO_IMAP_UE 0x1070UL
180 #define PSYCHO_IMAP_CE 0x1078UL
181 #define PSYCHO_IMAP_A_ERR 0x1080UL
182 #define PSYCHO_IMAP_B_ERR 0x1088UL
183 #define PSYCHO_IMAP_PMGMT 0x1090UL
184 #define PSYCHO_IMAP_GFX 0x1098UL
185 #define PSYCHO_IMAP_EUPA 0x10a0UL
187 static unsigned long __psycho_onboard_imap_off[] = {
188 /*0x20*/ PSYCHO_IMAP_SCSI,
189 /*0x21*/ PSYCHO_IMAP_ETH,
190 /*0x22*/ PSYCHO_IMAP_BPP,
191 /*0x23*/ PSYCHO_IMAP_AU_REC,
192 /*0x24*/ PSYCHO_IMAP_AU_PLAY,
193 /*0x25*/ PSYCHO_IMAP_PFAIL,
194 /*0x26*/ PSYCHO_IMAP_KMS,
195 /*0x27*/ PSYCHO_IMAP_FLPY,
196 /*0x28*/ PSYCHO_IMAP_SHW,
197 /*0x29*/ PSYCHO_IMAP_KBD,
198 /*0x2a*/ PSYCHO_IMAP_MS,
199 /*0x2b*/ PSYCHO_IMAP_SER,
200 /*0x2c*/ PSYCHO_IMAP_TIM0,
201 /*0x2d*/ PSYCHO_IMAP_TIM1,
202 /*0x2e*/ PSYCHO_IMAP_UE,
203 /*0x2f*/ PSYCHO_IMAP_CE,
204 /*0x30*/ PSYCHO_IMAP_A_ERR,
205 /*0x31*/ PSYCHO_IMAP_B_ERR,
206 /*0x32*/ PSYCHO_IMAP_PMGMT,
207 /*0x33*/ PSYCHO_IMAP_GFX,
208 /*0x34*/ PSYCHO_IMAP_EUPA,
210 #define PSYCHO_ONBOARD_IRQ_BASE 0x20
211 #define PSYCHO_ONBOARD_IRQ_LAST 0x34
212 #define psycho_onboard_imap_offset(__ino) \
213 __psycho_onboard_imap_off[(__ino) - PSYCHO_ONBOARD_IRQ_BASE]
215 #define PSYCHO_ICLR_A_SLOT0 0x1400UL
216 #define PSYCHO_ICLR_SCSI 0x1800UL
218 #define psycho_iclr_offset(ino) \
219 ((ino & 0x20) ? (PSYCHO_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
220 (PSYCHO_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
222 static unsigned int psycho_irq_build(struct device_node *dp,
226 unsigned long controller_regs = (unsigned long) _data;
227 unsigned long imap, iclr;
228 unsigned long imap_off, iclr_off;
232 if (ino < PSYCHO_ONBOARD_IRQ_BASE) {
234 imap_off = psycho_pcislot_imap_offset(ino);
237 if (ino > PSYCHO_ONBOARD_IRQ_LAST) {
238 prom_printf("psycho_irq_build: Wacky INO [%x]\n", ino);
241 imap_off = psycho_onboard_imap_offset(ino);
244 /* Now build the IRQ bucket. */
245 imap = controller_regs + imap_off;
247 iclr_off = psycho_iclr_offset(ino);
248 iclr = controller_regs + iclr_off;
250 if ((ino & 0x20) == 0)
251 inofixup = ino & 0x03;
253 return build_irq(inofixup, iclr, imap);
256 static void __init psycho_irq_trans_init(struct device_node *dp)
258 const struct linux_prom64_registers *regs;
260 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
261 dp->irq_trans->irq_build = psycho_irq_build;
263 regs = of_get_property(dp, "reg", NULL);
264 dp->irq_trans->data = (void *) regs[2].phys_addr;
267 #define sabre_read(__reg) \
269 __asm__ __volatile__("ldxa [%1] %2, %0" \
271 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
276 struct sabre_irq_data {
277 unsigned long controller_regs;
278 unsigned int pci_first_busno;
280 #define SABRE_CONFIGSPACE 0x001000000UL
281 #define SABRE_WRSYNC 0x1c20UL
283 #define SABRE_CONFIG_BASE(CONFIG_SPACE) \
284 (CONFIG_SPACE | (1UL << 24))
285 #define SABRE_CONFIG_ENCODE(BUS, DEVFN, REG) \
286 (((unsigned long)(BUS) << 16) | \
287 ((unsigned long)(DEVFN) << 8) | \
288 ((unsigned long)(REG)))
290 /* When a device lives behind a bridge deeper in the PCI bus topology
291 * than APB, a special sequence must run to make sure all pending DMA
292 * transfers at the time of IRQ delivery are visible in the coherency
293 * domain by the cpu. This sequence is to perform a read on the far
294 * side of the non-APB bridge, then perform a read of Sabre's DMA
295 * write-sync register.
297 static void sabre_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
299 unsigned int phys_hi = (unsigned int) (unsigned long) _arg1;
300 struct sabre_irq_data *irq_data = _arg2;
301 unsigned long controller_regs = irq_data->controller_regs;
302 unsigned long sync_reg = controller_regs + SABRE_WRSYNC;
303 unsigned long config_space = controller_regs + SABRE_CONFIGSPACE;
304 unsigned int bus, devfn;
307 config_space = SABRE_CONFIG_BASE(config_space);
309 bus = (phys_hi >> 16) & 0xff;
310 devfn = (phys_hi >> 8) & 0xff;
312 config_space |= SABRE_CONFIG_ENCODE(bus, devfn, 0x00);
314 __asm__ __volatile__("membar #Sync\n\t"
315 "lduha [%1] %2, %0\n\t"
318 : "r" ((u16 *) config_space),
319 "i" (ASI_PHYS_BYPASS_EC_E_L)
322 sabre_read(sync_reg);
325 #define SABRE_IMAP_A_SLOT0 0x0c00UL
326 #define SABRE_IMAP_B_SLOT0 0x0c20UL
327 #define SABRE_IMAP_SCSI 0x1000UL
328 #define SABRE_IMAP_ETH 0x1008UL
329 #define SABRE_IMAP_BPP 0x1010UL
330 #define SABRE_IMAP_AU_REC 0x1018UL
331 #define SABRE_IMAP_AU_PLAY 0x1020UL
332 #define SABRE_IMAP_PFAIL 0x1028UL
333 #define SABRE_IMAP_KMS 0x1030UL
334 #define SABRE_IMAP_FLPY 0x1038UL
335 #define SABRE_IMAP_SHW 0x1040UL
336 #define SABRE_IMAP_KBD 0x1048UL
337 #define SABRE_IMAP_MS 0x1050UL
338 #define SABRE_IMAP_SER 0x1058UL
339 #define SABRE_IMAP_UE 0x1070UL
340 #define SABRE_IMAP_CE 0x1078UL
341 #define SABRE_IMAP_PCIERR 0x1080UL
342 #define SABRE_IMAP_GFX 0x1098UL
343 #define SABRE_IMAP_EUPA 0x10a0UL
344 #define SABRE_ICLR_A_SLOT0 0x1400UL
345 #define SABRE_ICLR_B_SLOT0 0x1480UL
346 #define SABRE_ICLR_SCSI 0x1800UL
347 #define SABRE_ICLR_ETH 0x1808UL
348 #define SABRE_ICLR_BPP 0x1810UL
349 #define SABRE_ICLR_AU_REC 0x1818UL
350 #define SABRE_ICLR_AU_PLAY 0x1820UL
351 #define SABRE_ICLR_PFAIL 0x1828UL
352 #define SABRE_ICLR_KMS 0x1830UL
353 #define SABRE_ICLR_FLPY 0x1838UL
354 #define SABRE_ICLR_SHW 0x1840UL
355 #define SABRE_ICLR_KBD 0x1848UL
356 #define SABRE_ICLR_MS 0x1850UL
357 #define SABRE_ICLR_SER 0x1858UL
358 #define SABRE_ICLR_UE 0x1870UL
359 #define SABRE_ICLR_CE 0x1878UL
360 #define SABRE_ICLR_PCIERR 0x1880UL
362 static unsigned long sabre_pcislot_imap_offset(unsigned long ino)
364 unsigned int bus = (ino & 0x10) >> 4;
365 unsigned int slot = (ino & 0x0c) >> 2;
368 return SABRE_IMAP_A_SLOT0 + (slot * 8);
370 return SABRE_IMAP_B_SLOT0 + (slot * 8);
373 static unsigned long __sabre_onboard_imap_off[] = {
374 /*0x20*/ SABRE_IMAP_SCSI,
375 /*0x21*/ SABRE_IMAP_ETH,
376 /*0x22*/ SABRE_IMAP_BPP,
377 /*0x23*/ SABRE_IMAP_AU_REC,
378 /*0x24*/ SABRE_IMAP_AU_PLAY,
379 /*0x25*/ SABRE_IMAP_PFAIL,
380 /*0x26*/ SABRE_IMAP_KMS,
381 /*0x27*/ SABRE_IMAP_FLPY,
382 /*0x28*/ SABRE_IMAP_SHW,
383 /*0x29*/ SABRE_IMAP_KBD,
384 /*0x2a*/ SABRE_IMAP_MS,
385 /*0x2b*/ SABRE_IMAP_SER,
386 /*0x2c*/ 0 /* reserved */,
387 /*0x2d*/ 0 /* reserved */,
388 /*0x2e*/ SABRE_IMAP_UE,
389 /*0x2f*/ SABRE_IMAP_CE,
390 /*0x30*/ SABRE_IMAP_PCIERR,
391 /*0x31*/ 0 /* reserved */,
392 /*0x32*/ 0 /* reserved */,
393 /*0x33*/ SABRE_IMAP_GFX,
394 /*0x34*/ SABRE_IMAP_EUPA,
396 #define SABRE_ONBOARD_IRQ_BASE 0x20
397 #define SABRE_ONBOARD_IRQ_LAST 0x30
398 #define sabre_onboard_imap_offset(__ino) \
399 __sabre_onboard_imap_off[(__ino) - SABRE_ONBOARD_IRQ_BASE]
401 #define sabre_iclr_offset(ino) \
402 ((ino & 0x20) ? (SABRE_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
403 (SABRE_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
405 static int sabre_device_needs_wsync(struct device_node *dp)
407 struct device_node *parent = dp->parent;
408 const char *parent_model, *parent_compat;
410 /* This traversal up towards the root is meant to
413 * 1) non-PCI bus sitting under PCI, such as 'ebus'
414 * 2) the PCI controller interrupts themselves, which
415 * will use the sabre_irq_build but do not need
416 * the DMA synchronization handling
419 if (!strcmp(parent->type, "pci"))
421 parent = parent->parent;
427 parent_model = of_get_property(parent,
430 (!strcmp(parent_model, "SUNW,sabre") ||
431 !strcmp(parent_model, "SUNW,simba")))
434 parent_compat = of_get_property(parent,
437 (!strcmp(parent_compat, "pci108e,a000") ||
438 !strcmp(parent_compat, "pci108e,a001")))
444 static unsigned int sabre_irq_build(struct device_node *dp,
448 struct sabre_irq_data *irq_data = _data;
449 unsigned long controller_regs = irq_data->controller_regs;
450 const struct linux_prom_pci_registers *regs;
451 unsigned long imap, iclr;
452 unsigned long imap_off, iclr_off;
457 if (ino < SABRE_ONBOARD_IRQ_BASE) {
459 imap_off = sabre_pcislot_imap_offset(ino);
462 if (ino > SABRE_ONBOARD_IRQ_LAST) {
463 prom_printf("sabre_irq_build: Wacky INO [%x]\n", ino);
466 imap_off = sabre_onboard_imap_offset(ino);
469 /* Now build the IRQ bucket. */
470 imap = controller_regs + imap_off;
472 iclr_off = sabre_iclr_offset(ino);
473 iclr = controller_regs + iclr_off;
475 if ((ino & 0x20) == 0)
476 inofixup = ino & 0x03;
478 virt_irq = build_irq(inofixup, iclr, imap);
480 /* If the parent device is a PCI<->PCI bridge other than
481 * APB, we have to install a pre-handler to ensure that
482 * all pending DMA is drained before the interrupt handler
485 regs = of_get_property(dp, "reg", NULL);
486 if (regs && sabre_device_needs_wsync(dp)) {
487 irq_install_pre_handler(virt_irq,
489 (void *) (long) regs->phys_hi,
496 static void __init sabre_irq_trans_init(struct device_node *dp)
498 const struct linux_prom64_registers *regs;
499 struct sabre_irq_data *irq_data;
502 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
503 dp->irq_trans->irq_build = sabre_irq_build;
505 irq_data = prom_early_alloc(sizeof(struct sabre_irq_data));
507 regs = of_get_property(dp, "reg", NULL);
508 irq_data->controller_regs = regs[0].phys_addr;
510 busrange = of_get_property(dp, "bus-range", NULL);
511 irq_data->pci_first_busno = busrange[0];
513 dp->irq_trans->data = irq_data;
516 /* SCHIZO interrupt mapping support. Unlike Psycho, for this controller the
517 * imap/iclr registers are per-PBM.
519 #define SCHIZO_IMAP_BASE 0x1000UL
520 #define SCHIZO_ICLR_BASE 0x1400UL
522 static unsigned long schizo_imap_offset(unsigned long ino)
524 return SCHIZO_IMAP_BASE + (ino * 8UL);
527 static unsigned long schizo_iclr_offset(unsigned long ino)
529 return SCHIZO_ICLR_BASE + (ino * 8UL);
532 static unsigned long schizo_ino_to_iclr(unsigned long pbm_regs,
536 return pbm_regs + schizo_iclr_offset(ino);
539 static unsigned long schizo_ino_to_imap(unsigned long pbm_regs,
542 return pbm_regs + schizo_imap_offset(ino);
545 #define schizo_read(__reg) \
547 __asm__ __volatile__("ldxa [%1] %2, %0" \
549 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
553 #define schizo_write(__reg, __val) \
554 __asm__ __volatile__("stxa %0, [%1] %2" \
556 : "r" (__val), "r" (__reg), \
557 "i" (ASI_PHYS_BYPASS_EC_E) \
560 static void tomatillo_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
562 unsigned long sync_reg = (unsigned long) _arg2;
563 u64 mask = 1UL << (ino & IMAP_INO);
567 schizo_write(sync_reg, mask);
572 val = schizo_read(sync_reg);
577 printk("tomatillo_wsync_handler: DMA won't sync [%lx:%lx]\n",
582 static unsigned char cacheline[64]
583 __attribute__ ((aligned (64)));
585 __asm__ __volatile__("rd %%fprs, %0\n\t"
587 "wr %1, 0x0, %%fprs\n\t"
588 "stda %%f0, [%5] %6\n\t"
589 "wr %0, 0x0, %%fprs\n\t"
591 : "=&r" (mask), "=&r" (val)
592 : "0" (mask), "1" (val),
593 "i" (FPRS_FEF), "r" (&cacheline[0]),
594 "i" (ASI_BLK_COMMIT_P));
598 struct schizo_irq_data {
599 unsigned long pbm_regs;
600 unsigned long sync_reg;
605 static unsigned int schizo_irq_build(struct device_node *dp,
609 struct schizo_irq_data *irq_data = _data;
610 unsigned long pbm_regs = irq_data->pbm_regs;
611 unsigned long imap, iclr;
618 /* Now build the IRQ bucket. */
619 imap = schizo_ino_to_imap(pbm_regs, ino);
620 iclr = schizo_ino_to_iclr(pbm_regs, ino);
622 /* On Schizo, no inofixup occurs. This is because each
623 * INO has it's own IMAP register. On Psycho and Sabre
624 * there is only one IMAP register for each PCI slot even
625 * though four different INOs can be generated by each
628 * But, for JBUS variants (essentially, Tomatillo), we have
629 * to fixup the lowest bit of the interrupt group number.
633 is_tomatillo = (irq_data->sync_reg != 0UL);
636 if (irq_data->portid & 1)
637 ign_fixup = (1 << 6);
640 virt_irq = build_irq(ign_fixup, iclr, imap);
643 irq_install_pre_handler(virt_irq,
644 tomatillo_wsync_handler,
645 ((irq_data->chip_version <= 4) ?
646 (void *) 1 : (void *) 0),
647 (void *) irq_data->sync_reg);
653 static void __init __schizo_irq_trans_init(struct device_node *dp,
656 const struct linux_prom64_registers *regs;
657 struct schizo_irq_data *irq_data;
659 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
660 dp->irq_trans->irq_build = schizo_irq_build;
662 irq_data = prom_early_alloc(sizeof(struct schizo_irq_data));
664 regs = of_get_property(dp, "reg", NULL);
665 dp->irq_trans->data = irq_data;
667 irq_data->pbm_regs = regs[0].phys_addr;
669 irq_data->sync_reg = regs[3].phys_addr + 0x1a18UL;
671 irq_data->sync_reg = 0UL;
672 irq_data->portid = of_getintprop_default(dp, "portid", 0);
673 irq_data->chip_version = of_getintprop_default(dp, "version#", 0);
676 static void __init schizo_irq_trans_init(struct device_node *dp)
678 __schizo_irq_trans_init(dp, 0);
681 static void __init tomatillo_irq_trans_init(struct device_node *dp)
683 __schizo_irq_trans_init(dp, 1);
686 static unsigned int pci_sun4v_irq_build(struct device_node *dp,
690 u32 devhandle = (u32) (unsigned long) _data;
692 return sun4v_build_irq(devhandle, devino);
695 static void __init pci_sun4v_irq_trans_init(struct device_node *dp)
697 const struct linux_prom64_registers *regs;
699 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
700 dp->irq_trans->irq_build = pci_sun4v_irq_build;
702 regs = of_get_property(dp, "reg", NULL);
703 dp->irq_trans->data = (void *) (unsigned long)
704 ((regs->phys_addr >> 32UL) & 0x0fffffff);
707 struct fire_irq_data {
708 unsigned long pbm_regs;
712 #define FIRE_IMAP_BASE 0x001000
713 #define FIRE_ICLR_BASE 0x001400
715 static unsigned long fire_imap_offset(unsigned long ino)
717 return FIRE_IMAP_BASE + (ino * 8UL);
720 static unsigned long fire_iclr_offset(unsigned long ino)
722 return FIRE_ICLR_BASE + (ino * 8UL);
725 static unsigned long fire_ino_to_iclr(unsigned long pbm_regs,
728 return pbm_regs + fire_iclr_offset(ino);
731 static unsigned long fire_ino_to_imap(unsigned long pbm_regs,
734 return pbm_regs + fire_imap_offset(ino);
737 static unsigned int fire_irq_build(struct device_node *dp,
741 struct fire_irq_data *irq_data = _data;
742 unsigned long pbm_regs = irq_data->pbm_regs;
743 unsigned long imap, iclr;
744 unsigned long int_ctrlr;
748 /* Now build the IRQ bucket. */
749 imap = fire_ino_to_imap(pbm_regs, ino);
750 iclr = fire_ino_to_iclr(pbm_regs, ino);
752 /* Set the interrupt controller number. */
754 upa_writeq(int_ctrlr, imap);
756 /* The interrupt map registers do not have an INO field
757 * like other chips do. They return zero in the INO
758 * field, and the interrupt controller number is controlled
759 * in bits 6 to 9. So in order for build_irq() to get
760 * the INO right we pass it in as part of the fixup
761 * which will get added to the map register zero value
762 * read by build_irq().
764 ino |= (irq_data->portid << 6);
766 return build_irq(ino, iclr, imap);
769 static void __init fire_irq_trans_init(struct device_node *dp)
771 const struct linux_prom64_registers *regs;
772 struct fire_irq_data *irq_data;
774 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
775 dp->irq_trans->irq_build = fire_irq_build;
777 irq_data = prom_early_alloc(sizeof(struct fire_irq_data));
779 regs = of_get_property(dp, "reg", NULL);
780 dp->irq_trans->data = irq_data;
782 irq_data->pbm_regs = regs[0].phys_addr;
783 irq_data->portid = of_getintprop_default(dp, "portid", 0);
785 #endif /* CONFIG_PCI */
788 /* INO number to IMAP register offset for SYSIO external IRQ's.
789 * This should conform to both Sunfire/Wildfire server and Fusion
792 #define SYSIO_IMAP_SLOT0 0x2c00UL
793 #define SYSIO_IMAP_SLOT1 0x2c08UL
794 #define SYSIO_IMAP_SLOT2 0x2c10UL
795 #define SYSIO_IMAP_SLOT3 0x2c18UL
796 #define SYSIO_IMAP_SCSI 0x3000UL
797 #define SYSIO_IMAP_ETH 0x3008UL
798 #define SYSIO_IMAP_BPP 0x3010UL
799 #define SYSIO_IMAP_AUDIO 0x3018UL
800 #define SYSIO_IMAP_PFAIL 0x3020UL
801 #define SYSIO_IMAP_KMS 0x3028UL
802 #define SYSIO_IMAP_FLPY 0x3030UL
803 #define SYSIO_IMAP_SHW 0x3038UL
804 #define SYSIO_IMAP_KBD 0x3040UL
805 #define SYSIO_IMAP_MS 0x3048UL
806 #define SYSIO_IMAP_SER 0x3050UL
807 #define SYSIO_IMAP_TIM0 0x3060UL
808 #define SYSIO_IMAP_TIM1 0x3068UL
809 #define SYSIO_IMAP_UE 0x3070UL
810 #define SYSIO_IMAP_CE 0x3078UL
811 #define SYSIO_IMAP_SBERR 0x3080UL
812 #define SYSIO_IMAP_PMGMT 0x3088UL
813 #define SYSIO_IMAP_GFX 0x3090UL
814 #define SYSIO_IMAP_EUPA 0x3098UL
816 #define bogon ((unsigned long) -1)
817 static unsigned long sysio_irq_offsets[] = {
818 /* SBUS Slot 0 --> 3, level 1 --> 7 */
819 SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
820 SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0, SYSIO_IMAP_SLOT0,
821 SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
822 SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1, SYSIO_IMAP_SLOT1,
823 SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
824 SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2, SYSIO_IMAP_SLOT2,
825 SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
826 SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3, SYSIO_IMAP_SLOT3,
828 /* Onboard devices (not relevant/used on SunFire). */
859 #define NUM_SYSIO_OFFSETS ARRAY_SIZE(sysio_irq_offsets)
861 /* Convert Interrupt Mapping register pointer to associated
862 * Interrupt Clear register pointer, SYSIO specific version.
864 #define SYSIO_ICLR_UNUSED0 0x3400UL
865 #define SYSIO_ICLR_SLOT0 0x3408UL
866 #define SYSIO_ICLR_SLOT1 0x3448UL
867 #define SYSIO_ICLR_SLOT2 0x3488UL
868 #define SYSIO_ICLR_SLOT3 0x34c8UL
869 static unsigned long sysio_imap_to_iclr(unsigned long imap)
871 unsigned long diff = SYSIO_ICLR_UNUSED0 - SYSIO_IMAP_SLOT0;
875 static unsigned int sbus_of_build_irq(struct device_node *dp,
879 unsigned long reg_base = (unsigned long) _data;
880 const struct linux_prom_registers *regs;
881 unsigned long imap, iclr;
887 regs = of_get_property(dp, "reg", NULL);
889 sbus_slot = regs->which_io;
892 ino += (sbus_slot * 8);
894 imap = sysio_irq_offsets[ino];
895 if (imap == ((unsigned long)-1)) {
896 prom_printf("get_irq_translations: Bad SYSIO INO[%x]\n",
902 /* SYSIO inconsistency. For external SLOTS, we have to select
903 * the right ICLR register based upon the lower SBUS irq level
907 iclr = sysio_imap_to_iclr(imap);
909 sbus_level = ino & 0x7;
913 iclr = reg_base + SYSIO_ICLR_SLOT0;
916 iclr = reg_base + SYSIO_ICLR_SLOT1;
919 iclr = reg_base + SYSIO_ICLR_SLOT2;
923 iclr = reg_base + SYSIO_ICLR_SLOT3;
927 iclr += ((unsigned long)sbus_level - 1UL) * 8UL;
929 return build_irq(sbus_level, iclr, imap);
932 static void __init sbus_irq_trans_init(struct device_node *dp)
934 const struct linux_prom64_registers *regs;
936 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
937 dp->irq_trans->irq_build = sbus_of_build_irq;
939 regs = of_get_property(dp, "reg", NULL);
940 dp->irq_trans->data = (void *) (unsigned long) regs->phys_addr;
942 #endif /* CONFIG_SBUS */
945 static unsigned int central_build_irq(struct device_node *dp,
949 struct device_node *central_dp = _data;
950 struct of_device *central_op = of_find_device_by_node(central_dp);
951 struct resource *res;
952 unsigned long imap, iclr;
955 if (!strcmp(dp->name, "eeprom")) {
956 res = ¢ral_op->resource[5];
957 } else if (!strcmp(dp->name, "zs")) {
958 res = ¢ral_op->resource[4];
959 } else if (!strcmp(dp->name, "clock-board")) {
960 res = ¢ral_op->resource[3];
965 imap = res->start + 0x00UL;
966 iclr = res->start + 0x10UL;
968 /* Set the INO state to idle, and disable. */
972 tmp = upa_readl(imap);
974 upa_writel(tmp, imap);
976 return build_irq(0, iclr, imap);
979 static void __init central_irq_trans_init(struct device_node *dp)
981 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
982 dp->irq_trans->irq_build = central_build_irq;
984 dp->irq_trans->data = dp;
989 void (*init)(struct device_node *);
993 static struct irq_trans __initdata pci_irq_trans_table[] = {
994 { "SUNW,sabre", sabre_irq_trans_init },
995 { "pci108e,a000", sabre_irq_trans_init },
996 { "pci108e,a001", sabre_irq_trans_init },
997 { "SUNW,psycho", psycho_irq_trans_init },
998 { "pci108e,8000", psycho_irq_trans_init },
999 { "SUNW,schizo", schizo_irq_trans_init },
1000 { "pci108e,8001", schizo_irq_trans_init },
1001 { "SUNW,schizo+", schizo_irq_trans_init },
1002 { "pci108e,8002", schizo_irq_trans_init },
1003 { "SUNW,tomatillo", tomatillo_irq_trans_init },
1004 { "pci108e,a801", tomatillo_irq_trans_init },
1005 { "SUNW,sun4v-pci", pci_sun4v_irq_trans_init },
1006 { "pciex108e,80f0", fire_irq_trans_init },
1010 static unsigned int sun4v_vdev_irq_build(struct device_node *dp,
1011 unsigned int devino,
1014 u32 devhandle = (u32) (unsigned long) _data;
1016 return sun4v_build_irq(devhandle, devino);
1019 static void __init sun4v_vdev_irq_trans_init(struct device_node *dp)
1021 const struct linux_prom64_registers *regs;
1023 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
1024 dp->irq_trans->irq_build = sun4v_vdev_irq_build;
1026 regs = of_get_property(dp, "reg", NULL);
1027 dp->irq_trans->data = (void *) (unsigned long)
1028 ((regs->phys_addr >> 32UL) & 0x0fffffff);
1031 static void __init irq_trans_init(struct device_node *dp)
1039 model = of_get_property(dp, "model", NULL);
1041 model = of_get_property(dp, "compatible", NULL);
1043 for (i = 0; i < ARRAY_SIZE(pci_irq_trans_table); i++) {
1044 struct irq_trans *t = &pci_irq_trans_table[i];
1046 if (!strcmp(model, t->name))
1052 if (!strcmp(dp->name, "sbus") ||
1053 !strcmp(dp->name, "sbi"))
1054 return sbus_irq_trans_init(dp);
1056 if (!strcmp(dp->name, "fhc") &&
1057 !strcmp(dp->parent->name, "central"))
1058 return central_irq_trans_init(dp);
1059 if (!strcmp(dp->name, "virtual-devices") ||
1060 !strcmp(dp->name, "niu"))
1061 return sun4v_vdev_irq_trans_init(dp);
1064 static int is_root_node(const struct device_node *dp)
1069 return (dp->parent == NULL);
1072 /* The following routines deal with the black magic of fully naming a
1075 * Certain well known named nodes are just the simple name string.
1077 * Actual devices have an address specifier appended to the base name
1078 * string, like this "foo@addr". The "addr" can be in any number of
1079 * formats, and the platform plus the type of the node determine the
1080 * format and how it is constructed.
1082 * For children of the ROOT node, the naming convention is fixed and
1083 * determined by whether this is a sun4u or sun4v system.
1085 * For children of other nodes, it is bus type specific. So
1086 * we walk up the tree until we discover a "device_type" property
1087 * we recognize and we go from there.
1089 * As an example, the boot device on my workstation has a full path:
1091 * /pci@1e,600000/ide@d/disk@0,0:c
1093 static void __init sun4v_path_component(struct device_node *dp, char *tmp_buf)
1095 struct linux_prom64_registers *regs;
1096 struct property *rprop;
1097 u32 high_bits, low_bits, type;
1099 rprop = of_find_property(dp, "reg", NULL);
1103 regs = rprop->value;
1104 if (!is_root_node(dp->parent)) {
1105 sprintf(tmp_buf, "%s@%x,%x",
1107 (unsigned int) (regs->phys_addr >> 32UL),
1108 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1112 type = regs->phys_addr >> 60UL;
1113 high_bits = (regs->phys_addr >> 32UL) & 0x0fffffffUL;
1114 low_bits = (regs->phys_addr & 0xffffffffUL);
1116 if (type == 0 || type == 8) {
1117 const char *prefix = (type == 0) ? "m" : "i";
1120 sprintf(tmp_buf, "%s@%s%x,%x",
1122 high_bits, low_bits);
1124 sprintf(tmp_buf, "%s@%s%x",
1128 } else if (type == 12) {
1129 sprintf(tmp_buf, "%s@%x",
1130 dp->name, high_bits);
1134 static void __init sun4u_path_component(struct device_node *dp, char *tmp_buf)
1136 struct linux_prom64_registers *regs;
1137 struct property *prop;
1139 prop = of_find_property(dp, "reg", NULL);
1144 if (!is_root_node(dp->parent)) {
1145 sprintf(tmp_buf, "%s@%x,%x",
1147 (unsigned int) (regs->phys_addr >> 32UL),
1148 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1152 prop = of_find_property(dp, "upa-portid", NULL);
1154 prop = of_find_property(dp, "portid", NULL);
1156 unsigned long mask = 0xffffffffUL;
1158 if (tlb_type >= cheetah)
1161 sprintf(tmp_buf, "%s@%x,%x",
1163 *(u32 *)prop->value,
1164 (unsigned int) (regs->phys_addr & mask));
1168 /* "name@slot,offset" */
1169 static void __init sbus_path_component(struct device_node *dp, char *tmp_buf)
1171 struct linux_prom_registers *regs;
1172 struct property *prop;
1174 prop = of_find_property(dp, "reg", NULL);
1179 sprintf(tmp_buf, "%s@%x,%x",
1185 /* "name@devnum[,func]" */
1186 static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
1188 struct linux_prom_pci_registers *regs;
1189 struct property *prop;
1192 prop = of_find_property(dp, "reg", NULL);
1197 devfn = (regs->phys_hi >> 8) & 0xff;
1199 sprintf(tmp_buf, "%s@%x,%x",
1204 sprintf(tmp_buf, "%s@%x",
1210 /* "name@UPA_PORTID,offset" */
1211 static void __init upa_path_component(struct device_node *dp, char *tmp_buf)
1213 struct linux_prom64_registers *regs;
1214 struct property *prop;
1216 prop = of_find_property(dp, "reg", NULL);
1222 prop = of_find_property(dp, "upa-portid", NULL);
1226 sprintf(tmp_buf, "%s@%x,%x",
1228 *(u32 *) prop->value,
1229 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1233 static void __init vdev_path_component(struct device_node *dp, char *tmp_buf)
1235 struct property *prop;
1238 prop = of_find_property(dp, "reg", NULL);
1244 sprintf(tmp_buf, "%s@%x", dp->name, *regs);
1247 /* "name@addrhi,addrlo" */
1248 static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
1250 struct linux_prom64_registers *regs;
1251 struct property *prop;
1253 prop = of_find_property(dp, "reg", NULL);
1259 sprintf(tmp_buf, "%s@%x,%x",
1261 (unsigned int) (regs->phys_addr >> 32UL),
1262 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1265 /* "name@bus,addr" */
1266 static void __init i2c_path_component(struct device_node *dp, char *tmp_buf)
1268 struct property *prop;
1271 prop = of_find_property(dp, "reg", NULL);
1277 /* This actually isn't right... should look at the #address-cells
1278 * property of the i2c bus node etc. etc.
1280 sprintf(tmp_buf, "%s@%x,%x",
1281 dp->name, regs[0], regs[1]);
1284 /* "name@reg0[,reg1]" */
1285 static void __init usb_path_component(struct device_node *dp, char *tmp_buf)
1287 struct property *prop;
1290 prop = of_find_property(dp, "reg", NULL);
1296 if (prop->length == sizeof(u32) || regs[1] == 1) {
1297 sprintf(tmp_buf, "%s@%x",
1300 sprintf(tmp_buf, "%s@%x,%x",
1301 dp->name, regs[0], regs[1]);
1305 /* "name@reg0reg1[,reg2reg3]" */
1306 static void __init ieee1394_path_component(struct device_node *dp, char *tmp_buf)
1308 struct property *prop;
1311 prop = of_find_property(dp, "reg", NULL);
1317 if (regs[2] || regs[3]) {
1318 sprintf(tmp_buf, "%s@%08x%08x,%04x%08x",
1319 dp->name, regs[0], regs[1], regs[2], regs[3]);
1321 sprintf(tmp_buf, "%s@%08x%08x",
1322 dp->name, regs[0], regs[1]);
1326 static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
1328 struct device_node *parent = dp->parent;
1330 if (parent != NULL) {
1331 if (!strcmp(parent->type, "pci") ||
1332 !strcmp(parent->type, "pciex"))
1333 return pci_path_component(dp, tmp_buf);
1334 if (!strcmp(parent->type, "sbus"))
1335 return sbus_path_component(dp, tmp_buf);
1336 if (!strcmp(parent->type, "upa"))
1337 return upa_path_component(dp, tmp_buf);
1338 if (!strcmp(parent->type, "ebus"))
1339 return ebus_path_component(dp, tmp_buf);
1340 if (!strcmp(parent->name, "usb") ||
1341 !strcmp(parent->name, "hub"))
1342 return usb_path_component(dp, tmp_buf);
1343 if (!strcmp(parent->type, "i2c"))
1344 return i2c_path_component(dp, tmp_buf);
1345 if (!strcmp(parent->type, "firewire"))
1346 return ieee1394_path_component(dp, tmp_buf);
1347 if (!strcmp(parent->type, "virtual-devices"))
1348 return vdev_path_component(dp, tmp_buf);
1350 /* "isa" is handled with platform naming */
1353 /* Use platform naming convention. */
1354 if (tlb_type == hypervisor)
1355 return sun4v_path_component(dp, tmp_buf);
1357 return sun4u_path_component(dp, tmp_buf);
1360 static char * __init build_path_component(struct device_node *dp)
1362 char tmp_buf[64], *n;
1365 __build_path_component(dp, tmp_buf);
1366 if (tmp_buf[0] == '\0')
1367 strcpy(tmp_buf, dp->name);
1369 n = prom_early_alloc(strlen(tmp_buf) + 1);
1375 static char * __init build_full_name(struct device_node *dp)
1377 int len, ourlen, plen;
1380 plen = strlen(dp->parent->full_name);
1381 ourlen = strlen(dp->path_component_name);
1382 len = ourlen + plen + 2;
1384 n = prom_early_alloc(len);
1385 strcpy(n, dp->parent->full_name);
1386 if (!is_root_node(dp->parent)) {
1387 strcpy(n + plen, "/");
1390 strcpy(n + plen, dp->path_component_name);
1395 static unsigned int unique_id;
1397 static struct property * __init build_one_prop(phandle node, char *prev, char *special_name, void *special_val, int special_len)
1399 static struct property *tmp = NULL;
1404 memset(p, 0, sizeof(*p) + 32);
1407 p = prom_early_alloc(sizeof(struct property) + 32);
1408 p->unique_id = unique_id++;
1411 p->name = (char *) (p + 1);
1413 strcpy(p->name, special_name);
1414 p->length = special_len;
1415 p->value = prom_early_alloc(special_len);
1416 memcpy(p->value, special_val, special_len);
1419 prom_firstprop(node, p->name);
1421 prom_nextprop(node, prev, p->name);
1423 if (strlen(p->name) == 0) {
1427 p->length = prom_getproplen(node, p->name);
1428 if (p->length <= 0) {
1431 p->value = prom_early_alloc(p->length + 1);
1432 prom_getproperty(node, p->name, p->value, p->length);
1433 ((unsigned char *)p->value)[p->length] = '\0';
1439 static struct property * __init build_prop_list(phandle node)
1441 struct property *head, *tail;
1443 head = tail = build_one_prop(node, NULL,
1444 ".node", &node, sizeof(node));
1446 tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
1449 tail->next = build_one_prop(node, tail->name,
1457 static char * __init get_one_property(phandle node, const char *name)
1459 char *buf = "<NULL>";
1462 len = prom_getproplen(node, name);
1464 buf = prom_early_alloc(len);
1465 prom_getproperty(node, name, buf, len);
1471 static struct device_node * __init create_node(phandle node, struct device_node *parent)
1473 struct device_node *dp;
1478 dp = prom_early_alloc(sizeof(*dp));
1479 dp->unique_id = unique_id++;
1480 dp->parent = parent;
1482 kref_init(&dp->kref);
1484 dp->name = get_one_property(node, "name");
1485 dp->type = get_one_property(node, "device_type");
1488 dp->properties = build_prop_list(node);
1495 static struct device_node * __init build_tree(struct device_node *parent, phandle node, struct device_node ***nextp)
1497 struct device_node *ret = NULL, *prev_sibling = NULL;
1498 struct device_node *dp;
1501 dp = create_node(node, parent);
1506 prev_sibling->sibling = dp;
1513 *nextp = &dp->allnext;
1515 dp->path_component_name = build_path_component(dp);
1516 dp->full_name = build_full_name(dp);
1518 dp->child = build_tree(dp, prom_getchild(node), nextp);
1520 node = prom_getsibling(node);
1526 static const char *get_mid_prop(void)
1528 return (tlb_type == spitfire ? "upa-portid" : "portid");
1531 struct device_node *of_find_node_by_cpuid(int cpuid)
1533 struct device_node *dp;
1534 const char *mid_prop = get_mid_prop();
1536 for_each_node_by_type(dp, "cpu") {
1537 int id = of_getintprop_default(dp, mid_prop, -1);
1538 const char *this_mid_prop = mid_prop;
1541 this_mid_prop = "cpuid";
1542 id = of_getintprop_default(dp, this_mid_prop, -1);
1546 prom_printf("OF: Serious problem, cpu lacks "
1547 "%s property", this_mid_prop);
1556 static void __init of_fill_in_cpu_data(void)
1558 struct device_node *dp;
1559 const char *mid_prop = get_mid_prop();
1562 for_each_node_by_type(dp, "cpu") {
1563 int cpuid = of_getintprop_default(dp, mid_prop, -1);
1564 const char *this_mid_prop = mid_prop;
1565 struct device_node *portid_parent;
1568 portid_parent = NULL;
1570 this_mid_prop = "cpuid";
1571 cpuid = of_getintprop_default(dp, this_mid_prop, -1);
1577 portid_parent = portid_parent->parent;
1580 portid = of_getintprop_default(portid_parent,
1589 prom_printf("OF: Serious problem, cpu lacks "
1590 "%s property", this_mid_prop);
1597 if (cpuid >= NR_CPUS) {
1598 printk(KERN_WARNING "Ignoring CPU %d which is "
1599 ">= NR_CPUS (%d)\n",
1604 /* On uniprocessor we only want the values for the
1605 * real physical cpu the kernel booted onto, however
1606 * cpu_data() only has one entry at index 0.
1608 if (cpuid != real_hard_smp_processor_id())
1613 cpu_data(cpuid).clock_tick =
1614 of_getintprop_default(dp, "clock-frequency", 0);
1616 if (portid_parent) {
1617 cpu_data(cpuid).dcache_size =
1618 of_getintprop_default(dp, "l1-dcache-size",
1620 cpu_data(cpuid).dcache_line_size =
1621 of_getintprop_default(dp, "l1-dcache-line-size",
1623 cpu_data(cpuid).icache_size =
1624 of_getintprop_default(dp, "l1-icache-size",
1626 cpu_data(cpuid).icache_line_size =
1627 of_getintprop_default(dp, "l1-icache-line-size",
1629 cpu_data(cpuid).ecache_size =
1630 of_getintprop_default(dp, "l2-cache-size", 0);
1631 cpu_data(cpuid).ecache_line_size =
1632 of_getintprop_default(dp, "l2-cache-line-size", 0);
1633 if (!cpu_data(cpuid).ecache_size ||
1634 !cpu_data(cpuid).ecache_line_size) {
1635 cpu_data(cpuid).ecache_size =
1636 of_getintprop_default(portid_parent,
1639 cpu_data(cpuid).ecache_line_size =
1640 of_getintprop_default(portid_parent,
1641 "l2-cache-line-size", 64);
1644 cpu_data(cpuid).core_id = portid + 1;
1645 cpu_data(cpuid).proc_id = portid;
1647 sparc64_multi_core = 1;
1650 cpu_data(cpuid).dcache_size =
1651 of_getintprop_default(dp, "dcache-size", 16 * 1024);
1652 cpu_data(cpuid).dcache_line_size =
1653 of_getintprop_default(dp, "dcache-line-size", 32);
1655 cpu_data(cpuid).icache_size =
1656 of_getintprop_default(dp, "icache-size", 16 * 1024);
1657 cpu_data(cpuid).icache_line_size =
1658 of_getintprop_default(dp, "icache-line-size", 32);
1660 cpu_data(cpuid).ecache_size =
1661 of_getintprop_default(dp, "ecache-size",
1663 cpu_data(cpuid).ecache_line_size =
1664 of_getintprop_default(dp, "ecache-line-size", 64);
1666 cpu_data(cpuid).core_id = 0;
1667 cpu_data(cpuid).proc_id = -1;
1671 cpu_set(cpuid, cpu_present_map);
1672 cpu_set(cpuid, cpu_possible_map);
1676 smp_fill_in_sib_core_maps();
1679 struct device_node *of_console_device;
1680 EXPORT_SYMBOL(of_console_device);
1682 char *of_console_path;
1683 EXPORT_SYMBOL(of_console_path);
1685 char *of_console_options;
1686 EXPORT_SYMBOL(of_console_options);
1688 static void __init of_console_init(void)
1690 char *msg = "OF stdout device is: %s\n";
1691 struct device_node *dp;
1695 of_console_path = prom_early_alloc(256);
1696 if (prom_ihandle2path(prom_stdout, of_console_path, 256) < 0) {
1697 prom_printf("Cannot obtain path of stdout.\n");
1700 of_console_options = strrchr(of_console_path, ':');
1701 if (of_console_options) {
1702 of_console_options++;
1703 if (*of_console_options == '\0')
1704 of_console_options = NULL;
1707 node = prom_inst2pkg(prom_stdout);
1709 prom_printf("Cannot resolve stdout node from "
1710 "instance %08x.\n", prom_stdout);
1714 dp = of_find_node_by_phandle(node);
1715 type = of_get_property(dp, "device_type", NULL);
1717 prom_printf("Console stdout lacks device_type property.\n");
1721 if (strcmp(type, "display") && strcmp(type, "serial")) {
1722 prom_printf("Console device_type is neither display "
1727 of_console_device = dp;
1729 printk(msg, of_console_path);
1732 void __init prom_build_devicetree(void)
1734 struct device_node **nextp;
1736 allnodes = create_node(prom_root_node, NULL);
1737 allnodes->path_component_name = "";
1738 allnodes->full_name = "/";
1740 nextp = &allnodes->allnext;
1741 allnodes->child = build_tree(allnodes,
1742 prom_getchild(allnodes->node),
1746 printk("PROM: Built device tree with %u bytes of memory.\n",
1747 prom_early_allocated);
1749 if (tlb_type != hypervisor)
1750 of_fill_in_cpu_data();