ath9k_hw: tweak noise immunity thresholds for older chipsets
[linux/fpc-iii.git] / arch / sparc / kernel / prom_64.c
blob6b39125eb9271d986b32896fcd35015cbd752ef8
1 /*
2 * Procedures for creating, accessing and interpreting the device tree.
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
10 * Adapted for sparc64 by David S. Miller davem@davemloft.net
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
18 #include <linux/kernel.h>
19 #include <linux/types.h>
20 #include <linux/string.h>
21 #include <linux/mm.h>
22 #include <linux/memblock.h>
23 #include <linux/of.h>
25 #include <asm/prom.h>
26 #include <asm/oplib.h>
27 #include <asm/irq.h>
28 #include <asm/asi.h>
29 #include <asm/upa.h>
30 #include <asm/smp.h>
32 #include "prom.h"
34 void * __init prom_early_alloc(unsigned long size)
36 unsigned long paddr = memblock_alloc(size, SMP_CACHE_BYTES);
37 void *ret;
39 if (!paddr) {
40 prom_printf("prom_early_alloc(%lu) failed\n", size);
41 prom_halt();
44 ret = __va(paddr);
45 memset(ret, 0, size);
46 prom_early_allocated += size;
48 return ret;
51 /* The following routines deal with the black magic of fully naming a
52 * node.
54 * Certain well known named nodes are just the simple name string.
56 * Actual devices have an address specifier appended to the base name
57 * string, like this "foo@addr". The "addr" can be in any number of
58 * formats, and the platform plus the type of the node determine the
59 * format and how it is constructed.
61 * For children of the ROOT node, the naming convention is fixed and
62 * determined by whether this is a sun4u or sun4v system.
64 * For children of other nodes, it is bus type specific. So
65 * we walk up the tree until we discover a "device_type" property
66 * we recognize and we go from there.
68 * As an example, the boot device on my workstation has a full path:
70 * /pci@1e,600000/ide@d/disk@0,0:c
72 static void __init sun4v_path_component(struct device_node *dp, char *tmp_buf)
74 struct linux_prom64_registers *regs;
75 struct property *rprop;
76 u32 high_bits, low_bits, type;
78 rprop = of_find_property(dp, "reg", NULL);
79 if (!rprop)
80 return;
82 regs = rprop->value;
83 if (!of_node_is_root(dp->parent)) {
84 sprintf(tmp_buf, "%s@%x,%x",
85 dp->name,
86 (unsigned int) (regs->phys_addr >> 32UL),
87 (unsigned int) (regs->phys_addr & 0xffffffffUL));
88 return;
91 type = regs->phys_addr >> 60UL;
92 high_bits = (regs->phys_addr >> 32UL) & 0x0fffffffUL;
93 low_bits = (regs->phys_addr & 0xffffffffUL);
95 if (type == 0 || type == 8) {
96 const char *prefix = (type == 0) ? "m" : "i";
98 if (low_bits)
99 sprintf(tmp_buf, "%s@%s%x,%x",
100 dp->name, prefix,
101 high_bits, low_bits);
102 else
103 sprintf(tmp_buf, "%s@%s%x",
104 dp->name,
105 prefix,
106 high_bits);
107 } else if (type == 12) {
108 sprintf(tmp_buf, "%s@%x",
109 dp->name, high_bits);
113 static void __init sun4u_path_component(struct device_node *dp, char *tmp_buf)
115 struct linux_prom64_registers *regs;
116 struct property *prop;
118 prop = of_find_property(dp, "reg", NULL);
119 if (!prop)
120 return;
122 regs = prop->value;
123 if (!of_node_is_root(dp->parent)) {
124 sprintf(tmp_buf, "%s@%x,%x",
125 dp->name,
126 (unsigned int) (regs->phys_addr >> 32UL),
127 (unsigned int) (regs->phys_addr & 0xffffffffUL));
128 return;
131 prop = of_find_property(dp, "upa-portid", NULL);
132 if (!prop)
133 prop = of_find_property(dp, "portid", NULL);
134 if (prop) {
135 unsigned long mask = 0xffffffffUL;
137 if (tlb_type >= cheetah)
138 mask = 0x7fffff;
140 sprintf(tmp_buf, "%s@%x,%x",
141 dp->name,
142 *(u32 *)prop->value,
143 (unsigned int) (regs->phys_addr & mask));
147 /* "name@slot,offset" */
148 static void __init sbus_path_component(struct device_node *dp, char *tmp_buf)
150 struct linux_prom_registers *regs;
151 struct property *prop;
153 prop = of_find_property(dp, "reg", NULL);
154 if (!prop)
155 return;
157 regs = prop->value;
158 sprintf(tmp_buf, "%s@%x,%x",
159 dp->name,
160 regs->which_io,
161 regs->phys_addr);
164 /* "name@devnum[,func]" */
165 static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
167 struct linux_prom_pci_registers *regs;
168 struct property *prop;
169 unsigned int devfn;
171 prop = of_find_property(dp, "reg", NULL);
172 if (!prop)
173 return;
175 regs = prop->value;
176 devfn = (regs->phys_hi >> 8) & 0xff;
177 if (devfn & 0x07) {
178 sprintf(tmp_buf, "%s@%x,%x",
179 dp->name,
180 devfn >> 3,
181 devfn & 0x07);
182 } else {
183 sprintf(tmp_buf, "%s@%x",
184 dp->name,
185 devfn >> 3);
189 /* "name@UPA_PORTID,offset" */
190 static void __init upa_path_component(struct device_node *dp, char *tmp_buf)
192 struct linux_prom64_registers *regs;
193 struct property *prop;
195 prop = of_find_property(dp, "reg", NULL);
196 if (!prop)
197 return;
199 regs = prop->value;
201 prop = of_find_property(dp, "upa-portid", NULL);
202 if (!prop)
203 return;
205 sprintf(tmp_buf, "%s@%x,%x",
206 dp->name,
207 *(u32 *) prop->value,
208 (unsigned int) (regs->phys_addr & 0xffffffffUL));
211 /* "name@reg" */
212 static void __init vdev_path_component(struct device_node *dp, char *tmp_buf)
214 struct property *prop;
215 u32 *regs;
217 prop = of_find_property(dp, "reg", NULL);
218 if (!prop)
219 return;
221 regs = prop->value;
223 sprintf(tmp_buf, "%s@%x", dp->name, *regs);
226 /* "name@addrhi,addrlo" */
227 static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
229 struct linux_prom64_registers *regs;
230 struct property *prop;
232 prop = of_find_property(dp, "reg", NULL);
233 if (!prop)
234 return;
236 regs = prop->value;
238 sprintf(tmp_buf, "%s@%x,%x",
239 dp->name,
240 (unsigned int) (regs->phys_addr >> 32UL),
241 (unsigned int) (regs->phys_addr & 0xffffffffUL));
244 /* "name@bus,addr" */
245 static void __init i2c_path_component(struct device_node *dp, char *tmp_buf)
247 struct property *prop;
248 u32 *regs;
250 prop = of_find_property(dp, "reg", NULL);
251 if (!prop)
252 return;
254 regs = prop->value;
256 /* This actually isn't right... should look at the #address-cells
257 * property of the i2c bus node etc. etc.
259 sprintf(tmp_buf, "%s@%x,%x",
260 dp->name, regs[0], regs[1]);
263 /* "name@reg0[,reg1]" */
264 static void __init usb_path_component(struct device_node *dp, char *tmp_buf)
266 struct property *prop;
267 u32 *regs;
269 prop = of_find_property(dp, "reg", NULL);
270 if (!prop)
271 return;
273 regs = prop->value;
275 if (prop->length == sizeof(u32) || regs[1] == 1) {
276 sprintf(tmp_buf, "%s@%x",
277 dp->name, regs[0]);
278 } else {
279 sprintf(tmp_buf, "%s@%x,%x",
280 dp->name, regs[0], regs[1]);
284 /* "name@reg0reg1[,reg2reg3]" */
285 static void __init ieee1394_path_component(struct device_node *dp, char *tmp_buf)
287 struct property *prop;
288 u32 *regs;
290 prop = of_find_property(dp, "reg", NULL);
291 if (!prop)
292 return;
294 regs = prop->value;
296 if (regs[2] || regs[3]) {
297 sprintf(tmp_buf, "%s@%08x%08x,%04x%08x",
298 dp->name, regs[0], regs[1], regs[2], regs[3]);
299 } else {
300 sprintf(tmp_buf, "%s@%08x%08x",
301 dp->name, regs[0], regs[1]);
305 static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
307 struct device_node *parent = dp->parent;
309 if (parent != NULL) {
310 if (!strcmp(parent->type, "pci") ||
311 !strcmp(parent->type, "pciex")) {
312 pci_path_component(dp, tmp_buf);
313 return;
315 if (!strcmp(parent->type, "sbus")) {
316 sbus_path_component(dp, tmp_buf);
317 return;
319 if (!strcmp(parent->type, "upa")) {
320 upa_path_component(dp, tmp_buf);
321 return;
323 if (!strcmp(parent->type, "ebus")) {
324 ebus_path_component(dp, tmp_buf);
325 return;
327 if (!strcmp(parent->name, "usb") ||
328 !strcmp(parent->name, "hub")) {
329 usb_path_component(dp, tmp_buf);
330 return;
332 if (!strcmp(parent->type, "i2c")) {
333 i2c_path_component(dp, tmp_buf);
334 return;
336 if (!strcmp(parent->type, "firewire")) {
337 ieee1394_path_component(dp, tmp_buf);
338 return;
340 if (!strcmp(parent->type, "virtual-devices")) {
341 vdev_path_component(dp, tmp_buf);
342 return;
344 /* "isa" is handled with platform naming */
347 /* Use platform naming convention. */
348 if (tlb_type == hypervisor) {
349 sun4v_path_component(dp, tmp_buf);
350 return;
351 } else {
352 sun4u_path_component(dp, tmp_buf);
356 char * __init build_path_component(struct device_node *dp)
358 char tmp_buf[64], *n;
360 tmp_buf[0] = '\0';
361 __build_path_component(dp, tmp_buf);
362 if (tmp_buf[0] == '\0')
363 strcpy(tmp_buf, dp->name);
365 n = prom_early_alloc(strlen(tmp_buf) + 1);
366 strcpy(n, tmp_buf);
368 return n;
371 static const char *get_mid_prop(void)
373 return (tlb_type == spitfire ? "upa-portid" : "portid");
376 bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
377 int cpu, unsigned int *thread)
379 const char *mid_prop = get_mid_prop();
380 int this_cpu_id;
382 /* On hypervisor based platforms we interrogate the 'reg'
383 * property. On everything else we look for a 'upa-portis',
384 * 'portid', or 'cpuid' property.
387 if (tlb_type == hypervisor) {
388 struct property *prop = of_find_property(cpun, "reg", NULL);
389 u32 *regs;
391 if (!prop) {
392 pr_warn("CPU node missing reg property\n");
393 return false;
395 regs = prop->value;
396 this_cpu_id = regs[0] & 0x0fffffff;
397 } else {
398 this_cpu_id = of_getintprop_default(cpun, mid_prop, -1);
400 if (this_cpu_id < 0) {
401 mid_prop = "cpuid";
402 this_cpu_id = of_getintprop_default(cpun, mid_prop, -1);
404 if (this_cpu_id < 0) {
405 pr_warn("CPU node missing cpu ID property\n");
406 return false;
409 if (this_cpu_id == cpu) {
410 if (thread) {
411 int proc_id = cpu_data(cpu).proc_id;
413 /* On sparc64, the cpu thread information is obtained
414 * either from OBP or the machine description. We've
415 * actually probed this information already long before
416 * this interface gets called so instead of interrogating
417 * both the OF node and the MDESC again, just use what
418 * we discovered already.
420 if (proc_id < 0)
421 proc_id = 0;
422 *thread = proc_id;
424 return true;
426 return false;
429 static void *of_iterate_over_cpus(void *(*func)(struct device_node *, int, int), int arg)
431 struct device_node *dp;
432 const char *mid_prop;
434 mid_prop = get_mid_prop();
435 for_each_node_by_type(dp, "cpu") {
436 int cpuid = of_getintprop_default(dp, mid_prop, -1);
437 const char *this_mid_prop = mid_prop;
438 void *ret;
440 if (cpuid < 0) {
441 this_mid_prop = "cpuid";
442 cpuid = of_getintprop_default(dp, this_mid_prop, -1);
444 if (cpuid < 0) {
445 prom_printf("OF: Serious problem, cpu lacks "
446 "%s property", this_mid_prop);
447 prom_halt();
449 #ifdef CONFIG_SMP
450 if (cpuid >= NR_CPUS) {
451 printk(KERN_WARNING "Ignoring CPU %d which is "
452 ">= NR_CPUS (%d)\n",
453 cpuid, NR_CPUS);
454 continue;
456 #endif
457 ret = func(dp, cpuid, arg);
458 if (ret)
459 return ret;
461 return NULL;
464 static void *check_cpu_node(struct device_node *dp, int cpuid, int id)
466 if (id == cpuid)
467 return dp;
468 return NULL;
471 struct device_node *of_find_node_by_cpuid(int cpuid)
473 return of_iterate_over_cpus(check_cpu_node, cpuid);
476 static void *record_one_cpu(struct device_node *dp, int cpuid, int arg)
478 ncpus_probed++;
479 #ifdef CONFIG_SMP
480 set_cpu_present(cpuid, true);
481 set_cpu_possible(cpuid, true);
482 #endif
483 return NULL;
486 void __init of_populate_present_mask(void)
488 if (tlb_type == hypervisor)
489 return;
491 ncpus_probed = 0;
492 of_iterate_over_cpus(record_one_cpu, 0);
495 static void *fill_in_one_cpu(struct device_node *dp, int cpuid, int arg)
497 struct device_node *portid_parent = NULL;
498 int portid = -1;
500 if (of_find_property(dp, "cpuid", NULL)) {
501 int limit = 2;
503 portid_parent = dp;
504 while (limit--) {
505 portid_parent = portid_parent->parent;
506 if (!portid_parent)
507 break;
508 portid = of_getintprop_default(portid_parent,
509 "portid", -1);
510 if (portid >= 0)
511 break;
515 #ifndef CONFIG_SMP
516 /* On uniprocessor we only want the values for the
517 * real physical cpu the kernel booted onto, however
518 * cpu_data() only has one entry at index 0.
520 if (cpuid != real_hard_smp_processor_id())
521 return NULL;
522 cpuid = 0;
523 #endif
525 cpu_data(cpuid).clock_tick =
526 of_getintprop_default(dp, "clock-frequency", 0);
528 if (portid_parent) {
529 cpu_data(cpuid).dcache_size =
530 of_getintprop_default(dp, "l1-dcache-size",
531 16 * 1024);
532 cpu_data(cpuid).dcache_line_size =
533 of_getintprop_default(dp, "l1-dcache-line-size",
534 32);
535 cpu_data(cpuid).icache_size =
536 of_getintprop_default(dp, "l1-icache-size",
537 8 * 1024);
538 cpu_data(cpuid).icache_line_size =
539 of_getintprop_default(dp, "l1-icache-line-size",
540 32);
541 cpu_data(cpuid).ecache_size =
542 of_getintprop_default(dp, "l2-cache-size", 0);
543 cpu_data(cpuid).ecache_line_size =
544 of_getintprop_default(dp, "l2-cache-line-size", 0);
545 if (!cpu_data(cpuid).ecache_size ||
546 !cpu_data(cpuid).ecache_line_size) {
547 cpu_data(cpuid).ecache_size =
548 of_getintprop_default(portid_parent,
549 "l2-cache-size",
550 (4 * 1024 * 1024));
551 cpu_data(cpuid).ecache_line_size =
552 of_getintprop_default(portid_parent,
553 "l2-cache-line-size", 64);
556 cpu_data(cpuid).core_id = portid + 1;
557 cpu_data(cpuid).proc_id = portid;
558 #ifdef CONFIG_SMP
559 sparc64_multi_core = 1;
560 #endif
561 } else {
562 cpu_data(cpuid).dcache_size =
563 of_getintprop_default(dp, "dcache-size", 16 * 1024);
564 cpu_data(cpuid).dcache_line_size =
565 of_getintprop_default(dp, "dcache-line-size", 32);
567 cpu_data(cpuid).icache_size =
568 of_getintprop_default(dp, "icache-size", 16 * 1024);
569 cpu_data(cpuid).icache_line_size =
570 of_getintprop_default(dp, "icache-line-size", 32);
572 cpu_data(cpuid).ecache_size =
573 of_getintprop_default(dp, "ecache-size",
574 (4 * 1024 * 1024));
575 cpu_data(cpuid).ecache_line_size =
576 of_getintprop_default(dp, "ecache-line-size", 64);
578 cpu_data(cpuid).core_id = 0;
579 cpu_data(cpuid).proc_id = -1;
582 return NULL;
585 void __init of_fill_in_cpu_data(void)
587 if (tlb_type == hypervisor)
588 return;
590 of_iterate_over_cpus(fill_in_one_cpu, 0);
592 smp_fill_in_sib_core_maps();
595 void __init of_console_init(void)
597 char *msg = "OF stdout device is: %s\n";
598 struct device_node *dp;
599 const char *type;
600 phandle node;
602 of_console_path = prom_early_alloc(256);
603 if (prom_ihandle2path(prom_stdout, of_console_path, 256) < 0) {
604 prom_printf("Cannot obtain path of stdout.\n");
605 prom_halt();
607 of_console_options = strrchr(of_console_path, ':');
608 if (of_console_options) {
609 of_console_options++;
610 if (*of_console_options == '\0')
611 of_console_options = NULL;
614 node = prom_inst2pkg(prom_stdout);
615 if (!node) {
616 prom_printf("Cannot resolve stdout node from "
617 "instance %08x.\n", prom_stdout);
618 prom_halt();
621 dp = of_find_node_by_phandle(node);
622 type = of_get_property(dp, "device_type", NULL);
623 if (!type) {
624 prom_printf("Console stdout lacks device_type property.\n");
625 prom_halt();
628 if (strcmp(type, "display") && strcmp(type, "serial")) {
629 prom_printf("Console device_type is neither display "
630 "nor serial.\n");
631 prom_halt();
634 of_console_device = dp;
636 printk(msg, of_console_path);