1204431Sraj#ifndef _LIBFDT_H 2204431Sraj#define _LIBFDT_H 3204431Sraj/* 4204431Sraj * libfdt - Flat Device Tree manipulation 5204431Sraj * Copyright (C) 2006 David Gibson, IBM Corporation. 6204431Sraj * 7204431Sraj * libfdt is dual licensed: you can use it either under the terms of 8204431Sraj * the GPL, or the BSD license, at your option. 9204431Sraj * 10204431Sraj * a) This library is free software; you can redistribute it and/or 11204431Sraj * modify it under the terms of the GNU General Public License as 12204431Sraj * published by the Free Software Foundation; either version 2 of the 13204431Sraj * License, or (at your option) any later version. 14204431Sraj * 15204431Sraj * This library is distributed in the hope that it will be useful, 16204431Sraj * but WITHOUT ANY WARRANTY; without even the implied warranty of 17204431Sraj * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18204431Sraj * GNU General Public License for more details. 19204431Sraj * 20204431Sraj * You should have received a copy of the GNU General Public 21204431Sraj * License along with this library; if not, write to the Free 22204431Sraj * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 23204431Sraj * MA 02110-1301 USA 24204431Sraj * 25204431Sraj * Alternatively, 26204431Sraj * 27204431Sraj * b) Redistribution and use in source and binary forms, with or 28204431Sraj * without modification, are permitted provided that the following 29204431Sraj * conditions are met: 30204431Sraj * 31204431Sraj * 1. Redistributions of source code must retain the above 32204431Sraj * copyright notice, this list of conditions and the following 33204431Sraj * disclaimer. 34204431Sraj * 2. Redistributions in binary form must reproduce the above 35204431Sraj * copyright notice, this list of conditions and the following 36204431Sraj * disclaimer in the documentation and/or other materials 37204431Sraj * provided with the distribution. 38204431Sraj * 39204431Sraj * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 40204431Sraj * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 41204431Sraj * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 42204431Sraj * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 43204431Sraj * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 44204431Sraj * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45204431Sraj * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46204431Sraj * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47204431Sraj * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48204431Sraj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 49204431Sraj * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 50204431Sraj * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 51204431Sraj * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 52204431Sraj */ 53204431Sraj 54204431Sraj#include <libfdt_env.h> 55204431Sraj#include <fdt.h> 56204431Sraj 57204431Sraj#define FDT_FIRST_SUPPORTED_VERSION 0x10 58204431Sraj#define FDT_LAST_SUPPORTED_VERSION 0x11 59204431Sraj 60204431Sraj/* Error codes: informative error codes */ 61204431Sraj#define FDT_ERR_NOTFOUND 1 62204431Sraj /* FDT_ERR_NOTFOUND: The requested node or property does not exist */ 63204431Sraj#define FDT_ERR_EXISTS 2 64204431Sraj /* FDT_ERR_EXISTS: Attemped to create a node or property which 65204431Sraj * already exists */ 66204431Sraj#define FDT_ERR_NOSPACE 3 67204431Sraj /* FDT_ERR_NOSPACE: Operation needed to expand the device 68204431Sraj * tree, but its buffer did not have sufficient space to 69204431Sraj * contain the expanded tree. Use fdt_open_into() to move the 70204431Sraj * device tree to a buffer with more space. */ 71204431Sraj 72204431Sraj/* Error codes: codes for bad parameters */ 73204431Sraj#define FDT_ERR_BADOFFSET 4 74204431Sraj /* FDT_ERR_BADOFFSET: Function was passed a structure block 75204431Sraj * offset which is out-of-bounds, or which points to an 76204431Sraj * unsuitable part of the structure for the operation. */ 77204431Sraj#define FDT_ERR_BADPATH 5 78204431Sraj /* FDT_ERR_BADPATH: Function was passed a badly formatted path 79204431Sraj * (e.g. missing a leading / for a function which requires an 80204431Sraj * absolute path) */ 81204431Sraj#define FDT_ERR_BADPHANDLE 6 82204431Sraj /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle 83204431Sraj * value. phandle values of 0 and -1 are not permitted. */ 84204431Sraj#define FDT_ERR_BADSTATE 7 85204431Sraj /* FDT_ERR_BADSTATE: Function was passed an incomplete device 86204431Sraj * tree created by the sequential-write functions, which is 87204431Sraj * not sufficiently complete for the requested operation. */ 88204431Sraj 89204431Sraj/* Error codes: codes for bad device tree blobs */ 90204431Sraj#define FDT_ERR_TRUNCATED 8 91204431Sraj /* FDT_ERR_TRUNCATED: Structure block of the given device tree 92204431Sraj * ends without an FDT_END tag. */ 93204431Sraj#define FDT_ERR_BADMAGIC 9 94204431Sraj /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a 95204431Sraj * device tree at all - it is missing the flattened device 96204431Sraj * tree magic number. */ 97204431Sraj#define FDT_ERR_BADVERSION 10 98204431Sraj /* FDT_ERR_BADVERSION: Given device tree has a version which 99204431Sraj * can't be handled by the requested operation. For 100204431Sraj * read-write functions, this may mean that fdt_open_into() is 101204431Sraj * required to convert the tree to the expected version. */ 102204431Sraj#define FDT_ERR_BADSTRUCTURE 11 103204431Sraj /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt 104204431Sraj * structure block or other serious error (e.g. misnested 105204431Sraj * nodes, or subnodes preceding properties). */ 106204431Sraj#define FDT_ERR_BADLAYOUT 12 107204431Sraj /* FDT_ERR_BADLAYOUT: For read-write functions, the given 108204431Sraj * device tree has it's sub-blocks in an order that the 109204431Sraj * function can't handle (memory reserve map, then structure, 110204431Sraj * then strings). Use fdt_open_into() to reorganize the tree 111204431Sraj * into a form suitable for the read-write operations. */ 112204431Sraj 113204431Sraj/* "Can't happen" error indicating a bug in libfdt */ 114204431Sraj#define FDT_ERR_INTERNAL 13 115204431Sraj /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion. 116204431Sraj * Should never be returned, if it is, it indicates a bug in 117204431Sraj * libfdt itself. */ 118204431Sraj 119204431Sraj#define FDT_ERR_MAX 13 120204431Sraj 121204431Sraj/**********************************************************************/ 122204431Sraj/* Low-level functions (you probably don't need these) */ 123204431Sraj/**********************************************************************/ 124204431Sraj 125204433Srajconst void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); 126204431Srajstatic inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) 127204431Sraj{ 128204431Sraj return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); 129204431Sraj} 130204431Sraj 131204431Srajuint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); 132204431Sraj 133204431Sraj/**********************************************************************/ 134204431Sraj/* Traversal functions */ 135204431Sraj/**********************************************************************/ 136204431Sraj 137204431Srajint fdt_next_node(const void *fdt, int offset, int *depth); 138204431Sraj 139204431Sraj/**********************************************************************/ 140204431Sraj/* General functions */ 141204431Sraj/**********************************************************************/ 142204431Sraj 143204431Sraj#define fdt_get_header(fdt, field) \ 144204431Sraj (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field)) 145204431Sraj#define fdt_magic(fdt) (fdt_get_header(fdt, magic)) 146204431Sraj#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) 147204431Sraj#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) 148204431Sraj#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) 149204431Sraj#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) 150204431Sraj#define fdt_version(fdt) (fdt_get_header(fdt, version)) 151204431Sraj#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) 152204431Sraj#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) 153204431Sraj#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) 154204431Sraj#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) 155204431Sraj 156204431Sraj#define __fdt_set_hdr(name) \ 157204431Sraj static inline void fdt_set_##name(void *fdt, uint32_t val) \ 158204431Sraj { \ 159204433Sraj struct fdt_header *fdth = (struct fdt_header*)fdt; \ 160204431Sraj fdth->name = cpu_to_fdt32(val); \ 161204431Sraj } 162204431Sraj__fdt_set_hdr(magic); 163204431Sraj__fdt_set_hdr(totalsize); 164204431Sraj__fdt_set_hdr(off_dt_struct); 165204431Sraj__fdt_set_hdr(off_dt_strings); 166204431Sraj__fdt_set_hdr(off_mem_rsvmap); 167204431Sraj__fdt_set_hdr(version); 168204431Sraj__fdt_set_hdr(last_comp_version); 169204431Sraj__fdt_set_hdr(boot_cpuid_phys); 170204431Sraj__fdt_set_hdr(size_dt_strings); 171204431Sraj__fdt_set_hdr(size_dt_struct); 172204431Sraj#undef __fdt_set_hdr 173204431Sraj 174204431Sraj/** 175204431Sraj * fdt_check_header - sanity check a device tree or possible device tree 176204431Sraj * @fdt: pointer to data which might be a flattened device tree 177204431Sraj * 178204431Sraj * fdt_check_header() checks that the given buffer contains what 179204431Sraj * appears to be a flattened device tree with sane information in its 180204431Sraj * header. 181204431Sraj * 182204431Sraj * returns: 183204431Sraj * 0, if the buffer appears to contain a valid device tree 184204431Sraj * -FDT_ERR_BADMAGIC, 185204431Sraj * -FDT_ERR_BADVERSION, 186204431Sraj * -FDT_ERR_BADSTATE, standard meanings, as above 187204431Sraj */ 188204431Srajint fdt_check_header(const void *fdt); 189204431Sraj 190204431Sraj/** 191204431Sraj * fdt_move - move a device tree around in memory 192204431Sraj * @fdt: pointer to the device tree to move 193204431Sraj * @buf: pointer to memory where the device is to be moved 194204431Sraj * @bufsize: size of the memory space at buf 195204431Sraj * 196204431Sraj * fdt_move() relocates, if possible, the device tree blob located at 197204431Sraj * fdt to the buffer at buf of size bufsize. The buffer may overlap 198204431Sraj * with the existing device tree blob at fdt. Therefore, 199204431Sraj * fdt_move(fdt, fdt, fdt_totalsize(fdt)) 200204431Sraj * should always succeed. 201204431Sraj * 202204431Sraj * returns: 203204431Sraj * 0, on success 204204431Sraj * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree 205204431Sraj * -FDT_ERR_BADMAGIC, 206204431Sraj * -FDT_ERR_BADVERSION, 207204431Sraj * -FDT_ERR_BADSTATE, standard meanings 208204431Sraj */ 209204431Srajint fdt_move(const void *fdt, void *buf, int bufsize); 210204431Sraj 211204431Sraj/**********************************************************************/ 212204431Sraj/* Read-only functions */ 213204431Sraj/**********************************************************************/ 214204431Sraj 215204431Sraj/** 216204431Sraj * fdt_string - retrieve a string from the strings block of a device tree 217204431Sraj * @fdt: pointer to the device tree blob 218204431Sraj * @stroffset: offset of the string within the strings block (native endian) 219204431Sraj * 220204431Sraj * fdt_string() retrieves a pointer to a single string from the 221204431Sraj * strings block of the device tree blob at fdt. 222204431Sraj * 223204431Sraj * returns: 224204431Sraj * a pointer to the string, on success 225204431Sraj * NULL, if stroffset is out of bounds 226204431Sraj */ 227204431Srajconst char *fdt_string(const void *fdt, int stroffset); 228204431Sraj 229204431Sraj/** 230204431Sraj * fdt_num_mem_rsv - retrieve the number of memory reserve map entries 231204431Sraj * @fdt: pointer to the device tree blob 232204431Sraj * 233204431Sraj * Returns the number of entries in the device tree blob's memory 234204431Sraj * reservation map. This does not include the terminating 0,0 entry 235204431Sraj * or any other (0,0) entries reserved for expansion. 236204431Sraj * 237204431Sraj * returns: 238204431Sraj * the number of entries 239204431Sraj */ 240204431Srajint fdt_num_mem_rsv(const void *fdt); 241204431Sraj 242204431Sraj/** 243204431Sraj * fdt_get_mem_rsv - retrieve one memory reserve map entry 244204431Sraj * @fdt: pointer to the device tree blob 245204431Sraj * @address, @size: pointers to 64-bit variables 246204431Sraj * 247204431Sraj * On success, *address and *size will contain the address and size of 248204431Sraj * the n-th reserve map entry from the device tree blob, in 249204431Sraj * native-endian format. 250204431Sraj * 251204431Sraj * returns: 252204431Sraj * 0, on success 253204431Sraj * -FDT_ERR_BADMAGIC, 254204431Sraj * -FDT_ERR_BADVERSION, 255204431Sraj * -FDT_ERR_BADSTATE, standard meanings 256204431Sraj */ 257204431Srajint fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size); 258204431Sraj 259204431Sraj/** 260204431Sraj * fdt_subnode_offset_namelen - find a subnode based on substring 261204431Sraj * @fdt: pointer to the device tree blob 262204431Sraj * @parentoffset: structure block offset of a node 263204431Sraj * @name: name of the subnode to locate 264204431Sraj * @namelen: number of characters of name to consider 265204431Sraj * 266204431Sraj * Identical to fdt_subnode_offset(), but only examine the first 267204431Sraj * namelen characters of name for matching the subnode name. This is 268204431Sraj * useful for finding subnodes based on a portion of a larger string, 269204431Sraj * such as a full path. 270204431Sraj */ 271204431Srajint fdt_subnode_offset_namelen(const void *fdt, int parentoffset, 272204431Sraj const char *name, int namelen); 273204431Sraj/** 274204431Sraj * fdt_subnode_offset - find a subnode of a given node 275204431Sraj * @fdt: pointer to the device tree blob 276204431Sraj * @parentoffset: structure block offset of a node 277204431Sraj * @name: name of the subnode to locate 278204431Sraj * 279204431Sraj * fdt_subnode_offset() finds a subnode of the node at structure block 280204431Sraj * offset parentoffset with the given name. name may include a unit 281204431Sraj * address, in which case fdt_subnode_offset() will find the subnode 282204431Sraj * with that unit address, or the unit address may be omitted, in 283204431Sraj * which case fdt_subnode_offset() will find an arbitrary subnode 284204431Sraj * whose name excluding unit address matches the given name. 285204431Sraj * 286204431Sraj * returns: 287204431Sraj * structure block offset of the requested subnode (>=0), on success 288204431Sraj * -FDT_ERR_NOTFOUND, if the requested subnode does not exist 289204431Sraj * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag 290204431Sraj * -FDT_ERR_BADMAGIC, 291204431Sraj * -FDT_ERR_BADVERSION, 292204431Sraj * -FDT_ERR_BADSTATE, 293204431Sraj * -FDT_ERR_BADSTRUCTURE, 294204431Sraj * -FDT_ERR_TRUNCATED, standard meanings. 295204431Sraj */ 296204431Srajint fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); 297204431Sraj 298204431Sraj/** 299204431Sraj * fdt_path_offset - find a tree node by its full path 300204431Sraj * @fdt: pointer to the device tree blob 301204431Sraj * @path: full path of the node to locate 302204431Sraj * 303204431Sraj * fdt_path_offset() finds a node of a given path in the device tree. 304204431Sraj * Each path component may omit the unit address portion, but the 305204431Sraj * results of this are undefined if any such path component is 306204431Sraj * ambiguous (that is if there are multiple nodes at the relevant 307204431Sraj * level matching the given component, differentiated only by unit 308204431Sraj * address). 309204431Sraj * 310204431Sraj * returns: 311204431Sraj * structure block offset of the node with the requested path (>=0), on success 312204431Sraj * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid 313204431Sraj * -FDT_ERR_NOTFOUND, if the requested node does not exist 314204431Sraj * -FDT_ERR_BADMAGIC, 315204431Sraj * -FDT_ERR_BADVERSION, 316204431Sraj * -FDT_ERR_BADSTATE, 317204431Sraj * -FDT_ERR_BADSTRUCTURE, 318204431Sraj * -FDT_ERR_TRUNCATED, standard meanings. 319204431Sraj */ 320204431Srajint fdt_path_offset(const void *fdt, const char *path); 321204431Sraj 322204431Sraj/** 323204431Sraj * fdt_get_name - retrieve the name of a given node 324204431Sraj * @fdt: pointer to the device tree blob 325204431Sraj * @nodeoffset: structure block offset of the starting node 326204431Sraj * @lenp: pointer to an integer variable (will be overwritten) or NULL 327204431Sraj * 328204431Sraj * fdt_get_name() retrieves the name (including unit address) of the 329204431Sraj * device tree node at structure block offset nodeoffset. If lenp is 330204431Sraj * non-NULL, the length of this name is also returned, in the integer 331204431Sraj * pointed to by lenp. 332204431Sraj * 333204431Sraj * returns: 334204431Sraj * pointer to the node's name, on success 335204431Sraj * If lenp is non-NULL, *lenp contains the length of that name (>=0) 336204431Sraj * NULL, on error 337204431Sraj * if lenp is non-NULL *lenp contains an error code (<0): 338204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 339204431Sraj * -FDT_ERR_BADMAGIC, 340204431Sraj * -FDT_ERR_BADVERSION, 341204431Sraj * -FDT_ERR_BADSTATE, standard meanings 342204431Sraj */ 343204431Srajconst char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp); 344204431Sraj 345204431Sraj/** 346204433Sraj * fdt_get_property_namelen - find a property based on substring 347204433Sraj * @fdt: pointer to the device tree blob 348204433Sraj * @nodeoffset: offset of the node whose property to find 349204433Sraj * @name: name of the property to find 350204433Sraj * @namelen: number of characters of name to consider 351204433Sraj * @lenp: pointer to an integer variable (will be overwritten) or NULL 352204433Sraj * 353204433Sraj * Identical to fdt_get_property_namelen(), but only examine the first 354204433Sraj * namelen characters of name for matching the property name. 355204433Sraj */ 356204433Srajconst struct fdt_property *fdt_get_property_namelen(const void *fdt, 357204433Sraj int nodeoffset, 358204433Sraj const char *name, 359204433Sraj int namelen, int *lenp); 360204433Sraj 361204433Sraj/** 362204431Sraj * fdt_get_property - find a given property in a given node 363204431Sraj * @fdt: pointer to the device tree blob 364204431Sraj * @nodeoffset: offset of the node whose property to find 365204431Sraj * @name: name of the property to find 366204431Sraj * @lenp: pointer to an integer variable (will be overwritten) or NULL 367204431Sraj * 368204431Sraj * fdt_get_property() retrieves a pointer to the fdt_property 369204431Sraj * structure within the device tree blob corresponding to the property 370204431Sraj * named 'name' of the node at offset nodeoffset. If lenp is 371204431Sraj * non-NULL, the length of the property value is also returned, in the 372204431Sraj * integer pointed to by lenp. 373204431Sraj * 374204431Sraj * returns: 375204431Sraj * pointer to the structure representing the property 376204431Sraj * if lenp is non-NULL, *lenp contains the length of the property 377204431Sraj * value (>=0) 378204431Sraj * NULL, on error 379204431Sraj * if lenp is non-NULL, *lenp contains an error code (<0): 380204431Sraj * -FDT_ERR_NOTFOUND, node does not have named property 381204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 382204431Sraj * -FDT_ERR_BADMAGIC, 383204431Sraj * -FDT_ERR_BADVERSION, 384204431Sraj * -FDT_ERR_BADSTATE, 385204431Sraj * -FDT_ERR_BADSTRUCTURE, 386204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 387204431Sraj */ 388204431Srajconst struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset, 389204431Sraj const char *name, int *lenp); 390204431Srajstatic inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset, 391204431Sraj const char *name, 392204431Sraj int *lenp) 393204431Sraj{ 394204431Sraj return (struct fdt_property *)(uintptr_t) 395204431Sraj fdt_get_property(fdt, nodeoffset, name, lenp); 396204431Sraj} 397204431Sraj 398204431Sraj/** 399204433Sraj * fdt_getprop_namelen - get property value based on substring 400204433Sraj * @fdt: pointer to the device tree blob 401204433Sraj * @nodeoffset: offset of the node whose property to find 402204433Sraj * @name: name of the property to find 403204433Sraj * @namelen: number of characters of name to consider 404204433Sraj * @lenp: pointer to an integer variable (will be overwritten) or NULL 405204433Sraj * 406204433Sraj * Identical to fdt_getprop(), but only examine the first namelen 407204433Sraj * characters of name for matching the property name. 408204433Sraj */ 409204433Srajconst void *fdt_getprop_namelen(const void *fdt, int nodeoffset, 410204433Sraj const char *name, int namelen, int *lenp); 411204433Sraj 412204433Sraj/** 413204431Sraj * fdt_getprop - retrieve the value of a given property 414204431Sraj * @fdt: pointer to the device tree blob 415204431Sraj * @nodeoffset: offset of the node whose property to find 416204431Sraj * @name: name of the property to find 417204431Sraj * @lenp: pointer to an integer variable (will be overwritten) or NULL 418204431Sraj * 419204431Sraj * fdt_getprop() retrieves a pointer to the value of the property 420204431Sraj * named 'name' of the node at offset nodeoffset (this will be a 421204431Sraj * pointer to within the device blob itself, not a copy of the value). 422204431Sraj * If lenp is non-NULL, the length of the property value is also 423204431Sraj * returned, in the integer pointed to by lenp. 424204431Sraj * 425204431Sraj * returns: 426204431Sraj * pointer to the property's value 427204431Sraj * if lenp is non-NULL, *lenp contains the length of the property 428204431Sraj * value (>=0) 429204431Sraj * NULL, on error 430204431Sraj * if lenp is non-NULL, *lenp contains an error code (<0): 431204431Sraj * -FDT_ERR_NOTFOUND, node does not have named property 432204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 433204431Sraj * -FDT_ERR_BADMAGIC, 434204431Sraj * -FDT_ERR_BADVERSION, 435204431Sraj * -FDT_ERR_BADSTATE, 436204431Sraj * -FDT_ERR_BADSTRUCTURE, 437204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 438204431Sraj */ 439204431Srajconst void *fdt_getprop(const void *fdt, int nodeoffset, 440204431Sraj const char *name, int *lenp); 441204431Srajstatic inline void *fdt_getprop_w(void *fdt, int nodeoffset, 442204431Sraj const char *name, int *lenp) 443204431Sraj{ 444204431Sraj return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp); 445204431Sraj} 446204431Sraj 447204431Sraj/** 448204431Sraj * fdt_get_phandle - retrieve the phandle of a given node 449204431Sraj * @fdt: pointer to the device tree blob 450204431Sraj * @nodeoffset: structure block offset of the node 451204431Sraj * 452204431Sraj * fdt_get_phandle() retrieves the phandle of the device tree node at 453204431Sraj * structure block offset nodeoffset. 454204431Sraj * 455204431Sraj * returns: 456204431Sraj * the phandle of the node at nodeoffset, on success (!= 0, != -1) 457204431Sraj * 0, if the node has no phandle, or another error occurs 458204431Sraj */ 459204431Srajuint32_t fdt_get_phandle(const void *fdt, int nodeoffset); 460204431Sraj 461204431Sraj/** 462204433Sraj * fdt_get_alias_namelen - get alias based on substring 463204433Sraj * @fdt: pointer to the device tree blob 464204433Sraj * @name: name of the alias th look up 465204433Sraj * @namelen: number of characters of name to consider 466204433Sraj * 467204433Sraj * Identical to fdt_get_alias(), but only examine the first namelen 468204433Sraj * characters of name for matching the alias name. 469204433Sraj */ 470204433Srajconst char *fdt_get_alias_namelen(const void *fdt, 471204433Sraj const char *name, int namelen); 472204433Sraj 473204433Sraj/** 474204433Sraj * fdt_get_alias - retreive the path referenced by a given alias 475204433Sraj * @fdt: pointer to the device tree blob 476204433Sraj * @name: name of the alias th look up 477204433Sraj * 478204433Sraj * fdt_get_alias() retrieves the value of a given alias. That is, the 479204433Sraj * value of the property named 'name' in the node /aliases. 480204433Sraj * 481204433Sraj * returns: 482204433Sraj * a pointer to the expansion of the alias named 'name', of it exists 483204433Sraj * NULL, if the given alias or the /aliases node does not exist 484204433Sraj */ 485204433Srajconst char *fdt_get_alias(const void *fdt, const char *name); 486204433Sraj 487204433Sraj/** 488204431Sraj * fdt_get_path - determine the full path of a node 489204431Sraj * @fdt: pointer to the device tree blob 490204431Sraj * @nodeoffset: offset of the node whose path to find 491204431Sraj * @buf: character buffer to contain the returned path (will be overwritten) 492204431Sraj * @buflen: size of the character buffer at buf 493204431Sraj * 494204431Sraj * fdt_get_path() computes the full path of the node at offset 495204431Sraj * nodeoffset, and records that path in the buffer at buf. 496204431Sraj * 497204431Sraj * NOTE: This function is expensive, as it must scan the device tree 498204431Sraj * structure from the start to nodeoffset. 499204431Sraj * 500204431Sraj * returns: 501204431Sraj * 0, on success 502204431Sraj * buf contains the absolute path of the node at 503204431Sraj * nodeoffset, as a NUL-terminated string. 504204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 505204431Sraj * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1) 506204431Sraj * characters and will not fit in the given buffer. 507204431Sraj * -FDT_ERR_BADMAGIC, 508204431Sraj * -FDT_ERR_BADVERSION, 509204431Sraj * -FDT_ERR_BADSTATE, 510204431Sraj * -FDT_ERR_BADSTRUCTURE, standard meanings 511204431Sraj */ 512204431Srajint fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen); 513204431Sraj 514204431Sraj/** 515204431Sraj * fdt_supernode_atdepth_offset - find a specific ancestor of a node 516204431Sraj * @fdt: pointer to the device tree blob 517204431Sraj * @nodeoffset: offset of the node whose parent to find 518204431Sraj * @supernodedepth: depth of the ancestor to find 519204431Sraj * @nodedepth: pointer to an integer variable (will be overwritten) or NULL 520204431Sraj * 521204431Sraj * fdt_supernode_atdepth_offset() finds an ancestor of the given node 522204431Sraj * at a specific depth from the root (where the root itself has depth 523204431Sraj * 0, its immediate subnodes depth 1 and so forth). So 524204431Sraj * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL); 525204431Sraj * will always return 0, the offset of the root node. If the node at 526204431Sraj * nodeoffset has depth D, then: 527204431Sraj * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL); 528204431Sraj * will return nodeoffset itself. 529204431Sraj * 530204431Sraj * NOTE: This function is expensive, as it must scan the device tree 531204431Sraj * structure from the start to nodeoffset. 532204431Sraj * 533204431Sraj * returns: 534204431Sraj 535204431Sraj * structure block offset of the node at node offset's ancestor 536204431Sraj * of depth supernodedepth (>=0), on success 537204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 538204431Sraj* -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset 539204431Sraj * -FDT_ERR_BADMAGIC, 540204431Sraj * -FDT_ERR_BADVERSION, 541204431Sraj * -FDT_ERR_BADSTATE, 542204431Sraj * -FDT_ERR_BADSTRUCTURE, standard meanings 543204431Sraj */ 544204431Srajint fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, 545204431Sraj int supernodedepth, int *nodedepth); 546204431Sraj 547204431Sraj/** 548204431Sraj * fdt_node_depth - find the depth of a given node 549204431Sraj * @fdt: pointer to the device tree blob 550204431Sraj * @nodeoffset: offset of the node whose parent to find 551204431Sraj * 552204431Sraj * fdt_node_depth() finds the depth of a given node. The root node 553204431Sraj * has depth 0, its immediate subnodes depth 1 and so forth. 554204431Sraj * 555204431Sraj * NOTE: This function is expensive, as it must scan the device tree 556204431Sraj * structure from the start to nodeoffset. 557204431Sraj * 558204431Sraj * returns: 559204431Sraj * depth of the node at nodeoffset (>=0), on success 560204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 561204431Sraj * -FDT_ERR_BADMAGIC, 562204431Sraj * -FDT_ERR_BADVERSION, 563204431Sraj * -FDT_ERR_BADSTATE, 564204431Sraj * -FDT_ERR_BADSTRUCTURE, standard meanings 565204431Sraj */ 566204431Srajint fdt_node_depth(const void *fdt, int nodeoffset); 567204431Sraj 568204431Sraj/** 569204431Sraj * fdt_parent_offset - find the parent of a given node 570204431Sraj * @fdt: pointer to the device tree blob 571204431Sraj * @nodeoffset: offset of the node whose parent to find 572204431Sraj * 573204431Sraj * fdt_parent_offset() locates the parent node of a given node (that 574204431Sraj * is, it finds the offset of the node which contains the node at 575204431Sraj * nodeoffset as a subnode). 576204431Sraj * 577204431Sraj * NOTE: This function is expensive, as it must scan the device tree 578204431Sraj * structure from the start to nodeoffset, *twice*. 579204431Sraj * 580204431Sraj * returns: 581204431Sraj * structure block offset of the parent of the node at nodeoffset 582204431Sraj * (>=0), on success 583204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 584204431Sraj * -FDT_ERR_BADMAGIC, 585204431Sraj * -FDT_ERR_BADVERSION, 586204431Sraj * -FDT_ERR_BADSTATE, 587204431Sraj * -FDT_ERR_BADSTRUCTURE, standard meanings 588204431Sraj */ 589204431Srajint fdt_parent_offset(const void *fdt, int nodeoffset); 590204431Sraj 591204431Sraj/** 592204431Sraj * fdt_node_offset_by_prop_value - find nodes with a given property value 593204431Sraj * @fdt: pointer to the device tree blob 594204431Sraj * @startoffset: only find nodes after this offset 595204431Sraj * @propname: property name to check 596204431Sraj * @propval: property value to search for 597204431Sraj * @proplen: length of the value in propval 598204431Sraj * 599204431Sraj * fdt_node_offset_by_prop_value() returns the offset of the first 600204431Sraj * node after startoffset, which has a property named propname whose 601204431Sraj * value is of length proplen and has value equal to propval; or if 602204431Sraj * startoffset is -1, the very first such node in the tree. 603204431Sraj * 604204431Sraj * To iterate through all nodes matching the criterion, the following 605204431Sraj * idiom can be used: 606204431Sraj * offset = fdt_node_offset_by_prop_value(fdt, -1, propname, 607204431Sraj * propval, proplen); 608204431Sraj * while (offset != -FDT_ERR_NOTFOUND) { 609204431Sraj * // other code here 610204431Sraj * offset = fdt_node_offset_by_prop_value(fdt, offset, propname, 611204431Sraj * propval, proplen); 612204431Sraj * } 613204431Sraj * 614204431Sraj * Note the -1 in the first call to the function, if 0 is used here 615204431Sraj * instead, the function will never locate the root node, even if it 616204431Sraj * matches the criterion. 617204431Sraj * 618204431Sraj * returns: 619204431Sraj * structure block offset of the located node (>= 0, >startoffset), 620204431Sraj * on success 621204431Sraj * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the 622204431Sraj * tree after startoffset 623204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 624204431Sraj * -FDT_ERR_BADMAGIC, 625204431Sraj * -FDT_ERR_BADVERSION, 626204431Sraj * -FDT_ERR_BADSTATE, 627204431Sraj * -FDT_ERR_BADSTRUCTURE, standard meanings 628204431Sraj */ 629204431Srajint fdt_node_offset_by_prop_value(const void *fdt, int startoffset, 630204431Sraj const char *propname, 631204431Sraj const void *propval, int proplen); 632204431Sraj 633204431Sraj/** 634204431Sraj * fdt_node_offset_by_phandle - find the node with a given phandle 635204431Sraj * @fdt: pointer to the device tree blob 636204431Sraj * @phandle: phandle value 637204431Sraj * 638204431Sraj * fdt_node_offset_by_phandle() returns the offset of the node 639204431Sraj * which has the given phandle value. If there is more than one node 640204431Sraj * in the tree with the given phandle (an invalid tree), results are 641204431Sraj * undefined. 642204431Sraj * 643204431Sraj * returns: 644204431Sraj * structure block offset of the located node (>= 0), on success 645204431Sraj * -FDT_ERR_NOTFOUND, no node with that phandle exists 646204431Sraj * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1) 647204431Sraj * -FDT_ERR_BADMAGIC, 648204431Sraj * -FDT_ERR_BADVERSION, 649204431Sraj * -FDT_ERR_BADSTATE, 650204431Sraj * -FDT_ERR_BADSTRUCTURE, standard meanings 651204431Sraj */ 652204431Srajint fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle); 653204431Sraj 654204431Sraj/** 655204431Sraj * fdt_node_check_compatible: check a node's compatible property 656204431Sraj * @fdt: pointer to the device tree blob 657204431Sraj * @nodeoffset: offset of a tree node 658204431Sraj * @compatible: string to match against 659204431Sraj * 660204431Sraj * 661204431Sraj * fdt_node_check_compatible() returns 0 if the given node contains a 662204431Sraj * 'compatible' property with the given string as one of its elements, 663204431Sraj * it returns non-zero otherwise, or on error. 664204431Sraj * 665204431Sraj * returns: 666204431Sraj * 0, if the node has a 'compatible' property listing the given string 667204431Sraj * 1, if the node has a 'compatible' property, but it does not list 668204431Sraj * the given string 669204431Sraj * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property 670204431Sraj * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag 671204431Sraj * -FDT_ERR_BADMAGIC, 672204431Sraj * -FDT_ERR_BADVERSION, 673204431Sraj * -FDT_ERR_BADSTATE, 674204431Sraj * -FDT_ERR_BADSTRUCTURE, standard meanings 675204431Sraj */ 676204431Srajint fdt_node_check_compatible(const void *fdt, int nodeoffset, 677204431Sraj const char *compatible); 678204431Sraj 679204431Sraj/** 680204431Sraj * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value 681204431Sraj * @fdt: pointer to the device tree blob 682204431Sraj * @startoffset: only find nodes after this offset 683204431Sraj * @compatible: 'compatible' string to match against 684204431Sraj * 685204431Sraj * fdt_node_offset_by_compatible() returns the offset of the first 686204431Sraj * node after startoffset, which has a 'compatible' property which 687204431Sraj * lists the given compatible string; or if startoffset is -1, the 688204431Sraj * very first such node in the tree. 689204431Sraj * 690204431Sraj * To iterate through all nodes matching the criterion, the following 691204431Sraj * idiom can be used: 692204431Sraj * offset = fdt_node_offset_by_compatible(fdt, -1, compatible); 693204431Sraj * while (offset != -FDT_ERR_NOTFOUND) { 694204431Sraj * // other code here 695204431Sraj * offset = fdt_node_offset_by_compatible(fdt, offset, compatible); 696204431Sraj * } 697204431Sraj * 698204431Sraj * Note the -1 in the first call to the function, if 0 is used here 699204431Sraj * instead, the function will never locate the root node, even if it 700204431Sraj * matches the criterion. 701204431Sraj * 702204431Sraj * returns: 703204431Sraj * structure block offset of the located node (>= 0, >startoffset), 704204431Sraj * on success 705204431Sraj * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the 706204431Sraj * tree after startoffset 707204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 708204431Sraj * -FDT_ERR_BADMAGIC, 709204431Sraj * -FDT_ERR_BADVERSION, 710204431Sraj * -FDT_ERR_BADSTATE, 711204431Sraj * -FDT_ERR_BADSTRUCTURE, standard meanings 712204431Sraj */ 713204431Srajint fdt_node_offset_by_compatible(const void *fdt, int startoffset, 714204431Sraj const char *compatible); 715204431Sraj 716204431Sraj/**********************************************************************/ 717204431Sraj/* Write-in-place functions */ 718204431Sraj/**********************************************************************/ 719204431Sraj 720204431Sraj/** 721204431Sraj * fdt_setprop_inplace - change a property's value, but not its size 722204431Sraj * @fdt: pointer to the device tree blob 723204431Sraj * @nodeoffset: offset of the node whose property to change 724204431Sraj * @name: name of the property to change 725204431Sraj * @val: pointer to data to replace the property value with 726204431Sraj * @len: length of the property value 727204431Sraj * 728204431Sraj * fdt_setprop_inplace() replaces the value of a given property with 729204431Sraj * the data in val, of length len. This function cannot change the 730204431Sraj * size of a property, and so will only work if len is equal to the 731204431Sraj * current length of the property. 732204431Sraj * 733204431Sraj * This function will alter only the bytes in the blob which contain 734204431Sraj * the given property value, and will not alter or move any other part 735204431Sraj * of the tree. 736204431Sraj * 737204431Sraj * returns: 738204431Sraj * 0, on success 739204431Sraj * -FDT_ERR_NOSPACE, if len is not equal to the property's current length 740204431Sraj * -FDT_ERR_NOTFOUND, node does not have the named property 741204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 742204431Sraj * -FDT_ERR_BADMAGIC, 743204431Sraj * -FDT_ERR_BADVERSION, 744204431Sraj * -FDT_ERR_BADSTATE, 745204431Sraj * -FDT_ERR_BADSTRUCTURE, 746204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 747204431Sraj */ 748204431Srajint fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, 749204431Sraj const void *val, int len); 750204431Sraj 751204431Sraj/** 752204431Sraj * fdt_setprop_inplace_cell - change the value of a single-cell property 753204431Sraj * @fdt: pointer to the device tree blob 754204431Sraj * @nodeoffset: offset of the node whose property to change 755204431Sraj * @name: name of the property to change 756204431Sraj * @val: cell (32-bit integer) value to replace the property with 757204431Sraj * 758204431Sraj * fdt_setprop_inplace_cell() replaces the value of a given property 759204431Sraj * with the 32-bit integer cell value in val, converting val to 760204431Sraj * big-endian if necessary. This function cannot change the size of a 761204431Sraj * property, and so will only work if the property already exists and 762204431Sraj * has length 4. 763204431Sraj * 764204431Sraj * This function will alter only the bytes in the blob which contain 765204431Sraj * the given property value, and will not alter or move any other part 766204431Sraj * of the tree. 767204431Sraj * 768204431Sraj * returns: 769204431Sraj * 0, on success 770204431Sraj * -FDT_ERR_NOSPACE, if the property's length is not equal to 4 771204431Sraj * -FDT_ERR_NOTFOUND, node does not have the named property 772204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 773204431Sraj * -FDT_ERR_BADMAGIC, 774204431Sraj * -FDT_ERR_BADVERSION, 775204431Sraj * -FDT_ERR_BADSTATE, 776204431Sraj * -FDT_ERR_BADSTRUCTURE, 777204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 778204431Sraj */ 779204431Srajstatic inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset, 780204431Sraj const char *name, uint32_t val) 781204431Sraj{ 782204431Sraj val = cpu_to_fdt32(val); 783204431Sraj return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val)); 784204431Sraj} 785204431Sraj 786204431Sraj/** 787204431Sraj * fdt_nop_property - replace a property with nop tags 788204431Sraj * @fdt: pointer to the device tree blob 789204431Sraj * @nodeoffset: offset of the node whose property to nop 790204431Sraj * @name: name of the property to nop 791204431Sraj * 792204431Sraj * fdt_nop_property() will replace a given property's representation 793204431Sraj * in the blob with FDT_NOP tags, effectively removing it from the 794204431Sraj * tree. 795204431Sraj * 796204431Sraj * This function will alter only the bytes in the blob which contain 797204431Sraj * the property, and will not alter or move any other part of the 798204431Sraj * tree. 799204431Sraj * 800204431Sraj * returns: 801204431Sraj * 0, on success 802204431Sraj * -FDT_ERR_NOTFOUND, node does not have the named property 803204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 804204431Sraj * -FDT_ERR_BADMAGIC, 805204431Sraj * -FDT_ERR_BADVERSION, 806204431Sraj * -FDT_ERR_BADSTATE, 807204431Sraj * -FDT_ERR_BADSTRUCTURE, 808204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 809204431Sraj */ 810204431Srajint fdt_nop_property(void *fdt, int nodeoffset, const char *name); 811204431Sraj 812204431Sraj/** 813204431Sraj * fdt_nop_node - replace a node (subtree) with nop tags 814204431Sraj * @fdt: pointer to the device tree blob 815204431Sraj * @nodeoffset: offset of the node to nop 816204431Sraj * 817204431Sraj * fdt_nop_node() will replace a given node's representation in the 818204431Sraj * blob, including all its subnodes, if any, with FDT_NOP tags, 819204431Sraj * effectively removing it from the tree. 820204431Sraj * 821204431Sraj * This function will alter only the bytes in the blob which contain 822204431Sraj * the node and its properties and subnodes, and will not alter or 823204431Sraj * move any other part of the tree. 824204431Sraj * 825204431Sraj * returns: 826204431Sraj * 0, on success 827204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 828204431Sraj * -FDT_ERR_BADMAGIC, 829204431Sraj * -FDT_ERR_BADVERSION, 830204431Sraj * -FDT_ERR_BADSTATE, 831204431Sraj * -FDT_ERR_BADSTRUCTURE, 832204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 833204431Sraj */ 834204431Srajint fdt_nop_node(void *fdt, int nodeoffset); 835204431Sraj 836204431Sraj/**********************************************************************/ 837204431Sraj/* Sequential write functions */ 838204431Sraj/**********************************************************************/ 839204431Sraj 840204431Srajint fdt_create(void *buf, int bufsize); 841204431Srajint fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size); 842204431Srajint fdt_finish_reservemap(void *fdt); 843204431Srajint fdt_begin_node(void *fdt, const char *name); 844204431Srajint fdt_property(void *fdt, const char *name, const void *val, int len); 845204431Srajstatic inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) 846204431Sraj{ 847204431Sraj val = cpu_to_fdt32(val); 848204431Sraj return fdt_property(fdt, name, &val, sizeof(val)); 849204431Sraj} 850204431Sraj#define fdt_property_string(fdt, name, str) \ 851204431Sraj fdt_property(fdt, name, str, strlen(str)+1) 852204431Srajint fdt_end_node(void *fdt); 853204431Srajint fdt_finish(void *fdt); 854204431Sraj 855204431Sraj/**********************************************************************/ 856204431Sraj/* Read-write functions */ 857204431Sraj/**********************************************************************/ 858204431Sraj 859204431Srajint fdt_open_into(const void *fdt, void *buf, int bufsize); 860204431Srajint fdt_pack(void *fdt); 861204431Sraj 862204431Sraj/** 863204431Sraj * fdt_add_mem_rsv - add one memory reserve map entry 864204431Sraj * @fdt: pointer to the device tree blob 865204431Sraj * @address, @size: 64-bit values (native endian) 866204431Sraj * 867204431Sraj * Adds a reserve map entry to the given blob reserving a region at 868204431Sraj * address address of length size. 869204431Sraj * 870204431Sraj * This function will insert data into the reserve map and will 871204431Sraj * therefore change the indexes of some entries in the table. 872204431Sraj * 873204431Sraj * returns: 874204431Sraj * 0, on success 875204431Sraj * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 876204431Sraj * contain the new reservation entry 877204431Sraj * -FDT_ERR_BADMAGIC, 878204431Sraj * -FDT_ERR_BADVERSION, 879204431Sraj * -FDT_ERR_BADSTATE, 880204431Sraj * -FDT_ERR_BADSTRUCTURE, 881204431Sraj * -FDT_ERR_BADLAYOUT, 882204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 883204431Sraj */ 884204431Srajint fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size); 885204431Sraj 886204431Sraj/** 887204431Sraj * fdt_del_mem_rsv - remove a memory reserve map entry 888204431Sraj * @fdt: pointer to the device tree blob 889204431Sraj * @n: entry to remove 890204431Sraj * 891204431Sraj * fdt_del_mem_rsv() removes the n-th memory reserve map entry from 892204431Sraj * the blob. 893204431Sraj * 894204431Sraj * This function will delete data from the reservation table and will 895204431Sraj * therefore change the indexes of some entries in the table. 896204431Sraj * 897204431Sraj * returns: 898204431Sraj * 0, on success 899204431Sraj * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there 900204431Sraj * are less than n+1 reserve map entries) 901204431Sraj * -FDT_ERR_BADMAGIC, 902204431Sraj * -FDT_ERR_BADVERSION, 903204431Sraj * -FDT_ERR_BADSTATE, 904204431Sraj * -FDT_ERR_BADSTRUCTURE, 905204431Sraj * -FDT_ERR_BADLAYOUT, 906204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 907204431Sraj */ 908204431Srajint fdt_del_mem_rsv(void *fdt, int n); 909204431Sraj 910204431Sraj/** 911204431Sraj * fdt_set_name - change the name of a given node 912204431Sraj * @fdt: pointer to the device tree blob 913204431Sraj * @nodeoffset: structure block offset of a node 914204431Sraj * @name: name to give the node 915204431Sraj * 916204431Sraj * fdt_set_name() replaces the name (including unit address, if any) 917204431Sraj * of the given node with the given string. NOTE: this function can't 918204431Sraj * efficiently check if the new name is unique amongst the given 919204431Sraj * node's siblings; results are undefined if this function is invoked 920204431Sraj * with a name equal to one of the given node's siblings. 921204431Sraj * 922204431Sraj * This function may insert or delete data from the blob, and will 923204431Sraj * therefore change the offsets of some existing nodes. 924204431Sraj * 925204431Sraj * returns: 926204431Sraj * 0, on success 927204431Sraj * -FDT_ERR_NOSPACE, there is insufficient free space in the blob 928204431Sraj * to contain the new name 929204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 930204431Sraj * -FDT_ERR_BADMAGIC, 931204431Sraj * -FDT_ERR_BADVERSION, 932204431Sraj * -FDT_ERR_BADSTATE, standard meanings 933204431Sraj */ 934204431Srajint fdt_set_name(void *fdt, int nodeoffset, const char *name); 935204431Sraj 936204431Sraj/** 937204431Sraj * fdt_setprop - create or change a property 938204431Sraj * @fdt: pointer to the device tree blob 939204431Sraj * @nodeoffset: offset of the node whose property to change 940204431Sraj * @name: name of the property to change 941204431Sraj * @val: pointer to data to set the property value to 942204431Sraj * @len: length of the property value 943204431Sraj * 944204431Sraj * fdt_setprop() sets the value of the named property in the given 945204431Sraj * node to the given value and length, creating the property if it 946204431Sraj * does not already exist. 947204431Sraj * 948204431Sraj * This function may insert or delete data from the blob, and will 949204431Sraj * therefore change the offsets of some existing nodes. 950204431Sraj * 951204431Sraj * returns: 952204431Sraj * 0, on success 953204431Sraj * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 954204431Sraj * contain the new property value 955204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 956204431Sraj * -FDT_ERR_BADLAYOUT, 957204431Sraj * -FDT_ERR_BADMAGIC, 958204431Sraj * -FDT_ERR_BADVERSION, 959204431Sraj * -FDT_ERR_BADSTATE, 960204431Sraj * -FDT_ERR_BADSTRUCTURE, 961204431Sraj * -FDT_ERR_BADLAYOUT, 962204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 963204431Sraj */ 964204431Srajint fdt_setprop(void *fdt, int nodeoffset, const char *name, 965204431Sraj const void *val, int len); 966204431Sraj 967204431Sraj/** 968204431Sraj * fdt_setprop_cell - set a property to a single cell value 969204431Sraj * @fdt: pointer to the device tree blob 970204431Sraj * @nodeoffset: offset of the node whose property to change 971204431Sraj * @name: name of the property to change 972204431Sraj * @val: 32-bit integer value for the property (native endian) 973204431Sraj * 974204431Sraj * fdt_setprop_cell() sets the value of the named property in the 975204431Sraj * given node to the given cell value (converting to big-endian if 976204431Sraj * necessary), or creates a new property with that value if it does 977204431Sraj * not already exist. 978204431Sraj * 979204431Sraj * This function may insert or delete data from the blob, and will 980204431Sraj * therefore change the offsets of some existing nodes. 981204431Sraj * 982204431Sraj * returns: 983204431Sraj * 0, on success 984204431Sraj * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 985204431Sraj * contain the new property value 986204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 987204431Sraj * -FDT_ERR_BADLAYOUT, 988204431Sraj * -FDT_ERR_BADMAGIC, 989204431Sraj * -FDT_ERR_BADVERSION, 990204431Sraj * -FDT_ERR_BADSTATE, 991204431Sraj * -FDT_ERR_BADSTRUCTURE, 992204431Sraj * -FDT_ERR_BADLAYOUT, 993204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 994204431Sraj */ 995204431Srajstatic inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name, 996204431Sraj uint32_t val) 997204431Sraj{ 998204431Sraj val = cpu_to_fdt32(val); 999204431Sraj return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val)); 1000204431Sraj} 1001204431Sraj 1002204431Sraj/** 1003204431Sraj * fdt_setprop_string - set a property to a string value 1004204431Sraj * @fdt: pointer to the device tree blob 1005204431Sraj * @nodeoffset: offset of the node whose property to change 1006204431Sraj * @name: name of the property to change 1007204431Sraj * @str: string value for the property 1008204431Sraj * 1009204431Sraj * fdt_setprop_string() sets the value of the named property in the 1010204431Sraj * given node to the given string value (using the length of the 1011204431Sraj * string to determine the new length of the property), or creates a 1012204431Sraj * new property with that value if it does not already exist. 1013204431Sraj * 1014204431Sraj * This function may insert or delete data from the blob, and will 1015204431Sraj * therefore change the offsets of some existing nodes. 1016204431Sraj * 1017204431Sraj * returns: 1018204431Sraj * 0, on success 1019204431Sraj * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 1020204431Sraj * contain the new property value 1021204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 1022204431Sraj * -FDT_ERR_BADLAYOUT, 1023204431Sraj * -FDT_ERR_BADMAGIC, 1024204431Sraj * -FDT_ERR_BADVERSION, 1025204431Sraj * -FDT_ERR_BADSTATE, 1026204431Sraj * -FDT_ERR_BADSTRUCTURE, 1027204431Sraj * -FDT_ERR_BADLAYOUT, 1028204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 1029204431Sraj */ 1030204431Sraj#define fdt_setprop_string(fdt, nodeoffset, name, str) \ 1031204431Sraj fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) 1032204431Sraj 1033204431Sraj/** 1034204431Sraj * fdt_delprop - delete a property 1035204431Sraj * @fdt: pointer to the device tree blob 1036204431Sraj * @nodeoffset: offset of the node whose property to nop 1037204431Sraj * @name: name of the property to nop 1038204431Sraj * 1039204431Sraj * fdt_del_property() will delete the given property. 1040204431Sraj * 1041204431Sraj * This function will delete data from the blob, and will therefore 1042204431Sraj * change the offsets of some existing nodes. 1043204431Sraj * 1044204431Sraj * returns: 1045204431Sraj * 0, on success 1046204431Sraj * -FDT_ERR_NOTFOUND, node does not have the named property 1047204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 1048204431Sraj * -FDT_ERR_BADLAYOUT, 1049204431Sraj * -FDT_ERR_BADMAGIC, 1050204431Sraj * -FDT_ERR_BADVERSION, 1051204431Sraj * -FDT_ERR_BADSTATE, 1052204431Sraj * -FDT_ERR_BADSTRUCTURE, 1053204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 1054204431Sraj */ 1055204431Srajint fdt_delprop(void *fdt, int nodeoffset, const char *name); 1056204431Sraj 1057204431Sraj/** 1058204431Sraj * fdt_add_subnode_namelen - creates a new node based on substring 1059204431Sraj * @fdt: pointer to the device tree blob 1060204431Sraj * @parentoffset: structure block offset of a node 1061204431Sraj * @name: name of the subnode to locate 1062204431Sraj * @namelen: number of characters of name to consider 1063204431Sraj * 1064204431Sraj * Identical to fdt_add_subnode(), but use only the first namelen 1065204431Sraj * characters of name as the name of the new node. This is useful for 1066204431Sraj * creating subnodes based on a portion of a larger string, such as a 1067204431Sraj * full path. 1068204431Sraj */ 1069204431Srajint fdt_add_subnode_namelen(void *fdt, int parentoffset, 1070204431Sraj const char *name, int namelen); 1071204431Sraj 1072204431Sraj/** 1073204431Sraj * fdt_add_subnode - creates a new node 1074204431Sraj * @fdt: pointer to the device tree blob 1075204431Sraj * @parentoffset: structure block offset of a node 1076204431Sraj * @name: name of the subnode to locate 1077204431Sraj * 1078204431Sraj * fdt_add_subnode() creates a new node as a subnode of the node at 1079204431Sraj * structure block offset parentoffset, with the given name (which 1080204431Sraj * should include the unit address, if any). 1081204431Sraj * 1082204431Sraj * This function will insert data into the blob, and will therefore 1083204431Sraj * change the offsets of some existing nodes. 1084204431Sraj 1085204431Sraj * returns: 1086204431Sraj * structure block offset of the created nodeequested subnode (>=0), on success 1087204431Sraj * -FDT_ERR_NOTFOUND, if the requested subnode does not exist 1088204431Sraj * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag 1089204431Sraj * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of 1090204431Sraj * the given name 1091204431Sraj * -FDT_ERR_NOSPACE, if there is insufficient free space in the 1092204431Sraj * blob to contain the new node 1093204431Sraj * -FDT_ERR_NOSPACE 1094204431Sraj * -FDT_ERR_BADLAYOUT 1095204431Sraj * -FDT_ERR_BADMAGIC, 1096204431Sraj * -FDT_ERR_BADVERSION, 1097204431Sraj * -FDT_ERR_BADSTATE, 1098204431Sraj * -FDT_ERR_BADSTRUCTURE, 1099204431Sraj * -FDT_ERR_TRUNCATED, standard meanings. 1100204431Sraj */ 1101204431Srajint fdt_add_subnode(void *fdt, int parentoffset, const char *name); 1102204431Sraj 1103204431Sraj/** 1104204431Sraj * fdt_del_node - delete a node (subtree) 1105204431Sraj * @fdt: pointer to the device tree blob 1106204431Sraj * @nodeoffset: offset of the node to nop 1107204431Sraj * 1108204431Sraj * fdt_del_node() will remove the given node, including all its 1109204431Sraj * subnodes if any, from the blob. 1110204431Sraj * 1111204431Sraj * This function will delete data from the blob, and will therefore 1112204431Sraj * change the offsets of some existing nodes. 1113204431Sraj * 1114204431Sraj * returns: 1115204431Sraj * 0, on success 1116204431Sraj * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 1117204431Sraj * -FDT_ERR_BADLAYOUT, 1118204431Sraj * -FDT_ERR_BADMAGIC, 1119204431Sraj * -FDT_ERR_BADVERSION, 1120204431Sraj * -FDT_ERR_BADSTATE, 1121204431Sraj * -FDT_ERR_BADSTRUCTURE, 1122204431Sraj * -FDT_ERR_TRUNCATED, standard meanings 1123204431Sraj */ 1124204431Srajint fdt_del_node(void *fdt, int nodeoffset); 1125204431Sraj 1126204431Sraj/**********************************************************************/ 1127204431Sraj/* Debugging / informational functions */ 1128204431Sraj/**********************************************************************/ 1129204431Sraj 1130204431Srajconst char *fdt_strerror(int errval); 1131204431Sraj 1132204431Sraj#endif /* _LIBFDT_H */ 1133