Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1 | #ifndef _LIBFDT_H |
| 2 | #define _LIBFDT_H |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 3 | /* |
| 4 | * libfdt - Flat Device Tree manipulation |
| 5 | * Copyright (C) 2006 David Gibson, IBM Corporation. |
| 6 | * |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 7 | * libfdt is dual licensed: you can use it either under the terms of |
| 8 | * the GPL, or the BSD license, at your option. |
| 9 | * |
| 10 | * a) This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of the |
| 13 | * License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 19 | * |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 20 | * You should have received a copy of the GNU General Public |
| 21 | * License along with this library; if not, write to the Free |
| 22 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 23 | * MA 02110-1301 USA |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 24 | * |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 25 | * Alternatively, |
| 26 | * |
| 27 | * b) Redistribution and use in source and binary forms, with or |
| 28 | * without modification, are permitted provided that the following |
| 29 | * conditions are met: |
| 30 | * |
| 31 | * 1. Redistributions of source code must retain the above |
| 32 | * copyright notice, this list of conditions and the following |
| 33 | * disclaimer. |
| 34 | * 2. Redistributions in binary form must reproduce the above |
| 35 | * copyright notice, this list of conditions and the following |
| 36 | * disclaimer in the documentation and/or other materials |
| 37 | * provided with the distribution. |
| 38 | * |
| 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 43 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 44 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 49 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 50 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 51 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 52 | */ |
| 53 | |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 54 | #include <libfdt_env.h> |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 55 | #include <fdt.h> |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 56 | |
| 57 | #define FDT_FIRST_SUPPORTED_VERSION 0x10 |
| 58 | #define FDT_LAST_SUPPORTED_VERSION 0x11 |
| 59 | |
| 60 | /* Error codes: informative error codes */ |
| 61 | #define FDT_ERR_NOTFOUND 1 |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 62 | /* FDT_ERR_NOTFOUND: The requested node or property does not exist */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 63 | #define FDT_ERR_EXISTS 2 |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 64 | /* FDT_ERR_EXISTS: Attemped to create a node or property which |
| 65 | * already exists */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 66 | #define FDT_ERR_NOSPACE 3 |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 67 | /* FDT_ERR_NOSPACE: Operation needed to expand the device |
| 68 | * tree, but its buffer did not have sufficient space to |
| 69 | * contain the expanded tree. Use fdt_open_into() to move the |
| 70 | * device tree to a buffer with more space. */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 71 | |
| 72 | /* Error codes: codes for bad parameters */ |
| 73 | #define FDT_ERR_BADOFFSET 4 |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 74 | /* FDT_ERR_BADOFFSET: Function was passed a structure block |
| 75 | * offset which is out-of-bounds, or which points to an |
| 76 | * unsuitable part of the structure for the operation. */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 77 | #define FDT_ERR_BADPATH 5 |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 78 | /* FDT_ERR_BADPATH: Function was passed a badly formatted path |
| 79 | * (e.g. missing a leading / for a function which requires an |
| 80 | * absolute path) */ |
| 81 | #define FDT_ERR_BADPHANDLE 6 |
| 82 | /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle |
| 83 | * value. phandle values of 0 and -1 are not permitted. */ |
| 84 | #define FDT_ERR_BADSTATE 7 |
| 85 | /* FDT_ERR_BADSTATE: Function was passed an incomplete device |
| 86 | * tree created by the sequential-write functions, which is |
| 87 | * not sufficiently complete for the requested operation. */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 88 | |
| 89 | /* Error codes: codes for bad device tree blobs */ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 90 | #define FDT_ERR_TRUNCATED 8 |
| 91 | /* FDT_ERR_TRUNCATED: Structure block of the given device tree |
| 92 | * ends without an FDT_END tag. */ |
| 93 | #define FDT_ERR_BADMAGIC 9 |
| 94 | /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a |
| 95 | * device tree at all - it is missing the flattened device |
| 96 | * tree magic number. */ |
| 97 | #define FDT_ERR_BADVERSION 10 |
| 98 | /* FDT_ERR_BADVERSION: Given device tree has a version which |
| 99 | * can't be handled by the requested operation. For |
| 100 | * read-write functions, this may mean that fdt_open_into() is |
| 101 | * required to convert the tree to the expected version. */ |
| 102 | #define FDT_ERR_BADSTRUCTURE 11 |
| 103 | /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt |
| 104 | * structure block or other serious error (e.g. misnested |
| 105 | * nodes, or subnodes preceding properties). */ |
| 106 | #define FDT_ERR_BADLAYOUT 12 |
| 107 | /* FDT_ERR_BADLAYOUT: For read-write functions, the given |
| 108 | * device tree has it's sub-blocks in an order that the |
| 109 | * function can't handle (memory reserve map, then structure, |
| 110 | * then strings). Use fdt_open_into() to reorganize the tree |
| 111 | * into a form suitable for the read-write operations. */ |
| 112 | |
| 113 | /* "Can't happen" error indicating a bug in libfdt */ |
| 114 | #define FDT_ERR_INTERNAL 13 |
| 115 | /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion. |
| 116 | * Should never be returned, if it is, it indicates a bug in |
| 117 | * libfdt itself. */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 118 | |
Simon Glass | 536774d | 2014-07-30 03:59:03 -0600 | [diff] [blame] | 119 | /* Errors in device tree content */ |
| 120 | #define FDT_ERR_BADNCELLS 14 |
| 121 | /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells |
| 122 | * or similar property with a bad format or value */ |
| 123 | |
| 124 | #define FDT_ERR_MAX 14 |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 125 | |
| 126 | /**********************************************************************/ |
| 127 | /* Low-level functions (you probably don't need these) */ |
| 128 | /**********************************************************************/ |
| 129 | |
Jon Loeliger | d94d0f1 | 2008-09-25 11:02:17 -0500 | [diff] [blame] | 130 | const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 131 | static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) |
| 132 | { |
David Gibson | 870fa47 | 2008-07-07 10:14:15 +1000 | [diff] [blame] | 133 | return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); |
| 137 | |
| 138 | /**********************************************************************/ |
David Gibson | d9d793c | 2008-02-12 11:58:31 +1100 | [diff] [blame] | 139 | /* Traversal functions */ |
| 140 | /**********************************************************************/ |
| 141 | |
| 142 | int fdt_next_node(const void *fdt, int offset, int *depth); |
| 143 | |
Simon Glass | 3a4de33 | 2013-05-07 06:11:50 +0000 | [diff] [blame] | 144 | /** |
| 145 | * fdt_first_subnode() - get offset of first direct subnode |
| 146 | * |
| 147 | * @fdt: FDT blob |
| 148 | * @offset: Offset of node to check |
| 149 | * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none |
| 150 | */ |
| 151 | int fdt_first_subnode(const void *fdt, int offset); |
| 152 | |
| 153 | /** |
| 154 | * fdt_next_subnode() - get offset of next direct subnode |
| 155 | * |
| 156 | * After first calling fdt_first_subnode(), call this function repeatedly to |
| 157 | * get direct subnodes of a parent node. |
| 158 | * |
| 159 | * @fdt: FDT blob |
| 160 | * @offset: Offset of previous subnode |
| 161 | * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more |
| 162 | * subnodes |
| 163 | */ |
| 164 | int fdt_next_subnode(const void *fdt, int offset); |
| 165 | |
David Gibson | d9d793c | 2008-02-12 11:58:31 +1100 | [diff] [blame] | 166 | /**********************************************************************/ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 167 | /* General functions */ |
| 168 | /**********************************************************************/ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 169 | |
| 170 | #define fdt_get_header(fdt, field) \ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 171 | (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field)) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 172 | #define fdt_magic(fdt) (fdt_get_header(fdt, magic)) |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 173 | #define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) |
| 174 | #define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) |
| 175 | #define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) |
| 176 | #define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) |
| 177 | #define fdt_version(fdt) (fdt_get_header(fdt, version)) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 178 | #define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) |
| 179 | #define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) |
| 180 | #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 181 | #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) |
| 182 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 183 | #define __fdt_set_hdr(name) \ |
| 184 | static inline void fdt_set_##name(void *fdt, uint32_t val) \ |
| 185 | { \ |
Laurent Gregoire | a84542a | 2009-03-03 14:23:59 +0100 | [diff] [blame] | 186 | struct fdt_header *fdth = (struct fdt_header*)fdt; \ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 187 | fdth->name = cpu_to_fdt32(val); \ |
| 188 | } |
| 189 | __fdt_set_hdr(magic); |
| 190 | __fdt_set_hdr(totalsize); |
| 191 | __fdt_set_hdr(off_dt_struct); |
| 192 | __fdt_set_hdr(off_dt_strings); |
| 193 | __fdt_set_hdr(off_mem_rsvmap); |
| 194 | __fdt_set_hdr(version); |
| 195 | __fdt_set_hdr(last_comp_version); |
| 196 | __fdt_set_hdr(boot_cpuid_phys); |
| 197 | __fdt_set_hdr(size_dt_strings); |
| 198 | __fdt_set_hdr(size_dt_struct); |
| 199 | #undef __fdt_set_hdr |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 200 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 201 | /** |
| 202 | * fdt_check_header - sanity check a device tree or possible device tree |
| 203 | * @fdt: pointer to data which might be a flattened device tree |
| 204 | * |
| 205 | * fdt_check_header() checks that the given buffer contains what |
| 206 | * appears to be a flattened device tree with sane information in its |
| 207 | * header. |
| 208 | * |
| 209 | * returns: |
| 210 | * 0, if the buffer appears to contain a valid device tree |
| 211 | * -FDT_ERR_BADMAGIC, |
| 212 | * -FDT_ERR_BADVERSION, |
| 213 | * -FDT_ERR_BADSTATE, standard meanings, as above |
| 214 | */ |
Gerald Van Baren | 9f0f358 | 2007-04-06 14:17:14 -0400 | [diff] [blame] | 215 | int fdt_check_header(const void *fdt); |
| 216 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 217 | /** |
| 218 | * fdt_move - move a device tree around in memory |
| 219 | * @fdt: pointer to the device tree to move |
| 220 | * @buf: pointer to memory where the device is to be moved |
| 221 | * @bufsize: size of the memory space at buf |
| 222 | * |
| 223 | * fdt_move() relocates, if possible, the device tree blob located at |
| 224 | * fdt to the buffer at buf of size bufsize. The buffer may overlap |
| 225 | * with the existing device tree blob at fdt. Therefore, |
| 226 | * fdt_move(fdt, fdt, fdt_totalsize(fdt)) |
| 227 | * should always succeed. |
| 228 | * |
| 229 | * returns: |
| 230 | * 0, on success |
| 231 | * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree |
| 232 | * -FDT_ERR_BADMAGIC, |
| 233 | * -FDT_ERR_BADVERSION, |
| 234 | * -FDT_ERR_BADSTATE, standard meanings |
| 235 | */ |
| 236 | int fdt_move(const void *fdt, void *buf, int bufsize); |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 237 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 238 | /**********************************************************************/ |
| 239 | /* Read-only functions */ |
| 240 | /**********************************************************************/ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 241 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 242 | /** |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 243 | * fdt_string - retrieve a string from the strings block of a device tree |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 244 | * @fdt: pointer to the device tree blob |
| 245 | * @stroffset: offset of the string within the strings block (native endian) |
| 246 | * |
| 247 | * fdt_string() retrieves a pointer to a single string from the |
| 248 | * strings block of the device tree blob at fdt. |
| 249 | * |
| 250 | * returns: |
| 251 | * a pointer to the string, on success |
| 252 | * NULL, if stroffset is out of bounds |
| 253 | */ |
| 254 | const char *fdt_string(const void *fdt, int stroffset); |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 255 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 256 | /** |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 257 | * fdt_num_mem_rsv - retrieve the number of memory reserve map entries |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 258 | * @fdt: pointer to the device tree blob |
| 259 | * |
| 260 | * Returns the number of entries in the device tree blob's memory |
| 261 | * reservation map. This does not include the terminating 0,0 entry |
| 262 | * or any other (0,0) entries reserved for expansion. |
| 263 | * |
| 264 | * returns: |
| 265 | * the number of entries |
| 266 | */ |
| 267 | int fdt_num_mem_rsv(const void *fdt); |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 268 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 269 | /** |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 270 | * fdt_get_mem_rsv - retrieve one memory reserve map entry |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 271 | * @fdt: pointer to the device tree blob |
| 272 | * @address, @size: pointers to 64-bit variables |
| 273 | * |
| 274 | * On success, *address and *size will contain the address and size of |
| 275 | * the n-th reserve map entry from the device tree blob, in |
| 276 | * native-endian format. |
| 277 | * |
| 278 | * returns: |
| 279 | * 0, on success |
| 280 | * -FDT_ERR_BADMAGIC, |
| 281 | * -FDT_ERR_BADVERSION, |
| 282 | * -FDT_ERR_BADSTATE, standard meanings |
| 283 | */ |
| 284 | int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size); |
| 285 | |
| 286 | /** |
| 287 | * fdt_subnode_offset_namelen - find a subnode based on substring |
| 288 | * @fdt: pointer to the device tree blob |
| 289 | * @parentoffset: structure block offset of a node |
| 290 | * @name: name of the subnode to locate |
| 291 | * @namelen: number of characters of name to consider |
| 292 | * |
| 293 | * Identical to fdt_subnode_offset(), but only examine the first |
| 294 | * namelen characters of name for matching the subnode name. This is |
| 295 | * useful for finding subnodes based on a portion of a larger string, |
| 296 | * such as a full path. |
| 297 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 298 | int fdt_subnode_offset_namelen(const void *fdt, int parentoffset, |
| 299 | const char *name, int namelen); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 300 | /** |
| 301 | * fdt_subnode_offset - find a subnode of a given node |
| 302 | * @fdt: pointer to the device tree blob |
| 303 | * @parentoffset: structure block offset of a node |
| 304 | * @name: name of the subnode to locate |
| 305 | * |
| 306 | * fdt_subnode_offset() finds a subnode of the node at structure block |
| 307 | * offset parentoffset with the given name. name may include a unit |
| 308 | * address, in which case fdt_subnode_offset() will find the subnode |
| 309 | * with that unit address, or the unit address may be omitted, in |
| 310 | * which case fdt_subnode_offset() will find an arbitrary subnode |
| 311 | * whose name excluding unit address matches the given name. |
| 312 | * |
| 313 | * returns: |
| 314 | * structure block offset of the requested subnode (>=0), on success |
| 315 | * -FDT_ERR_NOTFOUND, if the requested subnode does not exist |
| 316 | * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag |
| 317 | * -FDT_ERR_BADMAGIC, |
| 318 | * -FDT_ERR_BADVERSION, |
| 319 | * -FDT_ERR_BADSTATE, |
| 320 | * -FDT_ERR_BADSTRUCTURE, |
| 321 | * -FDT_ERR_TRUNCATED, standard meanings. |
| 322 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 323 | int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); |
| 324 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 325 | /** |
| 326 | * fdt_path_offset - find a tree node by its full path |
| 327 | * @fdt: pointer to the device tree blob |
| 328 | * @path: full path of the node to locate |
| 329 | * |
| 330 | * fdt_path_offset() finds a node of a given path in the device tree. |
| 331 | * Each path component may omit the unit address portion, but the |
| 332 | * results of this are undefined if any such path component is |
| 333 | * ambiguous (that is if there are multiple nodes at the relevant |
| 334 | * level matching the given component, differentiated only by unit |
| 335 | * address). |
| 336 | * |
| 337 | * returns: |
| 338 | * structure block offset of the node with the requested path (>=0), on success |
| 339 | * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid |
| 340 | * -FDT_ERR_NOTFOUND, if the requested node does not exist |
| 341 | * -FDT_ERR_BADMAGIC, |
| 342 | * -FDT_ERR_BADVERSION, |
| 343 | * -FDT_ERR_BADSTATE, |
| 344 | * -FDT_ERR_BADSTRUCTURE, |
| 345 | * -FDT_ERR_TRUNCATED, standard meanings. |
| 346 | */ |
| 347 | int fdt_path_offset(const void *fdt, const char *path); |
| 348 | |
| 349 | /** |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 350 | * fdt_get_name - retrieve the name of a given node |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 351 | * @fdt: pointer to the device tree blob |
| 352 | * @nodeoffset: structure block offset of the starting node |
| 353 | * @lenp: pointer to an integer variable (will be overwritten) or NULL |
| 354 | * |
| 355 | * fdt_get_name() retrieves the name (including unit address) of the |
| 356 | * device tree node at structure block offset nodeoffset. If lenp is |
| 357 | * non-NULL, the length of this name is also returned, in the integer |
| 358 | * pointed to by lenp. |
| 359 | * |
| 360 | * returns: |
| 361 | * pointer to the node's name, on success |
| 362 | * If lenp is non-NULL, *lenp contains the length of that name (>=0) |
| 363 | * NULL, on error |
| 364 | * if lenp is non-NULL *lenp contains an error code (<0): |
| 365 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 366 | * -FDT_ERR_BADMAGIC, |
| 367 | * -FDT_ERR_BADVERSION, |
| 368 | * -FDT_ERR_BADSTATE, standard meanings |
| 369 | */ |
| 370 | const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp); |
| 371 | |
| 372 | /** |
David Gibson | 7b64da1 | 2010-03-09 17:39:14 +1100 | [diff] [blame] | 373 | * fdt_first_property_offset - find the offset of a node's first property |
| 374 | * @fdt: pointer to the device tree blob |
| 375 | * @nodeoffset: structure block offset of a node |
| 376 | * |
| 377 | * fdt_first_property_offset() finds the first property of the node at |
| 378 | * the given structure block offset. |
| 379 | * |
| 380 | * returns: |
| 381 | * structure block offset of the property (>=0), on success |
| 382 | * -FDT_ERR_NOTFOUND, if the requested node has no properties |
| 383 | * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag |
| 384 | * -FDT_ERR_BADMAGIC, |
| 385 | * -FDT_ERR_BADVERSION, |
| 386 | * -FDT_ERR_BADSTATE, |
| 387 | * -FDT_ERR_BADSTRUCTURE, |
| 388 | * -FDT_ERR_TRUNCATED, standard meanings. |
| 389 | */ |
| 390 | int fdt_first_property_offset(const void *fdt, int nodeoffset); |
| 391 | |
| 392 | /** |
| 393 | * fdt_next_property_offset - step through a node's properties |
| 394 | * @fdt: pointer to the device tree blob |
| 395 | * @offset: structure block offset of a property |
| 396 | * |
| 397 | * fdt_next_property_offset() finds the property immediately after the |
| 398 | * one at the given structure block offset. This will be a property |
| 399 | * of the same node as the given property. |
| 400 | * |
| 401 | * returns: |
| 402 | * structure block offset of the next property (>=0), on success |
| 403 | * -FDT_ERR_NOTFOUND, if the given property is the last in its node |
| 404 | * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag |
| 405 | * -FDT_ERR_BADMAGIC, |
| 406 | * -FDT_ERR_BADVERSION, |
| 407 | * -FDT_ERR_BADSTATE, |
| 408 | * -FDT_ERR_BADSTRUCTURE, |
| 409 | * -FDT_ERR_TRUNCATED, standard meanings. |
| 410 | */ |
| 411 | int fdt_next_property_offset(const void *fdt, int offset); |
| 412 | |
| 413 | /** |
| 414 | * fdt_get_property_by_offset - retrieve the property at a given offset |
| 415 | * @fdt: pointer to the device tree blob |
| 416 | * @offset: offset of the property to retrieve |
| 417 | * @lenp: pointer to an integer variable (will be overwritten) or NULL |
| 418 | * |
| 419 | * fdt_get_property_by_offset() retrieves a pointer to the |
| 420 | * fdt_property structure within the device tree blob at the given |
| 421 | * offset. If lenp is non-NULL, the length of the property value is |
| 422 | * also returned, in the integer pointed to by lenp. |
| 423 | * |
| 424 | * returns: |
| 425 | * pointer to the structure representing the property |
| 426 | * if lenp is non-NULL, *lenp contains the length of the property |
| 427 | * value (>=0) |
| 428 | * NULL, on error |
| 429 | * if lenp is non-NULL, *lenp contains an error code (<0): |
| 430 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag |
| 431 | * -FDT_ERR_BADMAGIC, |
| 432 | * -FDT_ERR_BADVERSION, |
| 433 | * -FDT_ERR_BADSTATE, |
| 434 | * -FDT_ERR_BADSTRUCTURE, |
| 435 | * -FDT_ERR_TRUNCATED, standard meanings |
| 436 | */ |
| 437 | const struct fdt_property *fdt_get_property_by_offset(const void *fdt, |
| 438 | int offset, |
| 439 | int *lenp); |
| 440 | |
| 441 | /** |
David Gibson | c5b130e | 2008-08-06 14:50:49 +1000 | [diff] [blame] | 442 | * fdt_get_property_namelen - find a property based on substring |
| 443 | * @fdt: pointer to the device tree blob |
| 444 | * @nodeoffset: offset of the node whose property to find |
| 445 | * @name: name of the property to find |
| 446 | * @namelen: number of characters of name to consider |
| 447 | * @lenp: pointer to an integer variable (will be overwritten) or NULL |
| 448 | * |
| 449 | * Identical to fdt_get_property_namelen(), but only examine the first |
| 450 | * namelen characters of name for matching the property name. |
| 451 | */ |
| 452 | const struct fdt_property *fdt_get_property_namelen(const void *fdt, |
| 453 | int nodeoffset, |
| 454 | const char *name, |
| 455 | int namelen, int *lenp); |
| 456 | |
| 457 | /** |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 458 | * fdt_get_property - find a given property in a given node |
| 459 | * @fdt: pointer to the device tree blob |
| 460 | * @nodeoffset: offset of the node whose property to find |
| 461 | * @name: name of the property to find |
| 462 | * @lenp: pointer to an integer variable (will be overwritten) or NULL |
| 463 | * |
| 464 | * fdt_get_property() retrieves a pointer to the fdt_property |
| 465 | * structure within the device tree blob corresponding to the property |
| 466 | * named 'name' of the node at offset nodeoffset. If lenp is |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 467 | * non-NULL, the length of the property value is also returned, in the |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 468 | * integer pointed to by lenp. |
| 469 | * |
| 470 | * returns: |
| 471 | * pointer to the structure representing the property |
| 472 | * if lenp is non-NULL, *lenp contains the length of the property |
| 473 | * value (>=0) |
| 474 | * NULL, on error |
| 475 | * if lenp is non-NULL, *lenp contains an error code (<0): |
| 476 | * -FDT_ERR_NOTFOUND, node does not have named property |
| 477 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 478 | * -FDT_ERR_BADMAGIC, |
| 479 | * -FDT_ERR_BADVERSION, |
| 480 | * -FDT_ERR_BADSTATE, |
| 481 | * -FDT_ERR_BADSTRUCTURE, |
| 482 | * -FDT_ERR_TRUNCATED, standard meanings |
| 483 | */ |
| 484 | const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset, |
| 485 | const char *name, int *lenp); |
| 486 | static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset, |
| 487 | const char *name, |
| 488 | int *lenp) |
| 489 | { |
David Gibson | 870fa47 | 2008-07-07 10:14:15 +1000 | [diff] [blame] | 490 | return (struct fdt_property *)(uintptr_t) |
| 491 | fdt_get_property(fdt, nodeoffset, name, lenp); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /** |
David Gibson | 7b64da1 | 2010-03-09 17:39:14 +1100 | [diff] [blame] | 495 | * fdt_getprop_by_offset - retrieve the value of a property at a given offset |
| 496 | * @fdt: pointer to the device tree blob |
| 497 | * @ffset: offset of the property to read |
| 498 | * @namep: pointer to a string variable (will be overwritten) or NULL |
| 499 | * @lenp: pointer to an integer variable (will be overwritten) or NULL |
| 500 | * |
| 501 | * fdt_getprop_by_offset() retrieves a pointer to the value of the |
| 502 | * property at structure block offset 'offset' (this will be a pointer |
| 503 | * to within the device blob itself, not a copy of the value). If |
| 504 | * lenp is non-NULL, the length of the property value is also |
| 505 | * returned, in the integer pointed to by lenp. If namep is non-NULL, |
| 506 | * the property's namne will also be returned in the char * pointed to |
| 507 | * by namep (this will be a pointer to within the device tree's string |
| 508 | * block, not a new copy of the name). |
| 509 | * |
| 510 | * returns: |
| 511 | * pointer to the property's value |
| 512 | * if lenp is non-NULL, *lenp contains the length of the property |
| 513 | * value (>=0) |
| 514 | * if namep is non-NULL *namep contiains a pointer to the property |
| 515 | * name. |
| 516 | * NULL, on error |
| 517 | * if lenp is non-NULL, *lenp contains an error code (<0): |
| 518 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag |
| 519 | * -FDT_ERR_BADMAGIC, |
| 520 | * -FDT_ERR_BADVERSION, |
| 521 | * -FDT_ERR_BADSTATE, |
| 522 | * -FDT_ERR_BADSTRUCTURE, |
| 523 | * -FDT_ERR_TRUNCATED, standard meanings |
| 524 | */ |
| 525 | const void *fdt_getprop_by_offset(const void *fdt, int offset, |
| 526 | const char **namep, int *lenp); |
| 527 | |
| 528 | /** |
David Gibson | c5b130e | 2008-08-06 14:50:49 +1000 | [diff] [blame] | 529 | * fdt_getprop_namelen - get property value based on substring |
| 530 | * @fdt: pointer to the device tree blob |
| 531 | * @nodeoffset: offset of the node whose property to find |
| 532 | * @name: name of the property to find |
| 533 | * @namelen: number of characters of name to consider |
| 534 | * @lenp: pointer to an integer variable (will be overwritten) or NULL |
| 535 | * |
| 536 | * Identical to fdt_getprop(), but only examine the first namelen |
| 537 | * characters of name for matching the property name. |
| 538 | */ |
| 539 | const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, |
| 540 | const char *name, int namelen, int *lenp); |
| 541 | |
| 542 | /** |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 543 | * fdt_getprop - retrieve the value of a given property |
| 544 | * @fdt: pointer to the device tree blob |
| 545 | * @nodeoffset: offset of the node whose property to find |
| 546 | * @name: name of the property to find |
| 547 | * @lenp: pointer to an integer variable (will be overwritten) or NULL |
| 548 | * |
| 549 | * fdt_getprop() retrieves a pointer to the value of the property |
| 550 | * named 'name' of the node at offset nodeoffset (this will be a |
| 551 | * pointer to within the device blob itself, not a copy of the value). |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 552 | * If lenp is non-NULL, the length of the property value is also |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 553 | * returned, in the integer pointed to by lenp. |
| 554 | * |
| 555 | * returns: |
| 556 | * pointer to the property's value |
| 557 | * if lenp is non-NULL, *lenp contains the length of the property |
| 558 | * value (>=0) |
| 559 | * NULL, on error |
| 560 | * if lenp is non-NULL, *lenp contains an error code (<0): |
| 561 | * -FDT_ERR_NOTFOUND, node does not have named property |
| 562 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 563 | * -FDT_ERR_BADMAGIC, |
| 564 | * -FDT_ERR_BADVERSION, |
| 565 | * -FDT_ERR_BADSTATE, |
| 566 | * -FDT_ERR_BADSTRUCTURE, |
| 567 | * -FDT_ERR_TRUNCATED, standard meanings |
| 568 | */ |
| 569 | const void *fdt_getprop(const void *fdt, int nodeoffset, |
| 570 | const char *name, int *lenp); |
| 571 | static inline void *fdt_getprop_w(void *fdt, int nodeoffset, |
| 572 | const char *name, int *lenp) |
| 573 | { |
David Gibson | 870fa47 | 2008-07-07 10:14:15 +1000 | [diff] [blame] | 574 | return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /** |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 578 | * fdt_get_phandle - retrieve the phandle of a given node |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 579 | * @fdt: pointer to the device tree blob |
| 580 | * @nodeoffset: structure block offset of the node |
| 581 | * |
| 582 | * fdt_get_phandle() retrieves the phandle of the device tree node at |
| 583 | * structure block offset nodeoffset. |
| 584 | * |
| 585 | * returns: |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 586 | * the phandle of the node at nodeoffset, on success (!= 0, != -1) |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 587 | * 0, if the node has no phandle, or another error occurs |
| 588 | */ |
| 589 | uint32_t fdt_get_phandle(const void *fdt, int nodeoffset); |
| 590 | |
| 591 | /** |
Gerald Van Baren | 9f45b90 | 2008-10-04 07:56:06 -0400 | [diff] [blame] | 592 | * fdt_get_alias_namelen - get alias based on substring |
David Gibson | d6656ea | 2008-08-20 16:55:14 +1000 | [diff] [blame] | 593 | * @fdt: pointer to the device tree blob |
| 594 | * @name: name of the alias th look up |
| 595 | * @namelen: number of characters of name to consider |
| 596 | * |
| 597 | * Identical to fdt_get_alias(), but only examine the first namelen |
| 598 | * characters of name for matching the alias name. |
| 599 | */ |
| 600 | const char *fdt_get_alias_namelen(const void *fdt, |
| 601 | const char *name, int namelen); |
| 602 | |
| 603 | /** |
Simon Glass | 536774d | 2014-07-30 03:59:03 -0600 | [diff] [blame] | 604 | * fdt_get_alias - retreive the path referenced by a given alias |
David Gibson | d6656ea | 2008-08-20 16:55:14 +1000 | [diff] [blame] | 605 | * @fdt: pointer to the device tree blob |
Simon Glass | 536774d | 2014-07-30 03:59:03 -0600 | [diff] [blame] | 606 | * @name: name of the alias th look up |
David Gibson | d6656ea | 2008-08-20 16:55:14 +1000 | [diff] [blame] | 607 | * |
| 608 | * fdt_get_alias() retrieves the value of a given alias. That is, the |
| 609 | * value of the property named 'name' in the node /aliases. |
| 610 | * |
| 611 | * returns: |
François Revol | 0f0ad8c | 2013-02-03 00:52:21 +0100 | [diff] [blame] | 612 | * a pointer to the expansion of the alias named 'name', if it exists |
David Gibson | d6656ea | 2008-08-20 16:55:14 +1000 | [diff] [blame] | 613 | * NULL, if the given alias or the /aliases node does not exist |
| 614 | */ |
| 615 | const char *fdt_get_alias(const void *fdt, const char *name); |
| 616 | |
| 617 | /** |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 618 | * fdt_get_path - determine the full path of a node |
| 619 | * @fdt: pointer to the device tree blob |
| 620 | * @nodeoffset: offset of the node whose path to find |
| 621 | * @buf: character buffer to contain the returned path (will be overwritten) |
| 622 | * @buflen: size of the character buffer at buf |
| 623 | * |
| 624 | * fdt_get_path() computes the full path of the node at offset |
| 625 | * nodeoffset, and records that path in the buffer at buf. |
| 626 | * |
| 627 | * NOTE: This function is expensive, as it must scan the device tree |
| 628 | * structure from the start to nodeoffset. |
| 629 | * |
| 630 | * returns: |
| 631 | * 0, on success |
| 632 | * buf contains the absolute path of the node at |
| 633 | * nodeoffset, as a NUL-terminated string. |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 634 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 635 | * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1) |
| 636 | * characters and will not fit in the given buffer. |
| 637 | * -FDT_ERR_BADMAGIC, |
| 638 | * -FDT_ERR_BADVERSION, |
| 639 | * -FDT_ERR_BADSTATE, |
| 640 | * -FDT_ERR_BADSTRUCTURE, standard meanings |
| 641 | */ |
| 642 | int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen); |
| 643 | |
| 644 | /** |
| 645 | * fdt_supernode_atdepth_offset - find a specific ancestor of a node |
| 646 | * @fdt: pointer to the device tree blob |
| 647 | * @nodeoffset: offset of the node whose parent to find |
| 648 | * @supernodedepth: depth of the ancestor to find |
| 649 | * @nodedepth: pointer to an integer variable (will be overwritten) or NULL |
| 650 | * |
| 651 | * fdt_supernode_atdepth_offset() finds an ancestor of the given node |
| 652 | * at a specific depth from the root (where the root itself has depth |
| 653 | * 0, its immediate subnodes depth 1 and so forth). So |
| 654 | * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL); |
| 655 | * will always return 0, the offset of the root node. If the node at |
| 656 | * nodeoffset has depth D, then: |
| 657 | * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL); |
| 658 | * will return nodeoffset itself. |
| 659 | * |
| 660 | * NOTE: This function is expensive, as it must scan the device tree |
| 661 | * structure from the start to nodeoffset. |
| 662 | * |
| 663 | * returns: |
| 664 | |
| 665 | * structure block offset of the node at node offset's ancestor |
| 666 | * of depth supernodedepth (>=0), on success |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 667 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 668 | * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset |
| 669 | * -FDT_ERR_BADMAGIC, |
| 670 | * -FDT_ERR_BADVERSION, |
| 671 | * -FDT_ERR_BADSTATE, |
| 672 | * -FDT_ERR_BADSTRUCTURE, standard meanings |
| 673 | */ |
| 674 | int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, |
| 675 | int supernodedepth, int *nodedepth); |
| 676 | |
| 677 | /** |
| 678 | * fdt_node_depth - find the depth of a given node |
| 679 | * @fdt: pointer to the device tree blob |
| 680 | * @nodeoffset: offset of the node whose parent to find |
| 681 | * |
| 682 | * fdt_node_depth() finds the depth of a given node. The root node |
| 683 | * has depth 0, its immediate subnodes depth 1 and so forth. |
| 684 | * |
| 685 | * NOTE: This function is expensive, as it must scan the device tree |
| 686 | * structure from the start to nodeoffset. |
| 687 | * |
| 688 | * returns: |
| 689 | * depth of the node at nodeoffset (>=0), on success |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 690 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 691 | * -FDT_ERR_BADMAGIC, |
| 692 | * -FDT_ERR_BADVERSION, |
| 693 | * -FDT_ERR_BADSTATE, |
| 694 | * -FDT_ERR_BADSTRUCTURE, standard meanings |
| 695 | */ |
| 696 | int fdt_node_depth(const void *fdt, int nodeoffset); |
| 697 | |
| 698 | /** |
| 699 | * fdt_parent_offset - find the parent of a given node |
| 700 | * @fdt: pointer to the device tree blob |
| 701 | * @nodeoffset: offset of the node whose parent to find |
| 702 | * |
| 703 | * fdt_parent_offset() locates the parent node of a given node (that |
| 704 | * is, it finds the offset of the node which contains the node at |
| 705 | * nodeoffset as a subnode). |
| 706 | * |
| 707 | * NOTE: This function is expensive, as it must scan the device tree |
| 708 | * structure from the start to nodeoffset, *twice*. |
| 709 | * |
| 710 | * returns: |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 711 | * structure block offset of the parent of the node at nodeoffset |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 712 | * (>=0), on success |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 713 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 714 | * -FDT_ERR_BADMAGIC, |
| 715 | * -FDT_ERR_BADVERSION, |
| 716 | * -FDT_ERR_BADSTATE, |
| 717 | * -FDT_ERR_BADSTRUCTURE, standard meanings |
| 718 | */ |
| 719 | int fdt_parent_offset(const void *fdt, int nodeoffset); |
| 720 | |
| 721 | /** |
| 722 | * fdt_node_offset_by_prop_value - find nodes with a given property value |
| 723 | * @fdt: pointer to the device tree blob |
| 724 | * @startoffset: only find nodes after this offset |
| 725 | * @propname: property name to check |
| 726 | * @propval: property value to search for |
| 727 | * @proplen: length of the value in propval |
| 728 | * |
| 729 | * fdt_node_offset_by_prop_value() returns the offset of the first |
| 730 | * node after startoffset, which has a property named propname whose |
| 731 | * value is of length proplen and has value equal to propval; or if |
| 732 | * startoffset is -1, the very first such node in the tree. |
| 733 | * |
| 734 | * To iterate through all nodes matching the criterion, the following |
| 735 | * idiom can be used: |
| 736 | * offset = fdt_node_offset_by_prop_value(fdt, -1, propname, |
| 737 | * propval, proplen); |
| 738 | * while (offset != -FDT_ERR_NOTFOUND) { |
Simon Glass | 536774d | 2014-07-30 03:59:03 -0600 | [diff] [blame] | 739 | * // other code here |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 740 | * offset = fdt_node_offset_by_prop_value(fdt, offset, propname, |
| 741 | * propval, proplen); |
| 742 | * } |
| 743 | * |
| 744 | * Note the -1 in the first call to the function, if 0 is used here |
| 745 | * instead, the function will never locate the root node, even if it |
| 746 | * matches the criterion. |
| 747 | * |
| 748 | * returns: |
| 749 | * structure block offset of the located node (>= 0, >startoffset), |
| 750 | * on success |
| 751 | * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the |
| 752 | * tree after startoffset |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 753 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 754 | * -FDT_ERR_BADMAGIC, |
| 755 | * -FDT_ERR_BADVERSION, |
| 756 | * -FDT_ERR_BADSTATE, |
| 757 | * -FDT_ERR_BADSTRUCTURE, standard meanings |
| 758 | */ |
| 759 | int fdt_node_offset_by_prop_value(const void *fdt, int startoffset, |
| 760 | const char *propname, |
| 761 | const void *propval, int proplen); |
| 762 | |
| 763 | /** |
| 764 | * fdt_node_offset_by_phandle - find the node with a given phandle |
| 765 | * @fdt: pointer to the device tree blob |
| 766 | * @phandle: phandle value |
| 767 | * |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 768 | * fdt_node_offset_by_phandle() returns the offset of the node |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 769 | * which has the given phandle value. If there is more than one node |
| 770 | * in the tree with the given phandle (an invalid tree), results are |
| 771 | * undefined. |
| 772 | * |
| 773 | * returns: |
| 774 | * structure block offset of the located node (>= 0), on success |
| 775 | * -FDT_ERR_NOTFOUND, no node with that phandle exists |
| 776 | * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1) |
| 777 | * -FDT_ERR_BADMAGIC, |
| 778 | * -FDT_ERR_BADVERSION, |
| 779 | * -FDT_ERR_BADSTATE, |
| 780 | * -FDT_ERR_BADSTRUCTURE, standard meanings |
| 781 | */ |
| 782 | int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle); |
| 783 | |
| 784 | /** |
| 785 | * fdt_node_check_compatible: check a node's compatible property |
| 786 | * @fdt: pointer to the device tree blob |
| 787 | * @nodeoffset: offset of a tree node |
| 788 | * @compatible: string to match against |
| 789 | * |
| 790 | * |
| 791 | * fdt_node_check_compatible() returns 0 if the given node contains a |
| 792 | * 'compatible' property with the given string as one of its elements, |
| 793 | * it returns non-zero otherwise, or on error. |
| 794 | * |
| 795 | * returns: |
| 796 | * 0, if the node has a 'compatible' property listing the given string |
| 797 | * 1, if the node has a 'compatible' property, but it does not list |
| 798 | * the given string |
| 799 | * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 800 | * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 801 | * -FDT_ERR_BADMAGIC, |
| 802 | * -FDT_ERR_BADVERSION, |
| 803 | * -FDT_ERR_BADSTATE, |
| 804 | * -FDT_ERR_BADSTRUCTURE, standard meanings |
| 805 | */ |
| 806 | int fdt_node_check_compatible(const void *fdt, int nodeoffset, |
| 807 | const char *compatible); |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 808 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 809 | /** |
| 810 | * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value |
| 811 | * @fdt: pointer to the device tree blob |
| 812 | * @startoffset: only find nodes after this offset |
| 813 | * @compatible: 'compatible' string to match against |
| 814 | * |
| 815 | * fdt_node_offset_by_compatible() returns the offset of the first |
| 816 | * node after startoffset, which has a 'compatible' property which |
| 817 | * lists the given compatible string; or if startoffset is -1, the |
| 818 | * very first such node in the tree. |
| 819 | * |
| 820 | * To iterate through all nodes matching the criterion, the following |
| 821 | * idiom can be used: |
| 822 | * offset = fdt_node_offset_by_compatible(fdt, -1, compatible); |
| 823 | * while (offset != -FDT_ERR_NOTFOUND) { |
Simon Glass | 536774d | 2014-07-30 03:59:03 -0600 | [diff] [blame] | 824 | * // other code here |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 825 | * offset = fdt_node_offset_by_compatible(fdt, offset, compatible); |
| 826 | * } |
| 827 | * |
| 828 | * Note the -1 in the first call to the function, if 0 is used here |
| 829 | * instead, the function will never locate the root node, even if it |
| 830 | * matches the criterion. |
| 831 | * |
| 832 | * returns: |
| 833 | * structure block offset of the located node (>= 0, >startoffset), |
| 834 | * on success |
| 835 | * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the |
| 836 | * tree after startoffset |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 837 | * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 838 | * -FDT_ERR_BADMAGIC, |
| 839 | * -FDT_ERR_BADVERSION, |
| 840 | * -FDT_ERR_BADSTATE, |
| 841 | * -FDT_ERR_BADSTRUCTURE, standard meanings |
| 842 | */ |
| 843 | int fdt_node_offset_by_compatible(const void *fdt, int startoffset, |
| 844 | const char *compatible); |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 845 | |
Simon Glass | 73b4756 | 2013-01-21 12:59:18 -0800 | [diff] [blame] | 846 | /** |
| 847 | * fdt_stringlist_contains - check a string list property for a string |
| 848 | * @strlist: Property containing a list of strings to check |
| 849 | * @listlen: Length of property |
| 850 | * @str: String to search for |
| 851 | * |
| 852 | * This is a utility function provided for convenience. The list contains |
| 853 | * one or more strings, each terminated by \0, as is found in a device tree |
| 854 | * "compatible" property. |
| 855 | * |
| 856 | * @return: 1 if the string is found in the list, 0 not found, or invalid list |
| 857 | */ |
| 858 | int fdt_stringlist_contains(const char *strlist, int listlen, const char *str); |
| 859 | |
Thierry Reding | 92ba09e | 2014-08-26 17:33:50 +0200 | [diff] [blame] | 860 | /** |
| 861 | * fdt_count_strings - count the number of strings in a string list |
| 862 | * @fdt: pointer to the device tree blob |
| 863 | * @node: offset of the node |
| 864 | * @property: name of the property containing the string list |
| 865 | * @return: the number of strings in the given property |
| 866 | */ |
| 867 | int fdt_count_strings(const void *fdt, int node, const char *property); |
| 868 | |
Thierry Reding | a24f1ac | 2014-08-26 17:33:51 +0200 | [diff] [blame^] | 869 | /** |
| 870 | * fdt_find_string - find a string in a string list and return its index |
| 871 | * @fdt: pointer to the device tree blob |
| 872 | * @node: offset of the node |
| 873 | * @property: name of the property containing the string list |
| 874 | * @string: string to look up in the string list |
| 875 | * @return: the index of the string or negative on error |
| 876 | */ |
| 877 | int fdt_find_string(const void *fdt, int node, const char *property, |
| 878 | const char *string); |
| 879 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 880 | /**********************************************************************/ |
Simon Glass | 536774d | 2014-07-30 03:59:03 -0600 | [diff] [blame] | 881 | /* Read-only functions (addressing related) */ |
| 882 | /**********************************************************************/ |
| 883 | |
| 884 | /** |
| 885 | * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells |
| 886 | * |
| 887 | * This is the maximum value for #address-cells, #size-cells and |
| 888 | * similar properties that will be processed by libfdt. IEE1275 |
| 889 | * requires that OF implementations handle values up to 4. |
| 890 | * Implementations may support larger values, but in practice higher |
| 891 | * values aren't used. |
| 892 | */ |
| 893 | #define FDT_MAX_NCELLS 4 |
| 894 | |
| 895 | /** |
| 896 | * fdt_address_cells - retrieve address size for a bus represented in the tree |
| 897 | * @fdt: pointer to the device tree blob |
| 898 | * @nodeoffset: offset of the node to find the address size for |
| 899 | * |
| 900 | * When the node has a valid #address-cells property, returns its value. |
| 901 | * |
| 902 | * returns: |
| 903 | * 0 <= n < FDT_MAX_NCELLS, on success |
| 904 | * 2, if the node has no #address-cells property |
| 905 | * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid |
| 906 | * #address-cells property |
| 907 | * -FDT_ERR_BADMAGIC, |
| 908 | * -FDT_ERR_BADVERSION, |
| 909 | * -FDT_ERR_BADSTATE, |
| 910 | * -FDT_ERR_BADSTRUCTURE, |
| 911 | * -FDT_ERR_TRUNCATED, standard meanings |
| 912 | */ |
| 913 | int fdt_address_cells(const void *fdt, int nodeoffset); |
| 914 | |
| 915 | /** |
| 916 | * fdt_size_cells - retrieve address range size for a bus represented in the |
| 917 | * tree |
| 918 | * @fdt: pointer to the device tree blob |
| 919 | * @nodeoffset: offset of the node to find the address range size for |
| 920 | * |
| 921 | * When the node has a valid #size-cells property, returns its value. |
| 922 | * |
| 923 | * returns: |
| 924 | * 0 <= n < FDT_MAX_NCELLS, on success |
| 925 | * 2, if the node has no #address-cells property |
| 926 | * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid |
| 927 | * #size-cells property |
| 928 | * -FDT_ERR_BADMAGIC, |
| 929 | * -FDT_ERR_BADVERSION, |
| 930 | * -FDT_ERR_BADSTATE, |
| 931 | * -FDT_ERR_BADSTRUCTURE, |
| 932 | * -FDT_ERR_TRUNCATED, standard meanings |
| 933 | */ |
| 934 | int fdt_size_cells(const void *fdt, int nodeoffset); |
| 935 | |
| 936 | |
| 937 | /**********************************************************************/ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 938 | /* Write-in-place functions */ |
| 939 | /**********************************************************************/ |
Gerald Van Baren | ca8d8a6 | 2007-03-31 12:13:43 -0400 | [diff] [blame] | 940 | |
David Gibson | e85cae1 | 2007-12-17 14:41:52 +1100 | [diff] [blame] | 941 | /** |
| 942 | * fdt_setprop_inplace - change a property's value, but not its size |
| 943 | * @fdt: pointer to the device tree blob |
| 944 | * @nodeoffset: offset of the node whose property to change |
| 945 | * @name: name of the property to change |
| 946 | * @val: pointer to data to replace the property value with |
| 947 | * @len: length of the property value |
| 948 | * |
| 949 | * fdt_setprop_inplace() replaces the value of a given property with |
| 950 | * the data in val, of length len. This function cannot change the |
| 951 | * size of a property, and so will only work if len is equal to the |
| 952 | * current length of the property. |
| 953 | * |
| 954 | * This function will alter only the bytes in the blob which contain |
| 955 | * the given property value, and will not alter or move any other part |
| 956 | * of the tree. |
| 957 | * |
| 958 | * returns: |
| 959 | * 0, on success |
| 960 | * -FDT_ERR_NOSPACE, if len is not equal to the property's current length |
| 961 | * -FDT_ERR_NOTFOUND, node does not have the named property |
| 962 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 963 | * -FDT_ERR_BADMAGIC, |
| 964 | * -FDT_ERR_BADVERSION, |
| 965 | * -FDT_ERR_BADSTATE, |
| 966 | * -FDT_ERR_BADSTRUCTURE, |
| 967 | * -FDT_ERR_TRUNCATED, standard meanings |
| 968 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 969 | int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, |
| 970 | const void *val, int len); |
David Gibson | e85cae1 | 2007-12-17 14:41:52 +1100 | [diff] [blame] | 971 | |
| 972 | /** |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 973 | * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property |
David Gibson | e85cae1 | 2007-12-17 14:41:52 +1100 | [diff] [blame] | 974 | * @fdt: pointer to the device tree blob |
| 975 | * @nodeoffset: offset of the node whose property to change |
| 976 | * @name: name of the property to change |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 977 | * @val: 32-bit integer value to replace the property with |
David Gibson | e85cae1 | 2007-12-17 14:41:52 +1100 | [diff] [blame] | 978 | * |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 979 | * fdt_setprop_inplace_u32() replaces the value of a given property |
| 980 | * with the 32-bit integer value in val, converting val to big-endian |
| 981 | * if necessary. This function cannot change the size of a property, |
| 982 | * and so will only work if the property already exists and has length |
| 983 | * 4. |
David Gibson | e85cae1 | 2007-12-17 14:41:52 +1100 | [diff] [blame] | 984 | * |
| 985 | * This function will alter only the bytes in the blob which contain |
| 986 | * the given property value, and will not alter or move any other part |
| 987 | * of the tree. |
| 988 | * |
| 989 | * returns: |
| 990 | * 0, on success |
| 991 | * -FDT_ERR_NOSPACE, if the property's length is not equal to 4 |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 992 | * -FDT_ERR_NOTFOUND, node does not have the named property |
David Gibson | e85cae1 | 2007-12-17 14:41:52 +1100 | [diff] [blame] | 993 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 994 | * -FDT_ERR_BADMAGIC, |
| 995 | * -FDT_ERR_BADVERSION, |
| 996 | * -FDT_ERR_BADSTATE, |
| 997 | * -FDT_ERR_BADSTRUCTURE, |
| 998 | * -FDT_ERR_TRUNCATED, standard meanings |
| 999 | */ |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1000 | static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset, |
| 1001 | const char *name, uint32_t val) |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1002 | { |
Kim Phillips | 38c3815 | 2013-01-16 13:59:50 +0000 | [diff] [blame] | 1003 | fdt32_t tmp = cpu_to_fdt32(val); |
| 1004 | return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp)); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1005 | } |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1006 | |
David Gibson | e85cae1 | 2007-12-17 14:41:52 +1100 | [diff] [blame] | 1007 | /** |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1008 | * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property |
| 1009 | * @fdt: pointer to the device tree blob |
| 1010 | * @nodeoffset: offset of the node whose property to change |
| 1011 | * @name: name of the property to change |
| 1012 | * @val: 64-bit integer value to replace the property with |
| 1013 | * |
| 1014 | * fdt_setprop_inplace_u64() replaces the value of a given property |
| 1015 | * with the 64-bit integer value in val, converting val to big-endian |
| 1016 | * if necessary. This function cannot change the size of a property, |
| 1017 | * and so will only work if the property already exists and has length |
| 1018 | * 8. |
| 1019 | * |
| 1020 | * This function will alter only the bytes in the blob which contain |
| 1021 | * the given property value, and will not alter or move any other part |
| 1022 | * of the tree. |
| 1023 | * |
| 1024 | * returns: |
| 1025 | * 0, on success |
| 1026 | * -FDT_ERR_NOSPACE, if the property's length is not equal to 8 |
| 1027 | * -FDT_ERR_NOTFOUND, node does not have the named property |
| 1028 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1029 | * -FDT_ERR_BADMAGIC, |
| 1030 | * -FDT_ERR_BADVERSION, |
| 1031 | * -FDT_ERR_BADSTATE, |
| 1032 | * -FDT_ERR_BADSTRUCTURE, |
| 1033 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1034 | */ |
| 1035 | static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset, |
| 1036 | const char *name, uint64_t val) |
| 1037 | { |
Kim Phillips | 38c3815 | 2013-01-16 13:59:50 +0000 | [diff] [blame] | 1038 | fdt64_t tmp = cpu_to_fdt64(val); |
| 1039 | return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp)); |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * fdt_setprop_inplace_cell - change the value of a single-cell property |
| 1044 | * |
| 1045 | * This is an alternative name for fdt_setprop_inplace_u32() |
| 1046 | */ |
| 1047 | static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset, |
| 1048 | const char *name, uint32_t val) |
| 1049 | { |
| 1050 | return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val); |
| 1051 | } |
| 1052 | |
| 1053 | /** |
David Gibson | e85cae1 | 2007-12-17 14:41:52 +1100 | [diff] [blame] | 1054 | * fdt_nop_property - replace a property with nop tags |
| 1055 | * @fdt: pointer to the device tree blob |
| 1056 | * @nodeoffset: offset of the node whose property to nop |
| 1057 | * @name: name of the property to nop |
| 1058 | * |
| 1059 | * fdt_nop_property() will replace a given property's representation |
| 1060 | * in the blob with FDT_NOP tags, effectively removing it from the |
| 1061 | * tree. |
| 1062 | * |
| 1063 | * This function will alter only the bytes in the blob which contain |
| 1064 | * the property, and will not alter or move any other part of the |
| 1065 | * tree. |
| 1066 | * |
| 1067 | * returns: |
| 1068 | * 0, on success |
| 1069 | * -FDT_ERR_NOTFOUND, node does not have the named property |
| 1070 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1071 | * -FDT_ERR_BADMAGIC, |
| 1072 | * -FDT_ERR_BADVERSION, |
| 1073 | * -FDT_ERR_BADSTATE, |
| 1074 | * -FDT_ERR_BADSTRUCTURE, |
| 1075 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1076 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1077 | int fdt_nop_property(void *fdt, int nodeoffset, const char *name); |
David Gibson | e85cae1 | 2007-12-17 14:41:52 +1100 | [diff] [blame] | 1078 | |
| 1079 | /** |
| 1080 | * fdt_nop_node - replace a node (subtree) with nop tags |
| 1081 | * @fdt: pointer to the device tree blob |
| 1082 | * @nodeoffset: offset of the node to nop |
| 1083 | * |
| 1084 | * fdt_nop_node() will replace a given node's representation in the |
| 1085 | * blob, including all its subnodes, if any, with FDT_NOP tags, |
| 1086 | * effectively removing it from the tree. |
| 1087 | * |
| 1088 | * This function will alter only the bytes in the blob which contain |
| 1089 | * the node and its properties and subnodes, and will not alter or |
| 1090 | * move any other part of the tree. |
| 1091 | * |
| 1092 | * returns: |
| 1093 | * 0, on success |
| 1094 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1095 | * -FDT_ERR_BADMAGIC, |
| 1096 | * -FDT_ERR_BADVERSION, |
| 1097 | * -FDT_ERR_BADSTATE, |
| 1098 | * -FDT_ERR_BADSTRUCTURE, |
| 1099 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1100 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1101 | int fdt_nop_node(void *fdt, int nodeoffset); |
Gerald Van Baren | c077a13 | 2007-04-14 22:46:41 -0400 | [diff] [blame] | 1102 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1103 | /**********************************************************************/ |
| 1104 | /* Sequential write functions */ |
| 1105 | /**********************************************************************/ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1106 | |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1107 | int fdt_create(void *buf, int bufsize); |
Simon Glass | 536774d | 2014-07-30 03:59:03 -0600 | [diff] [blame] | 1108 | int fdt_resize(void *fdt, void *buf, int bufsize); |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1109 | int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size); |
| 1110 | int fdt_finish_reservemap(void *fdt); |
| 1111 | int fdt_begin_node(void *fdt, const char *name); |
| 1112 | int fdt_property(void *fdt, const char *name, const void *val, int len); |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1113 | static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val) |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1114 | { |
Kim Phillips | 38c3815 | 2013-01-16 13:59:50 +0000 | [diff] [blame] | 1115 | fdt32_t tmp = cpu_to_fdt32(val); |
| 1116 | return fdt_property(fdt, name, &tmp, sizeof(tmp)); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1117 | } |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1118 | static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val) |
| 1119 | { |
Kim Phillips | 38c3815 | 2013-01-16 13:59:50 +0000 | [diff] [blame] | 1120 | fdt64_t tmp = cpu_to_fdt64(val); |
| 1121 | return fdt_property(fdt, name, &tmp, sizeof(tmp)); |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1122 | } |
| 1123 | static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) |
| 1124 | { |
| 1125 | return fdt_property_u32(fdt, name, val); |
| 1126 | } |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1127 | #define fdt_property_string(fdt, name, str) \ |
| 1128 | fdt_property(fdt, name, str, strlen(str)+1) |
| 1129 | int fdt_end_node(void *fdt); |
| 1130 | int fdt_finish(void *fdt); |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1131 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1132 | /**********************************************************************/ |
| 1133 | /* Read-write functions */ |
| 1134 | /**********************************************************************/ |
| 1135 | |
Gerald Van Baren | cb17cfa | 2012-10-15 22:24:36 -0400 | [diff] [blame] | 1136 | int fdt_create_empty_tree(void *buf, int bufsize); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1137 | int fdt_open_into(const void *fdt, void *buf, int bufsize); |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1138 | int fdt_pack(void *fdt); |
| 1139 | |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1140 | /** |
| 1141 | * fdt_add_mem_rsv - add one memory reserve map entry |
| 1142 | * @fdt: pointer to the device tree blob |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 1143 | * @address, @size: 64-bit values (native endian) |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1144 | * |
| 1145 | * Adds a reserve map entry to the given blob reserving a region at |
| 1146 | * address address of length size. |
| 1147 | * |
| 1148 | * This function will insert data into the reserve map and will |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 1149 | * therefore change the indexes of some entries in the table. |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1150 | * |
| 1151 | * returns: |
| 1152 | * 0, on success |
| 1153 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to |
| 1154 | * contain the new reservation entry |
| 1155 | * -FDT_ERR_BADMAGIC, |
| 1156 | * -FDT_ERR_BADVERSION, |
| 1157 | * -FDT_ERR_BADSTATE, |
| 1158 | * -FDT_ERR_BADSTRUCTURE, |
| 1159 | * -FDT_ERR_BADLAYOUT, |
| 1160 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1161 | */ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1162 | int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size); |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1163 | |
| 1164 | /** |
| 1165 | * fdt_del_mem_rsv - remove a memory reserve map entry |
| 1166 | * @fdt: pointer to the device tree blob |
| 1167 | * @n: entry to remove |
| 1168 | * |
| 1169 | * fdt_del_mem_rsv() removes the n-th memory reserve map entry from |
| 1170 | * the blob. |
| 1171 | * |
| 1172 | * This function will delete data from the reservation table and will |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 1173 | * therefore change the indexes of some entries in the table. |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1174 | * |
| 1175 | * returns: |
| 1176 | * 0, on success |
| 1177 | * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there |
| 1178 | * are less than n+1 reserve map entries) |
| 1179 | * -FDT_ERR_BADMAGIC, |
| 1180 | * -FDT_ERR_BADVERSION, |
| 1181 | * -FDT_ERR_BADSTATE, |
| 1182 | * -FDT_ERR_BADSTRUCTURE, |
| 1183 | * -FDT_ERR_BADLAYOUT, |
| 1184 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1185 | */ |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1186 | int fdt_del_mem_rsv(void *fdt, int n); |
| 1187 | |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1188 | /** |
David Gibson | fd1ea8f | 2008-01-11 14:55:05 +1100 | [diff] [blame] | 1189 | * fdt_set_name - change the name of a given node |
| 1190 | * @fdt: pointer to the device tree blob |
| 1191 | * @nodeoffset: structure block offset of a node |
| 1192 | * @name: name to give the node |
| 1193 | * |
| 1194 | * fdt_set_name() replaces the name (including unit address, if any) |
| 1195 | * of the given node with the given string. NOTE: this function can't |
| 1196 | * efficiently check if the new name is unique amongst the given |
| 1197 | * node's siblings; results are undefined if this function is invoked |
| 1198 | * with a name equal to one of the given node's siblings. |
| 1199 | * |
| 1200 | * This function may insert or delete data from the blob, and will |
| 1201 | * therefore change the offsets of some existing nodes. |
| 1202 | * |
| 1203 | * returns: |
| 1204 | * 0, on success |
| 1205 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob |
| 1206 | * to contain the new name |
| 1207 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1208 | * -FDT_ERR_BADMAGIC, |
| 1209 | * -FDT_ERR_BADVERSION, |
| 1210 | * -FDT_ERR_BADSTATE, standard meanings |
| 1211 | */ |
| 1212 | int fdt_set_name(void *fdt, int nodeoffset, const char *name); |
| 1213 | |
| 1214 | /** |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1215 | * fdt_setprop - create or change a property |
| 1216 | * @fdt: pointer to the device tree blob |
| 1217 | * @nodeoffset: offset of the node whose property to change |
| 1218 | * @name: name of the property to change |
| 1219 | * @val: pointer to data to set the property value to |
| 1220 | * @len: length of the property value |
| 1221 | * |
| 1222 | * fdt_setprop() sets the value of the named property in the given |
Wolfram Sang | 9a36da9 | 2008-07-09 11:22:44 +0200 | [diff] [blame] | 1223 | * node to the given value and length, creating the property if it |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1224 | * does not already exist. |
| 1225 | * |
| 1226 | * This function may insert or delete data from the blob, and will |
| 1227 | * therefore change the offsets of some existing nodes. |
| 1228 | * |
| 1229 | * returns: |
| 1230 | * 0, on success |
| 1231 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to |
| 1232 | * contain the new property value |
| 1233 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1234 | * -FDT_ERR_BADLAYOUT, |
| 1235 | * -FDT_ERR_BADMAGIC, |
| 1236 | * -FDT_ERR_BADVERSION, |
| 1237 | * -FDT_ERR_BADSTATE, |
| 1238 | * -FDT_ERR_BADSTRUCTURE, |
| 1239 | * -FDT_ERR_BADLAYOUT, |
| 1240 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1241 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1242 | int fdt_setprop(void *fdt, int nodeoffset, const char *name, |
| 1243 | const void *val, int len); |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1244 | |
| 1245 | /** |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1246 | * fdt_setprop_u32 - set a property to a 32-bit integer |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1247 | * @fdt: pointer to the device tree blob |
| 1248 | * @nodeoffset: offset of the node whose property to change |
| 1249 | * @name: name of the property to change |
| 1250 | * @val: 32-bit integer value for the property (native endian) |
| 1251 | * |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1252 | * fdt_setprop_u32() sets the value of the named property in the given |
| 1253 | * node to the given 32-bit integer value (converting to big-endian if |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1254 | * necessary), or creates a new property with that value if it does |
| 1255 | * not already exist. |
| 1256 | * |
| 1257 | * This function may insert or delete data from the blob, and will |
| 1258 | * therefore change the offsets of some existing nodes. |
| 1259 | * |
| 1260 | * returns: |
| 1261 | * 0, on success |
| 1262 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to |
| 1263 | * contain the new property value |
| 1264 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1265 | * -FDT_ERR_BADLAYOUT, |
| 1266 | * -FDT_ERR_BADMAGIC, |
| 1267 | * -FDT_ERR_BADVERSION, |
| 1268 | * -FDT_ERR_BADSTATE, |
| 1269 | * -FDT_ERR_BADSTRUCTURE, |
| 1270 | * -FDT_ERR_BADLAYOUT, |
| 1271 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1272 | */ |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1273 | static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name, |
| 1274 | uint32_t val) |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1275 | { |
Kim Phillips | 38c3815 | 2013-01-16 13:59:50 +0000 | [diff] [blame] | 1276 | fdt32_t tmp = cpu_to_fdt32(val); |
| 1277 | return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1278 | } |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1279 | |
| 1280 | /** |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1281 | * fdt_setprop_u64 - set a property to a 64-bit integer |
| 1282 | * @fdt: pointer to the device tree blob |
| 1283 | * @nodeoffset: offset of the node whose property to change |
| 1284 | * @name: name of the property to change |
| 1285 | * @val: 64-bit integer value for the property (native endian) |
| 1286 | * |
| 1287 | * fdt_setprop_u64() sets the value of the named property in the given |
| 1288 | * node to the given 64-bit integer value (converting to big-endian if |
| 1289 | * necessary), or creates a new property with that value if it does |
| 1290 | * not already exist. |
| 1291 | * |
| 1292 | * This function may insert or delete data from the blob, and will |
| 1293 | * therefore change the offsets of some existing nodes. |
| 1294 | * |
| 1295 | * returns: |
| 1296 | * 0, on success |
| 1297 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to |
| 1298 | * contain the new property value |
| 1299 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1300 | * -FDT_ERR_BADLAYOUT, |
| 1301 | * -FDT_ERR_BADMAGIC, |
| 1302 | * -FDT_ERR_BADVERSION, |
| 1303 | * -FDT_ERR_BADSTATE, |
| 1304 | * -FDT_ERR_BADSTRUCTURE, |
| 1305 | * -FDT_ERR_BADLAYOUT, |
| 1306 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1307 | */ |
| 1308 | static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name, |
| 1309 | uint64_t val) |
| 1310 | { |
Kim Phillips | 38c3815 | 2013-01-16 13:59:50 +0000 | [diff] [blame] | 1311 | fdt64_t tmp = cpu_to_fdt64(val); |
| 1312 | return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | /** |
| 1316 | * fdt_setprop_cell - set a property to a single cell value |
| 1317 | * |
| 1318 | * This is an alternative name for fdt_setprop_u32() |
| 1319 | */ |
| 1320 | static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name, |
| 1321 | uint32_t val) |
| 1322 | { |
| 1323 | return fdt_setprop_u32(fdt, nodeoffset, name, val); |
| 1324 | } |
| 1325 | |
| 1326 | /** |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1327 | * fdt_setprop_string - set a property to a string value |
| 1328 | * @fdt: pointer to the device tree blob |
| 1329 | * @nodeoffset: offset of the node whose property to change |
| 1330 | * @name: name of the property to change |
| 1331 | * @str: string value for the property |
| 1332 | * |
| 1333 | * fdt_setprop_string() sets the value of the named property in the |
| 1334 | * given node to the given string value (using the length of the |
| 1335 | * string to determine the new length of the property), or creates a |
| 1336 | * new property with that value if it does not already exist. |
| 1337 | * |
| 1338 | * This function may insert or delete data from the blob, and will |
| 1339 | * therefore change the offsets of some existing nodes. |
| 1340 | * |
| 1341 | * returns: |
| 1342 | * 0, on success |
| 1343 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to |
| 1344 | * contain the new property value |
| 1345 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1346 | * -FDT_ERR_BADLAYOUT, |
| 1347 | * -FDT_ERR_BADMAGIC, |
| 1348 | * -FDT_ERR_BADVERSION, |
| 1349 | * -FDT_ERR_BADSTATE, |
| 1350 | * -FDT_ERR_BADSTRUCTURE, |
| 1351 | * -FDT_ERR_BADLAYOUT, |
| 1352 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1353 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1354 | #define fdt_setprop_string(fdt, nodeoffset, name, str) \ |
| 1355 | fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1356 | |
| 1357 | /** |
Minghuan Lian | 3064827 | 2012-08-27 19:38:59 -0500 | [diff] [blame] | 1358 | * fdt_appendprop - append to or create a property |
| 1359 | * @fdt: pointer to the device tree blob |
| 1360 | * @nodeoffset: offset of the node whose property to change |
| 1361 | * @name: name of the property to append to |
| 1362 | * @val: pointer to data to append to the property value |
| 1363 | * @len: length of the data to append to the property value |
| 1364 | * |
| 1365 | * fdt_appendprop() appends the value to the named property in the |
| 1366 | * given node, creating the property if it does not already exist. |
| 1367 | * |
| 1368 | * This function may insert data into the blob, and will therefore |
| 1369 | * change the offsets of some existing nodes. |
| 1370 | * |
| 1371 | * returns: |
| 1372 | * 0, on success |
| 1373 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to |
| 1374 | * contain the new property value |
| 1375 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1376 | * -FDT_ERR_BADLAYOUT, |
| 1377 | * -FDT_ERR_BADMAGIC, |
| 1378 | * -FDT_ERR_BADVERSION, |
| 1379 | * -FDT_ERR_BADSTATE, |
| 1380 | * -FDT_ERR_BADSTRUCTURE, |
| 1381 | * -FDT_ERR_BADLAYOUT, |
| 1382 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1383 | */ |
| 1384 | int fdt_appendprop(void *fdt, int nodeoffset, const char *name, |
| 1385 | const void *val, int len); |
| 1386 | |
| 1387 | /** |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1388 | * fdt_appendprop_u32 - append a 32-bit integer value to a property |
Minghuan Lian | 3064827 | 2012-08-27 19:38:59 -0500 | [diff] [blame] | 1389 | * @fdt: pointer to the device tree blob |
| 1390 | * @nodeoffset: offset of the node whose property to change |
| 1391 | * @name: name of the property to change |
| 1392 | * @val: 32-bit integer value to append to the property (native endian) |
| 1393 | * |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1394 | * fdt_appendprop_u32() appends the given 32-bit integer value |
| 1395 | * (converting to big-endian if necessary) to the value of the named |
| 1396 | * property in the given node, or creates a new property with that |
| 1397 | * value if it does not already exist. |
Minghuan Lian | 3064827 | 2012-08-27 19:38:59 -0500 | [diff] [blame] | 1398 | * |
| 1399 | * This function may insert data into the blob, and will therefore |
| 1400 | * change the offsets of some existing nodes. |
| 1401 | * |
| 1402 | * returns: |
| 1403 | * 0, on success |
| 1404 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to |
| 1405 | * contain the new property value |
| 1406 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1407 | * -FDT_ERR_BADLAYOUT, |
| 1408 | * -FDT_ERR_BADMAGIC, |
| 1409 | * -FDT_ERR_BADVERSION, |
| 1410 | * -FDT_ERR_BADSTATE, |
| 1411 | * -FDT_ERR_BADSTRUCTURE, |
| 1412 | * -FDT_ERR_BADLAYOUT, |
| 1413 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1414 | */ |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1415 | static inline int fdt_appendprop_u32(void *fdt, int nodeoffset, |
| 1416 | const char *name, uint32_t val) |
Minghuan Lian | 3064827 | 2012-08-27 19:38:59 -0500 | [diff] [blame] | 1417 | { |
Kim Phillips | 38c3815 | 2013-01-16 13:59:50 +0000 | [diff] [blame] | 1418 | fdt32_t tmp = cpu_to_fdt32(val); |
| 1419 | return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); |
Minghuan Lian | 3064827 | 2012-08-27 19:38:59 -0500 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | /** |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1423 | * fdt_appendprop_u64 - append a 64-bit integer value to a property |
| 1424 | * @fdt: pointer to the device tree blob |
| 1425 | * @nodeoffset: offset of the node whose property to change |
| 1426 | * @name: name of the property to change |
| 1427 | * @val: 64-bit integer value to append to the property (native endian) |
| 1428 | * |
| 1429 | * fdt_appendprop_u64() appends the given 64-bit integer value |
| 1430 | * (converting to big-endian if necessary) to the value of the named |
| 1431 | * property in the given node, or creates a new property with that |
| 1432 | * value if it does not already exist. |
| 1433 | * |
| 1434 | * This function may insert data into the blob, and will therefore |
| 1435 | * change the offsets of some existing nodes. |
| 1436 | * |
| 1437 | * returns: |
| 1438 | * 0, on success |
| 1439 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to |
| 1440 | * contain the new property value |
| 1441 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1442 | * -FDT_ERR_BADLAYOUT, |
| 1443 | * -FDT_ERR_BADMAGIC, |
| 1444 | * -FDT_ERR_BADVERSION, |
| 1445 | * -FDT_ERR_BADSTATE, |
| 1446 | * -FDT_ERR_BADSTRUCTURE, |
| 1447 | * -FDT_ERR_BADLAYOUT, |
| 1448 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1449 | */ |
| 1450 | static inline int fdt_appendprop_u64(void *fdt, int nodeoffset, |
| 1451 | const char *name, uint64_t val) |
| 1452 | { |
Kim Phillips | 38c3815 | 2013-01-16 13:59:50 +0000 | [diff] [blame] | 1453 | fdt64_t tmp = cpu_to_fdt64(val); |
| 1454 | return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); |
David Gibson | b4afa9a | 2012-08-27 19:39:00 -0500 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | /** |
| 1458 | * fdt_appendprop_cell - append a single cell value to a property |
| 1459 | * |
| 1460 | * This is an alternative name for fdt_appendprop_u32() |
| 1461 | */ |
| 1462 | static inline int fdt_appendprop_cell(void *fdt, int nodeoffset, |
| 1463 | const char *name, uint32_t val) |
| 1464 | { |
| 1465 | return fdt_appendprop_u32(fdt, nodeoffset, name, val); |
| 1466 | } |
| 1467 | |
| 1468 | /** |
Minghuan Lian | 3064827 | 2012-08-27 19:38:59 -0500 | [diff] [blame] | 1469 | * fdt_appendprop_string - append a string to a property |
| 1470 | * @fdt: pointer to the device tree blob |
| 1471 | * @nodeoffset: offset of the node whose property to change |
| 1472 | * @name: name of the property to change |
| 1473 | * @str: string value to append to the property |
| 1474 | * |
| 1475 | * fdt_appendprop_string() appends the given string to the value of |
| 1476 | * the named property in the given node, or creates a new property |
| 1477 | * with that value if it does not already exist. |
| 1478 | * |
| 1479 | * This function may insert data into the blob, and will therefore |
| 1480 | * change the offsets of some existing nodes. |
| 1481 | * |
| 1482 | * returns: |
| 1483 | * 0, on success |
| 1484 | * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to |
| 1485 | * contain the new property value |
| 1486 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1487 | * -FDT_ERR_BADLAYOUT, |
| 1488 | * -FDT_ERR_BADMAGIC, |
| 1489 | * -FDT_ERR_BADVERSION, |
| 1490 | * -FDT_ERR_BADSTATE, |
| 1491 | * -FDT_ERR_BADSTRUCTURE, |
| 1492 | * -FDT_ERR_BADLAYOUT, |
| 1493 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1494 | */ |
| 1495 | #define fdt_appendprop_string(fdt, nodeoffset, name, str) \ |
| 1496 | fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) |
| 1497 | |
| 1498 | /** |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1499 | * fdt_delprop - delete a property |
| 1500 | * @fdt: pointer to the device tree blob |
| 1501 | * @nodeoffset: offset of the node whose property to nop |
| 1502 | * @name: name of the property to nop |
| 1503 | * |
| 1504 | * fdt_del_property() will delete the given property. |
| 1505 | * |
| 1506 | * This function will delete data from the blob, and will therefore |
| 1507 | * change the offsets of some existing nodes. |
| 1508 | * |
| 1509 | * returns: |
| 1510 | * 0, on success |
| 1511 | * -FDT_ERR_NOTFOUND, node does not have the named property |
| 1512 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1513 | * -FDT_ERR_BADLAYOUT, |
| 1514 | * -FDT_ERR_BADMAGIC, |
| 1515 | * -FDT_ERR_BADVERSION, |
| 1516 | * -FDT_ERR_BADSTATE, |
| 1517 | * -FDT_ERR_BADSTRUCTURE, |
| 1518 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1519 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1520 | int fdt_delprop(void *fdt, int nodeoffset, const char *name); |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1521 | |
| 1522 | /** |
| 1523 | * fdt_add_subnode_namelen - creates a new node based on substring |
| 1524 | * @fdt: pointer to the device tree blob |
| 1525 | * @parentoffset: structure block offset of a node |
| 1526 | * @name: name of the subnode to locate |
| 1527 | * @namelen: number of characters of name to consider |
| 1528 | * |
| 1529 | * Identical to fdt_add_subnode(), but use only the first namelen |
| 1530 | * characters of name as the name of the new node. This is useful for |
| 1531 | * creating subnodes based on a portion of a larger string, such as a |
| 1532 | * full path. |
| 1533 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1534 | int fdt_add_subnode_namelen(void *fdt, int parentoffset, |
| 1535 | const char *name, int namelen); |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1536 | |
| 1537 | /** |
| 1538 | * fdt_add_subnode - creates a new node |
| 1539 | * @fdt: pointer to the device tree blob |
| 1540 | * @parentoffset: structure block offset of a node |
| 1541 | * @name: name of the subnode to locate |
| 1542 | * |
| 1543 | * fdt_add_subnode() creates a new node as a subnode of the node at |
| 1544 | * structure block offset parentoffset, with the given name (which |
| 1545 | * should include the unit address, if any). |
| 1546 | * |
| 1547 | * This function will insert data into the blob, and will therefore |
| 1548 | * change the offsets of some existing nodes. |
| 1549 | |
| 1550 | * returns: |
| 1551 | * structure block offset of the created nodeequested subnode (>=0), on success |
| 1552 | * -FDT_ERR_NOTFOUND, if the requested subnode does not exist |
| 1553 | * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag |
| 1554 | * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of |
| 1555 | * the given name |
| 1556 | * -FDT_ERR_NOSPACE, if there is insufficient free space in the |
| 1557 | * blob to contain the new node |
| 1558 | * -FDT_ERR_NOSPACE |
| 1559 | * -FDT_ERR_BADLAYOUT |
| 1560 | * -FDT_ERR_BADMAGIC, |
| 1561 | * -FDT_ERR_BADVERSION, |
| 1562 | * -FDT_ERR_BADSTATE, |
| 1563 | * -FDT_ERR_BADSTRUCTURE, |
| 1564 | * -FDT_ERR_TRUNCATED, standard meanings. |
| 1565 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1566 | int fdt_add_subnode(void *fdt, int parentoffset, const char *name); |
David Gibson | 24d828f | 2007-12-17 14:42:07 +1100 | [diff] [blame] | 1567 | |
| 1568 | /** |
| 1569 | * fdt_del_node - delete a node (subtree) |
| 1570 | * @fdt: pointer to the device tree blob |
| 1571 | * @nodeoffset: offset of the node to nop |
| 1572 | * |
| 1573 | * fdt_del_node() will remove the given node, including all its |
| 1574 | * subnodes if any, from the blob. |
| 1575 | * |
| 1576 | * This function will delete data from the blob, and will therefore |
| 1577 | * change the offsets of some existing nodes. |
| 1578 | * |
| 1579 | * returns: |
| 1580 | * 0, on success |
| 1581 | * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag |
| 1582 | * -FDT_ERR_BADLAYOUT, |
| 1583 | * -FDT_ERR_BADMAGIC, |
| 1584 | * -FDT_ERR_BADVERSION, |
| 1585 | * -FDT_ERR_BADSTATE, |
| 1586 | * -FDT_ERR_BADSTRUCTURE, |
| 1587 | * -FDT_ERR_TRUNCATED, standard meanings |
| 1588 | */ |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1589 | int fdt_del_node(void *fdt, int nodeoffset); |
| 1590 | |
Kumar Gala | c8ab705 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 1591 | /**********************************************************************/ |
| 1592 | /* Debugging / informational functions */ |
| 1593 | /**********************************************************************/ |
| 1594 | |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1595 | const char *fdt_strerror(int errval); |
| 1596 | |
Simon Glass | b016702 | 2013-06-13 15:10:08 -0700 | [diff] [blame] | 1597 | struct fdt_region { |
| 1598 | int offset; |
| 1599 | int size; |
| 1600 | }; |
| 1601 | |
| 1602 | /** |
| 1603 | * fdt_find_regions() - find regions in device tree |
| 1604 | * |
| 1605 | * Given a list of nodes to include and properties to exclude, find |
| 1606 | * the regions of the device tree which describe those included parts. |
| 1607 | * |
| 1608 | * The intent is to get a list of regions which will be invariant provided |
| 1609 | * those parts are invariant. For example, if you request a list of regions |
| 1610 | * for all nodes but exclude the property "data", then you will get the |
| 1611 | * same region contents regardless of any change to "data" properties. |
| 1612 | * |
| 1613 | * This function can be used to produce a byte-stream to send to a hashing |
| 1614 | * function to verify that critical parts of the FDT have not changed. |
| 1615 | * |
| 1616 | * Nodes which are given in 'inc' are included in the region list, as |
| 1617 | * are the names of the immediate subnodes nodes (but not the properties |
| 1618 | * or subnodes of those subnodes). |
| 1619 | * |
| 1620 | * For eaxample "/" means to include the root node, all root properties |
| 1621 | * and the FDT_BEGIN_NODE and FDT_END_NODE of all subnodes of /. The latter |
| 1622 | * ensures that we capture the names of the subnodes. In a hashing situation |
| 1623 | * it prevents the root node from changing at all Any change to non-excluded |
| 1624 | * properties, names of subnodes or number of subnodes would be detected. |
| 1625 | * |
| 1626 | * When used with FITs this provides the ability to hash and sign parts of |
| 1627 | * the FIT based on different configurations in the FIT. Then it is |
| 1628 | * impossible to change anything about that configuration (include images |
| 1629 | * attached to the configuration), but it may be possible to add new |
| 1630 | * configurations, new images or new signatures within the existing |
| 1631 | * framework. |
| 1632 | * |
| 1633 | * Adding new properties to a device tree may result in the string table |
| 1634 | * being extended (if the new property names are different from those |
| 1635 | * already added). This function can optionally include a region for |
| 1636 | * the string table so that this can be part of the hash too. |
| 1637 | * |
| 1638 | * The device tree header is not included in the list. |
| 1639 | * |
| 1640 | * @fdt: Device tree to check |
| 1641 | * @inc: List of node paths to included |
| 1642 | * @inc_count: Number of node paths in list |
| 1643 | * @exc_prop: List of properties names to exclude |
| 1644 | * @exc_prop_count: Number of properties in exclude list |
| 1645 | * @region: Returns list of regions |
| 1646 | * @max_region: Maximum length of region list |
| 1647 | * @path: Pointer to a temporary string for the function to use for |
| 1648 | * building path names |
| 1649 | * @path_len: Length of path, must be large enough to hold the longest |
| 1650 | * path in the tree |
| 1651 | * @add_string_tab: 1 to add a region for the string table |
| 1652 | * @return number of regions in list. If this is >max_regions then the |
| 1653 | * region array was exhausted. You should increase max_regions and try |
| 1654 | * the call again. |
| 1655 | */ |
| 1656 | int fdt_find_regions(const void *fdt, char * const inc[], int inc_count, |
| 1657 | char * const exc_prop[], int exc_prop_count, |
| 1658 | struct fdt_region region[], int max_regions, |
| 1659 | char *path, int path_len, int add_string_tab); |
| 1660 | |
Gerald Van Baren | c0577a6 | 2007-03-31 11:59:59 -0400 | [diff] [blame] | 1661 | #endif /* _LIBFDT_H */ |