16780e684SKyle Evans #ifndef LIBFDT_H
26780e684SKyle Evans #define LIBFDT_H
321fdc27aSRafal Jaworowski /*
421fdc27aSRafal Jaworowski * libfdt - Flat Device Tree manipulation
521fdc27aSRafal Jaworowski * Copyright (C) 2006 David Gibson, IBM Corporation.
621fdc27aSRafal Jaworowski *
721fdc27aSRafal Jaworowski * libfdt is dual licensed: you can use it either under the terms of
821fdc27aSRafal Jaworowski * the GPL, or the BSD license, at your option.
921fdc27aSRafal Jaworowski *
1021fdc27aSRafal Jaworowski * a) This library is free software; you can redistribute it and/or
1121fdc27aSRafal Jaworowski * modify it under the terms of the GNU General Public License as
1221fdc27aSRafal Jaworowski * published by the Free Software Foundation; either version 2 of the
1321fdc27aSRafal Jaworowski * License, or (at your option) any later version.
1421fdc27aSRafal Jaworowski *
1521fdc27aSRafal Jaworowski * This library is distributed in the hope that it will be useful,
1621fdc27aSRafal Jaworowski * but WITHOUT ANY WARRANTY; without even the implied warranty of
1721fdc27aSRafal Jaworowski * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1821fdc27aSRafal Jaworowski * GNU General Public License for more details.
1921fdc27aSRafal Jaworowski *
2021fdc27aSRafal Jaworowski * You should have received a copy of the GNU General Public
2121fdc27aSRafal Jaworowski * License along with this library; if not, write to the Free
2221fdc27aSRafal Jaworowski * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
2321fdc27aSRafal Jaworowski * MA 02110-1301 USA
2421fdc27aSRafal Jaworowski *
2521fdc27aSRafal Jaworowski * Alternatively,
2621fdc27aSRafal Jaworowski *
2721fdc27aSRafal Jaworowski * b) Redistribution and use in source and binary forms, with or
2821fdc27aSRafal Jaworowski * without modification, are permitted provided that the following
2921fdc27aSRafal Jaworowski * conditions are met:
3021fdc27aSRafal Jaworowski *
3121fdc27aSRafal Jaworowski * 1. Redistributions of source code must retain the above
3221fdc27aSRafal Jaworowski * copyright notice, this list of conditions and the following
3321fdc27aSRafal Jaworowski * disclaimer.
3421fdc27aSRafal Jaworowski * 2. Redistributions in binary form must reproduce the above
3521fdc27aSRafal Jaworowski * copyright notice, this list of conditions and the following
3621fdc27aSRafal Jaworowski * disclaimer in the documentation and/or other materials
3721fdc27aSRafal Jaworowski * provided with the distribution.
3821fdc27aSRafal Jaworowski *
3921fdc27aSRafal Jaworowski * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
4021fdc27aSRafal Jaworowski * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
4121fdc27aSRafal Jaworowski * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
4221fdc27aSRafal Jaworowski * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
4321fdc27aSRafal Jaworowski * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
4421fdc27aSRafal Jaworowski * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4521fdc27aSRafal Jaworowski * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4621fdc27aSRafal Jaworowski * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4721fdc27aSRafal Jaworowski * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4821fdc27aSRafal Jaworowski * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4921fdc27aSRafal Jaworowski * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
5021fdc27aSRafal Jaworowski * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
5121fdc27aSRafal Jaworowski * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5221fdc27aSRafal Jaworowski */
5321fdc27aSRafal Jaworowski
5421fdc27aSRafal Jaworowski #include <libfdt_env.h>
5521fdc27aSRafal Jaworowski #include <fdt.h>
5621fdc27aSRafal Jaworowski
57*1a4529b5SKyle Evans #define FDT_FIRST_SUPPORTED_VERSION 0x02
5821fdc27aSRafal Jaworowski #define FDT_LAST_SUPPORTED_VERSION 0x11
5921fdc27aSRafal Jaworowski
6021fdc27aSRafal Jaworowski /* Error codes: informative error codes */
6121fdc27aSRafal Jaworowski #define FDT_ERR_NOTFOUND 1
6221fdc27aSRafal Jaworowski /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
6321fdc27aSRafal Jaworowski #define FDT_ERR_EXISTS 2
646780e684SKyle Evans /* FDT_ERR_EXISTS: Attempted to create a node or property which
6521fdc27aSRafal Jaworowski * already exists */
6621fdc27aSRafal Jaworowski #define FDT_ERR_NOSPACE 3
6721fdc27aSRafal Jaworowski /* FDT_ERR_NOSPACE: Operation needed to expand the device
6821fdc27aSRafal Jaworowski * tree, but its buffer did not have sufficient space to
6921fdc27aSRafal Jaworowski * contain the expanded tree. Use fdt_open_into() to move the
7021fdc27aSRafal Jaworowski * device tree to a buffer with more space. */
7121fdc27aSRafal Jaworowski
7221fdc27aSRafal Jaworowski /* Error codes: codes for bad parameters */
7321fdc27aSRafal Jaworowski #define FDT_ERR_BADOFFSET 4
7421fdc27aSRafal Jaworowski /* FDT_ERR_BADOFFSET: Function was passed a structure block
7521fdc27aSRafal Jaworowski * offset which is out-of-bounds, or which points to an
7621fdc27aSRafal Jaworowski * unsuitable part of the structure for the operation. */
7721fdc27aSRafal Jaworowski #define FDT_ERR_BADPATH 5
7821fdc27aSRafal Jaworowski /* FDT_ERR_BADPATH: Function was passed a badly formatted path
7921fdc27aSRafal Jaworowski * (e.g. missing a leading / for a function which requires an
8021fdc27aSRafal Jaworowski * absolute path) */
8121fdc27aSRafal Jaworowski #define FDT_ERR_BADPHANDLE 6
826780e684SKyle Evans /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
836780e684SKyle Evans * This can be caused either by an invalid phandle property
846780e684SKyle Evans * length, or the phandle value was either 0 or -1, which are
856780e684SKyle Evans * not permitted. */
8621fdc27aSRafal Jaworowski #define FDT_ERR_BADSTATE 7
8721fdc27aSRafal Jaworowski /* FDT_ERR_BADSTATE: Function was passed an incomplete device
8821fdc27aSRafal Jaworowski * tree created by the sequential-write functions, which is
8921fdc27aSRafal Jaworowski * not sufficiently complete for the requested operation. */
9021fdc27aSRafal Jaworowski
9121fdc27aSRafal Jaworowski /* Error codes: codes for bad device tree blobs */
9221fdc27aSRafal Jaworowski #define FDT_ERR_TRUNCATED 8
9321fdc27aSRafal Jaworowski /* FDT_ERR_TRUNCATED: Structure block of the given device tree
9421fdc27aSRafal Jaworowski * ends without an FDT_END tag. */
9521fdc27aSRafal Jaworowski #define FDT_ERR_BADMAGIC 9
9621fdc27aSRafal Jaworowski /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
9721fdc27aSRafal Jaworowski * device tree at all - it is missing the flattened device
9821fdc27aSRafal Jaworowski * tree magic number. */
9921fdc27aSRafal Jaworowski #define FDT_ERR_BADVERSION 10
10021fdc27aSRafal Jaworowski /* FDT_ERR_BADVERSION: Given device tree has a version which
10121fdc27aSRafal Jaworowski * can't be handled by the requested operation. For
10221fdc27aSRafal Jaworowski * read-write functions, this may mean that fdt_open_into() is
10321fdc27aSRafal Jaworowski * required to convert the tree to the expected version. */
10421fdc27aSRafal Jaworowski #define FDT_ERR_BADSTRUCTURE 11
10521fdc27aSRafal Jaworowski /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
10621fdc27aSRafal Jaworowski * structure block or other serious error (e.g. misnested
10721fdc27aSRafal Jaworowski * nodes, or subnodes preceding properties). */
10821fdc27aSRafal Jaworowski #define FDT_ERR_BADLAYOUT 12
10921fdc27aSRafal Jaworowski /* FDT_ERR_BADLAYOUT: For read-write functions, the given
11021fdc27aSRafal Jaworowski * device tree has it's sub-blocks in an order that the
11121fdc27aSRafal Jaworowski * function can't handle (memory reserve map, then structure,
11221fdc27aSRafal Jaworowski * then strings). Use fdt_open_into() to reorganize the tree
11321fdc27aSRafal Jaworowski * into a form suitable for the read-write operations. */
11421fdc27aSRafal Jaworowski
11521fdc27aSRafal Jaworowski /* "Can't happen" error indicating a bug in libfdt */
11621fdc27aSRafal Jaworowski #define FDT_ERR_INTERNAL 13
11721fdc27aSRafal Jaworowski /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
11821fdc27aSRafal Jaworowski * Should never be returned, if it is, it indicates a bug in
11921fdc27aSRafal Jaworowski * libfdt itself. */
12021fdc27aSRafal Jaworowski
1216780e684SKyle Evans /* Errors in device tree content */
1226780e684SKyle Evans #define FDT_ERR_BADNCELLS 14
1236780e684SKyle Evans /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
1246780e684SKyle Evans * or similar property with a bad format or value */
1256780e684SKyle Evans
1266780e684SKyle Evans #define FDT_ERR_BADVALUE 15
1276780e684SKyle Evans /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
1286780e684SKyle Evans * value. For example: a property expected to contain a string list
1296780e684SKyle Evans * is not NUL-terminated within the length of its value. */
1306780e684SKyle Evans
1316780e684SKyle Evans #define FDT_ERR_BADOVERLAY 16
1326780e684SKyle Evans /* FDT_ERR_BADOVERLAY: The device tree overlay, while
1336780e684SKyle Evans * correctly structured, cannot be applied due to some
1346780e684SKyle Evans * unexpected or missing value, property or node. */
1356780e684SKyle Evans
1366780e684SKyle Evans #define FDT_ERR_NOPHANDLES 17
1376780e684SKyle Evans /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
1386780e684SKyle Evans * phandle available anymore without causing an overflow */
1396780e684SKyle Evans
1406780e684SKyle Evans #define FDT_ERR_MAX 17
14121fdc27aSRafal Jaworowski
14221fdc27aSRafal Jaworowski /**********************************************************************/
14321fdc27aSRafal Jaworowski /* Low-level functions (you probably don't need these) */
14421fdc27aSRafal Jaworowski /**********************************************************************/
14521fdc27aSRafal Jaworowski
1466780e684SKyle Evans #ifndef SWIG /* This function is not useful in Python */
14721fdc27aSRafal Jaworowski const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
1486780e684SKyle Evans #endif
fdt_offset_ptr_w(void * fdt,int offset,int checklen)14921fdc27aSRafal Jaworowski static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
15021fdc27aSRafal Jaworowski {
15121fdc27aSRafal Jaworowski return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
15221fdc27aSRafal Jaworowski }
15321fdc27aSRafal Jaworowski
15421fdc27aSRafal Jaworowski uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
15521fdc27aSRafal Jaworowski
15621fdc27aSRafal Jaworowski /**********************************************************************/
15721fdc27aSRafal Jaworowski /* Traversal functions */
15821fdc27aSRafal Jaworowski /**********************************************************************/
15921fdc27aSRafal Jaworowski
16021fdc27aSRafal Jaworowski int fdt_next_node(const void *fdt, int offset, int *depth);
16121fdc27aSRafal Jaworowski
1626780e684SKyle Evans /**
1636780e684SKyle Evans * fdt_first_subnode() - get offset of first direct subnode
1646780e684SKyle Evans *
1656780e684SKyle Evans * @fdt: FDT blob
1666780e684SKyle Evans * @offset: Offset of node to check
1676780e684SKyle Evans * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
1686780e684SKyle Evans */
1696780e684SKyle Evans int fdt_first_subnode(const void *fdt, int offset);
1706780e684SKyle Evans
1716780e684SKyle Evans /**
1726780e684SKyle Evans * fdt_next_subnode() - get offset of next direct subnode
1736780e684SKyle Evans *
1746780e684SKyle Evans * After first calling fdt_first_subnode(), call this function repeatedly to
1756780e684SKyle Evans * get direct subnodes of a parent node.
1766780e684SKyle Evans *
1776780e684SKyle Evans * @fdt: FDT blob
1786780e684SKyle Evans * @offset: Offset of previous subnode
1796780e684SKyle Evans * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
1806780e684SKyle Evans * subnodes
1816780e684SKyle Evans */
1826780e684SKyle Evans int fdt_next_subnode(const void *fdt, int offset);
1836780e684SKyle Evans
1846780e684SKyle Evans /**
1856780e684SKyle Evans * fdt_for_each_subnode - iterate over all subnodes of a parent
1866780e684SKyle Evans *
1876780e684SKyle Evans * @node: child node (int, lvalue)
1886780e684SKyle Evans * @fdt: FDT blob (const void *)
1896780e684SKyle Evans * @parent: parent node (int)
1906780e684SKyle Evans *
1916780e684SKyle Evans * This is actually a wrapper around a for loop and would be used like so:
1926780e684SKyle Evans *
1936780e684SKyle Evans * fdt_for_each_subnode(node, fdt, parent) {
1946780e684SKyle Evans * Use node
1956780e684SKyle Evans * ...
1966780e684SKyle Evans * }
1976780e684SKyle Evans *
1986780e684SKyle Evans * if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) {
1996780e684SKyle Evans * Error handling
2006780e684SKyle Evans * }
2016780e684SKyle Evans *
2026780e684SKyle Evans * Note that this is implemented as a macro and @node is used as
2036780e684SKyle Evans * iterator in the loop. The parent variable be constant or even a
2046780e684SKyle Evans * literal.
2056780e684SKyle Evans *
2066780e684SKyle Evans */
2076780e684SKyle Evans #define fdt_for_each_subnode(node, fdt, parent) \
2086780e684SKyle Evans for (node = fdt_first_subnode(fdt, parent); \
2096780e684SKyle Evans node >= 0; \
2106780e684SKyle Evans node = fdt_next_subnode(fdt, node))
2116780e684SKyle Evans
21221fdc27aSRafal Jaworowski /**********************************************************************/
21321fdc27aSRafal Jaworowski /* General functions */
21421fdc27aSRafal Jaworowski /**********************************************************************/
21521fdc27aSRafal Jaworowski #define fdt_get_header(fdt, field) \
21621fdc27aSRafal Jaworowski (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
21721fdc27aSRafal Jaworowski #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
21821fdc27aSRafal Jaworowski #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
21921fdc27aSRafal Jaworowski #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
22021fdc27aSRafal Jaworowski #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
22121fdc27aSRafal Jaworowski #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
22221fdc27aSRafal Jaworowski #define fdt_version(fdt) (fdt_get_header(fdt, version))
22321fdc27aSRafal Jaworowski #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
22421fdc27aSRafal Jaworowski #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
22521fdc27aSRafal Jaworowski #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
22621fdc27aSRafal Jaworowski #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
22721fdc27aSRafal Jaworowski
2286780e684SKyle Evans #define fdt_set_hdr_(name) \
22921fdc27aSRafal Jaworowski static inline void fdt_set_##name(void *fdt, uint32_t val) \
23021fdc27aSRafal Jaworowski { \
23121fdc27aSRafal Jaworowski struct fdt_header *fdth = (struct fdt_header *)fdt; \
23221fdc27aSRafal Jaworowski fdth->name = cpu_to_fdt32(val); \
23321fdc27aSRafal Jaworowski }
2346780e684SKyle Evans fdt_set_hdr_(magic);
2356780e684SKyle Evans fdt_set_hdr_(totalsize);
2366780e684SKyle Evans fdt_set_hdr_(off_dt_struct);
2376780e684SKyle Evans fdt_set_hdr_(off_dt_strings);
2386780e684SKyle Evans fdt_set_hdr_(off_mem_rsvmap);
2396780e684SKyle Evans fdt_set_hdr_(version);
2406780e684SKyle Evans fdt_set_hdr_(last_comp_version);
2416780e684SKyle Evans fdt_set_hdr_(boot_cpuid_phys);
2426780e684SKyle Evans fdt_set_hdr_(size_dt_strings);
2436780e684SKyle Evans fdt_set_hdr_(size_dt_struct);
2446780e684SKyle Evans #undef fdt_set_hdr_
24521fdc27aSRafal Jaworowski
24621fdc27aSRafal Jaworowski /**
24721fdc27aSRafal Jaworowski * fdt_check_header - sanity check a device tree or possible device tree
24821fdc27aSRafal Jaworowski * @fdt: pointer to data which might be a flattened device tree
24921fdc27aSRafal Jaworowski *
25021fdc27aSRafal Jaworowski * fdt_check_header() checks that the given buffer contains what
25121fdc27aSRafal Jaworowski * appears to be a flattened device tree with sane information in its
25221fdc27aSRafal Jaworowski * header.
25321fdc27aSRafal Jaworowski *
25421fdc27aSRafal Jaworowski * returns:
25521fdc27aSRafal Jaworowski * 0, if the buffer appears to contain a valid device tree
25621fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
25721fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
25821fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE, standard meanings, as above
25921fdc27aSRafal Jaworowski */
26021fdc27aSRafal Jaworowski int fdt_check_header(const void *fdt);
26121fdc27aSRafal Jaworowski
26221fdc27aSRafal Jaworowski /**
26321fdc27aSRafal Jaworowski * fdt_move - move a device tree around in memory
26421fdc27aSRafal Jaworowski * @fdt: pointer to the device tree to move
26521fdc27aSRafal Jaworowski * @buf: pointer to memory where the device is to be moved
26621fdc27aSRafal Jaworowski * @bufsize: size of the memory space at buf
26721fdc27aSRafal Jaworowski *
26821fdc27aSRafal Jaworowski * fdt_move() relocates, if possible, the device tree blob located at
26921fdc27aSRafal Jaworowski * fdt to the buffer at buf of size bufsize. The buffer may overlap
27021fdc27aSRafal Jaworowski * with the existing device tree blob at fdt. Therefore,
27121fdc27aSRafal Jaworowski * fdt_move(fdt, fdt, fdt_totalsize(fdt))
27221fdc27aSRafal Jaworowski * should always succeed.
27321fdc27aSRafal Jaworowski *
27421fdc27aSRafal Jaworowski * returns:
27521fdc27aSRafal Jaworowski * 0, on success
27621fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
27721fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
27821fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
27921fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE, standard meanings
28021fdc27aSRafal Jaworowski */
28121fdc27aSRafal Jaworowski int fdt_move(const void *fdt, void *buf, int bufsize);
28221fdc27aSRafal Jaworowski
28321fdc27aSRafal Jaworowski /**********************************************************************/
28421fdc27aSRafal Jaworowski /* Read-only functions */
28521fdc27aSRafal Jaworowski /**********************************************************************/
28621fdc27aSRafal Jaworowski
28721fdc27aSRafal Jaworowski /**
28821fdc27aSRafal Jaworowski * fdt_string - retrieve a string from the strings block of a device tree
28921fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
29021fdc27aSRafal Jaworowski * @stroffset: offset of the string within the strings block (native endian)
29121fdc27aSRafal Jaworowski *
29221fdc27aSRafal Jaworowski * fdt_string() retrieves a pointer to a single string from the
29321fdc27aSRafal Jaworowski * strings block of the device tree blob at fdt.
29421fdc27aSRafal Jaworowski *
29521fdc27aSRafal Jaworowski * returns:
29621fdc27aSRafal Jaworowski * a pointer to the string, on success
29721fdc27aSRafal Jaworowski * NULL, if stroffset is out of bounds
29821fdc27aSRafal Jaworowski */
29921fdc27aSRafal Jaworowski const char *fdt_string(const void *fdt, int stroffset);
30021fdc27aSRafal Jaworowski
30121fdc27aSRafal Jaworowski /**
3026780e684SKyle Evans * fdt_get_max_phandle - retrieves the highest phandle in a tree
3036780e684SKyle Evans * @fdt: pointer to the device tree blob
3046780e684SKyle Evans *
3056780e684SKyle Evans * fdt_get_max_phandle retrieves the highest phandle in the given
3066780e684SKyle Evans * device tree. This will ignore badly formatted phandles, or phandles
3076780e684SKyle Evans * with a value of 0 or -1.
3086780e684SKyle Evans *
3096780e684SKyle Evans * returns:
3106780e684SKyle Evans * the highest phandle on success
3116780e684SKyle Evans * 0, if no phandle was found in the device tree
3126780e684SKyle Evans * -1, if an error occurred
3136780e684SKyle Evans */
3146780e684SKyle Evans uint32_t fdt_get_max_phandle(const void *fdt);
3156780e684SKyle Evans
3166780e684SKyle Evans /**
31721fdc27aSRafal Jaworowski * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
31821fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
31921fdc27aSRafal Jaworowski *
32021fdc27aSRafal Jaworowski * Returns the number of entries in the device tree blob's memory
32121fdc27aSRafal Jaworowski * reservation map. This does not include the terminating 0,0 entry
32221fdc27aSRafal Jaworowski * or any other (0,0) entries reserved for expansion.
32321fdc27aSRafal Jaworowski *
32421fdc27aSRafal Jaworowski * returns:
32521fdc27aSRafal Jaworowski * the number of entries
32621fdc27aSRafal Jaworowski */
32721fdc27aSRafal Jaworowski int fdt_num_mem_rsv(const void *fdt);
32821fdc27aSRafal Jaworowski
32921fdc27aSRafal Jaworowski /**
33021fdc27aSRafal Jaworowski * fdt_get_mem_rsv - retrieve one memory reserve map entry
33121fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
33221fdc27aSRafal Jaworowski * @address, @size: pointers to 64-bit variables
33321fdc27aSRafal Jaworowski *
33421fdc27aSRafal Jaworowski * On success, *address and *size will contain the address and size of
33521fdc27aSRafal Jaworowski * the n-th reserve map entry from the device tree blob, in
33621fdc27aSRafal Jaworowski * native-endian format.
33721fdc27aSRafal Jaworowski *
33821fdc27aSRafal Jaworowski * returns:
33921fdc27aSRafal Jaworowski * 0, on success
34021fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
34121fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
34221fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE, standard meanings
34321fdc27aSRafal Jaworowski */
34421fdc27aSRafal Jaworowski int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
34521fdc27aSRafal Jaworowski
34621fdc27aSRafal Jaworowski /**
34721fdc27aSRafal Jaworowski * fdt_subnode_offset_namelen - find a subnode based on substring
34821fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
34921fdc27aSRafal Jaworowski * @parentoffset: structure block offset of a node
35021fdc27aSRafal Jaworowski * @name: name of the subnode to locate
35121fdc27aSRafal Jaworowski * @namelen: number of characters of name to consider
35221fdc27aSRafal Jaworowski *
35321fdc27aSRafal Jaworowski * Identical to fdt_subnode_offset(), but only examine the first
35421fdc27aSRafal Jaworowski * namelen characters of name for matching the subnode name. This is
35521fdc27aSRafal Jaworowski * useful for finding subnodes based on a portion of a larger string,
35621fdc27aSRafal Jaworowski * such as a full path.
35721fdc27aSRafal Jaworowski */
3586780e684SKyle Evans #ifndef SWIG /* Not available in Python */
35921fdc27aSRafal Jaworowski int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
36021fdc27aSRafal Jaworowski const char *name, int namelen);
3616780e684SKyle Evans #endif
36221fdc27aSRafal Jaworowski /**
36321fdc27aSRafal Jaworowski * fdt_subnode_offset - find a subnode of a given node
36421fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
36521fdc27aSRafal Jaworowski * @parentoffset: structure block offset of a node
36621fdc27aSRafal Jaworowski * @name: name of the subnode to locate
36721fdc27aSRafal Jaworowski *
36821fdc27aSRafal Jaworowski * fdt_subnode_offset() finds a subnode of the node at structure block
36921fdc27aSRafal Jaworowski * offset parentoffset with the given name. name may include a unit
37021fdc27aSRafal Jaworowski * address, in which case fdt_subnode_offset() will find the subnode
37121fdc27aSRafal Jaworowski * with that unit address, or the unit address may be omitted, in
37221fdc27aSRafal Jaworowski * which case fdt_subnode_offset() will find an arbitrary subnode
37321fdc27aSRafal Jaworowski * whose name excluding unit address matches the given name.
37421fdc27aSRafal Jaworowski *
37521fdc27aSRafal Jaworowski * returns:
37621fdc27aSRafal Jaworowski * structure block offset of the requested subnode (>=0), on success
37721fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
3786780e684SKyle Evans * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
3796780e684SKyle Evans * tag
38021fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
38121fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
38221fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
38321fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
38421fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings.
38521fdc27aSRafal Jaworowski */
38621fdc27aSRafal Jaworowski int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
38721fdc27aSRafal Jaworowski
38821fdc27aSRafal Jaworowski /**
3896780e684SKyle Evans * fdt_path_offset_namelen - find a tree node by its full path
3906780e684SKyle Evans * @fdt: pointer to the device tree blob
3916780e684SKyle Evans * @path: full path of the node to locate
3926780e684SKyle Evans * @namelen: number of characters of path to consider
3936780e684SKyle Evans *
3946780e684SKyle Evans * Identical to fdt_path_offset(), but only consider the first namelen
3956780e684SKyle Evans * characters of path as the path name.
3966780e684SKyle Evans */
3976780e684SKyle Evans #ifndef SWIG /* Not available in Python */
3986780e684SKyle Evans int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
3996780e684SKyle Evans #endif
4006780e684SKyle Evans
4016780e684SKyle Evans /**
40221fdc27aSRafal Jaworowski * fdt_path_offset - find a tree node by its full path
40321fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
40421fdc27aSRafal Jaworowski * @path: full path of the node to locate
40521fdc27aSRafal Jaworowski *
40621fdc27aSRafal Jaworowski * fdt_path_offset() finds a node of a given path in the device tree.
40721fdc27aSRafal Jaworowski * Each path component may omit the unit address portion, but the
40821fdc27aSRafal Jaworowski * results of this are undefined if any such path component is
40921fdc27aSRafal Jaworowski * ambiguous (that is if there are multiple nodes at the relevant
41021fdc27aSRafal Jaworowski * level matching the given component, differentiated only by unit
41121fdc27aSRafal Jaworowski * address).
41221fdc27aSRafal Jaworowski *
41321fdc27aSRafal Jaworowski * returns:
4146780e684SKyle Evans * structure block offset of the node with the requested path (>=0), on
4156780e684SKyle Evans * success
41621fdc27aSRafal Jaworowski * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
41721fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, if the requested node does not exist
41821fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
41921fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
42021fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
42121fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
42221fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings.
42321fdc27aSRafal Jaworowski */
42421fdc27aSRafal Jaworowski int fdt_path_offset(const void *fdt, const char *path);
42521fdc27aSRafal Jaworowski
42621fdc27aSRafal Jaworowski /**
42721fdc27aSRafal Jaworowski * fdt_get_name - retrieve the name of a given node
42821fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
42921fdc27aSRafal Jaworowski * @nodeoffset: structure block offset of the starting node
43021fdc27aSRafal Jaworowski * @lenp: pointer to an integer variable (will be overwritten) or NULL
43121fdc27aSRafal Jaworowski *
43221fdc27aSRafal Jaworowski * fdt_get_name() retrieves the name (including unit address) of the
43321fdc27aSRafal Jaworowski * device tree node at structure block offset nodeoffset. If lenp is
43421fdc27aSRafal Jaworowski * non-NULL, the length of this name is also returned, in the integer
43521fdc27aSRafal Jaworowski * pointed to by lenp.
43621fdc27aSRafal Jaworowski *
43721fdc27aSRafal Jaworowski * returns:
43821fdc27aSRafal Jaworowski * pointer to the node's name, on success
4396780e684SKyle Evans * If lenp is non-NULL, *lenp contains the length of that name
4406780e684SKyle Evans * (>=0)
44121fdc27aSRafal Jaworowski * NULL, on error
44221fdc27aSRafal Jaworowski * if lenp is non-NULL *lenp contains an error code (<0):
4436780e684SKyle Evans * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
4446780e684SKyle Evans * tag
44521fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
44621fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
44721fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE, standard meanings
44821fdc27aSRafal Jaworowski */
44921fdc27aSRafal Jaworowski const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
45021fdc27aSRafal Jaworowski
45121fdc27aSRafal Jaworowski /**
45252baf267SWarner Losh * fdt_first_property_offset - find the offset of a node's first property
45352baf267SWarner Losh * @fdt: pointer to the device tree blob
45452baf267SWarner Losh * @nodeoffset: structure block offset of a node
45552baf267SWarner Losh *
45652baf267SWarner Losh * fdt_first_property_offset() finds the first property of the node at
45752baf267SWarner Losh * the given structure block offset.
45852baf267SWarner Losh *
45952baf267SWarner Losh * returns:
46052baf267SWarner Losh * structure block offset of the property (>=0), on success
46152baf267SWarner Losh * -FDT_ERR_NOTFOUND, if the requested node has no properties
46252baf267SWarner Losh * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
46352baf267SWarner Losh * -FDT_ERR_BADMAGIC,
46452baf267SWarner Losh * -FDT_ERR_BADVERSION,
46552baf267SWarner Losh * -FDT_ERR_BADSTATE,
46652baf267SWarner Losh * -FDT_ERR_BADSTRUCTURE,
46752baf267SWarner Losh * -FDT_ERR_TRUNCATED, standard meanings.
46852baf267SWarner Losh */
46952baf267SWarner Losh int fdt_first_property_offset(const void *fdt, int nodeoffset);
47052baf267SWarner Losh
47152baf267SWarner Losh /**
47252baf267SWarner Losh * fdt_next_property_offset - step through a node's properties
47352baf267SWarner Losh * @fdt: pointer to the device tree blob
47452baf267SWarner Losh * @offset: structure block offset of a property
47552baf267SWarner Losh *
47652baf267SWarner Losh * fdt_next_property_offset() finds the property immediately after the
47752baf267SWarner Losh * one at the given structure block offset. This will be a property
47852baf267SWarner Losh * of the same node as the given property.
47952baf267SWarner Losh *
48052baf267SWarner Losh * returns:
48152baf267SWarner Losh * structure block offset of the next property (>=0), on success
48252baf267SWarner Losh * -FDT_ERR_NOTFOUND, if the given property is the last in its node
48352baf267SWarner Losh * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
48452baf267SWarner Losh * -FDT_ERR_BADMAGIC,
48552baf267SWarner Losh * -FDT_ERR_BADVERSION,
48652baf267SWarner Losh * -FDT_ERR_BADSTATE,
48752baf267SWarner Losh * -FDT_ERR_BADSTRUCTURE,
48852baf267SWarner Losh * -FDT_ERR_TRUNCATED, standard meanings.
48952baf267SWarner Losh */
49052baf267SWarner Losh int fdt_next_property_offset(const void *fdt, int offset);
49152baf267SWarner Losh
49252baf267SWarner Losh /**
4936780e684SKyle Evans * fdt_for_each_property_offset - iterate over all properties of a node
4946780e684SKyle Evans *
4956780e684SKyle Evans * @property_offset: property offset (int, lvalue)
4966780e684SKyle Evans * @fdt: FDT blob (const void *)
4976780e684SKyle Evans * @node: node offset (int)
4986780e684SKyle Evans *
4996780e684SKyle Evans * This is actually a wrapper around a for loop and would be used like so:
5006780e684SKyle Evans *
5016780e684SKyle Evans * fdt_for_each_property_offset(property, fdt, node) {
5026780e684SKyle Evans * Use property
5036780e684SKyle Evans * ...
5046780e684SKyle Evans * }
5056780e684SKyle Evans *
5066780e684SKyle Evans * if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) {
5076780e684SKyle Evans * Error handling
5086780e684SKyle Evans * }
5096780e684SKyle Evans *
5106780e684SKyle Evans * Note that this is implemented as a macro and property is used as
5116780e684SKyle Evans * iterator in the loop. The node variable can be constant or even a
5126780e684SKyle Evans * literal.
5136780e684SKyle Evans */
5146780e684SKyle Evans #define fdt_for_each_property_offset(property, fdt, node) \
5156780e684SKyle Evans for (property = fdt_first_property_offset(fdt, node); \
5166780e684SKyle Evans property >= 0; \
5176780e684SKyle Evans property = fdt_next_property_offset(fdt, property))
5186780e684SKyle Evans
5196780e684SKyle Evans /**
52052baf267SWarner Losh * fdt_get_property_by_offset - retrieve the property at a given offset
52152baf267SWarner Losh * @fdt: pointer to the device tree blob
52252baf267SWarner Losh * @offset: offset of the property to retrieve
52352baf267SWarner Losh * @lenp: pointer to an integer variable (will be overwritten) or NULL
52452baf267SWarner Losh *
52552baf267SWarner Losh * fdt_get_property_by_offset() retrieves a pointer to the
52652baf267SWarner Losh * fdt_property structure within the device tree blob at the given
52752baf267SWarner Losh * offset. If lenp is non-NULL, the length of the property value is
52852baf267SWarner Losh * also returned, in the integer pointed to by lenp.
52952baf267SWarner Losh *
530*1a4529b5SKyle Evans * Note that this code only works on device tree versions >= 16. fdt_getprop()
531*1a4529b5SKyle Evans * works on all versions.
532*1a4529b5SKyle Evans *
53352baf267SWarner Losh * returns:
53452baf267SWarner Losh * pointer to the structure representing the property
53552baf267SWarner Losh * if lenp is non-NULL, *lenp contains the length of the property
53652baf267SWarner Losh * value (>=0)
53752baf267SWarner Losh * NULL, on error
53852baf267SWarner Losh * if lenp is non-NULL, *lenp contains an error code (<0):
53952baf267SWarner Losh * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
54052baf267SWarner Losh * -FDT_ERR_BADMAGIC,
54152baf267SWarner Losh * -FDT_ERR_BADVERSION,
54252baf267SWarner Losh * -FDT_ERR_BADSTATE,
54352baf267SWarner Losh * -FDT_ERR_BADSTRUCTURE,
54452baf267SWarner Losh * -FDT_ERR_TRUNCATED, standard meanings
54552baf267SWarner Losh */
54652baf267SWarner Losh const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
54752baf267SWarner Losh int offset,
54852baf267SWarner Losh int *lenp);
54952baf267SWarner Losh
55052baf267SWarner Losh /**
55121fdc27aSRafal Jaworowski * fdt_get_property_namelen - find a property based on substring
55221fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
55321fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to find
55421fdc27aSRafal Jaworowski * @name: name of the property to find
55521fdc27aSRafal Jaworowski * @namelen: number of characters of name to consider
55621fdc27aSRafal Jaworowski * @lenp: pointer to an integer variable (will be overwritten) or NULL
55721fdc27aSRafal Jaworowski *
5586780e684SKyle Evans * Identical to fdt_get_property(), but only examine the first namelen
5596780e684SKyle Evans * characters of name for matching the property name.
56021fdc27aSRafal Jaworowski */
5616780e684SKyle Evans #ifndef SWIG /* Not available in Python */
56221fdc27aSRafal Jaworowski const struct fdt_property *fdt_get_property_namelen(const void *fdt,
56321fdc27aSRafal Jaworowski int nodeoffset,
56421fdc27aSRafal Jaworowski const char *name,
56521fdc27aSRafal Jaworowski int namelen, int *lenp);
5666780e684SKyle Evans #endif
56721fdc27aSRafal Jaworowski
56821fdc27aSRafal Jaworowski /**
56921fdc27aSRafal Jaworowski * fdt_get_property - find a given property in a given node
57021fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
57121fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to find
57221fdc27aSRafal Jaworowski * @name: name of the property to find
57321fdc27aSRafal Jaworowski * @lenp: pointer to an integer variable (will be overwritten) or NULL
57421fdc27aSRafal Jaworowski *
57521fdc27aSRafal Jaworowski * fdt_get_property() retrieves a pointer to the fdt_property
57621fdc27aSRafal Jaworowski * structure within the device tree blob corresponding to the property
57721fdc27aSRafal Jaworowski * named 'name' of the node at offset nodeoffset. If lenp is
57821fdc27aSRafal Jaworowski * non-NULL, the length of the property value is also returned, in the
57921fdc27aSRafal Jaworowski * integer pointed to by lenp.
58021fdc27aSRafal Jaworowski *
58121fdc27aSRafal Jaworowski * returns:
58221fdc27aSRafal Jaworowski * pointer to the structure representing the property
58321fdc27aSRafal Jaworowski * if lenp is non-NULL, *lenp contains the length of the property
58421fdc27aSRafal Jaworowski * value (>=0)
58521fdc27aSRafal Jaworowski * NULL, on error
58621fdc27aSRafal Jaworowski * if lenp is non-NULL, *lenp contains an error code (<0):
58721fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, node does not have named property
5886780e684SKyle Evans * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
5896780e684SKyle Evans * tag
59021fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
59121fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
59221fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
59321fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
59421fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
59521fdc27aSRafal Jaworowski */
59621fdc27aSRafal Jaworowski const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
59721fdc27aSRafal Jaworowski const char *name, int *lenp);
fdt_get_property_w(void * fdt,int nodeoffset,const char * name,int * lenp)59821fdc27aSRafal Jaworowski static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
59921fdc27aSRafal Jaworowski const char *name,
60021fdc27aSRafal Jaworowski int *lenp)
60121fdc27aSRafal Jaworowski {
60221fdc27aSRafal Jaworowski return (struct fdt_property *)(uintptr_t)
60321fdc27aSRafal Jaworowski fdt_get_property(fdt, nodeoffset, name, lenp);
60421fdc27aSRafal Jaworowski }
60521fdc27aSRafal Jaworowski
60621fdc27aSRafal Jaworowski /**
60752baf267SWarner Losh * fdt_getprop_by_offset - retrieve the value of a property at a given offset
60852baf267SWarner Losh * @fdt: pointer to the device tree blob
60952baf267SWarner Losh * @ffset: offset of the property to read
61052baf267SWarner Losh * @namep: pointer to a string variable (will be overwritten) or NULL
61152baf267SWarner Losh * @lenp: pointer to an integer variable (will be overwritten) or NULL
61252baf267SWarner Losh *
61352baf267SWarner Losh * fdt_getprop_by_offset() retrieves a pointer to the value of the
61452baf267SWarner Losh * property at structure block offset 'offset' (this will be a pointer
61552baf267SWarner Losh * to within the device blob itself, not a copy of the value). If
61652baf267SWarner Losh * lenp is non-NULL, the length of the property value is also
61752baf267SWarner Losh * returned, in the integer pointed to by lenp. If namep is non-NULL,
61852baf267SWarner Losh * the property's namne will also be returned in the char * pointed to
61952baf267SWarner Losh * by namep (this will be a pointer to within the device tree's string
62052baf267SWarner Losh * block, not a new copy of the name).
62152baf267SWarner Losh *
62252baf267SWarner Losh * returns:
62352baf267SWarner Losh * pointer to the property's value
62452baf267SWarner Losh * if lenp is non-NULL, *lenp contains the length of the property
62552baf267SWarner Losh * value (>=0)
62652baf267SWarner Losh * if namep is non-NULL *namep contiains a pointer to the property
62752baf267SWarner Losh * name.
62852baf267SWarner Losh * NULL, on error
62952baf267SWarner Losh * if lenp is non-NULL, *lenp contains an error code (<0):
63052baf267SWarner Losh * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
63152baf267SWarner Losh * -FDT_ERR_BADMAGIC,
63252baf267SWarner Losh * -FDT_ERR_BADVERSION,
63352baf267SWarner Losh * -FDT_ERR_BADSTATE,
63452baf267SWarner Losh * -FDT_ERR_BADSTRUCTURE,
63552baf267SWarner Losh * -FDT_ERR_TRUNCATED, standard meanings
63652baf267SWarner Losh */
6376780e684SKyle Evans #ifndef SWIG /* This function is not useful in Python */
63852baf267SWarner Losh const void *fdt_getprop_by_offset(const void *fdt, int offset,
63952baf267SWarner Losh const char **namep, int *lenp);
6406780e684SKyle Evans #endif
64152baf267SWarner Losh
64252baf267SWarner Losh /**
64321fdc27aSRafal Jaworowski * fdt_getprop_namelen - get property value based on substring
64421fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
64521fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to find
64621fdc27aSRafal Jaworowski * @name: name of the property to find
64721fdc27aSRafal Jaworowski * @namelen: number of characters of name to consider
64821fdc27aSRafal Jaworowski * @lenp: pointer to an integer variable (will be overwritten) or NULL
64921fdc27aSRafal Jaworowski *
65021fdc27aSRafal Jaworowski * Identical to fdt_getprop(), but only examine the first namelen
65121fdc27aSRafal Jaworowski * characters of name for matching the property name.
65221fdc27aSRafal Jaworowski */
6536780e684SKyle Evans #ifndef SWIG /* Not available in Python */
65421fdc27aSRafal Jaworowski const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
65521fdc27aSRafal Jaworowski const char *name, int namelen, int *lenp);
fdt_getprop_namelen_w(void * fdt,int nodeoffset,const char * name,int namelen,int * lenp)6566780e684SKyle Evans static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
6576780e684SKyle Evans const char *name, int namelen,
6586780e684SKyle Evans int *lenp)
6596780e684SKyle Evans {
6606780e684SKyle Evans return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
6616780e684SKyle Evans namelen, lenp);
6626780e684SKyle Evans }
6636780e684SKyle Evans #endif
66421fdc27aSRafal Jaworowski
66521fdc27aSRafal Jaworowski /**
66621fdc27aSRafal Jaworowski * fdt_getprop - retrieve the value of a given property
66721fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
66821fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to find
66921fdc27aSRafal Jaworowski * @name: name of the property to find
67021fdc27aSRafal Jaworowski * @lenp: pointer to an integer variable (will be overwritten) or NULL
67121fdc27aSRafal Jaworowski *
67221fdc27aSRafal Jaworowski * fdt_getprop() retrieves a pointer to the value of the property
67321fdc27aSRafal Jaworowski * named 'name' of the node at offset nodeoffset (this will be a
67421fdc27aSRafal Jaworowski * pointer to within the device blob itself, not a copy of the value).
67521fdc27aSRafal Jaworowski * If lenp is non-NULL, the length of the property value is also
67621fdc27aSRafal Jaworowski * returned, in the integer pointed to by lenp.
67721fdc27aSRafal Jaworowski *
67821fdc27aSRafal Jaworowski * returns:
67921fdc27aSRafal Jaworowski * pointer to the property's value
68021fdc27aSRafal Jaworowski * if lenp is non-NULL, *lenp contains the length of the property
68121fdc27aSRafal Jaworowski * value (>=0)
68221fdc27aSRafal Jaworowski * NULL, on error
68321fdc27aSRafal Jaworowski * if lenp is non-NULL, *lenp contains an error code (<0):
68421fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, node does not have named property
6856780e684SKyle Evans * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
6866780e684SKyle Evans * tag
68721fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
68821fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
68921fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
69021fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
69121fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
69221fdc27aSRafal Jaworowski */
69321fdc27aSRafal Jaworowski const void *fdt_getprop(const void *fdt, int nodeoffset,
69421fdc27aSRafal Jaworowski const char *name, int *lenp);
fdt_getprop_w(void * fdt,int nodeoffset,const char * name,int * lenp)69521fdc27aSRafal Jaworowski static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
69621fdc27aSRafal Jaworowski const char *name, int *lenp)
69721fdc27aSRafal Jaworowski {
69821fdc27aSRafal Jaworowski return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
69921fdc27aSRafal Jaworowski }
70021fdc27aSRafal Jaworowski
70121fdc27aSRafal Jaworowski /**
70221fdc27aSRafal Jaworowski * fdt_get_phandle - retrieve the phandle of a given node
70321fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
70421fdc27aSRafal Jaworowski * @nodeoffset: structure block offset of the node
70521fdc27aSRafal Jaworowski *
70621fdc27aSRafal Jaworowski * fdt_get_phandle() retrieves the phandle of the device tree node at
70721fdc27aSRafal Jaworowski * structure block offset nodeoffset.
70821fdc27aSRafal Jaworowski *
70921fdc27aSRafal Jaworowski * returns:
71021fdc27aSRafal Jaworowski * the phandle of the node at nodeoffset, on success (!= 0, != -1)
71121fdc27aSRafal Jaworowski * 0, if the node has no phandle, or another error occurs
71221fdc27aSRafal Jaworowski */
71321fdc27aSRafal Jaworowski uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
71421fdc27aSRafal Jaworowski
71521fdc27aSRafal Jaworowski /**
71621fdc27aSRafal Jaworowski * fdt_get_alias_namelen - get alias based on substring
71721fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
71821fdc27aSRafal Jaworowski * @name: name of the alias th look up
71921fdc27aSRafal Jaworowski * @namelen: number of characters of name to consider
72021fdc27aSRafal Jaworowski *
72121fdc27aSRafal Jaworowski * Identical to fdt_get_alias(), but only examine the first namelen
72221fdc27aSRafal Jaworowski * characters of name for matching the alias name.
72321fdc27aSRafal Jaworowski */
7246780e684SKyle Evans #ifndef SWIG /* Not available in Python */
72521fdc27aSRafal Jaworowski const char *fdt_get_alias_namelen(const void *fdt,
72621fdc27aSRafal Jaworowski const char *name, int namelen);
7276780e684SKyle Evans #endif
72821fdc27aSRafal Jaworowski
72921fdc27aSRafal Jaworowski /**
7306780e684SKyle Evans * fdt_get_alias - retrieve the path referenced by a given alias
73121fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
73221fdc27aSRafal Jaworowski * @name: name of the alias th look up
73321fdc27aSRafal Jaworowski *
73421fdc27aSRafal Jaworowski * fdt_get_alias() retrieves the value of a given alias. That is, the
73521fdc27aSRafal Jaworowski * value of the property named 'name' in the node /aliases.
73621fdc27aSRafal Jaworowski *
73721fdc27aSRafal Jaworowski * returns:
7386780e684SKyle Evans * a pointer to the expansion of the alias named 'name', if it exists
73921fdc27aSRafal Jaworowski * NULL, if the given alias or the /aliases node does not exist
74021fdc27aSRafal Jaworowski */
74121fdc27aSRafal Jaworowski const char *fdt_get_alias(const void *fdt, const char *name);
74221fdc27aSRafal Jaworowski
74321fdc27aSRafal Jaworowski /**
74421fdc27aSRafal Jaworowski * fdt_get_path - determine the full path of a node
74521fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
74621fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose path to find
74721fdc27aSRafal Jaworowski * @buf: character buffer to contain the returned path (will be overwritten)
74821fdc27aSRafal Jaworowski * @buflen: size of the character buffer at buf
74921fdc27aSRafal Jaworowski *
75021fdc27aSRafal Jaworowski * fdt_get_path() computes the full path of the node at offset
75121fdc27aSRafal Jaworowski * nodeoffset, and records that path in the buffer at buf.
75221fdc27aSRafal Jaworowski *
75321fdc27aSRafal Jaworowski * NOTE: This function is expensive, as it must scan the device tree
75421fdc27aSRafal Jaworowski * structure from the start to nodeoffset.
75521fdc27aSRafal Jaworowski *
75621fdc27aSRafal Jaworowski * returns:
75721fdc27aSRafal Jaworowski * 0, on success
75821fdc27aSRafal Jaworowski * buf contains the absolute path of the node at
75921fdc27aSRafal Jaworowski * nodeoffset, as a NUL-terminated string.
76021fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
76121fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
76221fdc27aSRafal Jaworowski * characters and will not fit in the given buffer.
76321fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
76421fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
76521fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
76621fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE, standard meanings
76721fdc27aSRafal Jaworowski */
76821fdc27aSRafal Jaworowski int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
76921fdc27aSRafal Jaworowski
77021fdc27aSRafal Jaworowski /**
77121fdc27aSRafal Jaworowski * fdt_supernode_atdepth_offset - find a specific ancestor of a node
77221fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
77321fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose parent to find
77421fdc27aSRafal Jaworowski * @supernodedepth: depth of the ancestor to find
77521fdc27aSRafal Jaworowski * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
77621fdc27aSRafal Jaworowski *
77721fdc27aSRafal Jaworowski * fdt_supernode_atdepth_offset() finds an ancestor of the given node
77821fdc27aSRafal Jaworowski * at a specific depth from the root (where the root itself has depth
77921fdc27aSRafal Jaworowski * 0, its immediate subnodes depth 1 and so forth). So
78021fdc27aSRafal Jaworowski * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
78121fdc27aSRafal Jaworowski * will always return 0, the offset of the root node. If the node at
78221fdc27aSRafal Jaworowski * nodeoffset has depth D, then:
78321fdc27aSRafal Jaworowski * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
78421fdc27aSRafal Jaworowski * will return nodeoffset itself.
78521fdc27aSRafal Jaworowski *
78621fdc27aSRafal Jaworowski * NOTE: This function is expensive, as it must scan the device tree
78721fdc27aSRafal Jaworowski * structure from the start to nodeoffset.
78821fdc27aSRafal Jaworowski *
78921fdc27aSRafal Jaworowski * returns:
79021fdc27aSRafal Jaworowski * structure block offset of the node at node offset's ancestor
79121fdc27aSRafal Jaworowski * of depth supernodedepth (>=0), on success
79221fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
7936780e684SKyle Evans * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
7946780e684SKyle Evans * nodeoffset
79521fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
79621fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
79721fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
79821fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE, standard meanings
79921fdc27aSRafal Jaworowski */
80021fdc27aSRafal Jaworowski int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
80121fdc27aSRafal Jaworowski int supernodedepth, int *nodedepth);
80221fdc27aSRafal Jaworowski
80321fdc27aSRafal Jaworowski /**
80421fdc27aSRafal Jaworowski * fdt_node_depth - find the depth of a given node
80521fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
80621fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose parent to find
80721fdc27aSRafal Jaworowski *
80821fdc27aSRafal Jaworowski * fdt_node_depth() finds the depth of a given node. The root node
80921fdc27aSRafal Jaworowski * has depth 0, its immediate subnodes depth 1 and so forth.
81021fdc27aSRafal Jaworowski *
81121fdc27aSRafal Jaworowski * NOTE: This function is expensive, as it must scan the device tree
81221fdc27aSRafal Jaworowski * structure from the start to nodeoffset.
81321fdc27aSRafal Jaworowski *
81421fdc27aSRafal Jaworowski * returns:
81521fdc27aSRafal Jaworowski * depth of the node at nodeoffset (>=0), on success
81621fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
81721fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
81821fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
81921fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
82021fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE, standard meanings
82121fdc27aSRafal Jaworowski */
82221fdc27aSRafal Jaworowski int fdt_node_depth(const void *fdt, int nodeoffset);
82321fdc27aSRafal Jaworowski
82421fdc27aSRafal Jaworowski /**
82521fdc27aSRafal Jaworowski * fdt_parent_offset - find the parent of a given node
82621fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
82721fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose parent to find
82821fdc27aSRafal Jaworowski *
82921fdc27aSRafal Jaworowski * fdt_parent_offset() locates the parent node of a given node (that
83021fdc27aSRafal Jaworowski * is, it finds the offset of the node which contains the node at
83121fdc27aSRafal Jaworowski * nodeoffset as a subnode).
83221fdc27aSRafal Jaworowski *
83321fdc27aSRafal Jaworowski * NOTE: This function is expensive, as it must scan the device tree
83421fdc27aSRafal Jaworowski * structure from the start to nodeoffset, *twice*.
83521fdc27aSRafal Jaworowski *
83621fdc27aSRafal Jaworowski * returns:
83721fdc27aSRafal Jaworowski * structure block offset of the parent of the node at nodeoffset
83821fdc27aSRafal Jaworowski * (>=0), on success
83921fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
84021fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
84121fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
84221fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
84321fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE, standard meanings
84421fdc27aSRafal Jaworowski */
84521fdc27aSRafal Jaworowski int fdt_parent_offset(const void *fdt, int nodeoffset);
84621fdc27aSRafal Jaworowski
84721fdc27aSRafal Jaworowski /**
84821fdc27aSRafal Jaworowski * fdt_node_offset_by_prop_value - find nodes with a given property value
84921fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
85021fdc27aSRafal Jaworowski * @startoffset: only find nodes after this offset
85121fdc27aSRafal Jaworowski * @propname: property name to check
85221fdc27aSRafal Jaworowski * @propval: property value to search for
85321fdc27aSRafal Jaworowski * @proplen: length of the value in propval
85421fdc27aSRafal Jaworowski *
85521fdc27aSRafal Jaworowski * fdt_node_offset_by_prop_value() returns the offset of the first
85621fdc27aSRafal Jaworowski * node after startoffset, which has a property named propname whose
85721fdc27aSRafal Jaworowski * value is of length proplen and has value equal to propval; or if
85821fdc27aSRafal Jaworowski * startoffset is -1, the very first such node in the tree.
85921fdc27aSRafal Jaworowski *
86021fdc27aSRafal Jaworowski * To iterate through all nodes matching the criterion, the following
86121fdc27aSRafal Jaworowski * idiom can be used:
86221fdc27aSRafal Jaworowski * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
86321fdc27aSRafal Jaworowski * propval, proplen);
86421fdc27aSRafal Jaworowski * while (offset != -FDT_ERR_NOTFOUND) {
86521fdc27aSRafal Jaworowski * // other code here
86621fdc27aSRafal Jaworowski * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
86721fdc27aSRafal Jaworowski * propval, proplen);
86821fdc27aSRafal Jaworowski * }
86921fdc27aSRafal Jaworowski *
87021fdc27aSRafal Jaworowski * Note the -1 in the first call to the function, if 0 is used here
87121fdc27aSRafal Jaworowski * instead, the function will never locate the root node, even if it
87221fdc27aSRafal Jaworowski * matches the criterion.
87321fdc27aSRafal Jaworowski *
87421fdc27aSRafal Jaworowski * returns:
87521fdc27aSRafal Jaworowski * structure block offset of the located node (>= 0, >startoffset),
87621fdc27aSRafal Jaworowski * on success
87721fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
87821fdc27aSRafal Jaworowski * tree after startoffset
87921fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
88021fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
88121fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
88221fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
88321fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE, standard meanings
88421fdc27aSRafal Jaworowski */
88521fdc27aSRafal Jaworowski int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
88621fdc27aSRafal Jaworowski const char *propname,
88721fdc27aSRafal Jaworowski const void *propval, int proplen);
88821fdc27aSRafal Jaworowski
88921fdc27aSRafal Jaworowski /**
89021fdc27aSRafal Jaworowski * fdt_node_offset_by_phandle - find the node with a given phandle
89121fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
89221fdc27aSRafal Jaworowski * @phandle: phandle value
89321fdc27aSRafal Jaworowski *
89421fdc27aSRafal Jaworowski * fdt_node_offset_by_phandle() returns the offset of the node
89521fdc27aSRafal Jaworowski * which has the given phandle value. If there is more than one node
89621fdc27aSRafal Jaworowski * in the tree with the given phandle (an invalid tree), results are
89721fdc27aSRafal Jaworowski * undefined.
89821fdc27aSRafal Jaworowski *
89921fdc27aSRafal Jaworowski * returns:
90021fdc27aSRafal Jaworowski * structure block offset of the located node (>= 0), on success
90121fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, no node with that phandle exists
90221fdc27aSRafal Jaworowski * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
90321fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
90421fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
90521fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
90621fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE, standard meanings
90721fdc27aSRafal Jaworowski */
90821fdc27aSRafal Jaworowski int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
90921fdc27aSRafal Jaworowski
91021fdc27aSRafal Jaworowski /**
91121fdc27aSRafal Jaworowski * fdt_node_check_compatible: check a node's compatible property
91221fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
91321fdc27aSRafal Jaworowski * @nodeoffset: offset of a tree node
91421fdc27aSRafal Jaworowski * @compatible: string to match against
91521fdc27aSRafal Jaworowski *
91621fdc27aSRafal Jaworowski *
91721fdc27aSRafal Jaworowski * fdt_node_check_compatible() returns 0 if the given node contains a
91821fdc27aSRafal Jaworowski * 'compatible' property with the given string as one of its elements,
91921fdc27aSRafal Jaworowski * it returns non-zero otherwise, or on error.
92021fdc27aSRafal Jaworowski *
92121fdc27aSRafal Jaworowski * returns:
92221fdc27aSRafal Jaworowski * 0, if the node has a 'compatible' property listing the given string
92321fdc27aSRafal Jaworowski * 1, if the node has a 'compatible' property, but it does not list
92421fdc27aSRafal Jaworowski * the given string
92521fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
92621fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
92721fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
92821fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
92921fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
93021fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE, standard meanings
93121fdc27aSRafal Jaworowski */
93221fdc27aSRafal Jaworowski int fdt_node_check_compatible(const void *fdt, int nodeoffset,
93321fdc27aSRafal Jaworowski const char *compatible);
93421fdc27aSRafal Jaworowski
93521fdc27aSRafal Jaworowski /**
93621fdc27aSRafal Jaworowski * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
93721fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
93821fdc27aSRafal Jaworowski * @startoffset: only find nodes after this offset
93921fdc27aSRafal Jaworowski * @compatible: 'compatible' string to match against
94021fdc27aSRafal Jaworowski *
94121fdc27aSRafal Jaworowski * fdt_node_offset_by_compatible() returns the offset of the first
94221fdc27aSRafal Jaworowski * node after startoffset, which has a 'compatible' property which
94321fdc27aSRafal Jaworowski * lists the given compatible string; or if startoffset is -1, the
94421fdc27aSRafal Jaworowski * very first such node in the tree.
94521fdc27aSRafal Jaworowski *
94621fdc27aSRafal Jaworowski * To iterate through all nodes matching the criterion, the following
94721fdc27aSRafal Jaworowski * idiom can be used:
94821fdc27aSRafal Jaworowski * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
94921fdc27aSRafal Jaworowski * while (offset != -FDT_ERR_NOTFOUND) {
95021fdc27aSRafal Jaworowski * // other code here
95121fdc27aSRafal Jaworowski * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
95221fdc27aSRafal Jaworowski * }
95321fdc27aSRafal Jaworowski *
95421fdc27aSRafal Jaworowski * Note the -1 in the first call to the function, if 0 is used here
95521fdc27aSRafal Jaworowski * instead, the function will never locate the root node, even if it
95621fdc27aSRafal Jaworowski * matches the criterion.
95721fdc27aSRafal Jaworowski *
95821fdc27aSRafal Jaworowski * returns:
95921fdc27aSRafal Jaworowski * structure block offset of the located node (>= 0, >startoffset),
96021fdc27aSRafal Jaworowski * on success
96121fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
96221fdc27aSRafal Jaworowski * tree after startoffset
96321fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
96421fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
96521fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
96621fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
96721fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE, standard meanings
96821fdc27aSRafal Jaworowski */
96921fdc27aSRafal Jaworowski int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
97021fdc27aSRafal Jaworowski const char *compatible);
97121fdc27aSRafal Jaworowski
9726780e684SKyle Evans /**
9736780e684SKyle Evans * fdt_stringlist_contains - check a string list property for a string
9746780e684SKyle Evans * @strlist: Property containing a list of strings to check
9756780e684SKyle Evans * @listlen: Length of property
9766780e684SKyle Evans * @str: String to search for
9776780e684SKyle Evans *
9786780e684SKyle Evans * This is a utility function provided for convenience. The list contains
9796780e684SKyle Evans * one or more strings, each terminated by \0, as is found in a device tree
9806780e684SKyle Evans * "compatible" property.
9816780e684SKyle Evans *
9826780e684SKyle Evans * @return: 1 if the string is found in the list, 0 not found, or invalid list
9836780e684SKyle Evans */
9846780e684SKyle Evans int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
9856780e684SKyle Evans
9866780e684SKyle Evans /**
9876780e684SKyle Evans * fdt_stringlist_count - count the number of strings in a string list
9886780e684SKyle Evans * @fdt: pointer to the device tree blob
9896780e684SKyle Evans * @nodeoffset: offset of a tree node
9906780e684SKyle Evans * @property: name of the property containing the string list
9916780e684SKyle Evans * @return:
9926780e684SKyle Evans * the number of strings in the given property
9936780e684SKyle Evans * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
9946780e684SKyle Evans * -FDT_ERR_NOTFOUND if the property does not exist
9956780e684SKyle Evans */
9966780e684SKyle Evans int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
9976780e684SKyle Evans
9986780e684SKyle Evans /**
9996780e684SKyle Evans * fdt_stringlist_search - find a string in a string list and return its index
10006780e684SKyle Evans * @fdt: pointer to the device tree blob
10016780e684SKyle Evans * @nodeoffset: offset of a tree node
10026780e684SKyle Evans * @property: name of the property containing the string list
10036780e684SKyle Evans * @string: string to look up in the string list
10046780e684SKyle Evans *
10056780e684SKyle Evans * Note that it is possible for this function to succeed on property values
10066780e684SKyle Evans * that are not NUL-terminated. That's because the function will stop after
10076780e684SKyle Evans * finding the first occurrence of @string. This can for example happen with
10086780e684SKyle Evans * small-valued cell properties, such as #address-cells, when searching for
10096780e684SKyle Evans * the empty string.
10106780e684SKyle Evans *
10116780e684SKyle Evans * @return:
10126780e684SKyle Evans * the index of the string in the list of strings
10136780e684SKyle Evans * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
10146780e684SKyle Evans * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
10156780e684SKyle Evans * the given string
10166780e684SKyle Evans */
10176780e684SKyle Evans int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
10186780e684SKyle Evans const char *string);
10196780e684SKyle Evans
10206780e684SKyle Evans /**
10216780e684SKyle Evans * fdt_stringlist_get() - obtain the string at a given index in a string list
10226780e684SKyle Evans * @fdt: pointer to the device tree blob
10236780e684SKyle Evans * @nodeoffset: offset of a tree node
10246780e684SKyle Evans * @property: name of the property containing the string list
10256780e684SKyle Evans * @index: index of the string to return
10266780e684SKyle Evans * @lenp: return location for the string length or an error code on failure
10276780e684SKyle Evans *
10286780e684SKyle Evans * Note that this will successfully extract strings from properties with
10296780e684SKyle Evans * non-NUL-terminated values. For example on small-valued cell properties
10306780e684SKyle Evans * this function will return the empty string.
10316780e684SKyle Evans *
10326780e684SKyle Evans * If non-NULL, the length of the string (on success) or a negative error-code
10336780e684SKyle Evans * (on failure) will be stored in the integer pointer to by lenp.
10346780e684SKyle Evans *
10356780e684SKyle Evans * @return:
10366780e684SKyle Evans * A pointer to the string at the given index in the string list or NULL on
10376780e684SKyle Evans * failure. On success the length of the string will be stored in the memory
10386780e684SKyle Evans * location pointed to by the lenp parameter, if non-NULL. On failure one of
10396780e684SKyle Evans * the following negative error codes will be returned in the lenp parameter
10406780e684SKyle Evans * (if non-NULL):
10416780e684SKyle Evans * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
10426780e684SKyle Evans * -FDT_ERR_NOTFOUND if the property does not exist
10436780e684SKyle Evans */
10446780e684SKyle Evans const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
10456780e684SKyle Evans const char *property, int index,
10466780e684SKyle Evans int *lenp);
10476780e684SKyle Evans
10486780e684SKyle Evans /**********************************************************************/
10496780e684SKyle Evans /* Read-only functions (addressing related) */
10506780e684SKyle Evans /**********************************************************************/
10516780e684SKyle Evans
10526780e684SKyle Evans /**
10536780e684SKyle Evans * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
10546780e684SKyle Evans *
10556780e684SKyle Evans * This is the maximum value for #address-cells, #size-cells and
10566780e684SKyle Evans * similar properties that will be processed by libfdt. IEE1275
10576780e684SKyle Evans * requires that OF implementations handle values up to 4.
10586780e684SKyle Evans * Implementations may support larger values, but in practice higher
10596780e684SKyle Evans * values aren't used.
10606780e684SKyle Evans */
10616780e684SKyle Evans #define FDT_MAX_NCELLS 4
10626780e684SKyle Evans
10636780e684SKyle Evans /**
10646780e684SKyle Evans * fdt_address_cells - retrieve address size for a bus represented in the tree
10656780e684SKyle Evans * @fdt: pointer to the device tree blob
10666780e684SKyle Evans * @nodeoffset: offset of the node to find the address size for
10676780e684SKyle Evans *
10686780e684SKyle Evans * When the node has a valid #address-cells property, returns its value.
10696780e684SKyle Evans *
10706780e684SKyle Evans * returns:
10716780e684SKyle Evans * 0 <= n < FDT_MAX_NCELLS, on success
10726780e684SKyle Evans * 2, if the node has no #address-cells property
10736780e684SKyle Evans * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
10746780e684SKyle Evans * #address-cells property
10756780e684SKyle Evans * -FDT_ERR_BADMAGIC,
10766780e684SKyle Evans * -FDT_ERR_BADVERSION,
10776780e684SKyle Evans * -FDT_ERR_BADSTATE,
10786780e684SKyle Evans * -FDT_ERR_BADSTRUCTURE,
10796780e684SKyle Evans * -FDT_ERR_TRUNCATED, standard meanings
10806780e684SKyle Evans */
10816780e684SKyle Evans int fdt_address_cells(const void *fdt, int nodeoffset);
10826780e684SKyle Evans
10836780e684SKyle Evans /**
10846780e684SKyle Evans * fdt_size_cells - retrieve address range size for a bus represented in the
10856780e684SKyle Evans * tree
10866780e684SKyle Evans * @fdt: pointer to the device tree blob
10876780e684SKyle Evans * @nodeoffset: offset of the node to find the address range size for
10886780e684SKyle Evans *
10896780e684SKyle Evans * When the node has a valid #size-cells property, returns its value.
10906780e684SKyle Evans *
10916780e684SKyle Evans * returns:
10926780e684SKyle Evans * 0 <= n < FDT_MAX_NCELLS, on success
10936780e684SKyle Evans * 2, if the node has no #address-cells property
10946780e684SKyle Evans * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
10956780e684SKyle Evans * #size-cells property
10966780e684SKyle Evans * -FDT_ERR_BADMAGIC,
10976780e684SKyle Evans * -FDT_ERR_BADVERSION,
10986780e684SKyle Evans * -FDT_ERR_BADSTATE,
10996780e684SKyle Evans * -FDT_ERR_BADSTRUCTURE,
11006780e684SKyle Evans * -FDT_ERR_TRUNCATED, standard meanings
11016780e684SKyle Evans */
11026780e684SKyle Evans int fdt_size_cells(const void *fdt, int nodeoffset);
11036780e684SKyle Evans
11046780e684SKyle Evans
110521fdc27aSRafal Jaworowski /**********************************************************************/
110621fdc27aSRafal Jaworowski /* Write-in-place functions */
110721fdc27aSRafal Jaworowski /**********************************************************************/
110821fdc27aSRafal Jaworowski
110921fdc27aSRafal Jaworowski /**
11106780e684SKyle Evans * fdt_setprop_inplace_namelen_partial - change a property's value,
11116780e684SKyle Evans * but not its size
11126780e684SKyle Evans * @fdt: pointer to the device tree blob
11136780e684SKyle Evans * @nodeoffset: offset of the node whose property to change
11146780e684SKyle Evans * @name: name of the property to change
11156780e684SKyle Evans * @namelen: number of characters of name to consider
11166780e684SKyle Evans * @idx: index of the property to change in the array
11176780e684SKyle Evans * @val: pointer to data to replace the property value with
11186780e684SKyle Evans * @len: length of the property value
11196780e684SKyle Evans *
11206780e684SKyle Evans * Identical to fdt_setprop_inplace(), but modifies the given property
11216780e684SKyle Evans * starting from the given index, and using only the first characters
11226780e684SKyle Evans * of the name. It is useful when you want to manipulate only one value of
11236780e684SKyle Evans * an array and you have a string that doesn't end with \0.
11246780e684SKyle Evans */
11256780e684SKyle Evans #ifndef SWIG /* Not available in Python */
11266780e684SKyle Evans int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
11276780e684SKyle Evans const char *name, int namelen,
11286780e684SKyle Evans uint32_t idx, const void *val,
11296780e684SKyle Evans int len);
11306780e684SKyle Evans #endif
11316780e684SKyle Evans
11326780e684SKyle Evans /**
113321fdc27aSRafal Jaworowski * fdt_setprop_inplace - change a property's value, but not its size
113421fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
113521fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to change
113621fdc27aSRafal Jaworowski * @name: name of the property to change
113721fdc27aSRafal Jaworowski * @val: pointer to data to replace the property value with
113821fdc27aSRafal Jaworowski * @len: length of the property value
113921fdc27aSRafal Jaworowski *
114021fdc27aSRafal Jaworowski * fdt_setprop_inplace() replaces the value of a given property with
114121fdc27aSRafal Jaworowski * the data in val, of length len. This function cannot change the
114221fdc27aSRafal Jaworowski * size of a property, and so will only work if len is equal to the
114321fdc27aSRafal Jaworowski * current length of the property.
114421fdc27aSRafal Jaworowski *
114521fdc27aSRafal Jaworowski * This function will alter only the bytes in the blob which contain
114621fdc27aSRafal Jaworowski * the given property value, and will not alter or move any other part
114721fdc27aSRafal Jaworowski * of the tree.
114821fdc27aSRafal Jaworowski *
114921fdc27aSRafal Jaworowski * returns:
115021fdc27aSRafal Jaworowski * 0, on success
115121fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
115221fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, node does not have the named property
115321fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
115421fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
115521fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
115621fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
115721fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
115821fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
115921fdc27aSRafal Jaworowski */
11606780e684SKyle Evans #ifndef SWIG /* Not available in Python */
116121fdc27aSRafal Jaworowski int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
116221fdc27aSRafal Jaworowski const void *val, int len);
11636780e684SKyle Evans #endif
116421fdc27aSRafal Jaworowski
116521fdc27aSRafal Jaworowski /**
116652baf267SWarner Losh * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
116721fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
116821fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to change
116921fdc27aSRafal Jaworowski * @name: name of the property to change
117052baf267SWarner Losh * @val: 32-bit integer value to replace the property with
117121fdc27aSRafal Jaworowski *
117252baf267SWarner Losh * fdt_setprop_inplace_u32() replaces the value of a given property
117352baf267SWarner Losh * with the 32-bit integer value in val, converting val to big-endian
117452baf267SWarner Losh * if necessary. This function cannot change the size of a property,
117552baf267SWarner Losh * and so will only work if the property already exists and has length
117652baf267SWarner Losh * 4.
117721fdc27aSRafal Jaworowski *
117821fdc27aSRafal Jaworowski * This function will alter only the bytes in the blob which contain
117921fdc27aSRafal Jaworowski * the given property value, and will not alter or move any other part
118021fdc27aSRafal Jaworowski * of the tree.
118121fdc27aSRafal Jaworowski *
118221fdc27aSRafal Jaworowski * returns:
118321fdc27aSRafal Jaworowski * 0, on success
118421fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
118521fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, node does not have the named property
118621fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
118721fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
118821fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
118921fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
119021fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
119121fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
119221fdc27aSRafal Jaworowski */
fdt_setprop_inplace_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)119352baf267SWarner Losh static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
119421fdc27aSRafal Jaworowski const char *name, uint32_t val)
119521fdc27aSRafal Jaworowski {
11966780e684SKyle Evans fdt32_t tmp = cpu_to_fdt32(val);
11976780e684SKyle Evans return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
119821fdc27aSRafal Jaworowski }
119921fdc27aSRafal Jaworowski
120021fdc27aSRafal Jaworowski /**
120152baf267SWarner Losh * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
120252baf267SWarner Losh * @fdt: pointer to the device tree blob
120352baf267SWarner Losh * @nodeoffset: offset of the node whose property to change
120452baf267SWarner Losh * @name: name of the property to change
120552baf267SWarner Losh * @val: 64-bit integer value to replace the property with
120652baf267SWarner Losh *
120752baf267SWarner Losh * fdt_setprop_inplace_u64() replaces the value of a given property
120852baf267SWarner Losh * with the 64-bit integer value in val, converting val to big-endian
120952baf267SWarner Losh * if necessary. This function cannot change the size of a property,
121052baf267SWarner Losh * and so will only work if the property already exists and has length
121152baf267SWarner Losh * 8.
121252baf267SWarner Losh *
121352baf267SWarner Losh * This function will alter only the bytes in the blob which contain
121452baf267SWarner Losh * the given property value, and will not alter or move any other part
121552baf267SWarner Losh * of the tree.
121652baf267SWarner Losh *
121752baf267SWarner Losh * returns:
121852baf267SWarner Losh * 0, on success
121952baf267SWarner Losh * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
122052baf267SWarner Losh * -FDT_ERR_NOTFOUND, node does not have the named property
122152baf267SWarner Losh * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
122252baf267SWarner Losh * -FDT_ERR_BADMAGIC,
122352baf267SWarner Losh * -FDT_ERR_BADVERSION,
122452baf267SWarner Losh * -FDT_ERR_BADSTATE,
122552baf267SWarner Losh * -FDT_ERR_BADSTRUCTURE,
122652baf267SWarner Losh * -FDT_ERR_TRUNCATED, standard meanings
122752baf267SWarner Losh */
fdt_setprop_inplace_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)122852baf267SWarner Losh static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
122952baf267SWarner Losh const char *name, uint64_t val)
123052baf267SWarner Losh {
12316780e684SKyle Evans fdt64_t tmp = cpu_to_fdt64(val);
12326780e684SKyle Evans return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
123352baf267SWarner Losh }
123452baf267SWarner Losh
123552baf267SWarner Losh /**
123652baf267SWarner Losh * fdt_setprop_inplace_cell - change the value of a single-cell property
123752baf267SWarner Losh *
123852baf267SWarner Losh * This is an alternative name for fdt_setprop_inplace_u32()
123952baf267SWarner Losh */
fdt_setprop_inplace_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)124052baf267SWarner Losh static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
124152baf267SWarner Losh const char *name, uint32_t val)
124252baf267SWarner Losh {
124352baf267SWarner Losh return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
124452baf267SWarner Losh }
124552baf267SWarner Losh
124652baf267SWarner Losh /**
124721fdc27aSRafal Jaworowski * fdt_nop_property - replace a property with nop tags
124821fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
124921fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to nop
125021fdc27aSRafal Jaworowski * @name: name of the property to nop
125121fdc27aSRafal Jaworowski *
125221fdc27aSRafal Jaworowski * fdt_nop_property() will replace a given property's representation
125321fdc27aSRafal Jaworowski * in the blob with FDT_NOP tags, effectively removing it from the
125421fdc27aSRafal Jaworowski * tree.
125521fdc27aSRafal Jaworowski *
125621fdc27aSRafal Jaworowski * This function will alter only the bytes in the blob which contain
125721fdc27aSRafal Jaworowski * the property, and will not alter or move any other part of the
125821fdc27aSRafal Jaworowski * tree.
125921fdc27aSRafal Jaworowski *
126021fdc27aSRafal Jaworowski * returns:
126121fdc27aSRafal Jaworowski * 0, on success
126221fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, node does not have the named property
126321fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
126421fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
126521fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
126621fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
126721fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
126821fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
126921fdc27aSRafal Jaworowski */
127021fdc27aSRafal Jaworowski int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
127121fdc27aSRafal Jaworowski
127221fdc27aSRafal Jaworowski /**
127321fdc27aSRafal Jaworowski * fdt_nop_node - replace a node (subtree) with nop tags
127421fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
127521fdc27aSRafal Jaworowski * @nodeoffset: offset of the node to nop
127621fdc27aSRafal Jaworowski *
127721fdc27aSRafal Jaworowski * fdt_nop_node() will replace a given node's representation in the
127821fdc27aSRafal Jaworowski * blob, including all its subnodes, if any, with FDT_NOP tags,
127921fdc27aSRafal Jaworowski * effectively removing it from the tree.
128021fdc27aSRafal Jaworowski *
128121fdc27aSRafal Jaworowski * This function will alter only the bytes in the blob which contain
128221fdc27aSRafal Jaworowski * the node and its properties and subnodes, and will not alter or
128321fdc27aSRafal Jaworowski * move any other part of the tree.
128421fdc27aSRafal Jaworowski *
128521fdc27aSRafal Jaworowski * returns:
128621fdc27aSRafal Jaworowski * 0, on success
128721fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
128821fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
128921fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
129021fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
129121fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
129221fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
129321fdc27aSRafal Jaworowski */
129421fdc27aSRafal Jaworowski int fdt_nop_node(void *fdt, int nodeoffset);
129521fdc27aSRafal Jaworowski
129621fdc27aSRafal Jaworowski /**********************************************************************/
129721fdc27aSRafal Jaworowski /* Sequential write functions */
129821fdc27aSRafal Jaworowski /**********************************************************************/
129921fdc27aSRafal Jaworowski
130021fdc27aSRafal Jaworowski int fdt_create(void *buf, int bufsize);
13016780e684SKyle Evans int fdt_resize(void *fdt, void *buf, int bufsize);
130221fdc27aSRafal Jaworowski int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
130321fdc27aSRafal Jaworowski int fdt_finish_reservemap(void *fdt);
130421fdc27aSRafal Jaworowski int fdt_begin_node(void *fdt, const char *name);
130521fdc27aSRafal Jaworowski int fdt_property(void *fdt, const char *name, const void *val, int len);
fdt_property_u32(void * fdt,const char * name,uint32_t val)130652baf267SWarner Losh static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
130721fdc27aSRafal Jaworowski {
13086780e684SKyle Evans fdt32_t tmp = cpu_to_fdt32(val);
13096780e684SKyle Evans return fdt_property(fdt, name, &tmp, sizeof(tmp));
131021fdc27aSRafal Jaworowski }
fdt_property_u64(void * fdt,const char * name,uint64_t val)131152baf267SWarner Losh static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
131252baf267SWarner Losh {
13136780e684SKyle Evans fdt64_t tmp = cpu_to_fdt64(val);
13146780e684SKyle Evans return fdt_property(fdt, name, &tmp, sizeof(tmp));
131552baf267SWarner Losh }
fdt_property_cell(void * fdt,const char * name,uint32_t val)131652baf267SWarner Losh static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
131752baf267SWarner Losh {
131852baf267SWarner Losh return fdt_property_u32(fdt, name, val);
131952baf267SWarner Losh }
13206780e684SKyle Evans
13216780e684SKyle Evans /**
13226780e684SKyle Evans * fdt_property_placeholder - add a new property and return a ptr to its value
13236780e684SKyle Evans *
13246780e684SKyle Evans * @fdt: pointer to the device tree blob
13256780e684SKyle Evans * @name: name of property to add
13266780e684SKyle Evans * @len: length of property value in bytes
13276780e684SKyle Evans * @valp: returns a pointer to where where the value should be placed
13286780e684SKyle Evans *
13296780e684SKyle Evans * returns:
13306780e684SKyle Evans * 0, on success
13316780e684SKyle Evans * -FDT_ERR_BADMAGIC,
13326780e684SKyle Evans * -FDT_ERR_NOSPACE, standard meanings
13336780e684SKyle Evans */
13346780e684SKyle Evans int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp);
13356780e684SKyle Evans
133621fdc27aSRafal Jaworowski #define fdt_property_string(fdt, name, str) \
133721fdc27aSRafal Jaworowski fdt_property(fdt, name, str, strlen(str)+1)
133821fdc27aSRafal Jaworowski int fdt_end_node(void *fdt);
133921fdc27aSRafal Jaworowski int fdt_finish(void *fdt);
134021fdc27aSRafal Jaworowski
134121fdc27aSRafal Jaworowski /**********************************************************************/
134221fdc27aSRafal Jaworowski /* Read-write functions */
134321fdc27aSRafal Jaworowski /**********************************************************************/
134421fdc27aSRafal Jaworowski
134552baf267SWarner Losh int fdt_create_empty_tree(void *buf, int bufsize);
134621fdc27aSRafal Jaworowski int fdt_open_into(const void *fdt, void *buf, int bufsize);
134721fdc27aSRafal Jaworowski int fdt_pack(void *fdt);
134821fdc27aSRafal Jaworowski
134921fdc27aSRafal Jaworowski /**
135021fdc27aSRafal Jaworowski * fdt_add_mem_rsv - add one memory reserve map entry
135121fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
135221fdc27aSRafal Jaworowski * @address, @size: 64-bit values (native endian)
135321fdc27aSRafal Jaworowski *
135421fdc27aSRafal Jaworowski * Adds a reserve map entry to the given blob reserving a region at
135521fdc27aSRafal Jaworowski * address address of length size.
135621fdc27aSRafal Jaworowski *
135721fdc27aSRafal Jaworowski * This function will insert data into the reserve map and will
135821fdc27aSRafal Jaworowski * therefore change the indexes of some entries in the table.
135921fdc27aSRafal Jaworowski *
136021fdc27aSRafal Jaworowski * returns:
136121fdc27aSRafal Jaworowski * 0, on success
136221fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
136321fdc27aSRafal Jaworowski * contain the new reservation entry
136421fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
136521fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
136621fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
136721fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
136821fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT,
136921fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
137021fdc27aSRafal Jaworowski */
137121fdc27aSRafal Jaworowski int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
137221fdc27aSRafal Jaworowski
137321fdc27aSRafal Jaworowski /**
137421fdc27aSRafal Jaworowski * fdt_del_mem_rsv - remove a memory reserve map entry
137521fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
137621fdc27aSRafal Jaworowski * @n: entry to remove
137721fdc27aSRafal Jaworowski *
137821fdc27aSRafal Jaworowski * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
137921fdc27aSRafal Jaworowski * the blob.
138021fdc27aSRafal Jaworowski *
138121fdc27aSRafal Jaworowski * This function will delete data from the reservation table and will
138221fdc27aSRafal Jaworowski * therefore change the indexes of some entries in the table.
138321fdc27aSRafal Jaworowski *
138421fdc27aSRafal Jaworowski * returns:
138521fdc27aSRafal Jaworowski * 0, on success
138621fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
138721fdc27aSRafal Jaworowski * are less than n+1 reserve map entries)
138821fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
138921fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
139021fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
139121fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
139221fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT,
139321fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
139421fdc27aSRafal Jaworowski */
139521fdc27aSRafal Jaworowski int fdt_del_mem_rsv(void *fdt, int n);
139621fdc27aSRafal Jaworowski
139721fdc27aSRafal Jaworowski /**
139821fdc27aSRafal Jaworowski * fdt_set_name - change the name of a given node
139921fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
140021fdc27aSRafal Jaworowski * @nodeoffset: structure block offset of a node
140121fdc27aSRafal Jaworowski * @name: name to give the node
140221fdc27aSRafal Jaworowski *
140321fdc27aSRafal Jaworowski * fdt_set_name() replaces the name (including unit address, if any)
140421fdc27aSRafal Jaworowski * of the given node with the given string. NOTE: this function can't
140521fdc27aSRafal Jaworowski * efficiently check if the new name is unique amongst the given
140621fdc27aSRafal Jaworowski * node's siblings; results are undefined if this function is invoked
140721fdc27aSRafal Jaworowski * with a name equal to one of the given node's siblings.
140821fdc27aSRafal Jaworowski *
140921fdc27aSRafal Jaworowski * This function may insert or delete data from the blob, and will
141021fdc27aSRafal Jaworowski * therefore change the offsets of some existing nodes.
141121fdc27aSRafal Jaworowski *
141221fdc27aSRafal Jaworowski * returns:
141321fdc27aSRafal Jaworowski * 0, on success
141421fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
141521fdc27aSRafal Jaworowski * to contain the new name
141621fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
141721fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
141821fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
141921fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE, standard meanings
142021fdc27aSRafal Jaworowski */
142121fdc27aSRafal Jaworowski int fdt_set_name(void *fdt, int nodeoffset, const char *name);
142221fdc27aSRafal Jaworowski
142321fdc27aSRafal Jaworowski /**
142421fdc27aSRafal Jaworowski * fdt_setprop - create or change a property
142521fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
142621fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to change
142721fdc27aSRafal Jaworowski * @name: name of the property to change
142821fdc27aSRafal Jaworowski * @val: pointer to data to set the property value to
142921fdc27aSRafal Jaworowski * @len: length of the property value
143021fdc27aSRafal Jaworowski *
143121fdc27aSRafal Jaworowski * fdt_setprop() sets the value of the named property in the given
143221fdc27aSRafal Jaworowski * node to the given value and length, creating the property if it
143321fdc27aSRafal Jaworowski * does not already exist.
143421fdc27aSRafal Jaworowski *
143521fdc27aSRafal Jaworowski * This function may insert or delete data from the blob, and will
143621fdc27aSRafal Jaworowski * therefore change the offsets of some existing nodes.
143721fdc27aSRafal Jaworowski *
143821fdc27aSRafal Jaworowski * returns:
143921fdc27aSRafal Jaworowski * 0, on success
144021fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
144121fdc27aSRafal Jaworowski * contain the new property value
144221fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
144321fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT,
144421fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
144521fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
144621fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
144721fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
144821fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT,
144921fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
145021fdc27aSRafal Jaworowski */
145121fdc27aSRafal Jaworowski int fdt_setprop(void *fdt, int nodeoffset, const char *name,
145221fdc27aSRafal Jaworowski const void *val, int len);
145321fdc27aSRafal Jaworowski
145421fdc27aSRafal Jaworowski /**
14556780e684SKyle Evans * fdt_setprop_placeholder - allocate space for a property
14566780e684SKyle Evans * @fdt: pointer to the device tree blob
14576780e684SKyle Evans * @nodeoffset: offset of the node whose property to change
14586780e684SKyle Evans * @name: name of the property to change
14596780e684SKyle Evans * @len: length of the property value
14606780e684SKyle Evans * @prop_data: return pointer to property data
14616780e684SKyle Evans *
14626780e684SKyle Evans * fdt_setprop_placeholer() allocates the named property in the given node.
14636780e684SKyle Evans * If the property exists it is resized. In either case a pointer to the
14646780e684SKyle Evans * property data is returned.
14656780e684SKyle Evans *
14666780e684SKyle Evans * This function may insert or delete data from the blob, and will
14676780e684SKyle Evans * therefore change the offsets of some existing nodes.
14686780e684SKyle Evans *
14696780e684SKyle Evans * returns:
14706780e684SKyle Evans * 0, on success
14716780e684SKyle Evans * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
14726780e684SKyle Evans * contain the new property value
14736780e684SKyle Evans * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
14746780e684SKyle Evans * -FDT_ERR_BADLAYOUT,
14756780e684SKyle Evans * -FDT_ERR_BADMAGIC,
14766780e684SKyle Evans * -FDT_ERR_BADVERSION,
14776780e684SKyle Evans * -FDT_ERR_BADSTATE,
14786780e684SKyle Evans * -FDT_ERR_BADSTRUCTURE,
14796780e684SKyle Evans * -FDT_ERR_BADLAYOUT,
14806780e684SKyle Evans * -FDT_ERR_TRUNCATED, standard meanings
14816780e684SKyle Evans */
14826780e684SKyle Evans int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
14836780e684SKyle Evans int len, void **prop_data);
14846780e684SKyle Evans
14856780e684SKyle Evans /**
148652baf267SWarner Losh * fdt_setprop_u32 - set a property to a 32-bit integer
148721fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
148821fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to change
148921fdc27aSRafal Jaworowski * @name: name of the property to change
149021fdc27aSRafal Jaworowski * @val: 32-bit integer value for the property (native endian)
149121fdc27aSRafal Jaworowski *
149252baf267SWarner Losh * fdt_setprop_u32() sets the value of the named property in the given
149352baf267SWarner Losh * node to the given 32-bit integer value (converting to big-endian if
149421fdc27aSRafal Jaworowski * necessary), or creates a new property with that value if it does
149521fdc27aSRafal Jaworowski * not already exist.
149621fdc27aSRafal Jaworowski *
149721fdc27aSRafal Jaworowski * This function may insert or delete data from the blob, and will
149821fdc27aSRafal Jaworowski * therefore change the offsets of some existing nodes.
149921fdc27aSRafal Jaworowski *
150021fdc27aSRafal Jaworowski * returns:
150121fdc27aSRafal Jaworowski * 0, on success
150221fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
150321fdc27aSRafal Jaworowski * contain the new property value
150421fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
150521fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT,
150621fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
150721fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
150821fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
150921fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
151021fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT,
151121fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
151221fdc27aSRafal Jaworowski */
fdt_setprop_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)151352baf267SWarner Losh static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
151421fdc27aSRafal Jaworowski uint32_t val)
151521fdc27aSRafal Jaworowski {
15166780e684SKyle Evans fdt32_t tmp = cpu_to_fdt32(val);
15176780e684SKyle Evans return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
151821fdc27aSRafal Jaworowski }
151921fdc27aSRafal Jaworowski
152021fdc27aSRafal Jaworowski /**
152152baf267SWarner Losh * fdt_setprop_u64 - set a property to a 64-bit integer
152252baf267SWarner Losh * @fdt: pointer to the device tree blob
152352baf267SWarner Losh * @nodeoffset: offset of the node whose property to change
152452baf267SWarner Losh * @name: name of the property to change
152552baf267SWarner Losh * @val: 64-bit integer value for the property (native endian)
152652baf267SWarner Losh *
152752baf267SWarner Losh * fdt_setprop_u64() sets the value of the named property in the given
152852baf267SWarner Losh * node to the given 64-bit integer value (converting to big-endian if
152952baf267SWarner Losh * necessary), or creates a new property with that value if it does
153052baf267SWarner Losh * not already exist.
153152baf267SWarner Losh *
153252baf267SWarner Losh * This function may insert or delete data from the blob, and will
153352baf267SWarner Losh * therefore change the offsets of some existing nodes.
153452baf267SWarner Losh *
153552baf267SWarner Losh * returns:
153652baf267SWarner Losh * 0, on success
153752baf267SWarner Losh * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
153852baf267SWarner Losh * contain the new property value
153952baf267SWarner Losh * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
154052baf267SWarner Losh * -FDT_ERR_BADLAYOUT,
154152baf267SWarner Losh * -FDT_ERR_BADMAGIC,
154252baf267SWarner Losh * -FDT_ERR_BADVERSION,
154352baf267SWarner Losh * -FDT_ERR_BADSTATE,
154452baf267SWarner Losh * -FDT_ERR_BADSTRUCTURE,
154552baf267SWarner Losh * -FDT_ERR_BADLAYOUT,
154652baf267SWarner Losh * -FDT_ERR_TRUNCATED, standard meanings
154752baf267SWarner Losh */
fdt_setprop_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)154852baf267SWarner Losh static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
154952baf267SWarner Losh uint64_t val)
155052baf267SWarner Losh {
15516780e684SKyle Evans fdt64_t tmp = cpu_to_fdt64(val);
15526780e684SKyle Evans return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
155352baf267SWarner Losh }
155452baf267SWarner Losh
155552baf267SWarner Losh /**
155652baf267SWarner Losh * fdt_setprop_cell - set a property to a single cell value
155752baf267SWarner Losh *
155852baf267SWarner Losh * This is an alternative name for fdt_setprop_u32()
155952baf267SWarner Losh */
fdt_setprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)156052baf267SWarner Losh static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
156152baf267SWarner Losh uint32_t val)
156252baf267SWarner Losh {
156352baf267SWarner Losh return fdt_setprop_u32(fdt, nodeoffset, name, val);
156452baf267SWarner Losh }
156552baf267SWarner Losh
156652baf267SWarner Losh /**
156721fdc27aSRafal Jaworowski * fdt_setprop_string - set a property to a string value
156821fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
156921fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to change
157021fdc27aSRafal Jaworowski * @name: name of the property to change
157121fdc27aSRafal Jaworowski * @str: string value for the property
157221fdc27aSRafal Jaworowski *
157321fdc27aSRafal Jaworowski * fdt_setprop_string() sets the value of the named property in the
157421fdc27aSRafal Jaworowski * given node to the given string value (using the length of the
157521fdc27aSRafal Jaworowski * string to determine the new length of the property), or creates a
157621fdc27aSRafal Jaworowski * new property with that value if it does not already exist.
157721fdc27aSRafal Jaworowski *
157821fdc27aSRafal Jaworowski * This function may insert or delete data from the blob, and will
157921fdc27aSRafal Jaworowski * therefore change the offsets of some existing nodes.
158021fdc27aSRafal Jaworowski *
158121fdc27aSRafal Jaworowski * returns:
158221fdc27aSRafal Jaworowski * 0, on success
158321fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
158421fdc27aSRafal Jaworowski * contain the new property value
158521fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
158621fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT,
158721fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
158821fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
158921fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
159021fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
159121fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT,
159221fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
159321fdc27aSRafal Jaworowski */
159421fdc27aSRafal Jaworowski #define fdt_setprop_string(fdt, nodeoffset, name, str) \
159521fdc27aSRafal Jaworowski fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
159621fdc27aSRafal Jaworowski
15976780e684SKyle Evans
15986780e684SKyle Evans /**
15996780e684SKyle Evans * fdt_setprop_empty - set a property to an empty value
16006780e684SKyle Evans * @fdt: pointer to the device tree blob
16016780e684SKyle Evans * @nodeoffset: offset of the node whose property to change
16026780e684SKyle Evans * @name: name of the property to change
16036780e684SKyle Evans *
16046780e684SKyle Evans * fdt_setprop_empty() sets the value of the named property in the
16056780e684SKyle Evans * given node to an empty (zero length) value, or creates a new empty
16066780e684SKyle Evans * property if it does not already exist.
16076780e684SKyle Evans *
16086780e684SKyle Evans * This function may insert or delete data from the blob, and will
16096780e684SKyle Evans * therefore change the offsets of some existing nodes.
16106780e684SKyle Evans *
16116780e684SKyle Evans * returns:
16126780e684SKyle Evans * 0, on success
16136780e684SKyle Evans * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
16146780e684SKyle Evans * contain the new property value
16156780e684SKyle Evans * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
16166780e684SKyle Evans * -FDT_ERR_BADLAYOUT,
16176780e684SKyle Evans * -FDT_ERR_BADMAGIC,
16186780e684SKyle Evans * -FDT_ERR_BADVERSION,
16196780e684SKyle Evans * -FDT_ERR_BADSTATE,
16206780e684SKyle Evans * -FDT_ERR_BADSTRUCTURE,
16216780e684SKyle Evans * -FDT_ERR_BADLAYOUT,
16226780e684SKyle Evans * -FDT_ERR_TRUNCATED, standard meanings
16236780e684SKyle Evans */
16246780e684SKyle Evans #define fdt_setprop_empty(fdt, nodeoffset, name) \
16256780e684SKyle Evans fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
16266780e684SKyle Evans
162721fdc27aSRafal Jaworowski /**
162852baf267SWarner Losh * fdt_appendprop - append to or create a property
162952baf267SWarner Losh * @fdt: pointer to the device tree blob
163052baf267SWarner Losh * @nodeoffset: offset of the node whose property to change
163152baf267SWarner Losh * @name: name of the property to append to
163252baf267SWarner Losh * @val: pointer to data to append to the property value
163352baf267SWarner Losh * @len: length of the data to append to the property value
163452baf267SWarner Losh *
163552baf267SWarner Losh * fdt_appendprop() appends the value to the named property in the
163652baf267SWarner Losh * given node, creating the property if it does not already exist.
163752baf267SWarner Losh *
163852baf267SWarner Losh * This function may insert data into the blob, and will therefore
163952baf267SWarner Losh * change the offsets of some existing nodes.
164052baf267SWarner Losh *
164152baf267SWarner Losh * returns:
164252baf267SWarner Losh * 0, on success
164352baf267SWarner Losh * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
164452baf267SWarner Losh * contain the new property value
164552baf267SWarner Losh * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
164652baf267SWarner Losh * -FDT_ERR_BADLAYOUT,
164752baf267SWarner Losh * -FDT_ERR_BADMAGIC,
164852baf267SWarner Losh * -FDT_ERR_BADVERSION,
164952baf267SWarner Losh * -FDT_ERR_BADSTATE,
165052baf267SWarner Losh * -FDT_ERR_BADSTRUCTURE,
165152baf267SWarner Losh * -FDT_ERR_BADLAYOUT,
165252baf267SWarner Losh * -FDT_ERR_TRUNCATED, standard meanings
165352baf267SWarner Losh */
165452baf267SWarner Losh int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
165552baf267SWarner Losh const void *val, int len);
165652baf267SWarner Losh
165752baf267SWarner Losh /**
165852baf267SWarner Losh * fdt_appendprop_u32 - append a 32-bit integer value to a property
165952baf267SWarner Losh * @fdt: pointer to the device tree blob
166052baf267SWarner Losh * @nodeoffset: offset of the node whose property to change
166152baf267SWarner Losh * @name: name of the property to change
166252baf267SWarner Losh * @val: 32-bit integer value to append to the property (native endian)
166352baf267SWarner Losh *
166452baf267SWarner Losh * fdt_appendprop_u32() appends the given 32-bit integer value
166552baf267SWarner Losh * (converting to big-endian if necessary) to the value of the named
166652baf267SWarner Losh * property in the given node, or creates a new property with that
166752baf267SWarner Losh * value if it does not already exist.
166852baf267SWarner Losh *
166952baf267SWarner Losh * This function may insert data into the blob, and will therefore
167052baf267SWarner Losh * change the offsets of some existing nodes.
167152baf267SWarner Losh *
167252baf267SWarner Losh * returns:
167352baf267SWarner Losh * 0, on success
167452baf267SWarner Losh * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
167552baf267SWarner Losh * contain the new property value
167652baf267SWarner Losh * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
167752baf267SWarner Losh * -FDT_ERR_BADLAYOUT,
167852baf267SWarner Losh * -FDT_ERR_BADMAGIC,
167952baf267SWarner Losh * -FDT_ERR_BADVERSION,
168052baf267SWarner Losh * -FDT_ERR_BADSTATE,
168152baf267SWarner Losh * -FDT_ERR_BADSTRUCTURE,
168252baf267SWarner Losh * -FDT_ERR_BADLAYOUT,
168352baf267SWarner Losh * -FDT_ERR_TRUNCATED, standard meanings
168452baf267SWarner Losh */
fdt_appendprop_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)168552baf267SWarner Losh static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
168652baf267SWarner Losh const char *name, uint32_t val)
168752baf267SWarner Losh {
16886780e684SKyle Evans fdt32_t tmp = cpu_to_fdt32(val);
16896780e684SKyle Evans return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
169052baf267SWarner Losh }
169152baf267SWarner Losh
169252baf267SWarner Losh /**
169352baf267SWarner Losh * fdt_appendprop_u64 - append a 64-bit integer value to a property
169452baf267SWarner Losh * @fdt: pointer to the device tree blob
169552baf267SWarner Losh * @nodeoffset: offset of the node whose property to change
169652baf267SWarner Losh * @name: name of the property to change
169752baf267SWarner Losh * @val: 64-bit integer value to append to the property (native endian)
169852baf267SWarner Losh *
169952baf267SWarner Losh * fdt_appendprop_u64() appends the given 64-bit integer value
170052baf267SWarner Losh * (converting to big-endian if necessary) to the value of the named
170152baf267SWarner Losh * property in the given node, or creates a new property with that
170252baf267SWarner Losh * value if it does not already exist.
170352baf267SWarner Losh *
170452baf267SWarner Losh * This function may insert data into the blob, and will therefore
170552baf267SWarner Losh * change the offsets of some existing nodes.
170652baf267SWarner Losh *
170752baf267SWarner Losh * returns:
170852baf267SWarner Losh * 0, on success
170952baf267SWarner Losh * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
171052baf267SWarner Losh * contain the new property value
171152baf267SWarner Losh * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
171252baf267SWarner Losh * -FDT_ERR_BADLAYOUT,
171352baf267SWarner Losh * -FDT_ERR_BADMAGIC,
171452baf267SWarner Losh * -FDT_ERR_BADVERSION,
171552baf267SWarner Losh * -FDT_ERR_BADSTATE,
171652baf267SWarner Losh * -FDT_ERR_BADSTRUCTURE,
171752baf267SWarner Losh * -FDT_ERR_BADLAYOUT,
171852baf267SWarner Losh * -FDT_ERR_TRUNCATED, standard meanings
171952baf267SWarner Losh */
fdt_appendprop_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)172052baf267SWarner Losh static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
172152baf267SWarner Losh const char *name, uint64_t val)
172252baf267SWarner Losh {
17236780e684SKyle Evans fdt64_t tmp = cpu_to_fdt64(val);
17246780e684SKyle Evans return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
172552baf267SWarner Losh }
172652baf267SWarner Losh
172752baf267SWarner Losh /**
172852baf267SWarner Losh * fdt_appendprop_cell - append a single cell value to a property
172952baf267SWarner Losh *
173052baf267SWarner Losh * This is an alternative name for fdt_appendprop_u32()
173152baf267SWarner Losh */
fdt_appendprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)173252baf267SWarner Losh static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
173352baf267SWarner Losh const char *name, uint32_t val)
173452baf267SWarner Losh {
173552baf267SWarner Losh return fdt_appendprop_u32(fdt, nodeoffset, name, val);
173652baf267SWarner Losh }
173752baf267SWarner Losh
173852baf267SWarner Losh /**
173952baf267SWarner Losh * fdt_appendprop_string - append a string to a property
174052baf267SWarner Losh * @fdt: pointer to the device tree blob
174152baf267SWarner Losh * @nodeoffset: offset of the node whose property to change
174252baf267SWarner Losh * @name: name of the property to change
174352baf267SWarner Losh * @str: string value to append to the property
174452baf267SWarner Losh *
174552baf267SWarner Losh * fdt_appendprop_string() appends the given string to the value of
174652baf267SWarner Losh * the named property in the given node, or creates a new property
174752baf267SWarner Losh * with that value if it does not already exist.
174852baf267SWarner Losh *
174952baf267SWarner Losh * This function may insert data into the blob, and will therefore
175052baf267SWarner Losh * change the offsets of some existing nodes.
175152baf267SWarner Losh *
175252baf267SWarner Losh * returns:
175352baf267SWarner Losh * 0, on success
175452baf267SWarner Losh * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
175552baf267SWarner Losh * contain the new property value
175652baf267SWarner Losh * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
175752baf267SWarner Losh * -FDT_ERR_BADLAYOUT,
175852baf267SWarner Losh * -FDT_ERR_BADMAGIC,
175952baf267SWarner Losh * -FDT_ERR_BADVERSION,
176052baf267SWarner Losh * -FDT_ERR_BADSTATE,
176152baf267SWarner Losh * -FDT_ERR_BADSTRUCTURE,
176252baf267SWarner Losh * -FDT_ERR_BADLAYOUT,
176352baf267SWarner Losh * -FDT_ERR_TRUNCATED, standard meanings
176452baf267SWarner Losh */
176552baf267SWarner Losh #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
176652baf267SWarner Losh fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
176752baf267SWarner Losh
176852baf267SWarner Losh /**
176921fdc27aSRafal Jaworowski * fdt_delprop - delete a property
177021fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
177121fdc27aSRafal Jaworowski * @nodeoffset: offset of the node whose property to nop
177221fdc27aSRafal Jaworowski * @name: name of the property to nop
177321fdc27aSRafal Jaworowski *
177421fdc27aSRafal Jaworowski * fdt_del_property() will delete the given property.
177521fdc27aSRafal Jaworowski *
177621fdc27aSRafal Jaworowski * This function will delete data from the blob, and will therefore
177721fdc27aSRafal Jaworowski * change the offsets of some existing nodes.
177821fdc27aSRafal Jaworowski *
177921fdc27aSRafal Jaworowski * returns:
178021fdc27aSRafal Jaworowski * 0, on success
178121fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, node does not have the named property
178221fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
178321fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT,
178421fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
178521fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
178621fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
178721fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
178821fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
178921fdc27aSRafal Jaworowski */
179021fdc27aSRafal Jaworowski int fdt_delprop(void *fdt, int nodeoffset, const char *name);
179121fdc27aSRafal Jaworowski
179221fdc27aSRafal Jaworowski /**
179321fdc27aSRafal Jaworowski * fdt_add_subnode_namelen - creates a new node based on substring
179421fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
179521fdc27aSRafal Jaworowski * @parentoffset: structure block offset of a node
179621fdc27aSRafal Jaworowski * @name: name of the subnode to locate
179721fdc27aSRafal Jaworowski * @namelen: number of characters of name to consider
179821fdc27aSRafal Jaworowski *
179921fdc27aSRafal Jaworowski * Identical to fdt_add_subnode(), but use only the first namelen
180021fdc27aSRafal Jaworowski * characters of name as the name of the new node. This is useful for
180121fdc27aSRafal Jaworowski * creating subnodes based on a portion of a larger string, such as a
180221fdc27aSRafal Jaworowski * full path.
180321fdc27aSRafal Jaworowski */
18046780e684SKyle Evans #ifndef SWIG /* Not available in Python */
180521fdc27aSRafal Jaworowski int fdt_add_subnode_namelen(void *fdt, int parentoffset,
180621fdc27aSRafal Jaworowski const char *name, int namelen);
18076780e684SKyle Evans #endif
180821fdc27aSRafal Jaworowski
180921fdc27aSRafal Jaworowski /**
181021fdc27aSRafal Jaworowski * fdt_add_subnode - creates a new node
181121fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
181221fdc27aSRafal Jaworowski * @parentoffset: structure block offset of a node
181321fdc27aSRafal Jaworowski * @name: name of the subnode to locate
181421fdc27aSRafal Jaworowski *
181521fdc27aSRafal Jaworowski * fdt_add_subnode() creates a new node as a subnode of the node at
181621fdc27aSRafal Jaworowski * structure block offset parentoffset, with the given name (which
181721fdc27aSRafal Jaworowski * should include the unit address, if any).
181821fdc27aSRafal Jaworowski *
181921fdc27aSRafal Jaworowski * This function will insert data into the blob, and will therefore
182021fdc27aSRafal Jaworowski * change the offsets of some existing nodes.
182121fdc27aSRafal Jaworowski
182221fdc27aSRafal Jaworowski * returns:
18236780e684SKyle Evans * structure block offset of the created nodeequested subnode (>=0), on
18246780e684SKyle Evans * success
182521fdc27aSRafal Jaworowski * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
18266780e684SKyle Evans * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
18276780e684SKyle Evans * tag
182821fdc27aSRafal Jaworowski * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
182921fdc27aSRafal Jaworowski * the given name
183021fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE, if there is insufficient free space in the
183121fdc27aSRafal Jaworowski * blob to contain the new node
183221fdc27aSRafal Jaworowski * -FDT_ERR_NOSPACE
183321fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT
183421fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
183521fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
183621fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
183721fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
183821fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings.
183921fdc27aSRafal Jaworowski */
184021fdc27aSRafal Jaworowski int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
184121fdc27aSRafal Jaworowski
184221fdc27aSRafal Jaworowski /**
184321fdc27aSRafal Jaworowski * fdt_del_node - delete a node (subtree)
184421fdc27aSRafal Jaworowski * @fdt: pointer to the device tree blob
184521fdc27aSRafal Jaworowski * @nodeoffset: offset of the node to nop
184621fdc27aSRafal Jaworowski *
184721fdc27aSRafal Jaworowski * fdt_del_node() will remove the given node, including all its
184821fdc27aSRafal Jaworowski * subnodes if any, from the blob.
184921fdc27aSRafal Jaworowski *
185021fdc27aSRafal Jaworowski * This function will delete data from the blob, and will therefore
185121fdc27aSRafal Jaworowski * change the offsets of some existing nodes.
185221fdc27aSRafal Jaworowski *
185321fdc27aSRafal Jaworowski * returns:
185421fdc27aSRafal Jaworowski * 0, on success
185521fdc27aSRafal Jaworowski * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
185621fdc27aSRafal Jaworowski * -FDT_ERR_BADLAYOUT,
185721fdc27aSRafal Jaworowski * -FDT_ERR_BADMAGIC,
185821fdc27aSRafal Jaworowski * -FDT_ERR_BADVERSION,
185921fdc27aSRafal Jaworowski * -FDT_ERR_BADSTATE,
186021fdc27aSRafal Jaworowski * -FDT_ERR_BADSTRUCTURE,
186121fdc27aSRafal Jaworowski * -FDT_ERR_TRUNCATED, standard meanings
186221fdc27aSRafal Jaworowski */
186321fdc27aSRafal Jaworowski int fdt_del_node(void *fdt, int nodeoffset);
186421fdc27aSRafal Jaworowski
18656780e684SKyle Evans /**
18666780e684SKyle Evans * fdt_overlay_apply - Applies a DT overlay on a base DT
18676780e684SKyle Evans * @fdt: pointer to the base device tree blob
18686780e684SKyle Evans * @fdto: pointer to the device tree overlay blob
18696780e684SKyle Evans *
18706780e684SKyle Evans * fdt_overlay_apply() will apply the given device tree overlay on the
18716780e684SKyle Evans * given base device tree.
18726780e684SKyle Evans *
18736780e684SKyle Evans * Expect the base device tree to be modified, even if the function
18746780e684SKyle Evans * returns an error.
18756780e684SKyle Evans *
18766780e684SKyle Evans * returns:
18776780e684SKyle Evans * 0, on success
18786780e684SKyle Evans * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
18796780e684SKyle Evans * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
18806780e684SKyle Evans * properties in the base DT
18816780e684SKyle Evans * -FDT_ERR_BADPHANDLE,
18826780e684SKyle Evans * -FDT_ERR_BADOVERLAY,
18836780e684SKyle Evans * -FDT_ERR_NOPHANDLES,
18846780e684SKyle Evans * -FDT_ERR_INTERNAL,
18856780e684SKyle Evans * -FDT_ERR_BADLAYOUT,
18866780e684SKyle Evans * -FDT_ERR_BADMAGIC,
18876780e684SKyle Evans * -FDT_ERR_BADOFFSET,
18886780e684SKyle Evans * -FDT_ERR_BADPATH,
18896780e684SKyle Evans * -FDT_ERR_BADVERSION,
18906780e684SKyle Evans * -FDT_ERR_BADSTRUCTURE,
18916780e684SKyle Evans * -FDT_ERR_BADSTATE,
18926780e684SKyle Evans * -FDT_ERR_TRUNCATED, standard meanings
18936780e684SKyle Evans */
18946780e684SKyle Evans int fdt_overlay_apply(void *fdt, void *fdto);
18956780e684SKyle Evans
189621fdc27aSRafal Jaworowski /**********************************************************************/
189721fdc27aSRafal Jaworowski /* Debugging / informational functions */
189821fdc27aSRafal Jaworowski /**********************************************************************/
189921fdc27aSRafal Jaworowski
190021fdc27aSRafal Jaworowski const char *fdt_strerror(int errval);
190121fdc27aSRafal Jaworowski
19026780e684SKyle Evans #endif /* LIBFDT_H */
1903