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