2 * Procedures for creating, accessing and interpreting the device tree.
4 * Paul Mackerras August 1996.
5 * Copyright (C) 1996-2005 Paul Mackerras.
7 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
8 * {engebret|bergner}@us.ibm.com
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
19 #include <linux/config.h>
20 #include <linux/kernel.h>
21 #include <linux/string.h>
22 #include <linux/init.h>
23 #include <linux/threads.h>
24 #include <linux/spinlock.h>
25 #include <linux/types.h>
26 #include <linux/pci.h>
27 #include <linux/stringify.h>
28 #include <linux/delay.h>
29 #include <linux/initrd.h>
30 #include <linux/bitops.h>
31 #include <linux/module.h>
32 #include <linux/kexec.h>
38 #include <asm/processor.h>
41 #include <asm/kdump.h>
43 #include <asm/system.h>
45 #include <asm/pgtable.h>
47 #include <asm/iommu.h>
48 #include <asm/btext.h>
49 #include <asm/sections.h>
50 #include <asm/machdep.h>
51 #include <asm/pSeries_reconfig.h>
52 #include <asm/pci-bridge.h>
53 #include <asm/kexec.h>
56 #define DBG(fmt...) printk(KERN_ERR fmt)
62 static int __initdata dt_root_addr_cells;
63 static int __initdata dt_root_size_cells;
66 int __initdata iommu_is_off;
67 int __initdata iommu_force_on;
68 unsigned long tce_alloc_start, tce_alloc_end;
74 static struct boot_param_header *initial_boot_params __initdata;
76 struct boot_param_header *initial_boot_params;
79 static struct device_node *allnodes = NULL;
81 /* use when traversing tree through the allnext, child, sibling,
82 * or parent members of struct device_node.
84 static DEFINE_RWLOCK(devtree_lock);
86 /* export that to outside world */
87 struct device_node *of_chosen;
89 struct device_node *dflt_interrupt_controller;
90 int num_interrupt_controllers;
93 * Wrapper for allocating memory for various data that needs to be
94 * attached to device nodes as they are processed at boot or when
95 * added to the device tree later (e.g. DLPAR). At boot there is
96 * already a region reserved so we just increment *mem_start by size;
97 * otherwise we call kmalloc.
99 static void * prom_alloc(unsigned long size, unsigned long *mem_start)
104 return kmalloc(size, GFP_KERNEL);
112 * Find the device_node with a given phandle.
114 static struct device_node * find_phandle(phandle ph)
116 struct device_node *np;
118 for (np = allnodes; np != 0; np = np->allnext)
119 if (np->linux_phandle == ph)
125 * Find the interrupt parent of a node.
127 static struct device_node * __devinit intr_parent(struct device_node *p)
131 parp = (phandle *) get_property(p, "interrupt-parent", NULL);
134 p = find_phandle(*parp);
138 * On a powermac booted with BootX, we don't get to know the
139 * phandles for any nodes, so find_phandle will return NULL.
140 * Fortunately these machines only have one interrupt controller
141 * so there isn't in fact any ambiguity. -- paulus
143 if (num_interrupt_controllers == 1)
144 p = dflt_interrupt_controller;
149 * Find out the size of each entry of the interrupts property
152 int __devinit prom_n_intr_cells(struct device_node *np)
154 struct device_node *p;
157 for (p = np; (p = intr_parent(p)) != NULL; ) {
158 icp = (unsigned int *)
159 get_property(p, "#interrupt-cells", NULL);
162 if (get_property(p, "interrupt-controller", NULL) != NULL
163 || get_property(p, "interrupt-map", NULL) != NULL) {
164 printk("oops, node %s doesn't have #interrupt-cells\n",
170 printk("prom_n_intr_cells failed for %s\n", np->full_name);
176 * Map an interrupt from a device up to the platform interrupt
179 static int __devinit map_interrupt(unsigned int **irq, struct device_node **ictrler,
180 struct device_node *np, unsigned int *ints,
183 struct device_node *p, *ipar;
184 unsigned int *imap, *imask, *ip;
185 int i, imaplen, match;
186 int newintrc = 0, newaddrc = 0;
190 reg = (unsigned int *) get_property(np, "reg", NULL);
191 naddrc = prom_n_addr_cells(np);
194 if (get_property(p, "interrupt-controller", NULL) != NULL)
195 /* this node is an interrupt controller, stop here */
197 imap = (unsigned int *)
198 get_property(p, "interrupt-map", &imaplen);
203 imask = (unsigned int *)
204 get_property(p, "interrupt-map-mask", NULL);
206 printk("oops, %s has interrupt-map but no mask\n",
210 imaplen /= sizeof(unsigned int);
213 while (imaplen > 0 && !match) {
214 /* check the child-interrupt field */
216 for (i = 0; i < naddrc && match; ++i)
217 match = ((reg[i] ^ imap[i]) & imask[i]) == 0;
218 for (; i < naddrc + nintrc && match; ++i)
219 match = ((ints[i-naddrc] ^ imap[i]) & imask[i]) == 0;
220 imap += naddrc + nintrc;
221 imaplen -= naddrc + nintrc;
222 /* grab the interrupt parent */
223 ipar = find_phandle((phandle) *imap++);
225 if (ipar == NULL && num_interrupt_controllers == 1)
226 /* cope with BootX not giving us phandles */
227 ipar = dflt_interrupt_controller;
229 printk("oops, no int parent %x in map of %s\n",
230 imap[-1], p->full_name);
233 /* find the parent's # addr and intr cells */
234 ip = (unsigned int *)
235 get_property(ipar, "#interrupt-cells", NULL);
237 printk("oops, no #interrupt-cells on %s\n",
242 ip = (unsigned int *)
243 get_property(ipar, "#address-cells", NULL);
244 newaddrc = (ip == NULL)? 0: *ip;
245 imap += newaddrc + newintrc;
246 imaplen -= newaddrc + newintrc;
249 printk("oops, error decoding int-map on %s, len=%d\n",
250 p->full_name, imaplen);
255 printk("oops, no match in %s int-map for %s\n",
256 p->full_name, np->full_name);
263 ints = imap - nintrc;
268 printk("hmmm, int tree for %s doesn't have ctrler\n",
278 static unsigned char map_isa_senses[4] = {
279 IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE,
280 IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE,
281 IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE,
282 IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE
285 static unsigned char map_mpic_senses[4] = {
286 IRQ_SENSE_EDGE | IRQ_POLARITY_POSITIVE,
287 IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE,
288 /* 2 seems to be used for the 8259 cascade... */
289 IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE,
290 IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE,
293 static int __devinit finish_node_interrupts(struct device_node *np,
294 unsigned long *mem_start,
298 int intlen, intrcells, intrcount;
300 unsigned int *irq, virq;
301 struct device_node *ic;
304 //#define TRACE(fmt...) do { if (trace) { printk(fmt); mdelay(1000); } } while(0)
305 #define TRACE(fmt...)
307 if (!strcmp(np->name, "smu-doorbell"))
310 TRACE("Finishing SMU doorbell ! num_interrupt_controllers = %d\n",
311 num_interrupt_controllers);
313 if (num_interrupt_controllers == 0) {
315 * Old machines just have a list of interrupt numbers
316 * and no interrupt-controller nodes.
318 ints = (unsigned int *) get_property(np, "AAPL,interrupts",
320 /* XXX old interpret_pci_props looked in parent too */
321 /* XXX old interpret_macio_props looked for interrupts
322 before AAPL,interrupts */
324 ints = (unsigned int *) get_property(np, "interrupts",
329 np->n_intrs = intlen / sizeof(unsigned int);
330 np->intrs = prom_alloc(np->n_intrs * sizeof(np->intrs[0]),
337 for (i = 0; i < np->n_intrs; ++i) {
338 np->intrs[i].line = *ints++;
339 np->intrs[i].sense = IRQ_SENSE_LEVEL
340 | IRQ_POLARITY_NEGATIVE;
345 ints = (unsigned int *) get_property(np, "interrupts", &intlen);
346 TRACE("ints=%p, intlen=%d\n", ints, intlen);
349 intrcells = prom_n_intr_cells(np);
350 intlen /= intrcells * sizeof(unsigned int);
351 TRACE("intrcells=%d, new intlen=%d\n", intrcells, intlen);
352 np->intrs = prom_alloc(intlen * sizeof(*(np->intrs)), mem_start);
360 for (i = 0; i < intlen; ++i, ints += intrcells) {
361 n = map_interrupt(&irq, &ic, np, ints, intrcells);
362 TRACE("map, irq=%d, ic=%p, n=%d\n", irq, ic, n);
366 /* don't map IRQ numbers under a cascaded 8259 controller */
367 if (ic && device_is_compatible(ic, "chrp,iic")) {
368 np->intrs[intrcount].line = irq[0];
369 sense = (n > 1)? (irq[1] & 3): 3;
370 np->intrs[intrcount].sense = map_isa_senses[sense];
372 virq = virt_irq_create_mapping(irq[0]);
373 TRACE("virq=%d\n", virq);
375 if (virq == NO_IRQ) {
376 printk(KERN_CRIT "Could not allocate interrupt"
377 " number for %s\n", np->full_name);
381 np->intrs[intrcount].line = irq_offset_up(virq);
382 sense = (n > 1)? (irq[1] & 3): 1;
384 /* Apple uses bits in there in a different way, let's
385 * only keep the real sense bit on macs
387 if (machine_is(powermac))
389 np->intrs[intrcount].sense = map_mpic_senses[sense];
393 /* We offset irq numbers for the u3 MPIC by 128 in PowerMac */
394 if (machine_is(powermac) && ic && ic->parent) {
395 char *name = get_property(ic->parent, "name", NULL);
396 if (name && !strcmp(name, "u3"))
397 np->intrs[intrcount].line += 128;
398 else if (!(name && (!strcmp(name, "mac-io") ||
399 !strcmp(name, "u4"))))
400 /* ignore other cascaded controllers, such as
404 #endif /* CONFIG_PPC64 */
406 printk("hmmm, got %d intr cells for %s:", n,
408 for (j = 0; j < n; ++j)
409 printk(" %d", irq[j]);
414 np->n_intrs = intrcount;
419 static int __devinit finish_node(struct device_node *np,
420 unsigned long *mem_start,
423 struct device_node *child;
426 rc = finish_node_interrupts(np, mem_start, measure_only);
430 for (child = np->child; child != NULL; child = child->sibling) {
431 rc = finish_node(child, mem_start, measure_only);
439 static void __init scan_interrupt_controllers(void)
441 struct device_node *np;
446 for (np = allnodes; np != NULL; np = np->allnext) {
447 ic = get_property(np, "interrupt-controller", &iclen);
448 name = get_property(np, "name", NULL);
449 /* checking iclen makes sure we don't get a false
450 match on /chosen.interrupt_controller */
452 && strcmp(name, "interrupt-controller") == 0)
453 || (ic != NULL && iclen == 0
454 && strcmp(name, "AppleKiwi"))) {
456 dflt_interrupt_controller = np;
460 num_interrupt_controllers = n;
464 * finish_device_tree is called once things are running normally
465 * (i.e. with text and data mapped to the address they were linked at).
466 * It traverses the device tree and fills in some of the additional,
467 * fields in each node like {n_}addrs and {n_}intrs, the virt interrupt
468 * mapping is also initialized at this point.
470 void __init finish_device_tree(void)
472 unsigned long start, end, size = 0;
474 DBG(" -> finish_device_tree\n");
477 /* Initialize virtual IRQ map */
480 scan_interrupt_controllers();
483 * Finish device-tree (pre-parsing some properties etc...)
484 * We do this in 2 passes. One with "measure_only" set, which
485 * will only measure the amount of memory needed, then we can
486 * allocate that memory, and call finish_node again. However,
487 * we must be careful as most routines will fail nowadays when
488 * prom_alloc() returns 0, so we must make sure our first pass
489 * doesn't start at 0. We pre-initialize size to 16 for that
490 * reason and then remove those additional 16 bytes
493 finish_node(allnodes, &size, 1);
499 end = start = (unsigned long)__va(lmb_alloc(size, 128));
501 finish_node(allnodes, &end, 0);
502 BUG_ON(end != start + size);
504 DBG(" <- finish_device_tree\n");
507 static inline char *find_flat_dt_string(u32 offset)
509 return ((char *)initial_boot_params) +
510 initial_boot_params->off_dt_strings + offset;
514 * This function is used to scan the flattened device-tree, it is
515 * used to extract the memory informations at boot before we can
518 int __init of_scan_flat_dt(int (*it)(unsigned long node,
519 const char *uname, int depth,
523 unsigned long p = ((unsigned long)initial_boot_params) +
524 initial_boot_params->off_dt_struct;
529 u32 tag = *((u32 *)p);
533 if (tag == OF_DT_END_NODE) {
537 if (tag == OF_DT_NOP)
539 if (tag == OF_DT_END)
541 if (tag == OF_DT_PROP) {
542 u32 sz = *((u32 *)p);
544 if (initial_boot_params->version < 0x10)
545 p = _ALIGN(p, sz >= 8 ? 8 : 4);
550 if (tag != OF_DT_BEGIN_NODE) {
551 printk(KERN_WARNING "Invalid tag %x scanning flattened"
552 " device tree !\n", tag);
557 p = _ALIGN(p + strlen(pathp) + 1, 4);
558 if ((*pathp) == '/') {
560 for (lp = NULL, np = pathp; *np; np++)
566 rc = it(p, pathp, depth, data);
574 unsigned long __init of_get_flat_dt_root(void)
576 unsigned long p = ((unsigned long)initial_boot_params) +
577 initial_boot_params->off_dt_struct;
579 while(*((u32 *)p) == OF_DT_NOP)
581 BUG_ON (*((u32 *)p) != OF_DT_BEGIN_NODE);
583 return _ALIGN(p + strlen((char *)p) + 1, 4);
587 * This function can be used within scan_flattened_dt callback to get
588 * access to properties
590 void* __init of_get_flat_dt_prop(unsigned long node, const char *name,
593 unsigned long p = node;
596 u32 tag = *((u32 *)p);
601 if (tag == OF_DT_NOP)
603 if (tag != OF_DT_PROP)
607 noff = *((u32 *)(p + 4));
609 if (initial_boot_params->version < 0x10)
610 p = _ALIGN(p, sz >= 8 ? 8 : 4);
612 nstr = find_flat_dt_string(noff);
614 printk(KERN_WARNING "Can't find property index"
618 if (strcmp(name, nstr) == 0) {
628 int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
631 unsigned long cplen, l;
633 cp = of_get_flat_dt_prop(node, "compatible", &cplen);
637 if (strncasecmp(cp, compat, strlen(compat)) == 0)
647 static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size,
652 *mem = _ALIGN(*mem, align);
659 static unsigned long __init unflatten_dt_node(unsigned long mem,
661 struct device_node *dad,
662 struct device_node ***allnextpp,
663 unsigned long fpsize)
665 struct device_node *np;
666 struct property *pp, **prev_pp = NULL;
669 unsigned int l, allocl;
673 tag = *((u32 *)(*p));
674 if (tag != OF_DT_BEGIN_NODE) {
675 printk("Weird tag at start of node: %x\n", tag);
680 l = allocl = strlen(pathp) + 1;
681 *p = _ALIGN(*p + l, 4);
683 /* version 0x10 has a more compact unit name here instead of the full
684 * path. we accumulate the full path size using "fpsize", we'll rebuild
685 * it later. We detect this because the first character of the name is
688 if ((*pathp) != '/') {
691 /* root node: special case. fpsize accounts for path
692 * plus terminating zero. root node only has '/', so
693 * fpsize should be 2, but we want to avoid the first
694 * level nodes to have two '/' so we use fpsize 1 here
699 /* account for '/' and path size minus terminal 0
708 np = unflatten_dt_alloc(&mem, sizeof(struct device_node) + allocl,
709 __alignof__(struct device_node));
711 memset(np, 0, sizeof(*np));
712 np->full_name = ((char*)np) + sizeof(struct device_node);
714 char *p = np->full_name;
715 /* rebuild full path for new format */
716 if (dad && dad->parent) {
717 strcpy(p, dad->full_name);
719 if ((strlen(p) + l + 1) != allocl) {
720 DBG("%s: p: %d, l: %d, a: %d\n",
721 pathp, (int)strlen(p), l, allocl);
729 memcpy(np->full_name, pathp, l);
730 prev_pp = &np->properties;
732 *allnextpp = &np->allnext;
735 /* we temporarily use the next field as `last_child'*/
739 dad->next->sibling = np;
742 kref_init(&np->kref);
748 tag = *((u32 *)(*p));
749 if (tag == OF_DT_NOP) {
753 if (tag != OF_DT_PROP)
757 noff = *((u32 *)((*p) + 4));
759 if (initial_boot_params->version < 0x10)
760 *p = _ALIGN(*p, sz >= 8 ? 8 : 4);
762 pname = find_flat_dt_string(noff);
764 printk("Can't find property name in list !\n");
767 if (strcmp(pname, "name") == 0)
769 l = strlen(pname) + 1;
770 pp = unflatten_dt_alloc(&mem, sizeof(struct property),
771 __alignof__(struct property));
773 if (strcmp(pname, "linux,phandle") == 0) {
774 np->node = *((u32 *)*p);
775 if (np->linux_phandle == 0)
776 np->linux_phandle = np->node;
778 if (strcmp(pname, "ibm,phandle") == 0)
779 np->linux_phandle = *((u32 *)*p);
782 pp->value = (void *)*p;
786 *p = _ALIGN((*p) + sz, 4);
788 /* with version 0x10 we may not have the name property, recreate
789 * it here from the unit name if absent
792 char *p = pathp, *ps = pathp, *pa = NULL;
805 pp = unflatten_dt_alloc(&mem, sizeof(struct property) + sz,
806 __alignof__(struct property));
810 pp->value = (unsigned char *)(pp + 1);
813 memcpy(pp->value, ps, sz - 1);
814 ((char *)pp->value)[sz - 1] = 0;
815 DBG("fixed up name for %s -> %s\n", pathp, pp->value);
820 np->name = get_property(np, "name", NULL);
821 np->type = get_property(np, "device_type", NULL);
828 while (tag == OF_DT_BEGIN_NODE) {
829 mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize);
830 tag = *((u32 *)(*p));
832 if (tag != OF_DT_END_NODE) {
833 printk("Weird tag at end of node: %x\n", tag);
840 static int __init early_parse_mem(char *p)
845 memory_limit = PAGE_ALIGN(memparse(p, &p));
846 DBG("memory limit = 0x%lx\n", memory_limit);
850 early_param("mem", early_parse_mem);
853 * The device tree may be allocated below our memory limit, or inside the
854 * crash kernel region for kdump. If so, move it out now.
856 static void move_device_tree(void)
858 unsigned long start, size;
861 DBG("-> move_device_tree\n");
863 start = __pa(initial_boot_params);
864 size = initial_boot_params->totalsize;
866 if ((memory_limit && (start + size) > memory_limit) ||
867 overlaps_crashkernel(start, size)) {
868 p = __va(lmb_alloc_base(size, PAGE_SIZE, lmb.rmo_size));
869 memcpy(p, initial_boot_params, size);
870 initial_boot_params = (struct boot_param_header *)p;
871 DBG("Moved device tree to 0x%p\n", p);
874 DBG("<- move_device_tree\n");
878 * unflattens the device-tree passed by the firmware, creating the
879 * tree of struct device_node. It also fills the "name" and "type"
880 * pointers of the nodes so the normal device-tree walking functions
881 * can be used (this used to be done by finish_device_tree)
883 void __init unflatten_device_tree(void)
885 unsigned long start, mem, size;
886 struct device_node **allnextp = &allnodes;
888 DBG(" -> unflatten_device_tree()\n");
890 /* First pass, scan for size */
891 start = ((unsigned long)initial_boot_params) +
892 initial_boot_params->off_dt_struct;
893 size = unflatten_dt_node(0, &start, NULL, NULL, 0);
894 size = (size | 3) + 1;
896 DBG(" size is %lx, allocating...\n", size);
898 /* Allocate memory for the expanded device tree */
899 mem = lmb_alloc(size + 4, __alignof__(struct device_node));
900 mem = (unsigned long) __va(mem);
902 ((u32 *)mem)[size / 4] = 0xdeadbeef;
904 DBG(" unflattening %lx...\n", mem);
906 /* Second pass, do actual unflattening */
907 start = ((unsigned long)initial_boot_params) +
908 initial_boot_params->off_dt_struct;
909 unflatten_dt_node(mem, &start, NULL, &allnextp, 0);
910 if (*((u32 *)start) != OF_DT_END)
911 printk(KERN_WARNING "Weird tag at end of tree: %08x\n", *((u32 *)start));
912 if (((u32 *)mem)[size / 4] != 0xdeadbeef)
913 printk(KERN_WARNING "End of tree marker overwritten: %08x\n",
914 ((u32 *)mem)[size / 4] );
917 /* Get pointer to OF "/chosen" node for use everywhere */
918 of_chosen = of_find_node_by_path("/chosen");
919 if (of_chosen == NULL)
920 of_chosen = of_find_node_by_path("/chosen@0");
922 DBG(" <- unflatten_device_tree()\n");
926 * ibm,pa-features is a per-cpu property that contains a string of
927 * attribute descriptors, each of which has a 2 byte header plus up
928 * to 254 bytes worth of processor attribute bits. First header
929 * byte specifies the number of bytes following the header.
930 * Second header byte is an "attribute-specifier" type, of which
931 * zero is the only currently-defined value.
932 * Implementation: Pass in the byte and bit offset for the feature
933 * that we are interested in. The function will return -1 if the
934 * pa-features property is missing, or a 1/0 to indicate if the feature
935 * is supported/not supported. Note that the bit numbers are
936 * big-endian to match the definition in PAPR.
938 static struct ibm_pa_feature {
939 unsigned long cpu_features; /* CPU_FTR_xxx bit */
940 unsigned int cpu_user_ftrs; /* PPC_FEATURE_xxx bit */
941 unsigned char pabyte; /* byte number in ibm,pa-features */
942 unsigned char pabit; /* bit number (big-endian) */
943 unsigned char invert; /* if 1, pa bit set => clear feature */
944 } ibm_pa_features[] __initdata = {
945 {0, PPC_FEATURE_HAS_MMU, 0, 0, 0},
946 {0, PPC_FEATURE_HAS_FPU, 0, 1, 0},
947 {CPU_FTR_SLB, 0, 0, 2, 0},
948 {CPU_FTR_CTRL, 0, 0, 3, 0},
949 {CPU_FTR_NOEXECUTE, 0, 0, 6, 0},
950 {CPU_FTR_NODSISRALIGN, 0, 1, 1, 1},
951 {CPU_FTR_CI_LARGE_PAGE, 0, 1, 2, 0},
954 static void __init check_cpu_pa_features(unsigned long node)
956 unsigned char *pa_ftrs;
957 unsigned long len, tablelen, i, bit;
959 pa_ftrs = of_get_flat_dt_prop(node, "ibm,pa-features", &tablelen);
963 /* find descriptor with type == 0 */
967 len = 2 + pa_ftrs[0];
969 return; /* descriptor 0 not found */
976 /* loop over bits we know about */
977 for (i = 0; i < ARRAY_SIZE(ibm_pa_features); ++i) {
978 struct ibm_pa_feature *fp = &ibm_pa_features[i];
980 if (fp->pabyte >= pa_ftrs[0])
982 bit = (pa_ftrs[2 + fp->pabyte] >> (7 - fp->pabit)) & 1;
983 if (bit ^ fp->invert) {
984 cur_cpu_spec->cpu_features |= fp->cpu_features;
985 cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftrs;
987 cur_cpu_spec->cpu_features &= ~fp->cpu_features;
988 cur_cpu_spec->cpu_user_features &= ~fp->cpu_user_ftrs;
993 static int __init early_init_dt_scan_cpus(unsigned long node,
994 const char *uname, int depth,
997 static int logical_cpuid = 0;
998 char *type = of_get_flat_dt_prop(node, "device_type", NULL);
999 #ifdef CONFIG_ALTIVEC
1007 /* We are scanning "cpu" nodes only */
1008 if (type == NULL || strcmp(type, "cpu") != 0)
1011 /* Get physical cpuid */
1012 intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len);
1014 nthreads = len / sizeof(int);
1016 intserv = of_get_flat_dt_prop(node, "reg", NULL);
1021 * Now see if any of these threads match our boot cpu.
1022 * NOTE: This must match the parsing done in smp_setup_cpu_maps.
1024 for (i = 0; i < nthreads; i++) {
1026 * version 2 of the kexec param format adds the phys cpuid of
1029 if (initial_boot_params && initial_boot_params->version >= 2) {
1031 initial_boot_params->boot_cpuid_phys) {
1037 * Check if it's the boot-cpu, set it's hw index now,
1038 * unfortunately this format did not support booting
1039 * off secondary threads.
1041 if (of_get_flat_dt_prop(node,
1042 "linux,boot-cpu", NULL) != NULL) {
1049 /* logical cpu id is always 0 on UP kernels */
1055 DBG("boot cpu: logical %d physical %d\n", logical_cpuid,
1057 boot_cpuid = logical_cpuid;
1058 set_hard_smp_processor_id(boot_cpuid, intserv[i]);
1061 #ifdef CONFIG_ALTIVEC
1062 /* Check if we have a VMX and eventually update CPU features */
1063 prop = (u32 *)of_get_flat_dt_prop(node, "ibm,vmx", NULL);
1064 if (prop && (*prop) > 0) {
1065 cur_cpu_spec->cpu_features |= CPU_FTR_ALTIVEC;
1066 cur_cpu_spec->cpu_user_features |= PPC_FEATURE_HAS_ALTIVEC;
1069 /* Same goes for Apple's "altivec" property */
1070 prop = (u32 *)of_get_flat_dt_prop(node, "altivec", NULL);
1072 cur_cpu_spec->cpu_features |= CPU_FTR_ALTIVEC;
1073 cur_cpu_spec->cpu_user_features |= PPC_FEATURE_HAS_ALTIVEC;
1075 #endif /* CONFIG_ALTIVEC */
1077 check_cpu_pa_features(node);
1079 #ifdef CONFIG_PPC_PSERIES
1081 cur_cpu_spec->cpu_features |= CPU_FTR_SMT;
1083 cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT;
1089 static int __init early_init_dt_scan_chosen(unsigned long node,
1090 const char *uname, int depth, void *data)
1092 unsigned long *lprop;
1096 DBG("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
1099 (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
1103 /* check if iommu is forced on or off */
1104 if (of_get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL)
1106 if (of_get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL)
1110 /* mem=x on the command line is the preferred mechanism */
1111 lprop = of_get_flat_dt_prop(node, "linux,memory-limit", NULL);
1113 memory_limit = *lprop;
1116 lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-start", NULL);
1118 tce_alloc_start = *lprop;
1119 lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-end", NULL);
1121 tce_alloc_end = *lprop;
1124 #ifdef CONFIG_PPC_RTAS
1125 /* To help early debugging via the front panel, we retrieve a minimal
1126 * set of RTAS infos now if available
1129 u64 *basep, *entryp, *sizep;
1131 basep = of_get_flat_dt_prop(node, "linux,rtas-base", NULL);
1132 entryp = of_get_flat_dt_prop(node, "linux,rtas-entry", NULL);
1133 sizep = of_get_flat_dt_prop(node, "linux,rtas-size", NULL);
1134 if (basep && entryp && sizep) {
1136 rtas.entry = *entryp;
1140 #endif /* CONFIG_PPC_RTAS */
1143 lprop = (u64*)of_get_flat_dt_prop(node, "linux,crashkernel-base", NULL);
1145 crashk_res.start = *lprop;
1147 lprop = (u64*)of_get_flat_dt_prop(node, "linux,crashkernel-size", NULL);
1149 crashk_res.end = crashk_res.start + *lprop - 1;
1152 /* Retreive command line */
1153 p = of_get_flat_dt_prop(node, "bootargs", &l);
1154 if (p != NULL && l > 0)
1155 strlcpy(cmd_line, p, min((int)l, COMMAND_LINE_SIZE));
1157 #ifdef CONFIG_CMDLINE
1158 if (l == 0 || (l == 1 && (*p) == 0))
1159 strlcpy(cmd_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
1160 #endif /* CONFIG_CMDLINE */
1162 DBG("Command line is: %s\n", cmd_line);
1168 static int __init early_init_dt_scan_root(unsigned long node,
1169 const char *uname, int depth, void *data)
1176 prop = of_get_flat_dt_prop(node, "#size-cells", NULL);
1177 dt_root_size_cells = (prop == NULL) ? 1 : *prop;
1178 DBG("dt_root_size_cells = %x\n", dt_root_size_cells);
1180 prop = of_get_flat_dt_prop(node, "#address-cells", NULL);
1181 dt_root_addr_cells = (prop == NULL) ? 2 : *prop;
1182 DBG("dt_root_addr_cells = %x\n", dt_root_addr_cells);
1188 static unsigned long __init dt_mem_next_cell(int s, cell_t **cellp)
1193 /* Ignore more than 2 cells */
1194 while (s > sizeof(unsigned long) / 4) {
1212 static int __init early_init_dt_scan_memory(unsigned long node,
1213 const char *uname, int depth, void *data)
1215 char *type = of_get_flat_dt_prop(node, "device_type", NULL);
1219 /* We are scanning "memory" nodes only */
1222 * The longtrail doesn't have a device_type on the
1223 * /memory node, so look for the node called /memory@0.
1225 if (depth != 1 || strcmp(uname, "memory@0") != 0)
1227 } else if (strcmp(type, "memory") != 0)
1230 reg = (cell_t *)of_get_flat_dt_prop(node, "linux,usable-memory", &l);
1232 reg = (cell_t *)of_get_flat_dt_prop(node, "reg", &l);
1236 endp = reg + (l / sizeof(cell_t));
1238 DBG("memory scan node %s, reg size %ld, data: %x %x %x %x,\n",
1239 uname, l, reg[0], reg[1], reg[2], reg[3]);
1241 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
1242 unsigned long base, size;
1244 base = dt_mem_next_cell(dt_root_addr_cells, ®);
1245 size = dt_mem_next_cell(dt_root_size_cells, ®);
1249 DBG(" - %lx , %lx\n", base, size);
1252 if (base >= 0x80000000ul)
1254 if ((base + size) > 0x80000000ul)
1255 size = 0x80000000ul - base;
1258 lmb_add(base, size);
1263 static void __init early_reserve_mem(void)
1268 reserve_map = (u64 *)(((unsigned long)initial_boot_params) +
1269 initial_boot_params->off_mem_rsvmap);
1272 * Handle the case where we might be booting from an old kexec
1273 * image that setup the mem_rsvmap as pairs of 32-bit values
1275 if (*reserve_map > 0xffffffffull) {
1276 u32 base_32, size_32;
1277 u32 *reserve_map_32 = (u32 *)reserve_map;
1280 base_32 = *(reserve_map_32++);
1281 size_32 = *(reserve_map_32++);
1284 DBG("reserving: %x -> %x\n", base_32, size_32);
1285 lmb_reserve(base_32, size_32);
1291 base = *(reserve_map++);
1292 size = *(reserve_map++);
1295 DBG("reserving: %llx -> %llx\n", base, size);
1296 lmb_reserve(base, size);
1300 DBG("memory reserved, lmbs :\n");
1305 void __init early_init_devtree(void *params)
1307 DBG(" -> early_init_devtree()\n");
1309 /* Setup flat device-tree pointer */
1310 initial_boot_params = params;
1312 /* Retrieve various informations from the /chosen node of the
1313 * device-tree, including the platform type, initrd location and
1314 * size, TCE reserve, and more ...
1316 of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
1318 /* Scan memory nodes and rebuild LMBs */
1320 of_scan_flat_dt(early_init_dt_scan_root, NULL);
1321 of_scan_flat_dt(early_init_dt_scan_memory, NULL);
1323 /* Save command line for /proc/cmdline and then parse parameters */
1324 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
1325 parse_early_param();
1327 /* Reserve LMB regions used by kernel, initrd, dt, etc... */
1328 lmb_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START);
1329 #ifdef CONFIG_CRASH_DUMP
1330 lmb_reserve(0, KDUMP_RESERVE_LIMIT);
1332 early_reserve_mem();
1334 lmb_enforce_memory_limit(memory_limit);
1337 DBG("Phys. mem: %lx\n", lmb_phys_mem_size());
1339 /* We may need to relocate the flat tree, do it now.
1340 * FIXME .. and the initrd too? */
1343 DBG("Scanning CPUs ...\n");
1345 /* Retreive CPU related informations from the flat tree
1346 * (altivec support, boot CPU ID, ...)
1348 of_scan_flat_dt(early_init_dt_scan_cpus, NULL);
1350 DBG(" <- early_init_devtree()\n");
1356 prom_n_addr_cells(struct device_node* np)
1362 ip = (int *) get_property(np, "#address-cells", NULL);
1365 } while (np->parent);
1366 /* No #address-cells property for the root node, default to 1 */
1369 EXPORT_SYMBOL(prom_n_addr_cells);
1372 prom_n_size_cells(struct device_node* np)
1378 ip = (int *) get_property(np, "#size-cells", NULL);
1381 } while (np->parent);
1382 /* No #size-cells property for the root node, default to 1 */
1385 EXPORT_SYMBOL(prom_n_size_cells);
1388 * Work out the sense (active-low level / active-high edge)
1389 * of each interrupt from the device tree.
1391 void __init prom_get_irq_senses(unsigned char *senses, int off, int max)
1393 struct device_node *np;
1396 /* default to level-triggered */
1397 memset(senses, IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE, max - off);
1399 for (np = allnodes; np != 0; np = np->allnext) {
1400 for (j = 0; j < np->n_intrs; j++) {
1401 i = np->intrs[j].line;
1402 if (i >= off && i < max)
1403 senses[i-off] = np->intrs[j].sense;
1409 * Construct and return a list of the device_nodes with a given name.
1411 struct device_node *find_devices(const char *name)
1413 struct device_node *head, **prevp, *np;
1416 for (np = allnodes; np != 0; np = np->allnext) {
1417 if (np->name != 0 && strcasecmp(np->name, name) == 0) {
1425 EXPORT_SYMBOL(find_devices);
1428 * Construct and return a list of the device_nodes with a given type.
1430 struct device_node *find_type_devices(const char *type)
1432 struct device_node *head, **prevp, *np;
1435 for (np = allnodes; np != 0; np = np->allnext) {
1436 if (np->type != 0 && strcasecmp(np->type, type) == 0) {
1444 EXPORT_SYMBOL(find_type_devices);
1447 * Returns all nodes linked together
1449 struct device_node *find_all_nodes(void)
1451 struct device_node *head, **prevp, *np;
1454 for (np = allnodes; np != 0; np = np->allnext) {
1461 EXPORT_SYMBOL(find_all_nodes);
1463 /** Checks if the given "compat" string matches one of the strings in
1464 * the device's "compatible" property
1466 int device_is_compatible(struct device_node *device, const char *compat)
1471 cp = (char *) get_property(device, "compatible", &cplen);
1475 if (strncasecmp(cp, compat, strlen(compat)) == 0)
1484 EXPORT_SYMBOL(device_is_compatible);
1488 * Indicates whether the root node has a given value in its
1489 * compatible property.
1491 int machine_is_compatible(const char *compat)
1493 struct device_node *root;
1496 root = of_find_node_by_path("/");
1498 rc = device_is_compatible(root, compat);
1503 EXPORT_SYMBOL(machine_is_compatible);
1506 * Construct and return a list of the device_nodes with a given type
1507 * and compatible property.
1509 struct device_node *find_compatible_devices(const char *type,
1512 struct device_node *head, **prevp, *np;
1515 for (np = allnodes; np != 0; np = np->allnext) {
1517 && !(np->type != 0 && strcasecmp(np->type, type) == 0))
1519 if (device_is_compatible(np, compat)) {
1527 EXPORT_SYMBOL(find_compatible_devices);
1530 * Find the device_node with a given full_name.
1532 struct device_node *find_path_device(const char *path)
1534 struct device_node *np;
1536 for (np = allnodes; np != 0; np = np->allnext)
1537 if (np->full_name != 0 && strcasecmp(np->full_name, path) == 0)
1541 EXPORT_SYMBOL(find_path_device);
1545 * New implementation of the OF "find" APIs, return a refcounted
1546 * object, call of_node_put() when done. The device tree and list
1547 * are protected by a rw_lock.
1549 * Note that property management will need some locking as well,
1550 * this isn't dealt with yet.
1555 * of_find_node_by_name - Find a node by its "name" property
1556 * @from: The node to start searching from or NULL, the node
1557 * you pass will not be searched, only the next one
1558 * will; typically, you pass what the previous call
1559 * returned. of_node_put() will be called on it
1560 * @name: The name string to match against
1562 * Returns a node pointer with refcount incremented, use
1563 * of_node_put() on it when done.
1565 struct device_node *of_find_node_by_name(struct device_node *from,
1568 struct device_node *np;
1570 read_lock(&devtree_lock);
1571 np = from ? from->allnext : allnodes;
1572 for (; np != NULL; np = np->allnext)
1573 if (np->name != NULL && strcasecmp(np->name, name) == 0
1578 read_unlock(&devtree_lock);
1581 EXPORT_SYMBOL(of_find_node_by_name);
1584 * of_find_node_by_type - Find a node by its "device_type" property
1585 * @from: The node to start searching from or NULL, the node
1586 * you pass will not be searched, only the next one
1587 * will; typically, you pass what the previous call
1588 * returned. of_node_put() will be called on it
1589 * @name: The type string to match against
1591 * Returns a node pointer with refcount incremented, use
1592 * of_node_put() on it when done.
1594 struct device_node *of_find_node_by_type(struct device_node *from,
1597 struct device_node *np;
1599 read_lock(&devtree_lock);
1600 np = from ? from->allnext : allnodes;
1601 for (; np != 0; np = np->allnext)
1602 if (np->type != 0 && strcasecmp(np->type, type) == 0
1607 read_unlock(&devtree_lock);
1610 EXPORT_SYMBOL(of_find_node_by_type);
1613 * of_find_compatible_node - Find a node based on type and one of the
1614 * tokens in its "compatible" property
1615 * @from: The node to start searching from or NULL, the node
1616 * you pass will not be searched, only the next one
1617 * will; typically, you pass what the previous call
1618 * returned. of_node_put() will be called on it
1619 * @type: The type string to match "device_type" or NULL to ignore
1620 * @compatible: The string to match to one of the tokens in the device
1621 * "compatible" list.
1623 * Returns a node pointer with refcount incremented, use
1624 * of_node_put() on it when done.
1626 struct device_node *of_find_compatible_node(struct device_node *from,
1627 const char *type, const char *compatible)
1629 struct device_node *np;
1631 read_lock(&devtree_lock);
1632 np = from ? from->allnext : allnodes;
1633 for (; np != 0; np = np->allnext) {
1635 && !(np->type != 0 && strcasecmp(np->type, type) == 0))
1637 if (device_is_compatible(np, compatible) && of_node_get(np))
1642 read_unlock(&devtree_lock);
1645 EXPORT_SYMBOL(of_find_compatible_node);
1648 * of_find_node_by_path - Find a node matching a full OF path
1649 * @path: The full path to match
1651 * Returns a node pointer with refcount incremented, use
1652 * of_node_put() on it when done.
1654 struct device_node *of_find_node_by_path(const char *path)
1656 struct device_node *np = allnodes;
1658 read_lock(&devtree_lock);
1659 for (; np != 0; np = np->allnext) {
1660 if (np->full_name != 0 && strcasecmp(np->full_name, path) == 0
1664 read_unlock(&devtree_lock);
1667 EXPORT_SYMBOL(of_find_node_by_path);
1670 * of_find_node_by_phandle - Find a node given a phandle
1671 * @handle: phandle of the node to find
1673 * Returns a node pointer with refcount incremented, use
1674 * of_node_put() on it when done.
1676 struct device_node *of_find_node_by_phandle(phandle handle)
1678 struct device_node *np;
1680 read_lock(&devtree_lock);
1681 for (np = allnodes; np != 0; np = np->allnext)
1682 if (np->linux_phandle == handle)
1686 read_unlock(&devtree_lock);
1689 EXPORT_SYMBOL(of_find_node_by_phandle);
1692 * of_find_all_nodes - Get next node in global list
1693 * @prev: Previous node or NULL to start iteration
1694 * of_node_put() will be called on it
1696 * Returns a node pointer with refcount incremented, use
1697 * of_node_put() on it when done.
1699 struct device_node *of_find_all_nodes(struct device_node *prev)
1701 struct device_node *np;
1703 read_lock(&devtree_lock);
1704 np = prev ? prev->allnext : allnodes;
1705 for (; np != 0; np = np->allnext)
1706 if (of_node_get(np))
1710 read_unlock(&devtree_lock);
1713 EXPORT_SYMBOL(of_find_all_nodes);
1716 * of_get_parent - Get a node's parent if any
1717 * @node: Node to get parent
1719 * Returns a node pointer with refcount incremented, use
1720 * of_node_put() on it when done.
1722 struct device_node *of_get_parent(const struct device_node *node)
1724 struct device_node *np;
1729 read_lock(&devtree_lock);
1730 np = of_node_get(node->parent);
1731 read_unlock(&devtree_lock);
1734 EXPORT_SYMBOL(of_get_parent);
1737 * of_get_next_child - Iterate a node childs
1738 * @node: parent node
1739 * @prev: previous child of the parent node, or NULL to get first
1741 * Returns a node pointer with refcount incremented, use
1742 * of_node_put() on it when done.
1744 struct device_node *of_get_next_child(const struct device_node *node,
1745 struct device_node *prev)
1747 struct device_node *next;
1749 read_lock(&devtree_lock);
1750 next = prev ? prev->sibling : node->child;
1751 for (; next != 0; next = next->sibling)
1752 if (of_node_get(next))
1756 read_unlock(&devtree_lock);
1759 EXPORT_SYMBOL(of_get_next_child);
1762 * of_node_get - Increment refcount of a node
1763 * @node: Node to inc refcount, NULL is supported to
1764 * simplify writing of callers
1768 struct device_node *of_node_get(struct device_node *node)
1771 kref_get(&node->kref);
1774 EXPORT_SYMBOL(of_node_get);
1776 static inline struct device_node * kref_to_device_node(struct kref *kref)
1778 return container_of(kref, struct device_node, kref);
1782 * of_node_release - release a dynamically allocated node
1783 * @kref: kref element of the node to be released
1785 * In of_node_put() this function is passed to kref_put()
1786 * as the destructor.
1788 static void of_node_release(struct kref *kref)
1790 struct device_node *node = kref_to_device_node(kref);
1791 struct property *prop = node->properties;
1793 if (!OF_IS_DYNAMIC(node))
1796 struct property *next = prop->next;
1803 prop = node->deadprops;
1804 node->deadprops = NULL;
1808 kfree(node->full_name);
1814 * of_node_put - Decrement refcount of a node
1815 * @node: Node to dec refcount, NULL is supported to
1816 * simplify writing of callers
1819 void of_node_put(struct device_node *node)
1822 kref_put(&node->kref, of_node_release);
1824 EXPORT_SYMBOL(of_node_put);
1827 * Plug a device node into the tree and global list.
1829 void of_attach_node(struct device_node *np)
1831 write_lock(&devtree_lock);
1832 np->sibling = np->parent->child;
1833 np->allnext = allnodes;
1834 np->parent->child = np;
1836 write_unlock(&devtree_lock);
1840 * "Unplug" a node from the device tree. The caller must hold
1841 * a reference to the node. The memory associated with the node
1842 * is not freed until its refcount goes to zero.
1844 void of_detach_node(const struct device_node *np)
1846 struct device_node *parent;
1848 write_lock(&devtree_lock);
1850 parent = np->parent;
1853 allnodes = np->allnext;
1855 struct device_node *prev;
1856 for (prev = allnodes;
1857 prev->allnext != np;
1858 prev = prev->allnext)
1860 prev->allnext = np->allnext;
1863 if (parent->child == np)
1864 parent->child = np->sibling;
1866 struct device_node *prevsib;
1867 for (prevsib = np->parent->child;
1868 prevsib->sibling != np;
1869 prevsib = prevsib->sibling)
1871 prevsib->sibling = np->sibling;
1874 write_unlock(&devtree_lock);
1877 #ifdef CONFIG_PPC_PSERIES
1879 * Fix up the uninitialized fields in a new device node:
1880 * name, type, n_addrs, addrs, n_intrs, intrs, and pci-specific fields
1882 * A lot of boot-time code is duplicated here, because functions such
1883 * as finish_node_interrupts, interpret_pci_props, etc. cannot use the
1886 * This should probably be split up into smaller chunks.
1889 static int of_finish_dynamic_node(struct device_node *node)
1891 struct device_node *parent = of_get_parent(node);
1893 phandle *ibm_phandle;
1895 node->name = get_property(node, "name", NULL);
1896 node->type = get_property(node, "device_type", NULL);
1903 /* We don't support that function on PowerMac, at least
1906 if (machine_is(powermac))
1909 /* fix up new node's linux_phandle field */
1910 if ((ibm_phandle = (unsigned int *)get_property(node,
1911 "ibm,phandle", NULL)))
1912 node->linux_phandle = *ibm_phandle;
1915 of_node_put(parent);
1919 static int prom_reconfig_notifier(struct notifier_block *nb,
1920 unsigned long action, void *node)
1925 case PSERIES_RECONFIG_ADD:
1926 err = of_finish_dynamic_node(node);
1928 finish_node(node, NULL, 0);
1930 printk(KERN_ERR "finish_node returned %d\n", err);
1941 static struct notifier_block prom_reconfig_nb = {
1942 .notifier_call = prom_reconfig_notifier,
1943 .priority = 10, /* This one needs to run first */
1946 static int __init prom_reconfig_setup(void)
1948 return pSeries_reconfig_notifier_register(&prom_reconfig_nb);
1950 __initcall(prom_reconfig_setup);
1953 struct property *of_find_property(struct device_node *np, const char *name,
1956 struct property *pp;
1958 read_lock(&devtree_lock);
1959 for (pp = np->properties; pp != 0; pp = pp->next)
1960 if (strcmp(pp->name, name) == 0) {
1965 read_unlock(&devtree_lock);
1971 * Find a property with a given name for a given node
1972 * and return the value.
1974 unsigned char *get_property(struct device_node *np, const char *name,
1977 struct property *pp = of_find_property(np,name,lenp);
1978 return pp ? pp->value : NULL;
1980 EXPORT_SYMBOL(get_property);
1983 * Add a property to a node
1985 int prom_add_property(struct device_node* np, struct property* prop)
1987 struct property **next;
1990 write_lock(&devtree_lock);
1991 next = &np->properties;
1993 if (strcmp(prop->name, (*next)->name) == 0) {
1994 /* duplicate ! don't insert it */
1995 write_unlock(&devtree_lock);
1998 next = &(*next)->next;
2001 write_unlock(&devtree_lock);
2003 #ifdef CONFIG_PROC_DEVICETREE
2004 /* try to add to proc as well if it was initialized */
2006 proc_device_tree_add_prop(np->pde, prop);
2007 #endif /* CONFIG_PROC_DEVICETREE */
2013 * Remove a property from a node. Note that we don't actually
2014 * remove it, since we have given out who-knows-how-many pointers
2015 * to the data using get-property. Instead we just move the property
2016 * to the "dead properties" list, so it won't be found any more.
2018 int prom_remove_property(struct device_node *np, struct property *prop)
2020 struct property **next;
2023 write_lock(&devtree_lock);
2024 next = &np->properties;
2026 if (*next == prop) {
2027 /* found the node */
2029 prop->next = np->deadprops;
2030 np->deadprops = prop;
2034 next = &(*next)->next;
2036 write_unlock(&devtree_lock);
2041 #ifdef CONFIG_PROC_DEVICETREE
2042 /* try to remove the proc node as well */
2044 proc_device_tree_remove_prop(np->pde, prop);
2045 #endif /* CONFIG_PROC_DEVICETREE */
2051 * Update a property in a node. Note that we don't actually
2052 * remove it, since we have given out who-knows-how-many pointers
2053 * to the data using get-property. Instead we just move the property
2054 * to the "dead properties" list, and add the new property to the
2057 int prom_update_property(struct device_node *np,
2058 struct property *newprop,
2059 struct property *oldprop)
2061 struct property **next;
2064 write_lock(&devtree_lock);
2065 next = &np->properties;
2067 if (*next == oldprop) {
2068 /* found the node */
2069 newprop->next = oldprop->next;
2071 oldprop->next = np->deadprops;
2072 np->deadprops = oldprop;
2076 next = &(*next)->next;
2078 write_unlock(&devtree_lock);
2083 #ifdef CONFIG_PROC_DEVICETREE
2084 /* try to add to proc as well if it was initialized */
2086 proc_device_tree_update_prop(np->pde, newprop, oldprop);
2087 #endif /* CONFIG_PROC_DEVICETREE */