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.
17 #include <linux/kernel.h>
18 #include <linux/string.h>
19 #include <linux/init.h>
20 #include <linux/threads.h>
21 #include <linux/spinlock.h>
22 #include <linux/types.h>
23 #include <linux/pci.h>
24 #include <linux/stringify.h>
25 #include <linux/delay.h>
26 #include <linux/initrd.h>
27 #include <linux/bitops.h>
28 #include <linux/module.h>
29 #include <linux/kexec.h>
30 #include <linux/debugfs.h>
31 #include <linux/irq.h>
32 #include <linux/lmb.h>
36 #include <asm/processor.h>
39 #include <asm/system.h>
41 #include <asm/pgtable.h>
42 #include <linux/pci.h>
43 #include <asm/sections.h>
44 #include <asm/pci-bridge.h>
46 static int __initdata dt_root_addr_cells;
47 static int __initdata dt_root_size_cells;
51 static struct boot_param_header *initial_boot_params;
53 /* export that to outside world */
54 struct device_node *of_chosen;
56 static inline char *find_flat_dt_string(u32 offset)
58 return ((char *)initial_boot_params) +
59 initial_boot_params->off_dt_strings + offset;
63 * This function is used to scan the flattened device-tree, it is
64 * used to extract the memory informations at boot before we can
67 int __init of_scan_flat_dt(int (*it)(unsigned long node,
68 const char *uname, int depth,
72 unsigned long p = ((unsigned long)initial_boot_params) +
73 initial_boot_params->off_dt_struct;
78 u32 tag = *((u32 *)p);
82 if (tag == OF_DT_END_NODE) {
90 if (tag == OF_DT_PROP) {
93 if (initial_boot_params->version < 0x10)
94 p = _ALIGN(p, sz >= 8 ? 8 : 4);
99 if (tag != OF_DT_BEGIN_NODE) {
100 printk(KERN_WARNING "Invalid tag %x scanning flattened"
101 " device tree !\n", tag);
106 p = _ALIGN(p + strlen(pathp) + 1, 4);
107 if ((*pathp) == '/') {
109 for (lp = NULL, np = pathp; *np; np++)
115 rc = it(p, pathp, depth, data);
123 unsigned long __init of_get_flat_dt_root(void)
125 unsigned long p = ((unsigned long)initial_boot_params) +
126 initial_boot_params->off_dt_struct;
128 while (*((u32 *)p) == OF_DT_NOP)
130 BUG_ON(*((u32 *)p) != OF_DT_BEGIN_NODE);
132 return _ALIGN(p + strlen((char *)p) + 1, 4);
136 * This function can be used within scan_flattened_dt callback to get
137 * access to properties
139 void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
142 unsigned long p = node;
145 u32 tag = *((u32 *)p);
150 if (tag == OF_DT_NOP)
152 if (tag != OF_DT_PROP)
156 noff = *((u32 *)(p + 4));
158 if (initial_boot_params->version < 0x10)
159 p = _ALIGN(p, sz >= 8 ? 8 : 4);
161 nstr = find_flat_dt_string(noff);
163 printk(KERN_WARNING "Can't find property index"
167 if (strcmp(name, nstr) == 0) {
177 int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
180 unsigned long cplen, l;
182 cp = of_get_flat_dt_prop(node, "compatible", &cplen);
186 if (strncasecmp(cp, compat, strlen(compat)) == 0)
196 static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size,
201 *mem = _ALIGN(*mem, align);
208 static unsigned long __init unflatten_dt_node(unsigned long mem,
210 struct device_node *dad,
211 struct device_node ***allnextpp,
212 unsigned long fpsize)
214 struct device_node *np;
215 struct property *pp, **prev_pp = NULL;
218 unsigned int l, allocl;
222 tag = *((u32 *)(*p));
223 if (tag != OF_DT_BEGIN_NODE) {
224 printk("Weird tag at start of node: %x\n", tag);
229 l = allocl = strlen(pathp) + 1;
230 *p = _ALIGN(*p + l, 4);
232 /* version 0x10 has a more compact unit name here instead of the full
233 * path. we accumulate the full path size using "fpsize", we'll rebuild
234 * it later. We detect this because the first character of the name is
237 if ((*pathp) != '/') {
240 /* root node: special case. fpsize accounts for path
241 * plus terminating zero. root node only has '/', so
242 * fpsize should be 2, but we want to avoid the first
243 * level nodes to have two '/' so we use fpsize 1 here
248 /* account for '/' and path size minus terminal 0
256 np = unflatten_dt_alloc(&mem, sizeof(struct device_node) + allocl,
257 __alignof__(struct device_node));
259 memset(np, 0, sizeof(*np));
260 np->full_name = ((char *)np) + sizeof(struct device_node);
262 char *p2 = np->full_name;
263 /* rebuild full path for new format */
264 if (dad && dad->parent) {
265 strcpy(p2, dad->full_name);
267 if ((strlen(p2) + l + 1) != allocl) {
268 pr_debug("%s: p: %d, l: %d, a: %d\n",
269 pathp, (int)strlen(p2),
276 memcpy(p2, pathp, l);
278 memcpy(np->full_name, pathp, l);
279 prev_pp = &np->properties;
281 *allnextpp = &np->allnext;
284 /* we temporarily use the next field as `last_child'*/
285 if (dad->next == NULL)
288 dad->next->sibling = np;
291 kref_init(&np->kref);
297 tag = *((u32 *)(*p));
298 if (tag == OF_DT_NOP) {
302 if (tag != OF_DT_PROP)
306 noff = *((u32 *)((*p) + 4));
308 if (initial_boot_params->version < 0x10)
309 *p = _ALIGN(*p, sz >= 8 ? 8 : 4);
311 pname = find_flat_dt_string(noff);
314 "Can't find property name in list !\n");
317 if (strcmp(pname, "name") == 0)
319 l = strlen(pname) + 1;
320 pp = unflatten_dt_alloc(&mem, sizeof(struct property),
321 __alignof__(struct property));
323 if (strcmp(pname, "linux,phandle") == 0) {
324 np->node = *((u32 *)*p);
325 if (np->linux_phandle == 0)
326 np->linux_phandle = np->node;
328 if (strcmp(pname, "ibm,phandle") == 0)
329 np->linux_phandle = *((u32 *)*p);
332 pp->value = (void *)*p;
336 *p = _ALIGN((*p) + sz, 4);
338 /* with version 0x10 we may not have the name property, recreate
339 * it here from the unit name if absent
342 char *p1 = pathp, *ps = pathp, *pa = NULL;
355 pp = unflatten_dt_alloc(&mem, sizeof(struct property) + sz,
356 __alignof__(struct property));
363 memcpy(pp->value, ps, sz - 1);
364 ((char *)pp->value)[sz - 1] = 0;
365 pr_debug("fixed up name for %s -> %s\n", pathp,
371 np->name = of_get_property(np, "name", NULL);
372 np->type = of_get_property(np, "device_type", NULL);
379 while (tag == OF_DT_BEGIN_NODE) {
380 mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize);
381 tag = *((u32 *)(*p));
383 if (tag != OF_DT_END_NODE) {
384 printk(KERN_INFO "Weird tag at end of node: %x\n", tag);
392 * unflattens the device-tree passed by the firmware, creating the
393 * tree of struct device_node. It also fills the "name" and "type"
394 * pointers of the nodes so the normal device-tree walking functions
395 * can be used (this used to be done by finish_device_tree)
397 void __init unflatten_device_tree(void)
399 unsigned long start, mem, size;
400 struct device_node **allnextp = &allnodes;
402 pr_debug(" -> unflatten_device_tree()\n");
404 /* First pass, scan for size */
405 start = ((unsigned long)initial_boot_params) +
406 initial_boot_params->off_dt_struct;
407 size = unflatten_dt_node(0, &start, NULL, NULL, 0);
408 size = (size | 3) + 1;
410 pr_debug(" size is %lx, allocating...\n", size);
412 /* Allocate memory for the expanded device tree */
413 mem = lmb_alloc(size + 4, __alignof__(struct device_node));
414 mem = (unsigned long) __va(mem);
416 ((u32 *)mem)[size / 4] = 0xdeadbeef;
418 pr_debug(" unflattening %lx...\n", mem);
420 /* Second pass, do actual unflattening */
421 start = ((unsigned long)initial_boot_params) +
422 initial_boot_params->off_dt_struct;
423 unflatten_dt_node(mem, &start, NULL, &allnextp, 0);
424 if (*((u32 *)start) != OF_DT_END)
425 printk(KERN_WARNING "Weird tag at end of tree: %08x\n",
427 if (((u32 *)mem)[size / 4] != 0xdeadbeef)
428 printk(KERN_WARNING "End of tree marker overwritten: %08x\n",
429 ((u32 *)mem)[size / 4]);
432 /* Get pointer to OF "/chosen" node for use everywhere */
433 of_chosen = of_find_node_by_path("/chosen");
434 if (of_chosen == NULL)
435 of_chosen = of_find_node_by_path("/chosen@0");
437 pr_debug(" <- unflatten_device_tree()\n");
440 #define early_init_dt_scan_drconf_memory(node) 0
442 static int __init early_init_dt_scan_cpus(unsigned long node,
443 const char *uname, int depth,
446 static int logical_cpuid;
447 char *type = of_get_flat_dt_prop(node, "device_type", NULL);
452 /* We are scanning "cpu" nodes only */
453 if (type == NULL || strcmp(type, "cpu") != 0)
456 /* Get physical cpuid */
457 intserv = of_get_flat_dt_prop(node, "reg", NULL);
461 * Now see if any of these threads match our boot cpu.
462 * NOTE: This must match the parsing done in smp_setup_cpu_maps.
464 for (i = 0; i < nthreads; i++) {
466 * version 2 of the kexec param format adds the phys cpuid of
469 if (initial_boot_params && initial_boot_params->version >= 2) {
471 initial_boot_params->boot_cpuid_phys) {
477 * Check if it's the boot-cpu, set it's hw index now,
478 * unfortunately this format did not support booting
479 * off secondary threads.
481 if (of_get_flat_dt_prop(node,
482 "linux,boot-cpu", NULL) != NULL) {
489 /* logical cpu id is always 0 on UP kernels */
495 pr_debug("boot cpu: logical %d physical %d\n", logical_cpuid,
497 boot_cpuid = logical_cpuid;
503 #ifdef CONFIG_BLK_DEV_INITRD
504 static void __init early_init_dt_check_for_initrd(unsigned long node)
509 pr_debug("Looking for initrd properties... ");
511 prop = of_get_flat_dt_prop(node, "linux,initrd-start", &l);
513 initrd_start = (unsigned long)__va(of_read_ulong(prop, l/4));
515 prop = of_get_flat_dt_prop(node, "linux,initrd-end", &l);
517 initrd_end = (unsigned long)
518 __va(of_read_ulong(prop, l/4));
519 initrd_below_start_ok = 1;
525 pr_debug("initrd_start=0x%lx initrd_end=0x%lx\n",
526 initrd_start, initrd_end);
529 static inline void early_init_dt_check_for_initrd(unsigned long node)
532 #endif /* CONFIG_BLK_DEV_INITRD */
534 static int __init early_init_dt_scan_chosen(unsigned long node,
535 const char *uname, int depth, void *data)
540 pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
543 (strcmp(uname, "chosen") != 0 &&
544 strcmp(uname, "chosen@0") != 0))
548 lprop = (u64 *)of_get_flat_dt_prop(node,
549 "linux,crashkernel-base", NULL);
551 crashk_res.start = *lprop;
553 lprop = (u64 *)of_get_flat_dt_prop(node,
554 "linux,crashkernel-size", NULL);
556 crashk_res.end = crashk_res.start + *lprop - 1;
559 early_init_dt_check_for_initrd(node);
561 /* Retreive command line */
562 p = of_get_flat_dt_prop(node, "bootargs", &l);
563 if (p != NULL && l > 0)
564 strlcpy(cmd_line, p, min((int)l, COMMAND_LINE_SIZE));
566 #ifdef CONFIG_CMDLINE
567 if (p == NULL || l == 0 || (l == 1 && (*p) == 0))
568 strlcpy(cmd_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
569 #endif /* CONFIG_CMDLINE */
571 pr_debug("Command line is: %s\n", cmd_line);
577 static int __init early_init_dt_scan_root(unsigned long node,
578 const char *uname, int depth, void *data)
585 prop = of_get_flat_dt_prop(node, "#size-cells", NULL);
586 dt_root_size_cells = (prop == NULL) ? 1 : *prop;
587 pr_debug("dt_root_size_cells = %x\n", dt_root_size_cells);
589 prop = of_get_flat_dt_prop(node, "#address-cells", NULL);
590 dt_root_addr_cells = (prop == NULL) ? 2 : *prop;
591 pr_debug("dt_root_addr_cells = %x\n", dt_root_addr_cells);
597 static u64 __init dt_mem_next_cell(int s, cell_t **cellp)
602 return of_read_number(p, s);
605 static int __init early_init_dt_scan_memory(unsigned long node,
606 const char *uname, int depth, void *data)
608 char *type = of_get_flat_dt_prop(node, "device_type", NULL);
612 /* Look for the ibm,dynamic-reconfiguration-memory node */
614 strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0)
615 return early_init_dt_scan_drconf_memory(node);
617 /* We are scanning "memory" nodes only */
620 * The longtrail doesn't have a device_type on the
621 * /memory node, so look for the node called /memory@0.
623 if (depth != 1 || strcmp(uname, "memory@0") != 0)
625 } else if (strcmp(type, "memory") != 0)
628 reg = (cell_t *)of_get_flat_dt_prop(node, "linux,usable-memory", &l);
630 reg = (cell_t *)of_get_flat_dt_prop(node, "reg", &l);
634 endp = reg + (l / sizeof(cell_t));
636 pr_debug("memory scan node %s, reg size %ld, data: %x %x %x %x,\n",
637 uname, l, reg[0], reg[1], reg[2], reg[3]);
639 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
642 base = dt_mem_next_cell(dt_root_addr_cells, ®);
643 size = dt_mem_next_cell(dt_root_size_cells, ®);
647 pr_debug(" - %llx , %llx\n", (unsigned long long)base,
648 (unsigned long long)size);
655 #ifdef CONFIG_PHYP_DUMP
657 * phyp_dump_calculate_reserve_size() - reserve variable boot area 5% or arg
659 * Function to find the largest size we need to reserve
660 * during early boot process.
662 * It either looks for boot param and returns that OR
663 * returns larger of 256 or 5% rounded down to multiples of 256MB.
666 static inline unsigned long phyp_dump_calculate_reserve_size(void)
670 if (phyp_dump_info->reserve_bootvar)
671 return phyp_dump_info->reserve_bootvar;
673 /* divide by 20 to get 5% of value */
674 tmp = lmb_end_of_DRAM();
677 /* round it down in multiples of 256 */
678 tmp = tmp & ~0x0FFFFFFFUL;
680 return (tmp > PHYP_DUMP_RMR_END ? tmp : PHYP_DUMP_RMR_END);
684 * phyp_dump_reserve_mem() - reserve all not-yet-dumped mmemory
686 * This routine may reserve memory regions in the kernel only
687 * if the system is supported and a dump was taken in last
688 * boot instance or if the hardware is supported and the
689 * scratch area needs to be setup. In other instances it returns
690 * without reserving anything. The memory in case of dump being
691 * active is freed when the dump is collected (by userland tools).
693 static void __init phyp_dump_reserve_mem(void)
695 unsigned long base, size;
696 unsigned long variable_reserve_size;
698 if (!phyp_dump_info->phyp_dump_configured) {
699 printk(KERN_ERR "Phyp-dump not supported on this hardware\n");
703 if (!phyp_dump_info->phyp_dump_at_boot) {
704 printk(KERN_INFO "Phyp-dump disabled at boot time\n");
708 variable_reserve_size = phyp_dump_calculate_reserve_size();
710 if (phyp_dump_info->phyp_dump_is_active) {
711 /* Reserve *everything* above RMR.Area freed by userland tools*/
712 base = variable_reserve_size;
713 size = lmb_end_of_DRAM() - base;
715 /* XXX crashed_ram_end is wrong, since it may be beyond
716 * the memory_limit, it will need to be adjusted. */
717 lmb_reserve(base, size);
719 phyp_dump_info->init_reserve_start = base;
720 phyp_dump_info->init_reserve_size = size;
722 size = phyp_dump_info->cpu_state_size +
723 phyp_dump_info->hpte_region_size +
724 variable_reserve_size;
725 base = lmb_end_of_DRAM() - size;
726 lmb_reserve(base, size);
727 phyp_dump_info->init_reserve_start = base;
728 phyp_dump_info->init_reserve_size = size;
732 static inline void __init phyp_dump_reserve_mem(void) {}
733 #endif /* CONFIG_PHYP_DUMP && CONFIG_PPC_RTAS */
735 #ifdef CONFIG_EARLY_PRINTK
736 /* MS this is Microblaze specifig function */
737 static int __init early_init_dt_scan_serial(unsigned long node,
738 const char *uname, int depth, void *data)
744 pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
746 /* find all serial nodes */
747 if (strncmp(uname, "serial", 6) != 0)
750 early_init_dt_check_for_initrd(node);
752 /* find compatible node with uartlite */
753 p = of_get_flat_dt_prop(node, "compatible", &l);
754 if ((strncmp(p, "xlnx,xps-uartlite", 17) != 0) &&
755 (strncmp(p, "xlnx,opb-uartlite", 17) != 0))
758 addr = of_get_flat_dt_prop(node, "reg", &l);
759 return *addr; /* return address */
762 /* this function is looking for early uartlite console - Microblaze specific */
763 int __init early_uartlite_console(void)
765 return of_scan_flat_dt(early_init_dt_scan_serial, NULL);
769 void __init early_init_devtree(void *params)
771 pr_debug(" -> early_init_devtree(%p)\n", params);
773 /* Setup flat device-tree pointer */
774 initial_boot_params = params;
776 #ifdef CONFIG_PHYP_DUMP
777 /* scan tree to see if dump occured during last boot */
778 of_scan_flat_dt(early_init_dt_scan_phyp_dump, NULL);
781 /* Retrieve various informations from the /chosen node of the
782 * device-tree, including the platform type, initrd location and
783 * size, TCE reserve, and more ...
785 of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
787 /* Scan memory nodes and rebuild LMBs */
789 of_scan_flat_dt(early_init_dt_scan_root, NULL);
790 of_scan_flat_dt(early_init_dt_scan_memory, NULL);
792 /* Save command line for /proc/cmdline and then parse parameters */
793 strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
798 pr_debug("Phys. mem: %lx\n", (unsigned long) lmb_phys_mem_size());
800 pr_debug("Scanning CPUs ...\n");
802 /* Retreive CPU related informations from the flat tree
803 * (altivec support, boot CPU ID, ...)
805 of_scan_flat_dt(early_init_dt_scan_cpus, NULL);
807 pr_debug(" <- early_init_devtree()\n");
811 * Indicates whether the root node has a given value in its
812 * compatible property.
814 int machine_is_compatible(const char *compat)
816 struct device_node *root;
819 root = of_find_node_by_path("/");
821 rc = of_device_is_compatible(root, compat);
826 EXPORT_SYMBOL(machine_is_compatible);
830 * New implementation of the OF "find" APIs, return a refcounted
831 * object, call of_node_put() when done. The device tree and list
832 * are protected by a rw_lock.
834 * Note that property management will need some locking as well,
835 * this isn't dealt with yet.
840 * of_find_node_by_phandle - Find a node given a phandle
841 * @handle: phandle of the node to find
843 * Returns a node pointer with refcount incremented, use
844 * of_node_put() on it when done.
846 struct device_node *of_find_node_by_phandle(phandle handle)
848 struct device_node *np;
850 read_lock(&devtree_lock);
851 for (np = allnodes; np != NULL; np = np->allnext)
852 if (np->linux_phandle == handle)
855 read_unlock(&devtree_lock);
858 EXPORT_SYMBOL(of_find_node_by_phandle);
861 * of_find_all_nodes - Get next node in global list
862 * @prev: Previous node or NULL to start iteration
863 * of_node_put() will be called on it
865 * Returns a node pointer with refcount incremented, use
866 * of_node_put() on it when done.
868 struct device_node *of_find_all_nodes(struct device_node *prev)
870 struct device_node *np;
872 read_lock(&devtree_lock);
873 np = prev ? prev->allnext : allnodes;
874 for (; np != NULL; np = np->allnext)
878 read_unlock(&devtree_lock);
881 EXPORT_SYMBOL(of_find_all_nodes);
884 * of_node_get - Increment refcount of a node
885 * @node: Node to inc refcount, NULL is supported to
886 * simplify writing of callers
890 struct device_node *of_node_get(struct device_node *node)
893 kref_get(&node->kref);
896 EXPORT_SYMBOL(of_node_get);
898 static inline struct device_node *kref_to_device_node(struct kref *kref)
900 return container_of(kref, struct device_node, kref);
904 * of_node_release - release a dynamically allocated node
905 * @kref: kref element of the node to be released
907 * In of_node_put() this function is passed to kref_put()
910 static void of_node_release(struct kref *kref)
912 struct device_node *node = kref_to_device_node(kref);
913 struct property *prop = node->properties;
915 /* We should never be releasing nodes that haven't been detached. */
916 if (!of_node_check_flag(node, OF_DETACHED)) {
917 printk(KERN_INFO "WARNING: Bad of_node_put() on %s\n",
920 kref_init(&node->kref);
924 if (!of_node_check_flag(node, OF_DYNAMIC))
928 struct property *next = prop->next;
935 prop = node->deadprops;
936 node->deadprops = NULL;
939 kfree(node->full_name);
945 * of_node_put - Decrement refcount of a node
946 * @node: Node to dec refcount, NULL is supported to
947 * simplify writing of callers
950 void of_node_put(struct device_node *node)
953 kref_put(&node->kref, of_node_release);
955 EXPORT_SYMBOL(of_node_put);
958 * Plug a device node into the tree and global list.
960 void of_attach_node(struct device_node *np)
964 write_lock_irqsave(&devtree_lock, flags);
965 np->sibling = np->parent->child;
966 np->allnext = allnodes;
967 np->parent->child = np;
969 write_unlock_irqrestore(&devtree_lock, flags);
973 * "Unplug" a node from the device tree. The caller must hold
974 * a reference to the node. The memory associated with the node
975 * is not freed until its refcount goes to zero.
977 void of_detach_node(struct device_node *np)
979 struct device_node *parent;
982 write_lock_irqsave(&devtree_lock, flags);
989 allnodes = np->allnext;
991 struct device_node *prev;
992 for (prev = allnodes;
994 prev = prev->allnext)
996 prev->allnext = np->allnext;
999 if (parent->child == np)
1000 parent->child = np->sibling;
1002 struct device_node *prevsib;
1003 for (prevsib = np->parent->child;
1004 prevsib->sibling != np;
1005 prevsib = prevsib->sibling)
1007 prevsib->sibling = np->sibling;
1010 of_node_set_flag(np, OF_DETACHED);
1013 write_unlock_irqrestore(&devtree_lock, flags);
1017 * Add a property to a node
1019 int prom_add_property(struct device_node *np, struct property *prop)
1021 struct property **next;
1022 unsigned long flags;
1025 write_lock_irqsave(&devtree_lock, flags);
1026 next = &np->properties;
1028 if (strcmp(prop->name, (*next)->name) == 0) {
1029 /* duplicate ! don't insert it */
1030 write_unlock_irqrestore(&devtree_lock, flags);
1033 next = &(*next)->next;
1036 write_unlock_irqrestore(&devtree_lock, flags);
1038 #ifdef CONFIG_PROC_DEVICETREE
1039 /* try to add to proc as well if it was initialized */
1041 proc_device_tree_add_prop(np->pde, prop);
1042 #endif /* CONFIG_PROC_DEVICETREE */
1048 * Remove a property from a node. Note that we don't actually
1049 * remove it, since we have given out who-knows-how-many pointers
1050 * to the data using get-property. Instead we just move the property
1051 * to the "dead properties" list, so it won't be found any more.
1053 int prom_remove_property(struct device_node *np, struct property *prop)
1055 struct property **next;
1056 unsigned long flags;
1059 write_lock_irqsave(&devtree_lock, flags);
1060 next = &np->properties;
1062 if (*next == prop) {
1063 /* found the node */
1065 prop->next = np->deadprops;
1066 np->deadprops = prop;
1070 next = &(*next)->next;
1072 write_unlock_irqrestore(&devtree_lock, flags);
1077 #ifdef CONFIG_PROC_DEVICETREE
1078 /* try to remove the proc node as well */
1080 proc_device_tree_remove_prop(np->pde, prop);
1081 #endif /* CONFIG_PROC_DEVICETREE */
1087 * Update a property in a node. Note that we don't actually
1088 * remove it, since we have given out who-knows-how-many pointers
1089 * to the data using get-property. Instead we just move the property
1090 * to the "dead properties" list, and add the new property to the
1093 int prom_update_property(struct device_node *np,
1094 struct property *newprop,
1095 struct property *oldprop)
1097 struct property **next;
1098 unsigned long flags;
1101 write_lock_irqsave(&devtree_lock, flags);
1102 next = &np->properties;
1104 if (*next == oldprop) {
1105 /* found the node */
1106 newprop->next = oldprop->next;
1108 oldprop->next = np->deadprops;
1109 np->deadprops = oldprop;
1113 next = &(*next)->next;
1115 write_unlock_irqrestore(&devtree_lock, flags);
1120 #ifdef CONFIG_PROC_DEVICETREE
1121 /* try to add to proc as well if it was initialized */
1123 proc_device_tree_update_prop(np->pde, newprop, oldprop);
1124 #endif /* CONFIG_PROC_DEVICETREE */
1129 #if defined(CONFIG_DEBUG_FS) && defined(DEBUG)
1130 static struct debugfs_blob_wrapper flat_dt_blob;
1132 static int __init export_flat_device_tree(void)
1136 flat_dt_blob.data = initial_boot_params;
1137 flat_dt_blob.size = initial_boot_params->totalsize;
1139 d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR,
1140 of_debugfs_root, &flat_dt_blob);
1146 device_initcall(export_flat_device_tree);