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