19537Satgutier@umich.edu/*
29537Satgutier@umich.edu * libfdt - Flat Device Tree manipulation
39537Satgutier@umich.edu * Copyright (C) 2006 David Gibson, IBM Corporation.
49537Satgutier@umich.edu *
59537Satgutier@umich.edu *     Redistribution and use in source and binary forms, with or
69537Satgutier@umich.edu *     without modification, are permitted provided that the following
79537Satgutier@umich.edu *     conditions are met:
89537Satgutier@umich.edu *
99537Satgutier@umich.edu *     1. Redistributions of source code must retain the above
109537Satgutier@umich.edu *        copyright notice, this list of conditions and the following
119537Satgutier@umich.edu *        disclaimer.
129537Satgutier@umich.edu *     2. Redistributions in binary form must reproduce the above
139537Satgutier@umich.edu *        copyright notice, this list of conditions and the following
149537Satgutier@umich.edu *        disclaimer in the documentation and/or other materials
159537Satgutier@umich.edu *        provided with the distribution.
169537Satgutier@umich.edu *
179537Satgutier@umich.edu *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
189537Satgutier@umich.edu *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
199537Satgutier@umich.edu *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
209537Satgutier@umich.edu *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
219537Satgutier@umich.edu *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
229537Satgutier@umich.edu *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
239537Satgutier@umich.edu *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
249537Satgutier@umich.edu *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
259537Satgutier@umich.edu *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
269537Satgutier@umich.edu *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
279537Satgutier@umich.edu *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
289537Satgutier@umich.edu *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
299537Satgutier@umich.edu *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
309537Satgutier@umich.edu */
319537Satgutier@umich.edu#ifndef _LIBFDT_H
329537Satgutier@umich.edu#define _LIBFDT_H
339537Satgutier@umich.edu
349537Satgutier@umich.edu#ifdef __cplusplus
359537Satgutier@umich.eduextern "C" {
369537Satgutier@umich.edu#endif
379537Satgutier@umich.edu
389537Satgutier@umich.edu#include <fdt.h>
399537Satgutier@umich.edu#include <libfdt_env.h>
409537Satgutier@umich.edu
419537Satgutier@umich.edu#define FDT_FIRST_SUPPORTED_VERSION	0x10
429537Satgutier@umich.edu#define FDT_LAST_SUPPORTED_VERSION	0x11
439537Satgutier@umich.edu
449537Satgutier@umich.edu/* Error codes: informative error codes */
459537Satgutier@umich.edu#define FDT_ERR_NOTFOUND	1
469537Satgutier@umich.edu        /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
479537Satgutier@umich.edu#define FDT_ERR_EXISTS		2
489537Satgutier@umich.edu        /* FDT_ERR_EXISTS: Attemped to create a node or property which
499537Satgutier@umich.edu         * already exists */
509537Satgutier@umich.edu#define FDT_ERR_NOSPACE		3
519537Satgutier@umich.edu        /* FDT_ERR_NOSPACE: Operation needed to expand the device
529537Satgutier@umich.edu         * tree, but its buffer did not have sufficient space to
539537Satgutier@umich.edu         * contain the expanded tree. Use fdt_open_into() to move the
549537Satgutier@umich.edu         * device tree to a buffer with more space. */
559537Satgutier@umich.edu
569537Satgutier@umich.edu/* Error codes: codes for bad parameters */
579537Satgutier@umich.edu#define FDT_ERR_BADOFFSET	4
589537Satgutier@umich.edu        /* FDT_ERR_BADOFFSET: Function was passed a structure block
599537Satgutier@umich.edu         * offset which is out-of-bounds, or which points to an
609537Satgutier@umich.edu         * unsuitable part of the structure for the operation. */
619537Satgutier@umich.edu#define FDT_ERR_BADPATH		5
629537Satgutier@umich.edu        /* FDT_ERR_BADPATH: Function was passed a badly formatted path
639537Satgutier@umich.edu         * (e.g. missing a leading / for a function which requires an
649537Satgutier@umich.edu         * absolute path) */
659537Satgutier@umich.edu#define FDT_ERR_BADPHANDLE	6
669537Satgutier@umich.edu        /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle
679537Satgutier@umich.edu         * value.  phandle values of 0 and -1 are not permitted. */
689537Satgutier@umich.edu#define FDT_ERR_BADSTATE	7
699537Satgutier@umich.edu        /* FDT_ERR_BADSTATE: Function was passed an incomplete device
709537Satgutier@umich.edu         * tree created by the sequential-write functions, which is
719537Satgutier@umich.edu         * not sufficiently complete for the requested operation. */
729537Satgutier@umich.edu
739537Satgutier@umich.edu/* Error codes: codes for bad device tree blobs */
749537Satgutier@umich.edu#define FDT_ERR_TRUNCATED	8
759537Satgutier@umich.edu        /* FDT_ERR_TRUNCATED: Structure block of the given device tree
769537Satgutier@umich.edu         * ends without an FDT_END tag. */
779537Satgutier@umich.edu#define FDT_ERR_BADMAGIC	9
789537Satgutier@umich.edu        /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
799537Satgutier@umich.edu         * device tree at all - it is missing the flattened device
809537Satgutier@umich.edu         * tree magic number. */
819537Satgutier@umich.edu#define FDT_ERR_BADVERSION	10
829537Satgutier@umich.edu        /* FDT_ERR_BADVERSION: Given device tree has a version which
839537Satgutier@umich.edu         * can't be handled by the requested operation.  For
849537Satgutier@umich.edu         * read-write functions, this may mean that fdt_open_into() is
859537Satgutier@umich.edu         * required to convert the tree to the expected version. */
869537Satgutier@umich.edu#define FDT_ERR_BADSTRUCTURE	11
879537Satgutier@umich.edu        /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
889537Satgutier@umich.edu         * structure block or other serious error (e.g. misnested
899537Satgutier@umich.edu         * nodes, or subnodes preceding properties). */
909537Satgutier@umich.edu#define FDT_ERR_BADLAYOUT	12
919537Satgutier@umich.edu        /* FDT_ERR_BADLAYOUT: For read-write functions, the given
929537Satgutier@umich.edu         * device tree has it's sub-blocks in an order that the
939537Satgutier@umich.edu         * function can't handle (memory reserve map, then structure,
949537Satgutier@umich.edu         * then strings).  Use fdt_open_into() to reorganize the tree
959537Satgutier@umich.edu         * into a form suitable for the read-write operations. */
969537Satgutier@umich.edu
979537Satgutier@umich.edu/* "Can't happen" error indicating a bug in libfdt */
989537Satgutier@umich.edu#define FDT_ERR_INTERNAL	13
999537Satgutier@umich.edu        /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
1009537Satgutier@umich.edu         * Should never be returned, if it is, it indicates a bug in
1019537Satgutier@umich.edu         * libfdt itself. */
1029537Satgutier@umich.edu
1039537Satgutier@umich.edu#define FDT_ERR_MAX		13
1049537Satgutier@umich.edu
1059537Satgutier@umich.edu/**********************************************************************/
1069537Satgutier@umich.edu/* Low-level functions (you probably don't need these)                */
1079537Satgutier@umich.edu/**********************************************************************/
1089537Satgutier@umich.edu
1099537Satgutier@umich.educonst void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
1109537Satgutier@umich.edustatic inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
1119537Satgutier@umich.edu{
1129537Satgutier@umich.edu        return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
1139537Satgutier@umich.edu}
1149537Satgutier@umich.edu
1159537Satgutier@umich.eduuint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
1169537Satgutier@umich.edu
1179537Satgutier@umich.edu/**********************************************************************/
1189537Satgutier@umich.edu/* Traversal functions                                                */
1199537Satgutier@umich.edu/**********************************************************************/
1209537Satgutier@umich.edu
1219537Satgutier@umich.eduint fdt_next_node(const void *fdt, int offset, int *depth);
1229537Satgutier@umich.edu
1239537Satgutier@umich.edu/**********************************************************************/
1249537Satgutier@umich.edu/* General functions                                                  */
1259537Satgutier@umich.edu/**********************************************************************/
1269537Satgutier@umich.edu
1279537Satgutier@umich.edu#define fdt_get_header(fdt, field) \
1289537Satgutier@umich.edu        (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
1299537Satgutier@umich.edu#define fdt_magic(fdt) 			(fdt_get_header(fdt, magic))
1309537Satgutier@umich.edu#define fdt_totalsize(fdt)		(fdt_get_header(fdt, totalsize))
1319537Satgutier@umich.edu#define fdt_off_dt_struct(fdt)		(fdt_get_header(fdt, off_dt_struct))
1329537Satgutier@umich.edu#define fdt_off_dt_strings(fdt)		(fdt_get_header(fdt, off_dt_strings))
1339537Satgutier@umich.edu#define fdt_off_mem_rsvmap(fdt)		(fdt_get_header(fdt, off_mem_rsvmap))
1349537Satgutier@umich.edu#define fdt_version(fdt)		(fdt_get_header(fdt, version))
1359537Satgutier@umich.edu#define fdt_last_comp_version(fdt) 	(fdt_get_header(fdt, last_comp_version))
1369537Satgutier@umich.edu#define fdt_boot_cpuid_phys(fdt) 	(fdt_get_header(fdt, boot_cpuid_phys))
1379537Satgutier@umich.edu#define fdt_size_dt_strings(fdt) 	(fdt_get_header(fdt, size_dt_strings))
1389537Satgutier@umich.edu#define fdt_size_dt_struct(fdt)		(fdt_get_header(fdt, size_dt_struct))
1399537Satgutier@umich.edu
1409537Satgutier@umich.edu#define __fdt_set_hdr(name) \
1419537Satgutier@umich.edu        static inline void fdt_set_##name(void *fdt, uint32_t val) \
1429537Satgutier@umich.edu        { \
1439537Satgutier@umich.edu                struct fdt_header *fdth = (struct fdt_header*)fdt; \
1449537Satgutier@umich.edu                fdth->name = cpu_to_fdt32(val); \
1459537Satgutier@umich.edu        }
1469537Satgutier@umich.edu__fdt_set_hdr(magic);
1479537Satgutier@umich.edu__fdt_set_hdr(totalsize);
1489537Satgutier@umich.edu__fdt_set_hdr(off_dt_struct);
1499537Satgutier@umich.edu__fdt_set_hdr(off_dt_strings);
1509537Satgutier@umich.edu__fdt_set_hdr(off_mem_rsvmap);
1519537Satgutier@umich.edu__fdt_set_hdr(version);
1529537Satgutier@umich.edu__fdt_set_hdr(last_comp_version);
1539537Satgutier@umich.edu__fdt_set_hdr(boot_cpuid_phys);
1549537Satgutier@umich.edu__fdt_set_hdr(size_dt_strings);
1559537Satgutier@umich.edu__fdt_set_hdr(size_dt_struct);
1569537Satgutier@umich.edu#undef __fdt_set_hdr
1579537Satgutier@umich.edu
1589537Satgutier@umich.edu/**
1599537Satgutier@umich.edu * fdt_check_header - sanity check a device tree or possible device tree
1609537Satgutier@umich.edu * @fdt: pointer to data which might be a flattened device tree
1619537Satgutier@umich.edu *
1629537Satgutier@umich.edu * fdt_check_header() checks that the given buffer contains what
1639537Satgutier@umich.edu * appears to be a flattened device tree with sane information in its
1649537Satgutier@umich.edu * header.
1659537Satgutier@umich.edu *
1669537Satgutier@umich.edu * returns:
1679537Satgutier@umich.edu *     0, if the buffer appears to contain a valid device tree
1689537Satgutier@umich.edu *     -FDT_ERR_BADMAGIC,
1699537Satgutier@umich.edu *     -FDT_ERR_BADVERSION,
1709537Satgutier@umich.edu *     -FDT_ERR_BADSTATE, standard meanings, as above
1719537Satgutier@umich.edu */
1729537Satgutier@umich.eduint fdt_check_header(const void *fdt);
1739537Satgutier@umich.edu
1749537Satgutier@umich.edu/**
1759537Satgutier@umich.edu * fdt_move - move a device tree around in memory
1769537Satgutier@umich.edu * @fdt: pointer to the device tree to move
1779537Satgutier@umich.edu * @buf: pointer to memory where the device is to be moved
1789537Satgutier@umich.edu * @bufsize: size of the memory space at buf
1799537Satgutier@umich.edu *
1809537Satgutier@umich.edu * fdt_move() relocates, if possible, the device tree blob located at
1819537Satgutier@umich.edu * fdt to the buffer at buf of size bufsize.  The buffer may overlap
1829537Satgutier@umich.edu * with the existing device tree blob at fdt.  Therefore,
1839537Satgutier@umich.edu *     fdt_move(fdt, fdt, fdt_totalsize(fdt))
1849537Satgutier@umich.edu * should always succeed.
1859537Satgutier@umich.edu *
1869537Satgutier@umich.edu * returns:
1879537Satgutier@umich.edu *     0, on success
1889537Satgutier@umich.edu *     -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
1899537Satgutier@umich.edu *     -FDT_ERR_BADMAGIC,
1909537Satgutier@umich.edu *     -FDT_ERR_BADVERSION,
1919537Satgutier@umich.edu *     -FDT_ERR_BADSTATE, standard meanings
1929537Satgutier@umich.edu */
1939537Satgutier@umich.eduint fdt_move(const void *fdt, void *buf, int bufsize);
1949537Satgutier@umich.edu
1959537Satgutier@umich.edu/**********************************************************************/
1969537Satgutier@umich.edu/* Read-only functions                                                */
1979537Satgutier@umich.edu/**********************************************************************/
1989537Satgutier@umich.edu
1999537Satgutier@umich.edu/**
2009537Satgutier@umich.edu * fdt_string - retrieve a string from the strings block of a device tree
2019537Satgutier@umich.edu * @fdt: pointer to the device tree blob
2029537Satgutier@umich.edu * @stroffset: offset of the string within the strings block (native endian)
2039537Satgutier@umich.edu *
2049537Satgutier@umich.edu * fdt_string() retrieves a pointer to a single string from the
2059537Satgutier@umich.edu * strings block of the device tree blob at fdt.
2069537Satgutier@umich.edu *
2079537Satgutier@umich.edu * returns:
2089537Satgutier@umich.edu *     a pointer to the string, on success
2099537Satgutier@umich.edu *     NULL, if stroffset is out of bounds
2109537Satgutier@umich.edu */
2119537Satgutier@umich.educonst char *fdt_string(const void *fdt, int stroffset);
2129537Satgutier@umich.edu
2139537Satgutier@umich.edu/**
2149537Satgutier@umich.edu * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
2159537Satgutier@umich.edu * @fdt: pointer to the device tree blob
2169537Satgutier@umich.edu *
2179537Satgutier@umich.edu * Returns the number of entries in the device tree blob's memory
2189537Satgutier@umich.edu * reservation map.  This does not include the terminating 0,0 entry
2199537Satgutier@umich.edu * or any other (0,0) entries reserved for expansion.
2209537Satgutier@umich.edu *
2219537Satgutier@umich.edu * returns:
2229537Satgutier@umich.edu *     the number of entries
2239537Satgutier@umich.edu */
2249537Satgutier@umich.eduint fdt_num_mem_rsv(const void *fdt);
2259537Satgutier@umich.edu
2269537Satgutier@umich.edu/**
2279537Satgutier@umich.edu * fdt_get_mem_rsv - retrieve one memory reserve map entry
2289537Satgutier@umich.edu * @fdt: pointer to the device tree blob
2299537Satgutier@umich.edu * @address, @size: pointers to 64-bit variables
2309537Satgutier@umich.edu *
2319537Satgutier@umich.edu * On success, *address and *size will contain the address and size of
2329537Satgutier@umich.edu * the n-th reserve map entry from the device tree blob, in
2339537Satgutier@umich.edu * native-endian format.
2349537Satgutier@umich.edu *
2359537Satgutier@umich.edu * returns:
2369537Satgutier@umich.edu *     0, on success
2379537Satgutier@umich.edu *     -FDT_ERR_BADMAGIC,
2389537Satgutier@umich.edu *     -FDT_ERR_BADVERSION,
2399537Satgutier@umich.edu *     -FDT_ERR_BADSTATE, standard meanings
2409537Satgutier@umich.edu */
2419537Satgutier@umich.eduint fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
2429537Satgutier@umich.edu
2439537Satgutier@umich.edu/**
2449537Satgutier@umich.edu * fdt_subnode_offset_namelen - find a subnode based on substring
2459537Satgutier@umich.edu * @fdt: pointer to the device tree blob
2469537Satgutier@umich.edu * @parentoffset: structure block offset of a node
2479537Satgutier@umich.edu * @name: name of the subnode to locate
2489537Satgutier@umich.edu * @namelen: number of characters of name to consider
2499537Satgutier@umich.edu *
2509537Satgutier@umich.edu * Identical to fdt_subnode_offset(), but only examine the first
2519537Satgutier@umich.edu * namelen characters of name for matching the subnode name.  This is
2529537Satgutier@umich.edu * useful for finding subnodes based on a portion of a larger string,
2539537Satgutier@umich.edu * such as a full path.
2549537Satgutier@umich.edu */
2559537Satgutier@umich.eduint fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
2569537Satgutier@umich.edu                               const char *name, int namelen);
2579537Satgutier@umich.edu/**
2589537Satgutier@umich.edu * fdt_subnode_offset - find a subnode of a given node
2599537Satgutier@umich.edu * @fdt: pointer to the device tree blob
2609537Satgutier@umich.edu * @parentoffset: structure block offset of a node
2619537Satgutier@umich.edu * @name: name of the subnode to locate
2629537Satgutier@umich.edu *
2639537Satgutier@umich.edu * fdt_subnode_offset() finds a subnode of the node at structure block
2649537Satgutier@umich.edu * offset parentoffset with the given name.  name may include a unit
2659537Satgutier@umich.edu * address, in which case fdt_subnode_offset() will find the subnode
2669537Satgutier@umich.edu * with that unit address, or the unit address may be omitted, in
2679537Satgutier@umich.edu * which case fdt_subnode_offset() will find an arbitrary subnode
2689537Satgutier@umich.edu * whose name excluding unit address matches the given name.
2699537Satgutier@umich.edu *
2709537Satgutier@umich.edu * returns:
2719537Satgutier@umich.edu *	structure block offset of the requested subnode (>=0), on success
2729537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
2739537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
2749537Satgutier@umich.edu *      -FDT_ERR_BADMAGIC,
2759537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
2769537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
2779537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
2789537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings.
2799537Satgutier@umich.edu */
2809537Satgutier@umich.eduint fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
2819537Satgutier@umich.edu
2829537Satgutier@umich.edu/**
2839537Satgutier@umich.edu * fdt_path_offset - find a tree node by its full path
2849537Satgutier@umich.edu * @fdt: pointer to the device tree blob
2859537Satgutier@umich.edu * @path: full path of the node to locate
2869537Satgutier@umich.edu *
2879537Satgutier@umich.edu * fdt_path_offset() finds a node of a given path in the device tree.
2889537Satgutier@umich.edu * Each path component may omit the unit address portion, but the
2899537Satgutier@umich.edu * results of this are undefined if any such path component is
2909537Satgutier@umich.edu * ambiguous (that is if there are multiple nodes at the relevant
2919537Satgutier@umich.edu * level matching the given component, differentiated only by unit
2929537Satgutier@umich.edu * address).
2939537Satgutier@umich.edu *
2949537Satgutier@umich.edu * returns:
2959537Satgutier@umich.edu *	structure block offset of the node with the requested path (>=0), on success
2969537Satgutier@umich.edu *	-FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
2979537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, if the requested node does not exist
2989537Satgutier@umich.edu *      -FDT_ERR_BADMAGIC,
2999537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
3009537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
3019537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
3029537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings.
3039537Satgutier@umich.edu */
3049537Satgutier@umich.eduint fdt_path_offset(const void *fdt, const char *path);
3059537Satgutier@umich.edu
3069537Satgutier@umich.edu/**
3079537Satgutier@umich.edu * fdt_get_name - retrieve the name of a given node
3089537Satgutier@umich.edu * @fdt: pointer to the device tree blob
3099537Satgutier@umich.edu * @nodeoffset: structure block offset of the starting node
3109537Satgutier@umich.edu * @lenp: pointer to an integer variable (will be overwritten) or NULL
3119537Satgutier@umich.edu *
3129537Satgutier@umich.edu * fdt_get_name() retrieves the name (including unit address) of the
3139537Satgutier@umich.edu * device tree node at structure block offset nodeoffset.  If lenp is
3149537Satgutier@umich.edu * non-NULL, the length of this name is also returned, in the integer
3159537Satgutier@umich.edu * pointed to by lenp.
3169537Satgutier@umich.edu *
3179537Satgutier@umich.edu * returns:
3189537Satgutier@umich.edu *	pointer to the node's name, on success
3199537Satgutier@umich.edu *		If lenp is non-NULL, *lenp contains the length of that name (>=0)
3209537Satgutier@umich.edu *	NULL, on error
3219537Satgutier@umich.edu *		if lenp is non-NULL *lenp contains an error code (<0):
3229537Satgutier@umich.edu *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
3239537Satgutier@umich.edu *		-FDT_ERR_BADMAGIC,
3249537Satgutier@umich.edu *		-FDT_ERR_BADVERSION,
3259537Satgutier@umich.edu *		-FDT_ERR_BADSTATE, standard meanings
3269537Satgutier@umich.edu */
3279537Satgutier@umich.educonst char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
3289537Satgutier@umich.edu
3299537Satgutier@umich.edu/**
3309537Satgutier@umich.edu * fdt_first_property_offset - find the offset of a node's first property
3319537Satgutier@umich.edu * @fdt: pointer to the device tree blob
3329537Satgutier@umich.edu * @nodeoffset: structure block offset of a node
3339537Satgutier@umich.edu *
3349537Satgutier@umich.edu * fdt_first_property_offset() finds the first property of the node at
3359537Satgutier@umich.edu * the given structure block offset.
3369537Satgutier@umich.edu *
3379537Satgutier@umich.edu * returns:
3389537Satgutier@umich.edu *	structure block offset of the property (>=0), on success
3399537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, if the requested node has no properties
3409537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
3419537Satgutier@umich.edu *      -FDT_ERR_BADMAGIC,
3429537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
3439537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
3449537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
3459537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings.
3469537Satgutier@umich.edu */
3479537Satgutier@umich.eduint fdt_first_property_offset(const void *fdt, int nodeoffset);
3489537Satgutier@umich.edu
3499537Satgutier@umich.edu/**
3509537Satgutier@umich.edu * fdt_next_property_offset - step through a node's properties
3519537Satgutier@umich.edu * @fdt: pointer to the device tree blob
3529537Satgutier@umich.edu * @offset: structure block offset of a property
3539537Satgutier@umich.edu *
3549537Satgutier@umich.edu * fdt_next_property_offset() finds the property immediately after the
3559537Satgutier@umich.edu * one at the given structure block offset.  This will be a property
3569537Satgutier@umich.edu * of the same node as the given property.
3579537Satgutier@umich.edu *
3589537Satgutier@umich.edu * returns:
3599537Satgutier@umich.edu *	structure block offset of the next property (>=0), on success
3609537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, if the given property is the last in its node
3619537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
3629537Satgutier@umich.edu *      -FDT_ERR_BADMAGIC,
3639537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
3649537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
3659537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
3669537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings.
3679537Satgutier@umich.edu */
3689537Satgutier@umich.eduint fdt_next_property_offset(const void *fdt, int offset);
3699537Satgutier@umich.edu
3709537Satgutier@umich.edu/**
3719537Satgutier@umich.edu * fdt_get_property_by_offset - retrieve the property at a given offset
3729537Satgutier@umich.edu * @fdt: pointer to the device tree blob
3739537Satgutier@umich.edu * @offset: offset of the property to retrieve
3749537Satgutier@umich.edu * @lenp: pointer to an integer variable (will be overwritten) or NULL
3759537Satgutier@umich.edu *
3769537Satgutier@umich.edu * fdt_get_property_by_offset() retrieves a pointer to the
3779537Satgutier@umich.edu * fdt_property structure within the device tree blob at the given
3789537Satgutier@umich.edu * offset.  If lenp is non-NULL, the length of the property value is
3799537Satgutier@umich.edu * also returned, in the integer pointed to by lenp.
3809537Satgutier@umich.edu *
3819537Satgutier@umich.edu * returns:
3829537Satgutier@umich.edu *	pointer to the structure representing the property
3839537Satgutier@umich.edu *		if lenp is non-NULL, *lenp contains the length of the property
3849537Satgutier@umich.edu *		value (>=0)
3859537Satgutier@umich.edu *	NULL, on error
3869537Satgutier@umich.edu *		if lenp is non-NULL, *lenp contains an error code (<0):
3879537Satgutier@umich.edu *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
3889537Satgutier@umich.edu *		-FDT_ERR_BADMAGIC,
3899537Satgutier@umich.edu *		-FDT_ERR_BADVERSION,
3909537Satgutier@umich.edu *		-FDT_ERR_BADSTATE,
3919537Satgutier@umich.edu *		-FDT_ERR_BADSTRUCTURE,
3929537Satgutier@umich.edu *		-FDT_ERR_TRUNCATED, standard meanings
3939537Satgutier@umich.edu */
3949537Satgutier@umich.educonst struct fdt_property *fdt_get_property_by_offset(const void *fdt,
3959537Satgutier@umich.edu                                                      int offset,
3969537Satgutier@umich.edu                                                      int *lenp);
3979537Satgutier@umich.edu
3989537Satgutier@umich.edu/**
3999537Satgutier@umich.edu * fdt_get_property_namelen - find a property based on substring
4009537Satgutier@umich.edu * @fdt: pointer to the device tree blob
4019537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to find
4029537Satgutier@umich.edu * @name: name of the property to find
4039537Satgutier@umich.edu * @namelen: number of characters of name to consider
4049537Satgutier@umich.edu * @lenp: pointer to an integer variable (will be overwritten) or NULL
4059537Satgutier@umich.edu *
4069537Satgutier@umich.edu * Identical to fdt_get_property_namelen(), but only examine the first
4079537Satgutier@umich.edu * namelen characters of name for matching the property name.
4089537Satgutier@umich.edu */
4099537Satgutier@umich.educonst struct fdt_property *fdt_get_property_namelen(const void *fdt,
4109537Satgutier@umich.edu                                                    int nodeoffset,
4119537Satgutier@umich.edu                                                    const char *name,
4129537Satgutier@umich.edu                                                    int namelen, int *lenp);
4139537Satgutier@umich.edu
4149537Satgutier@umich.edu/**
4159537Satgutier@umich.edu * fdt_get_property - find a given property in a given node
4169537Satgutier@umich.edu * @fdt: pointer to the device tree blob
4179537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to find
4189537Satgutier@umich.edu * @name: name of the property to find
4199537Satgutier@umich.edu * @lenp: pointer to an integer variable (will be overwritten) or NULL
4209537Satgutier@umich.edu *
4219537Satgutier@umich.edu * fdt_get_property() retrieves a pointer to the fdt_property
4229537Satgutier@umich.edu * structure within the device tree blob corresponding to the property
4239537Satgutier@umich.edu * named 'name' of the node at offset nodeoffset.  If lenp is
4249537Satgutier@umich.edu * non-NULL, the length of the property value is also returned, in the
4259537Satgutier@umich.edu * integer pointed to by lenp.
4269537Satgutier@umich.edu *
4279537Satgutier@umich.edu * returns:
4289537Satgutier@umich.edu *	pointer to the structure representing the property
4299537Satgutier@umich.edu *		if lenp is non-NULL, *lenp contains the length of the property
4309537Satgutier@umich.edu *		value (>=0)
4319537Satgutier@umich.edu *	NULL, on error
4329537Satgutier@umich.edu *		if lenp is non-NULL, *lenp contains an error code (<0):
4339537Satgutier@umich.edu *		-FDT_ERR_NOTFOUND, node does not have named property
4349537Satgutier@umich.edu *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
4359537Satgutier@umich.edu *		-FDT_ERR_BADMAGIC,
4369537Satgutier@umich.edu *		-FDT_ERR_BADVERSION,
4379537Satgutier@umich.edu *		-FDT_ERR_BADSTATE,
4389537Satgutier@umich.edu *		-FDT_ERR_BADSTRUCTURE,
4399537Satgutier@umich.edu *		-FDT_ERR_TRUNCATED, standard meanings
4409537Satgutier@umich.edu */
4419537Satgutier@umich.educonst struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
4429537Satgutier@umich.edu                                            const char *name, int *lenp);
4439537Satgutier@umich.edustatic inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
4449537Satgutier@umich.edu                                                      const char *name,
4459537Satgutier@umich.edu                                                      int *lenp)
4469537Satgutier@umich.edu{
4479537Satgutier@umich.edu        return (struct fdt_property *)(uintptr_t)
4489537Satgutier@umich.edu                fdt_get_property(fdt, nodeoffset, name, lenp);
4499537Satgutier@umich.edu}
4509537Satgutier@umich.edu
4519537Satgutier@umich.edu/**
4529537Satgutier@umich.edu * fdt_getprop_by_offset - retrieve the value of a property at a given offset
4539537Satgutier@umich.edu * @fdt: pointer to the device tree blob
4549537Satgutier@umich.edu * @ffset: offset of the property to read
4559537Satgutier@umich.edu * @namep: pointer to a string variable (will be overwritten) or NULL
4569537Satgutier@umich.edu * @lenp: pointer to an integer variable (will be overwritten) or NULL
4579537Satgutier@umich.edu *
4589537Satgutier@umich.edu * fdt_getprop_by_offset() retrieves a pointer to the value of the
4599537Satgutier@umich.edu * property at structure block offset 'offset' (this will be a pointer
4609537Satgutier@umich.edu * to within the device blob itself, not a copy of the value).  If
4619537Satgutier@umich.edu * lenp is non-NULL, the length of the property value is also
4629537Satgutier@umich.edu * returned, in the integer pointed to by lenp.  If namep is non-NULL,
4639537Satgutier@umich.edu * the property's namne will also be returned in the char * pointed to
4649537Satgutier@umich.edu * by namep (this will be a pointer to within the device tree's string
4659537Satgutier@umich.edu * block, not a new copy of the name).
4669537Satgutier@umich.edu *
4679537Satgutier@umich.edu * returns:
4689537Satgutier@umich.edu *	pointer to the property's value
4699537Satgutier@umich.edu *		if lenp is non-NULL, *lenp contains the length of the property
4709537Satgutier@umich.edu *		value (>=0)
4719537Satgutier@umich.edu *		if namep is non-NULL *namep contiains a pointer to the property
4729537Satgutier@umich.edu *		name.
4739537Satgutier@umich.edu *	NULL, on error
4749537Satgutier@umich.edu *		if lenp is non-NULL, *lenp contains an error code (<0):
4759537Satgutier@umich.edu *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
4769537Satgutier@umich.edu *		-FDT_ERR_BADMAGIC,
4779537Satgutier@umich.edu *		-FDT_ERR_BADVERSION,
4789537Satgutier@umich.edu *		-FDT_ERR_BADSTATE,
4799537Satgutier@umich.edu *		-FDT_ERR_BADSTRUCTURE,
4809537Satgutier@umich.edu *		-FDT_ERR_TRUNCATED, standard meanings
4819537Satgutier@umich.edu */
4829537Satgutier@umich.educonst void *fdt_getprop_by_offset(const void *fdt, int offset,
4839537Satgutier@umich.edu                                  const char **namep, int *lenp);
4849537Satgutier@umich.edu
4859537Satgutier@umich.edu/**
4869537Satgutier@umich.edu * fdt_getprop_namelen - get property value based on substring
4879537Satgutier@umich.edu * @fdt: pointer to the device tree blob
4889537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to find
4899537Satgutier@umich.edu * @name: name of the property to find
4909537Satgutier@umich.edu * @namelen: number of characters of name to consider
4919537Satgutier@umich.edu * @lenp: pointer to an integer variable (will be overwritten) or NULL
4929537Satgutier@umich.edu *
4939537Satgutier@umich.edu * Identical to fdt_getprop(), but only examine the first namelen
4949537Satgutier@umich.edu * characters of name for matching the property name.
4959537Satgutier@umich.edu */
4969537Satgutier@umich.educonst void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
4979537Satgutier@umich.edu                                const char *name, int namelen, int *lenp);
4989537Satgutier@umich.edu
4999537Satgutier@umich.edu/**
5009537Satgutier@umich.edu * fdt_getprop - retrieve the value of a given property
5019537Satgutier@umich.edu * @fdt: pointer to the device tree blob
5029537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to find
5039537Satgutier@umich.edu * @name: name of the property to find
5049537Satgutier@umich.edu * @lenp: pointer to an integer variable (will be overwritten) or NULL
5059537Satgutier@umich.edu *
5069537Satgutier@umich.edu * fdt_getprop() retrieves a pointer to the value of the property
5079537Satgutier@umich.edu * named 'name' of the node at offset nodeoffset (this will be a
5089537Satgutier@umich.edu * pointer to within the device blob itself, not a copy of the value).
5099537Satgutier@umich.edu * If lenp is non-NULL, the length of the property value is also
5109537Satgutier@umich.edu * returned, in the integer pointed to by lenp.
5119537Satgutier@umich.edu *
5129537Satgutier@umich.edu * returns:
5139537Satgutier@umich.edu *	pointer to the property's value
5149537Satgutier@umich.edu *		if lenp is non-NULL, *lenp contains the length of the property
5159537Satgutier@umich.edu *		value (>=0)
5169537Satgutier@umich.edu *	NULL, on error
5179537Satgutier@umich.edu *		if lenp is non-NULL, *lenp contains an error code (<0):
5189537Satgutier@umich.edu *		-FDT_ERR_NOTFOUND, node does not have named property
5199537Satgutier@umich.edu *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
5209537Satgutier@umich.edu *		-FDT_ERR_BADMAGIC,
5219537Satgutier@umich.edu *		-FDT_ERR_BADVERSION,
5229537Satgutier@umich.edu *		-FDT_ERR_BADSTATE,
5239537Satgutier@umich.edu *		-FDT_ERR_BADSTRUCTURE,
5249537Satgutier@umich.edu *		-FDT_ERR_TRUNCATED, standard meanings
5259537Satgutier@umich.edu */
5269537Satgutier@umich.educonst void *fdt_getprop(const void *fdt, int nodeoffset,
5279537Satgutier@umich.edu                        const char *name, int *lenp);
5289537Satgutier@umich.edustatic inline void *fdt_getprop_w(void *fdt, int nodeoffset,
5299537Satgutier@umich.edu                                  const char *name, int *lenp)
5309537Satgutier@umich.edu{
5319537Satgutier@umich.edu        return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
5329537Satgutier@umich.edu}
5339537Satgutier@umich.edu
5349537Satgutier@umich.edu/**
5359537Satgutier@umich.edu * fdt_get_phandle - retrieve the phandle of a given node
5369537Satgutier@umich.edu * @fdt: pointer to the device tree blob
5379537Satgutier@umich.edu * @nodeoffset: structure block offset of the node
5389537Satgutier@umich.edu *
5399537Satgutier@umich.edu * fdt_get_phandle() retrieves the phandle of the device tree node at
5409537Satgutier@umich.edu * structure block offset nodeoffset.
5419537Satgutier@umich.edu *
5429537Satgutier@umich.edu * returns:
5439537Satgutier@umich.edu *	the phandle of the node at nodeoffset, on success (!= 0, != -1)
5449537Satgutier@umich.edu *	0, if the node has no phandle, or another error occurs
5459537Satgutier@umich.edu */
5469537Satgutier@umich.eduuint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
5479537Satgutier@umich.edu
5489537Satgutier@umich.edu/**
5499537Satgutier@umich.edu * fdt_get_alias_namelen - get alias based on substring
5509537Satgutier@umich.edu * @fdt: pointer to the device tree blob
5519537Satgutier@umich.edu * @name: name of the alias th look up
5529537Satgutier@umich.edu * @namelen: number of characters of name to consider
5539537Satgutier@umich.edu *
5549537Satgutier@umich.edu * Identical to fdt_get_alias(), but only examine the first namelen
5559537Satgutier@umich.edu * characters of name for matching the alias name.
5569537Satgutier@umich.edu */
5579537Satgutier@umich.educonst char *fdt_get_alias_namelen(const void *fdt,
5589537Satgutier@umich.edu                                  const char *name, int namelen);
5599537Satgutier@umich.edu
5609537Satgutier@umich.edu/**
5619537Satgutier@umich.edu * fdt_get_alias - retreive the path referenced by a given alias
5629537Satgutier@umich.edu * @fdt: pointer to the device tree blob
5639537Satgutier@umich.edu * @name: name of the alias th look up
5649537Satgutier@umich.edu *
5659537Satgutier@umich.edu * fdt_get_alias() retrieves the value of a given alias.  That is, the
5669537Satgutier@umich.edu * value of the property named 'name' in the node /aliases.
5679537Satgutier@umich.edu *
5689537Satgutier@umich.edu * returns:
5699537Satgutier@umich.edu *	a pointer to the expansion of the alias named 'name', of it exists
5709537Satgutier@umich.edu *	NULL, if the given alias or the /aliases node does not exist
5719537Satgutier@umich.edu */
5729537Satgutier@umich.educonst char *fdt_get_alias(const void *fdt, const char *name);
5739537Satgutier@umich.edu
5749537Satgutier@umich.edu/**
5759537Satgutier@umich.edu * fdt_get_path - determine the full path of a node
5769537Satgutier@umich.edu * @fdt: pointer to the device tree blob
5779537Satgutier@umich.edu * @nodeoffset: offset of the node whose path to find
5789537Satgutier@umich.edu * @buf: character buffer to contain the returned path (will be overwritten)
5799537Satgutier@umich.edu * @buflen: size of the character buffer at buf
5809537Satgutier@umich.edu *
5819537Satgutier@umich.edu * fdt_get_path() computes the full path of the node at offset
5829537Satgutier@umich.edu * nodeoffset, and records that path in the buffer at buf.
5839537Satgutier@umich.edu *
5849537Satgutier@umich.edu * NOTE: This function is expensive, as it must scan the device tree
5859537Satgutier@umich.edu * structure from the start to nodeoffset.
5869537Satgutier@umich.edu *
5879537Satgutier@umich.edu * returns:
5889537Satgutier@umich.edu *	0, on success
5899537Satgutier@umich.edu *		buf contains the absolute path of the node at
5909537Satgutier@umich.edu *		nodeoffset, as a NUL-terminated string.
5919537Satgutier@umich.edu * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
5929537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
5939537Satgutier@umich.edu *		characters and will not fit in the given buffer.
5949537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
5959537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
5969537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
5979537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE, standard meanings
5989537Satgutier@umich.edu */
5999537Satgutier@umich.eduint fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
6009537Satgutier@umich.edu
6019537Satgutier@umich.edu/**
6029537Satgutier@umich.edu * fdt_supernode_atdepth_offset - find a specific ancestor of a node
6039537Satgutier@umich.edu * @fdt: pointer to the device tree blob
6049537Satgutier@umich.edu * @nodeoffset: offset of the node whose parent to find
6059537Satgutier@umich.edu * @supernodedepth: depth of the ancestor to find
6069537Satgutier@umich.edu * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
6079537Satgutier@umich.edu *
6089537Satgutier@umich.edu * fdt_supernode_atdepth_offset() finds an ancestor of the given node
6099537Satgutier@umich.edu * at a specific depth from the root (where the root itself has depth
6109537Satgutier@umich.edu * 0, its immediate subnodes depth 1 and so forth).  So
6119537Satgutier@umich.edu *	fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
6129537Satgutier@umich.edu * will always return 0, the offset of the root node.  If the node at
6139537Satgutier@umich.edu * nodeoffset has depth D, then:
6149537Satgutier@umich.edu *	fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
6159537Satgutier@umich.edu * will return nodeoffset itself.
6169537Satgutier@umich.edu *
6179537Satgutier@umich.edu * NOTE: This function is expensive, as it must scan the device tree
6189537Satgutier@umich.edu * structure from the start to nodeoffset.
6199537Satgutier@umich.edu *
6209537Satgutier@umich.edu * returns:
6219537Satgutier@umich.edu
6229537Satgutier@umich.edu *	structure block offset of the node at node offset's ancestor
6239537Satgutier@umich.edu *		of depth supernodedepth (>=0), on success
6249537Satgutier@umich.edu * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
6259537Satgutier@umich.edu*	-FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset
6269537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
6279537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
6289537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
6299537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE, standard meanings
6309537Satgutier@umich.edu */
6319537Satgutier@umich.eduint fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
6329537Satgutier@umich.edu                                 int supernodedepth, int *nodedepth);
6339537Satgutier@umich.edu
6349537Satgutier@umich.edu/**
6359537Satgutier@umich.edu * fdt_node_depth - find the depth of a given node
6369537Satgutier@umich.edu * @fdt: pointer to the device tree blob
6379537Satgutier@umich.edu * @nodeoffset: offset of the node whose parent to find
6389537Satgutier@umich.edu *
6399537Satgutier@umich.edu * fdt_node_depth() finds the depth of a given node.  The root node
6409537Satgutier@umich.edu * has depth 0, its immediate subnodes depth 1 and so forth.
6419537Satgutier@umich.edu *
6429537Satgutier@umich.edu * NOTE: This function is expensive, as it must scan the device tree
6439537Satgutier@umich.edu * structure from the start to nodeoffset.
6449537Satgutier@umich.edu *
6459537Satgutier@umich.edu * returns:
6469537Satgutier@umich.edu *	depth of the node at nodeoffset (>=0), on success
6479537Satgutier@umich.edu * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
6489537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
6499537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
6509537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
6519537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE, standard meanings
6529537Satgutier@umich.edu */
6539537Satgutier@umich.eduint fdt_node_depth(const void *fdt, int nodeoffset);
6549537Satgutier@umich.edu
6559537Satgutier@umich.edu/**
6569537Satgutier@umich.edu * fdt_parent_offset - find the parent of a given node
6579537Satgutier@umich.edu * @fdt: pointer to the device tree blob
6589537Satgutier@umich.edu * @nodeoffset: offset of the node whose parent to find
6599537Satgutier@umich.edu *
6609537Satgutier@umich.edu * fdt_parent_offset() locates the parent node of a given node (that
6619537Satgutier@umich.edu * is, it finds the offset of the node which contains the node at
6629537Satgutier@umich.edu * nodeoffset as a subnode).
6639537Satgutier@umich.edu *
6649537Satgutier@umich.edu * NOTE: This function is expensive, as it must scan the device tree
6659537Satgutier@umich.edu * structure from the start to nodeoffset, *twice*.
6669537Satgutier@umich.edu *
6679537Satgutier@umich.edu * returns:
6689537Satgutier@umich.edu *	structure block offset of the parent of the node at nodeoffset
6699537Satgutier@umich.edu *		(>=0), on success
6709537Satgutier@umich.edu * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
6719537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
6729537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
6739537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
6749537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE, standard meanings
6759537Satgutier@umich.edu */
6769537Satgutier@umich.eduint fdt_parent_offset(const void *fdt, int nodeoffset);
6779537Satgutier@umich.edu
6789537Satgutier@umich.edu/**
6799537Satgutier@umich.edu * fdt_node_offset_by_prop_value - find nodes with a given property value
6809537Satgutier@umich.edu * @fdt: pointer to the device tree blob
6819537Satgutier@umich.edu * @startoffset: only find nodes after this offset
6829537Satgutier@umich.edu * @propname: property name to check
6839537Satgutier@umich.edu * @propval: property value to search for
6849537Satgutier@umich.edu * @proplen: length of the value in propval
6859537Satgutier@umich.edu *
6869537Satgutier@umich.edu * fdt_node_offset_by_prop_value() returns the offset of the first
6879537Satgutier@umich.edu * node after startoffset, which has a property named propname whose
6889537Satgutier@umich.edu * value is of length proplen and has value equal to propval; or if
6899537Satgutier@umich.edu * startoffset is -1, the very first such node in the tree.
6909537Satgutier@umich.edu *
6919537Satgutier@umich.edu * To iterate through all nodes matching the criterion, the following
6929537Satgutier@umich.edu * idiom can be used:
6939537Satgutier@umich.edu *	offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
6949537Satgutier@umich.edu *					       propval, proplen);
6959537Satgutier@umich.edu *	while (offset != -FDT_ERR_NOTFOUND) {
6969537Satgutier@umich.edu *		// other code here
6979537Satgutier@umich.edu *		offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
6989537Satgutier@umich.edu *						       propval, proplen);
6999537Satgutier@umich.edu *	}
7009537Satgutier@umich.edu *
7019537Satgutier@umich.edu * Note the -1 in the first call to the function, if 0 is used here
7029537Satgutier@umich.edu * instead, the function will never locate the root node, even if it
7039537Satgutier@umich.edu * matches the criterion.
7049537Satgutier@umich.edu *
7059537Satgutier@umich.edu * returns:
7069537Satgutier@umich.edu *	structure block offset of the located node (>= 0, >startoffset),
7079537Satgutier@umich.edu *		 on success
7089537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, no node matching the criterion exists in the
7099537Satgutier@umich.edu *		tree after startoffset
7109537Satgutier@umich.edu * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
7119537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
7129537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
7139537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
7149537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE, standard meanings
7159537Satgutier@umich.edu */
7169537Satgutier@umich.eduint fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
7179537Satgutier@umich.edu                                  const char *propname,
7189537Satgutier@umich.edu                                  const void *propval, int proplen);
7199537Satgutier@umich.edu
7209537Satgutier@umich.edu/**
7219537Satgutier@umich.edu * fdt_node_offset_by_phandle - find the node with a given phandle
7229537Satgutier@umich.edu * @fdt: pointer to the device tree blob
7239537Satgutier@umich.edu * @phandle: phandle value
7249537Satgutier@umich.edu *
7259537Satgutier@umich.edu * fdt_node_offset_by_phandle() returns the offset of the node
7269537Satgutier@umich.edu * which has the given phandle value.  If there is more than one node
7279537Satgutier@umich.edu * in the tree with the given phandle (an invalid tree), results are
7289537Satgutier@umich.edu * undefined.
7299537Satgutier@umich.edu *
7309537Satgutier@umich.edu * returns:
7319537Satgutier@umich.edu *	structure block offset of the located node (>= 0), on success
7329537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, no node with that phandle exists
7339537Satgutier@umich.edu *	-FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
7349537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
7359537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
7369537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
7379537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE, standard meanings
7389537Satgutier@umich.edu */
7399537Satgutier@umich.eduint fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
7409537Satgutier@umich.edu
7419537Satgutier@umich.edu/**
7429537Satgutier@umich.edu * fdt_node_check_compatible: check a node's compatible property
7439537Satgutier@umich.edu * @fdt: pointer to the device tree blob
7449537Satgutier@umich.edu * @nodeoffset: offset of a tree node
7459537Satgutier@umich.edu * @compatible: string to match against
7469537Satgutier@umich.edu *
7479537Satgutier@umich.edu *
7489537Satgutier@umich.edu * fdt_node_check_compatible() returns 0 if the given node contains a
7499537Satgutier@umich.edu * 'compatible' property with the given string as one of its elements,
7509537Satgutier@umich.edu * it returns non-zero otherwise, or on error.
7519537Satgutier@umich.edu *
7529537Satgutier@umich.edu * returns:
7539537Satgutier@umich.edu *	0, if the node has a 'compatible' property listing the given string
7549537Satgutier@umich.edu *	1, if the node has a 'compatible' property, but it does not list
7559537Satgutier@umich.edu *		the given string
7569537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
7579537Satgutier@umich.edu * 	-FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
7589537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
7599537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
7609537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
7619537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE, standard meanings
7629537Satgutier@umich.edu */
7639537Satgutier@umich.eduint fdt_node_check_compatible(const void *fdt, int nodeoffset,
7649537Satgutier@umich.edu                              const char *compatible);
7659537Satgutier@umich.edu
7669537Satgutier@umich.edu/**
7679537Satgutier@umich.edu * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
7689537Satgutier@umich.edu * @fdt: pointer to the device tree blob
7699537Satgutier@umich.edu * @startoffset: only find nodes after this offset
7709537Satgutier@umich.edu * @compatible: 'compatible' string to match against
7719537Satgutier@umich.edu *
7729537Satgutier@umich.edu * fdt_node_offset_by_compatible() returns the offset of the first
7739537Satgutier@umich.edu * node after startoffset, which has a 'compatible' property which
7749537Satgutier@umich.edu * lists the given compatible string; or if startoffset is -1, the
7759537Satgutier@umich.edu * very first such node in the tree.
7769537Satgutier@umich.edu *
7779537Satgutier@umich.edu * To iterate through all nodes matching the criterion, the following
7789537Satgutier@umich.edu * idiom can be used:
7799537Satgutier@umich.edu *	offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
7809537Satgutier@umich.edu *	while (offset != -FDT_ERR_NOTFOUND) {
7819537Satgutier@umich.edu *		// other code here
7829537Satgutier@umich.edu *		offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
7839537Satgutier@umich.edu *	}
7849537Satgutier@umich.edu *
7859537Satgutier@umich.edu * Note the -1 in the first call to the function, if 0 is used here
7869537Satgutier@umich.edu * instead, the function will never locate the root node, even if it
7879537Satgutier@umich.edu * matches the criterion.
7889537Satgutier@umich.edu *
7899537Satgutier@umich.edu * returns:
7909537Satgutier@umich.edu *	structure block offset of the located node (>= 0, >startoffset),
7919537Satgutier@umich.edu *		 on success
7929537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, no node matching the criterion exists in the
7939537Satgutier@umich.edu *		tree after startoffset
7949537Satgutier@umich.edu * 	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
7959537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
7969537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
7979537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
7989537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE, standard meanings
7999537Satgutier@umich.edu */
8009537Satgutier@umich.eduint fdt_node_offset_by_compatible(const void *fdt, int startoffset,
8019537Satgutier@umich.edu                                  const char *compatible);
8029537Satgutier@umich.edu
8039537Satgutier@umich.edu/**********************************************************************/
8049537Satgutier@umich.edu/* Write-in-place functions                                           */
8059537Satgutier@umich.edu/**********************************************************************/
8069537Satgutier@umich.edu
8079537Satgutier@umich.edu/**
8089537Satgutier@umich.edu * fdt_setprop_inplace - change a property's value, but not its size
8099537Satgutier@umich.edu * @fdt: pointer to the device tree blob
8109537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
8119537Satgutier@umich.edu * @name: name of the property to change
8129537Satgutier@umich.edu * @val: pointer to data to replace the property value with
8139537Satgutier@umich.edu * @len: length of the property value
8149537Satgutier@umich.edu *
8159537Satgutier@umich.edu * fdt_setprop_inplace() replaces the value of a given property with
8169537Satgutier@umich.edu * the data in val, of length len.  This function cannot change the
8179537Satgutier@umich.edu * size of a property, and so will only work if len is equal to the
8189537Satgutier@umich.edu * current length of the property.
8199537Satgutier@umich.edu *
8209537Satgutier@umich.edu * This function will alter only the bytes in the blob which contain
8219537Satgutier@umich.edu * the given property value, and will not alter or move any other part
8229537Satgutier@umich.edu * of the tree.
8239537Satgutier@umich.edu *
8249537Satgutier@umich.edu * returns:
8259537Satgutier@umich.edu *	0, on success
8269537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, if len is not equal to the property's current length
8279537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, node does not have the named property
8289537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
8299537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
8309537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
8319537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
8329537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
8339537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
8349537Satgutier@umich.edu */
8359537Satgutier@umich.eduint fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
8369537Satgutier@umich.edu                        const void *val, int len);
8379537Satgutier@umich.edu
8389537Satgutier@umich.edu/**
8399537Satgutier@umich.edu * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
8409537Satgutier@umich.edu * @fdt: pointer to the device tree blob
8419537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
8429537Satgutier@umich.edu * @name: name of the property to change
8439537Satgutier@umich.edu * @val: 32-bit integer value to replace the property with
8449537Satgutier@umich.edu *
8459537Satgutier@umich.edu * fdt_setprop_inplace_u32() replaces the value of a given property
8469537Satgutier@umich.edu * with the 32-bit integer value in val, converting val to big-endian
8479537Satgutier@umich.edu * if necessary.  This function cannot change the size of a property,
8489537Satgutier@umich.edu * and so will only work if the property already exists and has length
8499537Satgutier@umich.edu * 4.
8509537Satgutier@umich.edu *
8519537Satgutier@umich.edu * This function will alter only the bytes in the blob which contain
8529537Satgutier@umich.edu * the given property value, and will not alter or move any other part
8539537Satgutier@umich.edu * of the tree.
8549537Satgutier@umich.edu *
8559537Satgutier@umich.edu * returns:
8569537Satgutier@umich.edu *	0, on success
8579537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, if the property's length is not equal to 4
8589537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, node does not have the named property
8599537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
8609537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
8619537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
8629537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
8639537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
8649537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
8659537Satgutier@umich.edu */
8669537Satgutier@umich.edustatic inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
8679537Satgutier@umich.edu                                          const char *name, uint32_t val)
8689537Satgutier@umich.edu{
8699537Satgutier@umich.edu        fdt32_t tmp = cpu_to_fdt32(val);
8709537Satgutier@umich.edu        return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
8719537Satgutier@umich.edu}
8729537Satgutier@umich.edu
8739537Satgutier@umich.edu/**
8749537Satgutier@umich.edu * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
8759537Satgutier@umich.edu * @fdt: pointer to the device tree blob
8769537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
8779537Satgutier@umich.edu * @name: name of the property to change
8789537Satgutier@umich.edu * @val: 64-bit integer value to replace the property with
8799537Satgutier@umich.edu *
8809537Satgutier@umich.edu * fdt_setprop_inplace_u64() replaces the value of a given property
8819537Satgutier@umich.edu * with the 64-bit integer value in val, converting val to big-endian
8829537Satgutier@umich.edu * if necessary.  This function cannot change the size of a property,
8839537Satgutier@umich.edu * and so will only work if the property already exists and has length
8849537Satgutier@umich.edu * 8.
8859537Satgutier@umich.edu *
8869537Satgutier@umich.edu * This function will alter only the bytes in the blob which contain
8879537Satgutier@umich.edu * the given property value, and will not alter or move any other part
8889537Satgutier@umich.edu * of the tree.
8899537Satgutier@umich.edu *
8909537Satgutier@umich.edu * returns:
8919537Satgutier@umich.edu *	0, on success
8929537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, if the property's length is not equal to 8
8939537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, node does not have the named property
8949537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
8959537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
8969537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
8979537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
8989537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
8999537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
9009537Satgutier@umich.edu */
9019537Satgutier@umich.edustatic inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
9029537Satgutier@umich.edu                                          const char *name, uint64_t val)
9039537Satgutier@umich.edu{
9049537Satgutier@umich.edu        fdt64_t tmp = cpu_to_fdt64(val);
9059537Satgutier@umich.edu        return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
9069537Satgutier@umich.edu}
9079537Satgutier@umich.edu
9089537Satgutier@umich.edu/**
9099537Satgutier@umich.edu * fdt_setprop_inplace_cell - change the value of a single-cell property
9109537Satgutier@umich.edu *
9119537Satgutier@umich.edu * This is an alternative name for fdt_setprop_inplace_u32()
9129537Satgutier@umich.edu */
9139537Satgutier@umich.edustatic inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
9149537Satgutier@umich.edu                                           const char *name, uint32_t val)
9159537Satgutier@umich.edu{
9169537Satgutier@umich.edu        return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
9179537Satgutier@umich.edu}
9189537Satgutier@umich.edu
9199537Satgutier@umich.edu/**
9209537Satgutier@umich.edu * fdt_nop_property - replace a property with nop tags
9219537Satgutier@umich.edu * @fdt: pointer to the device tree blob
9229537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to nop
9239537Satgutier@umich.edu * @name: name of the property to nop
9249537Satgutier@umich.edu *
9259537Satgutier@umich.edu * fdt_nop_property() will replace a given property's representation
9269537Satgutier@umich.edu * in the blob with FDT_NOP tags, effectively removing it from the
9279537Satgutier@umich.edu * tree.
9289537Satgutier@umich.edu *
9299537Satgutier@umich.edu * This function will alter only the bytes in the blob which contain
9309537Satgutier@umich.edu * the property, and will not alter or move any other part of the
9319537Satgutier@umich.edu * tree.
9329537Satgutier@umich.edu *
9339537Satgutier@umich.edu * returns:
9349537Satgutier@umich.edu *	0, on success
9359537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, node does not have the named property
9369537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
9379537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
9389537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
9399537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
9409537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
9419537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
9429537Satgutier@umich.edu */
9439537Satgutier@umich.eduint fdt_nop_property(void *fdt, int nodeoffset, const char *name);
9449537Satgutier@umich.edu
9459537Satgutier@umich.edu/**
9469537Satgutier@umich.edu * fdt_nop_node - replace a node (subtree) with nop tags
9479537Satgutier@umich.edu * @fdt: pointer to the device tree blob
9489537Satgutier@umich.edu * @nodeoffset: offset of the node to nop
9499537Satgutier@umich.edu *
9509537Satgutier@umich.edu * fdt_nop_node() will replace a given node's representation in the
9519537Satgutier@umich.edu * blob, including all its subnodes, if any, with FDT_NOP tags,
9529537Satgutier@umich.edu * effectively removing it from the tree.
9539537Satgutier@umich.edu *
9549537Satgutier@umich.edu * This function will alter only the bytes in the blob which contain
9559537Satgutier@umich.edu * the node and its properties and subnodes, and will not alter or
9569537Satgutier@umich.edu * move any other part of the tree.
9579537Satgutier@umich.edu *
9589537Satgutier@umich.edu * returns:
9599537Satgutier@umich.edu *	0, on success
9609537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
9619537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
9629537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
9639537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
9649537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
9659537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
9669537Satgutier@umich.edu */
9679537Satgutier@umich.eduint fdt_nop_node(void *fdt, int nodeoffset);
9689537Satgutier@umich.edu
9699537Satgutier@umich.edu/**********************************************************************/
9709537Satgutier@umich.edu/* Sequential write functions                                         */
9719537Satgutier@umich.edu/**********************************************************************/
9729537Satgutier@umich.edu
9739537Satgutier@umich.eduint fdt_create(void *buf, int bufsize);
9749537Satgutier@umich.eduint fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
9759537Satgutier@umich.eduint fdt_finish_reservemap(void *fdt);
9769537Satgutier@umich.eduint fdt_begin_node(void *fdt, const char *name);
9779537Satgutier@umich.eduint fdt_property(void *fdt, const char *name, const void *val, int len);
9789537Satgutier@umich.edustatic inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
9799537Satgutier@umich.edu{
9809537Satgutier@umich.edu        fdt32_t tmp = cpu_to_fdt32(val);
9819537Satgutier@umich.edu        return fdt_property(fdt, name, &tmp, sizeof(tmp));
9829537Satgutier@umich.edu}
9839537Satgutier@umich.edustatic inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
9849537Satgutier@umich.edu{
9859537Satgutier@umich.edu        fdt64_t tmp = cpu_to_fdt64(val);
9869537Satgutier@umich.edu        return fdt_property(fdt, name, &tmp, sizeof(tmp));
9879537Satgutier@umich.edu}
9889537Satgutier@umich.edustatic inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
9899537Satgutier@umich.edu{
9909537Satgutier@umich.edu        return fdt_property_u32(fdt, name, val);
9919537Satgutier@umich.edu}
9929537Satgutier@umich.edu#define fdt_property_string(fdt, name, str) \
9939537Satgutier@umich.edu        fdt_property(fdt, name, str, strlen(str)+1)
9949537Satgutier@umich.eduint fdt_end_node(void *fdt);
9959537Satgutier@umich.eduint fdt_finish(void *fdt);
9969537Satgutier@umich.edu
9979537Satgutier@umich.edu/**********************************************************************/
9989537Satgutier@umich.edu/* Read-write functions                                               */
9999537Satgutier@umich.edu/**********************************************************************/
10009537Satgutier@umich.edu
10019537Satgutier@umich.eduint fdt_create_empty_tree(void *buf, int bufsize);
10029537Satgutier@umich.eduint fdt_open_into(const void *fdt, void *buf, int bufsize);
10039537Satgutier@umich.eduint fdt_pack(void *fdt);
10049537Satgutier@umich.edu
10059537Satgutier@umich.edu/**
10069537Satgutier@umich.edu * fdt_add_mem_rsv - add one memory reserve map entry
10079537Satgutier@umich.edu * @fdt: pointer to the device tree blob
10089537Satgutier@umich.edu * @address, @size: 64-bit values (native endian)
10099537Satgutier@umich.edu *
10109537Satgutier@umich.edu * Adds a reserve map entry to the given blob reserving a region at
10119537Satgutier@umich.edu * address address of length size.
10129537Satgutier@umich.edu *
10139537Satgutier@umich.edu * This function will insert data into the reserve map and will
10149537Satgutier@umich.edu * therefore change the indexes of some entries in the table.
10159537Satgutier@umich.edu *
10169537Satgutier@umich.edu * returns:
10179537Satgutier@umich.edu *	0, on success
10189537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
10199537Satgutier@umich.edu *		contain the new reservation entry
10209537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
10219537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
10229537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
10239537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
10249537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
10259537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
10269537Satgutier@umich.edu */
10279537Satgutier@umich.eduint fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
10289537Satgutier@umich.edu
10299537Satgutier@umich.edu/**
10309537Satgutier@umich.edu * fdt_del_mem_rsv - remove a memory reserve map entry
10319537Satgutier@umich.edu * @fdt: pointer to the device tree blob
10329537Satgutier@umich.edu * @n: entry to remove
10339537Satgutier@umich.edu *
10349537Satgutier@umich.edu * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
10359537Satgutier@umich.edu * the blob.
10369537Satgutier@umich.edu *
10379537Satgutier@umich.edu * This function will delete data from the reservation table and will
10389537Satgutier@umich.edu * therefore change the indexes of some entries in the table.
10399537Satgutier@umich.edu *
10409537Satgutier@umich.edu * returns:
10419537Satgutier@umich.edu *	0, on success
10429537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
10439537Satgutier@umich.edu *		are less than n+1 reserve map entries)
10449537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
10459537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
10469537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
10479537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
10489537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
10499537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
10509537Satgutier@umich.edu */
10519537Satgutier@umich.eduint fdt_del_mem_rsv(void *fdt, int n);
10529537Satgutier@umich.edu
10539537Satgutier@umich.edu/**
10549537Satgutier@umich.edu * fdt_set_name - change the name of a given node
10559537Satgutier@umich.edu * @fdt: pointer to the device tree blob
10569537Satgutier@umich.edu * @nodeoffset: structure block offset of a node
10579537Satgutier@umich.edu * @name: name to give the node
10589537Satgutier@umich.edu *
10599537Satgutier@umich.edu * fdt_set_name() replaces the name (including unit address, if any)
10609537Satgutier@umich.edu * of the given node with the given string.  NOTE: this function can't
10619537Satgutier@umich.edu * efficiently check if the new name is unique amongst the given
10629537Satgutier@umich.edu * node's siblings; results are undefined if this function is invoked
10639537Satgutier@umich.edu * with a name equal to one of the given node's siblings.
10649537Satgutier@umich.edu *
10659537Satgutier@umich.edu * This function may insert or delete data from the blob, and will
10669537Satgutier@umich.edu * therefore change the offsets of some existing nodes.
10679537Satgutier@umich.edu *
10689537Satgutier@umich.edu * returns:
10699537Satgutier@umich.edu *	0, on success
10709537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob
10719537Satgutier@umich.edu *		to contain the new name
10729537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
10739537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
10749537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
10759537Satgutier@umich.edu *	-FDT_ERR_BADSTATE, standard meanings
10769537Satgutier@umich.edu */
10779537Satgutier@umich.eduint fdt_set_name(void *fdt, int nodeoffset, const char *name);
10789537Satgutier@umich.edu
10799537Satgutier@umich.edu/**
10809537Satgutier@umich.edu * fdt_setprop - create or change a property
10819537Satgutier@umich.edu * @fdt: pointer to the device tree blob
10829537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
10839537Satgutier@umich.edu * @name: name of the property to change
10849537Satgutier@umich.edu * @val: pointer to data to set the property value to
10859537Satgutier@umich.edu * @len: length of the property value
10869537Satgutier@umich.edu *
10879537Satgutier@umich.edu * fdt_setprop() sets the value of the named property in the given
10889537Satgutier@umich.edu * node to the given value and length, creating the property if it
10899537Satgutier@umich.edu * does not already exist.
10909537Satgutier@umich.edu *
10919537Satgutier@umich.edu * This function may insert or delete data from the blob, and will
10929537Satgutier@umich.edu * therefore change the offsets of some existing nodes.
10939537Satgutier@umich.edu *
10949537Satgutier@umich.edu * returns:
10959537Satgutier@umich.edu *	0, on success
10969537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
10979537Satgutier@umich.edu *		contain the new property value
10989537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
10999537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
11009537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
11019537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
11029537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
11039537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
11049537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
11059537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
11069537Satgutier@umich.edu */
11079537Satgutier@umich.eduint fdt_setprop(void *fdt, int nodeoffset, const char *name,
11089537Satgutier@umich.edu                const void *val, int len);
11099537Satgutier@umich.edu
11109537Satgutier@umich.edu/**
11119537Satgutier@umich.edu * fdt_setprop_u32 - set a property to a 32-bit integer
11129537Satgutier@umich.edu * @fdt: pointer to the device tree blob
11139537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
11149537Satgutier@umich.edu * @name: name of the property to change
11159537Satgutier@umich.edu * @val: 32-bit integer value for the property (native endian)
11169537Satgutier@umich.edu *
11179537Satgutier@umich.edu * fdt_setprop_u32() sets the value of the named property in the given
11189537Satgutier@umich.edu * node to the given 32-bit integer value (converting to big-endian if
11199537Satgutier@umich.edu * necessary), or creates a new property with that value if it does
11209537Satgutier@umich.edu * not already exist.
11219537Satgutier@umich.edu *
11229537Satgutier@umich.edu * This function may insert or delete data from the blob, and will
11239537Satgutier@umich.edu * therefore change the offsets of some existing nodes.
11249537Satgutier@umich.edu *
11259537Satgutier@umich.edu * returns:
11269537Satgutier@umich.edu *	0, on success
11279537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
11289537Satgutier@umich.edu *		contain the new property value
11299537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
11309537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
11319537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
11329537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
11339537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
11349537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
11359537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
11369537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
11379537Satgutier@umich.edu */
11389537Satgutier@umich.edustatic inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
11399537Satgutier@umich.edu                                  uint32_t val)
11409537Satgutier@umich.edu{
11419537Satgutier@umich.edu        fdt32_t tmp = cpu_to_fdt32(val);
11429537Satgutier@umich.edu        return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
11439537Satgutier@umich.edu}
11449537Satgutier@umich.edu
11459537Satgutier@umich.edu/**
11469537Satgutier@umich.edu * fdt_setprop_u64 - set a property to a 64-bit integer
11479537Satgutier@umich.edu * @fdt: pointer to the device tree blob
11489537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
11499537Satgutier@umich.edu * @name: name of the property to change
11509537Satgutier@umich.edu * @val: 64-bit integer value for the property (native endian)
11519537Satgutier@umich.edu *
11529537Satgutier@umich.edu * fdt_setprop_u64() sets the value of the named property in the given
11539537Satgutier@umich.edu * node to the given 64-bit integer value (converting to big-endian if
11549537Satgutier@umich.edu * necessary), or creates a new property with that value if it does
11559537Satgutier@umich.edu * not already exist.
11569537Satgutier@umich.edu *
11579537Satgutier@umich.edu * This function may insert or delete data from the blob, and will
11589537Satgutier@umich.edu * therefore change the offsets of some existing nodes.
11599537Satgutier@umich.edu *
11609537Satgutier@umich.edu * returns:
11619537Satgutier@umich.edu *	0, on success
11629537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
11639537Satgutier@umich.edu *		contain the new property value
11649537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
11659537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
11669537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
11679537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
11689537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
11699537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
11709537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
11719537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
11729537Satgutier@umich.edu */
11739537Satgutier@umich.edustatic inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
11749537Satgutier@umich.edu                                  uint64_t val)
11759537Satgutier@umich.edu{
11769537Satgutier@umich.edu        fdt64_t tmp = cpu_to_fdt64(val);
11779537Satgutier@umich.edu        return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
11789537Satgutier@umich.edu}
11799537Satgutier@umich.edu
11809537Satgutier@umich.edu/**
11819537Satgutier@umich.edu * fdt_setprop_cell - set a property to a single cell value
11829537Satgutier@umich.edu *
11839537Satgutier@umich.edu * This is an alternative name for fdt_setprop_u32()
11849537Satgutier@umich.edu */
11859537Satgutier@umich.edustatic inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
11869537Satgutier@umich.edu                                   uint32_t val)
11879537Satgutier@umich.edu{
11889537Satgutier@umich.edu        return fdt_setprop_u32(fdt, nodeoffset, name, val);
11899537Satgutier@umich.edu}
11909537Satgutier@umich.edu
11919537Satgutier@umich.edu/**
11929537Satgutier@umich.edu * fdt_setprop_string - set a property to a string value
11939537Satgutier@umich.edu * @fdt: pointer to the device tree blob
11949537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
11959537Satgutier@umich.edu * @name: name of the property to change
11969537Satgutier@umich.edu * @str: string value for the property
11979537Satgutier@umich.edu *
11989537Satgutier@umich.edu * fdt_setprop_string() sets the value of the named property in the
11999537Satgutier@umich.edu * given node to the given string value (using the length of the
12009537Satgutier@umich.edu * string to determine the new length of the property), or creates a
12019537Satgutier@umich.edu * new property with that value if it does not already exist.
12029537Satgutier@umich.edu *
12039537Satgutier@umich.edu * This function may insert or delete data from the blob, and will
12049537Satgutier@umich.edu * therefore change the offsets of some existing nodes.
12059537Satgutier@umich.edu *
12069537Satgutier@umich.edu * returns:
12079537Satgutier@umich.edu *	0, on success
12089537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
12099537Satgutier@umich.edu *		contain the new property value
12109537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
12119537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
12129537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
12139537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
12149537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
12159537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
12169537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
12179537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
12189537Satgutier@umich.edu */
12199537Satgutier@umich.edu#define fdt_setprop_string(fdt, nodeoffset, name, str) \
12209537Satgutier@umich.edu        fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
12219537Satgutier@umich.edu
12229537Satgutier@umich.edu/**
12239537Satgutier@umich.edu * fdt_appendprop - append to or create a property
12249537Satgutier@umich.edu * @fdt: pointer to the device tree blob
12259537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
12269537Satgutier@umich.edu * @name: name of the property to append to
12279537Satgutier@umich.edu * @val: pointer to data to append to the property value
12289537Satgutier@umich.edu * @len: length of the data to append to the property value
12299537Satgutier@umich.edu *
12309537Satgutier@umich.edu * fdt_appendprop() appends the value to the named property in the
12319537Satgutier@umich.edu * given node, creating the property if it does not already exist.
12329537Satgutier@umich.edu *
12339537Satgutier@umich.edu * This function may insert data into the blob, and will therefore
12349537Satgutier@umich.edu * change the offsets of some existing nodes.
12359537Satgutier@umich.edu *
12369537Satgutier@umich.edu * returns:
12379537Satgutier@umich.edu *	0, on success
12389537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
12399537Satgutier@umich.edu *		contain the new property value
12409537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
12419537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
12429537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
12439537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
12449537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
12459537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
12469537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
12479537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
12489537Satgutier@umich.edu */
12499537Satgutier@umich.eduint fdt_appendprop(void *fdt, int nodeoffset, const char *name,
12509537Satgutier@umich.edu                   const void *val, int len);
12519537Satgutier@umich.edu
12529537Satgutier@umich.edu/**
12539537Satgutier@umich.edu * fdt_appendprop_u32 - append a 32-bit integer value to a property
12549537Satgutier@umich.edu * @fdt: pointer to the device tree blob
12559537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
12569537Satgutier@umich.edu * @name: name of the property to change
12579537Satgutier@umich.edu * @val: 32-bit integer value to append to the property (native endian)
12589537Satgutier@umich.edu *
12599537Satgutier@umich.edu * fdt_appendprop_u32() appends the given 32-bit integer value
12609537Satgutier@umich.edu * (converting to big-endian if necessary) to the value of the named
12619537Satgutier@umich.edu * property in the given node, or creates a new property with that
12629537Satgutier@umich.edu * value if it does not already exist.
12639537Satgutier@umich.edu *
12649537Satgutier@umich.edu * This function may insert data into the blob, and will therefore
12659537Satgutier@umich.edu * change the offsets of some existing nodes.
12669537Satgutier@umich.edu *
12679537Satgutier@umich.edu * returns:
12689537Satgutier@umich.edu *	0, on success
12699537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
12709537Satgutier@umich.edu *		contain the new property value
12719537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
12729537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
12739537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
12749537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
12759537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
12769537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
12779537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
12789537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
12799537Satgutier@umich.edu */
12809537Satgutier@umich.edustatic inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
12819537Satgutier@umich.edu                                     const char *name, uint32_t val)
12829537Satgutier@umich.edu{
12839537Satgutier@umich.edu        fdt32_t tmp = cpu_to_fdt32(val);
12849537Satgutier@umich.edu        return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
12859537Satgutier@umich.edu}
12869537Satgutier@umich.edu
12879537Satgutier@umich.edu/**
12889537Satgutier@umich.edu * fdt_appendprop_u64 - append a 64-bit integer value to a property
12899537Satgutier@umich.edu * @fdt: pointer to the device tree blob
12909537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
12919537Satgutier@umich.edu * @name: name of the property to change
12929537Satgutier@umich.edu * @val: 64-bit integer value to append to the property (native endian)
12939537Satgutier@umich.edu *
12949537Satgutier@umich.edu * fdt_appendprop_u64() appends the given 64-bit integer value
12959537Satgutier@umich.edu * (converting to big-endian if necessary) to the value of the named
12969537Satgutier@umich.edu * property in the given node, or creates a new property with that
12979537Satgutier@umich.edu * value if it does not already exist.
12989537Satgutier@umich.edu *
12999537Satgutier@umich.edu * This function may insert data into the blob, and will therefore
13009537Satgutier@umich.edu * change the offsets of some existing nodes.
13019537Satgutier@umich.edu *
13029537Satgutier@umich.edu * returns:
13039537Satgutier@umich.edu *	0, on success
13049537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
13059537Satgutier@umich.edu *		contain the new property value
13069537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
13079537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
13089537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
13099537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
13109537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
13119537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
13129537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
13139537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
13149537Satgutier@umich.edu */
13159537Satgutier@umich.edustatic inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
13169537Satgutier@umich.edu                                     const char *name, uint64_t val)
13179537Satgutier@umich.edu{
13189537Satgutier@umich.edu        fdt64_t tmp = cpu_to_fdt64(val);
13199537Satgutier@umich.edu        return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
13209537Satgutier@umich.edu}
13219537Satgutier@umich.edu
13229537Satgutier@umich.edu/**
13239537Satgutier@umich.edu * fdt_appendprop_cell - append a single cell value to a property
13249537Satgutier@umich.edu *
13259537Satgutier@umich.edu * This is an alternative name for fdt_appendprop_u32()
13269537Satgutier@umich.edu */
13279537Satgutier@umich.edustatic inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
13289537Satgutier@umich.edu                                      const char *name, uint32_t val)
13299537Satgutier@umich.edu{
13309537Satgutier@umich.edu        return fdt_appendprop_u32(fdt, nodeoffset, name, val);
13319537Satgutier@umich.edu}
13329537Satgutier@umich.edu
13339537Satgutier@umich.edu/**
13349537Satgutier@umich.edu * fdt_appendprop_string - append a string to a property
13359537Satgutier@umich.edu * @fdt: pointer to the device tree blob
13369537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to change
13379537Satgutier@umich.edu * @name: name of the property to change
13389537Satgutier@umich.edu * @str: string value to append to the property
13399537Satgutier@umich.edu *
13409537Satgutier@umich.edu * fdt_appendprop_string() appends the given string to the value of
13419537Satgutier@umich.edu * the named property in the given node, or creates a new property
13429537Satgutier@umich.edu * with that value if it does not already exist.
13439537Satgutier@umich.edu *
13449537Satgutier@umich.edu * This function may insert data into the blob, and will therefore
13459537Satgutier@umich.edu * change the offsets of some existing nodes.
13469537Satgutier@umich.edu *
13479537Satgutier@umich.edu * returns:
13489537Satgutier@umich.edu *	0, on success
13499537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
13509537Satgutier@umich.edu *		contain the new property value
13519537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
13529537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
13539537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
13549537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
13559537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
13569537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
13579537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
13589537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
13599537Satgutier@umich.edu */
13609537Satgutier@umich.edu#define fdt_appendprop_string(fdt, nodeoffset, name, str) \
13619537Satgutier@umich.edu        fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
13629537Satgutier@umich.edu
13639537Satgutier@umich.edu/**
13649537Satgutier@umich.edu * fdt_delprop - delete a property
13659537Satgutier@umich.edu * @fdt: pointer to the device tree blob
13669537Satgutier@umich.edu * @nodeoffset: offset of the node whose property to nop
13679537Satgutier@umich.edu * @name: name of the property to nop
13689537Satgutier@umich.edu *
13699537Satgutier@umich.edu * fdt_del_property() will delete the given property.
13709537Satgutier@umich.edu *
13719537Satgutier@umich.edu * This function will delete data from the blob, and will therefore
13729537Satgutier@umich.edu * change the offsets of some existing nodes.
13739537Satgutier@umich.edu *
13749537Satgutier@umich.edu * returns:
13759537Satgutier@umich.edu *	0, on success
13769537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, node does not have the named property
13779537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
13789537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
13799537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
13809537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
13819537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
13829537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
13839537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
13849537Satgutier@umich.edu */
13859537Satgutier@umich.eduint fdt_delprop(void *fdt, int nodeoffset, const char *name);
13869537Satgutier@umich.edu
13879537Satgutier@umich.edu/**
13889537Satgutier@umich.edu * fdt_add_subnode_namelen - creates a new node based on substring
13899537Satgutier@umich.edu * @fdt: pointer to the device tree blob
13909537Satgutier@umich.edu * @parentoffset: structure block offset of a node
13919537Satgutier@umich.edu * @name: name of the subnode to locate
13929537Satgutier@umich.edu * @namelen: number of characters of name to consider
13939537Satgutier@umich.edu *
13949537Satgutier@umich.edu * Identical to fdt_add_subnode(), but use only the first namelen
13959537Satgutier@umich.edu * characters of name as the name of the new node.  This is useful for
13969537Satgutier@umich.edu * creating subnodes based on a portion of a larger string, such as a
13979537Satgutier@umich.edu * full path.
13989537Satgutier@umich.edu */
13999537Satgutier@umich.eduint fdt_add_subnode_namelen(void *fdt, int parentoffset,
14009537Satgutier@umich.edu                            const char *name, int namelen);
14019537Satgutier@umich.edu
14029537Satgutier@umich.edu/**
14039537Satgutier@umich.edu * fdt_add_subnode - creates a new node
14049537Satgutier@umich.edu * @fdt: pointer to the device tree blob
14059537Satgutier@umich.edu * @parentoffset: structure block offset of a node
14069537Satgutier@umich.edu * @name: name of the subnode to locate
14079537Satgutier@umich.edu *
14089537Satgutier@umich.edu * fdt_add_subnode() creates a new node as a subnode of the node at
14099537Satgutier@umich.edu * structure block offset parentoffset, with the given name (which
14109537Satgutier@umich.edu * should include the unit address, if any).
14119537Satgutier@umich.edu *
14129537Satgutier@umich.edu * This function will insert data into the blob, and will therefore
14139537Satgutier@umich.edu * change the offsets of some existing nodes.
14149537Satgutier@umich.edu
14159537Satgutier@umich.edu * returns:
14169537Satgutier@umich.edu *	structure block offset of the created nodeequested subnode (>=0), on success
14179537Satgutier@umich.edu *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
14189537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
14199537Satgutier@umich.edu *	-FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
14209537Satgutier@umich.edu *		the given name
14219537Satgutier@umich.edu *	-FDT_ERR_NOSPACE, if there is insufficient free space in the
14229537Satgutier@umich.edu *		blob to contain the new node
14239537Satgutier@umich.edu *	-FDT_ERR_NOSPACE
14249537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT
14259537Satgutier@umich.edu *      -FDT_ERR_BADMAGIC,
14269537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
14279537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
14289537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
14299537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings.
14309537Satgutier@umich.edu */
14319537Satgutier@umich.eduint fdt_add_subnode(void *fdt, int parentoffset, const char *name);
14329537Satgutier@umich.edu
14339537Satgutier@umich.edu/**
14349537Satgutier@umich.edu * fdt_del_node - delete a node (subtree)
14359537Satgutier@umich.edu * @fdt: pointer to the device tree blob
14369537Satgutier@umich.edu * @nodeoffset: offset of the node to nop
14379537Satgutier@umich.edu *
14389537Satgutier@umich.edu * fdt_del_node() will remove the given node, including all its
14399537Satgutier@umich.edu * subnodes if any, from the blob.
14409537Satgutier@umich.edu *
14419537Satgutier@umich.edu * This function will delete data from the blob, and will therefore
14429537Satgutier@umich.edu * change the offsets of some existing nodes.
14439537Satgutier@umich.edu *
14449537Satgutier@umich.edu * returns:
14459537Satgutier@umich.edu *	0, on success
14469537Satgutier@umich.edu *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
14479537Satgutier@umich.edu *	-FDT_ERR_BADLAYOUT,
14489537Satgutier@umich.edu *	-FDT_ERR_BADMAGIC,
14499537Satgutier@umich.edu *	-FDT_ERR_BADVERSION,
14509537Satgutier@umich.edu *	-FDT_ERR_BADSTATE,
14519537Satgutier@umich.edu *	-FDT_ERR_BADSTRUCTURE,
14529537Satgutier@umich.edu *	-FDT_ERR_TRUNCATED, standard meanings
14539537Satgutier@umich.edu */
14549537Satgutier@umich.eduint fdt_del_node(void *fdt, int nodeoffset);
14559537Satgutier@umich.edu
14569537Satgutier@umich.edu/**********************************************************************/
14579537Satgutier@umich.edu/* Debugging / informational functions                                */
14589537Satgutier@umich.edu/**********************************************************************/
14599537Satgutier@umich.edu
14609537Satgutier@umich.educonst char *fdt_strerror(int errval);
14619537Satgutier@umich.edu
14629537Satgutier@umich.edu#ifdef __cplusplus
14639537Satgutier@umich.edu}
14649537Satgutier@umich.edu#endif
14659537Satgutier@umich.edu
14669537Satgutier@umich.edu#endif /* _LIBFDT_H */
1467