1204431Sraj#ifndef _LIBFDT_H
2204431Sraj#define _LIBFDT_H
3204431Sraj/*
4204431Sraj * libfdt - Flat Device Tree manipulation
5204431Sraj * Copyright (C) 2006 David Gibson, IBM Corporation.
6204431Sraj *
7204431Sraj * libfdt is dual licensed: you can use it either under the terms of
8204431Sraj * the GPL, or the BSD license, at your option.
9204431Sraj *
10204431Sraj *  a) This library is free software; you can redistribute it and/or
11204431Sraj *     modify it under the terms of the GNU General Public License as
12204431Sraj *     published by the Free Software Foundation; either version 2 of the
13204431Sraj *     License, or (at your option) any later version.
14204431Sraj *
15204431Sraj *     This library is distributed in the hope that it will be useful,
16204431Sraj *     but WITHOUT ANY WARRANTY; without even the implied warranty of
17204431Sraj *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18204431Sraj *     GNU General Public License for more details.
19204431Sraj *
20204431Sraj *     You should have received a copy of the GNU General Public
21204431Sraj *     License along with this library; if not, write to the Free
22204431Sraj *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
23204431Sraj *     MA 02110-1301 USA
24204431Sraj *
25204431Sraj * Alternatively,
26204431Sraj *
27204431Sraj *  b) Redistribution and use in source and binary forms, with or
28204431Sraj *     without modification, are permitted provided that the following
29204431Sraj *     conditions are met:
30204431Sraj *
31204431Sraj *     1. Redistributions of source code must retain the above
32204431Sraj *        copyright notice, this list of conditions and the following
33204431Sraj *        disclaimer.
34204431Sraj *     2. Redistributions in binary form must reproduce the above
35204431Sraj *        copyright notice, this list of conditions and the following
36204431Sraj *        disclaimer in the documentation and/or other materials
37204431Sraj *        provided with the distribution.
38204431Sraj *
39204431Sraj *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
40204431Sraj *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
41204431Sraj *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42204431Sraj *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43204431Sraj *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
44204431Sraj *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45204431Sraj *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46204431Sraj *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47204431Sraj *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48204431Sraj *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49204431Sraj *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
50204431Sraj *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
51204431Sraj *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52204431Sraj */
53204431Sraj
54204431Sraj#include <libfdt_env.h>
55204431Sraj#include <fdt.h>
56204431Sraj
57204431Sraj#define FDT_FIRST_SUPPORTED_VERSION	0x10
58204431Sraj#define FDT_LAST_SUPPORTED_VERSION	0x11
59204431Sraj
60204431Sraj/* Error codes: informative error codes */
61204431Sraj#define FDT_ERR_NOTFOUND	1
62204431Sraj	/* FDT_ERR_NOTFOUND: The requested node or property does not exist */
63204431Sraj#define FDT_ERR_EXISTS		2
64204431Sraj	/* FDT_ERR_EXISTS: Attemped to create a node or property which
65204431Sraj	 * already exists */
66204431Sraj#define FDT_ERR_NOSPACE		3
67204431Sraj	/* FDT_ERR_NOSPACE: Operation needed to expand the device
68204431Sraj	 * tree, but its buffer did not have sufficient space to
69204431Sraj	 * contain the expanded tree. Use fdt_open_into() to move the
70204431Sraj	 * device tree to a buffer with more space. */
71204431Sraj
72204431Sraj/* Error codes: codes for bad parameters */
73204431Sraj#define FDT_ERR_BADOFFSET	4
74204431Sraj	/* FDT_ERR_BADOFFSET: Function was passed a structure block
75204431Sraj	 * offset which is out-of-bounds, or which points to an
76204431Sraj	 * unsuitable part of the structure for the operation. */
77204431Sraj#define FDT_ERR_BADPATH		5
78204431Sraj	/* FDT_ERR_BADPATH: Function was passed a badly formatted path
79204431Sraj	 * (e.g. missing a leading / for a function which requires an
80204431Sraj	 * absolute path) */
81204431Sraj#define FDT_ERR_BADPHANDLE	6
82204431Sraj	/* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle
83204431Sraj	 * value.  phandle values of 0 and -1 are not permitted. */
84204431Sraj#define FDT_ERR_BADSTATE	7
85204431Sraj	/* FDT_ERR_BADSTATE: Function was passed an incomplete device
86204431Sraj	 * tree created by the sequential-write functions, which is
87204431Sraj	 * not sufficiently complete for the requested operation. */
88204431Sraj
89204431Sraj/* Error codes: codes for bad device tree blobs */
90204431Sraj#define FDT_ERR_TRUNCATED	8
91204431Sraj	/* FDT_ERR_TRUNCATED: Structure block of the given device tree
92204431Sraj	 * ends without an FDT_END tag. */
93204431Sraj#define FDT_ERR_BADMAGIC	9
94204431Sraj	/* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
95204431Sraj	 * device tree at all - it is missing the flattened device
96204431Sraj	 * tree magic number. */
97204431Sraj#define FDT_ERR_BADVERSION	10
98204431Sraj	/* FDT_ERR_BADVERSION: Given device tree has a version which
99204431Sraj	 * can't be handled by the requested operation.  For
100204431Sraj	 * read-write functions, this may mean that fdt_open_into() is
101204431Sraj	 * required to convert the tree to the expected version. */
102204431Sraj#define FDT_ERR_BADSTRUCTURE	11
103204431Sraj	/* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
104204431Sraj	 * structure block or other serious error (e.g. misnested
105204431Sraj	 * nodes, or subnodes preceding properties). */
106204431Sraj#define FDT_ERR_BADLAYOUT	12
107204431Sraj	/* FDT_ERR_BADLAYOUT: For read-write functions, the given
108204431Sraj	 * device tree has it's sub-blocks in an order that the
109204431Sraj	 * function can't handle (memory reserve map, then structure,
110204431Sraj	 * then strings).  Use fdt_open_into() to reorganize the tree
111204431Sraj	 * into a form suitable for the read-write operations. */
112204431Sraj
113204431Sraj/* "Can't happen" error indicating a bug in libfdt */
114204431Sraj#define FDT_ERR_INTERNAL	13
115204431Sraj	/* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
116204431Sraj	 * Should never be returned, if it is, it indicates a bug in
117204431Sraj	 * libfdt itself. */
118204431Sraj
119204431Sraj#define FDT_ERR_MAX		13
120204431Sraj
121204431Sraj/**********************************************************************/
122204431Sraj/* Low-level functions (you probably don't need these)                */
123204431Sraj/**********************************************************************/
124204431Sraj
125204433Srajconst void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
126204431Srajstatic inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
127204431Sraj{
128204431Sraj	return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
129204431Sraj}
130204431Sraj
131204431Srajuint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
132204431Sraj
133204431Sraj/**********************************************************************/
134204431Sraj/* Traversal functions                                                */
135204431Sraj/**********************************************************************/
136204431Sraj
137204431Srajint fdt_next_node(const void *fdt, int offset, int *depth);
138204431Sraj
139204431Sraj/**********************************************************************/
140204431Sraj/* General functions                                                  */
141204431Sraj/**********************************************************************/
142204431Sraj
143204431Sraj#define fdt_get_header(fdt, field) \
144204431Sraj	(fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
145204431Sraj#define fdt_magic(fdt) 			(fdt_get_header(fdt, magic))
146204431Sraj#define fdt_totalsize(fdt)		(fdt_get_header(fdt, totalsize))
147204431Sraj#define fdt_off_dt_struct(fdt)		(fdt_get_header(fdt, off_dt_struct))
148204431Sraj#define fdt_off_dt_strings(fdt)		(fdt_get_header(fdt, off_dt_strings))
149204431Sraj#define fdt_off_mem_rsvmap(fdt)		(fdt_get_header(fdt, off_mem_rsvmap))
150204431Sraj#define fdt_version(fdt)		(fdt_get_header(fdt, version))
151204431Sraj#define fdt_last_comp_version(fdt) 	(fdt_get_header(fdt, last_comp_version))
152204431Sraj#define fdt_boot_cpuid_phys(fdt) 	(fdt_get_header(fdt, boot_cpuid_phys))
153204431Sraj#define fdt_size_dt_strings(fdt) 	(fdt_get_header(fdt, size_dt_strings))
154204431Sraj#define fdt_size_dt_struct(fdt)		(fdt_get_header(fdt, size_dt_struct))
155204431Sraj
156204431Sraj#define __fdt_set_hdr(name) \
157204431Sraj	static inline void fdt_set_##name(void *fdt, uint32_t val) \
158204431Sraj	{ \
159204433Sraj		struct fdt_header *fdth = (struct fdt_header*)fdt; \
160204431Sraj		fdth->name = cpu_to_fdt32(val); \
161204431Sraj	}
162204431Sraj__fdt_set_hdr(magic);
163204431Sraj__fdt_set_hdr(totalsize);
164204431Sraj__fdt_set_hdr(off_dt_struct);
165204431Sraj__fdt_set_hdr(off_dt_strings);
166204431Sraj__fdt_set_hdr(off_mem_rsvmap);
167204431Sraj__fdt_set_hdr(version);
168204431Sraj__fdt_set_hdr(last_comp_version);
169204431Sraj__fdt_set_hdr(boot_cpuid_phys);
170204431Sraj__fdt_set_hdr(size_dt_strings);
171204431Sraj__fdt_set_hdr(size_dt_struct);
172204431Sraj#undef __fdt_set_hdr
173204431Sraj
174204431Sraj/**
175204431Sraj * fdt_check_header - sanity check a device tree or possible device tree
176204431Sraj * @fdt: pointer to data which might be a flattened device tree
177204431Sraj *
178204431Sraj * fdt_check_header() checks that the given buffer contains what
179204431Sraj * appears to be a flattened device tree with sane information in its
180204431Sraj * header.
181204431Sraj *
182204431Sraj * returns:
183204431Sraj *     0, if the buffer appears to contain a valid device tree
184204431Sraj *     -FDT_ERR_BADMAGIC,
185204431Sraj *     -FDT_ERR_BADVERSION,
186204431Sraj *     -FDT_ERR_BADSTATE, standard meanings, as above
187204431Sraj */
188204431Srajint fdt_check_header(const void *fdt);
189204431Sraj
190204431Sraj/**
191204431Sraj * fdt_move - move a device tree around in memory
192204431Sraj * @fdt: pointer to the device tree to move
193204431Sraj * @buf: pointer to memory where the device is to be moved
194204431Sraj * @bufsize: size of the memory space at buf
195204431Sraj *
196204431Sraj * fdt_move() relocates, if possible, the device tree blob located at
197204431Sraj * fdt to the buffer at buf of size bufsize.  The buffer may overlap
198204431Sraj * with the existing device tree blob at fdt.  Therefore,
199204431Sraj *     fdt_move(fdt, fdt, fdt_totalsize(fdt))
200204431Sraj * should always succeed.
201204431Sraj *
202204431Sraj * returns:
203204431Sraj *     0, on success
204204431Sraj *     -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
205204431Sraj *     -FDT_ERR_BADMAGIC,
206204431Sraj *     -FDT_ERR_BADVERSION,
207204431Sraj *     -FDT_ERR_BADSTATE, standard meanings
208204431Sraj */
209204431Srajint fdt_move(const void *fdt, void *buf, int bufsize);
210204431Sraj
211204431Sraj/**********************************************************************/
212204431Sraj/* Read-only functions                                                */
213204431Sraj/**********************************************************************/
214204431Sraj
215204431Sraj/**
216204431Sraj * fdt_string - retrieve a string from the strings block of a device tree
217204431Sraj * @fdt: pointer to the device tree blob
218204431Sraj * @stroffset: offset of the string within the strings block (native endian)
219204431Sraj *
220204431Sraj * fdt_string() retrieves a pointer to a single string from the
221204431Sraj * strings block of the device tree blob at fdt.
222204431Sraj *
223204431Sraj * returns:
224204431Sraj *     a pointer to the string, on success
225204431Sraj *     NULL, if stroffset is out of bounds
226204431Sraj */
227204431Srajconst char *fdt_string(const void *fdt, int stroffset);
228204431Sraj
229204431Sraj/**
230204431Sraj * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
231204431Sraj * @fdt: pointer to the device tree blob
232204431Sraj *
233204431Sraj * Returns the number of entries in the device tree blob's memory
234204431Sraj * reservation map.  This does not include the terminating 0,0 entry
235204431Sraj * or any other (0,0) entries reserved for expansion.
236204431Sraj *
237204431Sraj * returns:
238204431Sraj *     the number of entries
239204431Sraj */
240204431Srajint fdt_num_mem_rsv(const void *fdt);
241204431Sraj
242204431Sraj/**
243204431Sraj * fdt_get_mem_rsv - retrieve one memory reserve map entry
244204431Sraj * @fdt: pointer to the device tree blob
245204431Sraj * @address, @size: pointers to 64-bit variables
246204431Sraj *
247204431Sraj * On success, *address and *size will contain the address and size of
248204431Sraj * the n-th reserve map entry from the device tree blob, in
249204431Sraj * native-endian format.
250204431Sraj *
251204431Sraj * returns:
252204431Sraj *     0, on success
253204431Sraj *     -FDT_ERR_BADMAGIC,
254204431Sraj *     -FDT_ERR_BADVERSION,
255204431Sraj *     -FDT_ERR_BADSTATE, standard meanings
256204431Sraj */
257204431Srajint fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
258204431Sraj
259204431Sraj/**
260204431Sraj * fdt_subnode_offset_namelen - find a subnode based on substring
261204431Sraj * @fdt: pointer to the device tree blob
262204431Sraj * @parentoffset: structure block offset of a node
263204431Sraj * @name: name of the subnode to locate
264204431Sraj * @namelen: number of characters of name to consider
265204431Sraj *
266204431Sraj * Identical to fdt_subnode_offset(), but only examine the first
267204431Sraj * namelen characters of name for matching the subnode name.  This is
268204431Sraj * useful for finding subnodes based on a portion of a larger string,
269204431Sraj * such as a full path.
270204431Sraj */
271204431Srajint fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
272204431Sraj			       const char *name, int namelen);
273204431Sraj/**
274204431Sraj * fdt_subnode_offset - find a subnode of a given node
275204431Sraj * @fdt: pointer to the device tree blob
276204431Sraj * @parentoffset: structure block offset of a node
277204431Sraj * @name: name of the subnode to locate
278204431Sraj *
279204431Sraj * fdt_subnode_offset() finds a subnode of the node at structure block
280204431Sraj * offset parentoffset with the given name.  name may include a unit
281204431Sraj * address, in which case fdt_subnode_offset() will find the subnode
282204431Sraj * with that unit address, or the unit address may be omitted, in
283204431Sraj * which case fdt_subnode_offset() will find an arbitrary subnode
284204431Sraj * whose name excluding unit address matches the given name.
285204431Sraj *
286204431Sraj * returns:
287204431Sraj *	structure block offset of the requested subnode (>=0), on success
288204431Sraj *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
289204431Sraj *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
290204431Sraj *      -FDT_ERR_BADMAGIC,
291204431Sraj *	-FDT_ERR_BADVERSION,
292204431Sraj *	-FDT_ERR_BADSTATE,
293204431Sraj *	-FDT_ERR_BADSTRUCTURE,
294204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings.
295204431Sraj */
296204431Srajint fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
297204431Sraj
298204431Sraj/**
299204431Sraj * fdt_path_offset - find a tree node by its full path
300204431Sraj * @fdt: pointer to the device tree blob
301204431Sraj * @path: full path of the node to locate
302204431Sraj *
303204431Sraj * fdt_path_offset() finds a node of a given path in the device tree.
304204431Sraj * Each path component may omit the unit address portion, but the
305204431Sraj * results of this are undefined if any such path component is
306204431Sraj * ambiguous (that is if there are multiple nodes at the relevant
307204431Sraj * level matching the given component, differentiated only by unit
308204431Sraj * address).
309204431Sraj *
310204431Sraj * returns:
311204431Sraj *	structure block offset of the node with the requested path (>=0), on success
312204431Sraj *	-FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
313204431Sraj *	-FDT_ERR_NOTFOUND, if the requested node does not exist
314204431Sraj *      -FDT_ERR_BADMAGIC,
315204431Sraj *	-FDT_ERR_BADVERSION,
316204431Sraj *	-FDT_ERR_BADSTATE,
317204431Sraj *	-FDT_ERR_BADSTRUCTURE,
318204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings.
319204431Sraj */
320204431Srajint fdt_path_offset(const void *fdt, const char *path);
321204431Sraj
322204431Sraj/**
323204431Sraj * fdt_get_name - retrieve the name of a given node
324204431Sraj * @fdt: pointer to the device tree blob
325204431Sraj * @nodeoffset: structure block offset of the starting node
326204431Sraj * @lenp: pointer to an integer variable (will be overwritten) or NULL
327204431Sraj *
328204431Sraj * fdt_get_name() retrieves the name (including unit address) of the
329204431Sraj * device tree node at structure block offset nodeoffset.  If lenp is
330204431Sraj * non-NULL, the length of this name is also returned, in the integer
331204431Sraj * pointed to by lenp.
332204431Sraj *
333204431Sraj * returns:
334204431Sraj *	pointer to the node's name, on success
335204431Sraj *		If lenp is non-NULL, *lenp contains the length of that name (>=0)
336204431Sraj *	NULL, on error
337204431Sraj *		if lenp is non-NULL *lenp contains an error code (<0):
338204431Sraj *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
339204431Sraj *		-FDT_ERR_BADMAGIC,
340204431Sraj *		-FDT_ERR_BADVERSION,
341204431Sraj *		-FDT_ERR_BADSTATE, standard meanings
342204431Sraj */
343204431Srajconst char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
344204431Sraj
345204431Sraj/**
346238742Simp * fdt_first_property_offset - find the offset of a node's first property
347238742Simp * @fdt: pointer to the device tree blob
348238742Simp * @nodeoffset: structure block offset of a node
349238742Simp *
350238742Simp * fdt_first_property_offset() finds the first property of the node at
351238742Simp * the given structure block offset.
352238742Simp *
353238742Simp * returns:
354238742Simp *	structure block offset of the property (>=0), on success
355238742Simp *	-FDT_ERR_NOTFOUND, if the requested node has no properties
356238742Simp *	-FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
357238742Simp *      -FDT_ERR_BADMAGIC,
358238742Simp *	-FDT_ERR_BADVERSION,
359238742Simp *	-FDT_ERR_BADSTATE,
360238742Simp *	-FDT_ERR_BADSTRUCTURE,
361238742Simp *	-FDT_ERR_TRUNCATED, standard meanings.
362238742Simp */
363238742Simpint fdt_first_property_offset(const void *fdt, int nodeoffset);
364238742Simp
365238742Simp/**
366238742Simp * fdt_next_property_offset - step through a node's properties
367238742Simp * @fdt: pointer to the device tree blob
368238742Simp * @offset: structure block offset of a property
369238742Simp *
370238742Simp * fdt_next_property_offset() finds the property immediately after the
371238742Simp * one at the given structure block offset.  This will be a property
372238742Simp * of the same node as the given property.
373238742Simp *
374238742Simp * returns:
375238742Simp *	structure block offset of the next property (>=0), on success
376238742Simp *	-FDT_ERR_NOTFOUND, if the given property is the last in its node
377238742Simp *	-FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
378238742Simp *      -FDT_ERR_BADMAGIC,
379238742Simp *	-FDT_ERR_BADVERSION,
380238742Simp *	-FDT_ERR_BADSTATE,
381238742Simp *	-FDT_ERR_BADSTRUCTURE,
382238742Simp *	-FDT_ERR_TRUNCATED, standard meanings.
383238742Simp */
384238742Simpint fdt_next_property_offset(const void *fdt, int offset);
385238742Simp
386238742Simp/**
387238742Simp * fdt_get_property_by_offset - retrieve the property at a given offset
388238742Simp * @fdt: pointer to the device tree blob
389238742Simp * @offset: offset of the property to retrieve
390238742Simp * @lenp: pointer to an integer variable (will be overwritten) or NULL
391238742Simp *
392238742Simp * fdt_get_property_by_offset() retrieves a pointer to the
393238742Simp * fdt_property structure within the device tree blob at the given
394238742Simp * offset.  If lenp is non-NULL, the length of the property value is
395238742Simp * also returned, in the integer pointed to by lenp.
396238742Simp *
397238742Simp * returns:
398238742Simp *	pointer to the structure representing the property
399238742Simp *		if lenp is non-NULL, *lenp contains the length of the property
400238742Simp *		value (>=0)
401238742Simp *	NULL, on error
402238742Simp *		if lenp is non-NULL, *lenp contains an error code (<0):
403238742Simp *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
404238742Simp *		-FDT_ERR_BADMAGIC,
405238742Simp *		-FDT_ERR_BADVERSION,
406238742Simp *		-FDT_ERR_BADSTATE,
407238742Simp *		-FDT_ERR_BADSTRUCTURE,
408238742Simp *		-FDT_ERR_TRUNCATED, standard meanings
409238742Simp */
410238742Simpconst struct fdt_property *fdt_get_property_by_offset(const void *fdt,
411238742Simp						      int offset,
412238742Simp						      int *lenp);
413238742Simp
414238742Simp/**
415204433Sraj * fdt_get_property_namelen - find a property based on substring
416204433Sraj * @fdt: pointer to the device tree blob
417204433Sraj * @nodeoffset: offset of the node whose property to find
418204433Sraj * @name: name of the property to find
419204433Sraj * @namelen: number of characters of name to consider
420204433Sraj * @lenp: pointer to an integer variable (will be overwritten) or NULL
421204433Sraj *
422204433Sraj * Identical to fdt_get_property_namelen(), but only examine the first
423204433Sraj * namelen characters of name for matching the property name.
424204433Sraj */
425204433Srajconst struct fdt_property *fdt_get_property_namelen(const void *fdt,
426204433Sraj						    int nodeoffset,
427204433Sraj						    const char *name,
428204433Sraj						    int namelen, int *lenp);
429204433Sraj
430204433Sraj/**
431204431Sraj * fdt_get_property - find a given property in a given node
432204431Sraj * @fdt: pointer to the device tree blob
433204431Sraj * @nodeoffset: offset of the node whose property to find
434204431Sraj * @name: name of the property to find
435204431Sraj * @lenp: pointer to an integer variable (will be overwritten) or NULL
436204431Sraj *
437204431Sraj * fdt_get_property() retrieves a pointer to the fdt_property
438204431Sraj * structure within the device tree blob corresponding to the property
439204431Sraj * named 'name' of the node at offset nodeoffset.  If lenp is
440204431Sraj * non-NULL, the length of the property value is also returned, in the
441204431Sraj * integer pointed to by lenp.
442204431Sraj *
443204431Sraj * returns:
444204431Sraj *	pointer to the structure representing the property
445204431Sraj *		if lenp is non-NULL, *lenp contains the length of the property
446204431Sraj *		value (>=0)
447204431Sraj *	NULL, on error
448204431Sraj *		if lenp is non-NULL, *lenp contains an error code (<0):
449204431Sraj *		-FDT_ERR_NOTFOUND, node does not have named property
450204431Sraj *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
451204431Sraj *		-FDT_ERR_BADMAGIC,
452204431Sraj *		-FDT_ERR_BADVERSION,
453204431Sraj *		-FDT_ERR_BADSTATE,
454204431Sraj *		-FDT_ERR_BADSTRUCTURE,
455204431Sraj *		-FDT_ERR_TRUNCATED, standard meanings
456204431Sraj */
457204431Srajconst struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
458204431Sraj					    const char *name, int *lenp);
459204431Srajstatic inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
460204431Sraj						      const char *name,
461204431Sraj						      int *lenp)
462204431Sraj{
463204431Sraj	return (struct fdt_property *)(uintptr_t)
464204431Sraj		fdt_get_property(fdt, nodeoffset, name, lenp);
465204431Sraj}
466204431Sraj
467204431Sraj/**
468238742Simp * fdt_getprop_by_offset - retrieve the value of a property at a given offset
469238742Simp * @fdt: pointer to the device tree blob
470238742Simp * @ffset: offset of the property to read
471238742Simp * @namep: pointer to a string variable (will be overwritten) or NULL
472238742Simp * @lenp: pointer to an integer variable (will be overwritten) or NULL
473238742Simp *
474238742Simp * fdt_getprop_by_offset() retrieves a pointer to the value of the
475238742Simp * property at structure block offset 'offset' (this will be a pointer
476238742Simp * to within the device blob itself, not a copy of the value).  If
477238742Simp * lenp is non-NULL, the length of the property value is also
478238742Simp * returned, in the integer pointed to by lenp.  If namep is non-NULL,
479238742Simp * the property's namne will also be returned in the char * pointed to
480238742Simp * by namep (this will be a pointer to within the device tree's string
481238742Simp * block, not a new copy of the name).
482238742Simp *
483238742Simp * returns:
484238742Simp *	pointer to the property's value
485238742Simp *		if lenp is non-NULL, *lenp contains the length of the property
486238742Simp *		value (>=0)
487238742Simp *		if namep is non-NULL *namep contiains a pointer to the property
488238742Simp *		name.
489238742Simp *	NULL, on error
490238742Simp *		if lenp is non-NULL, *lenp contains an error code (<0):
491238742Simp *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
492238742Simp *		-FDT_ERR_BADMAGIC,
493238742Simp *		-FDT_ERR_BADVERSION,
494238742Simp *		-FDT_ERR_BADSTATE,
495238742Simp *		-FDT_ERR_BADSTRUCTURE,
496238742Simp *		-FDT_ERR_TRUNCATED, standard meanings
497238742Simp */
498238742Simpconst void *fdt_getprop_by_offset(const void *fdt, int offset,
499238742Simp				  const char **namep, int *lenp);
500238742Simp
501238742Simp/**
502204433Sraj * fdt_getprop_namelen - get property value based on substring
503204433Sraj * @fdt: pointer to the device tree blob
504204433Sraj * @nodeoffset: offset of the node whose property to find
505204433Sraj * @name: name of the property to find
506204433Sraj * @namelen: number of characters of name to consider
507204433Sraj * @lenp: pointer to an integer variable (will be overwritten) or NULL
508204433Sraj *
509204433Sraj * Identical to fdt_getprop(), but only examine the first namelen
510204433Sraj * characters of name for matching the property name.
511204433Sraj */
512204433Srajconst void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
513204433Sraj				const char *name, int namelen, int *lenp);
514204433Sraj
515204433Sraj/**
516204431Sraj * fdt_getprop - retrieve the value of a given property
517204431Sraj * @fdt: pointer to the device tree blob
518204431Sraj * @nodeoffset: offset of the node whose property to find
519204431Sraj * @name: name of the property to find
520204431Sraj * @lenp: pointer to an integer variable (will be overwritten) or NULL
521204431Sraj *
522204431Sraj * fdt_getprop() retrieves a pointer to the value of the property
523204431Sraj * named 'name' of the node at offset nodeoffset (this will be a
524204431Sraj * pointer to within the device blob itself, not a copy of the value).
525204431Sraj * If lenp is non-NULL, the length of the property value is also
526204431Sraj * returned, in the integer pointed to by lenp.
527204431Sraj *
528204431Sraj * returns:
529204431Sraj *	pointer to the property's value
530204431Sraj *		if lenp is non-NULL, *lenp contains the length of the property
531204431Sraj *		value (>=0)
532204431Sraj *	NULL, on error
533204431Sraj *		if lenp is non-NULL, *lenp contains an error code (<0):
534204431Sraj *		-FDT_ERR_NOTFOUND, node does not have named property
535204431Sraj *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
536204431Sraj *		-FDT_ERR_BADMAGIC,
537204431Sraj *		-FDT_ERR_BADVERSION,
538204431Sraj *		-FDT_ERR_BADSTATE,
539204431Sraj *		-FDT_ERR_BADSTRUCTURE,
540204431Sraj *		-FDT_ERR_TRUNCATED, standard meanings
541204431Sraj */
542204431Srajconst void *fdt_getprop(const void *fdt, int nodeoffset,
543204431Sraj			const char *name, int *lenp);
544204431Srajstatic inline void *fdt_getprop_w(void *fdt, int nodeoffset,
545204431Sraj				  const char *name, int *lenp)
546204431Sraj{
547204431Sraj	return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
548204431Sraj}
549204431Sraj
550204431Sraj/**
551204431Sraj * fdt_get_phandle - retrieve the phandle of a given node
552204431Sraj * @fdt: pointer to the device tree blob
553204431Sraj * @nodeoffset: structure block offset of the node
554204431Sraj *
555204431Sraj * fdt_get_phandle() retrieves the phandle of the device tree node at
556204431Sraj * structure block offset nodeoffset.
557204431Sraj *
558204431Sraj * returns:
559204431Sraj *	the phandle of the node at nodeoffset, on success (!= 0, != -1)
560204431Sraj *	0, if the node has no phandle, or another error occurs
561204431Sraj */
562204431Srajuint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
563204431Sraj
564204431Sraj/**
565204433Sraj * fdt_get_alias_namelen - get alias based on substring
566204433Sraj * @fdt: pointer to the device tree blob
567204433Sraj * @name: name of the alias th look up
568204433Sraj * @namelen: number of characters of name to consider
569204433Sraj *
570204433Sraj * Identical to fdt_get_alias(), but only examine the first namelen
571204433Sraj * characters of name for matching the alias name.
572204433Sraj */
573204433Srajconst char *fdt_get_alias_namelen(const void *fdt,
574204433Sraj				  const char *name, int namelen);
575204433Sraj
576204433Sraj/**
577204433Sraj * fdt_get_alias - retreive the path referenced by a given alias
578204433Sraj * @fdt: pointer to the device tree blob
579204433Sraj * @name: name of the alias th look up
580204433Sraj *
581204433Sraj * fdt_get_alias() retrieves the value of a given alias.  That is, the
582204433Sraj * value of the property named 'name' in the node /aliases.
583204433Sraj *
584204433Sraj * returns:
585204433Sraj *	a pointer to the expansion of the alias named 'name', of it exists
586204433Sraj *	NULL, if the given alias or the /aliases node does not exist
587204433Sraj */
588204433Srajconst char *fdt_get_alias(const void *fdt, const char *name);
589204433Sraj
590204433Sraj/**
591204431Sraj * fdt_get_path - determine the full path of a node
592204431Sraj * @fdt: pointer to the device tree blob
593204431Sraj * @nodeoffset: offset of the node whose path to find
594204431Sraj * @buf: character buffer to contain the returned path (will be overwritten)
595204431Sraj * @buflen: size of the character buffer at buf
596204431Sraj *
597204431Sraj * fdt_get_path() computes the full path of the node at offset
598204431Sraj * nodeoffset, and records that path in the buffer at buf.
599204431Sraj *
600204431Sraj * NOTE: This function is expensive, as it must scan the device tree
601204431Sraj * structure from the start to nodeoffset.
602204431Sraj *
603204431Sraj * returns:
604204431Sraj *	0, on success
605204431Sraj *		buf contains the absolute path of the node at
606204431Sraj *		nodeoffset, as a NUL-terminated string.
607204431Sraj * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
608204431Sraj *	-FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
609204431Sraj *		characters and will not fit in the given buffer.
610204431Sraj *	-FDT_ERR_BADMAGIC,
611204431Sraj *	-FDT_ERR_BADVERSION,
612204431Sraj *	-FDT_ERR_BADSTATE,
613204431Sraj *	-FDT_ERR_BADSTRUCTURE, standard meanings
614204431Sraj */
615204431Srajint fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
616204431Sraj
617204431Sraj/**
618204431Sraj * fdt_supernode_atdepth_offset - find a specific ancestor of a node
619204431Sraj * @fdt: pointer to the device tree blob
620204431Sraj * @nodeoffset: offset of the node whose parent to find
621204431Sraj * @supernodedepth: depth of the ancestor to find
622204431Sraj * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
623204431Sraj *
624204431Sraj * fdt_supernode_atdepth_offset() finds an ancestor of the given node
625204431Sraj * at a specific depth from the root (where the root itself has depth
626204431Sraj * 0, its immediate subnodes depth 1 and so forth).  So
627204431Sraj *	fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
628204431Sraj * will always return 0, the offset of the root node.  If the node at
629204431Sraj * nodeoffset has depth D, then:
630204431Sraj *	fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
631204431Sraj * will return nodeoffset itself.
632204431Sraj *
633204431Sraj * NOTE: This function is expensive, as it must scan the device tree
634204431Sraj * structure from the start to nodeoffset.
635204431Sraj *
636204431Sraj * returns:
637204431Sraj
638204431Sraj *	structure block offset of the node at node offset's ancestor
639204431Sraj *		of depth supernodedepth (>=0), on success
640204431Sraj * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
641204431Sraj*	-FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset
642204431Sraj *	-FDT_ERR_BADMAGIC,
643204431Sraj *	-FDT_ERR_BADVERSION,
644204431Sraj *	-FDT_ERR_BADSTATE,
645204431Sraj *	-FDT_ERR_BADSTRUCTURE, standard meanings
646204431Sraj */
647204431Srajint fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
648204431Sraj				 int supernodedepth, int *nodedepth);
649204431Sraj
650204431Sraj/**
651204431Sraj * fdt_node_depth - find the depth of a given node
652204431Sraj * @fdt: pointer to the device tree blob
653204431Sraj * @nodeoffset: offset of the node whose parent to find
654204431Sraj *
655204431Sraj * fdt_node_depth() finds the depth of a given node.  The root node
656204431Sraj * has depth 0, its immediate subnodes depth 1 and so forth.
657204431Sraj *
658204431Sraj * NOTE: This function is expensive, as it must scan the device tree
659204431Sraj * structure from the start to nodeoffset.
660204431Sraj *
661204431Sraj * returns:
662204431Sraj *	depth of the node at nodeoffset (>=0), on success
663204431Sraj * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
664204431Sraj *	-FDT_ERR_BADMAGIC,
665204431Sraj *	-FDT_ERR_BADVERSION,
666204431Sraj *	-FDT_ERR_BADSTATE,
667204431Sraj *	-FDT_ERR_BADSTRUCTURE, standard meanings
668204431Sraj */
669204431Srajint fdt_node_depth(const void *fdt, int nodeoffset);
670204431Sraj
671204431Sraj/**
672204431Sraj * fdt_parent_offset - find the parent of a given node
673204431Sraj * @fdt: pointer to the device tree blob
674204431Sraj * @nodeoffset: offset of the node whose parent to find
675204431Sraj *
676204431Sraj * fdt_parent_offset() locates the parent node of a given node (that
677204431Sraj * is, it finds the offset of the node which contains the node at
678204431Sraj * nodeoffset as a subnode).
679204431Sraj *
680204431Sraj * NOTE: This function is expensive, as it must scan the device tree
681204431Sraj * structure from the start to nodeoffset, *twice*.
682204431Sraj *
683204431Sraj * returns:
684204431Sraj *	structure block offset of the parent of the node at nodeoffset
685204431Sraj *		(>=0), on success
686204431Sraj * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
687204431Sraj *	-FDT_ERR_BADMAGIC,
688204431Sraj *	-FDT_ERR_BADVERSION,
689204431Sraj *	-FDT_ERR_BADSTATE,
690204431Sraj *	-FDT_ERR_BADSTRUCTURE, standard meanings
691204431Sraj */
692204431Srajint fdt_parent_offset(const void *fdt, int nodeoffset);
693204431Sraj
694204431Sraj/**
695204431Sraj * fdt_node_offset_by_prop_value - find nodes with a given property value
696204431Sraj * @fdt: pointer to the device tree blob
697204431Sraj * @startoffset: only find nodes after this offset
698204431Sraj * @propname: property name to check
699204431Sraj * @propval: property value to search for
700204431Sraj * @proplen: length of the value in propval
701204431Sraj *
702204431Sraj * fdt_node_offset_by_prop_value() returns the offset of the first
703204431Sraj * node after startoffset, which has a property named propname whose
704204431Sraj * value is of length proplen and has value equal to propval; or if
705204431Sraj * startoffset is -1, the very first such node in the tree.
706204431Sraj *
707204431Sraj * To iterate through all nodes matching the criterion, the following
708204431Sraj * idiom can be used:
709204431Sraj *	offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
710204431Sraj *					       propval, proplen);
711204431Sraj *	while (offset != -FDT_ERR_NOTFOUND) {
712204431Sraj *		// other code here
713204431Sraj *		offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
714204431Sraj *						       propval, proplen);
715204431Sraj *	}
716204431Sraj *
717204431Sraj * Note the -1 in the first call to the function, if 0 is used here
718204431Sraj * instead, the function will never locate the root node, even if it
719204431Sraj * matches the criterion.
720204431Sraj *
721204431Sraj * returns:
722204431Sraj *	structure block offset of the located node (>= 0, >startoffset),
723204431Sraj *		 on success
724204431Sraj *	-FDT_ERR_NOTFOUND, no node matching the criterion exists in the
725204431Sraj *		tree after startoffset
726204431Sraj * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
727204431Sraj *	-FDT_ERR_BADMAGIC,
728204431Sraj *	-FDT_ERR_BADVERSION,
729204431Sraj *	-FDT_ERR_BADSTATE,
730204431Sraj *	-FDT_ERR_BADSTRUCTURE, standard meanings
731204431Sraj */
732204431Srajint fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
733204431Sraj				  const char *propname,
734204431Sraj				  const void *propval, int proplen);
735204431Sraj
736204431Sraj/**
737204431Sraj * fdt_node_offset_by_phandle - find the node with a given phandle
738204431Sraj * @fdt: pointer to the device tree blob
739204431Sraj * @phandle: phandle value
740204431Sraj *
741204431Sraj * fdt_node_offset_by_phandle() returns the offset of the node
742204431Sraj * which has the given phandle value.  If there is more than one node
743204431Sraj * in the tree with the given phandle (an invalid tree), results are
744204431Sraj * undefined.
745204431Sraj *
746204431Sraj * returns:
747204431Sraj *	structure block offset of the located node (>= 0), on success
748204431Sraj *	-FDT_ERR_NOTFOUND, no node with that phandle exists
749204431Sraj *	-FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
750204431Sraj *	-FDT_ERR_BADMAGIC,
751204431Sraj *	-FDT_ERR_BADVERSION,
752204431Sraj *	-FDT_ERR_BADSTATE,
753204431Sraj *	-FDT_ERR_BADSTRUCTURE, standard meanings
754204431Sraj */
755204431Srajint fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
756204431Sraj
757204431Sraj/**
758204431Sraj * fdt_node_check_compatible: check a node's compatible property
759204431Sraj * @fdt: pointer to the device tree blob
760204431Sraj * @nodeoffset: offset of a tree node
761204431Sraj * @compatible: string to match against
762204431Sraj *
763204431Sraj *
764204431Sraj * fdt_node_check_compatible() returns 0 if the given node contains a
765204431Sraj * 'compatible' property with the given string as one of its elements,
766204431Sraj * it returns non-zero otherwise, or on error.
767204431Sraj *
768204431Sraj * returns:
769204431Sraj *	0, if the node has a 'compatible' property listing the given string
770204431Sraj *	1, if the node has a 'compatible' property, but it does not list
771204431Sraj *		the given string
772204431Sraj *	-FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
773204431Sraj * 	-FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
774204431Sraj *	-FDT_ERR_BADMAGIC,
775204431Sraj *	-FDT_ERR_BADVERSION,
776204431Sraj *	-FDT_ERR_BADSTATE,
777204431Sraj *	-FDT_ERR_BADSTRUCTURE, standard meanings
778204431Sraj */
779204431Srajint fdt_node_check_compatible(const void *fdt, int nodeoffset,
780204431Sraj			      const char *compatible);
781204431Sraj
782204431Sraj/**
783204431Sraj * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
784204431Sraj * @fdt: pointer to the device tree blob
785204431Sraj * @startoffset: only find nodes after this offset
786204431Sraj * @compatible: 'compatible' string to match against
787204431Sraj *
788204431Sraj * fdt_node_offset_by_compatible() returns the offset of the first
789204431Sraj * node after startoffset, which has a 'compatible' property which
790204431Sraj * lists the given compatible string; or if startoffset is -1, the
791204431Sraj * very first such node in the tree.
792204431Sraj *
793204431Sraj * To iterate through all nodes matching the criterion, the following
794204431Sraj * idiom can be used:
795204431Sraj *	offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
796204431Sraj *	while (offset != -FDT_ERR_NOTFOUND) {
797204431Sraj *		// other code here
798204431Sraj *		offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
799204431Sraj *	}
800204431Sraj *
801204431Sraj * Note the -1 in the first call to the function, if 0 is used here
802204431Sraj * instead, the function will never locate the root node, even if it
803204431Sraj * matches the criterion.
804204431Sraj *
805204431Sraj * returns:
806204431Sraj *	structure block offset of the located node (>= 0, >startoffset),
807204431Sraj *		 on success
808204431Sraj *	-FDT_ERR_NOTFOUND, no node matching the criterion exists in the
809204431Sraj *		tree after startoffset
810204431Sraj * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
811204431Sraj *	-FDT_ERR_BADMAGIC,
812204431Sraj *	-FDT_ERR_BADVERSION,
813204431Sraj *	-FDT_ERR_BADSTATE,
814204431Sraj *	-FDT_ERR_BADSTRUCTURE, standard meanings
815204431Sraj */
816204431Srajint fdt_node_offset_by_compatible(const void *fdt, int startoffset,
817204431Sraj				  const char *compatible);
818204431Sraj
819204431Sraj/**********************************************************************/
820204431Sraj/* Write-in-place functions                                           */
821204431Sraj/**********************************************************************/
822204431Sraj
823204431Sraj/**
824204431Sraj * fdt_setprop_inplace - change a property's value, but not its size
825204431Sraj * @fdt: pointer to the device tree blob
826204431Sraj * @nodeoffset: offset of the node whose property to change
827204431Sraj * @name: name of the property to change
828204431Sraj * @val: pointer to data to replace the property value with
829204431Sraj * @len: length of the property value
830204431Sraj *
831204431Sraj * fdt_setprop_inplace() replaces the value of a given property with
832204431Sraj * the data in val, of length len.  This function cannot change the
833204431Sraj * size of a property, and so will only work if len is equal to the
834204431Sraj * current length of the property.
835204431Sraj *
836204431Sraj * This function will alter only the bytes in the blob which contain
837204431Sraj * the given property value, and will not alter or move any other part
838204431Sraj * of the tree.
839204431Sraj *
840204431Sraj * returns:
841204431Sraj *	0, on success
842204431Sraj *	-FDT_ERR_NOSPACE, if len is not equal to the property's current length
843204431Sraj *	-FDT_ERR_NOTFOUND, node does not have the named property
844204431Sraj *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
845204431Sraj *	-FDT_ERR_BADMAGIC,
846204431Sraj *	-FDT_ERR_BADVERSION,
847204431Sraj *	-FDT_ERR_BADSTATE,
848204431Sraj *	-FDT_ERR_BADSTRUCTURE,
849204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
850204431Sraj */
851204431Srajint fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
852204431Sraj			const void *val, int len);
853204431Sraj
854204431Sraj/**
855238742Simp * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
856204431Sraj * @fdt: pointer to the device tree blob
857204431Sraj * @nodeoffset: offset of the node whose property to change
858204431Sraj * @name: name of the property to change
859238742Simp * @val: 32-bit integer value to replace the property with
860204431Sraj *
861238742Simp * fdt_setprop_inplace_u32() replaces the value of a given property
862238742Simp * with the 32-bit integer value in val, converting val to big-endian
863238742Simp * if necessary.  This function cannot change the size of a property,
864238742Simp * and so will only work if the property already exists and has length
865238742Simp * 4.
866204431Sraj *
867204431Sraj * This function will alter only the bytes in the blob which contain
868204431Sraj * the given property value, and will not alter or move any other part
869204431Sraj * of the tree.
870204431Sraj *
871204431Sraj * returns:
872204431Sraj *	0, on success
873204431Sraj *	-FDT_ERR_NOSPACE, if the property's length is not equal to 4
874238742Simp *	-FDT_ERR_NOTFOUND, node does not have the named property
875204431Sraj *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
876204431Sraj *	-FDT_ERR_BADMAGIC,
877204431Sraj *	-FDT_ERR_BADVERSION,
878204431Sraj *	-FDT_ERR_BADSTATE,
879204431Sraj *	-FDT_ERR_BADSTRUCTURE,
880204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
881204431Sraj */
882238742Simpstatic inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
883238742Simp					  const char *name, uint32_t val)
884204431Sraj{
885204431Sraj	val = cpu_to_fdt32(val);
886204431Sraj	return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
887204431Sraj}
888204431Sraj
889204431Sraj/**
890238742Simp * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
891238742Simp * @fdt: pointer to the device tree blob
892238742Simp * @nodeoffset: offset of the node whose property to change
893238742Simp * @name: name of the property to change
894238742Simp * @val: 64-bit integer value to replace the property with
895238742Simp *
896238742Simp * fdt_setprop_inplace_u64() replaces the value of a given property
897238742Simp * with the 64-bit integer value in val, converting val to big-endian
898238742Simp * if necessary.  This function cannot change the size of a property,
899238742Simp * and so will only work if the property already exists and has length
900238742Simp * 8.
901238742Simp *
902238742Simp * This function will alter only the bytes in the blob which contain
903238742Simp * the given property value, and will not alter or move any other part
904238742Simp * of the tree.
905238742Simp *
906238742Simp * returns:
907238742Simp *	0, on success
908238742Simp *	-FDT_ERR_NOSPACE, if the property's length is not equal to 8
909238742Simp *	-FDT_ERR_NOTFOUND, node does not have the named property
910238742Simp *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
911238742Simp *	-FDT_ERR_BADMAGIC,
912238742Simp *	-FDT_ERR_BADVERSION,
913238742Simp *	-FDT_ERR_BADSTATE,
914238742Simp *	-FDT_ERR_BADSTRUCTURE,
915238742Simp *	-FDT_ERR_TRUNCATED, standard meanings
916238742Simp */
917238742Simpstatic inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
918238742Simp					  const char *name, uint64_t val)
919238742Simp{
920238742Simp	val = cpu_to_fdt64(val);
921238742Simp	return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
922238742Simp}
923238742Simp
924238742Simp/**
925238742Simp * fdt_setprop_inplace_cell - change the value of a single-cell property
926238742Simp *
927238742Simp * This is an alternative name for fdt_setprop_inplace_u32()
928238742Simp */
929238742Simpstatic inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
930238742Simp					   const char *name, uint32_t val)
931238742Simp{
932238742Simp	return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
933238742Simp}
934238742Simp
935238742Simp/**
936204431Sraj * fdt_nop_property - replace a property with nop tags
937204431Sraj * @fdt: pointer to the device tree blob
938204431Sraj * @nodeoffset: offset of the node whose property to nop
939204431Sraj * @name: name of the property to nop
940204431Sraj *
941204431Sraj * fdt_nop_property() will replace a given property's representation
942204431Sraj * in the blob with FDT_NOP tags, effectively removing it from the
943204431Sraj * tree.
944204431Sraj *
945204431Sraj * This function will alter only the bytes in the blob which contain
946204431Sraj * the property, and will not alter or move any other part of the
947204431Sraj * tree.
948204431Sraj *
949204431Sraj * returns:
950204431Sraj *	0, on success
951204431Sraj *	-FDT_ERR_NOTFOUND, node does not have the named property
952204431Sraj *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
953204431Sraj *	-FDT_ERR_BADMAGIC,
954204431Sraj *	-FDT_ERR_BADVERSION,
955204431Sraj *	-FDT_ERR_BADSTATE,
956204431Sraj *	-FDT_ERR_BADSTRUCTURE,
957204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
958204431Sraj */
959204431Srajint fdt_nop_property(void *fdt, int nodeoffset, const char *name);
960204431Sraj
961204431Sraj/**
962204431Sraj * fdt_nop_node - replace a node (subtree) with nop tags
963204431Sraj * @fdt: pointer to the device tree blob
964204431Sraj * @nodeoffset: offset of the node to nop
965204431Sraj *
966204431Sraj * fdt_nop_node() will replace a given node's representation in the
967204431Sraj * blob, including all its subnodes, if any, with FDT_NOP tags,
968204431Sraj * effectively removing it from the tree.
969204431Sraj *
970204431Sraj * This function will alter only the bytes in the blob which contain
971204431Sraj * the node and its properties and subnodes, and will not alter or
972204431Sraj * move any other part of the tree.
973204431Sraj *
974204431Sraj * returns:
975204431Sraj *	0, on success
976204431Sraj *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
977204431Sraj *	-FDT_ERR_BADMAGIC,
978204431Sraj *	-FDT_ERR_BADVERSION,
979204431Sraj *	-FDT_ERR_BADSTATE,
980204431Sraj *	-FDT_ERR_BADSTRUCTURE,
981204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
982204431Sraj */
983204431Srajint fdt_nop_node(void *fdt, int nodeoffset);
984204431Sraj
985204431Sraj/**********************************************************************/
986204431Sraj/* Sequential write functions                                         */
987204431Sraj/**********************************************************************/
988204431Sraj
989204431Srajint fdt_create(void *buf, int bufsize);
990204431Srajint fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
991204431Srajint fdt_finish_reservemap(void *fdt);
992204431Srajint fdt_begin_node(void *fdt, const char *name);
993204431Srajint fdt_property(void *fdt, const char *name, const void *val, int len);
994238742Simpstatic inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
995204431Sraj{
996204431Sraj	val = cpu_to_fdt32(val);
997204431Sraj	return fdt_property(fdt, name, &val, sizeof(val));
998204431Sraj}
999238742Simpstatic inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
1000238742Simp{
1001238742Simp	val = cpu_to_fdt64(val);
1002238742Simp	return fdt_property(fdt, name, &val, sizeof(val));
1003238742Simp}
1004238742Simpstatic inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
1005238742Simp{
1006238742Simp	return fdt_property_u32(fdt, name, val);
1007238742Simp}
1008204431Sraj#define fdt_property_string(fdt, name, str) \
1009204431Sraj	fdt_property(fdt, name, str, strlen(str)+1)
1010204431Srajint fdt_end_node(void *fdt);
1011204431Srajint fdt_finish(void *fdt);
1012204431Sraj
1013204431Sraj/**********************************************************************/
1014204431Sraj/* Read-write functions                                               */
1015204431Sraj/**********************************************************************/
1016204431Sraj
1017238742Simpint fdt_create_empty_tree(void *buf, int bufsize);
1018204431Srajint fdt_open_into(const void *fdt, void *buf, int bufsize);
1019204431Srajint fdt_pack(void *fdt);
1020204431Sraj
1021204431Sraj/**
1022204431Sraj * fdt_add_mem_rsv - add one memory reserve map entry
1023204431Sraj * @fdt: pointer to the device tree blob
1024204431Sraj * @address, @size: 64-bit values (native endian)
1025204431Sraj *
1026204431Sraj * Adds a reserve map entry to the given blob reserving a region at
1027204431Sraj * address address of length size.
1028204431Sraj *
1029204431Sraj * This function will insert data into the reserve map and will
1030204431Sraj * therefore change the indexes of some entries in the table.
1031204431Sraj *
1032204431Sraj * returns:
1033204431Sraj *	0, on success
1034204431Sraj *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1035204431Sraj *		contain the new reservation entry
1036204431Sraj *	-FDT_ERR_BADMAGIC,
1037204431Sraj *	-FDT_ERR_BADVERSION,
1038204431Sraj *	-FDT_ERR_BADSTATE,
1039204431Sraj *	-FDT_ERR_BADSTRUCTURE,
1040204431Sraj *	-FDT_ERR_BADLAYOUT,
1041204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
1042204431Sraj */
1043204431Srajint fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
1044204431Sraj
1045204431Sraj/**
1046204431Sraj * fdt_del_mem_rsv - remove a memory reserve map entry
1047204431Sraj * @fdt: pointer to the device tree blob
1048204431Sraj * @n: entry to remove
1049204431Sraj *
1050204431Sraj * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
1051204431Sraj * the blob.
1052204431Sraj *
1053204431Sraj * This function will delete data from the reservation table and will
1054204431Sraj * therefore change the indexes of some entries in the table.
1055204431Sraj *
1056204431Sraj * returns:
1057204431Sraj *	0, on success
1058204431Sraj *	-FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
1059204431Sraj *		are less than n+1 reserve map entries)
1060204431Sraj *	-FDT_ERR_BADMAGIC,
1061204431Sraj *	-FDT_ERR_BADVERSION,
1062204431Sraj *	-FDT_ERR_BADSTATE,
1063204431Sraj *	-FDT_ERR_BADSTRUCTURE,
1064204431Sraj *	-FDT_ERR_BADLAYOUT,
1065204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
1066204431Sraj */
1067204431Srajint fdt_del_mem_rsv(void *fdt, int n);
1068204431Sraj
1069204431Sraj/**
1070204431Sraj * fdt_set_name - change the name of a given node
1071204431Sraj * @fdt: pointer to the device tree blob
1072204431Sraj * @nodeoffset: structure block offset of a node
1073204431Sraj * @name: name to give the node
1074204431Sraj *
1075204431Sraj * fdt_set_name() replaces the name (including unit address, if any)
1076204431Sraj * of the given node with the given string.  NOTE: this function can't
1077204431Sraj * efficiently check if the new name is unique amongst the given
1078204431Sraj * node's siblings; results are undefined if this function is invoked
1079204431Sraj * with a name equal to one of the given node's siblings.
1080204431Sraj *
1081204431Sraj * This function may insert or delete data from the blob, and will
1082204431Sraj * therefore change the offsets of some existing nodes.
1083204431Sraj *
1084204431Sraj * returns:
1085204431Sraj *	0, on success
1086204431Sraj *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob
1087204431Sraj *		to contain the new name
1088204431Sraj *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1089204431Sraj *	-FDT_ERR_BADMAGIC,
1090204431Sraj *	-FDT_ERR_BADVERSION,
1091204431Sraj *	-FDT_ERR_BADSTATE, standard meanings
1092204431Sraj */
1093204431Srajint fdt_set_name(void *fdt, int nodeoffset, const char *name);
1094204431Sraj
1095204431Sraj/**
1096204431Sraj * fdt_setprop - create or change a property
1097204431Sraj * @fdt: pointer to the device tree blob
1098204431Sraj * @nodeoffset: offset of the node whose property to change
1099204431Sraj * @name: name of the property to change
1100204431Sraj * @val: pointer to data to set the property value to
1101204431Sraj * @len: length of the property value
1102204431Sraj *
1103204431Sraj * fdt_setprop() sets the value of the named property in the given
1104204431Sraj * node to the given value and length, creating the property if it
1105204431Sraj * does not already exist.
1106204431Sraj *
1107204431Sraj * This function may insert or delete data from the blob, and will
1108204431Sraj * therefore change the offsets of some existing nodes.
1109204431Sraj *
1110204431Sraj * returns:
1111204431Sraj *	0, on success
1112204431Sraj *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1113204431Sraj *		contain the new property value
1114204431Sraj *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1115204431Sraj *	-FDT_ERR_BADLAYOUT,
1116204431Sraj *	-FDT_ERR_BADMAGIC,
1117204431Sraj *	-FDT_ERR_BADVERSION,
1118204431Sraj *	-FDT_ERR_BADSTATE,
1119204431Sraj *	-FDT_ERR_BADSTRUCTURE,
1120204431Sraj *	-FDT_ERR_BADLAYOUT,
1121204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
1122204431Sraj */
1123204431Srajint fdt_setprop(void *fdt, int nodeoffset, const char *name,
1124204431Sraj		const void *val, int len);
1125204431Sraj
1126204431Sraj/**
1127238742Simp * fdt_setprop_u32 - set a property to a 32-bit integer
1128204431Sraj * @fdt: pointer to the device tree blob
1129204431Sraj * @nodeoffset: offset of the node whose property to change
1130204431Sraj * @name: name of the property to change
1131204431Sraj * @val: 32-bit integer value for the property (native endian)
1132204431Sraj *
1133238742Simp * fdt_setprop_u32() sets the value of the named property in the given
1134238742Simp * node to the given 32-bit integer value (converting to big-endian if
1135204431Sraj * necessary), or creates a new property with that value if it does
1136204431Sraj * not already exist.
1137204431Sraj *
1138204431Sraj * This function may insert or delete data from the blob, and will
1139204431Sraj * therefore change the offsets of some existing nodes.
1140204431Sraj *
1141204431Sraj * returns:
1142204431Sraj *	0, on success
1143204431Sraj *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1144204431Sraj *		contain the new property value
1145204431Sraj *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1146204431Sraj *	-FDT_ERR_BADLAYOUT,
1147204431Sraj *	-FDT_ERR_BADMAGIC,
1148204431Sraj *	-FDT_ERR_BADVERSION,
1149204431Sraj *	-FDT_ERR_BADSTATE,
1150204431Sraj *	-FDT_ERR_BADSTRUCTURE,
1151204431Sraj *	-FDT_ERR_BADLAYOUT,
1152204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
1153204431Sraj */
1154238742Simpstatic inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
1155238742Simp				  uint32_t val)
1156204431Sraj{
1157204431Sraj	val = cpu_to_fdt32(val);
1158204431Sraj	return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
1159204431Sraj}
1160204431Sraj
1161204431Sraj/**
1162238742Simp * fdt_setprop_u64 - set a property to a 64-bit integer
1163238742Simp * @fdt: pointer to the device tree blob
1164238742Simp * @nodeoffset: offset of the node whose property to change
1165238742Simp * @name: name of the property to change
1166238742Simp * @val: 64-bit integer value for the property (native endian)
1167238742Simp *
1168238742Simp * fdt_setprop_u64() sets the value of the named property in the given
1169238742Simp * node to the given 64-bit integer value (converting to big-endian if
1170238742Simp * necessary), or creates a new property with that value if it does
1171238742Simp * not already exist.
1172238742Simp *
1173238742Simp * This function may insert or delete data from the blob, and will
1174238742Simp * therefore change the offsets of some existing nodes.
1175238742Simp *
1176238742Simp * returns:
1177238742Simp *	0, on success
1178238742Simp *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1179238742Simp *		contain the new property value
1180238742Simp *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1181238742Simp *	-FDT_ERR_BADLAYOUT,
1182238742Simp *	-FDT_ERR_BADMAGIC,
1183238742Simp *	-FDT_ERR_BADVERSION,
1184238742Simp *	-FDT_ERR_BADSTATE,
1185238742Simp *	-FDT_ERR_BADSTRUCTURE,
1186238742Simp *	-FDT_ERR_BADLAYOUT,
1187238742Simp *	-FDT_ERR_TRUNCATED, standard meanings
1188238742Simp */
1189238742Simpstatic inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
1190238742Simp				  uint64_t val)
1191238742Simp{
1192238742Simp	val = cpu_to_fdt64(val);
1193238742Simp	return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
1194238742Simp}
1195238742Simp
1196238742Simp/**
1197238742Simp * fdt_setprop_cell - set a property to a single cell value
1198238742Simp *
1199238742Simp * This is an alternative name for fdt_setprop_u32()
1200238742Simp */
1201238742Simpstatic inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
1202238742Simp				   uint32_t val)
1203238742Simp{
1204238742Simp	return fdt_setprop_u32(fdt, nodeoffset, name, val);
1205238742Simp}
1206238742Simp
1207238742Simp/**
1208204431Sraj * fdt_setprop_string - set a property to a string value
1209204431Sraj * @fdt: pointer to the device tree blob
1210204431Sraj * @nodeoffset: offset of the node whose property to change
1211204431Sraj * @name: name of the property to change
1212204431Sraj * @str: string value for the property
1213204431Sraj *
1214204431Sraj * fdt_setprop_string() sets the value of the named property in the
1215204431Sraj * given node to the given string value (using the length of the
1216204431Sraj * string to determine the new length of the property), or creates a
1217204431Sraj * new property with that value if it does not already exist.
1218204431Sraj *
1219204431Sraj * This function may insert or delete data from the blob, and will
1220204431Sraj * therefore change the offsets of some existing nodes.
1221204431Sraj *
1222204431Sraj * returns:
1223204431Sraj *	0, on success
1224204431Sraj *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1225204431Sraj *		contain the new property value
1226204431Sraj *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1227204431Sraj *	-FDT_ERR_BADLAYOUT,
1228204431Sraj *	-FDT_ERR_BADMAGIC,
1229204431Sraj *	-FDT_ERR_BADVERSION,
1230204431Sraj *	-FDT_ERR_BADSTATE,
1231204431Sraj *	-FDT_ERR_BADSTRUCTURE,
1232204431Sraj *	-FDT_ERR_BADLAYOUT,
1233204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
1234204431Sraj */
1235204431Sraj#define fdt_setprop_string(fdt, nodeoffset, name, str) \
1236204431Sraj	fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1237204431Sraj
1238204431Sraj/**
1239238742Simp * fdt_appendprop - append to or create a property
1240238742Simp * @fdt: pointer to the device tree blob
1241238742Simp * @nodeoffset: offset of the node whose property to change
1242238742Simp * @name: name of the property to append to
1243238742Simp * @val: pointer to data to append to the property value
1244238742Simp * @len: length of the data to append to the property value
1245238742Simp *
1246238742Simp * fdt_appendprop() appends the value to the named property in the
1247238742Simp * given node, creating the property if it does not already exist.
1248238742Simp *
1249238742Simp * This function may insert data into the blob, and will therefore
1250238742Simp * change the offsets of some existing nodes.
1251238742Simp *
1252238742Simp * returns:
1253238742Simp *	0, on success
1254238742Simp *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1255238742Simp *		contain the new property value
1256238742Simp *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1257238742Simp *	-FDT_ERR_BADLAYOUT,
1258238742Simp *	-FDT_ERR_BADMAGIC,
1259238742Simp *	-FDT_ERR_BADVERSION,
1260238742Simp *	-FDT_ERR_BADSTATE,
1261238742Simp *	-FDT_ERR_BADSTRUCTURE,
1262238742Simp *	-FDT_ERR_BADLAYOUT,
1263238742Simp *	-FDT_ERR_TRUNCATED, standard meanings
1264238742Simp */
1265238742Simpint fdt_appendprop(void *fdt, int nodeoffset, const char *name,
1266238742Simp		   const void *val, int len);
1267238742Simp
1268238742Simp/**
1269238742Simp * fdt_appendprop_u32 - append a 32-bit integer value to a property
1270238742Simp * @fdt: pointer to the device tree blob
1271238742Simp * @nodeoffset: offset of the node whose property to change
1272238742Simp * @name: name of the property to change
1273238742Simp * @val: 32-bit integer value to append to the property (native endian)
1274238742Simp *
1275238742Simp * fdt_appendprop_u32() appends the given 32-bit integer value
1276238742Simp * (converting to big-endian if necessary) to the value of the named
1277238742Simp * property in the given node, or creates a new property with that
1278238742Simp * value if it does not already exist.
1279238742Simp *
1280238742Simp * This function may insert data into the blob, and will therefore
1281238742Simp * change the offsets of some existing nodes.
1282238742Simp *
1283238742Simp * returns:
1284238742Simp *	0, on success
1285238742Simp *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1286238742Simp *		contain the new property value
1287238742Simp *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1288238742Simp *	-FDT_ERR_BADLAYOUT,
1289238742Simp *	-FDT_ERR_BADMAGIC,
1290238742Simp *	-FDT_ERR_BADVERSION,
1291238742Simp *	-FDT_ERR_BADSTATE,
1292238742Simp *	-FDT_ERR_BADSTRUCTURE,
1293238742Simp *	-FDT_ERR_BADLAYOUT,
1294238742Simp *	-FDT_ERR_TRUNCATED, standard meanings
1295238742Simp */
1296238742Simpstatic inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
1297238742Simp				     const char *name, uint32_t val)
1298238742Simp{
1299238742Simp	val = cpu_to_fdt32(val);
1300238742Simp	return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
1301238742Simp}
1302238742Simp
1303238742Simp/**
1304238742Simp * fdt_appendprop_u64 - append a 64-bit integer value to a property
1305238742Simp * @fdt: pointer to the device tree blob
1306238742Simp * @nodeoffset: offset of the node whose property to change
1307238742Simp * @name: name of the property to change
1308238742Simp * @val: 64-bit integer value to append to the property (native endian)
1309238742Simp *
1310238742Simp * fdt_appendprop_u64() appends the given 64-bit integer value
1311238742Simp * (converting to big-endian if necessary) to the value of the named
1312238742Simp * property in the given node, or creates a new property with that
1313238742Simp * value if it does not already exist.
1314238742Simp *
1315238742Simp * This function may insert data into the blob, and will therefore
1316238742Simp * change the offsets of some existing nodes.
1317238742Simp *
1318238742Simp * returns:
1319238742Simp *	0, on success
1320238742Simp *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1321238742Simp *		contain the new property value
1322238742Simp *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1323238742Simp *	-FDT_ERR_BADLAYOUT,
1324238742Simp *	-FDT_ERR_BADMAGIC,
1325238742Simp *	-FDT_ERR_BADVERSION,
1326238742Simp *	-FDT_ERR_BADSTATE,
1327238742Simp *	-FDT_ERR_BADSTRUCTURE,
1328238742Simp *	-FDT_ERR_BADLAYOUT,
1329238742Simp *	-FDT_ERR_TRUNCATED, standard meanings
1330238742Simp */
1331238742Simpstatic inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
1332238742Simp				     const char *name, uint64_t val)
1333238742Simp{
1334238742Simp	val = cpu_to_fdt64(val);
1335238742Simp	return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
1336238742Simp}
1337238742Simp
1338238742Simp/**
1339238742Simp * fdt_appendprop_cell - append a single cell value to a property
1340238742Simp *
1341238742Simp * This is an alternative name for fdt_appendprop_u32()
1342238742Simp */
1343238742Simpstatic inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
1344238742Simp				      const char *name, uint32_t val)
1345238742Simp{
1346238742Simp	return fdt_appendprop_u32(fdt, nodeoffset, name, val);
1347238742Simp}
1348238742Simp
1349238742Simp/**
1350238742Simp * fdt_appendprop_string - append a string to a property
1351238742Simp * @fdt: pointer to the device tree blob
1352238742Simp * @nodeoffset: offset of the node whose property to change
1353238742Simp * @name: name of the property to change
1354238742Simp * @str: string value to append to the property
1355238742Simp *
1356238742Simp * fdt_appendprop_string() appends the given string to the value of
1357238742Simp * the named property in the given node, or creates a new property
1358238742Simp * with that value if it does not already exist.
1359238742Simp *
1360238742Simp * This function may insert data into the blob, and will therefore
1361238742Simp * change the offsets of some existing nodes.
1362238742Simp *
1363238742Simp * returns:
1364238742Simp *	0, on success
1365238742Simp *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1366238742Simp *		contain the new property value
1367238742Simp *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1368238742Simp *	-FDT_ERR_BADLAYOUT,
1369238742Simp *	-FDT_ERR_BADMAGIC,
1370238742Simp *	-FDT_ERR_BADVERSION,
1371238742Simp *	-FDT_ERR_BADSTATE,
1372238742Simp *	-FDT_ERR_BADSTRUCTURE,
1373238742Simp *	-FDT_ERR_BADLAYOUT,
1374238742Simp *	-FDT_ERR_TRUNCATED, standard meanings
1375238742Simp */
1376238742Simp#define fdt_appendprop_string(fdt, nodeoffset, name, str) \
1377238742Simp	fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1378238742Simp
1379238742Simp/**
1380204431Sraj * fdt_delprop - delete a property
1381204431Sraj * @fdt: pointer to the device tree blob
1382204431Sraj * @nodeoffset: offset of the node whose property to nop
1383204431Sraj * @name: name of the property to nop
1384204431Sraj *
1385204431Sraj * fdt_del_property() will delete the given property.
1386204431Sraj *
1387204431Sraj * This function will delete data from the blob, and will therefore
1388204431Sraj * change the offsets of some existing nodes.
1389204431Sraj *
1390204431Sraj * returns:
1391204431Sraj *	0, on success
1392204431Sraj *	-FDT_ERR_NOTFOUND, node does not have the named property
1393204431Sraj *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1394204431Sraj *	-FDT_ERR_BADLAYOUT,
1395204431Sraj *	-FDT_ERR_BADMAGIC,
1396204431Sraj *	-FDT_ERR_BADVERSION,
1397204431Sraj *	-FDT_ERR_BADSTATE,
1398204431Sraj *	-FDT_ERR_BADSTRUCTURE,
1399204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
1400204431Sraj */
1401204431Srajint fdt_delprop(void *fdt, int nodeoffset, const char *name);
1402204431Sraj
1403204431Sraj/**
1404204431Sraj * fdt_add_subnode_namelen - creates a new node based on substring
1405204431Sraj * @fdt: pointer to the device tree blob
1406204431Sraj * @parentoffset: structure block offset of a node
1407204431Sraj * @name: name of the subnode to locate
1408204431Sraj * @namelen: number of characters of name to consider
1409204431Sraj *
1410204431Sraj * Identical to fdt_add_subnode(), but use only the first namelen
1411204431Sraj * characters of name as the name of the new node.  This is useful for
1412204431Sraj * creating subnodes based on a portion of a larger string, such as a
1413204431Sraj * full path.
1414204431Sraj */
1415204431Srajint fdt_add_subnode_namelen(void *fdt, int parentoffset,
1416204431Sraj			    const char *name, int namelen);
1417204431Sraj
1418204431Sraj/**
1419204431Sraj * fdt_add_subnode - creates a new node
1420204431Sraj * @fdt: pointer to the device tree blob
1421204431Sraj * @parentoffset: structure block offset of a node
1422204431Sraj * @name: name of the subnode to locate
1423204431Sraj *
1424204431Sraj * fdt_add_subnode() creates a new node as a subnode of the node at
1425204431Sraj * structure block offset parentoffset, with the given name (which
1426204431Sraj * should include the unit address, if any).
1427204431Sraj *
1428204431Sraj * This function will insert data into the blob, and will therefore
1429204431Sraj * change the offsets of some existing nodes.
1430204431Sraj
1431204431Sraj * returns:
1432204431Sraj *	structure block offset of the created nodeequested subnode (>=0), on success
1433204431Sraj *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
1434204431Sraj *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
1435204431Sraj *	-FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
1436204431Sraj *		the given name
1437204431Sraj *	-FDT_ERR_NOSPACE, if there is insufficient free space in the
1438204431Sraj *		blob to contain the new node
1439204431Sraj *	-FDT_ERR_NOSPACE
1440204431Sraj *	-FDT_ERR_BADLAYOUT
1441204431Sraj *      -FDT_ERR_BADMAGIC,
1442204431Sraj *	-FDT_ERR_BADVERSION,
1443204431Sraj *	-FDT_ERR_BADSTATE,
1444204431Sraj *	-FDT_ERR_BADSTRUCTURE,
1445204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings.
1446204431Sraj */
1447204431Srajint fdt_add_subnode(void *fdt, int parentoffset, const char *name);
1448204431Sraj
1449204431Sraj/**
1450204431Sraj * fdt_del_node - delete a node (subtree)
1451204431Sraj * @fdt: pointer to the device tree blob
1452204431Sraj * @nodeoffset: offset of the node to nop
1453204431Sraj *
1454204431Sraj * fdt_del_node() will remove the given node, including all its
1455204431Sraj * subnodes if any, from the blob.
1456204431Sraj *
1457204431Sraj * This function will delete data from the blob, and will therefore
1458204431Sraj * change the offsets of some existing nodes.
1459204431Sraj *
1460204431Sraj * returns:
1461204431Sraj *	0, on success
1462204431Sraj *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1463204431Sraj *	-FDT_ERR_BADLAYOUT,
1464204431Sraj *	-FDT_ERR_BADMAGIC,
1465204431Sraj *	-FDT_ERR_BADVERSION,
1466204431Sraj *	-FDT_ERR_BADSTATE,
1467204431Sraj *	-FDT_ERR_BADSTRUCTURE,
1468204431Sraj *	-FDT_ERR_TRUNCATED, standard meanings
1469204431Sraj */
1470204431Srajint fdt_del_node(void *fdt, int nodeoffset);
1471204431Sraj
1472204431Sraj/**********************************************************************/
1473204431Sraj/* Debugging / informational functions                                */
1474204431Sraj/**********************************************************************/
1475204431Sraj
1476204431Srajconst char *fdt_strerror(int errval);
1477204431Sraj
1478204431Sraj#endif /* _LIBFDT_H */
1479