blob: 88ea3e378255a6f81729fc05b948a6d55f4a3cdd [file] [log] [blame]
David Gibson3da0f9a2006-11-27 16:21:28 +11001#ifndef _LIBFDT_H
2#define _LIBFDT_H
3/*
4 * libfdt - Flat Device Tree manipulation
5 * Copyright (C) 2006 David Gibson, IBM Corporation.
6 *
David Gibson94816052007-06-13 16:30:48 +10007 * libfdt is dual licensed: you can use it either under the terms of
8 * the GPL, or the BSD license, at your option.
David Gibson3da0f9a2006-11-27 16:21:28 +11009 *
David Gibson94816052007-06-13 16:30:48 +100010 * a) This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of the
13 * License, or (at your option) any later version.
David Gibson3da0f9a2006-11-27 16:21:28 +110014 *
David Gibson94816052007-06-13 16:30:48 +100015 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this library; if not, write to the Free
22 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
23 * MA 02110-1301 USA
24 *
25 * Alternatively,
26 *
27 * b) Redistribution and use in source and binary forms, with or
28 * without modification, are permitted provided that the following
29 * conditions are met:
30 *
31 * 1. Redistributions of source code must retain the above
32 * copyright notice, this list of conditions and the following
33 * disclaimer.
34 * 2. Redistributions in binary form must reproduce the above
35 * copyright notice, this list of conditions and the following
36 * disclaimer in the documentation and/or other materials
37 * provided with the distribution.
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
40 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
41 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
44 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
50 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
51 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
David Gibson3da0f9a2006-11-27 16:21:28 +110052 */
53
David Gibsonede25de2006-12-01 15:02:10 +110054#include <libfdt_env.h>
David Gibson6f8b7712007-10-16 13:50:34 +100055#include <fdt.h>
David Gibson3da0f9a2006-11-27 16:21:28 +110056
57#define FDT_FIRST_SUPPORTED_VERSION 0x10
David Gibsonfe92f6b2006-12-01 16:25:39 +110058#define FDT_LAST_SUPPORTED_VERSION 0x11
David Gibson3da0f9a2006-11-27 16:21:28 +110059
David Gibson3aea8282006-12-15 15:12:52 +110060/* Error codes: informative error codes */
61#define FDT_ERR_NOTFOUND 1
David Gibsoncec0c382007-10-24 17:10:58 +100062 /* FDT_ERR_NOTFOUND: The requested node or property does not exist */
David Gibson3aea8282006-12-15 15:12:52 +110063#define FDT_ERR_EXISTS 2
David Gibsoncec0c382007-10-24 17:10:58 +100064 /* FDT_ERR_EXISTS: Attemped to create a node or property which
65 * already exists */
David Gibson3aea8282006-12-15 15:12:52 +110066#define FDT_ERR_NOSPACE 3
David Gibsoncec0c382007-10-24 17:10:58 +100067 /* FDT_ERR_NOSPACE: Operation needed to expand the device
68 * tree, but its buffer did not have sufficient space to
69 * contain the expanded tree. Use fdt_open_into() to move the
70 * device tree to a buffer with more space. */
David Gibson3da0f9a2006-11-27 16:21:28 +110071
David Gibson3aea8282006-12-15 15:12:52 +110072/* Error codes: codes for bad parameters */
73#define FDT_ERR_BADOFFSET 4
David Gibsoncec0c382007-10-24 17:10:58 +100074 /* FDT_ERR_BADOFFSET: Function was passed a structure block
75 * offset which is out-of-bounds, or which points to an
76 * unsuitable part of the structure for the operation. */
David Gibson3aea8282006-12-15 15:12:52 +110077#define FDT_ERR_BADPATH 5
David Gibsoncec0c382007-10-24 17:10:58 +100078 /* FDT_ERR_BADPATH: Function was passed a badly formatted path
79 * (e.g. missing a leading / for a function which requires an
80 * absolute path) */
David Gibson73468582007-11-13 09:59:38 +110081#define FDT_ERR_BADPHANDLE 6
82 /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle
83 * value. phandle values of 0 and -1 are not permitted. */
84#define FDT_ERR_BADSTATE 7
David Gibsoncec0c382007-10-24 17:10:58 +100085 /* FDT_ERR_BADSTATE: Function was passed an incomplete device
86 * tree created by the sequential-write functions, which is
87 * not sufficiently complete for the requested operation. */
David Gibson3aea8282006-12-15 15:12:52 +110088
89/* Error codes: codes for bad device tree blobs */
David Gibson73468582007-11-13 09:59:38 +110090#define FDT_ERR_TRUNCATED 8
David Gibsoncec0c382007-10-24 17:10:58 +100091 /* FDT_ERR_TRUNCATED: Structure block of the given device tree
92 * ends without an FDT_END tag. */
David Gibson73468582007-11-13 09:59:38 +110093#define FDT_ERR_BADMAGIC 9
David Gibsoncec0c382007-10-24 17:10:58 +100094 /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
95 * device tree at all - it is missing the flattened device
96 * tree magic number. */
David Gibson73468582007-11-13 09:59:38 +110097#define FDT_ERR_BADVERSION 10
David Gibsoncec0c382007-10-24 17:10:58 +100098 /* FDT_ERR_BADVERSION: Given device tree has a version which
99 * can't be handled by the requested operation. For
100 * read-write functions, this may mean that fdt_open_into() is
101 * required to convert the tree to the expected version. */
David Gibson73468582007-11-13 09:59:38 +1100102#define FDT_ERR_BADSTRUCTURE 11
David Gibsoncec0c382007-10-24 17:10:58 +1000103 /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt
104 * structure block or other serious error (e.g. misnested
105 * nodes, or subnodes preceding properties). */
David Gibson73468582007-11-13 09:59:38 +1100106#define FDT_ERR_BADLAYOUT 12
David Gibsoncec0c382007-10-24 17:10:58 +1000107 /* FDT_ERR_BADLAYOUT: For read-write functions, the given
108 * device tree has it's sub-blocks in an order that the
109 * function can't handle (memory reserve map, then structure,
110 * then strings). Use fdt_open_into() to reorganize the tree
111 * into a form suitable for the read-write operations. */
David Gibson3aea8282006-12-15 15:12:52 +1100112
David Gibson12482372007-08-30 14:54:04 +1000113/* "Can't happen" error indicating a bug in libfdt */
David Gibson73468582007-11-13 09:59:38 +1100114#define FDT_ERR_INTERNAL 13
David Gibsoncec0c382007-10-24 17:10:58 +1000115 /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion.
David Gibson9d3af7a2007-11-05 14:29:37 +1100116 * Should never be returned, if it is, it indicates a bug in
117 * libfdt itself. */
David Gibson12482372007-08-30 14:54:04 +1000118
David Gibson73468582007-11-13 09:59:38 +1100119#define FDT_ERR_MAX 13
David Gibson3da0f9a2006-11-27 16:21:28 +1100120
David Gibsoncec0c382007-10-24 17:10:58 +1000121/**********************************************************************/
122/* Low-level functions (you probably don't need these) */
123/**********************************************************************/
David Gibson96b5fad2007-10-24 10:28:52 +1000124
Jon Loeligerb2368932008-09-25 11:02:17 -0500125const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
David Gibson96b5fad2007-10-24 10:28:52 +1000126static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
127{
David Gibson14090972008-07-07 10:14:15 +1000128 return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);
David Gibson96b5fad2007-10-24 10:28:52 +1000129}
130
David Gibson3c44c872007-10-24 11:06:09 +1000131uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
David Gibson96b5fad2007-10-24 10:28:52 +1000132
David Gibsoncec0c382007-10-24 17:10:58 +1000133/**********************************************************************/
David Gibsonfc9769a2008-02-12 11:58:31 +1100134/* Traversal functions */
135/**********************************************************************/
136
137int fdt_next_node(const void *fdt, int offset, int *depth);
138
Kishor PK0a749fe2017-07-13 15:32:31 +0530139/**
140 * fdt_first_subnode() - get offset of first direct subnode
141 *
142 * @fdt: FDT blob
143 * @offset: Offset of node to check
144 * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none
145 */
146int fdt_first_subnode(const void *fdt, int offset);
147
148/**
149 * fdt_next_subnode() - get offset of next direct subnode
150 *
151 * After first calling fdt_first_subnode(), call this function repeatedly to
152 * get direct subnodes of a parent node.
153 *
154 * @fdt: FDT blob
155 * @offset: Offset of previous subnode
156 * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more
157 * subnodes
158 */
159int fdt_next_subnode(const void *fdt, int offset);
160
David Gibsonfc9769a2008-02-12 11:58:31 +1100161/**********************************************************************/
David Gibsoncec0c382007-10-24 17:10:58 +1000162/* General functions */
163/**********************************************************************/
164
David Gibson73d60922006-12-15 15:12:47 +1100165#define fdt_get_header(fdt, field) \
David Gibsona6c76f92007-06-13 14:18:10 +1000166 (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
David Gibson73d60922006-12-15 15:12:47 +1100167#define fdt_magic(fdt) (fdt_get_header(fdt, magic))
168#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
169#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
170#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
171#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
172#define fdt_version(fdt) (fdt_get_header(fdt, version))
173#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
174#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
175#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
176#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
David Gibsonede25de2006-12-01 15:02:10 +1100177
David Gibson9b911342007-10-25 14:29:38 +1000178#define __fdt_set_hdr(name) \
179 static inline void fdt_set_##name(void *fdt, uint32_t val) \
180 { \
Laurent Gregoiref281f522009-03-03 14:23:59 +0100181 struct fdt_header *fdth = (struct fdt_header*)fdt; \
David Gibson9b911342007-10-25 14:29:38 +1000182 fdth->name = cpu_to_fdt32(val); \
183 }
184__fdt_set_hdr(magic);
185__fdt_set_hdr(totalsize);
186__fdt_set_hdr(off_dt_struct);
187__fdt_set_hdr(off_dt_strings);
188__fdt_set_hdr(off_mem_rsvmap);
189__fdt_set_hdr(version);
190__fdt_set_hdr(last_comp_version);
191__fdt_set_hdr(boot_cpuid_phys);
192__fdt_set_hdr(size_dt_strings);
193__fdt_set_hdr(size_dt_struct);
194#undef __fdt_set_hdr
David Gibson73d60922006-12-15 15:12:47 +1100195
David Gibsoncec0c382007-10-24 17:10:58 +1000196/**
197 * fdt_check_header - sanity check a device tree or possible device tree
198 * @fdt: pointer to data which might be a flattened device tree
199 *
200 * fdt_check_header() checks that the given buffer contains what
201 * appears to be a flattened device tree with sane information in its
202 * header.
203 *
204 * returns:
205 * 0, if the buffer appears to contain a valid device tree
206 * -FDT_ERR_BADMAGIC,
207 * -FDT_ERR_BADVERSION,
208 * -FDT_ERR_BADSTATE, standard meanings, as above
209 */
David Gibson96b5fad2007-10-24 10:28:52 +1000210int fdt_check_header(const void *fdt);
David Gibsoncec0c382007-10-24 17:10:58 +1000211
212/**
213 * fdt_move - move a device tree around in memory
214 * @fdt: pointer to the device tree to move
215 * @buf: pointer to memory where the device is to be moved
216 * @bufsize: size of the memory space at buf
217 *
218 * fdt_move() relocates, if possible, the device tree blob located at
219 * fdt to the buffer at buf of size bufsize. The buffer may overlap
220 * with the existing device tree blob at fdt. Therefore,
221 * fdt_move(fdt, fdt, fdt_totalsize(fdt))
222 * should always succeed.
223 *
224 * returns:
225 * 0, on success
226 * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree
227 * -FDT_ERR_BADMAGIC,
228 * -FDT_ERR_BADVERSION,
229 * -FDT_ERR_BADSTATE, standard meanings
230 */
David Gibson73d60922006-12-15 15:12:47 +1100231int fdt_move(const void *fdt, void *buf, int bufsize);
David Gibson42369762006-12-01 15:07:19 +1100232
David Gibsoncec0c382007-10-24 17:10:58 +1000233/**********************************************************************/
234/* Read-only functions */
235/**********************************************************************/
236
237/**
Wolfram Sang08309aa2008-07-09 11:22:44 +0200238 * fdt_string - retrieve a string from the strings block of a device tree
David Gibsoncec0c382007-10-24 17:10:58 +1000239 * @fdt: pointer to the device tree blob
240 * @stroffset: offset of the string within the strings block (native endian)
241 *
242 * fdt_string() retrieves a pointer to a single string from the
243 * strings block of the device tree blob at fdt.
244 *
245 * returns:
246 * a pointer to the string, on success
247 * NULL, if stroffset is out of bounds
248 */
David Gibson11d53022007-10-18 12:10:42 +1000249const char *fdt_string(const void *fdt, int stroffset);
David Gibson3aa4cfd2006-11-29 16:34:30 +1100250
David Gibsoncec0c382007-10-24 17:10:58 +1000251/**
Wolfram Sang08309aa2008-07-09 11:22:44 +0200252 * fdt_num_mem_rsv - retrieve the number of memory reserve map entries
David Gibsoncec0c382007-10-24 17:10:58 +1000253 * @fdt: pointer to the device tree blob
254 *
255 * Returns the number of entries in the device tree blob's memory
256 * reservation map. This does not include the terminating 0,0 entry
257 * or any other (0,0) entries reserved for expansion.
258 *
259 * returns:
260 * the number of entries
261 */
David Gibsonfd1bf3a2007-10-10 17:12:12 +1000262int fdt_num_mem_rsv(const void *fdt);
263
David Gibsoncec0c382007-10-24 17:10:58 +1000264/**
Wolfram Sang08309aa2008-07-09 11:22:44 +0200265 * fdt_get_mem_rsv - retrieve one memory reserve map entry
David Gibsoncec0c382007-10-24 17:10:58 +1000266 * @fdt: pointer to the device tree blob
267 * @address, @size: pointers to 64-bit variables
268 *
269 * On success, *address and *size will contain the address and size of
270 * the n-th reserve map entry from the device tree blob, in
271 * native-endian format.
272 *
273 * returns:
274 * 0, on success
275 * -FDT_ERR_BADMAGIC,
276 * -FDT_ERR_BADVERSION,
277 * -FDT_ERR_BADSTATE, standard meanings
278 */
279int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size);
280
David Gibson57f99b72007-10-25 11:27:31 +1000281/**
282 * fdt_subnode_offset_namelen - find a subnode based on substring
283 * @fdt: pointer to the device tree blob
284 * @parentoffset: structure block offset of a node
285 * @name: name of the subnode to locate
286 * @namelen: number of characters of name to consider
287 *
288 * Identical to fdt_subnode_offset(), but only examine the first
289 * namelen characters of name for matching the subnode name. This is
290 * useful for finding subnodes based on a portion of a larger string,
291 * such as a full path.
292 */
David Gibson73d60922006-12-15 15:12:47 +1100293int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
David Gibson3da0f9a2006-11-27 16:21:28 +1100294 const char *name, int namelen);
David Gibson57f99b72007-10-25 11:27:31 +1000295/**
296 * fdt_subnode_offset - find a subnode of a given node
297 * @fdt: pointer to the device tree blob
298 * @parentoffset: structure block offset of a node
299 * @name: name of the subnode to locate
300 *
301 * fdt_subnode_offset() finds a subnode of the node at structure block
302 * offset parentoffset with the given name. name may include a unit
303 * address, in which case fdt_subnode_offset() will find the subnode
304 * with that unit address, or the unit address may be omitted, in
305 * which case fdt_subnode_offset() will find an arbitrary subnode
306 * whose name excluding unit address matches the given name.
307 *
308 * returns:
309 * structure block offset of the requested subnode (>=0), on success
310 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
311 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
312 * -FDT_ERR_BADMAGIC,
313 * -FDT_ERR_BADVERSION,
314 * -FDT_ERR_BADSTATE,
315 * -FDT_ERR_BADSTRUCTURE,
316 * -FDT_ERR_TRUNCATED, standard meanings.
317 */
David Gibson73d60922006-12-15 15:12:47 +1100318int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
David Gibson3da0f9a2006-11-27 16:21:28 +1100319
David Gibson57f99b72007-10-25 11:27:31 +1000320/**
321 * fdt_path_offset - find a tree node by its full path
322 * @fdt: pointer to the device tree blob
323 * @path: full path of the node to locate
324 *
325 * fdt_path_offset() finds a node of a given path in the device tree.
326 * Each path component may omit the unit address portion, but the
327 * results of this are undefined if any such path component is
328 * ambiguous (that is if there are multiple nodes at the relevant
329 * level matching the given component, differentiated only by unit
330 * address).
331 *
332 * returns:
333 * structure block offset of the node with the requested path (>=0), on success
334 * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
335 * -FDT_ERR_NOTFOUND, if the requested node does not exist
336 * -FDT_ERR_BADMAGIC,
337 * -FDT_ERR_BADVERSION,
338 * -FDT_ERR_BADSTATE,
339 * -FDT_ERR_BADSTRUCTURE,
340 * -FDT_ERR_TRUNCATED, standard meanings.
341 */
David Gibson73d60922006-12-15 15:12:47 +1100342int fdt_path_offset(const void *fdt, const char *path);
David Gibson3da0f9a2006-11-27 16:21:28 +1100343
David Gibson57f99b72007-10-25 11:27:31 +1000344/**
Wolfram Sang08309aa2008-07-09 11:22:44 +0200345 * fdt_get_name - retrieve the name of a given node
David Gibson57f99b72007-10-25 11:27:31 +1000346 * @fdt: pointer to the device tree blob
347 * @nodeoffset: structure block offset of the starting node
David Gibson2ec634d2007-11-05 14:29:18 +1100348 * @lenp: pointer to an integer variable (will be overwritten) or NULL
David Gibson57f99b72007-10-25 11:27:31 +1000349 *
350 * fdt_get_name() retrieves the name (including unit address) of the
David Gibson2ec634d2007-11-05 14:29:18 +1100351 * device tree node at structure block offset nodeoffset. If lenp is
David Gibson57f99b72007-10-25 11:27:31 +1000352 * non-NULL, the length of this name is also returned, in the integer
David Gibson2ec634d2007-11-05 14:29:18 +1100353 * pointed to by lenp.
David Gibson57f99b72007-10-25 11:27:31 +1000354 *
355 * returns:
356 * pointer to the node's name, on success
David Gibson2ec634d2007-11-05 14:29:18 +1100357 * If lenp is non-NULL, *lenp contains the length of that name (>=0)
David Gibson57f99b72007-10-25 11:27:31 +1000358 * NULL, on error
David Gibson2ec634d2007-11-05 14:29:18 +1100359 * if lenp is non-NULL *lenp contains an error code (<0):
David Gibson57f99b72007-10-25 11:27:31 +1000360 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
361 * -FDT_ERR_BADMAGIC,
362 * -FDT_ERR_BADVERSION,
363 * -FDT_ERR_BADSTATE, standard meanings
364 */
David Gibson2ec634d2007-11-05 14:29:18 +1100365const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp);
David Gibson9d26eab2007-08-30 14:54:04 +1000366
David Gibson2ec634d2007-11-05 14:29:18 +1100367/**
David Gibson73dca9a2010-03-09 17:39:14 +1100368 * fdt_first_property_offset - find the offset of a node's first property
369 * @fdt: pointer to the device tree blob
370 * @nodeoffset: structure block offset of a node
371 *
372 * fdt_first_property_offset() finds the first property of the node at
373 * the given structure block offset.
374 *
375 * returns:
376 * structure block offset of the property (>=0), on success
377 * -FDT_ERR_NOTFOUND, if the requested node has no properties
378 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag
379 * -FDT_ERR_BADMAGIC,
380 * -FDT_ERR_BADVERSION,
381 * -FDT_ERR_BADSTATE,
382 * -FDT_ERR_BADSTRUCTURE,
383 * -FDT_ERR_TRUNCATED, standard meanings.
384 */
385int fdt_first_property_offset(const void *fdt, int nodeoffset);
386
387/**
388 * fdt_next_property_offset - step through a node's properties
389 * @fdt: pointer to the device tree blob
390 * @offset: structure block offset of a property
391 *
392 * fdt_next_property_offset() finds the property immediately after the
393 * one at the given structure block offset. This will be a property
394 * of the same node as the given property.
395 *
396 * returns:
397 * structure block offset of the next property (>=0), on success
398 * -FDT_ERR_NOTFOUND, if the given property is the last in its node
399 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag
400 * -FDT_ERR_BADMAGIC,
401 * -FDT_ERR_BADVERSION,
402 * -FDT_ERR_BADSTATE,
403 * -FDT_ERR_BADSTRUCTURE,
404 * -FDT_ERR_TRUNCATED, standard meanings.
405 */
406int fdt_next_property_offset(const void *fdt, int offset);
407
408/**
409 * fdt_get_property_by_offset - retrieve the property at a given offset
410 * @fdt: pointer to the device tree blob
411 * @offset: offset of the property to retrieve
412 * @lenp: pointer to an integer variable (will be overwritten) or NULL
413 *
414 * fdt_get_property_by_offset() retrieves a pointer to the
415 * fdt_property structure within the device tree blob at the given
416 * offset. If lenp is non-NULL, the length of the property value is
417 * also returned, in the integer pointed to by lenp.
418 *
419 * returns:
420 * pointer to the structure representing the property
421 * if lenp is non-NULL, *lenp contains the length of the property
422 * value (>=0)
423 * NULL, on error
424 * if lenp is non-NULL, *lenp contains an error code (<0):
425 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
426 * -FDT_ERR_BADMAGIC,
427 * -FDT_ERR_BADVERSION,
428 * -FDT_ERR_BADSTATE,
429 * -FDT_ERR_BADSTRUCTURE,
430 * -FDT_ERR_TRUNCATED, standard meanings
431 */
432const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
433 int offset,
434 int *lenp);
435
436/**
David Gibsoncb650ae2008-08-06 14:50:49 +1000437 * fdt_get_property_namelen - find a property based on substring
438 * @fdt: pointer to the device tree blob
439 * @nodeoffset: offset of the node whose property to find
440 * @name: name of the property to find
441 * @namelen: number of characters of name to consider
442 * @lenp: pointer to an integer variable (will be overwritten) or NULL
443 *
444 * Identical to fdt_get_property_namelen(), but only examine the first
445 * namelen characters of name for matching the property name.
446 */
447const struct fdt_property *fdt_get_property_namelen(const void *fdt,
448 int nodeoffset,
449 const char *name,
450 int namelen, int *lenp);
451
452/**
David Gibson2ec634d2007-11-05 14:29:18 +1100453 * fdt_get_property - find a given property in a given node
454 * @fdt: pointer to the device tree blob
455 * @nodeoffset: offset of the node whose property to find
456 * @name: name of the property to find
457 * @lenp: pointer to an integer variable (will be overwritten) or NULL
458 *
459 * fdt_get_property() retrieves a pointer to the fdt_property
460 * structure within the device tree blob corresponding to the property
461 * named 'name' of the node at offset nodeoffset. If lenp is
Wolfram Sang08309aa2008-07-09 11:22:44 +0200462 * non-NULL, the length of the property value is also returned, in the
David Gibson2ec634d2007-11-05 14:29:18 +1100463 * integer pointed to by lenp.
464 *
465 * returns:
466 * pointer to the structure representing the property
467 * if lenp is non-NULL, *lenp contains the length of the property
468 * value (>=0)
469 * NULL, on error
470 * if lenp is non-NULL, *lenp contains an error code (<0):
471 * -FDT_ERR_NOTFOUND, node does not have named property
472 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
473 * -FDT_ERR_BADMAGIC,
474 * -FDT_ERR_BADVERSION,
475 * -FDT_ERR_BADSTATE,
476 * -FDT_ERR_BADSTRUCTURE,
477 * -FDT_ERR_TRUNCATED, standard meanings
478 */
David Gibsona6c76f92007-06-13 14:18:10 +1000479const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
480 const char *name, int *lenp);
David Gibsona6c76f92007-06-13 14:18:10 +1000481static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset,
482 const char *name,
483 int *lenp)
484{
David Gibson14090972008-07-07 10:14:15 +1000485 return (struct fdt_property *)(uintptr_t)
486 fdt_get_property(fdt, nodeoffset, name, lenp);
David Gibsona6c76f92007-06-13 14:18:10 +1000487}
488
David Gibson2ec634d2007-11-05 14:29:18 +1100489/**
David Gibson73dca9a2010-03-09 17:39:14 +1100490 * fdt_getprop_by_offset - retrieve the value of a property at a given offset
491 * @fdt: pointer to the device tree blob
492 * @ffset: offset of the property to read
493 * @namep: pointer to a string variable (will be overwritten) or NULL
494 * @lenp: pointer to an integer variable (will be overwritten) or NULL
495 *
496 * fdt_getprop_by_offset() retrieves a pointer to the value of the
497 * property at structure block offset 'offset' (this will be a pointer
498 * to within the device blob itself, not a copy of the value). If
499 * lenp is non-NULL, the length of the property value is also
500 * returned, in the integer pointed to by lenp. If namep is non-NULL,
501 * the property's namne will also be returned in the char * pointed to
502 * by namep (this will be a pointer to within the device tree's string
503 * block, not a new copy of the name).
504 *
505 * returns:
506 * pointer to the property's value
507 * if lenp is non-NULL, *lenp contains the length of the property
508 * value (>=0)
509 * if namep is non-NULL *namep contiains a pointer to the property
510 * name.
511 * NULL, on error
512 * if lenp is non-NULL, *lenp contains an error code (<0):
513 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag
514 * -FDT_ERR_BADMAGIC,
515 * -FDT_ERR_BADVERSION,
516 * -FDT_ERR_BADSTATE,
517 * -FDT_ERR_BADSTRUCTURE,
518 * -FDT_ERR_TRUNCATED, standard meanings
519 */
520const void *fdt_getprop_by_offset(const void *fdt, int offset,
521 const char **namep, int *lenp);
522
523/**
David Gibsoncb650ae2008-08-06 14:50:49 +1000524 * fdt_getprop_namelen - get property value based on substring
525 * @fdt: pointer to the device tree blob
526 * @nodeoffset: offset of the node whose property to find
527 * @name: name of the property to find
528 * @namelen: number of characters of name to consider
529 * @lenp: pointer to an integer variable (will be overwritten) or NULL
530 *
531 * Identical to fdt_getprop(), but only examine the first namelen
532 * characters of name for matching the property name.
533 */
534const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,
535 const char *name, int namelen, int *lenp);
536
537/**
David Gibson2ec634d2007-11-05 14:29:18 +1100538 * fdt_getprop - retrieve the value of a given property
539 * @fdt: pointer to the device tree blob
540 * @nodeoffset: offset of the node whose property to find
541 * @name: name of the property to find
542 * @lenp: pointer to an integer variable (will be overwritten) or NULL
543 *
544 * fdt_getprop() retrieves a pointer to the value of the property
545 * named 'name' of the node at offset nodeoffset (this will be a
546 * pointer to within the device blob itself, not a copy of the value).
Wolfram Sang08309aa2008-07-09 11:22:44 +0200547 * If lenp is non-NULL, the length of the property value is also
David Gibson2ec634d2007-11-05 14:29:18 +1100548 * returned, in the integer pointed to by lenp.
549 *
550 * returns:
551 * pointer to the property's value
552 * if lenp is non-NULL, *lenp contains the length of the property
553 * value (>=0)
554 * NULL, on error
555 * if lenp is non-NULL, *lenp contains an error code (<0):
556 * -FDT_ERR_NOTFOUND, node does not have named property
557 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
558 * -FDT_ERR_BADMAGIC,
559 * -FDT_ERR_BADVERSION,
560 * -FDT_ERR_BADSTATE,
561 * -FDT_ERR_BADSTRUCTURE,
562 * -FDT_ERR_TRUNCATED, standard meanings
563 */
David Gibsona6c76f92007-06-13 14:18:10 +1000564const void *fdt_getprop(const void *fdt, int nodeoffset,
565 const char *name, int *lenp);
566static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
567 const char *name, int *lenp)
568{
David Gibson14090972008-07-07 10:14:15 +1000569 return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp);
David Gibsona6c76f92007-06-13 14:18:10 +1000570}
David Gibson3da0f9a2006-11-27 16:21:28 +1100571
David Gibson2ec634d2007-11-05 14:29:18 +1100572/**
Wolfram Sang08309aa2008-07-09 11:22:44 +0200573 * fdt_get_phandle - retrieve the phandle of a given node
David Gibson73468582007-11-13 09:59:38 +1100574 * @fdt: pointer to the device tree blob
575 * @nodeoffset: structure block offset of the node
576 *
577 * fdt_get_phandle() retrieves the phandle of the device tree node at
578 * structure block offset nodeoffset.
579 *
580 * returns:
Wolfram Sang08309aa2008-07-09 11:22:44 +0200581 * the phandle of the node at nodeoffset, on success (!= 0, != -1)
David Gibson73468582007-11-13 09:59:38 +1100582 * 0, if the node has no phandle, or another error occurs
583 */
584uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
585
586/**
David Gibson75bdd842009-01-05 12:46:00 +1100587 * fdt_get_alias_namelen - get alias based on substring
David Gibson9c831152008-08-20 16:55:14 +1000588 * @fdt: pointer to the device tree blob
589 * @name: name of the alias th look up
590 * @namelen: number of characters of name to consider
591 *
592 * Identical to fdt_get_alias(), but only examine the first namelen
593 * characters of name for matching the alias name.
594 */
595const char *fdt_get_alias_namelen(const void *fdt,
596 const char *name, int namelen);
597
598/**
599 * fdt_get_alias - retreive the path referenced by a given alias
600 * @fdt: pointer to the device tree blob
601 * @name: name of the alias th look up
602 *
603 * fdt_get_alias() retrieves the value of a given alias. That is, the
604 * value of the property named 'name' in the node /aliases.
605 *
606 * returns:
607 * a pointer to the expansion of the alias named 'name', of it exists
608 * NULL, if the given alias or the /aliases node does not exist
609 */
610const char *fdt_get_alias(const void *fdt, const char *name);
611
612/**
David Gibson2ec634d2007-11-05 14:29:18 +1100613 * fdt_get_path - determine the full path of a node
614 * @fdt: pointer to the device tree blob
615 * @nodeoffset: offset of the node whose path to find
616 * @buf: character buffer to contain the returned path (will be overwritten)
617 * @buflen: size of the character buffer at buf
618 *
619 * fdt_get_path() computes the full path of the node at offset
620 * nodeoffset, and records that path in the buffer at buf.
621 *
622 * NOTE: This function is expensive, as it must scan the device tree
623 * structure from the start to nodeoffset.
624 *
625 * returns:
626 * 0, on success
627 * buf contains the absolute path of the node at
628 * nodeoffset, as a NUL-terminated string.
629 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
630 * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)
631 * characters and will not fit in the given buffer.
632 * -FDT_ERR_BADMAGIC,
633 * -FDT_ERR_BADVERSION,
634 * -FDT_ERR_BADSTATE,
635 * -FDT_ERR_BADSTRUCTURE, standard meanings
636 */
David Gibson037db262007-08-30 14:54:04 +1000637int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
638
David Gibson9d3af7a2007-11-05 14:29:37 +1100639/**
640 * fdt_supernode_atdepth_offset - find a specific ancestor of a node
641 * @fdt: pointer to the device tree blob
642 * @nodeoffset: offset of the node whose parent to find
643 * @supernodedepth: depth of the ancestor to find
644 * @nodedepth: pointer to an integer variable (will be overwritten) or NULL
645 *
646 * fdt_supernode_atdepth_offset() finds an ancestor of the given node
647 * at a specific depth from the root (where the root itself has depth
648 * 0, its immediate subnodes depth 1 and so forth). So
649 * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL);
650 * will always return 0, the offset of the root node. If the node at
651 * nodeoffset has depth D, then:
652 * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL);
653 * will return nodeoffset itself.
654 *
655 * NOTE: This function is expensive, as it must scan the device tree
656 * structure from the start to nodeoffset.
657 *
658 * returns:
659
660 * structure block offset of the node at node offset's ancestor
661 * of depth supernodedepth (>=0), on success
662 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
663* -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset
664 * -FDT_ERR_BADMAGIC,
665 * -FDT_ERR_BADVERSION,
666 * -FDT_ERR_BADSTATE,
667 * -FDT_ERR_BADSTRUCTURE, standard meanings
668 */
David Gibson12482372007-08-30 14:54:04 +1000669int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset,
670 int supernodedepth, int *nodedepth);
David Gibson9d3af7a2007-11-05 14:29:37 +1100671
672/**
673 * fdt_node_depth - find the depth of a given node
674 * @fdt: pointer to the device tree blob
675 * @nodeoffset: offset of the node whose parent to find
676 *
677 * fdt_node_depth() finds the depth of a given node. The root node
678 * has depth 0, its immediate subnodes depth 1 and so forth.
679 *
680 * NOTE: This function is expensive, as it must scan the device tree
681 * structure from the start to nodeoffset.
682 *
683 * returns:
684 * depth of the node at nodeoffset (>=0), on success
685 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
686 * -FDT_ERR_BADMAGIC,
687 * -FDT_ERR_BADVERSION,
688 * -FDT_ERR_BADSTATE,
689 * -FDT_ERR_BADSTRUCTURE, standard meanings
690 */
David Gibson12482372007-08-30 14:54:04 +1000691int fdt_node_depth(const void *fdt, int nodeoffset);
David Gibson9d3af7a2007-11-05 14:29:37 +1100692
693/**
694 * fdt_parent_offset - find the parent of a given node
695 * @fdt: pointer to the device tree blob
696 * @nodeoffset: offset of the node whose parent to find
697 *
698 * fdt_parent_offset() locates the parent node of a given node (that
699 * is, it finds the offset of the node which contains the node at
700 * nodeoffset as a subnode).
701 *
702 * NOTE: This function is expensive, as it must scan the device tree
703 * structure from the start to nodeoffset, *twice*.
704 *
705 * returns:
Wolfram Sang08309aa2008-07-09 11:22:44 +0200706 * structure block offset of the parent of the node at nodeoffset
David Gibson9d3af7a2007-11-05 14:29:37 +1100707 * (>=0), on success
708 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
709 * -FDT_ERR_BADMAGIC,
710 * -FDT_ERR_BADVERSION,
711 * -FDT_ERR_BADSTATE,
712 * -FDT_ERR_BADSTRUCTURE, standard meanings
713 */
David Gibson12482372007-08-30 14:54:04 +1000714int fdt_parent_offset(const void *fdt, int nodeoffset);
715
David Gibson53acf492007-11-07 11:54:14 +1100716/**
717 * fdt_node_offset_by_prop_value - find nodes with a given property value
718 * @fdt: pointer to the device tree blob
719 * @startoffset: only find nodes after this offset
720 * @propname: property name to check
721 * @propval: property value to search for
722 * @proplen: length of the value in propval
723 *
724 * fdt_node_offset_by_prop_value() returns the offset of the first
725 * node after startoffset, which has a property named propname whose
726 * value is of length proplen and has value equal to propval; or if
727 * startoffset is -1, the very first such node in the tree.
728 *
729 * To iterate through all nodes matching the criterion, the following
730 * idiom can be used:
731 * offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
732 * propval, proplen);
733 * while (offset != -FDT_ERR_NOTFOUND) {
734 * // other code here
735 * offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
736 * propval, proplen);
737 * }
738 *
739 * Note the -1 in the first call to the function, if 0 is used here
740 * instead, the function will never locate the root node, even if it
741 * matches the criterion.
742 *
743 * returns:
744 * structure block offset of the located node (>= 0, >startoffset),
745 * on success
746 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
747 * tree after startoffset
748 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
749 * -FDT_ERR_BADMAGIC,
750 * -FDT_ERR_BADVERSION,
751 * -FDT_ERR_BADSTATE,
752 * -FDT_ERR_BADSTRUCTURE, standard meanings
753 */
David Gibsonae1454b2007-09-17 14:28:34 +1000754int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
755 const char *propname,
756 const void *propval, int proplen);
757
David Gibson53acf492007-11-07 11:54:14 +1100758/**
David Gibson73468582007-11-13 09:59:38 +1100759 * fdt_node_offset_by_phandle - find the node with a given phandle
760 * @fdt: pointer to the device tree blob
761 * @phandle: phandle value
762 *
Wolfram Sang08309aa2008-07-09 11:22:44 +0200763 * fdt_node_offset_by_phandle() returns the offset of the node
David Gibson73468582007-11-13 09:59:38 +1100764 * which has the given phandle value. If there is more than one node
765 * in the tree with the given phandle (an invalid tree), results are
766 * undefined.
767 *
768 * returns:
769 * structure block offset of the located node (>= 0), on success
770 * -FDT_ERR_NOTFOUND, no node with that phandle exists
771 * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1)
772 * -FDT_ERR_BADMAGIC,
773 * -FDT_ERR_BADVERSION,
774 * -FDT_ERR_BADSTATE,
775 * -FDT_ERR_BADSTRUCTURE, standard meanings
776 */
777int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
778
779/**
David Gibson53acf492007-11-07 11:54:14 +1100780 * fdt_node_check_compatible: check a node's compatible property
781 * @fdt: pointer to the device tree blob
782 * @nodeoffset: offset of a tree node
783 * @compatible: string to match against
784 *
785 *
786 * fdt_node_check_compatible() returns 0 if the given node contains a
787 * 'compatible' property with the given string as one of its elements,
788 * it returns non-zero otherwise, or on error.
789 *
790 * returns:
791 * 0, if the node has a 'compatible' property listing the given string
792 * 1, if the node has a 'compatible' property, but it does not list
793 * the given string
794 * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
795 * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
796 * -FDT_ERR_BADMAGIC,
797 * -FDT_ERR_BADVERSION,
798 * -FDT_ERR_BADSTATE,
799 * -FDT_ERR_BADSTRUCTURE, standard meanings
800 */
David Gibson333542f2007-10-16 13:58:25 +1000801int fdt_node_check_compatible(const void *fdt, int nodeoffset,
802 const char *compatible);
David Gibson53acf492007-11-07 11:54:14 +1100803
804/**
805 * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
806 * @fdt: pointer to the device tree blob
807 * @startoffset: only find nodes after this offset
808 * @compatible: 'compatible' string to match against
809 *
810 * fdt_node_offset_by_compatible() returns the offset of the first
811 * node after startoffset, which has a 'compatible' property which
812 * lists the given compatible string; or if startoffset is -1, the
813 * very first such node in the tree.
814 *
815 * To iterate through all nodes matching the criterion, the following
816 * idiom can be used:
817 * offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
818 * while (offset != -FDT_ERR_NOTFOUND) {
819 * // other code here
820 * offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
821 * }
822 *
823 * Note the -1 in the first call to the function, if 0 is used here
824 * instead, the function will never locate the root node, even if it
825 * matches the criterion.
826 *
827 * returns:
828 * structure block offset of the located node (>= 0, >startoffset),
829 * on success
830 * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the
831 * tree after startoffset
832 * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
833 * -FDT_ERR_BADMAGIC,
834 * -FDT_ERR_BADVERSION,
835 * -FDT_ERR_BADSTATE,
836 * -FDT_ERR_BADSTRUCTURE, standard meanings
837 */
David Gibson333542f2007-10-16 13:58:25 +1000838int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
839 const char *compatible);
840
David Gibsoncec0c382007-10-24 17:10:58 +1000841/**********************************************************************/
842/* Write-in-place functions */
843/**********************************************************************/
844
David Gibsonf819a4e2007-12-17 14:41:52 +1100845/**
846 * fdt_setprop_inplace - change a property's value, but not its size
847 * @fdt: pointer to the device tree blob
848 * @nodeoffset: offset of the node whose property to change
849 * @name: name of the property to change
850 * @val: pointer to data to replace the property value with
851 * @len: length of the property value
852 *
853 * fdt_setprop_inplace() replaces the value of a given property with
854 * the data in val, of length len. This function cannot change the
855 * size of a property, and so will only work if len is equal to the
856 * current length of the property.
857 *
858 * This function will alter only the bytes in the blob which contain
859 * the given property value, and will not alter or move any other part
860 * of the tree.
861 *
862 * returns:
863 * 0, on success
864 * -FDT_ERR_NOSPACE, if len is not equal to the property's current length
865 * -FDT_ERR_NOTFOUND, node does not have the named property
866 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
867 * -FDT_ERR_BADMAGIC,
868 * -FDT_ERR_BADVERSION,
869 * -FDT_ERR_BADSTATE,
870 * -FDT_ERR_BADSTRUCTURE,
871 * -FDT_ERR_TRUNCATED, standard meanings
872 */
David Gibson73d60922006-12-15 15:12:47 +1100873int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
David Gibson3da0f9a2006-11-27 16:21:28 +1100874 const void *val, int len);
David Gibsonf819a4e2007-12-17 14:41:52 +1100875
876/**
David Gibsoncbf14102012-06-01 14:12:37 +1000877 * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property
David Gibsonf819a4e2007-12-17 14:41:52 +1100878 * @fdt: pointer to the device tree blob
879 * @nodeoffset: offset of the node whose property to change
880 * @name: name of the property to change
David Gibsoncbf14102012-06-01 14:12:37 +1000881 * @val: 32-bit integer value to replace the property with
David Gibsonf819a4e2007-12-17 14:41:52 +1100882 *
David Gibsoncbf14102012-06-01 14:12:37 +1000883 * fdt_setprop_inplace_u32() replaces the value of a given property
884 * with the 32-bit integer value in val, converting val to big-endian
885 * if necessary. This function cannot change the size of a property,
886 * and so will only work if the property already exists and has length
887 * 4.
David Gibsonf819a4e2007-12-17 14:41:52 +1100888 *
889 * This function will alter only the bytes in the blob which contain
890 * the given property value, and will not alter or move any other part
891 * of the tree.
892 *
893 * returns:
894 * 0, on success
895 * -FDT_ERR_NOSPACE, if the property's length is not equal to 4
David Gibsoncbf14102012-06-01 14:12:37 +1000896 * -FDT_ERR_NOTFOUND, node does not have the named property
David Gibsonf819a4e2007-12-17 14:41:52 +1100897 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
898 * -FDT_ERR_BADMAGIC,
899 * -FDT_ERR_BADVERSION,
900 * -FDT_ERR_BADSTATE,
901 * -FDT_ERR_BADSTRUCTURE,
902 * -FDT_ERR_TRUNCATED, standard meanings
903 */
David Gibsoncbf14102012-06-01 14:12:37 +1000904static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,
905 const char *name, uint32_t val)
David Gibson9521dc52007-11-20 13:35:46 +1100906{
907 val = cpu_to_fdt32(val);
908 return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
909}
David Gibson3da0f9a2006-11-27 16:21:28 +1100910
David Gibsonf819a4e2007-12-17 14:41:52 +1100911/**
David Gibsoncbf14102012-06-01 14:12:37 +1000912 * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property
913 * @fdt: pointer to the device tree blob
914 * @nodeoffset: offset of the node whose property to change
915 * @name: name of the property to change
916 * @val: 64-bit integer value to replace the property with
917 *
918 * fdt_setprop_inplace_u64() replaces the value of a given property
919 * with the 64-bit integer value in val, converting val to big-endian
920 * if necessary. This function cannot change the size of a property,
921 * and so will only work if the property already exists and has length
922 * 8.
923 *
924 * This function will alter only the bytes in the blob which contain
925 * the given property value, and will not alter or move any other part
926 * of the tree.
927 *
928 * returns:
929 * 0, on success
930 * -FDT_ERR_NOSPACE, if the property's length is not equal to 8
931 * -FDT_ERR_NOTFOUND, node does not have the named property
932 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
933 * -FDT_ERR_BADMAGIC,
934 * -FDT_ERR_BADVERSION,
935 * -FDT_ERR_BADSTATE,
936 * -FDT_ERR_BADSTRUCTURE,
937 * -FDT_ERR_TRUNCATED, standard meanings
938 */
939static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,
940 const char *name, uint64_t val)
941{
942 val = cpu_to_fdt64(val);
943 return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
944}
945
946/**
947 * fdt_setprop_inplace_cell - change the value of a single-cell property
948 *
949 * This is an alternative name for fdt_setprop_inplace_u32()
950 */
951static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
952 const char *name, uint32_t val)
953{
954 return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val);
955}
956
957/**
David Gibsonf819a4e2007-12-17 14:41:52 +1100958 * fdt_nop_property - replace a property with nop tags
959 * @fdt: pointer to the device tree blob
960 * @nodeoffset: offset of the node whose property to nop
961 * @name: name of the property to nop
962 *
963 * fdt_nop_property() will replace a given property's representation
964 * in the blob with FDT_NOP tags, effectively removing it from the
965 * tree.
966 *
967 * This function will alter only the bytes in the blob which contain
968 * the property, and will not alter or move any other part of the
969 * tree.
970 *
971 * returns:
972 * 0, on success
973 * -FDT_ERR_NOTFOUND, node does not have the named property
974 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
975 * -FDT_ERR_BADMAGIC,
976 * -FDT_ERR_BADVERSION,
977 * -FDT_ERR_BADSTATE,
978 * -FDT_ERR_BADSTRUCTURE,
979 * -FDT_ERR_TRUNCATED, standard meanings
980 */
David Gibson73d60922006-12-15 15:12:47 +1100981int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
David Gibsonf819a4e2007-12-17 14:41:52 +1100982
983/**
984 * fdt_nop_node - replace a node (subtree) with nop tags
985 * @fdt: pointer to the device tree blob
986 * @nodeoffset: offset of the node to nop
987 *
988 * fdt_nop_node() will replace a given node's representation in the
989 * blob, including all its subnodes, if any, with FDT_NOP tags,
990 * effectively removing it from the tree.
991 *
992 * This function will alter only the bytes in the blob which contain
993 * the node and its properties and subnodes, and will not alter or
994 * move any other part of the tree.
995 *
996 * returns:
997 * 0, on success
998 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
999 * -FDT_ERR_BADMAGIC,
1000 * -FDT_ERR_BADVERSION,
1001 * -FDT_ERR_BADSTATE,
1002 * -FDT_ERR_BADSTRUCTURE,
1003 * -FDT_ERR_TRUNCATED, standard meanings
1004 */
David Gibson73d60922006-12-15 15:12:47 +11001005int fdt_nop_node(void *fdt, int nodeoffset);
David Gibson3da0f9a2006-11-27 16:21:28 +11001006
David Gibsoncec0c382007-10-24 17:10:58 +10001007/**********************************************************************/
1008/* Sequential write functions */
1009/**********************************************************************/
1010
David Gibson73d60922006-12-15 15:12:47 +11001011int fdt_create(void *buf, int bufsize);
1012int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
1013int fdt_finish_reservemap(void *fdt);
1014int fdt_begin_node(void *fdt, const char *name);
1015int fdt_property(void *fdt, const char *name, const void *val, int len);
David Gibsoncbf14102012-06-01 14:12:37 +10001016static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)
David Gibson9521dc52007-11-20 13:35:46 +11001017{
1018 val = cpu_to_fdt32(val);
1019 return fdt_property(fdt, name, &val, sizeof(val));
1020}
David Gibsoncbf14102012-06-01 14:12:37 +10001021static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)
1022{
1023 val = cpu_to_fdt64(val);
1024 return fdt_property(fdt, name, &val, sizeof(val));
1025}
1026static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
1027{
1028 return fdt_property_u32(fdt, name, val);
1029}
David Gibson063693a2006-11-29 16:45:46 +11001030#define fdt_property_string(fdt, name, str) \
1031 fdt_property(fdt, name, str, strlen(str)+1)
David Gibson73d60922006-12-15 15:12:47 +11001032int fdt_end_node(void *fdt);
1033int fdt_finish(void *fdt);
David Gibson3da0f9a2006-11-27 16:21:28 +11001034
David Gibsoncec0c382007-10-24 17:10:58 +10001035/**********************************************************************/
1036/* Read-write functions */
1037/**********************************************************************/
1038
David Gibsonbe602682012-06-01 14:12:38 +10001039int fdt_create_empty_tree(void *buf, int bufsize);
David Gibsona041dcd2007-11-01 11:37:31 +11001040int fdt_open_into(const void *fdt, void *buf, int bufsize);
David Gibson73d60922006-12-15 15:12:47 +11001041int fdt_pack(void *fdt);
David Gibson7ba551f2006-12-01 16:59:43 +11001042
David Gibson30f7fbf2007-12-17 14:42:07 +11001043/**
1044 * fdt_add_mem_rsv - add one memory reserve map entry
1045 * @fdt: pointer to the device tree blob
Wolfram Sang08309aa2008-07-09 11:22:44 +02001046 * @address, @size: 64-bit values (native endian)
David Gibson30f7fbf2007-12-17 14:42:07 +11001047 *
1048 * Adds a reserve map entry to the given blob reserving a region at
1049 * address address of length size.
1050 *
1051 * This function will insert data into the reserve map and will
Wolfram Sang08309aa2008-07-09 11:22:44 +02001052 * therefore change the indexes of some entries in the table.
David Gibson30f7fbf2007-12-17 14:42:07 +11001053 *
1054 * returns:
1055 * 0, on success
1056 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1057 * contain the new reservation entry
1058 * -FDT_ERR_BADMAGIC,
1059 * -FDT_ERR_BADVERSION,
1060 * -FDT_ERR_BADSTATE,
1061 * -FDT_ERR_BADSTRUCTURE,
1062 * -FDT_ERR_BADLAYOUT,
1063 * -FDT_ERR_TRUNCATED, standard meanings
1064 */
David Gibsonfd1bf3a2007-10-10 17:12:12 +10001065int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
David Gibson30f7fbf2007-12-17 14:42:07 +11001066
1067/**
1068 * fdt_del_mem_rsv - remove a memory reserve map entry
1069 * @fdt: pointer to the device tree blob
1070 * @n: entry to remove
1071 *
1072 * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
1073 * the blob.
1074 *
1075 * This function will delete data from the reservation table and will
Wolfram Sang08309aa2008-07-09 11:22:44 +02001076 * therefore change the indexes of some entries in the table.
David Gibson30f7fbf2007-12-17 14:42:07 +11001077 *
1078 * returns:
1079 * 0, on success
1080 * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
1081 * are less than n+1 reserve map entries)
1082 * -FDT_ERR_BADMAGIC,
1083 * -FDT_ERR_BADVERSION,
1084 * -FDT_ERR_BADSTATE,
1085 * -FDT_ERR_BADSTRUCTURE,
1086 * -FDT_ERR_BADLAYOUT,
1087 * -FDT_ERR_TRUNCATED, standard meanings
1088 */
David Gibsonfd1bf3a2007-10-10 17:12:12 +10001089int fdt_del_mem_rsv(void *fdt, int n);
1090
David Gibson30f7fbf2007-12-17 14:42:07 +11001091/**
David Gibson82b327d2008-01-11 14:55:05 +11001092 * fdt_set_name - change the name of a given node
1093 * @fdt: pointer to the device tree blob
1094 * @nodeoffset: structure block offset of a node
1095 * @name: name to give the node
1096 *
1097 * fdt_set_name() replaces the name (including unit address, if any)
1098 * of the given node with the given string. NOTE: this function can't
1099 * efficiently check if the new name is unique amongst the given
1100 * node's siblings; results are undefined if this function is invoked
1101 * with a name equal to one of the given node's siblings.
1102 *
1103 * This function may insert or delete data from the blob, and will
1104 * therefore change the offsets of some existing nodes.
1105 *
1106 * returns:
1107 * 0, on success
1108 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob
1109 * to contain the new name
1110 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1111 * -FDT_ERR_BADMAGIC,
1112 * -FDT_ERR_BADVERSION,
1113 * -FDT_ERR_BADSTATE, standard meanings
1114 */
1115int fdt_set_name(void *fdt, int nodeoffset, const char *name);
1116
1117/**
David Gibson30f7fbf2007-12-17 14:42:07 +11001118 * fdt_setprop - create or change a property
1119 * @fdt: pointer to the device tree blob
1120 * @nodeoffset: offset of the node whose property to change
1121 * @name: name of the property to change
1122 * @val: pointer to data to set the property value to
1123 * @len: length of the property value
1124 *
1125 * fdt_setprop() sets the value of the named property in the given
Wolfram Sang08309aa2008-07-09 11:22:44 +02001126 * node to the given value and length, creating the property if it
David Gibson30f7fbf2007-12-17 14:42:07 +11001127 * does not already exist.
1128 *
1129 * This function may insert or delete data from the blob, and will
1130 * therefore change the offsets of some existing nodes.
1131 *
1132 * returns:
1133 * 0, on success
1134 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1135 * contain the new property value
1136 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1137 * -FDT_ERR_BADLAYOUT,
1138 * -FDT_ERR_BADMAGIC,
1139 * -FDT_ERR_BADVERSION,
1140 * -FDT_ERR_BADSTATE,
1141 * -FDT_ERR_BADSTRUCTURE,
1142 * -FDT_ERR_BADLAYOUT,
1143 * -FDT_ERR_TRUNCATED, standard meanings
1144 */
David Gibson73d60922006-12-15 15:12:47 +11001145int fdt_setprop(void *fdt, int nodeoffset, const char *name,
David Gibson7ba551f2006-12-01 16:59:43 +11001146 const void *val, int len);
David Gibson30f7fbf2007-12-17 14:42:07 +11001147
1148/**
David Gibsoncbf14102012-06-01 14:12:37 +10001149 * fdt_setprop_u32 - set a property to a 32-bit integer
David Gibson30f7fbf2007-12-17 14:42:07 +11001150 * @fdt: pointer to the device tree blob
1151 * @nodeoffset: offset of the node whose property to change
1152 * @name: name of the property to change
1153 * @val: 32-bit integer value for the property (native endian)
1154 *
David Gibsoncbf14102012-06-01 14:12:37 +10001155 * fdt_setprop_u32() sets the value of the named property in the given
1156 * node to the given 32-bit integer value (converting to big-endian if
David Gibson30f7fbf2007-12-17 14:42:07 +11001157 * necessary), or creates a new property with that value if it does
1158 * not already exist.
1159 *
1160 * This function may insert or delete data from the blob, and will
1161 * therefore change the offsets of some existing nodes.
1162 *
1163 * returns:
1164 * 0, on success
1165 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1166 * contain the new property value
1167 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1168 * -FDT_ERR_BADLAYOUT,
1169 * -FDT_ERR_BADMAGIC,
1170 * -FDT_ERR_BADVERSION,
1171 * -FDT_ERR_BADSTATE,
1172 * -FDT_ERR_BADSTRUCTURE,
1173 * -FDT_ERR_BADLAYOUT,
1174 * -FDT_ERR_TRUNCATED, standard meanings
1175 */
David Gibsoncbf14102012-06-01 14:12:37 +10001176static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
1177 uint32_t val)
David Gibson9521dc52007-11-20 13:35:46 +11001178{
1179 val = cpu_to_fdt32(val);
1180 return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
1181}
David Gibson30f7fbf2007-12-17 14:42:07 +11001182
1183/**
David Gibsoncbf14102012-06-01 14:12:37 +10001184 * fdt_setprop_u64 - set a property to a 64-bit integer
1185 * @fdt: pointer to the device tree blob
1186 * @nodeoffset: offset of the node whose property to change
1187 * @name: name of the property to change
1188 * @val: 64-bit integer value for the property (native endian)
1189 *
1190 * fdt_setprop_u64() sets the value of the named property in the given
1191 * node to the given 64-bit integer value (converting to big-endian if
1192 * necessary), or creates a new property with that value if it does
1193 * not already exist.
1194 *
1195 * This function may insert or delete data from the blob, and will
1196 * therefore change the offsets of some existing nodes.
1197 *
1198 * returns:
1199 * 0, on success
1200 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1201 * contain the new property value
1202 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1203 * -FDT_ERR_BADLAYOUT,
1204 * -FDT_ERR_BADMAGIC,
1205 * -FDT_ERR_BADVERSION,
1206 * -FDT_ERR_BADSTATE,
1207 * -FDT_ERR_BADSTRUCTURE,
1208 * -FDT_ERR_BADLAYOUT,
1209 * -FDT_ERR_TRUNCATED, standard meanings
1210 */
1211static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
1212 uint64_t val)
1213{
1214 val = cpu_to_fdt64(val);
1215 return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
1216}
1217
1218/**
1219 * fdt_setprop_cell - set a property to a single cell value
1220 *
1221 * This is an alternative name for fdt_setprop_u32()
1222 */
1223static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
1224 uint32_t val)
1225{
1226 return fdt_setprop_u32(fdt, nodeoffset, name, val);
1227}
1228
1229/**
David Gibson30f7fbf2007-12-17 14:42:07 +11001230 * fdt_setprop_string - set a property to a string value
1231 * @fdt: pointer to the device tree blob
1232 * @nodeoffset: offset of the node whose property to change
1233 * @name: name of the property to change
1234 * @str: string value for the property
1235 *
1236 * fdt_setprop_string() sets the value of the named property in the
1237 * given node to the given string value (using the length of the
1238 * string to determine the new length of the property), or creates a
1239 * new property with that value if it does not already exist.
1240 *
1241 * This function may insert or delete data from the blob, and will
1242 * therefore change the offsets of some existing nodes.
1243 *
1244 * returns:
1245 * 0, on success
1246 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1247 * contain the new property value
1248 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1249 * -FDT_ERR_BADLAYOUT,
1250 * -FDT_ERR_BADMAGIC,
1251 * -FDT_ERR_BADVERSION,
1252 * -FDT_ERR_BADSTATE,
1253 * -FDT_ERR_BADSTRUCTURE,
1254 * -FDT_ERR_BADLAYOUT,
1255 * -FDT_ERR_TRUNCATED, standard meanings
1256 */
David Gibson7ba551f2006-12-01 16:59:43 +11001257#define fdt_setprop_string(fdt, nodeoffset, name, str) \
1258 fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
David Gibson30f7fbf2007-12-17 14:42:07 +11001259
1260/**
Minghuan Liana31e3ef2011-12-05 12:22:07 +11001261 * fdt_appendprop - append to or create a property
1262 * @fdt: pointer to the device tree blob
1263 * @nodeoffset: offset of the node whose property to change
1264 * @name: name of the property to append to
1265 * @val: pointer to data to append to the property value
1266 * @len: length of the data to append to the property value
1267 *
1268 * fdt_appendprop() appends the value to the named property in the
1269 * given node, creating the property if it does not already exist.
1270 *
1271 * This function may insert data into the blob, and will therefore
1272 * change the offsets of some existing nodes.
1273 *
1274 * returns:
1275 * 0, on success
1276 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1277 * contain the new property value
1278 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1279 * -FDT_ERR_BADLAYOUT,
1280 * -FDT_ERR_BADMAGIC,
1281 * -FDT_ERR_BADVERSION,
1282 * -FDT_ERR_BADSTATE,
1283 * -FDT_ERR_BADSTRUCTURE,
1284 * -FDT_ERR_BADLAYOUT,
1285 * -FDT_ERR_TRUNCATED, standard meanings
1286 */
1287int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
1288 const void *val, int len);
Aparna Mallavarapu5ac55422014-07-11 20:49:44 +05301289/**
1290 * fdt_appendprop_str - append a string value to a property
1291 * @fdt: pointer to the device tree blob
1292 * @nodeoffset: offset of the node whose property to change
1293 * @name: name of the property to append to
1294 * @val: pointer to data to append to the property value
1295 * @len: length of the data to append to the property value
1296 *
1297 * fdt_appendprop_str() appends the string value to the named property
1298 * in the given node, creating the property if it does not already exist.
1299 *
1300 * This function may insert data into the blob along with a space between
1301 * the the two strings and will therefore change the offsets of some existing nodes.
1302 *
1303 * returns:
1304 * 0, on success
1305 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1306 * contain the new property value
1307 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1308 * -FDT_ERR_BADLAYOUT,
1309 * -FDT_ERR_BADMAGIC,
1310 * -FDT_ERR_BADVERSION,
1311 * -FDT_ERR_BADSTATE,
1312 * -FDT_ERR_BADSTRUCTURE,
1313 * -FDT_ERR_BADLAYOUT,
1314 * -FDT_ERR_TRUNCATED, standard meanings
1315 */
1316int fdt_appendprop_str(void *fdt, int nodeoffset, const char *name,
1317 const void *val, int len);
Minghuan Liana31e3ef2011-12-05 12:22:07 +11001318
1319/**
David Gibsoncbf14102012-06-01 14:12:37 +10001320 * fdt_appendprop_u32 - append a 32-bit integer value to a property
Minghuan Liana31e3ef2011-12-05 12:22:07 +11001321 * @fdt: pointer to the device tree blob
1322 * @nodeoffset: offset of the node whose property to change
1323 * @name: name of the property to change
1324 * @val: 32-bit integer value to append to the property (native endian)
1325 *
David Gibsoncbf14102012-06-01 14:12:37 +10001326 * fdt_appendprop_u32() appends the given 32-bit integer value
1327 * (converting to big-endian if necessary) to the value of the named
1328 * property in the given node, or creates a new property with that
1329 * value if it does not already exist.
Minghuan Liana31e3ef2011-12-05 12:22:07 +11001330 *
1331 * This function may insert data into the blob, and will therefore
1332 * change the offsets of some existing nodes.
1333 *
1334 * returns:
1335 * 0, on success
1336 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1337 * contain the new property value
1338 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1339 * -FDT_ERR_BADLAYOUT,
1340 * -FDT_ERR_BADMAGIC,
1341 * -FDT_ERR_BADVERSION,
1342 * -FDT_ERR_BADSTATE,
1343 * -FDT_ERR_BADSTRUCTURE,
1344 * -FDT_ERR_BADLAYOUT,
1345 * -FDT_ERR_TRUNCATED, standard meanings
1346 */
David Gibsoncbf14102012-06-01 14:12:37 +10001347static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
1348 const char *name, uint32_t val)
Minghuan Liana31e3ef2011-12-05 12:22:07 +11001349{
1350 val = cpu_to_fdt32(val);
1351 return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
1352}
1353
1354/**
David Gibsoncbf14102012-06-01 14:12:37 +10001355 * fdt_appendprop_u64 - append a 64-bit integer value to a property
1356 * @fdt: pointer to the device tree blob
1357 * @nodeoffset: offset of the node whose property to change
1358 * @name: name of the property to change
1359 * @val: 64-bit integer value to append to the property (native endian)
1360 *
1361 * fdt_appendprop_u64() appends the given 64-bit integer value
1362 * (converting to big-endian if necessary) to the value of the named
1363 * property in the given node, or creates a new property with that
1364 * value if it does not already exist.
1365 *
1366 * This function may insert data into the blob, and will therefore
1367 * change the offsets of some existing nodes.
1368 *
1369 * returns:
1370 * 0, on success
1371 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1372 * contain the new property value
1373 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1374 * -FDT_ERR_BADLAYOUT,
1375 * -FDT_ERR_BADMAGIC,
1376 * -FDT_ERR_BADVERSION,
1377 * -FDT_ERR_BADSTATE,
1378 * -FDT_ERR_BADSTRUCTURE,
1379 * -FDT_ERR_BADLAYOUT,
1380 * -FDT_ERR_TRUNCATED, standard meanings
1381 */
1382static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
1383 const char *name, uint64_t val)
1384{
1385 val = cpu_to_fdt64(val);
1386 return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
1387}
1388
1389/**
1390 * fdt_appendprop_cell - append a single cell value to a property
1391 *
1392 * This is an alternative name for fdt_appendprop_u32()
1393 */
1394static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
1395 const char *name, uint32_t val)
1396{
1397 return fdt_appendprop_u32(fdt, nodeoffset, name, val);
1398}
1399
1400/**
Minghuan Liana31e3ef2011-12-05 12:22:07 +11001401 * fdt_appendprop_string - append a string to a property
1402 * @fdt: pointer to the device tree blob
1403 * @nodeoffset: offset of the node whose property to change
1404 * @name: name of the property to change
1405 * @str: string value to append to the property
1406 *
1407 * fdt_appendprop_string() appends the given string to the value of
1408 * the named property in the given node, or creates a new property
1409 * with that value if it does not already exist.
1410 *
1411 * This function may insert data into the blob, and will therefore
1412 * change the offsets of some existing nodes.
1413 *
1414 * returns:
1415 * 0, on success
1416 * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
1417 * contain the new property value
1418 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1419 * -FDT_ERR_BADLAYOUT,
1420 * -FDT_ERR_BADMAGIC,
1421 * -FDT_ERR_BADVERSION,
1422 * -FDT_ERR_BADSTATE,
1423 * -FDT_ERR_BADSTRUCTURE,
1424 * -FDT_ERR_BADLAYOUT,
1425 * -FDT_ERR_TRUNCATED, standard meanings
1426 */
1427#define fdt_appendprop_string(fdt, nodeoffset, name, str) \
Aparna Mallavarapu5ac55422014-07-11 20:49:44 +05301428 fdt_appendprop_str((fdt), (nodeoffset), (name), (str), strlen(str)+1)
Minghuan Liana31e3ef2011-12-05 12:22:07 +11001429
1430/**
David Gibson30f7fbf2007-12-17 14:42:07 +11001431 * fdt_delprop - delete a property
1432 * @fdt: pointer to the device tree blob
1433 * @nodeoffset: offset of the node whose property to nop
1434 * @name: name of the property to nop
1435 *
1436 * fdt_del_property() will delete the given property.
1437 *
1438 * This function will delete data from the blob, and will therefore
1439 * change the offsets of some existing nodes.
1440 *
1441 * returns:
1442 * 0, on success
1443 * -FDT_ERR_NOTFOUND, node does not have the named property
1444 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1445 * -FDT_ERR_BADLAYOUT,
1446 * -FDT_ERR_BADMAGIC,
1447 * -FDT_ERR_BADVERSION,
1448 * -FDT_ERR_BADSTATE,
1449 * -FDT_ERR_BADSTRUCTURE,
1450 * -FDT_ERR_TRUNCATED, standard meanings
1451 */
David Gibson73d60922006-12-15 15:12:47 +11001452int fdt_delprop(void *fdt, int nodeoffset, const char *name);
David Gibson30f7fbf2007-12-17 14:42:07 +11001453
1454/**
1455 * fdt_add_subnode_namelen - creates a new node based on substring
1456 * @fdt: pointer to the device tree blob
1457 * @parentoffset: structure block offset of a node
1458 * @name: name of the subnode to locate
1459 * @namelen: number of characters of name to consider
1460 *
1461 * Identical to fdt_add_subnode(), but use only the first namelen
1462 * characters of name as the name of the new node. This is useful for
1463 * creating subnodes based on a portion of a larger string, such as a
1464 * full path.
1465 */
David Gibson73d60922006-12-15 15:12:47 +11001466int fdt_add_subnode_namelen(void *fdt, int parentoffset,
David Gibson7ba551f2006-12-01 16:59:43 +11001467 const char *name, int namelen);
David Gibson30f7fbf2007-12-17 14:42:07 +11001468
1469/**
1470 * fdt_add_subnode - creates a new node
1471 * @fdt: pointer to the device tree blob
1472 * @parentoffset: structure block offset of a node
1473 * @name: name of the subnode to locate
1474 *
1475 * fdt_add_subnode() creates a new node as a subnode of the node at
1476 * structure block offset parentoffset, with the given name (which
1477 * should include the unit address, if any).
1478 *
1479 * This function will insert data into the blob, and will therefore
1480 * change the offsets of some existing nodes.
1481
1482 * returns:
1483 * structure block offset of the created nodeequested subnode (>=0), on success
1484 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist
1485 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
1486 * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
1487 * the given name
1488 * -FDT_ERR_NOSPACE, if there is insufficient free space in the
1489 * blob to contain the new node
1490 * -FDT_ERR_NOSPACE
1491 * -FDT_ERR_BADLAYOUT
1492 * -FDT_ERR_BADMAGIC,
1493 * -FDT_ERR_BADVERSION,
1494 * -FDT_ERR_BADSTATE,
1495 * -FDT_ERR_BADSTRUCTURE,
1496 * -FDT_ERR_TRUNCATED, standard meanings.
1497 */
David Gibson73d60922006-12-15 15:12:47 +11001498int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
David Gibson30f7fbf2007-12-17 14:42:07 +11001499
1500/**
1501 * fdt_del_node - delete a node (subtree)
1502 * @fdt: pointer to the device tree blob
1503 * @nodeoffset: offset of the node to nop
1504 *
1505 * fdt_del_node() will remove the given node, including all its
1506 * subnodes if any, from the blob.
1507 *
1508 * This function will delete data from the blob, and will therefore
1509 * change the offsets of some existing nodes.
1510 *
1511 * returns:
1512 * 0, on success
1513 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
1514 * -FDT_ERR_BADLAYOUT,
1515 * -FDT_ERR_BADMAGIC,
1516 * -FDT_ERR_BADVERSION,
1517 * -FDT_ERR_BADSTATE,
1518 * -FDT_ERR_BADSTRUCTURE,
1519 * -FDT_ERR_TRUNCATED, standard meanings
1520 */
David Gibson73d60922006-12-15 15:12:47 +11001521int fdt_del_node(void *fdt, int nodeoffset);
David Gibson3da0f9a2006-11-27 16:21:28 +11001522
David Gibsoncec0c382007-10-24 17:10:58 +10001523/**********************************************************************/
1524/* Debugging / informational functions */
1525/**********************************************************************/
1526
David Gibson5b344f92006-12-21 09:57:08 +11001527const char *fdt_strerror(int errval);
1528
David Gibson3da0f9a2006-11-27 16:21:28 +11001529#endif /* _LIBFDT_H */