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