1*2fb928dbSskrll /* $NetBSD: libfdt.h,v 1.1.1.2 2017/06/08 15:53:15 skrll Exp $ */ 2*2fb928dbSskrll 37b5f0179Smacallan #ifndef _LIBFDT_H 47b5f0179Smacallan #define _LIBFDT_H 57b5f0179Smacallan /* 67b5f0179Smacallan * libfdt - Flat Device Tree manipulation 77b5f0179Smacallan * Copyright (C) 2006 David Gibson, IBM Corporation. 87b5f0179Smacallan * 97b5f0179Smacallan * libfdt is dual licensed: you can use it either under the terms of 107b5f0179Smacallan * the GPL, or the BSD license, at your option. 117b5f0179Smacallan * 127b5f0179Smacallan * a) This library is free software; you can redistribute it and/or 137b5f0179Smacallan * modify it under the terms of the GNU General Public License as 147b5f0179Smacallan * published by the Free Software Foundation; either version 2 of the 157b5f0179Smacallan * License, or (at your option) any later version. 167b5f0179Smacallan * 177b5f0179Smacallan * This library is distributed in the hope that it will be useful, 187b5f0179Smacallan * but WITHOUT ANY WARRANTY; without even the implied warranty of 197b5f0179Smacallan * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 207b5f0179Smacallan * GNU General Public License for more details. 217b5f0179Smacallan * 227b5f0179Smacallan * You should have received a copy of the GNU General Public 237b5f0179Smacallan * License along with this library; if not, write to the Free 247b5f0179Smacallan * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 257b5f0179Smacallan * MA 02110-1301 USA 267b5f0179Smacallan * 277b5f0179Smacallan * Alternatively, 287b5f0179Smacallan * 297b5f0179Smacallan * b) Redistribution and use in source and binary forms, with or 307b5f0179Smacallan * without modification, are permitted provided that the following 317b5f0179Smacallan * conditions are met: 327b5f0179Smacallan * 337b5f0179Smacallan * 1. Redistributions of source code must retain the above 347b5f0179Smacallan * copyright notice, this list of conditions and the following 357b5f0179Smacallan * disclaimer. 367b5f0179Smacallan * 2. Redistributions in binary form must reproduce the above 377b5f0179Smacallan * copyright notice, this list of conditions and the following 387b5f0179Smacallan * disclaimer in the documentation and/or other materials 397b5f0179Smacallan * provided with the distribution. 407b5f0179Smacallan * 417b5f0179Smacallan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 427b5f0179Smacallan * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 437b5f0179Smacallan * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 447b5f0179Smacallan * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 457b5f0179Smacallan * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 467b5f0179Smacallan * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 477b5f0179Smacallan * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 487b5f0179Smacallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 497b5f0179Smacallan * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 507b5f0179Smacallan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 517b5f0179Smacallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 527b5f0179Smacallan * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 537b5f0179Smacallan * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 547b5f0179Smacallan */ 557b5f0179Smacallan 567b5f0179Smacallan #include <libfdt_env.h> 577b5f0179Smacallan #include <fdt.h> 587b5f0179Smacallan 597b5f0179Smacallan #define FDT_FIRST_SUPPORTED_VERSION 0x10 607b5f0179Smacallan #define FDT_LAST_SUPPORTED_VERSION 0x11 617b5f0179Smacallan 627b5f0179Smacallan /* Error codes: informative error codes */ 637b5f0179Smacallan #define FDT_ERR_NOTFOUND 1 647b5f0179Smacallan /* FDT_ERR_NOTFOUND: The requested node or property does not exist */ 657b5f0179Smacallan #define FDT_ERR_EXISTS 2 66*2fb928dbSskrll /* FDT_ERR_EXISTS: Attempted to create a node or property which 677b5f0179Smacallan * already exists */ 687b5f0179Smacallan #define FDT_ERR_NOSPACE 3 697b5f0179Smacallan /* FDT_ERR_NOSPACE: Operation needed to expand the device 707b5f0179Smacallan * tree, but its buffer did not have sufficient space to 717b5f0179Smacallan * contain the expanded tree. Use fdt_open_into() to move the 727b5f0179Smacallan * device tree to a buffer with more space. */ 737b5f0179Smacallan 747b5f0179Smacallan /* Error codes: codes for bad parameters */ 757b5f0179Smacallan #define FDT_ERR_BADOFFSET 4 767b5f0179Smacallan /* FDT_ERR_BADOFFSET: Function was passed a structure block 777b5f0179Smacallan * offset which is out-of-bounds, or which points to an 787b5f0179Smacallan * unsuitable part of the structure for the operation. */ 797b5f0179Smacallan #define FDT_ERR_BADPATH 5 807b5f0179Smacallan /* FDT_ERR_BADPATH: Function was passed a badly formatted path 817b5f0179Smacallan * (e.g. missing a leading / for a function which requires an 827b5f0179Smacallan * absolute path) */ 837b5f0179Smacallan #define FDT_ERR_BADPHANDLE 6 84*2fb928dbSskrll /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle. 85*2fb928dbSskrll * This can be caused either by an invalid phandle property 86*2fb928dbSskrll * length, or the phandle value was either 0 or -1, which are 87*2fb928dbSskrll * not permitted. */ 887b5f0179Smacallan #define FDT_ERR_BADSTATE 7 897b5f0179Smacallan /* FDT_ERR_BADSTATE: Function was passed an incomplete device 907b5f0179Smacallan * tree created by the sequential-write functions, which is 917b5f0179Smacallan * not sufficiently complete for the requested operation. */ 927b5f0179Smacallan 937b5f0179Smacallan /* Error codes: codes for bad device tree blobs */ 947b5f0179Smacallan #define FDT_ERR_TRUNCATED 8 957b5f0179Smacallan /* FDT_ERR_TRUNCATED: Structure block of the given device tree 967b5f0179Smacallan * ends without an FDT_END tag. */ 977b5f0179Smacallan #define FDT_ERR_BADMAGIC 9 987b5f0179Smacallan /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a 997b5f0179Smacallan * device tree at all - it is missing the flattened device 1007b5f0179Smacallan * tree magic number. */ 1017b5f0179Smacallan #define FDT_ERR_BADVERSION 10 1027b5f0179Smacallan /* FDT_ERR_BADVERSION: Given device tree has a version which 1037b5f0179Smacallan * can't be handled by the requested operation. For 1047b5f0179Smacallan * read-write functions, this may mean that fdt_open_into() is 1057b5f0179Smacallan * required to convert the tree to the expected version. */ 1067b5f0179Smacallan #define FDT_ERR_BADSTRUCTURE 11 1077b5f0179Smacallan /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt 1087b5f0179Smacallan * structure block or other serious error (e.g. misnested 1097b5f0179Smacallan * nodes, or subnodes preceding properties). */ 1107b5f0179Smacallan #define FDT_ERR_BADLAYOUT 12 1117b5f0179Smacallan /* FDT_ERR_BADLAYOUT: For read-write functions, the given 1127b5f0179Smacallan * device tree has it's sub-blocks in an order that the 1137b5f0179Smacallan * function can't handle (memory reserve map, then structure, 1147b5f0179Smacallan * then strings). Use fdt_open_into() to reorganize the tree 1157b5f0179Smacallan * into a form suitable for the read-write operations. */ 1167b5f0179Smacallan 1177b5f0179Smacallan /* "Can't happen" error indicating a bug in libfdt */ 1187b5f0179Smacallan #define FDT_ERR_INTERNAL 13 1197b5f0179Smacallan /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion. 1207b5f0179Smacallan * Should never be returned, if it is, it indicates a bug in 1217b5f0179Smacallan * libfdt itself. */ 1227b5f0179Smacallan 1237b5f0179Smacallan /* Errors in device tree content */ 1247b5f0179Smacallan #define FDT_ERR_BADNCELLS 14 1257b5f0179Smacallan /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells 1267b5f0179Smacallan * or similar property with a bad format or value */ 1277b5f0179Smacallan 1287b5f0179Smacallan #define FDT_ERR_BADVALUE 15 1297b5f0179Smacallan /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected 1307b5f0179Smacallan * value. For example: a property expected to contain a string list 1317b5f0179Smacallan * is not NUL-terminated within the length of its value. */ 1327b5f0179Smacallan 133*2fb928dbSskrll #define FDT_ERR_BADOVERLAY 16 134*2fb928dbSskrll /* FDT_ERR_BADOVERLAY: The device tree overlay, while 135*2fb928dbSskrll * correctly structured, cannot be applied due to some 136*2fb928dbSskrll * unexpected or missing value, property or node. */ 137*2fb928dbSskrll 138*2fb928dbSskrll #define FDT_ERR_NOPHANDLES 17 139*2fb928dbSskrll /* FDT_ERR_NOPHANDLES: The device tree doesn't have any 140*2fb928dbSskrll * phandle available anymore without causing an overflow */ 141*2fb928dbSskrll 142*2fb928dbSskrll #define FDT_ERR_MAX 17 1437b5f0179Smacallan 1447b5f0179Smacallan /**********************************************************************/ 1457b5f0179Smacallan /* Low-level functions (you probably don't need these) */ 1467b5f0179Smacallan /**********************************************************************/ 1477b5f0179Smacallan 1487b5f0179Smacallan const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); 1497b5f0179Smacallan static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) 1507b5f0179Smacallan { 1517b5f0179Smacallan return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); 1527b5f0179Smacallan } 1537b5f0179Smacallan 1547b5f0179Smacallan uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); 1557b5f0179Smacallan 1567b5f0179Smacallan /**********************************************************************/ 1577b5f0179Smacallan /* Traversal functions */ 1587b5f0179Smacallan /**********************************************************************/ 1597b5f0179Smacallan 1607b5f0179Smacallan int fdt_next_node(const void *fdt, int offset, int *depth); 1617b5f0179Smacallan 1627b5f0179Smacallan /** 1637b5f0179Smacallan * fdt_first_subnode() - get offset of first direct subnode 1647b5f0179Smacallan * 1657b5f0179Smacallan * @fdt: FDT blob 1667b5f0179Smacallan * @offset: Offset of node to check 1677b5f0179Smacallan * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none 1687b5f0179Smacallan */ 1697b5f0179Smacallan int fdt_first_subnode(const void *fdt, int offset); 1707b5f0179Smacallan 1717b5f0179Smacallan /** 1727b5f0179Smacallan * fdt_next_subnode() - get offset of next direct subnode 1737b5f0179Smacallan * 1747b5f0179Smacallan * After first calling fdt_first_subnode(), call this function repeatedly to 1757b5f0179Smacallan * get direct subnodes of a parent node. 1767b5f0179Smacallan * 1777b5f0179Smacallan * @fdt: FDT blob 1787b5f0179Smacallan * @offset: Offset of previous subnode 1797b5f0179Smacallan * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more 1807b5f0179Smacallan * subnodes 1817b5f0179Smacallan */ 1827b5f0179Smacallan int fdt_next_subnode(const void *fdt, int offset); 1837b5f0179Smacallan 184*2fb928dbSskrll /** 185*2fb928dbSskrll * fdt_for_each_subnode - iterate over all subnodes of a parent 186*2fb928dbSskrll * 187*2fb928dbSskrll * @node: child node (int, lvalue) 188*2fb928dbSskrll * @fdt: FDT blob (const void *) 189*2fb928dbSskrll * @parent: parent node (int) 190*2fb928dbSskrll * 191*2fb928dbSskrll * This is actually a wrapper around a for loop and would be used like so: 192*2fb928dbSskrll * 193*2fb928dbSskrll * fdt_for_each_subnode(node, fdt, parent) { 194*2fb928dbSskrll * Use node 195*2fb928dbSskrll * ... 196*2fb928dbSskrll * } 197*2fb928dbSskrll * 198*2fb928dbSskrll * if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) { 199*2fb928dbSskrll * Error handling 200*2fb928dbSskrll * } 201*2fb928dbSskrll * 202*2fb928dbSskrll * Note that this is implemented as a macro and @node is used as 203*2fb928dbSskrll * iterator in the loop. The parent variable be constant or even a 204*2fb928dbSskrll * literal. 205*2fb928dbSskrll * 206*2fb928dbSskrll */ 207*2fb928dbSskrll #define fdt_for_each_subnode(node, fdt, parent) \ 208*2fb928dbSskrll for (node = fdt_first_subnode(fdt, parent); \ 209*2fb928dbSskrll node >= 0; \ 210*2fb928dbSskrll node = fdt_next_subnode(fdt, node)) 211*2fb928dbSskrll 2127b5f0179Smacallan /**********************************************************************/ 2137b5f0179Smacallan /* General functions */ 2147b5f0179Smacallan /**********************************************************************/ 2157b5f0179Smacallan 2167b5f0179Smacallan #define fdt_get_header(fdt, field) \ 2177b5f0179Smacallan (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field)) 2187b5f0179Smacallan #define fdt_magic(fdt) (fdt_get_header(fdt, magic)) 2197b5f0179Smacallan #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) 2207b5f0179Smacallan #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) 2217b5f0179Smacallan #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) 2227b5f0179Smacallan #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) 2237b5f0179Smacallan #define fdt_version(fdt) (fdt_get_header(fdt, version)) 2247b5f0179Smacallan #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) 2257b5f0179Smacallan #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) 2267b5f0179Smacallan #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) 2277b5f0179Smacallan #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) 2287b5f0179Smacallan 2297b5f0179Smacallan #define __fdt_set_hdr(name) \ 2307b5f0179Smacallan static inline void fdt_set_##name(void *fdt, uint32_t val) \ 2317b5f0179Smacallan { \ 2327b5f0179Smacallan struct fdt_header *fdth = (struct fdt_header *)fdt; \ 2337b5f0179Smacallan fdth->name = cpu_to_fdt32(val); \ 2347b5f0179Smacallan } 2357b5f0179Smacallan __fdt_set_hdr(magic); 2367b5f0179Smacallan __fdt_set_hdr(totalsize); 2377b5f0179Smacallan __fdt_set_hdr(off_dt_struct); 2387b5f0179Smacallan __fdt_set_hdr(off_dt_strings); 2397b5f0179Smacallan __fdt_set_hdr(off_mem_rsvmap); 2407b5f0179Smacallan __fdt_set_hdr(version); 2417b5f0179Smacallan __fdt_set_hdr(last_comp_version); 2427b5f0179Smacallan __fdt_set_hdr(boot_cpuid_phys); 2437b5f0179Smacallan __fdt_set_hdr(size_dt_strings); 2447b5f0179Smacallan __fdt_set_hdr(size_dt_struct); 2457b5f0179Smacallan #undef __fdt_set_hdr 2467b5f0179Smacallan 2477b5f0179Smacallan /** 2487b5f0179Smacallan * fdt_check_header - sanity check a device tree or possible device tree 2497b5f0179Smacallan * @fdt: pointer to data which might be a flattened device tree 2507b5f0179Smacallan * 2517b5f0179Smacallan * fdt_check_header() checks that the given buffer contains what 2527b5f0179Smacallan * appears to be a flattened device tree with sane information in its 2537b5f0179Smacallan * header. 2547b5f0179Smacallan * 2557b5f0179Smacallan * returns: 2567b5f0179Smacallan * 0, if the buffer appears to contain a valid device tree 2577b5f0179Smacallan * -FDT_ERR_BADMAGIC, 2587b5f0179Smacallan * -FDT_ERR_BADVERSION, 2597b5f0179Smacallan * -FDT_ERR_BADSTATE, standard meanings, as above 2607b5f0179Smacallan */ 2617b5f0179Smacallan int fdt_check_header(const void *fdt); 2627b5f0179Smacallan 2637b5f0179Smacallan /** 2647b5f0179Smacallan * fdt_move - move a device tree around in memory 2657b5f0179Smacallan * @fdt: pointer to the device tree to move 2667b5f0179Smacallan * @buf: pointer to memory where the device is to be moved 2677b5f0179Smacallan * @bufsize: size of the memory space at buf 2687b5f0179Smacallan * 2697b5f0179Smacallan * fdt_move() relocates, if possible, the device tree blob located at 2707b5f0179Smacallan * fdt to the buffer at buf of size bufsize. The buffer may overlap 2717b5f0179Smacallan * with the existing device tree blob at fdt. Therefore, 2727b5f0179Smacallan * fdt_move(fdt, fdt, fdt_totalsize(fdt)) 2737b5f0179Smacallan * should always succeed. 2747b5f0179Smacallan * 2757b5f0179Smacallan * returns: 2767b5f0179Smacallan * 0, on success 2777b5f0179Smacallan * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree 2787b5f0179Smacallan * -FDT_ERR_BADMAGIC, 2797b5f0179Smacallan * -FDT_ERR_BADVERSION, 2807b5f0179Smacallan * -FDT_ERR_BADSTATE, standard meanings 2817b5f0179Smacallan */ 2827b5f0179Smacallan int fdt_move(const void *fdt, void *buf, int bufsize); 2837b5f0179Smacallan 2847b5f0179Smacallan /**********************************************************************/ 2857b5f0179Smacallan /* Read-only functions */ 2867b5f0179Smacallan /**********************************************************************/ 2877b5f0179Smacallan 2887b5f0179Smacallan /** 2897b5f0179Smacallan * fdt_string - retrieve a string from the strings block of a device tree 2907b5f0179Smacallan * @fdt: pointer to the device tree blob 2917b5f0179Smacallan * @stroffset: offset of the string within the strings block (native endian) 2927b5f0179Smacallan * 2937b5f0179Smacallan * fdt_string() retrieves a pointer to a single string from the 2947b5f0179Smacallan * strings block of the device tree blob at fdt. 2957b5f0179Smacallan * 2967b5f0179Smacallan * returns: 2977b5f0179Smacallan * a pointer to the string, on success 2987b5f0179Smacallan * NULL, if stroffset is out of bounds 2997b5f0179Smacallan */ 3007b5f0179Smacallan const char *fdt_string(const void *fdt, int stroffset); 3017b5f0179Smacallan 3027b5f0179Smacallan /** 303*2fb928dbSskrll * fdt_get_max_phandle - retrieves the highest phandle in a tree 304*2fb928dbSskrll * @fdt: pointer to the device tree blob 305*2fb928dbSskrll * 306*2fb928dbSskrll * fdt_get_max_phandle retrieves the highest phandle in the given 307*2fb928dbSskrll * device tree. This will ignore badly formatted phandles, or phandles 308*2fb928dbSskrll * with a value of 0 or -1. 309*2fb928dbSskrll * 310*2fb928dbSskrll * returns: 311*2fb928dbSskrll * the highest phandle on success 312*2fb928dbSskrll * 0, if no phandle was found in the device tree 313*2fb928dbSskrll * -1, if an error occurred 314*2fb928dbSskrll */ 315*2fb928dbSskrll uint32_t fdt_get_max_phandle(const void *fdt); 316*2fb928dbSskrll 317*2fb928dbSskrll /** 3187b5f0179Smacallan * fdt_num_mem_rsv - retrieve the number of memory reserve map entries 3197b5f0179Smacallan * @fdt: pointer to the device tree blob 3207b5f0179Smacallan * 3217b5f0179Smacallan * Returns the number of entries in the device tree blob's memory 3227b5f0179Smacallan * reservation map. This does not include the terminating 0,0 entry 3237b5f0179Smacallan * or any other (0,0) entries reserved for expansion. 3247b5f0179Smacallan * 3257b5f0179Smacallan * returns: 3267b5f0179Smacallan * the number of entries 3277b5f0179Smacallan */ 3287b5f0179Smacallan int fdt_num_mem_rsv(const void *fdt); 3297b5f0179Smacallan 3307b5f0179Smacallan /** 3317b5f0179Smacallan * fdt_get_mem_rsv - retrieve one memory reserve map entry 3327b5f0179Smacallan * @fdt: pointer to the device tree blob 3337b5f0179Smacallan * @address, @size: pointers to 64-bit variables 3347b5f0179Smacallan * 3357b5f0179Smacallan * On success, *address and *size will contain the address and size of 3367b5f0179Smacallan * the n-th reserve map entry from the device tree blob, in 3377b5f0179Smacallan * native-endian format. 3387b5f0179Smacallan * 3397b5f0179Smacallan * returns: 3407b5f0179Smacallan * 0, on success 3417b5f0179Smacallan * -FDT_ERR_BADMAGIC, 3427b5f0179Smacallan * -FDT_ERR_BADVERSION, 3437b5f0179Smacallan * -FDT_ERR_BADSTATE, standard meanings 3447b5f0179Smacallan */ 3457b5f0179Smacallan int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size); 3467b5f0179Smacallan 3477b5f0179Smacallan /** 3487b5f0179Smacallan * fdt_subnode_offset_namelen - find a subnode based on substring 3497b5f0179Smacallan * @fdt: pointer to the device tree blob 3507b5f0179Smacallan * @parentoffset: structure block offset of a node 3517b5f0179Smacallan * @name: name of the subnode to locate 3527b5f0179Smacallan * @namelen: number of characters of name to consider 3537b5f0179Smacallan * 3547b5f0179Smacallan * Identical to fdt_subnode_offset(), but only examine the first 3557b5f0179Smacallan * namelen characters of name for matching the subnode name. This is 3567b5f0179Smacallan * useful for finding subnodes based on a portion of a larger string, 3577b5f0179Smacallan * such as a full path. 3587b5f0179Smacallan */ 3597b5f0179Smacallan int fdt_subnode_offset_namelen(const void *fdt, int parentoffset, 3607b5f0179Smacallan const char *name, int namelen); 3617b5f0179Smacallan /** 3627b5f0179Smacallan * fdt_subnode_offset - find a subnode of a given node 3637b5f0179Smacallan * @fdt: pointer to the device tree blob 3647b5f0179Smacallan * @parentoffset: structure block offset of a node 3657b5f0179Smacallan * @name: name of the subnode to locate 3667b5f0179Smacallan * 3677b5f0179Smacallan * fdt_subnode_offset() finds a subnode of the node at structure block 3687b5f0179Smacallan * offset parentoffset with the given name. name may include a unit 3697b5f0179Smacallan * address, in which case fdt_subnode_offset() will find the subnode 3707b5f0179Smacallan * with that unit address, or the unit address may be omitted, in 3717b5f0179Smacallan * which case fdt_subnode_offset() will find an arbitrary subnode 3727b5f0179Smacallan * whose name excluding unit address matches the given name. 3737b5f0179Smacallan * 3747b5f0179Smacallan * returns: 3757b5f0179Smacallan * structure block offset of the requested subnode (>=0), on success 3767b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the requested subnode does not exist 377*2fb928dbSskrll * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE 378*2fb928dbSskrll * tag 3797b5f0179Smacallan * -FDT_ERR_BADMAGIC, 3807b5f0179Smacallan * -FDT_ERR_BADVERSION, 3817b5f0179Smacallan * -FDT_ERR_BADSTATE, 3827b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 3837b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings. 3847b5f0179Smacallan */ 3857b5f0179Smacallan int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); 3867b5f0179Smacallan 3877b5f0179Smacallan /** 3887b5f0179Smacallan * fdt_path_offset_namelen - find a tree node by its full path 3897b5f0179Smacallan * @fdt: pointer to the device tree blob 3907b5f0179Smacallan * @path: full path of the node to locate 3917b5f0179Smacallan * @namelen: number of characters of path to consider 3927b5f0179Smacallan * 3937b5f0179Smacallan * Identical to fdt_path_offset(), but only consider the first namelen 3947b5f0179Smacallan * characters of path as the path name. 3957b5f0179Smacallan */ 3967b5f0179Smacallan int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen); 3977b5f0179Smacallan 3987b5f0179Smacallan /** 3997b5f0179Smacallan * fdt_path_offset - find a tree node by its full path 4007b5f0179Smacallan * @fdt: pointer to the device tree blob 4017b5f0179Smacallan * @path: full path of the node to locate 4027b5f0179Smacallan * 4037b5f0179Smacallan * fdt_path_offset() finds a node of a given path in the device tree. 4047b5f0179Smacallan * Each path component may omit the unit address portion, but the 4057b5f0179Smacallan * results of this are undefined if any such path component is 4067b5f0179Smacallan * ambiguous (that is if there are multiple nodes at the relevant 4077b5f0179Smacallan * level matching the given component, differentiated only by unit 4087b5f0179Smacallan * address). 4097b5f0179Smacallan * 4107b5f0179Smacallan * returns: 411*2fb928dbSskrll * structure block offset of the node with the requested path (>=0), on 412*2fb928dbSskrll * success 4137b5f0179Smacallan * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid 4147b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the requested node does not exist 4157b5f0179Smacallan * -FDT_ERR_BADMAGIC, 4167b5f0179Smacallan * -FDT_ERR_BADVERSION, 4177b5f0179Smacallan * -FDT_ERR_BADSTATE, 4187b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 4197b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings. 4207b5f0179Smacallan */ 4217b5f0179Smacallan int fdt_path_offset(const void *fdt, const char *path); 4227b5f0179Smacallan 4237b5f0179Smacallan /** 4247b5f0179Smacallan * fdt_get_name - retrieve the name of a given node 4257b5f0179Smacallan * @fdt: pointer to the device tree blob 4267b5f0179Smacallan * @nodeoffset: structure block offset of the starting node 4277b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL 4287b5f0179Smacallan * 4297b5f0179Smacallan * fdt_get_name() retrieves the name (including unit address) of the 4307b5f0179Smacallan * device tree node at structure block offset nodeoffset. If lenp is 4317b5f0179Smacallan * non-NULL, the length of this name is also returned, in the integer 4327b5f0179Smacallan * pointed to by lenp. 4337b5f0179Smacallan * 4347b5f0179Smacallan * returns: 4357b5f0179Smacallan * pointer to the node's name, on success 436*2fb928dbSskrll * If lenp is non-NULL, *lenp contains the length of that name 437*2fb928dbSskrll * (>=0) 4387b5f0179Smacallan * NULL, on error 4397b5f0179Smacallan * if lenp is non-NULL *lenp contains an error code (<0): 440*2fb928dbSskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE 441*2fb928dbSskrll * tag 4427b5f0179Smacallan * -FDT_ERR_BADMAGIC, 4437b5f0179Smacallan * -FDT_ERR_BADVERSION, 4447b5f0179Smacallan * -FDT_ERR_BADSTATE, standard meanings 4457b5f0179Smacallan */ 4467b5f0179Smacallan const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp); 4477b5f0179Smacallan 4487b5f0179Smacallan /** 4497b5f0179Smacallan * fdt_first_property_offset - find the offset of a node's first property 4507b5f0179Smacallan * @fdt: pointer to the device tree blob 4517b5f0179Smacallan * @nodeoffset: structure block offset of a node 4527b5f0179Smacallan * 4537b5f0179Smacallan * fdt_first_property_offset() finds the first property of the node at 4547b5f0179Smacallan * the given structure block offset. 4557b5f0179Smacallan * 4567b5f0179Smacallan * returns: 4577b5f0179Smacallan * structure block offset of the property (>=0), on success 4587b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the requested node has no properties 4597b5f0179Smacallan * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag 4607b5f0179Smacallan * -FDT_ERR_BADMAGIC, 4617b5f0179Smacallan * -FDT_ERR_BADVERSION, 4627b5f0179Smacallan * -FDT_ERR_BADSTATE, 4637b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 4647b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings. 4657b5f0179Smacallan */ 4667b5f0179Smacallan int fdt_first_property_offset(const void *fdt, int nodeoffset); 4677b5f0179Smacallan 4687b5f0179Smacallan /** 4697b5f0179Smacallan * fdt_next_property_offset - step through a node's properties 4707b5f0179Smacallan * @fdt: pointer to the device tree blob 4717b5f0179Smacallan * @offset: structure block offset of a property 4727b5f0179Smacallan * 4737b5f0179Smacallan * fdt_next_property_offset() finds the property immediately after the 4747b5f0179Smacallan * one at the given structure block offset. This will be a property 4757b5f0179Smacallan * of the same node as the given property. 4767b5f0179Smacallan * 4777b5f0179Smacallan * returns: 4787b5f0179Smacallan * structure block offset of the next property (>=0), on success 4797b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the given property is the last in its node 4807b5f0179Smacallan * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag 4817b5f0179Smacallan * -FDT_ERR_BADMAGIC, 4827b5f0179Smacallan * -FDT_ERR_BADVERSION, 4837b5f0179Smacallan * -FDT_ERR_BADSTATE, 4847b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 4857b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings. 4867b5f0179Smacallan */ 4877b5f0179Smacallan int fdt_next_property_offset(const void *fdt, int offset); 4887b5f0179Smacallan 4897b5f0179Smacallan /** 490*2fb928dbSskrll * fdt_for_each_property_offset - iterate over all properties of a node 491*2fb928dbSskrll * 492*2fb928dbSskrll * @property_offset: property offset (int, lvalue) 493*2fb928dbSskrll * @fdt: FDT blob (const void *) 494*2fb928dbSskrll * @node: node offset (int) 495*2fb928dbSskrll * 496*2fb928dbSskrll * This is actually a wrapper around a for loop and would be used like so: 497*2fb928dbSskrll * 498*2fb928dbSskrll * fdt_for_each_property_offset(property, fdt, node) { 499*2fb928dbSskrll * Use property 500*2fb928dbSskrll * ... 501*2fb928dbSskrll * } 502*2fb928dbSskrll * 503*2fb928dbSskrll * if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) { 504*2fb928dbSskrll * Error handling 505*2fb928dbSskrll * } 506*2fb928dbSskrll * 507*2fb928dbSskrll * Note that this is implemented as a macro and property is used as 508*2fb928dbSskrll * iterator in the loop. The node variable can be constant or even a 509*2fb928dbSskrll * literal. 510*2fb928dbSskrll */ 511*2fb928dbSskrll #define fdt_for_each_property_offset(property, fdt, node) \ 512*2fb928dbSskrll for (property = fdt_first_property_offset(fdt, node); \ 513*2fb928dbSskrll property >= 0; \ 514*2fb928dbSskrll property = fdt_next_property_offset(fdt, property)) 515*2fb928dbSskrll 516*2fb928dbSskrll /** 5177b5f0179Smacallan * fdt_get_property_by_offset - retrieve the property at a given offset 5187b5f0179Smacallan * @fdt: pointer to the device tree blob 5197b5f0179Smacallan * @offset: offset of the property to retrieve 5207b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL 5217b5f0179Smacallan * 5227b5f0179Smacallan * fdt_get_property_by_offset() retrieves a pointer to the 5237b5f0179Smacallan * fdt_property structure within the device tree blob at the given 5247b5f0179Smacallan * offset. If lenp is non-NULL, the length of the property value is 5257b5f0179Smacallan * also returned, in the integer pointed to by lenp. 5267b5f0179Smacallan * 5277b5f0179Smacallan * returns: 5287b5f0179Smacallan * pointer to the structure representing the property 5297b5f0179Smacallan * if lenp is non-NULL, *lenp contains the length of the property 5307b5f0179Smacallan * value (>=0) 5317b5f0179Smacallan * NULL, on error 5327b5f0179Smacallan * if lenp is non-NULL, *lenp contains an error code (<0): 5337b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag 5347b5f0179Smacallan * -FDT_ERR_BADMAGIC, 5357b5f0179Smacallan * -FDT_ERR_BADVERSION, 5367b5f0179Smacallan * -FDT_ERR_BADSTATE, 5377b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 5387b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 5397b5f0179Smacallan */ 5407b5f0179Smacallan const struct fdt_property *fdt_get_property_by_offset(const void *fdt, 5417b5f0179Smacallan int offset, 5427b5f0179Smacallan int *lenp); 5437b5f0179Smacallan 5447b5f0179Smacallan /** 5457b5f0179Smacallan * fdt_get_property_namelen - find a property based on substring 5467b5f0179Smacallan * @fdt: pointer to the device tree blob 5477b5f0179Smacallan * @nodeoffset: offset of the node whose property to find 5487b5f0179Smacallan * @name: name of the property to find 5497b5f0179Smacallan * @namelen: number of characters of name to consider 5507b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL 5517b5f0179Smacallan * 5527b5f0179Smacallan * Identical to fdt_get_property(), but only examine the first namelen 5537b5f0179Smacallan * characters of name for matching the property name. 5547b5f0179Smacallan */ 5557b5f0179Smacallan const struct fdt_property *fdt_get_property_namelen(const void *fdt, 5567b5f0179Smacallan int nodeoffset, 5577b5f0179Smacallan const char *name, 5587b5f0179Smacallan int namelen, int *lenp); 5597b5f0179Smacallan 5607b5f0179Smacallan /** 5617b5f0179Smacallan * fdt_get_property - find a given property in a given node 5627b5f0179Smacallan * @fdt: pointer to the device tree blob 5637b5f0179Smacallan * @nodeoffset: offset of the node whose property to find 5647b5f0179Smacallan * @name: name of the property to find 5657b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL 5667b5f0179Smacallan * 5677b5f0179Smacallan * fdt_get_property() retrieves a pointer to the fdt_property 5687b5f0179Smacallan * structure within the device tree blob corresponding to the property 5697b5f0179Smacallan * named 'name' of the node at offset nodeoffset. If lenp is 5707b5f0179Smacallan * non-NULL, the length of the property value is also returned, in the 5717b5f0179Smacallan * integer pointed to by lenp. 5727b5f0179Smacallan * 5737b5f0179Smacallan * returns: 5747b5f0179Smacallan * pointer to the structure representing the property 5757b5f0179Smacallan * if lenp is non-NULL, *lenp contains the length of the property 5767b5f0179Smacallan * value (>=0) 5777b5f0179Smacallan * NULL, on error 5787b5f0179Smacallan * if lenp is non-NULL, *lenp contains an error code (<0): 5797b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have named property 580*2fb928dbSskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE 581*2fb928dbSskrll * tag 5827b5f0179Smacallan * -FDT_ERR_BADMAGIC, 5837b5f0179Smacallan * -FDT_ERR_BADVERSION, 5847b5f0179Smacallan * -FDT_ERR_BADSTATE, 5857b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 5867b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 5877b5f0179Smacallan */ 5887b5f0179Smacallan const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset, 5897b5f0179Smacallan const char *name, int *lenp); 5907b5f0179Smacallan static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset, 5917b5f0179Smacallan const char *name, 5927b5f0179Smacallan int *lenp) 5937b5f0179Smacallan { 5947b5f0179Smacallan return (struct fdt_property *)(uintptr_t) 5957b5f0179Smacallan fdt_get_property(fdt, nodeoffset, name, lenp); 5967b5f0179Smacallan } 5977b5f0179Smacallan 5987b5f0179Smacallan /** 5997b5f0179Smacallan * fdt_getprop_by_offset - retrieve the value of a property at a given offset 6007b5f0179Smacallan * @fdt: pointer to the device tree blob 6017b5f0179Smacallan * @ffset: offset of the property to read 6027b5f0179Smacallan * @namep: pointer to a string variable (will be overwritten) or NULL 6037b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL 6047b5f0179Smacallan * 6057b5f0179Smacallan * fdt_getprop_by_offset() retrieves a pointer to the value of the 6067b5f0179Smacallan * property at structure block offset 'offset' (this will be a pointer 6077b5f0179Smacallan * to within the device blob itself, not a copy of the value). If 6087b5f0179Smacallan * lenp is non-NULL, the length of the property value is also 6097b5f0179Smacallan * returned, in the integer pointed to by lenp. If namep is non-NULL, 6107b5f0179Smacallan * the property's namne will also be returned in the char * pointed to 6117b5f0179Smacallan * by namep (this will be a pointer to within the device tree's string 6127b5f0179Smacallan * block, not a new copy of the name). 6137b5f0179Smacallan * 6147b5f0179Smacallan * returns: 6157b5f0179Smacallan * pointer to the property's value 6167b5f0179Smacallan * if lenp is non-NULL, *lenp contains the length of the property 6177b5f0179Smacallan * value (>=0) 6187b5f0179Smacallan * if namep is non-NULL *namep contiains a pointer to the property 6197b5f0179Smacallan * name. 6207b5f0179Smacallan * NULL, on error 6217b5f0179Smacallan * if lenp is non-NULL, *lenp contains an error code (<0): 6227b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag 6237b5f0179Smacallan * -FDT_ERR_BADMAGIC, 6247b5f0179Smacallan * -FDT_ERR_BADVERSION, 6257b5f0179Smacallan * -FDT_ERR_BADSTATE, 6267b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 6277b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 6287b5f0179Smacallan */ 6297b5f0179Smacallan const void *fdt_getprop_by_offset(const void *fdt, int offset, 6307b5f0179Smacallan const char **namep, int *lenp); 6317b5f0179Smacallan 6327b5f0179Smacallan /** 6337b5f0179Smacallan * fdt_getprop_namelen - get property value based on substring 6347b5f0179Smacallan * @fdt: pointer to the device tree blob 6357b5f0179Smacallan * @nodeoffset: offset of the node whose property to find 6367b5f0179Smacallan * @name: name of the property to find 6377b5f0179Smacallan * @namelen: number of characters of name to consider 6387b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL 6397b5f0179Smacallan * 6407b5f0179Smacallan * Identical to fdt_getprop(), but only examine the first namelen 6417b5f0179Smacallan * characters of name for matching the property name. 6427b5f0179Smacallan */ 6437b5f0179Smacallan const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, 6447b5f0179Smacallan const char *name, int namelen, int *lenp); 645*2fb928dbSskrll static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset, 646*2fb928dbSskrll const char *name, int namelen, 647*2fb928dbSskrll int *lenp) 648*2fb928dbSskrll { 649*2fb928dbSskrll return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name, 650*2fb928dbSskrll namelen, lenp); 651*2fb928dbSskrll } 6527b5f0179Smacallan 6537b5f0179Smacallan /** 6547b5f0179Smacallan * fdt_getprop - retrieve the value of a given property 6557b5f0179Smacallan * @fdt: pointer to the device tree blob 6567b5f0179Smacallan * @nodeoffset: offset of the node whose property to find 6577b5f0179Smacallan * @name: name of the property to find 6587b5f0179Smacallan * @lenp: pointer to an integer variable (will be overwritten) or NULL 6597b5f0179Smacallan * 6607b5f0179Smacallan * fdt_getprop() retrieves a pointer to the value of the property 6617b5f0179Smacallan * named 'name' of the node at offset nodeoffset (this will be a 6627b5f0179Smacallan * pointer to within the device blob itself, not a copy of the value). 6637b5f0179Smacallan * If lenp is non-NULL, the length of the property value is also 6647b5f0179Smacallan * returned, in the integer pointed to by lenp. 6657b5f0179Smacallan * 6667b5f0179Smacallan * returns: 6677b5f0179Smacallan * pointer to the property's value 6687b5f0179Smacallan * if lenp is non-NULL, *lenp contains the length of the property 6697b5f0179Smacallan * value (>=0) 6707b5f0179Smacallan * NULL, on error 6717b5f0179Smacallan * if lenp is non-NULL, *lenp contains an error code (<0): 6727b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have named property 673*2fb928dbSskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE 674*2fb928dbSskrll * tag 6757b5f0179Smacallan * -FDT_ERR_BADMAGIC, 6767b5f0179Smacallan * -FDT_ERR_BADVERSION, 6777b5f0179Smacallan * -FDT_ERR_BADSTATE, 6787b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 6797b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 6807b5f0179Smacallan */ 6817b5f0179Smacallan const void *fdt_getprop(const void *fdt, int nodeoffset, 6827b5f0179Smacallan const char *name, int *lenp); 6837b5f0179Smacallan static inline void *fdt_getprop_w(void *fdt, int nodeoffset, 6847b5f0179Smacallan const char *name, int *lenp) 6857b5f0179Smacallan { 6867b5f0179Smacallan return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp); 6877b5f0179Smacallan } 6887b5f0179Smacallan 6897b5f0179Smacallan /** 6907b5f0179Smacallan * fdt_get_phandle - retrieve the phandle of a given node 6917b5f0179Smacallan * @fdt: pointer to the device tree blob 6927b5f0179Smacallan * @nodeoffset: structure block offset of the node 6937b5f0179Smacallan * 6947b5f0179Smacallan * fdt_get_phandle() retrieves the phandle of the device tree node at 6957b5f0179Smacallan * structure block offset nodeoffset. 6967b5f0179Smacallan * 6977b5f0179Smacallan * returns: 6987b5f0179Smacallan * the phandle of the node at nodeoffset, on success (!= 0, != -1) 6997b5f0179Smacallan * 0, if the node has no phandle, or another error occurs 7007b5f0179Smacallan */ 7017b5f0179Smacallan uint32_t fdt_get_phandle(const void *fdt, int nodeoffset); 7027b5f0179Smacallan 7037b5f0179Smacallan /** 7047b5f0179Smacallan * fdt_get_alias_namelen - get alias based on substring 7057b5f0179Smacallan * @fdt: pointer to the device tree blob 7067b5f0179Smacallan * @name: name of the alias th look up 7077b5f0179Smacallan * @namelen: number of characters of name to consider 7087b5f0179Smacallan * 7097b5f0179Smacallan * Identical to fdt_get_alias(), but only examine the first namelen 7107b5f0179Smacallan * characters of name for matching the alias name. 7117b5f0179Smacallan */ 7127b5f0179Smacallan const char *fdt_get_alias_namelen(const void *fdt, 7137b5f0179Smacallan const char *name, int namelen); 7147b5f0179Smacallan 7157b5f0179Smacallan /** 716*2fb928dbSskrll * fdt_get_alias - retrieve the path referenced by a given alias 7177b5f0179Smacallan * @fdt: pointer to the device tree blob 7187b5f0179Smacallan * @name: name of the alias th look up 7197b5f0179Smacallan * 7207b5f0179Smacallan * fdt_get_alias() retrieves the value of a given alias. That is, the 7217b5f0179Smacallan * value of the property named 'name' in the node /aliases. 7227b5f0179Smacallan * 7237b5f0179Smacallan * returns: 7247b5f0179Smacallan * a pointer to the expansion of the alias named 'name', if it exists 7257b5f0179Smacallan * NULL, if the given alias or the /aliases node does not exist 7267b5f0179Smacallan */ 7277b5f0179Smacallan const char *fdt_get_alias(const void *fdt, const char *name); 7287b5f0179Smacallan 7297b5f0179Smacallan /** 7307b5f0179Smacallan * fdt_get_path - determine the full path of a node 7317b5f0179Smacallan * @fdt: pointer to the device tree blob 7327b5f0179Smacallan * @nodeoffset: offset of the node whose path to find 7337b5f0179Smacallan * @buf: character buffer to contain the returned path (will be overwritten) 7347b5f0179Smacallan * @buflen: size of the character buffer at buf 7357b5f0179Smacallan * 7367b5f0179Smacallan * fdt_get_path() computes the full path of the node at offset 7377b5f0179Smacallan * nodeoffset, and records that path in the buffer at buf. 7387b5f0179Smacallan * 7397b5f0179Smacallan * NOTE: This function is expensive, as it must scan the device tree 7407b5f0179Smacallan * structure from the start to nodeoffset. 7417b5f0179Smacallan * 7427b5f0179Smacallan * returns: 7437b5f0179Smacallan * 0, on success 7447b5f0179Smacallan * buf contains the absolute path of the node at 7457b5f0179Smacallan * nodeoffset, as a NUL-terminated string. 7467b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 7477b5f0179Smacallan * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1) 7487b5f0179Smacallan * characters and will not fit in the given buffer. 7497b5f0179Smacallan * -FDT_ERR_BADMAGIC, 7507b5f0179Smacallan * -FDT_ERR_BADVERSION, 7517b5f0179Smacallan * -FDT_ERR_BADSTATE, 7527b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings 7537b5f0179Smacallan */ 7547b5f0179Smacallan int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen); 7557b5f0179Smacallan 7567b5f0179Smacallan /** 7577b5f0179Smacallan * fdt_supernode_atdepth_offset - find a specific ancestor of a node 7587b5f0179Smacallan * @fdt: pointer to the device tree blob 7597b5f0179Smacallan * @nodeoffset: offset of the node whose parent to find 7607b5f0179Smacallan * @supernodedepth: depth of the ancestor to find 7617b5f0179Smacallan * @nodedepth: pointer to an integer variable (will be overwritten) or NULL 7627b5f0179Smacallan * 7637b5f0179Smacallan * fdt_supernode_atdepth_offset() finds an ancestor of the given node 7647b5f0179Smacallan * at a specific depth from the root (where the root itself has depth 7657b5f0179Smacallan * 0, its immediate subnodes depth 1 and so forth). So 7667b5f0179Smacallan * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL); 7677b5f0179Smacallan * will always return 0, the offset of the root node. If the node at 7687b5f0179Smacallan * nodeoffset has depth D, then: 7697b5f0179Smacallan * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL); 7707b5f0179Smacallan * will return nodeoffset itself. 7717b5f0179Smacallan * 7727b5f0179Smacallan * NOTE: This function is expensive, as it must scan the device tree 7737b5f0179Smacallan * structure from the start to nodeoffset. 7747b5f0179Smacallan * 7757b5f0179Smacallan * returns: 7767b5f0179Smacallan * structure block offset of the node at node offset's ancestor 7777b5f0179Smacallan * of depth supernodedepth (>=0), on success 7787b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 779*2fb928dbSskrll * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of 780*2fb928dbSskrll * nodeoffset 7817b5f0179Smacallan * -FDT_ERR_BADMAGIC, 7827b5f0179Smacallan * -FDT_ERR_BADVERSION, 7837b5f0179Smacallan * -FDT_ERR_BADSTATE, 7847b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings 7857b5f0179Smacallan */ 7867b5f0179Smacallan int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, 7877b5f0179Smacallan int supernodedepth, int *nodedepth); 7887b5f0179Smacallan 7897b5f0179Smacallan /** 7907b5f0179Smacallan * fdt_node_depth - find the depth of a given node 7917b5f0179Smacallan * @fdt: pointer to the device tree blob 7927b5f0179Smacallan * @nodeoffset: offset of the node whose parent to find 7937b5f0179Smacallan * 7947b5f0179Smacallan * fdt_node_depth() finds the depth of a given node. The root node 7957b5f0179Smacallan * has depth 0, its immediate subnodes depth 1 and so forth. 7967b5f0179Smacallan * 7977b5f0179Smacallan * NOTE: This function is expensive, as it must scan the device tree 7987b5f0179Smacallan * structure from the start to nodeoffset. 7997b5f0179Smacallan * 8007b5f0179Smacallan * returns: 8017b5f0179Smacallan * depth of the node at nodeoffset (>=0), on success 8027b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 8037b5f0179Smacallan * -FDT_ERR_BADMAGIC, 8047b5f0179Smacallan * -FDT_ERR_BADVERSION, 8057b5f0179Smacallan * -FDT_ERR_BADSTATE, 8067b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings 8077b5f0179Smacallan */ 8087b5f0179Smacallan int fdt_node_depth(const void *fdt, int nodeoffset); 8097b5f0179Smacallan 8107b5f0179Smacallan /** 8117b5f0179Smacallan * fdt_parent_offset - find the parent of a given node 8127b5f0179Smacallan * @fdt: pointer to the device tree blob 8137b5f0179Smacallan * @nodeoffset: offset of the node whose parent to find 8147b5f0179Smacallan * 8157b5f0179Smacallan * fdt_parent_offset() locates the parent node of a given node (that 8167b5f0179Smacallan * is, it finds the offset of the node which contains the node at 8177b5f0179Smacallan * nodeoffset as a subnode). 8187b5f0179Smacallan * 8197b5f0179Smacallan * NOTE: This function is expensive, as it must scan the device tree 8207b5f0179Smacallan * structure from the start to nodeoffset, *twice*. 8217b5f0179Smacallan * 8227b5f0179Smacallan * returns: 8237b5f0179Smacallan * structure block offset of the parent of the node at nodeoffset 8247b5f0179Smacallan * (>=0), on success 8257b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 8267b5f0179Smacallan * -FDT_ERR_BADMAGIC, 8277b5f0179Smacallan * -FDT_ERR_BADVERSION, 8287b5f0179Smacallan * -FDT_ERR_BADSTATE, 8297b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings 8307b5f0179Smacallan */ 8317b5f0179Smacallan int fdt_parent_offset(const void *fdt, int nodeoffset); 8327b5f0179Smacallan 8337b5f0179Smacallan /** 8347b5f0179Smacallan * fdt_node_offset_by_prop_value - find nodes with a given property value 8357b5f0179Smacallan * @fdt: pointer to the device tree blob 8367b5f0179Smacallan * @startoffset: only find nodes after this offset 8377b5f0179Smacallan * @propname: property name to check 8387b5f0179Smacallan * @propval: property value to search for 8397b5f0179Smacallan * @proplen: length of the value in propval 8407b5f0179Smacallan * 8417b5f0179Smacallan * fdt_node_offset_by_prop_value() returns the offset of the first 8427b5f0179Smacallan * node after startoffset, which has a property named propname whose 8437b5f0179Smacallan * value is of length proplen and has value equal to propval; or if 8447b5f0179Smacallan * startoffset is -1, the very first such node in the tree. 8457b5f0179Smacallan * 8467b5f0179Smacallan * To iterate through all nodes matching the criterion, the following 8477b5f0179Smacallan * idiom can be used: 8487b5f0179Smacallan * offset = fdt_node_offset_by_prop_value(fdt, -1, propname, 8497b5f0179Smacallan * propval, proplen); 8507b5f0179Smacallan * while (offset != -FDT_ERR_NOTFOUND) { 8517b5f0179Smacallan * // other code here 8527b5f0179Smacallan * offset = fdt_node_offset_by_prop_value(fdt, offset, propname, 8537b5f0179Smacallan * propval, proplen); 8547b5f0179Smacallan * } 8557b5f0179Smacallan * 8567b5f0179Smacallan * Note the -1 in the first call to the function, if 0 is used here 8577b5f0179Smacallan * instead, the function will never locate the root node, even if it 8587b5f0179Smacallan * matches the criterion. 8597b5f0179Smacallan * 8607b5f0179Smacallan * returns: 8617b5f0179Smacallan * structure block offset of the located node (>= 0, >startoffset), 8627b5f0179Smacallan * on success 8637b5f0179Smacallan * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the 8647b5f0179Smacallan * tree after startoffset 8657b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 8667b5f0179Smacallan * -FDT_ERR_BADMAGIC, 8677b5f0179Smacallan * -FDT_ERR_BADVERSION, 8687b5f0179Smacallan * -FDT_ERR_BADSTATE, 8697b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings 8707b5f0179Smacallan */ 8717b5f0179Smacallan int fdt_node_offset_by_prop_value(const void *fdt, int startoffset, 8727b5f0179Smacallan const char *propname, 8737b5f0179Smacallan const void *propval, int proplen); 8747b5f0179Smacallan 8757b5f0179Smacallan /** 8767b5f0179Smacallan * fdt_node_offset_by_phandle - find the node with a given phandle 8777b5f0179Smacallan * @fdt: pointer to the device tree blob 8787b5f0179Smacallan * @phandle: phandle value 8797b5f0179Smacallan * 8807b5f0179Smacallan * fdt_node_offset_by_phandle() returns the offset of the node 8817b5f0179Smacallan * which has the given phandle value. If there is more than one node 8827b5f0179Smacallan * in the tree with the given phandle (an invalid tree), results are 8837b5f0179Smacallan * undefined. 8847b5f0179Smacallan * 8857b5f0179Smacallan * returns: 8867b5f0179Smacallan * structure block offset of the located node (>= 0), on success 8877b5f0179Smacallan * -FDT_ERR_NOTFOUND, no node with that phandle exists 8887b5f0179Smacallan * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1) 8897b5f0179Smacallan * -FDT_ERR_BADMAGIC, 8907b5f0179Smacallan * -FDT_ERR_BADVERSION, 8917b5f0179Smacallan * -FDT_ERR_BADSTATE, 8927b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings 8937b5f0179Smacallan */ 8947b5f0179Smacallan int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle); 8957b5f0179Smacallan 8967b5f0179Smacallan /** 8977b5f0179Smacallan * fdt_node_check_compatible: check a node's compatible property 8987b5f0179Smacallan * @fdt: pointer to the device tree blob 8997b5f0179Smacallan * @nodeoffset: offset of a tree node 9007b5f0179Smacallan * @compatible: string to match against 9017b5f0179Smacallan * 9027b5f0179Smacallan * 9037b5f0179Smacallan * fdt_node_check_compatible() returns 0 if the given node contains a 9047b5f0179Smacallan * 'compatible' property with the given string as one of its elements, 9057b5f0179Smacallan * it returns non-zero otherwise, or on error. 9067b5f0179Smacallan * 9077b5f0179Smacallan * returns: 9087b5f0179Smacallan * 0, if the node has a 'compatible' property listing the given string 9097b5f0179Smacallan * 1, if the node has a 'compatible' property, but it does not list 9107b5f0179Smacallan * the given string 9117b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property 9127b5f0179Smacallan * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag 9137b5f0179Smacallan * -FDT_ERR_BADMAGIC, 9147b5f0179Smacallan * -FDT_ERR_BADVERSION, 9157b5f0179Smacallan * -FDT_ERR_BADSTATE, 9167b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings 9177b5f0179Smacallan */ 9187b5f0179Smacallan int fdt_node_check_compatible(const void *fdt, int nodeoffset, 9197b5f0179Smacallan const char *compatible); 9207b5f0179Smacallan 9217b5f0179Smacallan /** 9227b5f0179Smacallan * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value 9237b5f0179Smacallan * @fdt: pointer to the device tree blob 9247b5f0179Smacallan * @startoffset: only find nodes after this offset 9257b5f0179Smacallan * @compatible: 'compatible' string to match against 9267b5f0179Smacallan * 9277b5f0179Smacallan * fdt_node_offset_by_compatible() returns the offset of the first 9287b5f0179Smacallan * node after startoffset, which has a 'compatible' property which 9297b5f0179Smacallan * lists the given compatible string; or if startoffset is -1, the 9307b5f0179Smacallan * very first such node in the tree. 9317b5f0179Smacallan * 9327b5f0179Smacallan * To iterate through all nodes matching the criterion, the following 9337b5f0179Smacallan * idiom can be used: 9347b5f0179Smacallan * offset = fdt_node_offset_by_compatible(fdt, -1, compatible); 9357b5f0179Smacallan * while (offset != -FDT_ERR_NOTFOUND) { 9367b5f0179Smacallan * // other code here 9377b5f0179Smacallan * offset = fdt_node_offset_by_compatible(fdt, offset, compatible); 9387b5f0179Smacallan * } 9397b5f0179Smacallan * 9407b5f0179Smacallan * Note the -1 in the first call to the function, if 0 is used here 9417b5f0179Smacallan * instead, the function will never locate the root node, even if it 9427b5f0179Smacallan * matches the criterion. 9437b5f0179Smacallan * 9447b5f0179Smacallan * returns: 9457b5f0179Smacallan * structure block offset of the located node (>= 0, >startoffset), 9467b5f0179Smacallan * on success 9477b5f0179Smacallan * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the 9487b5f0179Smacallan * tree after startoffset 9497b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 9507b5f0179Smacallan * -FDT_ERR_BADMAGIC, 9517b5f0179Smacallan * -FDT_ERR_BADVERSION, 9527b5f0179Smacallan * -FDT_ERR_BADSTATE, 9537b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, standard meanings 9547b5f0179Smacallan */ 9557b5f0179Smacallan int fdt_node_offset_by_compatible(const void *fdt, int startoffset, 9567b5f0179Smacallan const char *compatible); 9577b5f0179Smacallan 9587b5f0179Smacallan /** 9597b5f0179Smacallan * fdt_stringlist_contains - check a string list property for a string 9607b5f0179Smacallan * @strlist: Property containing a list of strings to check 9617b5f0179Smacallan * @listlen: Length of property 9627b5f0179Smacallan * @str: String to search for 9637b5f0179Smacallan * 9647b5f0179Smacallan * This is a utility function provided for convenience. The list contains 9657b5f0179Smacallan * one or more strings, each terminated by \0, as is found in a device tree 9667b5f0179Smacallan * "compatible" property. 9677b5f0179Smacallan * 9687b5f0179Smacallan * @return: 1 if the string is found in the list, 0 not found, or invalid list 9697b5f0179Smacallan */ 9707b5f0179Smacallan int fdt_stringlist_contains(const char *strlist, int listlen, const char *str); 9717b5f0179Smacallan 9727b5f0179Smacallan /** 9737b5f0179Smacallan * fdt_stringlist_count - count the number of strings in a string list 9747b5f0179Smacallan * @fdt: pointer to the device tree blob 9757b5f0179Smacallan * @nodeoffset: offset of a tree node 9767b5f0179Smacallan * @property: name of the property containing the string list 9777b5f0179Smacallan * @return: 9787b5f0179Smacallan * the number of strings in the given property 9797b5f0179Smacallan * -FDT_ERR_BADVALUE if the property value is not NUL-terminated 9807b5f0179Smacallan * -FDT_ERR_NOTFOUND if the property does not exist 9817b5f0179Smacallan */ 9827b5f0179Smacallan int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property); 9837b5f0179Smacallan 9847b5f0179Smacallan /** 9857b5f0179Smacallan * fdt_stringlist_search - find a string in a string list and return its index 9867b5f0179Smacallan * @fdt: pointer to the device tree blob 9877b5f0179Smacallan * @nodeoffset: offset of a tree node 9887b5f0179Smacallan * @property: name of the property containing the string list 9897b5f0179Smacallan * @string: string to look up in the string list 9907b5f0179Smacallan * 9917b5f0179Smacallan * Note that it is possible for this function to succeed on property values 9927b5f0179Smacallan * that are not NUL-terminated. That's because the function will stop after 9937b5f0179Smacallan * finding the first occurrence of @string. This can for example happen with 9947b5f0179Smacallan * small-valued cell properties, such as #address-cells, when searching for 9957b5f0179Smacallan * the empty string. 9967b5f0179Smacallan * 9977b5f0179Smacallan * @return: 9987b5f0179Smacallan * the index of the string in the list of strings 9997b5f0179Smacallan * -FDT_ERR_BADVALUE if the property value is not NUL-terminated 10007b5f0179Smacallan * -FDT_ERR_NOTFOUND if the property does not exist or does not contain 10017b5f0179Smacallan * the given string 10027b5f0179Smacallan */ 10037b5f0179Smacallan int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property, 10047b5f0179Smacallan const char *string); 10057b5f0179Smacallan 10067b5f0179Smacallan /** 10077b5f0179Smacallan * fdt_stringlist_get() - obtain the string at a given index in a string list 10087b5f0179Smacallan * @fdt: pointer to the device tree blob 10097b5f0179Smacallan * @nodeoffset: offset of a tree node 10107b5f0179Smacallan * @property: name of the property containing the string list 10117b5f0179Smacallan * @index: index of the string to return 10127b5f0179Smacallan * @lenp: return location for the string length or an error code on failure 10137b5f0179Smacallan * 10147b5f0179Smacallan * Note that this will successfully extract strings from properties with 10157b5f0179Smacallan * non-NUL-terminated values. For example on small-valued cell properties 10167b5f0179Smacallan * this function will return the empty string. 10177b5f0179Smacallan * 10187b5f0179Smacallan * If non-NULL, the length of the string (on success) or a negative error-code 10197b5f0179Smacallan * (on failure) will be stored in the integer pointer to by lenp. 10207b5f0179Smacallan * 10217b5f0179Smacallan * @return: 10227b5f0179Smacallan * A pointer to the string at the given index in the string list or NULL on 10237b5f0179Smacallan * failure. On success the length of the string will be stored in the memory 10247b5f0179Smacallan * location pointed to by the lenp parameter, if non-NULL. On failure one of 10257b5f0179Smacallan * the following negative error codes will be returned in the lenp parameter 10267b5f0179Smacallan * (if non-NULL): 10277b5f0179Smacallan * -FDT_ERR_BADVALUE if the property value is not NUL-terminated 10287b5f0179Smacallan * -FDT_ERR_NOTFOUND if the property does not exist 10297b5f0179Smacallan */ 10307b5f0179Smacallan const char *fdt_stringlist_get(const void *fdt, int nodeoffset, 10317b5f0179Smacallan const char *property, int index, 10327b5f0179Smacallan int *lenp); 10337b5f0179Smacallan 10347b5f0179Smacallan /**********************************************************************/ 10357b5f0179Smacallan /* Read-only functions (addressing related) */ 10367b5f0179Smacallan /**********************************************************************/ 10377b5f0179Smacallan 10387b5f0179Smacallan /** 10397b5f0179Smacallan * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells 10407b5f0179Smacallan * 10417b5f0179Smacallan * This is the maximum value for #address-cells, #size-cells and 10427b5f0179Smacallan * similar properties that will be processed by libfdt. IEE1275 10437b5f0179Smacallan * requires that OF implementations handle values up to 4. 10447b5f0179Smacallan * Implementations may support larger values, but in practice higher 10457b5f0179Smacallan * values aren't used. 10467b5f0179Smacallan */ 10477b5f0179Smacallan #define FDT_MAX_NCELLS 4 10487b5f0179Smacallan 10497b5f0179Smacallan /** 10507b5f0179Smacallan * fdt_address_cells - retrieve address size for a bus represented in the tree 10517b5f0179Smacallan * @fdt: pointer to the device tree blob 10527b5f0179Smacallan * @nodeoffset: offset of the node to find the address size for 10537b5f0179Smacallan * 10547b5f0179Smacallan * When the node has a valid #address-cells property, returns its value. 10557b5f0179Smacallan * 10567b5f0179Smacallan * returns: 10577b5f0179Smacallan * 0 <= n < FDT_MAX_NCELLS, on success 10587b5f0179Smacallan * 2, if the node has no #address-cells property 1059*2fb928dbSskrll * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid 1060*2fb928dbSskrll * #address-cells property 10617b5f0179Smacallan * -FDT_ERR_BADMAGIC, 10627b5f0179Smacallan * -FDT_ERR_BADVERSION, 10637b5f0179Smacallan * -FDT_ERR_BADSTATE, 10647b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 10657b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 10667b5f0179Smacallan */ 10677b5f0179Smacallan int fdt_address_cells(const void *fdt, int nodeoffset); 10687b5f0179Smacallan 10697b5f0179Smacallan /** 10707b5f0179Smacallan * fdt_size_cells - retrieve address range size for a bus represented in the 10717b5f0179Smacallan * tree 10727b5f0179Smacallan * @fdt: pointer to the device tree blob 10737b5f0179Smacallan * @nodeoffset: offset of the node to find the address range size for 10747b5f0179Smacallan * 10757b5f0179Smacallan * When the node has a valid #size-cells property, returns its value. 10767b5f0179Smacallan * 10777b5f0179Smacallan * returns: 10787b5f0179Smacallan * 0 <= n < FDT_MAX_NCELLS, on success 10797b5f0179Smacallan * 2, if the node has no #address-cells property 1080*2fb928dbSskrll * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid 1081*2fb928dbSskrll * #size-cells property 10827b5f0179Smacallan * -FDT_ERR_BADMAGIC, 10837b5f0179Smacallan * -FDT_ERR_BADVERSION, 10847b5f0179Smacallan * -FDT_ERR_BADSTATE, 10857b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 10867b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 10877b5f0179Smacallan */ 10887b5f0179Smacallan int fdt_size_cells(const void *fdt, int nodeoffset); 10897b5f0179Smacallan 10907b5f0179Smacallan 10917b5f0179Smacallan /**********************************************************************/ 10927b5f0179Smacallan /* Write-in-place functions */ 10937b5f0179Smacallan /**********************************************************************/ 10947b5f0179Smacallan 10957b5f0179Smacallan /** 1096*2fb928dbSskrll * fdt_setprop_inplace_namelen_partial - change a property's value, 1097*2fb928dbSskrll * but not its size 1098*2fb928dbSskrll * @fdt: pointer to the device tree blob 1099*2fb928dbSskrll * @nodeoffset: offset of the node whose property to change 1100*2fb928dbSskrll * @name: name of the property to change 1101*2fb928dbSskrll * @namelen: number of characters of name to consider 1102*2fb928dbSskrll * @idx: index of the property to change in the array 1103*2fb928dbSskrll * @val: pointer to data to replace the property value with 1104*2fb928dbSskrll * @len: length of the property value 1105*2fb928dbSskrll * 1106*2fb928dbSskrll * Identical to fdt_setprop_inplace(), but modifies the given property 1107*2fb928dbSskrll * starting from the given index, and using only the first characters 1108*2fb928dbSskrll * of the name. It is useful when you want to manipulate only one value of 1109*2fb928dbSskrll * an array and you have a string that doesn't end with \0. 1110*2fb928dbSskrll */ 1111*2fb928dbSskrll int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, 1112*2fb928dbSskrll const char *name, int namelen, 1113*2fb928dbSskrll uint32_t idx, const void *val, 1114*2fb928dbSskrll int len); 1115*2fb928dbSskrll 1116*2fb928dbSskrll /** 11177b5f0179Smacallan * fdt_setprop_inplace - change a property's value, but not its size 11187b5f0179Smacallan * @fdt: pointer to the device tree blob 11197b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 11207b5f0179Smacallan * @name: name of the property to change 11217b5f0179Smacallan * @val: pointer to data to replace the property value with 11227b5f0179Smacallan * @len: length of the property value 11237b5f0179Smacallan * 11247b5f0179Smacallan * fdt_setprop_inplace() replaces the value of a given property with 11257b5f0179Smacallan * the data in val, of length len. This function cannot change the 11267b5f0179Smacallan * size of a property, and so will only work if len is equal to the 11277b5f0179Smacallan * current length of the property. 11287b5f0179Smacallan * 11297b5f0179Smacallan * This function will alter only the bytes in the blob which contain 11307b5f0179Smacallan * the given property value, and will not alter or move any other part 11317b5f0179Smacallan * of the tree. 11327b5f0179Smacallan * 11337b5f0179Smacallan * returns: 11347b5f0179Smacallan * 0, on success 11357b5f0179Smacallan * -FDT_ERR_NOSPACE, if len is not equal to the property's current length 11367b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property 11377b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 11387b5f0179Smacallan * -FDT_ERR_BADMAGIC, 11397b5f0179Smacallan * -FDT_ERR_BADVERSION, 11407b5f0179Smacallan * -FDT_ERR_BADSTATE, 11417b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 11427b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 11437b5f0179Smacallan */ 11447b5f0179Smacallan int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, 11457b5f0179Smacallan const void *val, int len); 11467b5f0179Smacallan 11477b5f0179Smacallan /** 11487b5f0179Smacallan * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property 11497b5f0179Smacallan * @fdt: pointer to the device tree blob 11507b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 11517b5f0179Smacallan * @name: name of the property to change 11527b5f0179Smacallan * @val: 32-bit integer value to replace the property with 11537b5f0179Smacallan * 11547b5f0179Smacallan * fdt_setprop_inplace_u32() replaces the value of a given property 11557b5f0179Smacallan * with the 32-bit integer value in val, converting val to big-endian 11567b5f0179Smacallan * if necessary. This function cannot change the size of a property, 11577b5f0179Smacallan * and so will only work if the property already exists and has length 11587b5f0179Smacallan * 4. 11597b5f0179Smacallan * 11607b5f0179Smacallan * This function will alter only the bytes in the blob which contain 11617b5f0179Smacallan * the given property value, and will not alter or move any other part 11627b5f0179Smacallan * of the tree. 11637b5f0179Smacallan * 11647b5f0179Smacallan * returns: 11657b5f0179Smacallan * 0, on success 11667b5f0179Smacallan * -FDT_ERR_NOSPACE, if the property's length is not equal to 4 11677b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property 11687b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 11697b5f0179Smacallan * -FDT_ERR_BADMAGIC, 11707b5f0179Smacallan * -FDT_ERR_BADVERSION, 11717b5f0179Smacallan * -FDT_ERR_BADSTATE, 11727b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 11737b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 11747b5f0179Smacallan */ 11757b5f0179Smacallan static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset, 11767b5f0179Smacallan const char *name, uint32_t val) 11777b5f0179Smacallan { 11787b5f0179Smacallan fdt32_t tmp = cpu_to_fdt32(val); 11797b5f0179Smacallan return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 11807b5f0179Smacallan } 11817b5f0179Smacallan 11827b5f0179Smacallan /** 11837b5f0179Smacallan * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property 11847b5f0179Smacallan * @fdt: pointer to the device tree blob 11857b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 11867b5f0179Smacallan * @name: name of the property to change 11877b5f0179Smacallan * @val: 64-bit integer value to replace the property with 11887b5f0179Smacallan * 11897b5f0179Smacallan * fdt_setprop_inplace_u64() replaces the value of a given property 11907b5f0179Smacallan * with the 64-bit integer value in val, converting val to big-endian 11917b5f0179Smacallan * if necessary. This function cannot change the size of a property, 11927b5f0179Smacallan * and so will only work if the property already exists and has length 11937b5f0179Smacallan * 8. 11947b5f0179Smacallan * 11957b5f0179Smacallan * This function will alter only the bytes in the blob which contain 11967b5f0179Smacallan * the given property value, and will not alter or move any other part 11977b5f0179Smacallan * of the tree. 11987b5f0179Smacallan * 11997b5f0179Smacallan * returns: 12007b5f0179Smacallan * 0, on success 12017b5f0179Smacallan * -FDT_ERR_NOSPACE, if the property's length is not equal to 8 12027b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property 12037b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 12047b5f0179Smacallan * -FDT_ERR_BADMAGIC, 12057b5f0179Smacallan * -FDT_ERR_BADVERSION, 12067b5f0179Smacallan * -FDT_ERR_BADSTATE, 12077b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 12087b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 12097b5f0179Smacallan */ 12107b5f0179Smacallan static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset, 12117b5f0179Smacallan const char *name, uint64_t val) 12127b5f0179Smacallan { 12137b5f0179Smacallan fdt64_t tmp = cpu_to_fdt64(val); 12147b5f0179Smacallan return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 12157b5f0179Smacallan } 12167b5f0179Smacallan 12177b5f0179Smacallan /** 12187b5f0179Smacallan * fdt_setprop_inplace_cell - change the value of a single-cell property 12197b5f0179Smacallan * 12207b5f0179Smacallan * This is an alternative name for fdt_setprop_inplace_u32() 12217b5f0179Smacallan */ 12227b5f0179Smacallan static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset, 12237b5f0179Smacallan const char *name, uint32_t val) 12247b5f0179Smacallan { 12257b5f0179Smacallan return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val); 12267b5f0179Smacallan } 12277b5f0179Smacallan 12287b5f0179Smacallan /** 12297b5f0179Smacallan * fdt_nop_property - replace a property with nop tags 12307b5f0179Smacallan * @fdt: pointer to the device tree blob 12317b5f0179Smacallan * @nodeoffset: offset of the node whose property to nop 12327b5f0179Smacallan * @name: name of the property to nop 12337b5f0179Smacallan * 12347b5f0179Smacallan * fdt_nop_property() will replace a given property's representation 12357b5f0179Smacallan * in the blob with FDT_NOP tags, effectively removing it from the 12367b5f0179Smacallan * tree. 12377b5f0179Smacallan * 12387b5f0179Smacallan * This function will alter only the bytes in the blob which contain 12397b5f0179Smacallan * the property, and will not alter or move any other part of the 12407b5f0179Smacallan * tree. 12417b5f0179Smacallan * 12427b5f0179Smacallan * returns: 12437b5f0179Smacallan * 0, on success 12447b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property 12457b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 12467b5f0179Smacallan * -FDT_ERR_BADMAGIC, 12477b5f0179Smacallan * -FDT_ERR_BADVERSION, 12487b5f0179Smacallan * -FDT_ERR_BADSTATE, 12497b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 12507b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 12517b5f0179Smacallan */ 12527b5f0179Smacallan int fdt_nop_property(void *fdt, int nodeoffset, const char *name); 12537b5f0179Smacallan 12547b5f0179Smacallan /** 12557b5f0179Smacallan * fdt_nop_node - replace a node (subtree) with nop tags 12567b5f0179Smacallan * @fdt: pointer to the device tree blob 12577b5f0179Smacallan * @nodeoffset: offset of the node to nop 12587b5f0179Smacallan * 12597b5f0179Smacallan * fdt_nop_node() will replace a given node's representation in the 12607b5f0179Smacallan * blob, including all its subnodes, if any, with FDT_NOP tags, 12617b5f0179Smacallan * effectively removing it from the tree. 12627b5f0179Smacallan * 12637b5f0179Smacallan * This function will alter only the bytes in the blob which contain 12647b5f0179Smacallan * the node and its properties and subnodes, and will not alter or 12657b5f0179Smacallan * move any other part of the tree. 12667b5f0179Smacallan * 12677b5f0179Smacallan * returns: 12687b5f0179Smacallan * 0, on success 12697b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 12707b5f0179Smacallan * -FDT_ERR_BADMAGIC, 12717b5f0179Smacallan * -FDT_ERR_BADVERSION, 12727b5f0179Smacallan * -FDT_ERR_BADSTATE, 12737b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 12747b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 12757b5f0179Smacallan */ 12767b5f0179Smacallan int fdt_nop_node(void *fdt, int nodeoffset); 12777b5f0179Smacallan 12787b5f0179Smacallan /**********************************************************************/ 12797b5f0179Smacallan /* Sequential write functions */ 12807b5f0179Smacallan /**********************************************************************/ 12817b5f0179Smacallan 12827b5f0179Smacallan int fdt_create(void *buf, int bufsize); 12837b5f0179Smacallan int fdt_resize(void *fdt, void *buf, int bufsize); 12847b5f0179Smacallan int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size); 12857b5f0179Smacallan int fdt_finish_reservemap(void *fdt); 12867b5f0179Smacallan int fdt_begin_node(void *fdt, const char *name); 12877b5f0179Smacallan int fdt_property(void *fdt, const char *name, const void *val, int len); 12887b5f0179Smacallan static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val) 12897b5f0179Smacallan { 12907b5f0179Smacallan fdt32_t tmp = cpu_to_fdt32(val); 12917b5f0179Smacallan return fdt_property(fdt, name, &tmp, sizeof(tmp)); 12927b5f0179Smacallan } 12937b5f0179Smacallan static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val) 12947b5f0179Smacallan { 12957b5f0179Smacallan fdt64_t tmp = cpu_to_fdt64(val); 12967b5f0179Smacallan return fdt_property(fdt, name, &tmp, sizeof(tmp)); 12977b5f0179Smacallan } 12987b5f0179Smacallan static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) 12997b5f0179Smacallan { 13007b5f0179Smacallan return fdt_property_u32(fdt, name, val); 13017b5f0179Smacallan } 13027b5f0179Smacallan #define fdt_property_string(fdt, name, str) \ 13037b5f0179Smacallan fdt_property(fdt, name, str, strlen(str)+1) 13047b5f0179Smacallan int fdt_end_node(void *fdt); 13057b5f0179Smacallan int fdt_finish(void *fdt); 13067b5f0179Smacallan 13077b5f0179Smacallan /**********************************************************************/ 13087b5f0179Smacallan /* Read-write functions */ 13097b5f0179Smacallan /**********************************************************************/ 13107b5f0179Smacallan 13117b5f0179Smacallan int fdt_create_empty_tree(void *buf, int bufsize); 13127b5f0179Smacallan int fdt_open_into(const void *fdt, void *buf, int bufsize); 13137b5f0179Smacallan int fdt_pack(void *fdt); 13147b5f0179Smacallan 13157b5f0179Smacallan /** 13167b5f0179Smacallan * fdt_add_mem_rsv - add one memory reserve map entry 13177b5f0179Smacallan * @fdt: pointer to the device tree blob 13187b5f0179Smacallan * @address, @size: 64-bit values (native endian) 13197b5f0179Smacallan * 13207b5f0179Smacallan * Adds a reserve map entry to the given blob reserving a region at 13217b5f0179Smacallan * address address of length size. 13227b5f0179Smacallan * 13237b5f0179Smacallan * This function will insert data into the reserve map and will 13247b5f0179Smacallan * therefore change the indexes of some entries in the table. 13257b5f0179Smacallan * 13267b5f0179Smacallan * returns: 13277b5f0179Smacallan * 0, on success 13287b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 13297b5f0179Smacallan * contain the new reservation entry 13307b5f0179Smacallan * -FDT_ERR_BADMAGIC, 13317b5f0179Smacallan * -FDT_ERR_BADVERSION, 13327b5f0179Smacallan * -FDT_ERR_BADSTATE, 13337b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 13347b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 13357b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 13367b5f0179Smacallan */ 13377b5f0179Smacallan int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size); 13387b5f0179Smacallan 13397b5f0179Smacallan /** 13407b5f0179Smacallan * fdt_del_mem_rsv - remove a memory reserve map entry 13417b5f0179Smacallan * @fdt: pointer to the device tree blob 13427b5f0179Smacallan * @n: entry to remove 13437b5f0179Smacallan * 13447b5f0179Smacallan * fdt_del_mem_rsv() removes the n-th memory reserve map entry from 13457b5f0179Smacallan * the blob. 13467b5f0179Smacallan * 13477b5f0179Smacallan * This function will delete data from the reservation table and will 13487b5f0179Smacallan * therefore change the indexes of some entries in the table. 13497b5f0179Smacallan * 13507b5f0179Smacallan * returns: 13517b5f0179Smacallan * 0, on success 13527b5f0179Smacallan * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there 13537b5f0179Smacallan * are less than n+1 reserve map entries) 13547b5f0179Smacallan * -FDT_ERR_BADMAGIC, 13557b5f0179Smacallan * -FDT_ERR_BADVERSION, 13567b5f0179Smacallan * -FDT_ERR_BADSTATE, 13577b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 13587b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 13597b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 13607b5f0179Smacallan */ 13617b5f0179Smacallan int fdt_del_mem_rsv(void *fdt, int n); 13627b5f0179Smacallan 13637b5f0179Smacallan /** 13647b5f0179Smacallan * fdt_set_name - change the name of a given node 13657b5f0179Smacallan * @fdt: pointer to the device tree blob 13667b5f0179Smacallan * @nodeoffset: structure block offset of a node 13677b5f0179Smacallan * @name: name to give the node 13687b5f0179Smacallan * 13697b5f0179Smacallan * fdt_set_name() replaces the name (including unit address, if any) 13707b5f0179Smacallan * of the given node with the given string. NOTE: this function can't 13717b5f0179Smacallan * efficiently check if the new name is unique amongst the given 13727b5f0179Smacallan * node's siblings; results are undefined if this function is invoked 13737b5f0179Smacallan * with a name equal to one of the given node's siblings. 13747b5f0179Smacallan * 13757b5f0179Smacallan * This function may insert or delete data from the blob, and will 13767b5f0179Smacallan * therefore change the offsets of some existing nodes. 13777b5f0179Smacallan * 13787b5f0179Smacallan * returns: 13797b5f0179Smacallan * 0, on success 13807b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob 13817b5f0179Smacallan * to contain the new name 13827b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 13837b5f0179Smacallan * -FDT_ERR_BADMAGIC, 13847b5f0179Smacallan * -FDT_ERR_BADVERSION, 13857b5f0179Smacallan * -FDT_ERR_BADSTATE, standard meanings 13867b5f0179Smacallan */ 13877b5f0179Smacallan int fdt_set_name(void *fdt, int nodeoffset, const char *name); 13887b5f0179Smacallan 13897b5f0179Smacallan /** 13907b5f0179Smacallan * fdt_setprop - create or change a property 13917b5f0179Smacallan * @fdt: pointer to the device tree blob 13927b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 13937b5f0179Smacallan * @name: name of the property to change 13947b5f0179Smacallan * @val: pointer to data to set the property value to 13957b5f0179Smacallan * @len: length of the property value 13967b5f0179Smacallan * 13977b5f0179Smacallan * fdt_setprop() sets the value of the named property in the given 13987b5f0179Smacallan * node to the given value and length, creating the property if it 13997b5f0179Smacallan * does not already exist. 14007b5f0179Smacallan * 14017b5f0179Smacallan * This function may insert or delete data from the blob, and will 14027b5f0179Smacallan * therefore change the offsets of some existing nodes. 14037b5f0179Smacallan * 14047b5f0179Smacallan * returns: 14057b5f0179Smacallan * 0, on success 14067b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 14077b5f0179Smacallan * contain the new property value 14087b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 14097b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 14107b5f0179Smacallan * -FDT_ERR_BADMAGIC, 14117b5f0179Smacallan * -FDT_ERR_BADVERSION, 14127b5f0179Smacallan * -FDT_ERR_BADSTATE, 14137b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 14147b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 14157b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 14167b5f0179Smacallan */ 14177b5f0179Smacallan int fdt_setprop(void *fdt, int nodeoffset, const char *name, 14187b5f0179Smacallan const void *val, int len); 14197b5f0179Smacallan 14207b5f0179Smacallan /** 14217b5f0179Smacallan * fdt_setprop_u32 - set a property to a 32-bit integer 14227b5f0179Smacallan * @fdt: pointer to the device tree blob 14237b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 14247b5f0179Smacallan * @name: name of the property to change 14257b5f0179Smacallan * @val: 32-bit integer value for the property (native endian) 14267b5f0179Smacallan * 14277b5f0179Smacallan * fdt_setprop_u32() sets the value of the named property in the given 14287b5f0179Smacallan * node to the given 32-bit integer value (converting to big-endian if 14297b5f0179Smacallan * necessary), or creates a new property with that value if it does 14307b5f0179Smacallan * not already exist. 14317b5f0179Smacallan * 14327b5f0179Smacallan * This function may insert or delete data from the blob, and will 14337b5f0179Smacallan * therefore change the offsets of some existing nodes. 14347b5f0179Smacallan * 14357b5f0179Smacallan * returns: 14367b5f0179Smacallan * 0, on success 14377b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 14387b5f0179Smacallan * contain the new property value 14397b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 14407b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 14417b5f0179Smacallan * -FDT_ERR_BADMAGIC, 14427b5f0179Smacallan * -FDT_ERR_BADVERSION, 14437b5f0179Smacallan * -FDT_ERR_BADSTATE, 14447b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 14457b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 14467b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 14477b5f0179Smacallan */ 14487b5f0179Smacallan static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name, 14497b5f0179Smacallan uint32_t val) 14507b5f0179Smacallan { 14517b5f0179Smacallan fdt32_t tmp = cpu_to_fdt32(val); 14527b5f0179Smacallan return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 14537b5f0179Smacallan } 14547b5f0179Smacallan 14557b5f0179Smacallan /** 14567b5f0179Smacallan * fdt_setprop_u64 - set a property to a 64-bit integer 14577b5f0179Smacallan * @fdt: pointer to the device tree blob 14587b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 14597b5f0179Smacallan * @name: name of the property to change 14607b5f0179Smacallan * @val: 64-bit integer value for the property (native endian) 14617b5f0179Smacallan * 14627b5f0179Smacallan * fdt_setprop_u64() sets the value of the named property in the given 14637b5f0179Smacallan * node to the given 64-bit integer value (converting to big-endian if 14647b5f0179Smacallan * necessary), or creates a new property with that value if it does 14657b5f0179Smacallan * not already exist. 14667b5f0179Smacallan * 14677b5f0179Smacallan * This function may insert or delete data from the blob, and will 14687b5f0179Smacallan * therefore change the offsets of some existing nodes. 14697b5f0179Smacallan * 14707b5f0179Smacallan * returns: 14717b5f0179Smacallan * 0, on success 14727b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 14737b5f0179Smacallan * contain the new property value 14747b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 14757b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 14767b5f0179Smacallan * -FDT_ERR_BADMAGIC, 14777b5f0179Smacallan * -FDT_ERR_BADVERSION, 14787b5f0179Smacallan * -FDT_ERR_BADSTATE, 14797b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 14807b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 14817b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 14827b5f0179Smacallan */ 14837b5f0179Smacallan static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name, 14847b5f0179Smacallan uint64_t val) 14857b5f0179Smacallan { 14867b5f0179Smacallan fdt64_t tmp = cpu_to_fdt64(val); 14877b5f0179Smacallan return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 14887b5f0179Smacallan } 14897b5f0179Smacallan 14907b5f0179Smacallan /** 14917b5f0179Smacallan * fdt_setprop_cell - set a property to a single cell value 14927b5f0179Smacallan * 14937b5f0179Smacallan * This is an alternative name for fdt_setprop_u32() 14947b5f0179Smacallan */ 14957b5f0179Smacallan static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name, 14967b5f0179Smacallan uint32_t val) 14977b5f0179Smacallan { 14987b5f0179Smacallan return fdt_setprop_u32(fdt, nodeoffset, name, val); 14997b5f0179Smacallan } 15007b5f0179Smacallan 15017b5f0179Smacallan /** 15027b5f0179Smacallan * fdt_setprop_string - set a property to a string value 15037b5f0179Smacallan * @fdt: pointer to the device tree blob 15047b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 15057b5f0179Smacallan * @name: name of the property to change 15067b5f0179Smacallan * @str: string value for the property 15077b5f0179Smacallan * 15087b5f0179Smacallan * fdt_setprop_string() sets the value of the named property in the 15097b5f0179Smacallan * given node to the given string value (using the length of the 15107b5f0179Smacallan * string to determine the new length of the property), or creates a 15117b5f0179Smacallan * new property with that value if it does not already exist. 15127b5f0179Smacallan * 15137b5f0179Smacallan * This function may insert or delete data from the blob, and will 15147b5f0179Smacallan * therefore change the offsets of some existing nodes. 15157b5f0179Smacallan * 15167b5f0179Smacallan * returns: 15177b5f0179Smacallan * 0, on success 15187b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 15197b5f0179Smacallan * contain the new property value 15207b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 15217b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 15227b5f0179Smacallan * -FDT_ERR_BADMAGIC, 15237b5f0179Smacallan * -FDT_ERR_BADVERSION, 15247b5f0179Smacallan * -FDT_ERR_BADSTATE, 15257b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 15267b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 15277b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 15287b5f0179Smacallan */ 15297b5f0179Smacallan #define fdt_setprop_string(fdt, nodeoffset, name, str) \ 15307b5f0179Smacallan fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) 15317b5f0179Smacallan 1532*2fb928dbSskrll 1533*2fb928dbSskrll /** 1534*2fb928dbSskrll * fdt_setprop_empty - set a property to an empty value 1535*2fb928dbSskrll * @fdt: pointer to the device tree blob 1536*2fb928dbSskrll * @nodeoffset: offset of the node whose property to change 1537*2fb928dbSskrll * @name: name of the property to change 1538*2fb928dbSskrll * 1539*2fb928dbSskrll * fdt_setprop_empty() sets the value of the named property in the 1540*2fb928dbSskrll * given node to an empty (zero length) value, or creates a new empty 1541*2fb928dbSskrll * property if it does not already exist. 1542*2fb928dbSskrll * 1543*2fb928dbSskrll * This function may insert or delete data from the blob, and will 1544*2fb928dbSskrll * therefore change the offsets of some existing nodes. 1545*2fb928dbSskrll * 1546*2fb928dbSskrll * returns: 1547*2fb928dbSskrll * 0, on success 1548*2fb928dbSskrll * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 1549*2fb928dbSskrll * contain the new property value 1550*2fb928dbSskrll * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 1551*2fb928dbSskrll * -FDT_ERR_BADLAYOUT, 1552*2fb928dbSskrll * -FDT_ERR_BADMAGIC, 1553*2fb928dbSskrll * -FDT_ERR_BADVERSION, 1554*2fb928dbSskrll * -FDT_ERR_BADSTATE, 1555*2fb928dbSskrll * -FDT_ERR_BADSTRUCTURE, 1556*2fb928dbSskrll * -FDT_ERR_BADLAYOUT, 1557*2fb928dbSskrll * -FDT_ERR_TRUNCATED, standard meanings 1558*2fb928dbSskrll */ 1559*2fb928dbSskrll #define fdt_setprop_empty(fdt, nodeoffset, name) \ 1560*2fb928dbSskrll fdt_setprop((fdt), (nodeoffset), (name), NULL, 0) 1561*2fb928dbSskrll 15627b5f0179Smacallan /** 15637b5f0179Smacallan * fdt_appendprop - append to or create a property 15647b5f0179Smacallan * @fdt: pointer to the device tree blob 15657b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 15667b5f0179Smacallan * @name: name of the property to append to 15677b5f0179Smacallan * @val: pointer to data to append to the property value 15687b5f0179Smacallan * @len: length of the data to append to the property value 15697b5f0179Smacallan * 15707b5f0179Smacallan * fdt_appendprop() appends the value to the named property in the 15717b5f0179Smacallan * given node, creating the property if it does not already exist. 15727b5f0179Smacallan * 15737b5f0179Smacallan * This function may insert data into the blob, and will therefore 15747b5f0179Smacallan * change the offsets of some existing nodes. 15757b5f0179Smacallan * 15767b5f0179Smacallan * returns: 15777b5f0179Smacallan * 0, on success 15787b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 15797b5f0179Smacallan * contain the new property value 15807b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 15817b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 15827b5f0179Smacallan * -FDT_ERR_BADMAGIC, 15837b5f0179Smacallan * -FDT_ERR_BADVERSION, 15847b5f0179Smacallan * -FDT_ERR_BADSTATE, 15857b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 15867b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 15877b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 15887b5f0179Smacallan */ 15897b5f0179Smacallan int fdt_appendprop(void *fdt, int nodeoffset, const char *name, 15907b5f0179Smacallan const void *val, int len); 15917b5f0179Smacallan 15927b5f0179Smacallan /** 15937b5f0179Smacallan * fdt_appendprop_u32 - append a 32-bit integer value to a property 15947b5f0179Smacallan * @fdt: pointer to the device tree blob 15957b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 15967b5f0179Smacallan * @name: name of the property to change 15977b5f0179Smacallan * @val: 32-bit integer value to append to the property (native endian) 15987b5f0179Smacallan * 15997b5f0179Smacallan * fdt_appendprop_u32() appends the given 32-bit integer value 16007b5f0179Smacallan * (converting to big-endian if necessary) to the value of the named 16017b5f0179Smacallan * property in the given node, or creates a new property with that 16027b5f0179Smacallan * value if it does not already exist. 16037b5f0179Smacallan * 16047b5f0179Smacallan * This function may insert data into the blob, and will therefore 16057b5f0179Smacallan * change the offsets of some existing nodes. 16067b5f0179Smacallan * 16077b5f0179Smacallan * returns: 16087b5f0179Smacallan * 0, on success 16097b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 16107b5f0179Smacallan * contain the new property value 16117b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 16127b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 16137b5f0179Smacallan * -FDT_ERR_BADMAGIC, 16147b5f0179Smacallan * -FDT_ERR_BADVERSION, 16157b5f0179Smacallan * -FDT_ERR_BADSTATE, 16167b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 16177b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 16187b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 16197b5f0179Smacallan */ 16207b5f0179Smacallan static inline int fdt_appendprop_u32(void *fdt, int nodeoffset, 16217b5f0179Smacallan const char *name, uint32_t val) 16227b5f0179Smacallan { 16237b5f0179Smacallan fdt32_t tmp = cpu_to_fdt32(val); 16247b5f0179Smacallan return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 16257b5f0179Smacallan } 16267b5f0179Smacallan 16277b5f0179Smacallan /** 16287b5f0179Smacallan * fdt_appendprop_u64 - append a 64-bit integer value to a property 16297b5f0179Smacallan * @fdt: pointer to the device tree blob 16307b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 16317b5f0179Smacallan * @name: name of the property to change 16327b5f0179Smacallan * @val: 64-bit integer value to append to the property (native endian) 16337b5f0179Smacallan * 16347b5f0179Smacallan * fdt_appendprop_u64() appends the given 64-bit integer value 16357b5f0179Smacallan * (converting to big-endian if necessary) to the value of the named 16367b5f0179Smacallan * property in the given node, or creates a new property with that 16377b5f0179Smacallan * value if it does not already exist. 16387b5f0179Smacallan * 16397b5f0179Smacallan * This function may insert data into the blob, and will therefore 16407b5f0179Smacallan * change the offsets of some existing nodes. 16417b5f0179Smacallan * 16427b5f0179Smacallan * returns: 16437b5f0179Smacallan * 0, on success 16447b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 16457b5f0179Smacallan * contain the new property value 16467b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 16477b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 16487b5f0179Smacallan * -FDT_ERR_BADMAGIC, 16497b5f0179Smacallan * -FDT_ERR_BADVERSION, 16507b5f0179Smacallan * -FDT_ERR_BADSTATE, 16517b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 16527b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 16537b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 16547b5f0179Smacallan */ 16557b5f0179Smacallan static inline int fdt_appendprop_u64(void *fdt, int nodeoffset, 16567b5f0179Smacallan const char *name, uint64_t val) 16577b5f0179Smacallan { 16587b5f0179Smacallan fdt64_t tmp = cpu_to_fdt64(val); 16597b5f0179Smacallan return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 16607b5f0179Smacallan } 16617b5f0179Smacallan 16627b5f0179Smacallan /** 16637b5f0179Smacallan * fdt_appendprop_cell - append a single cell value to a property 16647b5f0179Smacallan * 16657b5f0179Smacallan * This is an alternative name for fdt_appendprop_u32() 16667b5f0179Smacallan */ 16677b5f0179Smacallan static inline int fdt_appendprop_cell(void *fdt, int nodeoffset, 16687b5f0179Smacallan const char *name, uint32_t val) 16697b5f0179Smacallan { 16707b5f0179Smacallan return fdt_appendprop_u32(fdt, nodeoffset, name, val); 16717b5f0179Smacallan } 16727b5f0179Smacallan 16737b5f0179Smacallan /** 16747b5f0179Smacallan * fdt_appendprop_string - append a string to a property 16757b5f0179Smacallan * @fdt: pointer to the device tree blob 16767b5f0179Smacallan * @nodeoffset: offset of the node whose property to change 16777b5f0179Smacallan * @name: name of the property to change 16787b5f0179Smacallan * @str: string value to append to the property 16797b5f0179Smacallan * 16807b5f0179Smacallan * fdt_appendprop_string() appends the given string to the value of 16817b5f0179Smacallan * the named property in the given node, or creates a new property 16827b5f0179Smacallan * with that value if it does not already exist. 16837b5f0179Smacallan * 16847b5f0179Smacallan * This function may insert data into the blob, and will therefore 16857b5f0179Smacallan * change the offsets of some existing nodes. 16867b5f0179Smacallan * 16877b5f0179Smacallan * returns: 16887b5f0179Smacallan * 0, on success 16897b5f0179Smacallan * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 16907b5f0179Smacallan * contain the new property value 16917b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 16927b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 16937b5f0179Smacallan * -FDT_ERR_BADMAGIC, 16947b5f0179Smacallan * -FDT_ERR_BADVERSION, 16957b5f0179Smacallan * -FDT_ERR_BADSTATE, 16967b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 16977b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 16987b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 16997b5f0179Smacallan */ 17007b5f0179Smacallan #define fdt_appendprop_string(fdt, nodeoffset, name, str) \ 17017b5f0179Smacallan fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) 17027b5f0179Smacallan 17037b5f0179Smacallan /** 17047b5f0179Smacallan * fdt_delprop - delete a property 17057b5f0179Smacallan * @fdt: pointer to the device tree blob 17067b5f0179Smacallan * @nodeoffset: offset of the node whose property to nop 17077b5f0179Smacallan * @name: name of the property to nop 17087b5f0179Smacallan * 17097b5f0179Smacallan * fdt_del_property() will delete the given property. 17107b5f0179Smacallan * 17117b5f0179Smacallan * This function will delete data from the blob, and will therefore 17127b5f0179Smacallan * change the offsets of some existing nodes. 17137b5f0179Smacallan * 17147b5f0179Smacallan * returns: 17157b5f0179Smacallan * 0, on success 17167b5f0179Smacallan * -FDT_ERR_NOTFOUND, node does not have the named property 17177b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 17187b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 17197b5f0179Smacallan * -FDT_ERR_BADMAGIC, 17207b5f0179Smacallan * -FDT_ERR_BADVERSION, 17217b5f0179Smacallan * -FDT_ERR_BADSTATE, 17227b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 17237b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 17247b5f0179Smacallan */ 17257b5f0179Smacallan int fdt_delprop(void *fdt, int nodeoffset, const char *name); 17267b5f0179Smacallan 17277b5f0179Smacallan /** 17287b5f0179Smacallan * fdt_add_subnode_namelen - creates a new node based on substring 17297b5f0179Smacallan * @fdt: pointer to the device tree blob 17307b5f0179Smacallan * @parentoffset: structure block offset of a node 17317b5f0179Smacallan * @name: name of the subnode to locate 17327b5f0179Smacallan * @namelen: number of characters of name to consider 17337b5f0179Smacallan * 17347b5f0179Smacallan * Identical to fdt_add_subnode(), but use only the first namelen 17357b5f0179Smacallan * characters of name as the name of the new node. This is useful for 17367b5f0179Smacallan * creating subnodes based on a portion of a larger string, such as a 17377b5f0179Smacallan * full path. 17387b5f0179Smacallan */ 17397b5f0179Smacallan int fdt_add_subnode_namelen(void *fdt, int parentoffset, 17407b5f0179Smacallan const char *name, int namelen); 17417b5f0179Smacallan 17427b5f0179Smacallan /** 17437b5f0179Smacallan * fdt_add_subnode - creates a new node 17447b5f0179Smacallan * @fdt: pointer to the device tree blob 17457b5f0179Smacallan * @parentoffset: structure block offset of a node 17467b5f0179Smacallan * @name: name of the subnode to locate 17477b5f0179Smacallan * 17487b5f0179Smacallan * fdt_add_subnode() creates a new node as a subnode of the node at 17497b5f0179Smacallan * structure block offset parentoffset, with the given name (which 17507b5f0179Smacallan * should include the unit address, if any). 17517b5f0179Smacallan * 17527b5f0179Smacallan * This function will insert data into the blob, and will therefore 17537b5f0179Smacallan * change the offsets of some existing nodes. 17547b5f0179Smacallan 17557b5f0179Smacallan * returns: 1756*2fb928dbSskrll * structure block offset of the created nodeequested subnode (>=0), on 1757*2fb928dbSskrll * success 17587b5f0179Smacallan * -FDT_ERR_NOTFOUND, if the requested subnode does not exist 1759*2fb928dbSskrll * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE 1760*2fb928dbSskrll * tag 17617b5f0179Smacallan * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of 17627b5f0179Smacallan * the given name 17637b5f0179Smacallan * -FDT_ERR_NOSPACE, if there is insufficient free space in the 17647b5f0179Smacallan * blob to contain the new node 17657b5f0179Smacallan * -FDT_ERR_NOSPACE 17667b5f0179Smacallan * -FDT_ERR_BADLAYOUT 17677b5f0179Smacallan * -FDT_ERR_BADMAGIC, 17687b5f0179Smacallan * -FDT_ERR_BADVERSION, 17697b5f0179Smacallan * -FDT_ERR_BADSTATE, 17707b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 17717b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings. 17727b5f0179Smacallan */ 17737b5f0179Smacallan int fdt_add_subnode(void *fdt, int parentoffset, const char *name); 17747b5f0179Smacallan 17757b5f0179Smacallan /** 17767b5f0179Smacallan * fdt_del_node - delete a node (subtree) 17777b5f0179Smacallan * @fdt: pointer to the device tree blob 17787b5f0179Smacallan * @nodeoffset: offset of the node to nop 17797b5f0179Smacallan * 17807b5f0179Smacallan * fdt_del_node() will remove the given node, including all its 17817b5f0179Smacallan * subnodes if any, from the blob. 17827b5f0179Smacallan * 17837b5f0179Smacallan * This function will delete data from the blob, and will therefore 17847b5f0179Smacallan * change the offsets of some existing nodes. 17857b5f0179Smacallan * 17867b5f0179Smacallan * returns: 17877b5f0179Smacallan * 0, on success 17887b5f0179Smacallan * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 17897b5f0179Smacallan * -FDT_ERR_BADLAYOUT, 17907b5f0179Smacallan * -FDT_ERR_BADMAGIC, 17917b5f0179Smacallan * -FDT_ERR_BADVERSION, 17927b5f0179Smacallan * -FDT_ERR_BADSTATE, 17937b5f0179Smacallan * -FDT_ERR_BADSTRUCTURE, 17947b5f0179Smacallan * -FDT_ERR_TRUNCATED, standard meanings 17957b5f0179Smacallan */ 17967b5f0179Smacallan int fdt_del_node(void *fdt, int nodeoffset); 17977b5f0179Smacallan 1798*2fb928dbSskrll /** 1799*2fb928dbSskrll * fdt_overlay_apply - Applies a DT overlay on a base DT 1800*2fb928dbSskrll * @fdt: pointer to the base device tree blob 1801*2fb928dbSskrll * @fdto: pointer to the device tree overlay blob 1802*2fb928dbSskrll * 1803*2fb928dbSskrll * fdt_overlay_apply() will apply the given device tree overlay on the 1804*2fb928dbSskrll * given base device tree. 1805*2fb928dbSskrll * 1806*2fb928dbSskrll * Expect the base device tree to be modified, even if the function 1807*2fb928dbSskrll * returns an error. 1808*2fb928dbSskrll * 1809*2fb928dbSskrll * returns: 1810*2fb928dbSskrll * 0, on success 1811*2fb928dbSskrll * -FDT_ERR_NOSPACE, there's not enough space in the base device tree 1812*2fb928dbSskrll * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or 1813*2fb928dbSskrll * properties in the base DT 1814*2fb928dbSskrll * -FDT_ERR_BADPHANDLE, 1815*2fb928dbSskrll * -FDT_ERR_BADOVERLAY, 1816*2fb928dbSskrll * -FDT_ERR_NOPHANDLES, 1817*2fb928dbSskrll * -FDT_ERR_INTERNAL, 1818*2fb928dbSskrll * -FDT_ERR_BADLAYOUT, 1819*2fb928dbSskrll * -FDT_ERR_BADMAGIC, 1820*2fb928dbSskrll * -FDT_ERR_BADOFFSET, 1821*2fb928dbSskrll * -FDT_ERR_BADPATH, 1822*2fb928dbSskrll * -FDT_ERR_BADVERSION, 1823*2fb928dbSskrll * -FDT_ERR_BADSTRUCTURE, 1824*2fb928dbSskrll * -FDT_ERR_BADSTATE, 1825*2fb928dbSskrll * -FDT_ERR_TRUNCATED, standard meanings 1826*2fb928dbSskrll */ 1827*2fb928dbSskrll int fdt_overlay_apply(void *fdt, void *fdto); 1828*2fb928dbSskrll 18297b5f0179Smacallan /**********************************************************************/ 18307b5f0179Smacallan /* Debugging / informational functions */ 18317b5f0179Smacallan /**********************************************************************/ 18327b5f0179Smacallan 18337b5f0179Smacallan const char *fdt_strerror(int errval); 18347b5f0179Smacallan 18357b5f0179Smacallan #endif /* _LIBFDT_H */ 1836