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