forked from freebsd/freebsd-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OF_getprop.9
350 lines (347 loc) · 10.1 KB
/
OF_getprop.9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
.\"
.\" Copyright (c) 2018 Oleksandr Tymoshenko <[email protected]>
.\"
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd June 23, 2018
.Dt OF_GETPROP 9
.Os
.Sh NAME
.Nm OF_getprop ,
.Nm OF_getproplen ,
.Nm OF_getencprop ,
.Nm OF_hasprop ,
.Nm OF_searchprop ,
.Nm OF_searchencprop ,
.Nm OF_getprop_alloc ,
.Nm OF_getencprop_alloc ,
.Nm OF_getprop_alloc_multi ,
.Nm OF_getencprop_alloc_multi ,
.Nm OF_prop_free ,
.Nm OF_nextprop ,
.Nm OF_setprop
.Nd access properties of device tree node
.Sh SYNOPSIS
.In dev/ofw/ofw_bus.h
.In dev/ofw/ofw_bus_subr.h
.Ft ssize_t
.Fn OF_getproplen "phandle_t node" "const char *propname"
.Ft ssize_t
.Fn OF_getprop "phandle_t node" "const char *propname" \
"void *buf" "size_t len"
.Ft ssize_t
.Fn OF_getencprop "phandle_t node" "const char *prop" \
"pcell_t *buf" "size_t len"
.Ft int
.Fn OF_hasprop "phandle_t node" "const char *propname"
.Ft ssize_t
.Fn OF_searchprop "phandle_t node" "const char *propname" \
"void *buf" "size_t len"
.Ft ssize_t
.Fn OF_searchencprop "phandle_t node" "const char *propname" \
"pcell_t *buf" "size_t len"
.Ft ssize_t
.Fn OF_getprop_alloc "phandle_t node" "const char *propname" \
"void **buf"
.Ft ssize_t
.Fn OF_getencprop_alloc "phandle_t node" "const char *propname" \
"pcell_t **buf"
.Ft ssize_t
.Fn OF_getprop_alloc_multi "phandle_t node" "const char *propname" \
"int elsz" "void **buf"
.Ft ssize_t
.Fn OF_getencprop_alloc_multi "phandle_t node" "const char *propname" \
"int elsz" "pcell_t **buf"
.Ft void
.Fn OF_prop_free "void *buf"
.Ft int
.Fn OF_nextprop "phandle_t node" "const char *propname" \
"char *buf" "size_t len"
.Ft int
.Fn OF_setprop "phandle_t node" "const char *propname" \
"const void *buf" "size_t len"
.Sh DESCRIPTION
Device nodes can have associated properties.
Properties consist of a name and a value.
A name is a human-readable string from 1 to 31 characters long.
A value is an array of zero or more bytes that encode certain
information.
The meaning of that bytes depends on how drivers interpret them.
Properties can encode byte arrays, text strings, unsigned 32-bit
values or any combination of these types.
.Pp
Property with a zero-length value usually represents boolean
information.
If the property is present, it signifies true, otherwise false.
.Pp
A byte array is encoded as a sequence of bytes and represents
values like MAC addresses.
.Pp
A text string is a sequence of n printable characters.
It is encoded as a byte array of length n + 1 bytes with
characters represented as bytes plus a terminating null character.
.Pp
Unsigned 32-bit values, also sometimes called cells, are
encoded as a sequence of 4 bytes in big-endian order.
.Pp
.Fn OF_getproplen
returns either the length of the value associated with the property
.Fa propname
in the node identified by
.Fa node ,
or 0 if the property exists but has no associated value.
If
.Fa propname
does not exist, -1 is returned.
.Pp
.Fn OF_getprop
copies a maximum of
.Fa len
bytes from the value associated with the property
.Fa propname
of the device node
.Fa node
into the memory specified by
.Fa buf .
Returns the actual size of the value or -1 if the
property does not exist.
.Pp
.Fn OF_getencprop
copies a maximum of
.Fa len
bytes into memory specified by
.Fa buf ,
then converts cell values from big-endian to host byte order.
Returns the actual size of the value in bytes, or -1
if the property does not exist.
.Fa len
must be a multiple of 4.
.Pp
.Fn OF_hasprop
returns 1 if the device node
.Fa node
has a property specified by
.Fa propname ,
and zero if the property does not exist.
.Pp
.Fn OF_searchprop
recursively looks for the property specified by
.Fa propname
starting with the device node
.Fa node
followed by the parent node and up to the root node.
If the property is found, the function copies a maximum of
.Fa len
bytes of the value associated with the property
into the memory specified by
.Fa buf .
Returns the actual size in bytes of the value,
or -1 if the property does not exist.
.Pp
.Fn OF_searchencprop
recursively looks for the property specified by
.Fa propname
starting with the device node
.Fa node
followed by the parent node and up to the root node.
If the property is found, the function copies a maximum of
.Fa len
bytes of the value associated with the property
into the memory specified by
.Fa buf ,
then converts cell values from big-endian to host byte order.
Returns the actual size in bytes of the value,
or -1 if the property does not exist.
.Pp
.Fn OF_getprop_alloc
allocates memory large enough to hold the
value associated with the property
.Fa propname
of the device node
.Fa node
and copies the value into the newly allocated memory region.
Returns the actual size of the value and stores
the address of the allocated memory in
.Fa *buf .
If the property has a zero-sized value
.Fa *buf
is set NULL.
Returns -1 if the property does not exist or
memory allocation failed.
Allocated memory should be released when no longer required
by calling
.Fn OF_prop_free .
The function might sleep when allocating memory.
.Pp
.Fn OF_getencprop_alloc
allocates enough memory to hold the
value associated with the property
.Fa propname
of the device node
.Fa node ,
copies the value into the newly allocated memory region, and
then converts cell values from big-endian to host byte
order.
The actual size of the value is returned and the
address of allocated memory is stored in
.Fa *buf .
If the property has zero-length value,
.Fa *buf
is set to NULL.
Returns -1 if the property does not exist or
memory allocation failed or the size of the value is not
divisible by a cell size (4 bytes).
Allocated memory should be released when no longer required
by calling
.Fn OF_prop_free .
The function might sleep when allocating memory.
.Pp
.Fn OF_getprop_alloc_multi
allocates memory large enough to hold the
value associated with the property
.Fa propname
of the device node
.Fa node
and copies the value into the newly allocated memory region.
The value is expected to be an array of zero or more elements
.Fa elsz
bytes long.
Returns the number of elements in the value and stores
the address of the allocated memory in
.Fa *buf .
If the property has a zero-sized value
.Fa *buf
is set NULL.
Returns -1 if the property does not exist or
memory allocation failed or the size of the value is not
divisible by
.Fa elsz .
Allocated memory should be released when no longer required
by calling
.Fn OF_prop_free .
The function might sleep when allocating memory.
.Pp
.Fn OF_getencprop_alloc_multi
allocates memory large enough to hold the
value associated with the property
.Fa propname
of the device node
.Fa node
and copies the value into the newly allocated memory region, and
then converts cell values from big-endian to host byte
order.
The value is expected to be an array of zero or more elements
.Fa elsz
bytes long.
Returns the number of elements in the value and stores
the address of the allocated memory in
.Fa *buf .
If the property has a zero-sized value
.Fa *buf
is set NULL.
Returns -1 if the property does not exist or
memory allocation failed or the size of the value is not
divisible by
.Fa elsz .
Allocated memory should be released when no longer required
by calling
.Fn OF_prop_free .
The function might sleep when allocating memory.
.Pp
.Fn OF_prop_free
releases memory at
.Fa buf
that was allocated by
.Fn OF_getprop_alloc ,
.Fn OF_getencprop_alloc ,
.Fn OF_getprop_alloc_multi ,
.Fn OF_getencprop_alloc_multi .
.Pp
.Fn OF_nextprop
copies a maximum of
.Fa size
bytes of the name of the property following the
.Fa propname
property into
.Fa buf .
If
.Fa propname
is NULL, the function copies the name of the first property of the
device node
.Fa node .
.Fn OF_nextprop
returns -1 if
.Fa propname
is invalid or there is an internal error, 0 if there are no more
properties after
.Fa propname ,
or 1 otherwise.
.Pp
.Fn OF_setprop
sets the value of the property
.Fa propname
in the device node
.Fa node
to the value beginning at the address specified by
.Fa buf
and running for
.Fa len
bytes.
If the property does not exist, the function tries to create
it.
.Fn OF_setprop
returns the actual size of the new value, or -1 if the
property value cannot be changed or the new property
cannot be created.
.Sh EXAMPLES
.Bd -literal
phandle_t node;
phandle_t hdmixref, hdminode;
device_t hdmi;
uint8_t mac[6];
char *model;
/*
* Get a byte array property
*/
if (OF_getprop(node, "eth,hwaddr", mac, sizeof(mac)) != sizeof(mac))
return;
/*
* Get internal node reference and device associated with it
*/
if (OF_getencprop(node, "hdmi", &hdmixref) <= 0)
return;
hdmi = OF_device_from_xref(hdmixref);
/*
* Get string value of model property of HDMI framer node
*/
hdminode = OF_node_from_xref(hdmixref);
if (OF_getprop_alloc(hdminode, "model", (void **)&model) <= 0)
return;
.Ed
.Sh SEE ALSO
.Xr OF_device_from_xref 9 ,
.Xr OF_node_from_xref 9
.Sh AUTHORS
.An -nosplit
This manual page was written by
.An Oleksandr Tymoshenko Aq Mt [email protected] .