1 /* prom_common.c: OF device tree support common code.
3 * Paul Mackerras August 1996.
4 * Copyright (C) 1996-2005 Paul Mackerras.
6 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
7 * {engebret|bergner}@us.ibm.com
9 * Adapted for sparc by David S. Miller davem@davemloft.net
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/errno.h>
20 #include <linux/mutex.h>
21 #include <linux/slab.h>
24 #include <asm/oplib.h>
28 struct device_node *of_find_node_by_phandle(phandle handle)
30 struct device_node *np;
32 for (np = allnodes; np; np = np->allnext)
33 if (np->node == handle)
38 EXPORT_SYMBOL(of_find_node_by_phandle);
40 int of_getintprop_default(struct device_node *np, const char *name, int def)
42 struct property *prop;
45 prop = of_find_property(np, name, &len);
46 if (!prop || len != 4)
49 return *(int *) prop->value;
51 EXPORT_SYMBOL(of_getintprop_default);
53 DEFINE_MUTEX(of_set_property_mutex);
54 EXPORT_SYMBOL(of_set_property_mutex);
56 int of_set_property(struct device_node *dp, const char *name, void *val, int len)
58 struct property **prevp;
62 new_val = kmalloc(len, GFP_KERNEL);
66 memcpy(new_val, val, len);
70 write_lock(&devtree_lock);
71 prevp = &dp->properties;
73 struct property *prop = *prevp;
75 if (!strcasecmp(prop->name, name)) {
76 void *old_val = prop->value;
79 mutex_lock(&of_set_property_mutex);
80 ret = prom_setprop(dp->node, name, val, len);
81 mutex_unlock(&of_set_property_mutex);
85 prop->value = new_val;
88 if (OF_IS_DYNAMIC(prop))
91 OF_MARK_DYNAMIC(prop);
97 prevp = &(*prevp)->next;
99 write_unlock(&devtree_lock);
101 /* XXX Upate procfs if necessary... */
105 EXPORT_SYMBOL(of_set_property);
107 int of_find_in_proplist(const char *list, const char *match, int len)
112 if (!strcmp(list, match))
114 l = strlen(list) + 1;
120 EXPORT_SYMBOL(of_find_in_proplist);
122 unsigned int prom_unique_id;