diff options
Diffstat (limited to 'arch/sparc/prom/tree_32.c')
-rw-r--r-- | arch/sparc/prom/tree_32.c | 123 |
1 files changed, 37 insertions, 86 deletions
diff --git a/arch/sparc/prom/tree_32.c b/arch/sparc/prom/tree_32.c index b21592f8e3fe..f30e8d038f01 100644 --- a/arch/sparc/prom/tree_32.c +++ b/arch/sparc/prom/tree_32.c | |||
@@ -20,10 +20,10 @@ extern void restore_current(void); | |||
20 | static char promlib_buf[128]; | 20 | static char promlib_buf[128]; |
21 | 21 | ||
22 | /* Internal version of prom_getchild that does not alter return values. */ | 22 | /* Internal version of prom_getchild that does not alter return values. */ |
23 | int __prom_getchild(int node) | 23 | static phandle __prom_getchild(phandle node) |
24 | { | 24 | { |
25 | unsigned long flags; | 25 | unsigned long flags; |
26 | int cnode; | 26 | phandle cnode; |
27 | 27 | ||
28 | spin_lock_irqsave(&prom_lock, flags); | 28 | spin_lock_irqsave(&prom_lock, flags); |
29 | cnode = prom_nodeops->no_child(node); | 29 | cnode = prom_nodeops->no_child(node); |
@@ -36,15 +36,15 @@ int __prom_getchild(int node) | |||
36 | /* Return the child of node 'node' or zero if no this node has no | 36 | /* Return the child of node 'node' or zero if no this node has no |
37 | * direct descendent. | 37 | * direct descendent. |
38 | */ | 38 | */ |
39 | int prom_getchild(int node) | 39 | phandle prom_getchild(phandle node) |
40 | { | 40 | { |
41 | int cnode; | 41 | phandle cnode; |
42 | 42 | ||
43 | if (node == -1) | 43 | if ((s32)node == -1) |
44 | return 0; | 44 | return 0; |
45 | 45 | ||
46 | cnode = __prom_getchild(node); | 46 | cnode = __prom_getchild(node); |
47 | if (cnode == 0 || cnode == -1) | 47 | if (cnode == 0 || (s32)cnode == -1) |
48 | return 0; | 48 | return 0; |
49 | 49 | ||
50 | return cnode; | 50 | return cnode; |
@@ -52,10 +52,10 @@ int prom_getchild(int node) | |||
52 | EXPORT_SYMBOL(prom_getchild); | 52 | EXPORT_SYMBOL(prom_getchild); |
53 | 53 | ||
54 | /* Internal version of prom_getsibling that does not alter return values. */ | 54 | /* Internal version of prom_getsibling that does not alter return values. */ |
55 | int __prom_getsibling(int node) | 55 | static phandle __prom_getsibling(phandle node) |
56 | { | 56 | { |
57 | unsigned long flags; | 57 | unsigned long flags; |
58 | int cnode; | 58 | phandle cnode; |
59 | 59 | ||
60 | spin_lock_irqsave(&prom_lock, flags); | 60 | spin_lock_irqsave(&prom_lock, flags); |
61 | cnode = prom_nodeops->no_nextnode(node); | 61 | cnode = prom_nodeops->no_nextnode(node); |
@@ -68,15 +68,15 @@ int __prom_getsibling(int node) | |||
68 | /* Return the next sibling of node 'node' or zero if no more siblings | 68 | /* Return the next sibling of node 'node' or zero if no more siblings |
69 | * at this level of depth in the tree. | 69 | * at this level of depth in the tree. |
70 | */ | 70 | */ |
71 | int prom_getsibling(int node) | 71 | phandle prom_getsibling(phandle node) |
72 | { | 72 | { |
73 | int sibnode; | 73 | phandle sibnode; |
74 | 74 | ||
75 | if (node == -1) | 75 | if ((s32)node == -1) |
76 | return 0; | 76 | return 0; |
77 | 77 | ||
78 | sibnode = __prom_getsibling(node); | 78 | sibnode = __prom_getsibling(node); |
79 | if (sibnode == 0 || sibnode == -1) | 79 | if (sibnode == 0 || (s32)sibnode == -1) |
80 | return 0; | 80 | return 0; |
81 | 81 | ||
82 | return sibnode; | 82 | return sibnode; |
@@ -86,7 +86,7 @@ EXPORT_SYMBOL(prom_getsibling); | |||
86 | /* Return the length in bytes of property 'prop' at node 'node'. | 86 | /* Return the length in bytes of property 'prop' at node 'node'. |
87 | * Return -1 on error. | 87 | * Return -1 on error. |
88 | */ | 88 | */ |
89 | int prom_getproplen(int node, const char *prop) | 89 | int prom_getproplen(phandle node, const char *prop) |
90 | { | 90 | { |
91 | int ret; | 91 | int ret; |
92 | unsigned long flags; | 92 | unsigned long flags; |
@@ -106,7 +106,7 @@ EXPORT_SYMBOL(prom_getproplen); | |||
106 | * 'buffer' which has a size of 'bufsize'. If the acquisition | 106 | * 'buffer' which has a size of 'bufsize'. If the acquisition |
107 | * was successful the length will be returned, else -1 is returned. | 107 | * was successful the length will be returned, else -1 is returned. |
108 | */ | 108 | */ |
109 | int prom_getproperty(int node, const char *prop, char *buffer, int bufsize) | 109 | int prom_getproperty(phandle node, const char *prop, char *buffer, int bufsize) |
110 | { | 110 | { |
111 | int plen, ret; | 111 | int plen, ret; |
112 | unsigned long flags; | 112 | unsigned long flags; |
@@ -126,7 +126,7 @@ EXPORT_SYMBOL(prom_getproperty); | |||
126 | /* Acquire an integer property and return its value. Returns -1 | 126 | /* Acquire an integer property and return its value. Returns -1 |
127 | * on failure. | 127 | * on failure. |
128 | */ | 128 | */ |
129 | int prom_getint(int node, char *prop) | 129 | int prom_getint(phandle node, char *prop) |
130 | { | 130 | { |
131 | static int intprop; | 131 | static int intprop; |
132 | 132 | ||
@@ -140,7 +140,7 @@ EXPORT_SYMBOL(prom_getint); | |||
140 | /* Acquire an integer property, upon error return the passed default | 140 | /* Acquire an integer property, upon error return the passed default |
141 | * integer. | 141 | * integer. |
142 | */ | 142 | */ |
143 | int prom_getintdefault(int node, char *property, int deflt) | 143 | int prom_getintdefault(phandle node, char *property, int deflt) |
144 | { | 144 | { |
145 | int retval; | 145 | int retval; |
146 | 146 | ||
@@ -152,7 +152,7 @@ int prom_getintdefault(int node, char *property, int deflt) | |||
152 | EXPORT_SYMBOL(prom_getintdefault); | 152 | EXPORT_SYMBOL(prom_getintdefault); |
153 | 153 | ||
154 | /* Acquire a boolean property, 1=TRUE 0=FALSE. */ | 154 | /* Acquire a boolean property, 1=TRUE 0=FALSE. */ |
155 | int prom_getbool(int node, char *prop) | 155 | int prom_getbool(phandle node, char *prop) |
156 | { | 156 | { |
157 | int retval; | 157 | int retval; |
158 | 158 | ||
@@ -166,7 +166,7 @@ EXPORT_SYMBOL(prom_getbool); | |||
166 | * string on error. The char pointer is the user supplied string | 166 | * string on error. The char pointer is the user supplied string |
167 | * buffer. | 167 | * buffer. |
168 | */ | 168 | */ |
169 | void prom_getstring(int node, char *prop, char *user_buf, int ubuf_size) | 169 | void prom_getstring(phandle node, char *prop, char *user_buf, int ubuf_size) |
170 | { | 170 | { |
171 | int len; | 171 | int len; |
172 | 172 | ||
@@ -177,27 +177,14 @@ void prom_getstring(int node, char *prop, char *user_buf, int ubuf_size) | |||
177 | EXPORT_SYMBOL(prom_getstring); | 177 | EXPORT_SYMBOL(prom_getstring); |
178 | 178 | ||
179 | 179 | ||
180 | /* Does the device at node 'node' have name 'name'? | ||
181 | * YES = 1 NO = 0 | ||
182 | */ | ||
183 | int prom_nodematch(int node, char *name) | ||
184 | { | ||
185 | int error; | ||
186 | |||
187 | static char namebuf[128]; | ||
188 | error = prom_getproperty(node, "name", namebuf, sizeof(namebuf)); | ||
189 | if (error == -1) return 0; | ||
190 | if(strcmp(namebuf, name) == 0) return 1; | ||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | /* Search siblings at 'node_start' for a node with name | 180 | /* Search siblings at 'node_start' for a node with name |
195 | * 'nodename'. Return node if successful, zero if not. | 181 | * 'nodename'. Return node if successful, zero if not. |
196 | */ | 182 | */ |
197 | int prom_searchsiblings(int node_start, char *nodename) | 183 | phandle prom_searchsiblings(phandle node_start, char *nodename) |
198 | { | 184 | { |
199 | 185 | ||
200 | int thisnode, error; | 186 | phandle thisnode; |
187 | int error; | ||
201 | 188 | ||
202 | for(thisnode = node_start; thisnode; | 189 | for(thisnode = node_start; thisnode; |
203 | thisnode=prom_getsibling(thisnode)) { | 190 | thisnode=prom_getsibling(thisnode)) { |
@@ -213,7 +200,7 @@ int prom_searchsiblings(int node_start, char *nodename) | |||
213 | EXPORT_SYMBOL(prom_searchsiblings); | 200 | EXPORT_SYMBOL(prom_searchsiblings); |
214 | 201 | ||
215 | /* Interal version of nextprop that does not alter return values. */ | 202 | /* Interal version of nextprop that does not alter return values. */ |
216 | char * __prom_nextprop(int node, char * oprop) | 203 | static char *__prom_nextprop(phandle node, char * oprop) |
217 | { | 204 | { |
218 | unsigned long flags; | 205 | unsigned long flags; |
219 | char *prop; | 206 | char *prop; |
@@ -226,35 +213,24 @@ char * __prom_nextprop(int node, char * oprop) | |||
226 | return prop; | 213 | return prop; |
227 | } | 214 | } |
228 | 215 | ||
229 | /* Return the first property name for node 'node'. */ | ||
230 | /* buffer is unused argument, but as v9 uses it, we need to have the same interface */ | ||
231 | char * prom_firstprop(int node, char *bufer) | ||
232 | { | ||
233 | if (node == 0 || node == -1) | ||
234 | return ""; | ||
235 | |||
236 | return __prom_nextprop(node, ""); | ||
237 | } | ||
238 | EXPORT_SYMBOL(prom_firstprop); | ||
239 | |||
240 | /* Return the property type string after property type 'oprop' | 216 | /* Return the property type string after property type 'oprop' |
241 | * at node 'node' . Returns empty string if no more | 217 | * at node 'node' . Returns empty string if no more |
242 | * property types for this node. | 218 | * property types for this node. |
243 | */ | 219 | */ |
244 | char * prom_nextprop(int node, char *oprop, char *buffer) | 220 | char *prom_nextprop(phandle node, char *oprop, char *buffer) |
245 | { | 221 | { |
246 | if (node == 0 || node == -1) | 222 | if (node == 0 || (s32)node == -1) |
247 | return ""; | 223 | return ""; |
248 | 224 | ||
249 | return __prom_nextprop(node, oprop); | 225 | return __prom_nextprop(node, oprop); |
250 | } | 226 | } |
251 | EXPORT_SYMBOL(prom_nextprop); | 227 | EXPORT_SYMBOL(prom_nextprop); |
252 | 228 | ||
253 | int prom_finddevice(char *name) | 229 | phandle prom_finddevice(char *name) |
254 | { | 230 | { |
255 | char nbuf[128]; | 231 | char nbuf[128]; |
256 | char *s = name, *d; | 232 | char *s = name, *d; |
257 | int node = prom_root_node, node2; | 233 | phandle node = prom_root_node, node2; |
258 | unsigned int which_io, phys_addr; | 234 | unsigned int which_io, phys_addr; |
259 | struct linux_prom_registers reg[PROMREG_MAX]; | 235 | struct linux_prom_registers reg[PROMREG_MAX]; |
260 | 236 | ||
@@ -277,7 +253,7 @@ int prom_finddevice(char *name) | |||
277 | if (d != s + 3 && (!*d || *d == '/') | 253 | if (d != s + 3 && (!*d || *d == '/') |
278 | && d <= s + 3 + 8) { | 254 | && d <= s + 3 + 8) { |
279 | node2 = node; | 255 | node2 = node; |
280 | while (node2 && node2 != -1) { | 256 | while (node2 && (s32)node2 != -1) { |
281 | if (prom_getproperty (node2, "reg", (char *)reg, sizeof (reg)) > 0) { | 257 | if (prom_getproperty (node2, "reg", (char *)reg, sizeof (reg)) > 0) { |
282 | if (which_io == reg[0].which_io && phys_addr == reg[0].phys_addr) { | 258 | if (which_io == reg[0].which_io && phys_addr == reg[0].phys_addr) { |
283 | node = node2; | 259 | node = node2; |
@@ -285,7 +261,7 @@ int prom_finddevice(char *name) | |||
285 | } | 261 | } |
286 | } | 262 | } |
287 | node2 = prom_getsibling(node2); | 263 | node2 = prom_getsibling(node2); |
288 | if (!node2 || node2 == -1) | 264 | if (!node2 || (s32)node2 == -1) |
289 | break; | 265 | break; |
290 | node2 = prom_searchsiblings(prom_getsibling(node2), nbuf); | 266 | node2 = prom_searchsiblings(prom_getsibling(node2), nbuf); |
291 | } | 267 | } |
@@ -298,29 +274,18 @@ int prom_finddevice(char *name) | |||
298 | } | 274 | } |
299 | EXPORT_SYMBOL(prom_finddevice); | 275 | EXPORT_SYMBOL(prom_finddevice); |
300 | 276 | ||
301 | int prom_node_has_property(int node, char *prop) | ||
302 | { | ||
303 | char *current_property = ""; | ||
304 | |||
305 | do { | ||
306 | current_property = prom_nextprop(node, current_property, NULL); | ||
307 | if(!strcmp(current_property, prop)) | ||
308 | return 1; | ||
309 | } while (*current_property); | ||
310 | return 0; | ||
311 | } | ||
312 | EXPORT_SYMBOL(prom_node_has_property); | ||
313 | |||
314 | /* Set property 'pname' at node 'node' to value 'value' which has a length | 277 | /* Set property 'pname' at node 'node' to value 'value' which has a length |
315 | * of 'size' bytes. Return the number of bytes the prom accepted. | 278 | * of 'size' bytes. Return the number of bytes the prom accepted. |
316 | */ | 279 | */ |
317 | int prom_setprop(int node, const char *pname, char *value, int size) | 280 | int prom_setprop(phandle node, const char *pname, char *value, int size) |
318 | { | 281 | { |
319 | unsigned long flags; | 282 | unsigned long flags; |
320 | int ret; | 283 | int ret; |
321 | 284 | ||
322 | if(size == 0) return 0; | 285 | if (size == 0) |
323 | if((pname == 0) || (value == 0)) return 0; | 286 | return 0; |
287 | if ((pname == NULL) || (value == NULL)) | ||
288 | return 0; | ||
324 | spin_lock_irqsave(&prom_lock, flags); | 289 | spin_lock_irqsave(&prom_lock, flags); |
325 | ret = prom_nodeops->no_setprop(node, pname, value, size); | 290 | ret = prom_nodeops->no_setprop(node, pname, value, size); |
326 | restore_current(); | 291 | restore_current(); |
@@ -329,30 +294,16 @@ int prom_setprop(int node, const char *pname, char *value, int size) | |||
329 | } | 294 | } |
330 | EXPORT_SYMBOL(prom_setprop); | 295 | EXPORT_SYMBOL(prom_setprop); |
331 | 296 | ||
332 | int prom_inst2pkg(int inst) | 297 | phandle prom_inst2pkg(int inst) |
333 | { | 298 | { |
334 | int node; | 299 | phandle node; |
335 | unsigned long flags; | 300 | unsigned long flags; |
336 | 301 | ||
337 | spin_lock_irqsave(&prom_lock, flags); | 302 | spin_lock_irqsave(&prom_lock, flags); |
338 | node = (*romvec->pv_v2devops.v2_inst2pkg)(inst); | 303 | node = (*romvec->pv_v2devops.v2_inst2pkg)(inst); |
339 | restore_current(); | 304 | restore_current(); |
340 | spin_unlock_irqrestore(&prom_lock, flags); | 305 | spin_unlock_irqrestore(&prom_lock, flags); |
341 | if (node == -1) return 0; | 306 | if ((s32)node == -1) |
342 | return node; | 307 | return 0; |
343 | } | ||
344 | |||
345 | /* Return 'node' assigned to a particular prom 'path' | ||
346 | * FIXME: Should work for v0 as well | ||
347 | */ | ||
348 | int prom_pathtoinode(char *path) | ||
349 | { | ||
350 | int node, inst; | ||
351 | |||
352 | inst = prom_devopen (path); | ||
353 | if (inst == -1) return 0; | ||
354 | node = prom_inst2pkg (inst); | ||
355 | prom_devclose (inst); | ||
356 | if (node == -1) return 0; | ||
357 | return node; | 308 | return node; |
358 | } | 309 | } |