1*5a485aa9Sskrll /* $NetBSD: libfdt.h,v 1.1.1.3 2019/12/22 12:30:38 skrll Exp $ */
2fc885a42Sskrll
3*5a485aa9Sskrll /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
4*5a485aa9Sskrll #ifndef LIBFDT_H
5*5a485aa9Sskrll #define LIBFDT_H
66233fbe7Smacallan /*
76233fbe7Smacallan * libfdt - Flat Device Tree manipulation
86233fbe7Smacallan * Copyright (C) 2006 David Gibson, IBM Corporation.
96233fbe7Smacallan */
106233fbe7Smacallan
116233fbe7Smacallan #include <libfdt_env.h>
126233fbe7Smacallan #include <fdt.h>
136233fbe7Smacallan
14*5a485aa9Sskrll #define FDT_FIRST_SUPPORTED_VERSION 0x02
156233fbe7Smacallan #define FDT_LAST_SUPPORTED_VERSION 0x11
166233fbe7Smacallan
176233fbe7Smacallan /* Error codes: informative error codes */
186233fbe7Smacallan #define FDT_ERR_NOTFOUND 1
196233fbe7Smacallan /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
206233fbe7Smacallan #define FDT_ERR_EXISTS 2
21fc885a42Sskrll /* FDT_ERR_EXISTS: Attempted to create a node or property which
226233fbe7Smacallan * already exists */
236233fbe7Smacallan #define FDT_ERR_NOSPACE 3
246233fbe7Smacallan /* FDT_ERR_NOSPACE: Operation needed to expand the device
256233fbe7Smacallan * tree, but its buffer did not have sufficient space to
266233fbe7Smacallan * contain the expanded tree. Use fdt_open_into() to move the
276233fbe7Smacallan * device tree to a buffer with more space. */
286233fbe7Smacallan
296233fbe7Smacallan /* Error codes: codes for bad parameters */
306233fbe7Smacallan #define FDT_ERR_BADOFFSET 4
316233fbe7Smacallan /* FDT_ERR_BADOFFSET: Function was passed a structure block
326233fbe7Smacallan * offset which is out-of-bounds, or which points to an
336233fbe7Smacallan * unsuitable part of the structure for the operation. */
346233fbe7Smacallan #define FDT_ERR_BADPATH 5
356233fbe7Smacallan /* FDT_ERR_BADPATH: Function was passed a badly formatted path
366233fbe7Smacallan * (e.g. missing a leading / for a function which requires an
376233fbe7Smacallan * absolute path) */
386233fbe7Smacallan #define FDT_ERR_BADPHANDLE 6
39fc885a42Sskrll /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.
40fc885a42Sskrll * This can be caused either by an invalid phandle property
41fc885a42Sskrll * length, or the phandle value was either 0 or -1, which are
42fc885a42Sskrll * not permitted. */
436233fbe7Smacallan #define FDT_ERR_BADSTATE 7
446233fbe7Smacallan /* FDT_ERR_BADSTATE: Function was passed an incomplete device
456233fbe7Smacallan * tree created by the sequential-write functions, which is
466233fbe7Smacallan * not sufficiently complete for the requested operation. */
476233fbe7Smacallan
486233fbe7Smacallan /* Error codes: codes for bad device tree blobs */
496233fbe7Smacallan #define FDT_ERR_TRUNCATED 8
50*5a485aa9Sskrll /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly
51*5a485aa9Sskrll * terminated (overflows, goes outside allowed bounds, or
52*5a485aa9Sskrll * isn't properly terminated). */
536233fbe7Smacallan #define FDT_ERR_BADMAGIC 9
546233fbe7Smacallan /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
556233fbe7Smacallan * device tree at all - it is missing the flattened device
566233fbe7Smacallan * tree magic number. */
576233fbe7Smacallan #define FDT_ERR_BADVERSION 10
586233fbe7Smacallan /* FDT_ERR_BADVERSION: Given device tree has a version which
596233fbe7Smacallan * can't be handled by the requested operation. For
606233fbe7Smacallan * read-write functions, this may mean that fdt_open_into() is
616233fbe7Smacallan * required to convert the tree to the expected version. */
626233fbe7Smacallan #define FDT_ERR_BADSTRUCTURE 11
636233fbe7Smacallan /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
646233fbe7Smacallan * structure block or other serious error (e.g. misnested
656233fbe7Smacallan * nodes, or subnodes preceding properties). */
666233fbe7Smacallan #define FDT_ERR_BADLAYOUT 12
676233fbe7Smacallan /* FDT_ERR_BADLAYOUT: For read-write functions, the given
686233fbe7Smacallan * device tree has it's sub-blocks in an order that the
696233fbe7Smacallan * function can't handle (memory reserve map, then structure,
706233fbe7Smacallan * then strings). Use fdt_open_into() to reorganize the tree
716233fbe7Smacallan * into a form suitable for the read-write operations. */
726233fbe7Smacallan
736233fbe7Smacallan /* "Can't happen" error indicating a bug in libfdt */
746233fbe7Smacallan #define FDT_ERR_INTERNAL 13
756233fbe7Smacallan /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
766233fbe7Smacallan * Should never be returned, if it is, it indicates a bug in
776233fbe7Smacallan * libfdt itself. */
786233fbe7Smacallan
796233fbe7Smacallan /* Errors in device tree content */
806233fbe7Smacallan #define FDT_ERR_BADNCELLS 14
816233fbe7Smacallan /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
826233fbe7Smacallan * or similar property with a bad format or value */
836233fbe7Smacallan
846233fbe7Smacallan #define FDT_ERR_BADVALUE 15
856233fbe7Smacallan /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
866233fbe7Smacallan * value. For example: a property expected to contain a string list
876233fbe7Smacallan * is not NUL-terminated within the length of its value. */
886233fbe7Smacallan
89fc885a42Sskrll #define FDT_ERR_BADOVERLAY 16
90fc885a42Sskrll /* FDT_ERR_BADOVERLAY: The device tree overlay, while
91fc885a42Sskrll * correctly structured, cannot be applied due to some
92fc885a42Sskrll * unexpected or missing value, property or node. */
93fc885a42Sskrll
94fc885a42Sskrll #define FDT_ERR_NOPHANDLES 17
95fc885a42Sskrll /* FDT_ERR_NOPHANDLES: The device tree doesn't have any
96fc885a42Sskrll * phandle available anymore without causing an overflow */
97fc885a42Sskrll
98*5a485aa9Sskrll #define FDT_ERR_BADFLAGS 18
99*5a485aa9Sskrll /* FDT_ERR_BADFLAGS: The function was passed a flags field that
100*5a485aa9Sskrll * contains invalid flags or an invalid combination of flags. */
101*5a485aa9Sskrll
102*5a485aa9Sskrll #define FDT_ERR_MAX 18
103*5a485aa9Sskrll
104*5a485aa9Sskrll /* constants */
105*5a485aa9Sskrll #define FDT_MAX_PHANDLE 0xfffffffe
106*5a485aa9Sskrll /* Valid values for phandles range from 1 to 2^32-2. */
1076233fbe7Smacallan
1086233fbe7Smacallan /**********************************************************************/
1096233fbe7Smacallan /* Low-level functions (you probably don't need these) */
1106233fbe7Smacallan /**********************************************************************/
1116233fbe7Smacallan
112*5a485aa9Sskrll #ifndef SWIG /* This function is not useful in Python */
1136233fbe7Smacallan const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
114*5a485aa9Sskrll #endif
fdt_offset_ptr_w(void * fdt,int offset,int checklen)1156233fbe7Smacallan static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
1166233fbe7Smacallan {
1176233fbe7Smacallan return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
1186233fbe7Smacallan }
1196233fbe7Smacallan
1206233fbe7Smacallan uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
1216233fbe7Smacallan
122*5a485aa9Sskrll /*
123*5a485aa9Sskrll * Alignment helpers:
124*5a485aa9Sskrll * These helpers access words from a device tree blob. They're
125*5a485aa9Sskrll * built to work even with unaligned pointers on platforms (ike
126*5a485aa9Sskrll * ARM) that don't like unaligned loads and stores
127*5a485aa9Sskrll */
128*5a485aa9Sskrll
fdt32_ld(const fdt32_t * p)129*5a485aa9Sskrll static inline uint32_t fdt32_ld(const fdt32_t *p)
130*5a485aa9Sskrll {
131*5a485aa9Sskrll const uint8_t *bp = (const uint8_t *)p;
132*5a485aa9Sskrll
133*5a485aa9Sskrll return ((uint32_t)bp[0] << 24)
134*5a485aa9Sskrll | ((uint32_t)bp[1] << 16)
135*5a485aa9Sskrll | ((uint32_t)bp[2] << 8)
136*5a485aa9Sskrll | bp[3];
137*5a485aa9Sskrll }
138*5a485aa9Sskrll
fdt32_st(void * property,uint32_t value)139*5a485aa9Sskrll static inline void fdt32_st(void *property, uint32_t value)
140*5a485aa9Sskrll {
141*5a485aa9Sskrll uint8_t *bp = property;
142*5a485aa9Sskrll
143*5a485aa9Sskrll bp[0] = value >> 24;
144*5a485aa9Sskrll bp[1] = (value >> 16) & 0xff;
145*5a485aa9Sskrll bp[2] = (value >> 8) & 0xff;
146*5a485aa9Sskrll bp[3] = value & 0xff;
147*5a485aa9Sskrll }
148*5a485aa9Sskrll
fdt64_ld(const fdt64_t * p)149*5a485aa9Sskrll static inline uint64_t fdt64_ld(const fdt64_t *p)
150*5a485aa9Sskrll {
151*5a485aa9Sskrll const uint8_t *bp = (const uint8_t *)p;
152*5a485aa9Sskrll
153*5a485aa9Sskrll return ((uint64_t)bp[0] << 56)
154*5a485aa9Sskrll | ((uint64_t)bp[1] << 48)
155*5a485aa9Sskrll | ((uint64_t)bp[2] << 40)
156*5a485aa9Sskrll | ((uint64_t)bp[3] << 32)
157*5a485aa9Sskrll | ((uint64_t)bp[4] << 24)
158*5a485aa9Sskrll | ((uint64_t)bp[5] << 16)
159*5a485aa9Sskrll | ((uint64_t)bp[6] << 8)
160*5a485aa9Sskrll | bp[7];
161*5a485aa9Sskrll }
162*5a485aa9Sskrll
fdt64_st(void * property,uint64_t value)163*5a485aa9Sskrll static inline void fdt64_st(void *property, uint64_t value)
164*5a485aa9Sskrll {
165*5a485aa9Sskrll uint8_t *bp = property;
166*5a485aa9Sskrll
167*5a485aa9Sskrll bp[0] = value >> 56;
168*5a485aa9Sskrll bp[1] = (value >> 48) & 0xff;
169*5a485aa9Sskrll bp[2] = (value >> 40) & 0xff;
170*5a485aa9Sskrll bp[3] = (value >> 32) & 0xff;
171*5a485aa9Sskrll bp[4] = (value >> 24) & 0xff;
172*5a485aa9Sskrll bp[5] = (value >> 16) & 0xff;
173*5a485aa9Sskrll bp[6] = (value >> 8) & 0xff;
174*5a485aa9Sskrll bp[7] = value & 0xff;
175*5a485aa9Sskrll }
176*5a485aa9Sskrll
1776233fbe7Smacallan /**********************************************************************/
1786233fbe7Smacallan /* Traversal functions */
1796233fbe7Smacallan /**********************************************************************/
1806233fbe7Smacallan
1816233fbe7Smacallan int fdt_next_node(const void *fdt, int offset, int *depth);
1826233fbe7Smacallan
1836233fbe7Smacallan /**
1846233fbe7Smacallan * fdt_first_subnode() - get offset of first direct subnode
1856233fbe7Smacallan *
1866233fbe7Smacallan * @fdt: FDT blob
1876233fbe7Smacallan * @offset: Offset of node to check
1886233fbe7Smacallan * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
1896233fbe7Smacallan */
1906233fbe7Smacallan int fdt_first_subnode(const void *fdt, int offset);
1916233fbe7Smacallan
1926233fbe7Smacallan /**
1936233fbe7Smacallan * fdt_next_subnode() - get offset of next direct subnode
1946233fbe7Smacallan *
1956233fbe7Smacallan * After first calling fdt_first_subnode(), call this function repeatedly to
1966233fbe7Smacallan * get direct subnodes of a parent node.
1976233fbe7Smacallan *
1986233fbe7Smacallan * @fdt: FDT blob
1996233fbe7Smacallan * @offset: Offset of previous subnode
2006233fbe7Smacallan * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
2016233fbe7Smacallan * subnodes
2026233fbe7Smacallan */
2036233fbe7Smacallan int fdt_next_subnode(const void *fdt, int offset);
2046233fbe7Smacallan
205fc885a42Sskrll /**
206fc885a42Sskrll * fdt_for_each_subnode - iterate over all subnodes of a parent
207fc885a42Sskrll *
208fc885a42Sskrll * @node: child node (int, lvalue)
209fc885a42Sskrll * @fdt: FDT blob (const void *)
210fc885a42Sskrll * @parent: parent node (int)
211fc885a42Sskrll *
212fc885a42Sskrll * This is actually a wrapper around a for loop and would be used like so:
213fc885a42Sskrll *
214fc885a42Sskrll * fdt_for_each_subnode(node, fdt, parent) {
215fc885a42Sskrll * Use node
216fc885a42Sskrll * ...
217fc885a42Sskrll * }
218fc885a42Sskrll *
219*5a485aa9Sskrll * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
220fc885a42Sskrll * Error handling
221fc885a42Sskrll * }
222fc885a42Sskrll *
223fc885a42Sskrll * Note that this is implemented as a macro and @node is used as
224fc885a42Sskrll * iterator in the loop. The parent variable be constant or even a
225fc885a42Sskrll * literal.
226fc885a42Sskrll *
227fc885a42Sskrll */
228fc885a42Sskrll #define fdt_for_each_subnode(node, fdt, parent) \
229fc885a42Sskrll for (node = fdt_first_subnode(fdt, parent); \
230fc885a42Sskrll node >= 0; \
231fc885a42Sskrll node = fdt_next_subnode(fdt, node))
232fc885a42Sskrll
2336233fbe7Smacallan /**********************************************************************/
2346233fbe7Smacallan /* General functions */
2356233fbe7Smacallan /**********************************************************************/
2366233fbe7Smacallan #define fdt_get_header(fdt, field) \
237*5a485aa9Sskrll (fdt32_ld(&((const struct fdt_header *)(fdt))->field))
2386233fbe7Smacallan #define fdt_magic(fdt) (fdt_get_header(fdt, magic))
2396233fbe7Smacallan #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
2406233fbe7Smacallan #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
2416233fbe7Smacallan #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
2426233fbe7Smacallan #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
2436233fbe7Smacallan #define fdt_version(fdt) (fdt_get_header(fdt, version))
2446233fbe7Smacallan #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
2456233fbe7Smacallan #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
2466233fbe7Smacallan #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
2476233fbe7Smacallan #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
2486233fbe7Smacallan
249*5a485aa9Sskrll #define fdt_set_hdr_(name) \
2506233fbe7Smacallan static inline void fdt_set_##name(void *fdt, uint32_t val) \
2516233fbe7Smacallan { \
2526233fbe7Smacallan struct fdt_header *fdth = (struct fdt_header *)fdt; \
2536233fbe7Smacallan fdth->name = cpu_to_fdt32(val); \
2546233fbe7Smacallan }
255*5a485aa9Sskrll fdt_set_hdr_(magic);
256*5a485aa9Sskrll fdt_set_hdr_(totalsize);
257*5a485aa9Sskrll fdt_set_hdr_(off_dt_struct);
258*5a485aa9Sskrll fdt_set_hdr_(off_dt_strings);
259*5a485aa9Sskrll fdt_set_hdr_(off_mem_rsvmap);
260*5a485aa9Sskrll fdt_set_hdr_(version);
261*5a485aa9Sskrll fdt_set_hdr_(last_comp_version);
262*5a485aa9Sskrll fdt_set_hdr_(boot_cpuid_phys);
263*5a485aa9Sskrll fdt_set_hdr_(size_dt_strings);
264*5a485aa9Sskrll fdt_set_hdr_(size_dt_struct);
265*5a485aa9Sskrll #undef fdt_set_hdr_
2666233fbe7Smacallan
2676233fbe7Smacallan /**
268*5a485aa9Sskrll * fdt_header_size - return the size of the tree's header
269*5a485aa9Sskrll * @fdt: pointer to a flattened device tree
270*5a485aa9Sskrll */
271*5a485aa9Sskrll size_t fdt_header_size_(uint32_t version);
fdt_header_size(const void * fdt)272*5a485aa9Sskrll static inline size_t fdt_header_size(const void *fdt)
273*5a485aa9Sskrll {
274*5a485aa9Sskrll return fdt_header_size_(fdt_version(fdt));
275*5a485aa9Sskrll }
276*5a485aa9Sskrll
277*5a485aa9Sskrll /**
278*5a485aa9Sskrll * fdt_check_header - sanity check a device tree header
279*5a485aa9Sskrll
2806233fbe7Smacallan * @fdt: pointer to data which might be a flattened device tree
2816233fbe7Smacallan *
2826233fbe7Smacallan * fdt_check_header() checks that the given buffer contains what
283*5a485aa9Sskrll * appears to be a flattened device tree, and that the header contains
284*5a485aa9Sskrll * valid information (to the extent that can be determined from the
285*5a485aa9Sskrll * header alone).
2866233fbe7Smacallan *
2876233fbe7Smacallan * returns:
2886233fbe7Smacallan * 0, if the buffer appears to contain a valid device tree
2896233fbe7Smacallan * -FDT_ERR_BADMAGIC,
2906233fbe7Smacallan * -FDT_ERR_BADVERSION,
291*5a485aa9Sskrll * -FDT_ERR_BADSTATE,
292*5a485aa9Sskrll * -FDT_ERR_TRUNCATED, standard meanings, as above
2936233fbe7Smacallan */
2946233fbe7Smacallan int fdt_check_header(const void *fdt);
2956233fbe7Smacallan
2966233fbe7Smacallan /**
2976233fbe7Smacallan * fdt_move - move a device tree around in memory
2986233fbe7Smacallan * @fdt: pointer to the device tree to move
2996233fbe7Smacallan * @buf: pointer to memory where the device is to be moved
3006233fbe7Smacallan * @bufsize: size of the memory space at buf
3016233fbe7Smacallan *
3026233fbe7Smacallan * fdt_move() relocates, if possible, the device tree blob located at
3036233fbe7Smacallan * fdt to the buffer at buf of size bufsize. The buffer may overlap
3046233fbe7Smacallan * with the existing device tree blob at fdt. Therefore,
3056233fbe7Smacallan * fdt_move(fdt, fdt, fdt_totalsize(fdt))
3066233fbe7Smacallan * should always succeed.
3076233fbe7Smacallan *
3086233fbe7Smacallan * returns:
3096233fbe7Smacallan * 0, on success
3106233fbe7Smacallan * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
3116233fbe7Smacallan * -FDT_ERR_BADMAGIC,
3126233fbe7Smacallan * -FDT_ERR_BADVERSION,
3136233fbe7Smacallan * -FDT_ERR_BADSTATE, standard meanings
3146233fbe7Smacallan */
3156233fbe7Smacallan int fdt_move(const void *fdt, void *buf, int bufsize);
3166233fbe7Smacallan
3176233fbe7Smacallan /**********************************************************************/
3186233fbe7Smacallan /* Read-only functions */
3196233fbe7Smacallan /**********************************************************************/
3206233fbe7Smacallan
321*5a485aa9Sskrll int fdt_check_full(const void *fdt, size_t bufsize);
322*5a485aa9Sskrll
323*5a485aa9Sskrll /**
324*5a485aa9Sskrll * fdt_get_string - retrieve a string from the strings block of a device tree
325*5a485aa9Sskrll * @fdt: pointer to the device tree blob
326*5a485aa9Sskrll * @stroffset: offset of the string within the strings block (native endian)
327*5a485aa9Sskrll * @lenp: optional pointer to return the string's length
328*5a485aa9Sskrll *
329*5a485aa9Sskrll * fdt_get_string() retrieves a pointer to a single string from the
330*5a485aa9Sskrll * strings block of the device tree blob at fdt, and optionally also
331*5a485aa9Sskrll * returns the string's length in *lenp.
332*5a485aa9Sskrll *
333*5a485aa9Sskrll * returns:
334*5a485aa9Sskrll * a pointer to the string, on success
335*5a485aa9Sskrll * NULL, if stroffset is out of bounds, or doesn't point to a valid string
336*5a485aa9Sskrll */
337*5a485aa9Sskrll const char *fdt_get_string(const void *fdt, int stroffset, int *lenp);
338*5a485aa9Sskrll
3396233fbe7Smacallan /**
3406233fbe7Smacallan * fdt_string - retrieve a string from the strings block of a device tree
3416233fbe7Smacallan * @fdt: pointer to the device tree blob
3426233fbe7Smacallan * @stroffset: offset of the string within the strings block (native endian)
3436233fbe7Smacallan *
3446233fbe7Smacallan * fdt_string() retrieves a pointer to a single string from the
3456233fbe7Smacallan * strings block of the device tree blob at fdt.
3466233fbe7Smacallan *
3476233fbe7Smacallan * returns:
3486233fbe7Smacallan * a pointer to the string, on success
349*5a485aa9Sskrll * NULL, if stroffset is out of bounds, or doesn't point to a valid string
3506233fbe7Smacallan */
3516233fbe7Smacallan const char *fdt_string(const void *fdt, int stroffset);
3526233fbe7Smacallan
3536233fbe7Smacallan /**
354*5a485aa9Sskrll * fdt_find_max_phandle - find and return the highest phandle in a tree
355*5a485aa9Sskrll * @fdt: pointer to the device tree blob
356*5a485aa9Sskrll * @phandle: return location for the highest phandle value found in the tree
357*5a485aa9Sskrll *
358*5a485aa9Sskrll * fdt_find_max_phandle() finds the highest phandle value in the given device
359*5a485aa9Sskrll * tree. The value returned in @phandle is only valid if the function returns
360*5a485aa9Sskrll * success.
361*5a485aa9Sskrll *
362*5a485aa9Sskrll * returns:
363*5a485aa9Sskrll * 0 on success or a negative error code on failure
364*5a485aa9Sskrll */
365*5a485aa9Sskrll int fdt_find_max_phandle(const void *fdt, uint32_t *phandle);
366*5a485aa9Sskrll
367*5a485aa9Sskrll /**
368fc885a42Sskrll * fdt_get_max_phandle - retrieves the highest phandle in a tree
369fc885a42Sskrll * @fdt: pointer to the device tree blob
370fc885a42Sskrll *
371fc885a42Sskrll * fdt_get_max_phandle retrieves the highest phandle in the given
372fc885a42Sskrll * device tree. This will ignore badly formatted phandles, or phandles
373fc885a42Sskrll * with a value of 0 or -1.
374fc885a42Sskrll *
375*5a485aa9Sskrll * This function is deprecated in favour of fdt_find_max_phandle().
376*5a485aa9Sskrll *
377fc885a42Sskrll * returns:
378fc885a42Sskrll * the highest phandle on success
379fc885a42Sskrll * 0, if no phandle was found in the device tree
380fc885a42Sskrll * -1, if an error occurred
381fc885a42Sskrll */
fdt_get_max_phandle(const void * fdt)382*5a485aa9Sskrll static inline uint32_t fdt_get_max_phandle(const void *fdt)
383*5a485aa9Sskrll {
384*5a485aa9Sskrll uint32_t phandle;
385*5a485aa9Sskrll int err;
386*5a485aa9Sskrll
387*5a485aa9Sskrll err = fdt_find_max_phandle(fdt, &phandle);
388*5a485aa9Sskrll if (err < 0)
389*5a485aa9Sskrll return (uint32_t)-1;
390*5a485aa9Sskrll
391*5a485aa9Sskrll return phandle;
392*5a485aa9Sskrll }
393*5a485aa9Sskrll
394*5a485aa9Sskrll /**
395*5a485aa9Sskrll * fdt_generate_phandle - return a new, unused phandle for a device tree blob
396*5a485aa9Sskrll * @fdt: pointer to the device tree blob
397*5a485aa9Sskrll * @phandle: return location for the new phandle
398*5a485aa9Sskrll *
399*5a485aa9Sskrll * Walks the device tree blob and looks for the highest phandle value. On
400*5a485aa9Sskrll * success, the new, unused phandle value (one higher than the previously
401*5a485aa9Sskrll * highest phandle value in the device tree blob) will be returned in the
402*5a485aa9Sskrll * @phandle parameter.
403*5a485aa9Sskrll *
404*5a485aa9Sskrll * Returns:
405*5a485aa9Sskrll * 0 on success or a negative error-code on failure
406*5a485aa9Sskrll */
407*5a485aa9Sskrll int fdt_generate_phandle(const void *fdt, uint32_t *phandle);
408fc885a42Sskrll
409fc885a42Sskrll /**
4106233fbe7Smacallan * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
4116233fbe7Smacallan * @fdt: pointer to the device tree blob
4126233fbe7Smacallan *
4136233fbe7Smacallan * Returns the number of entries in the device tree blob's memory
4146233fbe7Smacallan * reservation map. This does not include the terminating 0,0 entry
4156233fbe7Smacallan * or any other (0,0) entries reserved for expansion.
4166233fbe7Smacallan *
4176233fbe7Smacallan * returns:
4186233fbe7Smacallan * the number of entries
4196233fbe7Smacallan */
4206233fbe7Smacallan int fdt_num_mem_rsv(const void *fdt);
4216233fbe7Smacallan
4226233fbe7Smacallan /**
4236233fbe7Smacallan * fdt_get_mem_rsv - retrieve one memory reserve map entry
4246233fbe7Smacallan * @fdt: pointer to the device tree blob
4256233fbe7Smacallan * @address, @size: pointers to 64-bit variables
4266233fbe7Smacallan *
4276233fbe7Smacallan * On success, *address and *size will contain the address and size of
4286233fbe7Smacallan * the n-th reserve map entry from the device tree blob, in
4296233fbe7Smacallan * native-endian format.
4306233fbe7Smacallan *
4316233fbe7Smacallan * returns:
4326233fbe7Smacallan * 0, on success
4336233fbe7Smacallan * -FDT_ERR_BADMAGIC,
4346233fbe7Smacallan * -FDT_ERR_BADVERSION,
4356233fbe7Smacallan * -FDT_ERR_BADSTATE, standard meanings
4366233fbe7Smacallan */
4376233fbe7Smacallan int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
4386233fbe7Smacallan
4396233fbe7Smacallan /**
4406233fbe7Smacallan * fdt_subnode_offset_namelen - find a subnode based on substring
4416233fbe7Smacallan * @fdt: pointer to the device tree blob
4426233fbe7Smacallan * @parentoffset: structure block offset of a node
4436233fbe7Smacallan * @name: name of the subnode to locate
4446233fbe7Smacallan * @namelen: number of characters of name to consider
4456233fbe7Smacallan *
4466233fbe7Smacallan * Identical to fdt_subnode_offset(), but only examine the first
4476233fbe7Smacallan * namelen characters of name for matching the subnode name. This is
4486233fbe7Smacallan * useful for finding subnodes based on a portion of a larger string,
4496233fbe7Smacallan * such as a full path.
4506233fbe7Smacallan */
451*5a485aa9Sskrll #ifndef SWIG /* Not available in Python */
4526233fbe7Smacallan int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
4536233fbe7Smacallan const char *name, int namelen);
454*5a485aa9Sskrll #endif
4556233fbe7Smacallan /**
4566233fbe7Smacallan * fdt_subnode_offset - find a subnode of a given node
4576233fbe7Smacallan * @fdt: pointer to the device tree blob
4586233fbe7Smacallan * @parentoffset: structure block offset of a node
4596233fbe7Smacallan * @name: name of the subnode to locate
4606233fbe7Smacallan *
4616233fbe7Smacallan * fdt_subnode_offset() finds a subnode of the node at structure block
4626233fbe7Smacallan * offset parentoffset with the given name. name may include a unit
4636233fbe7Smacallan * address, in which case fdt_subnode_offset() will find the subnode
4646233fbe7Smacallan * with that unit address, or the unit address may be omitted, in
4656233fbe7Smacallan * which case fdt_subnode_offset() will find an arbitrary subnode
4666233fbe7Smacallan * whose name excluding unit address matches the given name.
4676233fbe7Smacallan *
4686233fbe7Smacallan * returns:
4696233fbe7Smacallan * structure block offset of the requested subnode (>=0), on success
4706233fbe7Smacallan * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
471fc885a42Sskrll * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
472fc885a42Sskrll * tag
4736233fbe7Smacallan * -FDT_ERR_BADMAGIC,
4746233fbe7Smacallan * -FDT_ERR_BADVERSION,
4756233fbe7Smacallan * -FDT_ERR_BADSTATE,
4766233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
4776233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings.
4786233fbe7Smacallan */
4796233fbe7Smacallan int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
4806233fbe7Smacallan
4816233fbe7Smacallan /**
4826233fbe7Smacallan * fdt_path_offset_namelen - find a tree node by its full path
4836233fbe7Smacallan * @fdt: pointer to the device tree blob
4846233fbe7Smacallan * @path: full path of the node to locate
4856233fbe7Smacallan * @namelen: number of characters of path to consider
4866233fbe7Smacallan *
4876233fbe7Smacallan * Identical to fdt_path_offset(), but only consider the first namelen
4886233fbe7Smacallan * characters of path as the path name.
4896233fbe7Smacallan */
490*5a485aa9Sskrll #ifndef SWIG /* Not available in Python */
4916233fbe7Smacallan int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
492*5a485aa9Sskrll #endif
4936233fbe7Smacallan
4946233fbe7Smacallan /**
4956233fbe7Smacallan * fdt_path_offset - find a tree node by its full path
4966233fbe7Smacallan * @fdt: pointer to the device tree blob
4976233fbe7Smacallan * @path: full path of the node to locate
4986233fbe7Smacallan *
4996233fbe7Smacallan * fdt_path_offset() finds a node of a given path in the device tree.
5006233fbe7Smacallan * Each path component may omit the unit address portion, but the
5016233fbe7Smacallan * results of this are undefined if any such path component is
5026233fbe7Smacallan * ambiguous (that is if there are multiple nodes at the relevant
5036233fbe7Smacallan * level matching the given component, differentiated only by unit
5046233fbe7Smacallan * address).
5056233fbe7Smacallan *
5066233fbe7Smacallan * returns:
507fc885a42Sskrll * structure block offset of the node with the requested path (>=0), on
508fc885a42Sskrll * success
5096233fbe7Smacallan * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
5106233fbe7Smacallan * -FDT_ERR_NOTFOUND, if the requested node does not exist
5116233fbe7Smacallan * -FDT_ERR_BADMAGIC,
5126233fbe7Smacallan * -FDT_ERR_BADVERSION,
5136233fbe7Smacallan * -FDT_ERR_BADSTATE,
5146233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
5156233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings.
5166233fbe7Smacallan */
5176233fbe7Smacallan int fdt_path_offset(const void *fdt, const char *path);
5186233fbe7Smacallan
5196233fbe7Smacallan /**
5206233fbe7Smacallan * fdt_get_name - retrieve the name of a given node
5216233fbe7Smacallan * @fdt: pointer to the device tree blob
5226233fbe7Smacallan * @nodeoffset: structure block offset of the starting node
5236233fbe7Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
5246233fbe7Smacallan *
5256233fbe7Smacallan * fdt_get_name() retrieves the name (including unit address) of the
5266233fbe7Smacallan * device tree node at structure block offset nodeoffset. If lenp is
5276233fbe7Smacallan * non-NULL, the length of this name is also returned, in the integer
5286233fbe7Smacallan * pointed to by lenp.
5296233fbe7Smacallan *
5306233fbe7Smacallan * returns:
5316233fbe7Smacallan * pointer to the node's name, on success
532fc885a42Sskrll * If lenp is non-NULL, *lenp contains the length of that name
533fc885a42Sskrll * (>=0)
5346233fbe7Smacallan * NULL, on error
5356233fbe7Smacallan * if lenp is non-NULL *lenp contains an error code (<0):
536fc885a42Sskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
537fc885a42Sskrll * tag
5386233fbe7Smacallan * -FDT_ERR_BADMAGIC,
5396233fbe7Smacallan * -FDT_ERR_BADVERSION,
5406233fbe7Smacallan * -FDT_ERR_BADSTATE, standard meanings
5416233fbe7Smacallan */
5426233fbe7Smacallan const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
5436233fbe7Smacallan
5446233fbe7Smacallan /**
5456233fbe7Smacallan * fdt_first_property_offset - find the offset of a node's first property
5466233fbe7Smacallan * @fdt: pointer to the device tree blob
5476233fbe7Smacallan * @nodeoffset: structure block offset of a node
5486233fbe7Smacallan *
5496233fbe7Smacallan * fdt_first_property_offset() finds the first property of the node at
5506233fbe7Smacallan * the given structure block offset.
5516233fbe7Smacallan *
5526233fbe7Smacallan * returns:
5536233fbe7Smacallan * structure block offset of the property (>=0), on success
5546233fbe7Smacallan * -FDT_ERR_NOTFOUND, if the requested node has no properties
5556233fbe7Smacallan * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
5566233fbe7Smacallan * -FDT_ERR_BADMAGIC,
5576233fbe7Smacallan * -FDT_ERR_BADVERSION,
5586233fbe7Smacallan * -FDT_ERR_BADSTATE,
5596233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
5606233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings.
5616233fbe7Smacallan */
5626233fbe7Smacallan int fdt_first_property_offset(const void *fdt, int nodeoffset);
5636233fbe7Smacallan
5646233fbe7Smacallan /**
5656233fbe7Smacallan * fdt_next_property_offset - step through a node's properties
5666233fbe7Smacallan * @fdt: pointer to the device tree blob
5676233fbe7Smacallan * @offset: structure block offset of a property
5686233fbe7Smacallan *
5696233fbe7Smacallan * fdt_next_property_offset() finds the property immediately after the
5706233fbe7Smacallan * one at the given structure block offset. This will be a property
5716233fbe7Smacallan * of the same node as the given property.
5726233fbe7Smacallan *
5736233fbe7Smacallan * returns:
5746233fbe7Smacallan * structure block offset of the next property (>=0), on success
5756233fbe7Smacallan * -FDT_ERR_NOTFOUND, if the given property is the last in its node
5766233fbe7Smacallan * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
5776233fbe7Smacallan * -FDT_ERR_BADMAGIC,
5786233fbe7Smacallan * -FDT_ERR_BADVERSION,
5796233fbe7Smacallan * -FDT_ERR_BADSTATE,
5806233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
5816233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings.
5826233fbe7Smacallan */
5836233fbe7Smacallan int fdt_next_property_offset(const void *fdt, int offset);
5846233fbe7Smacallan
5856233fbe7Smacallan /**
586fc885a42Sskrll * fdt_for_each_property_offset - iterate over all properties of a node
587fc885a42Sskrll *
588fc885a42Sskrll * @property_offset: property offset (int, lvalue)
589fc885a42Sskrll * @fdt: FDT blob (const void *)
590fc885a42Sskrll * @node: node offset (int)
591fc885a42Sskrll *
592fc885a42Sskrll * This is actually a wrapper around a for loop and would be used like so:
593fc885a42Sskrll *
594fc885a42Sskrll * fdt_for_each_property_offset(property, fdt, node) {
595fc885a42Sskrll * Use property
596fc885a42Sskrll * ...
597fc885a42Sskrll * }
598fc885a42Sskrll *
599*5a485aa9Sskrll * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) {
600fc885a42Sskrll * Error handling
601fc885a42Sskrll * }
602fc885a42Sskrll *
603fc885a42Sskrll * Note that this is implemented as a macro and property is used as
604fc885a42Sskrll * iterator in the loop. The node variable can be constant or even a
605fc885a42Sskrll * literal.
606fc885a42Sskrll */
607fc885a42Sskrll #define fdt_for_each_property_offset(property, fdt, node) \
608fc885a42Sskrll for (property = fdt_first_property_offset(fdt, node); \
609fc885a42Sskrll property >= 0; \
610fc885a42Sskrll property = fdt_next_property_offset(fdt, property))
611fc885a42Sskrll
612fc885a42Sskrll /**
6136233fbe7Smacallan * fdt_get_property_by_offset - retrieve the property at a given offset
6146233fbe7Smacallan * @fdt: pointer to the device tree blob
6156233fbe7Smacallan * @offset: offset of the property to retrieve
6166233fbe7Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
6176233fbe7Smacallan *
6186233fbe7Smacallan * fdt_get_property_by_offset() retrieves a pointer to the
6196233fbe7Smacallan * fdt_property structure within the device tree blob at the given
6206233fbe7Smacallan * offset. If lenp is non-NULL, the length of the property value is
6216233fbe7Smacallan * also returned, in the integer pointed to by lenp.
6226233fbe7Smacallan *
623*5a485aa9Sskrll * Note that this code only works on device tree versions >= 16. fdt_getprop()
624*5a485aa9Sskrll * works on all versions.
625*5a485aa9Sskrll *
6266233fbe7Smacallan * returns:
6276233fbe7Smacallan * pointer to the structure representing the property
6286233fbe7Smacallan * if lenp is non-NULL, *lenp contains the length of the property
6296233fbe7Smacallan * value (>=0)
6306233fbe7Smacallan * NULL, on error
6316233fbe7Smacallan * if lenp is non-NULL, *lenp contains an error code (<0):
6326233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
6336233fbe7Smacallan * -FDT_ERR_BADMAGIC,
6346233fbe7Smacallan * -FDT_ERR_BADVERSION,
6356233fbe7Smacallan * -FDT_ERR_BADSTATE,
6366233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
6376233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
6386233fbe7Smacallan */
6396233fbe7Smacallan const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
6406233fbe7Smacallan int offset,
6416233fbe7Smacallan int *lenp);
6426233fbe7Smacallan
6436233fbe7Smacallan /**
6446233fbe7Smacallan * fdt_get_property_namelen - find a property based on substring
6456233fbe7Smacallan * @fdt: pointer to the device tree blob
6466233fbe7Smacallan * @nodeoffset: offset of the node whose property to find
6476233fbe7Smacallan * @name: name of the property to find
6486233fbe7Smacallan * @namelen: number of characters of name to consider
6496233fbe7Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
6506233fbe7Smacallan *
6516233fbe7Smacallan * Identical to fdt_get_property(), but only examine the first namelen
6526233fbe7Smacallan * characters of name for matching the property name.
6536233fbe7Smacallan */
654*5a485aa9Sskrll #ifndef SWIG /* Not available in Python */
6556233fbe7Smacallan const struct fdt_property *fdt_get_property_namelen(const void *fdt,
6566233fbe7Smacallan int nodeoffset,
6576233fbe7Smacallan const char *name,
6586233fbe7Smacallan int namelen, int *lenp);
659*5a485aa9Sskrll #endif
6606233fbe7Smacallan
6616233fbe7Smacallan /**
6626233fbe7Smacallan * fdt_get_property - find a given property in a given node
6636233fbe7Smacallan * @fdt: pointer to the device tree blob
6646233fbe7Smacallan * @nodeoffset: offset of the node whose property to find
6656233fbe7Smacallan * @name: name of the property to find
6666233fbe7Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
6676233fbe7Smacallan *
6686233fbe7Smacallan * fdt_get_property() retrieves a pointer to the fdt_property
6696233fbe7Smacallan * structure within the device tree blob corresponding to the property
6706233fbe7Smacallan * named 'name' of the node at offset nodeoffset. If lenp is
6716233fbe7Smacallan * non-NULL, the length of the property value is also returned, in the
6726233fbe7Smacallan * integer pointed to by lenp.
6736233fbe7Smacallan *
6746233fbe7Smacallan * returns:
6756233fbe7Smacallan * pointer to the structure representing the property
6766233fbe7Smacallan * if lenp is non-NULL, *lenp contains the length of the property
6776233fbe7Smacallan * value (>=0)
6786233fbe7Smacallan * NULL, on error
6796233fbe7Smacallan * if lenp is non-NULL, *lenp contains an error code (<0):
6806233fbe7Smacallan * -FDT_ERR_NOTFOUND, node does not have named property
681fc885a42Sskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
682fc885a42Sskrll * tag
6836233fbe7Smacallan * -FDT_ERR_BADMAGIC,
6846233fbe7Smacallan * -FDT_ERR_BADVERSION,
6856233fbe7Smacallan * -FDT_ERR_BADSTATE,
6866233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
6876233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
6886233fbe7Smacallan */
6896233fbe7Smacallan const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
6906233fbe7Smacallan const char *name, int *lenp);
fdt_get_property_w(void * fdt,int nodeoffset,const char * name,int * lenp)6916233fbe7Smacallan static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
6926233fbe7Smacallan const char *name,
6936233fbe7Smacallan int *lenp)
6946233fbe7Smacallan {
6956233fbe7Smacallan return (struct fdt_property *)(uintptr_t)
6966233fbe7Smacallan fdt_get_property(fdt, nodeoffset, name, lenp);
6976233fbe7Smacallan }
6986233fbe7Smacallan
6996233fbe7Smacallan /**
7006233fbe7Smacallan * fdt_getprop_by_offset - retrieve the value of a property at a given offset
7016233fbe7Smacallan * @fdt: pointer to the device tree blob
702*5a485aa9Sskrll * @offset: offset of the property to read
7036233fbe7Smacallan * @namep: pointer to a string variable (will be overwritten) or NULL
7046233fbe7Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
7056233fbe7Smacallan *
7066233fbe7Smacallan * fdt_getprop_by_offset() retrieves a pointer to the value of the
7076233fbe7Smacallan * property at structure block offset 'offset' (this will be a pointer
7086233fbe7Smacallan * to within the device blob itself, not a copy of the value). If
7096233fbe7Smacallan * lenp is non-NULL, the length of the property value is also
7106233fbe7Smacallan * returned, in the integer pointed to by lenp. If namep is non-NULL,
7116233fbe7Smacallan * the property's namne will also be returned in the char * pointed to
7126233fbe7Smacallan * by namep (this will be a pointer to within the device tree's string
7136233fbe7Smacallan * block, not a new copy of the name).
7146233fbe7Smacallan *
7156233fbe7Smacallan * returns:
7166233fbe7Smacallan * pointer to the property's value
7176233fbe7Smacallan * if lenp is non-NULL, *lenp contains the length of the property
7186233fbe7Smacallan * value (>=0)
7196233fbe7Smacallan * if namep is non-NULL *namep contiains a pointer to the property
7206233fbe7Smacallan * name.
7216233fbe7Smacallan * NULL, on error
7226233fbe7Smacallan * if lenp is non-NULL, *lenp contains an error code (<0):
7236233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
7246233fbe7Smacallan * -FDT_ERR_BADMAGIC,
7256233fbe7Smacallan * -FDT_ERR_BADVERSION,
7266233fbe7Smacallan * -FDT_ERR_BADSTATE,
7276233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
7286233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
7296233fbe7Smacallan */
730*5a485aa9Sskrll #ifndef SWIG /* This function is not useful in Python */
7316233fbe7Smacallan const void *fdt_getprop_by_offset(const void *fdt, int offset,
7326233fbe7Smacallan const char **namep, int *lenp);
733*5a485aa9Sskrll #endif
7346233fbe7Smacallan
7356233fbe7Smacallan /**
7366233fbe7Smacallan * fdt_getprop_namelen - get property value based on substring
7376233fbe7Smacallan * @fdt: pointer to the device tree blob
7386233fbe7Smacallan * @nodeoffset: offset of the node whose property to find
7396233fbe7Smacallan * @name: name of the property to find
7406233fbe7Smacallan * @namelen: number of characters of name to consider
7416233fbe7Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
7426233fbe7Smacallan *
7436233fbe7Smacallan * Identical to fdt_getprop(), but only examine the first namelen
7446233fbe7Smacallan * characters of name for matching the property name.
7456233fbe7Smacallan */
746*5a485aa9Sskrll #ifndef SWIG /* Not available in Python */
7476233fbe7Smacallan const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
7486233fbe7Smacallan const char *name, int namelen, int *lenp);
fdt_getprop_namelen_w(void * fdt,int nodeoffset,const char * name,int namelen,int * lenp)749fc885a42Sskrll static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
750fc885a42Sskrll const char *name, int namelen,
751fc885a42Sskrll int *lenp)
752fc885a42Sskrll {
753fc885a42Sskrll return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,
754fc885a42Sskrll namelen, lenp);
755fc885a42Sskrll }
756*5a485aa9Sskrll #endif
7576233fbe7Smacallan
7586233fbe7Smacallan /**
7596233fbe7Smacallan * fdt_getprop - retrieve the value of a given property
7606233fbe7Smacallan * @fdt: pointer to the device tree blob
7616233fbe7Smacallan * @nodeoffset: offset of the node whose property to find
7626233fbe7Smacallan * @name: name of the property to find
7636233fbe7Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL
7646233fbe7Smacallan *
7656233fbe7Smacallan * fdt_getprop() retrieves a pointer to the value of the property
7666233fbe7Smacallan * named 'name' of the node at offset nodeoffset (this will be a
7676233fbe7Smacallan * pointer to within the device blob itself, not a copy of the value).
7686233fbe7Smacallan * If lenp is non-NULL, the length of the property value is also
7696233fbe7Smacallan * returned, in the integer pointed to by lenp.
7706233fbe7Smacallan *
7716233fbe7Smacallan * returns:
7726233fbe7Smacallan * pointer to the property's value
7736233fbe7Smacallan * if lenp is non-NULL, *lenp contains the length of the property
7746233fbe7Smacallan * value (>=0)
7756233fbe7Smacallan * NULL, on error
7766233fbe7Smacallan * if lenp is non-NULL, *lenp contains an error code (<0):
7776233fbe7Smacallan * -FDT_ERR_NOTFOUND, node does not have named property
778fc885a42Sskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
779fc885a42Sskrll * tag
7806233fbe7Smacallan * -FDT_ERR_BADMAGIC,
7816233fbe7Smacallan * -FDT_ERR_BADVERSION,
7826233fbe7Smacallan * -FDT_ERR_BADSTATE,
7836233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
7846233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
7856233fbe7Smacallan */
7866233fbe7Smacallan const void *fdt_getprop(const void *fdt, int nodeoffset,
7876233fbe7Smacallan const char *name, int *lenp);
fdt_getprop_w(void * fdt,int nodeoffset,const char * name,int * lenp)7886233fbe7Smacallan static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
7896233fbe7Smacallan const char *name, int *lenp)
7906233fbe7Smacallan {
7916233fbe7Smacallan return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
7926233fbe7Smacallan }
7936233fbe7Smacallan
7946233fbe7Smacallan /**
7956233fbe7Smacallan * fdt_get_phandle - retrieve the phandle of a given node
7966233fbe7Smacallan * @fdt: pointer to the device tree blob
7976233fbe7Smacallan * @nodeoffset: structure block offset of the node
7986233fbe7Smacallan *
7996233fbe7Smacallan * fdt_get_phandle() retrieves the phandle of the device tree node at
8006233fbe7Smacallan * structure block offset nodeoffset.
8016233fbe7Smacallan *
8026233fbe7Smacallan * returns:
8036233fbe7Smacallan * the phandle of the node at nodeoffset, on success (!= 0, != -1)
8046233fbe7Smacallan * 0, if the node has no phandle, or another error occurs
8056233fbe7Smacallan */
8066233fbe7Smacallan uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
8076233fbe7Smacallan
8086233fbe7Smacallan /**
8096233fbe7Smacallan * fdt_get_alias_namelen - get alias based on substring
8106233fbe7Smacallan * @fdt: pointer to the device tree blob
8116233fbe7Smacallan * @name: name of the alias th look up
8126233fbe7Smacallan * @namelen: number of characters of name to consider
8136233fbe7Smacallan *
8146233fbe7Smacallan * Identical to fdt_get_alias(), but only examine the first namelen
8156233fbe7Smacallan * characters of name for matching the alias name.
8166233fbe7Smacallan */
817*5a485aa9Sskrll #ifndef SWIG /* Not available in Python */
8186233fbe7Smacallan const char *fdt_get_alias_namelen(const void *fdt,
8196233fbe7Smacallan const char *name, int namelen);
820*5a485aa9Sskrll #endif
8216233fbe7Smacallan
8226233fbe7Smacallan /**
823fc885a42Sskrll * fdt_get_alias - retrieve the path referenced by a given alias
8246233fbe7Smacallan * @fdt: pointer to the device tree blob
8256233fbe7Smacallan * @name: name of the alias th look up
8266233fbe7Smacallan *
8276233fbe7Smacallan * fdt_get_alias() retrieves the value of a given alias. That is, the
8286233fbe7Smacallan * value of the property named 'name' in the node /aliases.
8296233fbe7Smacallan *
8306233fbe7Smacallan * returns:
8316233fbe7Smacallan * a pointer to the expansion of the alias named 'name', if it exists
8326233fbe7Smacallan * NULL, if the given alias or the /aliases node does not exist
8336233fbe7Smacallan */
8346233fbe7Smacallan const char *fdt_get_alias(const void *fdt, const char *name);
8356233fbe7Smacallan
8366233fbe7Smacallan /**
8376233fbe7Smacallan * fdt_get_path - determine the full path of a node
8386233fbe7Smacallan * @fdt: pointer to the device tree blob
8396233fbe7Smacallan * @nodeoffset: offset of the node whose path to find
8406233fbe7Smacallan * @buf: character buffer to contain the returned path (will be overwritten)
8416233fbe7Smacallan * @buflen: size of the character buffer at buf
8426233fbe7Smacallan *
8436233fbe7Smacallan * fdt_get_path() computes the full path of the node at offset
8446233fbe7Smacallan * nodeoffset, and records that path in the buffer at buf.
8456233fbe7Smacallan *
8466233fbe7Smacallan * NOTE: This function is expensive, as it must scan the device tree
8476233fbe7Smacallan * structure from the start to nodeoffset.
8486233fbe7Smacallan *
8496233fbe7Smacallan * returns:
8506233fbe7Smacallan * 0, on success
8516233fbe7Smacallan * buf contains the absolute path of the node at
8526233fbe7Smacallan * nodeoffset, as a NUL-terminated string.
8536233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
8546233fbe7Smacallan * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
8556233fbe7Smacallan * characters and will not fit in the given buffer.
8566233fbe7Smacallan * -FDT_ERR_BADMAGIC,
8576233fbe7Smacallan * -FDT_ERR_BADVERSION,
8586233fbe7Smacallan * -FDT_ERR_BADSTATE,
8596233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
8606233fbe7Smacallan */
8616233fbe7Smacallan int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
8626233fbe7Smacallan
8636233fbe7Smacallan /**
8646233fbe7Smacallan * fdt_supernode_atdepth_offset - find a specific ancestor of a node
8656233fbe7Smacallan * @fdt: pointer to the device tree blob
8666233fbe7Smacallan * @nodeoffset: offset of the node whose parent to find
8676233fbe7Smacallan * @supernodedepth: depth of the ancestor to find
8686233fbe7Smacallan * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
8696233fbe7Smacallan *
8706233fbe7Smacallan * fdt_supernode_atdepth_offset() finds an ancestor of the given node
8716233fbe7Smacallan * at a specific depth from the root (where the root itself has depth
8726233fbe7Smacallan * 0, its immediate subnodes depth 1 and so forth). So
8736233fbe7Smacallan * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
8746233fbe7Smacallan * will always return 0, the offset of the root node. If the node at
8756233fbe7Smacallan * nodeoffset has depth D, then:
8766233fbe7Smacallan * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
8776233fbe7Smacallan * will return nodeoffset itself.
8786233fbe7Smacallan *
8796233fbe7Smacallan * NOTE: This function is expensive, as it must scan the device tree
8806233fbe7Smacallan * structure from the start to nodeoffset.
8816233fbe7Smacallan *
8826233fbe7Smacallan * returns:
8836233fbe7Smacallan * structure block offset of the node at node offset's ancestor
8846233fbe7Smacallan * of depth supernodedepth (>=0), on success
8856233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
886fc885a42Sskrll * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
887fc885a42Sskrll * nodeoffset
8886233fbe7Smacallan * -FDT_ERR_BADMAGIC,
8896233fbe7Smacallan * -FDT_ERR_BADVERSION,
8906233fbe7Smacallan * -FDT_ERR_BADSTATE,
8916233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
8926233fbe7Smacallan */
8936233fbe7Smacallan int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
8946233fbe7Smacallan int supernodedepth, int *nodedepth);
8956233fbe7Smacallan
8966233fbe7Smacallan /**
8976233fbe7Smacallan * fdt_node_depth - find the depth of a given node
8986233fbe7Smacallan * @fdt: pointer to the device tree blob
8996233fbe7Smacallan * @nodeoffset: offset of the node whose parent to find
9006233fbe7Smacallan *
9016233fbe7Smacallan * fdt_node_depth() finds the depth of a given node. The root node
9026233fbe7Smacallan * has depth 0, its immediate subnodes depth 1 and so forth.
9036233fbe7Smacallan *
9046233fbe7Smacallan * NOTE: This function is expensive, as it must scan the device tree
9056233fbe7Smacallan * structure from the start to nodeoffset.
9066233fbe7Smacallan *
9076233fbe7Smacallan * returns:
9086233fbe7Smacallan * depth of the node at nodeoffset (>=0), on success
9096233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
9106233fbe7Smacallan * -FDT_ERR_BADMAGIC,
9116233fbe7Smacallan * -FDT_ERR_BADVERSION,
9126233fbe7Smacallan * -FDT_ERR_BADSTATE,
9136233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
9146233fbe7Smacallan */
9156233fbe7Smacallan int fdt_node_depth(const void *fdt, int nodeoffset);
9166233fbe7Smacallan
9176233fbe7Smacallan /**
9186233fbe7Smacallan * fdt_parent_offset - find the parent of a given node
9196233fbe7Smacallan * @fdt: pointer to the device tree blob
9206233fbe7Smacallan * @nodeoffset: offset of the node whose parent to find
9216233fbe7Smacallan *
9226233fbe7Smacallan * fdt_parent_offset() locates the parent node of a given node (that
9236233fbe7Smacallan * is, it finds the offset of the node which contains the node at
9246233fbe7Smacallan * nodeoffset as a subnode).
9256233fbe7Smacallan *
9266233fbe7Smacallan * NOTE: This function is expensive, as it must scan the device tree
9276233fbe7Smacallan * structure from the start to nodeoffset, *twice*.
9286233fbe7Smacallan *
9296233fbe7Smacallan * returns:
9306233fbe7Smacallan * structure block offset of the parent of the node at nodeoffset
9316233fbe7Smacallan * (>=0), on success
9326233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
9336233fbe7Smacallan * -FDT_ERR_BADMAGIC,
9346233fbe7Smacallan * -FDT_ERR_BADVERSION,
9356233fbe7Smacallan * -FDT_ERR_BADSTATE,
9366233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
9376233fbe7Smacallan */
9386233fbe7Smacallan int fdt_parent_offset(const void *fdt, int nodeoffset);
9396233fbe7Smacallan
9406233fbe7Smacallan /**
9416233fbe7Smacallan * fdt_node_offset_by_prop_value - find nodes with a given property value
9426233fbe7Smacallan * @fdt: pointer to the device tree blob
9436233fbe7Smacallan * @startoffset: only find nodes after this offset
9446233fbe7Smacallan * @propname: property name to check
9456233fbe7Smacallan * @propval: property value to search for
9466233fbe7Smacallan * @proplen: length of the value in propval
9476233fbe7Smacallan *
9486233fbe7Smacallan * fdt_node_offset_by_prop_value() returns the offset of the first
9496233fbe7Smacallan * node after startoffset, which has a property named propname whose
9506233fbe7Smacallan * value is of length proplen and has value equal to propval; or if
9516233fbe7Smacallan * startoffset is -1, the very first such node in the tree.
9526233fbe7Smacallan *
9536233fbe7Smacallan * To iterate through all nodes matching the criterion, the following
9546233fbe7Smacallan * idiom can be used:
9556233fbe7Smacallan * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
9566233fbe7Smacallan * propval, proplen);
9576233fbe7Smacallan * while (offset != -FDT_ERR_NOTFOUND) {
9586233fbe7Smacallan * // other code here
9596233fbe7Smacallan * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
9606233fbe7Smacallan * propval, proplen);
9616233fbe7Smacallan * }
9626233fbe7Smacallan *
9636233fbe7Smacallan * Note the -1 in the first call to the function, if 0 is used here
9646233fbe7Smacallan * instead, the function will never locate the root node, even if it
9656233fbe7Smacallan * matches the criterion.
9666233fbe7Smacallan *
9676233fbe7Smacallan * returns:
9686233fbe7Smacallan * structure block offset of the located node (>= 0, >startoffset),
9696233fbe7Smacallan * on success
9706233fbe7Smacallan * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
9716233fbe7Smacallan * tree after startoffset
9726233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
9736233fbe7Smacallan * -FDT_ERR_BADMAGIC,
9746233fbe7Smacallan * -FDT_ERR_BADVERSION,
9756233fbe7Smacallan * -FDT_ERR_BADSTATE,
9766233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
9776233fbe7Smacallan */
9786233fbe7Smacallan int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
9796233fbe7Smacallan const char *propname,
9806233fbe7Smacallan const void *propval, int proplen);
9816233fbe7Smacallan
9826233fbe7Smacallan /**
9836233fbe7Smacallan * fdt_node_offset_by_phandle - find the node with a given phandle
9846233fbe7Smacallan * @fdt: pointer to the device tree blob
9856233fbe7Smacallan * @phandle: phandle value
9866233fbe7Smacallan *
9876233fbe7Smacallan * fdt_node_offset_by_phandle() returns the offset of the node
9886233fbe7Smacallan * which has the given phandle value. If there is more than one node
9896233fbe7Smacallan * in the tree with the given phandle (an invalid tree), results are
9906233fbe7Smacallan * undefined.
9916233fbe7Smacallan *
9926233fbe7Smacallan * returns:
9936233fbe7Smacallan * structure block offset of the located node (>= 0), on success
9946233fbe7Smacallan * -FDT_ERR_NOTFOUND, no node with that phandle exists
9956233fbe7Smacallan * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
9966233fbe7Smacallan * -FDT_ERR_BADMAGIC,
9976233fbe7Smacallan * -FDT_ERR_BADVERSION,
9986233fbe7Smacallan * -FDT_ERR_BADSTATE,
9996233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
10006233fbe7Smacallan */
10016233fbe7Smacallan int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
10026233fbe7Smacallan
10036233fbe7Smacallan /**
10046233fbe7Smacallan * fdt_node_check_compatible: check a node's compatible property
10056233fbe7Smacallan * @fdt: pointer to the device tree blob
10066233fbe7Smacallan * @nodeoffset: offset of a tree node
10076233fbe7Smacallan * @compatible: string to match against
10086233fbe7Smacallan *
10096233fbe7Smacallan *
10106233fbe7Smacallan * fdt_node_check_compatible() returns 0 if the given node contains a
10116233fbe7Smacallan * 'compatible' property with the given string as one of its elements,
10126233fbe7Smacallan * it returns non-zero otherwise, or on error.
10136233fbe7Smacallan *
10146233fbe7Smacallan * returns:
10156233fbe7Smacallan * 0, if the node has a 'compatible' property listing the given string
10166233fbe7Smacallan * 1, if the node has a 'compatible' property, but it does not list
10176233fbe7Smacallan * the given string
10186233fbe7Smacallan * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
10196233fbe7Smacallan * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
10206233fbe7Smacallan * -FDT_ERR_BADMAGIC,
10216233fbe7Smacallan * -FDT_ERR_BADVERSION,
10226233fbe7Smacallan * -FDT_ERR_BADSTATE,
10236233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
10246233fbe7Smacallan */
10256233fbe7Smacallan int fdt_node_check_compatible(const void *fdt, int nodeoffset,
10266233fbe7Smacallan const char *compatible);
10276233fbe7Smacallan
10286233fbe7Smacallan /**
10296233fbe7Smacallan * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
10306233fbe7Smacallan * @fdt: pointer to the device tree blob
10316233fbe7Smacallan * @startoffset: only find nodes after this offset
10326233fbe7Smacallan * @compatible: 'compatible' string to match against
10336233fbe7Smacallan *
10346233fbe7Smacallan * fdt_node_offset_by_compatible() returns the offset of the first
10356233fbe7Smacallan * node after startoffset, which has a 'compatible' property which
10366233fbe7Smacallan * lists the given compatible string; or if startoffset is -1, the
10376233fbe7Smacallan * very first such node in the tree.
10386233fbe7Smacallan *
10396233fbe7Smacallan * To iterate through all nodes matching the criterion, the following
10406233fbe7Smacallan * idiom can be used:
10416233fbe7Smacallan * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
10426233fbe7Smacallan * while (offset != -FDT_ERR_NOTFOUND) {
10436233fbe7Smacallan * // other code here
10446233fbe7Smacallan * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
10456233fbe7Smacallan * }
10466233fbe7Smacallan *
10476233fbe7Smacallan * Note the -1 in the first call to the function, if 0 is used here
10486233fbe7Smacallan * instead, the function will never locate the root node, even if it
10496233fbe7Smacallan * matches the criterion.
10506233fbe7Smacallan *
10516233fbe7Smacallan * returns:
10526233fbe7Smacallan * structure block offset of the located node (>= 0, >startoffset),
10536233fbe7Smacallan * on success
10546233fbe7Smacallan * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
10556233fbe7Smacallan * tree after startoffset
10566233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
10576233fbe7Smacallan * -FDT_ERR_BADMAGIC,
10586233fbe7Smacallan * -FDT_ERR_BADVERSION,
10596233fbe7Smacallan * -FDT_ERR_BADSTATE,
10606233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings
10616233fbe7Smacallan */
10626233fbe7Smacallan int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
10636233fbe7Smacallan const char *compatible);
10646233fbe7Smacallan
10656233fbe7Smacallan /**
10666233fbe7Smacallan * fdt_stringlist_contains - check a string list property for a string
10676233fbe7Smacallan * @strlist: Property containing a list of strings to check
10686233fbe7Smacallan * @listlen: Length of property
10696233fbe7Smacallan * @str: String to search for
10706233fbe7Smacallan *
10716233fbe7Smacallan * This is a utility function provided for convenience. The list contains
10726233fbe7Smacallan * one or more strings, each terminated by \0, as is found in a device tree
10736233fbe7Smacallan * "compatible" property.
10746233fbe7Smacallan *
10756233fbe7Smacallan * @return: 1 if the string is found in the list, 0 not found, or invalid list
10766233fbe7Smacallan */
10776233fbe7Smacallan int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
10786233fbe7Smacallan
10796233fbe7Smacallan /**
10806233fbe7Smacallan * fdt_stringlist_count - count the number of strings in a string list
10816233fbe7Smacallan * @fdt: pointer to the device tree blob
10826233fbe7Smacallan * @nodeoffset: offset of a tree node
10836233fbe7Smacallan * @property: name of the property containing the string list
10846233fbe7Smacallan * @return:
10856233fbe7Smacallan * the number of strings in the given property
10866233fbe7Smacallan * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
10876233fbe7Smacallan * -FDT_ERR_NOTFOUND if the property does not exist
10886233fbe7Smacallan */
10896233fbe7Smacallan int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
10906233fbe7Smacallan
10916233fbe7Smacallan /**
10926233fbe7Smacallan * fdt_stringlist_search - find a string in a string list and return its index
10936233fbe7Smacallan * @fdt: pointer to the device tree blob
10946233fbe7Smacallan * @nodeoffset: offset of a tree node
10956233fbe7Smacallan * @property: name of the property containing the string list
10966233fbe7Smacallan * @string: string to look up in the string list
10976233fbe7Smacallan *
10986233fbe7Smacallan * Note that it is possible for this function to succeed on property values
10996233fbe7Smacallan * that are not NUL-terminated. That's because the function will stop after
11006233fbe7Smacallan * finding the first occurrence of @string. This can for example happen with
11016233fbe7Smacallan * small-valued cell properties, such as #address-cells, when searching for
11026233fbe7Smacallan * the empty string.
11036233fbe7Smacallan *
11046233fbe7Smacallan * @return:
11056233fbe7Smacallan * the index of the string in the list of strings
11066233fbe7Smacallan * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
11076233fbe7Smacallan * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
11086233fbe7Smacallan * the given string
11096233fbe7Smacallan */
11106233fbe7Smacallan int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
11116233fbe7Smacallan const char *string);
11126233fbe7Smacallan
11136233fbe7Smacallan /**
11146233fbe7Smacallan * fdt_stringlist_get() - obtain the string at a given index in a string list
11156233fbe7Smacallan * @fdt: pointer to the device tree blob
11166233fbe7Smacallan * @nodeoffset: offset of a tree node
11176233fbe7Smacallan * @property: name of the property containing the string list
11186233fbe7Smacallan * @index: index of the string to return
11196233fbe7Smacallan * @lenp: return location for the string length or an error code on failure
11206233fbe7Smacallan *
11216233fbe7Smacallan * Note that this will successfully extract strings from properties with
11226233fbe7Smacallan * non-NUL-terminated values. For example on small-valued cell properties
11236233fbe7Smacallan * this function will return the empty string.
11246233fbe7Smacallan *
11256233fbe7Smacallan * If non-NULL, the length of the string (on success) or a negative error-code
11266233fbe7Smacallan * (on failure) will be stored in the integer pointer to by lenp.
11276233fbe7Smacallan *
11286233fbe7Smacallan * @return:
11296233fbe7Smacallan * A pointer to the string at the given index in the string list or NULL on
11306233fbe7Smacallan * failure. On success the length of the string will be stored in the memory
11316233fbe7Smacallan * location pointed to by the lenp parameter, if non-NULL. On failure one of
11326233fbe7Smacallan * the following negative error codes will be returned in the lenp parameter
11336233fbe7Smacallan * (if non-NULL):
11346233fbe7Smacallan * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
11356233fbe7Smacallan * -FDT_ERR_NOTFOUND if the property does not exist
11366233fbe7Smacallan */
11376233fbe7Smacallan const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
11386233fbe7Smacallan const char *property, int index,
11396233fbe7Smacallan int *lenp);
11406233fbe7Smacallan
11416233fbe7Smacallan /**********************************************************************/
11426233fbe7Smacallan /* Read-only functions (addressing related) */
11436233fbe7Smacallan /**********************************************************************/
11446233fbe7Smacallan
11456233fbe7Smacallan /**
11466233fbe7Smacallan * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
11476233fbe7Smacallan *
11486233fbe7Smacallan * This is the maximum value for #address-cells, #size-cells and
11496233fbe7Smacallan * similar properties that will be processed by libfdt. IEE1275
11506233fbe7Smacallan * requires that OF implementations handle values up to 4.
11516233fbe7Smacallan * Implementations may support larger values, but in practice higher
11526233fbe7Smacallan * values aren't used.
11536233fbe7Smacallan */
11546233fbe7Smacallan #define FDT_MAX_NCELLS 4
11556233fbe7Smacallan
11566233fbe7Smacallan /**
11576233fbe7Smacallan * fdt_address_cells - retrieve address size for a bus represented in the tree
11586233fbe7Smacallan * @fdt: pointer to the device tree blob
11596233fbe7Smacallan * @nodeoffset: offset of the node to find the address size for
11606233fbe7Smacallan *
11616233fbe7Smacallan * When the node has a valid #address-cells property, returns its value.
11626233fbe7Smacallan *
11636233fbe7Smacallan * returns:
11646233fbe7Smacallan * 0 <= n < FDT_MAX_NCELLS, on success
11656233fbe7Smacallan * 2, if the node has no #address-cells property
1166fc885a42Sskrll * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1167fc885a42Sskrll * #address-cells property
11686233fbe7Smacallan * -FDT_ERR_BADMAGIC,
11696233fbe7Smacallan * -FDT_ERR_BADVERSION,
11706233fbe7Smacallan * -FDT_ERR_BADSTATE,
11716233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
11726233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
11736233fbe7Smacallan */
11746233fbe7Smacallan int fdt_address_cells(const void *fdt, int nodeoffset);
11756233fbe7Smacallan
11766233fbe7Smacallan /**
11776233fbe7Smacallan * fdt_size_cells - retrieve address range size for a bus represented in the
11786233fbe7Smacallan * tree
11796233fbe7Smacallan * @fdt: pointer to the device tree blob
11806233fbe7Smacallan * @nodeoffset: offset of the node to find the address range size for
11816233fbe7Smacallan *
11826233fbe7Smacallan * When the node has a valid #size-cells property, returns its value.
11836233fbe7Smacallan *
11846233fbe7Smacallan * returns:
11856233fbe7Smacallan * 0 <= n < FDT_MAX_NCELLS, on success
1186*5a485aa9Sskrll * 1, if the node has no #size-cells property
1187fc885a42Sskrll * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1188fc885a42Sskrll * #size-cells property
11896233fbe7Smacallan * -FDT_ERR_BADMAGIC,
11906233fbe7Smacallan * -FDT_ERR_BADVERSION,
11916233fbe7Smacallan * -FDT_ERR_BADSTATE,
11926233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
11936233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
11946233fbe7Smacallan */
11956233fbe7Smacallan int fdt_size_cells(const void *fdt, int nodeoffset);
11966233fbe7Smacallan
11976233fbe7Smacallan
11986233fbe7Smacallan /**********************************************************************/
11996233fbe7Smacallan /* Write-in-place functions */
12006233fbe7Smacallan /**********************************************************************/
12016233fbe7Smacallan
12026233fbe7Smacallan /**
1203fc885a42Sskrll * fdt_setprop_inplace_namelen_partial - change a property's value,
1204fc885a42Sskrll * but not its size
1205fc885a42Sskrll * @fdt: pointer to the device tree blob
1206fc885a42Sskrll * @nodeoffset: offset of the node whose property to change
1207fc885a42Sskrll * @name: name of the property to change
1208fc885a42Sskrll * @namelen: number of characters of name to consider
1209fc885a42Sskrll * @idx: index of the property to change in the array
1210fc885a42Sskrll * @val: pointer to data to replace the property value with
1211fc885a42Sskrll * @len: length of the property value
1212fc885a42Sskrll *
1213fc885a42Sskrll * Identical to fdt_setprop_inplace(), but modifies the given property
1214fc885a42Sskrll * starting from the given index, and using only the first characters
1215fc885a42Sskrll * of the name. It is useful when you want to manipulate only one value of
1216fc885a42Sskrll * an array and you have a string that doesn't end with \0.
1217fc885a42Sskrll */
1218*5a485aa9Sskrll #ifndef SWIG /* Not available in Python */
1219fc885a42Sskrll int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
1220fc885a42Sskrll const char *name, int namelen,
1221fc885a42Sskrll uint32_t idx, const void *val,
1222fc885a42Sskrll int len);
1223*5a485aa9Sskrll #endif
1224fc885a42Sskrll
1225fc885a42Sskrll /**
12266233fbe7Smacallan * fdt_setprop_inplace - change a property's value, but not its size
12276233fbe7Smacallan * @fdt: pointer to the device tree blob
12286233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
12296233fbe7Smacallan * @name: name of the property to change
12306233fbe7Smacallan * @val: pointer to data to replace the property value with
12316233fbe7Smacallan * @len: length of the property value
12326233fbe7Smacallan *
12336233fbe7Smacallan * fdt_setprop_inplace() replaces the value of a given property with
12346233fbe7Smacallan * the data in val, of length len. This function cannot change the
12356233fbe7Smacallan * size of a property, and so will only work if len is equal to the
12366233fbe7Smacallan * current length of the property.
12376233fbe7Smacallan *
12386233fbe7Smacallan * This function will alter only the bytes in the blob which contain
12396233fbe7Smacallan * the given property value, and will not alter or move any other part
12406233fbe7Smacallan * of the tree.
12416233fbe7Smacallan *
12426233fbe7Smacallan * returns:
12436233fbe7Smacallan * 0, on success
12446233fbe7Smacallan * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
12456233fbe7Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property
12466233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
12476233fbe7Smacallan * -FDT_ERR_BADMAGIC,
12486233fbe7Smacallan * -FDT_ERR_BADVERSION,
12496233fbe7Smacallan * -FDT_ERR_BADSTATE,
12506233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
12516233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
12526233fbe7Smacallan */
1253*5a485aa9Sskrll #ifndef SWIG /* Not available in Python */
12546233fbe7Smacallan int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
12556233fbe7Smacallan const void *val, int len);
1256*5a485aa9Sskrll #endif
12576233fbe7Smacallan
12586233fbe7Smacallan /**
12596233fbe7Smacallan * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
12606233fbe7Smacallan * @fdt: pointer to the device tree blob
12616233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
12626233fbe7Smacallan * @name: name of the property to change
12636233fbe7Smacallan * @val: 32-bit integer value to replace the property with
12646233fbe7Smacallan *
12656233fbe7Smacallan * fdt_setprop_inplace_u32() replaces the value of a given property
12666233fbe7Smacallan * with the 32-bit integer value in val, converting val to big-endian
12676233fbe7Smacallan * if necessary. This function cannot change the size of a property,
12686233fbe7Smacallan * and so will only work if the property already exists and has length
12696233fbe7Smacallan * 4.
12706233fbe7Smacallan *
12716233fbe7Smacallan * This function will alter only the bytes in the blob which contain
12726233fbe7Smacallan * the given property value, and will not alter or move any other part
12736233fbe7Smacallan * of the tree.
12746233fbe7Smacallan *
12756233fbe7Smacallan * returns:
12766233fbe7Smacallan * 0, on success
12776233fbe7Smacallan * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
12786233fbe7Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property
12796233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
12806233fbe7Smacallan * -FDT_ERR_BADMAGIC,
12816233fbe7Smacallan * -FDT_ERR_BADVERSION,
12826233fbe7Smacallan * -FDT_ERR_BADSTATE,
12836233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
12846233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
12856233fbe7Smacallan */
fdt_setprop_inplace_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)12866233fbe7Smacallan static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
12876233fbe7Smacallan const char *name, uint32_t val)
12886233fbe7Smacallan {
12896233fbe7Smacallan fdt32_t tmp = cpu_to_fdt32(val);
12906233fbe7Smacallan return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
12916233fbe7Smacallan }
12926233fbe7Smacallan
12936233fbe7Smacallan /**
12946233fbe7Smacallan * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
12956233fbe7Smacallan * @fdt: pointer to the device tree blob
12966233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
12976233fbe7Smacallan * @name: name of the property to change
12986233fbe7Smacallan * @val: 64-bit integer value to replace the property with
12996233fbe7Smacallan *
13006233fbe7Smacallan * fdt_setprop_inplace_u64() replaces the value of a given property
13016233fbe7Smacallan * with the 64-bit integer value in val, converting val to big-endian
13026233fbe7Smacallan * if necessary. This function cannot change the size of a property,
13036233fbe7Smacallan * and so will only work if the property already exists and has length
13046233fbe7Smacallan * 8.
13056233fbe7Smacallan *
13066233fbe7Smacallan * This function will alter only the bytes in the blob which contain
13076233fbe7Smacallan * the given property value, and will not alter or move any other part
13086233fbe7Smacallan * of the tree.
13096233fbe7Smacallan *
13106233fbe7Smacallan * returns:
13116233fbe7Smacallan * 0, on success
13126233fbe7Smacallan * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
13136233fbe7Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property
13146233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
13156233fbe7Smacallan * -FDT_ERR_BADMAGIC,
13166233fbe7Smacallan * -FDT_ERR_BADVERSION,
13176233fbe7Smacallan * -FDT_ERR_BADSTATE,
13186233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
13196233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
13206233fbe7Smacallan */
fdt_setprop_inplace_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)13216233fbe7Smacallan static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
13226233fbe7Smacallan const char *name, uint64_t val)
13236233fbe7Smacallan {
13246233fbe7Smacallan fdt64_t tmp = cpu_to_fdt64(val);
13256233fbe7Smacallan return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));
13266233fbe7Smacallan }
13276233fbe7Smacallan
13286233fbe7Smacallan /**
13296233fbe7Smacallan * fdt_setprop_inplace_cell - change the value of a single-cell property
13306233fbe7Smacallan *
13316233fbe7Smacallan * This is an alternative name for fdt_setprop_inplace_u32()
13326233fbe7Smacallan */
fdt_setprop_inplace_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)13336233fbe7Smacallan static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
13346233fbe7Smacallan const char *name, uint32_t val)
13356233fbe7Smacallan {
13366233fbe7Smacallan return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
13376233fbe7Smacallan }
13386233fbe7Smacallan
13396233fbe7Smacallan /**
13406233fbe7Smacallan * fdt_nop_property - replace a property with nop tags
13416233fbe7Smacallan * @fdt: pointer to the device tree blob
13426233fbe7Smacallan * @nodeoffset: offset of the node whose property to nop
13436233fbe7Smacallan * @name: name of the property to nop
13446233fbe7Smacallan *
13456233fbe7Smacallan * fdt_nop_property() will replace a given property's representation
13466233fbe7Smacallan * in the blob with FDT_NOP tags, effectively removing it from the
13476233fbe7Smacallan * tree.
13486233fbe7Smacallan *
13496233fbe7Smacallan * This function will alter only the bytes in the blob which contain
13506233fbe7Smacallan * the property, and will not alter or move any other part of the
13516233fbe7Smacallan * tree.
13526233fbe7Smacallan *
13536233fbe7Smacallan * returns:
13546233fbe7Smacallan * 0, on success
13556233fbe7Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property
13566233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
13576233fbe7Smacallan * -FDT_ERR_BADMAGIC,
13586233fbe7Smacallan * -FDT_ERR_BADVERSION,
13596233fbe7Smacallan * -FDT_ERR_BADSTATE,
13606233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
13616233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
13626233fbe7Smacallan */
13636233fbe7Smacallan int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
13646233fbe7Smacallan
13656233fbe7Smacallan /**
13666233fbe7Smacallan * fdt_nop_node - replace a node (subtree) with nop tags
13676233fbe7Smacallan * @fdt: pointer to the device tree blob
13686233fbe7Smacallan * @nodeoffset: offset of the node to nop
13696233fbe7Smacallan *
13706233fbe7Smacallan * fdt_nop_node() will replace a given node's representation in the
13716233fbe7Smacallan * blob, including all its subnodes, if any, with FDT_NOP tags,
13726233fbe7Smacallan * effectively removing it from the tree.
13736233fbe7Smacallan *
13746233fbe7Smacallan * This function will alter only the bytes in the blob which contain
13756233fbe7Smacallan * the node and its properties and subnodes, and will not alter or
13766233fbe7Smacallan * move any other part of the tree.
13776233fbe7Smacallan *
13786233fbe7Smacallan * returns:
13796233fbe7Smacallan * 0, on success
13806233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
13816233fbe7Smacallan * -FDT_ERR_BADMAGIC,
13826233fbe7Smacallan * -FDT_ERR_BADVERSION,
13836233fbe7Smacallan * -FDT_ERR_BADSTATE,
13846233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
13856233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
13866233fbe7Smacallan */
13876233fbe7Smacallan int fdt_nop_node(void *fdt, int nodeoffset);
13886233fbe7Smacallan
13896233fbe7Smacallan /**********************************************************************/
13906233fbe7Smacallan /* Sequential write functions */
13916233fbe7Smacallan /**********************************************************************/
13926233fbe7Smacallan
1393*5a485aa9Sskrll /* fdt_create_with_flags flags */
1394*5a485aa9Sskrll #define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1
1395*5a485aa9Sskrll /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property
1396*5a485aa9Sskrll * names in the fdt. This can result in faster creation times, but
1397*5a485aa9Sskrll * a larger fdt. */
1398*5a485aa9Sskrll
1399*5a485aa9Sskrll #define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP)
1400*5a485aa9Sskrll
1401*5a485aa9Sskrll /**
1402*5a485aa9Sskrll * fdt_create_with_flags - begin creation of a new fdt
1403*5a485aa9Sskrll * @fdt: pointer to memory allocated where fdt will be created
1404*5a485aa9Sskrll * @bufsize: size of the memory space at fdt
1405*5a485aa9Sskrll * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0.
1406*5a485aa9Sskrll *
1407*5a485aa9Sskrll * fdt_create_with_flags() begins the process of creating a new fdt with
1408*5a485aa9Sskrll * the sequential write interface.
1409*5a485aa9Sskrll *
1410*5a485aa9Sskrll * fdt creation process must end with fdt_finished() to produce a valid fdt.
1411*5a485aa9Sskrll *
1412*5a485aa9Sskrll * returns:
1413*5a485aa9Sskrll * 0, on success
1414*5a485aa9Sskrll * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
1415*5a485aa9Sskrll * -FDT_ERR_BADFLAGS, flags is not valid
1416*5a485aa9Sskrll */
1417*5a485aa9Sskrll int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags);
1418*5a485aa9Sskrll
1419*5a485aa9Sskrll /**
1420*5a485aa9Sskrll * fdt_create - begin creation of a new fdt
1421*5a485aa9Sskrll * @fdt: pointer to memory allocated where fdt will be created
1422*5a485aa9Sskrll * @bufsize: size of the memory space at fdt
1423*5a485aa9Sskrll *
1424*5a485aa9Sskrll * fdt_create() is equivalent to fdt_create_with_flags() with flags=0.
1425*5a485aa9Sskrll *
1426*5a485aa9Sskrll * returns:
1427*5a485aa9Sskrll * 0, on success
1428*5a485aa9Sskrll * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt
1429*5a485aa9Sskrll */
14306233fbe7Smacallan int fdt_create(void *buf, int bufsize);
1431*5a485aa9Sskrll
14326233fbe7Smacallan int fdt_resize(void *fdt, void *buf, int bufsize);
14336233fbe7Smacallan int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
14346233fbe7Smacallan int fdt_finish_reservemap(void *fdt);
14356233fbe7Smacallan int fdt_begin_node(void *fdt, const char *name);
14366233fbe7Smacallan int fdt_property(void *fdt, const char *name, const void *val, int len);
fdt_property_u32(void * fdt,const char * name,uint32_t val)14376233fbe7Smacallan static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
14386233fbe7Smacallan {
14396233fbe7Smacallan fdt32_t tmp = cpu_to_fdt32(val);
14406233fbe7Smacallan return fdt_property(fdt, name, &tmp, sizeof(tmp));
14416233fbe7Smacallan }
fdt_property_u64(void * fdt,const char * name,uint64_t val)14426233fbe7Smacallan static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
14436233fbe7Smacallan {
14446233fbe7Smacallan fdt64_t tmp = cpu_to_fdt64(val);
14456233fbe7Smacallan return fdt_property(fdt, name, &tmp, sizeof(tmp));
14466233fbe7Smacallan }
1447*5a485aa9Sskrll
1448*5a485aa9Sskrll #ifndef SWIG /* Not available in Python */
fdt_property_cell(void * fdt,const char * name,uint32_t val)14496233fbe7Smacallan static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
14506233fbe7Smacallan {
14516233fbe7Smacallan return fdt_property_u32(fdt, name, val);
14526233fbe7Smacallan }
1453*5a485aa9Sskrll #endif
1454*5a485aa9Sskrll
1455*5a485aa9Sskrll /**
1456*5a485aa9Sskrll * fdt_property_placeholder - add a new property and return a ptr to its value
1457*5a485aa9Sskrll *
1458*5a485aa9Sskrll * @fdt: pointer to the device tree blob
1459*5a485aa9Sskrll * @name: name of property to add
1460*5a485aa9Sskrll * @len: length of property value in bytes
1461*5a485aa9Sskrll * @valp: returns a pointer to where where the value should be placed
1462*5a485aa9Sskrll *
1463*5a485aa9Sskrll * returns:
1464*5a485aa9Sskrll * 0, on success
1465*5a485aa9Sskrll * -FDT_ERR_BADMAGIC,
1466*5a485aa9Sskrll * -FDT_ERR_NOSPACE, standard meanings
1467*5a485aa9Sskrll */
1468*5a485aa9Sskrll int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp);
1469*5a485aa9Sskrll
14706233fbe7Smacallan #define fdt_property_string(fdt, name, str) \
14716233fbe7Smacallan fdt_property(fdt, name, str, strlen(str)+1)
14726233fbe7Smacallan int fdt_end_node(void *fdt);
14736233fbe7Smacallan int fdt_finish(void *fdt);
14746233fbe7Smacallan
14756233fbe7Smacallan /**********************************************************************/
14766233fbe7Smacallan /* Read-write functions */
14776233fbe7Smacallan /**********************************************************************/
14786233fbe7Smacallan
14796233fbe7Smacallan int fdt_create_empty_tree(void *buf, int bufsize);
14806233fbe7Smacallan int fdt_open_into(const void *fdt, void *buf, int bufsize);
14816233fbe7Smacallan int fdt_pack(void *fdt);
14826233fbe7Smacallan
14836233fbe7Smacallan /**
14846233fbe7Smacallan * fdt_add_mem_rsv - add one memory reserve map entry
14856233fbe7Smacallan * @fdt: pointer to the device tree blob
14866233fbe7Smacallan * @address, @size: 64-bit values (native endian)
14876233fbe7Smacallan *
14886233fbe7Smacallan * Adds a reserve map entry to the given blob reserving a region at
14896233fbe7Smacallan * address address of length size.
14906233fbe7Smacallan *
14916233fbe7Smacallan * This function will insert data into the reserve map and will
14926233fbe7Smacallan * therefore change the indexes of some entries in the table.
14936233fbe7Smacallan *
14946233fbe7Smacallan * returns:
14956233fbe7Smacallan * 0, on success
14966233fbe7Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
14976233fbe7Smacallan * contain the new reservation entry
14986233fbe7Smacallan * -FDT_ERR_BADMAGIC,
14996233fbe7Smacallan * -FDT_ERR_BADVERSION,
15006233fbe7Smacallan * -FDT_ERR_BADSTATE,
15016233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
15026233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
15036233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
15046233fbe7Smacallan */
15056233fbe7Smacallan int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
15066233fbe7Smacallan
15076233fbe7Smacallan /**
15086233fbe7Smacallan * fdt_del_mem_rsv - remove a memory reserve map entry
15096233fbe7Smacallan * @fdt: pointer to the device tree blob
15106233fbe7Smacallan * @n: entry to remove
15116233fbe7Smacallan *
15126233fbe7Smacallan * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
15136233fbe7Smacallan * the blob.
15146233fbe7Smacallan *
15156233fbe7Smacallan * This function will delete data from the reservation table and will
15166233fbe7Smacallan * therefore change the indexes of some entries in the table.
15176233fbe7Smacallan *
15186233fbe7Smacallan * returns:
15196233fbe7Smacallan * 0, on success
15206233fbe7Smacallan * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
15216233fbe7Smacallan * are less than n+1 reserve map entries)
15226233fbe7Smacallan * -FDT_ERR_BADMAGIC,
15236233fbe7Smacallan * -FDT_ERR_BADVERSION,
15246233fbe7Smacallan * -FDT_ERR_BADSTATE,
15256233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
15266233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
15276233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
15286233fbe7Smacallan */
15296233fbe7Smacallan int fdt_del_mem_rsv(void *fdt, int n);
15306233fbe7Smacallan
15316233fbe7Smacallan /**
15326233fbe7Smacallan * fdt_set_name - change the name of a given node
15336233fbe7Smacallan * @fdt: pointer to the device tree blob
15346233fbe7Smacallan * @nodeoffset: structure block offset of a node
15356233fbe7Smacallan * @name: name to give the node
15366233fbe7Smacallan *
15376233fbe7Smacallan * fdt_set_name() replaces the name (including unit address, if any)
15386233fbe7Smacallan * of the given node with the given string. NOTE: this function can't
15396233fbe7Smacallan * efficiently check if the new name is unique amongst the given
15406233fbe7Smacallan * node's siblings; results are undefined if this function is invoked
15416233fbe7Smacallan * with a name equal to one of the given node's siblings.
15426233fbe7Smacallan *
15436233fbe7Smacallan * This function may insert or delete data from the blob, and will
15446233fbe7Smacallan * therefore change the offsets of some existing nodes.
15456233fbe7Smacallan *
15466233fbe7Smacallan * returns:
15476233fbe7Smacallan * 0, on success
15486233fbe7Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
15496233fbe7Smacallan * to contain the new name
15506233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
15516233fbe7Smacallan * -FDT_ERR_BADMAGIC,
15526233fbe7Smacallan * -FDT_ERR_BADVERSION,
15536233fbe7Smacallan * -FDT_ERR_BADSTATE, standard meanings
15546233fbe7Smacallan */
15556233fbe7Smacallan int fdt_set_name(void *fdt, int nodeoffset, const char *name);
15566233fbe7Smacallan
15576233fbe7Smacallan /**
15586233fbe7Smacallan * fdt_setprop - create or change a property
15596233fbe7Smacallan * @fdt: pointer to the device tree blob
15606233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
15616233fbe7Smacallan * @name: name of the property to change
15626233fbe7Smacallan * @val: pointer to data to set the property value to
15636233fbe7Smacallan * @len: length of the property value
15646233fbe7Smacallan *
15656233fbe7Smacallan * fdt_setprop() sets the value of the named property in the given
15666233fbe7Smacallan * node to the given value and length, creating the property if it
15676233fbe7Smacallan * does not already exist.
15686233fbe7Smacallan *
15696233fbe7Smacallan * This function may insert or delete data from the blob, and will
15706233fbe7Smacallan * therefore change the offsets of some existing nodes.
15716233fbe7Smacallan *
15726233fbe7Smacallan * returns:
15736233fbe7Smacallan * 0, on success
15746233fbe7Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
15756233fbe7Smacallan * contain the new property value
15766233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
15776233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
15786233fbe7Smacallan * -FDT_ERR_BADMAGIC,
15796233fbe7Smacallan * -FDT_ERR_BADVERSION,
15806233fbe7Smacallan * -FDT_ERR_BADSTATE,
15816233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
15826233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
15836233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
15846233fbe7Smacallan */
15856233fbe7Smacallan int fdt_setprop(void *fdt, int nodeoffset, const char *name,
15866233fbe7Smacallan const void *val, int len);
15876233fbe7Smacallan
15886233fbe7Smacallan /**
1589*5a485aa9Sskrll * fdt_setprop_placeholder - allocate space for a property
1590*5a485aa9Sskrll * @fdt: pointer to the device tree blob
1591*5a485aa9Sskrll * @nodeoffset: offset of the node whose property to change
1592*5a485aa9Sskrll * @name: name of the property to change
1593*5a485aa9Sskrll * @len: length of the property value
1594*5a485aa9Sskrll * @prop_data: return pointer to property data
1595*5a485aa9Sskrll *
1596*5a485aa9Sskrll * fdt_setprop_placeholer() allocates the named property in the given node.
1597*5a485aa9Sskrll * If the property exists it is resized. In either case a pointer to the
1598*5a485aa9Sskrll * property data is returned.
1599*5a485aa9Sskrll *
1600*5a485aa9Sskrll * This function may insert or delete data from the blob, and will
1601*5a485aa9Sskrll * therefore change the offsets of some existing nodes.
1602*5a485aa9Sskrll *
1603*5a485aa9Sskrll * returns:
1604*5a485aa9Sskrll * 0, on success
1605*5a485aa9Sskrll * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1606*5a485aa9Sskrll * contain the new property value
1607*5a485aa9Sskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1608*5a485aa9Sskrll * -FDT_ERR_BADLAYOUT,
1609*5a485aa9Sskrll * -FDT_ERR_BADMAGIC,
1610*5a485aa9Sskrll * -FDT_ERR_BADVERSION,
1611*5a485aa9Sskrll * -FDT_ERR_BADSTATE,
1612*5a485aa9Sskrll * -FDT_ERR_BADSTRUCTURE,
1613*5a485aa9Sskrll * -FDT_ERR_BADLAYOUT,
1614*5a485aa9Sskrll * -FDT_ERR_TRUNCATED, standard meanings
1615*5a485aa9Sskrll */
1616*5a485aa9Sskrll int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
1617*5a485aa9Sskrll int len, void **prop_data);
1618*5a485aa9Sskrll
1619*5a485aa9Sskrll /**
16206233fbe7Smacallan * fdt_setprop_u32 - set a property to a 32-bit integer
16216233fbe7Smacallan * @fdt: pointer to the device tree blob
16226233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
16236233fbe7Smacallan * @name: name of the property to change
16246233fbe7Smacallan * @val: 32-bit integer value for the property (native endian)
16256233fbe7Smacallan *
16266233fbe7Smacallan * fdt_setprop_u32() sets the value of the named property in the given
16276233fbe7Smacallan * node to the given 32-bit integer value (converting to big-endian if
16286233fbe7Smacallan * necessary), or creates a new property with that value if it does
16296233fbe7Smacallan * not already exist.
16306233fbe7Smacallan *
16316233fbe7Smacallan * This function may insert or delete data from the blob, and will
16326233fbe7Smacallan * therefore change the offsets of some existing nodes.
16336233fbe7Smacallan *
16346233fbe7Smacallan * returns:
16356233fbe7Smacallan * 0, on success
16366233fbe7Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
16376233fbe7Smacallan * contain the new property value
16386233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
16396233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
16406233fbe7Smacallan * -FDT_ERR_BADMAGIC,
16416233fbe7Smacallan * -FDT_ERR_BADVERSION,
16426233fbe7Smacallan * -FDT_ERR_BADSTATE,
16436233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
16446233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
16456233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
16466233fbe7Smacallan */
fdt_setprop_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)16476233fbe7Smacallan static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
16486233fbe7Smacallan uint32_t val)
16496233fbe7Smacallan {
16506233fbe7Smacallan fdt32_t tmp = cpu_to_fdt32(val);
16516233fbe7Smacallan return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
16526233fbe7Smacallan }
16536233fbe7Smacallan
16546233fbe7Smacallan /**
16556233fbe7Smacallan * fdt_setprop_u64 - set a property to a 64-bit integer
16566233fbe7Smacallan * @fdt: pointer to the device tree blob
16576233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
16586233fbe7Smacallan * @name: name of the property to change
16596233fbe7Smacallan * @val: 64-bit integer value for the property (native endian)
16606233fbe7Smacallan *
16616233fbe7Smacallan * fdt_setprop_u64() sets the value of the named property in the given
16626233fbe7Smacallan * node to the given 64-bit integer value (converting to big-endian if
16636233fbe7Smacallan * necessary), or creates a new property with that value if it does
16646233fbe7Smacallan * not already exist.
16656233fbe7Smacallan *
16666233fbe7Smacallan * This function may insert or delete data from the blob, and will
16676233fbe7Smacallan * therefore change the offsets of some existing nodes.
16686233fbe7Smacallan *
16696233fbe7Smacallan * returns:
16706233fbe7Smacallan * 0, on success
16716233fbe7Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
16726233fbe7Smacallan * contain the new property value
16736233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
16746233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
16756233fbe7Smacallan * -FDT_ERR_BADMAGIC,
16766233fbe7Smacallan * -FDT_ERR_BADVERSION,
16776233fbe7Smacallan * -FDT_ERR_BADSTATE,
16786233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
16796233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
16806233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
16816233fbe7Smacallan */
fdt_setprop_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)16826233fbe7Smacallan static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
16836233fbe7Smacallan uint64_t val)
16846233fbe7Smacallan {
16856233fbe7Smacallan fdt64_t tmp = cpu_to_fdt64(val);
16866233fbe7Smacallan return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
16876233fbe7Smacallan }
16886233fbe7Smacallan
16896233fbe7Smacallan /**
16906233fbe7Smacallan * fdt_setprop_cell - set a property to a single cell value
16916233fbe7Smacallan *
16926233fbe7Smacallan * This is an alternative name for fdt_setprop_u32()
16936233fbe7Smacallan */
fdt_setprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)16946233fbe7Smacallan static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
16956233fbe7Smacallan uint32_t val)
16966233fbe7Smacallan {
16976233fbe7Smacallan return fdt_setprop_u32(fdt, nodeoffset, name, val);
16986233fbe7Smacallan }
16996233fbe7Smacallan
17006233fbe7Smacallan /**
17016233fbe7Smacallan * fdt_setprop_string - set a property to a string value
17026233fbe7Smacallan * @fdt: pointer to the device tree blob
17036233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
17046233fbe7Smacallan * @name: name of the property to change
17056233fbe7Smacallan * @str: string value for the property
17066233fbe7Smacallan *
17076233fbe7Smacallan * fdt_setprop_string() sets the value of the named property in the
17086233fbe7Smacallan * given node to the given string value (using the length of the
17096233fbe7Smacallan * string to determine the new length of the property), or creates a
17106233fbe7Smacallan * new property with that value if it does not already exist.
17116233fbe7Smacallan *
17126233fbe7Smacallan * This function may insert or delete data from the blob, and will
17136233fbe7Smacallan * therefore change the offsets of some existing nodes.
17146233fbe7Smacallan *
17156233fbe7Smacallan * returns:
17166233fbe7Smacallan * 0, on success
17176233fbe7Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
17186233fbe7Smacallan * contain the new property value
17196233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
17206233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
17216233fbe7Smacallan * -FDT_ERR_BADMAGIC,
17226233fbe7Smacallan * -FDT_ERR_BADVERSION,
17236233fbe7Smacallan * -FDT_ERR_BADSTATE,
17246233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
17256233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
17266233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
17276233fbe7Smacallan */
17286233fbe7Smacallan #define fdt_setprop_string(fdt, nodeoffset, name, str) \
17296233fbe7Smacallan fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
17306233fbe7Smacallan
1731fc885a42Sskrll
1732fc885a42Sskrll /**
1733fc885a42Sskrll * fdt_setprop_empty - set a property to an empty value
1734fc885a42Sskrll * @fdt: pointer to the device tree blob
1735fc885a42Sskrll * @nodeoffset: offset of the node whose property to change
1736fc885a42Sskrll * @name: name of the property to change
1737fc885a42Sskrll *
1738fc885a42Sskrll * fdt_setprop_empty() sets the value of the named property in the
1739fc885a42Sskrll * given node to an empty (zero length) value, or creates a new empty
1740fc885a42Sskrll * property if it does not already exist.
1741fc885a42Sskrll *
1742fc885a42Sskrll * This function may insert or delete data from the blob, and will
1743fc885a42Sskrll * therefore change the offsets of some existing nodes.
1744fc885a42Sskrll *
1745fc885a42Sskrll * returns:
1746fc885a42Sskrll * 0, on success
1747fc885a42Sskrll * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1748fc885a42Sskrll * contain the new property value
1749fc885a42Sskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1750fc885a42Sskrll * -FDT_ERR_BADLAYOUT,
1751fc885a42Sskrll * -FDT_ERR_BADMAGIC,
1752fc885a42Sskrll * -FDT_ERR_BADVERSION,
1753fc885a42Sskrll * -FDT_ERR_BADSTATE,
1754fc885a42Sskrll * -FDT_ERR_BADSTRUCTURE,
1755fc885a42Sskrll * -FDT_ERR_BADLAYOUT,
1756fc885a42Sskrll * -FDT_ERR_TRUNCATED, standard meanings
1757fc885a42Sskrll */
1758fc885a42Sskrll #define fdt_setprop_empty(fdt, nodeoffset, name) \
1759fc885a42Sskrll fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)
1760fc885a42Sskrll
17616233fbe7Smacallan /**
17626233fbe7Smacallan * fdt_appendprop - append to or create a property
17636233fbe7Smacallan * @fdt: pointer to the device tree blob
17646233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
17656233fbe7Smacallan * @name: name of the property to append to
17666233fbe7Smacallan * @val: pointer to data to append to the property value
17676233fbe7Smacallan * @len: length of the data to append to the property value
17686233fbe7Smacallan *
17696233fbe7Smacallan * fdt_appendprop() appends the value to the named property in the
17706233fbe7Smacallan * given node, creating the property if it does not already exist.
17716233fbe7Smacallan *
17726233fbe7Smacallan * This function may insert data into the blob, and will therefore
17736233fbe7Smacallan * change the offsets of some existing nodes.
17746233fbe7Smacallan *
17756233fbe7Smacallan * returns:
17766233fbe7Smacallan * 0, on success
17776233fbe7Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
17786233fbe7Smacallan * contain the new property value
17796233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
17806233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
17816233fbe7Smacallan * -FDT_ERR_BADMAGIC,
17826233fbe7Smacallan * -FDT_ERR_BADVERSION,
17836233fbe7Smacallan * -FDT_ERR_BADSTATE,
17846233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
17856233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
17866233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
17876233fbe7Smacallan */
17886233fbe7Smacallan int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
17896233fbe7Smacallan const void *val, int len);
17906233fbe7Smacallan
17916233fbe7Smacallan /**
17926233fbe7Smacallan * fdt_appendprop_u32 - append a 32-bit integer value to a property
17936233fbe7Smacallan * @fdt: pointer to the device tree blob
17946233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
17956233fbe7Smacallan * @name: name of the property to change
17966233fbe7Smacallan * @val: 32-bit integer value to append to the property (native endian)
17976233fbe7Smacallan *
17986233fbe7Smacallan * fdt_appendprop_u32() appends the given 32-bit integer value
17996233fbe7Smacallan * (converting to big-endian if necessary) to the value of the named
18006233fbe7Smacallan * property in the given node, or creates a new property with that
18016233fbe7Smacallan * value if it does not already exist.
18026233fbe7Smacallan *
18036233fbe7Smacallan * This function may insert data into the blob, and will therefore
18046233fbe7Smacallan * change the offsets of some existing nodes.
18056233fbe7Smacallan *
18066233fbe7Smacallan * returns:
18076233fbe7Smacallan * 0, on success
18086233fbe7Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
18096233fbe7Smacallan * contain the new property value
18106233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
18116233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
18126233fbe7Smacallan * -FDT_ERR_BADMAGIC,
18136233fbe7Smacallan * -FDT_ERR_BADVERSION,
18146233fbe7Smacallan * -FDT_ERR_BADSTATE,
18156233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
18166233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
18176233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
18186233fbe7Smacallan */
fdt_appendprop_u32(void * fdt,int nodeoffset,const char * name,uint32_t val)18196233fbe7Smacallan static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
18206233fbe7Smacallan const char *name, uint32_t val)
18216233fbe7Smacallan {
18226233fbe7Smacallan fdt32_t tmp = cpu_to_fdt32(val);
18236233fbe7Smacallan return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
18246233fbe7Smacallan }
18256233fbe7Smacallan
18266233fbe7Smacallan /**
18276233fbe7Smacallan * fdt_appendprop_u64 - append a 64-bit integer value to a property
18286233fbe7Smacallan * @fdt: pointer to the device tree blob
18296233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
18306233fbe7Smacallan * @name: name of the property to change
18316233fbe7Smacallan * @val: 64-bit integer value to append to the property (native endian)
18326233fbe7Smacallan *
18336233fbe7Smacallan * fdt_appendprop_u64() appends the given 64-bit integer value
18346233fbe7Smacallan * (converting to big-endian if necessary) to the value of the named
18356233fbe7Smacallan * property in the given node, or creates a new property with that
18366233fbe7Smacallan * value if it does not already exist.
18376233fbe7Smacallan *
18386233fbe7Smacallan * This function may insert data into the blob, and will therefore
18396233fbe7Smacallan * change the offsets of some existing nodes.
18406233fbe7Smacallan *
18416233fbe7Smacallan * returns:
18426233fbe7Smacallan * 0, on success
18436233fbe7Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
18446233fbe7Smacallan * contain the new property value
18456233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
18466233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
18476233fbe7Smacallan * -FDT_ERR_BADMAGIC,
18486233fbe7Smacallan * -FDT_ERR_BADVERSION,
18496233fbe7Smacallan * -FDT_ERR_BADSTATE,
18506233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
18516233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
18526233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
18536233fbe7Smacallan */
fdt_appendprop_u64(void * fdt,int nodeoffset,const char * name,uint64_t val)18546233fbe7Smacallan static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
18556233fbe7Smacallan const char *name, uint64_t val)
18566233fbe7Smacallan {
18576233fbe7Smacallan fdt64_t tmp = cpu_to_fdt64(val);
18586233fbe7Smacallan return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
18596233fbe7Smacallan }
18606233fbe7Smacallan
18616233fbe7Smacallan /**
18626233fbe7Smacallan * fdt_appendprop_cell - append a single cell value to a property
18636233fbe7Smacallan *
18646233fbe7Smacallan * This is an alternative name for fdt_appendprop_u32()
18656233fbe7Smacallan */
fdt_appendprop_cell(void * fdt,int nodeoffset,const char * name,uint32_t val)18666233fbe7Smacallan static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
18676233fbe7Smacallan const char *name, uint32_t val)
18686233fbe7Smacallan {
18696233fbe7Smacallan return fdt_appendprop_u32(fdt, nodeoffset, name, val);
18706233fbe7Smacallan }
18716233fbe7Smacallan
18726233fbe7Smacallan /**
18736233fbe7Smacallan * fdt_appendprop_string - append a string to a property
18746233fbe7Smacallan * @fdt: pointer to the device tree blob
18756233fbe7Smacallan * @nodeoffset: offset of the node whose property to change
18766233fbe7Smacallan * @name: name of the property to change
18776233fbe7Smacallan * @str: string value to append to the property
18786233fbe7Smacallan *
18796233fbe7Smacallan * fdt_appendprop_string() appends the given string to the value of
18806233fbe7Smacallan * the named property in the given node, or creates a new property
18816233fbe7Smacallan * with that value if it does not already exist.
18826233fbe7Smacallan *
18836233fbe7Smacallan * This function may insert data into the blob, and will therefore
18846233fbe7Smacallan * change the offsets of some existing nodes.
18856233fbe7Smacallan *
18866233fbe7Smacallan * returns:
18876233fbe7Smacallan * 0, on success
18886233fbe7Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
18896233fbe7Smacallan * contain the new property value
18906233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
18916233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
18926233fbe7Smacallan * -FDT_ERR_BADMAGIC,
18936233fbe7Smacallan * -FDT_ERR_BADVERSION,
18946233fbe7Smacallan * -FDT_ERR_BADSTATE,
18956233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
18966233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
18976233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
18986233fbe7Smacallan */
18996233fbe7Smacallan #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
19006233fbe7Smacallan fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
19016233fbe7Smacallan
19026233fbe7Smacallan /**
1903*5a485aa9Sskrll * fdt_appendprop_addrrange - append a address range property
1904*5a485aa9Sskrll * @fdt: pointer to the device tree blob
1905*5a485aa9Sskrll * @parent: offset of the parent node
1906*5a485aa9Sskrll * @nodeoffset: offset of the node to add a property at
1907*5a485aa9Sskrll * @name: name of property
1908*5a485aa9Sskrll * @addr: start address of a given range
1909*5a485aa9Sskrll * @size: size of a given range
1910*5a485aa9Sskrll *
1911*5a485aa9Sskrll * fdt_appendprop_addrrange() appends an address range value (start
1912*5a485aa9Sskrll * address and size) to the value of the named property in the given
1913*5a485aa9Sskrll * node, or creates a new property with that value if it does not
1914*5a485aa9Sskrll * already exist.
1915*5a485aa9Sskrll * If "name" is not specified, a default "reg" is used.
1916*5a485aa9Sskrll * Cell sizes are determined by parent's #address-cells and #size-cells.
1917*5a485aa9Sskrll *
1918*5a485aa9Sskrll * This function may insert data into the blob, and will therefore
1919*5a485aa9Sskrll * change the offsets of some existing nodes.
1920*5a485aa9Sskrll *
1921*5a485aa9Sskrll * returns:
1922*5a485aa9Sskrll * 0, on success
1923*5a485aa9Sskrll * -FDT_ERR_BADLAYOUT,
1924*5a485aa9Sskrll * -FDT_ERR_BADMAGIC,
1925*5a485aa9Sskrll * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1926*5a485aa9Sskrll * #address-cells property
1927*5a485aa9Sskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1928*5a485aa9Sskrll * -FDT_ERR_BADSTATE,
1929*5a485aa9Sskrll * -FDT_ERR_BADSTRUCTURE,
1930*5a485aa9Sskrll * -FDT_ERR_BADVERSION,
1931*5a485aa9Sskrll * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size
1932*5a485aa9Sskrll * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1933*5a485aa9Sskrll * contain a new property
1934*5a485aa9Sskrll * -FDT_ERR_TRUNCATED, standard meanings
1935*5a485aa9Sskrll */
1936*5a485aa9Sskrll int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
1937*5a485aa9Sskrll const char *name, uint64_t addr, uint64_t size);
1938*5a485aa9Sskrll
1939*5a485aa9Sskrll /**
19406233fbe7Smacallan * fdt_delprop - delete a property
19416233fbe7Smacallan * @fdt: pointer to the device tree blob
19426233fbe7Smacallan * @nodeoffset: offset of the node whose property to nop
19436233fbe7Smacallan * @name: name of the property to nop
19446233fbe7Smacallan *
19456233fbe7Smacallan * fdt_del_property() will delete the given property.
19466233fbe7Smacallan *
19476233fbe7Smacallan * This function will delete data from the blob, and will therefore
19486233fbe7Smacallan * change the offsets of some existing nodes.
19496233fbe7Smacallan *
19506233fbe7Smacallan * returns:
19516233fbe7Smacallan * 0, on success
19526233fbe7Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property
19536233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
19546233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
19556233fbe7Smacallan * -FDT_ERR_BADMAGIC,
19566233fbe7Smacallan * -FDT_ERR_BADVERSION,
19576233fbe7Smacallan * -FDT_ERR_BADSTATE,
19586233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
19596233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
19606233fbe7Smacallan */
19616233fbe7Smacallan int fdt_delprop(void *fdt, int nodeoffset, const char *name);
19626233fbe7Smacallan
19636233fbe7Smacallan /**
19646233fbe7Smacallan * fdt_add_subnode_namelen - creates a new node based on substring
19656233fbe7Smacallan * @fdt: pointer to the device tree blob
19666233fbe7Smacallan * @parentoffset: structure block offset of a node
19676233fbe7Smacallan * @name: name of the subnode to locate
19686233fbe7Smacallan * @namelen: number of characters of name to consider
19696233fbe7Smacallan *
19706233fbe7Smacallan * Identical to fdt_add_subnode(), but use only the first namelen
19716233fbe7Smacallan * characters of name as the name of the new node. This is useful for
19726233fbe7Smacallan * creating subnodes based on a portion of a larger string, such as a
19736233fbe7Smacallan * full path.
19746233fbe7Smacallan */
1975*5a485aa9Sskrll #ifndef SWIG /* Not available in Python */
19766233fbe7Smacallan int fdt_add_subnode_namelen(void *fdt, int parentoffset,
19776233fbe7Smacallan const char *name, int namelen);
1978*5a485aa9Sskrll #endif
19796233fbe7Smacallan
19806233fbe7Smacallan /**
19816233fbe7Smacallan * fdt_add_subnode - creates a new node
19826233fbe7Smacallan * @fdt: pointer to the device tree blob
19836233fbe7Smacallan * @parentoffset: structure block offset of a node
19846233fbe7Smacallan * @name: name of the subnode to locate
19856233fbe7Smacallan *
19866233fbe7Smacallan * fdt_add_subnode() creates a new node as a subnode of the node at
19876233fbe7Smacallan * structure block offset parentoffset, with the given name (which
19886233fbe7Smacallan * should include the unit address, if any).
19896233fbe7Smacallan *
19906233fbe7Smacallan * This function will insert data into the blob, and will therefore
19916233fbe7Smacallan * change the offsets of some existing nodes.
19926233fbe7Smacallan
19936233fbe7Smacallan * returns:
1994fc885a42Sskrll * structure block offset of the created nodeequested subnode (>=0), on
1995fc885a42Sskrll * success
19966233fbe7Smacallan * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
1997fc885a42Sskrll * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
1998fc885a42Sskrll * tag
19996233fbe7Smacallan * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
20006233fbe7Smacallan * the given name
20016233fbe7Smacallan * -FDT_ERR_NOSPACE, if there is insufficient free space in the
20026233fbe7Smacallan * blob to contain the new node
20036233fbe7Smacallan * -FDT_ERR_NOSPACE
20046233fbe7Smacallan * -FDT_ERR_BADLAYOUT
20056233fbe7Smacallan * -FDT_ERR_BADMAGIC,
20066233fbe7Smacallan * -FDT_ERR_BADVERSION,
20076233fbe7Smacallan * -FDT_ERR_BADSTATE,
20086233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
20096233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings.
20106233fbe7Smacallan */
20116233fbe7Smacallan int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
20126233fbe7Smacallan
20136233fbe7Smacallan /**
20146233fbe7Smacallan * fdt_del_node - delete a node (subtree)
20156233fbe7Smacallan * @fdt: pointer to the device tree blob
20166233fbe7Smacallan * @nodeoffset: offset of the node to nop
20176233fbe7Smacallan *
20186233fbe7Smacallan * fdt_del_node() will remove the given node, including all its
20196233fbe7Smacallan * subnodes if any, from the blob.
20206233fbe7Smacallan *
20216233fbe7Smacallan * This function will delete data from the blob, and will therefore
20226233fbe7Smacallan * change the offsets of some existing nodes.
20236233fbe7Smacallan *
20246233fbe7Smacallan * returns:
20256233fbe7Smacallan * 0, on success
20266233fbe7Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
20276233fbe7Smacallan * -FDT_ERR_BADLAYOUT,
20286233fbe7Smacallan * -FDT_ERR_BADMAGIC,
20296233fbe7Smacallan * -FDT_ERR_BADVERSION,
20306233fbe7Smacallan * -FDT_ERR_BADSTATE,
20316233fbe7Smacallan * -FDT_ERR_BADSTRUCTURE,
20326233fbe7Smacallan * -FDT_ERR_TRUNCATED, standard meanings
20336233fbe7Smacallan */
20346233fbe7Smacallan int fdt_del_node(void *fdt, int nodeoffset);
20356233fbe7Smacallan
2036fc885a42Sskrll /**
2037fc885a42Sskrll * fdt_overlay_apply - Applies a DT overlay on a base DT
2038fc885a42Sskrll * @fdt: pointer to the base device tree blob
2039fc885a42Sskrll * @fdto: pointer to the device tree overlay blob
2040fc885a42Sskrll *
2041fc885a42Sskrll * fdt_overlay_apply() will apply the given device tree overlay on the
2042fc885a42Sskrll * given base device tree.
2043fc885a42Sskrll *
2044fc885a42Sskrll * Expect the base device tree to be modified, even if the function
2045fc885a42Sskrll * returns an error.
2046fc885a42Sskrll *
2047fc885a42Sskrll * returns:
2048fc885a42Sskrll * 0, on success
2049fc885a42Sskrll * -FDT_ERR_NOSPACE, there's not enough space in the base device tree
2050fc885a42Sskrll * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or
2051fc885a42Sskrll * properties in the base DT
2052fc885a42Sskrll * -FDT_ERR_BADPHANDLE,
2053fc885a42Sskrll * -FDT_ERR_BADOVERLAY,
2054fc885a42Sskrll * -FDT_ERR_NOPHANDLES,
2055fc885a42Sskrll * -FDT_ERR_INTERNAL,
2056fc885a42Sskrll * -FDT_ERR_BADLAYOUT,
2057fc885a42Sskrll * -FDT_ERR_BADMAGIC,
2058fc885a42Sskrll * -FDT_ERR_BADOFFSET,
2059fc885a42Sskrll * -FDT_ERR_BADPATH,
2060fc885a42Sskrll * -FDT_ERR_BADVERSION,
2061fc885a42Sskrll * -FDT_ERR_BADSTRUCTURE,
2062fc885a42Sskrll * -FDT_ERR_BADSTATE,
2063fc885a42Sskrll * -FDT_ERR_TRUNCATED, standard meanings
2064fc885a42Sskrll */
2065fc885a42Sskrll int fdt_overlay_apply(void *fdt, void *fdto);
2066fc885a42Sskrll
20676233fbe7Smacallan /**********************************************************************/
20686233fbe7Smacallan /* Debugging / informational functions */
20696233fbe7Smacallan /**********************************************************************/
20706233fbe7Smacallan
20716233fbe7Smacallan const char *fdt_strerror(int errval);
20726233fbe7Smacallan
2073*5a485aa9Sskrll #endif /* LIBFDT_H */
2074