mtd: nand: omap: Fix comment in platform data using wrong Kconfig symbol
[linux/fpc-iii.git] / arch / sparc / kernel / prom_64.c
blobc50ff1fee0e638b6f68671f8f7b0e5be0499caa4
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/memblock.h>
19 #include <linux/kernel.h>
20 #include <linux/string.h>
21 #include <linux/types.h>
22 #include <linux/cpu.h>
23 #include <linux/mm.h>
24 #include <linux/of.h>
26 #include <asm/prom.h>
27 #include <asm/oplib.h>
28 #include <asm/irq.h>
29 #include <asm/asi.h>
30 #include <asm/upa.h>
31 #include <asm/smp.h>
33 #include "prom.h"
35 void * __init prom_early_alloc(unsigned long size)
37 void *ret = memblock_alloc(size, SMP_CACHE_BYTES);
39 if (!ret) {
40 prom_printf("prom_early_alloc(%lu) failed\n", size);
41 prom_halt();
44 prom_early_allocated += size;
46 return ret;
49 /* The following routines deal with the black magic of fully naming a
50 * node.
52 * Certain well known named nodes are just the simple name string.
54 * Actual devices have an address specifier appended to the base name
55 * string, like this "foo@addr". The "addr" can be in any number of
56 * formats, and the platform plus the type of the node determine the
57 * format and how it is constructed.
59 * For children of the ROOT node, the naming convention is fixed and
60 * determined by whether this is a sun4u or sun4v system.
62 * For children of other nodes, it is bus type specific. So
63 * we walk up the tree until we discover a "device_type" property
64 * we recognize and we go from there.
66 * As an example, the boot device on my workstation has a full path:
68 * /pci@1e,600000/ide@d/disk@0,0:c
70 static void __init sun4v_path_component(struct device_node *dp, char *tmp_buf)
72 const char *name = of_get_property(dp, "name", NULL);
73 struct linux_prom64_registers *regs;
74 struct property *rprop;
75 u32 high_bits, low_bits, type;
77 rprop = of_find_property(dp, "reg", NULL);
78 if (!rprop)
79 return;
81 regs = rprop->value;
82 if (!of_node_is_root(dp->parent)) {
83 sprintf(tmp_buf, "%s@%x,%x",
84 name,
85 (unsigned int) (regs->phys_addr >> 32UL),
86 (unsigned int) (regs->phys_addr & 0xffffffffUL));
87 return;
90 type = regs->phys_addr >> 60UL;
91 high_bits = (regs->phys_addr >> 32UL) & 0x0fffffffUL;
92 low_bits = (regs->phys_addr & 0xffffffffUL);
94 if (type == 0 || type == 8) {
95 const char *prefix = (type == 0) ? "m" : "i";
97 if (low_bits)
98 sprintf(tmp_buf, "%s@%s%x,%x",
99 name, prefix,
100 high_bits, low_bits);
101 else
102 sprintf(tmp_buf, "%s@%s%x",
103 name,
104 prefix,
105 high_bits);
106 } else if (type == 12) {
107 sprintf(tmp_buf, "%s@%x",
108 name, high_bits);
112 static void __init sun4u_path_component(struct device_node *dp, char *tmp_buf)
114 const char *name = of_get_property(dp, "name", NULL);
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 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 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 const char *name = of_get_property(dp, "name", NULL);
151 struct linux_prom_registers *regs;
152 struct property *prop;
154 prop = of_find_property(dp, "reg", NULL);
155 if (!prop)
156 return;
158 regs = prop->value;
159 sprintf(tmp_buf, "%s@%x,%x",
160 name,
161 regs->which_io,
162 regs->phys_addr);
165 /* "name@devnum[,func]" */
166 static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
168 const char *name = of_get_property(dp, "name", NULL);
169 struct linux_prom_pci_registers *regs;
170 struct property *prop;
171 unsigned int devfn;
173 prop = of_find_property(dp, "reg", NULL);
174 if (!prop)
175 return;
177 regs = prop->value;
178 devfn = (regs->phys_hi >> 8) & 0xff;
179 if (devfn & 0x07) {
180 sprintf(tmp_buf, "%s@%x,%x",
181 name,
182 devfn >> 3,
183 devfn & 0x07);
184 } else {
185 sprintf(tmp_buf, "%s@%x",
186 name,
187 devfn >> 3);
191 /* "name@UPA_PORTID,offset" */
192 static void __init upa_path_component(struct device_node *dp, char *tmp_buf)
194 const char *name = of_get_property(dp, "name", NULL);
195 struct linux_prom64_registers *regs;
196 struct property *prop;
198 prop = of_find_property(dp, "reg", NULL);
199 if (!prop)
200 return;
202 regs = prop->value;
204 prop = of_find_property(dp, "upa-portid", NULL);
205 if (!prop)
206 return;
208 sprintf(tmp_buf, "%s@%x,%x",
209 name,
210 *(u32 *) prop->value,
211 (unsigned int) (regs->phys_addr & 0xffffffffUL));
214 /* "name@reg" */
215 static void __init vdev_path_component(struct device_node *dp, char *tmp_buf)
217 const char *name = of_get_property(dp, "name", NULL);
218 struct property *prop;
219 u32 *regs;
221 prop = of_find_property(dp, "reg", NULL);
222 if (!prop)
223 return;
225 regs = prop->value;
227 sprintf(tmp_buf, "%s@%x", name, *regs);
230 /* "name@addrhi,addrlo" */
231 static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
233 const char *name = of_get_property(dp, "name", NULL);
234 struct linux_prom64_registers *regs;
235 struct property *prop;
237 prop = of_find_property(dp, "reg", NULL);
238 if (!prop)
239 return;
241 regs = prop->value;
243 sprintf(tmp_buf, "%s@%x,%x",
244 name,
245 (unsigned int) (regs->phys_addr >> 32UL),
246 (unsigned int) (regs->phys_addr & 0xffffffffUL));
249 /* "name@bus,addr" */
250 static void __init i2c_path_component(struct device_node *dp, char *tmp_buf)
252 const char *name = of_get_property(dp, "name", NULL);
253 struct property *prop;
254 u32 *regs;
256 prop = of_find_property(dp, "reg", NULL);
257 if (!prop)
258 return;
260 regs = prop->value;
262 /* This actually isn't right... should look at the #address-cells
263 * property of the i2c bus node etc. etc.
265 sprintf(tmp_buf, "%s@%x,%x",
266 name, regs[0], regs[1]);
269 /* "name@reg0[,reg1]" */
270 static void __init usb_path_component(struct device_node *dp, char *tmp_buf)
272 const char *name = of_get_property(dp, "name", NULL);
273 struct property *prop;
274 u32 *regs;
276 prop = of_find_property(dp, "reg", NULL);
277 if (!prop)
278 return;
280 regs = prop->value;
282 if (prop->length == sizeof(u32) || regs[1] == 1) {
283 sprintf(tmp_buf, "%s@%x",
284 name, regs[0]);
285 } else {
286 sprintf(tmp_buf, "%s@%x,%x",
287 name, regs[0], regs[1]);
291 /* "name@reg0reg1[,reg2reg3]" */
292 static void __init ieee1394_path_component(struct device_node *dp, char *tmp_buf)
294 const char *name = of_get_property(dp, "name", NULL);
295 struct property *prop;
296 u32 *regs;
298 prop = of_find_property(dp, "reg", NULL);
299 if (!prop)
300 return;
302 regs = prop->value;
304 if (regs[2] || regs[3]) {
305 sprintf(tmp_buf, "%s@%08x%08x,%04x%08x",
306 name, regs[0], regs[1], regs[2], regs[3]);
307 } else {
308 sprintf(tmp_buf, "%s@%08x%08x",
309 name, regs[0], regs[1]);
313 static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
315 struct device_node *parent = dp->parent;
317 if (parent != NULL) {
318 if (of_node_is_type(parent, "pci") ||
319 of_node_is_type(parent, "pciex")) {
320 pci_path_component(dp, tmp_buf);
321 return;
323 if (of_node_is_type(parent, "sbus")) {
324 sbus_path_component(dp, tmp_buf);
325 return;
327 if (of_node_is_type(parent, "upa")) {
328 upa_path_component(dp, tmp_buf);
329 return;
331 if (of_node_is_type(parent, "ebus")) {
332 ebus_path_component(dp, tmp_buf);
333 return;
335 if (of_node_name_eq(parent, "usb") ||
336 of_node_name_eq(parent, "hub")) {
337 usb_path_component(dp, tmp_buf);
338 return;
340 if (of_node_is_type(parent, "i2c")) {
341 i2c_path_component(dp, tmp_buf);
342 return;
344 if (of_node_is_type(parent, "firewire")) {
345 ieee1394_path_component(dp, tmp_buf);
346 return;
348 if (of_node_is_type(parent, "virtual-devices")) {
349 vdev_path_component(dp, tmp_buf);
350 return;
352 /* "isa" is handled with platform naming */
355 /* Use platform naming convention. */
356 if (tlb_type == hypervisor) {
357 sun4v_path_component(dp, tmp_buf);
358 return;
359 } else {
360 sun4u_path_component(dp, tmp_buf);
364 char * __init build_path_component(struct device_node *dp)
366 const char *name = of_get_property(dp, "name", NULL);
367 char tmp_buf[64], *n;
369 tmp_buf[0] = '\0';
370 __build_path_component(dp, tmp_buf);
371 if (tmp_buf[0] == '\0')
372 strcpy(tmp_buf, name);
374 n = prom_early_alloc(strlen(tmp_buf) + 1);
375 strcpy(n, tmp_buf);
377 return n;
380 static const char *get_mid_prop(void)
382 return (tlb_type == spitfire ? "upa-portid" : "portid");
385 bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
386 int cpu, unsigned int *thread)
388 const char *mid_prop = get_mid_prop();
389 int this_cpu_id;
391 /* On hypervisor based platforms we interrogate the 'reg'
392 * property. On everything else we look for a 'upa-portid',
393 * 'portid', or 'cpuid' property.
396 if (tlb_type == hypervisor) {
397 struct property *prop = of_find_property(cpun, "reg", NULL);
398 u32 *regs;
400 if (!prop) {
401 pr_warn("CPU node missing reg property\n");
402 return false;
404 regs = prop->value;
405 this_cpu_id = regs[0] & 0x0fffffff;
406 } else {
407 this_cpu_id = of_getintprop_default(cpun, mid_prop, -1);
409 if (this_cpu_id < 0) {
410 mid_prop = "cpuid";
411 this_cpu_id = of_getintprop_default(cpun, mid_prop, -1);
413 if (this_cpu_id < 0) {
414 pr_warn("CPU node missing cpu ID property\n");
415 return false;
418 if (this_cpu_id == cpu) {
419 if (thread) {
420 int proc_id = cpu_data(cpu).proc_id;
422 /* On sparc64, the cpu thread information is obtained
423 * either from OBP or the machine description. We've
424 * actually probed this information already long before
425 * this interface gets called so instead of interrogating
426 * both the OF node and the MDESC again, just use what
427 * we discovered already.
429 if (proc_id < 0)
430 proc_id = 0;
431 *thread = proc_id;
433 return true;
435 return false;
438 static void *of_iterate_over_cpus(void *(*func)(struct device_node *, int, int), int arg)
440 struct device_node *dp;
441 const char *mid_prop;
443 mid_prop = get_mid_prop();
444 for_each_node_by_type(dp, "cpu") {
445 int cpuid = of_getintprop_default(dp, mid_prop, -1);
446 const char *this_mid_prop = mid_prop;
447 void *ret;
449 if (cpuid < 0) {
450 this_mid_prop = "cpuid";
451 cpuid = of_getintprop_default(dp, this_mid_prop, -1);
453 if (cpuid < 0) {
454 prom_printf("OF: Serious problem, cpu lacks "
455 "%s property", this_mid_prop);
456 prom_halt();
458 #ifdef CONFIG_SMP
459 if (cpuid >= NR_CPUS) {
460 printk(KERN_WARNING "Ignoring CPU %d which is "
461 ">= NR_CPUS (%d)\n",
462 cpuid, NR_CPUS);
463 continue;
465 #endif
466 ret = func(dp, cpuid, arg);
467 if (ret)
468 return ret;
470 return NULL;
473 static void *check_cpu_node(struct device_node *dp, int cpuid, int id)
475 if (id == cpuid)
476 return dp;
477 return NULL;
480 struct device_node *of_find_node_by_cpuid(int cpuid)
482 return of_iterate_over_cpus(check_cpu_node, cpuid);
485 static void *record_one_cpu(struct device_node *dp, int cpuid, int arg)
487 ncpus_probed++;
488 #ifdef CONFIG_SMP
489 set_cpu_present(cpuid, true);
490 set_cpu_possible(cpuid, true);
491 #endif
492 return NULL;
495 void __init of_populate_present_mask(void)
497 if (tlb_type == hypervisor)
498 return;
500 ncpus_probed = 0;
501 of_iterate_over_cpus(record_one_cpu, 0);
504 static void *fill_in_one_cpu(struct device_node *dp, int cpuid, int arg)
506 struct device_node *portid_parent = NULL;
507 int portid = -1;
509 if (of_find_property(dp, "cpuid", NULL)) {
510 int limit = 2;
512 portid_parent = dp;
513 while (limit--) {
514 portid_parent = portid_parent->parent;
515 if (!portid_parent)
516 break;
517 portid = of_getintprop_default(portid_parent,
518 "portid", -1);
519 if (portid >= 0)
520 break;
524 #ifndef CONFIG_SMP
525 /* On uniprocessor we only want the values for the
526 * real physical cpu the kernel booted onto, however
527 * cpu_data() only has one entry at index 0.
529 if (cpuid != real_hard_smp_processor_id())
530 return NULL;
531 cpuid = 0;
532 #endif
534 cpu_data(cpuid).clock_tick =
535 of_getintprop_default(dp, "clock-frequency", 0);
537 if (portid_parent) {
538 cpu_data(cpuid).dcache_size =
539 of_getintprop_default(dp, "l1-dcache-size",
540 16 * 1024);
541 cpu_data(cpuid).dcache_line_size =
542 of_getintprop_default(dp, "l1-dcache-line-size",
543 32);
544 cpu_data(cpuid).icache_size =
545 of_getintprop_default(dp, "l1-icache-size",
546 8 * 1024);
547 cpu_data(cpuid).icache_line_size =
548 of_getintprop_default(dp, "l1-icache-line-size",
549 32);
550 cpu_data(cpuid).ecache_size =
551 of_getintprop_default(dp, "l2-cache-size", 0);
552 cpu_data(cpuid).ecache_line_size =
553 of_getintprop_default(dp, "l2-cache-line-size", 0);
554 if (!cpu_data(cpuid).ecache_size ||
555 !cpu_data(cpuid).ecache_line_size) {
556 cpu_data(cpuid).ecache_size =
557 of_getintprop_default(portid_parent,
558 "l2-cache-size",
559 (4 * 1024 * 1024));
560 cpu_data(cpuid).ecache_line_size =
561 of_getintprop_default(portid_parent,
562 "l2-cache-line-size", 64);
565 cpu_data(cpuid).core_id = portid + 1;
566 cpu_data(cpuid).proc_id = portid;
567 } else {
568 cpu_data(cpuid).dcache_size =
569 of_getintprop_default(dp, "dcache-size", 16 * 1024);
570 cpu_data(cpuid).dcache_line_size =
571 of_getintprop_default(dp, "dcache-line-size", 32);
573 cpu_data(cpuid).icache_size =
574 of_getintprop_default(dp, "icache-size", 16 * 1024);
575 cpu_data(cpuid).icache_line_size =
576 of_getintprop_default(dp, "icache-line-size", 32);
578 cpu_data(cpuid).ecache_size =
579 of_getintprop_default(dp, "ecache-size",
580 (4 * 1024 * 1024));
581 cpu_data(cpuid).ecache_line_size =
582 of_getintprop_default(dp, "ecache-line-size", 64);
584 cpu_data(cpuid).core_id = 0;
585 cpu_data(cpuid).proc_id = -1;
588 return NULL;
591 void __init of_fill_in_cpu_data(void)
593 if (tlb_type == hypervisor)
594 return;
596 of_iterate_over_cpus(fill_in_one_cpu, 0);
598 smp_fill_in_sib_core_maps();
601 void __init of_console_init(void)
603 char *msg = "OF stdout device is: %s\n";
604 struct device_node *dp;
605 phandle node;
607 of_console_path = prom_early_alloc(256);
608 if (prom_ihandle2path(prom_stdout, of_console_path, 256) < 0) {
609 prom_printf("Cannot obtain path of stdout.\n");
610 prom_halt();
612 of_console_options = strrchr(of_console_path, ':');
613 if (of_console_options) {
614 of_console_options++;
615 if (*of_console_options == '\0')
616 of_console_options = NULL;
619 node = prom_inst2pkg(prom_stdout);
620 if (!node) {
621 prom_printf("Cannot resolve stdout node from "
622 "instance %08x.\n", prom_stdout);
623 prom_halt();
626 dp = of_find_node_by_phandle(node);
628 if (!of_node_is_type(dp, "display") && !of_node_is_type(dp, "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);