20
20
static char promlib_buf[128];
22
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)
25
25
unsigned long flags;
28
28
spin_lock_irqsave(&prom_lock, flags);
29
29
cnode = prom_nodeops->no_child(node);
36
36
/* Return the child of node 'node' or zero if no this node has no
37
37
* direct descendent.
39
int prom_getchild(int node)
39
phandle prom_getchild(phandle node)
46
46
cnode = __prom_getchild(node);
47
if (cnode == 0 || cnode == -1)
47
if (cnode == 0 || (s32)cnode == -1)
52
52
EXPORT_SYMBOL(prom_getchild);
54
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)
57
57
unsigned long flags;
60
60
spin_lock_irqsave(&prom_lock, flags);
61
61
cnode = prom_nodeops->no_nextnode(node);
68
68
/* Return the next sibling of node 'node' or zero if no more siblings
69
69
* at this level of depth in the tree.
71
int prom_getsibling(int node)
71
phandle prom_getsibling(phandle node)
78
78
sibnode = __prom_getsibling(node);
79
if (sibnode == 0 || sibnode == -1)
79
if (sibnode == 0 || (s32)sibnode == -1)
106
106
* 'buffer' which has a size of 'bufsize'. If the acquisition
107
107
* was successful the length will be returned, else -1 is returned.
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)
112
112
unsigned long flags;
140
140
/* Acquire an integer property, upon error return the passed default
143
int prom_getintdefault(int node, char *property, int deflt)
143
int prom_getintdefault(phandle node, char *property, int deflt)
152
152
EXPORT_SYMBOL(prom_getintdefault);
154
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)
166
166
* string on error. The char pointer is the user supplied string
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)
173
173
len = prom_getproperty(node, prop, user_buf, ubuf_size);
174
174
if(len != -1) return;
178
177
EXPORT_SYMBOL(prom_getstring);
181
/* Does the device at node 'node' have name 'name'?
184
int prom_nodematch(int node, char *name)
188
static char namebuf[128];
189
error = prom_getproperty(node, "name", namebuf, sizeof(namebuf));
190
if (error == -1) return 0;
191
if(strcmp(namebuf, name) == 0) return 1;
195
180
/* Search siblings at 'node_start' for a node with name
196
181
* 'nodename'. Return node if successful, zero if not.
198
int prom_searchsiblings(int node_start, char *nodename)
183
phandle prom_searchsiblings(phandle node_start, char *nodename)
203
189
for(thisnode = node_start; thisnode;
204
190
thisnode=prom_getsibling(thisnode)) {
214
200
EXPORT_SYMBOL(prom_searchsiblings);
216
202
/* Interal version of nextprop that does not alter return values. */
217
char * __prom_nextprop(int node, char * oprop)
203
static char *__prom_nextprop(phandle node, char * oprop)
219
205
unsigned long flags;
230
/* Return the first property name for node 'node'. */
231
/* buffer is unused argument, but as v9 uses it, we need to have the same interface */
232
char * prom_firstprop(int node, char *bufer)
234
if (node == 0 || node == -1)
237
return __prom_nextprop(node, "");
239
EXPORT_SYMBOL(prom_firstprop);
241
216
/* Return the property type string after property type 'oprop'
242
217
* at node 'node' . Returns empty string if no more
243
218
* property types for this node.
245
char * prom_nextprop(int node, char *oprop, char *buffer)
220
char *prom_nextprop(phandle node, char *oprop, char *buffer)
247
if (node == 0 || node == -1)
222
if (node == 0 || (s32)node == -1)
250
225
return __prom_nextprop(node, oprop);
252
227
EXPORT_SYMBOL(prom_nextprop);
254
int prom_finddevice(char *name)
229
phandle prom_finddevice(char *name)
257
232
char *s = name, *d;
258
int node = prom_root_node, node2;
233
phandle node = prom_root_node, node2;
259
234
unsigned int which_io, phys_addr;
260
235
struct linux_prom_registers reg[PROMREG_MAX];
278
253
if (d != s + 3 && (!*d || *d == '/')
279
254
&& d <= s + 3 + 8) {
281
while (node2 && node2 != -1) {
256
while (node2 && (s32)node2 != -1) {
282
257
if (prom_getproperty (node2, "reg", (char *)reg, sizeof (reg)) > 0) {
283
258
if (which_io == reg[0].which_io && phys_addr == reg[0].phys_addr) {
288
263
node2 = prom_getsibling(node2);
289
if (!node2 || node2 == -1)
264
if (!node2 || (s32)node2 == -1)
291
266
node2 = prom_searchsiblings(prom_getsibling(node2), nbuf);
300
275
EXPORT_SYMBOL(prom_finddevice);
302
int prom_node_has_property(int node, char *prop)
304
char *current_property = "";
307
current_property = prom_nextprop(node, current_property, NULL);
308
if(!strcmp(current_property, prop))
310
} while (*current_property);
313
EXPORT_SYMBOL(prom_node_has_property);
315
277
/* Set property 'pname' at node 'node' to value 'value' which has a length
316
278
* of 'size' bytes. Return the number of bytes the prom accepted.
318
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)
320
282
unsigned long flags;
323
if(size == 0) return 0;
324
if((pname == 0) || (value == 0)) return 0;
287
if ((pname == NULL) || (value == NULL))
325
289
spin_lock_irqsave(&prom_lock, flags);
326
290
ret = prom_nodeops->no_setprop(node, pname, value, size);
327
291
restore_current();
331
295
EXPORT_SYMBOL(prom_setprop);
333
int prom_inst2pkg(int inst)
297
phandle prom_inst2pkg(int inst)
336
300
unsigned long flags;
338
302
spin_lock_irqsave(&prom_lock, flags);
339
303
node = (*romvec->pv_v2devops.v2_inst2pkg)(inst);
340
304
restore_current();
341
305
spin_unlock_irqrestore(&prom_lock, flags);
342
if (node == -1) return 0;
346
/* Return 'node' assigned to a particular prom 'path'
347
* FIXME: Should work for v0 as well
349
int prom_pathtoinode(char *path)
353
inst = prom_devopen (path);
354
if (inst == -1) return 0;
355
node = prom_inst2pkg (inst);
356
prom_devclose (inst);
357
if (node == -1) return 0;