xref: /freebsd/share/man/man9/OF_getprop.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.\"
2680cb7cd4SOleksandr Tymoshenko.Dd June 23, 2018
2780cb7cd4SOleksandr Tymoshenko.Dt OF_GETPROP 9
28ac32b99cSOleksandr Tymoshenko.Os
29ac32b99cSOleksandr Tymoshenko.Sh NAME
30ac32b99cSOleksandr Tymoshenko.Nm OF_getprop ,
31ac32b99cSOleksandr Tymoshenko.Nm OF_getproplen ,
32ac32b99cSOleksandr Tymoshenko.Nm OF_getencprop ,
33ac32b99cSOleksandr Tymoshenko.Nm OF_hasprop ,
34ac32b99cSOleksandr Tymoshenko.Nm OF_searchprop ,
35ac32b99cSOleksandr Tymoshenko.Nm OF_searchencprop ,
36ac32b99cSOleksandr Tymoshenko.Nm OF_getprop_alloc ,
37ac32b99cSOleksandr Tymoshenko.Nm OF_getencprop_alloc ,
3880cb7cd4SOleksandr Tymoshenko.Nm OF_getprop_alloc_multi ,
3980cb7cd4SOleksandr Tymoshenko.Nm OF_getencprop_alloc_multi ,
40ac32b99cSOleksandr Tymoshenko.Nm OF_prop_free ,
41ac32b99cSOleksandr Tymoshenko.Nm OF_nextprop ,
42ac32b99cSOleksandr Tymoshenko.Nm OF_setprop
43ac32b99cSOleksandr Tymoshenko.Nd access properties of device tree node
44ac32b99cSOleksandr Tymoshenko.Sh SYNOPSIS
45ac32b99cSOleksandr Tymoshenko.In dev/ofw/ofw_bus.h
46ac32b99cSOleksandr Tymoshenko.In dev/ofw/ofw_bus_subr.h
47ac32b99cSOleksandr Tymoshenko.Ft ssize_t
48ac32b99cSOleksandr Tymoshenko.Fn OF_getproplen "phandle_t node" "const char *propname"
49ac32b99cSOleksandr Tymoshenko.Ft ssize_t
50ac32b99cSOleksandr Tymoshenko.Fn OF_getprop "phandle_t node" "const char *propname" \
51ac32b99cSOleksandr Tymoshenko"void *buf" "size_t len"
52ac32b99cSOleksandr Tymoshenko.Ft ssize_t
53ac32b99cSOleksandr Tymoshenko.Fn OF_getencprop "phandle_t node" "const char *prop" \
54ac32b99cSOleksandr Tymoshenko"pcell_t *buf" "size_t len"
55ac32b99cSOleksandr Tymoshenko.Ft int
56ac32b99cSOleksandr Tymoshenko.Fn OF_hasprop "phandle_t node" "const char *propname"
57ac32b99cSOleksandr Tymoshenko.Ft ssize_t
58ac32b99cSOleksandr Tymoshenko.Fn OF_searchprop "phandle_t node" "const char *propname" \
59ac32b99cSOleksandr Tymoshenko"void *buf" "size_t len"
60ac32b99cSOleksandr Tymoshenko.Ft ssize_t
61ac32b99cSOleksandr Tymoshenko.Fn OF_searchencprop "phandle_t node" "const char *propname" \
62ac32b99cSOleksandr Tymoshenko"pcell_t *buf" "size_t len"
63ac32b99cSOleksandr Tymoshenko.Ft ssize_t
64ac32b99cSOleksandr Tymoshenko.Fn OF_getprop_alloc "phandle_t node" "const char *propname" \
65ac32b99cSOleksandr Tymoshenko"void **buf"
66ac32b99cSOleksandr Tymoshenko.Ft ssize_t
67ac32b99cSOleksandr Tymoshenko.Fn OF_getencprop_alloc "phandle_t node" "const char *propname" \
68ac32b99cSOleksandr Tymoshenko"pcell_t **buf"
6980cb7cd4SOleksandr Tymoshenko.Ft ssize_t
7080cb7cd4SOleksandr Tymoshenko.Fn OF_getprop_alloc_multi "phandle_t node" "const char *propname" \
7180cb7cd4SOleksandr Tymoshenko"int elsz" "void **buf"
7280cb7cd4SOleksandr Tymoshenko.Ft ssize_t
7380cb7cd4SOleksandr Tymoshenko.Fn OF_getencprop_alloc_multi "phandle_t node" "const char *propname" \
7480cb7cd4SOleksandr Tymoshenko"int elsz" "pcell_t **buf"
75ac32b99cSOleksandr Tymoshenko.Ft void
76ac32b99cSOleksandr Tymoshenko.Fn OF_prop_free "void *buf"
77ac32b99cSOleksandr Tymoshenko.Ft int
78ac32b99cSOleksandr Tymoshenko.Fn OF_nextprop "phandle_t node" "const char *propname" \
79ac32b99cSOleksandr Tymoshenko"char *buf" "size_t len"
80ac32b99cSOleksandr Tymoshenko.Ft int
81ac32b99cSOleksandr Tymoshenko.Fn OF_setprop "phandle_t node" "const char *propname" \
82ac32b99cSOleksandr Tymoshenko"const void *buf" "size_t len"
83ac32b99cSOleksandr Tymoshenko.Sh DESCRIPTION
84ac32b99cSOleksandr TymoshenkoDevice nodes can have associated properties.
85ac32b99cSOleksandr TymoshenkoProperties consist of a name and a value.
86ac32b99cSOleksandr TymoshenkoA name is a human-readable string from 1 to 31 characters long.
87ac32b99cSOleksandr TymoshenkoA value is an array of zero or more bytes that encode certain
88ac32b99cSOleksandr Tymoshenkoinformation.
89ac32b99cSOleksandr TymoshenkoThe meaning of that bytes depends on how drivers interpret them.
90ac32b99cSOleksandr TymoshenkoProperties can encode byte arrays, text strings, unsigned 32-bit
91ac32b99cSOleksandr Tymoshenkovalues or any combination of these types.
92ac32b99cSOleksandr Tymoshenko.Pp
93ac32b99cSOleksandr TymoshenkoProperty with a zero-length value usually represents boolean
94ac32b99cSOleksandr Tymoshenkoinformation.
95ac32b99cSOleksandr TymoshenkoIf the property is present, it signifies true, otherwise false.
96ac32b99cSOleksandr Tymoshenko.Pp
97ac32b99cSOleksandr TymoshenkoA byte array is encoded as a sequence of bytes and represents
98ac32b99cSOleksandr Tymoshenkovalues like MAC addresses.
99ac32b99cSOleksandr Tymoshenko.Pp
100ac32b99cSOleksandr TymoshenkoA text string is a sequence of n printable characters.
101ac32b99cSOleksandr TymoshenkoIt is encoded as a byte array of length n + 1 bytes with
102ac32b99cSOleksandr Tymoshenkocharacters represented as bytes plus a terminating null character.
103ac32b99cSOleksandr Tymoshenko.Pp
104ac32b99cSOleksandr TymoshenkoUnsigned 32-bit values, also sometimes called cells, are
105ac32b99cSOleksandr Tymoshenkoencoded as a sequence of 4 bytes in big-endian order.
106ac32b99cSOleksandr Tymoshenko.Pp
107ac32b99cSOleksandr Tymoshenko.Fn OF_getproplen
108ac32b99cSOleksandr Tymoshenkoreturns either the length of the value associated with the property
109ac32b99cSOleksandr Tymoshenko.Fa propname
110ac32b99cSOleksandr Tymoshenkoin the node identified by
111ac32b99cSOleksandr Tymoshenko.Fa node ,
112ac32b99cSOleksandr Tymoshenkoor 0 if the property exists but has no associated value.
113ac32b99cSOleksandr TymoshenkoIf
114ac32b99cSOleksandr Tymoshenko.Fa propname
115ac32b99cSOleksandr Tymoshenkodoes not exist, -1 is returned.
116ac32b99cSOleksandr Tymoshenko.Pp
117ac32b99cSOleksandr Tymoshenko.Fn OF_getprop
118ac32b99cSOleksandr Tymoshenkocopies a maximum of
119ac32b99cSOleksandr Tymoshenko.Fa len
120ac32b99cSOleksandr Tymoshenkobytes from the value associated with the property
121ac32b99cSOleksandr Tymoshenko.Fa propname
122ac32b99cSOleksandr Tymoshenkoof the device node
123ac32b99cSOleksandr Tymoshenko.Fa node
124ac32b99cSOleksandr Tymoshenkointo the memory specified by
125ac32b99cSOleksandr Tymoshenko.Fa buf .
126ac32b99cSOleksandr TymoshenkoReturns the actual size of the value or -1 if the
127ac32b99cSOleksandr Tymoshenkoproperty does not exist.
128ac32b99cSOleksandr Tymoshenko.Pp
129ac32b99cSOleksandr Tymoshenko.Fn OF_getencprop
130ac32b99cSOleksandr Tymoshenkocopies a maximum of
131ac32b99cSOleksandr Tymoshenko.Fa len
132ac32b99cSOleksandr Tymoshenkobytes into memory specified by
133ac32b99cSOleksandr Tymoshenko.Fa buf ,
134ac32b99cSOleksandr Tymoshenkothen converts cell values from big-endian to host byte order.
135ac32b99cSOleksandr TymoshenkoReturns the actual size of the value in bytes, or -1
136ac32b99cSOleksandr Tymoshenkoif the property does not exist.
137ac32b99cSOleksandr Tymoshenko.Fa len
138ac32b99cSOleksandr Tymoshenkomust be a multiple of 4.
139ac32b99cSOleksandr Tymoshenko.Pp
140ac32b99cSOleksandr Tymoshenko.Fn OF_hasprop
141ac32b99cSOleksandr Tymoshenkoreturns 1 if the device node
142ac32b99cSOleksandr Tymoshenko.Fa node
143ac32b99cSOleksandr Tymoshenkohas a property specified by
144ac32b99cSOleksandr Tymoshenko.Fa propname ,
145ac32b99cSOleksandr Tymoshenkoand zero if the property does not exist.
146ac32b99cSOleksandr Tymoshenko.Pp
147ac32b99cSOleksandr Tymoshenko.Fn OF_searchprop
148ac32b99cSOleksandr Tymoshenkorecursively looks for the property specified by
149ac32b99cSOleksandr Tymoshenko.Fa propname
150ac32b99cSOleksandr Tymoshenkostarting with the device node
151ac32b99cSOleksandr Tymoshenko.Fa node
152ac32b99cSOleksandr Tymoshenkofollowed by the parent node and up to the root node.
153ac32b99cSOleksandr TymoshenkoIf the property is found, the function copies a maximum of
154ac32b99cSOleksandr Tymoshenko.Fa len
155ac32b99cSOleksandr Tymoshenkobytes of the value associated with the property
156ac32b99cSOleksandr Tymoshenkointo the memory specified by
157ac32b99cSOleksandr Tymoshenko.Fa buf .
158ac32b99cSOleksandr TymoshenkoReturns the actual size in bytes of the value,
159ac32b99cSOleksandr Tymoshenkoor -1 if the property does not exist.
160ac32b99cSOleksandr Tymoshenko.Pp
161ac32b99cSOleksandr Tymoshenko.Fn OF_searchencprop
162ac32b99cSOleksandr Tymoshenkorecursively looks for the property specified by
163ac32b99cSOleksandr Tymoshenko.Fa propname
164ac32b99cSOleksandr Tymoshenkostarting with the device node
165ac32b99cSOleksandr Tymoshenko.Fa node
166ac32b99cSOleksandr Tymoshenkofollowed by the parent node and up to the root node.
167ac32b99cSOleksandr TymoshenkoIf the property is found, the function copies a maximum of
168ac32b99cSOleksandr Tymoshenko.Fa len
169ac32b99cSOleksandr Tymoshenkobytes of the value associated with the property
170ac32b99cSOleksandr Tymoshenkointo the memory specified by
171ac32b99cSOleksandr Tymoshenko.Fa buf ,
172ac32b99cSOleksandr Tymoshenkothen converts cell values from big-endian to host byte order.
173ac32b99cSOleksandr TymoshenkoReturns the actual size in bytes of the value,
174ac32b99cSOleksandr Tymoshenkoor -1 if the property does not exist.
175ac32b99cSOleksandr Tymoshenko.Pp
176ac32b99cSOleksandr Tymoshenko.Fn OF_getprop_alloc
177ac32b99cSOleksandr Tymoshenkoallocates memory large enough to hold the
178ac32b99cSOleksandr Tymoshenkovalue associated with the property
179ac32b99cSOleksandr Tymoshenko.Fa propname
180ac32b99cSOleksandr Tymoshenkoof the device node
181ac32b99cSOleksandr Tymoshenko.Fa node
182ac32b99cSOleksandr Tymoshenkoand copies the value into the newly allocated memory region.
183ac32b99cSOleksandr TymoshenkoReturns the actual size of the value and stores
184ac32b99cSOleksandr Tymoshenkothe address of the allocated memory in
185ac32b99cSOleksandr Tymoshenko.Fa *buf .
186ac32b99cSOleksandr TymoshenkoIf the property has a zero-sized value
187ac32b99cSOleksandr Tymoshenko.Fa *buf
188ac32b99cSOleksandr Tymoshenkois set NULL.
189ac32b99cSOleksandr TymoshenkoReturns -1 if the property does not exist or
190ac32b99cSOleksandr Tymoshenkomemory allocation failed.
191ac32b99cSOleksandr TymoshenkoAllocated memory should be released when no longer required
192ac32b99cSOleksandr Tymoshenkoby calling
193ac32b99cSOleksandr Tymoshenko.Fn OF_prop_free .
194ac32b99cSOleksandr TymoshenkoThe function might sleep when allocating memory.
195ac32b99cSOleksandr Tymoshenko.Pp
196ac32b99cSOleksandr Tymoshenko.Fn OF_getencprop_alloc
197ac32b99cSOleksandr Tymoshenkoallocates enough memory to hold the
198ac32b99cSOleksandr Tymoshenkovalue associated with the property
199ac32b99cSOleksandr Tymoshenko.Fa propname
200ac32b99cSOleksandr Tymoshenkoof the device node
201ac32b99cSOleksandr Tymoshenko.Fa node ,
202ac32b99cSOleksandr Tymoshenkocopies the value into the newly allocated memory region, and
203ac32b99cSOleksandr Tymoshenkothen converts cell values from big-endian to host byte
204ac32b99cSOleksandr Tymoshenkoorder.
205ac32b99cSOleksandr TymoshenkoThe actual size of the value is returned and the
206ac32b99cSOleksandr Tymoshenkoaddress of allocated memory is stored in
207ac32b99cSOleksandr Tymoshenko.Fa *buf .
208ac32b99cSOleksandr TymoshenkoIf the property has zero-length value,
209ac32b99cSOleksandr Tymoshenko.Fa *buf
210ac32b99cSOleksandr Tymoshenkois set to NULL.
211ac32b99cSOleksandr TymoshenkoReturns -1 if the property does not exist or
21280cb7cd4SOleksandr Tymoshenkomemory allocation failed or the size of the value is not
21380cb7cd4SOleksandr Tymoshenkodivisible by a cell size (4 bytes).
21480cb7cd4SOleksandr TymoshenkoAllocated memory should be released when no longer required
21580cb7cd4SOleksandr Tymoshenkoby calling
21680cb7cd4SOleksandr Tymoshenko.Fn OF_prop_free .
21780cb7cd4SOleksandr TymoshenkoThe function might sleep when allocating memory.
21880cb7cd4SOleksandr Tymoshenko.Pp
21980cb7cd4SOleksandr Tymoshenko.Fn OF_getprop_alloc_multi
22080cb7cd4SOleksandr Tymoshenkoallocates memory large enough to hold the
22180cb7cd4SOleksandr Tymoshenkovalue associated with the property
22280cb7cd4SOleksandr Tymoshenko.Fa propname
22380cb7cd4SOleksandr Tymoshenkoof the device node
22480cb7cd4SOleksandr Tymoshenko.Fa node
22580cb7cd4SOleksandr Tymoshenkoand copies the value into the newly allocated memory region.
22680cb7cd4SOleksandr TymoshenkoThe value is expected to be an array of zero or more elements
22780cb7cd4SOleksandr Tymoshenko.Fa elsz
22880cb7cd4SOleksandr Tymoshenkobytes long.
22980cb7cd4SOleksandr TymoshenkoReturns the number of elements in the value and stores
23080cb7cd4SOleksandr Tymoshenkothe address of the allocated memory in
23180cb7cd4SOleksandr Tymoshenko.Fa *buf .
23280cb7cd4SOleksandr TymoshenkoIf the property has a zero-sized value
23380cb7cd4SOleksandr Tymoshenko.Fa *buf
23480cb7cd4SOleksandr Tymoshenkois set NULL.
23580cb7cd4SOleksandr TymoshenkoReturns -1 if the property does not exist or
23680cb7cd4SOleksandr Tymoshenkomemory allocation failed or the size of the value is not
23780cb7cd4SOleksandr Tymoshenkodivisible by
23880cb7cd4SOleksandr Tymoshenko.Fa elsz .
23980cb7cd4SOleksandr TymoshenkoAllocated memory should be released when no longer required
24080cb7cd4SOleksandr Tymoshenkoby calling
24180cb7cd4SOleksandr Tymoshenko.Fn OF_prop_free .
24280cb7cd4SOleksandr TymoshenkoThe function might sleep when allocating memory.
24380cb7cd4SOleksandr Tymoshenko.Pp
24480cb7cd4SOleksandr Tymoshenko.Fn OF_getencprop_alloc_multi
24580cb7cd4SOleksandr Tymoshenkoallocates memory large enough to hold the
24680cb7cd4SOleksandr Tymoshenkovalue associated with the property
24780cb7cd4SOleksandr Tymoshenko.Fa propname
24880cb7cd4SOleksandr Tymoshenkoof the device node
24980cb7cd4SOleksandr Tymoshenko.Fa node
25080cb7cd4SOleksandr Tymoshenkoand copies the value into the newly allocated memory region, and
25180cb7cd4SOleksandr Tymoshenkothen converts cell values from big-endian to host byte
25280cb7cd4SOleksandr Tymoshenkoorder.
25380cb7cd4SOleksandr TymoshenkoThe value is expected to be an array of zero or more elements
25480cb7cd4SOleksandr Tymoshenko.Fa elsz
25580cb7cd4SOleksandr Tymoshenkobytes long.
25680cb7cd4SOleksandr TymoshenkoReturns the number of elements in the value and stores
25780cb7cd4SOleksandr Tymoshenkothe address of the allocated memory in
25880cb7cd4SOleksandr Tymoshenko.Fa *buf .
25980cb7cd4SOleksandr TymoshenkoIf the property has a zero-sized value
26080cb7cd4SOleksandr Tymoshenko.Fa *buf
26180cb7cd4SOleksandr Tymoshenkois set NULL.
26280cb7cd4SOleksandr TymoshenkoReturns -1 if the property does not exist or
26380cb7cd4SOleksandr Tymoshenkomemory allocation failed or the size of the value is not
26480cb7cd4SOleksandr Tymoshenkodivisible by
26580cb7cd4SOleksandr Tymoshenko.Fa elsz .
266ac32b99cSOleksandr TymoshenkoAllocated memory should be released when no longer required
267ac32b99cSOleksandr Tymoshenkoby calling
268ac32b99cSOleksandr Tymoshenko.Fn OF_prop_free .
269ac32b99cSOleksandr TymoshenkoThe function might sleep when allocating memory.
270ac32b99cSOleksandr Tymoshenko.Pp
271ac32b99cSOleksandr Tymoshenko.Fn OF_prop_free
272ac32b99cSOleksandr Tymoshenkoreleases memory at
273ac32b99cSOleksandr Tymoshenko.Fa buf
274ac32b99cSOleksandr Tymoshenkothat was allocated by
27580cb7cd4SOleksandr Tymoshenko.Fn OF_getprop_alloc ,
27680cb7cd4SOleksandr Tymoshenko.Fn OF_getencprop_alloc ,
27780cb7cd4SOleksandr Tymoshenko.Fn OF_getprop_alloc_multi ,
27880cb7cd4SOleksandr Tymoshenko.Fn OF_getencprop_alloc_multi .
279ac32b99cSOleksandr Tymoshenko.Pp
280ac32b99cSOleksandr Tymoshenko.Fn OF_nextprop
281ac32b99cSOleksandr Tymoshenkocopies a maximum of
282ac32b99cSOleksandr Tymoshenko.Fa size
283ac32b99cSOleksandr Tymoshenkobytes of the name of the property following the
284ac32b99cSOleksandr Tymoshenko.Fa propname
285ac32b99cSOleksandr Tymoshenkoproperty into
286ac32b99cSOleksandr Tymoshenko.Fa buf .
287ac32b99cSOleksandr TymoshenkoIf
288ac32b99cSOleksandr Tymoshenko.Fa propname
289ac32b99cSOleksandr Tymoshenkois NULL, the function copies the name of the first property of the
290ac32b99cSOleksandr Tymoshenkodevice node
291ac32b99cSOleksandr Tymoshenko.Fa node .
292ac32b99cSOleksandr Tymoshenko.Fn OF_nextprop
293ac32b99cSOleksandr Tymoshenkoreturns -1 if
294ac32b99cSOleksandr Tymoshenko.Fa propname
295ac32b99cSOleksandr Tymoshenkois invalid or there is an internal error, 0 if there are no more
296ac32b99cSOleksandr Tymoshenkoproperties after
297ac32b99cSOleksandr Tymoshenko.Fa propname ,
298ac32b99cSOleksandr Tymoshenkoor 1 otherwise.
299ac32b99cSOleksandr Tymoshenko.Pp
300ac32b99cSOleksandr Tymoshenko.Fn OF_setprop
301ac32b99cSOleksandr Tymoshenkosets the value of the property
302ac32b99cSOleksandr Tymoshenko.Fa propname
303ac32b99cSOleksandr Tymoshenkoin the device node
304ac32b99cSOleksandr Tymoshenko.Fa node
305ac32b99cSOleksandr Tymoshenkoto the value beginning at the address specified by
306ac32b99cSOleksandr Tymoshenko.Fa buf
307ac32b99cSOleksandr Tymoshenkoand running for
308ac32b99cSOleksandr Tymoshenko.Fa len
309ac32b99cSOleksandr Tymoshenkobytes.
310ac32b99cSOleksandr TymoshenkoIf the property does not exist, the function tries to create
311ac32b99cSOleksandr Tymoshenkoit.
312ac32b99cSOleksandr Tymoshenko.Fn OF_setprop
313ac32b99cSOleksandr Tymoshenkoreturns the actual size of the new value, or -1 if the
314ac32b99cSOleksandr Tymoshenkoproperty value cannot be changed or the new property
315ac32b99cSOleksandr Tymoshenkocannot be created.
316ac32b99cSOleksandr Tymoshenko.Sh EXAMPLES
317ac32b99cSOleksandr Tymoshenko.Bd -literal
318ac32b99cSOleksandr Tymoshenko    phandle_t node;
319ac32b99cSOleksandr Tymoshenko    phandle_t hdmixref, hdminode;
320ac32b99cSOleksandr Tymoshenko    device_t hdmi;
321ac32b99cSOleksandr Tymoshenko    uint8_t mac[6];
322ac32b99cSOleksandr Tymoshenko    char *model;
323ac32b99cSOleksandr Tymoshenko
324ac32b99cSOleksandr Tymoshenko    /*
325ac32b99cSOleksandr Tymoshenko     * Get a byte array property
326ac32b99cSOleksandr Tymoshenko     */
327ac32b99cSOleksandr Tymoshenko    if (OF_getprop(node, "eth,hwaddr", mac, sizeof(mac)) != sizeof(mac))
328ac32b99cSOleksandr Tymoshenko        return;
329ac32b99cSOleksandr Tymoshenko
330ac32b99cSOleksandr Tymoshenko    /*
331ac32b99cSOleksandr Tymoshenko     * Get internal node reference and device associated with it
332ac32b99cSOleksandr Tymoshenko     */
333ac32b99cSOleksandr Tymoshenko    if (OF_getencprop(node, "hdmi", &hdmixref) <= 0)
334ac32b99cSOleksandr Tymoshenko        return;
335ac32b99cSOleksandr Tymoshenko    hdmi = OF_device_from_xref(hdmixref);
336ac32b99cSOleksandr Tymoshenko
337ac32b99cSOleksandr Tymoshenko    /*
338ac32b99cSOleksandr Tymoshenko     * Get string value of model property of HDMI framer node
339ac32b99cSOleksandr Tymoshenko     */
340ac32b99cSOleksandr Tymoshenko    hdminode = OF_node_from_xref(hdmixref);
341ac32b99cSOleksandr Tymoshenko    if (OF_getprop_alloc(hdminode, "model", (void **)&model) <= 0)
342ac32b99cSOleksandr Tymoshenko        return;
343ac32b99cSOleksandr Tymoshenko.Ed
344ac32b99cSOleksandr Tymoshenko.Sh SEE ALSO
345*32068667SChristian Brueffer.Xr OF_device_from_xref 9 ,
346ac32b99cSOleksandr Tymoshenko.Xr OF_node_from_xref 9
347ac32b99cSOleksandr Tymoshenko.Sh AUTHORS
348ac32b99cSOleksandr Tymoshenko.An -nosplit
349ac32b99cSOleksandr TymoshenkoThis manual page was written by
350ac32b99cSOleksandr Tymoshenko.An Oleksandr Tymoshenko Aq Mt gonzo@FreeBSD.org .
351