xref: /utopia/UTPA2-700.0.x/projects/build/scripts/dtc/libfdt/libfdt.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1*53ee8cc1Swenshuai.xi #ifndef _LIBFDT_H
2*53ee8cc1Swenshuai.xi #define _LIBFDT_H
3*53ee8cc1Swenshuai.xi /*
4*53ee8cc1Swenshuai.xi  * libfdt - Flat Device Tree manipulation
5*53ee8cc1Swenshuai.xi  * Copyright (C) 2006 David Gibson, IBM Corporation.
6*53ee8cc1Swenshuai.xi  *
7*53ee8cc1Swenshuai.xi  * libfdt is dual licensed: you can use it either under the terms of
8*53ee8cc1Swenshuai.xi  * the GPL, or the BSD license, at your option.
9*53ee8cc1Swenshuai.xi  *
10*53ee8cc1Swenshuai.xi  *  a) This library is free software; you can redistribute it and/or
11*53ee8cc1Swenshuai.xi  *     modify it under the terms of the GNU General Public License as
12*53ee8cc1Swenshuai.xi  *     published by the Free Software Foundation; either version 2 of the
13*53ee8cc1Swenshuai.xi  *     License, or (at your option) any later version.
14*53ee8cc1Swenshuai.xi  *
15*53ee8cc1Swenshuai.xi  *     This library is distributed in the hope that it will be useful,
16*53ee8cc1Swenshuai.xi  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
17*53ee8cc1Swenshuai.xi  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*53ee8cc1Swenshuai.xi  *     GNU General Public License for more details.
19*53ee8cc1Swenshuai.xi  *
20*53ee8cc1Swenshuai.xi  *     You should have received a copy of the GNU General Public
21*53ee8cc1Swenshuai.xi  *     License along with this library; if not, write to the Free
22*53ee8cc1Swenshuai.xi  *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
23*53ee8cc1Swenshuai.xi  *     MA 02110-1301 USA
24*53ee8cc1Swenshuai.xi  *
25*53ee8cc1Swenshuai.xi  * Alternatively,
26*53ee8cc1Swenshuai.xi  *
27*53ee8cc1Swenshuai.xi  *  b) Redistribution and use in source and binary forms, with or
28*53ee8cc1Swenshuai.xi  *     without modification, are permitted provided that the following
29*53ee8cc1Swenshuai.xi  *     conditions are met:
30*53ee8cc1Swenshuai.xi  *
31*53ee8cc1Swenshuai.xi  *     1. Redistributions of source code must retain the above
32*53ee8cc1Swenshuai.xi  *        copyright notice, this list of conditions and the following
33*53ee8cc1Swenshuai.xi  *        disclaimer.
34*53ee8cc1Swenshuai.xi  *     2. Redistributions in binary form must reproduce the above
35*53ee8cc1Swenshuai.xi  *        copyright notice, this list of conditions and the following
36*53ee8cc1Swenshuai.xi  *        disclaimer in the documentation and/or other materials
37*53ee8cc1Swenshuai.xi  *        provided with the distribution.
38*53ee8cc1Swenshuai.xi  *
39*53ee8cc1Swenshuai.xi  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
40*53ee8cc1Swenshuai.xi  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
41*53ee8cc1Swenshuai.xi  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42*53ee8cc1Swenshuai.xi  *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43*53ee8cc1Swenshuai.xi  *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
44*53ee8cc1Swenshuai.xi  *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45*53ee8cc1Swenshuai.xi  *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46*53ee8cc1Swenshuai.xi  *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47*53ee8cc1Swenshuai.xi  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48*53ee8cc1Swenshuai.xi  *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49*53ee8cc1Swenshuai.xi  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
50*53ee8cc1Swenshuai.xi  *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
51*53ee8cc1Swenshuai.xi  *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52*53ee8cc1Swenshuai.xi  */
53*53ee8cc1Swenshuai.xi 
54*53ee8cc1Swenshuai.xi #include <libfdt_env.h>
55*53ee8cc1Swenshuai.xi #include <fdt.h>
56*53ee8cc1Swenshuai.xi 
57*53ee8cc1Swenshuai.xi #define FDT_FIRST_SUPPORTED_VERSION	0x10
58*53ee8cc1Swenshuai.xi #define FDT_LAST_SUPPORTED_VERSION	0x11
59*53ee8cc1Swenshuai.xi 
60*53ee8cc1Swenshuai.xi /* Error codes: informative error codes */
61*53ee8cc1Swenshuai.xi #define FDT_ERR_NOTFOUND	1
62*53ee8cc1Swenshuai.xi 	/* FDT_ERR_NOTFOUND: The requested node or property does not exist */
63*53ee8cc1Swenshuai.xi #define FDT_ERR_EXISTS		2
64*53ee8cc1Swenshuai.xi 	/* FDT_ERR_EXISTS: Attempted to create a node or property which
65*53ee8cc1Swenshuai.xi 	 * already exists */
66*53ee8cc1Swenshuai.xi #define FDT_ERR_NOSPACE		3
67*53ee8cc1Swenshuai.xi 	/* FDT_ERR_NOSPACE: Operation needed to expand the device
68*53ee8cc1Swenshuai.xi 	 * tree, but its buffer did not have sufficient space to
69*53ee8cc1Swenshuai.xi 	 * contain the expanded tree. Use fdt_open_into() to move the
70*53ee8cc1Swenshuai.xi 	 * device tree to a buffer with more space. */
71*53ee8cc1Swenshuai.xi 
72*53ee8cc1Swenshuai.xi /* Error codes: codes for bad parameters */
73*53ee8cc1Swenshuai.xi #define FDT_ERR_BADOFFSET	4
74*53ee8cc1Swenshuai.xi 	/* FDT_ERR_BADOFFSET: Function was passed a structure block
75*53ee8cc1Swenshuai.xi 	 * offset which is out-of-bounds, or which points to an
76*53ee8cc1Swenshuai.xi 	 * unsuitable part of the structure for the operation. */
77*53ee8cc1Swenshuai.xi #define FDT_ERR_BADPATH		5
78*53ee8cc1Swenshuai.xi 	/* FDT_ERR_BADPATH: Function was passed a badly formatted path
79*53ee8cc1Swenshuai.xi 	 * (e.g. missing a leading / for a function which requires an
80*53ee8cc1Swenshuai.xi 	 * absolute path) */
81*53ee8cc1Swenshuai.xi #define FDT_ERR_BADPHANDLE	6
82*53ee8cc1Swenshuai.xi 	/* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle
83*53ee8cc1Swenshuai.xi 	 * value.  phandle values of 0 and -1 are not permitted. */
84*53ee8cc1Swenshuai.xi #define FDT_ERR_BADSTATE	7
85*53ee8cc1Swenshuai.xi 	/* FDT_ERR_BADSTATE: Function was passed an incomplete device
86*53ee8cc1Swenshuai.xi 	 * tree created by the sequential-write functions, which is
87*53ee8cc1Swenshuai.xi 	 * not sufficiently complete for the requested operation. */
88*53ee8cc1Swenshuai.xi 
89*53ee8cc1Swenshuai.xi /* Error codes: codes for bad device tree blobs */
90*53ee8cc1Swenshuai.xi #define FDT_ERR_TRUNCATED	8
91*53ee8cc1Swenshuai.xi 	/* FDT_ERR_TRUNCATED: Structure block of the given device tree
92*53ee8cc1Swenshuai.xi 	 * ends without an FDT_END tag. */
93*53ee8cc1Swenshuai.xi #define FDT_ERR_BADMAGIC	9
94*53ee8cc1Swenshuai.xi 	/* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
95*53ee8cc1Swenshuai.xi 	 * device tree at all - it is missing the flattened device
96*53ee8cc1Swenshuai.xi 	 * tree magic number. */
97*53ee8cc1Swenshuai.xi #define FDT_ERR_BADVERSION	10
98*53ee8cc1Swenshuai.xi 	/* FDT_ERR_BADVERSION: Given device tree has a version which
99*53ee8cc1Swenshuai.xi 	 * can't be handled by the requested operation.  For
100*53ee8cc1Swenshuai.xi 	 * read-write functions, this may mean that fdt_open_into() is
101*53ee8cc1Swenshuai.xi 	 * required to convert the tree to the expected version. */
102*53ee8cc1Swenshuai.xi #define FDT_ERR_BADSTRUCTURE	11
103*53ee8cc1Swenshuai.xi 	/* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
104*53ee8cc1Swenshuai.xi 	 * structure block or other serious error (e.g. misnested
105*53ee8cc1Swenshuai.xi 	 * nodes, or subnodes preceding properties). */
106*53ee8cc1Swenshuai.xi #define FDT_ERR_BADLAYOUT	12
107*53ee8cc1Swenshuai.xi 	/* FDT_ERR_BADLAYOUT: For read-write functions, the given
108*53ee8cc1Swenshuai.xi 	 * device tree has it's sub-blocks in an order that the
109*53ee8cc1Swenshuai.xi 	 * function can't handle (memory reserve map, then structure,
110*53ee8cc1Swenshuai.xi 	 * then strings).  Use fdt_open_into() to reorganize the tree
111*53ee8cc1Swenshuai.xi 	 * into a form suitable for the read-write operations. */
112*53ee8cc1Swenshuai.xi 
113*53ee8cc1Swenshuai.xi /* "Can't happen" error indicating a bug in libfdt */
114*53ee8cc1Swenshuai.xi #define FDT_ERR_INTERNAL	13
115*53ee8cc1Swenshuai.xi 	/* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
116*53ee8cc1Swenshuai.xi 	 * Should never be returned, if it is, it indicates a bug in
117*53ee8cc1Swenshuai.xi 	 * libfdt itself. */
118*53ee8cc1Swenshuai.xi 
119*53ee8cc1Swenshuai.xi #define FDT_ERR_MAX		13
120*53ee8cc1Swenshuai.xi 
121*53ee8cc1Swenshuai.xi /**********************************************************************/
122*53ee8cc1Swenshuai.xi /* Low-level functions (you probably don't need these)                */
123*53ee8cc1Swenshuai.xi /**********************************************************************/
124*53ee8cc1Swenshuai.xi 
125*53ee8cc1Swenshuai.xi const void *fdt_offset_ptr(const void *fdt, int offset, int checklen);
fdt_offset_ptr_w(void * fdt,int offset,int checklen)126*53ee8cc1Swenshuai.xi static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
127*53ee8cc1Swenshuai.xi {
128*53ee8cc1Swenshuai.xi 	return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
129*53ee8cc1Swenshuai.xi }
130*53ee8cc1Swenshuai.xi 
131*53ee8cc1Swenshuai.xi uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
132*53ee8cc1Swenshuai.xi 
133*53ee8cc1Swenshuai.xi /**********************************************************************/
134*53ee8cc1Swenshuai.xi /* Traversal functions                                                */
135*53ee8cc1Swenshuai.xi /**********************************************************************/
136*53ee8cc1Swenshuai.xi 
137*53ee8cc1Swenshuai.xi int fdt_next_node(const void *fdt, int offset, int *depth);
138*53ee8cc1Swenshuai.xi 
139*53ee8cc1Swenshuai.xi /**********************************************************************/
140*53ee8cc1Swenshuai.xi /* General functions                                                  */
141*53ee8cc1Swenshuai.xi /**********************************************************************/
142*53ee8cc1Swenshuai.xi 
143*53ee8cc1Swenshuai.xi #define fdt_get_header(fdt, field) \
144*53ee8cc1Swenshuai.xi 	(fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
145*53ee8cc1Swenshuai.xi #define fdt_magic(fdt) 			(fdt_get_header(fdt, magic))
146*53ee8cc1Swenshuai.xi #define fdt_totalsize(fdt)		(fdt_get_header(fdt, totalsize))
147*53ee8cc1Swenshuai.xi #define fdt_off_dt_struct(fdt)		(fdt_get_header(fdt, off_dt_struct))
148*53ee8cc1Swenshuai.xi #define fdt_off_dt_strings(fdt)		(fdt_get_header(fdt, off_dt_strings))
149*53ee8cc1Swenshuai.xi #define fdt_off_mem_rsvmap(fdt)		(fdt_get_header(fdt, off_mem_rsvmap))
150*53ee8cc1Swenshuai.xi #define fdt_version(fdt)		(fdt_get_header(fdt, version))
151*53ee8cc1Swenshuai.xi #define fdt_last_comp_version(fdt) 	(fdt_get_header(fdt, last_comp_version))
152*53ee8cc1Swenshuai.xi #define fdt_boot_cpuid_phys(fdt) 	(fdt_get_header(fdt, boot_cpuid_phys))
153*53ee8cc1Swenshuai.xi #define fdt_size_dt_strings(fdt) 	(fdt_get_header(fdt, size_dt_strings))
154*53ee8cc1Swenshuai.xi #define fdt_size_dt_struct(fdt)		(fdt_get_header(fdt, size_dt_struct))
155*53ee8cc1Swenshuai.xi 
156*53ee8cc1Swenshuai.xi #define __fdt_set_hdr(name) \
157*53ee8cc1Swenshuai.xi 	static inline void fdt_set_##name(void *fdt, uint32_t val) \
158*53ee8cc1Swenshuai.xi 	{ \
159*53ee8cc1Swenshuai.xi 		struct fdt_header *fdth = fdt; \
160*53ee8cc1Swenshuai.xi 		fdth->name = cpu_to_fdt32(val); \
161*53ee8cc1Swenshuai.xi 	}
162*53ee8cc1Swenshuai.xi __fdt_set_hdr(magic);
163*53ee8cc1Swenshuai.xi __fdt_set_hdr(totalsize);
164*53ee8cc1Swenshuai.xi __fdt_set_hdr(off_dt_struct);
165*53ee8cc1Swenshuai.xi __fdt_set_hdr(off_dt_strings);
166*53ee8cc1Swenshuai.xi __fdt_set_hdr(off_mem_rsvmap);
167*53ee8cc1Swenshuai.xi __fdt_set_hdr(version);
168*53ee8cc1Swenshuai.xi __fdt_set_hdr(last_comp_version);
169*53ee8cc1Swenshuai.xi __fdt_set_hdr(boot_cpuid_phys);
170*53ee8cc1Swenshuai.xi __fdt_set_hdr(size_dt_strings);
171*53ee8cc1Swenshuai.xi __fdt_set_hdr(size_dt_struct);
172*53ee8cc1Swenshuai.xi #undef __fdt_set_hdr
173*53ee8cc1Swenshuai.xi 
174*53ee8cc1Swenshuai.xi /**
175*53ee8cc1Swenshuai.xi  * fdt_check_header - sanity check a device tree or possible device tree
176*53ee8cc1Swenshuai.xi  * @fdt: pointer to data which might be a flattened device tree
177*53ee8cc1Swenshuai.xi  *
178*53ee8cc1Swenshuai.xi  * fdt_check_header() checks that the given buffer contains what
179*53ee8cc1Swenshuai.xi  * appears to be a flattened device tree with sane information in its
180*53ee8cc1Swenshuai.xi  * header.
181*53ee8cc1Swenshuai.xi  *
182*53ee8cc1Swenshuai.xi  * returns:
183*53ee8cc1Swenshuai.xi  *     0, if the buffer appears to contain a valid device tree
184*53ee8cc1Swenshuai.xi  *     -FDT_ERR_BADMAGIC,
185*53ee8cc1Swenshuai.xi  *     -FDT_ERR_BADVERSION,
186*53ee8cc1Swenshuai.xi  *     -FDT_ERR_BADSTATE, standard meanings, as above
187*53ee8cc1Swenshuai.xi  */
188*53ee8cc1Swenshuai.xi int fdt_check_header(const void *fdt);
189*53ee8cc1Swenshuai.xi 
190*53ee8cc1Swenshuai.xi /**
191*53ee8cc1Swenshuai.xi  * fdt_move - move a device tree around in memory
192*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree to move
193*53ee8cc1Swenshuai.xi  * @buf: pointer to memory where the device is to be moved
194*53ee8cc1Swenshuai.xi  * @bufsize: size of the memory space at buf
195*53ee8cc1Swenshuai.xi  *
196*53ee8cc1Swenshuai.xi  * fdt_move() relocates, if possible, the device tree blob located at
197*53ee8cc1Swenshuai.xi  * fdt to the buffer at buf of size bufsize.  The buffer may overlap
198*53ee8cc1Swenshuai.xi  * with the existing device tree blob at fdt.  Therefore,
199*53ee8cc1Swenshuai.xi  *     fdt_move(fdt, fdt, fdt_totalsize(fdt))
200*53ee8cc1Swenshuai.xi  * should always succeed.
201*53ee8cc1Swenshuai.xi  *
202*53ee8cc1Swenshuai.xi  * returns:
203*53ee8cc1Swenshuai.xi  *     0, on success
204*53ee8cc1Swenshuai.xi  *     -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
205*53ee8cc1Swenshuai.xi  *     -FDT_ERR_BADMAGIC,
206*53ee8cc1Swenshuai.xi  *     -FDT_ERR_BADVERSION,
207*53ee8cc1Swenshuai.xi  *     -FDT_ERR_BADSTATE, standard meanings
208*53ee8cc1Swenshuai.xi  */
209*53ee8cc1Swenshuai.xi int fdt_move(const void *fdt, void *buf, int bufsize);
210*53ee8cc1Swenshuai.xi 
211*53ee8cc1Swenshuai.xi /**********************************************************************/
212*53ee8cc1Swenshuai.xi /* Read-only functions                                                */
213*53ee8cc1Swenshuai.xi /**********************************************************************/
214*53ee8cc1Swenshuai.xi 
215*53ee8cc1Swenshuai.xi /**
216*53ee8cc1Swenshuai.xi  * fdt_string - retrieve a string from the strings block of a device tree
217*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
218*53ee8cc1Swenshuai.xi  * @stroffset: offset of the string within the strings block (native endian)
219*53ee8cc1Swenshuai.xi  *
220*53ee8cc1Swenshuai.xi  * fdt_string() retrieves a pointer to a single string from the
221*53ee8cc1Swenshuai.xi  * strings block of the device tree blob at fdt.
222*53ee8cc1Swenshuai.xi  *
223*53ee8cc1Swenshuai.xi  * returns:
224*53ee8cc1Swenshuai.xi  *     a pointer to the string, on success
225*53ee8cc1Swenshuai.xi  *     NULL, if stroffset is out of bounds
226*53ee8cc1Swenshuai.xi  */
227*53ee8cc1Swenshuai.xi const char *fdt_string(const void *fdt, int stroffset);
228*53ee8cc1Swenshuai.xi 
229*53ee8cc1Swenshuai.xi /**
230*53ee8cc1Swenshuai.xi  * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
231*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
232*53ee8cc1Swenshuai.xi  *
233*53ee8cc1Swenshuai.xi  * Returns the number of entries in the device tree blob's memory
234*53ee8cc1Swenshuai.xi  * reservation map.  This does not include the terminating 0,0 entry
235*53ee8cc1Swenshuai.xi  * or any other (0,0) entries reserved for expansion.
236*53ee8cc1Swenshuai.xi  *
237*53ee8cc1Swenshuai.xi  * returns:
238*53ee8cc1Swenshuai.xi  *     the number of entries
239*53ee8cc1Swenshuai.xi  */
240*53ee8cc1Swenshuai.xi int fdt_num_mem_rsv(const void *fdt);
241*53ee8cc1Swenshuai.xi 
242*53ee8cc1Swenshuai.xi /**
243*53ee8cc1Swenshuai.xi  * fdt_get_mem_rsv - retrieve one memory reserve map entry
244*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
245*53ee8cc1Swenshuai.xi  * @address, @size: pointers to 64-bit variables
246*53ee8cc1Swenshuai.xi  *
247*53ee8cc1Swenshuai.xi  * On success, *address and *size will contain the address and size of
248*53ee8cc1Swenshuai.xi  * the n-th reserve map entry from the device tree blob, in
249*53ee8cc1Swenshuai.xi  * native-endian format.
250*53ee8cc1Swenshuai.xi  *
251*53ee8cc1Swenshuai.xi  * returns:
252*53ee8cc1Swenshuai.xi  *     0, on success
253*53ee8cc1Swenshuai.xi  *     -FDT_ERR_BADMAGIC,
254*53ee8cc1Swenshuai.xi  *     -FDT_ERR_BADVERSION,
255*53ee8cc1Swenshuai.xi  *     -FDT_ERR_BADSTATE, standard meanings
256*53ee8cc1Swenshuai.xi  */
257*53ee8cc1Swenshuai.xi int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
258*53ee8cc1Swenshuai.xi 
259*53ee8cc1Swenshuai.xi /**
260*53ee8cc1Swenshuai.xi  * fdt_subnode_offset_namelen - find a subnode based on substring
261*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
262*53ee8cc1Swenshuai.xi  * @parentoffset: structure block offset of a node
263*53ee8cc1Swenshuai.xi  * @name: name of the subnode to locate
264*53ee8cc1Swenshuai.xi  * @namelen: number of characters of name to consider
265*53ee8cc1Swenshuai.xi  *
266*53ee8cc1Swenshuai.xi  * Identical to fdt_subnode_offset(), but only examine the first
267*53ee8cc1Swenshuai.xi  * namelen characters of name for matching the subnode name.  This is
268*53ee8cc1Swenshuai.xi  * useful for finding subnodes based on a portion of a larger string,
269*53ee8cc1Swenshuai.xi  * such as a full path.
270*53ee8cc1Swenshuai.xi  */
271*53ee8cc1Swenshuai.xi int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
272*53ee8cc1Swenshuai.xi 			       const char *name, int namelen);
273*53ee8cc1Swenshuai.xi /**
274*53ee8cc1Swenshuai.xi  * fdt_subnode_offset - find a subnode of a given node
275*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
276*53ee8cc1Swenshuai.xi  * @parentoffset: structure block offset of a node
277*53ee8cc1Swenshuai.xi  * @name: name of the subnode to locate
278*53ee8cc1Swenshuai.xi  *
279*53ee8cc1Swenshuai.xi  * fdt_subnode_offset() finds a subnode of the node at structure block
280*53ee8cc1Swenshuai.xi  * offset parentoffset with the given name.  name may include a unit
281*53ee8cc1Swenshuai.xi  * address, in which case fdt_subnode_offset() will find the subnode
282*53ee8cc1Swenshuai.xi  * with that unit address, or the unit address may be omitted, in
283*53ee8cc1Swenshuai.xi  * which case fdt_subnode_offset() will find an arbitrary subnode
284*53ee8cc1Swenshuai.xi  * whose name excluding unit address matches the given name.
285*53ee8cc1Swenshuai.xi  *
286*53ee8cc1Swenshuai.xi  * returns:
287*53ee8cc1Swenshuai.xi  *	structure block offset of the requested subnode (>=0), on success
288*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
289*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
290*53ee8cc1Swenshuai.xi  *      -FDT_ERR_BADMAGIC,
291*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
292*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
293*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
294*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings.
295*53ee8cc1Swenshuai.xi  */
296*53ee8cc1Swenshuai.xi int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
297*53ee8cc1Swenshuai.xi 
298*53ee8cc1Swenshuai.xi /**
299*53ee8cc1Swenshuai.xi  * fdt_path_offset - find a tree node by its full path
300*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
301*53ee8cc1Swenshuai.xi  * @path: full path of the node to locate
302*53ee8cc1Swenshuai.xi  *
303*53ee8cc1Swenshuai.xi  * fdt_path_offset() finds a node of a given path in the device tree.
304*53ee8cc1Swenshuai.xi  * Each path component may omit the unit address portion, but the
305*53ee8cc1Swenshuai.xi  * results of this are undefined if any such path component is
306*53ee8cc1Swenshuai.xi  * ambiguous (that is if there are multiple nodes at the relevant
307*53ee8cc1Swenshuai.xi  * level matching the given component, differentiated only by unit
308*53ee8cc1Swenshuai.xi  * address).
309*53ee8cc1Swenshuai.xi  *
310*53ee8cc1Swenshuai.xi  * returns:
311*53ee8cc1Swenshuai.xi  *	structure block offset of the node with the requested path (>=0), on success
312*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
313*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, if the requested node does not exist
314*53ee8cc1Swenshuai.xi  *      -FDT_ERR_BADMAGIC,
315*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
316*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
317*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
318*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings.
319*53ee8cc1Swenshuai.xi  */
320*53ee8cc1Swenshuai.xi int fdt_path_offset(const void *fdt, const char *path);
321*53ee8cc1Swenshuai.xi 
322*53ee8cc1Swenshuai.xi /**
323*53ee8cc1Swenshuai.xi  * fdt_get_name - retrieve the name of a given node
324*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
325*53ee8cc1Swenshuai.xi  * @nodeoffset: structure block offset of the starting node
326*53ee8cc1Swenshuai.xi  * @lenp: pointer to an integer variable (will be overwritten) or NULL
327*53ee8cc1Swenshuai.xi  *
328*53ee8cc1Swenshuai.xi  * fdt_get_name() retrieves the name (including unit address) of the
329*53ee8cc1Swenshuai.xi  * device tree node at structure block offset nodeoffset.  If lenp is
330*53ee8cc1Swenshuai.xi  * non-NULL, the length of this name is also returned, in the integer
331*53ee8cc1Swenshuai.xi  * pointed to by lenp.
332*53ee8cc1Swenshuai.xi  *
333*53ee8cc1Swenshuai.xi  * returns:
334*53ee8cc1Swenshuai.xi  *	pointer to the node's name, on success
335*53ee8cc1Swenshuai.xi  *		If lenp is non-NULL, *lenp contains the length of that name (>=0)
336*53ee8cc1Swenshuai.xi  *	NULL, on error
337*53ee8cc1Swenshuai.xi  *		if lenp is non-NULL *lenp contains an error code (<0):
338*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
339*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADMAGIC,
340*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADVERSION,
341*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADSTATE, standard meanings
342*53ee8cc1Swenshuai.xi  */
343*53ee8cc1Swenshuai.xi const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
344*53ee8cc1Swenshuai.xi 
345*53ee8cc1Swenshuai.xi /**
346*53ee8cc1Swenshuai.xi  * fdt_get_property - find a given property in a given node
347*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
348*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose property to find
349*53ee8cc1Swenshuai.xi  * @name: name of the property to find
350*53ee8cc1Swenshuai.xi  * @lenp: pointer to an integer variable (will be overwritten) or NULL
351*53ee8cc1Swenshuai.xi  *
352*53ee8cc1Swenshuai.xi  * fdt_get_property() retrieves a pointer to the fdt_property
353*53ee8cc1Swenshuai.xi  * structure within the device tree blob corresponding to the property
354*53ee8cc1Swenshuai.xi  * named 'name' of the node at offset nodeoffset.  If lenp is
355*53ee8cc1Swenshuai.xi  * non-NULL, the length of the property value is also returned, in the
356*53ee8cc1Swenshuai.xi  * integer pointed to by lenp.
357*53ee8cc1Swenshuai.xi  *
358*53ee8cc1Swenshuai.xi  * returns:
359*53ee8cc1Swenshuai.xi  *	pointer to the structure representing the property
360*53ee8cc1Swenshuai.xi  *		if lenp is non-NULL, *lenp contains the length of the property
361*53ee8cc1Swenshuai.xi  *		value (>=0)
362*53ee8cc1Swenshuai.xi  *	NULL, on error
363*53ee8cc1Swenshuai.xi  *		if lenp is non-NULL, *lenp contains an error code (<0):
364*53ee8cc1Swenshuai.xi  *		-FDT_ERR_NOTFOUND, node does not have named property
365*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
366*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADMAGIC,
367*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADVERSION,
368*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADSTATE,
369*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADSTRUCTURE,
370*53ee8cc1Swenshuai.xi  *		-FDT_ERR_TRUNCATED, standard meanings
371*53ee8cc1Swenshuai.xi  */
372*53ee8cc1Swenshuai.xi const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
373*53ee8cc1Swenshuai.xi 					    const char *name, int *lenp);
fdt_get_property_w(void * fdt,int nodeoffset,const char * name,int * lenp)374*53ee8cc1Swenshuai.xi static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
375*53ee8cc1Swenshuai.xi 						      const char *name,
376*53ee8cc1Swenshuai.xi 						      int *lenp)
377*53ee8cc1Swenshuai.xi {
378*53ee8cc1Swenshuai.xi 	return (struct fdt_property *)(uintptr_t)
379*53ee8cc1Swenshuai.xi 		fdt_get_property(fdt, nodeoffset, name, lenp);
380*53ee8cc1Swenshuai.xi }
381*53ee8cc1Swenshuai.xi 
382*53ee8cc1Swenshuai.xi /**
383*53ee8cc1Swenshuai.xi  * fdt_getprop - retrieve the value of a given property
384*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
385*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose property to find
386*53ee8cc1Swenshuai.xi  * @name: name of the property to find
387*53ee8cc1Swenshuai.xi  * @lenp: pointer to an integer variable (will be overwritten) or NULL
388*53ee8cc1Swenshuai.xi  *
389*53ee8cc1Swenshuai.xi  * fdt_getprop() retrieves a pointer to the value of the property
390*53ee8cc1Swenshuai.xi  * named 'name' of the node at offset nodeoffset (this will be a
391*53ee8cc1Swenshuai.xi  * pointer to within the device blob itself, not a copy of the value).
392*53ee8cc1Swenshuai.xi  * If lenp is non-NULL, the length of the property value is also
393*53ee8cc1Swenshuai.xi  * returned, in the integer pointed to by lenp.
394*53ee8cc1Swenshuai.xi  *
395*53ee8cc1Swenshuai.xi  * returns:
396*53ee8cc1Swenshuai.xi  *	pointer to the property's value
397*53ee8cc1Swenshuai.xi  *		if lenp is non-NULL, *lenp contains the length of the property
398*53ee8cc1Swenshuai.xi  *		value (>=0)
399*53ee8cc1Swenshuai.xi  *	NULL, on error
400*53ee8cc1Swenshuai.xi  *		if lenp is non-NULL, *lenp contains an error code (<0):
401*53ee8cc1Swenshuai.xi  *		-FDT_ERR_NOTFOUND, node does not have named property
402*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
403*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADMAGIC,
404*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADVERSION,
405*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADSTATE,
406*53ee8cc1Swenshuai.xi  *		-FDT_ERR_BADSTRUCTURE,
407*53ee8cc1Swenshuai.xi  *		-FDT_ERR_TRUNCATED, standard meanings
408*53ee8cc1Swenshuai.xi  */
409*53ee8cc1Swenshuai.xi const void *fdt_getprop(const void *fdt, int nodeoffset,
410*53ee8cc1Swenshuai.xi 			const char *name, int *lenp);
fdt_getprop_w(void * fdt,int nodeoffset,const char * name,int * lenp)411*53ee8cc1Swenshuai.xi static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
412*53ee8cc1Swenshuai.xi 				  const char *name, int *lenp)
413*53ee8cc1Swenshuai.xi {
414*53ee8cc1Swenshuai.xi 	return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
415*53ee8cc1Swenshuai.xi }
416*53ee8cc1Swenshuai.xi 
417*53ee8cc1Swenshuai.xi /**
418*53ee8cc1Swenshuai.xi  * fdt_get_phandle - retrieve the phandle of a given node
419*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
420*53ee8cc1Swenshuai.xi  * @nodeoffset: structure block offset of the node
421*53ee8cc1Swenshuai.xi  *
422*53ee8cc1Swenshuai.xi  * fdt_get_phandle() retrieves the phandle of the device tree node at
423*53ee8cc1Swenshuai.xi  * structure block offset nodeoffset.
424*53ee8cc1Swenshuai.xi  *
425*53ee8cc1Swenshuai.xi  * returns:
426*53ee8cc1Swenshuai.xi  *	the phandle of the node at nodeoffset, on success (!= 0, != -1)
427*53ee8cc1Swenshuai.xi  *	0, if the node has no phandle, or another error occurs
428*53ee8cc1Swenshuai.xi  */
429*53ee8cc1Swenshuai.xi uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
430*53ee8cc1Swenshuai.xi 
431*53ee8cc1Swenshuai.xi /**
432*53ee8cc1Swenshuai.xi  * fdt_get_path - determine the full path of a node
433*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
434*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose path to find
435*53ee8cc1Swenshuai.xi  * @buf: character buffer to contain the returned path (will be overwritten)
436*53ee8cc1Swenshuai.xi  * @buflen: size of the character buffer at buf
437*53ee8cc1Swenshuai.xi  *
438*53ee8cc1Swenshuai.xi  * fdt_get_path() computes the full path of the node at offset
439*53ee8cc1Swenshuai.xi  * nodeoffset, and records that path in the buffer at buf.
440*53ee8cc1Swenshuai.xi  *
441*53ee8cc1Swenshuai.xi  * NOTE: This function is expensive, as it must scan the device tree
442*53ee8cc1Swenshuai.xi  * structure from the start to nodeoffset.
443*53ee8cc1Swenshuai.xi  *
444*53ee8cc1Swenshuai.xi  * returns:
445*53ee8cc1Swenshuai.xi  *	0, on success
446*53ee8cc1Swenshuai.xi  *		buf contains the absolute path of the node at
447*53ee8cc1Swenshuai.xi  *		nodeoffset, as a NUL-terminated string.
448*53ee8cc1Swenshuai.xi  * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
449*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
450*53ee8cc1Swenshuai.xi  *		characters and will not fit in the given buffer.
451*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
452*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
453*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
454*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE, standard meanings
455*53ee8cc1Swenshuai.xi  */
456*53ee8cc1Swenshuai.xi int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
457*53ee8cc1Swenshuai.xi 
458*53ee8cc1Swenshuai.xi /**
459*53ee8cc1Swenshuai.xi  * fdt_supernode_atdepth_offset - find a specific ancestor of a node
460*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
461*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose parent to find
462*53ee8cc1Swenshuai.xi  * @supernodedepth: depth of the ancestor to find
463*53ee8cc1Swenshuai.xi  * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
464*53ee8cc1Swenshuai.xi  *
465*53ee8cc1Swenshuai.xi  * fdt_supernode_atdepth_offset() finds an ancestor of the given node
466*53ee8cc1Swenshuai.xi  * at a specific depth from the root (where the root itself has depth
467*53ee8cc1Swenshuai.xi  * 0, its immediate subnodes depth 1 and so forth).  So
468*53ee8cc1Swenshuai.xi  *	fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
469*53ee8cc1Swenshuai.xi  * will always return 0, the offset of the root node.  If the node at
470*53ee8cc1Swenshuai.xi  * nodeoffset has depth D, then:
471*53ee8cc1Swenshuai.xi  *	fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
472*53ee8cc1Swenshuai.xi  * will return nodeoffset itself.
473*53ee8cc1Swenshuai.xi  *
474*53ee8cc1Swenshuai.xi  * NOTE: This function is expensive, as it must scan the device tree
475*53ee8cc1Swenshuai.xi  * structure from the start to nodeoffset.
476*53ee8cc1Swenshuai.xi  *
477*53ee8cc1Swenshuai.xi  * returns:
478*53ee8cc1Swenshuai.xi 
479*53ee8cc1Swenshuai.xi  *	structure block offset of the node at node offset's ancestor
480*53ee8cc1Swenshuai.xi  *		of depth supernodedepth (>=0), on success
481*53ee8cc1Swenshuai.xi  * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
482*53ee8cc1Swenshuai.xi *	-FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset
483*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
484*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
485*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
486*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE, standard meanings
487*53ee8cc1Swenshuai.xi  */
488*53ee8cc1Swenshuai.xi int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
489*53ee8cc1Swenshuai.xi 				 int supernodedepth, int *nodedepth);
490*53ee8cc1Swenshuai.xi 
491*53ee8cc1Swenshuai.xi /**
492*53ee8cc1Swenshuai.xi  * fdt_node_depth - find the depth of a given node
493*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
494*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose parent to find
495*53ee8cc1Swenshuai.xi  *
496*53ee8cc1Swenshuai.xi  * fdt_node_depth() finds the depth of a given node.  The root node
497*53ee8cc1Swenshuai.xi  * has depth 0, its immediate subnodes depth 1 and so forth.
498*53ee8cc1Swenshuai.xi  *
499*53ee8cc1Swenshuai.xi  * NOTE: This function is expensive, as it must scan the device tree
500*53ee8cc1Swenshuai.xi  * structure from the start to nodeoffset.
501*53ee8cc1Swenshuai.xi  *
502*53ee8cc1Swenshuai.xi  * returns:
503*53ee8cc1Swenshuai.xi  *	depth of the node at nodeoffset (>=0), on success
504*53ee8cc1Swenshuai.xi  * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
505*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
506*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
507*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
508*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE, standard meanings
509*53ee8cc1Swenshuai.xi  */
510*53ee8cc1Swenshuai.xi int fdt_node_depth(const void *fdt, int nodeoffset);
511*53ee8cc1Swenshuai.xi 
512*53ee8cc1Swenshuai.xi /**
513*53ee8cc1Swenshuai.xi  * fdt_parent_offset - find the parent of a given node
514*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
515*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose parent to find
516*53ee8cc1Swenshuai.xi  *
517*53ee8cc1Swenshuai.xi  * fdt_parent_offset() locates the parent node of a given node (that
518*53ee8cc1Swenshuai.xi  * is, it finds the offset of the node which contains the node at
519*53ee8cc1Swenshuai.xi  * nodeoffset as a subnode).
520*53ee8cc1Swenshuai.xi  *
521*53ee8cc1Swenshuai.xi  * NOTE: This function is expensive, as it must scan the device tree
522*53ee8cc1Swenshuai.xi  * structure from the start to nodeoffset, *twice*.
523*53ee8cc1Swenshuai.xi  *
524*53ee8cc1Swenshuai.xi  * returns:
525*53ee8cc1Swenshuai.xi  *	structure block offset of the parent of the node at nodeoffset
526*53ee8cc1Swenshuai.xi  *		(>=0), on success
527*53ee8cc1Swenshuai.xi  * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
528*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
529*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
530*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
531*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE, standard meanings
532*53ee8cc1Swenshuai.xi  */
533*53ee8cc1Swenshuai.xi int fdt_parent_offset(const void *fdt, int nodeoffset);
534*53ee8cc1Swenshuai.xi 
535*53ee8cc1Swenshuai.xi /**
536*53ee8cc1Swenshuai.xi  * fdt_node_offset_by_prop_value - find nodes with a given property value
537*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
538*53ee8cc1Swenshuai.xi  * @startoffset: only find nodes after this offset
539*53ee8cc1Swenshuai.xi  * @propname: property name to check
540*53ee8cc1Swenshuai.xi  * @propval: property value to search for
541*53ee8cc1Swenshuai.xi  * @proplen: length of the value in propval
542*53ee8cc1Swenshuai.xi  *
543*53ee8cc1Swenshuai.xi  * fdt_node_offset_by_prop_value() returns the offset of the first
544*53ee8cc1Swenshuai.xi  * node after startoffset, which has a property named propname whose
545*53ee8cc1Swenshuai.xi  * value is of length proplen and has value equal to propval; or if
546*53ee8cc1Swenshuai.xi  * startoffset is -1, the very first such node in the tree.
547*53ee8cc1Swenshuai.xi  *
548*53ee8cc1Swenshuai.xi  * To iterate through all nodes matching the criterion, the following
549*53ee8cc1Swenshuai.xi  * idiom can be used:
550*53ee8cc1Swenshuai.xi  *	offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
551*53ee8cc1Swenshuai.xi  *					       propval, proplen);
552*53ee8cc1Swenshuai.xi  *	while (offset != -FDT_ERR_NOTFOUND) {
553*53ee8cc1Swenshuai.xi  *		// other code here
554*53ee8cc1Swenshuai.xi  *		offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
555*53ee8cc1Swenshuai.xi  *						       propval, proplen);
556*53ee8cc1Swenshuai.xi  *	}
557*53ee8cc1Swenshuai.xi  *
558*53ee8cc1Swenshuai.xi  * Note the -1 in the first call to the function, if 0 is used here
559*53ee8cc1Swenshuai.xi  * instead, the function will never locate the root node, even if it
560*53ee8cc1Swenshuai.xi  * matches the criterion.
561*53ee8cc1Swenshuai.xi  *
562*53ee8cc1Swenshuai.xi  * returns:
563*53ee8cc1Swenshuai.xi  *	structure block offset of the located node (>= 0, >startoffset),
564*53ee8cc1Swenshuai.xi  *		 on success
565*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, no node matching the criterion exists in the
566*53ee8cc1Swenshuai.xi  *		tree after startoffset
567*53ee8cc1Swenshuai.xi  * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
568*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
569*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
570*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
571*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE, standard meanings
572*53ee8cc1Swenshuai.xi  */
573*53ee8cc1Swenshuai.xi int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
574*53ee8cc1Swenshuai.xi 				  const char *propname,
575*53ee8cc1Swenshuai.xi 				  const void *propval, int proplen);
576*53ee8cc1Swenshuai.xi 
577*53ee8cc1Swenshuai.xi /**
578*53ee8cc1Swenshuai.xi  * fdt_node_offset_by_phandle - find the node with a given phandle
579*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
580*53ee8cc1Swenshuai.xi  * @phandle: phandle value
581*53ee8cc1Swenshuai.xi  *
582*53ee8cc1Swenshuai.xi  * fdt_node_offset_by_phandle() returns the offset of the node
583*53ee8cc1Swenshuai.xi  * which has the given phandle value.  If there is more than one node
584*53ee8cc1Swenshuai.xi  * in the tree with the given phandle (an invalid tree), results are
585*53ee8cc1Swenshuai.xi  * undefined.
586*53ee8cc1Swenshuai.xi  *
587*53ee8cc1Swenshuai.xi  * returns:
588*53ee8cc1Swenshuai.xi  *	structure block offset of the located node (>= 0), on success
589*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, no node with that phandle exists
590*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
591*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
592*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
593*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
594*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE, standard meanings
595*53ee8cc1Swenshuai.xi  */
596*53ee8cc1Swenshuai.xi int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
597*53ee8cc1Swenshuai.xi 
598*53ee8cc1Swenshuai.xi /**
599*53ee8cc1Swenshuai.xi  * fdt_node_check_compatible: check a node's compatible property
600*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
601*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of a tree node
602*53ee8cc1Swenshuai.xi  * @compatible: string to match against
603*53ee8cc1Swenshuai.xi  *
604*53ee8cc1Swenshuai.xi  *
605*53ee8cc1Swenshuai.xi  * fdt_node_check_compatible() returns 0 if the given node contains a
606*53ee8cc1Swenshuai.xi  * 'compatible' property with the given string as one of its elements,
607*53ee8cc1Swenshuai.xi  * it returns non-zero otherwise, or on error.
608*53ee8cc1Swenshuai.xi  *
609*53ee8cc1Swenshuai.xi  * returns:
610*53ee8cc1Swenshuai.xi  *	0, if the node has a 'compatible' property listing the given string
611*53ee8cc1Swenshuai.xi  *	1, if the node has a 'compatible' property, but it does not list
612*53ee8cc1Swenshuai.xi  *		the given string
613*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
614*53ee8cc1Swenshuai.xi  * 	-FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
615*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
616*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
617*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
618*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE, standard meanings
619*53ee8cc1Swenshuai.xi  */
620*53ee8cc1Swenshuai.xi int fdt_node_check_compatible(const void *fdt, int nodeoffset,
621*53ee8cc1Swenshuai.xi 			      const char *compatible);
622*53ee8cc1Swenshuai.xi 
623*53ee8cc1Swenshuai.xi /**
624*53ee8cc1Swenshuai.xi  * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
625*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
626*53ee8cc1Swenshuai.xi  * @startoffset: only find nodes after this offset
627*53ee8cc1Swenshuai.xi  * @compatible: 'compatible' string to match against
628*53ee8cc1Swenshuai.xi  *
629*53ee8cc1Swenshuai.xi  * fdt_node_offset_by_compatible() returns the offset of the first
630*53ee8cc1Swenshuai.xi  * node after startoffset, which has a 'compatible' property which
631*53ee8cc1Swenshuai.xi  * lists the given compatible string; or if startoffset is -1, the
632*53ee8cc1Swenshuai.xi  * very first such node in the tree.
633*53ee8cc1Swenshuai.xi  *
634*53ee8cc1Swenshuai.xi  * To iterate through all nodes matching the criterion, the following
635*53ee8cc1Swenshuai.xi  * idiom can be used:
636*53ee8cc1Swenshuai.xi  *	offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
637*53ee8cc1Swenshuai.xi  *	while (offset != -FDT_ERR_NOTFOUND) {
638*53ee8cc1Swenshuai.xi  *		// other code here
639*53ee8cc1Swenshuai.xi  *		offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
640*53ee8cc1Swenshuai.xi  *	}
641*53ee8cc1Swenshuai.xi  *
642*53ee8cc1Swenshuai.xi  * Note the -1 in the first call to the function, if 0 is used here
643*53ee8cc1Swenshuai.xi  * instead, the function will never locate the root node, even if it
644*53ee8cc1Swenshuai.xi  * matches the criterion.
645*53ee8cc1Swenshuai.xi  *
646*53ee8cc1Swenshuai.xi  * returns:
647*53ee8cc1Swenshuai.xi  *	structure block offset of the located node (>= 0, >startoffset),
648*53ee8cc1Swenshuai.xi  *		 on success
649*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, no node matching the criterion exists in the
650*53ee8cc1Swenshuai.xi  *		tree after startoffset
651*53ee8cc1Swenshuai.xi  * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
652*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
653*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
654*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
655*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE, standard meanings
656*53ee8cc1Swenshuai.xi  */
657*53ee8cc1Swenshuai.xi int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
658*53ee8cc1Swenshuai.xi 				  const char *compatible);
659*53ee8cc1Swenshuai.xi 
660*53ee8cc1Swenshuai.xi /**********************************************************************/
661*53ee8cc1Swenshuai.xi /* Write-in-place functions                                           */
662*53ee8cc1Swenshuai.xi /**********************************************************************/
663*53ee8cc1Swenshuai.xi 
664*53ee8cc1Swenshuai.xi /**
665*53ee8cc1Swenshuai.xi  * fdt_setprop_inplace - change a property's value, but not its size
666*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
667*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose property to change
668*53ee8cc1Swenshuai.xi  * @name: name of the property to change
669*53ee8cc1Swenshuai.xi  * @val: pointer to data to replace the property value with
670*53ee8cc1Swenshuai.xi  * @len: length of the property value
671*53ee8cc1Swenshuai.xi  *
672*53ee8cc1Swenshuai.xi  * fdt_setprop_inplace() replaces the value of a given property with
673*53ee8cc1Swenshuai.xi  * the data in val, of length len.  This function cannot change the
674*53ee8cc1Swenshuai.xi  * size of a property, and so will only work if len is equal to the
675*53ee8cc1Swenshuai.xi  * current length of the property.
676*53ee8cc1Swenshuai.xi  *
677*53ee8cc1Swenshuai.xi  * This function will alter only the bytes in the blob which contain
678*53ee8cc1Swenshuai.xi  * the given property value, and will not alter or move any other part
679*53ee8cc1Swenshuai.xi  * of the tree.
680*53ee8cc1Swenshuai.xi  *
681*53ee8cc1Swenshuai.xi  * returns:
682*53ee8cc1Swenshuai.xi  *	0, on success
683*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOSPACE, if len is not equal to the property's current length
684*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, node does not have the named property
685*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
686*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
687*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
688*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
689*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
690*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
691*53ee8cc1Swenshuai.xi  */
692*53ee8cc1Swenshuai.xi int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
693*53ee8cc1Swenshuai.xi 			const void *val, int len);
694*53ee8cc1Swenshuai.xi 
695*53ee8cc1Swenshuai.xi /**
696*53ee8cc1Swenshuai.xi  * fdt_setprop_inplace_cell - change the value of a single-cell property
697*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
698*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose property to change
699*53ee8cc1Swenshuai.xi  * @name: name of the property to change
700*53ee8cc1Swenshuai.xi  * @val: cell (32-bit integer) value to replace the property with
701*53ee8cc1Swenshuai.xi  *
702*53ee8cc1Swenshuai.xi  * fdt_setprop_inplace_cell() replaces the value of a given property
703*53ee8cc1Swenshuai.xi  * with the 32-bit integer cell value in val, converting val to
704*53ee8cc1Swenshuai.xi  * big-endian if necessary.  This function cannot change the size of a
705*53ee8cc1Swenshuai.xi  * property, and so will only work if the property already exists and
706*53ee8cc1Swenshuai.xi  * has length 4.
707*53ee8cc1Swenshuai.xi  *
708*53ee8cc1Swenshuai.xi  * This function will alter only the bytes in the blob which contain
709*53ee8cc1Swenshuai.xi  * the given property value, and will not alter or move any other part
710*53ee8cc1Swenshuai.xi  * of the tree.
711*53ee8cc1Swenshuai.xi  *
712*53ee8cc1Swenshuai.xi  * returns:
713*53ee8cc1Swenshuai.xi  *	0, on success
714*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOSPACE, if the property's length is not equal to 4
715*53ee8cc1Swenshuai.xi   *	-FDT_ERR_NOTFOUND, node does not have the named property
716*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
717*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
718*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
719*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
720*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
721*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
722*53ee8cc1Swenshuai.xi  */
fdt_setprop_inplace_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)723*53ee8cc1Swenshuai.xi static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
724*53ee8cc1Swenshuai.xi 					   const char *name, uint32_t val)
725*53ee8cc1Swenshuai.xi {
726*53ee8cc1Swenshuai.xi 	val = cpu_to_fdt32(val);
727*53ee8cc1Swenshuai.xi 	return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
728*53ee8cc1Swenshuai.xi }
729*53ee8cc1Swenshuai.xi 
730*53ee8cc1Swenshuai.xi /**
731*53ee8cc1Swenshuai.xi  * fdt_nop_property - replace a property with nop tags
732*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
733*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose property to nop
734*53ee8cc1Swenshuai.xi  * @name: name of the property to nop
735*53ee8cc1Swenshuai.xi  *
736*53ee8cc1Swenshuai.xi  * fdt_nop_property() will replace a given property's representation
737*53ee8cc1Swenshuai.xi  * in the blob with FDT_NOP tags, effectively removing it from the
738*53ee8cc1Swenshuai.xi  * tree.
739*53ee8cc1Swenshuai.xi  *
740*53ee8cc1Swenshuai.xi  * This function will alter only the bytes in the blob which contain
741*53ee8cc1Swenshuai.xi  * the property, and will not alter or move any other part of the
742*53ee8cc1Swenshuai.xi  * tree.
743*53ee8cc1Swenshuai.xi  *
744*53ee8cc1Swenshuai.xi  * returns:
745*53ee8cc1Swenshuai.xi  *	0, on success
746*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, node does not have the named property
747*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
748*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
749*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
750*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
751*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
752*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
753*53ee8cc1Swenshuai.xi  */
754*53ee8cc1Swenshuai.xi int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
755*53ee8cc1Swenshuai.xi 
756*53ee8cc1Swenshuai.xi /**
757*53ee8cc1Swenshuai.xi  * fdt_nop_node - replace a node (subtree) with nop tags
758*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
759*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node to nop
760*53ee8cc1Swenshuai.xi  *
761*53ee8cc1Swenshuai.xi  * fdt_nop_node() will replace a given node's representation in the
762*53ee8cc1Swenshuai.xi  * blob, including all its subnodes, if any, with FDT_NOP tags,
763*53ee8cc1Swenshuai.xi  * effectively removing it from the tree.
764*53ee8cc1Swenshuai.xi  *
765*53ee8cc1Swenshuai.xi  * This function will alter only the bytes in the blob which contain
766*53ee8cc1Swenshuai.xi  * the node and its properties and subnodes, and will not alter or
767*53ee8cc1Swenshuai.xi  * move any other part of the tree.
768*53ee8cc1Swenshuai.xi  *
769*53ee8cc1Swenshuai.xi  * returns:
770*53ee8cc1Swenshuai.xi  *	0, on success
771*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
772*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
773*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
774*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
775*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
776*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
777*53ee8cc1Swenshuai.xi  */
778*53ee8cc1Swenshuai.xi int fdt_nop_node(void *fdt, int nodeoffset);
779*53ee8cc1Swenshuai.xi 
780*53ee8cc1Swenshuai.xi /**********************************************************************/
781*53ee8cc1Swenshuai.xi /* Sequential write functions                                         */
782*53ee8cc1Swenshuai.xi /**********************************************************************/
783*53ee8cc1Swenshuai.xi 
784*53ee8cc1Swenshuai.xi int fdt_create(void *buf, int bufsize);
785*53ee8cc1Swenshuai.xi int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
786*53ee8cc1Swenshuai.xi int fdt_finish_reservemap(void *fdt);
787*53ee8cc1Swenshuai.xi int fdt_begin_node(void *fdt, const char *name);
788*53ee8cc1Swenshuai.xi int fdt_property(void *fdt, const char *name, const void *val, int len);
fdt_property_cell(void * fdt,const char * name,uint32_t val)789*53ee8cc1Swenshuai.xi static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
790*53ee8cc1Swenshuai.xi {
791*53ee8cc1Swenshuai.xi 	val = cpu_to_fdt32(val);
792*53ee8cc1Swenshuai.xi 	return fdt_property(fdt, name, &val, sizeof(val));
793*53ee8cc1Swenshuai.xi }
794*53ee8cc1Swenshuai.xi #define fdt_property_string(fdt, name, str) \
795*53ee8cc1Swenshuai.xi 	fdt_property(fdt, name, str, strlen(str)+1)
796*53ee8cc1Swenshuai.xi int fdt_end_node(void *fdt);
797*53ee8cc1Swenshuai.xi int fdt_finish(void *fdt);
798*53ee8cc1Swenshuai.xi 
799*53ee8cc1Swenshuai.xi /**********************************************************************/
800*53ee8cc1Swenshuai.xi /* Read-write functions                                               */
801*53ee8cc1Swenshuai.xi /**********************************************************************/
802*53ee8cc1Swenshuai.xi 
803*53ee8cc1Swenshuai.xi int fdt_open_into(const void *fdt, void *buf, int bufsize);
804*53ee8cc1Swenshuai.xi int fdt_pack(void *fdt);
805*53ee8cc1Swenshuai.xi 
806*53ee8cc1Swenshuai.xi /**
807*53ee8cc1Swenshuai.xi  * fdt_add_mem_rsv - add one memory reserve map entry
808*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
809*53ee8cc1Swenshuai.xi  * @address, @size: 64-bit values (native endian)
810*53ee8cc1Swenshuai.xi  *
811*53ee8cc1Swenshuai.xi  * Adds a reserve map entry to the given blob reserving a region at
812*53ee8cc1Swenshuai.xi  * address address of length size.
813*53ee8cc1Swenshuai.xi  *
814*53ee8cc1Swenshuai.xi  * This function will insert data into the reserve map and will
815*53ee8cc1Swenshuai.xi  * therefore change the indexes of some entries in the table.
816*53ee8cc1Swenshuai.xi  *
817*53ee8cc1Swenshuai.xi  * returns:
818*53ee8cc1Swenshuai.xi  *	0, on success
819*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
820*53ee8cc1Swenshuai.xi  *		contain the new reservation entry
821*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
822*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
823*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
824*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
825*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT,
826*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
827*53ee8cc1Swenshuai.xi  */
828*53ee8cc1Swenshuai.xi int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
829*53ee8cc1Swenshuai.xi 
830*53ee8cc1Swenshuai.xi /**
831*53ee8cc1Swenshuai.xi  * fdt_del_mem_rsv - remove a memory reserve map entry
832*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
833*53ee8cc1Swenshuai.xi  * @n: entry to remove
834*53ee8cc1Swenshuai.xi  *
835*53ee8cc1Swenshuai.xi  * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
836*53ee8cc1Swenshuai.xi  * the blob.
837*53ee8cc1Swenshuai.xi  *
838*53ee8cc1Swenshuai.xi  * This function will delete data from the reservation table and will
839*53ee8cc1Swenshuai.xi  * therefore change the indexes of some entries in the table.
840*53ee8cc1Swenshuai.xi  *
841*53ee8cc1Swenshuai.xi  * returns:
842*53ee8cc1Swenshuai.xi  *	0, on success
843*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
844*53ee8cc1Swenshuai.xi  *		are less than n+1 reserve map entries)
845*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
846*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
847*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
848*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
849*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT,
850*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
851*53ee8cc1Swenshuai.xi  */
852*53ee8cc1Swenshuai.xi int fdt_del_mem_rsv(void *fdt, int n);
853*53ee8cc1Swenshuai.xi 
854*53ee8cc1Swenshuai.xi /**
855*53ee8cc1Swenshuai.xi  * fdt_set_name - change the name of a given node
856*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
857*53ee8cc1Swenshuai.xi  * @nodeoffset: structure block offset of a node
858*53ee8cc1Swenshuai.xi  * @name: name to give the node
859*53ee8cc1Swenshuai.xi  *
860*53ee8cc1Swenshuai.xi  * fdt_set_name() replaces the name (including unit address, if any)
861*53ee8cc1Swenshuai.xi  * of the given node with the given string.  NOTE: this function can't
862*53ee8cc1Swenshuai.xi  * efficiently check if the new name is unique amongst the given
863*53ee8cc1Swenshuai.xi  * node's siblings; results are undefined if this function is invoked
864*53ee8cc1Swenshuai.xi  * with a name equal to one of the given node's siblings.
865*53ee8cc1Swenshuai.xi  *
866*53ee8cc1Swenshuai.xi  * This function may insert or delete data from the blob, and will
867*53ee8cc1Swenshuai.xi  * therefore change the offsets of some existing nodes.
868*53ee8cc1Swenshuai.xi  *
869*53ee8cc1Swenshuai.xi  * returns:
870*53ee8cc1Swenshuai.xi  *	0, on success
871*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob
872*53ee8cc1Swenshuai.xi  *		to contain the new name
873*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
874*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
875*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
876*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE, standard meanings
877*53ee8cc1Swenshuai.xi  */
878*53ee8cc1Swenshuai.xi int fdt_set_name(void *fdt, int nodeoffset, const char *name);
879*53ee8cc1Swenshuai.xi 
880*53ee8cc1Swenshuai.xi /**
881*53ee8cc1Swenshuai.xi  * fdt_setprop - create or change a property
882*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
883*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose property to change
884*53ee8cc1Swenshuai.xi  * @name: name of the property to change
885*53ee8cc1Swenshuai.xi  * @val: pointer to data to set the property value to
886*53ee8cc1Swenshuai.xi  * @len: length of the property value
887*53ee8cc1Swenshuai.xi  *
888*53ee8cc1Swenshuai.xi  * fdt_setprop() sets the value of the named property in the given
889*53ee8cc1Swenshuai.xi  * node to the given value and length, creating the property if it
890*53ee8cc1Swenshuai.xi  * does not already exist.
891*53ee8cc1Swenshuai.xi  *
892*53ee8cc1Swenshuai.xi  * This function may insert or delete data from the blob, and will
893*53ee8cc1Swenshuai.xi  * therefore change the offsets of some existing nodes.
894*53ee8cc1Swenshuai.xi  *
895*53ee8cc1Swenshuai.xi  * returns:
896*53ee8cc1Swenshuai.xi  *	0, on success
897*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
898*53ee8cc1Swenshuai.xi  *		contain the new property value
899*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
900*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT,
901*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
902*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
903*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
904*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
905*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT,
906*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
907*53ee8cc1Swenshuai.xi  */
908*53ee8cc1Swenshuai.xi int fdt_setprop(void *fdt, int nodeoffset, const char *name,
909*53ee8cc1Swenshuai.xi 		const void *val, int len);
910*53ee8cc1Swenshuai.xi 
911*53ee8cc1Swenshuai.xi /**
912*53ee8cc1Swenshuai.xi  * fdt_setprop_cell - set a property to a single cell value
913*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
914*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose property to change
915*53ee8cc1Swenshuai.xi  * @name: name of the property to change
916*53ee8cc1Swenshuai.xi  * @val: 32-bit integer value for the property (native endian)
917*53ee8cc1Swenshuai.xi  *
918*53ee8cc1Swenshuai.xi  * fdt_setprop_cell() sets the value of the named property in the
919*53ee8cc1Swenshuai.xi  * given node to the given cell value (converting to big-endian if
920*53ee8cc1Swenshuai.xi  * necessary), or creates a new property with that value if it does
921*53ee8cc1Swenshuai.xi  * not already exist.
922*53ee8cc1Swenshuai.xi  *
923*53ee8cc1Swenshuai.xi  * This function may insert or delete data from the blob, and will
924*53ee8cc1Swenshuai.xi  * therefore change the offsets of some existing nodes.
925*53ee8cc1Swenshuai.xi  *
926*53ee8cc1Swenshuai.xi  * returns:
927*53ee8cc1Swenshuai.xi  *	0, on success
928*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
929*53ee8cc1Swenshuai.xi  *		contain the new property value
930*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
931*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT,
932*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
933*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
934*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
935*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
936*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT,
937*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
938*53ee8cc1Swenshuai.xi  */
fdt_setprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)939*53ee8cc1Swenshuai.xi static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
940*53ee8cc1Swenshuai.xi 				   uint32_t val)
941*53ee8cc1Swenshuai.xi {
942*53ee8cc1Swenshuai.xi 	val = cpu_to_fdt32(val);
943*53ee8cc1Swenshuai.xi 	return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
944*53ee8cc1Swenshuai.xi }
945*53ee8cc1Swenshuai.xi 
946*53ee8cc1Swenshuai.xi /**
947*53ee8cc1Swenshuai.xi  * fdt_setprop_string - set a property to a string value
948*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
949*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose property to change
950*53ee8cc1Swenshuai.xi  * @name: name of the property to change
951*53ee8cc1Swenshuai.xi  * @str: string value for the property
952*53ee8cc1Swenshuai.xi  *
953*53ee8cc1Swenshuai.xi  * fdt_setprop_string() sets the value of the named property in the
954*53ee8cc1Swenshuai.xi  * given node to the given string value (using the length of the
955*53ee8cc1Swenshuai.xi  * string to determine the new length of the property), or creates a
956*53ee8cc1Swenshuai.xi  * new property with that value if it does not already exist.
957*53ee8cc1Swenshuai.xi  *
958*53ee8cc1Swenshuai.xi  * This function may insert or delete data from the blob, and will
959*53ee8cc1Swenshuai.xi  * therefore change the offsets of some existing nodes.
960*53ee8cc1Swenshuai.xi  *
961*53ee8cc1Swenshuai.xi  * returns:
962*53ee8cc1Swenshuai.xi  *	0, on success
963*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
964*53ee8cc1Swenshuai.xi  *		contain the new property value
965*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
966*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT,
967*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
968*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
969*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
970*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
971*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT,
972*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
973*53ee8cc1Swenshuai.xi  */
974*53ee8cc1Swenshuai.xi #define fdt_setprop_string(fdt, nodeoffset, name, str) \
975*53ee8cc1Swenshuai.xi 	fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
976*53ee8cc1Swenshuai.xi 
977*53ee8cc1Swenshuai.xi /**
978*53ee8cc1Swenshuai.xi  * fdt_delprop - delete a property
979*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
980*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node whose property to nop
981*53ee8cc1Swenshuai.xi  * @name: name of the property to nop
982*53ee8cc1Swenshuai.xi  *
983*53ee8cc1Swenshuai.xi  * fdt_del_property() will delete the given property.
984*53ee8cc1Swenshuai.xi  *
985*53ee8cc1Swenshuai.xi  * This function will delete data from the blob, and will therefore
986*53ee8cc1Swenshuai.xi  * change the offsets of some existing nodes.
987*53ee8cc1Swenshuai.xi  *
988*53ee8cc1Swenshuai.xi  * returns:
989*53ee8cc1Swenshuai.xi  *	0, on success
990*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, node does not have the named property
991*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
992*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT,
993*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
994*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
995*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
996*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
997*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
998*53ee8cc1Swenshuai.xi  */
999*53ee8cc1Swenshuai.xi int fdt_delprop(void *fdt, int nodeoffset, const char *name);
1000*53ee8cc1Swenshuai.xi 
1001*53ee8cc1Swenshuai.xi /**
1002*53ee8cc1Swenshuai.xi  * fdt_add_subnode_namelen - creates a new node based on substring
1003*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
1004*53ee8cc1Swenshuai.xi  * @parentoffset: structure block offset of a node
1005*53ee8cc1Swenshuai.xi  * @name: name of the subnode to locate
1006*53ee8cc1Swenshuai.xi  * @namelen: number of characters of name to consider
1007*53ee8cc1Swenshuai.xi  *
1008*53ee8cc1Swenshuai.xi  * Identical to fdt_add_subnode(), but use only the first namelen
1009*53ee8cc1Swenshuai.xi  * characters of name as the name of the new node.  This is useful for
1010*53ee8cc1Swenshuai.xi  * creating subnodes based on a portion of a larger string, such as a
1011*53ee8cc1Swenshuai.xi  * full path.
1012*53ee8cc1Swenshuai.xi  */
1013*53ee8cc1Swenshuai.xi int fdt_add_subnode_namelen(void *fdt, int parentoffset,
1014*53ee8cc1Swenshuai.xi 			    const char *name, int namelen);
1015*53ee8cc1Swenshuai.xi 
1016*53ee8cc1Swenshuai.xi /**
1017*53ee8cc1Swenshuai.xi  * fdt_add_subnode - creates a new node
1018*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
1019*53ee8cc1Swenshuai.xi  * @parentoffset: structure block offset of a node
1020*53ee8cc1Swenshuai.xi  * @name: name of the subnode to locate
1021*53ee8cc1Swenshuai.xi  *
1022*53ee8cc1Swenshuai.xi  * fdt_add_subnode() creates a new node as a subnode of the node at
1023*53ee8cc1Swenshuai.xi  * structure block offset parentoffset, with the given name (which
1024*53ee8cc1Swenshuai.xi  * should include the unit address, if any).
1025*53ee8cc1Swenshuai.xi  *
1026*53ee8cc1Swenshuai.xi  * This function will insert data into the blob, and will therefore
1027*53ee8cc1Swenshuai.xi  * change the offsets of some existing nodes.
1028*53ee8cc1Swenshuai.xi 
1029*53ee8cc1Swenshuai.xi  * returns:
1030*53ee8cc1Swenshuai.xi  *	structure block offset of the created nodeequested subnode (>=0), on success
1031*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
1032*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
1033*53ee8cc1Swenshuai.xi  *	-FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
1034*53ee8cc1Swenshuai.xi  *		the given name
1035*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOSPACE, if there is insufficient free space in the
1036*53ee8cc1Swenshuai.xi  *		blob to contain the new node
1037*53ee8cc1Swenshuai.xi  *	-FDT_ERR_NOSPACE
1038*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT
1039*53ee8cc1Swenshuai.xi  *      -FDT_ERR_BADMAGIC,
1040*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
1041*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
1042*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
1043*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings.
1044*53ee8cc1Swenshuai.xi  */
1045*53ee8cc1Swenshuai.xi int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
1046*53ee8cc1Swenshuai.xi 
1047*53ee8cc1Swenshuai.xi /**
1048*53ee8cc1Swenshuai.xi  * fdt_del_node - delete a node (subtree)
1049*53ee8cc1Swenshuai.xi  * @fdt: pointer to the device tree blob
1050*53ee8cc1Swenshuai.xi  * @nodeoffset: offset of the node to nop
1051*53ee8cc1Swenshuai.xi  *
1052*53ee8cc1Swenshuai.xi  * fdt_del_node() will remove the given node, including all its
1053*53ee8cc1Swenshuai.xi  * subnodes if any, from the blob.
1054*53ee8cc1Swenshuai.xi  *
1055*53ee8cc1Swenshuai.xi  * This function will delete data from the blob, and will therefore
1056*53ee8cc1Swenshuai.xi  * change the offsets of some existing nodes.
1057*53ee8cc1Swenshuai.xi  *
1058*53ee8cc1Swenshuai.xi  * returns:
1059*53ee8cc1Swenshuai.xi  *	0, on success
1060*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1061*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADLAYOUT,
1062*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADMAGIC,
1063*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADVERSION,
1064*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTATE,
1065*53ee8cc1Swenshuai.xi  *	-FDT_ERR_BADSTRUCTURE,
1066*53ee8cc1Swenshuai.xi  *	-FDT_ERR_TRUNCATED, standard meanings
1067*53ee8cc1Swenshuai.xi  */
1068*53ee8cc1Swenshuai.xi int fdt_del_node(void *fdt, int nodeoffset);
1069*53ee8cc1Swenshuai.xi 
1070*53ee8cc1Swenshuai.xi /**********************************************************************/
1071*53ee8cc1Swenshuai.xi /* Debugging / informational functions                                */
1072*53ee8cc1Swenshuai.xi /**********************************************************************/
1073*53ee8cc1Swenshuai.xi 
1074*53ee8cc1Swenshuai.xi const char *fdt_strerror(int errval);
1075*53ee8cc1Swenshuai.xi 
1076*53ee8cc1Swenshuai.xi #endif /* _LIBFDT_H */
1077