]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Include/libfdt.h
MmcDxe: Adding eMMC support
[mirror_edk2.git] / EmbeddedPkg / Include / libfdt.h
CommitLineData
1e57a462 1#ifndef _LIBFDT_H\r
2#define _LIBFDT_H\r
3/*\r
4 * libfdt - Flat Device Tree manipulation\r
5 * Copyright (C) 2006 David Gibson, IBM Corporation.\r
6 *\r
7 * libfdt is dual licensed: you can use it either under the terms of\r
8 * the GPL, or the BSD license, at your option.\r
9 *\r
10 * a) This library is free software; you can redistribute it and/or\r
11 * modify it under the terms of the GNU General Public License as\r
12 * published by the Free Software Foundation; either version 2 of the\r
13 * License, or (at your option) any later version.\r
14 *\r
15 * This library is distributed in the hope that it will be useful,\r
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
18 * GNU General Public License for more details.\r
19 *\r
20 * You should have received a copy of the GNU General Public\r
21 * License along with this library; if not, write to the Free\r
22 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\r
23 * MA 02110-1301 USA\r
24 *\r
25 * Alternatively,\r
26 *\r
27 * b) Redistribution and use in source and binary forms, with or\r
28 * without modification, are permitted provided that the following\r
29 * conditions are met:\r
30 *\r
31 * 1. Redistributions of source code must retain the above\r
32 * copyright notice, this list of conditions and the following\r
33 * disclaimer.\r
34 * 2. Redistributions in binary form must reproduce the above\r
35 * copyright notice, this list of conditions and the following\r
36 * disclaimer in the documentation and/or other materials\r
37 * provided with the distribution.\r
38 *\r
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
40 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
41 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
43 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
44 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
49 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
50 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
51 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
52 */\r
53\r
54#include <libfdt_env.h>\r
55#include <fdt.h>\r
56\r
57#define FDT_FIRST_SUPPORTED_VERSION 0x10\r
58#define FDT_LAST_SUPPORTED_VERSION 0x11\r
59\r
60/* Error codes: informative error codes */\r
61#define FDT_ERR_NOTFOUND 1\r
62 /* FDT_ERR_NOTFOUND: The requested node or property does not exist */\r
63#define FDT_ERR_EXISTS 2\r
64 /* FDT_ERR_EXISTS: Attemped to create a node or property which\r
65 * already exists */\r
66#define FDT_ERR_NOSPACE 3\r
67 /* FDT_ERR_NOSPACE: Operation needed to expand the device\r
68 * tree, but its buffer did not have sufficient space to\r
69 * contain the expanded tree. Use fdt_open_into() to move the\r
70 * device tree to a buffer with more space. */\r
71\r
72/* Error codes: codes for bad parameters */\r
73#define FDT_ERR_BADOFFSET 4\r
74 /* FDT_ERR_BADOFFSET: Function was passed a structure block\r
75 * offset which is out-of-bounds, or which points to an\r
76 * unsuitable part of the structure for the operation. */\r
77#define FDT_ERR_BADPATH 5\r
78 /* FDT_ERR_BADPATH: Function was passed a badly formatted path\r
79 * (e.g. missing a leading / for a function which requires an\r
80 * absolute path) */\r
81#define FDT_ERR_BADPHANDLE 6\r
82 /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle\r
83 * value. phandle values of 0 and -1 are not permitted. */\r
84#define FDT_ERR_BADSTATE 7\r
85 /* FDT_ERR_BADSTATE: Function was passed an incomplete device\r
86 * tree created by the sequential-write functions, which is\r
87 * not sufficiently complete for the requested operation. */\r
88\r
89/* Error codes: codes for bad device tree blobs */\r
90#define FDT_ERR_TRUNCATED 8\r
91 /* FDT_ERR_TRUNCATED: Structure block of the given device tree\r
92 * ends without an FDT_END tag. */\r
93#define FDT_ERR_BADMAGIC 9\r
94 /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a\r
95 * device tree at all - it is missing the flattened device\r
96 * tree magic number. */\r
97#define FDT_ERR_BADVERSION 10\r
98 /* FDT_ERR_BADVERSION: Given device tree has a version which\r
99 * can't be handled by the requested operation. For\r
100 * read-write functions, this may mean that fdt_open_into() is\r
101 * required to convert the tree to the expected version. */\r
102#define FDT_ERR_BADSTRUCTURE 11\r
103 /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt\r
104 * structure block or other serious error (e.g. misnested\r
105 * nodes, or subnodes preceding properties). */\r
106#define FDT_ERR_BADLAYOUT 12\r
107 /* FDT_ERR_BADLAYOUT: For read-write functions, the given\r
108 * device tree has it's sub-blocks in an order that the\r
109 * function can't handle (memory reserve map, then structure,\r
110 * then strings). Use fdt_open_into() to reorganize the tree\r
111 * into a form suitable for the read-write operations. */\r
112\r
113/* "Can't happen" error indicating a bug in libfdt */\r
114#define FDT_ERR_INTERNAL 13\r
115 /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.\r
116 * Should never be returned, if it is, it indicates a bug in\r
117 * libfdt itself. */\r
118\r
119#define FDT_ERR_MAX 13\r
120\r
121/**********************************************************************/\r
122/* Low-level functions (you probably don't need these) */\r
123/**********************************************************************/\r
124\r
125const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);\r
126static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)\r
127{\r
128 return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);\r
129}\r
130\r
131uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);\r
132\r
133/**********************************************************************/\r
134/* Traversal functions */\r
135/**********************************************************************/\r
136\r
137int fdt_next_node(const void *fdt, int offset, int *depth);\r
138\r
139/**********************************************************************/\r
140/* General functions */\r
141/**********************************************************************/\r
142\r
143#define fdt_get_header(fdt, field) \\r
144 (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))\r
145#define fdt_magic(fdt) (fdt_get_header(fdt, magic))\r
146#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))\r
147#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))\r
148#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))\r
149#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))\r
150#define fdt_version(fdt) (fdt_get_header(fdt, version))\r
151#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))\r
152#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))\r
153#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))\r
154#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))\r
155\r
156#define __fdt_set_hdr(name) \\r
157 static inline void fdt_set_##name(void *fdt, uint32_t val) \\r
158 { \\r
159 struct fdt_header *fdth = (struct fdt_header*)fdt; \\r
160 fdth->name = cpu_to_fdt32(val); \\r
161 }\r
162__fdt_set_hdr(magic);\r
163__fdt_set_hdr(totalsize);\r
164__fdt_set_hdr(off_dt_struct);\r
165__fdt_set_hdr(off_dt_strings);\r
166__fdt_set_hdr(off_mem_rsvmap);\r
167__fdt_set_hdr(version);\r
168__fdt_set_hdr(last_comp_version);\r
169__fdt_set_hdr(boot_cpuid_phys);\r
170__fdt_set_hdr(size_dt_strings);\r
171__fdt_set_hdr(size_dt_struct);\r
172#undef __fdt_set_hdr\r
173\r
174/**\r
175 * fdt_check_header - sanity check a device tree or possible device tree\r
176 * @fdt: pointer to data which might be a flattened device tree\r
177 *\r
178 * fdt_check_header() checks that the given buffer contains what\r
179 * appears to be a flattened device tree with sane information in its\r
180 * header.\r
181 *\r
182 * returns:\r
183 * 0, if the buffer appears to contain a valid device tree\r
184 * -FDT_ERR_BADMAGIC,\r
185 * -FDT_ERR_BADVERSION,\r
186 * -FDT_ERR_BADSTATE, standard meanings, as above\r
187 */\r
188int fdt_check_header(const void *fdt);\r
189\r
190/**\r
191 * fdt_move - move a device tree around in memory\r
192 * @fdt: pointer to the device tree to move\r
193 * @buf: pointer to memory where the device is to be moved\r
194 * @bufsize: size of the memory space at buf\r
195 *\r
196 * fdt_move() relocates, if possible, the device tree blob located at\r
197 * fdt to the buffer at buf of size bufsize. The buffer may overlap\r
198 * with the existing device tree blob at fdt. Therefore,\r
199 * fdt_move(fdt, fdt, fdt_totalsize(fdt))\r
200 * should always succeed.\r
201 *\r
202 * returns:\r
203 * 0, on success\r
204 * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree\r
205 * -FDT_ERR_BADMAGIC,\r
206 * -FDT_ERR_BADVERSION,\r
207 * -FDT_ERR_BADSTATE, standard meanings\r
208 */\r
209int fdt_move(const void *fdt, void *buf, int bufsize);\r
210\r
211/**********************************************************************/\r
212/* Read-only functions */\r
213/**********************************************************************/\r
214\r
215/**\r
216 * fdt_string - retrieve a string from the strings block of a device tree\r
217 * @fdt: pointer to the device tree blob\r
218 * @stroffset: offset of the string within the strings block (native endian)\r
219 *\r
220 * fdt_string() retrieves a pointer to a single string from the\r
221 * strings block of the device tree blob at fdt.\r
222 *\r
223 * returns:\r
224 * a pointer to the string, on success\r
225 * NULL, if stroffset is out of bounds\r
226 */\r
227const char *fdt_string(const void *fdt, int stroffset);\r
228\r
229/**\r
230 * fdt_num_mem_rsv - retrieve the number of memory reserve map entries\r
231 * @fdt: pointer to the device tree blob\r
232 *\r
233 * Returns the number of entries in the device tree blob's memory\r
234 * reservation map. This does not include the terminating 0,0 entry\r
235 * or any other (0,0) entries reserved for expansion.\r
236 *\r
237 * returns:\r
238 * the number of entries\r
239 */\r
240int fdt_num_mem_rsv(const void *fdt);\r
241\r
242/**\r
243 * fdt_get_mem_rsv - retrieve one memory reserve map entry\r
244 * @fdt: pointer to the device tree blob\r
245 * @address, @size: pointers to 64-bit variables\r
246 *\r
247 * On success, *address and *size will contain the address and size of\r
248 * the n-th reserve map entry from the device tree blob, in\r
249 * native-endian format.\r
250 *\r
251 * returns:\r
252 * 0, on success\r
253 * -FDT_ERR_BADMAGIC,\r
254 * -FDT_ERR_BADVERSION,\r
255 * -FDT_ERR_BADSTATE, standard meanings\r
256 */\r
257int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);\r
258\r
259/**\r
260 * fdt_subnode_offset_namelen - find a subnode based on substring\r
261 * @fdt: pointer to the device tree blob\r
262 * @parentoffset: structure block offset of a node\r
263 * @name: name of the subnode to locate\r
264 * @namelen: number of characters of name to consider\r
265 *\r
266 * Identical to fdt_subnode_offset(), but only examine the first\r
267 * namelen characters of name for matching the subnode name. This is\r
268 * useful for finding subnodes based on a portion of a larger string,\r
269 * such as a full path.\r
270 */\r
271int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,\r
272 const char *name, int namelen);\r
273/**\r
274 * fdt_subnode_offset - find a subnode of a given node\r
275 * @fdt: pointer to the device tree blob\r
276 * @parentoffset: structure block offset of a node\r
277 * @name: name of the subnode to locate\r
278 *\r
279 * fdt_subnode_offset() finds a subnode of the node at structure block\r
280 * offset parentoffset with the given name. name may include a unit\r
281 * address, in which case fdt_subnode_offset() will find the subnode\r
282 * with that unit address, or the unit address may be omitted, in\r
283 * which case fdt_subnode_offset() will find an arbitrary subnode\r
284 * whose name excluding unit address matches the given name.\r
285 *\r
286 * returns:\r
287 * structure block offset of the requested subnode (>=0), on success\r
288 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist\r
289 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag\r
290 * -FDT_ERR_BADMAGIC,\r
291 * -FDT_ERR_BADVERSION,\r
292 * -FDT_ERR_BADSTATE,\r
293 * -FDT_ERR_BADSTRUCTURE,\r
294 * -FDT_ERR_TRUNCATED, standard meanings.\r
295 */\r
296int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);\r
297\r
298/**\r
299 * fdt_path_offset - find a tree node by its full path\r
300 * @fdt: pointer to the device tree blob\r
301 * @path: full path of the node to locate\r
302 *\r
303 * fdt_path_offset() finds a node of a given path in the device tree.\r
304 * Each path component may omit the unit address portion, but the\r
305 * results of this are undefined if any such path component is\r
306 * ambiguous (that is if there are multiple nodes at the relevant\r
307 * level matching the given component, differentiated only by unit\r
308 * address).\r
309 *\r
310 * returns:\r
311 * structure block offset of the node with the requested path (>=0), on success\r
312 * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid\r
313 * -FDT_ERR_NOTFOUND, if the requested node does not exist\r
314 * -FDT_ERR_BADMAGIC,\r
315 * -FDT_ERR_BADVERSION,\r
316 * -FDT_ERR_BADSTATE,\r
317 * -FDT_ERR_BADSTRUCTURE,\r
318 * -FDT_ERR_TRUNCATED, standard meanings.\r
319 */\r
320int fdt_path_offset(const void *fdt, const char *path);\r
321\r
322/**\r
323 * fdt_get_name - retrieve the name of a given node\r
324 * @fdt: pointer to the device tree blob\r
325 * @nodeoffset: structure block offset of the starting node\r
326 * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
327 *\r
328 * fdt_get_name() retrieves the name (including unit address) of the\r
329 * device tree node at structure block offset nodeoffset. If lenp is\r
330 * non-NULL, the length of this name is also returned, in the integer\r
331 * pointed to by lenp.\r
332 *\r
333 * returns:\r
334 * pointer to the node's name, on success\r
335 * If lenp is non-NULL, *lenp contains the length of that name (>=0)\r
336 * NULL, on error\r
337 * if lenp is non-NULL *lenp contains an error code (<0):\r
338 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
339 * -FDT_ERR_BADMAGIC,\r
340 * -FDT_ERR_BADVERSION,\r
341 * -FDT_ERR_BADSTATE, standard meanings\r
342 */\r
343const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);\r
344\r
345/**\r
346 * fdt_first_property_offset - find the offset of a node's first property\r
347 * @fdt: pointer to the device tree blob\r
348 * @nodeoffset: structure block offset of a node\r
349 *\r
350 * fdt_first_property_offset() finds the first property of the node at\r
351 * the given structure block offset.\r
352 *\r
353 * returns:\r
354 * structure block offset of the property (>=0), on success\r
355 * -FDT_ERR_NOTFOUND, if the requested node has no properties\r
356 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag\r
357 * -FDT_ERR_BADMAGIC,\r
358 * -FDT_ERR_BADVERSION,\r
359 * -FDT_ERR_BADSTATE,\r
360 * -FDT_ERR_BADSTRUCTURE,\r
361 * -FDT_ERR_TRUNCATED, standard meanings.\r
362 */\r
363int fdt_first_property_offset(const void *fdt, int nodeoffset);\r
364\r
365/**\r
366 * fdt_next_property_offset - step through a node's properties\r
367 * @fdt: pointer to the device tree blob\r
368 * @offset: structure block offset of a property\r
369 *\r
370 * fdt_next_property_offset() finds the property immediately after the\r
371 * one at the given structure block offset. This will be a property\r
372 * of the same node as the given property.\r
373 *\r
374 * returns:\r
375 * structure block offset of the next property (>=0), on success\r
376 * -FDT_ERR_NOTFOUND, if the given property is the last in its node\r
377 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag\r
378 * -FDT_ERR_BADMAGIC,\r
379 * -FDT_ERR_BADVERSION,\r
380 * -FDT_ERR_BADSTATE,\r
381 * -FDT_ERR_BADSTRUCTURE,\r
382 * -FDT_ERR_TRUNCATED, standard meanings.\r
383 */\r
384int fdt_next_property_offset(const void *fdt, int offset);\r
385\r
386/**\r
387 * fdt_get_property_by_offset - retrieve the property at a given offset\r
388 * @fdt: pointer to the device tree blob\r
389 * @offset: offset of the property to retrieve\r
390 * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
391 *\r
392 * fdt_get_property_by_offset() retrieves a pointer to the\r
393 * fdt_property structure within the device tree blob at the given\r
394 * offset. If lenp is non-NULL, the length of the property value is\r
395 * also returned, in the integer pointed to by lenp.\r
396 *\r
397 * returns:\r
398 * pointer to the structure representing the property\r
399 * if lenp is non-NULL, *lenp contains the length of the property\r
400 * value (>=0)\r
401 * NULL, on error\r
402 * if lenp is non-NULL, *lenp contains an error code (<0):\r
403 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag\r
404 * -FDT_ERR_BADMAGIC,\r
405 * -FDT_ERR_BADVERSION,\r
406 * -FDT_ERR_BADSTATE,\r
407 * -FDT_ERR_BADSTRUCTURE,\r
408 * -FDT_ERR_TRUNCATED, standard meanings\r
409 */\r
410const struct fdt_property *fdt_get_property_by_offset(const void *fdt,\r
411 int offset,\r
412 int *lenp);\r
413\r
414/**\r
415 * fdt_get_property_namelen - find a property based on substring\r
416 * @fdt: pointer to the device tree blob\r
417 * @nodeoffset: offset of the node whose property to find\r
418 * @name: name of the property to find\r
419 * @namelen: number of characters of name to consider\r
420 * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
421 *\r
422 * Identical to fdt_get_property_namelen(), but only examine the first\r
423 * namelen characters of name for matching the property name.\r
424 */\r
425const struct fdt_property *fdt_get_property_namelen(const void *fdt,\r
426 int nodeoffset,\r
427 const char *name,\r
428 int namelen, int *lenp);\r
429\r
430/**\r
431 * fdt_get_property - find a given property in a given node\r
432 * @fdt: pointer to the device tree blob\r
433 * @nodeoffset: offset of the node whose property to find\r
434 * @name: name of the property to find\r
435 * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
436 *\r
437 * fdt_get_property() retrieves a pointer to the fdt_property\r
438 * structure within the device tree blob corresponding to the property\r
439 * named 'name' of the node at offset nodeoffset. If lenp is\r
440 * non-NULL, the length of the property value is also returned, in the\r
441 * integer pointed to by lenp.\r
442 *\r
443 * returns:\r
444 * pointer to the structure representing the property\r
445 * if lenp is non-NULL, *lenp contains the length of the property\r
446 * value (>=0)\r
447 * NULL, on error\r
448 * if lenp is non-NULL, *lenp contains an error code (<0):\r
449 * -FDT_ERR_NOTFOUND, node does not have named property\r
450 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
451 * -FDT_ERR_BADMAGIC,\r
452 * -FDT_ERR_BADVERSION,\r
453 * -FDT_ERR_BADSTATE,\r
454 * -FDT_ERR_BADSTRUCTURE,\r
455 * -FDT_ERR_TRUNCATED, standard meanings\r
456 */\r
457const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,\r
458 const char *name, int *lenp);\r
459static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,\r
460 const char *name,\r
461 int *lenp)\r
462{\r
463 return (struct fdt_property *)(uintptr_t)\r
464 fdt_get_property(fdt, nodeoffset, name, lenp);\r
465}\r
466\r
467/**\r
468 * fdt_getprop_by_offset - retrieve the value of a property at a given offset\r
469 * @fdt: pointer to the device tree blob\r
470 * @ffset: offset of the property to read\r
471 * @namep: pointer to a string variable (will be overwritten) or NULL\r
472 * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
473 *\r
474 * fdt_getprop_by_offset() retrieves a pointer to the value of the\r
475 * property at structure block offset 'offset' (this will be a pointer\r
476 * to within the device blob itself, not a copy of the value). If\r
477 * lenp is non-NULL, the length of the property value is also\r
478 * returned, in the integer pointed to by lenp. If namep is non-NULL,\r
479 * the property's namne will also be returned in the char * pointed to\r
480 * by namep (this will be a pointer to within the device tree's string\r
481 * block, not a new copy of the name).\r
482 *\r
483 * returns:\r
484 * pointer to the property's value\r
485 * if lenp is non-NULL, *lenp contains the length of the property\r
486 * value (>=0)\r
487 * if namep is non-NULL *namep contiains a pointer to the property\r
488 * name.\r
489 * NULL, on error\r
490 * if lenp is non-NULL, *lenp contains an error code (<0):\r
491 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag\r
492 * -FDT_ERR_BADMAGIC,\r
493 * -FDT_ERR_BADVERSION,\r
494 * -FDT_ERR_BADSTATE,\r
495 * -FDT_ERR_BADSTRUCTURE,\r
496 * -FDT_ERR_TRUNCATED, standard meanings\r
497 */\r
498const void *fdt_getprop_by_offset(const void *fdt, int offset,\r
499 const char **namep, int *lenp);\r
500\r
501/**\r
502 * fdt_getprop_namelen - get property value based on substring\r
503 * @fdt: pointer to the device tree blob\r
504 * @nodeoffset: offset of the node whose property to find\r
505 * @name: name of the property to find\r
506 * @namelen: number of characters of name to consider\r
507 * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
508 *\r
509 * Identical to fdt_getprop(), but only examine the first namelen\r
510 * characters of name for matching the property name.\r
511 */\r
512const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,\r
513 const char *name, int namelen, int *lenp);\r
514\r
515/**\r
516 * fdt_getprop - retrieve the value of a given property\r
517 * @fdt: pointer to the device tree blob\r
518 * @nodeoffset: offset of the node whose property to find\r
519 * @name: name of the property to find\r
520 * @lenp: pointer to an integer variable (will be overwritten) or NULL\r
521 *\r
522 * fdt_getprop() retrieves a pointer to the value of the property\r
523 * named 'name' of the node at offset nodeoffset (this will be a\r
524 * pointer to within the device blob itself, not a copy of the value).\r
525 * If lenp is non-NULL, the length of the property value is also\r
526 * returned, in the integer pointed to by lenp.\r
527 *\r
528 * returns:\r
529 * pointer to the property's value\r
530 * if lenp is non-NULL, *lenp contains the length of the property\r
531 * value (>=0)\r
532 * NULL, on error\r
533 * if lenp is non-NULL, *lenp contains an error code (<0):\r
534 * -FDT_ERR_NOTFOUND, node does not have named property\r
535 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
536 * -FDT_ERR_BADMAGIC,\r
537 * -FDT_ERR_BADVERSION,\r
538 * -FDT_ERR_BADSTATE,\r
539 * -FDT_ERR_BADSTRUCTURE,\r
540 * -FDT_ERR_TRUNCATED, standard meanings\r
541 */\r
542const void *fdt_getprop(const void *fdt, int nodeoffset,\r
543 const char *name, int *lenp);\r
544static inline void *fdt_getprop_w(void *fdt, int nodeoffset,\r
545 const char *name, int *lenp)\r
546{\r
547 return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);\r
548}\r
549\r
550/**\r
551 * fdt_get_phandle - retrieve the phandle of a given node\r
552 * @fdt: pointer to the device tree blob\r
553 * @nodeoffset: structure block offset of the node\r
554 *\r
555 * fdt_get_phandle() retrieves the phandle of the device tree node at\r
556 * structure block offset nodeoffset.\r
557 *\r
558 * returns:\r
559 * the phandle of the node at nodeoffset, on success (!= 0, != -1)\r
560 * 0, if the node has no phandle, or another error occurs\r
561 */\r
562uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);\r
563\r
564/**\r
565 * fdt_get_alias_namelen - get alias based on substring\r
566 * @fdt: pointer to the device tree blob\r
567 * @name: name of the alias th look up\r
568 * @namelen: number of characters of name to consider\r
569 *\r
570 * Identical to fdt_get_alias(), but only examine the first namelen\r
571 * characters of name for matching the alias name.\r
572 */\r
573const char *fdt_get_alias_namelen(const void *fdt,\r
574 const char *name, int namelen);\r
575\r
576/**\r
577 * fdt_get_alias - retreive the path referenced by a given alias\r
578 * @fdt: pointer to the device tree blob\r
579 * @name: name of the alias th look up\r
580 *\r
581 * fdt_get_alias() retrieves the value of a given alias. That is, the\r
582 * value of the property named 'name' in the node /aliases.\r
583 *\r
584 * returns:\r
585 * a pointer to the expansion of the alias named 'name', of it exists\r
586 * NULL, if the given alias or the /aliases node does not exist\r
587 */\r
588const char *fdt_get_alias(const void *fdt, const char *name);\r
589\r
590/**\r
591 * fdt_get_path - determine the full path of a node\r
592 * @fdt: pointer to the device tree blob\r
593 * @nodeoffset: offset of the node whose path to find\r
594 * @buf: character buffer to contain the returned path (will be overwritten)\r
595 * @buflen: size of the character buffer at buf\r
596 *\r
597 * fdt_get_path() computes the full path of the node at offset\r
598 * nodeoffset, and records that path in the buffer at buf.\r
599 *\r
600 * NOTE: This function is expensive, as it must scan the device tree\r
601 * structure from the start to nodeoffset.\r
602 *\r
603 * returns:\r
604 * 0, on success\r
605 * buf contains the absolute path of the node at\r
606 * nodeoffset, as a NUL-terminated string.\r
607 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
608 * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)\r
609 * characters and will not fit in the given buffer.\r
610 * -FDT_ERR_BADMAGIC,\r
611 * -FDT_ERR_BADVERSION,\r
612 * -FDT_ERR_BADSTATE,\r
613 * -FDT_ERR_BADSTRUCTURE, standard meanings\r
614 */\r
615int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);\r
616\r
617/**\r
618 * fdt_supernode_atdepth_offset - find a specific ancestor of a node\r
619 * @fdt: pointer to the device tree blob\r
620 * @nodeoffset: offset of the node whose parent to find\r
621 * @supernodedepth: depth of the ancestor to find\r
622 * @nodedepth: pointer to an integer variable (will be overwritten) or NULL\r
623 *\r
624 * fdt_supernode_atdepth_offset() finds an ancestor of the given node\r
625 * at a specific depth from the root (where the root itself has depth\r
626 * 0, its immediate subnodes depth 1 and so forth). So\r
627 * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);\r
628 * will always return 0, the offset of the root node. If the node at\r
629 * nodeoffset has depth D, then:\r
630 * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);\r
631 * will return nodeoffset itself.\r
632 *\r
633 * NOTE: This function is expensive, as it must scan the device tree\r
634 * structure from the start to nodeoffset.\r
635 *\r
636 * returns:\r
637\r
638 * structure block offset of the node at node offset's ancestor\r
639 * of depth supernodedepth (>=0), on success\r
640 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
641* -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset\r
642 * -FDT_ERR_BADMAGIC,\r
643 * -FDT_ERR_BADVERSION,\r
644 * -FDT_ERR_BADSTATE,\r
645 * -FDT_ERR_BADSTRUCTURE, standard meanings\r
646 */\r
647int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,\r
648 int supernodedepth, int *nodedepth);\r
649\r
650/**\r
651 * fdt_node_depth - find the depth of a given node\r
652 * @fdt: pointer to the device tree blob\r
653 * @nodeoffset: offset of the node whose parent to find\r
654 *\r
655 * fdt_node_depth() finds the depth of a given node. The root node\r
656 * has depth 0, its immediate subnodes depth 1 and so forth.\r
657 *\r
658 * NOTE: This function is expensive, as it must scan the device tree\r
659 * structure from the start to nodeoffset.\r
660 *\r
661 * returns:\r
662 * depth of the node at nodeoffset (>=0), on success\r
663 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
664 * -FDT_ERR_BADMAGIC,\r
665 * -FDT_ERR_BADVERSION,\r
666 * -FDT_ERR_BADSTATE,\r
667 * -FDT_ERR_BADSTRUCTURE, standard meanings\r
668 */\r
669int fdt_node_depth(const void *fdt, int nodeoffset);\r
670\r
671/**\r
672 * fdt_parent_offset - find the parent of a given node\r
673 * @fdt: pointer to the device tree blob\r
674 * @nodeoffset: offset of the node whose parent to find\r
675 *\r
676 * fdt_parent_offset() locates the parent node of a given node (that\r
677 * is, it finds the offset of the node which contains the node at\r
678 * nodeoffset as a subnode).\r
679 *\r
680 * NOTE: This function is expensive, as it must scan the device tree\r
681 * structure from the start to nodeoffset, *twice*.\r
682 *\r
683 * returns:\r
684 * structure block offset of the parent of the node at nodeoffset\r
685 * (>=0), on success\r
686 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
687 * -FDT_ERR_BADMAGIC,\r
688 * -FDT_ERR_BADVERSION,\r
689 * -FDT_ERR_BADSTATE,\r
690 * -FDT_ERR_BADSTRUCTURE, standard meanings\r
691 */\r
692int fdt_parent_offset(const void *fdt, int nodeoffset);\r
693\r
694/**\r
695 * fdt_node_offset_by_prop_value - find nodes with a given property value\r
696 * @fdt: pointer to the device tree blob\r
697 * @startoffset: only find nodes after this offset\r
698 * @propname: property name to check\r
699 * @propval: property value to search for\r
700 * @proplen: length of the value in propval\r
701 *\r
702 * fdt_node_offset_by_prop_value() returns the offset of the first\r
703 * node after startoffset, which has a property named propname whose\r
704 * value is of length proplen and has value equal to propval; or if\r
705 * startoffset is -1, the very first such node in the tree.\r
706 *\r
707 * To iterate through all nodes matching the criterion, the following\r
708 * idiom can be used:\r
709 * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,\r
710 * propval, proplen);\r
711 * while (offset != -FDT_ERR_NOTFOUND) {\r
712 * // other code here\r
713 * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,\r
714 * propval, proplen);\r
715 * }\r
716 *\r
717 * Note the -1 in the first call to the function, if 0 is used here\r
718 * instead, the function will never locate the root node, even if it\r
719 * matches the criterion.\r
720 *\r
721 * returns:\r
722 * structure block offset of the located node (>= 0, >startoffset),\r
723 * on success\r
724 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the\r
725 * tree after startoffset\r
726 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
727 * -FDT_ERR_BADMAGIC,\r
728 * -FDT_ERR_BADVERSION,\r
729 * -FDT_ERR_BADSTATE,\r
730 * -FDT_ERR_BADSTRUCTURE, standard meanings\r
731 */\r
732int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,\r
733 const char *propname,\r
734 const void *propval, int proplen);\r
735\r
736/**\r
737 * fdt_node_offset_by_phandle - find the node with a given phandle\r
738 * @fdt: pointer to the device tree blob\r
739 * @phandle: phandle value\r
740 *\r
741 * fdt_node_offset_by_phandle() returns the offset of the node\r
742 * which has the given phandle value. If there is more than one node\r
743 * in the tree with the given phandle (an invalid tree), results are\r
744 * undefined.\r
745 *\r
746 * returns:\r
747 * structure block offset of the located node (>= 0), on success\r
748 * -FDT_ERR_NOTFOUND, no node with that phandle exists\r
749 * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)\r
750 * -FDT_ERR_BADMAGIC,\r
751 * -FDT_ERR_BADVERSION,\r
752 * -FDT_ERR_BADSTATE,\r
753 * -FDT_ERR_BADSTRUCTURE, standard meanings\r
754 */\r
755int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);\r
756\r
757/**\r
758 * fdt_node_check_compatible: check a node's compatible property\r
759 * @fdt: pointer to the device tree blob\r
760 * @nodeoffset: offset of a tree node\r
761 * @compatible: string to match against\r
762 *\r
763 *\r
764 * fdt_node_check_compatible() returns 0 if the given node contains a\r
765 * 'compatible' property with the given string as one of its elements,\r
766 * it returns non-zero otherwise, or on error.\r
767 *\r
768 * returns:\r
769 * 0, if the node has a 'compatible' property listing the given string\r
770 * 1, if the node has a 'compatible' property, but it does not list\r
771 * the given string\r
772 * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property\r
773 * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag\r
774 * -FDT_ERR_BADMAGIC,\r
775 * -FDT_ERR_BADVERSION,\r
776 * -FDT_ERR_BADSTATE,\r
777 * -FDT_ERR_BADSTRUCTURE, standard meanings\r
778 */\r
779int fdt_node_check_compatible(const void *fdt, int nodeoffset,\r
780 const char *compatible);\r
781\r
782/**\r
783 * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value\r
784 * @fdt: pointer to the device tree blob\r
785 * @startoffset: only find nodes after this offset\r
786 * @compatible: 'compatible' string to match against\r
787 *\r
788 * fdt_node_offset_by_compatible() returns the offset of the first\r
789 * node after startoffset, which has a 'compatible' property which\r
790 * lists the given compatible string; or if startoffset is -1, the\r
791 * very first such node in the tree.\r
792 *\r
793 * To iterate through all nodes matching the criterion, the following\r
794 * idiom can be used:\r
795 * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);\r
796 * while (offset != -FDT_ERR_NOTFOUND) {\r
797 * // other code here\r
798 * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);\r
799 * }\r
800 *\r
801 * Note the -1 in the first call to the function, if 0 is used here\r
802 * instead, the function will never locate the root node, even if it\r
803 * matches the criterion.\r
804 *\r
805 * returns:\r
806 * structure block offset of the located node (>= 0, >startoffset),\r
807 * on success\r
808 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the\r
809 * tree after startoffset\r
810 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
811 * -FDT_ERR_BADMAGIC,\r
812 * -FDT_ERR_BADVERSION,\r
813 * -FDT_ERR_BADSTATE,\r
814 * -FDT_ERR_BADSTRUCTURE, standard meanings\r
815 */\r
816int fdt_node_offset_by_compatible(const void *fdt, int startoffset,\r
817 const char *compatible);\r
818\r
819/**********************************************************************/\r
820/* Write-in-place functions */\r
821/**********************************************************************/\r
822\r
823/**\r
824 * fdt_setprop_inplace - change a property's value, but not its size\r
825 * @fdt: pointer to the device tree blob\r
826 * @nodeoffset: offset of the node whose property to change\r
827 * @name: name of the property to change\r
828 * @val: pointer to data to replace the property value with\r
829 * @len: length of the property value\r
830 *\r
831 * fdt_setprop_inplace() replaces the value of a given property with\r
832 * the data in val, of length len. This function cannot change the\r
833 * size of a property, and so will only work if len is equal to the\r
834 * current length of the property.\r
835 *\r
836 * This function will alter only the bytes in the blob which contain\r
837 * the given property value, and will not alter or move any other part\r
838 * of the tree.\r
839 *\r
840 * returns:\r
841 * 0, on success\r
842 * -FDT_ERR_NOSPACE, if len is not equal to the property's current length\r
843 * -FDT_ERR_NOTFOUND, node does not have the named property\r
844 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
845 * -FDT_ERR_BADMAGIC,\r
846 * -FDT_ERR_BADVERSION,\r
847 * -FDT_ERR_BADSTATE,\r
848 * -FDT_ERR_BADSTRUCTURE,\r
849 * -FDT_ERR_TRUNCATED, standard meanings\r
850 */\r
851int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,\r
852 const void *val, int len);\r
853\r
854/**\r
855 * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property\r
856 * @fdt: pointer to the device tree blob\r
857 * @nodeoffset: offset of the node whose property to change\r
858 * @name: name of the property to change\r
859 * @val: 32-bit integer value to replace the property with\r
860 *\r
861 * fdt_setprop_inplace_u32() replaces the value of a given property\r
862 * with the 32-bit integer value in val, converting val to big-endian\r
863 * if necessary. This function cannot change the size of a property,\r
864 * and so will only work if the property already exists and has length\r
865 * 4.\r
866 *\r
867 * This function will alter only the bytes in the blob which contain\r
868 * the given property value, and will not alter or move any other part\r
869 * of the tree.\r
870 *\r
871 * returns:\r
872 * 0, on success\r
873 * -FDT_ERR_NOSPACE, if the property's length is not equal to 4\r
874 * -FDT_ERR_NOTFOUND, node does not have the named property\r
875 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
876 * -FDT_ERR_BADMAGIC,\r
877 * -FDT_ERR_BADVERSION,\r
878 * -FDT_ERR_BADSTATE,\r
879 * -FDT_ERR_BADSTRUCTURE,\r
880 * -FDT_ERR_TRUNCATED, standard meanings\r
881 */\r
882static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,\r
883 const char *name, uint32_t val)\r
884{\r
885 val = cpu_to_fdt32(val);\r
886 return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));\r
887}\r
888\r
889/**\r
890 * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property\r
891 * @fdt: pointer to the device tree blob\r
892 * @nodeoffset: offset of the node whose property to change\r
893 * @name: name of the property to change\r
894 * @val: 64-bit integer value to replace the property with\r
895 *\r
896 * fdt_setprop_inplace_u64() replaces the value of a given property\r
897 * with the 64-bit integer value in val, converting val to big-endian\r
898 * if necessary. This function cannot change the size of a property,\r
899 * and so will only work if the property already exists and has length\r
900 * 8.\r
901 *\r
902 * This function will alter only the bytes in the blob which contain\r
903 * the given property value, and will not alter or move any other part\r
904 * of the tree.\r
905 *\r
906 * returns:\r
907 * 0, on success\r
908 * -FDT_ERR_NOSPACE, if the property's length is not equal to 8\r
909 * -FDT_ERR_NOTFOUND, node does not have the named property\r
910 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
911 * -FDT_ERR_BADMAGIC,\r
912 * -FDT_ERR_BADVERSION,\r
913 * -FDT_ERR_BADSTATE,\r
914 * -FDT_ERR_BADSTRUCTURE,\r
915 * -FDT_ERR_TRUNCATED, standard meanings\r
916 */\r
917static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,\r
918 const char *name, uint64_t val)\r
919{\r
920 val = cpu_to_fdt64(val);\r
921 return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));\r
922}\r
923\r
924/**\r
925 * fdt_setprop_inplace_cell - change the value of a single-cell property\r
926 *\r
927 * This is an alternative name for fdt_setprop_inplace_u32()\r
928 */\r
929static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,\r
930 const char *name, uint32_t val)\r
931{\r
932 return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);\r
933}\r
934\r
935/**\r
936 * fdt_nop_property - replace a property with nop tags\r
937 * @fdt: pointer to the device tree blob\r
938 * @nodeoffset: offset of the node whose property to nop\r
939 * @name: name of the property to nop\r
940 *\r
941 * fdt_nop_property() will replace a given property's representation\r
942 * in the blob with FDT_NOP tags, effectively removing it from the\r
943 * tree.\r
944 *\r
945 * This function will alter only the bytes in the blob which contain\r
946 * the property, and will not alter or move any other part of the\r
947 * tree.\r
948 *\r
949 * returns:\r
950 * 0, on success\r
951 * -FDT_ERR_NOTFOUND, node does not have the named property\r
952 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
953 * -FDT_ERR_BADMAGIC,\r
954 * -FDT_ERR_BADVERSION,\r
955 * -FDT_ERR_BADSTATE,\r
956 * -FDT_ERR_BADSTRUCTURE,\r
957 * -FDT_ERR_TRUNCATED, standard meanings\r
958 */\r
959int fdt_nop_property(void *fdt, int nodeoffset, const char *name);\r
960\r
961/**\r
962 * fdt_nop_node - replace a node (subtree) with nop tags\r
963 * @fdt: pointer to the device tree blob\r
964 * @nodeoffset: offset of the node to nop\r
965 *\r
966 * fdt_nop_node() will replace a given node's representation in the\r
967 * blob, including all its subnodes, if any, with FDT_NOP tags,\r
968 * effectively removing it from the tree.\r
969 *\r
970 * This function will alter only the bytes in the blob which contain\r
971 * the node and its properties and subnodes, and will not alter or\r
972 * move any other part of the tree.\r
973 *\r
974 * returns:\r
975 * 0, on success\r
976 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
977 * -FDT_ERR_BADMAGIC,\r
978 * -FDT_ERR_BADVERSION,\r
979 * -FDT_ERR_BADSTATE,\r
980 * -FDT_ERR_BADSTRUCTURE,\r
981 * -FDT_ERR_TRUNCATED, standard meanings\r
982 */\r
983int fdt_nop_node(void *fdt, int nodeoffset);\r
984\r
985/**********************************************************************/\r
986/* Sequential write functions */\r
987/**********************************************************************/\r
988\r
989int fdt_create(void *buf, int bufsize);\r
990int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);\r
991int fdt_finish_reservemap(void *fdt);\r
992int fdt_begin_node(void *fdt, const char *name);\r
993int fdt_property(void *fdt, const char *name, const void *val, int len);\r
994static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)\r
995{\r
996 val = cpu_to_fdt32(val);\r
997 return fdt_property(fdt, name, &val, sizeof(val));\r
998}\r
999static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)\r
1000{\r
1001 val = cpu_to_fdt64(val);\r
1002 return fdt_property(fdt, name, &val, sizeof(val));\r
1003}\r
1004static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)\r
1005{\r
1006 return fdt_property_u32(fdt, name, val);\r
1007}\r
1008#define fdt_property_string(fdt, name, str) \\r
1009 fdt_property(fdt, name, str, strlen(str)+1)\r
1010int fdt_end_node(void *fdt);\r
1011int fdt_finish(void *fdt);\r
1012\r
1013/**********************************************************************/\r
1014/* Read-write functions */\r
1015/**********************************************************************/\r
1016\r
1017int fdt_create_empty_tree(void *buf, int bufsize);\r
1018int fdt_open_into(const void *fdt, void *buf, int bufsize);\r
1019int fdt_pack(void *fdt);\r
1020\r
1021/**\r
1022 * fdt_add_mem_rsv - add one memory reserve map entry\r
1023 * @fdt: pointer to the device tree blob\r
1024 * @address, @size: 64-bit values (native endian)\r
1025 *\r
1026 * Adds a reserve map entry to the given blob reserving a region at\r
1027 * address address of length size.\r
1028 *\r
1029 * This function will insert data into the reserve map and will\r
1030 * therefore change the indexes of some entries in the table.\r
1031 *\r
1032 * returns:\r
1033 * 0, on success\r
1034 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
1035 * contain the new reservation entry\r
1036 * -FDT_ERR_BADMAGIC,\r
1037 * -FDT_ERR_BADVERSION,\r
1038 * -FDT_ERR_BADSTATE,\r
1039 * -FDT_ERR_BADSTRUCTURE,\r
1040 * -FDT_ERR_BADLAYOUT,\r
1041 * -FDT_ERR_TRUNCATED, standard meanings\r
1042 */\r
1043int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);\r
1044\r
1045/**\r
1046 * fdt_del_mem_rsv - remove a memory reserve map entry\r
1047 * @fdt: pointer to the device tree blob\r
1048 * @n: entry to remove\r
1049 *\r
1050 * fdt_del_mem_rsv() removes the n-th memory reserve map entry from\r
1051 * the blob.\r
1052 *\r
1053 * This function will delete data from the reservation table and will\r
1054 * therefore change the indexes of some entries in the table.\r
1055 *\r
1056 * returns:\r
1057 * 0, on success\r
1058 * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there\r
1059 * are less than n+1 reserve map entries)\r
1060 * -FDT_ERR_BADMAGIC,\r
1061 * -FDT_ERR_BADVERSION,\r
1062 * -FDT_ERR_BADSTATE,\r
1063 * -FDT_ERR_BADSTRUCTURE,\r
1064 * -FDT_ERR_BADLAYOUT,\r
1065 * -FDT_ERR_TRUNCATED, standard meanings\r
1066 */\r
1067int fdt_del_mem_rsv(void *fdt, int n);\r
1068\r
1069/**\r
1070 * fdt_set_name - change the name of a given node\r
1071 * @fdt: pointer to the device tree blob\r
1072 * @nodeoffset: structure block offset of a node\r
1073 * @name: name to give the node\r
1074 *\r
1075 * fdt_set_name() replaces the name (including unit address, if any)\r
1076 * of the given node with the given string. NOTE: this function can't\r
1077 * efficiently check if the new name is unique amongst the given\r
1078 * node's siblings; results are undefined if this function is invoked\r
1079 * with a name equal to one of the given node's siblings.\r
1080 *\r
1081 * This function may insert or delete data from the blob, and will\r
1082 * therefore change the offsets of some existing nodes.\r
1083 *\r
1084 * returns:\r
1085 * 0, on success\r
1086 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob\r
1087 * to contain the new name\r
1088 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1089 * -FDT_ERR_BADMAGIC,\r
1090 * -FDT_ERR_BADVERSION,\r
1091 * -FDT_ERR_BADSTATE, standard meanings\r
1092 */\r
1093int fdt_set_name(void *fdt, int nodeoffset, const char *name);\r
1094\r
1095/**\r
1096 * fdt_setprop - create or change a property\r
1097 * @fdt: pointer to the device tree blob\r
1098 * @nodeoffset: offset of the node whose property to change\r
1099 * @name: name of the property to change\r
1100 * @val: pointer to data to set the property value to\r
1101 * @len: length of the property value\r
1102 *\r
1103 * fdt_setprop() sets the value of the named property in the given\r
1104 * node to the given value and length, creating the property if it\r
1105 * does not already exist.\r
1106 *\r
1107 * This function may insert or delete data from the blob, and will\r
1108 * therefore change the offsets of some existing nodes.\r
1109 *\r
1110 * returns:\r
1111 * 0, on success\r
1112 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
1113 * contain the new property value\r
1114 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1115 * -FDT_ERR_BADLAYOUT,\r
1116 * -FDT_ERR_BADMAGIC,\r
1117 * -FDT_ERR_BADVERSION,\r
1118 * -FDT_ERR_BADSTATE,\r
1119 * -FDT_ERR_BADSTRUCTURE,\r
1120 * -FDT_ERR_BADLAYOUT,\r
1121 * -FDT_ERR_TRUNCATED, standard meanings\r
1122 */\r
1123int fdt_setprop(void *fdt, int nodeoffset, const char *name,\r
1124 const void *val, int len);\r
1125\r
1126/**\r
1127 * fdt_setprop_u32 - set a property to a 32-bit integer\r
1128 * @fdt: pointer to the device tree blob\r
1129 * @nodeoffset: offset of the node whose property to change\r
1130 * @name: name of the property to change\r
1131 * @val: 32-bit integer value for the property (native endian)\r
1132 *\r
1133 * fdt_setprop_u32() sets the value of the named property in the given\r
1134 * node to the given 32-bit integer value (converting to big-endian if\r
1135 * necessary), or creates a new property with that value if it does\r
1136 * not already exist.\r
1137 *\r
1138 * This function may insert or delete data from the blob, and will\r
1139 * therefore change the offsets of some existing nodes.\r
1140 *\r
1141 * returns:\r
1142 * 0, on success\r
1143 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
1144 * contain the new property value\r
1145 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1146 * -FDT_ERR_BADLAYOUT,\r
1147 * -FDT_ERR_BADMAGIC,\r
1148 * -FDT_ERR_BADVERSION,\r
1149 * -FDT_ERR_BADSTATE,\r
1150 * -FDT_ERR_BADSTRUCTURE,\r
1151 * -FDT_ERR_BADLAYOUT,\r
1152 * -FDT_ERR_TRUNCATED, standard meanings\r
1153 */\r
1154static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,\r
1155 uint32_t val)\r
1156{\r
1157 val = cpu_to_fdt32(val);\r
1158 return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));\r
1159}\r
1160\r
1161/**\r
1162 * fdt_setprop_u64 - set a property to a 64-bit integer\r
1163 * @fdt: pointer to the device tree blob\r
1164 * @nodeoffset: offset of the node whose property to change\r
1165 * @name: name of the property to change\r
1166 * @val: 64-bit integer value for the property (native endian)\r
1167 *\r
1168 * fdt_setprop_u64() sets the value of the named property in the given\r
1169 * node to the given 64-bit integer value (converting to big-endian if\r
1170 * necessary), or creates a new property with that value if it does\r
1171 * not already exist.\r
1172 *\r
1173 * This function may insert or delete data from the blob, and will\r
1174 * therefore change the offsets of some existing nodes.\r
1175 *\r
1176 * returns:\r
1177 * 0, on success\r
1178 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
1179 * contain the new property value\r
1180 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1181 * -FDT_ERR_BADLAYOUT,\r
1182 * -FDT_ERR_BADMAGIC,\r
1183 * -FDT_ERR_BADVERSION,\r
1184 * -FDT_ERR_BADSTATE,\r
1185 * -FDT_ERR_BADSTRUCTURE,\r
1186 * -FDT_ERR_BADLAYOUT,\r
1187 * -FDT_ERR_TRUNCATED, standard meanings\r
1188 */\r
1189static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,\r
1190 uint64_t val)\r
1191{\r
1192 val = cpu_to_fdt64(val);\r
1193 return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));\r
1194}\r
1195\r
1196/**\r
1197 * fdt_setprop_cell - set a property to a single cell value\r
1198 *\r
1199 * This is an alternative name for fdt_setprop_u32()\r
1200 */\r
1201static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,\r
1202 uint32_t val)\r
1203{\r
1204 return fdt_setprop_u32(fdt, nodeoffset, name, val);\r
1205}\r
1206\r
1207/**\r
1208 * fdt_setprop_string - set a property to a string value\r
1209 * @fdt: pointer to the device tree blob\r
1210 * @nodeoffset: offset of the node whose property to change\r
1211 * @name: name of the property to change\r
1212 * @str: string value for the property\r
1213 *\r
1214 * fdt_setprop_string() sets the value of the named property in the\r
1215 * given node to the given string value (using the length of the\r
1216 * string to determine the new length of the property), or creates a\r
1217 * new property with that value if it does not already exist.\r
1218 *\r
1219 * This function may insert or delete data from the blob, and will\r
1220 * therefore change the offsets of some existing nodes.\r
1221 *\r
1222 * returns:\r
1223 * 0, on success\r
1224 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
1225 * contain the new property value\r
1226 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1227 * -FDT_ERR_BADLAYOUT,\r
1228 * -FDT_ERR_BADMAGIC,\r
1229 * -FDT_ERR_BADVERSION,\r
1230 * -FDT_ERR_BADSTATE,\r
1231 * -FDT_ERR_BADSTRUCTURE,\r
1232 * -FDT_ERR_BADLAYOUT,\r
1233 * -FDT_ERR_TRUNCATED, standard meanings\r
1234 */\r
1235#define fdt_setprop_string(fdt, nodeoffset, name, str) \\r
1236 fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)\r
1237\r
1238/**\r
1239 * fdt_appendprop - append to or create a property\r
1240 * @fdt: pointer to the device tree blob\r
1241 * @nodeoffset: offset of the node whose property to change\r
1242 * @name: name of the property to append to\r
1243 * @val: pointer to data to append to the property value\r
1244 * @len: length of the data to append to the property value\r
1245 *\r
1246 * fdt_appendprop() appends the value to the named property in the\r
1247 * given node, creating the property if it does not already exist.\r
1248 *\r
1249 * This function may insert data into the blob, and will therefore\r
1250 * change the offsets of some existing nodes.\r
1251 *\r
1252 * returns:\r
1253 * 0, on success\r
1254 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
1255 * contain the new property value\r
1256 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1257 * -FDT_ERR_BADLAYOUT,\r
1258 * -FDT_ERR_BADMAGIC,\r
1259 * -FDT_ERR_BADVERSION,\r
1260 * -FDT_ERR_BADSTATE,\r
1261 * -FDT_ERR_BADSTRUCTURE,\r
1262 * -FDT_ERR_BADLAYOUT,\r
1263 * -FDT_ERR_TRUNCATED, standard meanings\r
1264 */\r
1265int fdt_appendprop(void *fdt, int nodeoffset, const char *name,\r
1266 const void *val, int len);\r
1267\r
1268/**\r
1269 * fdt_appendprop_u32 - append a 32-bit integer value to a property\r
1270 * @fdt: pointer to the device tree blob\r
1271 * @nodeoffset: offset of the node whose property to change\r
1272 * @name: name of the property to change\r
1273 * @val: 32-bit integer value to append to the property (native endian)\r
1274 *\r
1275 * fdt_appendprop_u32() appends the given 32-bit integer value\r
1276 * (converting to big-endian if necessary) to the value of the named\r
1277 * property in the given node, or creates a new property with that\r
1278 * value if it does not already exist.\r
1279 *\r
1280 * This function may insert data into the blob, and will therefore\r
1281 * change the offsets of some existing nodes.\r
1282 *\r
1283 * returns:\r
1284 * 0, on success\r
1285 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
1286 * contain the new property value\r
1287 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1288 * -FDT_ERR_BADLAYOUT,\r
1289 * -FDT_ERR_BADMAGIC,\r
1290 * -FDT_ERR_BADVERSION,\r
1291 * -FDT_ERR_BADSTATE,\r
1292 * -FDT_ERR_BADSTRUCTURE,\r
1293 * -FDT_ERR_BADLAYOUT,\r
1294 * -FDT_ERR_TRUNCATED, standard meanings\r
1295 */\r
1296static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,\r
1297 const char *name, uint32_t val)\r
1298{\r
1299 val = cpu_to_fdt32(val);\r
1300 return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));\r
1301}\r
1302\r
1303/**\r
1304 * fdt_appendprop_u64 - append a 64-bit integer value to a property\r
1305 * @fdt: pointer to the device tree blob\r
1306 * @nodeoffset: offset of the node whose property to change\r
1307 * @name: name of the property to change\r
1308 * @val: 64-bit integer value to append to the property (native endian)\r
1309 *\r
1310 * fdt_appendprop_u64() appends the given 64-bit integer value\r
1311 * (converting to big-endian if necessary) to the value of the named\r
1312 * property in the given node, or creates a new property with that\r
1313 * value if it does not already exist.\r
1314 *\r
1315 * This function may insert data into the blob, and will therefore\r
1316 * change the offsets of some existing nodes.\r
1317 *\r
1318 * returns:\r
1319 * 0, on success\r
1320 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
1321 * contain the new property value\r
1322 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1323 * -FDT_ERR_BADLAYOUT,\r
1324 * -FDT_ERR_BADMAGIC,\r
1325 * -FDT_ERR_BADVERSION,\r
1326 * -FDT_ERR_BADSTATE,\r
1327 * -FDT_ERR_BADSTRUCTURE,\r
1328 * -FDT_ERR_BADLAYOUT,\r
1329 * -FDT_ERR_TRUNCATED, standard meanings\r
1330 */\r
1331static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,\r
1332 const char *name, uint64_t val)\r
1333{\r
1334 val = cpu_to_fdt64(val);\r
1335 return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));\r
1336}\r
1337\r
1338/**\r
1339 * fdt_appendprop_cell - append a single cell value to a property\r
1340 *\r
1341 * This is an alternative name for fdt_appendprop_u32()\r
1342 */\r
1343static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,\r
1344 const char *name, uint32_t val)\r
1345{\r
1346 return fdt_appendprop_u32(fdt, nodeoffset, name, val);\r
1347}\r
1348\r
1349/**\r
1350 * fdt_appendprop_string - append a string to a property\r
1351 * @fdt: pointer to the device tree blob\r
1352 * @nodeoffset: offset of the node whose property to change\r
1353 * @name: name of the property to change\r
1354 * @str: string value to append to the property\r
1355 *\r
1356 * fdt_appendprop_string() appends the given string to the value of\r
1357 * the named property in the given node, or creates a new property\r
1358 * with that value if it does not already exist.\r
1359 *\r
1360 * This function may insert data into the blob, and will therefore\r
1361 * change the offsets of some existing nodes.\r
1362 *\r
1363 * returns:\r
1364 * 0, on success\r
1365 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
1366 * contain the new property value\r
1367 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1368 * -FDT_ERR_BADLAYOUT,\r
1369 * -FDT_ERR_BADMAGIC,\r
1370 * -FDT_ERR_BADVERSION,\r
1371 * -FDT_ERR_BADSTATE,\r
1372 * -FDT_ERR_BADSTRUCTURE,\r
1373 * -FDT_ERR_BADLAYOUT,\r
1374 * -FDT_ERR_TRUNCATED, standard meanings\r
1375 */\r
1376#define fdt_appendprop_string(fdt, nodeoffset, name, str) \\r
1377 fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)\r
1378\r
1379/**\r
1380 * fdt_delprop - delete a property\r
1381 * @fdt: pointer to the device tree blob\r
1382 * @nodeoffset: offset of the node whose property to nop\r
1383 * @name: name of the property to nop\r
1384 *\r
1385 * fdt_del_property() will delete the given property.\r
1386 *\r
1387 * This function will delete data from the blob, and will therefore\r
1388 * change the offsets of some existing nodes.\r
1389 *\r
1390 * returns:\r
1391 * 0, on success\r
1392 * -FDT_ERR_NOTFOUND, node does not have the named property\r
1393 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1394 * -FDT_ERR_BADLAYOUT,\r
1395 * -FDT_ERR_BADMAGIC,\r
1396 * -FDT_ERR_BADVERSION,\r
1397 * -FDT_ERR_BADSTATE,\r
1398 * -FDT_ERR_BADSTRUCTURE,\r
1399 * -FDT_ERR_TRUNCATED, standard meanings\r
1400 */\r
1401int fdt_delprop(void *fdt, int nodeoffset, const char *name);\r
1402\r
1403/**\r
1404 * fdt_add_subnode_namelen - creates a new node based on substring\r
1405 * @fdt: pointer to the device tree blob\r
1406 * @parentoffset: structure block offset of a node\r
1407 * @name: name of the subnode to locate\r
1408 * @namelen: number of characters of name to consider\r
1409 *\r
1410 * Identical to fdt_add_subnode(), but use only the first namelen\r
1411 * characters of name as the name of the new node. This is useful for\r
1412 * creating subnodes based on a portion of a larger string, such as a\r
1413 * full path.\r
1414 */\r
1415int fdt_add_subnode_namelen(void *fdt, int parentoffset,\r
1416 const char *name, int namelen);\r
1417\r
1418/**\r
1419 * fdt_add_subnode - creates a new node\r
1420 * @fdt: pointer to the device tree blob\r
1421 * @parentoffset: structure block offset of a node\r
1422 * @name: name of the subnode to locate\r
1423 *\r
1424 * fdt_add_subnode() creates a new node as a subnode of the node at\r
1425 * structure block offset parentoffset, with the given name (which\r
1426 * should include the unit address, if any).\r
1427 *\r
1428 * This function will insert data into the blob, and will therefore\r
1429 * change the offsets of some existing nodes.\r
1430\r
1431 * returns:\r
1432 * structure block offset of the created nodeequested subnode (>=0), on success\r
1433 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist\r
1434 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag\r
1435 * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of\r
1436 * the given name\r
1437 * -FDT_ERR_NOSPACE, if there is insufficient free space in the\r
1438 * blob to contain the new node\r
1439 * -FDT_ERR_NOSPACE\r
1440 * -FDT_ERR_BADLAYOUT\r
1441 * -FDT_ERR_BADMAGIC,\r
1442 * -FDT_ERR_BADVERSION,\r
1443 * -FDT_ERR_BADSTATE,\r
1444 * -FDT_ERR_BADSTRUCTURE,\r
1445 * -FDT_ERR_TRUNCATED, standard meanings.\r
1446 */\r
1447int fdt_add_subnode(void *fdt, int parentoffset, const char *name);\r
1448\r
1449/**\r
1450 * fdt_del_node - delete a node (subtree)\r
1451 * @fdt: pointer to the device tree blob\r
1452 * @nodeoffset: offset of the node to nop\r
1453 *\r
1454 * fdt_del_node() will remove the given node, including all its\r
1455 * subnodes if any, from the blob.\r
1456 *\r
1457 * This function will delete data from the blob, and will therefore\r
1458 * change the offsets of some existing nodes.\r
1459 *\r
1460 * returns:\r
1461 * 0, on success\r
1462 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
1463 * -FDT_ERR_BADLAYOUT,\r
1464 * -FDT_ERR_BADMAGIC,\r
1465 * -FDT_ERR_BADVERSION,\r
1466 * -FDT_ERR_BADSTATE,\r
1467 * -FDT_ERR_BADSTRUCTURE,\r
1468 * -FDT_ERR_TRUNCATED, standard meanings\r
1469 */\r
1470int fdt_del_node(void *fdt, int nodeoffset);\r
1471\r
1472/**********************************************************************/\r
1473/* Debugging / informational functions */\r
1474/**********************************************************************/\r
1475\r
1476const char *fdt_strerror(int errval);\r
1477\r
1478#endif /* _LIBFDT_H */\r