xref: /freebsd/share/man/man9/OF_getprop.9 (revision 320686674b3c8ce3ffe135c421a22d063917ee46)
1ac32b99cSOleksandr Tymoshenko.\"
2ac32b99cSOleksandr Tymoshenko.\" Copyright (c) 2018 Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3ac32b99cSOleksandr Tymoshenko.\"
4ac32b99cSOleksandr Tymoshenko.\" All rights reserved.
5ac32b99cSOleksandr Tymoshenko.\"
6ac32b99cSOleksandr Tymoshenko.\" Redistribution and use in source and binary forms, with or without
7ac32b99cSOleksandr Tymoshenko.\" modification, are permitted provided that the following conditions
8ac32b99cSOleksandr Tymoshenko.\" are met:
9ac32b99cSOleksandr Tymoshenko.\" 1. Redistributions of source code must retain the above copyright
10ac32b99cSOleksandr Tymoshenko.\"    notice, this list of conditions and the following disclaimer.
11ac32b99cSOleksandr Tymoshenko.\" 2. Redistributions in binary form must reproduce the above copyright
12ac32b99cSOleksandr Tymoshenko.\"    notice, this list of conditions and the following disclaimer in the
13ac32b99cSOleksandr Tymoshenko.\"    documentation and/or other materials provided with the distribution.
14ac32b99cSOleksandr Tymoshenko.\"
15ac32b99cSOleksandr Tymoshenko.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16ac32b99cSOleksandr Tymoshenko.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17ac32b99cSOleksandr Tymoshenko.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18ac32b99cSOleksandr Tymoshenko.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19ac32b99cSOleksandr Tymoshenko.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20ac32b99cSOleksandr Tymoshenko.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21ac32b99cSOleksandr Tymoshenko.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22ac32b99cSOleksandr Tymoshenko.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23ac32b99cSOleksandr Tymoshenko.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24ac32b99cSOleksandr Tymoshenko.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25ac32b99cSOleksandr Tymoshenko.\"
26ac32b99cSOleksandr Tymoshenko.\" $FreeBSD$
27ac32b99cSOleksandr Tymoshenko.\"
2880cb7cd4SOleksandr Tymoshenko.Dd June 23, 2018
2980cb7cd4SOleksandr Tymoshenko.Dt OF_GETPROP 9
30ac32b99cSOleksandr Tymoshenko.Os
31ac32b99cSOleksandr Tymoshenko.Sh NAME
32ac32b99cSOleksandr Tymoshenko.Nm OF_getprop ,
33ac32b99cSOleksandr Tymoshenko.Nm OF_getproplen ,
34ac32b99cSOleksandr Tymoshenko.Nm OF_getencprop ,
35ac32b99cSOleksandr Tymoshenko.Nm OF_hasprop ,
36ac32b99cSOleksandr Tymoshenko.Nm OF_searchprop ,
37ac32b99cSOleksandr Tymoshenko.Nm OF_searchencprop ,
38ac32b99cSOleksandr Tymoshenko.Nm OF_getprop_alloc ,
39ac32b99cSOleksandr Tymoshenko.Nm OF_getencprop_alloc ,
4080cb7cd4SOleksandr Tymoshenko.Nm OF_getprop_alloc_multi ,
4180cb7cd4SOleksandr Tymoshenko.Nm OF_getencprop_alloc_multi ,
42ac32b99cSOleksandr Tymoshenko.Nm OF_prop_free ,
43ac32b99cSOleksandr Tymoshenko.Nm OF_nextprop ,
44ac32b99cSOleksandr Tymoshenko.Nm OF_setprop
45ac32b99cSOleksandr Tymoshenko.Nd access properties of device tree node
46ac32b99cSOleksandr Tymoshenko.Sh SYNOPSIS
47ac32b99cSOleksandr Tymoshenko.In dev/ofw/ofw_bus.h
48ac32b99cSOleksandr Tymoshenko.In dev/ofw/ofw_bus_subr.h
49ac32b99cSOleksandr Tymoshenko.Ft ssize_t
50ac32b99cSOleksandr Tymoshenko.Fn OF_getproplen "phandle_t node" "const char *propname"
51ac32b99cSOleksandr Tymoshenko.Ft ssize_t
52ac32b99cSOleksandr Tymoshenko.Fn OF_getprop "phandle_t node" "const char *propname" \
53ac32b99cSOleksandr Tymoshenko"void *buf" "size_t len"
54ac32b99cSOleksandr Tymoshenko.Ft ssize_t
55ac32b99cSOleksandr Tymoshenko.Fn OF_getencprop "phandle_t node" "const char *prop" \
56ac32b99cSOleksandr Tymoshenko"pcell_t *buf" "size_t len"
57ac32b99cSOleksandr Tymoshenko.Ft int
58ac32b99cSOleksandr Tymoshenko.Fn OF_hasprop "phandle_t node" "const char *propname"
59ac32b99cSOleksandr Tymoshenko.Ft ssize_t
60ac32b99cSOleksandr Tymoshenko.Fn OF_searchprop "phandle_t node" "const char *propname" \
61ac32b99cSOleksandr Tymoshenko"void *buf" "size_t len"
62ac32b99cSOleksandr Tymoshenko.Ft ssize_t
63ac32b99cSOleksandr Tymoshenko.Fn OF_searchencprop "phandle_t node" "const char *propname" \
64ac32b99cSOleksandr Tymoshenko"pcell_t *buf" "size_t len"
65ac32b99cSOleksandr Tymoshenko.Ft ssize_t
66ac32b99cSOleksandr Tymoshenko.Fn OF_getprop_alloc "phandle_t node" "const char *propname" \
67ac32b99cSOleksandr Tymoshenko"void **buf"
68ac32b99cSOleksandr Tymoshenko.Ft ssize_t
69ac32b99cSOleksandr Tymoshenko.Fn OF_getencprop_alloc "phandle_t node" "const char *propname" \
70ac32b99cSOleksandr Tymoshenko"pcell_t **buf"
7180cb7cd4SOleksandr Tymoshenko.Ft ssize_t
7280cb7cd4SOleksandr Tymoshenko.Fn OF_getprop_alloc_multi "phandle_t node" "const char *propname" \
7380cb7cd4SOleksandr Tymoshenko"int elsz" "void **buf"
7480cb7cd4SOleksandr Tymoshenko.Ft ssize_t
7580cb7cd4SOleksandr Tymoshenko.Fn OF_getencprop_alloc_multi "phandle_t node" "const char *propname" \
7680cb7cd4SOleksandr Tymoshenko"int elsz" "pcell_t **buf"
77ac32b99cSOleksandr Tymoshenko.Ft void
78ac32b99cSOleksandr Tymoshenko.Fn OF_prop_free "void *buf"
79ac32b99cSOleksandr Tymoshenko.Ft int
80ac32b99cSOleksandr Tymoshenko.Fn OF_nextprop "phandle_t node" "const char *propname" \
81ac32b99cSOleksandr Tymoshenko"char *buf" "size_t len"
82ac32b99cSOleksandr Tymoshenko.Ft int
83ac32b99cSOleksandr Tymoshenko.Fn OF_setprop "phandle_t node" "const char *propname" \
84ac32b99cSOleksandr Tymoshenko"const void *buf" "size_t len"
85ac32b99cSOleksandr Tymoshenko.Sh DESCRIPTION
86ac32b99cSOleksandr TymoshenkoDevice nodes can have associated properties.
87ac32b99cSOleksandr TymoshenkoProperties consist of a name and a value.
88ac32b99cSOleksandr TymoshenkoA name is a human-readable string from 1 to 31 characters long.
89ac32b99cSOleksandr TymoshenkoA value is an array of zero or more bytes that encode certain
90ac32b99cSOleksandr Tymoshenkoinformation.
91ac32b99cSOleksandr TymoshenkoThe meaning of that bytes depends on how drivers interpret them.
92ac32b99cSOleksandr TymoshenkoProperties can encode byte arrays, text strings, unsigned 32-bit
93ac32b99cSOleksandr Tymoshenkovalues or any combination of these types.
94ac32b99cSOleksandr Tymoshenko.Pp
95ac32b99cSOleksandr TymoshenkoProperty with a zero-length value usually represents boolean
96ac32b99cSOleksandr Tymoshenkoinformation.
97ac32b99cSOleksandr TymoshenkoIf the property is present, it signifies true, otherwise false.
98ac32b99cSOleksandr Tymoshenko.Pp
99ac32b99cSOleksandr TymoshenkoA byte array is encoded as a sequence of bytes and represents
100ac32b99cSOleksandr Tymoshenkovalues like MAC addresses.
101ac32b99cSOleksandr Tymoshenko.Pp
102ac32b99cSOleksandr TymoshenkoA text string is a sequence of n printable characters.
103ac32b99cSOleksandr TymoshenkoIt is encoded as a byte array of length n + 1 bytes with
104ac32b99cSOleksandr Tymoshenkocharacters represented as bytes plus a terminating null character.
105ac32b99cSOleksandr Tymoshenko.Pp
106ac32b99cSOleksandr TymoshenkoUnsigned 32-bit values, also sometimes called cells, are
107ac32b99cSOleksandr Tymoshenkoencoded as a sequence of 4 bytes in big-endian order.
108ac32b99cSOleksandr Tymoshenko.Pp
109ac32b99cSOleksandr Tymoshenko.Fn OF_getproplen
110ac32b99cSOleksandr Tymoshenkoreturns either the length of the value associated with the property
111ac32b99cSOleksandr Tymoshenko.Fa propname
112ac32b99cSOleksandr Tymoshenkoin the node identified by
113ac32b99cSOleksandr Tymoshenko.Fa node ,
114ac32b99cSOleksandr Tymoshenkoor 0 if the property exists but has no associated value.
115ac32b99cSOleksandr TymoshenkoIf
116ac32b99cSOleksandr Tymoshenko.Fa propname
117ac32b99cSOleksandr Tymoshenkodoes not exist, -1 is returned.
118ac32b99cSOleksandr Tymoshenko.Pp
119ac32b99cSOleksandr Tymoshenko.Fn OF_getprop
120ac32b99cSOleksandr Tymoshenkocopies a maximum of
121ac32b99cSOleksandr Tymoshenko.Fa len
122ac32b99cSOleksandr Tymoshenkobytes from the value associated with the property
123ac32b99cSOleksandr Tymoshenko.Fa propname
124ac32b99cSOleksandr Tymoshenkoof the device node
125ac32b99cSOleksandr Tymoshenko.Fa node
126ac32b99cSOleksandr Tymoshenkointo the memory specified by
127ac32b99cSOleksandr Tymoshenko.Fa buf .
128ac32b99cSOleksandr TymoshenkoReturns the actual size of the value or -1 if the
129ac32b99cSOleksandr Tymoshenkoproperty does not exist.
130ac32b99cSOleksandr Tymoshenko.Pp
131ac32b99cSOleksandr Tymoshenko.Fn OF_getencprop
132ac32b99cSOleksandr Tymoshenkocopies a maximum of
133ac32b99cSOleksandr Tymoshenko.Fa len
134ac32b99cSOleksandr Tymoshenkobytes into memory specified by
135ac32b99cSOleksandr Tymoshenko.Fa buf ,
136ac32b99cSOleksandr Tymoshenkothen converts cell values from big-endian to host byte order.
137ac32b99cSOleksandr TymoshenkoReturns the actual size of the value in bytes, or -1
138ac32b99cSOleksandr Tymoshenkoif the property does not exist.
139ac32b99cSOleksandr Tymoshenko.Fa len
140ac32b99cSOleksandr Tymoshenkomust be a multiple of 4.
141ac32b99cSOleksandr Tymoshenko.Pp
142ac32b99cSOleksandr Tymoshenko.Fn OF_hasprop
143ac32b99cSOleksandr Tymoshenkoreturns 1 if the device node
144ac32b99cSOleksandr Tymoshenko.Fa node
145ac32b99cSOleksandr Tymoshenkohas a property specified by
146ac32b99cSOleksandr Tymoshenko.Fa propname ,
147ac32b99cSOleksandr Tymoshenkoand zero if the property does not exist.
148ac32b99cSOleksandr Tymoshenko.Pp
149ac32b99cSOleksandr Tymoshenko.Fn OF_searchprop
150ac32b99cSOleksandr Tymoshenkorecursively looks for the property specified by
151ac32b99cSOleksandr Tymoshenko.Fa propname
152ac32b99cSOleksandr Tymoshenkostarting with the device node
153ac32b99cSOleksandr Tymoshenko.Fa node
154ac32b99cSOleksandr Tymoshenkofollowed by the parent node and up to the root node.
155ac32b99cSOleksandr TymoshenkoIf the property is found, the function copies a maximum of
156ac32b99cSOleksandr Tymoshenko.Fa len
157ac32b99cSOleksandr Tymoshenkobytes of the value associated with the property
158ac32b99cSOleksandr Tymoshenkointo the memory specified by
159ac32b99cSOleksandr Tymoshenko.Fa buf .
160ac32b99cSOleksandr TymoshenkoReturns the actual size in bytes of the value,
161ac32b99cSOleksandr Tymoshenkoor -1 if the property does not exist.
162ac32b99cSOleksandr Tymoshenko.Pp
163ac32b99cSOleksandr Tymoshenko.Fn OF_searchencprop
164ac32b99cSOleksandr Tymoshenkorecursively looks for the property specified by
165ac32b99cSOleksandr Tymoshenko.Fa propname
166ac32b99cSOleksandr Tymoshenkostarting with the device node
167ac32b99cSOleksandr Tymoshenko.Fa node
168ac32b99cSOleksandr Tymoshenkofollowed by the parent node and up to the root node.
169ac32b99cSOleksandr TymoshenkoIf the property is found, the function copies a maximum of
170ac32b99cSOleksandr Tymoshenko.Fa len
171ac32b99cSOleksandr Tymoshenkobytes of the value associated with the property
172ac32b99cSOleksandr Tymoshenkointo the memory specified by
173ac32b99cSOleksandr Tymoshenko.Fa buf ,
174ac32b99cSOleksandr Tymoshenkothen converts cell values from big-endian to host byte order.
175ac32b99cSOleksandr TymoshenkoReturns the actual size in bytes of the value,
176ac32b99cSOleksandr Tymoshenkoor -1 if the property does not exist.
177ac32b99cSOleksandr Tymoshenko.Pp
178ac32b99cSOleksandr Tymoshenko.Fn OF_getprop_alloc
179ac32b99cSOleksandr Tymoshenkoallocates memory large enough to hold the
180ac32b99cSOleksandr Tymoshenkovalue associated with the property
181ac32b99cSOleksandr Tymoshenko.Fa propname
182ac32b99cSOleksandr Tymoshenkoof the device node
183ac32b99cSOleksandr Tymoshenko.Fa node
184ac32b99cSOleksandr Tymoshenkoand copies the value into the newly allocated memory region.
185ac32b99cSOleksandr TymoshenkoReturns the actual size of the value and stores
186ac32b99cSOleksandr Tymoshenkothe address of the allocated memory in
187ac32b99cSOleksandr Tymoshenko.Fa *buf .
188ac32b99cSOleksandr TymoshenkoIf the property has a zero-sized value
189ac32b99cSOleksandr Tymoshenko.Fa *buf
190ac32b99cSOleksandr Tymoshenkois set NULL.
191ac32b99cSOleksandr TymoshenkoReturns -1 if the property does not exist or
192ac32b99cSOleksandr Tymoshenkomemory allocation failed.
193ac32b99cSOleksandr TymoshenkoAllocated memory should be released when no longer required
194ac32b99cSOleksandr Tymoshenkoby calling
195ac32b99cSOleksandr Tymoshenko.Fn OF_prop_free .
196ac32b99cSOleksandr TymoshenkoThe function might sleep when allocating memory.
197ac32b99cSOleksandr Tymoshenko.Pp
198ac32b99cSOleksandr Tymoshenko.Fn OF_getencprop_alloc
199ac32b99cSOleksandr Tymoshenkoallocates enough memory to hold the
200ac32b99cSOleksandr Tymoshenkovalue associated with the property
201ac32b99cSOleksandr Tymoshenko.Fa propname
202ac32b99cSOleksandr Tymoshenkoof the device node
203ac32b99cSOleksandr Tymoshenko.Fa node ,
204ac32b99cSOleksandr Tymoshenkocopies the value into the newly allocated memory region, and
205ac32b99cSOleksandr Tymoshenkothen converts cell values from big-endian to host byte
206ac32b99cSOleksandr Tymoshenkoorder.
207ac32b99cSOleksandr TymoshenkoThe actual size of the value is returned and the
208ac32b99cSOleksandr Tymoshenkoaddress of allocated memory is stored in
209ac32b99cSOleksandr Tymoshenko.Fa *buf .
210ac32b99cSOleksandr TymoshenkoIf the property has zero-length value,
211ac32b99cSOleksandr Tymoshenko.Fa *buf
212ac32b99cSOleksandr Tymoshenkois set to NULL.
213ac32b99cSOleksandr TymoshenkoReturns -1 if the property does not exist or
21480cb7cd4SOleksandr Tymoshenkomemory allocation failed or the size of the value is not
21580cb7cd4SOleksandr Tymoshenkodivisible by a cell size (4 bytes).
21680cb7cd4SOleksandr TymoshenkoAllocated memory should be released when no longer required
21780cb7cd4SOleksandr Tymoshenkoby calling
21880cb7cd4SOleksandr Tymoshenko.Fn OF_prop_free .
21980cb7cd4SOleksandr TymoshenkoThe function might sleep when allocating memory.
22080cb7cd4SOleksandr Tymoshenko.Pp
22180cb7cd4SOleksandr Tymoshenko.Fn OF_getprop_alloc_multi
22280cb7cd4SOleksandr Tymoshenkoallocates memory large enough to hold the
22380cb7cd4SOleksandr Tymoshenkovalue associated with the property
22480cb7cd4SOleksandr Tymoshenko.Fa propname
22580cb7cd4SOleksandr Tymoshenkoof the device node
22680cb7cd4SOleksandr Tymoshenko.Fa node
22780cb7cd4SOleksandr Tymoshenkoand copies the value into the newly allocated memory region.
22880cb7cd4SOleksandr TymoshenkoThe value is expected to be an array of zero or more elements
22980cb7cd4SOleksandr Tymoshenko.Fa elsz
23080cb7cd4SOleksandr Tymoshenkobytes long.
23180cb7cd4SOleksandr TymoshenkoReturns the number of elements in the value and stores
23280cb7cd4SOleksandr Tymoshenkothe address of the allocated memory in
23380cb7cd4SOleksandr Tymoshenko.Fa *buf .
23480cb7cd4SOleksandr TymoshenkoIf the property has a zero-sized value
23580cb7cd4SOleksandr Tymoshenko.Fa *buf
23680cb7cd4SOleksandr Tymoshenkois set NULL.
23780cb7cd4SOleksandr TymoshenkoReturns -1 if the property does not exist or
23880cb7cd4SOleksandr Tymoshenkomemory allocation failed or the size of the value is not
23980cb7cd4SOleksandr Tymoshenkodivisible by
24080cb7cd4SOleksandr Tymoshenko.Fa elsz .
24180cb7cd4SOleksandr TymoshenkoAllocated memory should be released when no longer required
24280cb7cd4SOleksandr Tymoshenkoby calling
24380cb7cd4SOleksandr Tymoshenko.Fn OF_prop_free .
24480cb7cd4SOleksandr TymoshenkoThe function might sleep when allocating memory.
24580cb7cd4SOleksandr Tymoshenko.Pp
24680cb7cd4SOleksandr Tymoshenko.Fn OF_getencprop_alloc_multi
24780cb7cd4SOleksandr Tymoshenkoallocates memory large enough to hold the
24880cb7cd4SOleksandr Tymoshenkovalue associated with the property
24980cb7cd4SOleksandr Tymoshenko.Fa propname
25080cb7cd4SOleksandr Tymoshenkoof the device node
25180cb7cd4SOleksandr Tymoshenko.Fa node
25280cb7cd4SOleksandr Tymoshenkoand copies the value into the newly allocated memory region, and
25380cb7cd4SOleksandr Tymoshenkothen converts cell values from big-endian to host byte
25480cb7cd4SOleksandr Tymoshenkoorder.
25580cb7cd4SOleksandr TymoshenkoThe value is expected to be an array of zero or more elements
25680cb7cd4SOleksandr Tymoshenko.Fa elsz
25780cb7cd4SOleksandr Tymoshenkobytes long.
25880cb7cd4SOleksandr TymoshenkoReturns the number of elements in the value and stores
25980cb7cd4SOleksandr Tymoshenkothe address of the allocated memory in
26080cb7cd4SOleksandr Tymoshenko.Fa *buf .
26180cb7cd4SOleksandr TymoshenkoIf the property has a zero-sized value
26280cb7cd4SOleksandr Tymoshenko.Fa *buf
26380cb7cd4SOleksandr Tymoshenkois set NULL.
26480cb7cd4SOleksandr TymoshenkoReturns -1 if the property does not exist or
26580cb7cd4SOleksandr Tymoshenkomemory allocation failed or the size of the value is not
26680cb7cd4SOleksandr Tymoshenkodivisible by
26780cb7cd4SOleksandr Tymoshenko.Fa elsz .
268ac32b99cSOleksandr TymoshenkoAllocated memory should be released when no longer required
269ac32b99cSOleksandr Tymoshenkoby calling
270ac32b99cSOleksandr Tymoshenko.Fn OF_prop_free .
271ac32b99cSOleksandr TymoshenkoThe function might sleep when allocating memory.
272ac32b99cSOleksandr Tymoshenko.Pp
273ac32b99cSOleksandr Tymoshenko.Fn OF_prop_free
274ac32b99cSOleksandr Tymoshenkoreleases memory at
275ac32b99cSOleksandr Tymoshenko.Fa buf
276ac32b99cSOleksandr Tymoshenkothat was allocated by
27780cb7cd4SOleksandr Tymoshenko.Fn OF_getprop_alloc ,
27880cb7cd4SOleksandr Tymoshenko.Fn OF_getencprop_alloc ,
27980cb7cd4SOleksandr Tymoshenko.Fn OF_getprop_alloc_multi ,
28080cb7cd4SOleksandr Tymoshenko.Fn OF_getencprop_alloc_multi .
281ac32b99cSOleksandr Tymoshenko.Pp
282ac32b99cSOleksandr Tymoshenko.Fn OF_nextprop
283ac32b99cSOleksandr Tymoshenkocopies a maximum of
284ac32b99cSOleksandr Tymoshenko.Fa size
285ac32b99cSOleksandr Tymoshenkobytes of the name of the property following the
286ac32b99cSOleksandr Tymoshenko.Fa propname
287ac32b99cSOleksandr Tymoshenkoproperty into
288ac32b99cSOleksandr Tymoshenko.Fa buf .
289ac32b99cSOleksandr TymoshenkoIf
290ac32b99cSOleksandr Tymoshenko.Fa propname
291ac32b99cSOleksandr Tymoshenkois NULL, the function copies the name of the first property of the
292ac32b99cSOleksandr Tymoshenkodevice node
293ac32b99cSOleksandr Tymoshenko.Fa node .
294ac32b99cSOleksandr Tymoshenko.Fn OF_nextprop
295ac32b99cSOleksandr Tymoshenkoreturns -1 if
296ac32b99cSOleksandr Tymoshenko.Fa propname
297ac32b99cSOleksandr Tymoshenkois invalid or there is an internal error, 0 if there are no more
298ac32b99cSOleksandr Tymoshenkoproperties after
299ac32b99cSOleksandr Tymoshenko.Fa propname ,
300ac32b99cSOleksandr Tymoshenkoor 1 otherwise.
301ac32b99cSOleksandr Tymoshenko.Pp
302ac32b99cSOleksandr Tymoshenko.Fn OF_setprop
303ac32b99cSOleksandr Tymoshenkosets the value of the property
304ac32b99cSOleksandr Tymoshenko.Fa propname
305ac32b99cSOleksandr Tymoshenkoin the device node
306ac32b99cSOleksandr Tymoshenko.Fa node
307ac32b99cSOleksandr Tymoshenkoto the value beginning at the address specified by
308ac32b99cSOleksandr Tymoshenko.Fa buf
309ac32b99cSOleksandr Tymoshenkoand running for
310ac32b99cSOleksandr Tymoshenko.Fa len
311ac32b99cSOleksandr Tymoshenkobytes.
312ac32b99cSOleksandr TymoshenkoIf the property does not exist, the function tries to create
313ac32b99cSOleksandr Tymoshenkoit.
314ac32b99cSOleksandr Tymoshenko.Fn OF_setprop
315ac32b99cSOleksandr Tymoshenkoreturns the actual size of the new value, or -1 if the
316ac32b99cSOleksandr Tymoshenkoproperty value cannot be changed or the new property
317ac32b99cSOleksandr Tymoshenkocannot be created.
318ac32b99cSOleksandr Tymoshenko.Sh EXAMPLES
319ac32b99cSOleksandr Tymoshenko.Bd -literal
320ac32b99cSOleksandr Tymoshenko    phandle_t node;
321ac32b99cSOleksandr Tymoshenko    phandle_t hdmixref, hdminode;
322ac32b99cSOleksandr Tymoshenko    device_t hdmi;
323ac32b99cSOleksandr Tymoshenko    uint8_t mac[6];
324ac32b99cSOleksandr Tymoshenko    char *model;
325ac32b99cSOleksandr Tymoshenko
326ac32b99cSOleksandr Tymoshenko    /*
327ac32b99cSOleksandr Tymoshenko     * Get a byte array property
328ac32b99cSOleksandr Tymoshenko     */
329ac32b99cSOleksandr Tymoshenko    if (OF_getprop(node, "eth,hwaddr", mac, sizeof(mac)) != sizeof(mac))
330ac32b99cSOleksandr Tymoshenko        return;
331ac32b99cSOleksandr Tymoshenko
332ac32b99cSOleksandr Tymoshenko    /*
333ac32b99cSOleksandr Tymoshenko     * Get internal node reference and device associated with it
334ac32b99cSOleksandr Tymoshenko     */
335ac32b99cSOleksandr Tymoshenko    if (OF_getencprop(node, "hdmi", &hdmixref) <= 0)
336ac32b99cSOleksandr Tymoshenko        return;
337ac32b99cSOleksandr Tymoshenko    hdmi = OF_device_from_xref(hdmixref);
338ac32b99cSOleksandr Tymoshenko
339ac32b99cSOleksandr Tymoshenko    /*
340ac32b99cSOleksandr Tymoshenko     * Get string value of model property of HDMI framer node
341ac32b99cSOleksandr Tymoshenko     */
342ac32b99cSOleksandr Tymoshenko    hdminode = OF_node_from_xref(hdmixref);
343ac32b99cSOleksandr Tymoshenko    if (OF_getprop_alloc(hdminode, "model", (void **)&model) <= 0)
344ac32b99cSOleksandr Tymoshenko        return;
345ac32b99cSOleksandr Tymoshenko.Ed
346ac32b99cSOleksandr Tymoshenko.Sh SEE ALSO
347*32068667SChristian Brueffer.Xr OF_device_from_xref 9 ,
348ac32b99cSOleksandr Tymoshenko.Xr OF_node_from_xref 9
349ac32b99cSOleksandr Tymoshenko.Sh AUTHORS
350ac32b99cSOleksandr Tymoshenko.An -nosplit
351ac32b99cSOleksandr TymoshenkoThis manual page was written by
352ac32b99cSOleksandr Tymoshenko.An Oleksandr Tymoshenko Aq Mt gonzo@FreeBSD.org .
353