aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sparc64/kernel')
-rw-r--r--arch/sparc64/kernel/Makefile2
-rw-r--r--arch/sparc64/kernel/auxio.c109
-rw-r--r--arch/sparc64/kernel/central.c127
-rw-r--r--arch/sparc64/kernel/chmc.c69
-rw-r--r--arch/sparc64/kernel/devices.c222
-rw-r--r--arch/sparc64/kernel/ebus.c197
-rw-r--r--arch/sparc64/kernel/irq.c19
-rw-r--r--arch/sparc64/kernel/isa.c183
-rw-r--r--arch/sparc64/kernel/of_device.c279
-rw-r--r--arch/sparc64/kernel/pci.c59
-rw-r--r--arch/sparc64/kernel/pci_common.c227
-rw-r--r--arch/sparc64/kernel/pci_impl.h3
-rw-r--r--arch/sparc64/kernel/pci_psycho.c106
-rw-r--r--arch/sparc64/kernel/pci_sabre.c195
-rw-r--r--arch/sparc64/kernel/pci_schizo.c171
-rw-r--r--arch/sparc64/kernel/pci_sun4v.c160
-rw-r--r--arch/sparc64/kernel/power.c113
-rw-r--r--arch/sparc64/kernel/prom.c650
-rw-r--r--arch/sparc64/kernel/sbus.c67
-rw-r--r--arch/sparc64/kernel/setup.c4
-rw-r--r--arch/sparc64/kernel/smp.c41
-rw-r--r--arch/sparc64/kernel/time.c386
-rw-r--r--arch/sparc64/kernel/traps.c18
-rw-r--r--arch/sparc64/kernel/unaligned.c9
24 files changed, 2168 insertions, 1248 deletions
diff --git a/arch/sparc64/kernel/Makefile b/arch/sparc64/kernel/Makefile
index 6f6816488b04..86c9fe3f3e4a 100644
--- a/arch/sparc64/kernel/Makefile
+++ b/arch/sparc64/kernel/Makefile
@@ -12,7 +12,7 @@ obj-y := process.o setup.o cpu.o idprom.o \
12 irq.o ptrace.o time.o sys_sparc.o signal.o \ 12 irq.o ptrace.o time.o sys_sparc.o signal.o \
13 unaligned.o central.o pci.o starfire.o semaphore.o \ 13 unaligned.o central.o pci.o starfire.o semaphore.o \
14 power.o sbus.o iommu_common.o sparc64_ksyms.o chmc.o \ 14 power.o sbus.o iommu_common.o sparc64_ksyms.o chmc.o \
15 visemul.o 15 visemul.o prom.o of_device.o
16 16
17obj-$(CONFIG_PCI) += ebus.o isa.o pci_common.o pci_iommu.o \ 17obj-$(CONFIG_PCI) += ebus.o isa.o pci_common.o pci_iommu.o \
18 pci_psycho.o pci_sabre.o pci_schizo.o \ 18 pci_psycho.o pci_sabre.o pci_schizo.o \
diff --git a/arch/sparc64/kernel/auxio.c b/arch/sparc64/kernel/auxio.c
index 8852c20c8d99..2c42894b188f 100644
--- a/arch/sparc64/kernel/auxio.c
+++ b/arch/sparc64/kernel/auxio.c
@@ -110,43 +110,82 @@ void auxio_set_lte(int on)
110 } 110 }
111} 111}
112 112
113void __init auxio_probe(void) 113static void __devinit auxio_report_dev(struct device_node *dp)
114{ 114{
115 struct sbus_bus *sbus; 115 printk(KERN_INFO "AUXIO: Found device at %s\n",
116 struct sbus_dev *sdev = NULL; 116 dp->full_name);
117 117}
118 for_each_sbus(sbus) { 118
119 for_each_sbusdev(sdev, sbus) { 119static struct of_device_id auxio_match[] = {
120 if(!strcmp(sdev->prom_name, "auxio")) 120 {
121 goto found_sdev; 121 .name = "auxio",
122 } 122 },
123 } 123 {},
124 124};
125found_sdev: 125
126 if (sdev) { 126MODULE_DEVICE_TABLE(of, auxio_match);
127 auxio_devtype = AUXIO_TYPE_SBUS; 127
128 auxio_register = sbus_ioremap(&sdev->resource[0], 0, 128#ifdef CONFIG_SBUS
129 sdev->reg_addrs[0].reg_size, 129static int __devinit auxio_sbus_probe(struct of_device *dev, const struct of_device_id *match)
130 "auxiliaryIO"); 130{
131 } 131 struct sbus_dev *sdev = to_sbus_device(&dev->dev);
132
133 auxio_devtype = AUXIO_TYPE_SBUS;
134 auxio_register = sbus_ioremap(&sdev->resource[0], 0,
135 sdev->reg_addrs[0].reg_size,
136 "auxiliaryIO");
137 if (!auxio_register)
138 return -ENODEV;
139
140 auxio_report_dev(dev->node);
141 return 0;
142}
143
144static struct of_platform_driver auxio_sbus_driver = {
145 .name = "auxio",
146 .match_table = auxio_match,
147 .probe = auxio_sbus_probe,
148};
149#endif
150
132#ifdef CONFIG_PCI 151#ifdef CONFIG_PCI
133 else { 152static int __devinit auxio_ebus_probe(struct of_device *dev, const struct of_device_id *match)
134 struct linux_ebus *ebus; 153{
135 struct linux_ebus_device *edev = NULL; 154 struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
136 155
137 for_each_ebus(ebus) { 156 auxio_devtype = AUXIO_TYPE_EBUS;
138 for_each_ebusdev(edev, ebus) { 157 auxio_register = ioremap(edev->resource[0].start, sizeof(u32));
139 if (!strcmp(edev->prom_name, "auxio")) 158 if (!auxio_register)
140 goto ebus_done; 159 return -ENODEV;
141 } 160
142 } 161 auxio_report_dev(dev->node);
143 ebus_done: 162
144 if (edev) {
145 auxio_devtype = AUXIO_TYPE_EBUS;
146 auxio_register =
147 ioremap(edev->resource[0].start, sizeof(u32));
148 }
149 }
150 auxio_set_led(AUXIO_LED_ON); 163 auxio_set_led(AUXIO_LED_ON);
164
165 return 0;
166}
167
168static struct of_platform_driver auxio_ebus_driver = {
169 .name = "auxio",
170 .match_table = auxio_match,
171 .probe = auxio_ebus_probe,
172};
151#endif 173#endif
174
175static int __init auxio_probe(void)
176{
177#ifdef CONFIG_SBUS
178 of_register_driver(&auxio_sbus_driver, &sbus_bus_type);
179#endif
180#ifdef CONFIG_PCI
181 of_register_driver(&auxio_ebus_driver, &ebus_bus_type);
182#endif
183
184 return 0;
152} 185}
186
187/* Must be after subsys_initcall() so that busses are probed. Must
188 * be before device_initcall() because things like the floppy driver
189 * need to use the AUXIO register.
190 */
191fs_initcall(auxio_probe);
diff --git a/arch/sparc64/kernel/central.c b/arch/sparc64/kernel/central.c
index 3d184a784968..b66336db00ee 100644
--- a/arch/sparc64/kernel/central.c
+++ b/arch/sparc64/kernel/central.c
@@ -29,28 +29,34 @@ static void central_probe_failure(int line)
29 prom_halt(); 29 prom_halt();
30} 30}
31 31
32static void central_ranges_init(int cnode, struct linux_central *central) 32static void central_ranges_init(struct linux_central *central)
33{ 33{
34 int success; 34 struct device_node *dp = central->prom_node;
35 void *pval;
36 int len;
35 37
36 central->num_central_ranges = 0; 38 central->num_central_ranges = 0;
37 success = prom_getproperty(central->prom_node, "ranges", 39 pval = of_get_property(dp, "ranges", &len);
38 (char *) central->central_ranges, 40 if (pval) {
39 sizeof (central->central_ranges)); 41 memcpy(central->central_ranges, pval, len);
40 if (success != -1) 42 central->num_central_ranges =
41 central->num_central_ranges = (success/sizeof(struct linux_prom_ranges)); 43 (len / sizeof(struct linux_prom_ranges));
44 }
42} 45}
43 46
44static void fhc_ranges_init(int fnode, struct linux_fhc *fhc) 47static void fhc_ranges_init(struct linux_fhc *fhc)
45{ 48{
46 int success; 49 struct device_node *dp = fhc->prom_node;
50 void *pval;
51 int len;
47 52
48 fhc->num_fhc_ranges = 0; 53 fhc->num_fhc_ranges = 0;
49 success = prom_getproperty(fhc->prom_node, "ranges", 54 pval = of_get_property(dp, "ranges", &len);
50 (char *) fhc->fhc_ranges, 55 if (pval) {
51 sizeof (fhc->fhc_ranges)); 56 memcpy(fhc->fhc_ranges, pval, len);
52 if (success != -1) 57 fhc->num_fhc_ranges =
53 fhc->num_fhc_ranges = (success/sizeof(struct linux_prom_ranges)); 58 (len / sizeof(struct linux_prom_ranges));
59 }
54} 60}
55 61
56/* Range application routines are exported to various drivers, 62/* Range application routines are exported to various drivers,
@@ -112,15 +118,10 @@ static unsigned long prom_reg_to_paddr(struct linux_prom_registers *r)
112 118
113static void probe_other_fhcs(void) 119static void probe_other_fhcs(void)
114{ 120{
115 struct linux_prom64_registers fpregs[6]; 121 struct device_node *dp;
116 char namebuf[128]; 122 struct linux_prom64_registers *fpregs;
117 int node;
118 123
119 node = prom_getchild(prom_root_node); 124 for_each_node_by_name(dp, "fhc") {
120 node = prom_searchsiblings(node, "fhc");
121 if (node == 0)
122 central_probe_failure(__LINE__);
123 while (node) {
124 struct linux_fhc *fhc; 125 struct linux_fhc *fhc;
125 int board; 126 int board;
126 u32 tmp; 127 u32 tmp;
@@ -137,14 +138,12 @@ static void probe_other_fhcs(void)
137 /* Toplevel FHCs have no parent. */ 138 /* Toplevel FHCs have no parent. */
138 fhc->parent = NULL; 139 fhc->parent = NULL;
139 140
140 fhc->prom_node = node; 141 fhc->prom_node = dp;
141 prom_getstring(node, "name", namebuf, sizeof(namebuf)); 142 fhc_ranges_init(fhc);
142 strcpy(fhc->prom_name, namebuf);
143 fhc_ranges_init(node, fhc);
144 143
145 /* Non-central FHC's have 64-bit OBP format registers. */ 144 /* Non-central FHC's have 64-bit OBP format registers. */
146 if (prom_getproperty(node, "reg", 145 fpregs = of_get_property(dp, "reg", NULL);
147 (char *)&fpregs[0], sizeof(fpregs)) == -1) 146 if (!fpregs)
148 central_probe_failure(__LINE__); 147 central_probe_failure(__LINE__);
149 148
150 /* Only central FHC needs special ranges applied. */ 149 /* Only central FHC needs special ranges applied. */
@@ -155,7 +154,7 @@ static void probe_other_fhcs(void)
155 fhc->fhc_regs.uregs = fpregs[4].phys_addr; 154 fhc->fhc_regs.uregs = fpregs[4].phys_addr;
156 fhc->fhc_regs.tregs = fpregs[5].phys_addr; 155 fhc->fhc_regs.tregs = fpregs[5].phys_addr;
157 156
158 board = prom_getintdefault(node, "board#", -1); 157 board = of_getintprop_default(dp, "board#", -1);
159 fhc->board = board; 158 fhc->board = board;
160 159
161 tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_JCTRL); 160 tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_JCTRL);
@@ -179,33 +178,33 @@ static void probe_other_fhcs(void)
179 tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL); 178 tmp = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
180 tmp |= FHC_CONTROL_IXIST; 179 tmp |= FHC_CONTROL_IXIST;
181 upa_writel(tmp, fhc->fhc_regs.pregs + FHC_PREGS_CTRL); 180 upa_writel(tmp, fhc->fhc_regs.pregs + FHC_PREGS_CTRL);
182
183 /* Look for the next FHC. */
184 node = prom_getsibling(node);
185 if (node == 0)
186 break;
187 node = prom_searchsiblings(node, "fhc");
188 if (node == 0)
189 break;
190 } 181 }
191} 182}
192 183
193static void probe_clock_board(struct linux_central *central, 184static void probe_clock_board(struct linux_central *central,
194 struct linux_fhc *fhc, 185 struct linux_fhc *fhc,
195 int cnode, int fnode) 186 struct device_node *fp)
196{ 187{
197 struct linux_prom_registers cregs[3]; 188 struct device_node *dp;
198 int clknode, nslots, tmp, nregs; 189 struct linux_prom_registers cregs[3], *pr;
190 int nslots, tmp, nregs;
199 191
200 clknode = prom_searchsiblings(prom_getchild(fnode), "clock-board"); 192 dp = fp->child;
201 if (clknode == 0 || clknode == -1) 193 while (dp) {
194 if (!strcmp(dp->name, "clock-board"))
195 break;
196 dp = dp->sibling;
197 }
198 if (!dp)
202 central_probe_failure(__LINE__); 199 central_probe_failure(__LINE__);
203 200
204 nregs = prom_getproperty(clknode, "reg", (char *)&cregs[0], sizeof(cregs)); 201 pr = of_get_property(dp, "reg", &nregs);
205 if (nregs == -1) 202 if (!pr)
206 central_probe_failure(__LINE__); 203 central_probe_failure(__LINE__);
207 204
205 memcpy(cregs, pr, nregs);
208 nregs /= sizeof(struct linux_prom_registers); 206 nregs /= sizeof(struct linux_prom_registers);
207
209 apply_fhc_ranges(fhc, &cregs[0], nregs); 208 apply_fhc_ranges(fhc, &cregs[0], nregs);
210 apply_central_ranges(central, &cregs[0], nregs); 209 apply_central_ranges(central, &cregs[0], nregs);
211 central->cfreg = prom_reg_to_paddr(&cregs[0]); 210 central->cfreg = prom_reg_to_paddr(&cregs[0]);
@@ -296,13 +295,13 @@ static void init_all_fhc_hw(void)
296 295
297void central_probe(void) 296void central_probe(void)
298{ 297{
299 struct linux_prom_registers fpregs[6]; 298 struct linux_prom_registers fpregs[6], *pr;
300 struct linux_fhc *fhc; 299 struct linux_fhc *fhc;
301 char namebuf[128]; 300 struct device_node *dp, *fp;
302 int cnode, fnode, err; 301 int err;
303 302
304 cnode = prom_finddevice("/central"); 303 dp = of_find_node_by_name(NULL, "central");
305 if (cnode == 0 || cnode == -1) { 304 if (!dp) {
306 if (this_is_starfire) 305 if (this_is_starfire)
307 starfire_cpu_setup(); 306 starfire_cpu_setup();
308 return; 307 return;
@@ -321,31 +320,31 @@ void central_probe(void)
321 320
322 /* First init central. */ 321 /* First init central. */
323 central_bus->child = fhc; 322 central_bus->child = fhc;
324 central_bus->prom_node = cnode; 323 central_bus->prom_node = dp;
325 324 central_ranges_init(central_bus);
326 prom_getstring(cnode, "name", namebuf, sizeof(namebuf));
327 strcpy(central_bus->prom_name, namebuf);
328
329 central_ranges_init(cnode, central_bus);
330 325
331 /* And then central's FHC. */ 326 /* And then central's FHC. */
332 fhc->next = fhc_list; 327 fhc->next = fhc_list;
333 fhc_list = fhc; 328 fhc_list = fhc;
334 329
335 fhc->parent = central_bus; 330 fhc->parent = central_bus;
336 fnode = prom_searchsiblings(prom_getchild(cnode), "fhc"); 331 fp = dp->child;
337 if (fnode == 0 || fnode == -1) 332 while (fp) {
333 if (!strcmp(fp->name, "fhc"))
334 break;
335 fp = fp->sibling;
336 }
337 if (!fp)
338 central_probe_failure(__LINE__); 338 central_probe_failure(__LINE__);
339 339
340 fhc->prom_node = fnode; 340 fhc->prom_node = fp;
341 prom_getstring(fnode, "name", namebuf, sizeof(namebuf)); 341 fhc_ranges_init(fhc);
342 strcpy(fhc->prom_name, namebuf);
343
344 fhc_ranges_init(fnode, fhc);
345 342
346 /* Now, map in FHC register set. */ 343 /* Now, map in FHC register set. */
347 if (prom_getproperty(fnode, "reg", (char *)&fpregs[0], sizeof(fpregs)) == -1) 344 pr = of_get_property(fp, "reg", NULL);
345 if (!pr)
348 central_probe_failure(__LINE__); 346 central_probe_failure(__LINE__);
347 memcpy(fpregs, pr, sizeof(fpregs));
349 348
350 apply_central_ranges(central_bus, &fpregs[0], 6); 349 apply_central_ranges(central_bus, &fpregs[0], 6);
351 350
@@ -366,7 +365,7 @@ void central_probe(void)
366 fhc->jtag_master = 0; 365 fhc->jtag_master = 0;
367 366
368 /* Attach the clock board registers for CENTRAL. */ 367 /* Attach the clock board registers for CENTRAL. */
369 probe_clock_board(central_bus, fhc, cnode, fnode); 368 probe_clock_board(central_bus, fhc, fp);
370 369
371 err = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_ID); 370 err = upa_readl(fhc->fhc_regs.pregs + FHC_PREGS_ID);
372 printk("FHC(board %d): Version[%x] PartID[%x] Manuf[%x] (CENTRAL)\n", 371 printk("FHC(board %d): Version[%x] PartID[%x] Manuf[%x] (CENTRAL)\n",
diff --git a/arch/sparc64/kernel/chmc.c b/arch/sparc64/kernel/chmc.c
index 97cf912f0853..259f37e516f5 100644
--- a/arch/sparc64/kernel/chmc.c
+++ b/arch/sparc64/kernel/chmc.c
@@ -17,6 +17,7 @@
17#include <asm/spitfire.h> 17#include <asm/spitfire.h>
18#include <asm/chmctrl.h> 18#include <asm/chmctrl.h>
19#include <asm/oplib.h> 19#include <asm/oplib.h>
20#include <asm/prom.h>
20#include <asm/io.h> 21#include <asm/io.h>
21 22
22#define CHMCTRL_NDGRPS 2 23#define CHMCTRL_NDGRPS 2
@@ -67,7 +68,6 @@ struct bank_info {
67struct mctrl_info { 68struct mctrl_info {
68 struct list_head list; 69 struct list_head list;
69 int portid; 70 int portid;
70 int index;
71 71
72 struct obp_mem_layout layout_prop; 72 struct obp_mem_layout layout_prop;
73 int layout_size; 73 int layout_size;
@@ -339,12 +339,13 @@ static void fetch_decode_regs(struct mctrl_info *mp)
339 read_mcreg(mp, CHMCTRL_DECODE4)); 339 read_mcreg(mp, CHMCTRL_DECODE4));
340} 340}
341 341
342static int init_one_mctrl(int node, int index) 342static int init_one_mctrl(struct device_node *dp)
343{ 343{
344 struct mctrl_info *mp = kmalloc(sizeof(*mp), GFP_KERNEL); 344 struct mctrl_info *mp = kmalloc(sizeof(*mp), GFP_KERNEL);
345 int portid = prom_getintdefault(node, "portid", -1); 345 int portid = of_getintprop_default(dp, "portid", -1);
346 struct linux_prom64_registers p_reg_prop; 346 struct linux_prom64_registers *regs;
347 int t; 347 void *pval;
348 int len;
348 349
349 if (!mp) 350 if (!mp)
350 return -1; 351 return -1;
@@ -353,24 +354,21 @@ static int init_one_mctrl(int node, int index)
353 goto fail; 354 goto fail;
354 355
355 mp->portid = portid; 356 mp->portid = portid;
356 mp->layout_size = prom_getproplen(node, "memory-layout"); 357 pval = of_get_property(dp, "memory-layout", &len);
357 if (mp->layout_size < 0) 358 mp->layout_size = len;
359 if (!pval)
358 mp->layout_size = 0; 360 mp->layout_size = 0;
359 if (mp->layout_size > sizeof(mp->layout_prop)) 361 else {
360 goto fail; 362 if (mp->layout_size > sizeof(mp->layout_prop))
361 363 goto fail;
362 if (mp->layout_size > 0) 364 memcpy(&mp->layout_prop, pval, len);
363 prom_getproperty(node, "memory-layout", 365 }
364 (char *) &mp->layout_prop,
365 mp->layout_size);
366 366
367 t = prom_getproperty(node, "reg", 367 regs = of_get_property(dp, "reg", NULL);
368 (char *) &p_reg_prop, 368 if (!regs || regs->reg_size != 0x48)
369 sizeof(p_reg_prop));
370 if (t < 0 || p_reg_prop.reg_size != 0x48)
371 goto fail; 369 goto fail;
372 370
373 mp->regs = ioremap(p_reg_prop.phys_addr, p_reg_prop.reg_size); 371 mp->regs = ioremap(regs->phys_addr, regs->reg_size);
374 if (mp->regs == NULL) 372 if (mp->regs == NULL)
375 goto fail; 373 goto fail;
376 374
@@ -384,13 +382,11 @@ static int init_one_mctrl(int node, int index)
384 382
385 fetch_decode_regs(mp); 383 fetch_decode_regs(mp);
386 384
387 mp->index = index;
388
389 list_add(&mp->list, &mctrl_list); 385 list_add(&mp->list, &mctrl_list);
390 386
391 /* Report the device. */ 387 /* Report the device. */
392 printk(KERN_INFO "chmc%d: US3 memory controller at %p [%s]\n", 388 printk(KERN_INFO "%s: US3 memory controller at %p [%s]\n",
393 mp->index, 389 dp->full_name,
394 mp->regs, (mp->layout_size ? "ACTIVE" : "INACTIVE")); 390 mp->regs, (mp->layout_size ? "ACTIVE" : "INACTIVE"));
395 391
396 return 0; 392 return 0;
@@ -404,34 +400,19 @@ fail:
404 return -1; 400 return -1;
405} 401}
406 402
407static int __init probe_for_string(char *name, int index)
408{
409 int node = prom_getchild(prom_root_node);
410
411 while ((node = prom_searchsiblings(node, name)) != 0) {
412 int ret = init_one_mctrl(node, index);
413
414 if (!ret)
415 index++;
416
417 node = prom_getsibling(node);
418 if (!node)
419 break;
420 }
421
422 return index;
423}
424
425static int __init chmc_init(void) 403static int __init chmc_init(void)
426{ 404{
427 int index; 405 struct device_node *dp;
428 406
429 /* This driver is only for cheetah platforms. */ 407 /* This driver is only for cheetah platforms. */
430 if (tlb_type != cheetah && tlb_type != cheetah_plus) 408 if (tlb_type != cheetah && tlb_type != cheetah_plus)
431 return -ENODEV; 409 return -ENODEV;
432 410
433 index = probe_for_string("memory-controller", 0); 411 for_each_node_by_name(dp, "memory-controller")
434 index = probe_for_string("mc-us3", index); 412 init_one_mctrl(dp);
413
414 for_each_node_by_name(dp, "mc-us3")
415 init_one_mctrl(dp);
435 416
436 return 0; 417 return 0;
437} 418}
diff --git a/arch/sparc64/kernel/devices.c b/arch/sparc64/kernel/devices.c
index 0dd95ae50e12..389301c95cb2 100644
--- a/arch/sparc64/kernel/devices.c
+++ b/arch/sparc64/kernel/devices.c
@@ -33,7 +33,7 @@ extern void cpu_probe(void);
33extern void central_probe(void); 33extern void central_probe(void);
34 34
35u32 sun4v_vdev_devhandle; 35u32 sun4v_vdev_devhandle;
36int sun4v_vdev_root; 36struct device_node *sun4v_vdev_root;
37 37
38struct vdev_intmap { 38struct vdev_intmap {
39 unsigned int phys; 39 unsigned int phys;
@@ -50,102 +50,68 @@ struct vdev_intmask {
50 50
51static struct vdev_intmap *vdev_intmap; 51static struct vdev_intmap *vdev_intmap;
52static int vdev_num_intmap; 52static int vdev_num_intmap;
53static struct vdev_intmask vdev_intmask; 53static struct vdev_intmask *vdev_intmask;
54 54
55static void __init sun4v_virtual_device_probe(void) 55static void __init sun4v_virtual_device_probe(void)
56{ 56{
57 struct linux_prom64_registers regs; 57 struct linux_prom64_registers *regs;
58 struct vdev_intmap *ip; 58 struct property *prop;
59 int node, sz, err; 59 struct device_node *dp;
60 int sz;
60 61
61 if (tlb_type != hypervisor) 62 if (tlb_type != hypervisor)
62 return; 63 return;
63 64
64 node = prom_getchild(prom_root_node); 65 dp = of_find_node_by_name(NULL, "virtual-devices");
65 node = prom_searchsiblings(node, "virtual-devices"); 66 if (!dp) {
66 if (!node) {
67 prom_printf("SUN4V: Fatal error, no virtual-devices node.\n"); 67 prom_printf("SUN4V: Fatal error, no virtual-devices node.\n");
68 prom_halt(); 68 prom_halt();
69 } 69 }
70 70
71 sun4v_vdev_root = node; 71 sun4v_vdev_root = dp;
72 72
73 prom_getproperty(node, "reg", (char *)&regs, sizeof(regs)); 73 prop = of_find_property(dp, "reg", NULL);
74 sun4v_vdev_devhandle = (regs.phys_addr >> 32UL) & 0x0fffffff; 74 regs = prop->value;
75 sun4v_vdev_devhandle = (regs[0].phys_addr >> 32UL) & 0x0fffffff;
75 76
76 sz = prom_getproplen(node, "interrupt-map"); 77 prop = of_find_property(dp, "interrupt-map", &sz);
77 if (sz <= 0) { 78 vdev_intmap = prop->value;
78 prom_printf("SUN4V: Error, no vdev interrupt-map.\n"); 79 vdev_num_intmap = sz / sizeof(struct vdev_intmap);
79 prom_halt();
80 }
81
82 if ((sz % sizeof(*ip)) != 0) {
83 prom_printf("SUN4V: Bogus interrupt-map property size %d\n",
84 sz);
85 prom_halt();
86 }
87
88 vdev_intmap = ip = alloc_bootmem_low_pages(sz);
89 if (!vdev_intmap) {
90 prom_printf("SUN4V: Error, cannot allocate vdev_intmap.\n");
91 prom_halt();
92 }
93
94 err = prom_getproperty(node, "interrupt-map", (char *) ip, sz);
95 if (err == -1) {
96 prom_printf("SUN4V: Fatal error, no vdev interrupt-map.\n");
97 prom_halt();
98 }
99 if (err != sz) {
100 prom_printf("SUN4V: Inconsistent interrupt-map size, "
101 "proplen(%d) vs getprop(%d).\n", sz,err);
102 prom_halt();
103 }
104
105 vdev_num_intmap = err / sizeof(*ip);
106 80
107 err = prom_getproperty(node, "interrupt-map-mask", 81 prop = of_find_property(dp, "interrupt-map-mask", NULL);
108 (char *) &vdev_intmask, 82 vdev_intmask = prop->value;
109 sizeof(vdev_intmask));
110 if (err <= 0) {
111 prom_printf("SUN4V: Fatal error, no vdev "
112 "interrupt-map-mask.\n");
113 prom_halt();
114 }
115 if (err % sizeof(vdev_intmask)) {
116 prom_printf("SUN4V: Bogus interrupt-map-mask "
117 "property size %d\n", err);
118 prom_halt();
119 }
120 83
121 printk("SUN4V: virtual-devices devhandle[%x]\n", 84 printk("%s: Virtual Device Bus devhandle[%x]\n",
122 sun4v_vdev_devhandle); 85 dp->full_name, sun4v_vdev_devhandle);
123} 86}
124 87
125unsigned int sun4v_vdev_device_interrupt(unsigned int dev_node) 88unsigned int sun4v_vdev_device_interrupt(struct device_node *dev_node)
126{ 89{
90 struct property *prop;
127 unsigned int irq, reg; 91 unsigned int irq, reg;
128 int err, i; 92 int i;
129 93
130 err = prom_getproperty(dev_node, "interrupts", 94 prop = of_find_property(dev_node, "interrupts", NULL);
131 (char *) &irq, sizeof(irq)); 95 if (!prop) {
132 if (err <= 0) {
133 printk("VDEV: Cannot get \"interrupts\" " 96 printk("VDEV: Cannot get \"interrupts\" "
134 "property for OBP node %x\n", dev_node); 97 "property for OBP node %s\n",
98 dev_node->full_name);
135 return 0; 99 return 0;
136 } 100 }
101 irq = *(unsigned int *) prop->value;
137 102
138 err = prom_getproperty(dev_node, "reg", 103 prop = of_find_property(dev_node, "reg", NULL);
139 (char *) &reg, sizeof(reg)); 104 if (!prop) {
140 if (err <= 0) {
141 printk("VDEV: Cannot get \"reg\" " 105 printk("VDEV: Cannot get \"reg\" "
142 "property for OBP node %x\n", dev_node); 106 "property for OBP node %s\n",
107 dev_node->full_name);
143 return 0; 108 return 0;
144 } 109 }
110 reg = *(unsigned int *) prop->value;
145 111
146 for (i = 0; i < vdev_num_intmap; i++) { 112 for (i = 0; i < vdev_num_intmap; i++) {
147 if (vdev_intmap[i].phys == (reg & vdev_intmask.phys) && 113 if (vdev_intmap[i].phys == (reg & vdev_intmask->phys) &&
148 vdev_intmap[i].irq == (irq & vdev_intmask.interrupt)) { 114 vdev_intmap[i].irq == (irq & vdev_intmask->interrupt)) {
149 irq = vdev_intmap[i].cinterrupt; 115 irq = vdev_intmap[i].cinterrupt;
150 break; 116 break;
151 } 117 }
@@ -153,7 +119,7 @@ unsigned int sun4v_vdev_device_interrupt(unsigned int dev_node)
153 119
154 if (i == vdev_num_intmap) { 120 if (i == vdev_num_intmap) {
155 printk("VDEV: No matching interrupt map entry " 121 printk("VDEV: No matching interrupt map entry "
156 "for OBP node %x\n", dev_node); 122 "for OBP node %s\n", dev_node->full_name);
157 return 0; 123 return 0;
158 } 124 }
159 125
@@ -167,38 +133,44 @@ static const char *cpu_mid_prop(void)
167 return "portid"; 133 return "portid";
168} 134}
169 135
170static int get_cpu_mid(int prom_node) 136static int get_cpu_mid(struct device_node *dp)
171{ 137{
138 struct property *prop;
139
172 if (tlb_type == hypervisor) { 140 if (tlb_type == hypervisor) {
173 struct linux_prom64_registers reg; 141 struct linux_prom64_registers *reg;
142 int len;
174 143
175 if (prom_getproplen(prom_node, "cpuid") == 4) 144 prop = of_find_property(dp, "cpuid", &len);
176 return prom_getintdefault(prom_node, "cpuid", 0); 145 if (prop && len == 4)
146 return *(int *) prop->value;
177 147
178 prom_getproperty(prom_node, "reg", (char *) &reg, sizeof(reg)); 148 prop = of_find_property(dp, "reg", NULL);
179 return (reg.phys_addr >> 32) & 0x0fffffffUL; 149 reg = prop->value;
150 return (reg[0].phys_addr >> 32) & 0x0fffffffUL;
180 } else { 151 } else {
181 const char *prop_name = cpu_mid_prop(); 152 const char *prop_name = cpu_mid_prop();
182 153
183 return prom_getintdefault(prom_node, prop_name, 0); 154 prop = of_find_property(dp, prop_name, NULL);
155 if (prop)
156 return *(int *) prop->value;
157 return 0;
184 } 158 }
185} 159}
186 160
187static int check_cpu_node(int nd, int *cur_inst, 161static int check_cpu_node(struct device_node *dp, int *cur_inst,
188 int (*compare)(int, int, void *), void *compare_arg, 162 int (*compare)(struct device_node *, int, void *),
189 int *prom_node, int *mid) 163 void *compare_arg,
164 struct device_node **dev_node, int *mid)
190{ 165{
191 char node_str[128]; 166 if (strcmp(dp->type, "cpu"))
192
193 prom_getstring(nd, "device_type", node_str, sizeof(node_str));
194 if (strcmp(node_str, "cpu"))
195 return -ENODEV; 167 return -ENODEV;
196 168
197 if (!compare(nd, *cur_inst, compare_arg)) { 169 if (!compare(dp, *cur_inst, compare_arg)) {
198 if (prom_node) 170 if (dev_node)
199 *prom_node = nd; 171 *dev_node = dp;
200 if (mid) 172 if (mid)
201 *mid = get_cpu_mid(nd); 173 *mid = get_cpu_mid(dp);
202 return 0; 174 return 0;
203 } 175 }
204 176
@@ -207,25 +179,18 @@ static int check_cpu_node(int nd, int *cur_inst,
207 return -ENODEV; 179 return -ENODEV;
208} 180}
209 181
210static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg, 182static int __cpu_find_by(int (*compare)(struct device_node *, int, void *),
211 int *prom_node, int *mid) 183 void *compare_arg,
184 struct device_node **dev_node, int *mid)
212{ 185{
213 int nd, cur_inst, err; 186 struct device_node *dp;
187 int cur_inst;
214 188
215 nd = prom_root_node;
216 cur_inst = 0; 189 cur_inst = 0;
217 190 for_each_node_by_type(dp, "cpu") {
218 err = check_cpu_node(nd, &cur_inst, 191 int err = check_cpu_node(dp, &cur_inst,
219 compare, compare_arg, 192 compare, compare_arg,
220 prom_node, mid); 193 dev_node, mid);
221 if (err == 0)
222 return 0;
223
224 nd = prom_getchild(nd);
225 while ((nd = prom_getsibling(nd)) != 0) {
226 err = check_cpu_node(nd, &cur_inst,
227 compare, compare_arg,
228 prom_node, mid);
229 if (err == 0) 194 if (err == 0)
230 return 0; 195 return 0;
231 } 196 }
@@ -233,7 +198,7 @@ static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg,
233 return -ENODEV; 198 return -ENODEV;
234} 199}
235 200
236static int cpu_instance_compare(int nd, int instance, void *_arg) 201static int cpu_instance_compare(struct device_node *dp, int instance, void *_arg)
237{ 202{
238 int desired_instance = (int) (long) _arg; 203 int desired_instance = (int) (long) _arg;
239 204
@@ -242,27 +207,27 @@ static int cpu_instance_compare(int nd, int instance, void *_arg)
242 return -ENODEV; 207 return -ENODEV;
243} 208}
244 209
245int cpu_find_by_instance(int instance, int *prom_node, int *mid) 210int cpu_find_by_instance(int instance, struct device_node **dev_node, int *mid)
246{ 211{
247 return __cpu_find_by(cpu_instance_compare, (void *)(long)instance, 212 return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
248 prom_node, mid); 213 dev_node, mid);
249} 214}
250 215
251static int cpu_mid_compare(int nd, int instance, void *_arg) 216static int cpu_mid_compare(struct device_node *dp, int instance, void *_arg)
252{ 217{
253 int desired_mid = (int) (long) _arg; 218 int desired_mid = (int) (long) _arg;
254 int this_mid; 219 int this_mid;
255 220
256 this_mid = get_cpu_mid(nd); 221 this_mid = get_cpu_mid(dp);
257 if (this_mid == desired_mid) 222 if (this_mid == desired_mid)
258 return 0; 223 return 0;
259 return -ENODEV; 224 return -ENODEV;
260} 225}
261 226
262int cpu_find_by_mid(int mid, int *prom_node) 227int cpu_find_by_mid(int mid, struct device_node **dev_node)
263{ 228{
264 return __cpu_find_by(cpu_mid_compare, (void *)(long)mid, 229 return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
265 prom_node, NULL); 230 dev_node, NULL);
266} 231}
267 232
268void __init device_scan(void) 233void __init device_scan(void)
@@ -274,50 +239,47 @@ void __init device_scan(void)
274 239
275#ifndef CONFIG_SMP 240#ifndef CONFIG_SMP
276 { 241 {
277 int err, cpu_node, def; 242 struct device_node *dp;
243 int err, def;
278 244
279 err = cpu_find_by_instance(0, &cpu_node, NULL); 245 err = cpu_find_by_instance(0, &dp, NULL);
280 if (err) { 246 if (err) {
281 prom_printf("No cpu nodes, cannot continue\n"); 247 prom_printf("No cpu nodes, cannot continue\n");
282 prom_halt(); 248 prom_halt();
283 } 249 }
284 cpu_data(0).clock_tick = prom_getintdefault(cpu_node, 250 cpu_data(0).clock_tick =
285 "clock-frequency", 251 of_getintprop_default(dp, "clock-frequency", 0);
286 0);
287 252
288 def = ((tlb_type == hypervisor) ? 253 def = ((tlb_type == hypervisor) ?
289 (8 * 1024) : 254 (8 * 1024) :
290 (16 * 1024)); 255 (16 * 1024));
291 cpu_data(0).dcache_size = prom_getintdefault(cpu_node, 256 cpu_data(0).dcache_size = of_getintprop_default(dp,
292 "dcache-size", 257 "dcache-size",
293 def); 258 def);
294 259
295 def = 32; 260 def = 32;
296 cpu_data(0).dcache_line_size = 261 cpu_data(0).dcache_line_size =
297 prom_getintdefault(cpu_node, "dcache-line-size", 262 of_getintprop_default(dp, "dcache-line-size", def);
298 def);
299 263
300 def = 16 * 1024; 264 def = 16 * 1024;
301 cpu_data(0).icache_size = prom_getintdefault(cpu_node, 265 cpu_data(0).icache_size = of_getintprop_default(dp,
302 "icache-size", 266 "icache-size",
303 def); 267 def);
304 268
305 def = 32; 269 def = 32;
306 cpu_data(0).icache_line_size = 270 cpu_data(0).icache_line_size =
307 prom_getintdefault(cpu_node, "icache-line-size", 271 of_getintprop_default(dp, "icache-line-size", def);
308 def);
309 272
310 def = ((tlb_type == hypervisor) ? 273 def = ((tlb_type == hypervisor) ?
311 (3 * 1024 * 1024) : 274 (3 * 1024 * 1024) :
312 (4 * 1024 * 1024)); 275 (4 * 1024 * 1024));
313 cpu_data(0).ecache_size = prom_getintdefault(cpu_node, 276 cpu_data(0).ecache_size = of_getintprop_default(dp,
314 "ecache-size", 277 "ecache-size",
315 def); 278 def);
316 279
317 def = 64; 280 def = 64;
318 cpu_data(0).ecache_line_size = 281 cpu_data(0).ecache_line_size =
319 prom_getintdefault(cpu_node, "ecache-line-size", 282 of_getintprop_default(dp, "ecache-line-size", def);
320 def);
321 printk("CPU[0]: Caches " 283 printk("CPU[0]: Caches "
322 "D[sz(%d):line_sz(%d)] " 284 "D[sz(%d):line_sz(%d)] "
323 "I[sz(%d):line_sz(%d)] " 285 "I[sz(%d):line_sz(%d)] "
diff --git a/arch/sparc64/kernel/ebus.c b/arch/sparc64/kernel/ebus.c
index c69504aa638f..98e0a8cbeecd 100644
--- a/arch/sparc64/kernel/ebus.c
+++ b/arch/sparc64/kernel/ebus.c
@@ -269,10 +269,6 @@ EXPORT_SYMBOL(ebus_dma_enable);
269 269
270struct linux_ebus *ebus_chain = NULL; 270struct linux_ebus *ebus_chain = NULL;
271 271
272#ifdef CONFIG_SUN_AUXIO
273extern void auxio_probe(void);
274#endif
275
276static inline void *ebus_alloc(size_t size) 272static inline void *ebus_alloc(size_t size)
277{ 273{
278 void *mem; 274 void *mem;
@@ -283,77 +279,55 @@ static inline void *ebus_alloc(size_t size)
283 return mem; 279 return mem;
284} 280}
285 281
286static void __init ebus_ranges_init(struct linux_ebus *ebus)
287{
288 int success;
289
290 ebus->num_ebus_ranges = 0;
291 success = prom_getproperty(ebus->prom_node, "ranges",
292 (char *)ebus->ebus_ranges,
293 sizeof(ebus->ebus_ranges));
294 if (success != -1)
295 ebus->num_ebus_ranges = (success/sizeof(struct linux_prom_ebus_ranges));
296}
297
298static void __init ebus_intmap_init(struct linux_ebus *ebus)
299{
300 int success;
301
302 ebus->num_ebus_intmap = 0;
303 success = prom_getproperty(ebus->prom_node, "interrupt-map",
304 (char *)ebus->ebus_intmap,
305 sizeof(ebus->ebus_intmap));
306 if (success == -1)
307 return;
308
309 ebus->num_ebus_intmap = (success/sizeof(struct linux_prom_ebus_intmap));
310
311 success = prom_getproperty(ebus->prom_node, "interrupt-map-mask",
312 (char *)&ebus->ebus_intmask,
313 sizeof(ebus->ebus_intmask));
314 if (success == -1) {
315 prom_printf("%s: can't get interrupt-map-mask\n", __FUNCTION__);
316 prom_halt();
317 }
318}
319
320int __init ebus_intmap_match(struct linux_ebus *ebus, 282int __init ebus_intmap_match(struct linux_ebus *ebus,
321 struct linux_prom_registers *reg, 283 struct linux_prom_registers *reg,
322 int *interrupt) 284 int *interrupt)
323{ 285{
286 struct linux_prom_ebus_intmap *imap;
287 struct linux_prom_ebus_intmask *imask;
324 unsigned int hi, lo, irq; 288 unsigned int hi, lo, irq;
325 int i; 289 int i, len, n_imap;
290
291 imap = of_get_property(ebus->prom_node, "interrupt-map", &len);
292 if (!imap)
293 return 0;
294 n_imap = len / sizeof(imap[0]);
326 295
327 if (!ebus->num_ebus_intmap) 296 imask = of_get_property(ebus->prom_node, "interrupt-map-mask", NULL);
297 if (!imask)
328 return 0; 298 return 0;
329 299
330 hi = reg->which_io & ebus->ebus_intmask.phys_hi; 300 hi = reg->which_io & imask->phys_hi;
331 lo = reg->phys_addr & ebus->ebus_intmask.phys_lo; 301 lo = reg->phys_addr & imask->phys_lo;
332 irq = *interrupt & ebus->ebus_intmask.interrupt; 302 irq = *interrupt & imask->interrupt;
333 for (i = 0; i < ebus->num_ebus_intmap; i++) { 303 for (i = 0; i < n_imap; i++) {
334 if ((ebus->ebus_intmap[i].phys_hi == hi) && 304 if ((imap[i].phys_hi == hi) &&
335 (ebus->ebus_intmap[i].phys_lo == lo) && 305 (imap[i].phys_lo == lo) &&
336 (ebus->ebus_intmap[i].interrupt == irq)) { 306 (imap[i].interrupt == irq)) {
337 *interrupt = ebus->ebus_intmap[i].cinterrupt; 307 *interrupt = imap[i].cinterrupt;
338 return 0; 308 return 0;
339 } 309 }
340 } 310 }
341 return -1; 311 return -1;
342} 312}
343 313
344void __init fill_ebus_child(int node, struct linux_prom_registers *preg, 314void __init fill_ebus_child(struct device_node *dp,
345 struct linux_ebus_child *dev, int non_standard_regs) 315 struct linux_prom_registers *preg,
316 struct linux_ebus_child *dev,
317 int non_standard_regs)
346{ 318{
347 int regs[PROMREG_MAX]; 319 int *regs;
348 int irqs[PROMREG_MAX]; 320 int *irqs;
349 int i, len; 321 int i, len;
350 322
351 dev->prom_node = node; 323 dev->prom_node = dp;
352 prom_getstring(node, "name", dev->prom_name, sizeof(dev->prom_name)); 324 printk(" (%s)", dp->name);
353 printk(" (%s)", dev->prom_name);
354 325
355 len = prom_getproperty(node, "reg", (void *)regs, sizeof(regs)); 326 regs = of_get_property(dp, "reg", &len);
356 dev->num_addrs = len / sizeof(regs[0]); 327 if (!regs)
328 dev->num_addrs = 0;
329 else
330 dev->num_addrs = len / sizeof(regs[0]);
357 331
358 if (non_standard_regs) { 332 if (non_standard_regs) {
359 /* This is to handle reg properties which are not 333 /* This is to handle reg properties which are not
@@ -370,21 +344,21 @@ void __init fill_ebus_child(int node, struct linux_prom_registers *preg,
370 int rnum = regs[i]; 344 int rnum = regs[i];
371 if (rnum >= dev->parent->num_addrs) { 345 if (rnum >= dev->parent->num_addrs) {
372 prom_printf("UGH: property for %s was %d, need < %d\n", 346 prom_printf("UGH: property for %s was %d, need < %d\n",
373 dev->prom_name, len, dev->parent->num_addrs); 347 dp->name, len, dev->parent->num_addrs);
374 panic(__FUNCTION__); 348 prom_halt();
375 } 349 }
376 dev->resource[i].start = dev->parent->resource[i].start; 350 dev->resource[i].start = dev->parent->resource[i].start;
377 dev->resource[i].end = dev->parent->resource[i].end; 351 dev->resource[i].end = dev->parent->resource[i].end;
378 dev->resource[i].flags = IORESOURCE_MEM; 352 dev->resource[i].flags = IORESOURCE_MEM;
379 dev->resource[i].name = dev->prom_name; 353 dev->resource[i].name = dp->name;
380 } 354 }
381 } 355 }
382 356
383 for (i = 0; i < PROMINTR_MAX; i++) 357 for (i = 0; i < PROMINTR_MAX; i++)
384 dev->irqs[i] = PCI_IRQ_NONE; 358 dev->irqs[i] = PCI_IRQ_NONE;
385 359
386 len = prom_getproperty(node, "interrupts", (char *)&irqs, sizeof(irqs)); 360 irqs = of_get_property(dp, "interrupts", &len);
387 if ((len == -1) || (len == 0)) { 361 if (!irqs) {
388 dev->num_irqs = 0; 362 dev->num_irqs = 0;
389 /* 363 /*
390 * Oh, well, some PROMs don't export interrupts 364 * Oh, well, some PROMs don't export interrupts
@@ -392,8 +366,8 @@ void __init fill_ebus_child(int node, struct linux_prom_registers *preg,
392 * 366 *
393 * Be smart about PS/2 keyboard and mouse. 367 * Be smart about PS/2 keyboard and mouse.
394 */ 368 */
395 if (!strcmp(dev->parent->prom_name, "8042")) { 369 if (!strcmp(dev->parent->prom_node->name, "8042")) {
396 if (!strcmp(dev->prom_name, "kb_ps2")) { 370 if (!strcmp(dev->prom_node->name, "kb_ps2")) {
397 dev->num_irqs = 1; 371 dev->num_irqs = 1;
398 dev->irqs[0] = dev->parent->irqs[0]; 372 dev->irqs[0] = dev->parent->irqs[0];
399 } else { 373 } else {
@@ -423,32 +397,32 @@ void __init fill_ebus_child(int node, struct linux_prom_registers *preg,
423 397
424static int __init child_regs_nonstandard(struct linux_ebus_device *dev) 398static int __init child_regs_nonstandard(struct linux_ebus_device *dev)
425{ 399{
426 if (!strcmp(dev->prom_name, "i2c") || 400 if (!strcmp(dev->prom_node->name, "i2c") ||
427 !strcmp(dev->prom_name, "SUNW,lombus")) 401 !strcmp(dev->prom_node->name, "SUNW,lombus"))
428 return 1; 402 return 1;
429 return 0; 403 return 0;
430} 404}
431 405
432void __init fill_ebus_device(int node, struct linux_ebus_device *dev) 406void __init fill_ebus_device(struct device_node *dp, struct linux_ebus_device *dev)
433{ 407{
434 struct linux_prom_registers regs[PROMREG_MAX]; 408 struct linux_prom_registers *regs;
435 struct linux_ebus_child *child; 409 struct linux_ebus_child *child;
436 int irqs[PROMINTR_MAX]; 410 int *irqs;
437 int i, n, len; 411 int i, n, len;
438 412
439 dev->prom_node = node; 413 dev->prom_node = dp;
440 prom_getstring(node, "name", dev->prom_name, sizeof(dev->prom_name)); 414
441 printk(" [%s", dev->prom_name); 415 printk(" [%s", dp->name);
442 416
443 len = prom_getproperty(node, "reg", (void *)regs, sizeof(regs)); 417 regs = of_get_property(dp, "reg", &len);
444 if (len == -1) { 418 if (!regs) {
445 dev->num_addrs = 0; 419 dev->num_addrs = 0;
446 goto probe_interrupts; 420 goto probe_interrupts;
447 } 421 }
448 422
449 if (len % sizeof(struct linux_prom_registers)) { 423 if (len % sizeof(struct linux_prom_registers)) {
450 prom_printf("UGH: proplen for %s was %d, need multiple of %d\n", 424 prom_printf("UGH: proplen for %s was %d, need multiple of %d\n",
451 dev->prom_name, len, 425 dev->prom_node->name, len,
452 (int)sizeof(struct linux_prom_registers)); 426 (int)sizeof(struct linux_prom_registers));
453 prom_halt(); 427 prom_halt();
454 } 428 }
@@ -466,7 +440,7 @@ void __init fill_ebus_device(int node, struct linux_ebus_device *dev)
466 dev->resource[i].end = 440 dev->resource[i].end =
467 (dev->resource[i].start + (unsigned long)regs[i].reg_size - 1UL); 441 (dev->resource[i].start + (unsigned long)regs[i].reg_size - 1UL);
468 dev->resource[i].flags = IORESOURCE_MEM; 442 dev->resource[i].flags = IORESOURCE_MEM;
469 dev->resource[i].name = dev->prom_name; 443 dev->resource[i].name = dev->prom_node->name;
470 request_resource(&dev->bus->self->resource[n], 444 request_resource(&dev->bus->self->resource[n],
471 &dev->resource[i]); 445 &dev->resource[i]);
472 } 446 }
@@ -475,8 +449,8 @@ probe_interrupts:
475 for (i = 0; i < PROMINTR_MAX; i++) 449 for (i = 0; i < PROMINTR_MAX; i++)
476 dev->irqs[i] = PCI_IRQ_NONE; 450 dev->irqs[i] = PCI_IRQ_NONE;
477 451
478 len = prom_getproperty(node, "interrupts", (char *)&irqs, sizeof(irqs)); 452 irqs = of_get_property(dp, "interrupts", &len);
479 if ((len == -1) || (len == 0)) { 453 if (!irqs) {
480 dev->num_irqs = 0; 454 dev->num_irqs = 0;
481 } else { 455 } else {
482 dev->num_irqs = len / sizeof(irqs[0]); 456 dev->num_irqs = len / sizeof(irqs[0]);
@@ -497,7 +471,18 @@ probe_interrupts:
497 } 471 }
498 } 472 }
499 473
500 if ((node = prom_getchild(node))) { 474 dev->ofdev.node = dp;
475 dev->ofdev.dev.parent = &dev->bus->ofdev.dev;
476 dev->ofdev.dev.bus = &ebus_bus_type;
477 strcpy(dev->ofdev.dev.bus_id, dp->path_component_name);
478
479 /* Register with core */
480 if (of_device_register(&dev->ofdev) != 0)
481 printk(KERN_DEBUG "ebus: device registration error for %s!\n",
482 dev->ofdev.dev.bus_id);
483
484 dp = dp->child;
485 if (dp) {
501 printk(" ->"); 486 printk(" ->");
502 dev->children = ebus_alloc(sizeof(struct linux_ebus_child)); 487 dev->children = ebus_alloc(sizeof(struct linux_ebus_child));
503 488
@@ -505,18 +490,18 @@ probe_interrupts:
505 child->next = NULL; 490 child->next = NULL;
506 child->parent = dev; 491 child->parent = dev;
507 child->bus = dev->bus; 492 child->bus = dev->bus;
508 fill_ebus_child(node, &regs[0], 493 fill_ebus_child(dp, regs, child,
509 child, child_regs_nonstandard(dev)); 494 child_regs_nonstandard(dev));
510 495
511 while ((node = prom_getsibling(node)) != 0) { 496 while ((dp = dp->sibling) != NULL) {
512 child->next = ebus_alloc(sizeof(struct linux_ebus_child)); 497 child->next = ebus_alloc(sizeof(struct linux_ebus_child));
513 498
514 child = child->next; 499 child = child->next;
515 child->next = NULL; 500 child->next = NULL;
516 child->parent = dev; 501 child->parent = dev;
517 child->bus = dev->bus; 502 child->bus = dev->bus;
518 fill_ebus_child(node, &regs[0], 503 fill_ebus_child(dp, regs, child,
519 child, child_regs_nonstandard(dev)); 504 child_regs_nonstandard(dev));
520 } 505 }
521 } 506 }
522 printk("]"); 507 printk("]");
@@ -543,7 +528,8 @@ void __init ebus_init(void)
543 struct linux_ebus *ebus; 528 struct linux_ebus *ebus;
544 struct pci_dev *pdev; 529 struct pci_dev *pdev;
545 struct pcidev_cookie *cookie; 530 struct pcidev_cookie *cookie;
546 int nd, ebusnd, is_rio; 531 struct device_node *dp;
532 int is_rio;
547 int num_ebus = 0; 533 int num_ebus = 0;
548 534
549 pdev = find_next_ebus(NULL, &is_rio); 535 pdev = find_next_ebus(NULL, &is_rio);
@@ -553,20 +539,22 @@ void __init ebus_init(void)
553 } 539 }
554 540
555 cookie = pdev->sysdata; 541 cookie = pdev->sysdata;
556 ebusnd = cookie->prom_node; 542 dp = cookie->prom_node;
557 543
558 ebus_chain = ebus = ebus_alloc(sizeof(struct linux_ebus)); 544 ebus_chain = ebus = ebus_alloc(sizeof(struct linux_ebus));
559 ebus->next = NULL; 545 ebus->next = NULL;
560 ebus->is_rio = is_rio; 546 ebus->is_rio = is_rio;
561 547
562 while (ebusnd) { 548 while (dp) {
549 struct device_node *child;
550
563 /* SUNW,pci-qfe uses four empty ebuses on it. 551 /* SUNW,pci-qfe uses four empty ebuses on it.
564 I think we should not consider them here, 552 I think we should not consider them here,
565 as they have half of the properties this 553 as they have half of the properties this
566 code expects and once we do PCI hot-plug, 554 code expects and once we do PCI hot-plug,
567 we'd have to tweak with the ebus_chain 555 we'd have to tweak with the ebus_chain
568 in the runtime after initialization. -jj */ 556 in the runtime after initialization. -jj */
569 if (!prom_getchild (ebusnd)) { 557 if (!dp->child) {
570 pdev = find_next_ebus(pdev, &is_rio); 558 pdev = find_next_ebus(pdev, &is_rio);
571 if (!pdev) { 559 if (!pdev) {
572 if (ebus == ebus_chain) { 560 if (ebus == ebus_chain) {
@@ -578,22 +566,29 @@ void __init ebus_init(void)
578 } 566 }
579 ebus->is_rio = is_rio; 567 ebus->is_rio = is_rio;
580 cookie = pdev->sysdata; 568 cookie = pdev->sysdata;
581 ebusnd = cookie->prom_node; 569 dp = cookie->prom_node;
582 continue; 570 continue;
583 } 571 }
584 printk("ebus%d:", num_ebus); 572 printk("ebus%d:", num_ebus);
585 573
586 prom_getstring(ebusnd, "name", ebus->prom_name, sizeof(ebus->prom_name));
587 ebus->index = num_ebus; 574 ebus->index = num_ebus;
588 ebus->prom_node = ebusnd; 575 ebus->prom_node = dp;
589 ebus->self = pdev; 576 ebus->self = pdev;
590 ebus->parent = pbm = cookie->pbm; 577 ebus->parent = pbm = cookie->pbm;
591 578
592 ebus_ranges_init(ebus); 579 ebus->ofdev.node = dp;
593 ebus_intmap_init(ebus); 580 ebus->ofdev.dev.parent = &pdev->dev;
581 ebus->ofdev.dev.bus = &ebus_bus_type;
582 strcpy(ebus->ofdev.dev.bus_id, dp->path_component_name);
594 583
595 nd = prom_getchild(ebusnd); 584 /* Register with core */
596 if (!nd) 585 if (of_device_register(&ebus->ofdev) != 0)
586 printk(KERN_DEBUG "ebus: device registration error for %s!\n",
587 ebus->ofdev.dev.bus_id);
588
589
590 child = dp->child;
591 if (!child)
597 goto next_ebus; 592 goto next_ebus;
598 593
599 ebus->devices = ebus_alloc(sizeof(struct linux_ebus_device)); 594 ebus->devices = ebus_alloc(sizeof(struct linux_ebus_device));
@@ -602,16 +597,16 @@ void __init ebus_init(void)
602 dev->next = NULL; 597 dev->next = NULL;
603 dev->children = NULL; 598 dev->children = NULL;
604 dev->bus = ebus; 599 dev->bus = ebus;
605 fill_ebus_device(nd, dev); 600 fill_ebus_device(child, dev);
606 601
607 while ((nd = prom_getsibling(nd)) != 0) { 602 while ((child = child->sibling) != NULL) {
608 dev->next = ebus_alloc(sizeof(struct linux_ebus_device)); 603 dev->next = ebus_alloc(sizeof(struct linux_ebus_device));
609 604
610 dev = dev->next; 605 dev = dev->next;
611 dev->next = NULL; 606 dev->next = NULL;
612 dev->children = NULL; 607 dev->children = NULL;
613 dev->bus = ebus; 608 dev->bus = ebus;
614 fill_ebus_device(nd, dev); 609 fill_ebus_device(child, dev);
615 } 610 }
616 611
617 next_ebus: 612 next_ebus:
@@ -622,7 +617,7 @@ void __init ebus_init(void)
622 break; 617 break;
623 618
624 cookie = pdev->sysdata; 619 cookie = pdev->sysdata;
625 ebusnd = cookie->prom_node; 620 dp = cookie->prom_node;
626 621
627 ebus->next = ebus_alloc(sizeof(struct linux_ebus)); 622 ebus->next = ebus_alloc(sizeof(struct linux_ebus));
628 ebus = ebus->next; 623 ebus = ebus->next;
@@ -631,8 +626,4 @@ void __init ebus_init(void)
631 ++num_ebus; 626 ++num_ebus;
632 } 627 }
633 pci_dev_put(pdev); /* XXX for the case, when ebusnd is 0, is it OK? */ 628 pci_dev_put(pdev); /* XXX for the case, when ebusnd is 0, is it OK? */
634
635#ifdef CONFIG_SUN_AUXIO
636 auxio_probe();
637#endif
638} 629}
diff --git a/arch/sparc64/kernel/irq.c b/arch/sparc64/kernel/irq.c
index a8c9dc8d1958..31e0fbb0d82c 100644
--- a/arch/sparc64/kernel/irq.c
+++ b/arch/sparc64/kernel/irq.c
@@ -34,6 +34,7 @@
34#include <asm/iommu.h> 34#include <asm/iommu.h>
35#include <asm/upa.h> 35#include <asm/upa.h>
36#include <asm/oplib.h> 36#include <asm/oplib.h>
37#include <asm/prom.h>
37#include <asm/timer.h> 38#include <asm/timer.h>
38#include <asm/smp.h> 39#include <asm/smp.h>
39#include <asm/starfire.h> 40#include <asm/starfire.h>
@@ -635,23 +636,29 @@ static u64 prom_limit0, prom_limit1;
635 636
636static void map_prom_timers(void) 637static void map_prom_timers(void)
637{ 638{
638 unsigned int addr[3]; 639 struct device_node *dp;
639 int tnode, err; 640 unsigned int *addr;
640 641
641 /* PROM timer node hangs out in the top level of device siblings... */ 642 /* PROM timer node hangs out in the top level of device siblings... */
642 tnode = prom_finddevice("/counter-timer"); 643 dp = of_find_node_by_path("/");
644 dp = dp->child;
645 while (dp) {
646 if (!strcmp(dp->name, "counter-timer"))
647 break;
648 dp = dp->sibling;
649 }
643 650
644 /* Assume if node is not present, PROM uses different tick mechanism 651 /* Assume if node is not present, PROM uses different tick mechanism
645 * which we should not care about. 652 * which we should not care about.
646 */ 653 */
647 if (tnode == 0 || tnode == -1) { 654 if (!dp) {
648 prom_timers = (struct sun5_timer *) 0; 655 prom_timers = (struct sun5_timer *) 0;
649 return; 656 return;
650 } 657 }
651 658
652 /* If PROM is really using this, it must be mapped by him. */ 659 /* If PROM is really using this, it must be mapped by him. */
653 err = prom_getproperty(tnode, "address", (char *)addr, sizeof(addr)); 660 addr = of_get_property(dp, "address", NULL);
654 if (err == -1) { 661 if (!addr) {
655 prom_printf("PROM does not have timer mapped, trying to continue.\n"); 662 prom_printf("PROM does not have timer mapped, trying to continue.\n");
656 prom_timers = (struct sun5_timer *) 0; 663 prom_timers = (struct sun5_timer *) 0;
657 return; 664 return;
diff --git a/arch/sparc64/kernel/isa.c b/arch/sparc64/kernel/isa.c
index 30862abee611..6f16dee280a8 100644
--- a/arch/sparc64/kernel/isa.c
+++ b/arch/sparc64/kernel/isa.c
@@ -15,23 +15,19 @@ static void __init fatal_err(const char *reason)
15static void __init report_dev(struct sparc_isa_device *isa_dev, int child) 15static void __init report_dev(struct sparc_isa_device *isa_dev, int child)
16{ 16{
17 if (child) 17 if (child)
18 printk(" (%s)", isa_dev->prom_name); 18 printk(" (%s)", isa_dev->prom_node->name);
19 else 19 else
20 printk(" [%s", isa_dev->prom_name); 20 printk(" [%s", isa_dev->prom_node->name);
21} 21}
22 22
23static void __init isa_dev_get_resource(struct sparc_isa_device *isa_dev, 23static struct linux_prom_registers * __init
24 struct linux_prom_registers *pregs, 24isa_dev_get_resource(struct sparc_isa_device *isa_dev)
25 int pregs_size)
26{ 25{
26 struct linux_prom_registers *pregs;
27 unsigned long base, len; 27 unsigned long base, len;
28 int prop_len; 28 int prop_len;
29 29
30 prop_len = prom_getproperty(isa_dev->prom_node, "reg", 30 pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len);
31 (char *) pregs, pregs_size);
32
33 if (prop_len <= 0)
34 return;
35 31
36 /* Only the first one is interesting. */ 32 /* Only the first one is interesting. */
37 len = pregs[0].reg_size; 33 len = pregs[0].reg_size;
@@ -42,10 +38,12 @@ static void __init isa_dev_get_resource(struct sparc_isa_device *isa_dev,
42 isa_dev->resource.start = base; 38 isa_dev->resource.start = base;
43 isa_dev->resource.end = (base + len - 1UL); 39 isa_dev->resource.end = (base + len - 1UL);
44 isa_dev->resource.flags = IORESOURCE_IO; 40 isa_dev->resource.flags = IORESOURCE_IO;
45 isa_dev->resource.name = isa_dev->prom_name; 41 isa_dev->resource.name = isa_dev->prom_node->name;
46 42
47 request_resource(&isa_dev->bus->parent->io_space, 43 request_resource(&isa_dev->bus->parent->io_space,
48 &isa_dev->resource); 44 &isa_dev->resource);
45
46 return pregs;
49} 47}
50 48
51/* I can't believe they didn't put a real INO in the isa device 49/* I can't believe they didn't put a real INO in the isa device
@@ -74,19 +72,30 @@ static struct {
74static int __init isa_dev_get_irq_using_imap(struct sparc_isa_device *isa_dev, 72static int __init isa_dev_get_irq_using_imap(struct sparc_isa_device *isa_dev,
75 struct sparc_isa_bridge *isa_br, 73 struct sparc_isa_bridge *isa_br,
76 int *interrupt, 74 int *interrupt,
77 struct linux_prom_registers *pregs) 75 struct linux_prom_registers *reg)
78{ 76{
77 struct linux_prom_ebus_intmap *imap;
78 struct linux_prom_ebus_intmap *imask;
79 unsigned int hi, lo, irq; 79 unsigned int hi, lo, irq;
80 int i; 80 int i, len, n_imap;
81 81
82 hi = pregs->which_io & isa_br->isa_intmask.phys_hi; 82 imap = of_get_property(isa_br->prom_node, "interrupt-map", &len);
83 lo = pregs->phys_addr & isa_br->isa_intmask.phys_lo; 83 if (!imap)
84 irq = *interrupt & isa_br->isa_intmask.interrupt; 84 return 0;
85 for (i = 0; i < isa_br->num_isa_intmap; i++) { 85 n_imap = len / sizeof(imap[0]);
86 if ((isa_br->isa_intmap[i].phys_hi == hi) && 86
87 (isa_br->isa_intmap[i].phys_lo == lo) && 87 imask = of_get_property(isa_br->prom_node, "interrupt-map-mask", NULL);
88 (isa_br->isa_intmap[i].interrupt == irq)) { 88 if (!imask)
89 *interrupt = isa_br->isa_intmap[i].cinterrupt; 89 return 0;
90
91 hi = reg->which_io & imask->phys_hi;
92 lo = reg->phys_addr & imask->phys_lo;
93 irq = *interrupt & imask->interrupt;
94 for (i = 0; i < n_imap; i++) {
95 if ((imap[i].phys_hi == hi) &&
96 (imap[i].phys_lo == lo) &&
97 (imap[i].interrupt == irq)) {
98 *interrupt = imap[i].cinterrupt;
90 return 0; 99 return 0;
91 } 100 }
92 } 101 }
@@ -98,8 +107,8 @@ static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev,
98{ 107{
99 int irq_prop; 108 int irq_prop;
100 109
101 irq_prop = prom_getintdefault(isa_dev->prom_node, 110 irq_prop = of_getintprop_default(isa_dev->prom_node,
102 "interrupts", -1); 111 "interrupts", -1);
103 if (irq_prop <= 0) { 112 if (irq_prop <= 0) {
104 goto no_irq; 113 goto no_irq;
105 } else { 114 } else {
@@ -107,7 +116,8 @@ static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev,
107 struct pci_pbm_info *pbm; 116 struct pci_pbm_info *pbm;
108 int i; 117 int i;
109 118
110 if (isa_dev->bus->num_isa_intmap) { 119 if (of_find_property(isa_dev->bus->prom_node,
120 "interrupt-map", NULL)) {
111 if (!isa_dev_get_irq_using_imap(isa_dev, 121 if (!isa_dev_get_irq_using_imap(isa_dev,
112 isa_dev->bus, 122 isa_dev->bus,
113 &irq_prop, 123 &irq_prop,
@@ -141,16 +151,15 @@ no_irq:
141 151
142static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev) 152static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
143{ 153{
144 int node = prom_getchild(parent_isa_dev->prom_node); 154 struct device_node *dp = parent_isa_dev->prom_node->child;
145 155
146 if (node == 0) 156 if (!dp)
147 return; 157 return;
148 158
149 printk(" ->"); 159 printk(" ->");
150 while (node != 0) { 160 while (dp) {
151 struct linux_prom_registers regs[PROMREG_MAX]; 161 struct linux_prom_registers *regs;
152 struct sparc_isa_device *isa_dev; 162 struct sparc_isa_device *isa_dev;
153 int prop_len;
154 163
155 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL); 164 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
156 if (!isa_dev) { 165 if (!isa_dev) {
@@ -165,49 +174,46 @@ static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
165 parent_isa_dev->child = isa_dev; 174 parent_isa_dev->child = isa_dev;
166 175
167 isa_dev->bus = parent_isa_dev->bus; 176 isa_dev->bus = parent_isa_dev->bus;
168 isa_dev->prom_node = node; 177 isa_dev->prom_node = dp;
169 prop_len = prom_getproperty(node, "name",
170 (char *) isa_dev->prom_name,
171 sizeof(isa_dev->prom_name));
172 if (prop_len <= 0) {
173 fatal_err("cannot get child isa_dev OBP node name");
174 prom_halt();
175 }
176 178
177 prop_len = prom_getproperty(node, "compatible", 179 regs = isa_dev_get_resource(isa_dev);
178 (char *) isa_dev->compatible,
179 sizeof(isa_dev->compatible));
180
181 /* Not having this is OK. */
182 if (prop_len <= 0)
183 isa_dev->compatible[0] = '\0';
184
185 isa_dev_get_resource(isa_dev, regs, sizeof(regs));
186 isa_dev_get_irq(isa_dev, regs); 180 isa_dev_get_irq(isa_dev, regs);
187 181
188 report_dev(isa_dev, 1); 182 report_dev(isa_dev, 1);
189 183
190 node = prom_getsibling(node); 184 dp = dp->sibling;
191 } 185 }
192} 186}
193 187
194static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br) 188static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
195{ 189{
196 int node = prom_getchild(isa_br->prom_node); 190 struct device_node *dp = isa_br->prom_node->child;
197 191
198 while (node != 0) { 192 while (dp) {
199 struct linux_prom_registers regs[PROMREG_MAX]; 193 struct linux_prom_registers *regs;
200 struct sparc_isa_device *isa_dev; 194 struct sparc_isa_device *isa_dev;
201 int prop_len;
202 195
203 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL); 196 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
204 if (!isa_dev) { 197 if (!isa_dev) {
205 fatal_err("cannot allocate isa_dev"); 198 printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
206 prom_halt(); 199 return;
207 } 200 }
208 201
209 memset(isa_dev, 0, sizeof(*isa_dev)); 202 memset(isa_dev, 0, sizeof(*isa_dev));
210 203
204 isa_dev->ofdev.node = dp;
205 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
206 isa_dev->ofdev.dev.bus = &isa_bus_type;
207 strcpy(isa_dev->ofdev.dev.bus_id, dp->path_component_name);
208
209 /* Register with core */
210 if (of_device_register(&isa_dev->ofdev) != 0) {
211 printk(KERN_DEBUG "isa: device registration error for %s!\n",
212 isa_dev->ofdev.dev.bus_id);
213 kfree(isa_dev);
214 goto next_sibling;
215 }
216
211 /* Link it in. */ 217 /* Link it in. */
212 isa_dev->next = NULL; 218 isa_dev->next = NULL;
213 if (isa_br->devices == NULL) { 219 if (isa_br->devices == NULL) {
@@ -222,24 +228,9 @@ static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
222 } 228 }
223 229
224 isa_dev->bus = isa_br; 230 isa_dev->bus = isa_br;
225 isa_dev->prom_node = node; 231 isa_dev->prom_node = dp;
226 prop_len = prom_getproperty(node, "name",
227 (char *) isa_dev->prom_name,
228 sizeof(isa_dev->prom_name));
229 if (prop_len <= 0) {
230 fatal_err("cannot get isa_dev OBP node name");
231 prom_halt();
232 }
233
234 prop_len = prom_getproperty(node, "compatible",
235 (char *) isa_dev->compatible,
236 sizeof(isa_dev->compatible));
237 232
238 /* Not having this is OK. */ 233 regs = isa_dev_get_resource(isa_dev);
239 if (prop_len <= 0)
240 isa_dev->compatible[0] = '\0';
241
242 isa_dev_get_resource(isa_dev, regs, sizeof(regs));
243 isa_dev_get_irq(isa_dev, regs); 234 isa_dev_get_irq(isa_dev, regs);
244 235
245 report_dev(isa_dev, 0); 236 report_dev(isa_dev, 0);
@@ -248,7 +239,8 @@ static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
248 239
249 printk("]"); 240 printk("]");
250 241
251 node = prom_getsibling(node); 242 next_sibling:
243 dp = dp->sibling;
252 } 244 }
253} 245}
254 246
@@ -266,7 +258,7 @@ void __init isa_init(void)
266 struct pcidev_cookie *pdev_cookie; 258 struct pcidev_cookie *pdev_cookie;
267 struct pci_pbm_info *pbm; 259 struct pci_pbm_info *pbm;
268 struct sparc_isa_bridge *isa_br; 260 struct sparc_isa_bridge *isa_br;
269 int prop_len; 261 struct device_node *dp;
270 262
271 pdev_cookie = pdev->sysdata; 263 pdev_cookie = pdev->sysdata;
272 if (!pdev_cookie) { 264 if (!pdev_cookie) {
@@ -275,15 +267,29 @@ void __init isa_init(void)
275 continue; 267 continue;
276 } 268 }
277 pbm = pdev_cookie->pbm; 269 pbm = pdev_cookie->pbm;
270 dp = pdev_cookie->prom_node;
278 271
279 isa_br = kmalloc(sizeof(*isa_br), GFP_KERNEL); 272 isa_br = kmalloc(sizeof(*isa_br), GFP_KERNEL);
280 if (!isa_br) { 273 if (!isa_br) {
281 fatal_err("cannot allocate sparc_isa_bridge"); 274 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
282 prom_halt(); 275 return;
283 } 276 }
284 277
285 memset(isa_br, 0, sizeof(*isa_br)); 278 memset(isa_br, 0, sizeof(*isa_br));
286 279
280 isa_br->ofdev.node = dp;
281 isa_br->ofdev.dev.parent = &pdev->dev;
282 isa_br->ofdev.dev.bus = &isa_bus_type;
283 strcpy(isa_br->ofdev.dev.bus_id, dp->path_component_name);
284
285 /* Register with core */
286 if (of_device_register(&isa_br->ofdev) != 0) {
287 printk(KERN_DEBUG "isa: device registration error for %s!\n",
288 isa_br->ofdev.dev.bus_id);
289 kfree(isa_br);
290 return;
291 }
292
287 /* Link it in. */ 293 /* Link it in. */
288 isa_br->next = isa_chain; 294 isa_br->next = isa_chain;
289 isa_chain = isa_br; 295 isa_chain = isa_br;
@@ -292,33 +298,6 @@ void __init isa_init(void)
292 isa_br->self = pdev; 298 isa_br->self = pdev;
293 isa_br->index = index++; 299 isa_br->index = index++;
294 isa_br->prom_node = pdev_cookie->prom_node; 300 isa_br->prom_node = pdev_cookie->prom_node;
295 strncpy(isa_br->prom_name, pdev_cookie->prom_name,
296 sizeof(isa_br->prom_name));
297
298 prop_len = prom_getproperty(isa_br->prom_node,
299 "ranges",
300 (char *) isa_br->isa_ranges,
301 sizeof(isa_br->isa_ranges));
302 if (prop_len <= 0)
303 isa_br->num_isa_ranges = 0;
304 else
305 isa_br->num_isa_ranges =
306 (prop_len / sizeof(struct linux_prom_isa_ranges));
307
308 prop_len = prom_getproperty(isa_br->prom_node,
309 "interrupt-map",
310 (char *) isa_br->isa_intmap,
311 sizeof(isa_br->isa_intmap));
312 if (prop_len <= 0)
313 isa_br->num_isa_intmap = 0;
314 else
315 isa_br->num_isa_intmap =
316 (prop_len / sizeof(struct linux_prom_isa_intmap));
317
318 prop_len = prom_getproperty(isa_br->prom_node,
319 "interrupt-map-mask",
320 (char *) &(isa_br->isa_intmask),
321 sizeof(isa_br->isa_intmask));
322 301
323 printk("isa%d:", isa_br->index); 302 printk("isa%d:", isa_br->index);
324 303
diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c
new file mode 100644
index 000000000000..566aa343aa62
--- /dev/null
+++ b/arch/sparc64/kernel/of_device.c
@@ -0,0 +1,279 @@
1#include <linux/config.h>
2#include <linux/string.h>
3#include <linux/kernel.h>
4#include <linux/init.h>
5#include <linux/module.h>
6#include <linux/mod_devicetable.h>
7#include <linux/slab.h>
8
9#include <asm/errno.h>
10#include <asm/of_device.h>
11
12/**
13 * of_match_device - Tell if an of_device structure has a matching
14 * of_match structure
15 * @ids: array of of device match structures to search in
16 * @dev: the of device structure to match against
17 *
18 * Used by a driver to check whether an of_device present in the
19 * system is in its list of supported devices.
20 */
21const struct of_device_id *of_match_device(const struct of_device_id *matches,
22 const struct of_device *dev)
23{
24 if (!dev->node)
25 return NULL;
26 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
27 int match = 1;
28 if (matches->name[0])
29 match &= dev->node->name
30 && !strcmp(matches->name, dev->node->name);
31 if (matches->type[0])
32 match &= dev->node->type
33 && !strcmp(matches->type, dev->node->type);
34 if (matches->compatible[0])
35 match &= of_device_is_compatible(dev->node,
36 matches->compatible);
37 if (match)
38 return matches;
39 matches++;
40 }
41 return NULL;
42}
43
44static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
45{
46 struct of_device * of_dev = to_of_device(dev);
47 struct of_platform_driver * of_drv = to_of_platform_driver(drv);
48 const struct of_device_id * matches = of_drv->match_table;
49
50 if (!matches)
51 return 0;
52
53 return of_match_device(matches, of_dev) != NULL;
54}
55
56struct of_device *of_dev_get(struct of_device *dev)
57{
58 struct device *tmp;
59
60 if (!dev)
61 return NULL;
62 tmp = get_device(&dev->dev);
63 if (tmp)
64 return to_of_device(tmp);
65 else
66 return NULL;
67}
68
69void of_dev_put(struct of_device *dev)
70{
71 if (dev)
72 put_device(&dev->dev);
73}
74
75
76static int of_device_probe(struct device *dev)
77{
78 int error = -ENODEV;
79 struct of_platform_driver *drv;
80 struct of_device *of_dev;
81 const struct of_device_id *match;
82
83 drv = to_of_platform_driver(dev->driver);
84 of_dev = to_of_device(dev);
85
86 if (!drv->probe)
87 return error;
88
89 of_dev_get(of_dev);
90
91 match = of_match_device(drv->match_table, of_dev);
92 if (match)
93 error = drv->probe(of_dev, match);
94 if (error)
95 of_dev_put(of_dev);
96
97 return error;
98}
99
100static int of_device_remove(struct device *dev)
101{
102 struct of_device * of_dev = to_of_device(dev);
103 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
104
105 if (dev->driver && drv->remove)
106 drv->remove(of_dev);
107 return 0;
108}
109
110static int of_device_suspend(struct device *dev, pm_message_t state)
111{
112 struct of_device * of_dev = to_of_device(dev);
113 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
114 int error = 0;
115
116 if (dev->driver && drv->suspend)
117 error = drv->suspend(of_dev, state);
118 return error;
119}
120
121static int of_device_resume(struct device * dev)
122{
123 struct of_device * of_dev = to_of_device(dev);
124 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
125 int error = 0;
126
127 if (dev->driver && drv->resume)
128 error = drv->resume(of_dev);
129 return error;
130}
131
132#ifdef CONFIG_PCI
133struct bus_type isa_bus_type = {
134 .name = "isa",
135 .match = of_platform_bus_match,
136 .probe = of_device_probe,
137 .remove = of_device_remove,
138 .suspend = of_device_suspend,
139 .resume = of_device_resume,
140};
141
142struct bus_type ebus_bus_type = {
143 .name = "ebus",
144 .match = of_platform_bus_match,
145 .probe = of_device_probe,
146 .remove = of_device_remove,
147 .suspend = of_device_suspend,
148 .resume = of_device_resume,
149};
150#endif
151
152#ifdef CONFIG_SBUS
153struct bus_type sbus_bus_type = {
154 .name = "sbus",
155 .match = of_platform_bus_match,
156 .probe = of_device_probe,
157 .remove = of_device_remove,
158 .suspend = of_device_suspend,
159 .resume = of_device_resume,
160};
161#endif
162
163static int __init of_bus_driver_init(void)
164{
165 int err = 0;
166
167#ifdef CONFIG_PCI
168 if (!err)
169 err = bus_register(&isa_bus_type);
170 if (!err)
171 err = bus_register(&ebus_bus_type);
172#endif
173#ifdef CONFIG_SBUS
174 if (!err)
175 err = bus_register(&sbus_bus_type);
176#endif
177 return 0;
178}
179
180postcore_initcall(of_bus_driver_init);
181
182int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus)
183{
184 /* initialize common driver fields */
185 drv->driver.name = drv->name;
186 drv->driver.bus = bus;
187
188 /* register with core */
189 return driver_register(&drv->driver);
190}
191
192void of_unregister_driver(struct of_platform_driver *drv)
193{
194 driver_unregister(&drv->driver);
195}
196
197
198static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf)
199{
200 struct of_device *ofdev;
201
202 ofdev = to_of_device(dev);
203 return sprintf(buf, "%s", ofdev->node->full_name);
204}
205
206static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
207
208/**
209 * of_release_dev - free an of device structure when all users of it are finished.
210 * @dev: device that's been disconnected
211 *
212 * Will be called only by the device core when all users of this of device are
213 * done.
214 */
215void of_release_dev(struct device *dev)
216{
217 struct of_device *ofdev;
218
219 ofdev = to_of_device(dev);
220
221 kfree(ofdev);
222}
223
224int of_device_register(struct of_device *ofdev)
225{
226 int rc;
227
228 BUG_ON(ofdev->node == NULL);
229
230 rc = device_register(&ofdev->dev);
231 if (rc)
232 return rc;
233
234 device_create_file(&ofdev->dev, &dev_attr_devspec);
235
236 return 0;
237}
238
239void of_device_unregister(struct of_device *ofdev)
240{
241 device_remove_file(&ofdev->dev, &dev_attr_devspec);
242 device_unregister(&ofdev->dev);
243}
244
245struct of_device* of_platform_device_create(struct device_node *np,
246 const char *bus_id,
247 struct device *parent,
248 struct bus_type *bus)
249{
250 struct of_device *dev;
251
252 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
253 if (!dev)
254 return NULL;
255 memset(dev, 0, sizeof(*dev));
256
257 dev->dev.parent = parent;
258 dev->dev.bus = bus;
259 dev->dev.release = of_release_dev;
260
261 strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE);
262
263 if (of_device_register(dev) != 0) {
264 kfree(dev);
265 return NULL;
266 }
267
268 return dev;
269}
270
271EXPORT_SYMBOL(of_match_device);
272EXPORT_SYMBOL(of_register_driver);
273EXPORT_SYMBOL(of_unregister_driver);
274EXPORT_SYMBOL(of_device_register);
275EXPORT_SYMBOL(of_device_unregister);
276EXPORT_SYMBOL(of_dev_get);
277EXPORT_SYMBOL(of_dev_put);
278EXPORT_SYMBOL(of_platform_device_create);
279EXPORT_SYMBOL(of_release_dev);
diff --git a/arch/sparc64/kernel/pci.c b/arch/sparc64/kernel/pci.c
index 9472580a4319..6c9e3e94abaa 100644
--- a/arch/sparc64/kernel/pci.c
+++ b/arch/sparc64/kernel/pci.c
@@ -22,6 +22,7 @@
22#include <asm/irq.h> 22#include <asm/irq.h>
23#include <asm/ebus.h> 23#include <asm/ebus.h>
24#include <asm/isa.h> 24#include <asm/isa.h>
25#include <asm/prom.h>
25 26
26unsigned long pci_memspace_mask = 0xffffffffUL; 27unsigned long pci_memspace_mask = 0xffffffffUL;
27 28
@@ -177,16 +178,16 @@ void pci_config_write32(u32 *addr, u32 val)
177} 178}
178 179
179/* Probe for all PCI controllers in the system. */ 180/* Probe for all PCI controllers in the system. */
180extern void sabre_init(int, char *); 181extern void sabre_init(struct device_node *, const char *);
181extern void psycho_init(int, char *); 182extern void psycho_init(struct device_node *, const char *);
182extern void schizo_init(int, char *); 183extern void schizo_init(struct device_node *, const char *);
183extern void schizo_plus_init(int, char *); 184extern void schizo_plus_init(struct device_node *, const char *);
184extern void tomatillo_init(int, char *); 185extern void tomatillo_init(struct device_node *, const char *);
185extern void sun4v_pci_init(int, char *); 186extern void sun4v_pci_init(struct device_node *, const char *);
186 187
187static struct { 188static struct {
188 char *model_name; 189 char *model_name;
189 void (*init)(int, char *); 190 void (*init)(struct device_node *, const char *);
190} pci_controller_table[] __initdata = { 191} pci_controller_table[] __initdata = {
191 { "SUNW,sabre", sabre_init }, 192 { "SUNW,sabre", sabre_init },
192 { "pci108e,a000", sabre_init }, 193 { "pci108e,a000", sabre_init },
@@ -204,7 +205,7 @@ static struct {
204#define PCI_NUM_CONTROLLER_TYPES (sizeof(pci_controller_table) / \ 205#define PCI_NUM_CONTROLLER_TYPES (sizeof(pci_controller_table) / \
205 sizeof(pci_controller_table[0])) 206 sizeof(pci_controller_table[0]))
206 207
207static int __init pci_controller_init(char *model_name, int namelen, int node) 208static int __init pci_controller_init(const char *model_name, int namelen, struct device_node *dp)
208{ 209{
209 int i; 210 int i;
210 211
@@ -212,18 +213,15 @@ static int __init pci_controller_init(char *model_name, int namelen, int node)
212 if (!strncmp(model_name, 213 if (!strncmp(model_name,
213 pci_controller_table[i].model_name, 214 pci_controller_table[i].model_name,
214 namelen)) { 215 namelen)) {
215 pci_controller_table[i].init(node, model_name); 216 pci_controller_table[i].init(dp, model_name);
216 return 1; 217 return 1;
217 } 218 }
218 } 219 }
219 printk("PCI: Warning unknown controller, model name [%s]\n",
220 model_name);
221 printk("PCI: Ignoring controller...\n");
222 220
223 return 0; 221 return 0;
224} 222}
225 223
226static int __init pci_is_controller(char *model_name, int namelen, int node) 224static int __init pci_is_controller(const char *model_name, int namelen, struct device_node *dp)
227{ 225{
228 int i; 226 int i;
229 227
@@ -237,36 +235,35 @@ static int __init pci_is_controller(char *model_name, int namelen, int node)
237 return 0; 235 return 0;
238} 236}
239 237
240static int __init pci_controller_scan(int (*handler)(char *, int, int)) 238static int __init pci_controller_scan(int (*handler)(const char *, int, struct device_node *))
241{ 239{
242 char namebuf[64]; 240 struct device_node *dp;
243 int node;
244 int count = 0; 241 int count = 0;
245 242
246 node = prom_getchild(prom_root_node); 243 for_each_node_by_name(dp, "pci") {
247 while ((node = prom_searchsiblings(node, "pci")) != 0) { 244 struct property *prop;
248 int len; 245 int len;
249 246
250 if ((len = prom_getproperty(node, "model", namebuf, sizeof(namebuf))) > 0 || 247 prop = of_find_property(dp, "model", &len);
251 (len = prom_getproperty(node, "compatible", namebuf, sizeof(namebuf))) > 0) { 248 if (!prop)
249 prop = of_find_property(dp, "compatible", &len);
250
251 if (prop) {
252 const char *model = prop->value;
252 int item_len = 0; 253 int item_len = 0;
253 254
254 /* Our value may be a multi-valued string in the 255 /* Our value may be a multi-valued string in the
255 * case of some compatible properties. For sanity, 256 * case of some compatible properties. For sanity,
256 * only try the first one. */ 257 * only try the first one.
257 258 */
258 while (namebuf[item_len] && len) { 259 while (model[item_len] && len) {
259 len--; 260 len--;
260 item_len++; 261 item_len++;
261 } 262 }
262 263
263 if (handler(namebuf, item_len, node)) 264 if (handler(model, item_len, dp))
264 count++; 265 count++;
265 } 266 }
266
267 node = prom_getsibling(node);
268 if (!node)
269 break;
270 } 267 }
271 268
272 return count; 269 return count;
@@ -409,8 +406,14 @@ void pcibios_bus_to_resource(struct pci_dev *pdev, struct resource *res,
409} 406}
410EXPORT_SYMBOL(pcibios_bus_to_resource); 407EXPORT_SYMBOL(pcibios_bus_to_resource);
411 408
409extern int pci_irq_verbose;
410
412char * __init pcibios_setup(char *str) 411char * __init pcibios_setup(char *str)
413{ 412{
413 if (!strcmp(str, "irq_verbose")) {
414 pci_irq_verbose = 1;
415 return NULL;
416 }
414 return str; 417 return str;
415} 418}
416 419
diff --git a/arch/sparc64/kernel/pci_common.c b/arch/sparc64/kernel/pci_common.c
index 33dedb1aacd4..b06a2955bf5f 100644
--- a/arch/sparc64/kernel/pci_common.c
+++ b/arch/sparc64/kernel/pci_common.c
@@ -9,6 +9,12 @@
9#include <linux/init.h> 9#include <linux/init.h>
10 10
11#include <asm/pbm.h> 11#include <asm/pbm.h>
12#include <asm/prom.h>
13
14#include "pci_impl.h"
15
16/* Pass "pci=irq_verbose" on the kernel command line to enable this. */
17int pci_irq_verbose;
12 18
13/* Fix self device of BUS and hook it into BUS->self. 19/* Fix self device of BUS and hook it into BUS->self.
14 * The pci_scan_bus does not do this for the host bridge. 20 * The pci_scan_bus does not do this for the host bridge.
@@ -28,16 +34,14 @@ void __init pci_fixup_host_bridge_self(struct pci_bus *pbus)
28 prom_halt(); 34 prom_halt();
29} 35}
30 36
31/* Find the OBP PROM device tree node for a PCI device. 37/* Find the OBP PROM device tree node for a PCI device. */
32 * Return zero if not found. 38static struct device_node * __init
33 */ 39find_device_prom_node(struct pci_pbm_info *pbm, struct pci_dev *pdev,
34static int __init find_device_prom_node(struct pci_pbm_info *pbm, 40 struct device_node *bus_node,
35 struct pci_dev *pdev, 41 struct linux_prom_pci_registers **pregs,
36 int bus_prom_node, 42 int *nregs)
37 struct linux_prom_pci_registers *pregs,
38 int *nregs)
39{ 43{
40 int node; 44 struct device_node *dp;
41 45
42 *nregs = 0; 46 *nregs = 0;
43 47
@@ -54,24 +58,30 @@ static int __init find_device_prom_node(struct pci_pbm_info *pbm,
54 pdev->device == PCI_DEVICE_ID_SUN_TOMATILLO || 58 pdev->device == PCI_DEVICE_ID_SUN_TOMATILLO ||
55 pdev->device == PCI_DEVICE_ID_SUN_SABRE || 59 pdev->device == PCI_DEVICE_ID_SUN_SABRE ||
56 pdev->device == PCI_DEVICE_ID_SUN_HUMMINGBIRD)) 60 pdev->device == PCI_DEVICE_ID_SUN_HUMMINGBIRD))
57 return bus_prom_node; 61 return bus_node;
58 62
59 node = prom_getchild(bus_prom_node); 63 dp = bus_node->child;
60 while (node != 0) { 64 while (dp) {
61 int err = prom_getproperty(node, "reg", 65 struct linux_prom_pci_registers *regs;
62 (char *)pregs, 66 struct property *prop;
63 sizeof(*pregs) * PROMREG_MAX); 67 int len;
64 if (err == 0 || err == -1) 68
69 prop = of_find_property(dp, "reg", &len);
70 if (!prop)
65 goto do_next_sibling; 71 goto do_next_sibling;
66 if (((pregs[0].phys_hi >> 8) & 0xff) == pdev->devfn) { 72
67 *nregs = err / sizeof(*pregs); 73 regs = prop->value;
68 return node; 74 if (((regs[0].phys_hi >> 8) & 0xff) == pdev->devfn) {
75 *pregs = regs;
76 *nregs = len / sizeof(struct linux_prom_pci_registers);
77 return dp;
69 } 78 }
70 79
71 do_next_sibling: 80 do_next_sibling:
72 node = prom_getsibling(node); 81 dp = dp->sibling;
73 } 82 }
74 return 0; 83
84 return NULL;
75} 85}
76 86
77/* Older versions of OBP on PCI systems encode 64-bit MEM 87/* Older versions of OBP on PCI systems encode 64-bit MEM
@@ -128,15 +138,17 @@ static void __init fixup_obp_assignments(struct pci_dev *pdev,
128 */ 138 */
129static void __init pdev_cookie_fillin(struct pci_pbm_info *pbm, 139static void __init pdev_cookie_fillin(struct pci_pbm_info *pbm,
130 struct pci_dev *pdev, 140 struct pci_dev *pdev,
131 int bus_prom_node) 141 struct device_node *bus_node)
132{ 142{
133 struct linux_prom_pci_registers pregs[PROMREG_MAX]; 143 struct linux_prom_pci_registers *pregs = NULL;
134 struct pcidev_cookie *pcp; 144 struct pcidev_cookie *pcp;
135 int device_prom_node, nregs, err; 145 struct device_node *dp;
146 struct property *prop;
147 int nregs, len;
136 148
137 device_prom_node = find_device_prom_node(pbm, pdev, bus_prom_node, 149 dp = find_device_prom_node(pbm, pdev, bus_node,
138 pregs, &nregs); 150 &pregs, &nregs);
139 if (device_prom_node == 0) { 151 if (!dp) {
140 /* If it is not in the OBP device tree then 152 /* If it is not in the OBP device tree then
141 * there must be a damn good reason for it. 153 * there must be a damn good reason for it.
142 * 154 *
@@ -150,45 +162,43 @@ static void __init pdev_cookie_fillin(struct pci_pbm_info *pbm,
150 return; 162 return;
151 } 163 }
152 164
153 pcp = kmalloc(sizeof(*pcp), GFP_ATOMIC); 165 pcp = kzalloc(sizeof(*pcp), GFP_ATOMIC);
154 if (pcp == NULL) { 166 if (pcp == NULL) {
155 prom_printf("PCI_COOKIE: Fatal malloc error, aborting...\n"); 167 prom_printf("PCI_COOKIE: Fatal malloc error, aborting...\n");
156 prom_halt(); 168 prom_halt();
157 } 169 }
158 pcp->pbm = pbm; 170 pcp->pbm = pbm;
159 pcp->prom_node = device_prom_node; 171 pcp->prom_node = dp;
160 memcpy(pcp->prom_regs, pregs, sizeof(pcp->prom_regs)); 172 memcpy(pcp->prom_regs, pregs,
173 nregs * sizeof(struct linux_prom_pci_registers));
161 pcp->num_prom_regs = nregs; 174 pcp->num_prom_regs = nregs;
162 err = prom_getproperty(device_prom_node, "name", 175
163 pcp->prom_name, sizeof(pcp->prom_name)); 176 /* We can't have the pcidev_cookie assignments be just
164 if (err > 0) 177 * direct pointers into the property value, since they
165 pcp->prom_name[err] = 0; 178 * are potentially modified by the probing process.
166 else 179 */
167 pcp->prom_name[0] = 0; 180 prop = of_find_property(dp, "assigned-addresses", &len);
168 181 if (!prop) {
169 err = prom_getproperty(device_prom_node,
170 "assigned-addresses",
171 (char *)pcp->prom_assignments,
172 sizeof(pcp->prom_assignments));
173 if (err == 0 || err == -1)
174 pcp->num_prom_assignments = 0; 182 pcp->num_prom_assignments = 0;
175 else 183 } else {
184 memcpy(pcp->prom_assignments, prop->value, len);
176 pcp->num_prom_assignments = 185 pcp->num_prom_assignments =
177 (err / sizeof(pcp->prom_assignments[0])); 186 (len / sizeof(pcp->prom_assignments[0]));
187 }
178 188
179 if (strcmp(pcp->prom_name, "ebus") == 0) { 189 if (strcmp(dp->name, "ebus") == 0) {
180 struct linux_prom_ebus_ranges erng[PROM_PCIRNG_MAX]; 190 struct linux_prom_ebus_ranges *erng;
181 int iter; 191 int iter;
182 192
183 /* EBUS is special... */ 193 /* EBUS is special... */
184 err = prom_getproperty(device_prom_node, "ranges", 194 prop = of_find_property(dp, "ranges", &len);
185 (char *)&erng[0], sizeof(erng)); 195 if (!prop) {
186 if (err == 0 || err == -1) {
187 prom_printf("EBUS: Fatal error, no range property\n"); 196 prom_printf("EBUS: Fatal error, no range property\n");
188 prom_halt(); 197 prom_halt();
189 } 198 }
190 err = (err / sizeof(erng[0])); 199 erng = prop->value;
191 for(iter = 0; iter < err; iter++) { 200 len = (len / sizeof(erng[0]));
201 for (iter = 0; iter < len; iter++) {
192 struct linux_prom_ebus_ranges *ep = &erng[iter]; 202 struct linux_prom_ebus_ranges *ep = &erng[iter];
193 struct linux_prom_pci_registers *ap; 203 struct linux_prom_pci_registers *ap;
194 204
@@ -200,7 +210,7 @@ static void __init pdev_cookie_fillin(struct pci_pbm_info *pbm,
200 ap->size_hi = 0; 210 ap->size_hi = 0;
201 ap->size_lo = ep->size; 211 ap->size_lo = ep->size;
202 } 212 }
203 pcp->num_prom_assignments = err; 213 pcp->num_prom_assignments = len;
204 } 214 }
205 215
206 fixup_obp_assignments(pdev, pcp); 216 fixup_obp_assignments(pdev, pcp);
@@ -210,7 +220,7 @@ static void __init pdev_cookie_fillin(struct pci_pbm_info *pbm,
210 220
211void __init pci_fill_in_pbm_cookies(struct pci_bus *pbus, 221void __init pci_fill_in_pbm_cookies(struct pci_bus *pbus,
212 struct pci_pbm_info *pbm, 222 struct pci_pbm_info *pbm,
213 int prom_node) 223 struct device_node *dp)
214{ 224{
215 struct pci_dev *pdev, *pdev_next; 225 struct pci_dev *pdev, *pdev_next;
216 struct pci_bus *this_pbus, *pbus_next; 226 struct pci_bus *this_pbus, *pbus_next;
@@ -218,7 +228,7 @@ void __init pci_fill_in_pbm_cookies(struct pci_bus *pbus,
218 /* This must be _safe because the cookie fillin 228 /* This must be _safe because the cookie fillin
219 routine can delete devices from the tree. */ 229 routine can delete devices from the tree. */
220 list_for_each_entry_safe(pdev, pdev_next, &pbus->devices, bus_list) 230 list_for_each_entry_safe(pdev, pdev_next, &pbus->devices, bus_list)
221 pdev_cookie_fillin(pbm, pdev, prom_node); 231 pdev_cookie_fillin(pbm, pdev, dp);
222 232
223 list_for_each_entry_safe(this_pbus, pbus_next, &pbus->children, node) { 233 list_for_each_entry_safe(this_pbus, pbus_next, &pbus->children, node) {
224 struct pcidev_cookie *pcp = this_pbus->self->sysdata; 234 struct pcidev_cookie *pcp = this_pbus->self->sysdata;
@@ -241,7 +251,6 @@ static void __init bad_assignment(struct pci_dev *pdev,
241 if (res) 251 if (res)
242 prom_printf("PCI: RES[%016lx-->%016lx:(%lx)]\n", 252 prom_printf("PCI: RES[%016lx-->%016lx:(%lx)]\n",
243 res->start, res->end, res->flags); 253 res->start, res->end, res->flags);
244 prom_printf("Please email this information to davem@redhat.com\n");
245 if (do_prom_halt) 254 if (do_prom_halt)
246 prom_halt(); 255 prom_halt();
247} 256}
@@ -273,8 +282,7 @@ __init get_root_resource(struct linux_prom_pci_registers *ap,
273 return &pbm->mem_space; 282 return &pbm->mem_space;
274 283
275 default: 284 default:
276 printk("PCI: What is resource space %x? " 285 printk("PCI: What is resource space %x?\n", space);
277 "Tell davem@redhat.com about it!\n", space);
278 return NULL; 286 return NULL;
279 }; 287 };
280} 288}
@@ -556,9 +564,10 @@ static inline unsigned int pci_slot_swivel(struct pci_pbm_info *pbm,
556 564
557 ret = ((interrupt - 1 + (PCI_SLOT(pdev->devfn) & 3)) & 3) + 1; 565 ret = ((interrupt - 1 + (PCI_SLOT(pdev->devfn) & 3)) & 3) + 1;
558 566
559 printk("%s: %s IRQ Swivel %s [%x:%x] -> [%x]\n", 567 if (pci_irq_verbose)
560 pbm->name, pci_name(toplevel_pdev), pci_name(pdev), 568 printk("%s: %s IRQ Swivel %s [%x:%x] -> [%x]\n",
561 interrupt, PCI_SLOT(pdev->devfn), ret); 569 pbm->name, pci_name(toplevel_pdev), pci_name(pdev),
570 interrupt, PCI_SLOT(pdev->devfn), ret);
562 571
563 return ret; 572 return ret;
564} 573}
@@ -568,58 +577,60 @@ static inline unsigned int pci_apply_intmap(struct pci_pbm_info *pbm,
568 struct pci_dev *pbus, 577 struct pci_dev *pbus,
569 struct pci_dev *pdev, 578 struct pci_dev *pdev,
570 unsigned int interrupt, 579 unsigned int interrupt,
571 unsigned int *cnode) 580 struct device_node **cnode)
572{ 581{
573 struct linux_prom_pci_intmap imap[PROM_PCIIMAP_MAX]; 582 struct linux_prom_pci_intmap *imap;
574 struct linux_prom_pci_intmask imask; 583 struct linux_prom_pci_intmask *imask;
575 struct pcidev_cookie *pbus_pcp = pbus->sysdata; 584 struct pcidev_cookie *pbus_pcp = pbus->sysdata;
576 struct pcidev_cookie *pdev_pcp = pdev->sysdata; 585 struct pcidev_cookie *pdev_pcp = pdev->sysdata;
577 struct linux_prom_pci_registers *pregs = pdev_pcp->prom_regs; 586 struct linux_prom_pci_registers *pregs = pdev_pcp->prom_regs;
587 struct property *prop;
578 int plen, num_imap, i; 588 int plen, num_imap, i;
579 unsigned int hi, mid, lo, irq, orig_interrupt; 589 unsigned int hi, mid, lo, irq, orig_interrupt;
580 590
581 *cnode = pbus_pcp->prom_node; 591 *cnode = pbus_pcp->prom_node;
582 592
583 plen = prom_getproperty(pbus_pcp->prom_node, "interrupt-map", 593 prop = of_find_property(pbus_pcp->prom_node, "interrupt-map", &plen);
584 (char *) &imap[0], sizeof(imap)); 594 if (!prop ||
585 if (plen <= 0 ||
586 (plen % sizeof(struct linux_prom_pci_intmap)) != 0) { 595 (plen % sizeof(struct linux_prom_pci_intmap)) != 0) {
587 printk("%s: Device %s interrupt-map has bad len %d\n", 596 printk("%s: Device %s interrupt-map has bad len %d\n",
588 pbm->name, pci_name(pbus), plen); 597 pbm->name, pci_name(pbus), plen);
589 goto no_intmap; 598 goto no_intmap;
590 } 599 }
600 imap = prop->value;
591 num_imap = plen / sizeof(struct linux_prom_pci_intmap); 601 num_imap = plen / sizeof(struct linux_prom_pci_intmap);
592 602
593 plen = prom_getproperty(pbus_pcp->prom_node, "interrupt-map-mask", 603 prop = of_find_property(pbus_pcp->prom_node, "interrupt-map-mask", &plen);
594 (char *) &imask, sizeof(imask)); 604 if (!prop ||
595 if (plen <= 0 ||
596 (plen % sizeof(struct linux_prom_pci_intmask)) != 0) { 605 (plen % sizeof(struct linux_prom_pci_intmask)) != 0) {
597 printk("%s: Device %s interrupt-map-mask has bad len %d\n", 606 printk("%s: Device %s interrupt-map-mask has bad len %d\n",
598 pbm->name, pci_name(pbus), plen); 607 pbm->name, pci_name(pbus), plen);
599 goto no_intmap; 608 goto no_intmap;
600 } 609 }
610 imask = prop->value;
601 611
602 orig_interrupt = interrupt; 612 orig_interrupt = interrupt;
603 613
604 hi = pregs->phys_hi & imask.phys_hi; 614 hi = pregs->phys_hi & imask->phys_hi;
605 mid = pregs->phys_mid & imask.phys_mid; 615 mid = pregs->phys_mid & imask->phys_mid;
606 lo = pregs->phys_lo & imask.phys_lo; 616 lo = pregs->phys_lo & imask->phys_lo;
607 irq = interrupt & imask.interrupt; 617 irq = interrupt & imask->interrupt;
608 618
609 for (i = 0; i < num_imap; i++) { 619 for (i = 0; i < num_imap; i++) {
610 if (imap[i].phys_hi == hi && 620 if (imap[i].phys_hi == hi &&
611 imap[i].phys_mid == mid && 621 imap[i].phys_mid == mid &&
612 imap[i].phys_lo == lo && 622 imap[i].phys_lo == lo &&
613 imap[i].interrupt == irq) { 623 imap[i].interrupt == irq) {
614 *cnode = imap[i].cnode; 624 *cnode = of_find_node_by_phandle(imap[i].cnode);
615 interrupt = imap[i].cinterrupt; 625 interrupt = imap[i].cinterrupt;
616 } 626 }
617 } 627 }
618 628
619 printk("%s: %s MAP BUS %s DEV %s [%x] -> [%x]\n", 629 if (pci_irq_verbose)
620 pbm->name, pci_name(toplevel_pdev), 630 printk("%s: %s MAP BUS %s DEV %s [%x] -> [%x]\n",
621 pci_name(pbus), pci_name(pdev), 631 pbm->name, pci_name(toplevel_pdev),
622 orig_interrupt, interrupt); 632 pci_name(pbus), pci_name(pdev),
633 orig_interrupt, interrupt);
623 634
624no_intmap: 635no_intmap:
625 return interrupt; 636 return interrupt;
@@ -633,21 +644,22 @@ no_intmap:
633 * all interrupt translations are complete, else we should use that node's 644 * all interrupt translations are complete, else we should use that node's
634 * "reg" property to apply the PBM's "interrupt-{map,mask}" to the interrupt. 645 * "reg" property to apply the PBM's "interrupt-{map,mask}" to the interrupt.
635 */ 646 */
636static unsigned int __init pci_intmap_match_to_root(struct pci_pbm_info *pbm, 647static struct device_node * __init
637 struct pci_dev *pdev, 648pci_intmap_match_to_root(struct pci_pbm_info *pbm,
638 unsigned int *interrupt) 649 struct pci_dev *pdev,
650 unsigned int *interrupt)
639{ 651{
640 struct pci_dev *toplevel_pdev = pdev; 652 struct pci_dev *toplevel_pdev = pdev;
641 struct pcidev_cookie *toplevel_pcp = toplevel_pdev->sysdata; 653 struct pcidev_cookie *toplevel_pcp = toplevel_pdev->sysdata;
642 unsigned int cnode = toplevel_pcp->prom_node; 654 struct device_node *cnode = toplevel_pcp->prom_node;
643 655
644 while (pdev->bus->number != pbm->pci_first_busno) { 656 while (pdev->bus->number != pbm->pci_first_busno) {
645 struct pci_dev *pbus = pdev->bus->self; 657 struct pci_dev *pbus = pdev->bus->self;
646 struct pcidev_cookie *pcp = pbus->sysdata; 658 struct pcidev_cookie *pcp = pbus->sysdata;
647 int plen; 659 struct property *prop;
648 660
649 plen = prom_getproplen(pcp->prom_node, "interrupt-map"); 661 prop = of_find_property(pcp->prom_node, "interrupt-map", NULL);
650 if (plen <= 0) { 662 if (!prop) {
651 *interrupt = pci_slot_swivel(pbm, toplevel_pdev, 663 *interrupt = pci_slot_swivel(pbm, toplevel_pdev,
652 pdev, *interrupt); 664 pdev, *interrupt);
653 cnode = pcp->prom_node; 665 cnode = pcp->prom_node;
@@ -675,26 +687,29 @@ static int __init pci_intmap_match(struct pci_dev *pdev, unsigned int *interrupt
675{ 687{
676 struct pcidev_cookie *dev_pcp = pdev->sysdata; 688 struct pcidev_cookie *dev_pcp = pdev->sysdata;
677 struct pci_pbm_info *pbm = dev_pcp->pbm; 689 struct pci_pbm_info *pbm = dev_pcp->pbm;
678 struct linux_prom_pci_registers reg[PROMREG_MAX]; 690 struct linux_prom_pci_registers *reg;
691 struct device_node *cnode;
692 struct property *prop;
679 unsigned int hi, mid, lo, irq; 693 unsigned int hi, mid, lo, irq;
680 int i, cnode, plen; 694 int i, plen;
681 695
682 cnode = pci_intmap_match_to_root(pbm, pdev, interrupt); 696 cnode = pci_intmap_match_to_root(pbm, pdev, interrupt);
683 if (cnode == pbm->prom_node) 697 if (cnode == pbm->prom_node)
684 goto success; 698 goto success;
685 699
686 plen = prom_getproperty(cnode, "reg", (char *) reg, sizeof(reg)); 700 prop = of_find_property(cnode, "reg", &plen);
687 if (plen <= 0 || 701 if (!prop ||
688 (plen % sizeof(struct linux_prom_pci_registers)) != 0) { 702 (plen % sizeof(struct linux_prom_pci_registers)) != 0) {
689 printk("%s: OBP node %x reg property has bad len %d\n", 703 printk("%s: OBP node %s reg property has bad len %d\n",
690 pbm->name, cnode, plen); 704 pbm->name, cnode->full_name, plen);
691 goto fail; 705 goto fail;
692 } 706 }
707 reg = prop->value;
693 708
694 hi = reg[0].phys_hi & pbm->pbm_intmask.phys_hi; 709 hi = reg[0].phys_hi & pbm->pbm_intmask->phys_hi;
695 mid = reg[0].phys_mid & pbm->pbm_intmask.phys_mid; 710 mid = reg[0].phys_mid & pbm->pbm_intmask->phys_mid;
696 lo = reg[0].phys_lo & pbm->pbm_intmask.phys_lo; 711 lo = reg[0].phys_lo & pbm->pbm_intmask->phys_lo;
697 irq = *interrupt & pbm->pbm_intmask.interrupt; 712 irq = *interrupt & pbm->pbm_intmask->interrupt;
698 713
699 for (i = 0; i < pbm->num_pbm_intmap; i++) { 714 for (i = 0; i < pbm->num_pbm_intmap; i++) {
700 struct linux_prom_pci_intmap *intmap; 715 struct linux_prom_pci_intmap *intmap;
@@ -714,9 +729,11 @@ fail:
714 return 0; 729 return 0;
715 730
716success: 731success:
717 printk("PCI-IRQ: Routing bus[%2x] slot[%2x] to INO[%02x]\n", 732 if (pci_irq_verbose)
718 pdev->bus->number, PCI_SLOT(pdev->devfn), 733 printk("%s: Routing bus[%2x] slot[%2x] to INO[%02x]\n",
719 *interrupt); 734 pbm->name,
735 pdev->bus->number, PCI_SLOT(pdev->devfn),
736 *interrupt);
720 return 1; 737 return 1;
721} 738}
722 739
@@ -727,8 +744,8 @@ static void __init pdev_fixup_irq(struct pci_dev *pdev)
727 struct pci_controller_info *p = pbm->parent; 744 struct pci_controller_info *p = pbm->parent;
728 unsigned int portid = pbm->portid; 745 unsigned int portid = pbm->portid;
729 unsigned int prom_irq; 746 unsigned int prom_irq;
730 int prom_node = pcp->prom_node; 747 struct device_node *dp = pcp->prom_node;
731 int err; 748 struct property *prop;
732 749
733 /* If this is an empty EBUS device, sometimes OBP fails to 750 /* If this is an empty EBUS device, sometimes OBP fails to
734 * give it a valid fully specified interrupts property. 751 * give it a valid fully specified interrupts property.
@@ -739,17 +756,17 @@ static void __init pdev_fixup_irq(struct pci_dev *pdev)
739 */ 756 */
740 if (pdev->vendor == PCI_VENDOR_ID_SUN && 757 if (pdev->vendor == PCI_VENDOR_ID_SUN &&
741 pdev->device == PCI_DEVICE_ID_SUN_EBUS && 758 pdev->device == PCI_DEVICE_ID_SUN_EBUS &&
742 !prom_getchild(prom_node)) { 759 !dp->child) {
743 pdev->irq = 0; 760 pdev->irq = 0;
744 return; 761 return;
745 } 762 }
746 763
747 err = prom_getproperty(prom_node, "interrupts", 764 prop = of_find_property(dp, "interrupts", NULL);
748 (char *)&prom_irq, sizeof(prom_irq)); 765 if (!prop) {
749 if (err == 0 || err == -1) {
750 pdev->irq = 0; 766 pdev->irq = 0;
751 return; 767 return;
752 } 768 }
769 prom_irq = *(unsigned int *) prop->value;
753 770
754 if (tlb_type != hypervisor) { 771 if (tlb_type != hypervisor) {
755 /* Fully specified already? */ 772 /* Fully specified already? */
diff --git a/arch/sparc64/kernel/pci_impl.h b/arch/sparc64/kernel/pci_impl.h
index 6c3205962544..971e2bea30b4 100644
--- a/arch/sparc64/kernel/pci_impl.h
+++ b/arch/sparc64/kernel/pci_impl.h
@@ -10,6 +10,7 @@
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/spinlock.h> 11#include <linux/spinlock.h>
12#include <asm/io.h> 12#include <asm/io.h>
13#include <asm/prom.h>
13 14
14extern struct pci_controller_info *pci_controller_root; 15extern struct pci_controller_info *pci_controller_root;
15 16
@@ -19,7 +20,7 @@ extern int pci_num_controllers;
19extern void pci_fixup_host_bridge_self(struct pci_bus *pbus); 20extern void pci_fixup_host_bridge_self(struct pci_bus *pbus);
20extern void pci_fill_in_pbm_cookies(struct pci_bus *pbus, 21extern void pci_fill_in_pbm_cookies(struct pci_bus *pbus,
21 struct pci_pbm_info *pbm, 22 struct pci_pbm_info *pbm,
22 int prom_node); 23 struct device_node *prom_node);
23extern void pci_record_assignments(struct pci_pbm_info *pbm, 24extern void pci_record_assignments(struct pci_pbm_info *pbm,
24 struct pci_bus *pbus); 25 struct pci_bus *pbus);
25extern void pci_assign_unassigned(struct pci_pbm_info *pbm, 26extern void pci_assign_unassigned(struct pci_pbm_info *pbm,
diff --git a/arch/sparc64/kernel/pci_psycho.c b/arch/sparc64/kernel/pci_psycho.c
index 24db22aa9728..5b2261ebda6f 100644
--- a/arch/sparc64/kernel/pci_psycho.c
+++ b/arch/sparc64/kernel/pci_psycho.c
@@ -17,6 +17,7 @@
17#include <asm/iommu.h> 17#include <asm/iommu.h>
18#include <asm/irq.h> 18#include <asm/irq.h>
19#include <asm/starfire.h> 19#include <asm/starfire.h>
20#include <asm/prom.h>
20 21
21#include "pci_impl.h" 22#include "pci_impl.h"
22#include "iommu_common.h" 23#include "iommu_common.h"
@@ -1291,11 +1292,12 @@ static void psycho_pbm_strbuf_init(struct pci_controller_info *p,
1291#define PSYCHO_MEMSPACE_SIZE 0x07fffffffUL 1292#define PSYCHO_MEMSPACE_SIZE 0x07fffffffUL
1292 1293
1293static void psycho_pbm_init(struct pci_controller_info *p, 1294static void psycho_pbm_init(struct pci_controller_info *p,
1294 int prom_node, int is_pbm_a) 1295 struct device_node *dp, int is_pbm_a)
1295{ 1296{
1296 unsigned int busrange[2]; 1297 unsigned int *busrange;
1298 struct property *prop;
1297 struct pci_pbm_info *pbm; 1299 struct pci_pbm_info *pbm;
1298 int err; 1300 int len;
1299 1301
1300 if (is_pbm_a) { 1302 if (is_pbm_a) {
1301 pbm = &p->pbm_A; 1303 pbm = &p->pbm_A;
@@ -1310,10 +1312,14 @@ static void psycho_pbm_init(struct pci_controller_info *p,
1310 } 1312 }
1311 1313
1312 pbm->chip_type = PBM_CHIP_TYPE_PSYCHO; 1314 pbm->chip_type = PBM_CHIP_TYPE_PSYCHO;
1313 pbm->chip_version = 1315 pbm->chip_version = 0;
1314 prom_getintdefault(prom_node, "version#", 0); 1316 prop = of_find_property(dp, "version#", NULL);
1315 pbm->chip_revision = 1317 if (prop)
1316 prom_getintdefault(prom_node, "module-revision#", 0); 1318 pbm->chip_version = *(int *) prop->value;
1319 pbm->chip_revision = 0;
1320 prop = of_find_property(dp, "module-revision#", NULL);
1321 if (prop)
1322 pbm->chip_revision = *(int *) prop->value;
1317 1323
1318 pbm->io_space.end = pbm->io_space.start + PSYCHO_IOSPACE_SIZE; 1324 pbm->io_space.end = pbm->io_space.start + PSYCHO_IOSPACE_SIZE;
1319 pbm->io_space.flags = IORESOURCE_IO; 1325 pbm->io_space.flags = IORESOURCE_IO;
@@ -1322,45 +1328,36 @@ static void psycho_pbm_init(struct pci_controller_info *p,
1322 pbm_register_toplevel_resources(p, pbm); 1328 pbm_register_toplevel_resources(p, pbm);
1323 1329
1324 pbm->parent = p; 1330 pbm->parent = p;
1325 pbm->prom_node = prom_node; 1331 pbm->prom_node = dp;
1326 prom_getstring(prom_node, "name", 1332 pbm->name = dp->full_name;
1327 pbm->prom_name, 1333
1328 sizeof(pbm->prom_name)); 1334 printk("%s: PSYCHO PCI Bus Module ver[%x:%x]\n",
1329 1335 pbm->name,
1330 err = prom_getproperty(prom_node, "ranges", 1336 pbm->chip_version, pbm->chip_revision);
1331 (char *)pbm->pbm_ranges, 1337
1332 sizeof(pbm->pbm_ranges)); 1338 prop = of_find_property(dp, "ranges", &len);
1333 if (err != -1) 1339 if (prop) {
1340 pbm->pbm_ranges = prop->value;
1334 pbm->num_pbm_ranges = 1341 pbm->num_pbm_ranges =
1335 (err / sizeof(struct linux_prom_pci_ranges)); 1342 (len / sizeof(struct linux_prom_pci_ranges));
1336 else 1343 } else {
1337 pbm->num_pbm_ranges = 0; 1344 pbm->num_pbm_ranges = 0;
1345 }
1338 1346
1339 err = prom_getproperty(prom_node, "interrupt-map", 1347 prop = of_find_property(dp, "interrupt-map", &len);
1340 (char *)pbm->pbm_intmap, 1348 if (prop) {
1341 sizeof(pbm->pbm_intmap)); 1349 pbm->pbm_intmap = prop->value;
1342 if (err != -1) { 1350 pbm->num_pbm_intmap =
1343 pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap)); 1351 (len / sizeof(struct linux_prom_pci_intmap));
1344 err = prom_getproperty(prom_node, "interrupt-map-mask", 1352
1345 (char *)&pbm->pbm_intmask, 1353 prop = of_find_property(dp, "interrupt-map-mask", NULL);
1346 sizeof(pbm->pbm_intmask)); 1354 pbm->pbm_intmask = prop->value;
1347 if (err == -1) {
1348 prom_printf("PSYCHO-PBM: Fatal error, no "
1349 "interrupt-map-mask.\n");
1350 prom_halt();
1351 }
1352 } else { 1355 } else {
1353 pbm->num_pbm_intmap = 0; 1356 pbm->num_pbm_intmap = 0;
1354 memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
1355 } 1357 }
1356 1358
1357 err = prom_getproperty(prom_node, "bus-range", 1359 prop = of_find_property(dp, "bus-range", NULL);
1358 (char *)&busrange[0], 1360 busrange = prop->value;
1359 sizeof(busrange));
1360 if (err == 0 || err == -1) {
1361 prom_printf("PSYCHO-PBM: Fatal error, no bus-range.\n");
1362 prom_halt();
1363 }
1364 pbm->pci_first_busno = busrange[0]; 1361 pbm->pci_first_busno = busrange[0];
1365 pbm->pci_last_busno = busrange[1]; 1362 pbm->pci_last_busno = busrange[1];
1366 1363
@@ -1369,20 +1366,24 @@ static void psycho_pbm_init(struct pci_controller_info *p,
1369 1366
1370#define PSYCHO_CONFIGSPACE 0x001000000UL 1367#define PSYCHO_CONFIGSPACE 0x001000000UL
1371 1368
1372void psycho_init(int node, char *model_name) 1369void psycho_init(struct device_node *dp, char *model_name)
1373{ 1370{
1374 struct linux_prom64_registers pr_regs[3]; 1371 struct linux_prom64_registers *pr_regs;
1375 struct pci_controller_info *p; 1372 struct pci_controller_info *p;
1376 struct pci_iommu *iommu; 1373 struct pci_iommu *iommu;
1374 struct property *prop;
1377 u32 upa_portid; 1375 u32 upa_portid;
1378 int is_pbm_a, err; 1376 int is_pbm_a;
1379 1377
1380 upa_portid = prom_getintdefault(node, "upa-portid", 0xff); 1378 upa_portid = 0xff;
1379 prop = of_find_property(dp, "upa-portid", NULL);
1380 if (prop)
1381 upa_portid = *(u32 *) prop->value;
1381 1382
1382 for(p = pci_controller_root; p; p = p->next) { 1383 for(p = pci_controller_root; p; p = p->next) {
1383 if (p->pbm_A.portid == upa_portid) { 1384 if (p->pbm_A.portid == upa_portid) {
1384 is_pbm_a = (p->pbm_A.prom_node == 0); 1385 is_pbm_a = (p->pbm_A.prom_node == NULL);
1385 psycho_pbm_init(p, node, is_pbm_a); 1386 psycho_pbm_init(p, dp, is_pbm_a);
1386 return; 1387 return;
1387 } 1388 }
1388 } 1389 }
@@ -1412,23 +1413,14 @@ void psycho_init(int node, char *model_name)
1412 p->resource_adjust = psycho_resource_adjust; 1413 p->resource_adjust = psycho_resource_adjust;
1413 p->pci_ops = &psycho_ops; 1414 p->pci_ops = &psycho_ops;
1414 1415
1415 err = prom_getproperty(node, "reg", 1416 prop = of_find_property(dp, "reg", NULL);
1416 (char *)&pr_regs[0], 1417 pr_regs = prop->value;
1417 sizeof(pr_regs));
1418 if (err == 0 || err == -1) {
1419 prom_printf("PSYCHO: Fatal error, no reg property.\n");
1420 prom_halt();
1421 }
1422 1418
1423 p->pbm_A.controller_regs = pr_regs[2].phys_addr; 1419 p->pbm_A.controller_regs = pr_regs[2].phys_addr;
1424 p->pbm_B.controller_regs = pr_regs[2].phys_addr; 1420 p->pbm_B.controller_regs = pr_regs[2].phys_addr;
1425 printk("PCI: Found PSYCHO, control regs at %016lx\n",
1426 p->pbm_A.controller_regs);
1427 1421
1428 p->pbm_A.config_space = p->pbm_B.config_space = 1422 p->pbm_A.config_space = p->pbm_B.config_space =
1429 (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE); 1423 (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE);
1430 printk("PSYCHO: Shared PCI config space at %016lx\n",
1431 p->pbm_A.config_space);
1432 1424
1433 /* 1425 /*
1434 * Psycho's PCI MEM space is mapped to a 2GB aligned area, so 1426 * Psycho's PCI MEM space is mapped to a 2GB aligned area, so
@@ -1441,5 +1433,5 @@ void psycho_init(int node, char *model_name)
1441 psycho_iommu_init(p); 1433 psycho_iommu_init(p);
1442 1434
1443 is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000); 1435 is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000);
1444 psycho_pbm_init(p, node, is_pbm_a); 1436 psycho_pbm_init(p, dp, is_pbm_a);
1445} 1437}
diff --git a/arch/sparc64/kernel/pci_sabre.c b/arch/sparc64/kernel/pci_sabre.c
index b7d997b55f0a..26f194ce4400 100644
--- a/arch/sparc64/kernel/pci_sabre.c
+++ b/arch/sparc64/kernel/pci_sabre.c
@@ -19,6 +19,7 @@
19#include <asm/irq.h> 19#include <asm/irq.h>
20#include <asm/smp.h> 20#include <asm/smp.h>
21#include <asm/oplib.h> 21#include <asm/oplib.h>
22#include <asm/prom.h>
22 23
23#include "pci_impl.h" 24#include "pci_impl.h"
24#include "iommu_common.h" 25#include "iommu_common.h"
@@ -1306,34 +1307,36 @@ static void pbm_register_toplevel_resources(struct pci_controller_info *p,
1306 &pbm->mem_space); 1307 &pbm->mem_space);
1307} 1308}
1308 1309
1309static void sabre_pbm_init(struct pci_controller_info *p, int sabre_node, u32 dma_begin) 1310static void sabre_pbm_init(struct pci_controller_info *p, struct device_node *dp, u32 dma_begin)
1310{ 1311{
1311 struct pci_pbm_info *pbm; 1312 struct pci_pbm_info *pbm;
1312 char namebuf[128]; 1313 struct device_node *node;
1313 u32 busrange[2]; 1314 struct property *prop;
1314 int node, simbas_found; 1315 u32 *busrange;
1316 int len, simbas_found;
1315 1317
1316 simbas_found = 0; 1318 simbas_found = 0;
1317 node = prom_getchild(sabre_node); 1319 node = dp->child;
1318 while ((node = prom_searchsiblings(node, "pci")) != 0) { 1320 while (node != NULL) {
1319 int err; 1321 if (strcmp(node->name, "pci"))
1320
1321 err = prom_getproperty(node, "model", namebuf, sizeof(namebuf));
1322 if ((err <= 0) || strncmp(namebuf, "SUNW,simba", err))
1323 goto next_pci; 1322 goto next_pci;
1324 1323
1325 err = prom_getproperty(node, "bus-range", 1324 prop = of_find_property(node, "model", NULL);
1326 (char *)&busrange[0], sizeof(busrange)); 1325 if (!prop || strncmp(prop->value, "SUNW,simba", prop->length))
1327 if (err == 0 || err == -1) { 1326 goto next_pci;
1328 prom_printf("APB: Error, cannot get PCI bus-range.\n");
1329 prom_halt();
1330 }
1331 1327
1332 simbas_found++; 1328 simbas_found++;
1329
1330 prop = of_find_property(node, "bus-range", NULL);
1331 busrange = prop->value;
1333 if (busrange[0] == 1) 1332 if (busrange[0] == 1)
1334 pbm = &p->pbm_B; 1333 pbm = &p->pbm_B;
1335 else 1334 else
1336 pbm = &p->pbm_A; 1335 pbm = &p->pbm_A;
1336
1337 pbm->name = node->full_name;
1338 printk("%s: SABRE PCI Bus Module\n", pbm->name);
1339
1337 pbm->chip_type = PBM_CHIP_TYPE_SABRE; 1340 pbm->chip_type = PBM_CHIP_TYPE_SABRE;
1338 pbm->parent = p; 1341 pbm->parent = p;
1339 pbm->prom_node = node; 1342 pbm->prom_node = node;
@@ -1341,83 +1344,68 @@ static void sabre_pbm_init(struct pci_controller_info *p, int sabre_node, u32 dm
1341 pbm->pci_first_busno = busrange[0]; 1344 pbm->pci_first_busno = busrange[0];
1342 pbm->pci_last_busno = busrange[1]; 1345 pbm->pci_last_busno = busrange[1];
1343 1346
1344 prom_getstring(node, "name", pbm->prom_name, sizeof(pbm->prom_name)); 1347 prop = of_find_property(node, "ranges", &len);
1345 err = prom_getproperty(node, "ranges", 1348 if (prop) {
1346 (char *)pbm->pbm_ranges, 1349 pbm->pbm_ranges = prop->value;
1347 sizeof(pbm->pbm_ranges));
1348 if (err != -1)
1349 pbm->num_pbm_ranges = 1350 pbm->num_pbm_ranges =
1350 (err / sizeof(struct linux_prom_pci_ranges)); 1351 (len / sizeof(struct linux_prom_pci_ranges));
1351 else 1352 } else {
1352 pbm->num_pbm_ranges = 0; 1353 pbm->num_pbm_ranges = 0;
1354 }
1353 1355
1354 err = prom_getproperty(node, "interrupt-map", 1356 prop = of_find_property(node, "interrupt-map", &len);
1355 (char *)pbm->pbm_intmap, 1357 if (prop) {
1356 sizeof(pbm->pbm_intmap)); 1358 pbm->pbm_intmap = prop->value;
1357 if (err != -1) { 1359 pbm->num_pbm_intmap =
1358 pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap)); 1360 (len / sizeof(struct linux_prom_pci_intmap));
1359 err = prom_getproperty(node, "interrupt-map-mask", 1361
1360 (char *)&pbm->pbm_intmask, 1362 prop = of_find_property(node, "interrupt-map-mask",
1361 sizeof(pbm->pbm_intmask)); 1363 NULL);
1362 if (err == -1) { 1364 pbm->pbm_intmask = prop->value;
1363 prom_printf("APB: Fatal error, no interrupt-map-mask.\n");
1364 prom_halt();
1365 }
1366 } else { 1365 } else {
1367 pbm->num_pbm_intmap = 0; 1366 pbm->num_pbm_intmap = 0;
1368 memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
1369 } 1367 }
1370 1368
1371 pbm_register_toplevel_resources(p, pbm); 1369 pbm_register_toplevel_resources(p, pbm);
1372 1370
1373 next_pci: 1371 next_pci:
1374 node = prom_getsibling(node); 1372 node = node->sibling;
1375 if (!node)
1376 break;
1377 } 1373 }
1378 if (simbas_found == 0) { 1374 if (simbas_found == 0) {
1379 int err;
1380
1381 /* No APBs underneath, probably this is a hummingbird 1375 /* No APBs underneath, probably this is a hummingbird
1382 * system. 1376 * system.
1383 */ 1377 */
1384 pbm = &p->pbm_A; 1378 pbm = &p->pbm_A;
1385 pbm->parent = p; 1379 pbm->parent = p;
1386 pbm->prom_node = sabre_node; 1380 pbm->prom_node = dp;
1387 pbm->pci_first_busno = p->pci_first_busno; 1381 pbm->pci_first_busno = p->pci_first_busno;
1388 pbm->pci_last_busno = p->pci_last_busno; 1382 pbm->pci_last_busno = p->pci_last_busno;
1389 1383
1390 prom_getstring(sabre_node, "name", pbm->prom_name, sizeof(pbm->prom_name)); 1384 prop = of_find_property(dp, "ranges", &len);
1391 err = prom_getproperty(sabre_node, "ranges", 1385 if (prop) {
1392 (char *) pbm->pbm_ranges, 1386 pbm->pbm_ranges = prop->value;
1393 sizeof(pbm->pbm_ranges));
1394 if (err != -1)
1395 pbm->num_pbm_ranges = 1387 pbm->num_pbm_ranges =
1396 (err / sizeof(struct linux_prom_pci_ranges)); 1388 (len / sizeof(struct linux_prom_pci_ranges));
1397 else 1389 } else {
1398 pbm->num_pbm_ranges = 0; 1390 pbm->num_pbm_ranges = 0;
1391 }
1399 1392
1400 err = prom_getproperty(sabre_node, "interrupt-map", 1393 prop = of_find_property(dp, "interrupt-map", &len);
1401 (char *) pbm->pbm_intmap, 1394 if (prop) {
1402 sizeof(pbm->pbm_intmap)); 1395 pbm->pbm_intmap = prop->value;
1403 1396 pbm->num_pbm_intmap =
1404 if (err != -1) { 1397 (len / sizeof(struct linux_prom_pci_intmap));
1405 pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap)); 1398
1406 err = prom_getproperty(sabre_node, "interrupt-map-mask", 1399 prop = of_find_property(dp, "interrupt-map-mask",
1407 (char *)&pbm->pbm_intmask, 1400 NULL);
1408 sizeof(pbm->pbm_intmask)); 1401 pbm->pbm_intmask = prop->value;
1409 if (err == -1) {
1410 prom_printf("Hummingbird: Fatal error, no interrupt-map-mask.\n");
1411 prom_halt();
1412 }
1413 } else { 1402 } else {
1414 pbm->num_pbm_intmap = 0; 1403 pbm->num_pbm_intmap = 0;
1415 memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
1416 } 1404 }
1417 1405
1406 pbm->name = dp->full_name;
1407 printk("%s: SABRE PCI Bus Module\n", pbm->name);
1418 1408
1419 sprintf(pbm->name, "SABRE%d PBM%c", p->index,
1420 (pbm == &p->pbm_A ? 'A' : 'B'));
1421 pbm->io_space.name = pbm->mem_space.name = pbm->name; 1409 pbm->io_space.name = pbm->mem_space.name = pbm->name;
1422 1410
1423 /* Hack up top-level resources. */ 1411 /* Hack up top-level resources. */
@@ -1443,14 +1431,15 @@ static void sabre_pbm_init(struct pci_controller_info *p, int sabre_node, u32 dm
1443 } 1431 }
1444} 1432}
1445 1433
1446void sabre_init(int pnode, char *model_name) 1434void sabre_init(struct device_node *dp, char *model_name)
1447{ 1435{
1448 struct linux_prom64_registers pr_regs[2]; 1436 struct linux_prom64_registers *pr_regs;
1449 struct pci_controller_info *p; 1437 struct pci_controller_info *p;
1450 struct pci_iommu *iommu; 1438 struct pci_iommu *iommu;
1451 int tsbsize, err; 1439 struct property *prop;
1452 u32 busrange[2]; 1440 int tsbsize;
1453 u32 vdma[2]; 1441 u32 *busrange;
1442 u32 *vdma;
1454 u32 upa_portid, dma_mask; 1443 u32 upa_portid, dma_mask;
1455 u64 clear_irq; 1444 u64 clear_irq;
1456 1445
@@ -1458,22 +1447,21 @@ void sabre_init(int pnode, char *model_name)
1458 if (!strcmp(model_name, "pci108e,a001")) 1447 if (!strcmp(model_name, "pci108e,a001"))
1459 hummingbird_p = 1; 1448 hummingbird_p = 1;
1460 else if (!strcmp(model_name, "SUNW,sabre")) { 1449 else if (!strcmp(model_name, "SUNW,sabre")) {
1461 char compat[64]; 1450 prop = of_find_property(dp, "compatible", NULL);
1451 if (prop) {
1452 const char *compat = prop->value;
1462 1453
1463 if (prom_getproperty(pnode, "compatible", 1454 if (!strcmp(compat, "pci108e,a001"))
1464 compat, sizeof(compat)) > 0 && 1455 hummingbird_p = 1;
1465 !strcmp(compat, "pci108e,a001")) { 1456 }
1466 hummingbird_p = 1; 1457 if (!hummingbird_p) {
1467 } else { 1458 struct device_node *dp;
1468 int cpu_node;
1469 1459
1470 /* Of course, Sun has to encode things a thousand 1460 /* Of course, Sun has to encode things a thousand
1471 * different ways, inconsistently. 1461 * different ways, inconsistently.
1472 */ 1462 */
1473 cpu_find_by_instance(0, &cpu_node, NULL); 1463 cpu_find_by_instance(0, &dp, NULL);
1474 if (prom_getproperty(cpu_node, "name", 1464 if (!strcmp(dp->name, "SUNW,UltraSPARC-IIe"))
1475 compat, sizeof(compat)) > 0 &&
1476 !strcmp(compat, "SUNW,UltraSPARC-IIe"))
1477 hummingbird_p = 1; 1465 hummingbird_p = 1;
1478 } 1466 }
1479 } 1467 }
@@ -1491,7 +1479,10 @@ void sabre_init(int pnode, char *model_name)
1491 } 1479 }
1492 p->pbm_A.iommu = p->pbm_B.iommu = iommu; 1480 p->pbm_A.iommu = p->pbm_B.iommu = iommu;
1493 1481
1494 upa_portid = prom_getintdefault(pnode, "upa-portid", 0xff); 1482 upa_portid = 0xff;
1483 prop = of_find_property(dp, "upa-portid", NULL);
1484 if (prop)
1485 upa_portid = *(u32 *) prop->value;
1495 1486
1496 p->next = pci_controller_root; 1487 p->next = pci_controller_root;
1497 pci_controller_root = p; 1488 pci_controller_root = p;
@@ -1509,13 +1500,9 @@ void sabre_init(int pnode, char *model_name)
1509 /* 1500 /*
1510 * Map in SABRE register set and report the presence of this SABRE. 1501 * Map in SABRE register set and report the presence of this SABRE.
1511 */ 1502 */
1512 err = prom_getproperty(pnode, "reg", 1503
1513 (char *)&pr_regs[0], sizeof(pr_regs)); 1504 prop = of_find_property(dp, "reg", NULL);
1514 if(err == 0 || err == -1) { 1505 pr_regs = prop->value;
1515 prom_printf("SABRE: Error, cannot get U2P registers "
1516 "from PROM.\n");
1517 prom_halt();
1518 }
1519 1506
1520 /* 1507 /*
1521 * First REG in property is base of entire SABRE register space. 1508 * First REG in property is base of entire SABRE register space.
@@ -1523,9 +1510,6 @@ void sabre_init(int pnode, char *model_name)
1523 p->pbm_A.controller_regs = pr_regs[0].phys_addr; 1510 p->pbm_A.controller_regs = pr_regs[0].phys_addr;
1524 p->pbm_B.controller_regs = pr_regs[0].phys_addr; 1511 p->pbm_B.controller_regs = pr_regs[0].phys_addr;
1525 1512
1526 printk("PCI: Found SABRE, main regs at %016lx\n",
1527 p->pbm_A.controller_regs);
1528
1529 /* Clear interrupts */ 1513 /* Clear interrupts */
1530 1514
1531 /* PCI first */ 1515 /* PCI first */
@@ -1544,16 +1528,9 @@ void sabre_init(int pnode, char *model_name)
1544 /* Now map in PCI config space for entire SABRE. */ 1528 /* Now map in PCI config space for entire SABRE. */
1545 p->pbm_A.config_space = p->pbm_B.config_space = 1529 p->pbm_A.config_space = p->pbm_B.config_space =
1546 (p->pbm_A.controller_regs + SABRE_CONFIGSPACE); 1530 (p->pbm_A.controller_regs + SABRE_CONFIGSPACE);
1547 printk("SABRE: Shared PCI config space at %016lx\n", 1531
1548 p->pbm_A.config_space); 1532 prop = of_find_property(dp, "virtual-dma", NULL);
1549 1533 vdma = prop->value;
1550 err = prom_getproperty(pnode, "virtual-dma",
1551 (char *)&vdma[0], sizeof(vdma));
1552 if(err == 0 || err == -1) {
1553 prom_printf("SABRE: Error, cannot get virtual-dma property "
1554 "from PROM.\n");
1555 prom_halt();
1556 }
1557 1534
1558 dma_mask = vdma[0]; 1535 dma_mask = vdma[0];
1559 switch(vdma[1]) { 1536 switch(vdma[1]) {
@@ -1577,21 +1554,13 @@ void sabre_init(int pnode, char *model_name)
1577 1554
1578 sabre_iommu_init(p, tsbsize, vdma[0], dma_mask); 1555 sabre_iommu_init(p, tsbsize, vdma[0], dma_mask);
1579 1556
1580 printk("SABRE: DVMA at %08x [%08x]\n", vdma[0], vdma[1]); 1557 prop = of_find_property(dp, "bus-range", NULL);
1581 1558 busrange = prop->value;
1582 err = prom_getproperty(pnode, "bus-range",
1583 (char *)&busrange[0], sizeof(busrange));
1584 if(err == 0 || err == -1) {
1585 prom_printf("SABRE: Error, cannot get PCI bus-range "
1586 " from PROM.\n");
1587 prom_halt();
1588 }
1589
1590 p->pci_first_busno = busrange[0]; 1559 p->pci_first_busno = busrange[0];
1591 p->pci_last_busno = busrange[1]; 1560 p->pci_last_busno = busrange[1];
1592 1561
1593 /* 1562 /*
1594 * Look for APB underneath. 1563 * Look for APB underneath.
1595 */ 1564 */
1596 sabre_pbm_init(p, pnode, vdma[0]); 1565 sabre_pbm_init(p, dp, vdma[0]);
1597} 1566}
diff --git a/arch/sparc64/kernel/pci_schizo.c b/arch/sparc64/kernel/pci_schizo.c
index cc662e915d32..f16449ccd7bc 100644
--- a/arch/sparc64/kernel/pci_schizo.c
+++ b/arch/sparc64/kernel/pci_schizo.c
@@ -16,6 +16,7 @@
16#include <asm/irq.h> 16#include <asm/irq.h>
17#include <asm/upa.h> 17#include <asm/upa.h>
18#include <asm/pstate.h> 18#include <asm/pstate.h>
19#include <asm/prom.h>
19 20
20#include "pci_impl.h" 21#include "pci_impl.h"
21#include "iommu_common.h" 22#include "iommu_common.h"
@@ -1456,10 +1457,12 @@ static void __schizo_scan_bus(struct pci_controller_info *p,
1456 1457
1457 pbm_config_busmastering(&p->pbm_B); 1458 pbm_config_busmastering(&p->pbm_B);
1458 p->pbm_B.is_66mhz_capable = 1459 p->pbm_B.is_66mhz_capable =
1459 prom_getbool(p->pbm_B.prom_node, "66mhz-capable"); 1460 (of_find_property(p->pbm_B.prom_node, "66mhz-capable", NULL)
1461 != NULL);
1460 pbm_config_busmastering(&p->pbm_A); 1462 pbm_config_busmastering(&p->pbm_A);
1461 p->pbm_A.is_66mhz_capable = 1463 p->pbm_A.is_66mhz_capable =
1462 prom_getbool(p->pbm_A.prom_node, "66mhz-capable"); 1464 (of_find_property(p->pbm_A.prom_node, "66mhz-capable", NULL)
1465 != NULL);
1463 pbm_scan_bus(p, &p->pbm_B); 1466 pbm_scan_bus(p, &p->pbm_B);
1464 pbm_scan_bus(p, &p->pbm_A); 1467 pbm_scan_bus(p, &p->pbm_A);
1465 1468
@@ -1661,13 +1664,18 @@ static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
1661{ 1664{
1662 struct pci_iommu *iommu = pbm->iommu; 1665 struct pci_iommu *iommu = pbm->iommu;
1663 unsigned long i, tagbase, database; 1666 unsigned long i, tagbase, database;
1667 struct property *prop;
1664 u32 vdma[2], dma_mask; 1668 u32 vdma[2], dma_mask;
1665 u64 control; 1669 u64 control;
1666 int err, tsbsize; 1670 int tsbsize;
1667 1671
1668 err = prom_getproperty(pbm->prom_node, "virtual-dma", 1672 prop = of_find_property(pbm->prom_node, "virtual-dma", NULL);
1669 (char *)&vdma[0], sizeof(vdma)); 1673 if (prop) {
1670 if (err == 0 || err == -1) { 1674 u32 *val = prop->value;
1675
1676 vdma[0] = val[0];
1677 vdma[1] = val[1];
1678 } else {
1671 /* No property, use default values. */ 1679 /* No property, use default values. */
1672 vdma[0] = 0xc0000000; 1680 vdma[0] = 0xc0000000;
1673 vdma[1] = 0x40000000; 1681 vdma[1] = 0x40000000;
@@ -1778,6 +1786,7 @@ static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
1778 1786
1779static void schizo_pbm_hw_init(struct pci_pbm_info *pbm) 1787static void schizo_pbm_hw_init(struct pci_pbm_info *pbm)
1780{ 1788{
1789 struct property *prop;
1781 u64 tmp; 1790 u64 tmp;
1782 1791
1783 schizo_write(pbm->pbm_regs + SCHIZO_PCI_IRQ_RETRY, 5); 1792 schizo_write(pbm->pbm_regs + SCHIZO_PCI_IRQ_RETRY, 5);
@@ -1791,7 +1800,8 @@ static void schizo_pbm_hw_init(struct pci_pbm_info *pbm)
1791 pbm->chip_version >= 0x2) 1800 pbm->chip_version >= 0x2)
1792 tmp |= 0x3UL << SCHIZO_PCICTRL_PTO_SHIFT; 1801 tmp |= 0x3UL << SCHIZO_PCICTRL_PTO_SHIFT;
1793 1802
1794 if (!prom_getbool(pbm->prom_node, "no-bus-parking")) 1803 prop = of_find_property(pbm->prom_node, "no-bus-parking", NULL);
1804 if (!prop)
1795 tmp |= SCHIZO_PCICTRL_PARK; 1805 tmp |= SCHIZO_PCICTRL_PARK;
1796 else 1806 else
1797 tmp &= ~SCHIZO_PCICTRL_PARK; 1807 tmp &= ~SCHIZO_PCICTRL_PARK;
@@ -1831,16 +1841,17 @@ static void schizo_pbm_hw_init(struct pci_pbm_info *pbm)
1831} 1841}
1832 1842
1833static void schizo_pbm_init(struct pci_controller_info *p, 1843static void schizo_pbm_init(struct pci_controller_info *p,
1834 int prom_node, u32 portid, 1844 struct device_node *dp, u32 portid,
1835 int chip_type) 1845 int chip_type)
1836{ 1846{
1837 struct linux_prom64_registers pr_regs[4]; 1847 struct linux_prom64_registers *regs;
1838 unsigned int busrange[2]; 1848 struct property *prop;
1849 unsigned int *busrange;
1839 struct pci_pbm_info *pbm; 1850 struct pci_pbm_info *pbm;
1840 const char *chipset_name; 1851 const char *chipset_name;
1841 u32 ino_bitmap[2]; 1852 u32 *ino_bitmap;
1842 int is_pbm_a; 1853 int is_pbm_a;
1843 int err; 1854 int len;
1844 1855
1845 switch (chip_type) { 1856 switch (chip_type) {
1846 case PBM_CHIP_TYPE_TOMATILLO: 1857 case PBM_CHIP_TYPE_TOMATILLO:
@@ -1868,16 +1879,10 @@ static void schizo_pbm_init(struct pci_controller_info *p,
1868 * 3) PBM PCI config space 1879 * 3) PBM PCI config space
1869 * 4) Ichip regs 1880 * 4) Ichip regs
1870 */ 1881 */
1871 err = prom_getproperty(prom_node, "reg", 1882 prop = of_find_property(dp, "reg", NULL);
1872 (char *)&pr_regs[0], 1883 regs = prop->value;
1873 sizeof(pr_regs));
1874 if (err == 0 || err == -1) {
1875 prom_printf("%s: Fatal error, no reg property.\n",
1876 chipset_name);
1877 prom_halt();
1878 }
1879 1884
1880 is_pbm_a = ((pr_regs[0].phys_addr & 0x00700000) == 0x00600000); 1885 is_pbm_a = ((regs[0].phys_addr & 0x00700000) == 0x00600000);
1881 1886
1882 if (is_pbm_a) 1887 if (is_pbm_a)
1883 pbm = &p->pbm_A; 1888 pbm = &p->pbm_A;
@@ -1886,92 +1891,62 @@ static void schizo_pbm_init(struct pci_controller_info *p,
1886 1891
1887 pbm->portid = portid; 1892 pbm->portid = portid;
1888 pbm->parent = p; 1893 pbm->parent = p;
1889 pbm->prom_node = prom_node; 1894 pbm->prom_node = dp;
1890 pbm->pci_first_slot = 1; 1895 pbm->pci_first_slot = 1;
1891 1896
1892 pbm->chip_type = chip_type; 1897 pbm->chip_type = chip_type;
1893 pbm->chip_version = 1898 pbm->chip_version = 0;
1894 prom_getintdefault(prom_node, "version#", 0); 1899 prop = of_find_property(dp, "version#", NULL);
1895 pbm->chip_revision = 1900 if (prop)
1896 prom_getintdefault(prom_node, "module-revision#", 0); 1901 pbm->chip_version = *(int *) prop->value;
1897 1902 pbm->chip_revision = 0;
1898 pbm->pbm_regs = pr_regs[0].phys_addr; 1903 prop = of_find_property(dp, "module-revision#", NULL);
1899 pbm->controller_regs = pr_regs[1].phys_addr - 0x10000UL; 1904 if (prop)
1905 pbm->chip_revision = *(int *) prop->value;
1906
1907 pbm->pbm_regs = regs[0].phys_addr;
1908 pbm->controller_regs = regs[1].phys_addr - 0x10000UL;
1900 1909
1901 if (chip_type == PBM_CHIP_TYPE_TOMATILLO) 1910 if (chip_type == PBM_CHIP_TYPE_TOMATILLO)
1902 pbm->sync_reg = pr_regs[3].phys_addr + 0x1a18UL; 1911 pbm->sync_reg = regs[3].phys_addr + 0x1a18UL;
1903 1912
1904 sprintf(pbm->name, 1913 pbm->name = dp->full_name;
1905 (chip_type == PBM_CHIP_TYPE_TOMATILLO ?
1906 "TOMATILLO%d PBM%c" :
1907 "SCHIZO%d PBM%c"),
1908 p->index,
1909 (pbm == &p->pbm_A ? 'A' : 'B'));
1910 1914
1911 printk("%s: ver[%x:%x], portid %x, " 1915 printk("%s: %s PCI Bus Module ver[%x:%x]\n",
1912 "cregs[%lx] pregs[%lx]\n",
1913 pbm->name, 1916 pbm->name,
1914 pbm->chip_version, pbm->chip_revision, 1917 (chip_type == PBM_CHIP_TYPE_TOMATILLO ?
1915 pbm->portid, 1918 "TOMATILLO" : "SCHIZO"),
1916 pbm->controller_regs, 1919 pbm->chip_version, pbm->chip_revision);
1917 pbm->pbm_regs);
1918 1920
1919 schizo_pbm_hw_init(pbm); 1921 schizo_pbm_hw_init(pbm);
1920 1922
1921 prom_getstring(prom_node, "name", 1923 prop = of_find_property(dp, "ranges", &len);
1922 pbm->prom_name, 1924 pbm->pbm_ranges = prop->value;
1923 sizeof(pbm->prom_name));
1924
1925 err = prom_getproperty(prom_node, "ranges",
1926 (char *) pbm->pbm_ranges,
1927 sizeof(pbm->pbm_ranges));
1928 if (err == 0 || err == -1) {
1929 prom_printf("%s: Fatal error, no ranges property.\n",
1930 pbm->name);
1931 prom_halt();
1932 }
1933
1934 pbm->num_pbm_ranges = 1925 pbm->num_pbm_ranges =
1935 (err / sizeof(struct linux_prom_pci_ranges)); 1926 (len / sizeof(struct linux_prom_pci_ranges));
1936 1927
1937 schizo_determine_mem_io_space(pbm); 1928 schizo_determine_mem_io_space(pbm);
1938 pbm_register_toplevel_resources(p, pbm); 1929 pbm_register_toplevel_resources(p, pbm);
1939 1930
1940 err = prom_getproperty(prom_node, "interrupt-map", 1931 prop = of_find_property(dp, "interrupt-map", &len);
1941 (char *)pbm->pbm_intmap, 1932 if (prop) {
1942 sizeof(pbm->pbm_intmap)); 1933 pbm->pbm_intmap = prop->value;
1943 if (err != -1) { 1934 pbm->num_pbm_intmap =
1944 pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap)); 1935 (len / sizeof(struct linux_prom_pci_intmap));
1945 err = prom_getproperty(prom_node, "interrupt-map-mask", 1936
1946 (char *)&pbm->pbm_intmask, 1937 prop = of_find_property(dp, "interrupt-map-mask", NULL);
1947 sizeof(pbm->pbm_intmask)); 1938 pbm->pbm_intmask = prop->value;
1948 if (err == -1) {
1949 prom_printf("%s: Fatal error, no "
1950 "interrupt-map-mask.\n", pbm->name);
1951 prom_halt();
1952 }
1953 } else { 1939 } else {
1954 pbm->num_pbm_intmap = 0; 1940 pbm->num_pbm_intmap = 0;
1955 memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
1956 } 1941 }
1957 1942
1958 err = prom_getproperty(prom_node, "ino-bitmap", 1943 prop = of_find_property(dp, "ino-bitmap", NULL);
1959 (char *) &ino_bitmap[0], 1944 ino_bitmap = prop->value;
1960 sizeof(ino_bitmap));
1961 if (err == 0 || err == -1) {
1962 prom_printf("%s: Fatal error, no ino-bitmap.\n", pbm->name);
1963 prom_halt();
1964 }
1965 pbm->ino_bitmap = (((u64)ino_bitmap[1] << 32UL) | 1945 pbm->ino_bitmap = (((u64)ino_bitmap[1] << 32UL) |
1966 ((u64)ino_bitmap[0] << 0UL)); 1946 ((u64)ino_bitmap[0] << 0UL));
1967 1947
1968 err = prom_getproperty(prom_node, "bus-range", 1948 prop = of_find_property(dp, "bus-range", NULL);
1969 (char *)&busrange[0], 1949 busrange = prop->value;
1970 sizeof(busrange));
1971 if (err == 0 || err == -1) {
1972 prom_printf("%s: Fatal error, no bus-range.\n", pbm->name);
1973 prom_halt();
1974 }
1975 pbm->pci_first_busno = busrange[0]; 1950 pbm->pci_first_busno = busrange[0];
1976 pbm->pci_last_busno = busrange[1]; 1951 pbm->pci_last_busno = busrange[1];
1977 1952
@@ -1989,16 +1964,20 @@ static inline int portid_compare(u32 x, u32 y, int chip_type)
1989 return (x == y); 1964 return (x == y);
1990} 1965}
1991 1966
1992static void __schizo_init(int node, char *model_name, int chip_type) 1967static void __schizo_init(struct device_node *dp, char *model_name, int chip_type)
1993{ 1968{
1994 struct pci_controller_info *p; 1969 struct pci_controller_info *p;
1995 struct pci_iommu *iommu; 1970 struct pci_iommu *iommu;
1971 struct property *prop;
1996 int is_pbm_a; 1972 int is_pbm_a;
1997 u32 portid; 1973 u32 portid;
1998 1974
1999 portid = prom_getintdefault(node, "portid", 0xff); 1975 portid = 0xff;
1976 prop = of_find_property(dp, "portid", NULL);
1977 if (prop)
1978 portid = *(u32 *) prop->value;
2000 1979
2001 for(p = pci_controller_root; p; p = p->next) { 1980 for (p = pci_controller_root; p; p = p->next) {
2002 struct pci_pbm_info *pbm; 1981 struct pci_pbm_info *pbm;
2003 1982
2004 if (p->pbm_A.prom_node && p->pbm_B.prom_node) 1983 if (p->pbm_A.prom_node && p->pbm_B.prom_node)
@@ -2009,8 +1988,8 @@ static void __schizo_init(int node, char *model_name, int chip_type)
2009 &p->pbm_B); 1988 &p->pbm_B);
2010 1989
2011 if (portid_compare(pbm->portid, portid, chip_type)) { 1990 if (portid_compare(pbm->portid, portid, chip_type)) {
2012 is_pbm_a = (p->pbm_A.prom_node == 0); 1991 is_pbm_a = (p->pbm_A.prom_node == NULL);
2013 schizo_pbm_init(p, node, portid, chip_type); 1992 schizo_pbm_init(p, dp, portid, chip_type);
2014 return; 1993 return;
2015 } 1994 }
2016 } 1995 }
@@ -2051,20 +2030,20 @@ static void __schizo_init(int node, char *model_name, int chip_type)
2051 /* Like PSYCHO we have a 2GB aligned area for memory space. */ 2030 /* Like PSYCHO we have a 2GB aligned area for memory space. */
2052 pci_memspace_mask = 0x7fffffffUL; 2031 pci_memspace_mask = 0x7fffffffUL;
2053 2032
2054 schizo_pbm_init(p, node, portid, chip_type); 2033 schizo_pbm_init(p, dp, portid, chip_type);
2055} 2034}
2056 2035
2057void schizo_init(int node, char *model_name) 2036void schizo_init(struct device_node *dp, char *model_name)
2058{ 2037{
2059 __schizo_init(node, model_name, PBM_CHIP_TYPE_SCHIZO); 2038 __schizo_init(dp, model_name, PBM_CHIP_TYPE_SCHIZO);
2060} 2039}
2061 2040
2062void schizo_plus_init(int node, char *model_name) 2041void schizo_plus_init(struct device_node *dp, char *model_name)
2063{ 2042{
2064 __schizo_init(node, model_name, PBM_CHIP_TYPE_SCHIZO_PLUS); 2043 __schizo_init(dp, model_name, PBM_CHIP_TYPE_SCHIZO_PLUS);
2065} 2044}
2066 2045
2067void tomatillo_init(int node, char *model_name) 2046void tomatillo_init(struct device_node *dp, char *model_name)
2068{ 2047{
2069 __schizo_init(node, model_name, PBM_CHIP_TYPE_TOMATILLO); 2048 __schizo_init(dp, model_name, PBM_CHIP_TYPE_TOMATILLO);
2070} 2049}
diff --git a/arch/sparc64/kernel/pci_sun4v.c b/arch/sparc64/kernel/pci_sun4v.c
index 5419480edf41..b69e2270a721 100644
--- a/arch/sparc64/kernel/pci_sun4v.c
+++ b/arch/sparc64/kernel/pci_sun4v.c
@@ -18,6 +18,7 @@
18#include <asm/pstate.h> 18#include <asm/pstate.h>
19#include <asm/oplib.h> 19#include <asm/oplib.h>
20#include <asm/hypervisor.h> 20#include <asm/hypervisor.h>
21#include <asm/prom.h>
21 22
22#include "pci_impl.h" 23#include "pci_impl.h"
23#include "iommu_common.h" 24#include "iommu_common.h"
@@ -646,35 +647,37 @@ static int pdev_htab_add(u32 devhandle, unsigned int bus, unsigned int device, u
646/* Recursively descend into the OBP device tree, rooted at toplevel_node, 647/* Recursively descend into the OBP device tree, rooted at toplevel_node,
647 * looking for a PCI device matching bus and devfn. 648 * looking for a PCI device matching bus and devfn.
648 */ 649 */
649static int obp_find(struct linux_prom_pci_registers *pregs, int toplevel_node, unsigned int bus, unsigned int devfn) 650static int obp_find(struct device_node *toplevel_node, unsigned int bus, unsigned int devfn)
650{ 651{
651 toplevel_node = prom_getchild(toplevel_node); 652 toplevel_node = toplevel_node->child;
652 653
653 while (toplevel_node != 0) { 654 while (toplevel_node != NULL) {
654 int ret = obp_find(pregs, toplevel_node, bus, devfn); 655 struct linux_prom_pci_registers *regs;
656 struct property *prop;
657 int ret;
655 658
659 ret = obp_find(toplevel_node, bus, devfn);
656 if (ret != 0) 660 if (ret != 0)
657 return ret; 661 return ret;
658 662
659 ret = prom_getproperty(toplevel_node, "reg", (char *) pregs, 663 prop = of_find_property(toplevel_node, "reg", NULL);
660 sizeof(*pregs) * PROMREG_MAX); 664 if (!prop)
661 if (ret == 0 || ret == -1)
662 goto next_sibling; 665 goto next_sibling;
663 666
664 if (((pregs[0].phys_hi >> 16) & 0xff) == bus && 667 regs = prop->value;
665 ((pregs[0].phys_hi >> 8) & 0xff) == devfn) 668 if (((regs->phys_hi >> 16) & 0xff) == bus &&
669 ((regs->phys_hi >> 8) & 0xff) == devfn)
666 break; 670 break;
667 671
668 next_sibling: 672 next_sibling:
669 toplevel_node = prom_getsibling(toplevel_node); 673 toplevel_node = toplevel_node->sibling;
670 } 674 }
671 675
672 return toplevel_node; 676 return toplevel_node != NULL;
673} 677}
674 678
675static int pdev_htab_populate(struct pci_pbm_info *pbm) 679static int pdev_htab_populate(struct pci_pbm_info *pbm)
676{ 680{
677 struct linux_prom_pci_registers pr[PROMREG_MAX];
678 u32 devhandle = pbm->devhandle; 681 u32 devhandle = pbm->devhandle;
679 unsigned int bus; 682 unsigned int bus;
680 683
@@ -685,7 +688,7 @@ static int pdev_htab_populate(struct pci_pbm_info *pbm)
685 unsigned int device = PCI_SLOT(devfn); 688 unsigned int device = PCI_SLOT(devfn);
686 unsigned int func = PCI_FUNC(devfn); 689 unsigned int func = PCI_FUNC(devfn);
687 690
688 if (obp_find(pr, pbm->prom_node, bus, devfn)) { 691 if (obp_find(pbm->prom_node, bus, devfn)) {
689 int err = pdev_htab_add(devhandle, bus, 692 int err = pdev_htab_add(devhandle, bus,
690 device, func); 693 device, func);
691 if (err) 694 if (err)
@@ -811,8 +814,7 @@ static void pbm_scan_bus(struct pci_controller_info *p,
811 pci_fixup_host_bridge_self(pbm->pci_bus); 814 pci_fixup_host_bridge_self(pbm->pci_bus);
812 pbm->pci_bus->self->sysdata = cookie; 815 pbm->pci_bus->self->sysdata = cookie;
813#endif 816#endif
814 pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, 817 pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
815 pbm->prom_node);
816 pci_record_assignments(pbm, pbm->pci_bus); 818 pci_record_assignments(pbm, pbm->pci_bus);
817 pci_assign_unassigned(pbm, pbm->pci_bus); 819 pci_assign_unassigned(pbm, pbm->pci_bus);
818 pci_fixup_irq(pbm, pbm->pci_bus); 820 pci_fixup_irq(pbm, pbm->pci_bus);
@@ -822,15 +824,18 @@ static void pbm_scan_bus(struct pci_controller_info *p,
822 824
823static void pci_sun4v_scan_bus(struct pci_controller_info *p) 825static void pci_sun4v_scan_bus(struct pci_controller_info *p)
824{ 826{
825 if (p->pbm_A.prom_node) { 827 struct property *prop;
826 p->pbm_A.is_66mhz_capable = 828 struct device_node *dp;
827 prom_getbool(p->pbm_A.prom_node, "66mhz-capable"); 829
830 if ((dp = p->pbm_A.prom_node) != NULL) {
831 prop = of_find_property(dp, "66mhz-capable", NULL);
832 p->pbm_A.is_66mhz_capable = (prop != NULL);
828 833
829 pbm_scan_bus(p, &p->pbm_A); 834 pbm_scan_bus(p, &p->pbm_A);
830 } 835 }
831 if (p->pbm_B.prom_node) { 836 if ((dp = p->pbm_B.prom_node) != NULL) {
832 p->pbm_B.is_66mhz_capable = 837 prop = of_find_property(dp, "66mhz-capable", NULL);
833 prom_getbool(p->pbm_B.prom_node, "66mhz-capable"); 838 p->pbm_B.is_66mhz_capable = (prop != NULL);
834 839
835 pbm_scan_bus(p, &p->pbm_B); 840 pbm_scan_bus(p, &p->pbm_B);
836 } 841 }
@@ -982,8 +987,13 @@ static unsigned long probe_existing_entries(struct pci_pbm_info *pbm,
982 HV_PCI_TSBID(0, i), 987 HV_PCI_TSBID(0, i),
983 &io_attrs, &ra); 988 &io_attrs, &ra);
984 if (ret == HV_EOK) { 989 if (ret == HV_EOK) {
985 cnt++; 990 if (page_in_phys_avail(ra)) {
986 __set_bit(i, arena->map); 991 pci_sun4v_iommu_demap(devhandle,
992 HV_PCI_TSBID(0, i), 1);
993 } else {
994 cnt++;
995 __set_bit(i, arena->map);
996 }
987 } 997 }
988 } 998 }
989 999
@@ -993,13 +1003,18 @@ static unsigned long probe_existing_entries(struct pci_pbm_info *pbm,
993static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm) 1003static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
994{ 1004{
995 struct pci_iommu *iommu = pbm->iommu; 1005 struct pci_iommu *iommu = pbm->iommu;
1006 struct property *prop;
996 unsigned long num_tsb_entries, sz; 1007 unsigned long num_tsb_entries, sz;
997 u32 vdma[2], dma_mask, dma_offset; 1008 u32 vdma[2], dma_mask, dma_offset;
998 int err, tsbsize; 1009 int tsbsize;
1010
1011 prop = of_find_property(pbm->prom_node, "virtual-dma", NULL);
1012 if (prop) {
1013 u32 *val = prop->value;
999 1014
1000 err = prom_getproperty(pbm->prom_node, "virtual-dma", 1015 vdma[0] = val[0];
1001 (char *)&vdma[0], sizeof(vdma)); 1016 vdma[1] = val[1];
1002 if (err == 0 || err == -1) { 1017 } else {
1003 /* No property, use default values. */ 1018 /* No property, use default values. */
1004 vdma[0] = 0x80000000; 1019 vdma[0] = 0x80000000;
1005 vdma[1] = 0x80000000; 1020 vdma[1] = 0x80000000;
@@ -1051,34 +1066,30 @@ static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
1051 iommu->arena.limit = num_tsb_entries; 1066 iommu->arena.limit = num_tsb_entries;
1052 1067
1053 sz = probe_existing_entries(pbm, iommu); 1068 sz = probe_existing_entries(pbm, iommu);
1054 1069 if (sz)
1055 printk("%s: TSB entries [%lu], existing mapings [%lu]\n", 1070 printk("%s: Imported %lu TSB entries from OBP\n",
1056 pbm->name, num_tsb_entries, sz); 1071 pbm->name, sz);
1057} 1072}
1058 1073
1059static void pci_sun4v_get_bus_range(struct pci_pbm_info *pbm) 1074static void pci_sun4v_get_bus_range(struct pci_pbm_info *pbm)
1060{ 1075{
1061 unsigned int busrange[2]; 1076 struct property *prop;
1062 int prom_node = pbm->prom_node; 1077 unsigned int *busrange;
1063 int err; 1078
1064 1079 prop = of_find_property(pbm->prom_node, "bus-range", NULL);
1065 err = prom_getproperty(prom_node, "bus-range", 1080
1066 (char *)&busrange[0], 1081 busrange = prop->value;
1067 sizeof(busrange));
1068 if (err == 0 || err == -1) {
1069 prom_printf("%s: Fatal error, no bus-range.\n", pbm->name);
1070 prom_halt();
1071 }
1072 1082
1073 pbm->pci_first_busno = busrange[0]; 1083 pbm->pci_first_busno = busrange[0];
1074 pbm->pci_last_busno = busrange[1]; 1084 pbm->pci_last_busno = busrange[1];
1075 1085
1076} 1086}
1077 1087
1078static void pci_sun4v_pbm_init(struct pci_controller_info *p, int prom_node, u32 devhandle) 1088static void pci_sun4v_pbm_init(struct pci_controller_info *p, struct device_node *dp, u32 devhandle)
1079{ 1089{
1080 struct pci_pbm_info *pbm; 1090 struct pci_pbm_info *pbm;
1081 int err, i; 1091 struct property *prop;
1092 int len, i;
1082 1093
1083 if (devhandle & 0x40) 1094 if (devhandle & 0x40)
1084 pbm = &p->pbm_B; 1095 pbm = &p->pbm_B;
@@ -1086,32 +1097,19 @@ static void pci_sun4v_pbm_init(struct pci_controller_info *p, int prom_node, u32
1086 pbm = &p->pbm_A; 1097 pbm = &p->pbm_A;
1087 1098
1088 pbm->parent = p; 1099 pbm->parent = p;
1089 pbm->prom_node = prom_node; 1100 pbm->prom_node = dp;
1090 pbm->pci_first_slot = 1; 1101 pbm->pci_first_slot = 1;
1091 1102
1092 pbm->devhandle = devhandle; 1103 pbm->devhandle = devhandle;
1093 1104
1094 sprintf(pbm->name, "SUN4V-PCI%d PBM%c", 1105 pbm->name = dp->full_name;
1095 p->index, (pbm == &p->pbm_A ? 'A' : 'B'));
1096 1106
1097 printk("%s: devhandle[%x] prom_node[%x:%x]\n", 1107 printk("%s: SUN4V PCI Bus Module\n", pbm->name);
1098 pbm->name, pbm->devhandle,
1099 pbm->prom_node, prom_getchild(pbm->prom_node));
1100
1101 prom_getstring(prom_node, "name",
1102 pbm->prom_name, sizeof(pbm->prom_name));
1103
1104 err = prom_getproperty(prom_node, "ranges",
1105 (char *) pbm->pbm_ranges,
1106 sizeof(pbm->pbm_ranges));
1107 if (err == 0 || err == -1) {
1108 prom_printf("%s: Fatal error, no ranges property.\n",
1109 pbm->name);
1110 prom_halt();
1111 }
1112 1108
1109 prop = of_find_property(dp, "ranges", &len);
1110 pbm->pbm_ranges = prop->value;
1113 pbm->num_pbm_ranges = 1111 pbm->num_pbm_ranges =
1114 (err / sizeof(struct linux_prom_pci_ranges)); 1112 (len / sizeof(struct linux_prom_pci_ranges));
1115 1113
1116 /* Mask out the top 8 bits of the ranges, leaving the real 1114 /* Mask out the top 8 bits of the ranges, leaving the real
1117 * physical address. 1115 * physical address.
@@ -1122,24 +1120,13 @@ static void pci_sun4v_pbm_init(struct pci_controller_info *p, int prom_node, u32
1122 pci_sun4v_determine_mem_io_space(pbm); 1120 pci_sun4v_determine_mem_io_space(pbm);
1123 pbm_register_toplevel_resources(p, pbm); 1121 pbm_register_toplevel_resources(p, pbm);
1124 1122
1125 err = prom_getproperty(prom_node, "interrupt-map", 1123 prop = of_find_property(dp, "interrupt-map", &len);
1126 (char *)pbm->pbm_intmap, 1124 pbm->pbm_intmap = prop->value;
1127 sizeof(pbm->pbm_intmap)); 1125 pbm->num_pbm_intmap =
1128 if (err == 0 || err == -1) { 1126 (len / sizeof(struct linux_prom_pci_intmap));
1129 prom_printf("%s: Fatal error, no interrupt-map property.\n",
1130 pbm->name);
1131 prom_halt();
1132 }
1133 1127
1134 pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap)); 1128 prop = of_find_property(dp, "interrupt-map-mask", NULL);
1135 err = prom_getproperty(prom_node, "interrupt-map-mask", 1129 pbm->pbm_intmask = prop->value;
1136 (char *)&pbm->pbm_intmask,
1137 sizeof(pbm->pbm_intmask));
1138 if (err == 0 || err == -1) {
1139 prom_printf("%s: Fatal error, no interrupt-map-mask.\n",
1140 pbm->name);
1141 prom_halt();
1142 }
1143 1130
1144 pci_sun4v_get_bus_range(pbm); 1131 pci_sun4v_get_bus_range(pbm);
1145 pci_sun4v_iommu_init(pbm); 1132 pci_sun4v_iommu_init(pbm);
@@ -1147,16 +1134,19 @@ static void pci_sun4v_pbm_init(struct pci_controller_info *p, int prom_node, u32
1147 pdev_htab_populate(pbm); 1134 pdev_htab_populate(pbm);
1148} 1135}
1149 1136
1150void sun4v_pci_init(int node, char *model_name) 1137void sun4v_pci_init(struct device_node *dp, char *model_name)
1151{ 1138{
1152 struct pci_controller_info *p; 1139 struct pci_controller_info *p;
1153 struct pci_iommu *iommu; 1140 struct pci_iommu *iommu;
1154 struct linux_prom64_registers regs; 1141 struct property *prop;
1142 struct linux_prom64_registers *regs;
1155 u32 devhandle; 1143 u32 devhandle;
1156 int i; 1144 int i;
1157 1145
1158 prom_getproperty(node, "reg", (char *)&regs, sizeof(regs)); 1146 prop = of_find_property(dp, "reg", NULL);
1159 devhandle = (regs.phys_addr >> 32UL) & 0x0fffffff; 1147 regs = prop->value;
1148
1149 devhandle = (regs->phys_addr >> 32UL) & 0x0fffffff;
1160 1150
1161 for (p = pci_controller_root; p; p = p->next) { 1151 for (p = pci_controller_root; p; p = p->next) {
1162 struct pci_pbm_info *pbm; 1152 struct pci_pbm_info *pbm;
@@ -1169,7 +1159,7 @@ void sun4v_pci_init(int node, char *model_name)
1169 &p->pbm_B); 1159 &p->pbm_B);
1170 1160
1171 if (pbm->devhandle == (devhandle ^ 0x40)) { 1161 if (pbm->devhandle == (devhandle ^ 0x40)) {
1172 pci_sun4v_pbm_init(p, node, devhandle); 1162 pci_sun4v_pbm_init(p, dp, devhandle);
1173 return; 1163 return;
1174 } 1164 }
1175 } 1165 }
@@ -1220,7 +1210,7 @@ void sun4v_pci_init(int node, char *model_name)
1220 */ 1210 */
1221 pci_memspace_mask = 0x7fffffffUL; 1211 pci_memspace_mask = 0x7fffffffUL;
1222 1212
1223 pci_sun4v_pbm_init(p, node, devhandle); 1213 pci_sun4v_pbm_init(p, dp, devhandle);
1224 return; 1214 return;
1225 1215
1226fatal_memory_error: 1216fatal_memory_error:
diff --git a/arch/sparc64/kernel/power.c b/arch/sparc64/kernel/power.c
index 30bcaf58e3ab..9496c7734014 100644
--- a/arch/sparc64/kernel/power.c
+++ b/arch/sparc64/kernel/power.c
@@ -105,76 +105,25 @@ again:
105 return 0; 105 return 0;
106} 106}
107 107
108static int __init has_button_interrupt(unsigned int irq, int prom_node) 108static int __init has_button_interrupt(unsigned int irq, struct device_node *dp)
109{ 109{
110 if (irq == PCI_IRQ_NONE) 110 if (irq == PCI_IRQ_NONE)
111 return 0; 111 return 0;
112 if (!prom_node_has_property(prom_node, "button")) 112 if (!of_find_property(dp, "button", NULL))
113 return 0; 113 return 0;
114 114
115 return 1; 115 return 1;
116} 116}
117 117
118static int __init power_probe_ebus(struct resource **resp, unsigned int *irq_p, int *prom_node_p) 118static void __devinit power_probe_common(struct of_device *dev, struct resource *res, unsigned int irq)
119{ 119{
120 struct linux_ebus *ebus;
121 struct linux_ebus_device *edev;
122
123 for_each_ebus(ebus) {
124 for_each_ebusdev(edev, ebus) {
125 if (!strcmp(edev->prom_name, "power")) {
126 *resp = &edev->resource[0];
127 *irq_p = edev->irqs[0];
128 *prom_node_p = edev->prom_node;
129 return 0;
130 }
131 }
132 }
133 return -ENODEV;
134}
135
136static int __init power_probe_isa(struct resource **resp, unsigned int *irq_p, int *prom_node_p)
137{
138 struct sparc_isa_bridge *isa_bus;
139 struct sparc_isa_device *isa_dev;
140
141 for_each_isa(isa_bus) {
142 for_each_isadev(isa_dev, isa_bus) {
143 if (!strcmp(isa_dev->prom_name, "power")) {
144 *resp = &isa_dev->resource;
145 *irq_p = isa_dev->irq;
146 *prom_node_p = isa_dev->prom_node;
147 return 0;
148 }
149 }
150 }
151 return -ENODEV;
152}
153
154void __init power_init(void)
155{
156 struct resource *res = NULL;
157 unsigned int irq;
158 int prom_node;
159 static int invoked;
160
161 if (invoked)
162 return;
163 invoked = 1;
164
165 if (!power_probe_ebus(&res, &irq, &prom_node))
166 goto found;
167
168 if (!power_probe_isa(&res, &irq, &prom_node))
169 goto found;
170
171 return;
172
173found:
174 power_reg = ioremap(res->start, 0x4); 120 power_reg = ioremap(res->start, 0x4);
121
175 printk("power: Control reg at %p ... ", power_reg); 122 printk("power: Control reg at %p ... ", power_reg);
123
176 poweroff_method = machine_halt; /* able to use the standard halt */ 124 poweroff_method = machine_halt; /* able to use the standard halt */
177 if (has_button_interrupt(irq, prom_node)) { 125
126 if (has_button_interrupt(irq, dev->node)) {
178 if (kernel_thread(powerd, NULL, CLONE_FS) < 0) { 127 if (kernel_thread(powerd, NULL, CLONE_FS) < 0) {
179 printk("Failed to start power daemon.\n"); 128 printk("Failed to start power daemon.\n");
180 return; 129 return;
@@ -188,4 +137,52 @@ found:
188 printk("not using powerd.\n"); 137 printk("not using powerd.\n");
189 } 138 }
190} 139}
140
141static struct of_device_id power_match[] = {
142 {
143 .name = "power",
144 },
145 {},
146};
147
148static int __devinit ebus_power_probe(struct of_device *dev, const struct of_device_id *match)
149{
150 struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
151 struct resource *res = &edev->resource[0];
152 unsigned int irq = edev->irqs[0];
153
154 power_probe_common(dev, res,irq);
155
156 return 0;
157}
158
159static struct of_platform_driver ebus_power_driver = {
160 .name = "power",
161 .match_table = power_match,
162 .probe = ebus_power_probe,
163};
164
165static int __devinit isa_power_probe(struct of_device *dev, const struct of_device_id *match)
166{
167 struct sparc_isa_device *idev = to_isa_device(&dev->dev);
168 struct resource *res = &idev->resource;
169 unsigned int irq = idev->irq;
170
171 power_probe_common(dev, res,irq);
172
173 return 0;
174}
175
176static struct of_platform_driver isa_power_driver = {
177 .name = "power",
178 .match_table = power_match,
179 .probe = isa_power_probe,
180};
181
182void __init power_init(void)
183{
184 of_register_driver(&ebus_power_driver, &ebus_bus_type);
185 of_register_driver(&isa_power_driver, &isa_bus_type);
186 return;
187}
191#endif /* CONFIG_PCI */ 188#endif /* CONFIG_PCI */
diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c
new file mode 100644
index 000000000000..e9d703eea806
--- /dev/null
+++ b/arch/sparc64/kernel/prom.c
@@ -0,0 +1,650 @@
1/*
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>
22#include <linux/bootmem.h>
23#include <linux/module.h>
24
25#include <asm/prom.h>
26#include <asm/oplib.h>
27
28static struct device_node *allnodes;
29
30int of_device_is_compatible(struct device_node *device, const char *compat)
31{
32 const char* cp;
33 int cplen, l;
34
35 cp = (char *) of_get_property(device, "compatible", &cplen);
36 if (cp == NULL)
37 return 0;
38 while (cplen > 0) {
39 if (strncmp(cp, compat, strlen(compat)) == 0)
40 return 1;
41 l = strlen(cp) + 1;
42 cp += l;
43 cplen -= l;
44 }
45
46 return 0;
47}
48EXPORT_SYMBOL(of_device_is_compatible);
49
50struct device_node *of_get_parent(const struct device_node *node)
51{
52 struct device_node *np;
53
54 if (!node)
55 return NULL;
56
57 np = node->parent;
58
59 return np;
60}
61EXPORT_SYMBOL(of_get_parent);
62
63struct device_node *of_get_next_child(const struct device_node *node,
64 struct device_node *prev)
65{
66 struct device_node *next;
67
68 next = prev ? prev->sibling : node->child;
69 for (; next != 0; next = next->sibling) {
70 break;
71 }
72
73 return next;
74}
75EXPORT_SYMBOL(of_get_next_child);
76
77struct device_node *of_find_node_by_path(const char *path)
78{
79 struct device_node *np = allnodes;
80
81 for (; np != 0; np = np->allnext) {
82 if (np->full_name != 0 && strcmp(np->full_name, path) == 0)
83 break;
84 }
85
86 return np;
87}
88EXPORT_SYMBOL(of_find_node_by_path);
89
90struct device_node *of_find_node_by_phandle(phandle handle)
91{
92 struct device_node *np;
93
94 for (np = allnodes; np != 0; np = np->allnext)
95 if (np->node == handle)
96 break;
97
98 return np;
99}
100EXPORT_SYMBOL(of_find_node_by_phandle);
101
102struct device_node *of_find_node_by_name(struct device_node *from,
103 const char *name)
104{
105 struct device_node *np;
106
107 np = from ? from->allnext : allnodes;
108 for (; np != NULL; np = np->allnext)
109 if (np->name != NULL && strcmp(np->name, name) == 0)
110 break;
111
112 return np;
113}
114EXPORT_SYMBOL(of_find_node_by_name);
115
116struct device_node *of_find_node_by_type(struct device_node *from,
117 const char *type)
118{
119 struct device_node *np;
120
121 np = from ? from->allnext : allnodes;
122 for (; np != 0; np = np->allnext)
123 if (np->type != 0 && strcmp(np->type, type) == 0)
124 break;
125
126 return np;
127}
128EXPORT_SYMBOL(of_find_node_by_type);
129
130struct device_node *of_find_compatible_node(struct device_node *from,
131 const char *type, const char *compatible)
132{
133 struct device_node *np;
134
135 np = from ? from->allnext : allnodes;
136 for (; np != 0; np = np->allnext) {
137 if (type != NULL
138 && !(np->type != 0 && strcmp(np->type, type) == 0))
139 continue;
140 if (of_device_is_compatible(np, compatible))
141 break;
142 }
143
144 return np;
145}
146EXPORT_SYMBOL(of_find_compatible_node);
147
148struct property *of_find_property(struct device_node *np, const char *name,
149 int *lenp)
150{
151 struct property *pp;
152
153 for (pp = np->properties; pp != 0; pp = pp->next) {
154 if (strcmp(pp->name, name) == 0) {
155 if (lenp != 0)
156 *lenp = pp->length;
157 break;
158 }
159 }
160 return pp;
161}
162EXPORT_SYMBOL(of_find_property);
163
164/*
165 * Find a property with a given name for a given node
166 * and return the value.
167 */
168void *of_get_property(struct device_node *np, const char *name, int *lenp)
169{
170 struct property *pp = of_find_property(np,name,lenp);
171 return pp ? pp->value : NULL;
172}
173EXPORT_SYMBOL(of_get_property);
174
175int of_getintprop_default(struct device_node *np, const char *name, int def)
176{
177 struct property *prop;
178 int len;
179
180 prop = of_find_property(np, name, &len);
181 if (!prop || len != 4)
182 return def;
183
184 return *(int *) prop->value;
185}
186EXPORT_SYMBOL(of_getintprop_default);
187
188static unsigned int prom_early_allocated;
189
190static void * __init prom_early_alloc(unsigned long size)
191{
192 void *ret;
193
194 ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
195 if (ret != NULL)
196 memset(ret, 0, size);
197
198 prom_early_allocated += size;
199
200 return ret;
201}
202
203static int is_root_node(const struct device_node *dp)
204{
205 if (!dp)
206 return 0;
207
208 return (dp->parent == NULL);
209}
210
211/* The following routines deal with the black magic of fully naming a
212 * node.
213 *
214 * Certain well known named nodes are just the simple name string.
215 *
216 * Actual devices have an address specifier appended to the base name
217 * string, like this "foo@addr". The "addr" can be in any number of
218 * formats, and the platform plus the type of the node determine the
219 * format and how it is constructed.
220 *
221 * For children of the ROOT node, the naming convention is fixed and
222 * determined by whether this is a sun4u or sun4v system.
223 *
224 * For children of other nodes, it is bus type specific. So
225 * we walk up the tree until we discover a "device_type" property
226 * we recognize and we go from there.
227 *
228 * As an example, the boot device on my workstation has a full path:
229 *
230 * /pci@1e,600000/ide@d/disk@0,0:c
231 */
232static void __init sun4v_path_component(struct device_node *dp, char *tmp_buf)
233{
234 struct linux_prom64_registers *regs;
235 struct property *rprop;
236 u32 high_bits, low_bits, type;
237
238 rprop = of_find_property(dp, "reg", NULL);
239 if (!rprop)
240 return;
241
242 regs = rprop->value;
243 if (!is_root_node(dp->parent)) {
244 sprintf(tmp_buf, "%s@%x,%x",
245 dp->name,
246 (unsigned int) (regs->phys_addr >> 32UL),
247 (unsigned int) (regs->phys_addr & 0xffffffffUL));
248 return;
249 }
250
251 type = regs->phys_addr >> 60UL;
252 high_bits = (regs->phys_addr >> 32UL) & 0x0fffffffUL;
253 low_bits = (regs->phys_addr & 0xffffffffUL);
254
255 if (type == 0 || type == 8) {
256 const char *prefix = (type == 0) ? "m" : "i";
257
258 if (low_bits)
259 sprintf(tmp_buf, "%s@%s%x,%x",
260 dp->name, prefix,
261 high_bits, low_bits);
262 else
263 sprintf(tmp_buf, "%s@%s%x",
264 dp->name,
265 prefix,
266 high_bits);
267 } else if (type == 12) {
268 sprintf(tmp_buf, "%s@%x",
269 dp->name, high_bits);
270 }
271}
272
273static void __init sun4u_path_component(struct device_node *dp, char *tmp_buf)
274{
275 struct linux_prom64_registers *regs;
276 struct property *prop;
277
278 prop = of_find_property(dp, "reg", NULL);
279 if (!prop)
280 return;
281
282 regs = prop->value;
283 if (!is_root_node(dp->parent)) {
284 sprintf(tmp_buf, "%s@%x,%x",
285 dp->name,
286 (unsigned int) (regs->phys_addr >> 32UL),
287 (unsigned int) (regs->phys_addr & 0xffffffffUL));
288 return;
289 }
290
291 prop = of_find_property(dp, "upa-portid", NULL);
292 if (!prop)
293 prop = of_find_property(dp, "portid", NULL);
294 if (prop) {
295 unsigned long mask = 0xffffffffUL;
296
297 if (tlb_type >= cheetah)
298 mask = 0x7fffff;
299
300 sprintf(tmp_buf, "%s@%x,%x",
301 dp->name,
302 *(u32 *)prop->value,
303 (unsigned int) (regs->phys_addr & mask));
304 }
305}
306
307/* "name@slot,offset" */
308static void __init sbus_path_component(struct device_node *dp, char *tmp_buf)
309{
310 struct linux_prom_registers *regs;
311 struct property *prop;
312
313 prop = of_find_property(dp, "reg", NULL);
314 if (!prop)
315 return;
316
317 regs = prop->value;
318 sprintf(tmp_buf, "%s@%x,%x",
319 dp->name,
320 regs->which_io,
321 regs->phys_addr);
322}
323
324/* "name@devnum[,func]" */
325static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
326{
327 struct linux_prom_pci_registers *regs;
328 struct property *prop;
329 unsigned int devfn;
330
331 prop = of_find_property(dp, "reg", NULL);
332 if (!prop)
333 return;
334
335 regs = prop->value;
336 devfn = (regs->phys_hi >> 8) & 0xff;
337 if (devfn & 0x07) {
338 sprintf(tmp_buf, "%s@%x,%x",
339 dp->name,
340 devfn >> 3,
341 devfn & 0x07);
342 } else {
343 sprintf(tmp_buf, "%s@%x",
344 dp->name,
345 devfn >> 3);
346 }
347}
348
349/* "name@UPA_PORTID,offset" */
350static void __init upa_path_component(struct device_node *dp, char *tmp_buf)
351{
352 struct linux_prom64_registers *regs;
353 struct property *prop;
354
355 prop = of_find_property(dp, "reg", NULL);
356 if (!prop)
357 return;
358
359 regs = prop->value;
360
361 prop = of_find_property(dp, "upa-portid", NULL);
362 if (!prop)
363 return;
364
365 sprintf(tmp_buf, "%s@%x,%x",
366 dp->name,
367 *(u32 *) prop->value,
368 (unsigned int) (regs->phys_addr & 0xffffffffUL));
369}
370
371/* "name@reg" */
372static void __init vdev_path_component(struct device_node *dp, char *tmp_buf)
373{
374 struct property *prop;
375 u32 *regs;
376
377 prop = of_find_property(dp, "reg", NULL);
378 if (!prop)
379 return;
380
381 regs = prop->value;
382
383 sprintf(tmp_buf, "%s@%x", dp->name, *regs);
384}
385
386/* "name@addrhi,addrlo" */
387static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
388{
389 struct linux_prom64_registers *regs;
390 struct property *prop;
391
392 prop = of_find_property(dp, "reg", NULL);
393 if (!prop)
394 return;
395
396 regs = prop->value;
397
398 sprintf(tmp_buf, "%s@%x,%x",
399 dp->name,
400 (unsigned int) (regs->phys_addr >> 32UL),
401 (unsigned int) (regs->phys_addr & 0xffffffffUL));
402}
403
404/* "name@bus,addr" */
405static void __init i2c_path_component(struct device_node *dp, char *tmp_buf)
406{
407 struct property *prop;
408 u32 *regs;
409
410 prop = of_find_property(dp, "reg", NULL);
411 if (!prop)
412 return;
413
414 regs = prop->value;
415
416 /* This actually isn't right... should look at the #address-cells
417 * property of the i2c bus node etc. etc.
418 */
419 sprintf(tmp_buf, "%s@%x,%x",
420 dp->name, regs[0], regs[1]);
421}
422
423/* "name@reg0[,reg1]" */
424static void __init usb_path_component(struct device_node *dp, char *tmp_buf)
425{
426 struct property *prop;
427 u32 *regs;
428
429 prop = of_find_property(dp, "reg", NULL);
430 if (!prop)
431 return;
432
433 regs = prop->value;
434
435 if (prop->length == sizeof(u32) || regs[1] == 1) {
436 sprintf(tmp_buf, "%s@%x",
437 dp->name, regs[0]);
438 } else {
439 sprintf(tmp_buf, "%s@%x,%x",
440 dp->name, regs[0], regs[1]);
441 }
442}
443
444/* "name@reg0reg1[,reg2reg3]" */
445static void __init ieee1394_path_component(struct device_node *dp, char *tmp_buf)
446{
447 struct property *prop;
448 u32 *regs;
449
450 prop = of_find_property(dp, "reg", NULL);
451 if (!prop)
452 return;
453
454 regs = prop->value;
455
456 if (regs[2] || regs[3]) {
457 sprintf(tmp_buf, "%s@%08x%08x,%04x%08x",
458 dp->name, regs[0], regs[1], regs[2], regs[3]);
459 } else {
460 sprintf(tmp_buf, "%s@%08x%08x",
461 dp->name, regs[0], regs[1]);
462 }
463}
464
465static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
466{
467 struct device_node *parent = dp->parent;
468
469 if (parent != NULL) {
470 if (!strcmp(parent->type, "pci") ||
471 !strcmp(parent->type, "pciex"))
472 return pci_path_component(dp, tmp_buf);
473 if (!strcmp(parent->type, "sbus"))
474 return sbus_path_component(dp, tmp_buf);
475 if (!strcmp(parent->type, "upa"))
476 return upa_path_component(dp, tmp_buf);
477 if (!strcmp(parent->type, "ebus"))
478 return ebus_path_component(dp, tmp_buf);
479 if (!strcmp(parent->name, "usb") ||
480 !strcmp(parent->name, "hub"))
481 return usb_path_component(dp, tmp_buf);
482 if (!strcmp(parent->type, "i2c"))
483 return i2c_path_component(dp, tmp_buf);
484 if (!strcmp(parent->type, "firewire"))
485 return ieee1394_path_component(dp, tmp_buf);
486 if (!strcmp(parent->type, "virtual-devices"))
487 return vdev_path_component(dp, tmp_buf);
488
489 /* "isa" is handled with platform naming */
490 }
491
492 /* Use platform naming convention. */
493 if (tlb_type == hypervisor)
494 return sun4v_path_component(dp, tmp_buf);
495 else
496 return sun4u_path_component(dp, tmp_buf);
497}
498
499static char * __init build_path_component(struct device_node *dp)
500{
501 char tmp_buf[64], *n;
502
503 tmp_buf[0] = '\0';
504 __build_path_component(dp, tmp_buf);
505 if (tmp_buf[0] == '\0')
506 strcpy(tmp_buf, dp->name);
507
508 n = prom_early_alloc(strlen(tmp_buf) + 1);
509 strcpy(n, tmp_buf);
510
511 return n;
512}
513
514static char * __init build_full_name(struct device_node *dp)
515{
516 int len, ourlen, plen;
517 char *n;
518
519 plen = strlen(dp->parent->full_name);
520 ourlen = strlen(dp->path_component_name);
521 len = ourlen + plen + 2;
522
523 n = prom_early_alloc(len);
524 strcpy(n, dp->parent->full_name);
525 if (!is_root_node(dp->parent)) {
526 strcpy(n + plen, "/");
527 plen++;
528 }
529 strcpy(n + plen, dp->path_component_name);
530
531 return n;
532}
533
534static struct property * __init build_one_prop(phandle node, char *prev)
535{
536 static struct property *tmp = NULL;
537 struct property *p;
538
539 if (tmp) {
540 p = tmp;
541 memset(p, 0, sizeof(*p) + 32);
542 tmp = NULL;
543 } else
544 p = prom_early_alloc(sizeof(struct property) + 32);
545
546 p->name = (char *) (p + 1);
547 if (prev == NULL) {
548 prom_firstprop(node, p->name);
549 } else {
550 prom_nextprop(node, prev, p->name);
551 }
552 if (strlen(p->name) == 0) {
553 tmp = p;
554 return NULL;
555 }
556 p->length = prom_getproplen(node, p->name);
557 if (p->length <= 0) {
558 p->length = 0;
559 } else {
560 p->value = prom_early_alloc(p->length);
561 prom_getproperty(node, p->name, p->value, p->length);
562 }
563 return p;
564}
565
566static struct property * __init build_prop_list(phandle node)
567{
568 struct property *head, *tail;
569
570 head = tail = build_one_prop(node, NULL);
571 while(tail) {
572 tail->next = build_one_prop(node, tail->name);
573 tail = tail->next;
574 }
575
576 return head;
577}
578
579static char * __init get_one_property(phandle node, const char *name)
580{
581 char *buf = "<NULL>";
582 int len;
583
584 len = prom_getproplen(node, name);
585 if (len > 0) {
586 buf = prom_early_alloc(len);
587 prom_getproperty(node, name, buf, len);
588 }
589
590 return buf;
591}
592
593static struct device_node * __init create_node(phandle node)
594{
595 struct device_node *dp;
596
597 if (!node)
598 return NULL;
599
600 dp = prom_early_alloc(sizeof(*dp));
601
602 kref_init(&dp->kref);
603
604 dp->name = get_one_property(node, "name");
605 dp->type = get_one_property(node, "device_type");
606 dp->node = node;
607
608 /* Build interrupts later... */
609
610 dp->properties = build_prop_list(node);
611
612 return dp;
613}
614
615static struct device_node * __init build_tree(struct device_node *parent, phandle node, struct device_node ***nextp)
616{
617 struct device_node *dp;
618
619 dp = create_node(node);
620 if (dp) {
621 *(*nextp) = dp;
622 *nextp = &dp->allnext;
623
624 dp->parent = parent;
625 dp->path_component_name = build_path_component(dp);
626 dp->full_name = build_full_name(dp);
627
628 dp->child = build_tree(dp, prom_getchild(node), nextp);
629
630 dp->sibling = build_tree(parent, prom_getsibling(node), nextp);
631 }
632
633 return dp;
634}
635
636void __init prom_build_devicetree(void)
637{
638 struct device_node **nextp;
639
640 allnodes = create_node(prom_root_node);
641 allnodes->path_component_name = "";
642 allnodes->full_name = "/";
643
644 nextp = &allnodes->allnext;
645 allnodes->child = build_tree(allnodes,
646 prom_getchild(allnodes->node),
647 &nextp);
648 printk("PROM: Built device tree with %u bytes of memory.\n",
649 prom_early_allocated);
650}
diff --git a/arch/sparc64/kernel/sbus.c b/arch/sparc64/kernel/sbus.c
index 8812417247d4..ac05e0f692ef 100644
--- a/arch/sparc64/kernel/sbus.c
+++ b/arch/sparc64/kernel/sbus.c
@@ -19,6 +19,7 @@
19#include <asm/cache.h> 19#include <asm/cache.h>
20#include <asm/dma.h> 20#include <asm/dma.h>
21#include <asm/irq.h> 21#include <asm/irq.h>
22#include <asm/prom.h>
22#include <asm/starfire.h> 23#include <asm/starfire.h>
23 24
24#include "iommu_common.h" 25#include "iommu_common.h"
@@ -1098,24 +1099,25 @@ static void __init sysio_register_error_handlers(struct sbus_bus *sbus)
1098} 1099}
1099 1100
1100/* Boot time initialization. */ 1101/* Boot time initialization. */
1101void __init sbus_iommu_init(int prom_node, struct sbus_bus *sbus) 1102static void __init sbus_iommu_init(int __node, struct sbus_bus *sbus)
1102{ 1103{
1103 struct linux_prom64_registers rprop; 1104 struct linux_prom64_registers *pr;
1105 struct device_node *dp;
1104 struct sbus_iommu *iommu; 1106 struct sbus_iommu *iommu;
1105 unsigned long regs, tsb_base; 1107 unsigned long regs, tsb_base;
1106 u64 control; 1108 u64 control;
1107 int err, i; 1109 int i;
1110
1111 dp = of_find_node_by_phandle(__node);
1108 1112
1109 sbus->portid = prom_getintdefault(sbus->prom_node, 1113 sbus->portid = of_getintprop_default(dp, "upa-portid", -1);
1110 "upa-portid", -1);
1111 1114
1112 err = prom_getproperty(prom_node, "reg", 1115 pr = of_get_property(dp, "reg", NULL);
1113 (char *)&rprop, sizeof(rprop)); 1116 if (!pr) {
1114 if (err < 0) {
1115 prom_printf("sbus_iommu_init: Cannot map SYSIO control registers.\n"); 1117 prom_printf("sbus_iommu_init: Cannot map SYSIO control registers.\n");
1116 prom_halt(); 1118 prom_halt();
1117 } 1119 }
1118 regs = rprop.phys_addr; 1120 regs = pr->phys_addr;
1119 1121
1120 iommu = kmalloc(sizeof(*iommu) + SMP_CACHE_BYTES, GFP_ATOMIC); 1122 iommu = kmalloc(sizeof(*iommu) + SMP_CACHE_BYTES, GFP_ATOMIC);
1121 if (iommu == NULL) { 1123 if (iommu == NULL) {
@@ -1225,3 +1227,50 @@ void __init sbus_iommu_init(int prom_node, struct sbus_bus *sbus)
1225 1227
1226 sysio_register_error_handlers(sbus); 1228 sysio_register_error_handlers(sbus);
1227} 1229}
1230
1231void sbus_fill_device_irq(struct sbus_dev *sdev)
1232{
1233 struct device_node *dp = of_find_node_by_phandle(sdev->prom_node);
1234 struct linux_prom_irqs *irqs;
1235
1236 irqs = of_get_property(dp, "interrupts", NULL);
1237 if (!irqs) {
1238 sdev->irqs[0] = 0;
1239 sdev->num_irqs = 0;
1240 } else {
1241 unsigned int pri = irqs[0].pri;
1242
1243 sdev->num_irqs = 1;
1244 if (pri < 0x20)
1245 pri += sdev->slot * 8;
1246
1247 sdev->irqs[0] = sbus_build_irq(sdev->bus, pri);
1248 }
1249}
1250
1251void __init sbus_arch_bus_ranges_init(struct device_node *pn, struct sbus_bus *sbus)
1252{
1253}
1254
1255void __init sbus_setup_iommu(struct sbus_bus *sbus, struct device_node *dp)
1256{
1257 sbus_iommu_init(dp->node, sbus);
1258}
1259
1260void __init sbus_setup_arch_props(struct sbus_bus *sbus, struct device_node *dp)
1261{
1262}
1263
1264int __init sbus_arch_preinit(void)
1265{
1266 return 0;
1267}
1268
1269void __init sbus_arch_postinit(void)
1270{
1271 extern void firetruck_init(void);
1272 extern void clock_probe(void);
1273
1274 firetruck_init();
1275 clock_probe();
1276}
diff --git a/arch/sparc64/kernel/setup.c b/arch/sparc64/kernel/setup.c
index 9cf1c88cd774..a6a7d8168346 100644
--- a/arch/sparc64/kernel/setup.c
+++ b/arch/sparc64/kernel/setup.c
@@ -376,12 +376,12 @@ void __init setup_arch(char **cmdline_p)
376 } 376 }
377#endif 377#endif
378 378
379 smp_setup_cpu_possible_map();
380
381 /* Get boot processor trap_block[] setup. */ 379 /* Get boot processor trap_block[] setup. */
382 init_cur_cpu_trap(current_thread_info()); 380 init_cur_cpu_trap(current_thread_info());
383 381
384 paging_init(); 382 paging_init();
383
384 smp_setup_cpu_possible_map();
385} 385}
386 386
387static int __init set_preferred_console(void) 387static int __init set_preferred_console(void)
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c
index f03d52d0b88d..f62bf3a2de1a 100644
--- a/arch/sparc64/kernel/smp.c
+++ b/arch/sparc64/kernel/smp.c
@@ -39,6 +39,7 @@
39#include <asm/starfire.h> 39#include <asm/starfire.h>
40#include <asm/tlb.h> 40#include <asm/tlb.h>
41#include <asm/sections.h> 41#include <asm/sections.h>
42#include <asm/prom.h>
42 43
43extern void calibrate_delay(void); 44extern void calibrate_delay(void);
44 45
@@ -76,41 +77,42 @@ void smp_bogo(struct seq_file *m)
76 77
77void __init smp_store_cpu_info(int id) 78void __init smp_store_cpu_info(int id)
78{ 79{
79 int cpu_node, def; 80 struct device_node *dp;
81 int def;
80 82
81 /* multiplier and counter set by 83 /* multiplier and counter set by
82 smp_setup_percpu_timer() */ 84 smp_setup_percpu_timer() */
83 cpu_data(id).udelay_val = loops_per_jiffy; 85 cpu_data(id).udelay_val = loops_per_jiffy;
84 86
85 cpu_find_by_mid(id, &cpu_node); 87 cpu_find_by_mid(id, &dp);
86 cpu_data(id).clock_tick = prom_getintdefault(cpu_node, 88 cpu_data(id).clock_tick =
87 "clock-frequency", 0); 89 of_getintprop_default(dp, "clock-frequency", 0);
88 90
89 def = ((tlb_type == hypervisor) ? (8 * 1024) : (16 * 1024)); 91 def = ((tlb_type == hypervisor) ? (8 * 1024) : (16 * 1024));
90 cpu_data(id).dcache_size = prom_getintdefault(cpu_node, "dcache-size", 92 cpu_data(id).dcache_size =
91 def); 93 of_getintprop_default(dp, "dcache-size", def);
92 94
93 def = 32; 95 def = 32;
94 cpu_data(id).dcache_line_size = 96 cpu_data(id).dcache_line_size =
95 prom_getintdefault(cpu_node, "dcache-line-size", def); 97 of_getintprop_default(dp, "dcache-line-size", def);
96 98
97 def = 16 * 1024; 99 def = 16 * 1024;
98 cpu_data(id).icache_size = prom_getintdefault(cpu_node, "icache-size", 100 cpu_data(id).icache_size =
99 def); 101 of_getintprop_default(dp, "icache-size", def);
100 102
101 def = 32; 103 def = 32;
102 cpu_data(id).icache_line_size = 104 cpu_data(id).icache_line_size =
103 prom_getintdefault(cpu_node, "icache-line-size", def); 105 of_getintprop_default(dp, "icache-line-size", def);
104 106
105 def = ((tlb_type == hypervisor) ? 107 def = ((tlb_type == hypervisor) ?
106 (3 * 1024 * 1024) : 108 (3 * 1024 * 1024) :
107 (4 * 1024 * 1024)); 109 (4 * 1024 * 1024));
108 cpu_data(id).ecache_size = prom_getintdefault(cpu_node, "ecache-size", 110 cpu_data(id).ecache_size =
109 def); 111 of_getintprop_default(dp, "ecache-size", def);
110 112
111 def = 64; 113 def = 64;
112 cpu_data(id).ecache_line_size = 114 cpu_data(id).ecache_line_size =
113 prom_getintdefault(cpu_node, "ecache-line-size", def); 115 of_getintprop_default(dp, "ecache-line-size", def);
114 116
115 printk("CPU[%d]: Caches " 117 printk("CPU[%d]: Caches "
116 "D[sz(%d):line_sz(%d)] " 118 "D[sz(%d):line_sz(%d)] "
@@ -342,10 +344,10 @@ static int __devinit smp_boot_one_cpu(unsigned int cpu)
342 344
343 prom_startcpu_cpuid(cpu, entry, cookie); 345 prom_startcpu_cpuid(cpu, entry, cookie);
344 } else { 346 } else {
345 int cpu_node; 347 struct device_node *dp;
346 348
347 cpu_find_by_mid(cpu, &cpu_node); 349 cpu_find_by_mid(cpu, &dp);
348 prom_startcpu(cpu_node, entry, cookie); 350 prom_startcpu(dp->node, entry, cookie);
349 } 351 }
350 352
351 for (timeout = 0; timeout < 5000000; timeout++) { 353 for (timeout = 0; timeout < 5000000; timeout++) {
@@ -1289,7 +1291,8 @@ int setup_profiling_timer(unsigned int multiplier)
1289 1291
1290static void __init smp_tune_scheduling(void) 1292static void __init smp_tune_scheduling(void)
1291{ 1293{
1292 int instance, node; 1294 struct device_node *dp;
1295 int instance;
1293 unsigned int def, smallest = ~0U; 1296 unsigned int def, smallest = ~0U;
1294 1297
1295 def = ((tlb_type == hypervisor) ? 1298 def = ((tlb_type == hypervisor) ?
@@ -1297,10 +1300,10 @@ static void __init smp_tune_scheduling(void)
1297 (4 * 1024 * 1024)); 1300 (4 * 1024 * 1024));
1298 1301
1299 instance = 0; 1302 instance = 0;
1300 while (!cpu_find_by_instance(instance, &node, NULL)) { 1303 while (!cpu_find_by_instance(instance, &dp, NULL)) {
1301 unsigned int val; 1304 unsigned int val;
1302 1305
1303 val = prom_getintdefault(node, "ecache-size", def); 1306 val = of_getintprop_default(dp, "ecache-size", def);
1304 if (val < smallest) 1307 if (val < smallest)
1305 smallest = val; 1308 smallest = val;
1306 1309
diff --git a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c
index 0f00a99927e9..348b82035561 100644
--- a/arch/sparc64/kernel/time.c
+++ b/arch/sparc64/kernel/time.c
@@ -48,6 +48,7 @@
48#include <asm/sections.h> 48#include <asm/sections.h>
49#include <asm/cpudata.h> 49#include <asm/cpudata.h>
50#include <asm/uaccess.h> 50#include <asm/uaccess.h>
51#include <asm/prom.h>
51 52
52DEFINE_SPINLOCK(mostek_lock); 53DEFINE_SPINLOCK(mostek_lock);
53DEFINE_SPINLOCK(rtc_lock); 54DEFINE_SPINLOCK(rtc_lock);
@@ -755,24 +756,200 @@ retry:
755 return -EOPNOTSUPP; 756 return -EOPNOTSUPP;
756} 757}
757 758
758void __init clock_probe(void) 759static int __init clock_model_matches(char *model)
759{ 760{
760 struct linux_prom_registers clk_reg[2]; 761 if (strcmp(model, "mk48t02") &&
761 char model[128]; 762 strcmp(model, "mk48t08") &&
762 int node, busnd = -1, err; 763 strcmp(model, "mk48t59") &&
763 unsigned long flags; 764 strcmp(model, "m5819") &&
764 struct linux_central *cbus; 765 strcmp(model, "m5819p") &&
766 strcmp(model, "m5823") &&
767 strcmp(model, "ds1287"))
768 return 0;
769
770 return 1;
771}
772
773static void __init __clock_assign_common(void __iomem *addr, char *model)
774{
775 if (model[5] == '0' && model[6] == '2') {
776 mstk48t02_regs = addr;
777 } else if(model[5] == '0' && model[6] == '8') {
778 mstk48t08_regs = addr;
779 mstk48t02_regs = mstk48t08_regs + MOSTEK_48T08_48T02;
780 } else {
781 mstk48t59_regs = addr;
782 mstk48t02_regs = mstk48t59_regs + MOSTEK_48T59_48T02;
783 }
784}
785
786static void __init clock_assign_clk_reg(struct linux_prom_registers *clk_reg,
787 char *model)
788{
789 unsigned long addr;
790
791 addr = ((unsigned long) clk_reg[0].phys_addr |
792 (((unsigned long) clk_reg[0].which_io) << 32UL));
793
794 __clock_assign_common((void __iomem *) addr, model);
795}
796
797static int __init clock_probe_central(void)
798{
799 struct linux_prom_registers clk_reg[2], *pr;
800 struct device_node *dp;
801 char *model;
802
803 if (!central_bus)
804 return 0;
805
806 /* Get Central FHC's prom node. */
807 dp = central_bus->child->prom_node;
808
809 /* Then get the first child device below it. */
810 dp = dp->child;
811
812 while (dp) {
813 model = of_get_property(dp, "model", NULL);
814 if (!model || !clock_model_matches(model))
815 goto next_sibling;
816
817 pr = of_get_property(dp, "reg", NULL);
818 memcpy(clk_reg, pr, sizeof(clk_reg));
819
820 apply_fhc_ranges(central_bus->child, clk_reg, 1);
821 apply_central_ranges(central_bus, clk_reg, 1);
822
823 clock_assign_clk_reg(clk_reg, model);
824 return 1;
825
826 next_sibling:
827 dp = dp->sibling;
828 }
829
830 return 0;
831}
832
765#ifdef CONFIG_PCI 833#ifdef CONFIG_PCI
766 struct linux_ebus *ebus = NULL; 834static void __init clock_isa_ebus_assign_regs(struct resource *res, char *model)
767 struct sparc_isa_bridge *isa_br = NULL; 835{
836 if (!strcmp(model, "ds1287") ||
837 !strcmp(model, "m5819") ||
838 !strcmp(model, "m5819p") ||
839 !strcmp(model, "m5823")) {
840 ds1287_regs = res->start;
841 } else {
842 mstk48t59_regs = (void __iomem *) res->start;
843 mstk48t02_regs = mstk48t59_regs + MOSTEK_48T59_48T02;
844 }
845}
846
847static int __init clock_probe_one_ebus_dev(struct linux_ebus_device *edev)
848{
849 struct device_node *dp = edev->prom_node;
850 char *model;
851
852 model = of_get_property(dp, "model", NULL);
853 if (!clock_model_matches(model))
854 return 0;
855
856 clock_isa_ebus_assign_regs(&edev->resource[0], model);
857
858 return 1;
859}
860
861static int __init clock_probe_ebus(void)
862{
863 struct linux_ebus *ebus;
864
865 for_each_ebus(ebus) {
866 struct linux_ebus_device *edev;
867
868 for_each_ebusdev(edev, ebus) {
869 if (clock_probe_one_ebus_dev(edev))
870 return 1;
871 }
872 }
873
874 return 0;
875}
876
877static int __init clock_probe_one_isa_dev(struct sparc_isa_device *idev)
878{
879 struct device_node *dp = idev->prom_node;
880 char *model;
881
882 model = of_get_property(dp, "model", NULL);
883 if (!clock_model_matches(model))
884 return 0;
885
886 clock_isa_ebus_assign_regs(&idev->resource, model);
887
888 return 1;
889}
890
891static int __init clock_probe_isa(void)
892{
893 struct sparc_isa_bridge *isa_br;
894
895 for_each_isa(isa_br) {
896 struct sparc_isa_device *isa_dev;
897
898 for_each_isadev(isa_dev, isa_br) {
899 if (clock_probe_one_isa_dev(isa_dev))
900 return 1;
901 }
902 }
903
904 return 0;
905}
906#endif /* CONFIG_PCI */
907
908#ifdef CONFIG_SBUS
909static int __init clock_probe_one_sbus_dev(struct sbus_bus *sbus, struct sbus_dev *sdev)
910{
911 struct resource *res;
912 char model[64];
913 void __iomem *addr;
914
915 prom_getstring(sdev->prom_node, "model", model, sizeof(model));
916 if (!clock_model_matches(model))
917 return 0;
918
919 res = &sdev->resource[0];
920 addr = sbus_ioremap(res, 0, 0x800UL, "eeprom");
921
922 __clock_assign_common(addr, model);
923
924 return 1;
925}
926
927static int __init clock_probe_sbus(void)
928{
929 struct sbus_bus *sbus;
930
931 for_each_sbus(sbus) {
932 struct sbus_dev *sdev;
933
934 for_each_sbusdev(sdev, sbus) {
935 if (clock_probe_one_sbus_dev(sbus, sdev))
936 return 1;
937 }
938 }
939
940 return 0;
941}
768#endif 942#endif
943
944void __init clock_probe(void)
945{
769 static int invoked; 946 static int invoked;
947 unsigned long flags;
770 948
771 if (invoked) 949 if (invoked)
772 return; 950 return;
773 invoked = 1; 951 invoked = 1;
774 952
775
776 if (this_is_starfire) { 953 if (this_is_starfire) {
777 xtime.tv_sec = starfire_get_time(); 954 xtime.tv_sec = starfire_get_time();
778 xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ); 955 xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
@@ -788,183 +965,27 @@ void __init clock_probe(void)
788 return; 965 return;
789 } 966 }
790 967
791 local_irq_save(flags);
792
793 cbus = central_bus;
794 if (cbus != NULL)
795 busnd = central_bus->child->prom_node;
796
797 /* Check FHC Central then EBUSs then ISA bridges then SBUSs. 968 /* Check FHC Central then EBUSs then ISA bridges then SBUSs.
798 * That way we handle the presence of multiple properly. 969 * That way we handle the presence of multiple properly.
799 * 970 *
800 * As a special case, machines with Central must provide the 971 * As a special case, machines with Central must provide the
801 * timer chip there. 972 * timer chip there.
802 */ 973 */
974 if (!clock_probe_central() &&
803#ifdef CONFIG_PCI 975#ifdef CONFIG_PCI
804 if (ebus_chain != NULL) { 976 !clock_probe_ebus() &&
805 ebus = ebus_chain; 977 !clock_probe_isa() &&
806 if (busnd == -1)
807 busnd = ebus->prom_node;
808 }
809 if (isa_chain != NULL) {
810 isa_br = isa_chain;
811 if (busnd == -1)
812 busnd = isa_br->prom_node;
813 }
814#endif
815 if (sbus_root != NULL && busnd == -1)
816 busnd = sbus_root->prom_node;
817
818 if (busnd == -1) {
819 prom_printf("clock_probe: problem, cannot find bus to search.\n");
820 prom_halt();
821 }
822
823 node = prom_getchild(busnd);
824
825 while (1) {
826 if (!node)
827 model[0] = 0;
828 else
829 prom_getstring(node, "model", model, sizeof(model));
830 if (strcmp(model, "mk48t02") &&
831 strcmp(model, "mk48t08") &&
832 strcmp(model, "mk48t59") &&
833 strcmp(model, "m5819") &&
834 strcmp(model, "m5819p") &&
835 strcmp(model, "m5823") &&
836 strcmp(model, "ds1287")) {
837 if (cbus != NULL) {
838 prom_printf("clock_probe: Central bus lacks timer chip.\n");
839 prom_halt();
840 }
841
842 if (node != 0)
843 node = prom_getsibling(node);
844#ifdef CONFIG_PCI
845 while ((node == 0) && ebus != NULL) {
846 ebus = ebus->next;
847 if (ebus != NULL) {
848 busnd = ebus->prom_node;
849 node = prom_getchild(busnd);
850 }
851 }
852 while ((node == 0) && isa_br != NULL) {
853 isa_br = isa_br->next;
854 if (isa_br != NULL) {
855 busnd = isa_br->prom_node;
856 node = prom_getchild(busnd);
857 }
858 }
859#endif 978#endif
860 if (node == 0) { 979#ifdef CONFIG_SBUS
861 prom_printf("clock_probe: Cannot find timer chip\n"); 980 !clock_probe_sbus()
862 prom_halt();
863 }
864 continue;
865 }
866
867 err = prom_getproperty(node, "reg", (char *)clk_reg,
868 sizeof(clk_reg));
869 if(err == -1) {
870 prom_printf("clock_probe: Cannot get Mostek reg property\n");
871 prom_halt();
872 }
873
874 if (cbus != NULL) {
875 apply_fhc_ranges(central_bus->child, clk_reg, 1);
876 apply_central_ranges(central_bus, clk_reg, 1);
877 }
878#ifdef CONFIG_PCI
879 else if (ebus != NULL) {
880 struct linux_ebus_device *edev;
881
882 for_each_ebusdev(edev, ebus)
883 if (edev->prom_node == node)
884 break;
885 if (edev == NULL) {
886 if (isa_chain != NULL)
887 goto try_isa_clock;
888 prom_printf("%s: Mostek not probed by EBUS\n",
889 __FUNCTION__);
890 prom_halt();
891 }
892
893 if (!strcmp(model, "ds1287") ||
894 !strcmp(model, "m5819") ||
895 !strcmp(model, "m5819p") ||
896 !strcmp(model, "m5823")) {
897 ds1287_regs = edev->resource[0].start;
898 } else {
899 mstk48t59_regs = (void __iomem *)
900 edev->resource[0].start;
901 mstk48t02_regs = mstk48t59_regs + MOSTEK_48T59_48T02;
902 }
903 break;
904 }
905 else if (isa_br != NULL) {
906 struct sparc_isa_device *isadev;
907
908try_isa_clock:
909 for_each_isadev(isadev, isa_br)
910 if (isadev->prom_node == node)
911 break;
912 if (isadev == NULL) {
913 prom_printf("%s: Mostek not probed by ISA\n");
914 prom_halt();
915 }
916 if (!strcmp(model, "ds1287") ||
917 !strcmp(model, "m5819") ||
918 !strcmp(model, "m5819p") ||
919 !strcmp(model, "m5823")) {
920 ds1287_regs = isadev->resource.start;
921 } else {
922 mstk48t59_regs = (void __iomem *)
923 isadev->resource.start;
924 mstk48t02_regs = mstk48t59_regs + MOSTEK_48T59_48T02;
925 }
926 break;
927 }
928#endif 981#endif
929 else { 982 ) {
930 if (sbus_root->num_sbus_ranges) { 983 printk(KERN_WARNING "No clock chip found.\n");
931 int nranges = sbus_root->num_sbus_ranges; 984 return;
932 int rngc;
933
934 for (rngc = 0; rngc < nranges; rngc++)
935 if (clk_reg[0].which_io ==
936 sbus_root->sbus_ranges[rngc].ot_child_space)
937 break;
938 if (rngc == nranges) {
939 prom_printf("clock_probe: Cannot find ranges for "
940 "clock regs.\n");
941 prom_halt();
942 }
943 clk_reg[0].which_io =
944 sbus_root->sbus_ranges[rngc].ot_parent_space;
945 clk_reg[0].phys_addr +=
946 sbus_root->sbus_ranges[rngc].ot_parent_base;
947 }
948 }
949
950 if(model[5] == '0' && model[6] == '2') {
951 mstk48t02_regs = (void __iomem *)
952 (((u64)clk_reg[0].phys_addr) |
953 (((u64)clk_reg[0].which_io)<<32UL));
954 } else if(model[5] == '0' && model[6] == '8') {
955 mstk48t08_regs = (void __iomem *)
956 (((u64)clk_reg[0].phys_addr) |
957 (((u64)clk_reg[0].which_io)<<32UL));
958 mstk48t02_regs = mstk48t08_regs + MOSTEK_48T08_48T02;
959 } else {
960 mstk48t59_regs = (void __iomem *)
961 (((u64)clk_reg[0].phys_addr) |
962 (((u64)clk_reg[0].which_io)<<32UL));
963 mstk48t02_regs = mstk48t59_regs + MOSTEK_48T59_48T02;
964 }
965 break;
966 } 985 }
967 986
987 local_irq_save(flags);
988
968 if (mstk48t02_regs != NULL) { 989 if (mstk48t02_regs != NULL) {
969 /* Report a low battery voltage condition. */ 990 /* Report a low battery voltage condition. */
970 if (has_low_battery()) 991 if (has_low_battery())
@@ -983,12 +1004,14 @@ try_isa_clock:
983/* This is gets the master TICK_INT timer going. */ 1004/* This is gets the master TICK_INT timer going. */
984static unsigned long sparc64_init_timers(void) 1005static unsigned long sparc64_init_timers(void)
985{ 1006{
1007 struct device_node *dp;
1008 struct property *prop;
986 unsigned long clock; 1009 unsigned long clock;
987 int node;
988#ifdef CONFIG_SMP 1010#ifdef CONFIG_SMP
989 extern void smp_tick_init(void); 1011 extern void smp_tick_init(void);
990#endif 1012#endif
991 1013
1014 dp = of_find_node_by_path("/");
992 if (tlb_type == spitfire) { 1015 if (tlb_type == spitfire) {
993 unsigned long ver, manuf, impl; 1016 unsigned long ver, manuf, impl;
994 1017
@@ -999,18 +1022,17 @@ static unsigned long sparc64_init_timers(void)
999 if (manuf == 0x17 && impl == 0x13) { 1022 if (manuf == 0x17 && impl == 0x13) {
1000 /* Hummingbird, aka Ultra-IIe */ 1023 /* Hummingbird, aka Ultra-IIe */
1001 tick_ops = &hbtick_operations; 1024 tick_ops = &hbtick_operations;
1002 node = prom_root_node; 1025 prop = of_find_property(dp, "stick-frequency", NULL);
1003 clock = prom_getint(node, "stick-frequency");
1004 } else { 1026 } else {
1005 tick_ops = &tick_operations; 1027 tick_ops = &tick_operations;
1006 cpu_find_by_instance(0, &node, NULL); 1028 cpu_find_by_instance(0, &dp, NULL);
1007 clock = prom_getint(node, "clock-frequency"); 1029 prop = of_find_property(dp, "clock-frequency", NULL);
1008 } 1030 }
1009 } else { 1031 } else {
1010 tick_ops = &stick_operations; 1032 tick_ops = &stick_operations;
1011 node = prom_root_node; 1033 prop = of_find_property(dp, "stick-frequency", NULL);
1012 clock = prom_getint(node, "stick-frequency");
1013 } 1034 }
1035 clock = *(unsigned int *) prop->value;
1014 timer_tick_offset = clock / HZ; 1036 timer_tick_offset = clock / HZ;
1015 1037
1016#ifdef CONFIG_SMP 1038#ifdef CONFIG_SMP
diff --git a/arch/sparc64/kernel/traps.c b/arch/sparc64/kernel/traps.c
index 5059cbd4feee..1ff34b019f3f 100644
--- a/arch/sparc64/kernel/traps.c
+++ b/arch/sparc64/kernel/traps.c
@@ -42,6 +42,7 @@
42#ifdef CONFIG_KMOD 42#ifdef CONFIG_KMOD
43#include <linux/kmod.h> 43#include <linux/kmod.h>
44#endif 44#endif
45#include <asm/prom.h>
45 46
46ATOMIC_NOTIFIER_HEAD(sparc64die_chain); 47ATOMIC_NOTIFIER_HEAD(sparc64die_chain);
47 48
@@ -807,7 +808,8 @@ extern unsigned int cheetah_deferred_trap_vector[], cheetah_deferred_trap_vector
807void __init cheetah_ecache_flush_init(void) 808void __init cheetah_ecache_flush_init(void)
808{ 809{
809 unsigned long largest_size, smallest_linesize, order, ver; 810 unsigned long largest_size, smallest_linesize, order, ver;
810 int node, i, instance; 811 struct device_node *dp;
812 int i, instance, sz;
811 813
812 /* Scan all cpu device tree nodes, note two values: 814 /* Scan all cpu device tree nodes, note two values:
813 * 1) largest E-cache size 815 * 1) largest E-cache size
@@ -817,14 +819,14 @@ void __init cheetah_ecache_flush_init(void)
817 smallest_linesize = ~0UL; 819 smallest_linesize = ~0UL;
818 820
819 instance = 0; 821 instance = 0;
820 while (!cpu_find_by_instance(instance, &node, NULL)) { 822 while (!cpu_find_by_instance(instance, &dp, NULL)) {
821 unsigned long val; 823 unsigned long val;
822 824
823 val = prom_getintdefault(node, "ecache-size", 825 val = of_getintprop_default(dp, "ecache-size",
824 (2 * 1024 * 1024)); 826 (2 * 1024 * 1024));
825 if (val > largest_size) 827 if (val > largest_size)
826 largest_size = val; 828 largest_size = val;
827 val = prom_getintdefault(node, "ecache-line-size", 64); 829 val = of_getintprop_default(dp, "ecache-line-size", 64);
828 if (val < smallest_linesize) 830 if (val < smallest_linesize)
829 smallest_linesize = val; 831 smallest_linesize = val;
830 instance++; 832 instance++;
@@ -849,16 +851,16 @@ void __init cheetah_ecache_flush_init(void)
849 } 851 }
850 852
851 /* Now allocate error trap reporting scoreboard. */ 853 /* Now allocate error trap reporting scoreboard. */
852 node = NR_CPUS * (2 * sizeof(struct cheetah_err_info)); 854 sz = NR_CPUS * (2 * sizeof(struct cheetah_err_info));
853 for (order = 0; order < MAX_ORDER; order++) { 855 for (order = 0; order < MAX_ORDER; order++) {
854 if ((PAGE_SIZE << order) >= node) 856 if ((PAGE_SIZE << order) >= sz)
855 break; 857 break;
856 } 858 }
857 cheetah_error_log = (struct cheetah_err_info *) 859 cheetah_error_log = (struct cheetah_err_info *)
858 __get_free_pages(GFP_KERNEL, order); 860 __get_free_pages(GFP_KERNEL, order);
859 if (!cheetah_error_log) { 861 if (!cheetah_error_log) {
860 prom_printf("cheetah_ecache_flush_init: Failed to allocate " 862 prom_printf("cheetah_ecache_flush_init: Failed to allocate "
861 "error logging scoreboard (%d bytes).\n", node); 863 "error logging scoreboard (%d bytes).\n", sz);
862 prom_halt(); 864 prom_halt();
863 } 865 }
864 memset(cheetah_error_log, 0, PAGE_SIZE << order); 866 memset(cheetah_error_log, 0, PAGE_SIZE << order);
diff --git a/arch/sparc64/kernel/unaligned.c b/arch/sparc64/kernel/unaligned.c
index 001e8518331f..bb2d68577855 100644
--- a/arch/sparc64/kernel/unaligned.c
+++ b/arch/sparc64/kernel/unaligned.c
@@ -279,12 +279,21 @@ static void kernel_mna_trap_fault(void)
279 279
280asmlinkage void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn) 280asmlinkage void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn)
281{ 281{
282 static unsigned long count, last_time;
282 enum direction dir = decode_direction(insn); 283 enum direction dir = decode_direction(insn);
283 int size = decode_access_size(insn); 284 int size = decode_access_size(insn);
284 285
285 current_thread_info()->kern_una_regs = regs; 286 current_thread_info()->kern_una_regs = regs;
286 current_thread_info()->kern_una_insn = insn; 287 current_thread_info()->kern_una_insn = insn;
287 288
289 if (jiffies - last_time > 5 * HZ)
290 count = 0;
291 if (count < 5) {
292 last_time = jiffies;
293 count++;
294 printk("Kernel unaligned access at TPC[%lx]\n", regs->tpc);
295 }
296
288 if (!ok_for_kernel(insn) || dir == both) { 297 if (!ok_for_kernel(insn) || dir == both) {
289 printk("Unsupported unaligned load/store trap for kernel " 298 printk("Unsupported unaligned load/store trap for kernel "
290 "at <%016lx>.\n", regs->tpc); 299 "at <%016lx>.\n", regs->tpc);