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