xref: /openbmc/linux/scripts/dtc/libfdt/libfdt.h (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
112869ecdSRob Herring /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
29130ba88SRob Herring #ifndef LIBFDT_H
39130ba88SRob Herring #define LIBFDT_H
49fffb55fSDavid Gibson /*
59fffb55fSDavid Gibson  * libfdt - Flat Device Tree manipulation
69fffb55fSDavid Gibson  * Copyright (C) 2006 David Gibson, IBM Corporation.
79fffb55fSDavid Gibson  */
89fffb55fSDavid Gibson 
947605971SRob Herring #include "libfdt_env.h"
1047605971SRob Herring #include "fdt.h"
119fffb55fSDavid Gibson 
123eb619b2SRob Herring #ifdef __cplusplus
133eb619b2SRob Herring extern "C" {
143eb619b2SRob Herring #endif
153eb619b2SRob Herring 
169130ba88SRob Herring #define FDT_FIRST_SUPPORTED_VERSION	0x02
1779edff12SRob Herring #define FDT_LAST_COMPATIBLE_VERSION 0x10
189fffb55fSDavid Gibson #define FDT_LAST_SUPPORTED_VERSION	0x11
199fffb55fSDavid Gibson 
209fffb55fSDavid Gibson /* Error codes: informative error codes */
219fffb55fSDavid Gibson #define FDT_ERR_NOTFOUND	1
229fffb55fSDavid Gibson 	/* FDT_ERR_NOTFOUND: The requested node or property does not exist */
239fffb55fSDavid Gibson #define FDT_ERR_EXISTS		2
246f05afcbSRob Herring 	/* FDT_ERR_EXISTS: Attempted to create a node or property which
259fffb55fSDavid Gibson 	 * already exists */
269fffb55fSDavid Gibson #define FDT_ERR_NOSPACE		3
279fffb55fSDavid Gibson 	/* FDT_ERR_NOSPACE: Operation needed to expand the device
289fffb55fSDavid Gibson 	 * tree, but its buffer did not have sufficient space to
299fffb55fSDavid Gibson 	 * contain the expanded tree. Use fdt_open_into() to move the
309fffb55fSDavid Gibson 	 * device tree to a buffer with more space. */
319fffb55fSDavid Gibson 
329fffb55fSDavid Gibson /* Error codes: codes for bad parameters */
339fffb55fSDavid Gibson #define FDT_ERR_BADOFFSET	4
349fffb55fSDavid Gibson 	/* FDT_ERR_BADOFFSET: Function was passed a structure block
359fffb55fSDavid Gibson 	 * offset which is out-of-bounds, or which points to an
369fffb55fSDavid Gibson 	 * unsuitable part of the structure for the operation. */
379fffb55fSDavid Gibson #define FDT_ERR_BADPATH		5
389fffb55fSDavid Gibson 	/* FDT_ERR_BADPATH: Function was passed a badly formatted path
399fffb55fSDavid Gibson 	 * (e.g. missing a leading / for a function which requires an
409fffb55fSDavid Gibson 	 * absolute path) */
419fffb55fSDavid Gibson #define FDT_ERR_BADPHANDLE	6
426f05afcbSRob Herring 	/* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
436f05afcbSRob Herring 	 * This can be caused either by an invalid phandle property
446f05afcbSRob Herring 	 * length, or the phandle value was either 0 or -1, which are
456f05afcbSRob Herring 	 * not permitted. */
469fffb55fSDavid Gibson #define FDT_ERR_BADSTATE	7
479fffb55fSDavid Gibson 	/* FDT_ERR_BADSTATE: Function was passed an incomplete device
489fffb55fSDavid Gibson 	 * tree created by the sequential-write functions, which is
499fffb55fSDavid Gibson 	 * not sufficiently complete for the requested operation. */
509fffb55fSDavid Gibson 
519fffb55fSDavid Gibson /* Error codes: codes for bad device tree blobs */
529fffb55fSDavid Gibson #define FDT_ERR_TRUNCATED	8
53f858927fSRob Herring 	/* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly
54f858927fSRob Herring 	 * terminated (overflows, goes outside allowed bounds, or
55f858927fSRob Herring 	 * isn't properly terminated).  */
569fffb55fSDavid Gibson #define FDT_ERR_BADMAGIC	9
579fffb55fSDavid Gibson 	/* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
589fffb55fSDavid Gibson 	 * device tree at all - it is missing the flattened device
599fffb55fSDavid Gibson 	 * tree magic number. */
609fffb55fSDavid Gibson #define FDT_ERR_BADVERSION	10
619fffb55fSDavid Gibson 	/* FDT_ERR_BADVERSION: Given device tree has a version which
629fffb55fSDavid Gibson 	 * can't be handled by the requested operation.  For
639fffb55fSDavid Gibson 	 * read-write functions, this may mean that fdt_open_into() is
649fffb55fSDavid Gibson 	 * required to convert the tree to the expected version. */
659fffb55fSDavid Gibson #define FDT_ERR_BADSTRUCTURE	11
669fffb55fSDavid Gibson 	/* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
679fffb55fSDavid Gibson 	 * structure block or other serious error (e.g. misnested
689fffb55fSDavid Gibson 	 * nodes, or subnodes preceding properties). */
699fffb55fSDavid Gibson #define FDT_ERR_BADLAYOUT	12
709fffb55fSDavid Gibson 	/* FDT_ERR_BADLAYOUT: For read-write functions, the given
719fffb55fSDavid Gibson 	 * device tree has it's sub-blocks in an order that the
729fffb55fSDavid Gibson 	 * function can't handle (memory reserve map, then structure,
739fffb55fSDavid Gibson 	 * then strings).  Use fdt_open_into() to reorganize the tree
749fffb55fSDavid Gibson 	 * into a form suitable for the read-write operations. */
759fffb55fSDavid Gibson 
769fffb55fSDavid Gibson /* "Can't happen" error indicating a bug in libfdt */
779fffb55fSDavid Gibson #define FDT_ERR_INTERNAL	13
789fffb55fSDavid Gibson 	/* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
799fffb55fSDavid Gibson 	 * Should never be returned, if it is, it indicates a bug in
809fffb55fSDavid Gibson 	 * libfdt itself. */
819fffb55fSDavid Gibson 
8247605971SRob Herring /* Errors in device tree content */
8347605971SRob Herring #define FDT_ERR_BADNCELLS	14
8447605971SRob Herring 	/* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
8547605971SRob Herring 	 * or similar property with a bad format or value */
8647605971SRob Herring 
8791feabc2SRob Herring #define FDT_ERR_BADVALUE	15
8891feabc2SRob Herring 	/* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
8991feabc2SRob Herring 	 * value. For example: a property expected to contain a string list
9091feabc2SRob Herring 	 * is not NUL-terminated within the length of its value. */
9191feabc2SRob Herring 
926f05afcbSRob Herring #define FDT_ERR_BADOVERLAY	16
936f05afcbSRob Herring 	/* FDT_ERR_BADOVERLAY: The device tree overlay, while
946f05afcbSRob Herring 	 * correctly structured, cannot be applied due to some
956f05afcbSRob Herring 	 * unexpected or missing value, property or node. */
966f05afcbSRob Herring 
976f05afcbSRob Herring #define FDT_ERR_NOPHANDLES	17
986f05afcbSRob Herring 	/* FDT_ERR_NOPHANDLES: The device tree doesn't have any
996f05afcbSRob Herring 	 * phandle available anymore without causing an overflow */
1006f05afcbSRob Herring 
1019bb9c6a1SRob Herring #define FDT_ERR_BADFLAGS	18
1029bb9c6a1SRob Herring 	/* FDT_ERR_BADFLAGS: The function was passed a flags field that
1039bb9c6a1SRob Herring 	 * contains invalid flags or an invalid combination of flags. */
1049bb9c6a1SRob Herring 
10579edff12SRob Herring #define FDT_ERR_ALIGNMENT	19
10679edff12SRob Herring 	/* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte
10779edff12SRob Herring 	 * aligned. */
10879edff12SRob Herring 
10979edff12SRob Herring #define FDT_ERR_MAX		19
1109bb9c6a1SRob Herring 
1119bb9c6a1SRob Herring /* constants */
1129bb9c6a1SRob Herring #define FDT_MAX_PHANDLE 0xfffffffe
1139bb9c6a1SRob Herring 	/* Valid values for phandles range from 1 to 2^32-2. */
1149fffb55fSDavid Gibson 
1159fffb55fSDavid Gibson /**********************************************************************/
1169fffb55fSDavid Gibson /* Low-level functions (you probably don't need these)                */
1179fffb55fSDavid Gibson /**********************************************************************/
1189fffb55fSDavid Gibson 
11989d12310SRob Herring #ifndef SWIG /* This function is not useful in Python */
120cd296721SStephen Warren const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
12189d12310SRob Herring #endif
fdt_offset_ptr_w(void * fdt,int offset,int checklen)1229fffb55fSDavid Gibson static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
1239fffb55fSDavid Gibson {
1249fffb55fSDavid Gibson 	return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
1259fffb55fSDavid Gibson }
1269fffb55fSDavid Gibson 
1279fffb55fSDavid Gibson uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
1289fffb55fSDavid Gibson 
129f858927fSRob Herring /*
13079edff12SRob Herring  * External helpers to access words from a device tree blob. They're built
13179edff12SRob Herring  * to work even with unaligned pointers on platforms (such as ARMv5) that don't
13279edff12SRob Herring  * like unaligned loads and stores.
133f858927fSRob Herring  */
fdt16_ld(const fdt16_t * p)134a77725a9SRob Herring static inline uint16_t fdt16_ld(const fdt16_t *p)
135a77725a9SRob Herring {
136a77725a9SRob Herring 	const uint8_t *bp = (const uint8_t *)p;
137a77725a9SRob Herring 
138a77725a9SRob Herring 	return ((uint16_t)bp[0] << 8) | bp[1];
139a77725a9SRob Herring }
140a77725a9SRob Herring 
fdt32_ld(const fdt32_t * p)141f858927fSRob Herring static inline uint32_t fdt32_ld(const fdt32_t *p)
142f858927fSRob Herring {
143c2e7075cSRob Herring 	const uint8_t *bp = (const uint8_t *)p;
144f858927fSRob Herring 
145c2e7075cSRob Herring 	return ((uint32_t)bp[0] << 24)
146c2e7075cSRob Herring 		| ((uint32_t)bp[1] << 16)
147c2e7075cSRob Herring 		| ((uint32_t)bp[2] << 8)
148c2e7075cSRob Herring 		| bp[3];
149f858927fSRob Herring }
150f858927fSRob Herring 
fdt32_st(void * property,uint32_t value)1519bb9c6a1SRob Herring static inline void fdt32_st(void *property, uint32_t value)
1529bb9c6a1SRob Herring {
1530cec114eSRob Herring 	uint8_t *bp = (uint8_t *)property;
1549bb9c6a1SRob Herring 
1559bb9c6a1SRob Herring 	bp[0] = value >> 24;
1569bb9c6a1SRob Herring 	bp[1] = (value >> 16) & 0xff;
1579bb9c6a1SRob Herring 	bp[2] = (value >> 8) & 0xff;
1589bb9c6a1SRob Herring 	bp[3] = value & 0xff;
1599bb9c6a1SRob Herring }
1609bb9c6a1SRob Herring 
fdt64_ld(const fdt64_t * p)161f858927fSRob Herring static inline uint64_t fdt64_ld(const fdt64_t *p)
162f858927fSRob Herring {
163c2e7075cSRob Herring 	const uint8_t *bp = (const uint8_t *)p;
164f858927fSRob Herring 
165c2e7075cSRob Herring 	return ((uint64_t)bp[0] << 56)
166c2e7075cSRob Herring 		| ((uint64_t)bp[1] << 48)
167c2e7075cSRob Herring 		| ((uint64_t)bp[2] << 40)
168c2e7075cSRob Herring 		| ((uint64_t)bp[3] << 32)
169c2e7075cSRob Herring 		| ((uint64_t)bp[4] << 24)
170c2e7075cSRob Herring 		| ((uint64_t)bp[5] << 16)
171c2e7075cSRob Herring 		| ((uint64_t)bp[6] << 8)
172c2e7075cSRob Herring 		| bp[7];
173f858927fSRob Herring }
174f858927fSRob Herring 
fdt64_st(void * property,uint64_t value)1759bb9c6a1SRob Herring static inline void fdt64_st(void *property, uint64_t value)
1769bb9c6a1SRob Herring {
1770cec114eSRob Herring 	uint8_t *bp = (uint8_t *)property;
1789bb9c6a1SRob Herring 
1799bb9c6a1SRob Herring 	bp[0] = value >> 56;
1809bb9c6a1SRob Herring 	bp[1] = (value >> 48) & 0xff;
1819bb9c6a1SRob Herring 	bp[2] = (value >> 40) & 0xff;
1829bb9c6a1SRob Herring 	bp[3] = (value >> 32) & 0xff;
1839bb9c6a1SRob Herring 	bp[4] = (value >> 24) & 0xff;
1849bb9c6a1SRob Herring 	bp[5] = (value >> 16) & 0xff;
1859bb9c6a1SRob Herring 	bp[6] = (value >> 8) & 0xff;
1869bb9c6a1SRob Herring 	bp[7] = value & 0xff;
1879bb9c6a1SRob Herring }
1889bb9c6a1SRob Herring 
1899fffb55fSDavid Gibson /**********************************************************************/
1909fffb55fSDavid Gibson /* Traversal functions                                                */
1919fffb55fSDavid Gibson /**********************************************************************/
1929fffb55fSDavid Gibson 
1939fffb55fSDavid Gibson int fdt_next_node(const void *fdt, int offset, int *depth);
1949fffb55fSDavid Gibson 
19547605971SRob Herring /**
19647605971SRob Herring  * fdt_first_subnode() - get offset of first direct subnode
19747605971SRob Herring  * @fdt:	FDT blob
19847605971SRob Herring  * @offset:	Offset of node to check
19979edff12SRob Herring  *
20079edff12SRob Herring  * Return: offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
20147605971SRob Herring  */
20247605971SRob Herring int fdt_first_subnode(const void *fdt, int offset);
20347605971SRob Herring 
20447605971SRob Herring /**
20547605971SRob Herring  * fdt_next_subnode() - get offset of next direct subnode
20679edff12SRob Herring  * @fdt:	FDT blob
20779edff12SRob Herring  * @offset:	Offset of previous subnode
20847605971SRob Herring  *
20947605971SRob Herring  * After first calling fdt_first_subnode(), call this function repeatedly to
21047605971SRob Herring  * get direct subnodes of a parent node.
21147605971SRob Herring  *
21279edff12SRob Herring  * Return: offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
21347605971SRob Herring  *         subnodes
21447605971SRob Herring  */
21547605971SRob Herring int fdt_next_subnode(const void *fdt, int offset);
21647605971SRob Herring 
2176f05afcbSRob Herring /**
2186f05afcbSRob Herring  * fdt_for_each_subnode - iterate over all subnodes of a parent
2196f05afcbSRob Herring  *
2206f05afcbSRob Herring  * @node:	child node (int, lvalue)
2216f05afcbSRob Herring  * @fdt:	FDT blob (const void *)
2226f05afcbSRob Herring  * @parent:	parent node (int)
2236f05afcbSRob Herring  *
2246f05afcbSRob Herring  * This is actually a wrapper around a for loop and would be used like so:
2256f05afcbSRob Herring  *
2266f05afcbSRob Herring  *	fdt_for_each_subnode(node, fdt, parent) {
2276f05afcbSRob Herring  *		Use node
2286f05afcbSRob Herring  *		...
2296f05afcbSRob Herring  *	}
2306f05afcbSRob Herring  *
2319bb9c6a1SRob Herring  *	if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
2326f05afcbSRob Herring  *		Error handling
2336f05afcbSRob Herring  *	}
2346f05afcbSRob Herring  *
2356f05afcbSRob Herring  * Note that this is implemented as a macro and @node is used as
2366f05afcbSRob Herring  * iterator in the loop. The parent variable be constant or even a
2376f05afcbSRob Herring  * literal.
2386f05afcbSRob Herring  */
2396f05afcbSRob Herring #define fdt_for_each_subnode(node, fdt, parent)		\
2406f05afcbSRob Herring 	for (node = fdt_first_subnode(fdt, parent);	\
2416f05afcbSRob Herring 	     node >= 0;					\
2426f05afcbSRob Herring 	     node = fdt_next_subnode(fdt, node))
2436f05afcbSRob Herring 
2449fffb55fSDavid Gibson /**********************************************************************/
2459fffb55fSDavid Gibson /* General functions                                                  */
2469fffb55fSDavid Gibson /**********************************************************************/
2479fffb55fSDavid Gibson #define fdt_get_header(fdt, field) \
248f858927fSRob Herring 	(fdt32_ld(&((const struct fdt_header *)(fdt))->field))
2499fffb55fSDavid Gibson #define fdt_magic(fdt)			(fdt_get_header(fdt, magic))
2509fffb55fSDavid Gibson #define fdt_totalsize(fdt)		(fdt_get_header(fdt, totalsize))
2519fffb55fSDavid Gibson #define fdt_off_dt_struct(fdt)		(fdt_get_header(fdt, off_dt_struct))
2529fffb55fSDavid Gibson #define fdt_off_dt_strings(fdt)		(fdt_get_header(fdt, off_dt_strings))
2539fffb55fSDavid Gibson #define fdt_off_mem_rsvmap(fdt)		(fdt_get_header(fdt, off_mem_rsvmap))
2549fffb55fSDavid Gibson #define fdt_version(fdt)		(fdt_get_header(fdt, version))
2559fffb55fSDavid Gibson #define fdt_last_comp_version(fdt)	(fdt_get_header(fdt, last_comp_version))
2569fffb55fSDavid Gibson #define fdt_boot_cpuid_phys(fdt)	(fdt_get_header(fdt, boot_cpuid_phys))
2579fffb55fSDavid Gibson #define fdt_size_dt_strings(fdt)	(fdt_get_header(fdt, size_dt_strings))
2589fffb55fSDavid Gibson #define fdt_size_dt_struct(fdt)		(fdt_get_header(fdt, size_dt_struct))
2599fffb55fSDavid Gibson 
2609130ba88SRob Herring #define fdt_set_hdr_(name) \
2619fffb55fSDavid Gibson 	static inline void fdt_set_##name(void *fdt, uint32_t val) \
2629fffb55fSDavid Gibson 	{ \
263cd296721SStephen Warren 		struct fdt_header *fdth = (struct fdt_header *)fdt; \
2649fffb55fSDavid Gibson 		fdth->name = cpu_to_fdt32(val); \
2659fffb55fSDavid Gibson 	}
2669130ba88SRob Herring fdt_set_hdr_(magic);
2679130ba88SRob Herring fdt_set_hdr_(totalsize);
2689130ba88SRob Herring fdt_set_hdr_(off_dt_struct);
2699130ba88SRob Herring fdt_set_hdr_(off_dt_strings);
2709130ba88SRob Herring fdt_set_hdr_(off_mem_rsvmap);
2719130ba88SRob Herring fdt_set_hdr_(version);
2729130ba88SRob Herring fdt_set_hdr_(last_comp_version);
2739130ba88SRob Herring fdt_set_hdr_(boot_cpuid_phys);
2749130ba88SRob Herring fdt_set_hdr_(size_dt_strings);
2759130ba88SRob Herring fdt_set_hdr_(size_dt_struct);
2769130ba88SRob Herring #undef fdt_set_hdr_
2779fffb55fSDavid Gibson 
2789fffb55fSDavid Gibson /**
279f858927fSRob Herring  * fdt_header_size - return the size of the tree's header
280f858927fSRob Herring  * @fdt: pointer to a flattened device tree
28179edff12SRob Herring  *
28279edff12SRob Herring  * Return: size of DTB header in bytes
283f858927fSRob Herring  */
284d047cd8aSRob Herring size_t fdt_header_size(const void *fdt);
285d047cd8aSRob Herring 
286d047cd8aSRob Herring /**
28779edff12SRob Herring  * fdt_header_size_ - internal function to get header size from a version number
28879edff12SRob Herring  * @version: devicetree version number
28979edff12SRob Herring  *
29079edff12SRob Herring  * Return: size of DTB header in bytes
291d047cd8aSRob Herring  */
292f858927fSRob Herring size_t fdt_header_size_(uint32_t version);
293f858927fSRob Herring 
294f858927fSRob Herring /**
295f858927fSRob Herring  * fdt_check_header - sanity check a device tree header
2969fffb55fSDavid Gibson  * @fdt: pointer to data which might be a flattened device tree
2979fffb55fSDavid Gibson  *
2989fffb55fSDavid Gibson  * fdt_check_header() checks that the given buffer contains what
299f858927fSRob Herring  * appears to be a flattened device tree, and that the header contains
300f858927fSRob Herring  * valid information (to the extent that can be determined from the
301f858927fSRob Herring  * header alone).
3029fffb55fSDavid Gibson  *
3039fffb55fSDavid Gibson  * returns:
3049fffb55fSDavid Gibson  *     0, if the buffer appears to contain a valid device tree
3059fffb55fSDavid Gibson  *     -FDT_ERR_BADMAGIC,
3069fffb55fSDavid Gibson  *     -FDT_ERR_BADVERSION,
307f858927fSRob Herring  *     -FDT_ERR_BADSTATE,
308f858927fSRob Herring  *     -FDT_ERR_TRUNCATED, standard meanings, as above
3099fffb55fSDavid Gibson  */
3109fffb55fSDavid Gibson int fdt_check_header(const void *fdt);
3119fffb55fSDavid Gibson 
3129fffb55fSDavid Gibson /**
3139fffb55fSDavid Gibson  * fdt_move - move a device tree around in memory
3149fffb55fSDavid Gibson  * @fdt: pointer to the device tree to move
3159fffb55fSDavid Gibson  * @buf: pointer to memory where the device is to be moved
3169fffb55fSDavid Gibson  * @bufsize: size of the memory space at buf
3179fffb55fSDavid Gibson  *
3189fffb55fSDavid Gibson  * fdt_move() relocates, if possible, the device tree blob located at
3199fffb55fSDavid Gibson  * fdt to the buffer at buf of size bufsize.  The buffer may overlap
3209fffb55fSDavid Gibson  * with the existing device tree blob at fdt.  Therefore,
3219fffb55fSDavid Gibson  *     fdt_move(fdt, fdt, fdt_totalsize(fdt))
3229fffb55fSDavid Gibson  * should always succeed.
3239fffb55fSDavid Gibson  *
3249fffb55fSDavid Gibson  * returns:
3259fffb55fSDavid Gibson  *     0, on success
3269fffb55fSDavid Gibson  *     -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
3279fffb55fSDavid Gibson  *     -FDT_ERR_BADMAGIC,
3289fffb55fSDavid Gibson  *     -FDT_ERR_BADVERSION,
3299fffb55fSDavid Gibson  *     -FDT_ERR_BADSTATE, standard meanings
3309fffb55fSDavid Gibson  */
3319fffb55fSDavid Gibson int fdt_move(const void *fdt, void *buf, int bufsize);
3329fffb55fSDavid Gibson 
3339fffb55fSDavid Gibson /**********************************************************************/
3349fffb55fSDavid Gibson /* Read-only functions                                                */
3359fffb55fSDavid Gibson /**********************************************************************/
3369fffb55fSDavid Gibson 
337f858927fSRob Herring int fdt_check_full(const void *fdt, size_t bufsize);
338f858927fSRob Herring 
339f858927fSRob Herring /**
340f858927fSRob Herring  * fdt_get_string - retrieve a string from the strings block of a device tree
341f858927fSRob Herring  * @fdt: pointer to the device tree blob
342f858927fSRob Herring  * @stroffset: offset of the string within the strings block (native endian)
343f858927fSRob Herring  * @lenp: optional pointer to return the string's length
344f858927fSRob Herring  *
345f858927fSRob Herring  * fdt_get_string() retrieves a pointer to a single string from the
346f858927fSRob Herring  * strings block of the device tree blob at fdt, and optionally also
347f858927fSRob Herring  * returns the string's length in *lenp.
348f858927fSRob Herring  *
349f858927fSRob Herring  * returns:
350f858927fSRob Herring  *     a pointer to the string, on success
351f858927fSRob Herring  *     NULL, if stroffset is out of bounds, or doesn't point to a valid string
352f858927fSRob Herring  */
353f858927fSRob Herring const char *fdt_get_string(const void *fdt, int stroffset, int *lenp);
354f858927fSRob Herring 
3559fffb55fSDavid Gibson /**
3569fffb55fSDavid Gibson  * fdt_string - retrieve a string from the strings block of a device tree
3579fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
3589fffb55fSDavid Gibson  * @stroffset: offset of the string within the strings block (native endian)
3599fffb55fSDavid Gibson  *
3609fffb55fSDavid Gibson  * fdt_string() retrieves a pointer to a single string from the
3619fffb55fSDavid Gibson  * strings block of the device tree blob at fdt.
3629fffb55fSDavid Gibson  *
3639fffb55fSDavid Gibson  * returns:
3649fffb55fSDavid Gibson  *     a pointer to the string, on success
365f858927fSRob Herring  *     NULL, if stroffset is out of bounds, or doesn't point to a valid string
3669fffb55fSDavid Gibson  */
3679fffb55fSDavid Gibson const char *fdt_string(const void *fdt, int stroffset);
3689fffb55fSDavid Gibson 
3699fffb55fSDavid Gibson /**
3709bb9c6a1SRob Herring  * fdt_find_max_phandle - find and return the highest phandle in a tree
3719bb9c6a1SRob Herring  * @fdt: pointer to the device tree blob
3729bb9c6a1SRob Herring  * @phandle: return location for the highest phandle value found in the tree
3739bb9c6a1SRob Herring  *
3749bb9c6a1SRob Herring  * fdt_find_max_phandle() finds the highest phandle value in the given device
3759bb9c6a1SRob Herring  * tree. The value returned in @phandle is only valid if the function returns
3769bb9c6a1SRob Herring  * success.
3779bb9c6a1SRob Herring  *
3789bb9c6a1SRob Herring  * returns:
3799bb9c6a1SRob Herring  *     0 on success or a negative error code on failure
3809bb9c6a1SRob Herring  */
3819bb9c6a1SRob Herring int fdt_find_max_phandle(const void *fdt, uint32_t *phandle);
3829bb9c6a1SRob Herring 
3839bb9c6a1SRob Herring /**
3846f05afcbSRob Herring  * fdt_get_max_phandle - retrieves the highest phandle in a tree
3856f05afcbSRob Herring  * @fdt: pointer to the device tree blob
3866f05afcbSRob Herring  *
3876f05afcbSRob Herring  * fdt_get_max_phandle retrieves the highest phandle in the given
3886f05afcbSRob Herring  * device tree. This will ignore badly formatted phandles, or phandles
3896f05afcbSRob Herring  * with a value of 0 or -1.
3906f05afcbSRob Herring  *
3919bb9c6a1SRob Herring  * This function is deprecated in favour of fdt_find_max_phandle().
3929bb9c6a1SRob Herring  *
3936f05afcbSRob Herring  * returns:
3946f05afcbSRob Herring  *      the highest phandle on success
3956f05afcbSRob Herring  *      0, if no phandle was found in the device tree
3966f05afcbSRob Herring  *      -1, if an error occurred
3976f05afcbSRob Herring  */
fdt_get_max_phandle(const void * fdt)3989bb9c6a1SRob Herring static inline uint32_t fdt_get_max_phandle(const void *fdt)
3999bb9c6a1SRob Herring {
4009bb9c6a1SRob Herring 	uint32_t phandle;
4019bb9c6a1SRob Herring 	int err;
4029bb9c6a1SRob Herring 
4039bb9c6a1SRob Herring 	err = fdt_find_max_phandle(fdt, &phandle);
4049bb9c6a1SRob Herring 	if (err < 0)
4059bb9c6a1SRob Herring 		return (uint32_t)-1;
4069bb9c6a1SRob Herring 
4079bb9c6a1SRob Herring 	return phandle;
4089bb9c6a1SRob Herring }
4099bb9c6a1SRob Herring 
4109bb9c6a1SRob Herring /**
4119bb9c6a1SRob Herring  * fdt_generate_phandle - return a new, unused phandle for a device tree blob
4129bb9c6a1SRob Herring  * @fdt: pointer to the device tree blob
4139bb9c6a1SRob Herring  * @phandle: return location for the new phandle
4149bb9c6a1SRob Herring  *
4159bb9c6a1SRob Herring  * Walks the device tree blob and looks for the highest phandle value. On
4169bb9c6a1SRob Herring  * success, the new, unused phandle value (one higher than the previously
4179bb9c6a1SRob Herring  * highest phandle value in the device tree blob) will be returned in the
4189bb9c6a1SRob Herring  * @phandle parameter.
4199bb9c6a1SRob Herring  *
42079edff12SRob Herring  * Return: 0 on success or a negative error-code on failure
4219bb9c6a1SRob Herring  */
4229bb9c6a1SRob Herring int fdt_generate_phandle(const void *fdt, uint32_t *phandle);
4236f05afcbSRob Herring 
4246f05afcbSRob Herring /**
4259fffb55fSDavid Gibson  * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
4269fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
4279fffb55fSDavid Gibson  *
4289fffb55fSDavid Gibson  * Returns the number of entries in the device tree blob's memory
4299fffb55fSDavid Gibson  * reservation map.  This does not include the terminating 0,0 entry
4309fffb55fSDavid Gibson  * or any other (0,0) entries reserved for expansion.
4319fffb55fSDavid Gibson  *
4329fffb55fSDavid Gibson  * returns:
4339fffb55fSDavid Gibson  *     the number of entries
4349fffb55fSDavid Gibson  */
4359fffb55fSDavid Gibson int fdt_num_mem_rsv(const void *fdt);
4369fffb55fSDavid Gibson 
4379fffb55fSDavid Gibson /**
4389fffb55fSDavid Gibson  * fdt_get_mem_rsv - retrieve one memory reserve map entry
4399fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
44079edff12SRob Herring  * @n: index of reserve map entry
44179edff12SRob Herring  * @address: pointer to 64-bit variable to hold the start address
44279edff12SRob Herring  * @size: pointer to 64-bit variable to hold the size of the entry
4439fffb55fSDavid Gibson  *
44479edff12SRob Herring  * On success, @address and @size will contain the address and size of
4459fffb55fSDavid Gibson  * the n-th reserve map entry from the device tree blob, in
4469fffb55fSDavid Gibson  * native-endian format.
4479fffb55fSDavid Gibson  *
4489fffb55fSDavid Gibson  * returns:
4499fffb55fSDavid Gibson  *     0, on success
4509fffb55fSDavid Gibson  *     -FDT_ERR_BADMAGIC,
4519fffb55fSDavid Gibson  *     -FDT_ERR_BADVERSION,
4529fffb55fSDavid Gibson  *     -FDT_ERR_BADSTATE, standard meanings
4539fffb55fSDavid Gibson  */
4549fffb55fSDavid Gibson int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
4559fffb55fSDavid Gibson 
4569fffb55fSDavid Gibson /**
4579fffb55fSDavid Gibson  * fdt_subnode_offset_namelen - find a subnode based on substring
4589fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
4599fffb55fSDavid Gibson  * @parentoffset: structure block offset of a node
4609fffb55fSDavid Gibson  * @name: name of the subnode to locate
4619fffb55fSDavid Gibson  * @namelen: number of characters of name to consider
4629fffb55fSDavid Gibson  *
4639fffb55fSDavid Gibson  * Identical to fdt_subnode_offset(), but only examine the first
4649fffb55fSDavid Gibson  * namelen characters of name for matching the subnode name.  This is
4659fffb55fSDavid Gibson  * useful for finding subnodes based on a portion of a larger string,
4669fffb55fSDavid Gibson  * such as a full path.
46779edff12SRob Herring  *
46879edff12SRob Herring  * Return: offset of the subnode or -FDT_ERR_NOTFOUND if name not found.
4699fffb55fSDavid Gibson  */
47089d12310SRob Herring #ifndef SWIG /* Not available in Python */
4719fffb55fSDavid Gibson int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
4729fffb55fSDavid Gibson 			       const char *name, int namelen);
47389d12310SRob Herring #endif
4749fffb55fSDavid Gibson /**
4759fffb55fSDavid Gibson  * fdt_subnode_offset - find a subnode of a given node
4769fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
4779fffb55fSDavid Gibson  * @parentoffset: structure block offset of a node
4789fffb55fSDavid Gibson  * @name: name of the subnode to locate
4799fffb55fSDavid Gibson  *
4809fffb55fSDavid Gibson  * fdt_subnode_offset() finds a subnode of the node at structure block
4819fffb55fSDavid Gibson  * offset parentoffset with the given name.  name may include a unit
4829fffb55fSDavid Gibson  * address, in which case fdt_subnode_offset() will find the subnode
4839fffb55fSDavid Gibson  * with that unit address, or the unit address may be omitted, in
4849fffb55fSDavid Gibson  * which case fdt_subnode_offset() will find an arbitrary subnode
4859fffb55fSDavid Gibson  * whose name excluding unit address matches the given name.
4869fffb55fSDavid Gibson  *
4879fffb55fSDavid Gibson  * returns:
4889fffb55fSDavid Gibson  *	structure block offset of the requested subnode (>=0), on success
4899fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
4906f05afcbSRob Herring  *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
4916f05afcbSRob Herring  *		tag
4929fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
4939fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
4949fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
4959fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
4969fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings.
4979fffb55fSDavid Gibson  */
4989fffb55fSDavid Gibson int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
4999fffb55fSDavid Gibson 
5009fffb55fSDavid Gibson /**
50147605971SRob Herring  * fdt_path_offset_namelen - find a tree node by its full path
50247605971SRob Herring  * @fdt: pointer to the device tree blob
50347605971SRob Herring  * @path: full path of the node to locate
50447605971SRob Herring  * @namelen: number of characters of path to consider
50547605971SRob Herring  *
50647605971SRob Herring  * Identical to fdt_path_offset(), but only consider the first namelen
50747605971SRob Herring  * characters of path as the path name.
50879edff12SRob Herring  *
50979edff12SRob Herring  * Return: offset of the node or negative libfdt error value otherwise
51047605971SRob Herring  */
51189d12310SRob Herring #ifndef SWIG /* Not available in Python */
51247605971SRob Herring int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
51389d12310SRob Herring #endif
51447605971SRob Herring 
51547605971SRob Herring /**
5169fffb55fSDavid Gibson  * fdt_path_offset - find a tree node by its full path
5179fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
5189fffb55fSDavid Gibson  * @path: full path of the node to locate
5199fffb55fSDavid Gibson  *
5209fffb55fSDavid Gibson  * fdt_path_offset() finds a node of a given path in the device tree.
5219fffb55fSDavid Gibson  * Each path component may omit the unit address portion, but the
5229fffb55fSDavid Gibson  * results of this are undefined if any such path component is
5239fffb55fSDavid Gibson  * ambiguous (that is if there are multiple nodes at the relevant
5249fffb55fSDavid Gibson  * level matching the given component, differentiated only by unit
5259fffb55fSDavid Gibson  * address).
5269fffb55fSDavid Gibson  *
5279fffb55fSDavid Gibson  * returns:
5286f05afcbSRob Herring  *	structure block offset of the node with the requested path (>=0), on
5296f05afcbSRob Herring  *		success
5309fffb55fSDavid Gibson  *	-FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
5319fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, if the requested node does not exist
5329fffb55fSDavid Gibson  *      -FDT_ERR_BADMAGIC,
5339fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
5349fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
5359fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
5369fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings.
5379fffb55fSDavid Gibson  */
5389fffb55fSDavid Gibson int fdt_path_offset(const void *fdt, const char *path);
5399fffb55fSDavid Gibson 
5409fffb55fSDavid Gibson /**
5419fffb55fSDavid Gibson  * fdt_get_name - retrieve the name of a given node
5429fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
5439fffb55fSDavid Gibson  * @nodeoffset: structure block offset of the starting node
5449fffb55fSDavid Gibson  * @lenp: pointer to an integer variable (will be overwritten) or NULL
5459fffb55fSDavid Gibson  *
5469fffb55fSDavid Gibson  * fdt_get_name() retrieves the name (including unit address) of the
5479fffb55fSDavid Gibson  * device tree node at structure block offset nodeoffset.  If lenp is
5489fffb55fSDavid Gibson  * non-NULL, the length of this name is also returned, in the integer
5499fffb55fSDavid Gibson  * pointed to by lenp.
5509fffb55fSDavid Gibson  *
5519fffb55fSDavid Gibson  * returns:
5529fffb55fSDavid Gibson  *	pointer to the node's name, on success
5536f05afcbSRob Herring  *		If lenp is non-NULL, *lenp contains the length of that name
5546f05afcbSRob Herring  *			(>=0)
5559fffb55fSDavid Gibson  *	NULL, on error
5569fffb55fSDavid Gibson  *		if lenp is non-NULL *lenp contains an error code (<0):
5576f05afcbSRob Herring  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
5586f05afcbSRob Herring  *			tag
5599fffb55fSDavid Gibson  *		-FDT_ERR_BADMAGIC,
5609fffb55fSDavid Gibson  *		-FDT_ERR_BADVERSION,
5619fffb55fSDavid Gibson  *		-FDT_ERR_BADSTATE, standard meanings
5629fffb55fSDavid Gibson  */
5639fffb55fSDavid Gibson const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
5649fffb55fSDavid Gibson 
5659fffb55fSDavid Gibson /**
566cd296721SStephen Warren  * fdt_first_property_offset - find the offset of a node's first property
567cd296721SStephen Warren  * @fdt: pointer to the device tree blob
568cd296721SStephen Warren  * @nodeoffset: structure block offset of a node
569cd296721SStephen Warren  *
570cd296721SStephen Warren  * fdt_first_property_offset() finds the first property of the node at
571cd296721SStephen Warren  * the given structure block offset.
572cd296721SStephen Warren  *
573cd296721SStephen Warren  * returns:
574cd296721SStephen Warren  *	structure block offset of the property (>=0), on success
575cd296721SStephen Warren  *	-FDT_ERR_NOTFOUND, if the requested node has no properties
576cd296721SStephen Warren  *	-FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
577cd296721SStephen Warren  *      -FDT_ERR_BADMAGIC,
578cd296721SStephen Warren  *	-FDT_ERR_BADVERSION,
579cd296721SStephen Warren  *	-FDT_ERR_BADSTATE,
580cd296721SStephen Warren  *	-FDT_ERR_BADSTRUCTURE,
581cd296721SStephen Warren  *	-FDT_ERR_TRUNCATED, standard meanings.
582cd296721SStephen Warren  */
583cd296721SStephen Warren int fdt_first_property_offset(const void *fdt, int nodeoffset);
584cd296721SStephen Warren 
585cd296721SStephen Warren /**
586cd296721SStephen Warren  * fdt_next_property_offset - step through a node's properties
587cd296721SStephen Warren  * @fdt: pointer to the device tree blob
588cd296721SStephen Warren  * @offset: structure block offset of a property
589cd296721SStephen Warren  *
590cd296721SStephen Warren  * fdt_next_property_offset() finds the property immediately after the
591cd296721SStephen Warren  * one at the given structure block offset.  This will be a property
592cd296721SStephen Warren  * of the same node as the given property.
593cd296721SStephen Warren  *
594cd296721SStephen Warren  * returns:
595cd296721SStephen Warren  *	structure block offset of the next property (>=0), on success
596cd296721SStephen Warren  *	-FDT_ERR_NOTFOUND, if the given property is the last in its node
597cd296721SStephen Warren  *	-FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
598cd296721SStephen Warren  *      -FDT_ERR_BADMAGIC,
599cd296721SStephen Warren  *	-FDT_ERR_BADVERSION,
600cd296721SStephen Warren  *	-FDT_ERR_BADSTATE,
601cd296721SStephen Warren  *	-FDT_ERR_BADSTRUCTURE,
602cd296721SStephen Warren  *	-FDT_ERR_TRUNCATED, standard meanings.
603cd296721SStephen Warren  */
604cd296721SStephen Warren int fdt_next_property_offset(const void *fdt, int offset);
605cd296721SStephen Warren 
606cd296721SStephen Warren /**
6076f05afcbSRob Herring  * fdt_for_each_property_offset - iterate over all properties of a node
6086f05afcbSRob Herring  *
60979edff12SRob Herring  * @property:	property offset (int, lvalue)
6106f05afcbSRob Herring  * @fdt:	FDT blob (const void *)
6116f05afcbSRob Herring  * @node:	node offset (int)
6126f05afcbSRob Herring  *
6136f05afcbSRob Herring  * This is actually a wrapper around a for loop and would be used like so:
6146f05afcbSRob Herring  *
6156f05afcbSRob Herring  *	fdt_for_each_property_offset(property, fdt, node) {
6166f05afcbSRob Herring  *		Use property
6176f05afcbSRob Herring  *		...
6186f05afcbSRob Herring  *	}
6196f05afcbSRob Herring  *
6209bb9c6a1SRob Herring  *	if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) {
6216f05afcbSRob Herring  *		Error handling
6226f05afcbSRob Herring  *	}
6236f05afcbSRob Herring  *
6246f05afcbSRob Herring  * Note that this is implemented as a macro and property is used as
6256f05afcbSRob Herring  * iterator in the loop. The node variable can be constant or even a
6266f05afcbSRob Herring  * literal.
6276f05afcbSRob Herring  */
6286f05afcbSRob Herring #define fdt_for_each_property_offset(property, fdt, node)	\
6296f05afcbSRob Herring 	for (property = fdt_first_property_offset(fdt, node);	\
6306f05afcbSRob Herring 	     property >= 0;					\
6316f05afcbSRob Herring 	     property = fdt_next_property_offset(fdt, property))
6326f05afcbSRob Herring 
6336f05afcbSRob Herring /**
634cd296721SStephen Warren  * fdt_get_property_by_offset - retrieve the property at a given offset
635cd296721SStephen Warren  * @fdt: pointer to the device tree blob
636cd296721SStephen Warren  * @offset: offset of the property to retrieve
637cd296721SStephen Warren  * @lenp: pointer to an integer variable (will be overwritten) or NULL
638cd296721SStephen Warren  *
639cd296721SStephen Warren  * fdt_get_property_by_offset() retrieves a pointer to the
640cd296721SStephen Warren  * fdt_property structure within the device tree blob at the given
641cd296721SStephen Warren  * offset.  If lenp is non-NULL, the length of the property value is
642cd296721SStephen Warren  * also returned, in the integer pointed to by lenp.
643cd296721SStephen Warren  *
6449130ba88SRob Herring  * Note that this code only works on device tree versions >= 16. fdt_getprop()
6459130ba88SRob Herring  * works on all versions.
6469130ba88SRob Herring  *
647cd296721SStephen Warren  * returns:
648cd296721SStephen Warren  *	pointer to the structure representing the property
649cd296721SStephen Warren  *		if lenp is non-NULL, *lenp contains the length of the property
650cd296721SStephen Warren  *		value (>=0)
651cd296721SStephen Warren  *	NULL, on error
652cd296721SStephen Warren  *		if lenp is non-NULL, *lenp contains an error code (<0):
653cd296721SStephen Warren  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
654cd296721SStephen Warren  *		-FDT_ERR_BADMAGIC,
655cd296721SStephen Warren  *		-FDT_ERR_BADVERSION,
656cd296721SStephen Warren  *		-FDT_ERR_BADSTATE,
657cd296721SStephen Warren  *		-FDT_ERR_BADSTRUCTURE,
658cd296721SStephen Warren  *		-FDT_ERR_TRUNCATED, standard meanings
659cd296721SStephen Warren  */
660cd296721SStephen Warren const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
661cd296721SStephen Warren 						      int offset,
662cd296721SStephen Warren 						      int *lenp);
fdt_get_property_by_offset_w(void * fdt,int offset,int * lenp)663*ea3723a5SRob Herring static inline struct fdt_property *fdt_get_property_by_offset_w(void *fdt,
664*ea3723a5SRob Herring 								int offset,
665*ea3723a5SRob Herring 								int *lenp)
666*ea3723a5SRob Herring {
667*ea3723a5SRob Herring 	return (struct fdt_property *)(uintptr_t)
668*ea3723a5SRob Herring 		fdt_get_property_by_offset(fdt, offset, lenp);
669*ea3723a5SRob Herring }
670cd296721SStephen Warren 
671cd296721SStephen Warren /**
672cd296721SStephen Warren  * fdt_get_property_namelen - find a property based on substring
673cd296721SStephen Warren  * @fdt: pointer to the device tree blob
674cd296721SStephen Warren  * @nodeoffset: offset of the node whose property to find
675cd296721SStephen Warren  * @name: name of the property to find
676cd296721SStephen Warren  * @namelen: number of characters of name to consider
677cd296721SStephen Warren  * @lenp: pointer to an integer variable (will be overwritten) or NULL
678cd296721SStephen Warren  *
67991feabc2SRob Herring  * Identical to fdt_get_property(), but only examine the first namelen
68091feabc2SRob Herring  * characters of name for matching the property name.
68179edff12SRob Herring  *
68279edff12SRob Herring  * Return: pointer to the structure representing the property, or NULL
68379edff12SRob Herring  *         if not found
684cd296721SStephen Warren  */
68589d12310SRob Herring #ifndef SWIG /* Not available in Python */
686cd296721SStephen Warren const struct fdt_property *fdt_get_property_namelen(const void *fdt,
687cd296721SStephen Warren 						    int nodeoffset,
688cd296721SStephen Warren 						    const char *name,
689cd296721SStephen Warren 						    int namelen, int *lenp);
69089d12310SRob Herring #endif
691cd296721SStephen Warren 
692cd296721SStephen Warren /**
6939fffb55fSDavid Gibson  * fdt_get_property - find a given property in a given node
6949fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
6959fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose property to find
6969fffb55fSDavid Gibson  * @name: name of the property to find
6979fffb55fSDavid Gibson  * @lenp: pointer to an integer variable (will be overwritten) or NULL
6989fffb55fSDavid Gibson  *
6999fffb55fSDavid Gibson  * fdt_get_property() retrieves a pointer to the fdt_property
7009fffb55fSDavid Gibson  * structure within the device tree blob corresponding to the property
7019fffb55fSDavid Gibson  * named 'name' of the node at offset nodeoffset.  If lenp is
7029fffb55fSDavid Gibson  * non-NULL, the length of the property value is also returned, in the
7039fffb55fSDavid Gibson  * integer pointed to by lenp.
7049fffb55fSDavid Gibson  *
7059fffb55fSDavid Gibson  * returns:
7069fffb55fSDavid Gibson  *	pointer to the structure representing the property
7079fffb55fSDavid Gibson  *		if lenp is non-NULL, *lenp contains the length of the property
7089fffb55fSDavid Gibson  *		value (>=0)
7099fffb55fSDavid Gibson  *	NULL, on error
7109fffb55fSDavid Gibson  *		if lenp is non-NULL, *lenp contains an error code (<0):
7119fffb55fSDavid Gibson  *		-FDT_ERR_NOTFOUND, node does not have named property
7126f05afcbSRob Herring  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
7136f05afcbSRob Herring  *			tag
7149fffb55fSDavid Gibson  *		-FDT_ERR_BADMAGIC,
7159fffb55fSDavid Gibson  *		-FDT_ERR_BADVERSION,
7169fffb55fSDavid Gibson  *		-FDT_ERR_BADSTATE,
7179fffb55fSDavid Gibson  *		-FDT_ERR_BADSTRUCTURE,
7189fffb55fSDavid Gibson  *		-FDT_ERR_TRUNCATED, standard meanings
7199fffb55fSDavid Gibson  */
7209fffb55fSDavid Gibson const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
7219fffb55fSDavid Gibson 					    const char *name, int *lenp);
fdt_get_property_w(void * fdt,int nodeoffset,const char * name,int * lenp)7229fffb55fSDavid Gibson static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
7239fffb55fSDavid Gibson 						      const char *name,
7249fffb55fSDavid Gibson 						      int *lenp)
7259fffb55fSDavid Gibson {
7269fffb55fSDavid Gibson 	return (struct fdt_property *)(uintptr_t)
7279fffb55fSDavid Gibson 		fdt_get_property(fdt, nodeoffset, name, lenp);
7289fffb55fSDavid Gibson }
7299fffb55fSDavid Gibson 
7309fffb55fSDavid Gibson /**
731cd296721SStephen Warren  * fdt_getprop_by_offset - retrieve the value of a property at a given offset
732cd296721SStephen Warren  * @fdt: pointer to the device tree blob
7339bb9c6a1SRob Herring  * @offset: offset of the property to read
734cd296721SStephen Warren  * @namep: pointer to a string variable (will be overwritten) or NULL
735cd296721SStephen Warren  * @lenp: pointer to an integer variable (will be overwritten) or NULL
736cd296721SStephen Warren  *
737cd296721SStephen Warren  * fdt_getprop_by_offset() retrieves a pointer to the value of the
738cd296721SStephen Warren  * property at structure block offset 'offset' (this will be a pointer
739cd296721SStephen Warren  * to within the device blob itself, not a copy of the value).  If
740cd296721SStephen Warren  * lenp is non-NULL, the length of the property value is also
741cd296721SStephen Warren  * returned, in the integer pointed to by lenp.  If namep is non-NULL,
742cd296721SStephen Warren  * the property's namne will also be returned in the char * pointed to
743cd296721SStephen Warren  * by namep (this will be a pointer to within the device tree's string
744cd296721SStephen Warren  * block, not a new copy of the name).
745cd296721SStephen Warren  *
746cd296721SStephen Warren  * returns:
747cd296721SStephen Warren  *	pointer to the property's value
748cd296721SStephen Warren  *		if lenp is non-NULL, *lenp contains the length of the property
749cd296721SStephen Warren  *		value (>=0)
750cd296721SStephen Warren  *		if namep is non-NULL *namep contiains a pointer to the property
751cd296721SStephen Warren  *		name.
752cd296721SStephen Warren  *	NULL, on error
753cd296721SStephen Warren  *		if lenp is non-NULL, *lenp contains an error code (<0):
754cd296721SStephen Warren  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
755cd296721SStephen Warren  *		-FDT_ERR_BADMAGIC,
756cd296721SStephen Warren  *		-FDT_ERR_BADVERSION,
757cd296721SStephen Warren  *		-FDT_ERR_BADSTATE,
758cd296721SStephen Warren  *		-FDT_ERR_BADSTRUCTURE,
759cd296721SStephen Warren  *		-FDT_ERR_TRUNCATED, standard meanings
760cd296721SStephen Warren  */
76189d12310SRob Herring #ifndef SWIG /* This function is not useful in Python */
762cd296721SStephen Warren const void *fdt_getprop_by_offset(const void *fdt, int offset,
763cd296721SStephen Warren 				  const char **namep, int *lenp);
76489d12310SRob Herring #endif
765cd296721SStephen Warren 
766cd296721SStephen Warren /**
767cd296721SStephen Warren  * fdt_getprop_namelen - get property value based on substring
768cd296721SStephen Warren  * @fdt: pointer to the device tree blob
769cd296721SStephen Warren  * @nodeoffset: offset of the node whose property to find
770cd296721SStephen Warren  * @name: name of the property to find
771cd296721SStephen Warren  * @namelen: number of characters of name to consider
772cd296721SStephen Warren  * @lenp: pointer to an integer variable (will be overwritten) or NULL
773cd296721SStephen Warren  *
774cd296721SStephen Warren  * Identical to fdt_getprop(), but only examine the first namelen
775cd296721SStephen Warren  * characters of name for matching the property name.
77679edff12SRob Herring  *
77779edff12SRob Herring  * Return: pointer to the property's value or NULL on error
778cd296721SStephen Warren  */
77989d12310SRob Herring #ifndef SWIG /* Not available in Python */
780cd296721SStephen Warren const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
781cd296721SStephen Warren 				const char *name, int namelen, int *lenp);
fdt_getprop_namelen_w(void * fdt,int nodeoffset,const char * name,int namelen,int * lenp)7826f05afcbSRob Herring static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
7836f05afcbSRob Herring 					  const char *name, int namelen,
7846f05afcbSRob Herring 					  int *lenp)
7856f05afcbSRob Herring {
7866f05afcbSRob Herring 	return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
7876f05afcbSRob Herring 						      namelen, lenp);
7886f05afcbSRob Herring }
78989d12310SRob Herring #endif
790cd296721SStephen Warren 
791cd296721SStephen Warren /**
7929fffb55fSDavid Gibson  * fdt_getprop - retrieve the value of a given property
7939fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
7949fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose property to find
7959fffb55fSDavid Gibson  * @name: name of the property to find
7969fffb55fSDavid Gibson  * @lenp: pointer to an integer variable (will be overwritten) or NULL
7979fffb55fSDavid Gibson  *
7989fffb55fSDavid Gibson  * fdt_getprop() retrieves a pointer to the value of the property
79979edff12SRob Herring  * named @name of the node at offset @nodeoffset (this will be a
8009fffb55fSDavid Gibson  * pointer to within the device blob itself, not a copy of the value).
80179edff12SRob Herring  * If @lenp is non-NULL, the length of the property value is also
80279edff12SRob Herring  * returned, in the integer pointed to by @lenp.
8039fffb55fSDavid Gibson  *
8049fffb55fSDavid Gibson  * returns:
8059fffb55fSDavid Gibson  *	pointer to the property's value
8069fffb55fSDavid Gibson  *		if lenp is non-NULL, *lenp contains the length of the property
8079fffb55fSDavid Gibson  *		value (>=0)
8089fffb55fSDavid Gibson  *	NULL, on error
8099fffb55fSDavid Gibson  *		if lenp is non-NULL, *lenp contains an error code (<0):
8109fffb55fSDavid Gibson  *		-FDT_ERR_NOTFOUND, node does not have named property
8116f05afcbSRob Herring  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
8126f05afcbSRob Herring  *			tag
8139fffb55fSDavid Gibson  *		-FDT_ERR_BADMAGIC,
8149fffb55fSDavid Gibson  *		-FDT_ERR_BADVERSION,
8159fffb55fSDavid Gibson  *		-FDT_ERR_BADSTATE,
8169fffb55fSDavid Gibson  *		-FDT_ERR_BADSTRUCTURE,
8179fffb55fSDavid Gibson  *		-FDT_ERR_TRUNCATED, standard meanings
8189fffb55fSDavid Gibson  */
8199fffb55fSDavid Gibson const void *fdt_getprop(const void *fdt, int nodeoffset,
8209fffb55fSDavid Gibson 			const char *name, int *lenp);
fdt_getprop_w(void * fdt,int nodeoffset,const char * name,int * lenp)8219fffb55fSDavid Gibson static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
8229fffb55fSDavid Gibson 				  const char *name, int *lenp)
8239fffb55fSDavid Gibson {
8249fffb55fSDavid Gibson 	return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
8259fffb55fSDavid Gibson }
8269fffb55fSDavid Gibson 
8279fffb55fSDavid Gibson /**
8289fffb55fSDavid Gibson  * fdt_get_phandle - retrieve the phandle of a given node
8299fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
8309fffb55fSDavid Gibson  * @nodeoffset: structure block offset of the node
8319fffb55fSDavid Gibson  *
8329fffb55fSDavid Gibson  * fdt_get_phandle() retrieves the phandle of the device tree node at
8339fffb55fSDavid Gibson  * structure block offset nodeoffset.
8349fffb55fSDavid Gibson  *
8359fffb55fSDavid Gibson  * returns:
8369fffb55fSDavid Gibson  *	the phandle of the node at nodeoffset, on success (!= 0, != -1)
8379fffb55fSDavid Gibson  *	0, if the node has no phandle, or another error occurs
8389fffb55fSDavid Gibson  */
8399fffb55fSDavid Gibson uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
8409fffb55fSDavid Gibson 
8419fffb55fSDavid Gibson /**
842cd296721SStephen Warren  * fdt_get_alias_namelen - get alias based on substring
843cd296721SStephen Warren  * @fdt: pointer to the device tree blob
844cd296721SStephen Warren  * @name: name of the alias th look up
845cd296721SStephen Warren  * @namelen: number of characters of name to consider
846cd296721SStephen Warren  *
84779edff12SRob Herring  * Identical to fdt_get_alias(), but only examine the first @namelen
84879edff12SRob Herring  * characters of @name for matching the alias name.
84979edff12SRob Herring  *
85079edff12SRob Herring  * Return: a pointer to the expansion of the alias named @name, if it exists,
85179edff12SRob Herring  *	   NULL otherwise
852cd296721SStephen Warren  */
85389d12310SRob Herring #ifndef SWIG /* Not available in Python */
854cd296721SStephen Warren const char *fdt_get_alias_namelen(const void *fdt,
855cd296721SStephen Warren 				  const char *name, int namelen);
85689d12310SRob Herring #endif
857cd296721SStephen Warren 
858cd296721SStephen Warren /**
8596f05afcbSRob Herring  * fdt_get_alias - retrieve the path referenced by a given alias
860cd296721SStephen Warren  * @fdt: pointer to the device tree blob
861cd296721SStephen Warren  * @name: name of the alias th look up
862cd296721SStephen Warren  *
863cd296721SStephen Warren  * fdt_get_alias() retrieves the value of a given alias.  That is, the
86479edff12SRob Herring  * value of the property named @name in the node /aliases.
865cd296721SStephen Warren  *
866cd296721SStephen Warren  * returns:
86747605971SRob Herring  *	a pointer to the expansion of the alias named 'name', if it exists
868cd296721SStephen Warren  *	NULL, if the given alias or the /aliases node does not exist
869cd296721SStephen Warren  */
870cd296721SStephen Warren const char *fdt_get_alias(const void *fdt, const char *name);
871cd296721SStephen Warren 
872cd296721SStephen Warren /**
8739fffb55fSDavid Gibson  * fdt_get_path - determine the full path of a node
8749fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
8759fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose path to find
8769fffb55fSDavid Gibson  * @buf: character buffer to contain the returned path (will be overwritten)
8779fffb55fSDavid Gibson  * @buflen: size of the character buffer at buf
8789fffb55fSDavid Gibson  *
8799fffb55fSDavid Gibson  * fdt_get_path() computes the full path of the node at offset
8809fffb55fSDavid Gibson  * nodeoffset, and records that path in the buffer at buf.
8819fffb55fSDavid Gibson  *
8829fffb55fSDavid Gibson  * NOTE: This function is expensive, as it must scan the device tree
8839fffb55fSDavid Gibson  * structure from the start to nodeoffset.
8849fffb55fSDavid Gibson  *
8859fffb55fSDavid Gibson  * returns:
8869fffb55fSDavid Gibson  *	0, on success
8879fffb55fSDavid Gibson  *		buf contains the absolute path of the node at
8889fffb55fSDavid Gibson  *		nodeoffset, as a NUL-terminated string.
8899fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
8909fffb55fSDavid Gibson  *	-FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
8919fffb55fSDavid Gibson  *		characters and will not fit in the given buffer.
8929fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
8939fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
8949fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
8959fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE, standard meanings
8969fffb55fSDavid Gibson  */
8979fffb55fSDavid Gibson int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
8989fffb55fSDavid Gibson 
8999fffb55fSDavid Gibson /**
9009fffb55fSDavid Gibson  * fdt_supernode_atdepth_offset - find a specific ancestor of a node
9019fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
9029fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose parent to find
9039fffb55fSDavid Gibson  * @supernodedepth: depth of the ancestor to find
9049fffb55fSDavid Gibson  * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
9059fffb55fSDavid Gibson  *
9069fffb55fSDavid Gibson  * fdt_supernode_atdepth_offset() finds an ancestor of the given node
9079fffb55fSDavid Gibson  * at a specific depth from the root (where the root itself has depth
9089fffb55fSDavid Gibson  * 0, its immediate subnodes depth 1 and so forth).  So
9099fffb55fSDavid Gibson  *	fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
9109fffb55fSDavid Gibson  * will always return 0, the offset of the root node.  If the node at
9119fffb55fSDavid Gibson  * nodeoffset has depth D, then:
9129fffb55fSDavid Gibson  *	fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
9139fffb55fSDavid Gibson  * will return nodeoffset itself.
9149fffb55fSDavid Gibson  *
9159fffb55fSDavid Gibson  * NOTE: This function is expensive, as it must scan the device tree
9169fffb55fSDavid Gibson  * structure from the start to nodeoffset.
9179fffb55fSDavid Gibson  *
9189fffb55fSDavid Gibson  * returns:
9199fffb55fSDavid Gibson  *	structure block offset of the node at node offset's ancestor
9209fffb55fSDavid Gibson  *		of depth supernodedepth (>=0), on success
9219fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
9226f05afcbSRob Herring  *	-FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
9236f05afcbSRob Herring  *		nodeoffset
9249fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
9259fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
9269fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
9279fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE, standard meanings
9289fffb55fSDavid Gibson  */
9299fffb55fSDavid Gibson int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
9309fffb55fSDavid Gibson 				 int supernodedepth, int *nodedepth);
9319fffb55fSDavid Gibson 
9329fffb55fSDavid Gibson /**
9339fffb55fSDavid Gibson  * fdt_node_depth - find the depth of a given node
9349fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
9359fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose parent to find
9369fffb55fSDavid Gibson  *
9379fffb55fSDavid Gibson  * fdt_node_depth() finds the depth of a given node.  The root node
9389fffb55fSDavid Gibson  * has depth 0, its immediate subnodes depth 1 and so forth.
9399fffb55fSDavid Gibson  *
9409fffb55fSDavid Gibson  * NOTE: This function is expensive, as it must scan the device tree
9419fffb55fSDavid Gibson  * structure from the start to nodeoffset.
9429fffb55fSDavid Gibson  *
9439fffb55fSDavid Gibson  * returns:
9449fffb55fSDavid Gibson  *	depth of the node at nodeoffset (>=0), on success
9459fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
9469fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
9479fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
9489fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
9499fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE, standard meanings
9509fffb55fSDavid Gibson  */
9519fffb55fSDavid Gibson int fdt_node_depth(const void *fdt, int nodeoffset);
9529fffb55fSDavid Gibson 
9539fffb55fSDavid Gibson /**
9549fffb55fSDavid Gibson  * fdt_parent_offset - find the parent of a given node
9559fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
9569fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose parent to find
9579fffb55fSDavid Gibson  *
9589fffb55fSDavid Gibson  * fdt_parent_offset() locates the parent node of a given node (that
9599fffb55fSDavid Gibson  * is, it finds the offset of the node which contains the node at
9609fffb55fSDavid Gibson  * nodeoffset as a subnode).
9619fffb55fSDavid Gibson  *
9629fffb55fSDavid Gibson  * NOTE: This function is expensive, as it must scan the device tree
9639fffb55fSDavid Gibson  * structure from the start to nodeoffset, *twice*.
9649fffb55fSDavid Gibson  *
9659fffb55fSDavid Gibson  * returns:
9669fffb55fSDavid Gibson  *	structure block offset of the parent of the node at nodeoffset
9679fffb55fSDavid Gibson  *		(>=0), on success
9689fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
9699fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
9709fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
9719fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
9729fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE, standard meanings
9739fffb55fSDavid Gibson  */
9749fffb55fSDavid Gibson int fdt_parent_offset(const void *fdt, int nodeoffset);
9759fffb55fSDavid Gibson 
9769fffb55fSDavid Gibson /**
9779fffb55fSDavid Gibson  * fdt_node_offset_by_prop_value - find nodes with a given property value
9789fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
9799fffb55fSDavid Gibson  * @startoffset: only find nodes after this offset
9809fffb55fSDavid Gibson  * @propname: property name to check
9819fffb55fSDavid Gibson  * @propval: property value to search for
9829fffb55fSDavid Gibson  * @proplen: length of the value in propval
9839fffb55fSDavid Gibson  *
9849fffb55fSDavid Gibson  * fdt_node_offset_by_prop_value() returns the offset of the first
9859fffb55fSDavid Gibson  * node after startoffset, which has a property named propname whose
9869fffb55fSDavid Gibson  * value is of length proplen and has value equal to propval; or if
9879fffb55fSDavid Gibson  * startoffset is -1, the very first such node in the tree.
9889fffb55fSDavid Gibson  *
9899fffb55fSDavid Gibson  * To iterate through all nodes matching the criterion, the following
9909fffb55fSDavid Gibson  * idiom can be used:
9919fffb55fSDavid Gibson  *	offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
9929fffb55fSDavid Gibson  *					       propval, proplen);
9939fffb55fSDavid Gibson  *	while (offset != -FDT_ERR_NOTFOUND) {
9949fffb55fSDavid Gibson  *		// other code here
9959fffb55fSDavid Gibson  *		offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
9969fffb55fSDavid Gibson  *						       propval, proplen);
9979fffb55fSDavid Gibson  *	}
9989fffb55fSDavid Gibson  *
9999fffb55fSDavid Gibson  * Note the -1 in the first call to the function, if 0 is used here
10009fffb55fSDavid Gibson  * instead, the function will never locate the root node, even if it
10019fffb55fSDavid Gibson  * matches the criterion.
10029fffb55fSDavid Gibson  *
10039fffb55fSDavid Gibson  * returns:
10049fffb55fSDavid Gibson  *	structure block offset of the located node (>= 0, >startoffset),
10059fffb55fSDavid Gibson  *		 on success
10069fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, no node matching the criterion exists in the
10079fffb55fSDavid Gibson  *		tree after startoffset
10089fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
10099fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
10109fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
10119fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
10129fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE, standard meanings
10139fffb55fSDavid Gibson  */
10149fffb55fSDavid Gibson int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
10159fffb55fSDavid Gibson 				  const char *propname,
10169fffb55fSDavid Gibson 				  const void *propval, int proplen);
10179fffb55fSDavid Gibson 
10189fffb55fSDavid Gibson /**
10199fffb55fSDavid Gibson  * fdt_node_offset_by_phandle - find the node with a given phandle
10209fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
10219fffb55fSDavid Gibson  * @phandle: phandle value
10229fffb55fSDavid Gibson  *
10239fffb55fSDavid Gibson  * fdt_node_offset_by_phandle() returns the offset of the node
10249fffb55fSDavid Gibson  * which has the given phandle value.  If there is more than one node
10259fffb55fSDavid Gibson  * in the tree with the given phandle (an invalid tree), results are
10269fffb55fSDavid Gibson  * undefined.
10279fffb55fSDavid Gibson  *
10289fffb55fSDavid Gibson  * returns:
10299fffb55fSDavid Gibson  *	structure block offset of the located node (>= 0), on success
10309fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, no node with that phandle exists
10319fffb55fSDavid Gibson  *	-FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
10329fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
10339fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
10349fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
10359fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE, standard meanings
10369fffb55fSDavid Gibson  */
10379fffb55fSDavid Gibson int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
10389fffb55fSDavid Gibson 
10399fffb55fSDavid Gibson /**
104079edff12SRob Herring  * fdt_node_check_compatible - check a node's compatible property
10419fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
10429fffb55fSDavid Gibson  * @nodeoffset: offset of a tree node
10439fffb55fSDavid Gibson  * @compatible: string to match against
10449fffb55fSDavid Gibson  *
10459fffb55fSDavid Gibson  * fdt_node_check_compatible() returns 0 if the given node contains a
104679edff12SRob Herring  * @compatible property with the given string as one of its elements,
10479fffb55fSDavid Gibson  * it returns non-zero otherwise, or on error.
10489fffb55fSDavid Gibson  *
10499fffb55fSDavid Gibson  * returns:
10509fffb55fSDavid Gibson  *	0, if the node has a 'compatible' property listing the given string
10519fffb55fSDavid Gibson  *	1, if the node has a 'compatible' property, but it does not list
10529fffb55fSDavid Gibson  *		the given string
10539fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
10549fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
10559fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
10569fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
10579fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
10589fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE, standard meanings
10599fffb55fSDavid Gibson  */
10609fffb55fSDavid Gibson int fdt_node_check_compatible(const void *fdt, int nodeoffset,
10619fffb55fSDavid Gibson 			      const char *compatible);
10629fffb55fSDavid Gibson 
10639fffb55fSDavid Gibson /**
10649fffb55fSDavid Gibson  * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
10659fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
10669fffb55fSDavid Gibson  * @startoffset: only find nodes after this offset
10679fffb55fSDavid Gibson  * @compatible: 'compatible' string to match against
10689fffb55fSDavid Gibson  *
10699fffb55fSDavid Gibson  * fdt_node_offset_by_compatible() returns the offset of the first
10709fffb55fSDavid Gibson  * node after startoffset, which has a 'compatible' property which
10719fffb55fSDavid Gibson  * lists the given compatible string; or if startoffset is -1, the
10729fffb55fSDavid Gibson  * very first such node in the tree.
10739fffb55fSDavid Gibson  *
10749fffb55fSDavid Gibson  * To iterate through all nodes matching the criterion, the following
10759fffb55fSDavid Gibson  * idiom can be used:
10769fffb55fSDavid Gibson  *	offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
10779fffb55fSDavid Gibson  *	while (offset != -FDT_ERR_NOTFOUND) {
10789fffb55fSDavid Gibson  *		// other code here
10799fffb55fSDavid Gibson  *		offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
10809fffb55fSDavid Gibson  *	}
10819fffb55fSDavid Gibson  *
10829fffb55fSDavid Gibson  * Note the -1 in the first call to the function, if 0 is used here
10839fffb55fSDavid Gibson  * instead, the function will never locate the root node, even if it
10849fffb55fSDavid Gibson  * matches the criterion.
10859fffb55fSDavid Gibson  *
10869fffb55fSDavid Gibson  * returns:
10879fffb55fSDavid Gibson  *	structure block offset of the located node (>= 0, >startoffset),
10889fffb55fSDavid Gibson  *		 on success
10899fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, no node matching the criterion exists in the
10909fffb55fSDavid Gibson  *		tree after startoffset
10919fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
10929fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
10939fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
10949fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
10959fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE, standard meanings
10969fffb55fSDavid Gibson  */
10979fffb55fSDavid Gibson int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
10989fffb55fSDavid Gibson 				  const char *compatible);
10999fffb55fSDavid Gibson 
110047605971SRob Herring /**
110147605971SRob Herring  * fdt_stringlist_contains - check a string list property for a string
110247605971SRob Herring  * @strlist: Property containing a list of strings to check
110347605971SRob Herring  * @listlen: Length of property
110447605971SRob Herring  * @str: String to search for
110547605971SRob Herring  *
110647605971SRob Herring  * This is a utility function provided for convenience. The list contains
110747605971SRob Herring  * one or more strings, each terminated by \0, as is found in a device tree
110847605971SRob Herring  * "compatible" property.
110947605971SRob Herring  *
111079edff12SRob Herring  * Return: 1 if the string is found in the list, 0 not found, or invalid list
111147605971SRob Herring  */
111247605971SRob Herring int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
111347605971SRob Herring 
111491feabc2SRob Herring /**
111591feabc2SRob Herring  * fdt_stringlist_count - count the number of strings in a string list
111691feabc2SRob Herring  * @fdt: pointer to the device tree blob
111791feabc2SRob Herring  * @nodeoffset: offset of a tree node
111891feabc2SRob Herring  * @property: name of the property containing the string list
111979edff12SRob Herring  *
112079edff12SRob Herring  * Return:
112191feabc2SRob Herring  *   the number of strings in the given property
112291feabc2SRob Herring  *   -FDT_ERR_BADVALUE if the property value is not NUL-terminated
112391feabc2SRob Herring  *   -FDT_ERR_NOTFOUND if the property does not exist
112491feabc2SRob Herring  */
112591feabc2SRob Herring int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
112691feabc2SRob Herring 
112791feabc2SRob Herring /**
112891feabc2SRob Herring  * fdt_stringlist_search - find a string in a string list and return its index
112991feabc2SRob Herring  * @fdt: pointer to the device tree blob
113091feabc2SRob Herring  * @nodeoffset: offset of a tree node
113191feabc2SRob Herring  * @property: name of the property containing the string list
113291feabc2SRob Herring  * @string: string to look up in the string list
113391feabc2SRob Herring  *
113491feabc2SRob Herring  * Note that it is possible for this function to succeed on property values
113591feabc2SRob Herring  * that are not NUL-terminated. That's because the function will stop after
113691feabc2SRob Herring  * finding the first occurrence of @string. This can for example happen with
113791feabc2SRob Herring  * small-valued cell properties, such as #address-cells, when searching for
113891feabc2SRob Herring  * the empty string.
113991feabc2SRob Herring  *
114079edff12SRob Herring  * return:
114191feabc2SRob Herring  *   the index of the string in the list of strings
114291feabc2SRob Herring  *   -FDT_ERR_BADVALUE if the property value is not NUL-terminated
114391feabc2SRob Herring  *   -FDT_ERR_NOTFOUND if the property does not exist or does not contain
114491feabc2SRob Herring  *                     the given string
114591feabc2SRob Herring  */
114691feabc2SRob Herring int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
114791feabc2SRob Herring 			  const char *string);
114891feabc2SRob Herring 
114991feabc2SRob Herring /**
115091feabc2SRob Herring  * fdt_stringlist_get() - obtain the string at a given index in a string list
115191feabc2SRob Herring  * @fdt: pointer to the device tree blob
115291feabc2SRob Herring  * @nodeoffset: offset of a tree node
115391feabc2SRob Herring  * @property: name of the property containing the string list
115491feabc2SRob Herring  * @index: index of the string to return
115591feabc2SRob Herring  * @lenp: return location for the string length or an error code on failure
115691feabc2SRob Herring  *
115791feabc2SRob Herring  * Note that this will successfully extract strings from properties with
115891feabc2SRob Herring  * non-NUL-terminated values. For example on small-valued cell properties
115991feabc2SRob Herring  * this function will return the empty string.
116091feabc2SRob Herring  *
116191feabc2SRob Herring  * If non-NULL, the length of the string (on success) or a negative error-code
116291feabc2SRob Herring  * (on failure) will be stored in the integer pointer to by lenp.
116391feabc2SRob Herring  *
116479edff12SRob Herring  * Return:
116591feabc2SRob Herring  *   A pointer to the string at the given index in the string list or NULL on
116691feabc2SRob Herring  *   failure. On success the length of the string will be stored in the memory
116791feabc2SRob Herring  *   location pointed to by the lenp parameter, if non-NULL. On failure one of
116891feabc2SRob Herring  *   the following negative error codes will be returned in the lenp parameter
116991feabc2SRob Herring  *   (if non-NULL):
117091feabc2SRob Herring  *     -FDT_ERR_BADVALUE if the property value is not NUL-terminated
117191feabc2SRob Herring  *     -FDT_ERR_NOTFOUND if the property does not exist
117291feabc2SRob Herring  */
117391feabc2SRob Herring const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
117491feabc2SRob Herring 			       const char *property, int index,
117591feabc2SRob Herring 			       int *lenp);
117691feabc2SRob Herring 
117747605971SRob Herring /**********************************************************************/
117847605971SRob Herring /* Read-only functions (addressing related)                           */
117947605971SRob Herring /**********************************************************************/
118047605971SRob Herring 
118147605971SRob Herring /**
118247605971SRob Herring  * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
118347605971SRob Herring  *
118447605971SRob Herring  * This is the maximum value for #address-cells, #size-cells and
118547605971SRob Herring  * similar properties that will be processed by libfdt.  IEE1275
118647605971SRob Herring  * requires that OF implementations handle values up to 4.
118747605971SRob Herring  * Implementations may support larger values, but in practice higher
118847605971SRob Herring  * values aren't used.
118947605971SRob Herring  */
119047605971SRob Herring #define FDT_MAX_NCELLS		4
119147605971SRob Herring 
119247605971SRob Herring /**
119347605971SRob Herring  * fdt_address_cells - retrieve address size for a bus represented in the tree
119447605971SRob Herring  * @fdt: pointer to the device tree blob
119547605971SRob Herring  * @nodeoffset: offset of the node to find the address size for
119647605971SRob Herring  *
119747605971SRob Herring  * When the node has a valid #address-cells property, returns its value.
119847605971SRob Herring  *
119947605971SRob Herring  * returns:
120047605971SRob Herring  *	0 <= n < FDT_MAX_NCELLS, on success
120147605971SRob Herring  *      2, if the node has no #address-cells property
12026f05afcbSRob Herring  *      -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
12036f05afcbSRob Herring  *		#address-cells property
120447605971SRob Herring  *	-FDT_ERR_BADMAGIC,
120547605971SRob Herring  *	-FDT_ERR_BADVERSION,
120647605971SRob Herring  *	-FDT_ERR_BADSTATE,
120747605971SRob Herring  *	-FDT_ERR_BADSTRUCTURE,
120847605971SRob Herring  *	-FDT_ERR_TRUNCATED, standard meanings
120947605971SRob Herring  */
121047605971SRob Herring int fdt_address_cells(const void *fdt, int nodeoffset);
121147605971SRob Herring 
121247605971SRob Herring /**
121347605971SRob Herring  * fdt_size_cells - retrieve address range size for a bus represented in the
121447605971SRob Herring  *                  tree
121547605971SRob Herring  * @fdt: pointer to the device tree blob
121647605971SRob Herring  * @nodeoffset: offset of the node to find the address range size for
121747605971SRob Herring  *
121847605971SRob Herring  * When the node has a valid #size-cells property, returns its value.
121947605971SRob Herring  *
122047605971SRob Herring  * returns:
122147605971SRob Herring  *	0 <= n < FDT_MAX_NCELLS, on success
1222c2e7075cSRob Herring  *      1, if the node has no #size-cells property
12236f05afcbSRob Herring  *      -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
12246f05afcbSRob Herring  *		#size-cells property
122547605971SRob Herring  *	-FDT_ERR_BADMAGIC,
122647605971SRob Herring  *	-FDT_ERR_BADVERSION,
122747605971SRob Herring  *	-FDT_ERR_BADSTATE,
122847605971SRob Herring  *	-FDT_ERR_BADSTRUCTURE,
122947605971SRob Herring  *	-FDT_ERR_TRUNCATED, standard meanings
123047605971SRob Herring  */
123147605971SRob Herring int fdt_size_cells(const void *fdt, int nodeoffset);
123247605971SRob Herring 
123347605971SRob Herring 
12349fffb55fSDavid Gibson /**********************************************************************/
12359fffb55fSDavid Gibson /* Write-in-place functions                                           */
12369fffb55fSDavid Gibson /**********************************************************************/
12379fffb55fSDavid Gibson 
12389fffb55fSDavid Gibson /**
12396f05afcbSRob Herring  * fdt_setprop_inplace_namelen_partial - change a property's value,
12406f05afcbSRob Herring  *                                       but not its size
12416f05afcbSRob Herring  * @fdt: pointer to the device tree blob
12426f05afcbSRob Herring  * @nodeoffset: offset of the node whose property to change
12436f05afcbSRob Herring  * @name: name of the property to change
12446f05afcbSRob Herring  * @namelen: number of characters of name to consider
12456f05afcbSRob Herring  * @idx: index of the property to change in the array
12466f05afcbSRob Herring  * @val: pointer to data to replace the property value with
12476f05afcbSRob Herring  * @len: length of the property value
12486f05afcbSRob Herring  *
12496f05afcbSRob Herring  * Identical to fdt_setprop_inplace(), but modifies the given property
12506f05afcbSRob Herring  * starting from the given index, and using only the first characters
12516f05afcbSRob Herring  * of the name. It is useful when you want to manipulate only one value of
12526f05afcbSRob Herring  * an array and you have a string that doesn't end with \0.
125379edff12SRob Herring  *
125479edff12SRob Herring  * Return: 0 on success, negative libfdt error value otherwise
12556f05afcbSRob Herring  */
125689d12310SRob Herring #ifndef SWIG /* Not available in Python */
12576f05afcbSRob Herring int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
12586f05afcbSRob Herring 					const char *name, int namelen,
12596f05afcbSRob Herring 					uint32_t idx, const void *val,
12606f05afcbSRob Herring 					int len);
126189d12310SRob Herring #endif
12626f05afcbSRob Herring 
12636f05afcbSRob Herring /**
12649fffb55fSDavid Gibson  * fdt_setprop_inplace - change a property's value, but not its size
12659fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
12669fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose property to change
12679fffb55fSDavid Gibson  * @name: name of the property to change
12689fffb55fSDavid Gibson  * @val: pointer to data to replace the property value with
12699fffb55fSDavid Gibson  * @len: length of the property value
12709fffb55fSDavid Gibson  *
12719fffb55fSDavid Gibson  * fdt_setprop_inplace() replaces the value of a given property with
12729fffb55fSDavid Gibson  * the data in val, of length len.  This function cannot change the
12739fffb55fSDavid Gibson  * size of a property, and so will only work if len is equal to the
12749fffb55fSDavid Gibson  * current length of the property.
12759fffb55fSDavid Gibson  *
12769fffb55fSDavid Gibson  * This function will alter only the bytes in the blob which contain
12779fffb55fSDavid Gibson  * the given property value, and will not alter or move any other part
12789fffb55fSDavid Gibson  * of the tree.
12799fffb55fSDavid Gibson  *
12809fffb55fSDavid Gibson  * returns:
12819fffb55fSDavid Gibson  *	0, on success
12829fffb55fSDavid Gibson  *	-FDT_ERR_NOSPACE, if len is not equal to the property's current length
12839fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, node does not have the named property
12849fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
12859fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
12869fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
12879fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
12889fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
12899fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
12909fffb55fSDavid Gibson  */
129189d12310SRob Herring #ifndef SWIG /* Not available in Python */
12929fffb55fSDavid Gibson int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
12939fffb55fSDavid Gibson 			const void *val, int len);
129489d12310SRob Herring #endif
12959fffb55fSDavid Gibson 
12969fffb55fSDavid Gibson /**
1297cd296721SStephen Warren  * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
12989fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
12999fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose property to change
13009fffb55fSDavid Gibson  * @name: name of the property to change
1301cd296721SStephen Warren  * @val: 32-bit integer value to replace the property with
13029fffb55fSDavid Gibson  *
1303cd296721SStephen Warren  * fdt_setprop_inplace_u32() replaces the value of a given property
1304cd296721SStephen Warren  * with the 32-bit integer value in val, converting val to big-endian
1305cd296721SStephen Warren  * if necessary.  This function cannot change the size of a property,
1306cd296721SStephen Warren  * and so will only work if the property already exists and has length
1307cd296721SStephen Warren  * 4.
13089fffb55fSDavid Gibson  *
13099fffb55fSDavid Gibson  * This function will alter only the bytes in the blob which contain
13109fffb55fSDavid Gibson  * the given property value, and will not alter or move any other part
13119fffb55fSDavid Gibson  * of the tree.
13129fffb55fSDavid Gibson  *
13139fffb55fSDavid Gibson  * returns:
13149fffb55fSDavid Gibson  *	0, on success
13159fffb55fSDavid Gibson  *	-FDT_ERR_NOSPACE, if the property's length is not equal to 4
13169fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, node does not have the named property
13179fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
13189fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
13199fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
13209fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
13219fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
13229fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
13239fffb55fSDavid Gibson  */
fdt_setprop_inplace_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)1324cd296721SStephen Warren static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
13259fffb55fSDavid Gibson 					  const char *name, uint32_t val)
13269fffb55fSDavid Gibson {
132747605971SRob Herring 	fdt32_t tmp = cpu_to_fdt32(val);
132847605971SRob Herring 	return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
13299fffb55fSDavid Gibson }
13309fffb55fSDavid Gibson 
13319fffb55fSDavid Gibson /**
1332cd296721SStephen Warren  * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
1333cd296721SStephen Warren  * @fdt: pointer to the device tree blob
1334cd296721SStephen Warren  * @nodeoffset: offset of the node whose property to change
1335cd296721SStephen Warren  * @name: name of the property to change
1336cd296721SStephen Warren  * @val: 64-bit integer value to replace the property with
1337cd296721SStephen Warren  *
1338cd296721SStephen Warren  * fdt_setprop_inplace_u64() replaces the value of a given property
1339cd296721SStephen Warren  * with the 64-bit integer value in val, converting val to big-endian
1340cd296721SStephen Warren  * if necessary.  This function cannot change the size of a property,
1341cd296721SStephen Warren  * and so will only work if the property already exists and has length
1342cd296721SStephen Warren  * 8.
1343cd296721SStephen Warren  *
1344cd296721SStephen Warren  * This function will alter only the bytes in the blob which contain
1345cd296721SStephen Warren  * the given property value, and will not alter or move any other part
1346cd296721SStephen Warren  * of the tree.
1347cd296721SStephen Warren  *
1348cd296721SStephen Warren  * returns:
1349cd296721SStephen Warren  *	0, on success
1350cd296721SStephen Warren  *	-FDT_ERR_NOSPACE, if the property's length is not equal to 8
1351cd296721SStephen Warren  *	-FDT_ERR_NOTFOUND, node does not have the named property
1352cd296721SStephen Warren  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1353cd296721SStephen Warren  *	-FDT_ERR_BADMAGIC,
1354cd296721SStephen Warren  *	-FDT_ERR_BADVERSION,
1355cd296721SStephen Warren  *	-FDT_ERR_BADSTATE,
1356cd296721SStephen Warren  *	-FDT_ERR_BADSTRUCTURE,
1357cd296721SStephen Warren  *	-FDT_ERR_TRUNCATED, standard meanings
1358cd296721SStephen Warren  */
fdt_setprop_inplace_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)1359cd296721SStephen Warren static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
1360cd296721SStephen Warren 					  const char *name, uint64_t val)
1361cd296721SStephen Warren {
136247605971SRob Herring 	fdt64_t tmp = cpu_to_fdt64(val);
136347605971SRob Herring 	return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1364cd296721SStephen Warren }
1365cd296721SStephen Warren 
1366cd296721SStephen Warren /**
1367cd296721SStephen Warren  * fdt_setprop_inplace_cell - change the value of a single-cell property
136879edff12SRob Herring  * @fdt: pointer to the device tree blob
136979edff12SRob Herring  * @nodeoffset: offset of the node containing the property
137079edff12SRob Herring  * @name: name of the property to change the value of
137179edff12SRob Herring  * @val: new value of the 32-bit cell
1372cd296721SStephen Warren  *
1373cd296721SStephen Warren  * This is an alternative name for fdt_setprop_inplace_u32()
137479edff12SRob Herring  * Return: 0 on success, negative libfdt error number otherwise.
1375cd296721SStephen Warren  */
fdt_setprop_inplace_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)1376cd296721SStephen Warren static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
1377cd296721SStephen Warren 					   const char *name, uint32_t val)
1378cd296721SStephen Warren {
1379cd296721SStephen Warren 	return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
1380cd296721SStephen Warren }
1381cd296721SStephen Warren 
1382cd296721SStephen Warren /**
13839fffb55fSDavid Gibson  * fdt_nop_property - replace a property with nop tags
13849fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
13859fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose property to nop
13869fffb55fSDavid Gibson  * @name: name of the property to nop
13879fffb55fSDavid Gibson  *
13889fffb55fSDavid Gibson  * fdt_nop_property() will replace a given property's representation
13899fffb55fSDavid Gibson  * in the blob with FDT_NOP tags, effectively removing it from the
13909fffb55fSDavid Gibson  * tree.
13919fffb55fSDavid Gibson  *
13929fffb55fSDavid Gibson  * This function will alter only the bytes in the blob which contain
13939fffb55fSDavid Gibson  * the property, and will not alter or move any other part of the
13949fffb55fSDavid Gibson  * tree.
13959fffb55fSDavid Gibson  *
13969fffb55fSDavid Gibson  * returns:
13979fffb55fSDavid Gibson  *	0, on success
13989fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, node does not have the named property
13999fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
14009fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
14019fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
14029fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
14039fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
14049fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
14059fffb55fSDavid Gibson  */
14069fffb55fSDavid Gibson int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
14079fffb55fSDavid Gibson 
14089fffb55fSDavid Gibson /**
14099fffb55fSDavid Gibson  * fdt_nop_node - replace a node (subtree) with nop tags
14109fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
14119fffb55fSDavid Gibson  * @nodeoffset: offset of the node to nop
14129fffb55fSDavid Gibson  *
14139fffb55fSDavid Gibson  * fdt_nop_node() will replace a given node's representation in the
14149fffb55fSDavid Gibson  * blob, including all its subnodes, if any, with FDT_NOP tags,
14159fffb55fSDavid Gibson  * effectively removing it from the tree.
14169fffb55fSDavid Gibson  *
14179fffb55fSDavid Gibson  * This function will alter only the bytes in the blob which contain
14189fffb55fSDavid Gibson  * the node and its properties and subnodes, and will not alter or
14199fffb55fSDavid Gibson  * move any other part of the tree.
14209fffb55fSDavid Gibson  *
14219fffb55fSDavid Gibson  * returns:
14229fffb55fSDavid Gibson  *	0, on success
14239fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
14249fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
14259fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
14269fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
14279fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
14289fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
14299fffb55fSDavid Gibson  */
14309fffb55fSDavid Gibson int fdt_nop_node(void *fdt, int nodeoffset);
14319fffb55fSDavid Gibson 
14329fffb55fSDavid Gibson /**********************************************************************/
14339fffb55fSDavid Gibson /* Sequential write functions                                         */
14349fffb55fSDavid Gibson /**********************************************************************/
14359fffb55fSDavid Gibson 
14369bb9c6a1SRob Herring /* fdt_create_with_flags flags */
14379bb9c6a1SRob Herring #define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1
14389bb9c6a1SRob Herring 	/* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property
14399bb9c6a1SRob Herring 	 * names in the fdt. This can result in faster creation times, but
14409bb9c6a1SRob Herring 	 * a larger fdt. */
14419bb9c6a1SRob Herring 
14429bb9c6a1SRob Herring #define FDT_CREATE_FLAGS_ALL	(FDT_CREATE_FLAG_NO_NAME_DEDUP)
14439bb9c6a1SRob Herring 
14449bb9c6a1SRob Herring /**
14459bb9c6a1SRob Herring  * fdt_create_with_flags - begin creation of a new fdt
144679edff12SRob Herring  * @buf: pointer to memory allocated where fdt will be created
14479bb9c6a1SRob Herring  * @bufsize: size of the memory space at fdt
14489bb9c6a1SRob Herring  * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0.
14499bb9c6a1SRob Herring  *
14509bb9c6a1SRob Herring  * fdt_create_with_flags() begins the process of creating a new fdt with
14519bb9c6a1SRob Herring  * the sequential write interface.
14529bb9c6a1SRob Herring  *
14539bb9c6a1SRob Herring  * fdt creation process must end with fdt_finished() to produce a valid fdt.
14549bb9c6a1SRob Herring  *
14559bb9c6a1SRob Herring  * returns:
14569bb9c6a1SRob Herring  *	0, on success
14579bb9c6a1SRob Herring  *	-FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
14589bb9c6a1SRob Herring  *	-FDT_ERR_BADFLAGS, flags is not valid
14599bb9c6a1SRob Herring  */
14609bb9c6a1SRob Herring int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags);
14619bb9c6a1SRob Herring 
14629bb9c6a1SRob Herring /**
14639bb9c6a1SRob Herring  * fdt_create - begin creation of a new fdt
146479edff12SRob Herring  * @buf: pointer to memory allocated where fdt will be created
14659bb9c6a1SRob Herring  * @bufsize: size of the memory space at fdt
14669bb9c6a1SRob Herring  *
14679bb9c6a1SRob Herring  * fdt_create() is equivalent to fdt_create_with_flags() with flags=0.
14689bb9c6a1SRob Herring  *
14699bb9c6a1SRob Herring  * returns:
14709bb9c6a1SRob Herring  *	0, on success
14719bb9c6a1SRob Herring  *	-FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
14729bb9c6a1SRob Herring  */
14739fffb55fSDavid Gibson int fdt_create(void *buf, int bufsize);
14749bb9c6a1SRob Herring 
147547605971SRob Herring int fdt_resize(void *fdt, void *buf, int bufsize);
14769fffb55fSDavid Gibson int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
14779fffb55fSDavid Gibson int fdt_finish_reservemap(void *fdt);
14789fffb55fSDavid Gibson int fdt_begin_node(void *fdt, const char *name);
14799fffb55fSDavid Gibson int fdt_property(void *fdt, const char *name, const void *val, int len);
fdt_property_u32(void * fdt,const char * name,uint32_t val)1480cd296721SStephen Warren static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
14819fffb55fSDavid Gibson {
148247605971SRob Herring 	fdt32_t tmp = cpu_to_fdt32(val);
148347605971SRob Herring 	return fdt_property(fdt, name, &tmp, sizeof(tmp));
14849fffb55fSDavid Gibson }
fdt_property_u64(void * fdt,const char * name,uint64_t val)1485cd296721SStephen Warren static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
1486cd296721SStephen Warren {
148747605971SRob Herring 	fdt64_t tmp = cpu_to_fdt64(val);
148847605971SRob Herring 	return fdt_property(fdt, name, &tmp, sizeof(tmp));
1489cd296721SStephen Warren }
1490f858927fSRob Herring 
1491f858927fSRob Herring #ifndef SWIG /* Not available in Python */
fdt_property_cell(void * fdt,const char * name,uint32_t val)1492cd296721SStephen Warren static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
1493cd296721SStephen Warren {
1494cd296721SStephen Warren 	return fdt_property_u32(fdt, name, val);
1495cd296721SStephen Warren }
1496f858927fSRob Herring #endif
14974201d057SRob Herring 
14984201d057SRob Herring /**
14994201d057SRob Herring  * fdt_property_placeholder - add a new property and return a ptr to its value
15004201d057SRob Herring  *
15014201d057SRob Herring  * @fdt: pointer to the device tree blob
15024201d057SRob Herring  * @name: name of property to add
15034201d057SRob Herring  * @len: length of property value in bytes
15044201d057SRob Herring  * @valp: returns a pointer to where where the value should be placed
15054201d057SRob Herring  *
15064201d057SRob Herring  * returns:
15074201d057SRob Herring  *	0, on success
15084201d057SRob Herring  *	-FDT_ERR_BADMAGIC,
15094201d057SRob Herring  *	-FDT_ERR_NOSPACE, standard meanings
15104201d057SRob Herring  */
15114201d057SRob Herring int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp);
15124201d057SRob Herring 
15139fffb55fSDavid Gibson #define fdt_property_string(fdt, name, str) \
15149fffb55fSDavid Gibson 	fdt_property(fdt, name, str, strlen(str)+1)
15159fffb55fSDavid Gibson int fdt_end_node(void *fdt);
15169fffb55fSDavid Gibson int fdt_finish(void *fdt);
15179fffb55fSDavid Gibson 
15189fffb55fSDavid Gibson /**********************************************************************/
15199fffb55fSDavid Gibson /* Read-write functions                                               */
15209fffb55fSDavid Gibson /**********************************************************************/
15219fffb55fSDavid Gibson 
1522cd296721SStephen Warren int fdt_create_empty_tree(void *buf, int bufsize);
15239fffb55fSDavid Gibson int fdt_open_into(const void *fdt, void *buf, int bufsize);
15249fffb55fSDavid Gibson int fdt_pack(void *fdt);
15259fffb55fSDavid Gibson 
15269fffb55fSDavid Gibson /**
15279fffb55fSDavid Gibson  * fdt_add_mem_rsv - add one memory reserve map entry
15289fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
152979edff12SRob Herring  * @address: 64-bit start address of the reserve map entry
153079edff12SRob Herring  * @size: 64-bit size of the reserved region
15319fffb55fSDavid Gibson  *
15329fffb55fSDavid Gibson  * Adds a reserve map entry to the given blob reserving a region at
15339fffb55fSDavid Gibson  * address address of length size.
15349fffb55fSDavid Gibson  *
15359fffb55fSDavid Gibson  * This function will insert data into the reserve map and will
15369fffb55fSDavid Gibson  * therefore change the indexes of some entries in the table.
15379fffb55fSDavid Gibson  *
15389fffb55fSDavid Gibson  * returns:
15399fffb55fSDavid Gibson  *	0, on success
15409fffb55fSDavid Gibson  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
15419fffb55fSDavid Gibson  *		contain the new reservation entry
15429fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
15439fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
15449fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
15459fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
15469fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT,
15479fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
15489fffb55fSDavid Gibson  */
15499fffb55fSDavid Gibson int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
15509fffb55fSDavid Gibson 
15519fffb55fSDavid Gibson /**
15529fffb55fSDavid Gibson  * fdt_del_mem_rsv - remove a memory reserve map entry
15539fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
15549fffb55fSDavid Gibson  * @n: entry to remove
15559fffb55fSDavid Gibson  *
15569fffb55fSDavid Gibson  * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
15579fffb55fSDavid Gibson  * the blob.
15589fffb55fSDavid Gibson  *
15599fffb55fSDavid Gibson  * This function will delete data from the reservation table and will
15609fffb55fSDavid Gibson  * therefore change the indexes of some entries in the table.
15619fffb55fSDavid Gibson  *
15629fffb55fSDavid Gibson  * returns:
15639fffb55fSDavid Gibson  *	0, on success
15649fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
15659fffb55fSDavid Gibson  *		are less than n+1 reserve map entries)
15669fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
15679fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
15689fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
15699fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
15709fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT,
15719fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
15729fffb55fSDavid Gibson  */
15739fffb55fSDavid Gibson int fdt_del_mem_rsv(void *fdt, int n);
15749fffb55fSDavid Gibson 
15759fffb55fSDavid Gibson /**
15769fffb55fSDavid Gibson  * fdt_set_name - change the name of a given node
15779fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
15789fffb55fSDavid Gibson  * @nodeoffset: structure block offset of a node
15799fffb55fSDavid Gibson  * @name: name to give the node
15809fffb55fSDavid Gibson  *
15819fffb55fSDavid Gibson  * fdt_set_name() replaces the name (including unit address, if any)
15829fffb55fSDavid Gibson  * of the given node with the given string.  NOTE: this function can't
15839fffb55fSDavid Gibson  * efficiently check if the new name is unique amongst the given
15849fffb55fSDavid Gibson  * node's siblings; results are undefined if this function is invoked
15859fffb55fSDavid Gibson  * with a name equal to one of the given node's siblings.
15869fffb55fSDavid Gibson  *
15879fffb55fSDavid Gibson  * This function may insert or delete data from the blob, and will
15889fffb55fSDavid Gibson  * therefore change the offsets of some existing nodes.
15899fffb55fSDavid Gibson  *
15909fffb55fSDavid Gibson  * returns:
15919fffb55fSDavid Gibson  *	0, on success
15929fffb55fSDavid Gibson  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob
15939fffb55fSDavid Gibson  *		to contain the new name
15949fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
15959fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
15969fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
15979fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE, standard meanings
15989fffb55fSDavid Gibson  */
15999fffb55fSDavid Gibson int fdt_set_name(void *fdt, int nodeoffset, const char *name);
16009fffb55fSDavid Gibson 
16019fffb55fSDavid Gibson /**
16029fffb55fSDavid Gibson  * fdt_setprop - create or change a property
16039fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
16049fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose property to change
16059fffb55fSDavid Gibson  * @name: name of the property to change
16069fffb55fSDavid Gibson  * @val: pointer to data to set the property value to
16079fffb55fSDavid Gibson  * @len: length of the property value
16089fffb55fSDavid Gibson  *
16099fffb55fSDavid Gibson  * fdt_setprop() sets the value of the named property in the given
16109fffb55fSDavid Gibson  * node to the given value and length, creating the property if it
16119fffb55fSDavid Gibson  * does not already exist.
16129fffb55fSDavid Gibson  *
16139fffb55fSDavid Gibson  * This function may insert or delete data from the blob, and will
16149fffb55fSDavid Gibson  * therefore change the offsets of some existing nodes.
16159fffb55fSDavid Gibson  *
16169fffb55fSDavid Gibson  * returns:
16179fffb55fSDavid Gibson  *	0, on success
16189fffb55fSDavid Gibson  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
16199fffb55fSDavid Gibson  *		contain the new property value
16209fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
16219fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT,
16229fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
16239fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
16249fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
16259fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
16269fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT,
16279fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
16289fffb55fSDavid Gibson  */
16299fffb55fSDavid Gibson int fdt_setprop(void *fdt, int nodeoffset, const char *name,
16309fffb55fSDavid Gibson 		const void *val, int len);
16319fffb55fSDavid Gibson 
16329fffb55fSDavid Gibson /**
16334201d057SRob Herring  * fdt_setprop_placeholder - allocate space for a property
16344201d057SRob Herring  * @fdt: pointer to the device tree blob
16354201d057SRob Herring  * @nodeoffset: offset of the node whose property to change
16364201d057SRob Herring  * @name: name of the property to change
16374201d057SRob Herring  * @len: length of the property value
16384201d057SRob Herring  * @prop_data: return pointer to property data
16394201d057SRob Herring  *
16404201d057SRob Herring  * fdt_setprop_placeholer() allocates the named property in the given node.
16414201d057SRob Herring  * If the property exists it is resized. In either case a pointer to the
16424201d057SRob Herring  * property data is returned.
16434201d057SRob Herring  *
16444201d057SRob Herring  * This function may insert or delete data from the blob, and will
16454201d057SRob Herring  * therefore change the offsets of some existing nodes.
16464201d057SRob Herring  *
16474201d057SRob Herring  * returns:
16484201d057SRob Herring  *	0, on success
16494201d057SRob Herring  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
16504201d057SRob Herring  *		contain the new property value
16514201d057SRob Herring  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
16524201d057SRob Herring  *	-FDT_ERR_BADLAYOUT,
16534201d057SRob Herring  *	-FDT_ERR_BADMAGIC,
16544201d057SRob Herring  *	-FDT_ERR_BADVERSION,
16554201d057SRob Herring  *	-FDT_ERR_BADSTATE,
16564201d057SRob Herring  *	-FDT_ERR_BADSTRUCTURE,
16574201d057SRob Herring  *	-FDT_ERR_BADLAYOUT,
16584201d057SRob Herring  *	-FDT_ERR_TRUNCATED, standard meanings
16594201d057SRob Herring  */
16604201d057SRob Herring int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
16614201d057SRob Herring 			    int len, void **prop_data);
16624201d057SRob Herring 
16634201d057SRob Herring /**
1664cd296721SStephen Warren  * fdt_setprop_u32 - set a property to a 32-bit integer
16659fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
16669fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose property to change
16679fffb55fSDavid Gibson  * @name: name of the property to change
16689fffb55fSDavid Gibson  * @val: 32-bit integer value for the property (native endian)
16699fffb55fSDavid Gibson  *
1670cd296721SStephen Warren  * fdt_setprop_u32() sets the value of the named property in the given
1671cd296721SStephen Warren  * node to the given 32-bit integer value (converting to big-endian if
16729fffb55fSDavid Gibson  * necessary), or creates a new property with that value if it does
16739fffb55fSDavid Gibson  * not already exist.
16749fffb55fSDavid Gibson  *
16759fffb55fSDavid Gibson  * This function may insert or delete data from the blob, and will
16769fffb55fSDavid Gibson  * therefore change the offsets of some existing nodes.
16779fffb55fSDavid Gibson  *
16789fffb55fSDavid Gibson  * returns:
16799fffb55fSDavid Gibson  *	0, on success
16809fffb55fSDavid Gibson  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
16819fffb55fSDavid Gibson  *		contain the new property value
16829fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
16839fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT,
16849fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
16859fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
16869fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
16879fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
16889fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT,
16899fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
16909fffb55fSDavid Gibson  */
fdt_setprop_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)1691cd296721SStephen Warren static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
16929fffb55fSDavid Gibson 				  uint32_t val)
16939fffb55fSDavid Gibson {
169447605971SRob Herring 	fdt32_t tmp = cpu_to_fdt32(val);
169547605971SRob Herring 	return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
16969fffb55fSDavid Gibson }
16979fffb55fSDavid Gibson 
16989fffb55fSDavid Gibson /**
1699cd296721SStephen Warren  * fdt_setprop_u64 - set a property to a 64-bit integer
1700cd296721SStephen Warren  * @fdt: pointer to the device tree blob
1701cd296721SStephen Warren  * @nodeoffset: offset of the node whose property to change
1702cd296721SStephen Warren  * @name: name of the property to change
1703cd296721SStephen Warren  * @val: 64-bit integer value for the property (native endian)
1704cd296721SStephen Warren  *
1705cd296721SStephen Warren  * fdt_setprop_u64() sets the value of the named property in the given
1706cd296721SStephen Warren  * node to the given 64-bit integer value (converting to big-endian if
1707cd296721SStephen Warren  * necessary), or creates a new property with that value if it does
1708cd296721SStephen Warren  * not already exist.
1709cd296721SStephen Warren  *
1710cd296721SStephen Warren  * This function may insert or delete data from the blob, and will
1711cd296721SStephen Warren  * therefore change the offsets of some existing nodes.
1712cd296721SStephen Warren  *
1713cd296721SStephen Warren  * returns:
1714cd296721SStephen Warren  *	0, on success
1715cd296721SStephen Warren  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1716cd296721SStephen Warren  *		contain the new property value
1717cd296721SStephen Warren  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1718cd296721SStephen Warren  *	-FDT_ERR_BADLAYOUT,
1719cd296721SStephen Warren  *	-FDT_ERR_BADMAGIC,
1720cd296721SStephen Warren  *	-FDT_ERR_BADVERSION,
1721cd296721SStephen Warren  *	-FDT_ERR_BADSTATE,
1722cd296721SStephen Warren  *	-FDT_ERR_BADSTRUCTURE,
1723cd296721SStephen Warren  *	-FDT_ERR_BADLAYOUT,
1724cd296721SStephen Warren  *	-FDT_ERR_TRUNCATED, standard meanings
1725cd296721SStephen Warren  */
fdt_setprop_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)1726cd296721SStephen Warren static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
1727cd296721SStephen Warren 				  uint64_t val)
1728cd296721SStephen Warren {
172947605971SRob Herring 	fdt64_t tmp = cpu_to_fdt64(val);
173047605971SRob Herring 	return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1731cd296721SStephen Warren }
1732cd296721SStephen Warren 
1733cd296721SStephen Warren /**
1734cd296721SStephen Warren  * fdt_setprop_cell - set a property to a single cell value
173579edff12SRob Herring  * @fdt: pointer to the device tree blob
173679edff12SRob Herring  * @nodeoffset: offset of the node whose property to change
173779edff12SRob Herring  * @name: name of the property to change
173879edff12SRob Herring  * @val: 32-bit integer value for the property (native endian)
1739cd296721SStephen Warren  *
1740cd296721SStephen Warren  * This is an alternative name for fdt_setprop_u32()
174179edff12SRob Herring  *
174279edff12SRob Herring  * Return: 0 on success, negative libfdt error value otherwise.
1743cd296721SStephen Warren  */
fdt_setprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)1744cd296721SStephen Warren static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
1745cd296721SStephen Warren 				   uint32_t val)
1746cd296721SStephen Warren {
1747cd296721SStephen Warren 	return fdt_setprop_u32(fdt, nodeoffset, name, val);
1748cd296721SStephen Warren }
1749cd296721SStephen Warren 
1750cd296721SStephen Warren /**
17519fffb55fSDavid Gibson  * fdt_setprop_string - set a property to a string value
17529fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
17539fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose property to change
17549fffb55fSDavid Gibson  * @name: name of the property to change
17559fffb55fSDavid Gibson  * @str: string value for the property
17569fffb55fSDavid Gibson  *
17579fffb55fSDavid Gibson  * fdt_setprop_string() sets the value of the named property in the
17589fffb55fSDavid Gibson  * given node to the given string value (using the length of the
17599fffb55fSDavid Gibson  * string to determine the new length of the property), or creates a
17609fffb55fSDavid Gibson  * new property with that value if it does not already exist.
17619fffb55fSDavid Gibson  *
17629fffb55fSDavid Gibson  * This function may insert or delete data from the blob, and will
17639fffb55fSDavid Gibson  * therefore change the offsets of some existing nodes.
17649fffb55fSDavid Gibson  *
17659fffb55fSDavid Gibson  * returns:
17669fffb55fSDavid Gibson  *	0, on success
17679fffb55fSDavid Gibson  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
17689fffb55fSDavid Gibson  *		contain the new property value
17699fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
17709fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT,
17719fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
17729fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
17739fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
17749fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
17759fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT,
17769fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
17779fffb55fSDavid Gibson  */
17789fffb55fSDavid Gibson #define fdt_setprop_string(fdt, nodeoffset, name, str) \
17799fffb55fSDavid Gibson 	fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
17809fffb55fSDavid Gibson 
178189d12310SRob Herring 
178289d12310SRob Herring /**
178389d12310SRob Herring  * fdt_setprop_empty - set a property to an empty value
178489d12310SRob Herring  * @fdt: pointer to the device tree blob
178589d12310SRob Herring  * @nodeoffset: offset of the node whose property to change
178689d12310SRob Herring  * @name: name of the property to change
178789d12310SRob Herring  *
178889d12310SRob Herring  * fdt_setprop_empty() sets the value of the named property in the
178989d12310SRob Herring  * given node to an empty (zero length) value, or creates a new empty
179089d12310SRob Herring  * property if it does not already exist.
179189d12310SRob Herring  *
179289d12310SRob Herring  * This function may insert or delete data from the blob, and will
179389d12310SRob Herring  * therefore change the offsets of some existing nodes.
179489d12310SRob Herring  *
179589d12310SRob Herring  * returns:
179689d12310SRob Herring  *	0, on success
179789d12310SRob Herring  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
179889d12310SRob Herring  *		contain the new property value
179989d12310SRob Herring  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
180089d12310SRob Herring  *	-FDT_ERR_BADLAYOUT,
180189d12310SRob Herring  *	-FDT_ERR_BADMAGIC,
180289d12310SRob Herring  *	-FDT_ERR_BADVERSION,
180389d12310SRob Herring  *	-FDT_ERR_BADSTATE,
180489d12310SRob Herring  *	-FDT_ERR_BADSTRUCTURE,
180589d12310SRob Herring  *	-FDT_ERR_BADLAYOUT,
180689d12310SRob Herring  *	-FDT_ERR_TRUNCATED, standard meanings
180789d12310SRob Herring  */
180889d12310SRob Herring #define fdt_setprop_empty(fdt, nodeoffset, name) \
180989d12310SRob Herring 	fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
181089d12310SRob Herring 
18119fffb55fSDavid Gibson /**
1812cd296721SStephen Warren  * fdt_appendprop - append to or create a property
1813cd296721SStephen Warren  * @fdt: pointer to the device tree blob
1814cd296721SStephen Warren  * @nodeoffset: offset of the node whose property to change
1815cd296721SStephen Warren  * @name: name of the property to append to
1816cd296721SStephen Warren  * @val: pointer to data to append to the property value
1817cd296721SStephen Warren  * @len: length of the data to append to the property value
1818cd296721SStephen Warren  *
1819cd296721SStephen Warren  * fdt_appendprop() appends the value to the named property in the
1820cd296721SStephen Warren  * given node, creating the property if it does not already exist.
1821cd296721SStephen Warren  *
1822cd296721SStephen Warren  * This function may insert data into the blob, and will therefore
1823cd296721SStephen Warren  * change the offsets of some existing nodes.
1824cd296721SStephen Warren  *
1825cd296721SStephen Warren  * returns:
1826cd296721SStephen Warren  *	0, on success
1827cd296721SStephen Warren  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1828cd296721SStephen Warren  *		contain the new property value
1829cd296721SStephen Warren  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1830cd296721SStephen Warren  *	-FDT_ERR_BADLAYOUT,
1831cd296721SStephen Warren  *	-FDT_ERR_BADMAGIC,
1832cd296721SStephen Warren  *	-FDT_ERR_BADVERSION,
1833cd296721SStephen Warren  *	-FDT_ERR_BADSTATE,
1834cd296721SStephen Warren  *	-FDT_ERR_BADSTRUCTURE,
1835cd296721SStephen Warren  *	-FDT_ERR_BADLAYOUT,
1836cd296721SStephen Warren  *	-FDT_ERR_TRUNCATED, standard meanings
1837cd296721SStephen Warren  */
1838cd296721SStephen Warren int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
1839cd296721SStephen Warren 		   const void *val, int len);
1840cd296721SStephen Warren 
1841cd296721SStephen Warren /**
1842cd296721SStephen Warren  * fdt_appendprop_u32 - append a 32-bit integer value to a property
1843cd296721SStephen Warren  * @fdt: pointer to the device tree blob
1844cd296721SStephen Warren  * @nodeoffset: offset of the node whose property to change
1845cd296721SStephen Warren  * @name: name of the property to change
1846cd296721SStephen Warren  * @val: 32-bit integer value to append to the property (native endian)
1847cd296721SStephen Warren  *
1848cd296721SStephen Warren  * fdt_appendprop_u32() appends the given 32-bit integer value
1849cd296721SStephen Warren  * (converting to big-endian if necessary) to the value of the named
1850cd296721SStephen Warren  * property in the given node, or creates a new property with that
1851cd296721SStephen Warren  * value if it does not already exist.
1852cd296721SStephen Warren  *
1853cd296721SStephen Warren  * This function may insert data into the blob, and will therefore
1854cd296721SStephen Warren  * change the offsets of some existing nodes.
1855cd296721SStephen Warren  *
1856cd296721SStephen Warren  * returns:
1857cd296721SStephen Warren  *	0, on success
1858cd296721SStephen Warren  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1859cd296721SStephen Warren  *		contain the new property value
1860cd296721SStephen Warren  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1861cd296721SStephen Warren  *	-FDT_ERR_BADLAYOUT,
1862cd296721SStephen Warren  *	-FDT_ERR_BADMAGIC,
1863cd296721SStephen Warren  *	-FDT_ERR_BADVERSION,
1864cd296721SStephen Warren  *	-FDT_ERR_BADSTATE,
1865cd296721SStephen Warren  *	-FDT_ERR_BADSTRUCTURE,
1866cd296721SStephen Warren  *	-FDT_ERR_BADLAYOUT,
1867cd296721SStephen Warren  *	-FDT_ERR_TRUNCATED, standard meanings
1868cd296721SStephen Warren  */
fdt_appendprop_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)1869cd296721SStephen Warren static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
1870cd296721SStephen Warren 				     const char *name, uint32_t val)
1871cd296721SStephen Warren {
187247605971SRob Herring 	fdt32_t tmp = cpu_to_fdt32(val);
187347605971SRob Herring 	return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1874cd296721SStephen Warren }
1875cd296721SStephen Warren 
1876cd296721SStephen Warren /**
1877cd296721SStephen Warren  * fdt_appendprop_u64 - append a 64-bit integer value to a property
1878cd296721SStephen Warren  * @fdt: pointer to the device tree blob
1879cd296721SStephen Warren  * @nodeoffset: offset of the node whose property to change
1880cd296721SStephen Warren  * @name: name of the property to change
1881cd296721SStephen Warren  * @val: 64-bit integer value to append to the property (native endian)
1882cd296721SStephen Warren  *
1883cd296721SStephen Warren  * fdt_appendprop_u64() appends the given 64-bit integer value
1884cd296721SStephen Warren  * (converting to big-endian if necessary) to the value of the named
1885cd296721SStephen Warren  * property in the given node, or creates a new property with that
1886cd296721SStephen Warren  * value if it does not already exist.
1887cd296721SStephen Warren  *
1888cd296721SStephen Warren  * This function may insert data into the blob, and will therefore
1889cd296721SStephen Warren  * change the offsets of some existing nodes.
1890cd296721SStephen Warren  *
1891cd296721SStephen Warren  * returns:
1892cd296721SStephen Warren  *	0, on success
1893cd296721SStephen Warren  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1894cd296721SStephen Warren  *		contain the new property value
1895cd296721SStephen Warren  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1896cd296721SStephen Warren  *	-FDT_ERR_BADLAYOUT,
1897cd296721SStephen Warren  *	-FDT_ERR_BADMAGIC,
1898cd296721SStephen Warren  *	-FDT_ERR_BADVERSION,
1899cd296721SStephen Warren  *	-FDT_ERR_BADSTATE,
1900cd296721SStephen Warren  *	-FDT_ERR_BADSTRUCTURE,
1901cd296721SStephen Warren  *	-FDT_ERR_BADLAYOUT,
1902cd296721SStephen Warren  *	-FDT_ERR_TRUNCATED, standard meanings
1903cd296721SStephen Warren  */
fdt_appendprop_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)1904cd296721SStephen Warren static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
1905cd296721SStephen Warren 				     const char *name, uint64_t val)
1906cd296721SStephen Warren {
190747605971SRob Herring 	fdt64_t tmp = cpu_to_fdt64(val);
190847605971SRob Herring 	return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
1909cd296721SStephen Warren }
1910cd296721SStephen Warren 
1911cd296721SStephen Warren /**
1912cd296721SStephen Warren  * fdt_appendprop_cell - append a single cell value to a property
191379edff12SRob Herring  * @fdt: pointer to the device tree blob
191479edff12SRob Herring  * @nodeoffset: offset of the node whose property to change
191579edff12SRob Herring  * @name: name of the property to change
191679edff12SRob Herring  * @val: 32-bit integer value to append to the property (native endian)
1917cd296721SStephen Warren  *
1918cd296721SStephen Warren  * This is an alternative name for fdt_appendprop_u32()
191979edff12SRob Herring  *
192079edff12SRob Herring  * Return: 0 on success, negative libfdt error value otherwise.
1921cd296721SStephen Warren  */
fdt_appendprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)1922cd296721SStephen Warren static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
1923cd296721SStephen Warren 				      const char *name, uint32_t val)
1924cd296721SStephen Warren {
1925cd296721SStephen Warren 	return fdt_appendprop_u32(fdt, nodeoffset, name, val);
1926cd296721SStephen Warren }
1927cd296721SStephen Warren 
1928cd296721SStephen Warren /**
1929cd296721SStephen Warren  * fdt_appendprop_string - append a string to a property
1930cd296721SStephen Warren  * @fdt: pointer to the device tree blob
1931cd296721SStephen Warren  * @nodeoffset: offset of the node whose property to change
1932cd296721SStephen Warren  * @name: name of the property to change
1933cd296721SStephen Warren  * @str: string value to append to the property
1934cd296721SStephen Warren  *
1935cd296721SStephen Warren  * fdt_appendprop_string() appends the given string to the value of
1936cd296721SStephen Warren  * the named property in the given node, or creates a new property
1937cd296721SStephen Warren  * with that value if it does not already exist.
1938cd296721SStephen Warren  *
1939cd296721SStephen Warren  * This function may insert data into the blob, and will therefore
1940cd296721SStephen Warren  * change the offsets of some existing nodes.
1941cd296721SStephen Warren  *
1942cd296721SStephen Warren  * returns:
1943cd296721SStephen Warren  *	0, on success
1944cd296721SStephen Warren  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1945cd296721SStephen Warren  *		contain the new property value
1946cd296721SStephen Warren  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1947cd296721SStephen Warren  *	-FDT_ERR_BADLAYOUT,
1948cd296721SStephen Warren  *	-FDT_ERR_BADMAGIC,
1949cd296721SStephen Warren  *	-FDT_ERR_BADVERSION,
1950cd296721SStephen Warren  *	-FDT_ERR_BADSTATE,
1951cd296721SStephen Warren  *	-FDT_ERR_BADSTRUCTURE,
1952cd296721SStephen Warren  *	-FDT_ERR_BADLAYOUT,
1953cd296721SStephen Warren  *	-FDT_ERR_TRUNCATED, standard meanings
1954cd296721SStephen Warren  */
1955cd296721SStephen Warren #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
1956cd296721SStephen Warren 	fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
1957cd296721SStephen Warren 
1958cd296721SStephen Warren /**
19599bb9c6a1SRob Herring  * fdt_appendprop_addrrange - append a address range property
19609bb9c6a1SRob Herring  * @fdt: pointer to the device tree blob
19619bb9c6a1SRob Herring  * @parent: offset of the parent node
19629bb9c6a1SRob Herring  * @nodeoffset: offset of the node to add a property at
19639bb9c6a1SRob Herring  * @name: name of property
19649bb9c6a1SRob Herring  * @addr: start address of a given range
19659bb9c6a1SRob Herring  * @size: size of a given range
19669bb9c6a1SRob Herring  *
19679bb9c6a1SRob Herring  * fdt_appendprop_addrrange() appends an address range value (start
19689bb9c6a1SRob Herring  * address and size) to the value of the named property in the given
19699bb9c6a1SRob Herring  * node, or creates a new property with that value if it does not
19709bb9c6a1SRob Herring  * already exist.
19719bb9c6a1SRob Herring  * If "name" is not specified, a default "reg" is used.
19729bb9c6a1SRob Herring  * Cell sizes are determined by parent's #address-cells and #size-cells.
19739bb9c6a1SRob Herring  *
19749bb9c6a1SRob Herring  * This function may insert data into the blob, and will therefore
19759bb9c6a1SRob Herring  * change the offsets of some existing nodes.
19769bb9c6a1SRob Herring  *
19779bb9c6a1SRob Herring  * returns:
19789bb9c6a1SRob Herring  *	0, on success
19799bb9c6a1SRob Herring  *	-FDT_ERR_BADLAYOUT,
19809bb9c6a1SRob Herring  *	-FDT_ERR_BADMAGIC,
19819bb9c6a1SRob Herring  *	-FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
19829bb9c6a1SRob Herring  *		#address-cells property
19839bb9c6a1SRob Herring  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
19849bb9c6a1SRob Herring  *	-FDT_ERR_BADSTATE,
19859bb9c6a1SRob Herring  *	-FDT_ERR_BADSTRUCTURE,
19869bb9c6a1SRob Herring  *	-FDT_ERR_BADVERSION,
19879bb9c6a1SRob Herring  *	-FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size
19889bb9c6a1SRob Herring  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
19899bb9c6a1SRob Herring  *		contain a new property
19909bb9c6a1SRob Herring  *	-FDT_ERR_TRUNCATED, standard meanings
19919bb9c6a1SRob Herring  */
19929bb9c6a1SRob Herring int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
19939bb9c6a1SRob Herring 			     const char *name, uint64_t addr, uint64_t size);
19949bb9c6a1SRob Herring 
19959bb9c6a1SRob Herring /**
19969fffb55fSDavid Gibson  * fdt_delprop - delete a property
19979fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
19989fffb55fSDavid Gibson  * @nodeoffset: offset of the node whose property to nop
19999fffb55fSDavid Gibson  * @name: name of the property to nop
20009fffb55fSDavid Gibson  *
20019fffb55fSDavid Gibson  * fdt_del_property() will delete the given property.
20029fffb55fSDavid Gibson  *
20039fffb55fSDavid Gibson  * This function will delete data from the blob, and will therefore
20049fffb55fSDavid Gibson  * change the offsets of some existing nodes.
20059fffb55fSDavid Gibson  *
20069fffb55fSDavid Gibson  * returns:
20079fffb55fSDavid Gibson  *	0, on success
20089fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, node does not have the named property
20099fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
20109fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT,
20119fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
20129fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
20139fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
20149fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
20159fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
20169fffb55fSDavid Gibson  */
20179fffb55fSDavid Gibson int fdt_delprop(void *fdt, int nodeoffset, const char *name);
20189fffb55fSDavid Gibson 
20199fffb55fSDavid Gibson /**
20209fffb55fSDavid Gibson  * fdt_add_subnode_namelen - creates a new node based on substring
20219fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
20229fffb55fSDavid Gibson  * @parentoffset: structure block offset of a node
202379edff12SRob Herring  * @name: name of the subnode to create
20249fffb55fSDavid Gibson  * @namelen: number of characters of name to consider
20259fffb55fSDavid Gibson  *
202679edff12SRob Herring  * Identical to fdt_add_subnode(), but use only the first @namelen
202779edff12SRob Herring  * characters of @name as the name of the new node.  This is useful for
20289fffb55fSDavid Gibson  * creating subnodes based on a portion of a larger string, such as a
20299fffb55fSDavid Gibson  * full path.
203079edff12SRob Herring  *
203179edff12SRob Herring  * Return: structure block offset of the created subnode (>=0),
203279edff12SRob Herring  *	   negative libfdt error value otherwise
20339fffb55fSDavid Gibson  */
203489d12310SRob Herring #ifndef SWIG /* Not available in Python */
20359fffb55fSDavid Gibson int fdt_add_subnode_namelen(void *fdt, int parentoffset,
20369fffb55fSDavid Gibson 			    const char *name, int namelen);
203789d12310SRob Herring #endif
20389fffb55fSDavid Gibson 
20399fffb55fSDavid Gibson /**
20409fffb55fSDavid Gibson  * fdt_add_subnode - creates a new node
20419fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
20429fffb55fSDavid Gibson  * @parentoffset: structure block offset of a node
20439fffb55fSDavid Gibson  * @name: name of the subnode to locate
20449fffb55fSDavid Gibson  *
20459fffb55fSDavid Gibson  * fdt_add_subnode() creates a new node as a subnode of the node at
20469fffb55fSDavid Gibson  * structure block offset parentoffset, with the given name (which
20479fffb55fSDavid Gibson  * should include the unit address, if any).
20489fffb55fSDavid Gibson  *
20499fffb55fSDavid Gibson  * This function will insert data into the blob, and will therefore
20509fffb55fSDavid Gibson  * change the offsets of some existing nodes.
205179edff12SRob Herring  *
20529fffb55fSDavid Gibson  * returns:
20536f05afcbSRob Herring  *	structure block offset of the created nodeequested subnode (>=0), on
20546f05afcbSRob Herring  *		success
20559fffb55fSDavid Gibson  *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
20566f05afcbSRob Herring  *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
20576f05afcbSRob Herring  *		tag
20589fffb55fSDavid Gibson  *	-FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
20599fffb55fSDavid Gibson  *		the given name
20609fffb55fSDavid Gibson  *	-FDT_ERR_NOSPACE, if there is insufficient free space in the
20619fffb55fSDavid Gibson  *		blob to contain the new node
20629fffb55fSDavid Gibson  *	-FDT_ERR_NOSPACE
20639fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT
20649fffb55fSDavid Gibson  *      -FDT_ERR_BADMAGIC,
20659fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
20669fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
20679fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
20689fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings.
20699fffb55fSDavid Gibson  */
20709fffb55fSDavid Gibson int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
20719fffb55fSDavid Gibson 
20729fffb55fSDavid Gibson /**
20739fffb55fSDavid Gibson  * fdt_del_node - delete a node (subtree)
20749fffb55fSDavid Gibson  * @fdt: pointer to the device tree blob
20759fffb55fSDavid Gibson  * @nodeoffset: offset of the node to nop
20769fffb55fSDavid Gibson  *
20779fffb55fSDavid Gibson  * fdt_del_node() will remove the given node, including all its
20789fffb55fSDavid Gibson  * subnodes if any, from the blob.
20799fffb55fSDavid Gibson  *
20809fffb55fSDavid Gibson  * This function will delete data from the blob, and will therefore
20819fffb55fSDavid Gibson  * change the offsets of some existing nodes.
20829fffb55fSDavid Gibson  *
20839fffb55fSDavid Gibson  * returns:
20849fffb55fSDavid Gibson  *	0, on success
20859fffb55fSDavid Gibson  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
20869fffb55fSDavid Gibson  *	-FDT_ERR_BADLAYOUT,
20879fffb55fSDavid Gibson  *	-FDT_ERR_BADMAGIC,
20889fffb55fSDavid Gibson  *	-FDT_ERR_BADVERSION,
20899fffb55fSDavid Gibson  *	-FDT_ERR_BADSTATE,
20909fffb55fSDavid Gibson  *	-FDT_ERR_BADSTRUCTURE,
20919fffb55fSDavid Gibson  *	-FDT_ERR_TRUNCATED, standard meanings
20929fffb55fSDavid Gibson  */
20939fffb55fSDavid Gibson int fdt_del_node(void *fdt, int nodeoffset);
20949fffb55fSDavid Gibson 
20956f05afcbSRob Herring /**
20966f05afcbSRob Herring  * fdt_overlay_apply - Applies a DT overlay on a base DT
20976f05afcbSRob Herring  * @fdt: pointer to the base device tree blob
20986f05afcbSRob Herring  * @fdto: pointer to the device tree overlay blob
20996f05afcbSRob Herring  *
21006f05afcbSRob Herring  * fdt_overlay_apply() will apply the given device tree overlay on the
21016f05afcbSRob Herring  * given base device tree.
21026f05afcbSRob Herring  *
21036f05afcbSRob Herring  * Expect the base device tree to be modified, even if the function
21046f05afcbSRob Herring  * returns an error.
21056f05afcbSRob Herring  *
21066f05afcbSRob Herring  * returns:
21076f05afcbSRob Herring  *	0, on success
21086f05afcbSRob Herring  *	-FDT_ERR_NOSPACE, there's not enough space in the base device tree
21096f05afcbSRob Herring  *	-FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
21106f05afcbSRob Herring  *		properties in the base DT
21116f05afcbSRob Herring  *	-FDT_ERR_BADPHANDLE,
21126f05afcbSRob Herring  *	-FDT_ERR_BADOVERLAY,
21136f05afcbSRob Herring  *	-FDT_ERR_NOPHANDLES,
21146f05afcbSRob Herring  *	-FDT_ERR_INTERNAL,
21156f05afcbSRob Herring  *	-FDT_ERR_BADLAYOUT,
21166f05afcbSRob Herring  *	-FDT_ERR_BADMAGIC,
21176f05afcbSRob Herring  *	-FDT_ERR_BADOFFSET,
21186f05afcbSRob Herring  *	-FDT_ERR_BADPATH,
21196f05afcbSRob Herring  *	-FDT_ERR_BADVERSION,
21206f05afcbSRob Herring  *	-FDT_ERR_BADSTRUCTURE,
21216f05afcbSRob Herring  *	-FDT_ERR_BADSTATE,
21226f05afcbSRob Herring  *	-FDT_ERR_TRUNCATED, standard meanings
21236f05afcbSRob Herring  */
21246f05afcbSRob Herring int fdt_overlay_apply(void *fdt, void *fdto);
21256f05afcbSRob Herring 
2126*ea3723a5SRob Herring /**
2127*ea3723a5SRob Herring  * fdt_overlay_target_offset - retrieves the offset of a fragment's target
2128*ea3723a5SRob Herring  * @fdt: Base device tree blob
2129*ea3723a5SRob Herring  * @fdto: Device tree overlay blob
2130*ea3723a5SRob Herring  * @fragment_offset: node offset of the fragment in the overlay
2131*ea3723a5SRob Herring  * @pathp: pointer which receives the path of the target (or NULL)
2132*ea3723a5SRob Herring  *
2133*ea3723a5SRob Herring  * fdt_overlay_target_offset() retrieves the target offset in the base
2134*ea3723a5SRob Herring  * device tree of a fragment, no matter how the actual targeting is
2135*ea3723a5SRob Herring  * done (through a phandle or a path)
2136*ea3723a5SRob Herring  *
2137*ea3723a5SRob Herring  * returns:
2138*ea3723a5SRob Herring  *      the targeted node offset in the base device tree
2139*ea3723a5SRob Herring  *      Negative error code on error
2140*ea3723a5SRob Herring  */
2141*ea3723a5SRob Herring int fdt_overlay_target_offset(const void *fdt, const void *fdto,
2142*ea3723a5SRob Herring 			      int fragment_offset, char const **pathp);
2143*ea3723a5SRob Herring 
21449fffb55fSDavid Gibson /**********************************************************************/
21459fffb55fSDavid Gibson /* Debugging / informational functions                                */
21469fffb55fSDavid Gibson /**********************************************************************/
21479fffb55fSDavid Gibson 
21489fffb55fSDavid Gibson const char *fdt_strerror(int errval);
21499fffb55fSDavid Gibson 
21503eb619b2SRob Herring #ifdef __cplusplus
21513eb619b2SRob Herring }
21523eb619b2SRob Herring #endif
21533eb619b2SRob Herring 
21549130ba88SRob Herring #endif /* LIBFDT_H */
2155