OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [sparc/] [prom/] [tree.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1624 jcastillo
/* $Id: tree.c,v 1.1 2005-12-20 09:49:32 jcastillo Exp $
2
 * tree.c: Basic device tree traversal/scanning for the Linux
3
 *         prom library.
4
 *
5
 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6
 */
7
 
8
#include <linux/config.h>
9
#include <linux/string.h>
10
 
11
#include <asm/openprom.h>
12
#include <asm/oplib.h>
13
 
14
static char promlib_buf[128];
15
 
16
/* Return the child of node 'node' or zero if no this node has no
17
 * direct descendent.
18
 */
19
int
20
prom_getchild(int node)
21
{
22
        int cnode;
23
 
24
#if CONFIG_AP1000
25
        printk("prom_getchild -> 0\n");
26
        return 0;
27
#endif
28
        if(node == -1) return 0;
29
        cnode = prom_nodeops->no_child(node);
30
        if((cnode == 0) || (cnode == -1)) return 0;
31
        return cnode;
32
}
33
 
34
/* Return the next sibling of node 'node' or zero if no more siblings
35
 * at this level of depth in the tree.
36
 */
37
int
38
prom_getsibling(int node)
39
{
40
        int sibnode;
41
 
42
#if CONFIG_AP1000
43
        printk("prom_getsibling -> 0\n");
44
        return 0;
45
#endif
46
        if(node == -1) return 0;
47
        sibnode = prom_nodeops->no_nextnode(node);
48
        if((sibnode == 0) || (sibnode == -1)) return 0;
49
        return sibnode;
50
}
51
 
52
/* Return the length in bytes of property 'prop' at node 'node'.
53
 * Return -1 on error.
54
 */
55
int
56
prom_getproplen(int node, char *prop)
57
{
58
#if CONFIG_AP1000
59
        printk("prom_getproplen(%s) -> -1\n",prop);
60
        return -1;
61
#endif
62
        if((!node) || (!prop)) return -1;
63
        return prom_nodeops->no_proplen(node, prop);
64
}
65
 
66
/* Acquire a property 'prop' at node 'node' and place it in
67
 * 'buffer' which has a size of 'bufsize'.  If the acquisition
68
 * was successful the length will be returned, else -1 is returned.
69
 */
70
int
71
prom_getproperty(int node, char *prop, char *buffer, int bufsize)
72
{
73
        int plen;
74
 
75
#if CONFIG_AP1000
76
        printk("prom_getproperty(%s) -> -1\n",prop);
77
        return -1;
78
#endif
79
        plen = prom_getproplen(node, prop);
80
        if((plen > bufsize) || (plen == 0) || (plen == -1)) return -1;
81
 
82
        /* Ok, things seem all right. */
83
        return prom_nodeops->no_getprop(node, prop, buffer);
84
}
85
 
86
/* Acquire an integer property and return its value.  Returns -1
87
 * on failure.
88
 */
89
int
90
prom_getint(int node, char *prop)
91
{
92
        static int intprop;
93
 
94
#if CONFIG_AP1000
95
        printk("prom_getint(%s) -> -1\n",prop);
96
        return -1;
97
#endif
98
        if(prom_getproperty(node, prop, (char *) &intprop, sizeof(int)) != -1)
99
                return intprop;
100
 
101
        return -1;
102
}
103
 
104
/* Acquire an integer property, upon error return the passed default
105
 * integer.
106
 */
107
 
108
int
109
prom_getintdefault(int node, char *property, int deflt)
110
{
111
        int retval;
112
 
113
#if CONFIG_AP1000
114
        printk("prom_getintdefault(%s) -> 0\n",property);
115
        return 0;
116
#endif
117
        retval = prom_getint(node, property);
118
        if(retval == -1) return deflt;
119
 
120
        return retval;
121
}
122
 
123
/* Acquire a boolean property, 1=TRUE 0=FALSE. */
124
int
125
prom_getbool(int node, char *prop)
126
{
127
        int retval;
128
 
129
#if CONFIG_AP1000
130
        printk("prom_getbool(%s) -> 0\n",prop);
131
        return 0;
132
#endif
133
        retval = prom_getproplen(node, prop);
134
        if(retval == -1) return 0;
135
        return 1;
136
}
137
 
138
/* Acquire a property whose value is a string, returns a null
139
 * string on error.  The char pointer is the user supplied string
140
 * buffer.
141
 */
142
void
143
prom_getstring(int node, char *prop, char *user_buf, int ubuf_size)
144
{
145
        int len;
146
 
147
#if CONFIG_AP1000
148
        printk("prom_getstring(%s) -> .\n",prop);
149
        return;
150
#endif
151
        len = prom_getproperty(node, prop, user_buf, ubuf_size);
152
        if(len != -1) return;
153
        user_buf[0] = 0;
154
        return;
155
}
156
 
157
 
158
/* Does the device at node 'node' have name 'name'?
159
 * YES = 1   NO = 0
160
 */
161
int
162
prom_nodematch(int node, char *name)
163
{
164
        static char namebuf[128];
165
        prom_getproperty(node, "name", namebuf, sizeof(namebuf));
166
        if(strcmp(namebuf, name) == 0) return 1;
167
        return 0;
168
}
169
 
170
/* Search siblings at 'node_start' for a node with name
171
 * 'nodename'.  Return node if successful, zero if not.
172
 */
173
int
174
prom_searchsiblings(int node_start, char *nodename)
175
{
176
        int thisnode, error;
177
 
178
        for(thisnode = node_start; thisnode;
179
            thisnode=prom_getsibling(thisnode)) {
180
                error = prom_getproperty(thisnode, "name", promlib_buf,
181
                                         sizeof(promlib_buf));
182
                /* Should this ever happen? */
183
                if(error == -1) continue;
184
                if(strcmp(nodename, promlib_buf)==0) return thisnode;
185
        }
186
 
187
        return 0;
188
}
189
 
190
/* Return the first property type for node 'node'.
191
 */
192
char *
193
prom_firstprop(int node)
194
{
195
        if(node == -1) return "";
196
        return prom_nodeops->no_nextprop(node, (char *) 0x0);
197
}
198
 
199
/* Return the property type string after property type 'oprop'
200
 * at node 'node' .  Returns NULL string if no more
201
 * property types for this node.
202
 */
203
char *
204
prom_nextprop(int node, char *oprop)
205
{
206
        if(node == -1) return "";
207
        return prom_nodeops->no_nextprop(node, oprop);
208
}
209
 
210
int
211
prom_node_has_property(int node, char *prop)
212
{
213
        char *current_property = "";
214
 
215
        do {
216
                current_property = prom_nextprop(node, current_property);
217
                if(!strcmp(current_property, prop))
218
                   return 1;
219
        } while (*current_property);
220
        return 0;
221
}
222
 
223
/* Set property 'pname' at node 'node' to value 'value' which has a length
224
 * of 'size' bytes.  Return the number of bytes the prom accepted.
225
 */
226
int
227
prom_setprop(int node, char *pname, char *value, int size)
228
{
229
        if(size == 0) return 0;
230
        if((pname == 0) || (value == 0)) return 0;
231
        return prom_nodeops->no_setprop(node, pname, value, size);
232
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.