1*b9ee18deSskrll /* $NetBSD: libfdt.h,v 1.1.1.3 2019/12/22 12:30:38 skrll Exp $ */
22fb928dbSskrll
3*b9ee18deSskrll /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
4*b9ee18deSskrll #ifndef LIBFDT_H
5*b9ee18deSskrll #define LIBFDT_H
67b5f0179Smacallan /*
77b5f0179Smacallan * libfdt - Flat Device Tree manipulation
87b5f0179Smacallan * Copyright (C) 2006 David Gibson, IBM Corporation.
97b5f0179Smacallan */
107b5f0179Smacallan
117b5f0179Smacallan #include <libfdt_env.h>
127b5f0179Smacallan #include <fdt.h>
137b5f0179Smacallan
14*b9ee18deSskrll #define FDT_FIRST_SUPPORTED_VERSION 0x02
157b5f0179Smacallan #define FDT_LAST_SUPPORTED_VERSION 0x11
167b5f0179Smacallan
177b5f0179Smacallan /* Error codes: informative error codes */
187b5f0179Smacallan #define FDT_ERR_NOTFOUND 1
197b5f0179Smacallan /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
207b5f0179Smacallan #define FDT_ERR_EXISTS 2
212fb928dbSskrll /* FDT_ERR_EXISTS: Attempted to create a node or property which
227b5f0179Smacallan * already exists */
237b5f0179Smacallan #define FDT_ERR_NOSPACE 3
247b5f0179Smacallan /* FDT_ERR_NOSPACE: Operation needed to expand the device
257b5f0179Smacallan * tree, but its buffer did not have sufficient space to
267b5f0179Smacallan * contain the expanded tree. Use fdt_open_into() to move the
277b5f0179Smacallan * device tree to a buffer with more space. */
287b5f0179Smacallan
297b5f0179Smacallan /* Error codes: codes for bad parameters */
307b5f0179Smacallan #define FDT_ERR_BADOFFSET 4
317b5f0179Smacallan /* FDT_ERR_BADOFFSET: Function was passed a structure block
327b5f0179Smacallan * offset which is out-of-bounds, or which points to an
337b5f0179Smacallan * unsuitable part of the structure for the operation. */
347b5f0179Smacallan #define FDT_ERR_BADPATH 5
357b5f0179Smacallan /* FDT_ERR_BADPATH: Function was passed a badly formatted path
367b5f0179Smacallan * (e.g. missing a leading / for a function which requires an
377b5f0179Smacallan * absolute path) */
387b5f0179Smacallan #define FDT_ERR_BADPHANDLE 6
392fb928dbSskrll /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
402fb928dbSskrll * This can be caused either by an invalid phandle property
412fb928dbSskrll * length, or the phandle value was either 0 or -1, which are
422fb928dbSskrll * not permitted. */
437b5f0179Smacallan #define FDT_ERR_BADSTATE 7
447b5f0179Smacallan /* FDT_ERR_BADSTATE: Function was passed an incomplete device
457b5f0179Smacallan * tree created by the sequential-write functions, which is
467b5f0179Smacallan * not sufficiently complete for the requested operation. */
477b5f0179Smacallan
487b5f0179Smacallan /* Error codes: codes for bad device tree blobs */
497b5f0179Smacallan #define FDT_ERR_TRUNCATED 8
50*b9ee18deSskrll /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly
51*b9ee18deSskrll * terminated (overflows, goes outside allowed bounds, or
52*b9ee18deSskrll * isn't properly terminated). */
537b5f0179Smacallan #define FDT_ERR_BADMAGIC 9
547b5f0179Smacallan /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
557b5f0179Smacallan * device tree at all - it is missing the flattened device
567b5f0179Smacallan * tree magic number. */
577b5f0179Smacallan #define FDT_ERR_BADVERSION 10
587b5f0179Smacallan /* FDT_ERR_BADVERSION: Given device tree has a version which
597b5f0179Smacallan * can't be handled by the requested operation. For
607b5f0179Smacallan * read-write functions, this may mean that fdt_open_into() is
617b5f0179Smacallan * required to convert the tree to the expected version. */
627b5f0179Smacallan #define FDT_ERR_BADSTRUCTURE 11
637b5f0179Smacallan /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
647b5f0179Smacallan * structure block or other serious error (e.g. misnested
657b5f0179Smacallan * nodes, or subnodes preceding properties). */
667b5f0179Smacallan #define FDT_ERR_BADLAYOUT 12
677b5f0179Smacallan /* FDT_ERR_BADLAYOUT: For read-write functions, the given
687b5f0179Smacallan * device tree has it's sub-blocks in an order that the
697b5f0179Smacallan * function can't handle (memory reserve map, then structure,
707b5f0179Smacallan * then strings). Use fdt_open_into() to reorganize the tree
717b5f0179Smacallan * into a form suitable for the read-write operations. */
727b5f0179Smacallan
737b5f0179Smacallan /* "Can't happen" error indicating a bug in libfdt */
747b5f0179Smacallan #define FDT_ERR_INTERNAL 13
757b5f0179Smacallan /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
767b5f0179Smacallan * Should never be returned, if it is, it indicates a bug in
777b5f0179Smacallan * libfdt itself. */
787b5f0179Smacallan
797b5f0179Smacallan /* Errors in device tree content */
807b5f0179Smacallan #define FDT_ERR_BADNCELLS 14
817b5f0179Smacallan /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
827b5f0179Smacallan * or similar property with a bad format or value */
837b5f0179Smacallan
847b5f0179Smacallan #define FDT_ERR_BADVALUE 15
857b5f0179Smacallan /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
867b5f0179Smacallan * value. For example: a property expected to contain a string list
877b5f0179Smacallan * is not NUL-terminated within the length of its value. */
887b5f0179Smacallan
892fb928dbSskrll #define FDT_ERR_BADOVERLAY 16
902fb928dbSskrll /* FDT_ERR_BADOVERLAY: The device tree overlay, while
912fb928dbSskrll * correctly structured, cannot be applied due to some
922fb928dbSskrll * unexpected or missing value, property or node. */
932fb928dbSskrll
942fb928dbSskrll #define FDT_ERR_NOPHANDLES 17
952fb928dbSskrll /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
962fb928dbSskrll * phandle available anymore without causing an overflow */
972fb928dbSskrll
98*b9ee18deSskrll #define FDT_ERR_BADFLAGS 18
99*b9ee18deSskrll /* FDT_ERR_BADFLAGS: The function was passed a flags field that
100*b9ee18deSskrll * contains invalid flags or an invalid combination of flags. */
101*b9ee18deSskrll
102*b9ee18deSskrll #define FDT_ERR_MAX 18
103*b9ee18deSskrll
104*b9ee18deSskrll /* constants */
105*b9ee18deSskrll #define FDT_MAX_PHANDLE 0xfffffffe
106*b9ee18deSskrll /* Valid values for phandles range from 1 to 2^32-2. */
1077b5f0179Smacallan
1087b5f0179Smacallan /**********************************************************************/
1097b5f0179Smacallan /* Low-level functions (you probably don't need these) */
1107b5f0179Smacallan /**********************************************************************/
1117b5f0179Smacallan
112*b9ee18deSskrll #ifndef SWIG /* This function is not useful in Python */
1137b5f0179Smacallan const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
114*b9ee18deSskrll #endif
fdt_offset_ptr_w(void * fdt,int offset,int checklen)1157b5f0179Smacallan static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
1167b5f0179Smacallan {
1177b5f0179Smacallan return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
1187b5f0179Smacallan }
1197b5f0179Smacallan
1207b5f0179Smacallan uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
1217b5f0179Smacallan
122*b9ee18deSskrll /*
123*b9ee18deSskrll * Alignment helpers:
124*b9ee18deSskrll * These helpers access words from a device tree blob. They're
125*b9ee18deSskrll * built to work even with unaligned pointers on platforms (ike
126*b9ee18deSskrll * ARM) that don't like unaligned loads and stores
127*b9ee18deSskrll */
128*b9ee18deSskrll
fdt32_ld(const fdt32_t * p)129*b9ee18deSskrll static inline uint32_t fdt32_ld(const fdt32_t *p)
130*b9ee18deSskrll {
131*b9ee18deSskrll const uint8_t *bp = (const uint8_t *)p;
132*b9ee18deSskrll
133*b9ee18deSskrll return ((uint32_t)bp[0] << 24)
134*b9ee18deSskrll | ((uint32_t)bp[1] << 16)
135*b9ee18deSskrll | ((uint32_t)bp[2] << 8)
136*b9ee18deSskrll | bp[3];
137*b9ee18deSskrll }
138*b9ee18deSskrll
fdt32_st(void * property,uint32_t value)139*b9ee18deSskrll static inline void fdt32_st(void *property, uint32_t value)
140*b9ee18deSskrll {
141*b9ee18deSskrll uint8_t *bp = property;
142*b9ee18deSskrll
143*b9ee18deSskrll bp[0] = value >> 24;
144*b9ee18deSskrll bp[1] = (value >> 16) & 0xff;
145*b9ee18deSskrll bp[2] = (value >> 8) & 0xff;
146*b9ee18deSskrll bp[3] = value & 0xff;
147*b9ee18deSskrll }
148*b9ee18deSskrll
fdt64_ld(const fdt64_t * p)149*b9ee18deSskrll static inline uint64_t fdt64_ld(const fdt64_t *p)
150*b9ee18deSskrll {
151*b9ee18deSskrll const uint8_t *bp = (const uint8_t *)p;
152*b9ee18deSskrll
153*b9ee18deSskrll return ((uint64_t)bp[0] << 56)
154*b9ee18deSskrll | ((uint64_t)bp[1] << 48)
155*b9ee18deSskrll | ((uint64_t)bp[2] << 40)
156*b9ee18deSskrll | ((uint64_t)bp[3] << 32)
157*b9ee18deSskrll | ((uint64_t)bp[4] << 24)
158*b9ee18deSskrll | ((uint64_t)bp[5] << 16)
159*b9ee18deSskrll | ((uint64_t)bp[6] << 8)
160*b9ee18deSskrll | bp[7];
161*b9ee18deSskrll }
162*b9ee18deSskrll
fdt64_st(void * property,uint64_t value)163*b9ee18deSskrll static inline void fdt64_st(void *property, uint64_t value)
164*b9ee18deSskrll {
165*b9ee18deSskrll uint8_t *bp = property;
166*b9ee18deSskrll
167*b9ee18deSskrll bp[0] = value >> 56;
168*b9ee18deSskrll bp[1] = (value >> 48) & 0xff;
169*b9ee18deSskrll bp[2] = (value >> 40) & 0xff;
170*b9ee18deSskrll bp[3] = (value >> 32) & 0xff;
171*b9ee18deSskrll bp[4] = (value >> 24) & 0xff;
172*b9ee18deSskrll bp[5] = (value >> 16) & 0xff;
173*b9ee18deSskrll bp[6] = (value >> 8) & 0xff;
174*b9ee18deSskrll bp[7] = value & 0xff;
175*b9ee18deSskrll }
176*b9ee18deSskrll
1777b5f0179Smacallan /**********************************************************************/
1787b5f0179Smacallan /* Traversal functions */
1797b5f0179Smacallan /**********************************************************************/
1807b5f0179Smacallan
1817b5f0179Smacallan int fdt_next_node(const void *fdt, int offset, int *depth);
1827b5f0179Smacallan
1837b5f0179Smacallan /**
1847b5f0179Smacallan * fdt_first_subnode() - get offset of first direct subnode
1857b5f0179Smacallan *
1867b5f0179Smacallan * @fdt: FDT blob
1877b5f0179Smacallan * @offset: Offset of node to check
1887b5f0179Smacallan * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
1897b5f0179Smacallan */
1907b5f0179Smacallan int fdt_first_subnode(const void *fdt, int offset);
1917b5f0179Smacallan
1927b5f0179Smacallan /**
1937b5f0179Smacallan * fdt_next_subnode() - get offset of next direct subnode
1947b5f0179Smacallan *
1957b5f0179Smacallan * After first calling fdt_first_subnode(), call this function repeatedly to
1967b5f0179Smacallan * get direct subnodes of a parent node.
1977b5f0179Smacallan *
1987b5f0179Smacallan * @fdt: FDT blob
1997b5f0179Smacallan * @offset: Offset of previous subnode
2007b5f0179Smacallan * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
2017b5f0179Smacallan * subnodes
2027b5f0179Smacallan */
2037b5f0179Smacallan int fdt_next_subnode(const void *fdt, int offset);
2047b5f0179Smacallan
2052fb928dbSskrll /**
2062fb928dbSskrll * fdt_for_each_subnode - iterate over all subnodes of a parent
2072fb928dbSskrll *
2082fb928dbSskrll * @node: child node (int, lvalue)
2092fb928dbSskrll * @fdt: FDT blob (const void *)
2102fb928dbSskrll * @parent: parent node (int)
2112fb928dbSskrll *
2122fb928dbSskrll * This is actually a wrapper around a for loop and would be used like so:
2132fb928dbSskrll *
2142fb928dbSskrll * fdt_for_each_subnode(node, fdt, parent) {
2152fb928dbSskrll * Use node
2162fb928dbSskrll * ...
2172fb928dbSskrll * }
2182fb928dbSskrll *
219*b9ee18deSskrll * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
2202fb928dbSskrll * Error handling
2212fb928dbSskrll * }
2222fb928dbSskrll *
2232fb928dbSskrll * Note that this is implemented as a macro and @node is used as
2242fb928dbSskrll * iterator in the loop. The parent variable be constant or even a
2252fb928dbSskrll * literal.
2262fb928dbSskrll *
2272fb928dbSskrll */
2282fb928dbSskrll #define fdt_for_each_subnode(node, fdt, parent) \
2292fb928dbSskrll for (node = fdt_first_subnode(fdt, parent); \
2302fb928dbSskrll node >= 0; \
2312fb928dbSskrll node = fdt_next_subnode(fdt, node))
2322fb928dbSskrll
2337b5f0179Smacallan /**********************************************************************/
2347b5f0179Smacallan /* General functions */
2357b5f0179Smacallan /**********************************************************************/
2367b5f0179Smacallan #define fdt_get_header(fdt, field) \
237*b9ee18deSskrll (fdt32_ld(&((const struct fdt_header *)(fdt))->field))
2387b5f0179Smacallan #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
2397b5f0179Smacallan #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
2407b5f0179Smacallan #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
2417b5f0179Smacallan #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
2427b5f0179Smacallan #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
2437b5f0179Smacallan #define fdt_version(fdt) (fdt_get_header(fdt, version))
2447b5f0179Smacallan #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
2457b5f0179Smacallan #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
2467b5f0179Smacallan #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
2477b5f0179Smacallan #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
2487b5f0179Smacallan
249*b9ee18deSskrll #define fdt_set_hdr_(name) \
2507b5f0179Smacallan static inline void fdt_set_##name(void *fdt, uint32_t val) \
2517b5f0179Smacallan { \
2527b5f0179Smacallan struct fdt_header *fdth = (struct fdt_header *)fdt; \
2537b5f0179Smacallan fdth->name = cpu_to_fdt32(val); \
2547b5f0179Smacallan }
255*b9ee18deSskrll fdt_set_hdr_(magic);
256*b9ee18deSskrll fdt_set_hdr_(totalsize);
257*b9ee18deSskrll fdt_set_hdr_(off_dt_struct);
258*b9ee18deSskrll fdt_set_hdr_(off_dt_strings);
259*b9ee18deSskrll fdt_set_hdr_(off_mem_rsvmap);
260*b9ee18deSskrll fdt_set_hdr_(version);
261*b9ee18deSskrll fdt_set_hdr_(last_comp_version);
262*b9ee18deSskrll fdt_set_hdr_(boot_cpuid_phys);
263*b9ee18deSskrll fdt_set_hdr_(size_dt_strings);
264*b9ee18deSskrll fdt_set_hdr_(size_dt_struct);
265*b9ee18deSskrll #undef fdt_set_hdr_
2667b5f0179Smacallan
2677b5f0179Smacallan /**
268*b9ee18deSskrll * fdt_header_size - return the size of the tree's header
269*b9ee18deSskrll * @fdt: pointer to a flattened device tree
270*b9ee18deSskrll */
271*b9ee18deSskrll size_t fdt_header_size_(uint32_t version);
fdt_header_size(const void * fdt)272*b9ee18deSskrll static inline size_t fdt_header_size(const void *fdt)
273*b9ee18deSskrll {
274*b9ee18deSskrll return fdt_header_size_(fdt_version(fdt));
275*b9ee18deSskrll }
276*b9ee18deSskrll
277*b9ee18deSskrll /**
278*b9ee18deSskrll * fdt_check_header - sanity check a device tree header
279*b9ee18deSskrll
2807b5f0179Smacallan * @fdt: pointer to data which might be a flattened device tree
2817b5f0179Smacallan *
2827b5f0179Smacallan * fdt_check_header() checks that the given buffer contains what
283*b9ee18deSskrll * appears to be a flattened device tree, and that the header contains
284*b9ee18deSskrll * valid information (to the extent that can be determined from the
285*b9ee18deSskrll * header alone).
2867b5f0179Smacallan *
2877b5f0179Smacallan * returns:
2887b5f0179Smacallan * 0, if the buffer appears to contain a valid device tree
2897b5f0179Smacallan * -FDT_ERR_BADMAGIC,
2907b5f0179Smacallan * -FDT_ERR_BADVERSION,
291*b9ee18deSskrll * -FDT_ERR_BADSTATE,
292*b9ee18deSskrll * -FDT_ERR_TRUNCATED, standard meanings, as above
2937b5f0179Smacallan */
2947b5f0179Smacallan int fdt_check_header(const void *fdt);
2957b5f0179Smacallan
2967b5f0179Smacallan /**
2977b5f0179Smacallan * fdt_move - move a device tree around in memory
2987b5f0179Smacallan * @fdt: pointer to the device tree to move
2997b5f0179Smacallan * @buf: pointer to memory where the device is to be moved
3007b5f0179Smacallan * @bufsize: size of the memory space at buf
3017b5f0179Smacallan *
3027b5f0179Smacallan * fdt_move() relocates, if possible, the device tree blob located at
3037b5f0179Smacallan * fdt to the buffer at buf of size bufsize. The buffer may overlap
3047b5f0179Smacallan * with the existing device tree blob at fdt. Therefore,
3057b5f0179Smacallan * fdt_move(fdt, fdt, fdt_totalsize(fdt))
3067b5f0179Smacallan * should always succeed.
3077b5f0179Smacallan *
3087b5f0179Smacallan * returns:
3097b5f0179Smacallan * 0, on success
3107b5f0179Smacallan * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
3117b5f0179Smacallan * -FDT_ERR_BADMAGIC,
3127b5f0179Smacallan * -FDT_ERR_BADVERSION,
3137b5f0179Smacallan * -FDT_ERR_BADSTATE, standard meanings
3147b5f0179Smacallan */
3157b5f0179Smacallan int fdt_move(const void *fdt, void *buf, int bufsize);
3167b5f0179Smacallan
3177b5f0179Smacallan /**********************************************************************/
3187b5f0179Smacallan /* Read-only functions */
3197b5f0179Smacallan /**********************************************************************/
3207b5f0179Smacallan
321*b9ee18deSskrll int fdt_check_full(const void *fdt, size_t bufsize);
322*b9ee18deSskrll
323*b9ee18deSskrll /**
324*b9ee18deSskrll * fdt_get_string - retrieve a string from the strings block of a device tree
325*b9ee18deSskrll * @fdt: pointer to the device tree blob
326*b9ee18deSskrll * @stroffset: offset of the string within the strings block (native endian)
327*b9ee18deSskrll * @lenp: optional pointer to return the string's length
328*b9ee18deSskrll *
329*b9ee18deSskrll * fdt_get_string() retrieves a pointer to a single string from the
330*b9ee18deSskrll * strings block of the device tree blob at fdt, and optionally also
331*b9ee18deSskrll * returns the string's length in *lenp.
332*b9ee18deSskrll *
333*b9ee18deSskrll * returns:
334*b9ee18deSskrll * a pointer to the string, on success
335*b9ee18deSskrll * NULL, if stroffset is out of bounds, or doesn't point to a valid string
336*b9ee18deSskrll */
337*b9ee18deSskrll const char *fdt_get_string(const void *fdt, int stroffset, int *lenp);
338*b9ee18deSskrll
3397b5f0179Smacallan /**
3407b5f0179Smacallan * fdt_string - retrieve a string from the strings block of a device tree
3417b5f0179Smacallan * @fdt: pointer to the device tree blob
3427b5f0179Smacallan * @stroffset: offset of the string within the strings block (native endian)
3437b5f0179Smacallan *
3447b5f0179Smacallan * fdt_string() retrieves a pointer to a single string from the
3457b5f0179Smacallan * strings block of the device tree blob at fdt.
3467b5f0179Smacallan *
3477b5f0179Smacallan * returns:
3487b5f0179Smacallan * a pointer to the string, on success
349*b9ee18deSskrll * NULL, if stroffset is out of bounds, or doesn't point to a valid string
3507b5f0179Smacallan */
3517b5f0179Smacallan const char *fdt_string(const void *fdt, int stroffset);
3527b5f0179Smacallan
3537b5f0179Smacallan /**
354*b9ee18deSskrll * fdt_find_max_phandle - find and return the highest phandle in a tree
355*b9ee18deSskrll * @fdt: pointer to the device tree blob
356*b9ee18deSskrll * @phandle: return location for the highest phandle value found in the tree
357*b9ee18deSskrll *
358*b9ee18deSskrll * fdt_find_max_phandle() finds the highest phandle value in the given device
359*b9ee18deSskrll * tree. The value returned in @phandle is only valid if the function returns
360*b9ee18deSskrll * success.
361*b9ee18deSskrll *
362*b9ee18deSskrll * returns:
363*b9ee18deSskrll * 0 on success or a negative error code on failure
364*b9ee18deSskrll */
365*b9ee18deSskrll int fdt_find_max_phandle(const void *fdt, uint32_t *phandle);
366*b9ee18deSskrll
367*b9ee18deSskrll /**
3682fb928dbSskrll * fdt_get_max_phandle - retrieves the highest phandle in a tree
3692fb928dbSskrll * @fdt: pointer to the device tree blob
3702fb928dbSskrll *
3712fb928dbSskrll * fdt_get_max_phandle retrieves the highest phandle in the given
3722fb928dbSskrll * device tree. This will ignore badly formatted phandles, or phandles
3732fb928dbSskrll * with a value of 0 or -1.
3742fb928dbSskrll *
375*b9ee18deSskrll * This function is deprecated in favour of fdt_find_max_phandle().
376*b9ee18deSskrll *
3772fb928dbSskrll * returns:
3782fb928dbSskrll * the highest phandle on success
3792fb928dbSskrll * 0, if no phandle was found in the device tree
3802fb928dbSskrll * -1, if an error occurred
3812fb928dbSskrll */
fdt_get_max_phandle(const void * fdt)382*b9ee18deSskrll static inline uint32_t fdt_get_max_phandle(const void *fdt)
383*b9ee18deSskrll {
384*b9ee18deSskrll uint32_t phandle;
385*b9ee18deSskrll int err;
386*b9ee18deSskrll
387*b9ee18deSskrll err = fdt_find_max_phandle(fdt, &phandle);
388*b9ee18deSskrll if (err < 0)
389*b9ee18deSskrll return (uint32_t)-1;
390*b9ee18deSskrll
391*b9ee18deSskrll return phandle;
392*b9ee18deSskrll }
393*b9ee18deSskrll
394*b9ee18deSskrll /**
395*b9ee18deSskrll * fdt_generate_phandle - return a new, unused phandle for a device tree blob
396*b9ee18deSskrll * @fdt: pointer to the device tree blob
397*b9ee18deSskrll * @phandle: return location for the new phandle
398*b9ee18deSskrll *
399*b9ee18deSskrll * Walks the device tree blob and looks for the highest phandle value. On
400*b9ee18deSskrll * success, the new, unused phandle value (one higher than the previously
401*b9ee18deSskrll * highest phandle value in the device tree blob) will be returned in the
402*b9ee18deSskrll * @phandle parameter.
403*b9ee18deSskrll *
404*b9ee18deSskrll * Returns:
405*b9ee18deSskrll * 0 on success or a negative error-code on failure
406*b9ee18deSskrll */
407*b9ee18deSskrll int fdt_generate_phandle(const void *fdt, uint32_t *phandle);
4082fb928dbSskrll
4092fb928dbSskrll /**
4107b5f0179Smacallan * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
4117b5f0179Smacallan * @fdt: pointer to the device tree blob
4127b5f0179Smacallan *
4137b5f0179Smacallan * Returns the number of entries in the device tree blob's memory
4147b5f0179Smacallan * reservation map. This does not include the terminating 0,0 entry
4157b5f0179Smacallan * or any other (0,0) entries reserved for expansion.
4167b5f0179Smacallan *
4177b5f0179Smacallan * returns:
4187b5f0179Smacallan * the number of entries
4197b5f0179Smacallan */
4207b5f0179Smacallan int fdt_num_mem_rsv(const void *fdt);
4217b5f0179Smacallan
4227b5f0179Smacallan /**
4237b5f0179Smacallan * fdt_get_mem_rsv - retrieve one memory reserve map entry
4247b5f0179Smacallan * @fdt: pointer to the device tree blob
4257b5f0179Smacallan * @address, @size: pointers to 64-bit variables
4267b5f0179Smacallan *
4277b5f0179Smacallan * On success, *address and *size will contain the address and size of
4287b5f0179Smacallan * the n-th reserve map entry from the device tree blob, in
4297b5f0179Smacallan * native-endian format.
4307b5f0179Smacallan *
4317b5f0179Smacallan * returns:
4327b5f0179Smacallan * 0, on success
4337b5f0179Smacallan * -FDT_ERR_BADMAGIC,
4347b5f0179Smacallan * -FDT_ERR_BADVERSION,
4357b5f0179Smacallan * -FDT_ERR_BADSTATE, standard meanings
4367b5f0179Smacallan */
4377b5f0179Smacallan int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
4387b5f0179Smacallan
4397b5f0179Smacallan /**
4407b5f0179Smacallan * fdt_subnode_offset_namelen - find a subnode based on substring
4417b5f0179Smacallan * @fdt: pointer to the device tree blob
4427b5f0179Smacallan * @parentoffset: structure block offset of a node
4437b5f0179Smacallan * @name: name of the subnode to locate
4447b5f0179Smacallan * @namelen: number of characters of name to consider
4457b5f0179Smacallan *
4467b5f0179Smacallan * Identical to fdt_subnode_offset(), but only examine the first
4477b5f0179Smacallan * namelen characters of name for matching the subnode name. This is
4487b5f0179Smacallan * useful for finding subnodes based on a portion of a larger string,
4497b5f0179Smacallan * such as a full path.
4507b5f0179Smacallan */
451*b9ee18deSskrll #ifndef SWIG /* Not available in Python */
4527b5f0179Smacallan int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
4537b5f0179Smacallan const char *name, int namelen);
454*b9ee18deSskrll #endif
4557b5f0179Smacallan /**
4567b5f0179Smacallan * fdt_subnode_offset - find a subnode of a given node
4577b5f0179Smacallan * @fdt: pointer to the device tree blob
4587b5f0179Smacallan * @parentoffset: structure block offset of a node
4597b5f0179Smacallan * @name: name of the subnode to locate
4607b5f0179Smacallan *
4617b5f0179Smacallan * fdt_subnode_offset() finds a subnode of the node at structure block
4627b5f0179Smacallan * offset parentoffset with the given name. name may include a unit
4637b5f0179Smacallan * address, in which case fdt_subnode_offset() will find the subnode
4647b5f0179Smacallan * with that unit address, or the unit address may be omitted, in
4657b5f0179Smacallan * which case fdt_subnode_offset() will find an arbitrary subnode
4667b5f0179Smacallan * whose name excluding unit address matches the given name.
4677b5f0179Smacallan *
4687b5f0179Smacallan * returns:
4697b5f0179Smacallan * structure block offset of the requested subnode (>=0), on success
4707b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
4712fb928dbSskrll * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
4722fb928dbSskrll * tag
4737b5f0179Smacallan * -FDT_ERR_BADMAGIC,
4747b5f0179Smacallan * -FDT_ERR_BADVERSION,
4757b5f0179Smacallan * -FDT_ERR_BADSTATE,
4767b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
4777b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings.
4787b5f0179Smacallan */
4797b5f0179Smacallan int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
4807b5f0179Smacallan
4817b5f0179Smacallan /**
4827b5f0179Smacallan * fdt_path_offset_namelen - find a tree node by its full path
4837b5f0179Smacallan * @fdt: pointer to the device tree blob
4847b5f0179Smacallan * @path: full path of the node to locate
4857b5f0179Smacallan * @namelen: number of characters of path to consider
4867b5f0179Smacallan *
4877b5f0179Smacallan * Identical to fdt_path_offset(), but only consider the first namelen
4887b5f0179Smacallan * characters of path as the path name.
4897b5f0179Smacallan */
490*b9ee18deSskrll #ifndef SWIG /* Not available in Python */
4917b5f0179Smacallan int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
492*b9ee18deSskrll #endif
4937b5f0179Smacallan
4947b5f0179Smacallan /**
4957b5f0179Smacallan * fdt_path_offset - find a tree node by its full path
4967b5f0179Smacallan * @fdt: pointer to the device tree blob
4977b5f0179Smacallan * @path: full path of the node to locate
4987b5f0179Smacallan *
4997b5f0179Smacallan * fdt_path_offset() finds a node of a given path in the device tree.
5007b5f0179Smacallan * Each path component may omit the unit address portion, but the
5017b5f0179Smacallan * results of this are undefined if any such path component is
5027b5f0179Smacallan * ambiguous (that is if there are multiple nodes at the relevant
5037b5f0179Smacallan * level matching the given component, differentiated only by unit
5047b5f0179Smacallan * address).
5057b5f0179Smacallan *
5067b5f0179Smacallan * returns:
5072fb928dbSskrll * structure block offset of the node with the requested path (>=0), on
5082fb928dbSskrll * success
5097b5f0179Smacallan * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
5107b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the requested node does not exist
5117b5f0179Smacallan * -FDT_ERR_BADMAGIC,
5127b5f0179Smacallan * -FDT_ERR_BADVERSION,
5137b5f0179Smacallan * -FDT_ERR_BADSTATE,
5147b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
5157b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings.
5167b5f0179Smacallan */
5177b5f0179Smacallan int fdt_path_offset(const void *fdt, const char *path);
5187b5f0179Smacallan
5197b5f0179Smacallan /**
5207b5f0179Smacallan * fdt_get_name - retrieve the name of a given node
5217b5f0179Smacallan * @fdt: pointer to the device tree blob
5227b5f0179Smacallan * @nodeoffset: structure block offset of the starting node
5237b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
5247b5f0179Smacallan *
5257b5f0179Smacallan * fdt_get_name() retrieves the name (including unit address) of the
5267b5f0179Smacallan * device tree node at structure block offset nodeoffset. If lenp is
5277b5f0179Smacallan * non-NULL, the length of this name is also returned, in the integer
5287b5f0179Smacallan * pointed to by lenp.
5297b5f0179Smacallan *
5307b5f0179Smacallan * returns:
5317b5f0179Smacallan * pointer to the node's name, on success
5322fb928dbSskrll * If lenp is non-NULL, *lenp contains the length of that name
5332fb928dbSskrll * (>=0)
5347b5f0179Smacallan * NULL, on error
5357b5f0179Smacallan * if lenp is non-NULL *lenp contains an error code (<0):
5362fb928dbSskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
5372fb928dbSskrll * tag
5387b5f0179Smacallan * -FDT_ERR_BADMAGIC,
5397b5f0179Smacallan * -FDT_ERR_BADVERSION,
5407b5f0179Smacallan * -FDT_ERR_BADSTATE, standard meanings
5417b5f0179Smacallan */
5427b5f0179Smacallan const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
5437b5f0179Smacallan
5447b5f0179Smacallan /**
5457b5f0179Smacallan * fdt_first_property_offset - find the offset of a node's first property
5467b5f0179Smacallan * @fdt: pointer to the device tree blob
5477b5f0179Smacallan * @nodeoffset: structure block offset of a node
5487b5f0179Smacallan *
5497b5f0179Smacallan * fdt_first_property_offset() finds the first property of the node at
5507b5f0179Smacallan * the given structure block offset.
5517b5f0179Smacallan *
5527b5f0179Smacallan * returns:
5537b5f0179Smacallan * structure block offset of the property (>=0), on success
5547b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the requested node has no properties
5557b5f0179Smacallan * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
5567b5f0179Smacallan * -FDT_ERR_BADMAGIC,
5577b5f0179Smacallan * -FDT_ERR_BADVERSION,
5587b5f0179Smacallan * -FDT_ERR_BADSTATE,
5597b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
5607b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings.
5617b5f0179Smacallan */
5627b5f0179Smacallan int fdt_first_property_offset(const void *fdt, int nodeoffset);
5637b5f0179Smacallan
5647b5f0179Smacallan /**
5657b5f0179Smacallan * fdt_next_property_offset - step through a node's properties
5667b5f0179Smacallan * @fdt: pointer to the device tree blob
5677b5f0179Smacallan * @offset: structure block offset of a property
5687b5f0179Smacallan *
5697b5f0179Smacallan * fdt_next_property_offset() finds the property immediately after the
5707b5f0179Smacallan * one at the given structure block offset. This will be a property
5717b5f0179Smacallan * of the same node as the given property.
5727b5f0179Smacallan *
5737b5f0179Smacallan * returns:
5747b5f0179Smacallan * structure block offset of the next property (>=0), on success
5757b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the given property is the last in its node
5767b5f0179Smacallan * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
5777b5f0179Smacallan * -FDT_ERR_BADMAGIC,
5787b5f0179Smacallan * -FDT_ERR_BADVERSION,
5797b5f0179Smacallan * -FDT_ERR_BADSTATE,
5807b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
5817b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings.
5827b5f0179Smacallan */
5837b5f0179Smacallan int fdt_next_property_offset(const void *fdt, int offset);
5847b5f0179Smacallan
5857b5f0179Smacallan /**
5862fb928dbSskrll * fdt_for_each_property_offset - iterate over all properties of a node
5872fb928dbSskrll *
5882fb928dbSskrll * @property_offset: property offset (int, lvalue)
5892fb928dbSskrll * @fdt: FDT blob (const void *)
5902fb928dbSskrll * @node: node offset (int)
5912fb928dbSskrll *
5922fb928dbSskrll * This is actually a wrapper around a for loop and would be used like so:
5932fb928dbSskrll *
5942fb928dbSskrll * fdt_for_each_property_offset(property, fdt, node) {
5952fb928dbSskrll * Use property
5962fb928dbSskrll * ...
5972fb928dbSskrll * }
5982fb928dbSskrll *
599*b9ee18deSskrll * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) {
6002fb928dbSskrll * Error handling
6012fb928dbSskrll * }
6022fb928dbSskrll *
6032fb928dbSskrll * Note that this is implemented as a macro and property is used as
6042fb928dbSskrll * iterator in the loop. The node variable can be constant or even a
6052fb928dbSskrll * literal.
6062fb928dbSskrll */
6072fb928dbSskrll #define fdt_for_each_property_offset(property, fdt, node) \
6082fb928dbSskrll for (property = fdt_first_property_offset(fdt, node); \
6092fb928dbSskrll property >= 0; \
6102fb928dbSskrll property = fdt_next_property_offset(fdt, property))
6112fb928dbSskrll
6122fb928dbSskrll /**
6137b5f0179Smacallan * fdt_get_property_by_offset - retrieve the property at a given offset
6147b5f0179Smacallan * @fdt: pointer to the device tree blob
6157b5f0179Smacallan * @offset: offset of the property to retrieve
6167b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
6177b5f0179Smacallan *
6187b5f0179Smacallan * fdt_get_property_by_offset() retrieves a pointer to the
6197b5f0179Smacallan * fdt_property structure within the device tree blob at the given
6207b5f0179Smacallan * offset. If lenp is non-NULL, the length of the property value is
6217b5f0179Smacallan * also returned, in the integer pointed to by lenp.
6227b5f0179Smacallan *
623*b9ee18deSskrll * Note that this code only works on device tree versions >= 16. fdt_getprop()
624*b9ee18deSskrll * works on all versions.
625*b9ee18deSskrll *
6267b5f0179Smacallan * returns:
6277b5f0179Smacallan * pointer to the structure representing the property
6287b5f0179Smacallan * if lenp is non-NULL, *lenp contains the length of the property
6297b5f0179Smacallan * value (>=0)
6307b5f0179Smacallan * NULL, on error
6317b5f0179Smacallan * if lenp is non-NULL, *lenp contains an error code (<0):
6327b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
6337b5f0179Smacallan * -FDT_ERR_BADMAGIC,
6347b5f0179Smacallan * -FDT_ERR_BADVERSION,
6357b5f0179Smacallan * -FDT_ERR_BADSTATE,
6367b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
6377b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
6387b5f0179Smacallan */
6397b5f0179Smacallan const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
6407b5f0179Smacallan int offset,
6417b5f0179Smacallan int *lenp);
6427b5f0179Smacallan
6437b5f0179Smacallan /**
6447b5f0179Smacallan * fdt_get_property_namelen - find a property based on substring
6457b5f0179Smacallan * @fdt: pointer to the device tree blob
6467b5f0179Smacallan * @nodeoffset: offset of the node whose property to find
6477b5f0179Smacallan * @name: name of the property to find
6487b5f0179Smacallan * @namelen: number of characters of name to consider
6497b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
6507b5f0179Smacallan *
6517b5f0179Smacallan * Identical to fdt_get_property(), but only examine the first namelen
6527b5f0179Smacallan * characters of name for matching the property name.
6537b5f0179Smacallan */
654*b9ee18deSskrll #ifndef SWIG /* Not available in Python */
6557b5f0179Smacallan const struct fdt_property *fdt_get_property_namelen(const void *fdt,
6567b5f0179Smacallan int nodeoffset,
6577b5f0179Smacallan const char *name,
6587b5f0179Smacallan int namelen, int *lenp);
659*b9ee18deSskrll #endif
6607b5f0179Smacallan
6617b5f0179Smacallan /**
6627b5f0179Smacallan * fdt_get_property - find a given property in a given node
6637b5f0179Smacallan * @fdt: pointer to the device tree blob
6647b5f0179Smacallan * @nodeoffset: offset of the node whose property to find
6657b5f0179Smacallan * @name: name of the property to find
6667b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
6677b5f0179Smacallan *
6687b5f0179Smacallan * fdt_get_property() retrieves a pointer to the fdt_property
6697b5f0179Smacallan * structure within the device tree blob corresponding to the property
6707b5f0179Smacallan * named 'name' of the node at offset nodeoffset. If lenp is
6717b5f0179Smacallan * non-NULL, the length of the property value is also returned, in the
6727b5f0179Smacallan * integer pointed to by lenp.
6737b5f0179Smacallan *
6747b5f0179Smacallan * returns:
6757b5f0179Smacallan * pointer to the structure representing the property
6767b5f0179Smacallan * if lenp is non-NULL, *lenp contains the length of the property
6777b5f0179Smacallan * value (>=0)
6787b5f0179Smacallan * NULL, on error
6797b5f0179Smacallan * if lenp is non-NULL, *lenp contains an error code (<0):
6807b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have named property
6812fb928dbSskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
6822fb928dbSskrll * tag
6837b5f0179Smacallan * -FDT_ERR_BADMAGIC,
6847b5f0179Smacallan * -FDT_ERR_BADVERSION,
6857b5f0179Smacallan * -FDT_ERR_BADSTATE,
6867b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
6877b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
6887b5f0179Smacallan */
6897b5f0179Smacallan const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
6907b5f0179Smacallan const char *name, int *lenp);
fdt_get_property_w(void * fdt,int nodeoffset,const char * name,int * lenp)6917b5f0179Smacallan static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
6927b5f0179Smacallan const char *name,
6937b5f0179Smacallan int *lenp)
6947b5f0179Smacallan {
6957b5f0179Smacallan return (struct fdt_property *)(uintptr_t)
6967b5f0179Smacallan fdt_get_property(fdt, nodeoffset, name, lenp);
6977b5f0179Smacallan }
6987b5f0179Smacallan
6997b5f0179Smacallan /**
7007b5f0179Smacallan * fdt_getprop_by_offset - retrieve the value of a property at a given offset
7017b5f0179Smacallan * @fdt: pointer to the device tree blob
702*b9ee18deSskrll * @offset: offset of the property to read
7037b5f0179Smacallan * @namep: pointer to a string variable (will be overwritten) or NULL
7047b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
7057b5f0179Smacallan *
7067b5f0179Smacallan * fdt_getprop_by_offset() retrieves a pointer to the value of the
7077b5f0179Smacallan * property at structure block offset 'offset' (this will be a pointer
7087b5f0179Smacallan * to within the device blob itself, not a copy of the value). If
7097b5f0179Smacallan * lenp is non-NULL, the length of the property value is also
7107b5f0179Smacallan * returned, in the integer pointed to by lenp. If namep is non-NULL,
7117b5f0179Smacallan * the property's namne will also be returned in the char * pointed to
7127b5f0179Smacallan * by namep (this will be a pointer to within the device tree's string
7137b5f0179Smacallan * block, not a new copy of the name).
7147b5f0179Smacallan *
7157b5f0179Smacallan * returns:
7167b5f0179Smacallan * pointer to the property's value
7177b5f0179Smacallan * if lenp is non-NULL, *lenp contains the length of the property
7187b5f0179Smacallan * value (>=0)
7197b5f0179Smacallan * if namep is non-NULL *namep contiains a pointer to the property
7207b5f0179Smacallan * name.
7217b5f0179Smacallan * NULL, on error
7227b5f0179Smacallan * if lenp is non-NULL, *lenp contains an error code (<0):
7237b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
7247b5f0179Smacallan * -FDT_ERR_BADMAGIC,
7257b5f0179Smacallan * -FDT_ERR_BADVERSION,
7267b5f0179Smacallan * -FDT_ERR_BADSTATE,
7277b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
7287b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
7297b5f0179Smacallan */
730*b9ee18deSskrll #ifndef SWIG /* This function is not useful in Python */
7317b5f0179Smacallan const void *fdt_getprop_by_offset(const void *fdt, int offset,
7327b5f0179Smacallan const char **namep, int *lenp);
733*b9ee18deSskrll #endif
7347b5f0179Smacallan
7357b5f0179Smacallan /**
7367b5f0179Smacallan * fdt_getprop_namelen - get property value based on substring
7377b5f0179Smacallan * @fdt: pointer to the device tree blob
7387b5f0179Smacallan * @nodeoffset: offset of the node whose property to find
7397b5f0179Smacallan * @name: name of the property to find
7407b5f0179Smacallan * @namelen: number of characters of name to consider
7417b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
7427b5f0179Smacallan *
7437b5f0179Smacallan * Identical to fdt_getprop(), but only examine the first namelen
7447b5f0179Smacallan * characters of name for matching the property name.
7457b5f0179Smacallan */
746*b9ee18deSskrll #ifndef SWIG /* Not available in Python */
7477b5f0179Smacallan const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
7487b5f0179Smacallan const char *name, int namelen, int *lenp);
fdt_getprop_namelen_w(void * fdt,int nodeoffset,const char * name,int namelen,int * lenp)7492fb928dbSskrll static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
7502fb928dbSskrll const char *name, int namelen,
7512fb928dbSskrll int *lenp)
7522fb928dbSskrll {
7532fb928dbSskrll return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
7542fb928dbSskrll namelen, lenp);
7552fb928dbSskrll }
756*b9ee18deSskrll #endif
7577b5f0179Smacallan
7587b5f0179Smacallan /**
7597b5f0179Smacallan * fdt_getprop - retrieve the value of a given property
7607b5f0179Smacallan * @fdt: pointer to the device tree blob
7617b5f0179Smacallan * @nodeoffset: offset of the node whose property to find
7627b5f0179Smacallan * @name: name of the property to find
7637b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
7647b5f0179Smacallan *
7657b5f0179Smacallan * fdt_getprop() retrieves a pointer to the value of the property
7667b5f0179Smacallan * named 'name' of the node at offset nodeoffset (this will be a
7677b5f0179Smacallan * pointer to within the device blob itself, not a copy of the value).
7687b5f0179Smacallan * If lenp is non-NULL, the length of the property value is also
7697b5f0179Smacallan * returned, in the integer pointed to by lenp.
7707b5f0179Smacallan *
7717b5f0179Smacallan * returns:
7727b5f0179Smacallan * pointer to the property's value
7737b5f0179Smacallan * if lenp is non-NULL, *lenp contains the length of the property
7747b5f0179Smacallan * value (>=0)
7757b5f0179Smacallan * NULL, on error
7767b5f0179Smacallan * if lenp is non-NULL, *lenp contains an error code (<0):
7777b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have named property
7782fb928dbSskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
7792fb928dbSskrll * tag
7807b5f0179Smacallan * -FDT_ERR_BADMAGIC,
7817b5f0179Smacallan * -FDT_ERR_BADVERSION,
7827b5f0179Smacallan * -FDT_ERR_BADSTATE,
7837b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
7847b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
7857b5f0179Smacallan */
7867b5f0179Smacallan const void *fdt_getprop(const void *fdt, int nodeoffset,
7877b5f0179Smacallan const char *name, int *lenp);
fdt_getprop_w(void * fdt,int nodeoffset,const char * name,int * lenp)7887b5f0179Smacallan static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
7897b5f0179Smacallan const char *name, int *lenp)
7907b5f0179Smacallan {
7917b5f0179Smacallan return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
7927b5f0179Smacallan }
7937b5f0179Smacallan
7947b5f0179Smacallan /**
7957b5f0179Smacallan * fdt_get_phandle - retrieve the phandle of a given node
7967b5f0179Smacallan * @fdt: pointer to the device tree blob
7977b5f0179Smacallan * @nodeoffset: structure block offset of the node
7987b5f0179Smacallan *
7997b5f0179Smacallan * fdt_get_phandle() retrieves the phandle of the device tree node at
8007b5f0179Smacallan * structure block offset nodeoffset.
8017b5f0179Smacallan *
8027b5f0179Smacallan * returns:
8037b5f0179Smacallan * the phandle of the node at nodeoffset, on success (!= 0, != -1)
8047b5f0179Smacallan * 0, if the node has no phandle, or another error occurs
8057b5f0179Smacallan */
8067b5f0179Smacallan uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
8077b5f0179Smacallan
8087b5f0179Smacallan /**
8097b5f0179Smacallan * fdt_get_alias_namelen - get alias based on substring
8107b5f0179Smacallan * @fdt: pointer to the device tree blob
8117b5f0179Smacallan * @name: name of the alias th look up
8127b5f0179Smacallan * @namelen: number of characters of name to consider
8137b5f0179Smacallan *
8147b5f0179Smacallan * Identical to fdt_get_alias(), but only examine the first namelen
8157b5f0179Smacallan * characters of name for matching the alias name.
8167b5f0179Smacallan */
817*b9ee18deSskrll #ifndef SWIG /* Not available in Python */
8187b5f0179Smacallan const char *fdt_get_alias_namelen(const void *fdt,
8197b5f0179Smacallan const char *name, int namelen);
820*b9ee18deSskrll #endif
8217b5f0179Smacallan
8227b5f0179Smacallan /**
8232fb928dbSskrll * fdt_get_alias - retrieve the path referenced by a given alias
8247b5f0179Smacallan * @fdt: pointer to the device tree blob
8257b5f0179Smacallan * @name: name of the alias th look up
8267b5f0179Smacallan *
8277b5f0179Smacallan * fdt_get_alias() retrieves the value of a given alias. That is, the
8287b5f0179Smacallan * value of the property named 'name' in the node /aliases.
8297b5f0179Smacallan *
8307b5f0179Smacallan * returns:
8317b5f0179Smacallan * a pointer to the expansion of the alias named 'name', if it exists
8327b5f0179Smacallan * NULL, if the given alias or the /aliases node does not exist
8337b5f0179Smacallan */
8347b5f0179Smacallan const char *fdt_get_alias(const void *fdt, const char *name);
8357b5f0179Smacallan
8367b5f0179Smacallan /**
8377b5f0179Smacallan * fdt_get_path - determine the full path of a node
8387b5f0179Smacallan * @fdt: pointer to the device tree blob
8397b5f0179Smacallan * @nodeoffset: offset of the node whose path to find
8407b5f0179Smacallan * @buf: character buffer to contain the returned path (will be overwritten)
8417b5f0179Smacallan * @buflen: size of the character buffer at buf
8427b5f0179Smacallan *
8437b5f0179Smacallan * fdt_get_path() computes the full path of the node at offset
8447b5f0179Smacallan * nodeoffset, and records that path in the buffer at buf.
8457b5f0179Smacallan *
8467b5f0179Smacallan * NOTE: This function is expensive, as it must scan the device tree
8477b5f0179Smacallan * structure from the start to nodeoffset.
8487b5f0179Smacallan *
8497b5f0179Smacallan * returns:
8507b5f0179Smacallan * 0, on success
8517b5f0179Smacallan * buf contains the absolute path of the node at
8527b5f0179Smacallan * nodeoffset, as a NUL-terminated string.
8537b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
8547b5f0179Smacallan * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
8557b5f0179Smacallan * characters and will not fit in the given buffer.
8567b5f0179Smacallan * -FDT_ERR_BADMAGIC,
8577b5f0179Smacallan * -FDT_ERR_BADVERSION,
8587b5f0179Smacallan * -FDT_ERR_BADSTATE,
8597b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
8607b5f0179Smacallan */
8617b5f0179Smacallan int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
8627b5f0179Smacallan
8637b5f0179Smacallan /**
8647b5f0179Smacallan * fdt_supernode_atdepth_offset - find a specific ancestor of a node
8657b5f0179Smacallan * @fdt: pointer to the device tree blob
8667b5f0179Smacallan * @nodeoffset: offset of the node whose parent to find
8677b5f0179Smacallan * @supernodedepth: depth of the ancestor to find
8687b5f0179Smacallan * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
8697b5f0179Smacallan *
8707b5f0179Smacallan * fdt_supernode_atdepth_offset() finds an ancestor of the given node
8717b5f0179Smacallan * at a specific depth from the root (where the root itself has depth
8727b5f0179Smacallan * 0, its immediate subnodes depth 1 and so forth). So
8737b5f0179Smacallan * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
8747b5f0179Smacallan * will always return 0, the offset of the root node. If the node at
8757b5f0179Smacallan * nodeoffset has depth D, then:
8767b5f0179Smacallan * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
8777b5f0179Smacallan * will return nodeoffset itself.
8787b5f0179Smacallan *
8797b5f0179Smacallan * NOTE: This function is expensive, as it must scan the device tree
8807b5f0179Smacallan * structure from the start to nodeoffset.
8817b5f0179Smacallan *
8827b5f0179Smacallan * returns:
8837b5f0179Smacallan * structure block offset of the node at node offset's ancestor
8847b5f0179Smacallan * of depth supernodedepth (>=0), on success
8857b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
8862fb928dbSskrll * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
8872fb928dbSskrll * nodeoffset
8887b5f0179Smacallan * -FDT_ERR_BADMAGIC,
8897b5f0179Smacallan * -FDT_ERR_BADVERSION,
8907b5f0179Smacallan * -FDT_ERR_BADSTATE,
8917b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
8927b5f0179Smacallan */
8937b5f0179Smacallan int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
8947b5f0179Smacallan int supernodedepth, int *nodedepth);
8957b5f0179Smacallan
8967b5f0179Smacallan /**
8977b5f0179Smacallan * fdt_node_depth - find the depth of a given node
8987b5f0179Smacallan * @fdt: pointer to the device tree blob
8997b5f0179Smacallan * @nodeoffset: offset of the node whose parent to find
9007b5f0179Smacallan *
9017b5f0179Smacallan * fdt_node_depth() finds the depth of a given node. The root node
9027b5f0179Smacallan * has depth 0, its immediate subnodes depth 1 and so forth.
9037b5f0179Smacallan *
9047b5f0179Smacallan * NOTE: This function is expensive, as it must scan the device tree
9057b5f0179Smacallan * structure from the start to nodeoffset.
9067b5f0179Smacallan *
9077b5f0179Smacallan * returns:
9087b5f0179Smacallan * depth of the node at nodeoffset (>=0), on success
9097b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
9107b5f0179Smacallan * -FDT_ERR_BADMAGIC,
9117b5f0179Smacallan * -FDT_ERR_BADVERSION,
9127b5f0179Smacallan * -FDT_ERR_BADSTATE,
9137b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
9147b5f0179Smacallan */
9157b5f0179Smacallan int fdt_node_depth(const void *fdt, int nodeoffset);
9167b5f0179Smacallan
9177b5f0179Smacallan /**
9187b5f0179Smacallan * fdt_parent_offset - find the parent of a given node
9197b5f0179Smacallan * @fdt: pointer to the device tree blob
9207b5f0179Smacallan * @nodeoffset: offset of the node whose parent to find
9217b5f0179Smacallan *
9227b5f0179Smacallan * fdt_parent_offset() locates the parent node of a given node (that
9237b5f0179Smacallan * is, it finds the offset of the node which contains the node at
9247b5f0179Smacallan * nodeoffset as a subnode).
9257b5f0179Smacallan *
9267b5f0179Smacallan * NOTE: This function is expensive, as it must scan the device tree
9277b5f0179Smacallan * structure from the start to nodeoffset, *twice*.
9287b5f0179Smacallan *
9297b5f0179Smacallan * returns:
9307b5f0179Smacallan * structure block offset of the parent of the node at nodeoffset
9317b5f0179Smacallan * (>=0), on success
9327b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
9337b5f0179Smacallan * -FDT_ERR_BADMAGIC,
9347b5f0179Smacallan * -FDT_ERR_BADVERSION,
9357b5f0179Smacallan * -FDT_ERR_BADSTATE,
9367b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
9377b5f0179Smacallan */
9387b5f0179Smacallan int fdt_parent_offset(const void *fdt, int nodeoffset);
9397b5f0179Smacallan
9407b5f0179Smacallan /**
9417b5f0179Smacallan * fdt_node_offset_by_prop_value - find nodes with a given property value
9427b5f0179Smacallan * @fdt: pointer to the device tree blob
9437b5f0179Smacallan * @startoffset: only find nodes after this offset
9447b5f0179Smacallan * @propname: property name to check
9457b5f0179Smacallan * @propval: property value to search for
9467b5f0179Smacallan * @proplen: length of the value in propval
9477b5f0179Smacallan *
9487b5f0179Smacallan * fdt_node_offset_by_prop_value() returns the offset of the first
9497b5f0179Smacallan * node after startoffset, which has a property named propname whose
9507b5f0179Smacallan * value is of length proplen and has value equal to propval; or if
9517b5f0179Smacallan * startoffset is -1, the very first such node in the tree.
9527b5f0179Smacallan *
9537b5f0179Smacallan * To iterate through all nodes matching the criterion, the following
9547b5f0179Smacallan * idiom can be used:
9557b5f0179Smacallan * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
9567b5f0179Smacallan * propval, proplen);
9577b5f0179Smacallan * while (offset != -FDT_ERR_NOTFOUND) {
9587b5f0179Smacallan * // other code here
9597b5f0179Smacallan * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
9607b5f0179Smacallan * propval, proplen);
9617b5f0179Smacallan * }
9627b5f0179Smacallan *
9637b5f0179Smacallan * Note the -1 in the first call to the function, if 0 is used here
9647b5f0179Smacallan * instead, the function will never locate the root node, even if it
9657b5f0179Smacallan * matches the criterion.
9667b5f0179Smacallan *
9677b5f0179Smacallan * returns:
9687b5f0179Smacallan * structure block offset of the located node (>= 0, >startoffset),
9697b5f0179Smacallan * on success
9707b5f0179Smacallan * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
9717b5f0179Smacallan * tree after startoffset
9727b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
9737b5f0179Smacallan * -FDT_ERR_BADMAGIC,
9747b5f0179Smacallan * -FDT_ERR_BADVERSION,
9757b5f0179Smacallan * -FDT_ERR_BADSTATE,
9767b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
9777b5f0179Smacallan */
9787b5f0179Smacallan int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
9797b5f0179Smacallan const char *propname,
9807b5f0179Smacallan const void *propval, int proplen);
9817b5f0179Smacallan
9827b5f0179Smacallan /**
9837b5f0179Smacallan * fdt_node_offset_by_phandle - find the node with a given phandle
9847b5f0179Smacallan * @fdt: pointer to the device tree blob
9857b5f0179Smacallan * @phandle: phandle value
9867b5f0179Smacallan *
9877b5f0179Smacallan * fdt_node_offset_by_phandle() returns the offset of the node
9887b5f0179Smacallan * which has the given phandle value. If there is more than one node
9897b5f0179Smacallan * in the tree with the given phandle (an invalid tree), results are
9907b5f0179Smacallan * undefined.
9917b5f0179Smacallan *
9927b5f0179Smacallan * returns:
9937b5f0179Smacallan * structure block offset of the located node (>= 0), on success
9947b5f0179Smacallan * -FDT_ERR_NOTFOUND, no node with that phandle exists
9957b5f0179Smacallan * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
9967b5f0179Smacallan * -FDT_ERR_BADMAGIC,
9977b5f0179Smacallan * -FDT_ERR_BADVERSION,
9987b5f0179Smacallan * -FDT_ERR_BADSTATE,
9997b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
10007b5f0179Smacallan */
10017b5f0179Smacallan int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
10027b5f0179Smacallan
10037b5f0179Smacallan /**
10047b5f0179Smacallan * fdt_node_check_compatible: check a node's compatible property
10057b5f0179Smacallan * @fdt: pointer to the device tree blob
10067b5f0179Smacallan * @nodeoffset: offset of a tree node
10077b5f0179Smacallan * @compatible: string to match against
10087b5f0179Smacallan *
10097b5f0179Smacallan *
10107b5f0179Smacallan * fdt_node_check_compatible() returns 0 if the given node contains a
10117b5f0179Smacallan * 'compatible' property with the given string as one of its elements,
10127b5f0179Smacallan * it returns non-zero otherwise, or on error.
10137b5f0179Smacallan *
10147b5f0179Smacallan * returns:
10157b5f0179Smacallan * 0, if the node has a 'compatible' property listing the given string
10167b5f0179Smacallan * 1, if the node has a 'compatible' property, but it does not list
10177b5f0179Smacallan * the given string
10187b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
10197b5f0179Smacallan * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
10207b5f0179Smacallan * -FDT_ERR_BADMAGIC,
10217b5f0179Smacallan * -FDT_ERR_BADVERSION,
10227b5f0179Smacallan * -FDT_ERR_BADSTATE,
10237b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
10247b5f0179Smacallan */
10257b5f0179Smacallan int fdt_node_check_compatible(const void *fdt, int nodeoffset,
10267b5f0179Smacallan const char *compatible);
10277b5f0179Smacallan
10287b5f0179Smacallan /**
10297b5f0179Smacallan * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
10307b5f0179Smacallan * @fdt: pointer to the device tree blob
10317b5f0179Smacallan * @startoffset: only find nodes after this offset
10327b5f0179Smacallan * @compatible: 'compatible' string to match against
10337b5f0179Smacallan *
10347b5f0179Smacallan * fdt_node_offset_by_compatible() returns the offset of the first
10357b5f0179Smacallan * node after startoffset, which has a 'compatible' property which
10367b5f0179Smacallan * lists the given compatible string; or if startoffset is -1, the
10377b5f0179Smacallan * very first such node in the tree.
10387b5f0179Smacallan *
10397b5f0179Smacallan * To iterate through all nodes matching the criterion, the following
10407b5f0179Smacallan * idiom can be used:
10417b5f0179Smacallan * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
10427b5f0179Smacallan * while (offset != -FDT_ERR_NOTFOUND) {
10437b5f0179Smacallan * // other code here
10447b5f0179Smacallan * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
10457b5f0179Smacallan * }
10467b5f0179Smacallan *
10477b5f0179Smacallan * Note the -1 in the first call to the function, if 0 is used here
10487b5f0179Smacallan * instead, the function will never locate the root node, even if it
10497b5f0179Smacallan * matches the criterion.
10507b5f0179Smacallan *
10517b5f0179Smacallan * returns:
10527b5f0179Smacallan * structure block offset of the located node (>= 0, >startoffset),
10537b5f0179Smacallan * on success
10547b5f0179Smacallan * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
10557b5f0179Smacallan * tree after startoffset
10567b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
10577b5f0179Smacallan * -FDT_ERR_BADMAGIC,
10587b5f0179Smacallan * -FDT_ERR_BADVERSION,
10597b5f0179Smacallan * -FDT_ERR_BADSTATE,
10607b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
10617b5f0179Smacallan */
10627b5f0179Smacallan int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
10637b5f0179Smacallan const char *compatible);
10647b5f0179Smacallan
10657b5f0179Smacallan /**
10667b5f0179Smacallan * fdt_stringlist_contains - check a string list property for a string
10677b5f0179Smacallan * @strlist: Property containing a list of strings to check
10687b5f0179Smacallan * @listlen: Length of property
10697b5f0179Smacallan * @str: String to search for
10707b5f0179Smacallan *
10717b5f0179Smacallan * This is a utility function provided for convenience. The list contains
10727b5f0179Smacallan * one or more strings, each terminated by \0, as is found in a device tree
10737b5f0179Smacallan * "compatible" property.
10747b5f0179Smacallan *
10757b5f0179Smacallan * @return: 1 if the string is found in the list, 0 not found, or invalid list
10767b5f0179Smacallan */
10777b5f0179Smacallan int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
10787b5f0179Smacallan
10797b5f0179Smacallan /**
10807b5f0179Smacallan * fdt_stringlist_count - count the number of strings in a string list
10817b5f0179Smacallan * @fdt: pointer to the device tree blob
10827b5f0179Smacallan * @nodeoffset: offset of a tree node
10837b5f0179Smacallan * @property: name of the property containing the string list
10847b5f0179Smacallan * @return:
10857b5f0179Smacallan * the number of strings in the given property
10867b5f0179Smacallan * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
10877b5f0179Smacallan * -FDT_ERR_NOTFOUND if the property does not exist
10887b5f0179Smacallan */
10897b5f0179Smacallan int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
10907b5f0179Smacallan
10917b5f0179Smacallan /**
10927b5f0179Smacallan * fdt_stringlist_search - find a string in a string list and return its index
10937b5f0179Smacallan * @fdt: pointer to the device tree blob
10947b5f0179Smacallan * @nodeoffset: offset of a tree node
10957b5f0179Smacallan * @property: name of the property containing the string list
10967b5f0179Smacallan * @string: string to look up in the string list
10977b5f0179Smacallan *
10987b5f0179Smacallan * Note that it is possible for this function to succeed on property values
10997b5f0179Smacallan * that are not NUL-terminated. That's because the function will stop after
11007b5f0179Smacallan * finding the first occurrence of @string. This can for example happen with
11017b5f0179Smacallan * small-valued cell properties, such as #address-cells, when searching for
11027b5f0179Smacallan * the empty string.
11037b5f0179Smacallan *
11047b5f0179Smacallan * @return:
11057b5f0179Smacallan * the index of the string in the list of strings
11067b5f0179Smacallan * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
11077b5f0179Smacallan * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
11087b5f0179Smacallan * the given string
11097b5f0179Smacallan */
11107b5f0179Smacallan int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
11117b5f0179Smacallan const char *string);
11127b5f0179Smacallan
11137b5f0179Smacallan /**
11147b5f0179Smacallan * fdt_stringlist_get() - obtain the string at a given index in a string list
11157b5f0179Smacallan * @fdt: pointer to the device tree blob
11167b5f0179Smacallan * @nodeoffset: offset of a tree node
11177b5f0179Smacallan * @property: name of the property containing the string list
11187b5f0179Smacallan * @index: index of the string to return
11197b5f0179Smacallan * @lenp: return location for the string length or an error code on failure
11207b5f0179Smacallan *
11217b5f0179Smacallan * Note that this will successfully extract strings from properties with
11227b5f0179Smacallan * non-NUL-terminated values. For example on small-valued cell properties
11237b5f0179Smacallan * this function will return the empty string.
11247b5f0179Smacallan *
11257b5f0179Smacallan * If non-NULL, the length of the string (on success) or a negative error-code
11267b5f0179Smacallan * (on failure) will be stored in the integer pointer to by lenp.
11277b5f0179Smacallan *
11287b5f0179Smacallan * @return:
11297b5f0179Smacallan * A pointer to the string at the given index in the string list or NULL on
11307b5f0179Smacallan * failure. On success the length of the string will be stored in the memory
11317b5f0179Smacallan * location pointed to by the lenp parameter, if non-NULL. On failure one of
11327b5f0179Smacallan * the following negative error codes will be returned in the lenp parameter
11337b5f0179Smacallan * (if non-NULL):
11347b5f0179Smacallan * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
11357b5f0179Smacallan * -FDT_ERR_NOTFOUND if the property does not exist
11367b5f0179Smacallan */
11377b5f0179Smacallan const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
11387b5f0179Smacallan const char *property, int index,
11397b5f0179Smacallan int *lenp);
11407b5f0179Smacallan
11417b5f0179Smacallan /**********************************************************************/
11427b5f0179Smacallan /* Read-only functions (addressing related) */
11437b5f0179Smacallan /**********************************************************************/
11447b5f0179Smacallan
11457b5f0179Smacallan /**
11467b5f0179Smacallan * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
11477b5f0179Smacallan *
11487b5f0179Smacallan * This is the maximum value for #address-cells, #size-cells and
11497b5f0179Smacallan * similar properties that will be processed by libfdt. IEE1275
11507b5f0179Smacallan * requires that OF implementations handle values up to 4.
11517b5f0179Smacallan * Implementations may support larger values, but in practice higher
11527b5f0179Smacallan * values aren't used.
11537b5f0179Smacallan */
11547b5f0179Smacallan #define FDT_MAX_NCELLS 4
11557b5f0179Smacallan
11567b5f0179Smacallan /**
11577b5f0179Smacallan * fdt_address_cells - retrieve address size for a bus represented in the tree
11587b5f0179Smacallan * @fdt: pointer to the device tree blob
11597b5f0179Smacallan * @nodeoffset: offset of the node to find the address size for
11607b5f0179Smacallan *
11617b5f0179Smacallan * When the node has a valid #address-cells property, returns its value.
11627b5f0179Smacallan *
11637b5f0179Smacallan * returns:
11647b5f0179Smacallan * 0 <= n < FDT_MAX_NCELLS, on success
11657b5f0179Smacallan * 2, if the node has no #address-cells property
11662fb928dbSskrll * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
11672fb928dbSskrll * #address-cells property
11687b5f0179Smacallan * -FDT_ERR_BADMAGIC,
11697b5f0179Smacallan * -FDT_ERR_BADVERSION,
11707b5f0179Smacallan * -FDT_ERR_BADSTATE,
11717b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
11727b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
11737b5f0179Smacallan */
11747b5f0179Smacallan int fdt_address_cells(const void *fdt, int nodeoffset);
11757b5f0179Smacallan
11767b5f0179Smacallan /**
11777b5f0179Smacallan * fdt_size_cells - retrieve address range size for a bus represented in the
11787b5f0179Smacallan * tree
11797b5f0179Smacallan * @fdt: pointer to the device tree blob
11807b5f0179Smacallan * @nodeoffset: offset of the node to find the address range size for
11817b5f0179Smacallan *
11827b5f0179Smacallan * When the node has a valid #size-cells property, returns its value.
11837b5f0179Smacallan *
11847b5f0179Smacallan * returns:
11857b5f0179Smacallan * 0 <= n < FDT_MAX_NCELLS, on success
1186*b9ee18deSskrll * 1, if the node has no #size-cells property
11872fb928dbSskrll * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
11882fb928dbSskrll * #size-cells property
11897b5f0179Smacallan * -FDT_ERR_BADMAGIC,
11907b5f0179Smacallan * -FDT_ERR_BADVERSION,
11917b5f0179Smacallan * -FDT_ERR_BADSTATE,
11927b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
11937b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
11947b5f0179Smacallan */
11957b5f0179Smacallan int fdt_size_cells(const void *fdt, int nodeoffset);
11967b5f0179Smacallan
11977b5f0179Smacallan
11987b5f0179Smacallan /**********************************************************************/
11997b5f0179Smacallan /* Write-in-place functions */
12007b5f0179Smacallan /**********************************************************************/
12017b5f0179Smacallan
12027b5f0179Smacallan /**
12032fb928dbSskrll * fdt_setprop_inplace_namelen_partial - change a property's value,
12042fb928dbSskrll * but not its size
12052fb928dbSskrll * @fdt: pointer to the device tree blob
12062fb928dbSskrll * @nodeoffset: offset of the node whose property to change
12072fb928dbSskrll * @name: name of the property to change
12082fb928dbSskrll * @namelen: number of characters of name to consider
12092fb928dbSskrll * @idx: index of the property to change in the array
12102fb928dbSskrll * @val: pointer to data to replace the property value with
12112fb928dbSskrll * @len: length of the property value
12122fb928dbSskrll *
12132fb928dbSskrll * Identical to fdt_setprop_inplace(), but modifies the given property
12142fb928dbSskrll * starting from the given index, and using only the first characters
12152fb928dbSskrll * of the name. It is useful when you want to manipulate only one value of
12162fb928dbSskrll * an array and you have a string that doesn't end with \0.
12172fb928dbSskrll */
1218*b9ee18deSskrll #ifndef SWIG /* Not available in Python */
12192fb928dbSskrll int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
12202fb928dbSskrll const char *name, int namelen,
12212fb928dbSskrll uint32_t idx, const void *val,
12222fb928dbSskrll int len);
1223*b9ee18deSskrll #endif
12242fb928dbSskrll
12252fb928dbSskrll /**
12267b5f0179Smacallan * fdt_setprop_inplace - change a property's value, but not its size
12277b5f0179Smacallan * @fdt: pointer to the device tree blob
12287b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
12297b5f0179Smacallan * @name: name of the property to change
12307b5f0179Smacallan * @val: pointer to data to replace the property value with
12317b5f0179Smacallan * @len: length of the property value
12327b5f0179Smacallan *
12337b5f0179Smacallan * fdt_setprop_inplace() replaces the value of a given property with
12347b5f0179Smacallan * the data in val, of length len. This function cannot change the
12357b5f0179Smacallan * size of a property, and so will only work if len is equal to the
12367b5f0179Smacallan * current length of the property.
12377b5f0179Smacallan *
12387b5f0179Smacallan * This function will alter only the bytes in the blob which contain
12397b5f0179Smacallan * the given property value, and will not alter or move any other part
12407b5f0179Smacallan * of the tree.
12417b5f0179Smacallan *
12427b5f0179Smacallan * returns:
12437b5f0179Smacallan * 0, on success
12447b5f0179Smacallan * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
12457b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property
12467b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
12477b5f0179Smacallan * -FDT_ERR_BADMAGIC,
12487b5f0179Smacallan * -FDT_ERR_BADVERSION,
12497b5f0179Smacallan * -FDT_ERR_BADSTATE,
12507b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
12517b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
12527b5f0179Smacallan */
1253*b9ee18deSskrll #ifndef SWIG /* Not available in Python */
12547b5f0179Smacallan int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
12557b5f0179Smacallan const void *val, int len);
1256*b9ee18deSskrll #endif
12577b5f0179Smacallan
12587b5f0179Smacallan /**
12597b5f0179Smacallan * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
12607b5f0179Smacallan * @fdt: pointer to the device tree blob
12617b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
12627b5f0179Smacallan * @name: name of the property to change
12637b5f0179Smacallan * @val: 32-bit integer value to replace the property with
12647b5f0179Smacallan *
12657b5f0179Smacallan * fdt_setprop_inplace_u32() replaces the value of a given property
12667b5f0179Smacallan * with the 32-bit integer value in val, converting val to big-endian
12677b5f0179Smacallan * if necessary. This function cannot change the size of a property,
12687b5f0179Smacallan * and so will only work if the property already exists and has length
12697b5f0179Smacallan * 4.
12707b5f0179Smacallan *
12717b5f0179Smacallan * This function will alter only the bytes in the blob which contain
12727b5f0179Smacallan * the given property value, and will not alter or move any other part
12737b5f0179Smacallan * of the tree.
12747b5f0179Smacallan *
12757b5f0179Smacallan * returns:
12767b5f0179Smacallan * 0, on success
12777b5f0179Smacallan * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
12787b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property
12797b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
12807b5f0179Smacallan * -FDT_ERR_BADMAGIC,
12817b5f0179Smacallan * -FDT_ERR_BADVERSION,
12827b5f0179Smacallan * -FDT_ERR_BADSTATE,
12837b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
12847b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
12857b5f0179Smacallan */
fdt_setprop_inplace_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)12867b5f0179Smacallan static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
12877b5f0179Smacallan const char *name, uint32_t val)
12887b5f0179Smacallan {
12897b5f0179Smacallan fdt32_t tmp = cpu_to_fdt32(val);
12907b5f0179Smacallan return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
12917b5f0179Smacallan }
12927b5f0179Smacallan
12937b5f0179Smacallan /**
12947b5f0179Smacallan * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
12957b5f0179Smacallan * @fdt: pointer to the device tree blob
12967b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
12977b5f0179Smacallan * @name: name of the property to change
12987b5f0179Smacallan * @val: 64-bit integer value to replace the property with
12997b5f0179Smacallan *
13007b5f0179Smacallan * fdt_setprop_inplace_u64() replaces the value of a given property
13017b5f0179Smacallan * with the 64-bit integer value in val, converting val to big-endian
13027b5f0179Smacallan * if necessary. This function cannot change the size of a property,
13037b5f0179Smacallan * and so will only work if the property already exists and has length
13047b5f0179Smacallan * 8.
13057b5f0179Smacallan *
13067b5f0179Smacallan * This function will alter only the bytes in the blob which contain
13077b5f0179Smacallan * the given property value, and will not alter or move any other part
13087b5f0179Smacallan * of the tree.
13097b5f0179Smacallan *
13107b5f0179Smacallan * returns:
13117b5f0179Smacallan * 0, on success
13127b5f0179Smacallan * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
13137b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property
13147b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
13157b5f0179Smacallan * -FDT_ERR_BADMAGIC,
13167b5f0179Smacallan * -FDT_ERR_BADVERSION,
13177b5f0179Smacallan * -FDT_ERR_BADSTATE,
13187b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
13197b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
13207b5f0179Smacallan */
fdt_setprop_inplace_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)13217b5f0179Smacallan static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
13227b5f0179Smacallan const char *name, uint64_t val)
13237b5f0179Smacallan {
13247b5f0179Smacallan fdt64_t tmp = cpu_to_fdt64(val);
13257b5f0179Smacallan return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
13267b5f0179Smacallan }
13277b5f0179Smacallan
13287b5f0179Smacallan /**
13297b5f0179Smacallan * fdt_setprop_inplace_cell - change the value of a single-cell property
13307b5f0179Smacallan *
13317b5f0179Smacallan * This is an alternative name for fdt_setprop_inplace_u32()
13327b5f0179Smacallan */
fdt_setprop_inplace_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)13337b5f0179Smacallan static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
13347b5f0179Smacallan const char *name, uint32_t val)
13357b5f0179Smacallan {
13367b5f0179Smacallan return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
13377b5f0179Smacallan }
13387b5f0179Smacallan
13397b5f0179Smacallan /**
13407b5f0179Smacallan * fdt_nop_property - replace a property with nop tags
13417b5f0179Smacallan * @fdt: pointer to the device tree blob
13427b5f0179Smacallan * @nodeoffset: offset of the node whose property to nop
13437b5f0179Smacallan * @name: name of the property to nop
13447b5f0179Smacallan *
13457b5f0179Smacallan * fdt_nop_property() will replace a given property's representation
13467b5f0179Smacallan * in the blob with FDT_NOP tags, effectively removing it from the
13477b5f0179Smacallan * tree.
13487b5f0179Smacallan *
13497b5f0179Smacallan * This function will alter only the bytes in the blob which contain
13507b5f0179Smacallan * the property, and will not alter or move any other part of the
13517b5f0179Smacallan * tree.
13527b5f0179Smacallan *
13537b5f0179Smacallan * returns:
13547b5f0179Smacallan * 0, on success
13557b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property
13567b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
13577b5f0179Smacallan * -FDT_ERR_BADMAGIC,
13587b5f0179Smacallan * -FDT_ERR_BADVERSION,
13597b5f0179Smacallan * -FDT_ERR_BADSTATE,
13607b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
13617b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
13627b5f0179Smacallan */
13637b5f0179Smacallan int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
13647b5f0179Smacallan
13657b5f0179Smacallan /**
13667b5f0179Smacallan * fdt_nop_node - replace a node (subtree) with nop tags
13677b5f0179Smacallan * @fdt: pointer to the device tree blob
13687b5f0179Smacallan * @nodeoffset: offset of the node to nop
13697b5f0179Smacallan *
13707b5f0179Smacallan * fdt_nop_node() will replace a given node's representation in the
13717b5f0179Smacallan * blob, including all its subnodes, if any, with FDT_NOP tags,
13727b5f0179Smacallan * effectively removing it from the tree.
13737b5f0179Smacallan *
13747b5f0179Smacallan * This function will alter only the bytes in the blob which contain
13757b5f0179Smacallan * the node and its properties and subnodes, and will not alter or
13767b5f0179Smacallan * move any other part of the tree.
13777b5f0179Smacallan *
13787b5f0179Smacallan * returns:
13797b5f0179Smacallan * 0, on success
13807b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
13817b5f0179Smacallan * -FDT_ERR_BADMAGIC,
13827b5f0179Smacallan * -FDT_ERR_BADVERSION,
13837b5f0179Smacallan * -FDT_ERR_BADSTATE,
13847b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
13857b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
13867b5f0179Smacallan */
13877b5f0179Smacallan int fdt_nop_node(void *fdt, int nodeoffset);
13887b5f0179Smacallan
13897b5f0179Smacallan /**********************************************************************/
13907b5f0179Smacallan /* Sequential write functions */
13917b5f0179Smacallan /**********************************************************************/
13927b5f0179Smacallan
1393*b9ee18deSskrll /* fdt_create_with_flags flags */
1394*b9ee18deSskrll #define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1
1395*b9ee18deSskrll /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property
1396*b9ee18deSskrll * names in the fdt. This can result in faster creation times, but
1397*b9ee18deSskrll * a larger fdt. */
1398*b9ee18deSskrll
1399*b9ee18deSskrll #define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP)
1400*b9ee18deSskrll
1401*b9ee18deSskrll /**
1402*b9ee18deSskrll * fdt_create_with_flags - begin creation of a new fdt
1403*b9ee18deSskrll * @fdt: pointer to memory allocated where fdt will be created
1404*b9ee18deSskrll * @bufsize: size of the memory space at fdt
1405*b9ee18deSskrll * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0.
1406*b9ee18deSskrll *
1407*b9ee18deSskrll * fdt_create_with_flags() begins the process of creating a new fdt with
1408*b9ee18deSskrll * the sequential write interface.
1409*b9ee18deSskrll *
1410*b9ee18deSskrll * fdt creation process must end with fdt_finished() to produce a valid fdt.
1411*b9ee18deSskrll *
1412*b9ee18deSskrll * returns:
1413*b9ee18deSskrll * 0, on success
1414*b9ee18deSskrll * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
1415*b9ee18deSskrll * -FDT_ERR_BADFLAGS, flags is not valid
1416*b9ee18deSskrll */
1417*b9ee18deSskrll int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags);
1418*b9ee18deSskrll
1419*b9ee18deSskrll /**
1420*b9ee18deSskrll * fdt_create - begin creation of a new fdt
1421*b9ee18deSskrll * @fdt: pointer to memory allocated where fdt will be created
1422*b9ee18deSskrll * @bufsize: size of the memory space at fdt
1423*b9ee18deSskrll *
1424*b9ee18deSskrll * fdt_create() is equivalent to fdt_create_with_flags() with flags=0.
1425*b9ee18deSskrll *
1426*b9ee18deSskrll * returns:
1427*b9ee18deSskrll * 0, on success
1428*b9ee18deSskrll * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
1429*b9ee18deSskrll */
14307b5f0179Smacallan int fdt_create(void *buf, int bufsize);
1431*b9ee18deSskrll
14327b5f0179Smacallan int fdt_resize(void *fdt, void *buf, int bufsize);
14337b5f0179Smacallan int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
14347b5f0179Smacallan int fdt_finish_reservemap(void *fdt);
14357b5f0179Smacallan int fdt_begin_node(void *fdt, const char *name);
14367b5f0179Smacallan int fdt_property(void *fdt, const char *name, const void *val, int len);
fdt_property_u32(void * fdt,const char * name,uint32_t val)14377b5f0179Smacallan static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
14387b5f0179Smacallan {
14397b5f0179Smacallan fdt32_t tmp = cpu_to_fdt32(val);
14407b5f0179Smacallan return fdt_property(fdt, name, &tmp, sizeof(tmp));
14417b5f0179Smacallan }
fdt_property_u64(void * fdt,const char * name,uint64_t val)14427b5f0179Smacallan static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
14437b5f0179Smacallan {
14447b5f0179Smacallan fdt64_t tmp = cpu_to_fdt64(val);
14457b5f0179Smacallan return fdt_property(fdt, name, &tmp, sizeof(tmp));
14467b5f0179Smacallan }
1447*b9ee18deSskrll
1448*b9ee18deSskrll #ifndef SWIG /* Not available in Python */
fdt_property_cell(void * fdt,const char * name,uint32_t val)14497b5f0179Smacallan static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
14507b5f0179Smacallan {
14517b5f0179Smacallan return fdt_property_u32(fdt, name, val);
14527b5f0179Smacallan }
1453*b9ee18deSskrll #endif
1454*b9ee18deSskrll
1455*b9ee18deSskrll /**
1456*b9ee18deSskrll * fdt_property_placeholder - add a new property and return a ptr to its value
1457*b9ee18deSskrll *
1458*b9ee18deSskrll * @fdt: pointer to the device tree blob
1459*b9ee18deSskrll * @name: name of property to add
1460*b9ee18deSskrll * @len: length of property value in bytes
1461*b9ee18deSskrll * @valp: returns a pointer to where where the value should be placed
1462*b9ee18deSskrll *
1463*b9ee18deSskrll * returns:
1464*b9ee18deSskrll * 0, on success
1465*b9ee18deSskrll * -FDT_ERR_BADMAGIC,
1466*b9ee18deSskrll * -FDT_ERR_NOSPACE, standard meanings
1467*b9ee18deSskrll */
1468*b9ee18deSskrll int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp);
1469*b9ee18deSskrll
14707b5f0179Smacallan #define fdt_property_string(fdt, name, str) \
14717b5f0179Smacallan fdt_property(fdt, name, str, strlen(str)+1)
14727b5f0179Smacallan int fdt_end_node(void *fdt);
14737b5f0179Smacallan int fdt_finish(void *fdt);
14747b5f0179Smacallan
14757b5f0179Smacallan /**********************************************************************/
14767b5f0179Smacallan /* Read-write functions */
14777b5f0179Smacallan /**********************************************************************/
14787b5f0179Smacallan
14797b5f0179Smacallan int fdt_create_empty_tree(void *buf, int bufsize);
14807b5f0179Smacallan int fdt_open_into(const void *fdt, void *buf, int bufsize);
14817b5f0179Smacallan int fdt_pack(void *fdt);
14827b5f0179Smacallan
14837b5f0179Smacallan /**
14847b5f0179Smacallan * fdt_add_mem_rsv - add one memory reserve map entry
14857b5f0179Smacallan * @fdt: pointer to the device tree blob
14867b5f0179Smacallan * @address, @size: 64-bit values (native endian)
14877b5f0179Smacallan *
14887b5f0179Smacallan * Adds a reserve map entry to the given blob reserving a region at
14897b5f0179Smacallan * address address of length size.
14907b5f0179Smacallan *
14917b5f0179Smacallan * This function will insert data into the reserve map and will
14927b5f0179Smacallan * therefore change the indexes of some entries in the table.
14937b5f0179Smacallan *
14947b5f0179Smacallan * returns:
14957b5f0179Smacallan * 0, on success
14967b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
14977b5f0179Smacallan * contain the new reservation entry
14987b5f0179Smacallan * -FDT_ERR_BADMAGIC,
14997b5f0179Smacallan * -FDT_ERR_BADVERSION,
15007b5f0179Smacallan * -FDT_ERR_BADSTATE,
15017b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
15027b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
15037b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
15047b5f0179Smacallan */
15057b5f0179Smacallan int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
15067b5f0179Smacallan
15077b5f0179Smacallan /**
15087b5f0179Smacallan * fdt_del_mem_rsv - remove a memory reserve map entry
15097b5f0179Smacallan * @fdt: pointer to the device tree blob
15107b5f0179Smacallan * @n: entry to remove
15117b5f0179Smacallan *
15127b5f0179Smacallan * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
15137b5f0179Smacallan * the blob.
15147b5f0179Smacallan *
15157b5f0179Smacallan * This function will delete data from the reservation table and will
15167b5f0179Smacallan * therefore change the indexes of some entries in the table.
15177b5f0179Smacallan *
15187b5f0179Smacallan * returns:
15197b5f0179Smacallan * 0, on success
15207b5f0179Smacallan * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
15217b5f0179Smacallan * are less than n+1 reserve map entries)
15227b5f0179Smacallan * -FDT_ERR_BADMAGIC,
15237b5f0179Smacallan * -FDT_ERR_BADVERSION,
15247b5f0179Smacallan * -FDT_ERR_BADSTATE,
15257b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
15267b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
15277b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
15287b5f0179Smacallan */
15297b5f0179Smacallan int fdt_del_mem_rsv(void *fdt, int n);
15307b5f0179Smacallan
15317b5f0179Smacallan /**
15327b5f0179Smacallan * fdt_set_name - change the name of a given node
15337b5f0179Smacallan * @fdt: pointer to the device tree blob
15347b5f0179Smacallan * @nodeoffset: structure block offset of a node
15357b5f0179Smacallan * @name: name to give the node
15367b5f0179Smacallan *
15377b5f0179Smacallan * fdt_set_name() replaces the name (including unit address, if any)
15387b5f0179Smacallan * of the given node with the given string. NOTE: this function can't
15397b5f0179Smacallan * efficiently check if the new name is unique amongst the given
15407b5f0179Smacallan * node's siblings; results are undefined if this function is invoked
15417b5f0179Smacallan * with a name equal to one of the given node's siblings.
15427b5f0179Smacallan *
15437b5f0179Smacallan * This function may insert or delete data from the blob, and will
15447b5f0179Smacallan * therefore change the offsets of some existing nodes.
15457b5f0179Smacallan *
15467b5f0179Smacallan * returns:
15477b5f0179Smacallan * 0, on success
15487b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
15497b5f0179Smacallan * to contain the new name
15507b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
15517b5f0179Smacallan * -FDT_ERR_BADMAGIC,
15527b5f0179Smacallan * -FDT_ERR_BADVERSION,
15537b5f0179Smacallan * -FDT_ERR_BADSTATE, standard meanings
15547b5f0179Smacallan */
15557b5f0179Smacallan int fdt_set_name(void *fdt, int nodeoffset, const char *name);
15567b5f0179Smacallan
15577b5f0179Smacallan /**
15587b5f0179Smacallan * fdt_setprop - create or change a property
15597b5f0179Smacallan * @fdt: pointer to the device tree blob
15607b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
15617b5f0179Smacallan * @name: name of the property to change
15627b5f0179Smacallan * @val: pointer to data to set the property value to
15637b5f0179Smacallan * @len: length of the property value
15647b5f0179Smacallan *
15657b5f0179Smacallan * fdt_setprop() sets the value of the named property in the given
15667b5f0179Smacallan * node to the given value and length, creating the property if it
15677b5f0179Smacallan * does not already exist.
15687b5f0179Smacallan *
15697b5f0179Smacallan * This function may insert or delete data from the blob, and will
15707b5f0179Smacallan * therefore change the offsets of some existing nodes.
15717b5f0179Smacallan *
15727b5f0179Smacallan * returns:
15737b5f0179Smacallan * 0, on success
15747b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
15757b5f0179Smacallan * contain the new property value
15767b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
15777b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
15787b5f0179Smacallan * -FDT_ERR_BADMAGIC,
15797b5f0179Smacallan * -FDT_ERR_BADVERSION,
15807b5f0179Smacallan * -FDT_ERR_BADSTATE,
15817b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
15827b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
15837b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
15847b5f0179Smacallan */
15857b5f0179Smacallan int fdt_setprop(void *fdt, int nodeoffset, const char *name,
15867b5f0179Smacallan const void *val, int len);
15877b5f0179Smacallan
15887b5f0179Smacallan /**
1589*b9ee18deSskrll * fdt_setprop_placeholder - allocate space for a property
1590*b9ee18deSskrll * @fdt: pointer to the device tree blob
1591*b9ee18deSskrll * @nodeoffset: offset of the node whose property to change
1592*b9ee18deSskrll * @name: name of the property to change
1593*b9ee18deSskrll * @len: length of the property value
1594*b9ee18deSskrll * @prop_data: return pointer to property data
1595*b9ee18deSskrll *
1596*b9ee18deSskrll * fdt_setprop_placeholer() allocates the named property in the given node.
1597*b9ee18deSskrll * If the property exists it is resized. In either case a pointer to the
1598*b9ee18deSskrll * property data is returned.
1599*b9ee18deSskrll *
1600*b9ee18deSskrll * This function may insert or delete data from the blob, and will
1601*b9ee18deSskrll * therefore change the offsets of some existing nodes.
1602*b9ee18deSskrll *
1603*b9ee18deSskrll * returns:
1604*b9ee18deSskrll * 0, on success
1605*b9ee18deSskrll * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1606*b9ee18deSskrll * contain the new property value
1607*b9ee18deSskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1608*b9ee18deSskrll * -FDT_ERR_BADLAYOUT,
1609*b9ee18deSskrll * -FDT_ERR_BADMAGIC,
1610*b9ee18deSskrll * -FDT_ERR_BADVERSION,
1611*b9ee18deSskrll * -FDT_ERR_BADSTATE,
1612*b9ee18deSskrll * -FDT_ERR_BADSTRUCTURE,
1613*b9ee18deSskrll * -FDT_ERR_BADLAYOUT,
1614*b9ee18deSskrll * -FDT_ERR_TRUNCATED, standard meanings
1615*b9ee18deSskrll */
1616*b9ee18deSskrll int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
1617*b9ee18deSskrll int len, void **prop_data);
1618*b9ee18deSskrll
1619*b9ee18deSskrll /**
16207b5f0179Smacallan * fdt_setprop_u32 - set a property to a 32-bit integer
16217b5f0179Smacallan * @fdt: pointer to the device tree blob
16227b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
16237b5f0179Smacallan * @name: name of the property to change
16247b5f0179Smacallan * @val: 32-bit integer value for the property (native endian)
16257b5f0179Smacallan *
16267b5f0179Smacallan * fdt_setprop_u32() sets the value of the named property in the given
16277b5f0179Smacallan * node to the given 32-bit integer value (converting to big-endian if
16287b5f0179Smacallan * necessary), or creates a new property with that value if it does
16297b5f0179Smacallan * not already exist.
16307b5f0179Smacallan *
16317b5f0179Smacallan * This function may insert or delete data from the blob, and will
16327b5f0179Smacallan * therefore change the offsets of some existing nodes.
16337b5f0179Smacallan *
16347b5f0179Smacallan * returns:
16357b5f0179Smacallan * 0, on success
16367b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
16377b5f0179Smacallan * contain the new property value
16387b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
16397b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
16407b5f0179Smacallan * -FDT_ERR_BADMAGIC,
16417b5f0179Smacallan * -FDT_ERR_BADVERSION,
16427b5f0179Smacallan * -FDT_ERR_BADSTATE,
16437b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
16447b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
16457b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
16467b5f0179Smacallan */
fdt_setprop_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)16477b5f0179Smacallan static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
16487b5f0179Smacallan uint32_t val)
16497b5f0179Smacallan {
16507b5f0179Smacallan fdt32_t tmp = cpu_to_fdt32(val);
16517b5f0179Smacallan return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
16527b5f0179Smacallan }
16537b5f0179Smacallan
16547b5f0179Smacallan /**
16557b5f0179Smacallan * fdt_setprop_u64 - set a property to a 64-bit integer
16567b5f0179Smacallan * @fdt: pointer to the device tree blob
16577b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
16587b5f0179Smacallan * @name: name of the property to change
16597b5f0179Smacallan * @val: 64-bit integer value for the property (native endian)
16607b5f0179Smacallan *
16617b5f0179Smacallan * fdt_setprop_u64() sets the value of the named property in the given
16627b5f0179Smacallan * node to the given 64-bit integer value (converting to big-endian if
16637b5f0179Smacallan * necessary), or creates a new property with that value if it does
16647b5f0179Smacallan * not already exist.
16657b5f0179Smacallan *
16667b5f0179Smacallan * This function may insert or delete data from the blob, and will
16677b5f0179Smacallan * therefore change the offsets of some existing nodes.
16687b5f0179Smacallan *
16697b5f0179Smacallan * returns:
16707b5f0179Smacallan * 0, on success
16717b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
16727b5f0179Smacallan * contain the new property value
16737b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
16747b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
16757b5f0179Smacallan * -FDT_ERR_BADMAGIC,
16767b5f0179Smacallan * -FDT_ERR_BADVERSION,
16777b5f0179Smacallan * -FDT_ERR_BADSTATE,
16787b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
16797b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
16807b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
16817b5f0179Smacallan */
fdt_setprop_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)16827b5f0179Smacallan static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
16837b5f0179Smacallan uint64_t val)
16847b5f0179Smacallan {
16857b5f0179Smacallan fdt64_t tmp = cpu_to_fdt64(val);
16867b5f0179Smacallan return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
16877b5f0179Smacallan }
16887b5f0179Smacallan
16897b5f0179Smacallan /**
16907b5f0179Smacallan * fdt_setprop_cell - set a property to a single cell value
16917b5f0179Smacallan *
16927b5f0179Smacallan * This is an alternative name for fdt_setprop_u32()
16937b5f0179Smacallan */
fdt_setprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)16947b5f0179Smacallan static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
16957b5f0179Smacallan uint32_t val)
16967b5f0179Smacallan {
16977b5f0179Smacallan return fdt_setprop_u32(fdt, nodeoffset, name, val);
16987b5f0179Smacallan }
16997b5f0179Smacallan
17007b5f0179Smacallan /**
17017b5f0179Smacallan * fdt_setprop_string - set a property to a string value
17027b5f0179Smacallan * @fdt: pointer to the device tree blob
17037b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
17047b5f0179Smacallan * @name: name of the property to change
17057b5f0179Smacallan * @str: string value for the property
17067b5f0179Smacallan *
17077b5f0179Smacallan * fdt_setprop_string() sets the value of the named property in the
17087b5f0179Smacallan * given node to the given string value (using the length of the
17097b5f0179Smacallan * string to determine the new length of the property), or creates a
17107b5f0179Smacallan * new property with that value if it does not already exist.
17117b5f0179Smacallan *
17127b5f0179Smacallan * This function may insert or delete data from the blob, and will
17137b5f0179Smacallan * therefore change the offsets of some existing nodes.
17147b5f0179Smacallan *
17157b5f0179Smacallan * returns:
17167b5f0179Smacallan * 0, on success
17177b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
17187b5f0179Smacallan * contain the new property value
17197b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
17207b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
17217b5f0179Smacallan * -FDT_ERR_BADMAGIC,
17227b5f0179Smacallan * -FDT_ERR_BADVERSION,
17237b5f0179Smacallan * -FDT_ERR_BADSTATE,
17247b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
17257b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
17267b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
17277b5f0179Smacallan */
17287b5f0179Smacallan #define fdt_setprop_string(fdt, nodeoffset, name, str) \
17297b5f0179Smacallan fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
17307b5f0179Smacallan
17312fb928dbSskrll
17322fb928dbSskrll /**
17332fb928dbSskrll * fdt_setprop_empty - set a property to an empty value
17342fb928dbSskrll * @fdt: pointer to the device tree blob
17352fb928dbSskrll * @nodeoffset: offset of the node whose property to change
17362fb928dbSskrll * @name: name of the property to change
17372fb928dbSskrll *
17382fb928dbSskrll * fdt_setprop_empty() sets the value of the named property in the
17392fb928dbSskrll * given node to an empty (zero length) value, or creates a new empty
17402fb928dbSskrll * property if it does not already exist.
17412fb928dbSskrll *
17422fb928dbSskrll * This function may insert or delete data from the blob, and will
17432fb928dbSskrll * therefore change the offsets of some existing nodes.
17442fb928dbSskrll *
17452fb928dbSskrll * returns:
17462fb928dbSskrll * 0, on success
17472fb928dbSskrll * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
17482fb928dbSskrll * contain the new property value
17492fb928dbSskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
17502fb928dbSskrll * -FDT_ERR_BADLAYOUT,
17512fb928dbSskrll * -FDT_ERR_BADMAGIC,
17522fb928dbSskrll * -FDT_ERR_BADVERSION,
17532fb928dbSskrll * -FDT_ERR_BADSTATE,
17542fb928dbSskrll * -FDT_ERR_BADSTRUCTURE,
17552fb928dbSskrll * -FDT_ERR_BADLAYOUT,
17562fb928dbSskrll * -FDT_ERR_TRUNCATED, standard meanings
17572fb928dbSskrll */
17582fb928dbSskrll #define fdt_setprop_empty(fdt, nodeoffset, name) \
17592fb928dbSskrll fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
17602fb928dbSskrll
17617b5f0179Smacallan /**
17627b5f0179Smacallan * fdt_appendprop - append to or create a property
17637b5f0179Smacallan * @fdt: pointer to the device tree blob
17647b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
17657b5f0179Smacallan * @name: name of the property to append to
17667b5f0179Smacallan * @val: pointer to data to append to the property value
17677b5f0179Smacallan * @len: length of the data to append to the property value
17687b5f0179Smacallan *
17697b5f0179Smacallan * fdt_appendprop() appends the value to the named property in the
17707b5f0179Smacallan * given node, creating the property if it does not already exist.
17717b5f0179Smacallan *
17727b5f0179Smacallan * This function may insert data into the blob, and will therefore
17737b5f0179Smacallan * change the offsets of some existing nodes.
17747b5f0179Smacallan *
17757b5f0179Smacallan * returns:
17767b5f0179Smacallan * 0, on success
17777b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
17787b5f0179Smacallan * contain the new property value
17797b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
17807b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
17817b5f0179Smacallan * -FDT_ERR_BADMAGIC,
17827b5f0179Smacallan * -FDT_ERR_BADVERSION,
17837b5f0179Smacallan * -FDT_ERR_BADSTATE,
17847b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
17857b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
17867b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
17877b5f0179Smacallan */
17887b5f0179Smacallan int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
17897b5f0179Smacallan const void *val, int len);
17907b5f0179Smacallan
17917b5f0179Smacallan /**
17927b5f0179Smacallan * fdt_appendprop_u32 - append a 32-bit integer value to a property
17937b5f0179Smacallan * @fdt: pointer to the device tree blob
17947b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
17957b5f0179Smacallan * @name: name of the property to change
17967b5f0179Smacallan * @val: 32-bit integer value to append to the property (native endian)
17977b5f0179Smacallan *
17987b5f0179Smacallan * fdt_appendprop_u32() appends the given 32-bit integer value
17997b5f0179Smacallan * (converting to big-endian if necessary) to the value of the named
18007b5f0179Smacallan * property in the given node, or creates a new property with that
18017b5f0179Smacallan * value if it does not already exist.
18027b5f0179Smacallan *
18037b5f0179Smacallan * This function may insert data into the blob, and will therefore
18047b5f0179Smacallan * change the offsets of some existing nodes.
18057b5f0179Smacallan *
18067b5f0179Smacallan * returns:
18077b5f0179Smacallan * 0, on success
18087b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
18097b5f0179Smacallan * contain the new property value
18107b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
18117b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
18127b5f0179Smacallan * -FDT_ERR_BADMAGIC,
18137b5f0179Smacallan * -FDT_ERR_BADVERSION,
18147b5f0179Smacallan * -FDT_ERR_BADSTATE,
18157b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
18167b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
18177b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
18187b5f0179Smacallan */
fdt_appendprop_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)18197b5f0179Smacallan static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
18207b5f0179Smacallan const char *name, uint32_t val)
18217b5f0179Smacallan {
18227b5f0179Smacallan fdt32_t tmp = cpu_to_fdt32(val);
18237b5f0179Smacallan return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
18247b5f0179Smacallan }
18257b5f0179Smacallan
18267b5f0179Smacallan /**
18277b5f0179Smacallan * fdt_appendprop_u64 - append a 64-bit integer value to a property
18287b5f0179Smacallan * @fdt: pointer to the device tree blob
18297b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
18307b5f0179Smacallan * @name: name of the property to change
18317b5f0179Smacallan * @val: 64-bit integer value to append to the property (native endian)
18327b5f0179Smacallan *
18337b5f0179Smacallan * fdt_appendprop_u64() appends the given 64-bit integer value
18347b5f0179Smacallan * (converting to big-endian if necessary) to the value of the named
18357b5f0179Smacallan * property in the given node, or creates a new property with that
18367b5f0179Smacallan * value if it does not already exist.
18377b5f0179Smacallan *
18387b5f0179Smacallan * This function may insert data into the blob, and will therefore
18397b5f0179Smacallan * change the offsets of some existing nodes.
18407b5f0179Smacallan *
18417b5f0179Smacallan * returns:
18427b5f0179Smacallan * 0, on success
18437b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
18447b5f0179Smacallan * contain the new property value
18457b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
18467b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
18477b5f0179Smacallan * -FDT_ERR_BADMAGIC,
18487b5f0179Smacallan * -FDT_ERR_BADVERSION,
18497b5f0179Smacallan * -FDT_ERR_BADSTATE,
18507b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
18517b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
18527b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
18537b5f0179Smacallan */
fdt_appendprop_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)18547b5f0179Smacallan static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
18557b5f0179Smacallan const char *name, uint64_t val)
18567b5f0179Smacallan {
18577b5f0179Smacallan fdt64_t tmp = cpu_to_fdt64(val);
18587b5f0179Smacallan return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
18597b5f0179Smacallan }
18607b5f0179Smacallan
18617b5f0179Smacallan /**
18627b5f0179Smacallan * fdt_appendprop_cell - append a single cell value to a property
18637b5f0179Smacallan *
18647b5f0179Smacallan * This is an alternative name for fdt_appendprop_u32()
18657b5f0179Smacallan */
fdt_appendprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)18667b5f0179Smacallan static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
18677b5f0179Smacallan const char *name, uint32_t val)
18687b5f0179Smacallan {
18697b5f0179Smacallan return fdt_appendprop_u32(fdt, nodeoffset, name, val);
18707b5f0179Smacallan }
18717b5f0179Smacallan
18727b5f0179Smacallan /**
18737b5f0179Smacallan * fdt_appendprop_string - append a string to a property
18747b5f0179Smacallan * @fdt: pointer to the device tree blob
18757b5f0179Smacallan * @nodeoffset: offset of the node whose property to change
18767b5f0179Smacallan * @name: name of the property to change
18777b5f0179Smacallan * @str: string value to append to the property
18787b5f0179Smacallan *
18797b5f0179Smacallan * fdt_appendprop_string() appends the given string to the value of
18807b5f0179Smacallan * the named property in the given node, or creates a new property
18817b5f0179Smacallan * with that value if it does not already exist.
18827b5f0179Smacallan *
18837b5f0179Smacallan * This function may insert data into the blob, and will therefore
18847b5f0179Smacallan * change the offsets of some existing nodes.
18857b5f0179Smacallan *
18867b5f0179Smacallan * returns:
18877b5f0179Smacallan * 0, on success
18887b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
18897b5f0179Smacallan * contain the new property value
18907b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
18917b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
18927b5f0179Smacallan * -FDT_ERR_BADMAGIC,
18937b5f0179Smacallan * -FDT_ERR_BADVERSION,
18947b5f0179Smacallan * -FDT_ERR_BADSTATE,
18957b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
18967b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
18977b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
18987b5f0179Smacallan */
18997b5f0179Smacallan #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
19007b5f0179Smacallan fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
19017b5f0179Smacallan
19027b5f0179Smacallan /**
1903*b9ee18deSskrll * fdt_appendprop_addrrange - append a address range property
1904*b9ee18deSskrll * @fdt: pointer to the device tree blob
1905*b9ee18deSskrll * @parent: offset of the parent node
1906*b9ee18deSskrll * @nodeoffset: offset of the node to add a property at
1907*b9ee18deSskrll * @name: name of property
1908*b9ee18deSskrll * @addr: start address of a given range
1909*b9ee18deSskrll * @size: size of a given range
1910*b9ee18deSskrll *
1911*b9ee18deSskrll * fdt_appendprop_addrrange() appends an address range value (start
1912*b9ee18deSskrll * address and size) to the value of the named property in the given
1913*b9ee18deSskrll * node, or creates a new property with that value if it does not
1914*b9ee18deSskrll * already exist.
1915*b9ee18deSskrll * If "name" is not specified, a default "reg" is used.
1916*b9ee18deSskrll * Cell sizes are determined by parent's #address-cells and #size-cells.
1917*b9ee18deSskrll *
1918*b9ee18deSskrll * This function may insert data into the blob, and will therefore
1919*b9ee18deSskrll * change the offsets of some existing nodes.
1920*b9ee18deSskrll *
1921*b9ee18deSskrll * returns:
1922*b9ee18deSskrll * 0, on success
1923*b9ee18deSskrll * -FDT_ERR_BADLAYOUT,
1924*b9ee18deSskrll * -FDT_ERR_BADMAGIC,
1925*b9ee18deSskrll * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1926*b9ee18deSskrll * #address-cells property
1927*b9ee18deSskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1928*b9ee18deSskrll * -FDT_ERR_BADSTATE,
1929*b9ee18deSskrll * -FDT_ERR_BADSTRUCTURE,
1930*b9ee18deSskrll * -FDT_ERR_BADVERSION,
1931*b9ee18deSskrll * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size
1932*b9ee18deSskrll * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1933*b9ee18deSskrll * contain a new property
1934*b9ee18deSskrll * -FDT_ERR_TRUNCATED, standard meanings
1935*b9ee18deSskrll */
1936*b9ee18deSskrll int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
1937*b9ee18deSskrll const char *name, uint64_t addr, uint64_t size);
1938*b9ee18deSskrll
1939*b9ee18deSskrll /**
19407b5f0179Smacallan * fdt_delprop - delete a property
19417b5f0179Smacallan * @fdt: pointer to the device tree blob
19427b5f0179Smacallan * @nodeoffset: offset of the node whose property to nop
19437b5f0179Smacallan * @name: name of the property to nop
19447b5f0179Smacallan *
19457b5f0179Smacallan * fdt_del_property() will delete the given property.
19467b5f0179Smacallan *
19477b5f0179Smacallan * This function will delete data from the blob, and will therefore
19487b5f0179Smacallan * change the offsets of some existing nodes.
19497b5f0179Smacallan *
19507b5f0179Smacallan * returns:
19517b5f0179Smacallan * 0, on success
19527b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property
19537b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
19547b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
19557b5f0179Smacallan * -FDT_ERR_BADMAGIC,
19567b5f0179Smacallan * -FDT_ERR_BADVERSION,
19577b5f0179Smacallan * -FDT_ERR_BADSTATE,
19587b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
19597b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
19607b5f0179Smacallan */
19617b5f0179Smacallan int fdt_delprop(void *fdt, int nodeoffset, const char *name);
19627b5f0179Smacallan
19637b5f0179Smacallan /**
19647b5f0179Smacallan * fdt_add_subnode_namelen - creates a new node based on substring
19657b5f0179Smacallan * @fdt: pointer to the device tree blob
19667b5f0179Smacallan * @parentoffset: structure block offset of a node
19677b5f0179Smacallan * @name: name of the subnode to locate
19687b5f0179Smacallan * @namelen: number of characters of name to consider
19697b5f0179Smacallan *
19707b5f0179Smacallan * Identical to fdt_add_subnode(), but use only the first namelen
19717b5f0179Smacallan * characters of name as the name of the new node. This is useful for
19727b5f0179Smacallan * creating subnodes based on a portion of a larger string, such as a
19737b5f0179Smacallan * full path.
19747b5f0179Smacallan */
1975*b9ee18deSskrll #ifndef SWIG /* Not available in Python */
19767b5f0179Smacallan int fdt_add_subnode_namelen(void *fdt, int parentoffset,
19777b5f0179Smacallan const char *name, int namelen);
1978*b9ee18deSskrll #endif
19797b5f0179Smacallan
19807b5f0179Smacallan /**
19817b5f0179Smacallan * fdt_add_subnode - creates a new node
19827b5f0179Smacallan * @fdt: pointer to the device tree blob
19837b5f0179Smacallan * @parentoffset: structure block offset of a node
19847b5f0179Smacallan * @name: name of the subnode to locate
19857b5f0179Smacallan *
19867b5f0179Smacallan * fdt_add_subnode() creates a new node as a subnode of the node at
19877b5f0179Smacallan * structure block offset parentoffset, with the given name (which
19887b5f0179Smacallan * should include the unit address, if any).
19897b5f0179Smacallan *
19907b5f0179Smacallan * This function will insert data into the blob, and will therefore
19917b5f0179Smacallan * change the offsets of some existing nodes.
19927b5f0179Smacallan
19937b5f0179Smacallan * returns:
19942fb928dbSskrll * structure block offset of the created nodeequested subnode (>=0), on
19952fb928dbSskrll * success
19967b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
19972fb928dbSskrll * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
19982fb928dbSskrll * tag
19997b5f0179Smacallan * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
20007b5f0179Smacallan * the given name
20017b5f0179Smacallan * -FDT_ERR_NOSPACE, if there is insufficient free space in the
20027b5f0179Smacallan * blob to contain the new node
20037b5f0179Smacallan * -FDT_ERR_NOSPACE
20047b5f0179Smacallan * -FDT_ERR_BADLAYOUT
20057b5f0179Smacallan * -FDT_ERR_BADMAGIC,
20067b5f0179Smacallan * -FDT_ERR_BADVERSION,
20077b5f0179Smacallan * -FDT_ERR_BADSTATE,
20087b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
20097b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings.
20107b5f0179Smacallan */
20117b5f0179Smacallan int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
20127b5f0179Smacallan
20137b5f0179Smacallan /**
20147b5f0179Smacallan * fdt_del_node - delete a node (subtree)
20157b5f0179Smacallan * @fdt: pointer to the device tree blob
20167b5f0179Smacallan * @nodeoffset: offset of the node to nop
20177b5f0179Smacallan *
20187b5f0179Smacallan * fdt_del_node() will remove the given node, including all its
20197b5f0179Smacallan * subnodes if any, from the blob.
20207b5f0179Smacallan *
20217b5f0179Smacallan * This function will delete data from the blob, and will therefore
20227b5f0179Smacallan * change the offsets of some existing nodes.
20237b5f0179Smacallan *
20247b5f0179Smacallan * returns:
20257b5f0179Smacallan * 0, on success
20267b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
20277b5f0179Smacallan * -FDT_ERR_BADLAYOUT,
20287b5f0179Smacallan * -FDT_ERR_BADMAGIC,
20297b5f0179Smacallan * -FDT_ERR_BADVERSION,
20307b5f0179Smacallan * -FDT_ERR_BADSTATE,
20317b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE,
20327b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings
20337b5f0179Smacallan */
20347b5f0179Smacallan int fdt_del_node(void *fdt, int nodeoffset);
20357b5f0179Smacallan
20362fb928dbSskrll /**
20372fb928dbSskrll * fdt_overlay_apply - Applies a DT overlay on a base DT
20382fb928dbSskrll * @fdt: pointer to the base device tree blob
20392fb928dbSskrll * @fdto: pointer to the device tree overlay blob
20402fb928dbSskrll *
20412fb928dbSskrll * fdt_overlay_apply() will apply the given device tree overlay on the
20422fb928dbSskrll * given base device tree.
20432fb928dbSskrll *
20442fb928dbSskrll * Expect the base device tree to be modified, even if the function
20452fb928dbSskrll * returns an error.
20462fb928dbSskrll *
20472fb928dbSskrll * returns:
20482fb928dbSskrll * 0, on success
20492fb928dbSskrll * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
20502fb928dbSskrll * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
20512fb928dbSskrll * properties in the base DT
20522fb928dbSskrll * -FDT_ERR_BADPHANDLE,
20532fb928dbSskrll * -FDT_ERR_BADOVERLAY,
20542fb928dbSskrll * -FDT_ERR_NOPHANDLES,
20552fb928dbSskrll * -FDT_ERR_INTERNAL,
20562fb928dbSskrll * -FDT_ERR_BADLAYOUT,
20572fb928dbSskrll * -FDT_ERR_BADMAGIC,
20582fb928dbSskrll * -FDT_ERR_BADOFFSET,
20592fb928dbSskrll * -FDT_ERR_BADPATH,
20602fb928dbSskrll * -FDT_ERR_BADVERSION,
20612fb928dbSskrll * -FDT_ERR_BADSTRUCTURE,
20622fb928dbSskrll * -FDT_ERR_BADSTATE,
20632fb928dbSskrll * -FDT_ERR_TRUNCATED, standard meanings
20642fb928dbSskrll */
20652fb928dbSskrll int fdt_overlay_apply(void *fdt, void *fdto);
20662fb928dbSskrll
20677b5f0179Smacallan /**********************************************************************/
20687b5f0179Smacallan /* Debugging / informational functions */
20697b5f0179Smacallan /**********************************************************************/
20707b5f0179Smacallan
20717b5f0179Smacallan const char *fdt_strerror(int errval);
20727b5f0179Smacallan
2073*b9ee18deSskrll #endif /* LIBFDT_H */
2074