Home | History | Annotate | Line # | Download | only in dist
libfdt.h revision 1.1.1.2
      1  1.1.1.2     skrll /*	$NetBSD: libfdt.h,v 1.1.1.2 2017/06/08 15:53:15 skrll Exp $	*/
      2  1.1.1.2     skrll 
      3      1.1  macallan #ifndef _LIBFDT_H
      4      1.1  macallan #define _LIBFDT_H
      5      1.1  macallan /*
      6      1.1  macallan  * libfdt - Flat Device Tree manipulation
      7      1.1  macallan  * Copyright (C) 2006 David Gibson, IBM Corporation.
      8      1.1  macallan  *
      9      1.1  macallan  * libfdt is dual licensed: you can use it either under the terms of
     10      1.1  macallan  * the GPL, or the BSD license, at your option.
     11      1.1  macallan  *
     12      1.1  macallan  *  a) This library is free software; you can redistribute it and/or
     13      1.1  macallan  *     modify it under the terms of the GNU General Public License as
     14      1.1  macallan  *     published by the Free Software Foundation; either version 2 of the
     15      1.1  macallan  *     License, or (at your option) any later version.
     16      1.1  macallan  *
     17      1.1  macallan  *     This library is distributed in the hope that it will be useful,
     18      1.1  macallan  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
     19      1.1  macallan  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     20      1.1  macallan  *     GNU General Public License for more details.
     21      1.1  macallan  *
     22      1.1  macallan  *     You should have received a copy of the GNU General Public
     23      1.1  macallan  *     License along with this library; if not, write to the Free
     24      1.1  macallan  *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
     25      1.1  macallan  *     MA 02110-1301 USA
     26      1.1  macallan  *
     27      1.1  macallan  * Alternatively,
     28      1.1  macallan  *
     29      1.1  macallan  *  b) Redistribution and use in source and binary forms, with or
     30      1.1  macallan  *     without modification, are permitted provided that the following
     31      1.1  macallan  *     conditions are met:
     32      1.1  macallan  *
     33      1.1  macallan  *     1. Redistributions of source code must retain the above
     34      1.1  macallan  *        copyright notice, this list of conditions and the following
     35      1.1  macallan  *        disclaimer.
     36      1.1  macallan  *     2. Redistributions in binary form must reproduce the above
     37      1.1  macallan  *        copyright notice, this list of conditions and the following
     38      1.1  macallan  *        disclaimer in the documentation and/or other materials
     39      1.1  macallan  *        provided with the distribution.
     40      1.1  macallan  *
     41      1.1  macallan  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
     42      1.1  macallan  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
     43      1.1  macallan  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     44      1.1  macallan  *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     45      1.1  macallan  *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     46      1.1  macallan  *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     47      1.1  macallan  *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     48      1.1  macallan  *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     49      1.1  macallan  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     50      1.1  macallan  *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     51      1.1  macallan  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     52      1.1  macallan  *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     53      1.1  macallan  *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     54      1.1  macallan  */
     55      1.1  macallan 
     56      1.1  macallan #include <libfdt_env.h>
     57      1.1  macallan #include <fdt.h>
     58      1.1  macallan 
     59      1.1  macallan #define FDT_FIRST_SUPPORTED_VERSION	0x10
     60      1.1  macallan #define FDT_LAST_SUPPORTED_VERSION	0x11
     61      1.1  macallan 
     62      1.1  macallan /* Error codes: informative error codes */
     63      1.1  macallan #define FDT_ERR_NOTFOUND	1
     64      1.1  macallan 	/* FDT_ERR_NOTFOUND: The requested node or property does not exist */
     65      1.1  macallan #define FDT_ERR_EXISTS		2
     66  1.1.1.2     skrll 	/* FDT_ERR_EXISTS: Attempted to create a node or property which
     67      1.1  macallan 	 * already exists */
     68      1.1  macallan #define FDT_ERR_NOSPACE		3
     69      1.1  macallan 	/* FDT_ERR_NOSPACE: Operation needed to expand the device
     70      1.1  macallan 	 * tree, but its buffer did not have sufficient space to
     71      1.1  macallan 	 * contain the expanded tree. Use fdt_open_into() to move the
     72      1.1  macallan 	 * device tree to a buffer with more space. */
     73      1.1  macallan 
     74      1.1  macallan /* Error codes: codes for bad parameters */
     75      1.1  macallan #define FDT_ERR_BADOFFSET	4
     76      1.1  macallan 	/* FDT_ERR_BADOFFSET: Function was passed a structure block
     77      1.1  macallan 	 * offset which is out-of-bounds, or which points to an
     78      1.1  macallan 	 * unsuitable part of the structure for the operation. */
     79      1.1  macallan #define FDT_ERR_BADPATH		5
     80      1.1  macallan 	/* FDT_ERR_BADPATH: Function was passed a badly formatted path
     81      1.1  macallan 	 * (e.g. missing a leading / for a function which requires an
     82      1.1  macallan 	 * absolute path) */
     83      1.1  macallan #define FDT_ERR_BADPHANDLE	6
     84  1.1.1.2     skrll 	/* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
     85  1.1.1.2     skrll 	 * This can be caused either by an invalid phandle property
     86  1.1.1.2     skrll 	 * length, or the phandle value was either 0 or -1, which are
     87  1.1.1.2     skrll 	 * not permitted. */
     88      1.1  macallan #define FDT_ERR_BADSTATE	7
     89      1.1  macallan 	/* FDT_ERR_BADSTATE: Function was passed an incomplete device
     90      1.1  macallan 	 * tree created by the sequential-write functions, which is
     91      1.1  macallan 	 * not sufficiently complete for the requested operation. */
     92      1.1  macallan 
     93      1.1  macallan /* Error codes: codes for bad device tree blobs */
     94      1.1  macallan #define FDT_ERR_TRUNCATED	8
     95      1.1  macallan 	/* FDT_ERR_TRUNCATED: Structure block of the given device tree
     96      1.1  macallan 	 * ends without an FDT_END tag. */
     97      1.1  macallan #define FDT_ERR_BADMAGIC	9
     98      1.1  macallan 	/* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
     99      1.1  macallan 	 * device tree at all - it is missing the flattened device
    100      1.1  macallan 	 * tree magic number. */
    101      1.1  macallan #define FDT_ERR_BADVERSION	10
    102      1.1  macallan 	/* FDT_ERR_BADVERSION: Given device tree has a version which
    103      1.1  macallan 	 * can't be handled by the requested operation.  For
    104      1.1  macallan 	 * read-write functions, this may mean that fdt_open_into() is
    105      1.1  macallan 	 * required to convert the tree to the expected version. */
    106      1.1  macallan #define FDT_ERR_BADSTRUCTURE	11
    107      1.1  macallan 	/* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
    108      1.1  macallan 	 * structure block or other serious error (e.g. misnested
    109      1.1  macallan 	 * nodes, or subnodes preceding properties). */
    110      1.1  macallan #define FDT_ERR_BADLAYOUT	12
    111      1.1  macallan 	/* FDT_ERR_BADLAYOUT: For read-write functions, the given
    112      1.1  macallan 	 * device tree has it's sub-blocks in an order that the
    113      1.1  macallan 	 * function can't handle (memory reserve map, then structure,
    114      1.1  macallan 	 * then strings).  Use fdt_open_into() to reorganize the tree
    115      1.1  macallan 	 * into a form suitable for the read-write operations. */
    116      1.1  macallan 
    117      1.1  macallan /* "Can't happen" error indicating a bug in libfdt */
    118      1.1  macallan #define FDT_ERR_INTERNAL	13
    119      1.1  macallan 	/* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
    120      1.1  macallan 	 * Should never be returned, if it is, it indicates a bug in
    121      1.1  macallan 	 * libfdt itself. */
    122      1.1  macallan 
    123      1.1  macallan /* Errors in device tree content */
    124      1.1  macallan #define FDT_ERR_BADNCELLS	14
    125      1.1  macallan 	/* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
    126      1.1  macallan 	 * or similar property with a bad format or value */
    127      1.1  macallan 
    128      1.1  macallan #define FDT_ERR_BADVALUE	15
    129      1.1  macallan 	/* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
    130      1.1  macallan 	 * value. For example: a property expected to contain a string list
    131      1.1  macallan 	 * is not NUL-terminated within the length of its value. */
    132      1.1  macallan 
    133  1.1.1.2     skrll #define FDT_ERR_BADOVERLAY	16
    134  1.1.1.2     skrll 	/* FDT_ERR_BADOVERLAY: The device tree overlay, while
    135  1.1.1.2     skrll 	 * correctly structured, cannot be applied due to some
    136  1.1.1.2     skrll 	 * unexpected or missing value, property or node. */
    137  1.1.1.2     skrll 
    138  1.1.1.2     skrll #define FDT_ERR_NOPHANDLES	17
    139  1.1.1.2     skrll 	/* FDT_ERR_NOPHANDLES: The device tree doesn't have any
    140  1.1.1.2     skrll 	 * phandle available anymore without causing an overflow */
    141  1.1.1.2     skrll 
    142  1.1.1.2     skrll #define FDT_ERR_MAX		17
    143      1.1  macallan 
    144      1.1  macallan /**********************************************************************/
    145      1.1  macallan /* Low-level functions (you probably don't need these)                */
    146      1.1  macallan /**********************************************************************/
    147      1.1  macallan 
    148      1.1  macallan const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
    149      1.1  macallan static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
    150      1.1  macallan {
    151      1.1  macallan 	return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
    152      1.1  macallan }
    153      1.1  macallan 
    154      1.1  macallan uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
    155      1.1  macallan 
    156      1.1  macallan /**********************************************************************/
    157      1.1  macallan /* Traversal functions                                                */
    158      1.1  macallan /**********************************************************************/
    159      1.1  macallan 
    160      1.1  macallan int fdt_next_node(const void *fdt, int offset, int *depth);
    161      1.1  macallan 
    162      1.1  macallan /**
    163      1.1  macallan  * fdt_first_subnode() - get offset of first direct subnode
    164      1.1  macallan  *
    165      1.1  macallan  * @fdt:	FDT blob
    166      1.1  macallan  * @offset:	Offset of node to check
    167      1.1  macallan  * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
    168      1.1  macallan  */
    169      1.1  macallan int fdt_first_subnode(const void *fdt, int offset);
    170      1.1  macallan 
    171      1.1  macallan /**
    172      1.1  macallan  * fdt_next_subnode() - get offset of next direct subnode
    173      1.1  macallan  *
    174      1.1  macallan  * After first calling fdt_first_subnode(), call this function repeatedly to
    175      1.1  macallan  * get direct subnodes of a parent node.
    176      1.1  macallan  *
    177      1.1  macallan  * @fdt:	FDT blob
    178      1.1  macallan  * @offset:	Offset of previous subnode
    179      1.1  macallan  * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
    180      1.1  macallan  * subnodes
    181      1.1  macallan  */
    182      1.1  macallan int fdt_next_subnode(const void *fdt, int offset);
    183      1.1  macallan 
    184  1.1.1.2     skrll /**
    185  1.1.1.2     skrll  * fdt_for_each_subnode - iterate over all subnodes of a parent
    186  1.1.1.2     skrll  *
    187  1.1.1.2     skrll  * @node:	child node (int, lvalue)
    188  1.1.1.2     skrll  * @fdt:	FDT blob (const void *)
    189  1.1.1.2     skrll  * @parent:	parent node (int)
    190  1.1.1.2     skrll  *
    191  1.1.1.2     skrll  * This is actually a wrapper around a for loop and would be used like so:
    192  1.1.1.2     skrll  *
    193  1.1.1.2     skrll  *	fdt_for_each_subnode(node, fdt, parent) {
    194  1.1.1.2     skrll  *		Use node
    195  1.1.1.2     skrll  *		...
    196  1.1.1.2     skrll  *	}
    197  1.1.1.2     skrll  *
    198  1.1.1.2     skrll  *	if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) {
    199  1.1.1.2     skrll  *		Error handling
    200  1.1.1.2     skrll  *	}
    201  1.1.1.2     skrll  *
    202  1.1.1.2     skrll  * Note that this is implemented as a macro and @node is used as
    203  1.1.1.2     skrll  * iterator in the loop. The parent variable be constant or even a
    204  1.1.1.2     skrll  * literal.
    205  1.1.1.2     skrll  *
    206  1.1.1.2     skrll  */
    207  1.1.1.2     skrll #define fdt_for_each_subnode(node, fdt, parent)		\
    208  1.1.1.2     skrll 	for (node = fdt_first_subnode(fdt, parent);	\
    209  1.1.1.2     skrll 	     node >= 0;					\
    210  1.1.1.2     skrll 	     node = fdt_next_subnode(fdt, node))
    211  1.1.1.2     skrll 
    212      1.1  macallan /**********************************************************************/
    213      1.1  macallan /* General functions                                                  */
    214      1.1  macallan /**********************************************************************/
    215      1.1  macallan 
    216      1.1  macallan #define fdt_get_header(fdt, field) \
    217      1.1  macallan 	(fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
    218  1.1.1.2     skrll #define fdt_magic(fdt)			(fdt_get_header(fdt, magic))
    219      1.1  macallan #define fdt_totalsize(fdt)		(fdt_get_header(fdt, totalsize))
    220      1.1  macallan #define fdt_off_dt_struct(fdt)		(fdt_get_header(fdt, off_dt_struct))
    221      1.1  macallan #define fdt_off_dt_strings(fdt)		(fdt_get_header(fdt, off_dt_strings))
    222      1.1  macallan #define fdt_off_mem_rsvmap(fdt)		(fdt_get_header(fdt, off_mem_rsvmap))
    223      1.1  macallan #define fdt_version(fdt)		(fdt_get_header(fdt, version))
    224  1.1.1.2     skrll #define fdt_last_comp_version(fdt)	(fdt_get_header(fdt, last_comp_version))
    225  1.1.1.2     skrll #define fdt_boot_cpuid_phys(fdt)	(fdt_get_header(fdt, boot_cpuid_phys))
    226  1.1.1.2     skrll #define fdt_size_dt_strings(fdt)	(fdt_get_header(fdt, size_dt_strings))
    227      1.1  macallan #define fdt_size_dt_struct(fdt)		(fdt_get_header(fdt, size_dt_struct))
    228      1.1  macallan 
    229      1.1  macallan #define __fdt_set_hdr(name) \
    230      1.1  macallan 	static inline void fdt_set_##name(void *fdt, uint32_t val) \
    231      1.1  macallan 	{ \
    232  1.1.1.2     skrll 		struct fdt_header *fdth = (struct fdt_header *)fdt; \
    233      1.1  macallan 		fdth->name = cpu_to_fdt32(val); \
    234      1.1  macallan 	}
    235      1.1  macallan __fdt_set_hdr(magic);
    236      1.1  macallan __fdt_set_hdr(totalsize);
    237      1.1  macallan __fdt_set_hdr(off_dt_struct);
    238      1.1  macallan __fdt_set_hdr(off_dt_strings);
    239      1.1  macallan __fdt_set_hdr(off_mem_rsvmap);
    240      1.1  macallan __fdt_set_hdr(version);
    241      1.1  macallan __fdt_set_hdr(last_comp_version);
    242      1.1  macallan __fdt_set_hdr(boot_cpuid_phys);
    243      1.1  macallan __fdt_set_hdr(size_dt_strings);
    244      1.1  macallan __fdt_set_hdr(size_dt_struct);
    245      1.1  macallan #undef __fdt_set_hdr
    246      1.1  macallan 
    247      1.1  macallan /**
    248      1.1  macallan  * fdt_check_header - sanity check a device tree or possible device tree
    249      1.1  macallan  * @fdt: pointer to data which might be a flattened device tree
    250      1.1  macallan  *
    251      1.1  macallan  * fdt_check_header() checks that the given buffer contains what
    252      1.1  macallan  * appears to be a flattened device tree with sane information in its
    253      1.1  macallan  * header.
    254      1.1  macallan  *
    255      1.1  macallan  * returns:
    256      1.1  macallan  *     0, if the buffer appears to contain a valid device tree
    257      1.1  macallan  *     -FDT_ERR_BADMAGIC,
    258      1.1  macallan  *     -FDT_ERR_BADVERSION,
    259      1.1  macallan  *     -FDT_ERR_BADSTATE, standard meanings, as above
    260      1.1  macallan  */
    261      1.1  macallan int fdt_check_header(const void *fdt);
    262      1.1  macallan 
    263      1.1  macallan /**
    264      1.1  macallan  * fdt_move - move a device tree around in memory
    265      1.1  macallan  * @fdt: pointer to the device tree to move
    266      1.1  macallan  * @buf: pointer to memory where the device is to be moved
    267      1.1  macallan  * @bufsize: size of the memory space at buf
    268      1.1  macallan  *
    269      1.1  macallan  * fdt_move() relocates, if possible, the device tree blob located at
    270      1.1  macallan  * fdt to the buffer at buf of size bufsize.  The buffer may overlap
    271      1.1  macallan  * with the existing device tree blob at fdt.  Therefore,
    272      1.1  macallan  *     fdt_move(fdt, fdt, fdt_totalsize(fdt))
    273      1.1  macallan  * should always succeed.
    274      1.1  macallan  *
    275      1.1  macallan  * returns:
    276      1.1  macallan  *     0, on success
    277      1.1  macallan  *     -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
    278      1.1  macallan  *     -FDT_ERR_BADMAGIC,
    279      1.1  macallan  *     -FDT_ERR_BADVERSION,
    280      1.1  macallan  *     -FDT_ERR_BADSTATE, standard meanings
    281      1.1  macallan  */
    282      1.1  macallan int fdt_move(const void *fdt, void *buf, int bufsize);
    283      1.1  macallan 
    284      1.1  macallan /**********************************************************************/
    285      1.1  macallan /* Read-only functions                                                */
    286      1.1  macallan /**********************************************************************/
    287      1.1  macallan 
    288      1.1  macallan /**
    289      1.1  macallan  * fdt_string - retrieve a string from the strings block of a device tree
    290      1.1  macallan  * @fdt: pointer to the device tree blob
    291      1.1  macallan  * @stroffset: offset of the string within the strings block (native endian)
    292      1.1  macallan  *
    293      1.1  macallan  * fdt_string() retrieves a pointer to a single string from the
    294      1.1  macallan  * strings block of the device tree blob at fdt.
    295      1.1  macallan  *
    296      1.1  macallan  * returns:
    297      1.1  macallan  *     a pointer to the string, on success
    298      1.1  macallan  *     NULL, if stroffset is out of bounds
    299      1.1  macallan  */
    300      1.1  macallan const char *fdt_string(const void *fdt, int stroffset);
    301      1.1  macallan 
    302      1.1  macallan /**
    303  1.1.1.2     skrll  * fdt_get_max_phandle - retrieves the highest phandle in a tree
    304  1.1.1.2     skrll  * @fdt: pointer to the device tree blob
    305  1.1.1.2     skrll  *
    306  1.1.1.2     skrll  * fdt_get_max_phandle retrieves the highest phandle in the given
    307  1.1.1.2     skrll  * device tree. This will ignore badly formatted phandles, or phandles
    308  1.1.1.2     skrll  * with a value of 0 or -1.
    309  1.1.1.2     skrll  *
    310  1.1.1.2     skrll  * returns:
    311  1.1.1.2     skrll  *      the highest phandle on success
    312  1.1.1.2     skrll  *      0, if no phandle was found in the device tree
    313  1.1.1.2     skrll  *      -1, if an error occurred
    314  1.1.1.2     skrll  */
    315  1.1.1.2     skrll uint32_t fdt_get_max_phandle(const void *fdt);
    316  1.1.1.2     skrll 
    317  1.1.1.2     skrll /**
    318      1.1  macallan  * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
    319      1.1  macallan  * @fdt: pointer to the device tree blob
    320      1.1  macallan  *
    321      1.1  macallan  * Returns the number of entries in the device tree blob's memory
    322      1.1  macallan  * reservation map.  This does not include the terminating 0,0 entry
    323      1.1  macallan  * or any other (0,0) entries reserved for expansion.
    324      1.1  macallan  *
    325      1.1  macallan  * returns:
    326      1.1  macallan  *     the number of entries
    327      1.1  macallan  */
    328      1.1  macallan int fdt_num_mem_rsv(const void *fdt);
    329      1.1  macallan 
    330      1.1  macallan /**
    331      1.1  macallan  * fdt_get_mem_rsv - retrieve one memory reserve map entry
    332      1.1  macallan  * @fdt: pointer to the device tree blob
    333      1.1  macallan  * @address, @size: pointers to 64-bit variables
    334      1.1  macallan  *
    335      1.1  macallan  * On success, *address and *size will contain the address and size of
    336      1.1  macallan  * the n-th reserve map entry from the device tree blob, in
    337      1.1  macallan  * native-endian format.
    338      1.1  macallan  *
    339      1.1  macallan  * returns:
    340      1.1  macallan  *     0, on success
    341      1.1  macallan  *     -FDT_ERR_BADMAGIC,
    342      1.1  macallan  *     -FDT_ERR_BADVERSION,
    343      1.1  macallan  *     -FDT_ERR_BADSTATE, standard meanings
    344      1.1  macallan  */
    345      1.1  macallan int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
    346      1.1  macallan 
    347      1.1  macallan /**
    348      1.1  macallan  * fdt_subnode_offset_namelen - find a subnode based on substring
    349      1.1  macallan  * @fdt: pointer to the device tree blob
    350      1.1  macallan  * @parentoffset: structure block offset of a node
    351      1.1  macallan  * @name: name of the subnode to locate
    352      1.1  macallan  * @namelen: number of characters of name to consider
    353      1.1  macallan  *
    354      1.1  macallan  * Identical to fdt_subnode_offset(), but only examine the first
    355      1.1  macallan  * namelen characters of name for matching the subnode name.  This is
    356      1.1  macallan  * useful for finding subnodes based on a portion of a larger string,
    357      1.1  macallan  * such as a full path.
    358      1.1  macallan  */
    359      1.1  macallan int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
    360      1.1  macallan 			       const char *name, int namelen);
    361      1.1  macallan /**
    362      1.1  macallan  * fdt_subnode_offset - find a subnode of a given node
    363      1.1  macallan  * @fdt: pointer to the device tree blob
    364      1.1  macallan  * @parentoffset: structure block offset of a node
    365      1.1  macallan  * @name: name of the subnode to locate
    366      1.1  macallan  *
    367      1.1  macallan  * fdt_subnode_offset() finds a subnode of the node at structure block
    368      1.1  macallan  * offset parentoffset with the given name.  name may include a unit
    369      1.1  macallan  * address, in which case fdt_subnode_offset() will find the subnode
    370      1.1  macallan  * with that unit address, or the unit address may be omitted, in
    371      1.1  macallan  * which case fdt_subnode_offset() will find an arbitrary subnode
    372      1.1  macallan  * whose name excluding unit address matches the given name.
    373      1.1  macallan  *
    374      1.1  macallan  * returns:
    375      1.1  macallan  *	structure block offset of the requested subnode (>=0), on success
    376      1.1  macallan  *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
    377  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
    378  1.1.1.2     skrll  *		tag
    379  1.1.1.2     skrll  *	-FDT_ERR_BADMAGIC,
    380      1.1  macallan  *	-FDT_ERR_BADVERSION,
    381      1.1  macallan  *	-FDT_ERR_BADSTATE,
    382      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
    383      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings.
    384      1.1  macallan  */
    385      1.1  macallan int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
    386      1.1  macallan 
    387      1.1  macallan /**
    388      1.1  macallan  * fdt_path_offset_namelen - find a tree node by its full path
    389      1.1  macallan  * @fdt: pointer to the device tree blob
    390      1.1  macallan  * @path: full path of the node to locate
    391      1.1  macallan  * @namelen: number of characters of path to consider
    392      1.1  macallan  *
    393      1.1  macallan  * Identical to fdt_path_offset(), but only consider the first namelen
    394      1.1  macallan  * characters of path as the path name.
    395      1.1  macallan  */
    396      1.1  macallan int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
    397      1.1  macallan 
    398      1.1  macallan /**
    399      1.1  macallan  * fdt_path_offset - find a tree node by its full path
    400      1.1  macallan  * @fdt: pointer to the device tree blob
    401      1.1  macallan  * @path: full path of the node to locate
    402      1.1  macallan  *
    403      1.1  macallan  * fdt_path_offset() finds a node of a given path in the device tree.
    404      1.1  macallan  * Each path component may omit the unit address portion, but the
    405      1.1  macallan  * results of this are undefined if any such path component is
    406      1.1  macallan  * ambiguous (that is if there are multiple nodes at the relevant
    407      1.1  macallan  * level matching the given component, differentiated only by unit
    408      1.1  macallan  * address).
    409      1.1  macallan  *
    410      1.1  macallan  * returns:
    411  1.1.1.2     skrll  *	structure block offset of the node with the requested path (>=0), on
    412  1.1.1.2     skrll  *		success
    413      1.1  macallan  *	-FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
    414      1.1  macallan  *	-FDT_ERR_NOTFOUND, if the requested node does not exist
    415      1.1  macallan  *      -FDT_ERR_BADMAGIC,
    416      1.1  macallan  *	-FDT_ERR_BADVERSION,
    417      1.1  macallan  *	-FDT_ERR_BADSTATE,
    418      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
    419      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings.
    420      1.1  macallan  */
    421      1.1  macallan int fdt_path_offset(const void *fdt, const char *path);
    422      1.1  macallan 
    423      1.1  macallan /**
    424      1.1  macallan  * fdt_get_name - retrieve the name of a given node
    425      1.1  macallan  * @fdt: pointer to the device tree blob
    426      1.1  macallan  * @nodeoffset: structure block offset of the starting node
    427      1.1  macallan  * @lenp: pointer to an integer variable (will be overwritten) or NULL
    428      1.1  macallan  *
    429      1.1  macallan  * fdt_get_name() retrieves the name (including unit address) of the
    430      1.1  macallan  * device tree node at structure block offset nodeoffset.  If lenp is
    431      1.1  macallan  * non-NULL, the length of this name is also returned, in the integer
    432      1.1  macallan  * pointed to by lenp.
    433      1.1  macallan  *
    434      1.1  macallan  * returns:
    435      1.1  macallan  *	pointer to the node's name, on success
    436  1.1.1.2     skrll  *		If lenp is non-NULL, *lenp contains the length of that name
    437  1.1.1.2     skrll  *			(>=0)
    438      1.1  macallan  *	NULL, on error
    439      1.1  macallan  *		if lenp is non-NULL *lenp contains an error code (<0):
    440  1.1.1.2     skrll  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
    441  1.1.1.2     skrll  *			tag
    442      1.1  macallan  *		-FDT_ERR_BADMAGIC,
    443      1.1  macallan  *		-FDT_ERR_BADVERSION,
    444      1.1  macallan  *		-FDT_ERR_BADSTATE, standard meanings
    445      1.1  macallan  */
    446      1.1  macallan const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
    447      1.1  macallan 
    448      1.1  macallan /**
    449      1.1  macallan  * fdt_first_property_offset - find the offset of a node's first property
    450      1.1  macallan  * @fdt: pointer to the device tree blob
    451      1.1  macallan  * @nodeoffset: structure block offset of a node
    452      1.1  macallan  *
    453      1.1  macallan  * fdt_first_property_offset() finds the first property of the node at
    454      1.1  macallan  * the given structure block offset.
    455      1.1  macallan  *
    456      1.1  macallan  * returns:
    457      1.1  macallan  *	structure block offset of the property (>=0), on success
    458      1.1  macallan  *	-FDT_ERR_NOTFOUND, if the requested node has no properties
    459      1.1  macallan  *	-FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
    460      1.1  macallan  *      -FDT_ERR_BADMAGIC,
    461      1.1  macallan  *	-FDT_ERR_BADVERSION,
    462      1.1  macallan  *	-FDT_ERR_BADSTATE,
    463      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
    464      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings.
    465      1.1  macallan  */
    466      1.1  macallan int fdt_first_property_offset(const void *fdt, int nodeoffset);
    467      1.1  macallan 
    468      1.1  macallan /**
    469      1.1  macallan  * fdt_next_property_offset - step through a node's properties
    470      1.1  macallan  * @fdt: pointer to the device tree blob
    471      1.1  macallan  * @offset: structure block offset of a property
    472      1.1  macallan  *
    473      1.1  macallan  * fdt_next_property_offset() finds the property immediately after the
    474      1.1  macallan  * one at the given structure block offset.  This will be a property
    475      1.1  macallan  * of the same node as the given property.
    476      1.1  macallan  *
    477      1.1  macallan  * returns:
    478      1.1  macallan  *	structure block offset of the next property (>=0), on success
    479      1.1  macallan  *	-FDT_ERR_NOTFOUND, if the given property is the last in its node
    480      1.1  macallan  *	-FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
    481      1.1  macallan  *      -FDT_ERR_BADMAGIC,
    482      1.1  macallan  *	-FDT_ERR_BADVERSION,
    483      1.1  macallan  *	-FDT_ERR_BADSTATE,
    484      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
    485      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings.
    486      1.1  macallan  */
    487      1.1  macallan int fdt_next_property_offset(const void *fdt, int offset);
    488      1.1  macallan 
    489      1.1  macallan /**
    490  1.1.1.2     skrll  * fdt_for_each_property_offset - iterate over all properties of a node
    491  1.1.1.2     skrll  *
    492  1.1.1.2     skrll  * @property_offset:	property offset (int, lvalue)
    493  1.1.1.2     skrll  * @fdt:		FDT blob (const void *)
    494  1.1.1.2     skrll  * @node:		node offset (int)
    495  1.1.1.2     skrll  *
    496  1.1.1.2     skrll  * This is actually a wrapper around a for loop and would be used like so:
    497  1.1.1.2     skrll  *
    498  1.1.1.2     skrll  *	fdt_for_each_property_offset(property, fdt, node) {
    499  1.1.1.2     skrll  *		Use property
    500  1.1.1.2     skrll  *		...
    501  1.1.1.2     skrll  *	}
    502  1.1.1.2     skrll  *
    503  1.1.1.2     skrll  *	if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) {
    504  1.1.1.2     skrll  *		Error handling
    505  1.1.1.2     skrll  *	}
    506  1.1.1.2     skrll  *
    507  1.1.1.2     skrll  * Note that this is implemented as a macro and property is used as
    508  1.1.1.2     skrll  * iterator in the loop. The node variable can be constant or even a
    509  1.1.1.2     skrll  * literal.
    510  1.1.1.2     skrll  */
    511  1.1.1.2     skrll #define fdt_for_each_property_offset(property, fdt, node)	\
    512  1.1.1.2     skrll 	for (property = fdt_first_property_offset(fdt, node);	\
    513  1.1.1.2     skrll 	     property >= 0;					\
    514  1.1.1.2     skrll 	     property = fdt_next_property_offset(fdt, property))
    515  1.1.1.2     skrll 
    516  1.1.1.2     skrll /**
    517      1.1  macallan  * fdt_get_property_by_offset - retrieve the property at a given offset
    518      1.1  macallan  * @fdt: pointer to the device tree blob
    519      1.1  macallan  * @offset: offset of the property to retrieve
    520      1.1  macallan  * @lenp: pointer to an integer variable (will be overwritten) or NULL
    521      1.1  macallan  *
    522      1.1  macallan  * fdt_get_property_by_offset() retrieves a pointer to the
    523      1.1  macallan  * fdt_property structure within the device tree blob at the given
    524      1.1  macallan  * offset.  If lenp is non-NULL, the length of the property value is
    525      1.1  macallan  * also returned, in the integer pointed to by lenp.
    526      1.1  macallan  *
    527      1.1  macallan  * returns:
    528      1.1  macallan  *	pointer to the structure representing the property
    529      1.1  macallan  *		if lenp is non-NULL, *lenp contains the length of the property
    530      1.1  macallan  *		value (>=0)
    531      1.1  macallan  *	NULL, on error
    532      1.1  macallan  *		if lenp is non-NULL, *lenp contains an error code (<0):
    533      1.1  macallan  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
    534      1.1  macallan  *		-FDT_ERR_BADMAGIC,
    535      1.1  macallan  *		-FDT_ERR_BADVERSION,
    536      1.1  macallan  *		-FDT_ERR_BADSTATE,
    537      1.1  macallan  *		-FDT_ERR_BADSTRUCTURE,
    538      1.1  macallan  *		-FDT_ERR_TRUNCATED, standard meanings
    539      1.1  macallan  */
    540      1.1  macallan const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
    541      1.1  macallan 						      int offset,
    542      1.1  macallan 						      int *lenp);
    543      1.1  macallan 
    544      1.1  macallan /**
    545      1.1  macallan  * fdt_get_property_namelen - find a property based on substring
    546      1.1  macallan  * @fdt: pointer to the device tree blob
    547      1.1  macallan  * @nodeoffset: offset of the node whose property to find
    548      1.1  macallan  * @name: name of the property to find
    549      1.1  macallan  * @namelen: number of characters of name to consider
    550      1.1  macallan  * @lenp: pointer to an integer variable (will be overwritten) or NULL
    551      1.1  macallan  *
    552      1.1  macallan  * Identical to fdt_get_property(), but only examine the first namelen
    553      1.1  macallan  * characters of name for matching the property name.
    554      1.1  macallan  */
    555      1.1  macallan const struct fdt_property *fdt_get_property_namelen(const void *fdt,
    556      1.1  macallan 						    int nodeoffset,
    557      1.1  macallan 						    const char *name,
    558      1.1  macallan 						    int namelen, int *lenp);
    559      1.1  macallan 
    560      1.1  macallan /**
    561      1.1  macallan  * fdt_get_property - find a given property in a given node
    562      1.1  macallan  * @fdt: pointer to the device tree blob
    563      1.1  macallan  * @nodeoffset: offset of the node whose property to find
    564      1.1  macallan  * @name: name of the property to find
    565      1.1  macallan  * @lenp: pointer to an integer variable (will be overwritten) or NULL
    566      1.1  macallan  *
    567      1.1  macallan  * fdt_get_property() retrieves a pointer to the fdt_property
    568      1.1  macallan  * structure within the device tree blob corresponding to the property
    569      1.1  macallan  * named 'name' of the node at offset nodeoffset.  If lenp is
    570      1.1  macallan  * non-NULL, the length of the property value is also returned, in the
    571      1.1  macallan  * integer pointed to by lenp.
    572      1.1  macallan  *
    573      1.1  macallan  * returns:
    574      1.1  macallan  *	pointer to the structure representing the property
    575      1.1  macallan  *		if lenp is non-NULL, *lenp contains the length of the property
    576      1.1  macallan  *		value (>=0)
    577      1.1  macallan  *	NULL, on error
    578      1.1  macallan  *		if lenp is non-NULL, *lenp contains an error code (<0):
    579      1.1  macallan  *		-FDT_ERR_NOTFOUND, node does not have named property
    580  1.1.1.2     skrll  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
    581  1.1.1.2     skrll  *			tag
    582      1.1  macallan  *		-FDT_ERR_BADMAGIC,
    583      1.1  macallan  *		-FDT_ERR_BADVERSION,
    584      1.1  macallan  *		-FDT_ERR_BADSTATE,
    585      1.1  macallan  *		-FDT_ERR_BADSTRUCTURE,
    586      1.1  macallan  *		-FDT_ERR_TRUNCATED, standard meanings
    587      1.1  macallan  */
    588      1.1  macallan const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
    589      1.1  macallan 					    const char *name, int *lenp);
    590      1.1  macallan static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
    591      1.1  macallan 						      const char *name,
    592      1.1  macallan 						      int *lenp)
    593      1.1  macallan {
    594      1.1  macallan 	return (struct fdt_property *)(uintptr_t)
    595      1.1  macallan 		fdt_get_property(fdt, nodeoffset, name, lenp);
    596      1.1  macallan }
    597      1.1  macallan 
    598      1.1  macallan /**
    599      1.1  macallan  * fdt_getprop_by_offset - retrieve the value of a property at a given offset
    600      1.1  macallan  * @fdt: pointer to the device tree blob
    601      1.1  macallan  * @ffset: offset of the property to read
    602      1.1  macallan  * @namep: pointer to a string variable (will be overwritten) or NULL
    603      1.1  macallan  * @lenp: pointer to an integer variable (will be overwritten) or NULL
    604      1.1  macallan  *
    605      1.1  macallan  * fdt_getprop_by_offset() retrieves a pointer to the value of the
    606      1.1  macallan  * property at structure block offset 'offset' (this will be a pointer
    607      1.1  macallan  * to within the device blob itself, not a copy of the value).  If
    608      1.1  macallan  * lenp is non-NULL, the length of the property value is also
    609      1.1  macallan  * returned, in the integer pointed to by lenp.  If namep is non-NULL,
    610      1.1  macallan  * the property's namne will also be returned in the char * pointed to
    611      1.1  macallan  * by namep (this will be a pointer to within the device tree's string
    612      1.1  macallan  * block, not a new copy of the name).
    613      1.1  macallan  *
    614      1.1  macallan  * returns:
    615      1.1  macallan  *	pointer to the property's value
    616      1.1  macallan  *		if lenp is non-NULL, *lenp contains the length of the property
    617      1.1  macallan  *		value (>=0)
    618      1.1  macallan  *		if namep is non-NULL *namep contiains a pointer to the property
    619      1.1  macallan  *		name.
    620      1.1  macallan  *	NULL, on error
    621      1.1  macallan  *		if lenp is non-NULL, *lenp contains an error code (<0):
    622      1.1  macallan  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
    623      1.1  macallan  *		-FDT_ERR_BADMAGIC,
    624      1.1  macallan  *		-FDT_ERR_BADVERSION,
    625      1.1  macallan  *		-FDT_ERR_BADSTATE,
    626      1.1  macallan  *		-FDT_ERR_BADSTRUCTURE,
    627      1.1  macallan  *		-FDT_ERR_TRUNCATED, standard meanings
    628      1.1  macallan  */
    629      1.1  macallan const void *fdt_getprop_by_offset(const void *fdt, int offset,
    630      1.1  macallan 				  const char **namep, int *lenp);
    631      1.1  macallan 
    632      1.1  macallan /**
    633      1.1  macallan  * fdt_getprop_namelen - get property value based on substring
    634      1.1  macallan  * @fdt: pointer to the device tree blob
    635      1.1  macallan  * @nodeoffset: offset of the node whose property to find
    636      1.1  macallan  * @name: name of the property to find
    637      1.1  macallan  * @namelen: number of characters of name to consider
    638      1.1  macallan  * @lenp: pointer to an integer variable (will be overwritten) or NULL
    639      1.1  macallan  *
    640      1.1  macallan  * Identical to fdt_getprop(), but only examine the first namelen
    641      1.1  macallan  * characters of name for matching the property name.
    642      1.1  macallan  */
    643      1.1  macallan const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
    644      1.1  macallan 				const char *name, int namelen, int *lenp);
    645  1.1.1.2     skrll static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
    646  1.1.1.2     skrll 					  const char *name, int namelen,
    647  1.1.1.2     skrll 					  int *lenp)
    648  1.1.1.2     skrll {
    649  1.1.1.2     skrll 	return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
    650  1.1.1.2     skrll 						      namelen, lenp);
    651  1.1.1.2     skrll }
    652      1.1  macallan 
    653      1.1  macallan /**
    654      1.1  macallan  * fdt_getprop - retrieve the value of a given property
    655      1.1  macallan  * @fdt: pointer to the device tree blob
    656      1.1  macallan  * @nodeoffset: offset of the node whose property to find
    657      1.1  macallan  * @name: name of the property to find
    658      1.1  macallan  * @lenp: pointer to an integer variable (will be overwritten) or NULL
    659      1.1  macallan  *
    660      1.1  macallan  * fdt_getprop() retrieves a pointer to the value of the property
    661      1.1  macallan  * named 'name' of the node at offset nodeoffset (this will be a
    662      1.1  macallan  * pointer to within the device blob itself, not a copy of the value).
    663      1.1  macallan  * If lenp is non-NULL, the length of the property value is also
    664      1.1  macallan  * returned, in the integer pointed to by lenp.
    665      1.1  macallan  *
    666      1.1  macallan  * returns:
    667      1.1  macallan  *	pointer to the property's value
    668      1.1  macallan  *		if lenp is non-NULL, *lenp contains the length of the property
    669      1.1  macallan  *		value (>=0)
    670      1.1  macallan  *	NULL, on error
    671      1.1  macallan  *		if lenp is non-NULL, *lenp contains an error code (<0):
    672      1.1  macallan  *		-FDT_ERR_NOTFOUND, node does not have named property
    673  1.1.1.2     skrll  *		-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
    674  1.1.1.2     skrll  *			tag
    675      1.1  macallan  *		-FDT_ERR_BADMAGIC,
    676      1.1  macallan  *		-FDT_ERR_BADVERSION,
    677      1.1  macallan  *		-FDT_ERR_BADSTATE,
    678      1.1  macallan  *		-FDT_ERR_BADSTRUCTURE,
    679      1.1  macallan  *		-FDT_ERR_TRUNCATED, standard meanings
    680      1.1  macallan  */
    681      1.1  macallan const void *fdt_getprop(const void *fdt, int nodeoffset,
    682      1.1  macallan 			const char *name, int *lenp);
    683      1.1  macallan static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
    684      1.1  macallan 				  const char *name, int *lenp)
    685      1.1  macallan {
    686      1.1  macallan 	return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
    687      1.1  macallan }
    688      1.1  macallan 
    689      1.1  macallan /**
    690      1.1  macallan  * fdt_get_phandle - retrieve the phandle of a given node
    691      1.1  macallan  * @fdt: pointer to the device tree blob
    692      1.1  macallan  * @nodeoffset: structure block offset of the node
    693      1.1  macallan  *
    694      1.1  macallan  * fdt_get_phandle() retrieves the phandle of the device tree node at
    695      1.1  macallan  * structure block offset nodeoffset.
    696      1.1  macallan  *
    697      1.1  macallan  * returns:
    698      1.1  macallan  *	the phandle of the node at nodeoffset, on success (!= 0, != -1)
    699      1.1  macallan  *	0, if the node has no phandle, or another error occurs
    700      1.1  macallan  */
    701      1.1  macallan uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
    702      1.1  macallan 
    703      1.1  macallan /**
    704      1.1  macallan  * fdt_get_alias_namelen - get alias based on substring
    705      1.1  macallan  * @fdt: pointer to the device tree blob
    706      1.1  macallan  * @name: name of the alias th look up
    707      1.1  macallan  * @namelen: number of characters of name to consider
    708      1.1  macallan  *
    709      1.1  macallan  * Identical to fdt_get_alias(), but only examine the first namelen
    710      1.1  macallan  * characters of name for matching the alias name.
    711      1.1  macallan  */
    712      1.1  macallan const char *fdt_get_alias_namelen(const void *fdt,
    713      1.1  macallan 				  const char *name, int namelen);
    714      1.1  macallan 
    715      1.1  macallan /**
    716  1.1.1.2     skrll  * fdt_get_alias - retrieve the path referenced by a given alias
    717      1.1  macallan  * @fdt: pointer to the device tree blob
    718      1.1  macallan  * @name: name of the alias th look up
    719      1.1  macallan  *
    720      1.1  macallan  * fdt_get_alias() retrieves the value of a given alias.  That is, the
    721      1.1  macallan  * value of the property named 'name' in the node /aliases.
    722      1.1  macallan  *
    723      1.1  macallan  * returns:
    724      1.1  macallan  *	a pointer to the expansion of the alias named 'name', if it exists
    725      1.1  macallan  *	NULL, if the given alias or the /aliases node does not exist
    726      1.1  macallan  */
    727      1.1  macallan const char *fdt_get_alias(const void *fdt, const char *name);
    728      1.1  macallan 
    729      1.1  macallan /**
    730      1.1  macallan  * fdt_get_path - determine the full path of a node
    731      1.1  macallan  * @fdt: pointer to the device tree blob
    732      1.1  macallan  * @nodeoffset: offset of the node whose path to find
    733      1.1  macallan  * @buf: character buffer to contain the returned path (will be overwritten)
    734      1.1  macallan  * @buflen: size of the character buffer at buf
    735      1.1  macallan  *
    736      1.1  macallan  * fdt_get_path() computes the full path of the node at offset
    737      1.1  macallan  * nodeoffset, and records that path in the buffer at buf.
    738      1.1  macallan  *
    739      1.1  macallan  * NOTE: This function is expensive, as it must scan the device tree
    740      1.1  macallan  * structure from the start to nodeoffset.
    741      1.1  macallan  *
    742      1.1  macallan  * returns:
    743      1.1  macallan  *	0, on success
    744      1.1  macallan  *		buf contains the absolute path of the node at
    745      1.1  macallan  *		nodeoffset, as a NUL-terminated string.
    746  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
    747      1.1  macallan  *	-FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
    748      1.1  macallan  *		characters and will not fit in the given buffer.
    749      1.1  macallan  *	-FDT_ERR_BADMAGIC,
    750      1.1  macallan  *	-FDT_ERR_BADVERSION,
    751      1.1  macallan  *	-FDT_ERR_BADSTATE,
    752      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE, standard meanings
    753      1.1  macallan  */
    754      1.1  macallan int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
    755      1.1  macallan 
    756      1.1  macallan /**
    757      1.1  macallan  * fdt_supernode_atdepth_offset - find a specific ancestor of a node
    758      1.1  macallan  * @fdt: pointer to the device tree blob
    759      1.1  macallan  * @nodeoffset: offset of the node whose parent to find
    760      1.1  macallan  * @supernodedepth: depth of the ancestor to find
    761      1.1  macallan  * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
    762      1.1  macallan  *
    763      1.1  macallan  * fdt_supernode_atdepth_offset() finds an ancestor of the given node
    764      1.1  macallan  * at a specific depth from the root (where the root itself has depth
    765      1.1  macallan  * 0, its immediate subnodes depth 1 and so forth).  So
    766      1.1  macallan  *	fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
    767      1.1  macallan  * will always return 0, the offset of the root node.  If the node at
    768      1.1  macallan  * nodeoffset has depth D, then:
    769      1.1  macallan  *	fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
    770      1.1  macallan  * will return nodeoffset itself.
    771      1.1  macallan  *
    772      1.1  macallan  * NOTE: This function is expensive, as it must scan the device tree
    773      1.1  macallan  * structure from the start to nodeoffset.
    774      1.1  macallan  *
    775      1.1  macallan  * returns:
    776      1.1  macallan  *	structure block offset of the node at node offset's ancestor
    777      1.1  macallan  *		of depth supernodedepth (>=0), on success
    778  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
    779  1.1.1.2     skrll  *	-FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
    780  1.1.1.2     skrll  *		nodeoffset
    781      1.1  macallan  *	-FDT_ERR_BADMAGIC,
    782      1.1  macallan  *	-FDT_ERR_BADVERSION,
    783      1.1  macallan  *	-FDT_ERR_BADSTATE,
    784      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE, standard meanings
    785      1.1  macallan  */
    786      1.1  macallan int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
    787      1.1  macallan 				 int supernodedepth, int *nodedepth);
    788      1.1  macallan 
    789      1.1  macallan /**
    790      1.1  macallan  * fdt_node_depth - find the depth of a given node
    791      1.1  macallan  * @fdt: pointer to the device tree blob
    792      1.1  macallan  * @nodeoffset: offset of the node whose parent to find
    793      1.1  macallan  *
    794      1.1  macallan  * fdt_node_depth() finds the depth of a given node.  The root node
    795      1.1  macallan  * has depth 0, its immediate subnodes depth 1 and so forth.
    796      1.1  macallan  *
    797      1.1  macallan  * NOTE: This function is expensive, as it must scan the device tree
    798      1.1  macallan  * structure from the start to nodeoffset.
    799      1.1  macallan  *
    800      1.1  macallan  * returns:
    801      1.1  macallan  *	depth of the node at nodeoffset (>=0), on success
    802  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
    803      1.1  macallan  *	-FDT_ERR_BADMAGIC,
    804      1.1  macallan  *	-FDT_ERR_BADVERSION,
    805      1.1  macallan  *	-FDT_ERR_BADSTATE,
    806      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE, standard meanings
    807      1.1  macallan  */
    808      1.1  macallan int fdt_node_depth(const void *fdt, int nodeoffset);
    809      1.1  macallan 
    810      1.1  macallan /**
    811      1.1  macallan  * fdt_parent_offset - find the parent of a given node
    812      1.1  macallan  * @fdt: pointer to the device tree blob
    813      1.1  macallan  * @nodeoffset: offset of the node whose parent to find
    814      1.1  macallan  *
    815      1.1  macallan  * fdt_parent_offset() locates the parent node of a given node (that
    816      1.1  macallan  * is, it finds the offset of the node which contains the node at
    817      1.1  macallan  * nodeoffset as a subnode).
    818      1.1  macallan  *
    819      1.1  macallan  * NOTE: This function is expensive, as it must scan the device tree
    820      1.1  macallan  * structure from the start to nodeoffset, *twice*.
    821      1.1  macallan  *
    822      1.1  macallan  * returns:
    823      1.1  macallan  *	structure block offset of the parent of the node at nodeoffset
    824      1.1  macallan  *		(>=0), on success
    825  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
    826      1.1  macallan  *	-FDT_ERR_BADMAGIC,
    827      1.1  macallan  *	-FDT_ERR_BADVERSION,
    828      1.1  macallan  *	-FDT_ERR_BADSTATE,
    829      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE, standard meanings
    830      1.1  macallan  */
    831      1.1  macallan int fdt_parent_offset(const void *fdt, int nodeoffset);
    832      1.1  macallan 
    833      1.1  macallan /**
    834      1.1  macallan  * fdt_node_offset_by_prop_value - find nodes with a given property value
    835      1.1  macallan  * @fdt: pointer to the device tree blob
    836      1.1  macallan  * @startoffset: only find nodes after this offset
    837      1.1  macallan  * @propname: property name to check
    838      1.1  macallan  * @propval: property value to search for
    839      1.1  macallan  * @proplen: length of the value in propval
    840      1.1  macallan  *
    841      1.1  macallan  * fdt_node_offset_by_prop_value() returns the offset of the first
    842      1.1  macallan  * node after startoffset, which has a property named propname whose
    843      1.1  macallan  * value is of length proplen and has value equal to propval; or if
    844      1.1  macallan  * startoffset is -1, the very first such node in the tree.
    845      1.1  macallan  *
    846      1.1  macallan  * To iterate through all nodes matching the criterion, the following
    847      1.1  macallan  * idiom can be used:
    848      1.1  macallan  *	offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
    849      1.1  macallan  *					       propval, proplen);
    850      1.1  macallan  *	while (offset != -FDT_ERR_NOTFOUND) {
    851      1.1  macallan  *		// other code here
    852      1.1  macallan  *		offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
    853      1.1  macallan  *						       propval, proplen);
    854      1.1  macallan  *	}
    855      1.1  macallan  *
    856      1.1  macallan  * Note the -1 in the first call to the function, if 0 is used here
    857      1.1  macallan  * instead, the function will never locate the root node, even if it
    858      1.1  macallan  * matches the criterion.
    859      1.1  macallan  *
    860      1.1  macallan  * returns:
    861      1.1  macallan  *	structure block offset of the located node (>= 0, >startoffset),
    862      1.1  macallan  *		 on success
    863      1.1  macallan  *	-FDT_ERR_NOTFOUND, no node matching the criterion exists in the
    864      1.1  macallan  *		tree after startoffset
    865  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
    866      1.1  macallan  *	-FDT_ERR_BADMAGIC,
    867      1.1  macallan  *	-FDT_ERR_BADVERSION,
    868      1.1  macallan  *	-FDT_ERR_BADSTATE,
    869      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE, standard meanings
    870      1.1  macallan  */
    871      1.1  macallan int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
    872      1.1  macallan 				  const char *propname,
    873      1.1  macallan 				  const void *propval, int proplen);
    874      1.1  macallan 
    875      1.1  macallan /**
    876      1.1  macallan  * fdt_node_offset_by_phandle - find the node with a given phandle
    877      1.1  macallan  * @fdt: pointer to the device tree blob
    878      1.1  macallan  * @phandle: phandle value
    879      1.1  macallan  *
    880      1.1  macallan  * fdt_node_offset_by_phandle() returns the offset of the node
    881      1.1  macallan  * which has the given phandle value.  If there is more than one node
    882      1.1  macallan  * in the tree with the given phandle (an invalid tree), results are
    883      1.1  macallan  * undefined.
    884      1.1  macallan  *
    885      1.1  macallan  * returns:
    886      1.1  macallan  *	structure block offset of the located node (>= 0), on success
    887      1.1  macallan  *	-FDT_ERR_NOTFOUND, no node with that phandle exists
    888      1.1  macallan  *	-FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
    889      1.1  macallan  *	-FDT_ERR_BADMAGIC,
    890      1.1  macallan  *	-FDT_ERR_BADVERSION,
    891      1.1  macallan  *	-FDT_ERR_BADSTATE,
    892      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE, standard meanings
    893      1.1  macallan  */
    894      1.1  macallan int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
    895      1.1  macallan 
    896      1.1  macallan /**
    897      1.1  macallan  * fdt_node_check_compatible: check a node's compatible property
    898      1.1  macallan  * @fdt: pointer to the device tree blob
    899      1.1  macallan  * @nodeoffset: offset of a tree node
    900      1.1  macallan  * @compatible: string to match against
    901      1.1  macallan  *
    902      1.1  macallan  *
    903      1.1  macallan  * fdt_node_check_compatible() returns 0 if the given node contains a
    904      1.1  macallan  * 'compatible' property with the given string as one of its elements,
    905      1.1  macallan  * it returns non-zero otherwise, or on error.
    906      1.1  macallan  *
    907      1.1  macallan  * returns:
    908      1.1  macallan  *	0, if the node has a 'compatible' property listing the given string
    909      1.1  macallan  *	1, if the node has a 'compatible' property, but it does not list
    910      1.1  macallan  *		the given string
    911      1.1  macallan  *	-FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
    912  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
    913      1.1  macallan  *	-FDT_ERR_BADMAGIC,
    914      1.1  macallan  *	-FDT_ERR_BADVERSION,
    915      1.1  macallan  *	-FDT_ERR_BADSTATE,
    916      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE, standard meanings
    917      1.1  macallan  */
    918      1.1  macallan int fdt_node_check_compatible(const void *fdt, int nodeoffset,
    919      1.1  macallan 			      const char *compatible);
    920      1.1  macallan 
    921      1.1  macallan /**
    922      1.1  macallan  * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
    923      1.1  macallan  * @fdt: pointer to the device tree blob
    924      1.1  macallan  * @startoffset: only find nodes after this offset
    925      1.1  macallan  * @compatible: 'compatible' string to match against
    926      1.1  macallan  *
    927      1.1  macallan  * fdt_node_offset_by_compatible() returns the offset of the first
    928      1.1  macallan  * node after startoffset, which has a 'compatible' property which
    929      1.1  macallan  * lists the given compatible string; or if startoffset is -1, the
    930      1.1  macallan  * very first such node in the tree.
    931      1.1  macallan  *
    932      1.1  macallan  * To iterate through all nodes matching the criterion, the following
    933      1.1  macallan  * idiom can be used:
    934      1.1  macallan  *	offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
    935      1.1  macallan  *	while (offset != -FDT_ERR_NOTFOUND) {
    936      1.1  macallan  *		// other code here
    937      1.1  macallan  *		offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
    938      1.1  macallan  *	}
    939      1.1  macallan  *
    940      1.1  macallan  * Note the -1 in the first call to the function, if 0 is used here
    941      1.1  macallan  * instead, the function will never locate the root node, even if it
    942      1.1  macallan  * matches the criterion.
    943      1.1  macallan  *
    944      1.1  macallan  * returns:
    945      1.1  macallan  *	structure block offset of the located node (>= 0, >startoffset),
    946      1.1  macallan  *		 on success
    947      1.1  macallan  *	-FDT_ERR_NOTFOUND, no node matching the criterion exists in the
    948      1.1  macallan  *		tree after startoffset
    949  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
    950      1.1  macallan  *	-FDT_ERR_BADMAGIC,
    951      1.1  macallan  *	-FDT_ERR_BADVERSION,
    952      1.1  macallan  *	-FDT_ERR_BADSTATE,
    953      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE, standard meanings
    954      1.1  macallan  */
    955      1.1  macallan int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
    956      1.1  macallan 				  const char *compatible);
    957      1.1  macallan 
    958      1.1  macallan /**
    959      1.1  macallan  * fdt_stringlist_contains - check a string list property for a string
    960      1.1  macallan  * @strlist: Property containing a list of strings to check
    961      1.1  macallan  * @listlen: Length of property
    962      1.1  macallan  * @str: String to search for
    963      1.1  macallan  *
    964      1.1  macallan  * This is a utility function provided for convenience. The list contains
    965      1.1  macallan  * one or more strings, each terminated by \0, as is found in a device tree
    966      1.1  macallan  * "compatible" property.
    967      1.1  macallan  *
    968      1.1  macallan  * @return: 1 if the string is found in the list, 0 not found, or invalid list
    969      1.1  macallan  */
    970      1.1  macallan int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
    971      1.1  macallan 
    972      1.1  macallan /**
    973      1.1  macallan  * fdt_stringlist_count - count the number of strings in a string list
    974      1.1  macallan  * @fdt: pointer to the device tree blob
    975      1.1  macallan  * @nodeoffset: offset of a tree node
    976      1.1  macallan  * @property: name of the property containing the string list
    977      1.1  macallan  * @return:
    978      1.1  macallan  *   the number of strings in the given property
    979      1.1  macallan  *   -FDT_ERR_BADVALUE if the property value is not NUL-terminated
    980      1.1  macallan  *   -FDT_ERR_NOTFOUND if the property does not exist
    981      1.1  macallan  */
    982      1.1  macallan int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
    983      1.1  macallan 
    984      1.1  macallan /**
    985      1.1  macallan  * fdt_stringlist_search - find a string in a string list and return its index
    986      1.1  macallan  * @fdt: pointer to the device tree blob
    987      1.1  macallan  * @nodeoffset: offset of a tree node
    988      1.1  macallan  * @property: name of the property containing the string list
    989      1.1  macallan  * @string: string to look up in the string list
    990      1.1  macallan  *
    991      1.1  macallan  * Note that it is possible for this function to succeed on property values
    992      1.1  macallan  * that are not NUL-terminated. That's because the function will stop after
    993      1.1  macallan  * finding the first occurrence of @string. This can for example happen with
    994      1.1  macallan  * small-valued cell properties, such as #address-cells, when searching for
    995      1.1  macallan  * the empty string.
    996      1.1  macallan  *
    997      1.1  macallan  * @return:
    998      1.1  macallan  *   the index of the string in the list of strings
    999      1.1  macallan  *   -FDT_ERR_BADVALUE if the property value is not NUL-terminated
   1000      1.1  macallan  *   -FDT_ERR_NOTFOUND if the property does not exist or does not contain
   1001      1.1  macallan  *                     the given string
   1002      1.1  macallan  */
   1003      1.1  macallan int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
   1004      1.1  macallan 			  const char *string);
   1005      1.1  macallan 
   1006      1.1  macallan /**
   1007      1.1  macallan  * fdt_stringlist_get() - obtain the string at a given index in a string list
   1008      1.1  macallan  * @fdt: pointer to the device tree blob
   1009      1.1  macallan  * @nodeoffset: offset of a tree node
   1010      1.1  macallan  * @property: name of the property containing the string list
   1011      1.1  macallan  * @index: index of the string to return
   1012      1.1  macallan  * @lenp: return location for the string length or an error code on failure
   1013      1.1  macallan  *
   1014      1.1  macallan  * Note that this will successfully extract strings from properties with
   1015      1.1  macallan  * non-NUL-terminated values. For example on small-valued cell properties
   1016      1.1  macallan  * this function will return the empty string.
   1017      1.1  macallan  *
   1018      1.1  macallan  * If non-NULL, the length of the string (on success) or a negative error-code
   1019      1.1  macallan  * (on failure) will be stored in the integer pointer to by lenp.
   1020      1.1  macallan  *
   1021      1.1  macallan  * @return:
   1022      1.1  macallan  *   A pointer to the string at the given index in the string list or NULL on
   1023      1.1  macallan  *   failure. On success the length of the string will be stored in the memory
   1024      1.1  macallan  *   location pointed to by the lenp parameter, if non-NULL. On failure one of
   1025      1.1  macallan  *   the following negative error codes will be returned in the lenp parameter
   1026      1.1  macallan  *   (if non-NULL):
   1027      1.1  macallan  *     -FDT_ERR_BADVALUE if the property value is not NUL-terminated
   1028      1.1  macallan  *     -FDT_ERR_NOTFOUND if the property does not exist
   1029      1.1  macallan  */
   1030      1.1  macallan const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
   1031      1.1  macallan 			       const char *property, int index,
   1032      1.1  macallan 			       int *lenp);
   1033      1.1  macallan 
   1034      1.1  macallan /**********************************************************************/
   1035      1.1  macallan /* Read-only functions (addressing related)                           */
   1036      1.1  macallan /**********************************************************************/
   1037      1.1  macallan 
   1038      1.1  macallan /**
   1039      1.1  macallan  * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
   1040      1.1  macallan  *
   1041      1.1  macallan  * This is the maximum value for #address-cells, #size-cells and
   1042      1.1  macallan  * similar properties that will be processed by libfdt.  IEE1275
   1043      1.1  macallan  * requires that OF implementations handle values up to 4.
   1044      1.1  macallan  * Implementations may support larger values, but in practice higher
   1045      1.1  macallan  * values aren't used.
   1046      1.1  macallan  */
   1047      1.1  macallan #define FDT_MAX_NCELLS		4
   1048      1.1  macallan 
   1049      1.1  macallan /**
   1050      1.1  macallan  * fdt_address_cells - retrieve address size for a bus represented in the tree
   1051      1.1  macallan  * @fdt: pointer to the device tree blob
   1052      1.1  macallan  * @nodeoffset: offset of the node to find the address size for
   1053      1.1  macallan  *
   1054      1.1  macallan  * When the node has a valid #address-cells property, returns its value.
   1055      1.1  macallan  *
   1056      1.1  macallan  * returns:
   1057      1.1  macallan  *	0 <= n < FDT_MAX_NCELLS, on success
   1058      1.1  macallan  *      2, if the node has no #address-cells property
   1059  1.1.1.2     skrll  *      -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
   1060  1.1.1.2     skrll  *		#address-cells property
   1061      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1062      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1063      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1064      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1065      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1066      1.1  macallan  */
   1067      1.1  macallan int fdt_address_cells(const void *fdt, int nodeoffset);
   1068      1.1  macallan 
   1069      1.1  macallan /**
   1070      1.1  macallan  * fdt_size_cells - retrieve address range size for a bus represented in the
   1071      1.1  macallan  *                  tree
   1072      1.1  macallan  * @fdt: pointer to the device tree blob
   1073      1.1  macallan  * @nodeoffset: offset of the node to find the address range size for
   1074      1.1  macallan  *
   1075      1.1  macallan  * When the node has a valid #size-cells property, returns its value.
   1076      1.1  macallan  *
   1077      1.1  macallan  * returns:
   1078      1.1  macallan  *	0 <= n < FDT_MAX_NCELLS, on success
   1079      1.1  macallan  *      2, if the node has no #address-cells property
   1080  1.1.1.2     skrll  *      -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
   1081  1.1.1.2     skrll  *		#size-cells property
   1082      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1083      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1084      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1085      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1086      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1087      1.1  macallan  */
   1088      1.1  macallan int fdt_size_cells(const void *fdt, int nodeoffset);
   1089      1.1  macallan 
   1090      1.1  macallan 
   1091      1.1  macallan /**********************************************************************/
   1092      1.1  macallan /* Write-in-place functions                                           */
   1093      1.1  macallan /**********************************************************************/
   1094      1.1  macallan 
   1095      1.1  macallan /**
   1096  1.1.1.2     skrll  * fdt_setprop_inplace_namelen_partial - change a property's value,
   1097  1.1.1.2     skrll  *                                       but not its size
   1098  1.1.1.2     skrll  * @fdt: pointer to the device tree blob
   1099  1.1.1.2     skrll  * @nodeoffset: offset of the node whose property to change
   1100  1.1.1.2     skrll  * @name: name of the property to change
   1101  1.1.1.2     skrll  * @namelen: number of characters of name to consider
   1102  1.1.1.2     skrll  * @idx: index of the property to change in the array
   1103  1.1.1.2     skrll  * @val: pointer to data to replace the property value with
   1104  1.1.1.2     skrll  * @len: length of the property value
   1105  1.1.1.2     skrll  *
   1106  1.1.1.2     skrll  * Identical to fdt_setprop_inplace(), but modifies the given property
   1107  1.1.1.2     skrll  * starting from the given index, and using only the first characters
   1108  1.1.1.2     skrll  * of the name. It is useful when you want to manipulate only one value of
   1109  1.1.1.2     skrll  * an array and you have a string that doesn't end with \0.
   1110  1.1.1.2     skrll  */
   1111  1.1.1.2     skrll int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
   1112  1.1.1.2     skrll 					const char *name, int namelen,
   1113  1.1.1.2     skrll 					uint32_t idx, const void *val,
   1114  1.1.1.2     skrll 					int len);
   1115  1.1.1.2     skrll 
   1116  1.1.1.2     skrll /**
   1117      1.1  macallan  * fdt_setprop_inplace - change a property's value, but not its size
   1118      1.1  macallan  * @fdt: pointer to the device tree blob
   1119      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1120      1.1  macallan  * @name: name of the property to change
   1121      1.1  macallan  * @val: pointer to data to replace the property value with
   1122      1.1  macallan  * @len: length of the property value
   1123      1.1  macallan  *
   1124      1.1  macallan  * fdt_setprop_inplace() replaces the value of a given property with
   1125      1.1  macallan  * the data in val, of length len.  This function cannot change the
   1126      1.1  macallan  * size of a property, and so will only work if len is equal to the
   1127      1.1  macallan  * current length of the property.
   1128      1.1  macallan  *
   1129      1.1  macallan  * This function will alter only the bytes in the blob which contain
   1130      1.1  macallan  * the given property value, and will not alter or move any other part
   1131      1.1  macallan  * of the tree.
   1132      1.1  macallan  *
   1133      1.1  macallan  * returns:
   1134      1.1  macallan  *	0, on success
   1135      1.1  macallan  *	-FDT_ERR_NOSPACE, if len is not equal to the property's current length
   1136      1.1  macallan  *	-FDT_ERR_NOTFOUND, node does not have the named property
   1137      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1138      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1139      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1140      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1141      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1142      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1143      1.1  macallan  */
   1144      1.1  macallan int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
   1145      1.1  macallan 			const void *val, int len);
   1146      1.1  macallan 
   1147      1.1  macallan /**
   1148      1.1  macallan  * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
   1149      1.1  macallan  * @fdt: pointer to the device tree blob
   1150      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1151      1.1  macallan  * @name: name of the property to change
   1152      1.1  macallan  * @val: 32-bit integer value to replace the property with
   1153      1.1  macallan  *
   1154      1.1  macallan  * fdt_setprop_inplace_u32() replaces the value of a given property
   1155      1.1  macallan  * with the 32-bit integer value in val, converting val to big-endian
   1156      1.1  macallan  * if necessary.  This function cannot change the size of a property,
   1157      1.1  macallan  * and so will only work if the property already exists and has length
   1158      1.1  macallan  * 4.
   1159      1.1  macallan  *
   1160      1.1  macallan  * This function will alter only the bytes in the blob which contain
   1161      1.1  macallan  * the given property value, and will not alter or move any other part
   1162      1.1  macallan  * of the tree.
   1163      1.1  macallan  *
   1164      1.1  macallan  * returns:
   1165      1.1  macallan  *	0, on success
   1166      1.1  macallan  *	-FDT_ERR_NOSPACE, if the property's length is not equal to 4
   1167      1.1  macallan  *	-FDT_ERR_NOTFOUND, node does not have the named property
   1168      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1169      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1170      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1171      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1172      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1173      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1174      1.1  macallan  */
   1175      1.1  macallan static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
   1176      1.1  macallan 					  const char *name, uint32_t val)
   1177      1.1  macallan {
   1178      1.1  macallan 	fdt32_t tmp = cpu_to_fdt32(val);
   1179      1.1  macallan 	return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
   1180      1.1  macallan }
   1181      1.1  macallan 
   1182      1.1  macallan /**
   1183      1.1  macallan  * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
   1184      1.1  macallan  * @fdt: pointer to the device tree blob
   1185      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1186      1.1  macallan  * @name: name of the property to change
   1187      1.1  macallan  * @val: 64-bit integer value to replace the property with
   1188      1.1  macallan  *
   1189      1.1  macallan  * fdt_setprop_inplace_u64() replaces the value of a given property
   1190      1.1  macallan  * with the 64-bit integer value in val, converting val to big-endian
   1191      1.1  macallan  * if necessary.  This function cannot change the size of a property,
   1192      1.1  macallan  * and so will only work if the property already exists and has length
   1193      1.1  macallan  * 8.
   1194      1.1  macallan  *
   1195      1.1  macallan  * This function will alter only the bytes in the blob which contain
   1196      1.1  macallan  * the given property value, and will not alter or move any other part
   1197      1.1  macallan  * of the tree.
   1198      1.1  macallan  *
   1199      1.1  macallan  * returns:
   1200      1.1  macallan  *	0, on success
   1201      1.1  macallan  *	-FDT_ERR_NOSPACE, if the property's length is not equal to 8
   1202      1.1  macallan  *	-FDT_ERR_NOTFOUND, node does not have the named property
   1203      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1204      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1205      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1206      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1207      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1208      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1209      1.1  macallan  */
   1210      1.1  macallan static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
   1211      1.1  macallan 					  const char *name, uint64_t val)
   1212      1.1  macallan {
   1213      1.1  macallan 	fdt64_t tmp = cpu_to_fdt64(val);
   1214      1.1  macallan 	return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
   1215      1.1  macallan }
   1216      1.1  macallan 
   1217      1.1  macallan /**
   1218      1.1  macallan  * fdt_setprop_inplace_cell - change the value of a single-cell property
   1219      1.1  macallan  *
   1220      1.1  macallan  * This is an alternative name for fdt_setprop_inplace_u32()
   1221      1.1  macallan  */
   1222      1.1  macallan static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
   1223      1.1  macallan 					   const char *name, uint32_t val)
   1224      1.1  macallan {
   1225      1.1  macallan 	return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
   1226      1.1  macallan }
   1227      1.1  macallan 
   1228      1.1  macallan /**
   1229      1.1  macallan  * fdt_nop_property - replace a property with nop tags
   1230      1.1  macallan  * @fdt: pointer to the device tree blob
   1231      1.1  macallan  * @nodeoffset: offset of the node whose property to nop
   1232      1.1  macallan  * @name: name of the property to nop
   1233      1.1  macallan  *
   1234      1.1  macallan  * fdt_nop_property() will replace a given property's representation
   1235      1.1  macallan  * in the blob with FDT_NOP tags, effectively removing it from the
   1236      1.1  macallan  * tree.
   1237      1.1  macallan  *
   1238      1.1  macallan  * This function will alter only the bytes in the blob which contain
   1239      1.1  macallan  * the property, and will not alter or move any other part of the
   1240      1.1  macallan  * tree.
   1241      1.1  macallan  *
   1242      1.1  macallan  * returns:
   1243      1.1  macallan  *	0, on success
   1244      1.1  macallan  *	-FDT_ERR_NOTFOUND, node does not have the named property
   1245      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1246      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1247      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1248      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1249      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1250      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1251      1.1  macallan  */
   1252      1.1  macallan int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
   1253      1.1  macallan 
   1254      1.1  macallan /**
   1255      1.1  macallan  * fdt_nop_node - replace a node (subtree) with nop tags
   1256      1.1  macallan  * @fdt: pointer to the device tree blob
   1257      1.1  macallan  * @nodeoffset: offset of the node to nop
   1258      1.1  macallan  *
   1259      1.1  macallan  * fdt_nop_node() will replace a given node's representation in the
   1260      1.1  macallan  * blob, including all its subnodes, if any, with FDT_NOP tags,
   1261      1.1  macallan  * effectively removing it from the tree.
   1262      1.1  macallan  *
   1263      1.1  macallan  * This function will alter only the bytes in the blob which contain
   1264      1.1  macallan  * the node and its properties and subnodes, and will not alter or
   1265      1.1  macallan  * move any other part of the tree.
   1266      1.1  macallan  *
   1267      1.1  macallan  * returns:
   1268      1.1  macallan  *	0, on success
   1269      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1270      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1271      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1272      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1273      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1274      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1275      1.1  macallan  */
   1276      1.1  macallan int fdt_nop_node(void *fdt, int nodeoffset);
   1277      1.1  macallan 
   1278      1.1  macallan /**********************************************************************/
   1279      1.1  macallan /* Sequential write functions                                         */
   1280      1.1  macallan /**********************************************************************/
   1281      1.1  macallan 
   1282      1.1  macallan int fdt_create(void *buf, int bufsize);
   1283      1.1  macallan int fdt_resize(void *fdt, void *buf, int bufsize);
   1284      1.1  macallan int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
   1285      1.1  macallan int fdt_finish_reservemap(void *fdt);
   1286      1.1  macallan int fdt_begin_node(void *fdt, const char *name);
   1287      1.1  macallan int fdt_property(void *fdt, const char *name, const void *val, int len);
   1288      1.1  macallan static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
   1289      1.1  macallan {
   1290      1.1  macallan 	fdt32_t tmp = cpu_to_fdt32(val);
   1291      1.1  macallan 	return fdt_property(fdt, name, &tmp, sizeof(tmp));
   1292      1.1  macallan }
   1293      1.1  macallan static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
   1294      1.1  macallan {
   1295      1.1  macallan 	fdt64_t tmp = cpu_to_fdt64(val);
   1296      1.1  macallan 	return fdt_property(fdt, name, &tmp, sizeof(tmp));
   1297      1.1  macallan }
   1298      1.1  macallan static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
   1299      1.1  macallan {
   1300      1.1  macallan 	return fdt_property_u32(fdt, name, val);
   1301      1.1  macallan }
   1302      1.1  macallan #define fdt_property_string(fdt, name, str) \
   1303      1.1  macallan 	fdt_property(fdt, name, str, strlen(str)+1)
   1304      1.1  macallan int fdt_end_node(void *fdt);
   1305      1.1  macallan int fdt_finish(void *fdt);
   1306      1.1  macallan 
   1307      1.1  macallan /**********************************************************************/
   1308      1.1  macallan /* Read-write functions                                               */
   1309      1.1  macallan /**********************************************************************/
   1310      1.1  macallan 
   1311      1.1  macallan int fdt_create_empty_tree(void *buf, int bufsize);
   1312      1.1  macallan int fdt_open_into(const void *fdt, void *buf, int bufsize);
   1313      1.1  macallan int fdt_pack(void *fdt);
   1314      1.1  macallan 
   1315      1.1  macallan /**
   1316      1.1  macallan  * fdt_add_mem_rsv - add one memory reserve map entry
   1317      1.1  macallan  * @fdt: pointer to the device tree blob
   1318      1.1  macallan  * @address, @size: 64-bit values (native endian)
   1319      1.1  macallan  *
   1320      1.1  macallan  * Adds a reserve map entry to the given blob reserving a region at
   1321      1.1  macallan  * address address of length size.
   1322      1.1  macallan  *
   1323      1.1  macallan  * This function will insert data into the reserve map and will
   1324      1.1  macallan  * therefore change the indexes of some entries in the table.
   1325      1.1  macallan  *
   1326      1.1  macallan  * returns:
   1327      1.1  macallan  *	0, on success
   1328      1.1  macallan  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
   1329      1.1  macallan  *		contain the new reservation entry
   1330      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1331      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1332      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1333      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1334      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1335      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1336      1.1  macallan  */
   1337      1.1  macallan int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
   1338      1.1  macallan 
   1339      1.1  macallan /**
   1340      1.1  macallan  * fdt_del_mem_rsv - remove a memory reserve map entry
   1341      1.1  macallan  * @fdt: pointer to the device tree blob
   1342      1.1  macallan  * @n: entry to remove
   1343      1.1  macallan  *
   1344      1.1  macallan  * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
   1345      1.1  macallan  * the blob.
   1346      1.1  macallan  *
   1347      1.1  macallan  * This function will delete data from the reservation table and will
   1348      1.1  macallan  * therefore change the indexes of some entries in the table.
   1349      1.1  macallan  *
   1350      1.1  macallan  * returns:
   1351      1.1  macallan  *	0, on success
   1352      1.1  macallan  *	-FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
   1353      1.1  macallan  *		are less than n+1 reserve map entries)
   1354      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1355      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1356      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1357      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1358      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1359      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1360      1.1  macallan  */
   1361      1.1  macallan int fdt_del_mem_rsv(void *fdt, int n);
   1362      1.1  macallan 
   1363      1.1  macallan /**
   1364      1.1  macallan  * fdt_set_name - change the name of a given node
   1365      1.1  macallan  * @fdt: pointer to the device tree blob
   1366      1.1  macallan  * @nodeoffset: structure block offset of a node
   1367      1.1  macallan  * @name: name to give the node
   1368      1.1  macallan  *
   1369      1.1  macallan  * fdt_set_name() replaces the name (including unit address, if any)
   1370      1.1  macallan  * of the given node with the given string.  NOTE: this function can't
   1371      1.1  macallan  * efficiently check if the new name is unique amongst the given
   1372      1.1  macallan  * node's siblings; results are undefined if this function is invoked
   1373      1.1  macallan  * with a name equal to one of the given node's siblings.
   1374      1.1  macallan  *
   1375      1.1  macallan  * This function may insert or delete data from the blob, and will
   1376      1.1  macallan  * therefore change the offsets of some existing nodes.
   1377      1.1  macallan  *
   1378      1.1  macallan  * returns:
   1379      1.1  macallan  *	0, on success
   1380      1.1  macallan  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob
   1381      1.1  macallan  *		to contain the new name
   1382      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1383      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1384      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1385      1.1  macallan  *	-FDT_ERR_BADSTATE, standard meanings
   1386      1.1  macallan  */
   1387      1.1  macallan int fdt_set_name(void *fdt, int nodeoffset, const char *name);
   1388      1.1  macallan 
   1389      1.1  macallan /**
   1390      1.1  macallan  * fdt_setprop - create or change a property
   1391      1.1  macallan  * @fdt: pointer to the device tree blob
   1392      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1393      1.1  macallan  * @name: name of the property to change
   1394      1.1  macallan  * @val: pointer to data to set the property value to
   1395      1.1  macallan  * @len: length of the property value
   1396      1.1  macallan  *
   1397      1.1  macallan  * fdt_setprop() sets the value of the named property in the given
   1398      1.1  macallan  * node to the given value and length, creating the property if it
   1399      1.1  macallan  * does not already exist.
   1400      1.1  macallan  *
   1401      1.1  macallan  * This function may insert or delete data from the blob, and will
   1402      1.1  macallan  * therefore change the offsets of some existing nodes.
   1403      1.1  macallan  *
   1404      1.1  macallan  * returns:
   1405      1.1  macallan  *	0, on success
   1406      1.1  macallan  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
   1407      1.1  macallan  *		contain the new property value
   1408      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1409      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1410      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1411      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1412      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1413      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1414      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1415      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1416      1.1  macallan  */
   1417      1.1  macallan int fdt_setprop(void *fdt, int nodeoffset, const char *name,
   1418      1.1  macallan 		const void *val, int len);
   1419      1.1  macallan 
   1420      1.1  macallan /**
   1421      1.1  macallan  * fdt_setprop_u32 - set a property to a 32-bit integer
   1422      1.1  macallan  * @fdt: pointer to the device tree blob
   1423      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1424      1.1  macallan  * @name: name of the property to change
   1425      1.1  macallan  * @val: 32-bit integer value for the property (native endian)
   1426      1.1  macallan  *
   1427      1.1  macallan  * fdt_setprop_u32() sets the value of the named property in the given
   1428      1.1  macallan  * node to the given 32-bit integer value (converting to big-endian if
   1429      1.1  macallan  * necessary), or creates a new property with that value if it does
   1430      1.1  macallan  * not already exist.
   1431      1.1  macallan  *
   1432      1.1  macallan  * This function may insert or delete data from the blob, and will
   1433      1.1  macallan  * therefore change the offsets of some existing nodes.
   1434      1.1  macallan  *
   1435      1.1  macallan  * returns:
   1436      1.1  macallan  *	0, on success
   1437      1.1  macallan  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
   1438      1.1  macallan  *		contain the new property value
   1439      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1440      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1441      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1442      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1443      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1444      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1445      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1446      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1447      1.1  macallan  */
   1448      1.1  macallan static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
   1449      1.1  macallan 				  uint32_t val)
   1450      1.1  macallan {
   1451      1.1  macallan 	fdt32_t tmp = cpu_to_fdt32(val);
   1452      1.1  macallan 	return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
   1453      1.1  macallan }
   1454      1.1  macallan 
   1455      1.1  macallan /**
   1456      1.1  macallan  * fdt_setprop_u64 - set a property to a 64-bit integer
   1457      1.1  macallan  * @fdt: pointer to the device tree blob
   1458      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1459      1.1  macallan  * @name: name of the property to change
   1460      1.1  macallan  * @val: 64-bit integer value for the property (native endian)
   1461      1.1  macallan  *
   1462      1.1  macallan  * fdt_setprop_u64() sets the value of the named property in the given
   1463      1.1  macallan  * node to the given 64-bit integer value (converting to big-endian if
   1464      1.1  macallan  * necessary), or creates a new property with that value if it does
   1465      1.1  macallan  * not already exist.
   1466      1.1  macallan  *
   1467      1.1  macallan  * This function may insert or delete data from the blob, and will
   1468      1.1  macallan  * therefore change the offsets of some existing nodes.
   1469      1.1  macallan  *
   1470      1.1  macallan  * returns:
   1471      1.1  macallan  *	0, on success
   1472      1.1  macallan  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
   1473      1.1  macallan  *		contain the new property value
   1474      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1475      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1476      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1477      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1478      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1479      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1480      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1481      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1482      1.1  macallan  */
   1483      1.1  macallan static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
   1484      1.1  macallan 				  uint64_t val)
   1485      1.1  macallan {
   1486      1.1  macallan 	fdt64_t tmp = cpu_to_fdt64(val);
   1487      1.1  macallan 	return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
   1488      1.1  macallan }
   1489      1.1  macallan 
   1490      1.1  macallan /**
   1491      1.1  macallan  * fdt_setprop_cell - set a property to a single cell value
   1492      1.1  macallan  *
   1493      1.1  macallan  * This is an alternative name for fdt_setprop_u32()
   1494      1.1  macallan  */
   1495      1.1  macallan static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
   1496      1.1  macallan 				   uint32_t val)
   1497      1.1  macallan {
   1498      1.1  macallan 	return fdt_setprop_u32(fdt, nodeoffset, name, val);
   1499      1.1  macallan }
   1500      1.1  macallan 
   1501      1.1  macallan /**
   1502      1.1  macallan  * fdt_setprop_string - set a property to a string value
   1503      1.1  macallan  * @fdt: pointer to the device tree blob
   1504      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1505      1.1  macallan  * @name: name of the property to change
   1506      1.1  macallan  * @str: string value for the property
   1507      1.1  macallan  *
   1508      1.1  macallan  * fdt_setprop_string() sets the value of the named property in the
   1509      1.1  macallan  * given node to the given string value (using the length of the
   1510      1.1  macallan  * string to determine the new length of the property), or creates a
   1511      1.1  macallan  * new property with that value if it does not already exist.
   1512      1.1  macallan  *
   1513      1.1  macallan  * This function may insert or delete data from the blob, and will
   1514      1.1  macallan  * therefore change the offsets of some existing nodes.
   1515      1.1  macallan  *
   1516      1.1  macallan  * returns:
   1517      1.1  macallan  *	0, on success
   1518      1.1  macallan  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
   1519      1.1  macallan  *		contain the new property value
   1520      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1521      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1522      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1523      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1524      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1525      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1526      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1527      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1528      1.1  macallan  */
   1529      1.1  macallan #define fdt_setprop_string(fdt, nodeoffset, name, str) \
   1530      1.1  macallan 	fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
   1531      1.1  macallan 
   1532  1.1.1.2     skrll 
   1533  1.1.1.2     skrll /**
   1534  1.1.1.2     skrll  * fdt_setprop_empty - set a property to an empty value
   1535  1.1.1.2     skrll  * @fdt: pointer to the device tree blob
   1536  1.1.1.2     skrll  * @nodeoffset: offset of the node whose property to change
   1537  1.1.1.2     skrll  * @name: name of the property to change
   1538  1.1.1.2     skrll  *
   1539  1.1.1.2     skrll  * fdt_setprop_empty() sets the value of the named property in the
   1540  1.1.1.2     skrll  * given node to an empty (zero length) value, or creates a new empty
   1541  1.1.1.2     skrll  * property if it does not already exist.
   1542  1.1.1.2     skrll  *
   1543  1.1.1.2     skrll  * This function may insert or delete data from the blob, and will
   1544  1.1.1.2     skrll  * therefore change the offsets of some existing nodes.
   1545  1.1.1.2     skrll  *
   1546  1.1.1.2     skrll  * returns:
   1547  1.1.1.2     skrll  *	0, on success
   1548  1.1.1.2     skrll  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
   1549  1.1.1.2     skrll  *		contain the new property value
   1550  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1551  1.1.1.2     skrll  *	-FDT_ERR_BADLAYOUT,
   1552  1.1.1.2     skrll  *	-FDT_ERR_BADMAGIC,
   1553  1.1.1.2     skrll  *	-FDT_ERR_BADVERSION,
   1554  1.1.1.2     skrll  *	-FDT_ERR_BADSTATE,
   1555  1.1.1.2     skrll  *	-FDT_ERR_BADSTRUCTURE,
   1556  1.1.1.2     skrll  *	-FDT_ERR_BADLAYOUT,
   1557  1.1.1.2     skrll  *	-FDT_ERR_TRUNCATED, standard meanings
   1558  1.1.1.2     skrll  */
   1559  1.1.1.2     skrll #define fdt_setprop_empty(fdt, nodeoffset, name) \
   1560  1.1.1.2     skrll 	fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
   1561  1.1.1.2     skrll 
   1562      1.1  macallan /**
   1563      1.1  macallan  * fdt_appendprop - append to or create a property
   1564      1.1  macallan  * @fdt: pointer to the device tree blob
   1565      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1566      1.1  macallan  * @name: name of the property to append to
   1567      1.1  macallan  * @val: pointer to data to append to the property value
   1568      1.1  macallan  * @len: length of the data to append to the property value
   1569      1.1  macallan  *
   1570      1.1  macallan  * fdt_appendprop() appends the value to the named property in the
   1571      1.1  macallan  * given node, creating the property if it does not already exist.
   1572      1.1  macallan  *
   1573      1.1  macallan  * This function may insert data into the blob, and will therefore
   1574      1.1  macallan  * change the offsets of some existing nodes.
   1575      1.1  macallan  *
   1576      1.1  macallan  * returns:
   1577      1.1  macallan  *	0, on success
   1578      1.1  macallan  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
   1579      1.1  macallan  *		contain the new property value
   1580      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1581      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1582      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1583      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1584      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1585      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1586      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1587      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1588      1.1  macallan  */
   1589      1.1  macallan int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
   1590      1.1  macallan 		   const void *val, int len);
   1591      1.1  macallan 
   1592      1.1  macallan /**
   1593      1.1  macallan  * fdt_appendprop_u32 - append a 32-bit integer value to a property
   1594      1.1  macallan  * @fdt: pointer to the device tree blob
   1595      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1596      1.1  macallan  * @name: name of the property to change
   1597      1.1  macallan  * @val: 32-bit integer value to append to the property (native endian)
   1598      1.1  macallan  *
   1599      1.1  macallan  * fdt_appendprop_u32() appends the given 32-bit integer value
   1600      1.1  macallan  * (converting to big-endian if necessary) to the value of the named
   1601      1.1  macallan  * property in the given node, or creates a new property with that
   1602      1.1  macallan  * value if it does not already exist.
   1603      1.1  macallan  *
   1604      1.1  macallan  * This function may insert data into the blob, and will therefore
   1605      1.1  macallan  * change the offsets of some existing nodes.
   1606      1.1  macallan  *
   1607      1.1  macallan  * returns:
   1608      1.1  macallan  *	0, on success
   1609      1.1  macallan  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
   1610      1.1  macallan  *		contain the new property value
   1611      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1612      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1613      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1614      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1615      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1616      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1617      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1618      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1619      1.1  macallan  */
   1620      1.1  macallan static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
   1621      1.1  macallan 				     const char *name, uint32_t val)
   1622      1.1  macallan {
   1623      1.1  macallan 	fdt32_t tmp = cpu_to_fdt32(val);
   1624      1.1  macallan 	return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
   1625      1.1  macallan }
   1626      1.1  macallan 
   1627      1.1  macallan /**
   1628      1.1  macallan  * fdt_appendprop_u64 - append a 64-bit integer value to a property
   1629      1.1  macallan  * @fdt: pointer to the device tree blob
   1630      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1631      1.1  macallan  * @name: name of the property to change
   1632      1.1  macallan  * @val: 64-bit integer value to append to the property (native endian)
   1633      1.1  macallan  *
   1634      1.1  macallan  * fdt_appendprop_u64() appends the given 64-bit integer value
   1635      1.1  macallan  * (converting to big-endian if necessary) to the value of the named
   1636      1.1  macallan  * property in the given node, or creates a new property with that
   1637      1.1  macallan  * value if it does not already exist.
   1638      1.1  macallan  *
   1639      1.1  macallan  * This function may insert data into the blob, and will therefore
   1640      1.1  macallan  * change the offsets of some existing nodes.
   1641      1.1  macallan  *
   1642      1.1  macallan  * returns:
   1643      1.1  macallan  *	0, on success
   1644      1.1  macallan  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
   1645      1.1  macallan  *		contain the new property value
   1646      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1647      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1648      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1649      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1650      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1651      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1652      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1653      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1654      1.1  macallan  */
   1655      1.1  macallan static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
   1656      1.1  macallan 				     const char *name, uint64_t val)
   1657      1.1  macallan {
   1658      1.1  macallan 	fdt64_t tmp = cpu_to_fdt64(val);
   1659      1.1  macallan 	return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
   1660      1.1  macallan }
   1661      1.1  macallan 
   1662      1.1  macallan /**
   1663      1.1  macallan  * fdt_appendprop_cell - append a single cell value to a property
   1664      1.1  macallan  *
   1665      1.1  macallan  * This is an alternative name for fdt_appendprop_u32()
   1666      1.1  macallan  */
   1667      1.1  macallan static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
   1668      1.1  macallan 				      const char *name, uint32_t val)
   1669      1.1  macallan {
   1670      1.1  macallan 	return fdt_appendprop_u32(fdt, nodeoffset, name, val);
   1671      1.1  macallan }
   1672      1.1  macallan 
   1673      1.1  macallan /**
   1674      1.1  macallan  * fdt_appendprop_string - append a string to a property
   1675      1.1  macallan  * @fdt: pointer to the device tree blob
   1676      1.1  macallan  * @nodeoffset: offset of the node whose property to change
   1677      1.1  macallan  * @name: name of the property to change
   1678      1.1  macallan  * @str: string value to append to the property
   1679      1.1  macallan  *
   1680      1.1  macallan  * fdt_appendprop_string() appends the given string to the value of
   1681      1.1  macallan  * the named property in the given node, or creates a new property
   1682      1.1  macallan  * with that value if it does not already exist.
   1683      1.1  macallan  *
   1684      1.1  macallan  * This function may insert data into the blob, and will therefore
   1685      1.1  macallan  * change the offsets of some existing nodes.
   1686      1.1  macallan  *
   1687      1.1  macallan  * returns:
   1688      1.1  macallan  *	0, on success
   1689      1.1  macallan  *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
   1690      1.1  macallan  *		contain the new property value
   1691      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1692      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1693      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1694      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1695      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1696      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1697      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1698      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1699      1.1  macallan  */
   1700      1.1  macallan #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
   1701      1.1  macallan 	fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
   1702      1.1  macallan 
   1703      1.1  macallan /**
   1704      1.1  macallan  * fdt_delprop - delete a property
   1705      1.1  macallan  * @fdt: pointer to the device tree blob
   1706      1.1  macallan  * @nodeoffset: offset of the node whose property to nop
   1707      1.1  macallan  * @name: name of the property to nop
   1708      1.1  macallan  *
   1709      1.1  macallan  * fdt_del_property() will delete the given property.
   1710      1.1  macallan  *
   1711      1.1  macallan  * This function will delete data from the blob, and will therefore
   1712      1.1  macallan  * change the offsets of some existing nodes.
   1713      1.1  macallan  *
   1714      1.1  macallan  * returns:
   1715      1.1  macallan  *	0, on success
   1716      1.1  macallan  *	-FDT_ERR_NOTFOUND, node does not have the named property
   1717      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1718      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1719      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1720      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1721      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1722      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1723      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1724      1.1  macallan  */
   1725      1.1  macallan int fdt_delprop(void *fdt, int nodeoffset, const char *name);
   1726      1.1  macallan 
   1727      1.1  macallan /**
   1728      1.1  macallan  * fdt_add_subnode_namelen - creates a new node based on substring
   1729      1.1  macallan  * @fdt: pointer to the device tree blob
   1730      1.1  macallan  * @parentoffset: structure block offset of a node
   1731      1.1  macallan  * @name: name of the subnode to locate
   1732      1.1  macallan  * @namelen: number of characters of name to consider
   1733      1.1  macallan  *
   1734      1.1  macallan  * Identical to fdt_add_subnode(), but use only the first namelen
   1735      1.1  macallan  * characters of name as the name of the new node.  This is useful for
   1736      1.1  macallan  * creating subnodes based on a portion of a larger string, such as a
   1737      1.1  macallan  * full path.
   1738      1.1  macallan  */
   1739      1.1  macallan int fdt_add_subnode_namelen(void *fdt, int parentoffset,
   1740      1.1  macallan 			    const char *name, int namelen);
   1741      1.1  macallan 
   1742      1.1  macallan /**
   1743      1.1  macallan  * fdt_add_subnode - creates a new node
   1744      1.1  macallan  * @fdt: pointer to the device tree blob
   1745      1.1  macallan  * @parentoffset: structure block offset of a node
   1746      1.1  macallan  * @name: name of the subnode to locate
   1747      1.1  macallan  *
   1748      1.1  macallan  * fdt_add_subnode() creates a new node as a subnode of the node at
   1749      1.1  macallan  * structure block offset parentoffset, with the given name (which
   1750      1.1  macallan  * should include the unit address, if any).
   1751      1.1  macallan  *
   1752      1.1  macallan  * This function will insert data into the blob, and will therefore
   1753      1.1  macallan  * change the offsets of some existing nodes.
   1754      1.1  macallan 
   1755      1.1  macallan  * returns:
   1756  1.1.1.2     skrll  *	structure block offset of the created nodeequested subnode (>=0), on
   1757  1.1.1.2     skrll  *		success
   1758      1.1  macallan  *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
   1759  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
   1760  1.1.1.2     skrll  *		tag
   1761      1.1  macallan  *	-FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
   1762      1.1  macallan  *		the given name
   1763      1.1  macallan  *	-FDT_ERR_NOSPACE, if there is insufficient free space in the
   1764      1.1  macallan  *		blob to contain the new node
   1765      1.1  macallan  *	-FDT_ERR_NOSPACE
   1766      1.1  macallan  *	-FDT_ERR_BADLAYOUT
   1767      1.1  macallan  *      -FDT_ERR_BADMAGIC,
   1768      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1769      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1770      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1771      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings.
   1772      1.1  macallan  */
   1773      1.1  macallan int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
   1774      1.1  macallan 
   1775      1.1  macallan /**
   1776      1.1  macallan  * fdt_del_node - delete a node (subtree)
   1777      1.1  macallan  * @fdt: pointer to the device tree blob
   1778      1.1  macallan  * @nodeoffset: offset of the node to nop
   1779      1.1  macallan  *
   1780      1.1  macallan  * fdt_del_node() will remove the given node, including all its
   1781      1.1  macallan  * subnodes if any, from the blob.
   1782      1.1  macallan  *
   1783      1.1  macallan  * This function will delete data from the blob, and will therefore
   1784      1.1  macallan  * change the offsets of some existing nodes.
   1785      1.1  macallan  *
   1786      1.1  macallan  * returns:
   1787      1.1  macallan  *	0, on success
   1788      1.1  macallan  *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
   1789      1.1  macallan  *	-FDT_ERR_BADLAYOUT,
   1790      1.1  macallan  *	-FDT_ERR_BADMAGIC,
   1791      1.1  macallan  *	-FDT_ERR_BADVERSION,
   1792      1.1  macallan  *	-FDT_ERR_BADSTATE,
   1793      1.1  macallan  *	-FDT_ERR_BADSTRUCTURE,
   1794      1.1  macallan  *	-FDT_ERR_TRUNCATED, standard meanings
   1795      1.1  macallan  */
   1796      1.1  macallan int fdt_del_node(void *fdt, int nodeoffset);
   1797      1.1  macallan 
   1798  1.1.1.2     skrll /**
   1799  1.1.1.2     skrll  * fdt_overlay_apply - Applies a DT overlay on a base DT
   1800  1.1.1.2     skrll  * @fdt: pointer to the base device tree blob
   1801  1.1.1.2     skrll  * @fdto: pointer to the device tree overlay blob
   1802  1.1.1.2     skrll  *
   1803  1.1.1.2     skrll  * fdt_overlay_apply() will apply the given device tree overlay on the
   1804  1.1.1.2     skrll  * given base device tree.
   1805  1.1.1.2     skrll  *
   1806  1.1.1.2     skrll  * Expect the base device tree to be modified, even if the function
   1807  1.1.1.2     skrll  * returns an error.
   1808  1.1.1.2     skrll  *
   1809  1.1.1.2     skrll  * returns:
   1810  1.1.1.2     skrll  *	0, on success
   1811  1.1.1.2     skrll  *	-FDT_ERR_NOSPACE, there's not enough space in the base device tree
   1812  1.1.1.2     skrll  *	-FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
   1813  1.1.1.2     skrll  *		properties in the base DT
   1814  1.1.1.2     skrll  *	-FDT_ERR_BADPHANDLE,
   1815  1.1.1.2     skrll  *	-FDT_ERR_BADOVERLAY,
   1816  1.1.1.2     skrll  *	-FDT_ERR_NOPHANDLES,
   1817  1.1.1.2     skrll  *	-FDT_ERR_INTERNAL,
   1818  1.1.1.2     skrll  *	-FDT_ERR_BADLAYOUT,
   1819  1.1.1.2     skrll  *	-FDT_ERR_BADMAGIC,
   1820  1.1.1.2     skrll  *	-FDT_ERR_BADOFFSET,
   1821  1.1.1.2     skrll  *	-FDT_ERR_BADPATH,
   1822  1.1.1.2     skrll  *	-FDT_ERR_BADVERSION,
   1823  1.1.1.2     skrll  *	-FDT_ERR_BADSTRUCTURE,
   1824  1.1.1.2     skrll  *	-FDT_ERR_BADSTATE,
   1825  1.1.1.2     skrll  *	-FDT_ERR_TRUNCATED, standard meanings
   1826  1.1.1.2     skrll  */
   1827  1.1.1.2     skrll int fdt_overlay_apply(void *fdt, void *fdto);
   1828  1.1.1.2     skrll 
   1829      1.1  macallan /**********************************************************************/
   1830      1.1  macallan /* Debugging / informational functions                                */
   1831      1.1  macallan /**********************************************************************/
   1832      1.1  macallan 
   1833      1.1  macallan const char *fdt_strerror(int errval);
   1834      1.1  macallan 
   1835      1.1  macallan #endif /* _LIBFDT_H */
   1836