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