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