blob: 5f50e2b17a8fb3b977f6846ac5aa327b5cf952e4 [file] [log] [blame]
David S. Miller372b07b2006-06-21 15:35:28 -07001/*
2 * Procedures for creating, accessing and interpreting the device tree.
3 *
4 * Paul Mackerras August 1996.
5 * Copyright (C) 1996-2005 Paul Mackerras.
6 *
7 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
8 * {engebret|bergner}@us.ibm.com
9 *
10 * Adapted for sparc64 by David S. Miller davem@davemloft.net
11 *
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.
16 */
17
18#include <linux/kernel.h>
19#include <linux/types.h>
20#include <linux/string.h>
21#include <linux/mm.h>
David S. Millerde8d28b2006-06-22 16:18:54 -070022#include <linux/module.h>
David S. Millerad072002008-02-13 19:21:51 -080023#include <linux/lmb.h>
Stephen Rothwell764f2572008-08-07 15:33:36 -070024#include <linux/of_device.h>
David S. Miller372b07b2006-06-21 15:35:28 -070025
26#include <asm/prom.h>
27#include <asm/oplib.h>
David S. Miller2b1e5972006-06-29 15:07:37 -070028#include <asm/irq.h>
29#include <asm/asi.h>
30#include <asm/upa.h>
David S. Miller5cbc3072007-05-25 15:49:59 -070031#include <asm/smp.h>
David S. Miller372b07b2006-06-21 15:35:28 -070032
Stephen Rothwell1ef4d422007-04-24 17:57:33 +100033extern struct device_node *allnodes; /* temporary while merging */
David S. Miller372b07b2006-06-21 15:35:28 -070034
Stephen Rothwell581b6052007-04-24 16:46:53 +100035extern rwlock_t devtree_lock; /* temporary while merging */
David S. Millerfb7cd9d2006-06-25 23:18:36 -070036
David S. Millerde8d28b2006-06-22 16:18:54 -070037struct device_node *of_find_node_by_phandle(phandle handle)
38{
39 struct device_node *np;
40
David S. Millerc91e2ec2008-09-11 23:52:35 -070041 for (np = allnodes; np; np = np->allnext)
David S. Millerde8d28b2006-06-22 16:18:54 -070042 if (np->node == handle)
43 break;
44
45 return np;
46}
David S. Miller8cd24ed2006-06-22 22:08:58 -070047EXPORT_SYMBOL(of_find_node_by_phandle);
David S. Millerde8d28b2006-06-22 16:18:54 -070048
David S. Miller6d307722006-06-21 23:07:29 -070049int of_getintprop_default(struct device_node *np, const char *name, int def)
50{
51 struct property *prop;
52 int len;
53
54 prop = of_find_property(np, name, &len);
55 if (!prop || len != 4)
56 return def;
57
58 return *(int *) prop->value;
59}
David S. Millerde8d28b2006-06-22 16:18:54 -070060EXPORT_SYMBOL(of_getintprop_default);
David S. Miller6d307722006-06-21 23:07:29 -070061
David S. Miller2481d762008-08-19 21:56:35 -070062DEFINE_MUTEX(of_set_property_mutex);
63EXPORT_SYMBOL(of_set_property_mutex);
64
David S. Millerfb7cd9d2006-06-25 23:18:36 -070065int of_set_property(struct device_node *dp, const char *name, void *val, int len)
66{
67 struct property **prevp;
68 void *new_val;
69 int err;
70
71 new_val = kmalloc(len, GFP_KERNEL);
72 if (!new_val)
73 return -ENOMEM;
74
75 memcpy(new_val, val, len);
76
77 err = -ENODEV;
78
79 write_lock(&devtree_lock);
80 prevp = &dp->properties;
81 while (*prevp) {
82 struct property *prop = *prevp;
83
David S. Millera8b88142007-03-29 01:28:51 -070084 if (!strcasecmp(prop->name, name)) {
David S. Millerfb7cd9d2006-06-25 23:18:36 -070085 void *old_val = prop->value;
86 int ret;
87
David S. Miller2481d762008-08-19 21:56:35 -070088 mutex_lock(&of_set_property_mutex);
David S. Millerfb7cd9d2006-06-25 23:18:36 -070089 ret = prom_setprop(dp->node, name, val, len);
David S. Miller2481d762008-08-19 21:56:35 -070090 mutex_unlock(&of_set_property_mutex);
91
David S. Millerfb7cd9d2006-06-25 23:18:36 -070092 err = -EINVAL;
93 if (ret >= 0) {
94 prop->value = new_val;
95 prop->length = len;
96
97 if (OF_IS_DYNAMIC(prop))
98 kfree(old_val);
99
100 OF_MARK_DYNAMIC(prop);
101
102 err = 0;
103 }
104 break;
105 }
106 prevp = &(*prevp)->next;
107 }
108 write_unlock(&devtree_lock);
109
110 /* XXX Upate procfs if necessary... */
111
112 return err;
113}
114EXPORT_SYMBOL(of_set_property);
115
David S. Miller46bcea72007-08-07 18:46:36 -0700116int of_find_in_proplist(const char *list, const char *match, int len)
117{
118 while (len > 0) {
119 int l;
120
121 if (!strcmp(list, match))
122 return 1;
123 l = strlen(list) + 1;
124 list += l;
125 len -= l;
126 }
127 return 0;
128}
129EXPORT_SYMBOL(of_find_in_proplist);
130
David S. Millerad072002008-02-13 19:21:51 -0800131static unsigned int prom_early_allocated __initdata;
David S. Miller372b07b2006-06-21 15:35:28 -0700132
133static void * __init prom_early_alloc(unsigned long size)
134{
David S. Millerad072002008-02-13 19:21:51 -0800135 unsigned long paddr = lmb_alloc(size, SMP_CACHE_BYTES);
David S. Miller372b07b2006-06-21 15:35:28 -0700136 void *ret;
137
David S. Millerad072002008-02-13 19:21:51 -0800138 if (!paddr) {
139 prom_printf("prom_early_alloc(%lu) failed\n");
140 prom_halt();
141 }
David S. Miller372b07b2006-06-21 15:35:28 -0700142
David S. Millerad072002008-02-13 19:21:51 -0800143 ret = __va(paddr);
144 memset(ret, 0, size);
David S. Miller372b07b2006-06-21 15:35:28 -0700145 prom_early_allocated += size;
146
147 return ret;
148}
149
David S. Miller2b1e5972006-06-29 15:07:37 -0700150#ifdef CONFIG_PCI
151/* PSYCHO interrupt mapping support. */
152#define PSYCHO_IMAP_A_SLOT0 0x0c00UL
153#define PSYCHO_IMAP_B_SLOT0 0x0c20UL
154static unsigned long psycho_pcislot_imap_offset(unsigned long ino)
155{
156 unsigned int bus = (ino & 0x10) >> 4;
157 unsigned int slot = (ino & 0x0c) >> 2;
158
159 if (bus == 0)
160 return PSYCHO_IMAP_A_SLOT0 + (slot * 8);
161 else
162 return PSYCHO_IMAP_B_SLOT0 + (slot * 8);
163}
164
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
186
187static 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,
David S. Miller46ba6d72006-07-16 22:10:44 -0700206/*0x32*/ PSYCHO_IMAP_PMGMT,
207/*0x33*/ PSYCHO_IMAP_GFX,
208/*0x34*/ PSYCHO_IMAP_EUPA,
David S. Miller2b1e5972006-06-29 15:07:37 -0700209};
210#define PSYCHO_ONBOARD_IRQ_BASE 0x20
David S. Miller46ba6d72006-07-16 22:10:44 -0700211#define PSYCHO_ONBOARD_IRQ_LAST 0x34
David S. Miller2b1e5972006-06-29 15:07:37 -0700212#define psycho_onboard_imap_offset(__ino) \
213 __psycho_onboard_imap_off[(__ino) - PSYCHO_ONBOARD_IRQ_BASE]
214
215#define PSYCHO_ICLR_A_SLOT0 0x1400UL
216#define PSYCHO_ICLR_SCSI 0x1800UL
217
218#define psycho_iclr_offset(ino) \
219 ((ino & 0x20) ? (PSYCHO_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
220 (PSYCHO_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
221
222static unsigned int psycho_irq_build(struct device_node *dp,
223 unsigned int ino,
224 void *_data)
225{
226 unsigned long controller_regs = (unsigned long) _data;
227 unsigned long imap, iclr;
228 unsigned long imap_off, iclr_off;
229 int inofixup = 0;
230
231 ino &= 0x3f;
232 if (ino < PSYCHO_ONBOARD_IRQ_BASE) {
233 /* PCI slot */
234 imap_off = psycho_pcislot_imap_offset(ino);
235 } else {
236 /* Onboard device */
237 if (ino > PSYCHO_ONBOARD_IRQ_LAST) {
238 prom_printf("psycho_irq_build: Wacky INO [%x]\n", ino);
239 prom_halt();
240 }
241 imap_off = psycho_onboard_imap_offset(ino);
242 }
243
244 /* Now build the IRQ bucket. */
245 imap = controller_regs + imap_off;
David S. Miller2b1e5972006-06-29 15:07:37 -0700246
247 iclr_off = psycho_iclr_offset(ino);
248 iclr = controller_regs + iclr_off;
David S. Miller2b1e5972006-06-29 15:07:37 -0700249
250 if ((ino & 0x20) == 0)
251 inofixup = ino & 0x03;
252
253 return build_irq(inofixup, iclr, imap);
254}
255
David S. Millerc35a3762007-05-07 00:02:24 -0700256static void __init psycho_irq_trans_init(struct device_node *dp)
David S. Miller2b1e5972006-06-29 15:07:37 -0700257{
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700258 const struct linux_prom64_registers *regs;
David S. Miller2b1e5972006-06-29 15:07:37 -0700259
260 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
261 dp->irq_trans->irq_build = psycho_irq_build;
262
263 regs = of_get_property(dp, "reg", NULL);
264 dp->irq_trans->data = (void *) regs[2].phys_addr;
265}
266
267#define sabre_read(__reg) \
268({ u64 __ret; \
269 __asm__ __volatile__("ldxa [%1] %2, %0" \
270 : "=r" (__ret) \
271 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
272 : "memory"); \
273 __ret; \
274})
275
276struct sabre_irq_data {
277 unsigned long controller_regs;
278 unsigned int pci_first_busno;
279};
280#define SABRE_CONFIGSPACE 0x001000000UL
281#define SABRE_WRSYNC 0x1c20UL
282
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)))
289
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.
296 */
297static void sabre_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
298{
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;
305 u16 _unused;
306
307 config_space = SABRE_CONFIG_BASE(config_space);
308
309 bus = (phys_hi >> 16) & 0xff;
310 devfn = (phys_hi >> 8) & 0xff;
311
312 config_space |= SABRE_CONFIG_ENCODE(bus, devfn, 0x00);
313
314 __asm__ __volatile__("membar #Sync\n\t"
315 "lduha [%1] %2, %0\n\t"
316 "membar #Sync"
317 : "=r" (_unused)
318 : "r" ((u16 *) config_space),
319 "i" (ASI_PHYS_BYPASS_EC_E_L)
320 : "memory");
321
322 sabre_read(sync_reg);
323}
324
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
361
362static unsigned long sabre_pcislot_imap_offset(unsigned long ino)
363{
364 unsigned int bus = (ino & 0x10) >> 4;
365 unsigned int slot = (ino & 0x0c) >> 2;
366
367 if (bus == 0)
368 return SABRE_IMAP_A_SLOT0 + (slot * 8);
369 else
370 return SABRE_IMAP_B_SLOT0 + (slot * 8);
371}
372
373static 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,
David S. Miller46ba6d72006-07-16 22:10:44 -0700391/*0x31*/ 0 /* reserved */,
392/*0x32*/ 0 /* reserved */,
393/*0x33*/ SABRE_IMAP_GFX,
394/*0x34*/ SABRE_IMAP_EUPA,
David S. Miller2b1e5972006-06-29 15:07:37 -0700395};
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]
400
401#define sabre_iclr_offset(ino) \
402 ((ino & 0x20) ? (SABRE_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
403 (SABRE_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
404
David S. Miller9bbd9522006-07-12 21:16:07 -0700405static int sabre_device_needs_wsync(struct device_node *dp)
David S. Millera23c3a82006-07-12 15:59:53 -0700406{
David S. Miller9bbd9522006-07-12 21:16:07 -0700407 struct device_node *parent = dp->parent;
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700408 const char *parent_model, *parent_compat;
David S. Millera23c3a82006-07-12 15:59:53 -0700409
David S. Miller9bbd9522006-07-12 21:16:07 -0700410 /* This traversal up towards the root is meant to
411 * handle two cases:
412 *
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
417 */
418 while (parent) {
419 if (!strcmp(parent->type, "pci"))
420 break;
421 parent = parent->parent;
422 }
423
424 if (!parent)
425 return 0;
426
427 parent_model = of_get_property(parent,
428 "model", NULL);
David S. Millera23c3a82006-07-12 15:59:53 -0700429 if (parent_model &&
430 (!strcmp(parent_model, "SUNW,sabre") ||
431 !strcmp(parent_model, "SUNW,simba")))
David S. Miller9bbd9522006-07-12 21:16:07 -0700432 return 0;
David S. Millera23c3a82006-07-12 15:59:53 -0700433
David S. Miller9bbd9522006-07-12 21:16:07 -0700434 parent_compat = of_get_property(parent,
435 "compatible", NULL);
David S. Millera23c3a82006-07-12 15:59:53 -0700436 if (parent_compat &&
437 (!strcmp(parent_compat, "pci108e,a000") ||
438 !strcmp(parent_compat, "pci108e,a001")))
David S. Miller9bbd9522006-07-12 21:16:07 -0700439 return 0;
David S. Millera23c3a82006-07-12 15:59:53 -0700440
David S. Miller9bbd9522006-07-12 21:16:07 -0700441 return 1;
David S. Millera23c3a82006-07-12 15:59:53 -0700442}
443
David S. Miller2b1e5972006-06-29 15:07:37 -0700444static unsigned int sabre_irq_build(struct device_node *dp,
445 unsigned int ino,
446 void *_data)
447{
448 struct sabre_irq_data *irq_data = _data;
449 unsigned long controller_regs = irq_data->controller_regs;
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700450 const struct linux_prom_pci_registers *regs;
David S. Miller2b1e5972006-06-29 15:07:37 -0700451 unsigned long imap, iclr;
452 unsigned long imap_off, iclr_off;
453 int inofixup = 0;
454 int virt_irq;
455
456 ino &= 0x3f;
457 if (ino < SABRE_ONBOARD_IRQ_BASE) {
458 /* PCI slot */
459 imap_off = sabre_pcislot_imap_offset(ino);
460 } else {
461 /* onboard device */
462 if (ino > SABRE_ONBOARD_IRQ_LAST) {
463 prom_printf("sabre_irq_build: Wacky INO [%x]\n", ino);
464 prom_halt();
465 }
466 imap_off = sabre_onboard_imap_offset(ino);
467 }
468
469 /* Now build the IRQ bucket. */
470 imap = controller_regs + imap_off;
David S. Miller2b1e5972006-06-29 15:07:37 -0700471
472 iclr_off = sabre_iclr_offset(ino);
473 iclr = controller_regs + iclr_off;
David S. Miller2b1e5972006-06-29 15:07:37 -0700474
475 if ((ino & 0x20) == 0)
476 inofixup = ino & 0x03;
477
478 virt_irq = build_irq(inofixup, iclr, imap);
479
David S. Millera23c3a82006-07-12 15:59:53 -0700480 /* 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
483 * is run.
484 */
David S. Miller2b1e5972006-06-29 15:07:37 -0700485 regs = of_get_property(dp, "reg", NULL);
David S. Miller9bbd9522006-07-12 21:16:07 -0700486 if (regs && sabre_device_needs_wsync(dp)) {
David S. Miller2b1e5972006-06-29 15:07:37 -0700487 irq_install_pre_handler(virt_irq,
488 sabre_wsync_handler,
489 (void *) (long) regs->phys_hi,
David S. Millera23c3a82006-07-12 15:59:53 -0700490 (void *) irq_data);
David S. Miller2b1e5972006-06-29 15:07:37 -0700491 }
492
493 return virt_irq;
494}
495
David S. Millerc35a3762007-05-07 00:02:24 -0700496static void __init sabre_irq_trans_init(struct device_node *dp)
David S. Miller2b1e5972006-06-29 15:07:37 -0700497{
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700498 const struct linux_prom64_registers *regs;
David S. Miller2b1e5972006-06-29 15:07:37 -0700499 struct sabre_irq_data *irq_data;
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700500 const u32 *busrange;
David S. Miller2b1e5972006-06-29 15:07:37 -0700501
502 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
503 dp->irq_trans->irq_build = sabre_irq_build;
504
505 irq_data = prom_early_alloc(sizeof(struct sabre_irq_data));
506
507 regs = of_get_property(dp, "reg", NULL);
508 irq_data->controller_regs = regs[0].phys_addr;
509
510 busrange = of_get_property(dp, "bus-range", NULL);
511 irq_data->pci_first_busno = busrange[0];
512
513 dp->irq_trans->data = irq_data;
514}
515
516/* SCHIZO interrupt mapping support. Unlike Psycho, for this controller the
517 * imap/iclr registers are per-PBM.
518 */
519#define SCHIZO_IMAP_BASE 0x1000UL
520#define SCHIZO_ICLR_BASE 0x1400UL
521
522static unsigned long schizo_imap_offset(unsigned long ino)
523{
524 return SCHIZO_IMAP_BASE + (ino * 8UL);
525}
526
527static unsigned long schizo_iclr_offset(unsigned long ino)
528{
529 return SCHIZO_ICLR_BASE + (ino * 8UL);
530}
531
532static unsigned long schizo_ino_to_iclr(unsigned long pbm_regs,
533 unsigned int ino)
534{
David S. Miller861fe902007-05-02 17:31:36 -0700535
536 return pbm_regs + schizo_iclr_offset(ino);
David S. Miller2b1e5972006-06-29 15:07:37 -0700537}
538
539static unsigned long schizo_ino_to_imap(unsigned long pbm_regs,
540 unsigned int ino)
541{
David S. Miller861fe902007-05-02 17:31:36 -0700542 return pbm_regs + schizo_imap_offset(ino);
David S. Miller2b1e5972006-06-29 15:07:37 -0700543}
544
545#define schizo_read(__reg) \
546({ u64 __ret; \
547 __asm__ __volatile__("ldxa [%1] %2, %0" \
548 : "=r" (__ret) \
549 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
550 : "memory"); \
551 __ret; \
552})
553#define schizo_write(__reg, __val) \
554 __asm__ __volatile__("stxa %0, [%1] %2" \
555 : /* no outputs */ \
556 : "r" (__val), "r" (__reg), \
557 "i" (ASI_PHYS_BYPASS_EC_E) \
558 : "memory")
559
560static void tomatillo_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
561{
562 unsigned long sync_reg = (unsigned long) _arg2;
563 u64 mask = 1UL << (ino & IMAP_INO);
564 u64 val;
565 int limit;
566
567 schizo_write(sync_reg, mask);
568
569 limit = 100000;
570 val = 0;
571 while (--limit) {
572 val = schizo_read(sync_reg);
573 if (!(val & mask))
574 break;
575 }
576 if (limit <= 0) {
577 printk("tomatillo_wsync_handler: DMA won't sync [%lx:%lx]\n",
578 val, mask);
579 }
580
581 if (_arg1) {
582 static unsigned char cacheline[64]
583 __attribute__ ((aligned (64)));
584
585 __asm__ __volatile__("rd %%fprs, %0\n\t"
586 "or %0, %4, %1\n\t"
587 "wr %1, 0x0, %%fprs\n\t"
588 "stda %%f0, [%5] %6\n\t"
589 "wr %0, 0x0, %%fprs\n\t"
590 "membar #Sync"
591 : "=&r" (mask), "=&r" (val)
592 : "0" (mask), "1" (val),
593 "i" (FPRS_FEF), "r" (&cacheline[0]),
594 "i" (ASI_BLK_COMMIT_P));
595 }
596}
597
598struct schizo_irq_data {
599 unsigned long pbm_regs;
600 unsigned long sync_reg;
601 u32 portid;
602 int chip_version;
603};
604
605static unsigned int schizo_irq_build(struct device_node *dp,
606 unsigned int ino,
607 void *_data)
608{
609 struct schizo_irq_data *irq_data = _data;
610 unsigned long pbm_regs = irq_data->pbm_regs;
611 unsigned long imap, iclr;
612 int ign_fixup;
613 int virt_irq;
614 int is_tomatillo;
615
616 ino &= 0x3f;
617
618 /* Now build the IRQ bucket. */
619 imap = schizo_ino_to_imap(pbm_regs, ino);
620 iclr = schizo_ino_to_iclr(pbm_regs, ino);
621
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
626 * PCI slot.
627 *
628 * But, for JBUS variants (essentially, Tomatillo), we have
629 * to fixup the lowest bit of the interrupt group number.
630 */
631 ign_fixup = 0;
632
633 is_tomatillo = (irq_data->sync_reg != 0UL);
634
635 if (is_tomatillo) {
636 if (irq_data->portid & 1)
637 ign_fixup = (1 << 6);
638 }
639
640 virt_irq = build_irq(ign_fixup, iclr, imap);
641
642 if (is_tomatillo) {
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);
648 }
649
650 return virt_irq;
651}
652
David S. Millerc35a3762007-05-07 00:02:24 -0700653static void __init __schizo_irq_trans_init(struct device_node *dp,
654 int is_tomatillo)
David S. Miller2b1e5972006-06-29 15:07:37 -0700655{
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700656 const struct linux_prom64_registers *regs;
David S. Miller2b1e5972006-06-29 15:07:37 -0700657 struct schizo_irq_data *irq_data;
658
659 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
660 dp->irq_trans->irq_build = schizo_irq_build;
661
662 irq_data = prom_early_alloc(sizeof(struct schizo_irq_data));
663
664 regs = of_get_property(dp, "reg", NULL);
665 dp->irq_trans->data = irq_data;
666
667 irq_data->pbm_regs = regs[0].phys_addr;
David S. Miller9001f282006-10-29 16:32:31 -0800668 if (is_tomatillo)
669 irq_data->sync_reg = regs[3].phys_addr + 0x1a18UL;
670 else
671 irq_data->sync_reg = 0UL;
David S. Miller2b1e5972006-06-29 15:07:37 -0700672 irq_data->portid = of_getintprop_default(dp, "portid", 0);
673 irq_data->chip_version = of_getintprop_default(dp, "version#", 0);
674}
675
David S. Millerc35a3762007-05-07 00:02:24 -0700676static void __init schizo_irq_trans_init(struct device_node *dp)
David S. Miller9001f282006-10-29 16:32:31 -0800677{
678 __schizo_irq_trans_init(dp, 0);
679}
680
David S. Millerc35a3762007-05-07 00:02:24 -0700681static void __init tomatillo_irq_trans_init(struct device_node *dp)
David S. Miller9001f282006-10-29 16:32:31 -0800682{
683 __schizo_irq_trans_init(dp, 1);
684}
685
David S. Miller2b1e5972006-06-29 15:07:37 -0700686static unsigned int pci_sun4v_irq_build(struct device_node *dp,
687 unsigned int devino,
688 void *_data)
689{
690 u32 devhandle = (u32) (unsigned long) _data;
691
692 return sun4v_build_irq(devhandle, devino);
693}
694
David S. Millerc35a3762007-05-07 00:02:24 -0700695static void __init pci_sun4v_irq_trans_init(struct device_node *dp)
David S. Miller2b1e5972006-06-29 15:07:37 -0700696{
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700697 const struct linux_prom64_registers *regs;
David S. Miller2b1e5972006-06-29 15:07:37 -0700698
699 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
700 dp->irq_trans->irq_build = pci_sun4v_irq_build;
701
702 regs = of_get_property(dp, "reg", NULL);
703 dp->irq_trans->data = (void *) (unsigned long)
704 ((regs->phys_addr >> 32UL) & 0x0fffffff);
705}
David S. Miller861fe902007-05-02 17:31:36 -0700706
707struct fire_irq_data {
708 unsigned long pbm_regs;
709 u32 portid;
710};
711
712#define FIRE_IMAP_BASE 0x001000
713#define FIRE_ICLR_BASE 0x001400
714
715static unsigned long fire_imap_offset(unsigned long ino)
716{
717 return FIRE_IMAP_BASE + (ino * 8UL);
718}
719
720static unsigned long fire_iclr_offset(unsigned long ino)
721{
722 return FIRE_ICLR_BASE + (ino * 8UL);
723}
724
725static unsigned long fire_ino_to_iclr(unsigned long pbm_regs,
726 unsigned int ino)
727{
728 return pbm_regs + fire_iclr_offset(ino);
729}
730
731static unsigned long fire_ino_to_imap(unsigned long pbm_regs,
732 unsigned int ino)
733{
734 return pbm_regs + fire_imap_offset(ino);
735}
736
737static unsigned int fire_irq_build(struct device_node *dp,
738 unsigned int ino,
739 void *_data)
740{
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;
745
746 ino &= 0x3f;
747
748 /* Now build the IRQ bucket. */
749 imap = fire_ino_to_imap(pbm_regs, ino);
750 iclr = fire_ino_to_iclr(pbm_regs, ino);
751
752 /* Set the interrupt controller number. */
753 int_ctrlr = 1 << 6;
754 upa_writeq(int_ctrlr, imap);
755
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
Simon Arlotte5dd42e2007-05-11 13:52:08 -0700759 * in bits 6 to 9. So in order for build_irq() to get
David S. Miller861fe902007-05-02 17:31:36 -0700760 * 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().
763 */
764 ino |= (irq_data->portid << 6);
765 ino -= int_ctrlr;
766 return build_irq(ino, iclr, imap);
767}
768
David S. Millerc35a3762007-05-07 00:02:24 -0700769static void __init fire_irq_trans_init(struct device_node *dp)
David S. Miller861fe902007-05-02 17:31:36 -0700770{
771 const struct linux_prom64_registers *regs;
772 struct fire_irq_data *irq_data;
773
774 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
775 dp->irq_trans->irq_build = fire_irq_build;
776
777 irq_data = prom_early_alloc(sizeof(struct fire_irq_data));
778
779 regs = of_get_property(dp, "reg", NULL);
780 dp->irq_trans->data = irq_data;
781
782 irq_data->pbm_regs = regs[0].phys_addr;
783 irq_data->portid = of_getintprop_default(dp, "portid", 0);
784}
David S. Miller2b1e5972006-06-29 15:07:37 -0700785#endif /* CONFIG_PCI */
786
787#ifdef CONFIG_SBUS
788/* INO number to IMAP register offset for SYSIO external IRQ's.
789 * This should conform to both Sunfire/Wildfire server and Fusion
790 * desktop designs.
791 */
David S. Millerec4d18f2007-06-07 16:58:22 -0700792#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
David S. Miller2b1e5972006-06-29 15:07:37 -0700815
816#define bogon ((unsigned long) -1)
817static 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,
827
828 /* Onboard devices (not relevant/used on SunFire). */
829 SYSIO_IMAP_SCSI,
830 SYSIO_IMAP_ETH,
831 SYSIO_IMAP_BPP,
832 bogon,
833 SYSIO_IMAP_AUDIO,
834 SYSIO_IMAP_PFAIL,
835 bogon,
836 bogon,
837 SYSIO_IMAP_KMS,
838 SYSIO_IMAP_FLPY,
839 SYSIO_IMAP_SHW,
840 SYSIO_IMAP_KBD,
841 SYSIO_IMAP_MS,
842 SYSIO_IMAP_SER,
843 bogon,
844 bogon,
845 SYSIO_IMAP_TIM0,
846 SYSIO_IMAP_TIM1,
847 bogon,
848 bogon,
849 SYSIO_IMAP_UE,
850 SYSIO_IMAP_CE,
851 SYSIO_IMAP_SBERR,
852 SYSIO_IMAP_PMGMT,
David S. Miller46ba6d72006-07-16 22:10:44 -0700853 SYSIO_IMAP_GFX,
854 SYSIO_IMAP_EUPA,
David S. Miller2b1e5972006-06-29 15:07:37 -0700855};
856
857#undef bogon
858
859#define NUM_SYSIO_OFFSETS ARRAY_SIZE(sysio_irq_offsets)
860
861/* Convert Interrupt Mapping register pointer to associated
862 * Interrupt Clear register pointer, SYSIO specific version.
863 */
864#define SYSIO_ICLR_UNUSED0 0x3400UL
David S. Millerec4d18f2007-06-07 16:58:22 -0700865#define SYSIO_ICLR_SLOT0 0x3408UL
866#define SYSIO_ICLR_SLOT1 0x3448UL
867#define SYSIO_ICLR_SLOT2 0x3488UL
868#define SYSIO_ICLR_SLOT3 0x34c8UL
David S. Miller2b1e5972006-06-29 15:07:37 -0700869static unsigned long sysio_imap_to_iclr(unsigned long imap)
870{
871 unsigned long diff = SYSIO_ICLR_UNUSED0 - SYSIO_IMAP_SLOT0;
872 return imap + diff;
873}
874
875static unsigned int sbus_of_build_irq(struct device_node *dp,
876 unsigned int ino,
877 void *_data)
878{
879 unsigned long reg_base = (unsigned long) _data;
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700880 const struct linux_prom_registers *regs;
David S. Miller2b1e5972006-06-29 15:07:37 -0700881 unsigned long imap, iclr;
882 int sbus_slot = 0;
883 int sbus_level = 0;
884
885 ino &= 0x3f;
886
887 regs = of_get_property(dp, "reg", NULL);
888 if (regs)
889 sbus_slot = regs->which_io;
890
891 if (ino < 0x20)
892 ino += (sbus_slot * 8);
893
894 imap = sysio_irq_offsets[ino];
895 if (imap == ((unsigned long)-1)) {
896 prom_printf("get_irq_translations: Bad SYSIO INO[%x]\n",
897 ino);
898 prom_halt();
899 }
900 imap += reg_base;
901
902 /* SYSIO inconsistency. For external SLOTS, we have to select
903 * the right ICLR register based upon the lower SBUS irq level
904 * bits.
905 */
906 if (ino >= 0x20) {
907 iclr = sysio_imap_to_iclr(imap);
908 } else {
909 sbus_level = ino & 0x7;
910
911 switch(sbus_slot) {
912 case 0:
913 iclr = reg_base + SYSIO_ICLR_SLOT0;
914 break;
915 case 1:
916 iclr = reg_base + SYSIO_ICLR_SLOT1;
917 break;
918 case 2:
919 iclr = reg_base + SYSIO_ICLR_SLOT2;
920 break;
921 default:
922 case 3:
923 iclr = reg_base + SYSIO_ICLR_SLOT3;
924 break;
925 };
926
927 iclr += ((unsigned long)sbus_level - 1UL) * 8UL;
928 }
929 return build_irq(sbus_level, iclr, imap);
930}
931
David S. Millerc35a3762007-05-07 00:02:24 -0700932static void __init sbus_irq_trans_init(struct device_node *dp)
David S. Miller2b1e5972006-06-29 15:07:37 -0700933{
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700934 const struct linux_prom64_registers *regs;
David S. Miller2b1e5972006-06-29 15:07:37 -0700935
936 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
937 dp->irq_trans->irq_build = sbus_of_build_irq;
938
939 regs = of_get_property(dp, "reg", NULL);
940 dp->irq_trans->data = (void *) (unsigned long) regs->phys_addr;
941}
942#endif /* CONFIG_SBUS */
943
944
945static unsigned int central_build_irq(struct device_node *dp,
946 unsigned int ino,
947 void *_data)
948{
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;
953 u32 tmp;
954
955 if (!strcmp(dp->name, "eeprom")) {
956 res = &central_op->resource[5];
957 } else if (!strcmp(dp->name, "zs")) {
958 res = &central_op->resource[4];
959 } else if (!strcmp(dp->name, "clock-board")) {
960 res = &central_op->resource[3];
961 } else {
962 return ino;
963 }
964
965 imap = res->start + 0x00UL;
966 iclr = res->start + 0x10UL;
967
968 /* Set the INO state to idle, and disable. */
969 upa_writel(0, iclr);
970 upa_readl(iclr);
971
972 tmp = upa_readl(imap);
973 tmp &= ~0x80000000;
974 upa_writel(tmp, imap);
975
976 return build_irq(0, iclr, imap);
977}
978
David S. Millerc35a3762007-05-07 00:02:24 -0700979static void __init central_irq_trans_init(struct device_node *dp)
David S. Miller2b1e5972006-06-29 15:07:37 -0700980{
981 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
982 dp->irq_trans->irq_build = central_build_irq;
983
984 dp->irq_trans->data = dp;
985}
986
987struct irq_trans {
988 const char *name;
989 void (*init)(struct device_node *);
990};
991
992#ifdef CONFIG_PCI
David S. Millerc35a3762007-05-07 00:02:24 -0700993static struct irq_trans __initdata pci_irq_trans_table[] = {
David S. Miller2b1e5972006-06-29 15:07:37 -0700994 { "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 },
David S. Miller9001f282006-10-29 16:32:31 -08001003 { "SUNW,tomatillo", tomatillo_irq_trans_init },
1004 { "pci108e,a801", tomatillo_irq_trans_init },
David S. Miller2b1e5972006-06-29 15:07:37 -07001005 { "SUNW,sun4v-pci", pci_sun4v_irq_trans_init },
David S. Miller861fe902007-05-02 17:31:36 -07001006 { "pciex108e,80f0", fire_irq_trans_init },
David S. Miller2b1e5972006-06-29 15:07:37 -07001007};
1008#endif
1009
David S. Miller6e990b52006-06-30 00:07:40 -07001010static unsigned int sun4v_vdev_irq_build(struct device_node *dp,
1011 unsigned int devino,
1012 void *_data)
1013{
1014 u32 devhandle = (u32) (unsigned long) _data;
1015
1016 return sun4v_build_irq(devhandle, devino);
1017}
1018
David S. Millerc35a3762007-05-07 00:02:24 -07001019static void __init sun4v_vdev_irq_trans_init(struct device_node *dp)
David S. Miller6e990b52006-06-30 00:07:40 -07001020{
Stephen Rothwell6a23acf2007-04-23 15:53:27 -07001021 const struct linux_prom64_registers *regs;
David S. Miller6e990b52006-06-30 00:07:40 -07001022
1023 dp->irq_trans = prom_early_alloc(sizeof(struct of_irq_controller));
1024 dp->irq_trans->irq_build = sun4v_vdev_irq_build;
1025
1026 regs = of_get_property(dp, "reg", NULL);
1027 dp->irq_trans->data = (void *) (unsigned long)
1028 ((regs->phys_addr >> 32UL) & 0x0fffffff);
1029}
1030
David S. Millerc35a3762007-05-07 00:02:24 -07001031static void __init irq_trans_init(struct device_node *dp)
David S. Miller2b1e5972006-06-29 15:07:37 -07001032{
Randy Dunlap72335892006-07-05 20:18:39 -07001033#ifdef CONFIG_PCI
David S. Miller4130a4b2006-10-25 22:31:06 -07001034 const char *model;
David S. Miller2b1e5972006-06-29 15:07:37 -07001035 int i;
Randy Dunlap72335892006-07-05 20:18:39 -07001036#endif
David S. Miller2b1e5972006-06-29 15:07:37 -07001037
David S. Miller4130a4b2006-10-25 22:31:06 -07001038#ifdef CONFIG_PCI
David S. Miller2b1e5972006-06-29 15:07:37 -07001039 model = of_get_property(dp, "model", NULL);
1040 if (!model)
1041 model = of_get_property(dp, "compatible", NULL);
David S. Miller4130a4b2006-10-25 22:31:06 -07001042 if (model) {
1043 for (i = 0; i < ARRAY_SIZE(pci_irq_trans_table); i++) {
1044 struct irq_trans *t = &pci_irq_trans_table[i];
David S. Miller2b1e5972006-06-29 15:07:37 -07001045
David S. Millerc91e2ec2008-09-11 23:52:35 -07001046 if (!strcmp(model, t->name)) {
1047 t->init(dp);
1048 return;
1049 }
David S. Miller4130a4b2006-10-25 22:31:06 -07001050 }
David S. Miller2b1e5972006-06-29 15:07:37 -07001051 }
1052#endif
1053#ifdef CONFIG_SBUS
1054 if (!strcmp(dp->name, "sbus") ||
David S. Millerc91e2ec2008-09-11 23:52:35 -07001055 !strcmp(dp->name, "sbi")) {
1056 sbus_irq_trans_init(dp);
1057 return;
1058 }
David S. Miller2b1e5972006-06-29 15:07:37 -07001059#endif
David S. Miller4130a4b2006-10-25 22:31:06 -07001060 if (!strcmp(dp->name, "fhc") &&
David S. Millerc91e2ec2008-09-11 23:52:35 -07001061 !strcmp(dp->parent->name, "central")) {
1062 central_irq_trans_init(dp);
1063 return;
1064 }
David S. Millerb2b27752007-10-04 15:03:35 -07001065 if (!strcmp(dp->name, "virtual-devices") ||
David S. Millerc91e2ec2008-09-11 23:52:35 -07001066 !strcmp(dp->name, "niu")) {
1067 sun4v_vdev_irq_trans_init(dp);
1068 return;
1069 }
David S. Miller2b1e5972006-06-29 15:07:37 -07001070}
1071
David S. Miller372b07b2006-06-21 15:35:28 -07001072static int is_root_node(const struct device_node *dp)
1073{
1074 if (!dp)
1075 return 0;
1076
1077 return (dp->parent == NULL);
1078}
1079
1080/* The following routines deal with the black magic of fully naming a
1081 * node.
1082 *
1083 * Certain well known named nodes are just the simple name string.
1084 *
1085 * Actual devices have an address specifier appended to the base name
1086 * string, like this "foo@addr". The "addr" can be in any number of
1087 * formats, and the platform plus the type of the node determine the
1088 * format and how it is constructed.
1089 *
1090 * For children of the ROOT node, the naming convention is fixed and
1091 * determined by whether this is a sun4u or sun4v system.
1092 *
1093 * For children of other nodes, it is bus type specific. So
1094 * we walk up the tree until we discover a "device_type" property
1095 * we recognize and we go from there.
1096 *
1097 * As an example, the boot device on my workstation has a full path:
1098 *
1099 * /pci@1e,600000/ide@d/disk@0,0:c
1100 */
1101static void __init sun4v_path_component(struct device_node *dp, char *tmp_buf)
1102{
1103 struct linux_prom64_registers *regs;
1104 struct property *rprop;
1105 u32 high_bits, low_bits, type;
1106
1107 rprop = of_find_property(dp, "reg", NULL);
1108 if (!rprop)
1109 return;
1110
1111 regs = rprop->value;
1112 if (!is_root_node(dp->parent)) {
1113 sprintf(tmp_buf, "%s@%x,%x",
1114 dp->name,
1115 (unsigned int) (regs->phys_addr >> 32UL),
1116 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1117 return;
1118 }
1119
1120 type = regs->phys_addr >> 60UL;
1121 high_bits = (regs->phys_addr >> 32UL) & 0x0fffffffUL;
1122 low_bits = (regs->phys_addr & 0xffffffffUL);
1123
1124 if (type == 0 || type == 8) {
1125 const char *prefix = (type == 0) ? "m" : "i";
1126
1127 if (low_bits)
1128 sprintf(tmp_buf, "%s@%s%x,%x",
1129 dp->name, prefix,
1130 high_bits, low_bits);
1131 else
1132 sprintf(tmp_buf, "%s@%s%x",
1133 dp->name,
1134 prefix,
1135 high_bits);
1136 } else if (type == 12) {
1137 sprintf(tmp_buf, "%s@%x",
1138 dp->name, high_bits);
1139 }
1140}
1141
1142static void __init sun4u_path_component(struct device_node *dp, char *tmp_buf)
1143{
1144 struct linux_prom64_registers *regs;
1145 struct property *prop;
1146
1147 prop = of_find_property(dp, "reg", NULL);
1148 if (!prop)
1149 return;
1150
1151 regs = prop->value;
1152 if (!is_root_node(dp->parent)) {
1153 sprintf(tmp_buf, "%s@%x,%x",
1154 dp->name,
1155 (unsigned int) (regs->phys_addr >> 32UL),
1156 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1157 return;
1158 }
1159
1160 prop = of_find_property(dp, "upa-portid", NULL);
1161 if (!prop)
1162 prop = of_find_property(dp, "portid", NULL);
1163 if (prop) {
1164 unsigned long mask = 0xffffffffUL;
1165
1166 if (tlb_type >= cheetah)
1167 mask = 0x7fffff;
1168
1169 sprintf(tmp_buf, "%s@%x,%x",
1170 dp->name,
1171 *(u32 *)prop->value,
1172 (unsigned int) (regs->phys_addr & mask));
1173 }
1174}
1175
1176/* "name@slot,offset" */
1177static void __init sbus_path_component(struct device_node *dp, char *tmp_buf)
1178{
1179 struct linux_prom_registers *regs;
1180 struct property *prop;
1181
1182 prop = of_find_property(dp, "reg", NULL);
1183 if (!prop)
1184 return;
1185
1186 regs = prop->value;
1187 sprintf(tmp_buf, "%s@%x,%x",
1188 dp->name,
1189 regs->which_io,
1190 regs->phys_addr);
1191}
1192
1193/* "name@devnum[,func]" */
1194static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
1195{
1196 struct linux_prom_pci_registers *regs;
1197 struct property *prop;
1198 unsigned int devfn;
1199
1200 prop = of_find_property(dp, "reg", NULL);
1201 if (!prop)
1202 return;
1203
1204 regs = prop->value;
1205 devfn = (regs->phys_hi >> 8) & 0xff;
1206 if (devfn & 0x07) {
1207 sprintf(tmp_buf, "%s@%x,%x",
1208 dp->name,
1209 devfn >> 3,
1210 devfn & 0x07);
1211 } else {
1212 sprintf(tmp_buf, "%s@%x",
1213 dp->name,
1214 devfn >> 3);
1215 }
1216}
1217
1218/* "name@UPA_PORTID,offset" */
1219static void __init upa_path_component(struct device_node *dp, char *tmp_buf)
1220{
1221 struct linux_prom64_registers *regs;
1222 struct property *prop;
1223
1224 prop = of_find_property(dp, "reg", NULL);
1225 if (!prop)
1226 return;
1227
1228 regs = prop->value;
1229
1230 prop = of_find_property(dp, "upa-portid", NULL);
1231 if (!prop)
1232 return;
1233
1234 sprintf(tmp_buf, "%s@%x,%x",
1235 dp->name,
1236 *(u32 *) prop->value,
1237 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1238}
1239
1240/* "name@reg" */
1241static void __init vdev_path_component(struct device_node *dp, char *tmp_buf)
1242{
1243 struct property *prop;
1244 u32 *regs;
1245
1246 prop = of_find_property(dp, "reg", NULL);
1247 if (!prop)
1248 return;
1249
1250 regs = prop->value;
1251
1252 sprintf(tmp_buf, "%s@%x", dp->name, *regs);
1253}
1254
1255/* "name@addrhi,addrlo" */
1256static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
1257{
1258 struct linux_prom64_registers *regs;
1259 struct property *prop;
1260
1261 prop = of_find_property(dp, "reg", NULL);
1262 if (!prop)
1263 return;
1264
1265 regs = prop->value;
1266
1267 sprintf(tmp_buf, "%s@%x,%x",
1268 dp->name,
1269 (unsigned int) (regs->phys_addr >> 32UL),
1270 (unsigned int) (regs->phys_addr & 0xffffffffUL));
1271}
1272
1273/* "name@bus,addr" */
1274static void __init i2c_path_component(struct device_node *dp, char *tmp_buf)
1275{
1276 struct property *prop;
1277 u32 *regs;
1278
1279 prop = of_find_property(dp, "reg", NULL);
1280 if (!prop)
1281 return;
1282
1283 regs = prop->value;
1284
1285 /* This actually isn't right... should look at the #address-cells
1286 * property of the i2c bus node etc. etc.
1287 */
1288 sprintf(tmp_buf, "%s@%x,%x",
1289 dp->name, regs[0], regs[1]);
1290}
1291
1292/* "name@reg0[,reg1]" */
1293static void __init usb_path_component(struct device_node *dp, char *tmp_buf)
1294{
1295 struct property *prop;
1296 u32 *regs;
1297
1298 prop = of_find_property(dp, "reg", NULL);
1299 if (!prop)
1300 return;
1301
1302 regs = prop->value;
1303
1304 if (prop->length == sizeof(u32) || regs[1] == 1) {
1305 sprintf(tmp_buf, "%s@%x",
1306 dp->name, regs[0]);
1307 } else {
1308 sprintf(tmp_buf, "%s@%x,%x",
1309 dp->name, regs[0], regs[1]);
1310 }
1311}
1312
1313/* "name@reg0reg1[,reg2reg3]" */
1314static void __init ieee1394_path_component(struct device_node *dp, char *tmp_buf)
1315{
1316 struct property *prop;
1317 u32 *regs;
1318
1319 prop = of_find_property(dp, "reg", NULL);
1320 if (!prop)
1321 return;
1322
1323 regs = prop->value;
1324
1325 if (regs[2] || regs[3]) {
1326 sprintf(tmp_buf, "%s@%08x%08x,%04x%08x",
1327 dp->name, regs[0], regs[1], regs[2], regs[3]);
1328 } else {
1329 sprintf(tmp_buf, "%s@%08x%08x",
1330 dp->name, regs[0], regs[1]);
1331 }
1332}
1333
1334static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
1335{
1336 struct device_node *parent = dp->parent;
1337
1338 if (parent != NULL) {
1339 if (!strcmp(parent->type, "pci") ||
David S. Millerc91e2ec2008-09-11 23:52:35 -07001340 !strcmp(parent->type, "pciex")) {
1341 pci_path_component(dp, tmp_buf);
1342 return;
1343 }
1344 if (!strcmp(parent->type, "sbus")) {
1345 sbus_path_component(dp, tmp_buf);
1346 return;
1347 }
1348 if (!strcmp(parent->type, "upa")) {
1349 upa_path_component(dp, tmp_buf);
1350 return;
1351 }
1352 if (!strcmp(parent->type, "ebus")) {
1353 ebus_path_component(dp, tmp_buf);
1354 return;
1355 }
David S. Miller372b07b2006-06-21 15:35:28 -07001356 if (!strcmp(parent->name, "usb") ||
David S. Millerc91e2ec2008-09-11 23:52:35 -07001357 !strcmp(parent->name, "hub")) {
1358 usb_path_component(dp, tmp_buf);
1359 return;
1360 }
1361 if (!strcmp(parent->type, "i2c")) {
1362 i2c_path_component(dp, tmp_buf);
1363 return;
1364 }
1365 if (!strcmp(parent->type, "firewire")) {
1366 ieee1394_path_component(dp, tmp_buf);
1367 return;
1368 }
1369 if (!strcmp(parent->type, "virtual-devices")) {
1370 vdev_path_component(dp, tmp_buf);
1371 return;
1372 }
David S. Miller372b07b2006-06-21 15:35:28 -07001373 /* "isa" is handled with platform naming */
1374 }
1375
1376 /* Use platform naming convention. */
David S. Millerc91e2ec2008-09-11 23:52:35 -07001377 if (tlb_type == hypervisor) {
1378 sun4v_path_component(dp, tmp_buf);
1379 return;
1380 } else {
1381 sun4u_path_component(dp, tmp_buf);
1382 }
David S. Miller372b07b2006-06-21 15:35:28 -07001383}
1384
1385static char * __init build_path_component(struct device_node *dp)
1386{
1387 char tmp_buf[64], *n;
1388
1389 tmp_buf[0] = '\0';
1390 __build_path_component(dp, tmp_buf);
1391 if (tmp_buf[0] == '\0')
1392 strcpy(tmp_buf, dp->name);
1393
1394 n = prom_early_alloc(strlen(tmp_buf) + 1);
1395 strcpy(n, tmp_buf);
1396
1397 return n;
1398}
1399
1400static char * __init build_full_name(struct device_node *dp)
1401{
1402 int len, ourlen, plen;
1403 char *n;
1404
1405 plen = strlen(dp->parent->full_name);
1406 ourlen = strlen(dp->path_component_name);
1407 len = ourlen + plen + 2;
1408
1409 n = prom_early_alloc(len);
1410 strcpy(n, dp->parent->full_name);
1411 if (!is_root_node(dp->parent)) {
1412 strcpy(n + plen, "/");
1413 plen++;
1414 }
1415 strcpy(n + plen, dp->path_component_name);
1416
1417 return n;
1418}
1419
David S. Miller87b385d2006-06-25 23:18:57 -07001420static unsigned int unique_id;
1421
1422static struct property * __init build_one_prop(phandle node, char *prev, char *special_name, void *special_val, int special_len)
David S. Miller372b07b2006-06-21 15:35:28 -07001423{
1424 static struct property *tmp = NULL;
1425 struct property *p;
1426
1427 if (tmp) {
1428 p = tmp;
1429 memset(p, 0, sizeof(*p) + 32);
1430 tmp = NULL;
David S. Miller87b385d2006-06-25 23:18:57 -07001431 } else {
David S. Miller372b07b2006-06-21 15:35:28 -07001432 p = prom_early_alloc(sizeof(struct property) + 32);
David S. Miller87b385d2006-06-25 23:18:57 -07001433 p->unique_id = unique_id++;
1434 }
David S. Miller372b07b2006-06-21 15:35:28 -07001435
1436 p->name = (char *) (p + 1);
David S. Miller87b385d2006-06-25 23:18:57 -07001437 if (special_name) {
1438 strcpy(p->name, special_name);
1439 p->length = special_len;
1440 p->value = prom_early_alloc(special_len);
1441 memcpy(p->value, special_val, special_len);
David S. Miller372b07b2006-06-21 15:35:28 -07001442 } else {
David S. Miller87b385d2006-06-25 23:18:57 -07001443 if (prev == NULL) {
1444 prom_firstprop(node, p->name);
1445 } else {
1446 prom_nextprop(node, prev, p->name);
1447 }
1448 if (strlen(p->name) == 0) {
1449 tmp = p;
1450 return NULL;
1451 }
1452 p->length = prom_getproplen(node, p->name);
1453 if (p->length <= 0) {
1454 p->length = 0;
1455 } else {
1456 p->value = prom_early_alloc(p->length + 1);
1457 prom_getproperty(node, p->name, p->value, p->length);
1458 ((unsigned char *)p->value)[p->length] = '\0';
1459 }
David S. Miller372b07b2006-06-21 15:35:28 -07001460 }
1461 return p;
1462}
1463
1464static struct property * __init build_prop_list(phandle node)
1465{
1466 struct property *head, *tail;
1467
David S. Miller87b385d2006-06-25 23:18:57 -07001468 head = tail = build_one_prop(node, NULL,
1469 ".node", &node, sizeof(node));
1470
1471 tail->next = build_one_prop(node, NULL, NULL, NULL, 0);
1472 tail = tail->next;
David S. Miller372b07b2006-06-21 15:35:28 -07001473 while(tail) {
David S. Miller87b385d2006-06-25 23:18:57 -07001474 tail->next = build_one_prop(node, tail->name,
1475 NULL, NULL, 0);
David S. Miller372b07b2006-06-21 15:35:28 -07001476 tail = tail->next;
1477 }
1478
1479 return head;
1480}
1481
1482static char * __init get_one_property(phandle node, const char *name)
1483{
1484 char *buf = "<NULL>";
1485 int len;
1486
1487 len = prom_getproplen(node, name);
1488 if (len > 0) {
1489 buf = prom_early_alloc(len);
1490 prom_getproperty(node, name, buf, len);
1491 }
1492
1493 return buf;
1494}
1495
David S. Miller4130a4b2006-10-25 22:31:06 -07001496static struct device_node * __init create_node(phandle node, struct device_node *parent)
David S. Miller372b07b2006-06-21 15:35:28 -07001497{
1498 struct device_node *dp;
1499
1500 if (!node)
1501 return NULL;
1502
1503 dp = prom_early_alloc(sizeof(*dp));
David S. Miller87b385d2006-06-25 23:18:57 -07001504 dp->unique_id = unique_id++;
David S. Miller4130a4b2006-10-25 22:31:06 -07001505 dp->parent = parent;
David S. Miller372b07b2006-06-21 15:35:28 -07001506
1507 kref_init(&dp->kref);
1508
1509 dp->name = get_one_property(node, "name");
1510 dp->type = get_one_property(node, "device_type");
1511 dp->node = node;
1512
David S. Miller372b07b2006-06-21 15:35:28 -07001513 dp->properties = build_prop_list(node);
1514
David S. Miller2b1e5972006-06-29 15:07:37 -07001515 irq_trans_init(dp);
1516
David S. Miller372b07b2006-06-21 15:35:28 -07001517 return dp;
1518}
1519
1520static struct device_node * __init build_tree(struct device_node *parent, phandle node, struct device_node ***nextp)
1521{
David S. Milleraa5242e2007-05-10 00:53:29 -07001522 struct device_node *ret = NULL, *prev_sibling = NULL;
David S. Miller372b07b2006-06-21 15:35:28 -07001523 struct device_node *dp;
1524
David S. Milleraa5242e2007-05-10 00:53:29 -07001525 while (1) {
1526 dp = create_node(node, parent);
1527 if (!dp)
1528 break;
1529
1530 if (prev_sibling)
1531 prev_sibling->sibling = dp;
1532
1533 if (!ret)
1534 ret = dp;
1535 prev_sibling = dp;
1536
David S. Miller372b07b2006-06-21 15:35:28 -07001537 *(*nextp) = dp;
1538 *nextp = &dp->allnext;
1539
David S. Miller372b07b2006-06-21 15:35:28 -07001540 dp->path_component_name = build_path_component(dp);
1541 dp->full_name = build_full_name(dp);
1542
1543 dp->child = build_tree(dp, prom_getchild(node), nextp);
1544
David S. Milleraa5242e2007-05-10 00:53:29 -07001545 node = prom_getsibling(node);
David S. Miller372b07b2006-06-21 15:35:28 -07001546 }
1547
David S. Milleraa5242e2007-05-10 00:53:29 -07001548 return ret;
David S. Miller372b07b2006-06-21 15:35:28 -07001549}
1550
David S. Miller5cbc3072007-05-25 15:49:59 -07001551static const char *get_mid_prop(void)
1552{
1553 return (tlb_type == spitfire ? "upa-portid" : "portid");
1554}
1555
1556struct device_node *of_find_node_by_cpuid(int cpuid)
1557{
1558 struct device_node *dp;
1559 const char *mid_prop = get_mid_prop();
1560
1561 for_each_node_by_type(dp, "cpu") {
1562 int id = of_getintprop_default(dp, mid_prop, -1);
1563 const char *this_mid_prop = mid_prop;
1564
1565 if (id < 0) {
1566 this_mid_prop = "cpuid";
1567 id = of_getintprop_default(dp, this_mid_prop, -1);
1568 }
1569
1570 if (id < 0) {
1571 prom_printf("OF: Serious problem, cpu lacks "
1572 "%s property", this_mid_prop);
1573 prom_halt();
1574 }
1575 if (cpuid == id)
1576 return dp;
1577 }
1578 return NULL;
1579}
1580
1581static void __init of_fill_in_cpu_data(void)
1582{
1583 struct device_node *dp;
1584 const char *mid_prop = get_mid_prop();
1585
1586 ncpus_probed = 0;
1587 for_each_node_by_type(dp, "cpu") {
1588 int cpuid = of_getintprop_default(dp, mid_prop, -1);
1589 const char *this_mid_prop = mid_prop;
1590 struct device_node *portid_parent;
1591 int portid = -1;
1592
1593 portid_parent = NULL;
1594 if (cpuid < 0) {
1595 this_mid_prop = "cpuid";
1596 cpuid = of_getintprop_default(dp, this_mid_prop, -1);
1597 if (cpuid >= 0) {
1598 int limit = 2;
1599
1600 portid_parent = dp;
1601 while (limit--) {
1602 portid_parent = portid_parent->parent;
1603 if (!portid_parent)
1604 break;
1605 portid = of_getintprop_default(portid_parent,
1606 "portid", -1);
1607 if (portid >= 0)
1608 break;
1609 }
1610 }
1611 }
1612
1613 if (cpuid < 0) {
1614 prom_printf("OF: Serious problem, cpu lacks "
1615 "%s property", this_mid_prop);
1616 prom_halt();
1617 }
1618
1619 ncpus_probed++;
1620
1621#ifdef CONFIG_SMP
David S. Miller8a177c42007-09-16 14:45:06 -07001622 if (cpuid >= NR_CPUS) {
1623 printk(KERN_WARNING "Ignoring CPU %d which is "
1624 ">= NR_CPUS (%d)\n",
1625 cpuid, NR_CPUS);
David S. Miller5cbc3072007-05-25 15:49:59 -07001626 continue;
David S. Miller8a177c42007-09-16 14:45:06 -07001627 }
David S. Miller5cbc3072007-05-25 15:49:59 -07001628#else
1629 /* On uniprocessor we only want the values for the
1630 * real physical cpu the kernel booted onto, however
1631 * cpu_data() only has one entry at index 0.
1632 */
1633 if (cpuid != real_hard_smp_processor_id())
1634 continue;
1635 cpuid = 0;
1636#endif
1637
1638 cpu_data(cpuid).clock_tick =
1639 of_getintprop_default(dp, "clock-frequency", 0);
1640
1641 if (portid_parent) {
1642 cpu_data(cpuid).dcache_size =
1643 of_getintprop_default(dp, "l1-dcache-size",
1644 16 * 1024);
1645 cpu_data(cpuid).dcache_line_size =
1646 of_getintprop_default(dp, "l1-dcache-line-size",
1647 32);
1648 cpu_data(cpuid).icache_size =
1649 of_getintprop_default(dp, "l1-icache-size",
1650 8 * 1024);
1651 cpu_data(cpuid).icache_line_size =
1652 of_getintprop_default(dp, "l1-icache-line-size",
1653 32);
1654 cpu_data(cpuid).ecache_size =
1655 of_getintprop_default(dp, "l2-cache-size", 0);
1656 cpu_data(cpuid).ecache_line_size =
1657 of_getintprop_default(dp, "l2-cache-line-size", 0);
1658 if (!cpu_data(cpuid).ecache_size ||
1659 !cpu_data(cpuid).ecache_line_size) {
1660 cpu_data(cpuid).ecache_size =
1661 of_getintprop_default(portid_parent,
1662 "l2-cache-size",
1663 (4 * 1024 * 1024));
1664 cpu_data(cpuid).ecache_line_size =
1665 of_getintprop_default(portid_parent,
1666 "l2-cache-line-size", 64);
1667 }
1668
1669 cpu_data(cpuid).core_id = portid + 1;
David S. Miller5cd342d2007-06-04 21:35:18 -07001670 cpu_data(cpuid).proc_id = portid;
David S. Millera2f9f6b2007-06-04 21:48:33 -07001671#ifdef CONFIG_SMP
1672 sparc64_multi_core = 1;
1673#endif
David S. Miller5cbc3072007-05-25 15:49:59 -07001674 } else {
1675 cpu_data(cpuid).dcache_size =
1676 of_getintprop_default(dp, "dcache-size", 16 * 1024);
1677 cpu_data(cpuid).dcache_line_size =
1678 of_getintprop_default(dp, "dcache-line-size", 32);
1679
1680 cpu_data(cpuid).icache_size =
1681 of_getintprop_default(dp, "icache-size", 16 * 1024);
1682 cpu_data(cpuid).icache_line_size =
1683 of_getintprop_default(dp, "icache-line-size", 32);
1684
1685 cpu_data(cpuid).ecache_size =
1686 of_getintprop_default(dp, "ecache-size",
1687 (4 * 1024 * 1024));
1688 cpu_data(cpuid).ecache_line_size =
1689 of_getintprop_default(dp, "ecache-line-size", 64);
1690
1691 cpu_data(cpuid).core_id = 0;
David S. Miller5cd342d2007-06-04 21:35:18 -07001692 cpu_data(cpuid).proc_id = -1;
David S. Miller5cbc3072007-05-25 15:49:59 -07001693 }
1694
1695#ifdef CONFIG_SMP
1696 cpu_set(cpuid, cpu_present_map);
David S. Miller4f0234f2007-07-13 16:03:42 -07001697 cpu_set(cpuid, cpu_possible_map);
David S. Miller5cbc3072007-05-25 15:49:59 -07001698#endif
1699 }
1700
1701 smp_fill_in_sib_core_maps();
1702}
1703
David S. Millerc73fcc82007-07-20 16:59:26 -07001704struct device_node *of_console_device;
1705EXPORT_SYMBOL(of_console_device);
1706
1707char *of_console_path;
1708EXPORT_SYMBOL(of_console_path);
1709
1710char *of_console_options;
1711EXPORT_SYMBOL(of_console_options);
1712
1713static void __init of_console_init(void)
1714{
1715 char *msg = "OF stdout device is: %s\n";
1716 struct device_node *dp;
1717 const char *type;
1718 phandle node;
1719
1720 of_console_path = prom_early_alloc(256);
1721 if (prom_ihandle2path(prom_stdout, of_console_path, 256) < 0) {
1722 prom_printf("Cannot obtain path of stdout.\n");
1723 prom_halt();
1724 }
1725 of_console_options = strrchr(of_console_path, ':');
1726 if (of_console_options) {
1727 of_console_options++;
1728 if (*of_console_options == '\0')
1729 of_console_options = NULL;
1730 }
1731
1732 node = prom_inst2pkg(prom_stdout);
1733 if (!node) {
1734 prom_printf("Cannot resolve stdout node from "
1735 "instance %08x.\n", prom_stdout);
1736 prom_halt();
1737 }
1738
1739 dp = of_find_node_by_phandle(node);
1740 type = of_get_property(dp, "device_type", NULL);
1741 if (!type) {
1742 prom_printf("Console stdout lacks device_type property.\n");
1743 prom_halt();
1744 }
1745
1746 if (strcmp(type, "display") && strcmp(type, "serial")) {
1747 prom_printf("Console device_type is neither display "
1748 "nor serial.\n");
1749 prom_halt();
1750 }
1751
1752 of_console_device = dp;
1753
David S. Millerc73fcc82007-07-20 16:59:26 -07001754 printk(msg, of_console_path);
1755}
1756
David S. Miller372b07b2006-06-21 15:35:28 -07001757void __init prom_build_devicetree(void)
1758{
1759 struct device_node **nextp;
1760
David S. Miller4130a4b2006-10-25 22:31:06 -07001761 allnodes = create_node(prom_root_node, NULL);
David S. Miller372b07b2006-06-21 15:35:28 -07001762 allnodes->path_component_name = "";
1763 allnodes->full_name = "/";
1764
1765 nextp = &allnodes->allnext;
1766 allnodes->child = build_tree(allnodes,
1767 prom_getchild(allnodes->node),
1768 &nextp);
David S. Millerc73fcc82007-07-20 16:59:26 -07001769 of_console_init();
1770
David S. Miller372b07b2006-06-21 15:35:28 -07001771 printk("PROM: Built device tree with %u bytes of memory.\n",
1772 prom_early_allocated);
David S. Miller5cbc3072007-05-25 15:49:59 -07001773
1774 if (tlb_type != hypervisor)
1775 of_fill_in_cpu_data();
David S. Miller372b07b2006-06-21 15:35:28 -07001776}