This source file includes following definitions.
- prom_getchild
- prom_getsibling
- prom_getproplen
- prom_getproperty
- prom_getint
- prom_getintdefault
- prom_getbool
- prom_getstring
- prom_nodematch
- prom_searchsiblings
- prom_firstprop
- prom_nextprop
- prom_node_has_property
- prom_setprop
1
2
3
4
5
6
7
8 #include <linux/string.h>
9
10 #include <asm/openprom.h>
11 #include <asm/oplib.h>
12
13 static char promlib_buf[128];
14
15
16
17
18 int
19 prom_getchild(int node)
20 {
21 int cnode;
22
23 if(node == -1) return 0;
24 cnode = prom_nodeops->no_child(node);
25 if((cnode == 0) || (cnode == -1)) return 0;
26 return cnode;
27 }
28
29
30
31
32 int
33 prom_getsibling(int node)
34 {
35 int sibnode;
36
37 if(node == -1) return 0;
38 sibnode = prom_nodeops->no_nextnode(node);
39 if((sibnode == 0) || (sibnode == -1)) return 0;
40 return sibnode;
41 }
42
43
44
45
46 int
47 prom_getproplen(int node, char *prop)
48 {
49 if((!node) || (!prop)) return -1;
50 return prom_nodeops->no_proplen(node, prop);
51 }
52
53
54
55
56
57 int
58 prom_getproperty(int node, char *prop, char *buffer, int bufsize)
59 {
60 int plen;
61
62 plen = prom_getproplen(node, prop);
63 if((plen > bufsize) || (plen == 0) || (plen == -1)) return -1;
64
65
66 return prom_nodeops->no_getprop(node, prop, buffer);
67 }
68
69
70
71
72 int
73 prom_getint(int node, char *prop)
74 {
75 static int intprop;
76
77 if(prom_getproperty(node, prop, (char *) &intprop, sizeof(int)) != -1)
78 return intprop;
79
80 return -1;
81 }
82
83
84
85
86
87 int
88 prom_getintdefault(int node, char *property, int deflt)
89 {
90 int retval;
91
92 retval = prom_getint(node, property);
93 if(retval == -1) return deflt;
94
95 return retval;
96 }
97
98
99 int
100 prom_getbool(int node, char *prop)
101 {
102 int retval;
103
104 retval = prom_getproplen(node, prop);
105 if(retval == -1) return 0;
106 return 1;
107 }
108
109
110
111
112
113 void
114 prom_getstring(int node, char *prop, char *user_buf, int ubuf_size)
115 {
116 int len;
117
118 len = prom_getproperty(node, prop, user_buf, ubuf_size);
119 if(len != -1) return;
120 user_buf[0] = 0;
121 return;
122 }
123
124
125
126
127
128 int
129 prom_nodematch(int node, char *name)
130 {
131 static char namebuf[128];
132 prom_getproperty(node, "name", namebuf, sizeof(namebuf));
133 if(strcmp(namebuf, name) == 0) return 1;
134 return 0;
135 }
136
137
138
139
140 int
141 prom_searchsiblings(int node_start, char *nodename)
142 {
143 int thisnode, error;
144
145 for(thisnode = node_start; thisnode;
146 thisnode=prom_getsibling(thisnode)) {
147 error = prom_getproperty(thisnode, "name", promlib_buf,
148 sizeof(promlib_buf));
149
150 if(error == -1) continue;
151 if(strcmp(nodename, promlib_buf)==0) return thisnode;
152 }
153
154 return 0;
155 }
156
157
158
159 char *
160 prom_firstprop(int node)
161 {
162 if(node == -1) return "";
163 return prom_nodeops->no_nextprop(node, (char *) 0x0);
164 }
165
166
167
168
169
170 char *
171 prom_nextprop(int node, char *oprop)
172 {
173 if(node == -1) return "";
174 return prom_nodeops->no_nextprop(node, oprop);
175 }
176
177 int
178 prom_node_has_property(int node, char *prop)
179 {
180 char *current_property = "";
181
182 do {
183 current_property = prom_nextprop(node, current_property);
184 if(!strcmp(current_property, prop))
185 return 1;
186 } while (*current_property);
187 return 0;
188 }
189
190
191
192
193 int
194 prom_setprop(int node, char *pname, char *value, int size)
195 {
196 if(size == 0) return 0;
197 if((pname == 0) || (value == 0)) return 0;
198 return prom_nodeops->no_setprop(node, pname, value, size);
199 }