762056762b72af72abc5e7cd8ff330243f47f4a1
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
;
124 static struct property
* __init
build_one_prop(phandle node
, char *prev
,
129 static struct property
*tmp
= NULL
;
135 memset(p
, 0, sizeof(*p
) + 32);
138 p
= prom_early_alloc(sizeof(struct property
) + 32);
139 p
->unique_id
= prom_unique_id
++;
142 p
->name
= (char *) (p
+ 1);
144 strcpy(p
->name
, special_name
);
145 p
->length
= special_len
;
146 p
->value
= prom_early_alloc(special_len
);
147 memcpy(p
->value
, special_val
, special_len
);
149 #ifdef CONFIG_SPARC32
151 name
= prom_firstprop(node
, NULL
);
153 name
= prom_nextprop(node
, prev
, NULL
);
157 prom_firstprop(node
, p
->name
);
159 prom_nextprop(node
, prev
, p
->name
);
163 if (strlen(name
) == 0) {
167 #ifdef CONFIG_SPARC32
168 strcpy(p
->name
, name
);
170 p
->length
= prom_getproplen(node
, p
->name
);
171 if (p
->length
<= 0) {
176 p
->value
= prom_early_alloc(p
->length
+ 1);
177 len
= prom_getproperty(node
, p
->name
, p
->value
,
181 ((unsigned char *)p
->value
)[p
->length
] = '\0';
187 struct property
* __init
build_prop_list(phandle node
)
189 struct property
*head
, *tail
;
191 head
= tail
= build_one_prop(node
, NULL
,
192 ".node", &node
, sizeof(node
));
194 tail
->next
= build_one_prop(node
, NULL
, NULL
, NULL
, 0);
197 tail
->next
= build_one_prop(node
, tail
->name
,
This page took 0.035269 seconds and 4 git commands to generate.