1 | #ifndef _LIBFDT_H
|
---|
2 | #define _LIBFDT_H
|
---|
3 |
|
---|
4 | /*
|
---|
5 | * libfdt - Flat Device Tree manipulation
|
---|
6 | * Copyright (C) 2006 David Gibson, IBM Corporation.
|
---|
7 | *
|
---|
8 | * libfdt is dual licensed: you can use it either under the terms of
|
---|
9 | * the GPL, or the BSD license, at your option.
|
---|
10 | *
|
---|
11 | * a) This library is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License as
|
---|
13 | * published by the Free Software Foundation; either version 2 of the
|
---|
14 | * License, or (at your option) any later version.
|
---|
15 | *
|
---|
16 | * This library is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public
|
---|
22 | * License along with this library; if not, write to the Free
|
---|
23 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
---|
24 | * MA 02110-1301 USA
|
---|
25 | *
|
---|
26 | * Alternatively,
|
---|
27 | *
|
---|
28 | * b) Redistribution and use in source and binary forms, with or
|
---|
29 | * without modification, are permitted provided that the following
|
---|
30 | * conditions are met:
|
---|
31 | *
|
---|
32 | * 1. Redistributions of source code must retain the above
|
---|
33 | * copyright notice, this list of conditions and the following
|
---|
34 | * disclaimer.
|
---|
35 | * 2. Redistributions in binary form must reproduce the above
|
---|
36 | * copyright notice, this list of conditions and the following
|
---|
37 | * disclaimer in the documentation and/or other materials
|
---|
38 | * provided with the distribution.
|
---|
39 | *
|
---|
40 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
---|
41 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
---|
42 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
---|
43 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
44 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
---|
45 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
46 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
47 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
48 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
49 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
50 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
---|
51 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
---|
52 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
53 | */
|
---|
54 |
|
---|
55 | #include <libfdt_env.h>
|
---|
56 | #include <fdt.h>
|
---|
57 |
|
---|
58 | #define FDT_FIRST_SUPPORTED_VERSION 0x10
|
---|
59 | #define FDT_LAST_SUPPORTED_VERSION 0x11
|
---|
60 |
|
---|
61 | /* Error codes: informative error codes */
|
---|
62 | #define FDT_ERR_NOTFOUND 1
|
---|
63 | /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
|
---|
64 | #define FDT_ERR_EXISTS 2
|
---|
65 |
|
---|
66 | /* FDT_ERR_EXISTS: Attempted to create a node or property which
|
---|
67 | * already exists */
|
---|
68 | #define FDT_ERR_NOSPACE 3
|
---|
69 |
|
---|
70 | /* FDT_ERR_NOSPACE: Operation needed to expand the device
|
---|
71 | * tree, but its buffer did not have sufficient space to
|
---|
72 | * contain the expanded tree. Use fdt_open_into() to move the
|
---|
73 | * device tree to a buffer with more space. */
|
---|
74 |
|
---|
75 | /* Error codes: codes for bad parameters */
|
---|
76 | #define FDT_ERR_BADOFFSET 4
|
---|
77 |
|
---|
78 | /* FDT_ERR_BADOFFSET: Function was passed a structure block
|
---|
79 | * offset which is out-of-bounds, or which points to an
|
---|
80 | * unsuitable part of the structure for the operation. */
|
---|
81 | #define FDT_ERR_BADPATH 5
|
---|
82 |
|
---|
83 | /* FDT_ERR_BADPATH: Function was passed a badly formatted path
|
---|
84 | * (e.g. missing a leading / for a function which requires an
|
---|
85 | * absolute path) */
|
---|
86 | #define FDT_ERR_BADPHANDLE 6
|
---|
87 |
|
---|
88 | /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
|
---|
89 | * This can be caused either by an invalid phandle property
|
---|
90 | * length, or the phandle value was either 0 or -1, which are
|
---|
91 | * not permitted. */
|
---|
92 | #define FDT_ERR_BADSTATE 7
|
---|
93 |
|
---|
94 | /* FDT_ERR_BADSTATE: Function was passed an incomplete device
|
---|
95 | * tree created by the sequential-write functions, which is
|
---|
96 | * not sufficiently complete for the requested operation. */
|
---|
97 |
|
---|
98 | /* Error codes: codes for bad device tree blobs */
|
---|
99 | #define FDT_ERR_TRUNCATED 8
|
---|
100 |
|
---|
101 | /* FDT_ERR_TRUNCATED: Structure block of the given device tree
|
---|
102 | * ends without an FDT_END tag. */
|
---|
103 | #define FDT_ERR_BADMAGIC 9
|
---|
104 |
|
---|
105 | /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
|
---|
106 | * device tree at all - it is missing the flattened device
|
---|
107 | * tree magic number. */
|
---|
108 | #define FDT_ERR_BADVERSION 10
|
---|
109 |
|
---|
110 | /* FDT_ERR_BADVERSION: Given device tree has a version which
|
---|
111 | * can't be handled by the requested operation. For
|
---|
112 | * read-write functions, this may mean that fdt_open_into() is
|
---|
113 | * required to convert the tree to the expected version. */
|
---|
114 | #define FDT_ERR_BADSTRUCTURE 11
|
---|
115 |
|
---|
116 | /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
|
---|
117 | * structure block or other serious error (e.g. misnested
|
---|
118 | * nodes, or subnodes preceding properties). */
|
---|
119 | #define FDT_ERR_BADLAYOUT 12
|
---|
120 |
|
---|
121 | /* FDT_ERR_BADLAYOUT: For read-write functions, the given
|
---|
122 | * device tree has it's sub-blocks in an order that the
|
---|
123 | * function can't handle (memory reserve map, then structure,
|
---|
124 | * then strings). Use fdt_open_into() to reorganize the tree
|
---|
125 | * into a form suitable for the read-write operations. */
|
---|
126 |
|
---|
127 | /* "Can't happen" error indicating a bug in libfdt */
|
---|
128 | #define FDT_ERR_INTERNAL 13
|
---|
129 |
|
---|
130 | /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
|
---|
131 | * Should never be returned, if it is, it indicates a bug in
|
---|
132 | * libfdt itself. */
|
---|
133 |
|
---|
134 | /* Errors in device tree content */
|
---|
135 | #define FDT_ERR_BADNCELLS 14
|
---|
136 |
|
---|
137 | /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
|
---|
138 | * or similar property with a bad format or value */
|
---|
139 |
|
---|
140 | #define FDT_ERR_BADVALUE 15
|
---|
141 |
|
---|
142 | /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
|
---|
143 | * value. For example: a property expected to contain a string list
|
---|
144 | * is not NUL-terminated within the length of its value. */
|
---|
145 |
|
---|
146 | #define FDT_ERR_BADOVERLAY 16
|
---|
147 |
|
---|
148 | /* FDT_ERR_BADOVERLAY: The device tree overlay, while
|
---|
149 | * correctly structured, cannot be applied due to some
|
---|
150 | * unexpected or missing value, property or node. */
|
---|
151 |
|
---|
152 | #define FDT_ERR_NOPHANDLES 17
|
---|
153 |
|
---|
154 | /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
|
---|
155 | * phandle available anymore without causing an overflow */
|
---|
156 |
|
---|
157 | #define FDT_ERR_MAX 17
|
---|
158 |
|
---|
159 | /**********************************************************************/
|
---|
160 | /* Low-level functions (you probably don't need these) */
|
---|
161 | /**********************************************************************/
|
---|
162 |
|
---|
163 | #ifndef SWIG /* This function is not useful in Python */
|
---|
164 | const void *
|
---|
165 | fdt_offset_ptr (
|
---|
166 | const void *fdt,
|
---|
167 | int offset,
|
---|
168 | unsigned int checklen
|
---|
169 | );
|
---|
170 |
|
---|
171 | #endif
|
---|
172 | static inline void *
|
---|
173 | fdt_offset_ptr_w (
|
---|
174 | void *fdt,
|
---|
175 | int offset,
|
---|
176 | int checklen
|
---|
177 | )
|
---|
178 | {
|
---|
179 | return (void *)(uintptr_t)fdt_offset_ptr (fdt, offset, checklen);
|
---|
180 | }
|
---|
181 |
|
---|
182 | uint32_t
|
---|
183 | fdt_next_tag (
|
---|
184 | const void *fdt,
|
---|
185 | int offset,
|
---|
186 | int *nextoffset
|
---|
187 | );
|
---|
188 |
|
---|
189 | /**********************************************************************/
|
---|
190 | /* Traversal functions */
|
---|
191 | /**********************************************************************/
|
---|
192 |
|
---|
193 | int
|
---|
194 | fdt_next_node (
|
---|
195 | const void *fdt,
|
---|
196 | int offset,
|
---|
197 | int *depth
|
---|
198 | );
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * fdt_first_subnode() - get offset of first direct subnode
|
---|
202 | *
|
---|
203 | * @fdt: FDT blob
|
---|
204 | * @offset: Offset of node to check
|
---|
205 | * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
|
---|
206 | */
|
---|
207 | int
|
---|
208 | fdt_first_subnode (
|
---|
209 | const void *fdt,
|
---|
210 | int offset
|
---|
211 | );
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * fdt_next_subnode() - get offset of next direct subnode
|
---|
215 | *
|
---|
216 | * After first calling fdt_first_subnode(), call this function repeatedly to
|
---|
217 | * get direct subnodes of a parent node.
|
---|
218 | *
|
---|
219 | * @fdt: FDT blob
|
---|
220 | * @offset: Offset of previous subnode
|
---|
221 | * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
|
---|
222 | * subnodes
|
---|
223 | */
|
---|
224 | int
|
---|
225 | fdt_next_subnode (
|
---|
226 | const void *fdt,
|
---|
227 | int offset
|
---|
228 | );
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * fdt_for_each_subnode - iterate over all subnodes of a parent
|
---|
232 | *
|
---|
233 | * @node: child node (int, lvalue)
|
---|
234 | * @fdt: FDT blob (const void *)
|
---|
235 | * @parent: parent node (int)
|
---|
236 | *
|
---|
237 | * This is actually a wrapper around a for loop and would be used like so:
|
---|
238 | *
|
---|
239 | * fdt_for_each_subnode(node, fdt, parent) {
|
---|
240 | * Use node
|
---|
241 | * ...
|
---|
242 | * }
|
---|
243 | *
|
---|
244 | * if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) {
|
---|
245 | * Error handling
|
---|
246 | * }
|
---|
247 | *
|
---|
248 | * Note that this is implemented as a macro and @node is used as
|
---|
249 | * iterator in the loop. The parent variable be constant or even a
|
---|
250 | * literal.
|
---|
251 | *
|
---|
252 | */
|
---|
253 | #define fdt_for_each_subnode(node, fdt, parent) \
|
---|
254 | for (node = fdt_first_subnode(fdt, parent); \
|
---|
255 | node >= 0; \
|
---|
256 | node = fdt_next_subnode(fdt, node))
|
---|
257 |
|
---|
258 | /**********************************************************************/
|
---|
259 | /* General functions */
|
---|
260 | /**********************************************************************/
|
---|
261 | #define fdt_get_header(fdt, field) \
|
---|
262 | (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
|
---|
263 | #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
|
---|
264 | #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
|
---|
265 | #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
|
---|
266 | #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
|
---|
267 | #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
|
---|
268 | #define fdt_version(fdt) (fdt_get_header(fdt, version))
|
---|
269 | #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
|
---|
270 | #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
|
---|
271 | #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
|
---|
272 | #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
|
---|
273 |
|
---|
274 | #define __fdt_set_hdr(name) \
|
---|
275 | static inline void fdt_set_##name(void *fdt, uint32_t val) \
|
---|
276 | { \
|
---|
277 | struct fdt_header *fdth = (struct fdt_header *)fdt; \
|
---|
278 | fdth->name = cpu_to_fdt32(val); \
|
---|
279 | }
|
---|
280 | __fdt_set_hdr (magic);
|
---|
281 | __fdt_set_hdr (totalsize);
|
---|
282 | __fdt_set_hdr (off_dt_struct);
|
---|
283 | __fdt_set_hdr (off_dt_strings);
|
---|
284 | __fdt_set_hdr (off_mem_rsvmap);
|
---|
285 | __fdt_set_hdr (version);
|
---|
286 | __fdt_set_hdr (last_comp_version);
|
---|
287 | __fdt_set_hdr (boot_cpuid_phys);
|
---|
288 | __fdt_set_hdr (size_dt_strings);
|
---|
289 | __fdt_set_hdr (size_dt_struct);
|
---|
290 | #undef __fdt_set_hdr
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * fdt_check_header - sanity check a device tree or possible device tree
|
---|
294 | * @fdt: pointer to data which might be a flattened device tree
|
---|
295 | *
|
---|
296 | * fdt_check_header() checks that the given buffer contains what
|
---|
297 | * appears to be a flattened device tree with sane information in its
|
---|
298 | * header.
|
---|
299 | *
|
---|
300 | * returns:
|
---|
301 | * 0, if the buffer appears to contain a valid device tree
|
---|
302 | * -FDT_ERR_BADMAGIC,
|
---|
303 | * -FDT_ERR_BADVERSION,
|
---|
304 | * -FDT_ERR_BADSTATE, standard meanings, as above
|
---|
305 | */
|
---|
306 | int
|
---|
307 | fdt_check_header (
|
---|
308 | const void *fdt
|
---|
309 | );
|
---|
310 |
|
---|
311 | /**
|
---|
312 | * fdt_move - move a device tree around in memory
|
---|
313 | * @fdt: pointer to the device tree to move
|
---|
314 | * @buf: pointer to memory where the device is to be moved
|
---|
315 | * @bufsize: size of the memory space at buf
|
---|
316 | *
|
---|
317 | * fdt_move() relocates, if possible, the device tree blob located at
|
---|
318 | * fdt to the buffer at buf of size bufsize. The buffer may overlap
|
---|
319 | * with the existing device tree blob at fdt. Therefore,
|
---|
320 | * fdt_move(fdt, fdt, fdt_totalsize(fdt))
|
---|
321 | * should always succeed.
|
---|
322 | *
|
---|
323 | * returns:
|
---|
324 | * 0, on success
|
---|
325 | * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
|
---|
326 | * -FDT_ERR_BADMAGIC,
|
---|
327 | * -FDT_ERR_BADVERSION,
|
---|
328 | * -FDT_ERR_BADSTATE, standard meanings
|
---|
329 | */
|
---|
330 | int
|
---|
331 | fdt_move (
|
---|
332 | const void *fdt,
|
---|
333 | void *buf,
|
---|
334 | int bufsize
|
---|
335 | );
|
---|
336 |
|
---|
337 | /**********************************************************************/
|
---|
338 | /* Read-only functions */
|
---|
339 | /**********************************************************************/
|
---|
340 |
|
---|
341 | /**
|
---|
342 | * fdt_string - retrieve a string from the strings block of a device tree
|
---|
343 | * @fdt: pointer to the device tree blob
|
---|
344 | * @stroffset: offset of the string within the strings block (native endian)
|
---|
345 | *
|
---|
346 | * fdt_string() retrieves a pointer to a single string from the
|
---|
347 | * strings block of the device tree blob at fdt.
|
---|
348 | *
|
---|
349 | * returns:
|
---|
350 | * a pointer to the string, on success
|
---|
351 | * NULL, if stroffset is out of bounds
|
---|
352 | */
|
---|
353 | const char *
|
---|
354 | fdt_string (
|
---|
355 | const void *fdt,
|
---|
356 | int stroffset
|
---|
357 | );
|
---|
358 |
|
---|
359 | /**
|
---|
360 | * fdt_get_max_phandle - retrieves the highest phandle in a tree
|
---|
361 | * @fdt: pointer to the device tree blob
|
---|
362 | *
|
---|
363 | * fdt_get_max_phandle retrieves the highest phandle in the given
|
---|
364 | * device tree. This will ignore badly formatted phandles, or phandles
|
---|
365 | * with a value of 0 or -1.
|
---|
366 | *
|
---|
367 | * returns:
|
---|
368 | * the highest phandle on success
|
---|
369 | * 0, if no phandle was found in the device tree
|
---|
370 | * -1, if an error occurred
|
---|
371 | */
|
---|
372 | uint32_t
|
---|
373 | fdt_get_max_phandle (
|
---|
374 | const void *fdt
|
---|
375 | );
|
---|
376 |
|
---|
377 | /**
|
---|
378 | * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
|
---|
379 | * @fdt: pointer to the device tree blob
|
---|
380 | *
|
---|
381 | * Returns the number of entries in the device tree blob's memory
|
---|
382 | * reservation map. This does not include the terminating 0,0 entry
|
---|
383 | * or any other (0,0) entries reserved for expansion.
|
---|
384 | *
|
---|
385 | * returns:
|
---|
386 | * the number of entries
|
---|
387 | */
|
---|
388 | int
|
---|
389 | fdt_num_mem_rsv (
|
---|
390 | const void *fdt
|
---|
391 | );
|
---|
392 |
|
---|
393 | /**
|
---|
394 | * fdt_get_mem_rsv - retrieve one memory reserve map entry
|
---|
395 | * @fdt: pointer to the device tree blob
|
---|
396 | * @address, @size: pointers to 64-bit variables
|
---|
397 | *
|
---|
398 | * On success, *address and *size will contain the address and size of
|
---|
399 | * the n-th reserve map entry from the device tree blob, in
|
---|
400 | * native-endian format.
|
---|
401 | *
|
---|
402 | * returns:
|
---|
403 | * 0, on success
|
---|
404 | * -FDT_ERR_BADMAGIC,
|
---|
405 | * -FDT_ERR_BADVERSION,
|
---|
406 | * -FDT_ERR_BADSTATE, standard meanings
|
---|
407 | */
|
---|
408 | int
|
---|
409 | fdt_get_mem_rsv (
|
---|
410 | const void *fdt,
|
---|
411 | int n,
|
---|
412 | uint64_t *address,
|
---|
413 | uint64_t *size
|
---|
414 | );
|
---|
415 |
|
---|
416 | /**
|
---|
417 | * fdt_subnode_offset_namelen - find a subnode based on substring
|
---|
418 | * @fdt: pointer to the device tree blob
|
---|
419 | * @parentoffset: structure block offset of a node
|
---|
420 | * @name: name of the subnode to locate
|
---|
421 | * @namelen: number of characters of name to consider
|
---|
422 | *
|
---|
423 | * Identical to fdt_subnode_offset(), but only examine the first
|
---|
424 | * namelen characters of name for matching the subnode name. This is
|
---|
425 | * useful for finding subnodes based on a portion of a larger string,
|
---|
426 | * such as a full path.
|
---|
427 | */
|
---|
428 | #ifndef SWIG /* Not available in Python */
|
---|
429 | int
|
---|
430 | fdt_subnode_offset_namelen (
|
---|
431 | const void *fdt,
|
---|
432 | int parentoffset,
|
---|
433 | const char *name,
|
---|
434 | int namelen
|
---|
435 | );
|
---|
436 |
|
---|
437 | #endif
|
---|
438 |
|
---|
439 | /**
|
---|
440 | * fdt_subnode_offset - find a subnode of a given node
|
---|
441 | * @fdt: pointer to the device tree blob
|
---|
442 | * @parentoffset: structure block offset of a node
|
---|
443 | * @name: name of the subnode to locate
|
---|
444 | *
|
---|
445 | * fdt_subnode_offset() finds a subnode of the node at structure block
|
---|
446 | * offset parentoffset with the given name. name may include a unit
|
---|
447 | * address, in which case fdt_subnode_offset() will find the subnode
|
---|
448 | * with that unit address, or the unit address may be omitted, in
|
---|
449 | * which case fdt_subnode_offset() will find an arbitrary subnode
|
---|
450 | * whose name excluding unit address matches the given name.
|
---|
451 | *
|
---|
452 | * returns:
|
---|
453 | * structure block offset of the requested subnode (>=0), on success
|
---|
454 | * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
|
---|
455 | * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
|
---|
456 | * tag
|
---|
457 | * -FDT_ERR_BADMAGIC,
|
---|
458 | * -FDT_ERR_BADVERSION,
|
---|
459 | * -FDT_ERR_BADSTATE,
|
---|
460 | * -FDT_ERR_BADSTRUCTURE,
|
---|
461 | * -FDT_ERR_TRUNCATED, standard meanings.
|
---|
462 | */
|
---|
463 | int
|
---|
464 | fdt_subnode_offset (
|
---|
465 | const void *fdt,
|
---|
466 | int parentoffset,
|
---|
467 | const char *name
|
---|
468 | );
|
---|
469 |
|
---|
470 | /**
|
---|
471 | * fdt_path_offset_namelen - find a tree node by its full path
|
---|
472 | * @fdt: pointer to the device tree blob
|
---|
473 | * @path: full path of the node to locate
|
---|
474 | * @namelen: number of characters of path to consider
|
---|
475 | *
|
---|
476 | * Identical to fdt_path_offset(), but only consider the first namelen
|
---|
477 | * characters of path as the path name.
|
---|
478 | */
|
---|
479 | #ifndef SWIG /* Not available in Python */
|
---|
480 | int
|
---|
481 | fdt_path_offset_namelen (
|
---|
482 | const void *fdt,
|
---|
483 | const char *path,
|
---|
484 | int namelen
|
---|
485 | );
|
---|
486 |
|
---|
487 | #endif
|
---|
488 |
|
---|
489 | /**
|
---|
490 | * fdt_path_offset - find a tree node by its full path
|
---|
491 | * @fdt: pointer to the device tree blob
|
---|
492 | * @path: full path of the node to locate
|
---|
493 | *
|
---|
494 | * fdt_path_offset() finds a node of a given path in the device tree.
|
---|
495 | * Each path component may omit the unit address portion, but the
|
---|
496 | * results of this are undefined if any such path component is
|
---|
497 | * ambiguous (that is if there are multiple nodes at the relevant
|
---|
498 | * level matching the given component, differentiated only by unit
|
---|
499 | * address).
|
---|
500 | *
|
---|
501 | * returns:
|
---|
502 | * structure block offset of the node with the requested path (>=0), on
|
---|
503 | * success
|
---|
504 | * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
|
---|
505 | * -FDT_ERR_NOTFOUND, if the requested node does not exist
|
---|
506 | * -FDT_ERR_BADMAGIC,
|
---|
507 | * -FDT_ERR_BADVERSION,
|
---|
508 | * -FDT_ERR_BADSTATE,
|
---|
509 | * -FDT_ERR_BADSTRUCTURE,
|
---|
510 | * -FDT_ERR_TRUNCATED, standard meanings.
|
---|
511 | */
|
---|
512 | int
|
---|
513 | fdt_path_offset (
|
---|
514 | const void *fdt,
|
---|
515 | const char *path
|
---|
516 | );
|
---|
517 |
|
---|
518 | /**
|
---|
519 | * fdt_get_name - retrieve the name of a given node
|
---|
520 | * @fdt: pointer to the device tree blob
|
---|
521 | * @nodeoffset: structure block offset of the starting node
|
---|
522 | * @lenp: pointer to an integer variable (will be overwritten) or NULL
|
---|
523 | *
|
---|
524 | * fdt_get_name() retrieves the name (including unit address) of the
|
---|
525 | * device tree node at structure block offset nodeoffset. If lenp is
|
---|
526 | * non-NULL, the length of this name is also returned, in the integer
|
---|
527 | * pointed to by lenp.
|
---|
528 | *
|
---|
529 | * returns:
|
---|
530 | * pointer to the node's name, on success
|
---|
531 | * If lenp is non-NULL, *lenp contains the length of that name
|
---|
532 | * (>=0)
|
---|
533 | * NULL, on error
|
---|
534 | * if lenp is non-NULL *lenp contains an error code (<0):
|
---|
535 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
|
---|
536 | * tag
|
---|
537 | * -FDT_ERR_BADMAGIC,
|
---|
538 | * -FDT_ERR_BADVERSION,
|
---|
539 | * -FDT_ERR_BADSTATE, standard meanings
|
---|
540 | */
|
---|
541 | const char *
|
---|
542 | fdt_get_name (
|
---|
543 | const void *fdt,
|
---|
544 | int nodeoffset,
|
---|
545 | int *lenp
|
---|
546 | );
|
---|
547 |
|
---|
548 | /**
|
---|
549 | * fdt_first_property_offset - find the offset of a node's first property
|
---|
550 | * @fdt: pointer to the device tree blob
|
---|
551 | * @nodeoffset: structure block offset of a node
|
---|
552 | *
|
---|
553 | * fdt_first_property_offset() finds the first property of the node at
|
---|
554 | * the given structure block offset.
|
---|
555 | *
|
---|
556 | * returns:
|
---|
557 | * structure block offset of the property (>=0), on success
|
---|
558 | * -FDT_ERR_NOTFOUND, if the requested node has no properties
|
---|
559 | * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
|
---|
560 | * -FDT_ERR_BADMAGIC,
|
---|
561 | * -FDT_ERR_BADVERSION,
|
---|
562 | * -FDT_ERR_BADSTATE,
|
---|
563 | * -FDT_ERR_BADSTRUCTURE,
|
---|
564 | * -FDT_ERR_TRUNCATED, standard meanings.
|
---|
565 | */
|
---|
566 | int
|
---|
567 | fdt_first_property_offset (
|
---|
568 | const void *fdt,
|
---|
569 | int nodeoffset
|
---|
570 | );
|
---|
571 |
|
---|
572 | /**
|
---|
573 | * fdt_next_property_offset - step through a node's properties
|
---|
574 | * @fdt: pointer to the device tree blob
|
---|
575 | * @offset: structure block offset of a property
|
---|
576 | *
|
---|
577 | * fdt_next_property_offset() finds the property immediately after the
|
---|
578 | * one at the given structure block offset. This will be a property
|
---|
579 | * of the same node as the given property.
|
---|
580 | *
|
---|
581 | * returns:
|
---|
582 | * structure block offset of the next property (>=0), on success
|
---|
583 | * -FDT_ERR_NOTFOUND, if the given property is the last in its node
|
---|
584 | * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
|
---|
585 | * -FDT_ERR_BADMAGIC,
|
---|
586 | * -FDT_ERR_BADVERSION,
|
---|
587 | * -FDT_ERR_BADSTATE,
|
---|
588 | * -FDT_ERR_BADSTRUCTURE,
|
---|
589 | * -FDT_ERR_TRUNCATED, standard meanings.
|
---|
590 | */
|
---|
591 | int
|
---|
592 | fdt_next_property_offset (
|
---|
593 | const void *fdt,
|
---|
594 | int offset
|
---|
595 | );
|
---|
596 |
|
---|
597 | /**
|
---|
598 | * fdt_for_each_property_offset - iterate over all properties of a node
|
---|
599 | *
|
---|
600 | * @property_offset: property offset (int, lvalue)
|
---|
601 | * @fdt: FDT blob (const void *)
|
---|
602 | * @node: node offset (int)
|
---|
603 | *
|
---|
604 | * This is actually a wrapper around a for loop and would be used like so:
|
---|
605 | *
|
---|
606 | * fdt_for_each_property_offset(property, fdt, node) {
|
---|
607 | * Use property
|
---|
608 | * ...
|
---|
609 | * }
|
---|
610 | *
|
---|
611 | * if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) {
|
---|
612 | * Error handling
|
---|
613 | * }
|
---|
614 | *
|
---|
615 | * Note that this is implemented as a macro and property is used as
|
---|
616 | * iterator in the loop. The node variable can be constant or even a
|
---|
617 | * literal.
|
---|
618 | */
|
---|
619 | #define fdt_for_each_property_offset(property, fdt, node) \
|
---|
620 | for (property = fdt_first_property_offset(fdt, node); \
|
---|
621 | property >= 0; \
|
---|
622 | property = fdt_next_property_offset(fdt, property))
|
---|
623 |
|
---|
624 | /**
|
---|
625 | * fdt_get_property_by_offset - retrieve the property at a given offset
|
---|
626 | * @fdt: pointer to the device tree blob
|
---|
627 | * @offset: offset of the property to retrieve
|
---|
628 | * @lenp: pointer to an integer variable (will be overwritten) or NULL
|
---|
629 | *
|
---|
630 | * fdt_get_property_by_offset() retrieves a pointer to the
|
---|
631 | * fdt_property structure within the device tree blob at the given
|
---|
632 | * offset. If lenp is non-NULL, the length of the property value is
|
---|
633 | * also returned, in the integer pointed to by lenp.
|
---|
634 | *
|
---|
635 | * returns:
|
---|
636 | * pointer to the structure representing the property
|
---|
637 | * if lenp is non-NULL, *lenp contains the length of the property
|
---|
638 | * value (>=0)
|
---|
639 | * NULL, on error
|
---|
640 | * if lenp is non-NULL, *lenp contains an error code (<0):
|
---|
641 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
|
---|
642 | * -FDT_ERR_BADMAGIC,
|
---|
643 | * -FDT_ERR_BADVERSION,
|
---|
644 | * -FDT_ERR_BADSTATE,
|
---|
645 | * -FDT_ERR_BADSTRUCTURE,
|
---|
646 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
647 | */
|
---|
648 | const struct fdt_property *
|
---|
649 | fdt_get_property_by_offset (
|
---|
650 | const void *fdt,
|
---|
651 | int offset,
|
---|
652 | int *lenp
|
---|
653 | );
|
---|
654 |
|
---|
655 | /**
|
---|
656 | * fdt_get_property_namelen - find a property based on substring
|
---|
657 | * @fdt: pointer to the device tree blob
|
---|
658 | * @nodeoffset: offset of the node whose property to find
|
---|
659 | * @name: name of the property to find
|
---|
660 | * @namelen: number of characters of name to consider
|
---|
661 | * @lenp: pointer to an integer variable (will be overwritten) or NULL
|
---|
662 | *
|
---|
663 | * Identical to fdt_get_property(), but only examine the first namelen
|
---|
664 | * characters of name for matching the property name.
|
---|
665 | */
|
---|
666 | #ifndef SWIG /* Not available in Python */
|
---|
667 | const struct fdt_property *
|
---|
668 | fdt_get_property_namelen (
|
---|
669 | const void *fdt,
|
---|
670 | int nodeoffset,
|
---|
671 | const char *name,
|
---|
672 | int namelen,
|
---|
673 | int *lenp
|
---|
674 | );
|
---|
675 |
|
---|
676 | #endif
|
---|
677 |
|
---|
678 | /**
|
---|
679 | * fdt_get_property - find a given property in a given node
|
---|
680 | * @fdt: pointer to the device tree blob
|
---|
681 | * @nodeoffset: offset of the node whose property to find
|
---|
682 | * @name: name of the property to find
|
---|
683 | * @lenp: pointer to an integer variable (will be overwritten) or NULL
|
---|
684 | *
|
---|
685 | * fdt_get_property() retrieves a pointer to the fdt_property
|
---|
686 | * structure within the device tree blob corresponding to the property
|
---|
687 | * named 'name' of the node at offset nodeoffset. If lenp is
|
---|
688 | * non-NULL, the length of the property value is also returned, in the
|
---|
689 | * integer pointed to by lenp.
|
---|
690 | *
|
---|
691 | * returns:
|
---|
692 | * pointer to the structure representing the property
|
---|
693 | * if lenp is non-NULL, *lenp contains the length of the property
|
---|
694 | * value (>=0)
|
---|
695 | * NULL, on error
|
---|
696 | * if lenp is non-NULL, *lenp contains an error code (<0):
|
---|
697 | * -FDT_ERR_NOTFOUND, node does not have named property
|
---|
698 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
|
---|
699 | * tag
|
---|
700 | * -FDT_ERR_BADMAGIC,
|
---|
701 | * -FDT_ERR_BADVERSION,
|
---|
702 | * -FDT_ERR_BADSTATE,
|
---|
703 | * -FDT_ERR_BADSTRUCTURE,
|
---|
704 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
705 | */
|
---|
706 | const struct fdt_property *
|
---|
707 | fdt_get_property (
|
---|
708 | const void *fdt,
|
---|
709 | int nodeoffset,
|
---|
710 | const char *name,
|
---|
711 | int *lenp
|
---|
712 | );
|
---|
713 |
|
---|
714 | static inline struct fdt_property *
|
---|
715 | fdt_get_property_w (
|
---|
716 | void *fdt,
|
---|
717 | int nodeoffset,
|
---|
718 | const char *name,
|
---|
719 | int *lenp
|
---|
720 | )
|
---|
721 | {
|
---|
722 | return (struct fdt_property *)(uintptr_t)
|
---|
723 | fdt_get_property (fdt, nodeoffset, name, lenp);
|
---|
724 | }
|
---|
725 |
|
---|
726 | /**
|
---|
727 | * fdt_getprop_by_offset - retrieve the value of a property at a given offset
|
---|
728 | * @fdt: pointer to the device tree blob
|
---|
729 | * @ffset: offset of the property to read
|
---|
730 | * @namep: pointer to a string variable (will be overwritten) or NULL
|
---|
731 | * @lenp: pointer to an integer variable (will be overwritten) or NULL
|
---|
732 | *
|
---|
733 | * fdt_getprop_by_offset() retrieves a pointer to the value of the
|
---|
734 | * property at structure block offset 'offset' (this will be a pointer
|
---|
735 | * to within the device blob itself, not a copy of the value). If
|
---|
736 | * lenp is non-NULL, the length of the property value is also
|
---|
737 | * returned, in the integer pointed to by lenp. If namep is non-NULL,
|
---|
738 | * the property's namne will also be returned in the char * pointed to
|
---|
739 | * by namep (this will be a pointer to within the device tree's string
|
---|
740 | * block, not a new copy of the name).
|
---|
741 | *
|
---|
742 | * returns:
|
---|
743 | * pointer to the property's value
|
---|
744 | * if lenp is non-NULL, *lenp contains the length of the property
|
---|
745 | * value (>=0)
|
---|
746 | * if namep is non-NULL *namep contiains a pointer to the property
|
---|
747 | * name.
|
---|
748 | * NULL, on error
|
---|
749 | * if lenp is non-NULL, *lenp contains an error code (<0):
|
---|
750 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
|
---|
751 | * -FDT_ERR_BADMAGIC,
|
---|
752 | * -FDT_ERR_BADVERSION,
|
---|
753 | * -FDT_ERR_BADSTATE,
|
---|
754 | * -FDT_ERR_BADSTRUCTURE,
|
---|
755 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
756 | */
|
---|
757 | #ifndef SWIG /* This function is not useful in Python */
|
---|
758 | const void *
|
---|
759 | fdt_getprop_by_offset (
|
---|
760 | const void *fdt,
|
---|
761 | int offset,
|
---|
762 | const char **namep,
|
---|
763 | int *lenp
|
---|
764 | );
|
---|
765 |
|
---|
766 | #endif
|
---|
767 |
|
---|
768 | /**
|
---|
769 | * fdt_getprop_namelen - get property value based on substring
|
---|
770 | * @fdt: pointer to the device tree blob
|
---|
771 | * @nodeoffset: offset of the node whose property to find
|
---|
772 | * @name: name of the property to find
|
---|
773 | * @namelen: number of characters of name to consider
|
---|
774 | * @lenp: pointer to an integer variable (will be overwritten) or NULL
|
---|
775 | *
|
---|
776 | * Identical to fdt_getprop(), but only examine the first namelen
|
---|
777 | * characters of name for matching the property name.
|
---|
778 | */
|
---|
779 | #ifndef SWIG /* Not available in Python */
|
---|
780 | const void *
|
---|
781 | fdt_getprop_namelen (
|
---|
782 | const void *fdt,
|
---|
783 | int nodeoffset,
|
---|
784 | const char *name,
|
---|
785 | int namelen,
|
---|
786 | int *lenp
|
---|
787 | );
|
---|
788 |
|
---|
789 | static inline void *
|
---|
790 | fdt_getprop_namelen_w (
|
---|
791 | void *fdt,
|
---|
792 | int nodeoffset,
|
---|
793 | const char *name,
|
---|
794 | int namelen,
|
---|
795 | int *lenp
|
---|
796 | )
|
---|
797 | {
|
---|
798 | return (void *)(uintptr_t)fdt_getprop_namelen (
|
---|
799 | fdt,
|
---|
800 | nodeoffset,
|
---|
801 | name,
|
---|
802 | namelen,
|
---|
803 | lenp
|
---|
804 | );
|
---|
805 | }
|
---|
806 |
|
---|
807 | #endif
|
---|
808 |
|
---|
809 | /**
|
---|
810 | * fdt_getprop - retrieve the value of a given property
|
---|
811 | * @fdt: pointer to the device tree blob
|
---|
812 | * @nodeoffset: offset of the node whose property to find
|
---|
813 | * @name: name of the property to find
|
---|
814 | * @lenp: pointer to an integer variable (will be overwritten) or NULL
|
---|
815 | *
|
---|
816 | * fdt_getprop() retrieves a pointer to the value of the property
|
---|
817 | * named 'name' of the node at offset nodeoffset (this will be a
|
---|
818 | * pointer to within the device blob itself, not a copy of the value).
|
---|
819 | * If lenp is non-NULL, the length of the property value is also
|
---|
820 | * returned, in the integer pointed to by lenp.
|
---|
821 | *
|
---|
822 | * returns:
|
---|
823 | * pointer to the property's value
|
---|
824 | * if lenp is non-NULL, *lenp contains the length of the property
|
---|
825 | * value (>=0)
|
---|
826 | * NULL, on error
|
---|
827 | * if lenp is non-NULL, *lenp contains an error code (<0):
|
---|
828 | * -FDT_ERR_NOTFOUND, node does not have named property
|
---|
829 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
|
---|
830 | * tag
|
---|
831 | * -FDT_ERR_BADMAGIC,
|
---|
832 | * -FDT_ERR_BADVERSION,
|
---|
833 | * -FDT_ERR_BADSTATE,
|
---|
834 | * -FDT_ERR_BADSTRUCTURE,
|
---|
835 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
836 | */
|
---|
837 | const void *
|
---|
838 | fdt_getprop (
|
---|
839 | const void *fdt,
|
---|
840 | int nodeoffset,
|
---|
841 | const char *name,
|
---|
842 | int *lenp
|
---|
843 | );
|
---|
844 |
|
---|
845 | static inline void *
|
---|
846 | fdt_getprop_w (
|
---|
847 | void *fdt,
|
---|
848 | int nodeoffset,
|
---|
849 | const char *name,
|
---|
850 | int *lenp
|
---|
851 | )
|
---|
852 | {
|
---|
853 | return (void *)(uintptr_t)fdt_getprop (fdt, nodeoffset, name, lenp);
|
---|
854 | }
|
---|
855 |
|
---|
856 | /**
|
---|
857 | * fdt_get_phandle - retrieve the phandle of a given node
|
---|
858 | * @fdt: pointer to the device tree blob
|
---|
859 | * @nodeoffset: structure block offset of the node
|
---|
860 | *
|
---|
861 | * fdt_get_phandle() retrieves the phandle of the device tree node at
|
---|
862 | * structure block offset nodeoffset.
|
---|
863 | *
|
---|
864 | * returns:
|
---|
865 | * the phandle of the node at nodeoffset, on success (!= 0, != -1)
|
---|
866 | * 0, if the node has no phandle, or another error occurs
|
---|
867 | */
|
---|
868 | uint32_t
|
---|
869 | fdt_get_phandle (
|
---|
870 | const void *fdt,
|
---|
871 | int nodeoffset
|
---|
872 | );
|
---|
873 |
|
---|
874 | /**
|
---|
875 | * fdt_get_alias_namelen - get alias based on substring
|
---|
876 | * @fdt: pointer to the device tree blob
|
---|
877 | * @name: name of the alias th look up
|
---|
878 | * @namelen: number of characters of name to consider
|
---|
879 | *
|
---|
880 | * Identical to fdt_get_alias(), but only examine the first namelen
|
---|
881 | * characters of name for matching the alias name.
|
---|
882 | */
|
---|
883 | #ifndef SWIG /* Not available in Python */
|
---|
884 | const char *
|
---|
885 | fdt_get_alias_namelen (
|
---|
886 | const void *fdt,
|
---|
887 | const char *name,
|
---|
888 | int namelen
|
---|
889 | );
|
---|
890 |
|
---|
891 | #endif
|
---|
892 |
|
---|
893 | /**
|
---|
894 | * fdt_get_alias - retrieve the path referenced by a given alias
|
---|
895 | * @fdt: pointer to the device tree blob
|
---|
896 | * @name: name of the alias th look up
|
---|
897 | *
|
---|
898 | * fdt_get_alias() retrieves the value of a given alias. That is, the
|
---|
899 | * value of the property named 'name' in the node /aliases.
|
---|
900 | *
|
---|
901 | * returns:
|
---|
902 | * a pointer to the expansion of the alias named 'name', if it exists
|
---|
903 | * NULL, if the given alias or the /aliases node does not exist
|
---|
904 | */
|
---|
905 | const char *
|
---|
906 | fdt_get_alias (
|
---|
907 | const void *fdt,
|
---|
908 | const char *name
|
---|
909 | );
|
---|
910 |
|
---|
911 | /**
|
---|
912 | * fdt_get_path - determine the full path of a node
|
---|
913 | * @fdt: pointer to the device tree blob
|
---|
914 | * @nodeoffset: offset of the node whose path to find
|
---|
915 | * @buf: character buffer to contain the returned path (will be overwritten)
|
---|
916 | * @buflen: size of the character buffer at buf
|
---|
917 | *
|
---|
918 | * fdt_get_path() computes the full path of the node at offset
|
---|
919 | * nodeoffset, and records that path in the buffer at buf.
|
---|
920 | *
|
---|
921 | * NOTE: This function is expensive, as it must scan the device tree
|
---|
922 | * structure from the start to nodeoffset.
|
---|
923 | *
|
---|
924 | * returns:
|
---|
925 | * 0, on success
|
---|
926 | * buf contains the absolute path of the node at
|
---|
927 | * nodeoffset, as a NUL-terminated string.
|
---|
928 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
|
---|
929 | * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
|
---|
930 | * characters and will not fit in the given buffer.
|
---|
931 | * -FDT_ERR_BADMAGIC,
|
---|
932 | * -FDT_ERR_BADVERSION,
|
---|
933 | * -FDT_ERR_BADSTATE,
|
---|
934 | * -FDT_ERR_BADSTRUCTURE, standard meanings
|
---|
935 | */
|
---|
936 | int
|
---|
937 | fdt_get_path (
|
---|
938 | const void *fdt,
|
---|
939 | int nodeoffset,
|
---|
940 | char *buf,
|
---|
941 | int buflen
|
---|
942 | );
|
---|
943 |
|
---|
944 | /**
|
---|
945 | * fdt_supernode_atdepth_offset - find a specific ancestor of a node
|
---|
946 | * @fdt: pointer to the device tree blob
|
---|
947 | * @nodeoffset: offset of the node whose parent to find
|
---|
948 | * @supernodedepth: depth of the ancestor to find
|
---|
949 | * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
|
---|
950 | *
|
---|
951 | * fdt_supernode_atdepth_offset() finds an ancestor of the given node
|
---|
952 | * at a specific depth from the root (where the root itself has depth
|
---|
953 | * 0, its immediate subnodes depth 1 and so forth). So
|
---|
954 | * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
|
---|
955 | * will always return 0, the offset of the root node. If the node at
|
---|
956 | * nodeoffset has depth D, then:
|
---|
957 | * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
|
---|
958 | * will return nodeoffset itself.
|
---|
959 | *
|
---|
960 | * NOTE: This function is expensive, as it must scan the device tree
|
---|
961 | * structure from the start to nodeoffset.
|
---|
962 | *
|
---|
963 | * returns:
|
---|
964 | * structure block offset of the node at node offset's ancestor
|
---|
965 | * of depth supernodedepth (>=0), on success
|
---|
966 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
|
---|
967 | * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
|
---|
968 | * nodeoffset
|
---|
969 | * -FDT_ERR_BADMAGIC,
|
---|
970 | * -FDT_ERR_BADVERSION,
|
---|
971 | * -FDT_ERR_BADSTATE,
|
---|
972 | * -FDT_ERR_BADSTRUCTURE, standard meanings
|
---|
973 | */
|
---|
974 | int
|
---|
975 | fdt_supernode_atdepth_offset (
|
---|
976 | const void *fdt,
|
---|
977 | int nodeoffset,
|
---|
978 | int supernodedepth,
|
---|
979 | int *nodedepth
|
---|
980 | );
|
---|
981 |
|
---|
982 | /**
|
---|
983 | * fdt_node_depth - find the depth of a given node
|
---|
984 | * @fdt: pointer to the device tree blob
|
---|
985 | * @nodeoffset: offset of the node whose parent to find
|
---|
986 | *
|
---|
987 | * fdt_node_depth() finds the depth of a given node. The root node
|
---|
988 | * has depth 0, its immediate subnodes depth 1 and so forth.
|
---|
989 | *
|
---|
990 | * NOTE: This function is expensive, as it must scan the device tree
|
---|
991 | * structure from the start to nodeoffset.
|
---|
992 | *
|
---|
993 | * returns:
|
---|
994 | * depth of the node at nodeoffset (>=0), on success
|
---|
995 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
|
---|
996 | * -FDT_ERR_BADMAGIC,
|
---|
997 | * -FDT_ERR_BADVERSION,
|
---|
998 | * -FDT_ERR_BADSTATE,
|
---|
999 | * -FDT_ERR_BADSTRUCTURE, standard meanings
|
---|
1000 | */
|
---|
1001 | int
|
---|
1002 | fdt_node_depth (
|
---|
1003 | const void *fdt,
|
---|
1004 | int nodeoffset
|
---|
1005 | );
|
---|
1006 |
|
---|
1007 | /**
|
---|
1008 | * fdt_parent_offset - find the parent of a given node
|
---|
1009 | * @fdt: pointer to the device tree blob
|
---|
1010 | * @nodeoffset: offset of the node whose parent to find
|
---|
1011 | *
|
---|
1012 | * fdt_parent_offset() locates the parent node of a given node (that
|
---|
1013 | * is, it finds the offset of the node which contains the node at
|
---|
1014 | * nodeoffset as a subnode).
|
---|
1015 | *
|
---|
1016 | * NOTE: This function is expensive, as it must scan the device tree
|
---|
1017 | * structure from the start to nodeoffset, *twice*.
|
---|
1018 | *
|
---|
1019 | * returns:
|
---|
1020 | * structure block offset of the parent of the node at nodeoffset
|
---|
1021 | * (>=0), on success
|
---|
1022 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
|
---|
1023 | * -FDT_ERR_BADMAGIC,
|
---|
1024 | * -FDT_ERR_BADVERSION,
|
---|
1025 | * -FDT_ERR_BADSTATE,
|
---|
1026 | * -FDT_ERR_BADSTRUCTURE, standard meanings
|
---|
1027 | */
|
---|
1028 | int
|
---|
1029 | fdt_parent_offset (
|
---|
1030 | const void *fdt,
|
---|
1031 | int nodeoffset
|
---|
1032 | );
|
---|
1033 |
|
---|
1034 | /**
|
---|
1035 | * fdt_node_offset_by_prop_value - find nodes with a given property value
|
---|
1036 | * @fdt: pointer to the device tree blob
|
---|
1037 | * @startoffset: only find nodes after this offset
|
---|
1038 | * @propname: property name to check
|
---|
1039 | * @propval: property value to search for
|
---|
1040 | * @proplen: length of the value in propval
|
---|
1041 | *
|
---|
1042 | * fdt_node_offset_by_prop_value() returns the offset of the first
|
---|
1043 | * node after startoffset, which has a property named propname whose
|
---|
1044 | * value is of length proplen and has value equal to propval; or if
|
---|
1045 | * startoffset is -1, the very first such node in the tree.
|
---|
1046 | *
|
---|
1047 | * To iterate through all nodes matching the criterion, the following
|
---|
1048 | * idiom can be used:
|
---|
1049 | * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
|
---|
1050 | * propval, proplen);
|
---|
1051 | * while (offset != -FDT_ERR_NOTFOUND) {
|
---|
1052 | * // other code here
|
---|
1053 | * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
|
---|
1054 | * propval, proplen);
|
---|
1055 | * }
|
---|
1056 | *
|
---|
1057 | * Note the -1 in the first call to the function, if 0 is used here
|
---|
1058 | * instead, the function will never locate the root node, even if it
|
---|
1059 | * matches the criterion.
|
---|
1060 | *
|
---|
1061 | * returns:
|
---|
1062 | * structure block offset of the located node (>= 0, >startoffset),
|
---|
1063 | * on success
|
---|
1064 | * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
|
---|
1065 | * tree after startoffset
|
---|
1066 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
|
---|
1067 | * -FDT_ERR_BADMAGIC,
|
---|
1068 | * -FDT_ERR_BADVERSION,
|
---|
1069 | * -FDT_ERR_BADSTATE,
|
---|
1070 | * -FDT_ERR_BADSTRUCTURE, standard meanings
|
---|
1071 | */
|
---|
1072 | int
|
---|
1073 | fdt_node_offset_by_prop_value (
|
---|
1074 | const void *fdt,
|
---|
1075 | int startoffset,
|
---|
1076 | const char *propname,
|
---|
1077 | const void *propval,
|
---|
1078 | int proplen
|
---|
1079 | );
|
---|
1080 |
|
---|
1081 | /**
|
---|
1082 | * fdt_node_offset_by_phandle - find the node with a given phandle
|
---|
1083 | * @fdt: pointer to the device tree blob
|
---|
1084 | * @phandle: phandle value
|
---|
1085 | *
|
---|
1086 | * fdt_node_offset_by_phandle() returns the offset of the node
|
---|
1087 | * which has the given phandle value. If there is more than one node
|
---|
1088 | * in the tree with the given phandle (an invalid tree), results are
|
---|
1089 | * undefined.
|
---|
1090 | *
|
---|
1091 | * returns:
|
---|
1092 | * structure block offset of the located node (>= 0), on success
|
---|
1093 | * -FDT_ERR_NOTFOUND, no node with that phandle exists
|
---|
1094 | * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
|
---|
1095 | * -FDT_ERR_BADMAGIC,
|
---|
1096 | * -FDT_ERR_BADVERSION,
|
---|
1097 | * -FDT_ERR_BADSTATE,
|
---|
1098 | * -FDT_ERR_BADSTRUCTURE, standard meanings
|
---|
1099 | */
|
---|
1100 | int
|
---|
1101 | fdt_node_offset_by_phandle (
|
---|
1102 | const void *fdt,
|
---|
1103 | uint32_t phandle
|
---|
1104 | );
|
---|
1105 |
|
---|
1106 | /**
|
---|
1107 | * fdt_node_check_compatible: check a node's compatible property
|
---|
1108 | * @fdt: pointer to the device tree blob
|
---|
1109 | * @nodeoffset: offset of a tree node
|
---|
1110 | * @compatible: string to match against
|
---|
1111 | *
|
---|
1112 | *
|
---|
1113 | * fdt_node_check_compatible() returns 0 if the given node contains a
|
---|
1114 | * 'compatible' property with the given string as one of its elements,
|
---|
1115 | * it returns non-zero otherwise, or on error.
|
---|
1116 | *
|
---|
1117 | * returns:
|
---|
1118 | * 0, if the node has a 'compatible' property listing the given string
|
---|
1119 | * 1, if the node has a 'compatible' property, but it does not list
|
---|
1120 | * the given string
|
---|
1121 | * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
|
---|
1122 | * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
|
---|
1123 | * -FDT_ERR_BADMAGIC,
|
---|
1124 | * -FDT_ERR_BADVERSION,
|
---|
1125 | * -FDT_ERR_BADSTATE,
|
---|
1126 | * -FDT_ERR_BADSTRUCTURE, standard meanings
|
---|
1127 | */
|
---|
1128 | int
|
---|
1129 | fdt_node_check_compatible (
|
---|
1130 | const void *fdt,
|
---|
1131 | int nodeoffset,
|
---|
1132 | const char *compatible
|
---|
1133 | );
|
---|
1134 |
|
---|
1135 | /**
|
---|
1136 | * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
|
---|
1137 | * @fdt: pointer to the device tree blob
|
---|
1138 | * @startoffset: only find nodes after this offset
|
---|
1139 | * @compatible: 'compatible' string to match against
|
---|
1140 | *
|
---|
1141 | * fdt_node_offset_by_compatible() returns the offset of the first
|
---|
1142 | * node after startoffset, which has a 'compatible' property which
|
---|
1143 | * lists the given compatible string; or if startoffset is -1, the
|
---|
1144 | * very first such node in the tree.
|
---|
1145 | *
|
---|
1146 | * To iterate through all nodes matching the criterion, the following
|
---|
1147 | * idiom can be used:
|
---|
1148 | * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
|
---|
1149 | * while (offset != -FDT_ERR_NOTFOUND) {
|
---|
1150 | * // other code here
|
---|
1151 | * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
|
---|
1152 | * }
|
---|
1153 | *
|
---|
1154 | * Note the -1 in the first call to the function, if 0 is used here
|
---|
1155 | * instead, the function will never locate the root node, even if it
|
---|
1156 | * matches the criterion.
|
---|
1157 | *
|
---|
1158 | * returns:
|
---|
1159 | * structure block offset of the located node (>= 0, >startoffset),
|
---|
1160 | * on success
|
---|
1161 | * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
|
---|
1162 | * tree after startoffset
|
---|
1163 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
|
---|
1164 | * -FDT_ERR_BADMAGIC,
|
---|
1165 | * -FDT_ERR_BADVERSION,
|
---|
1166 | * -FDT_ERR_BADSTATE,
|
---|
1167 | * -FDT_ERR_BADSTRUCTURE, standard meanings
|
---|
1168 | */
|
---|
1169 | int
|
---|
1170 | fdt_node_offset_by_compatible (
|
---|
1171 | const void *fdt,
|
---|
1172 | int startoffset,
|
---|
1173 | const char *compatible
|
---|
1174 | );
|
---|
1175 |
|
---|
1176 | /**
|
---|
1177 | * fdt_stringlist_contains - check a string list property for a string
|
---|
1178 | * @strlist: Property containing a list of strings to check
|
---|
1179 | * @listlen: Length of property
|
---|
1180 | * @str: String to search for
|
---|
1181 | *
|
---|
1182 | * This is a utility function provided for convenience. The list contains
|
---|
1183 | * one or more strings, each terminated by \0, as is found in a device tree
|
---|
1184 | * "compatible" property.
|
---|
1185 | *
|
---|
1186 | * @return: 1 if the string is found in the list, 0 not found, or invalid list
|
---|
1187 | */
|
---|
1188 | int
|
---|
1189 | fdt_stringlist_contains (
|
---|
1190 | const char *strlist,
|
---|
1191 | int listlen,
|
---|
1192 | const char *str
|
---|
1193 | );
|
---|
1194 |
|
---|
1195 | /**
|
---|
1196 | * fdt_stringlist_count - count the number of strings in a string list
|
---|
1197 | * @fdt: pointer to the device tree blob
|
---|
1198 | * @nodeoffset: offset of a tree node
|
---|
1199 | * @property: name of the property containing the string list
|
---|
1200 | * @return:
|
---|
1201 | * the number of strings in the given property
|
---|
1202 | * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
|
---|
1203 | * -FDT_ERR_NOTFOUND if the property does not exist
|
---|
1204 | */
|
---|
1205 | int
|
---|
1206 | fdt_stringlist_count (
|
---|
1207 | const void *fdt,
|
---|
1208 | int nodeoffset,
|
---|
1209 | const char *property
|
---|
1210 | );
|
---|
1211 |
|
---|
1212 | /**
|
---|
1213 | * fdt_stringlist_search - find a string in a string list and return its index
|
---|
1214 | * @fdt: pointer to the device tree blob
|
---|
1215 | * @nodeoffset: offset of a tree node
|
---|
1216 | * @property: name of the property containing the string list
|
---|
1217 | * @string: string to look up in the string list
|
---|
1218 | *
|
---|
1219 | * Note that it is possible for this function to succeed on property values
|
---|
1220 | * that are not NUL-terminated. That's because the function will stop after
|
---|
1221 | * finding the first occurrence of @string. This can for example happen with
|
---|
1222 | * small-valued cell properties, such as #address-cells, when searching for
|
---|
1223 | * the empty string.
|
---|
1224 | *
|
---|
1225 | * @return:
|
---|
1226 | * the index of the string in the list of strings
|
---|
1227 | * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
|
---|
1228 | * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
|
---|
1229 | * the given string
|
---|
1230 | */
|
---|
1231 | int
|
---|
1232 | fdt_stringlist_search (
|
---|
1233 | const void *fdt,
|
---|
1234 | int nodeoffset,
|
---|
1235 | const char *property,
|
---|
1236 | const char *string
|
---|
1237 | );
|
---|
1238 |
|
---|
1239 | /**
|
---|
1240 | * fdt_stringlist_get() - obtain the string at a given index in a string list
|
---|
1241 | * @fdt: pointer to the device tree blob
|
---|
1242 | * @nodeoffset: offset of a tree node
|
---|
1243 | * @property: name of the property containing the string list
|
---|
1244 | * @index: index of the string to return
|
---|
1245 | * @lenp: return location for the string length or an error code on failure
|
---|
1246 | *
|
---|
1247 | * Note that this will successfully extract strings from properties with
|
---|
1248 | * non-NUL-terminated values. For example on small-valued cell properties
|
---|
1249 | * this function will return the empty string.
|
---|
1250 | *
|
---|
1251 | * If non-NULL, the length of the string (on success) or a negative error-code
|
---|
1252 | * (on failure) will be stored in the integer pointer to by lenp.
|
---|
1253 | *
|
---|
1254 | * @return:
|
---|
1255 | * A pointer to the string at the given index in the string list or NULL on
|
---|
1256 | * failure. On success the length of the string will be stored in the memory
|
---|
1257 | * location pointed to by the lenp parameter, if non-NULL. On failure one of
|
---|
1258 | * the following negative error codes will be returned in the lenp parameter
|
---|
1259 | * (if non-NULL):
|
---|
1260 | * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
|
---|
1261 | * -FDT_ERR_NOTFOUND if the property does not exist
|
---|
1262 | */
|
---|
1263 | const char *
|
---|
1264 | fdt_stringlist_get (
|
---|
1265 | const void *fdt,
|
---|
1266 | int nodeoffset,
|
---|
1267 | const char *property,
|
---|
1268 | int index,
|
---|
1269 | int *lenp
|
---|
1270 | );
|
---|
1271 |
|
---|
1272 | /**********************************************************************/
|
---|
1273 | /* Read-only functions (addressing related) */
|
---|
1274 | /**********************************************************************/
|
---|
1275 |
|
---|
1276 | /**
|
---|
1277 | * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
|
---|
1278 | *
|
---|
1279 | * This is the maximum value for #address-cells, #size-cells and
|
---|
1280 | * similar properties that will be processed by libfdt. IEE1275
|
---|
1281 | * requires that OF implementations handle values up to 4.
|
---|
1282 | * Implementations may support larger values, but in practice higher
|
---|
1283 | * values aren't used.
|
---|
1284 | */
|
---|
1285 | #define FDT_MAX_NCELLS 4
|
---|
1286 |
|
---|
1287 | /**
|
---|
1288 | * fdt_address_cells - retrieve address size for a bus represented in the tree
|
---|
1289 | * @fdt: pointer to the device tree blob
|
---|
1290 | * @nodeoffset: offset of the node to find the address size for
|
---|
1291 | *
|
---|
1292 | * When the node has a valid #address-cells property, returns its value.
|
---|
1293 | *
|
---|
1294 | * returns:
|
---|
1295 | * 0 <= n < FDT_MAX_NCELLS, on success
|
---|
1296 | * 2, if the node has no #address-cells property
|
---|
1297 | * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
|
---|
1298 | * #address-cells property
|
---|
1299 | * -FDT_ERR_BADMAGIC,
|
---|
1300 | * -FDT_ERR_BADVERSION,
|
---|
1301 | * -FDT_ERR_BADSTATE,
|
---|
1302 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1303 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1304 | */
|
---|
1305 | int
|
---|
1306 | fdt_address_cells (
|
---|
1307 | const void *fdt,
|
---|
1308 | int nodeoffset
|
---|
1309 | );
|
---|
1310 |
|
---|
1311 | /**
|
---|
1312 | * fdt_size_cells - retrieve address range size for a bus represented in the
|
---|
1313 | * tree
|
---|
1314 | * @fdt: pointer to the device tree blob
|
---|
1315 | * @nodeoffset: offset of the node to find the address range size for
|
---|
1316 | *
|
---|
1317 | * When the node has a valid #size-cells property, returns its value.
|
---|
1318 | *
|
---|
1319 | * returns:
|
---|
1320 | * 0 <= n < FDT_MAX_NCELLS, on success
|
---|
1321 | * 2, if the node has no #address-cells property
|
---|
1322 | * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
|
---|
1323 | * #size-cells property
|
---|
1324 | * -FDT_ERR_BADMAGIC,
|
---|
1325 | * -FDT_ERR_BADVERSION,
|
---|
1326 | * -FDT_ERR_BADSTATE,
|
---|
1327 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1328 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1329 | */
|
---|
1330 | int
|
---|
1331 | fdt_size_cells (
|
---|
1332 | const void *fdt,
|
---|
1333 | int nodeoffset
|
---|
1334 | );
|
---|
1335 |
|
---|
1336 | /**********************************************************************/
|
---|
1337 | /* Write-in-place functions */
|
---|
1338 | /**********************************************************************/
|
---|
1339 |
|
---|
1340 | /**
|
---|
1341 | * fdt_setprop_inplace_namelen_partial - change a property's value,
|
---|
1342 | * but not its size
|
---|
1343 | * @fdt: pointer to the device tree blob
|
---|
1344 | * @nodeoffset: offset of the node whose property to change
|
---|
1345 | * @name: name of the property to change
|
---|
1346 | * @namelen: number of characters of name to consider
|
---|
1347 | * @idx: index of the property to change in the array
|
---|
1348 | * @val: pointer to data to replace the property value with
|
---|
1349 | * @len: length of the property value
|
---|
1350 | *
|
---|
1351 | * Identical to fdt_setprop_inplace(), but modifies the given property
|
---|
1352 | * starting from the given index, and using only the first characters
|
---|
1353 | * of the name. It is useful when you want to manipulate only one value of
|
---|
1354 | * an array and you have a string that doesn't end with \0.
|
---|
1355 | */
|
---|
1356 | #ifndef SWIG /* Not available in Python */
|
---|
1357 | int
|
---|
1358 | fdt_setprop_inplace_namelen_partial (
|
---|
1359 | void *fdt,
|
---|
1360 | int nodeoffset,
|
---|
1361 | const char *name,
|
---|
1362 | int namelen,
|
---|
1363 | uint32_t idx,
|
---|
1364 | const void *val,
|
---|
1365 | int len
|
---|
1366 | );
|
---|
1367 |
|
---|
1368 | #endif
|
---|
1369 |
|
---|
1370 | /**
|
---|
1371 | * fdt_setprop_inplace - change a property's value, but not its size
|
---|
1372 | * @fdt: pointer to the device tree blob
|
---|
1373 | * @nodeoffset: offset of the node whose property to change
|
---|
1374 | * @name: name of the property to change
|
---|
1375 | * @val: pointer to data to replace the property value with
|
---|
1376 | * @len: length of the property value
|
---|
1377 | *
|
---|
1378 | * fdt_setprop_inplace() replaces the value of a given property with
|
---|
1379 | * the data in val, of length len. This function cannot change the
|
---|
1380 | * size of a property, and so will only work if len is equal to the
|
---|
1381 | * current length of the property.
|
---|
1382 | *
|
---|
1383 | * This function will alter only the bytes in the blob which contain
|
---|
1384 | * the given property value, and will not alter or move any other part
|
---|
1385 | * of the tree.
|
---|
1386 | *
|
---|
1387 | * returns:
|
---|
1388 | * 0, on success
|
---|
1389 | * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
|
---|
1390 | * -FDT_ERR_NOTFOUND, node does not have the named property
|
---|
1391 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1392 | * -FDT_ERR_BADMAGIC,
|
---|
1393 | * -FDT_ERR_BADVERSION,
|
---|
1394 | * -FDT_ERR_BADSTATE,
|
---|
1395 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1396 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1397 | */
|
---|
1398 | #ifndef SWIG /* Not available in Python */
|
---|
1399 | int
|
---|
1400 | fdt_setprop_inplace (
|
---|
1401 | void *fdt,
|
---|
1402 | int nodeoffset,
|
---|
1403 | const char *name,
|
---|
1404 | const void *val,
|
---|
1405 | int len
|
---|
1406 | );
|
---|
1407 |
|
---|
1408 | #endif
|
---|
1409 |
|
---|
1410 | /**
|
---|
1411 | * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
|
---|
1412 | * @fdt: pointer to the device tree blob
|
---|
1413 | * @nodeoffset: offset of the node whose property to change
|
---|
1414 | * @name: name of the property to change
|
---|
1415 | * @val: 32-bit integer value to replace the property with
|
---|
1416 | *
|
---|
1417 | * fdt_setprop_inplace_u32() replaces the value of a given property
|
---|
1418 | * with the 32-bit integer value in val, converting val to big-endian
|
---|
1419 | * if necessary. This function cannot change the size of a property,
|
---|
1420 | * and so will only work if the property already exists and has length
|
---|
1421 | * 4.
|
---|
1422 | *
|
---|
1423 | * This function will alter only the bytes in the blob which contain
|
---|
1424 | * the given property value, and will not alter or move any other part
|
---|
1425 | * of the tree.
|
---|
1426 | *
|
---|
1427 | * returns:
|
---|
1428 | * 0, on success
|
---|
1429 | * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
|
---|
1430 | * -FDT_ERR_NOTFOUND, node does not have the named property
|
---|
1431 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1432 | * -FDT_ERR_BADMAGIC,
|
---|
1433 | * -FDT_ERR_BADVERSION,
|
---|
1434 | * -FDT_ERR_BADSTATE,
|
---|
1435 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1436 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1437 | */
|
---|
1438 | static inline int
|
---|
1439 | fdt_setprop_inplace_u32 (
|
---|
1440 | void *fdt,
|
---|
1441 | int nodeoffset,
|
---|
1442 | const char *name,
|
---|
1443 | uint32_t val
|
---|
1444 | )
|
---|
1445 | {
|
---|
1446 | fdt32_t tmp = cpu_to_fdt32 (val);
|
---|
1447 |
|
---|
1448 | return fdt_setprop_inplace (fdt, nodeoffset, name, &tmp, sizeof (tmp));
|
---|
1449 | }
|
---|
1450 |
|
---|
1451 | /**
|
---|
1452 | * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
|
---|
1453 | * @fdt: pointer to the device tree blob
|
---|
1454 | * @nodeoffset: offset of the node whose property to change
|
---|
1455 | * @name: name of the property to change
|
---|
1456 | * @val: 64-bit integer value to replace the property with
|
---|
1457 | *
|
---|
1458 | * fdt_setprop_inplace_u64() replaces the value of a given property
|
---|
1459 | * with the 64-bit integer value in val, converting val to big-endian
|
---|
1460 | * if necessary. This function cannot change the size of a property,
|
---|
1461 | * and so will only work if the property already exists and has length
|
---|
1462 | * 8.
|
---|
1463 | *
|
---|
1464 | * This function will alter only the bytes in the blob which contain
|
---|
1465 | * the given property value, and will not alter or move any other part
|
---|
1466 | * of the tree.
|
---|
1467 | *
|
---|
1468 | * returns:
|
---|
1469 | * 0, on success
|
---|
1470 | * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
|
---|
1471 | * -FDT_ERR_NOTFOUND, node does not have the named property
|
---|
1472 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1473 | * -FDT_ERR_BADMAGIC,
|
---|
1474 | * -FDT_ERR_BADVERSION,
|
---|
1475 | * -FDT_ERR_BADSTATE,
|
---|
1476 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1477 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1478 | */
|
---|
1479 | static inline int
|
---|
1480 | fdt_setprop_inplace_u64 (
|
---|
1481 | void *fdt,
|
---|
1482 | int nodeoffset,
|
---|
1483 | const char *name,
|
---|
1484 | uint64_t val
|
---|
1485 | )
|
---|
1486 | {
|
---|
1487 | fdt64_t tmp = cpu_to_fdt64 (val);
|
---|
1488 |
|
---|
1489 | return fdt_setprop_inplace (fdt, nodeoffset, name, &tmp, sizeof (tmp));
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 | /**
|
---|
1493 | * fdt_setprop_inplace_cell - change the value of a single-cell property
|
---|
1494 | *
|
---|
1495 | * This is an alternative name for fdt_setprop_inplace_u32()
|
---|
1496 | */
|
---|
1497 | static inline int
|
---|
1498 | fdt_setprop_inplace_cell (
|
---|
1499 | void *fdt,
|
---|
1500 | int nodeoffset,
|
---|
1501 | const char *name,
|
---|
1502 | uint32_t val
|
---|
1503 | )
|
---|
1504 | {
|
---|
1505 | return fdt_setprop_inplace_u32 (fdt, nodeoffset, name, val);
|
---|
1506 | }
|
---|
1507 |
|
---|
1508 | /**
|
---|
1509 | * fdt_nop_property - replace a property with nop tags
|
---|
1510 | * @fdt: pointer to the device tree blob
|
---|
1511 | * @nodeoffset: offset of the node whose property to nop
|
---|
1512 | * @name: name of the property to nop
|
---|
1513 | *
|
---|
1514 | * fdt_nop_property() will replace a given property's representation
|
---|
1515 | * in the blob with FDT_NOP tags, effectively removing it from the
|
---|
1516 | * tree.
|
---|
1517 | *
|
---|
1518 | * This function will alter only the bytes in the blob which contain
|
---|
1519 | * the property, and will not alter or move any other part of the
|
---|
1520 | * tree.
|
---|
1521 | *
|
---|
1522 | * returns:
|
---|
1523 | * 0, on success
|
---|
1524 | * -FDT_ERR_NOTFOUND, node does not have the named property
|
---|
1525 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1526 | * -FDT_ERR_BADMAGIC,
|
---|
1527 | * -FDT_ERR_BADVERSION,
|
---|
1528 | * -FDT_ERR_BADSTATE,
|
---|
1529 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1530 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1531 | */
|
---|
1532 | int
|
---|
1533 | fdt_nop_property (
|
---|
1534 | void *fdt,
|
---|
1535 | int nodeoffset,
|
---|
1536 | const char *name
|
---|
1537 | );
|
---|
1538 |
|
---|
1539 | /**
|
---|
1540 | * fdt_nop_node - replace a node (subtree) with nop tags
|
---|
1541 | * @fdt: pointer to the device tree blob
|
---|
1542 | * @nodeoffset: offset of the node to nop
|
---|
1543 | *
|
---|
1544 | * fdt_nop_node() will replace a given node's representation in the
|
---|
1545 | * blob, including all its subnodes, if any, with FDT_NOP tags,
|
---|
1546 | * effectively removing it from the tree.
|
---|
1547 | *
|
---|
1548 | * This function will alter only the bytes in the blob which contain
|
---|
1549 | * the node and its properties and subnodes, and will not alter or
|
---|
1550 | * move any other part of the tree.
|
---|
1551 | *
|
---|
1552 | * returns:
|
---|
1553 | * 0, on success
|
---|
1554 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1555 | * -FDT_ERR_BADMAGIC,
|
---|
1556 | * -FDT_ERR_BADVERSION,
|
---|
1557 | * -FDT_ERR_BADSTATE,
|
---|
1558 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1559 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1560 | */
|
---|
1561 | int
|
---|
1562 | fdt_nop_node (
|
---|
1563 | void *fdt,
|
---|
1564 | int nodeoffset
|
---|
1565 | );
|
---|
1566 |
|
---|
1567 | /**********************************************************************/
|
---|
1568 | /* Sequential write functions */
|
---|
1569 | /**********************************************************************/
|
---|
1570 |
|
---|
1571 | int
|
---|
1572 | fdt_create (
|
---|
1573 | void *buf,
|
---|
1574 | int bufsize
|
---|
1575 | );
|
---|
1576 |
|
---|
1577 | int
|
---|
1578 | fdt_resize (
|
---|
1579 | void *fdt,
|
---|
1580 | void *buf,
|
---|
1581 | int bufsize
|
---|
1582 | );
|
---|
1583 |
|
---|
1584 | int
|
---|
1585 | fdt_add_reservemap_entry (
|
---|
1586 | void *fdt,
|
---|
1587 | uint64_t addr,
|
---|
1588 | uint64_t size
|
---|
1589 | );
|
---|
1590 |
|
---|
1591 | int
|
---|
1592 | fdt_finish_reservemap (
|
---|
1593 | void *fdt
|
---|
1594 | );
|
---|
1595 |
|
---|
1596 | int
|
---|
1597 | fdt_begin_node (
|
---|
1598 | void *fdt,
|
---|
1599 | const char *name
|
---|
1600 | );
|
---|
1601 |
|
---|
1602 | int
|
---|
1603 | fdt_property (
|
---|
1604 | void *fdt,
|
---|
1605 | const char *name,
|
---|
1606 | const void *val,
|
---|
1607 | int len
|
---|
1608 | );
|
---|
1609 |
|
---|
1610 | static inline int
|
---|
1611 | fdt_property_u32 (
|
---|
1612 | void *fdt,
|
---|
1613 | const char *name,
|
---|
1614 | uint32_t val
|
---|
1615 | )
|
---|
1616 | {
|
---|
1617 | fdt32_t tmp = cpu_to_fdt32 (val);
|
---|
1618 |
|
---|
1619 | return fdt_property (fdt, name, &tmp, sizeof (tmp));
|
---|
1620 | }
|
---|
1621 |
|
---|
1622 | static inline int
|
---|
1623 | fdt_property_u64 (
|
---|
1624 | void *fdt,
|
---|
1625 | const char *name,
|
---|
1626 | uint64_t val
|
---|
1627 | )
|
---|
1628 | {
|
---|
1629 | fdt64_t tmp = cpu_to_fdt64 (val);
|
---|
1630 |
|
---|
1631 | return fdt_property (fdt, name, &tmp, sizeof (tmp));
|
---|
1632 | }
|
---|
1633 |
|
---|
1634 | static inline int
|
---|
1635 | fdt_property_cell (
|
---|
1636 | void *fdt,
|
---|
1637 | const char *name,
|
---|
1638 | uint32_t val
|
---|
1639 | )
|
---|
1640 | {
|
---|
1641 | return fdt_property_u32 (fdt, name, val);
|
---|
1642 | }
|
---|
1643 |
|
---|
1644 | /**
|
---|
1645 | * fdt_property_placeholder - add a new property and return a ptr to its value
|
---|
1646 | *
|
---|
1647 | * @fdt: pointer to the device tree blob
|
---|
1648 | * @name: name of property to add
|
---|
1649 | * @len: length of property value in bytes
|
---|
1650 | * @valp: returns a pointer to where where the value should be placed
|
---|
1651 | *
|
---|
1652 | * returns:
|
---|
1653 | * 0, on success
|
---|
1654 | * -FDT_ERR_BADMAGIC,
|
---|
1655 | * -FDT_ERR_NOSPACE, standard meanings
|
---|
1656 | */
|
---|
1657 | int
|
---|
1658 | fdt_property_placeholder (
|
---|
1659 | void *fdt,
|
---|
1660 | const char *name,
|
---|
1661 | int len,
|
---|
1662 | void **valp
|
---|
1663 | );
|
---|
1664 |
|
---|
1665 | #define fdt_property_string(fdt, name, str) \
|
---|
1666 | fdt_property(fdt, name, str, strlen(str)+1)
|
---|
1667 | int
|
---|
1668 | fdt_end_node (
|
---|
1669 | void *fdt
|
---|
1670 | );
|
---|
1671 |
|
---|
1672 | int
|
---|
1673 | fdt_finish (
|
---|
1674 | void *fdt
|
---|
1675 | );
|
---|
1676 |
|
---|
1677 | /**********************************************************************/
|
---|
1678 | /* Read-write functions */
|
---|
1679 | /**********************************************************************/
|
---|
1680 |
|
---|
1681 | int
|
---|
1682 | fdt_create_empty_tree (
|
---|
1683 | void *buf,
|
---|
1684 | int bufsize
|
---|
1685 | );
|
---|
1686 |
|
---|
1687 | int
|
---|
1688 | fdt_open_into (
|
---|
1689 | const void *fdt,
|
---|
1690 | void *buf,
|
---|
1691 | int bufsize
|
---|
1692 | );
|
---|
1693 |
|
---|
1694 | int
|
---|
1695 | fdt_pack (
|
---|
1696 | void *fdt
|
---|
1697 | );
|
---|
1698 |
|
---|
1699 | /**
|
---|
1700 | * fdt_add_mem_rsv - add one memory reserve map entry
|
---|
1701 | * @fdt: pointer to the device tree blob
|
---|
1702 | * @address, @size: 64-bit values (native endian)
|
---|
1703 | *
|
---|
1704 | * Adds a reserve map entry to the given blob reserving a region at
|
---|
1705 | * address address of length size.
|
---|
1706 | *
|
---|
1707 | * This function will insert data into the reserve map and will
|
---|
1708 | * therefore change the indexes of some entries in the table.
|
---|
1709 | *
|
---|
1710 | * returns:
|
---|
1711 | * 0, on success
|
---|
1712 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
1713 | * contain the new reservation entry
|
---|
1714 | * -FDT_ERR_BADMAGIC,
|
---|
1715 | * -FDT_ERR_BADVERSION,
|
---|
1716 | * -FDT_ERR_BADSTATE,
|
---|
1717 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1718 | * -FDT_ERR_BADLAYOUT,
|
---|
1719 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1720 | */
|
---|
1721 | int
|
---|
1722 | fdt_add_mem_rsv (
|
---|
1723 | void *fdt,
|
---|
1724 | uint64_t address,
|
---|
1725 | uint64_t size
|
---|
1726 | );
|
---|
1727 |
|
---|
1728 | /**
|
---|
1729 | * fdt_del_mem_rsv - remove a memory reserve map entry
|
---|
1730 | * @fdt: pointer to the device tree blob
|
---|
1731 | * @n: entry to remove
|
---|
1732 | *
|
---|
1733 | * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
|
---|
1734 | * the blob.
|
---|
1735 | *
|
---|
1736 | * This function will delete data from the reservation table and will
|
---|
1737 | * therefore change the indexes of some entries in the table.
|
---|
1738 | *
|
---|
1739 | * returns:
|
---|
1740 | * 0, on success
|
---|
1741 | * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
|
---|
1742 | * are less than n+1 reserve map entries)
|
---|
1743 | * -FDT_ERR_BADMAGIC,
|
---|
1744 | * -FDT_ERR_BADVERSION,
|
---|
1745 | * -FDT_ERR_BADSTATE,
|
---|
1746 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1747 | * -FDT_ERR_BADLAYOUT,
|
---|
1748 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1749 | */
|
---|
1750 | int
|
---|
1751 | fdt_del_mem_rsv (
|
---|
1752 | void *fdt,
|
---|
1753 | int n
|
---|
1754 | );
|
---|
1755 |
|
---|
1756 | /**
|
---|
1757 | * fdt_set_name - change the name of a given node
|
---|
1758 | * @fdt: pointer to the device tree blob
|
---|
1759 | * @nodeoffset: structure block offset of a node
|
---|
1760 | * @name: name to give the node
|
---|
1761 | *
|
---|
1762 | * fdt_set_name() replaces the name (including unit address, if any)
|
---|
1763 | * of the given node with the given string. NOTE: this function can't
|
---|
1764 | * efficiently check if the new name is unique amongst the given
|
---|
1765 | * node's siblings; results are undefined if this function is invoked
|
---|
1766 | * with a name equal to one of the given node's siblings.
|
---|
1767 | *
|
---|
1768 | * This function may insert or delete data from the blob, and will
|
---|
1769 | * therefore change the offsets of some existing nodes.
|
---|
1770 | *
|
---|
1771 | * returns:
|
---|
1772 | * 0, on success
|
---|
1773 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
|
---|
1774 | * to contain the new name
|
---|
1775 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1776 | * -FDT_ERR_BADMAGIC,
|
---|
1777 | * -FDT_ERR_BADVERSION,
|
---|
1778 | * -FDT_ERR_BADSTATE, standard meanings
|
---|
1779 | */
|
---|
1780 | int
|
---|
1781 | fdt_set_name (
|
---|
1782 | void *fdt,
|
---|
1783 | int nodeoffset,
|
---|
1784 | const char *name
|
---|
1785 | );
|
---|
1786 |
|
---|
1787 | /**
|
---|
1788 | * fdt_setprop - create or change a property
|
---|
1789 | * @fdt: pointer to the device tree blob
|
---|
1790 | * @nodeoffset: offset of the node whose property to change
|
---|
1791 | * @name: name of the property to change
|
---|
1792 | * @val: pointer to data to set the property value to
|
---|
1793 | * @len: length of the property value
|
---|
1794 | *
|
---|
1795 | * fdt_setprop() sets the value of the named property in the given
|
---|
1796 | * node to the given value and length, creating the property if it
|
---|
1797 | * does not already exist.
|
---|
1798 | *
|
---|
1799 | * This function may insert or delete data from the blob, and will
|
---|
1800 | * therefore change the offsets of some existing nodes.
|
---|
1801 | *
|
---|
1802 | * returns:
|
---|
1803 | * 0, on success
|
---|
1804 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
1805 | * contain the new property value
|
---|
1806 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1807 | * -FDT_ERR_BADLAYOUT,
|
---|
1808 | * -FDT_ERR_BADMAGIC,
|
---|
1809 | * -FDT_ERR_BADVERSION,
|
---|
1810 | * -FDT_ERR_BADSTATE,
|
---|
1811 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1812 | * -FDT_ERR_BADLAYOUT,
|
---|
1813 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1814 | */
|
---|
1815 | int
|
---|
1816 | fdt_setprop (
|
---|
1817 | void *fdt,
|
---|
1818 | int nodeoffset,
|
---|
1819 | const char *name,
|
---|
1820 | const void *val,
|
---|
1821 | int len
|
---|
1822 | );
|
---|
1823 |
|
---|
1824 | /**
|
---|
1825 | * fdt_setprop _placeholder - allocate space for a property
|
---|
1826 | * @fdt: pointer to the device tree blob
|
---|
1827 | * @nodeoffset: offset of the node whose property to change
|
---|
1828 | * @name: name of the property to change
|
---|
1829 | * @len: length of the property value
|
---|
1830 | * @prop_data: return pointer to property data
|
---|
1831 | *
|
---|
1832 | * fdt_setprop_placeholer() allocates the named property in the given node.
|
---|
1833 | * If the property exists it is resized. In either case a pointer to the
|
---|
1834 | * property data is returned.
|
---|
1835 | *
|
---|
1836 | * This function may insert or delete data from the blob, and will
|
---|
1837 | * therefore change the offsets of some existing nodes.
|
---|
1838 | *
|
---|
1839 | * returns:
|
---|
1840 | * 0, on success
|
---|
1841 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
1842 | * contain the new property value
|
---|
1843 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1844 | * -FDT_ERR_BADLAYOUT,
|
---|
1845 | * -FDT_ERR_BADMAGIC,
|
---|
1846 | * -FDT_ERR_BADVERSION,
|
---|
1847 | * -FDT_ERR_BADSTATE,
|
---|
1848 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1849 | * -FDT_ERR_BADLAYOUT,
|
---|
1850 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1851 | */
|
---|
1852 | int
|
---|
1853 | fdt_setprop_placeholder (
|
---|
1854 | void *fdt,
|
---|
1855 | int nodeoffset,
|
---|
1856 | const char *name,
|
---|
1857 | int len,
|
---|
1858 | void **prop_data
|
---|
1859 | );
|
---|
1860 |
|
---|
1861 | /**
|
---|
1862 | * fdt_setprop_u32 - set a property to a 32-bit integer
|
---|
1863 | * @fdt: pointer to the device tree blob
|
---|
1864 | * @nodeoffset: offset of the node whose property to change
|
---|
1865 | * @name: name of the property to change
|
---|
1866 | * @val: 32-bit integer value for the property (native endian)
|
---|
1867 | *
|
---|
1868 | * fdt_setprop_u32() sets the value of the named property in the given
|
---|
1869 | * node to the given 32-bit integer value (converting to big-endian if
|
---|
1870 | * necessary), or creates a new property with that value if it does
|
---|
1871 | * not already exist.
|
---|
1872 | *
|
---|
1873 | * This function may insert or delete data from the blob, and will
|
---|
1874 | * therefore change the offsets of some existing nodes.
|
---|
1875 | *
|
---|
1876 | * returns:
|
---|
1877 | * 0, on success
|
---|
1878 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
1879 | * contain the new property value
|
---|
1880 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1881 | * -FDT_ERR_BADLAYOUT,
|
---|
1882 | * -FDT_ERR_BADMAGIC,
|
---|
1883 | * -FDT_ERR_BADVERSION,
|
---|
1884 | * -FDT_ERR_BADSTATE,
|
---|
1885 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1886 | * -FDT_ERR_BADLAYOUT,
|
---|
1887 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1888 | */
|
---|
1889 | static inline int
|
---|
1890 | fdt_setprop_u32 (
|
---|
1891 | void *fdt,
|
---|
1892 | int nodeoffset,
|
---|
1893 | const char *name,
|
---|
1894 | uint32_t val
|
---|
1895 | )
|
---|
1896 | {
|
---|
1897 | fdt32_t tmp = cpu_to_fdt32 (val);
|
---|
1898 |
|
---|
1899 | return fdt_setprop (fdt, nodeoffset, name, &tmp, sizeof (tmp));
|
---|
1900 | }
|
---|
1901 |
|
---|
1902 | /**
|
---|
1903 | * fdt_setprop_u64 - set a property to a 64-bit integer
|
---|
1904 | * @fdt: pointer to the device tree blob
|
---|
1905 | * @nodeoffset: offset of the node whose property to change
|
---|
1906 | * @name: name of the property to change
|
---|
1907 | * @val: 64-bit integer value for the property (native endian)
|
---|
1908 | *
|
---|
1909 | * fdt_setprop_u64() sets the value of the named property in the given
|
---|
1910 | * node to the given 64-bit integer value (converting to big-endian if
|
---|
1911 | * necessary), or creates a new property with that value if it does
|
---|
1912 | * not already exist.
|
---|
1913 | *
|
---|
1914 | * This function may insert or delete data from the blob, and will
|
---|
1915 | * therefore change the offsets of some existing nodes.
|
---|
1916 | *
|
---|
1917 | * returns:
|
---|
1918 | * 0, on success
|
---|
1919 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
1920 | * contain the new property value
|
---|
1921 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1922 | * -FDT_ERR_BADLAYOUT,
|
---|
1923 | * -FDT_ERR_BADMAGIC,
|
---|
1924 | * -FDT_ERR_BADVERSION,
|
---|
1925 | * -FDT_ERR_BADSTATE,
|
---|
1926 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1927 | * -FDT_ERR_BADLAYOUT,
|
---|
1928 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1929 | */
|
---|
1930 | static inline int
|
---|
1931 | fdt_setprop_u64 (
|
---|
1932 | void *fdt,
|
---|
1933 | int nodeoffset,
|
---|
1934 | const char *name,
|
---|
1935 | uint64_t val
|
---|
1936 | )
|
---|
1937 | {
|
---|
1938 | fdt64_t tmp = cpu_to_fdt64 (val);
|
---|
1939 |
|
---|
1940 | return fdt_setprop (fdt, nodeoffset, name, &tmp, sizeof (tmp));
|
---|
1941 | }
|
---|
1942 |
|
---|
1943 | /**
|
---|
1944 | * fdt_setprop_cell - set a property to a single cell value
|
---|
1945 | *
|
---|
1946 | * This is an alternative name for fdt_setprop_u32()
|
---|
1947 | */
|
---|
1948 | static inline int
|
---|
1949 | fdt_setprop_cell (
|
---|
1950 | void *fdt,
|
---|
1951 | int nodeoffset,
|
---|
1952 | const char *name,
|
---|
1953 | uint32_t val
|
---|
1954 | )
|
---|
1955 | {
|
---|
1956 | return fdt_setprop_u32 (fdt, nodeoffset, name, val);
|
---|
1957 | }
|
---|
1958 |
|
---|
1959 | /**
|
---|
1960 | * fdt_setprop_string - set a property to a string value
|
---|
1961 | * @fdt: pointer to the device tree blob
|
---|
1962 | * @nodeoffset: offset of the node whose property to change
|
---|
1963 | * @name: name of the property to change
|
---|
1964 | * @str: string value for the property
|
---|
1965 | *
|
---|
1966 | * fdt_setprop_string() sets the value of the named property in the
|
---|
1967 | * given node to the given string value (using the length of the
|
---|
1968 | * string to determine the new length of the property), or creates a
|
---|
1969 | * new property with that value if it does not already exist.
|
---|
1970 | *
|
---|
1971 | * This function may insert or delete data from the blob, and will
|
---|
1972 | * therefore change the offsets of some existing nodes.
|
---|
1973 | *
|
---|
1974 | * returns:
|
---|
1975 | * 0, on success
|
---|
1976 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
1977 | * contain the new property value
|
---|
1978 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
1979 | * -FDT_ERR_BADLAYOUT,
|
---|
1980 | * -FDT_ERR_BADMAGIC,
|
---|
1981 | * -FDT_ERR_BADVERSION,
|
---|
1982 | * -FDT_ERR_BADSTATE,
|
---|
1983 | * -FDT_ERR_BADSTRUCTURE,
|
---|
1984 | * -FDT_ERR_BADLAYOUT,
|
---|
1985 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
1986 | */
|
---|
1987 | #define fdt_setprop_string(fdt, nodeoffset, name, str) \
|
---|
1988 | fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
|
---|
1989 |
|
---|
1990 | /**
|
---|
1991 | * fdt_setprop_empty - set a property to an empty value
|
---|
1992 | * @fdt: pointer to the device tree blob
|
---|
1993 | * @nodeoffset: offset of the node whose property to change
|
---|
1994 | * @name: name of the property to change
|
---|
1995 | *
|
---|
1996 | * fdt_setprop_empty() sets the value of the named property in the
|
---|
1997 | * given node to an empty (zero length) value, or creates a new empty
|
---|
1998 | * property if it does not already exist.
|
---|
1999 | *
|
---|
2000 | * This function may insert or delete data from the blob, and will
|
---|
2001 | * therefore change the offsets of some existing nodes.
|
---|
2002 | *
|
---|
2003 | * returns:
|
---|
2004 | * 0, on success
|
---|
2005 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
2006 | * contain the new property value
|
---|
2007 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
2008 | * -FDT_ERR_BADLAYOUT,
|
---|
2009 | * -FDT_ERR_BADMAGIC,
|
---|
2010 | * -FDT_ERR_BADVERSION,
|
---|
2011 | * -FDT_ERR_BADSTATE,
|
---|
2012 | * -FDT_ERR_BADSTRUCTURE,
|
---|
2013 | * -FDT_ERR_BADLAYOUT,
|
---|
2014 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
2015 | */
|
---|
2016 | #define fdt_setprop_empty(fdt, nodeoffset, name) \
|
---|
2017 | fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
|
---|
2018 |
|
---|
2019 | /**
|
---|
2020 | * fdt_appendprop - append to or create a property
|
---|
2021 | * @fdt: pointer to the device tree blob
|
---|
2022 | * @nodeoffset: offset of the node whose property to change
|
---|
2023 | * @name: name of the property to append to
|
---|
2024 | * @val: pointer to data to append to the property value
|
---|
2025 | * @len: length of the data to append to the property value
|
---|
2026 | *
|
---|
2027 | * fdt_appendprop() appends the value to the named property in the
|
---|
2028 | * given node, creating the property if it does not already exist.
|
---|
2029 | *
|
---|
2030 | * This function may insert data into the blob, and will therefore
|
---|
2031 | * change the offsets of some existing nodes.
|
---|
2032 | *
|
---|
2033 | * returns:
|
---|
2034 | * 0, on success
|
---|
2035 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
2036 | * contain the new property value
|
---|
2037 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
2038 | * -FDT_ERR_BADLAYOUT,
|
---|
2039 | * -FDT_ERR_BADMAGIC,
|
---|
2040 | * -FDT_ERR_BADVERSION,
|
---|
2041 | * -FDT_ERR_BADSTATE,
|
---|
2042 | * -FDT_ERR_BADSTRUCTURE,
|
---|
2043 | * -FDT_ERR_BADLAYOUT,
|
---|
2044 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
2045 | */
|
---|
2046 | int
|
---|
2047 | fdt_appendprop (
|
---|
2048 | void *fdt,
|
---|
2049 | int nodeoffset,
|
---|
2050 | const char *name,
|
---|
2051 | const void *val,
|
---|
2052 | int len
|
---|
2053 | );
|
---|
2054 |
|
---|
2055 | /**
|
---|
2056 | * fdt_appendprop_u32 - append a 32-bit integer value to a property
|
---|
2057 | * @fdt: pointer to the device tree blob
|
---|
2058 | * @nodeoffset: offset of the node whose property to change
|
---|
2059 | * @name: name of the property to change
|
---|
2060 | * @val: 32-bit integer value to append to the property (native endian)
|
---|
2061 | *
|
---|
2062 | * fdt_appendprop_u32() appends the given 32-bit integer value
|
---|
2063 | * (converting to big-endian if necessary) to the value of the named
|
---|
2064 | * property in the given node, or creates a new property with that
|
---|
2065 | * value if it does not already exist.
|
---|
2066 | *
|
---|
2067 | * This function may insert data into the blob, and will therefore
|
---|
2068 | * change the offsets of some existing nodes.
|
---|
2069 | *
|
---|
2070 | * returns:
|
---|
2071 | * 0, on success
|
---|
2072 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
2073 | * contain the new property value
|
---|
2074 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
2075 | * -FDT_ERR_BADLAYOUT,
|
---|
2076 | * -FDT_ERR_BADMAGIC,
|
---|
2077 | * -FDT_ERR_BADVERSION,
|
---|
2078 | * -FDT_ERR_BADSTATE,
|
---|
2079 | * -FDT_ERR_BADSTRUCTURE,
|
---|
2080 | * -FDT_ERR_BADLAYOUT,
|
---|
2081 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
2082 | */
|
---|
2083 | static inline int
|
---|
2084 | fdt_appendprop_u32 (
|
---|
2085 | void *fdt,
|
---|
2086 | int nodeoffset,
|
---|
2087 | const char *name,
|
---|
2088 | uint32_t val
|
---|
2089 | )
|
---|
2090 | {
|
---|
2091 | fdt32_t tmp = cpu_to_fdt32 (val);
|
---|
2092 |
|
---|
2093 | return fdt_appendprop (fdt, nodeoffset, name, &tmp, sizeof (tmp));
|
---|
2094 | }
|
---|
2095 |
|
---|
2096 | /**
|
---|
2097 | * fdt_appendprop_u64 - append a 64-bit integer value to a property
|
---|
2098 | * @fdt: pointer to the device tree blob
|
---|
2099 | * @nodeoffset: offset of the node whose property to change
|
---|
2100 | * @name: name of the property to change
|
---|
2101 | * @val: 64-bit integer value to append to the property (native endian)
|
---|
2102 | *
|
---|
2103 | * fdt_appendprop_u64() appends the given 64-bit integer value
|
---|
2104 | * (converting to big-endian if necessary) to the value of the named
|
---|
2105 | * property in the given node, or creates a new property with that
|
---|
2106 | * value if it does not already exist.
|
---|
2107 | *
|
---|
2108 | * This function may insert data into the blob, and will therefore
|
---|
2109 | * change the offsets of some existing nodes.
|
---|
2110 | *
|
---|
2111 | * returns:
|
---|
2112 | * 0, on success
|
---|
2113 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
2114 | * contain the new property value
|
---|
2115 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
2116 | * -FDT_ERR_BADLAYOUT,
|
---|
2117 | * -FDT_ERR_BADMAGIC,
|
---|
2118 | * -FDT_ERR_BADVERSION,
|
---|
2119 | * -FDT_ERR_BADSTATE,
|
---|
2120 | * -FDT_ERR_BADSTRUCTURE,
|
---|
2121 | * -FDT_ERR_BADLAYOUT,
|
---|
2122 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
2123 | */
|
---|
2124 | static inline int
|
---|
2125 | fdt_appendprop_u64 (
|
---|
2126 | void *fdt,
|
---|
2127 | int nodeoffset,
|
---|
2128 | const char *name,
|
---|
2129 | uint64_t val
|
---|
2130 | )
|
---|
2131 | {
|
---|
2132 | fdt64_t tmp = cpu_to_fdt64 (val);
|
---|
2133 |
|
---|
2134 | return fdt_appendprop (fdt, nodeoffset, name, &tmp, sizeof (tmp));
|
---|
2135 | }
|
---|
2136 |
|
---|
2137 | /**
|
---|
2138 | * fdt_appendprop_cell - append a single cell value to a property
|
---|
2139 | *
|
---|
2140 | * This is an alternative name for fdt_appendprop_u32()
|
---|
2141 | */
|
---|
2142 | static inline int
|
---|
2143 | fdt_appendprop_cell (
|
---|
2144 | void *fdt,
|
---|
2145 | int nodeoffset,
|
---|
2146 | const char *name,
|
---|
2147 | uint32_t val
|
---|
2148 | )
|
---|
2149 | {
|
---|
2150 | return fdt_appendprop_u32 (fdt, nodeoffset, name, val);
|
---|
2151 | }
|
---|
2152 |
|
---|
2153 | /**
|
---|
2154 | * fdt_appendprop_string - append a string to a property
|
---|
2155 | * @fdt: pointer to the device tree blob
|
---|
2156 | * @nodeoffset: offset of the node whose property to change
|
---|
2157 | * @name: name of the property to change
|
---|
2158 | * @str: string value to append to the property
|
---|
2159 | *
|
---|
2160 | * fdt_appendprop_string() appends the given string to the value of
|
---|
2161 | * the named property in the given node, or creates a new property
|
---|
2162 | * with that value if it does not already exist.
|
---|
2163 | *
|
---|
2164 | * This function may insert data into the blob, and will therefore
|
---|
2165 | * change the offsets of some existing nodes.
|
---|
2166 | *
|
---|
2167 | * returns:
|
---|
2168 | * 0, on success
|
---|
2169 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
---|
2170 | * contain the new property value
|
---|
2171 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
2172 | * -FDT_ERR_BADLAYOUT,
|
---|
2173 | * -FDT_ERR_BADMAGIC,
|
---|
2174 | * -FDT_ERR_BADVERSION,
|
---|
2175 | * -FDT_ERR_BADSTATE,
|
---|
2176 | * -FDT_ERR_BADSTRUCTURE,
|
---|
2177 | * -FDT_ERR_BADLAYOUT,
|
---|
2178 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
2179 | */
|
---|
2180 | #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
|
---|
2181 | fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
|
---|
2182 |
|
---|
2183 | /**
|
---|
2184 | * fdt_delprop - delete a property
|
---|
2185 | * @fdt: pointer to the device tree blob
|
---|
2186 | * @nodeoffset: offset of the node whose property to nop
|
---|
2187 | * @name: name of the property to nop
|
---|
2188 | *
|
---|
2189 | * fdt_del_property() will delete the given property.
|
---|
2190 | *
|
---|
2191 | * This function will delete data from the blob, and will therefore
|
---|
2192 | * change the offsets of some existing nodes.
|
---|
2193 | *
|
---|
2194 | * returns:
|
---|
2195 | * 0, on success
|
---|
2196 | * -FDT_ERR_NOTFOUND, node does not have the named property
|
---|
2197 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
2198 | * -FDT_ERR_BADLAYOUT,
|
---|
2199 | * -FDT_ERR_BADMAGIC,
|
---|
2200 | * -FDT_ERR_BADVERSION,
|
---|
2201 | * -FDT_ERR_BADSTATE,
|
---|
2202 | * -FDT_ERR_BADSTRUCTURE,
|
---|
2203 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
2204 | */
|
---|
2205 | int
|
---|
2206 | fdt_delprop (
|
---|
2207 | void *fdt,
|
---|
2208 | int nodeoffset,
|
---|
2209 | const char *name
|
---|
2210 | );
|
---|
2211 |
|
---|
2212 | /**
|
---|
2213 | * fdt_add_subnode_namelen - creates a new node based on substring
|
---|
2214 | * @fdt: pointer to the device tree blob
|
---|
2215 | * @parentoffset: structure block offset of a node
|
---|
2216 | * @name: name of the subnode to locate
|
---|
2217 | * @namelen: number of characters of name to consider
|
---|
2218 | *
|
---|
2219 | * Identical to fdt_add_subnode(), but use only the first namelen
|
---|
2220 | * characters of name as the name of the new node. This is useful for
|
---|
2221 | * creating subnodes based on a portion of a larger string, such as a
|
---|
2222 | * full path.
|
---|
2223 | */
|
---|
2224 | #ifndef SWIG /* Not available in Python */
|
---|
2225 | int
|
---|
2226 | fdt_add_subnode_namelen (
|
---|
2227 | void *fdt,
|
---|
2228 | int parentoffset,
|
---|
2229 | const char *name,
|
---|
2230 | int namelen
|
---|
2231 | );
|
---|
2232 |
|
---|
2233 | #endif
|
---|
2234 |
|
---|
2235 | /**
|
---|
2236 | * fdt_add_subnode - creates a new node
|
---|
2237 | * @fdt: pointer to the device tree blob
|
---|
2238 | * @parentoffset: structure block offset of a node
|
---|
2239 | * @name: name of the subnode to locate
|
---|
2240 | *
|
---|
2241 | * fdt_add_subnode() creates a new node as a subnode of the node at
|
---|
2242 | * structure block offset parentoffset, with the given name (which
|
---|
2243 | * should include the unit address, if any).
|
---|
2244 | *
|
---|
2245 | * This function will insert data into the blob, and will therefore
|
---|
2246 | * change the offsets of some existing nodes.
|
---|
2247 |
|
---|
2248 | * returns:
|
---|
2249 | * structure block offset of the created nodeequested subnode (>=0), on
|
---|
2250 | * success
|
---|
2251 | * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
|
---|
2252 | * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
|
---|
2253 | * tag
|
---|
2254 | * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
|
---|
2255 | * the given name
|
---|
2256 | * -FDT_ERR_NOSPACE, if there is insufficient free space in the
|
---|
2257 | * blob to contain the new node
|
---|
2258 | * -FDT_ERR_NOSPACE
|
---|
2259 | * -FDT_ERR_BADLAYOUT
|
---|
2260 | * -FDT_ERR_BADMAGIC,
|
---|
2261 | * -FDT_ERR_BADVERSION,
|
---|
2262 | * -FDT_ERR_BADSTATE,
|
---|
2263 | * -FDT_ERR_BADSTRUCTURE,
|
---|
2264 | * -FDT_ERR_TRUNCATED, standard meanings.
|
---|
2265 | */
|
---|
2266 | int
|
---|
2267 | fdt_add_subnode (
|
---|
2268 | void *fdt,
|
---|
2269 | int parentoffset,
|
---|
2270 | const char *name
|
---|
2271 | );
|
---|
2272 |
|
---|
2273 | /**
|
---|
2274 | * fdt_del_node - delete a node (subtree)
|
---|
2275 | * @fdt: pointer to the device tree blob
|
---|
2276 | * @nodeoffset: offset of the node to nop
|
---|
2277 | *
|
---|
2278 | * fdt_del_node() will remove the given node, including all its
|
---|
2279 | * subnodes if any, from the blob.
|
---|
2280 | *
|
---|
2281 | * This function will delete data from the blob, and will therefore
|
---|
2282 | * change the offsets of some existing nodes.
|
---|
2283 | *
|
---|
2284 | * returns:
|
---|
2285 | * 0, on success
|
---|
2286 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
---|
2287 | * -FDT_ERR_BADLAYOUT,
|
---|
2288 | * -FDT_ERR_BADMAGIC,
|
---|
2289 | * -FDT_ERR_BADVERSION,
|
---|
2290 | * -FDT_ERR_BADSTATE,
|
---|
2291 | * -FDT_ERR_BADSTRUCTURE,
|
---|
2292 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
2293 | */
|
---|
2294 | int
|
---|
2295 | fdt_del_node (
|
---|
2296 | void *fdt,
|
---|
2297 | int nodeoffset
|
---|
2298 | );
|
---|
2299 |
|
---|
2300 | /**
|
---|
2301 | * fdt_overlay_apply - Applies a DT overlay on a base DT
|
---|
2302 | * @fdt: pointer to the base device tree blob
|
---|
2303 | * @fdto: pointer to the device tree overlay blob
|
---|
2304 | *
|
---|
2305 | * fdt_overlay_apply() will apply the given device tree overlay on the
|
---|
2306 | * given base device tree.
|
---|
2307 | *
|
---|
2308 | * Expect the base device tree to be modified, even if the function
|
---|
2309 | * returns an error.
|
---|
2310 | *
|
---|
2311 | * returns:
|
---|
2312 | * 0, on success
|
---|
2313 | * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
|
---|
2314 | * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
|
---|
2315 | * properties in the base DT
|
---|
2316 | * -FDT_ERR_BADPHANDLE,
|
---|
2317 | * -FDT_ERR_BADOVERLAY,
|
---|
2318 | * -FDT_ERR_NOPHANDLES,
|
---|
2319 | * -FDT_ERR_INTERNAL,
|
---|
2320 | * -FDT_ERR_BADLAYOUT,
|
---|
2321 | * -FDT_ERR_BADMAGIC,
|
---|
2322 | * -FDT_ERR_BADOFFSET,
|
---|
2323 | * -FDT_ERR_BADPATH,
|
---|
2324 | * -FDT_ERR_BADVERSION,
|
---|
2325 | * -FDT_ERR_BADSTRUCTURE,
|
---|
2326 | * -FDT_ERR_BADSTATE,
|
---|
2327 | * -FDT_ERR_TRUNCATED, standard meanings
|
---|
2328 | */
|
---|
2329 | int
|
---|
2330 | fdt_overlay_apply (
|
---|
2331 | void *fdt,
|
---|
2332 | void *fdto
|
---|
2333 | );
|
---|
2334 |
|
---|
2335 | /**********************************************************************/
|
---|
2336 | /* Debugging / informational functions */
|
---|
2337 | /**********************************************************************/
|
---|
2338 |
|
---|
2339 | const char *
|
---|
2340 | fdt_strerror (
|
---|
2341 | int errval
|
---|
2342 | );
|
---|
2343 |
|
---|
2344 | #endif /* _LIBFDT_H */
|
---|