162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ 262306a36Sopenharmony_ci#ifndef LIBFDT_H 362306a36Sopenharmony_ci#define LIBFDT_H 462306a36Sopenharmony_ci/* 562306a36Sopenharmony_ci * libfdt - Flat Device Tree manipulation 662306a36Sopenharmony_ci * Copyright (C) 2006 David Gibson, IBM Corporation. 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include "libfdt_env.h" 1062306a36Sopenharmony_ci#include "fdt.h" 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#ifdef __cplusplus 1362306a36Sopenharmony_ciextern "C" { 1462306a36Sopenharmony_ci#endif 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#define FDT_FIRST_SUPPORTED_VERSION 0x02 1762306a36Sopenharmony_ci#define FDT_LAST_COMPATIBLE_VERSION 0x10 1862306a36Sopenharmony_ci#define FDT_LAST_SUPPORTED_VERSION 0x11 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci/* Error codes: informative error codes */ 2162306a36Sopenharmony_ci#define FDT_ERR_NOTFOUND 1 2262306a36Sopenharmony_ci /* FDT_ERR_NOTFOUND: The requested node or property does not exist */ 2362306a36Sopenharmony_ci#define FDT_ERR_EXISTS 2 2462306a36Sopenharmony_ci /* FDT_ERR_EXISTS: Attempted to create a node or property which 2562306a36Sopenharmony_ci * already exists */ 2662306a36Sopenharmony_ci#define FDT_ERR_NOSPACE 3 2762306a36Sopenharmony_ci /* FDT_ERR_NOSPACE: Operation needed to expand the device 2862306a36Sopenharmony_ci * tree, but its buffer did not have sufficient space to 2962306a36Sopenharmony_ci * contain the expanded tree. Use fdt_open_into() to move the 3062306a36Sopenharmony_ci * device tree to a buffer with more space. */ 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* Error codes: codes for bad parameters */ 3362306a36Sopenharmony_ci#define FDT_ERR_BADOFFSET 4 3462306a36Sopenharmony_ci /* FDT_ERR_BADOFFSET: Function was passed a structure block 3562306a36Sopenharmony_ci * offset which is out-of-bounds, or which points to an 3662306a36Sopenharmony_ci * unsuitable part of the structure for the operation. */ 3762306a36Sopenharmony_ci#define FDT_ERR_BADPATH 5 3862306a36Sopenharmony_ci /* FDT_ERR_BADPATH: Function was passed a badly formatted path 3962306a36Sopenharmony_ci * (e.g. missing a leading / for a function which requires an 4062306a36Sopenharmony_ci * absolute path) */ 4162306a36Sopenharmony_ci#define FDT_ERR_BADPHANDLE 6 4262306a36Sopenharmony_ci /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle. 4362306a36Sopenharmony_ci * This can be caused either by an invalid phandle property 4462306a36Sopenharmony_ci * length, or the phandle value was either 0 or -1, which are 4562306a36Sopenharmony_ci * not permitted. */ 4662306a36Sopenharmony_ci#define FDT_ERR_BADSTATE 7 4762306a36Sopenharmony_ci /* FDT_ERR_BADSTATE: Function was passed an incomplete device 4862306a36Sopenharmony_ci * tree created by the sequential-write functions, which is 4962306a36Sopenharmony_ci * not sufficiently complete for the requested operation. */ 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/* Error codes: codes for bad device tree blobs */ 5262306a36Sopenharmony_ci#define FDT_ERR_TRUNCATED 8 5362306a36Sopenharmony_ci /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly 5462306a36Sopenharmony_ci * terminated (overflows, goes outside allowed bounds, or 5562306a36Sopenharmony_ci * isn't properly terminated). */ 5662306a36Sopenharmony_ci#define FDT_ERR_BADMAGIC 9 5762306a36Sopenharmony_ci /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a 5862306a36Sopenharmony_ci * device tree at all - it is missing the flattened device 5962306a36Sopenharmony_ci * tree magic number. */ 6062306a36Sopenharmony_ci#define FDT_ERR_BADVERSION 10 6162306a36Sopenharmony_ci /* FDT_ERR_BADVERSION: Given device tree has a version which 6262306a36Sopenharmony_ci * can't be handled by the requested operation. For 6362306a36Sopenharmony_ci * read-write functions, this may mean that fdt_open_into() is 6462306a36Sopenharmony_ci * required to convert the tree to the expected version. */ 6562306a36Sopenharmony_ci#define FDT_ERR_BADSTRUCTURE 11 6662306a36Sopenharmony_ci /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt 6762306a36Sopenharmony_ci * structure block or other serious error (e.g. misnested 6862306a36Sopenharmony_ci * nodes, or subnodes preceding properties). */ 6962306a36Sopenharmony_ci#define FDT_ERR_BADLAYOUT 12 7062306a36Sopenharmony_ci /* FDT_ERR_BADLAYOUT: For read-write functions, the given 7162306a36Sopenharmony_ci * device tree has it's sub-blocks in an order that the 7262306a36Sopenharmony_ci * function can't handle (memory reserve map, then structure, 7362306a36Sopenharmony_ci * then strings). Use fdt_open_into() to reorganize the tree 7462306a36Sopenharmony_ci * into a form suitable for the read-write operations. */ 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci/* "Can't happen" error indicating a bug in libfdt */ 7762306a36Sopenharmony_ci#define FDT_ERR_INTERNAL 13 7862306a36Sopenharmony_ci /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion. 7962306a36Sopenharmony_ci * Should never be returned, if it is, it indicates a bug in 8062306a36Sopenharmony_ci * libfdt itself. */ 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci/* Errors in device tree content */ 8362306a36Sopenharmony_ci#define FDT_ERR_BADNCELLS 14 8462306a36Sopenharmony_ci /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells 8562306a36Sopenharmony_ci * or similar property with a bad format or value */ 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci#define FDT_ERR_BADVALUE 15 8862306a36Sopenharmony_ci /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected 8962306a36Sopenharmony_ci * value. For example: a property expected to contain a string list 9062306a36Sopenharmony_ci * is not NUL-terminated within the length of its value. */ 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci#define FDT_ERR_BADOVERLAY 16 9362306a36Sopenharmony_ci /* FDT_ERR_BADOVERLAY: The device tree overlay, while 9462306a36Sopenharmony_ci * correctly structured, cannot be applied due to some 9562306a36Sopenharmony_ci * unexpected or missing value, property or node. */ 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci#define FDT_ERR_NOPHANDLES 17 9862306a36Sopenharmony_ci /* FDT_ERR_NOPHANDLES: The device tree doesn't have any 9962306a36Sopenharmony_ci * phandle available anymore without causing an overflow */ 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#define FDT_ERR_BADFLAGS 18 10262306a36Sopenharmony_ci /* FDT_ERR_BADFLAGS: The function was passed a flags field that 10362306a36Sopenharmony_ci * contains invalid flags or an invalid combination of flags. */ 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci#define FDT_ERR_ALIGNMENT 19 10662306a36Sopenharmony_ci /* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte 10762306a36Sopenharmony_ci * aligned. */ 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci#define FDT_ERR_MAX 19 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci/* constants */ 11262306a36Sopenharmony_ci#define FDT_MAX_PHANDLE 0xfffffffe 11362306a36Sopenharmony_ci /* Valid values for phandles range from 1 to 2^32-2. */ 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci/**********************************************************************/ 11662306a36Sopenharmony_ci/* Low-level functions (you probably don't need these) */ 11762306a36Sopenharmony_ci/**********************************************************************/ 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci#ifndef SWIG /* This function is not useful in Python */ 12062306a36Sopenharmony_ciconst void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); 12162306a36Sopenharmony_ci#endif 12262306a36Sopenharmony_cistatic inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) 12362306a36Sopenharmony_ci{ 12462306a36Sopenharmony_ci return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); 12562306a36Sopenharmony_ci} 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ciuint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci/* 13062306a36Sopenharmony_ci * External helpers to access words from a device tree blob. They're built 13162306a36Sopenharmony_ci * to work even with unaligned pointers on platforms (such as ARMv5) that don't 13262306a36Sopenharmony_ci * like unaligned loads and stores. 13362306a36Sopenharmony_ci */ 13462306a36Sopenharmony_cistatic inline uint16_t fdt16_ld(const fdt16_t *p) 13562306a36Sopenharmony_ci{ 13662306a36Sopenharmony_ci const uint8_t *bp = (const uint8_t *)p; 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci return ((uint16_t)bp[0] << 8) | bp[1]; 13962306a36Sopenharmony_ci} 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_cistatic inline uint32_t fdt32_ld(const fdt32_t *p) 14262306a36Sopenharmony_ci{ 14362306a36Sopenharmony_ci const uint8_t *bp = (const uint8_t *)p; 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci return ((uint32_t)bp[0] << 24) 14662306a36Sopenharmony_ci | ((uint32_t)bp[1] << 16) 14762306a36Sopenharmony_ci | ((uint32_t)bp[2] << 8) 14862306a36Sopenharmony_ci | bp[3]; 14962306a36Sopenharmony_ci} 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_cistatic inline void fdt32_st(void *property, uint32_t value) 15262306a36Sopenharmony_ci{ 15362306a36Sopenharmony_ci uint8_t *bp = (uint8_t *)property; 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci bp[0] = value >> 24; 15662306a36Sopenharmony_ci bp[1] = (value >> 16) & 0xff; 15762306a36Sopenharmony_ci bp[2] = (value >> 8) & 0xff; 15862306a36Sopenharmony_ci bp[3] = value & 0xff; 15962306a36Sopenharmony_ci} 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_cistatic inline uint64_t fdt64_ld(const fdt64_t *p) 16262306a36Sopenharmony_ci{ 16362306a36Sopenharmony_ci const uint8_t *bp = (const uint8_t *)p; 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci return ((uint64_t)bp[0] << 56) 16662306a36Sopenharmony_ci | ((uint64_t)bp[1] << 48) 16762306a36Sopenharmony_ci | ((uint64_t)bp[2] << 40) 16862306a36Sopenharmony_ci | ((uint64_t)bp[3] << 32) 16962306a36Sopenharmony_ci | ((uint64_t)bp[4] << 24) 17062306a36Sopenharmony_ci | ((uint64_t)bp[5] << 16) 17162306a36Sopenharmony_ci | ((uint64_t)bp[6] << 8) 17262306a36Sopenharmony_ci | bp[7]; 17362306a36Sopenharmony_ci} 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_cistatic inline void fdt64_st(void *property, uint64_t value) 17662306a36Sopenharmony_ci{ 17762306a36Sopenharmony_ci uint8_t *bp = (uint8_t *)property; 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci bp[0] = value >> 56; 18062306a36Sopenharmony_ci bp[1] = (value >> 48) & 0xff; 18162306a36Sopenharmony_ci bp[2] = (value >> 40) & 0xff; 18262306a36Sopenharmony_ci bp[3] = (value >> 32) & 0xff; 18362306a36Sopenharmony_ci bp[4] = (value >> 24) & 0xff; 18462306a36Sopenharmony_ci bp[5] = (value >> 16) & 0xff; 18562306a36Sopenharmony_ci bp[6] = (value >> 8) & 0xff; 18662306a36Sopenharmony_ci bp[7] = value & 0xff; 18762306a36Sopenharmony_ci} 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci/**********************************************************************/ 19062306a36Sopenharmony_ci/* Traversal functions */ 19162306a36Sopenharmony_ci/**********************************************************************/ 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ciint fdt_next_node(const void *fdt, int offset, int *depth); 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ci/** 19662306a36Sopenharmony_ci * fdt_first_subnode() - get offset of first direct subnode 19762306a36Sopenharmony_ci * @fdt: FDT blob 19862306a36Sopenharmony_ci * @offset: Offset of node to check 19962306a36Sopenharmony_ci * 20062306a36Sopenharmony_ci * Return: offset of first subnode, or -FDT_ERR_NOTFOUND if there is none 20162306a36Sopenharmony_ci */ 20262306a36Sopenharmony_ciint fdt_first_subnode(const void *fdt, int offset); 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ci/** 20562306a36Sopenharmony_ci * fdt_next_subnode() - get offset of next direct subnode 20662306a36Sopenharmony_ci * @fdt: FDT blob 20762306a36Sopenharmony_ci * @offset: Offset of previous subnode 20862306a36Sopenharmony_ci * 20962306a36Sopenharmony_ci * After first calling fdt_first_subnode(), call this function repeatedly to 21062306a36Sopenharmony_ci * get direct subnodes of a parent node. 21162306a36Sopenharmony_ci * 21262306a36Sopenharmony_ci * Return: offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more 21362306a36Sopenharmony_ci * subnodes 21462306a36Sopenharmony_ci */ 21562306a36Sopenharmony_ciint fdt_next_subnode(const void *fdt, int offset); 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci/** 21862306a36Sopenharmony_ci * fdt_for_each_subnode - iterate over all subnodes of a parent 21962306a36Sopenharmony_ci * 22062306a36Sopenharmony_ci * @node: child node (int, lvalue) 22162306a36Sopenharmony_ci * @fdt: FDT blob (const void *) 22262306a36Sopenharmony_ci * @parent: parent node (int) 22362306a36Sopenharmony_ci * 22462306a36Sopenharmony_ci * This is actually a wrapper around a for loop and would be used like so: 22562306a36Sopenharmony_ci * 22662306a36Sopenharmony_ci * fdt_for_each_subnode(node, fdt, parent) { 22762306a36Sopenharmony_ci * Use node 22862306a36Sopenharmony_ci * ... 22962306a36Sopenharmony_ci * } 23062306a36Sopenharmony_ci * 23162306a36Sopenharmony_ci * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) { 23262306a36Sopenharmony_ci * Error handling 23362306a36Sopenharmony_ci * } 23462306a36Sopenharmony_ci * 23562306a36Sopenharmony_ci * Note that this is implemented as a macro and @node is used as 23662306a36Sopenharmony_ci * iterator in the loop. The parent variable be constant or even a 23762306a36Sopenharmony_ci * literal. 23862306a36Sopenharmony_ci */ 23962306a36Sopenharmony_ci#define fdt_for_each_subnode(node, fdt, parent) \ 24062306a36Sopenharmony_ci for (node = fdt_first_subnode(fdt, parent); \ 24162306a36Sopenharmony_ci node >= 0; \ 24262306a36Sopenharmony_ci node = fdt_next_subnode(fdt, node)) 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci/**********************************************************************/ 24562306a36Sopenharmony_ci/* General functions */ 24662306a36Sopenharmony_ci/**********************************************************************/ 24762306a36Sopenharmony_ci#define fdt_get_header(fdt, field) \ 24862306a36Sopenharmony_ci (fdt32_ld(&((const struct fdt_header *)(fdt))->field)) 24962306a36Sopenharmony_ci#define fdt_magic(fdt) (fdt_get_header(fdt, magic)) 25062306a36Sopenharmony_ci#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) 25162306a36Sopenharmony_ci#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) 25262306a36Sopenharmony_ci#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) 25362306a36Sopenharmony_ci#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) 25462306a36Sopenharmony_ci#define fdt_version(fdt) (fdt_get_header(fdt, version)) 25562306a36Sopenharmony_ci#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) 25662306a36Sopenharmony_ci#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) 25762306a36Sopenharmony_ci#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) 25862306a36Sopenharmony_ci#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci#define fdt_set_hdr_(name) \ 26162306a36Sopenharmony_ci static inline void fdt_set_##name(void *fdt, uint32_t val) \ 26262306a36Sopenharmony_ci { \ 26362306a36Sopenharmony_ci struct fdt_header *fdth = (struct fdt_header *)fdt; \ 26462306a36Sopenharmony_ci fdth->name = cpu_to_fdt32(val); \ 26562306a36Sopenharmony_ci } 26662306a36Sopenharmony_cifdt_set_hdr_(magic); 26762306a36Sopenharmony_cifdt_set_hdr_(totalsize); 26862306a36Sopenharmony_cifdt_set_hdr_(off_dt_struct); 26962306a36Sopenharmony_cifdt_set_hdr_(off_dt_strings); 27062306a36Sopenharmony_cifdt_set_hdr_(off_mem_rsvmap); 27162306a36Sopenharmony_cifdt_set_hdr_(version); 27262306a36Sopenharmony_cifdt_set_hdr_(last_comp_version); 27362306a36Sopenharmony_cifdt_set_hdr_(boot_cpuid_phys); 27462306a36Sopenharmony_cifdt_set_hdr_(size_dt_strings); 27562306a36Sopenharmony_cifdt_set_hdr_(size_dt_struct); 27662306a36Sopenharmony_ci#undef fdt_set_hdr_ 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci/** 27962306a36Sopenharmony_ci * fdt_header_size - return the size of the tree's header 28062306a36Sopenharmony_ci * @fdt: pointer to a flattened device tree 28162306a36Sopenharmony_ci * 28262306a36Sopenharmony_ci * Return: size of DTB header in bytes 28362306a36Sopenharmony_ci */ 28462306a36Sopenharmony_cisize_t fdt_header_size(const void *fdt); 28562306a36Sopenharmony_ci 28662306a36Sopenharmony_ci/** 28762306a36Sopenharmony_ci * fdt_header_size_ - internal function to get header size from a version number 28862306a36Sopenharmony_ci * @version: devicetree version number 28962306a36Sopenharmony_ci * 29062306a36Sopenharmony_ci * Return: size of DTB header in bytes 29162306a36Sopenharmony_ci */ 29262306a36Sopenharmony_cisize_t fdt_header_size_(uint32_t version); 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ci/** 29562306a36Sopenharmony_ci * fdt_check_header - sanity check a device tree header 29662306a36Sopenharmony_ci * @fdt: pointer to data which might be a flattened device tree 29762306a36Sopenharmony_ci * 29862306a36Sopenharmony_ci * fdt_check_header() checks that the given buffer contains what 29962306a36Sopenharmony_ci * appears to be a flattened device tree, and that the header contains 30062306a36Sopenharmony_ci * valid information (to the extent that can be determined from the 30162306a36Sopenharmony_ci * header alone). 30262306a36Sopenharmony_ci * 30362306a36Sopenharmony_ci * returns: 30462306a36Sopenharmony_ci * 0, if the buffer appears to contain a valid device tree 30562306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 30662306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 30762306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 30862306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings, as above 30962306a36Sopenharmony_ci */ 31062306a36Sopenharmony_ciint fdt_check_header(const void *fdt); 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ci/** 31362306a36Sopenharmony_ci * fdt_move - move a device tree around in memory 31462306a36Sopenharmony_ci * @fdt: pointer to the device tree to move 31562306a36Sopenharmony_ci * @buf: pointer to memory where the device is to be moved 31662306a36Sopenharmony_ci * @bufsize: size of the memory space at buf 31762306a36Sopenharmony_ci * 31862306a36Sopenharmony_ci * fdt_move() relocates, if possible, the device tree blob located at 31962306a36Sopenharmony_ci * fdt to the buffer at buf of size bufsize. The buffer may overlap 32062306a36Sopenharmony_ci * with the existing device tree blob at fdt. Therefore, 32162306a36Sopenharmony_ci * fdt_move(fdt, fdt, fdt_totalsize(fdt)) 32262306a36Sopenharmony_ci * should always succeed. 32362306a36Sopenharmony_ci * 32462306a36Sopenharmony_ci * returns: 32562306a36Sopenharmony_ci * 0, on success 32662306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree 32762306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 32862306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 32962306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, standard meanings 33062306a36Sopenharmony_ci */ 33162306a36Sopenharmony_ciint fdt_move(const void *fdt, void *buf, int bufsize); 33262306a36Sopenharmony_ci 33362306a36Sopenharmony_ci/**********************************************************************/ 33462306a36Sopenharmony_ci/* Read-only functions */ 33562306a36Sopenharmony_ci/**********************************************************************/ 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ciint fdt_check_full(const void *fdt, size_t bufsize); 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci/** 34062306a36Sopenharmony_ci * fdt_get_string - retrieve a string from the strings block of a device tree 34162306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 34262306a36Sopenharmony_ci * @stroffset: offset of the string within the strings block (native endian) 34362306a36Sopenharmony_ci * @lenp: optional pointer to return the string's length 34462306a36Sopenharmony_ci * 34562306a36Sopenharmony_ci * fdt_get_string() retrieves a pointer to a single string from the 34662306a36Sopenharmony_ci * strings block of the device tree blob at fdt, and optionally also 34762306a36Sopenharmony_ci * returns the string's length in *lenp. 34862306a36Sopenharmony_ci * 34962306a36Sopenharmony_ci * returns: 35062306a36Sopenharmony_ci * a pointer to the string, on success 35162306a36Sopenharmony_ci * NULL, if stroffset is out of bounds, or doesn't point to a valid string 35262306a36Sopenharmony_ci */ 35362306a36Sopenharmony_ciconst char *fdt_get_string(const void *fdt, int stroffset, int *lenp); 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_ci/** 35662306a36Sopenharmony_ci * fdt_string - retrieve a string from the strings block of a device tree 35762306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 35862306a36Sopenharmony_ci * @stroffset: offset of the string within the strings block (native endian) 35962306a36Sopenharmony_ci * 36062306a36Sopenharmony_ci * fdt_string() retrieves a pointer to a single string from the 36162306a36Sopenharmony_ci * strings block of the device tree blob at fdt. 36262306a36Sopenharmony_ci * 36362306a36Sopenharmony_ci * returns: 36462306a36Sopenharmony_ci * a pointer to the string, on success 36562306a36Sopenharmony_ci * NULL, if stroffset is out of bounds, or doesn't point to a valid string 36662306a36Sopenharmony_ci */ 36762306a36Sopenharmony_ciconst char *fdt_string(const void *fdt, int stroffset); 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_ci/** 37062306a36Sopenharmony_ci * fdt_find_max_phandle - find and return the highest phandle in a tree 37162306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 37262306a36Sopenharmony_ci * @phandle: return location for the highest phandle value found in the tree 37362306a36Sopenharmony_ci * 37462306a36Sopenharmony_ci * fdt_find_max_phandle() finds the highest phandle value in the given device 37562306a36Sopenharmony_ci * tree. The value returned in @phandle is only valid if the function returns 37662306a36Sopenharmony_ci * success. 37762306a36Sopenharmony_ci * 37862306a36Sopenharmony_ci * returns: 37962306a36Sopenharmony_ci * 0 on success or a negative error code on failure 38062306a36Sopenharmony_ci */ 38162306a36Sopenharmony_ciint fdt_find_max_phandle(const void *fdt, uint32_t *phandle); 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ci/** 38462306a36Sopenharmony_ci * fdt_get_max_phandle - retrieves the highest phandle in a tree 38562306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 38662306a36Sopenharmony_ci * 38762306a36Sopenharmony_ci * fdt_get_max_phandle retrieves the highest phandle in the given 38862306a36Sopenharmony_ci * device tree. This will ignore badly formatted phandles, or phandles 38962306a36Sopenharmony_ci * with a value of 0 or -1. 39062306a36Sopenharmony_ci * 39162306a36Sopenharmony_ci * This function is deprecated in favour of fdt_find_max_phandle(). 39262306a36Sopenharmony_ci * 39362306a36Sopenharmony_ci * returns: 39462306a36Sopenharmony_ci * the highest phandle on success 39562306a36Sopenharmony_ci * 0, if no phandle was found in the device tree 39662306a36Sopenharmony_ci * -1, if an error occurred 39762306a36Sopenharmony_ci */ 39862306a36Sopenharmony_cistatic inline uint32_t fdt_get_max_phandle(const void *fdt) 39962306a36Sopenharmony_ci{ 40062306a36Sopenharmony_ci uint32_t phandle; 40162306a36Sopenharmony_ci int err; 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci err = fdt_find_max_phandle(fdt, &phandle); 40462306a36Sopenharmony_ci if (err < 0) 40562306a36Sopenharmony_ci return (uint32_t)-1; 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ci return phandle; 40862306a36Sopenharmony_ci} 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_ci/** 41162306a36Sopenharmony_ci * fdt_generate_phandle - return a new, unused phandle for a device tree blob 41262306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 41362306a36Sopenharmony_ci * @phandle: return location for the new phandle 41462306a36Sopenharmony_ci * 41562306a36Sopenharmony_ci * Walks the device tree blob and looks for the highest phandle value. On 41662306a36Sopenharmony_ci * success, the new, unused phandle value (one higher than the previously 41762306a36Sopenharmony_ci * highest phandle value in the device tree blob) will be returned in the 41862306a36Sopenharmony_ci * @phandle parameter. 41962306a36Sopenharmony_ci * 42062306a36Sopenharmony_ci * Return: 0 on success or a negative error-code on failure 42162306a36Sopenharmony_ci */ 42262306a36Sopenharmony_ciint fdt_generate_phandle(const void *fdt, uint32_t *phandle); 42362306a36Sopenharmony_ci 42462306a36Sopenharmony_ci/** 42562306a36Sopenharmony_ci * fdt_num_mem_rsv - retrieve the number of memory reserve map entries 42662306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 42762306a36Sopenharmony_ci * 42862306a36Sopenharmony_ci * Returns the number of entries in the device tree blob's memory 42962306a36Sopenharmony_ci * reservation map. This does not include the terminating 0,0 entry 43062306a36Sopenharmony_ci * or any other (0,0) entries reserved for expansion. 43162306a36Sopenharmony_ci * 43262306a36Sopenharmony_ci * returns: 43362306a36Sopenharmony_ci * the number of entries 43462306a36Sopenharmony_ci */ 43562306a36Sopenharmony_ciint fdt_num_mem_rsv(const void *fdt); 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_ci/** 43862306a36Sopenharmony_ci * fdt_get_mem_rsv - retrieve one memory reserve map entry 43962306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 44062306a36Sopenharmony_ci * @n: index of reserve map entry 44162306a36Sopenharmony_ci * @address: pointer to 64-bit variable to hold the start address 44262306a36Sopenharmony_ci * @size: pointer to 64-bit variable to hold the size of the entry 44362306a36Sopenharmony_ci * 44462306a36Sopenharmony_ci * On success, @address and @size will contain the address and size of 44562306a36Sopenharmony_ci * the n-th reserve map entry from the device tree blob, in 44662306a36Sopenharmony_ci * native-endian format. 44762306a36Sopenharmony_ci * 44862306a36Sopenharmony_ci * returns: 44962306a36Sopenharmony_ci * 0, on success 45062306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 45162306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 45262306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, standard meanings 45362306a36Sopenharmony_ci */ 45462306a36Sopenharmony_ciint fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size); 45562306a36Sopenharmony_ci 45662306a36Sopenharmony_ci/** 45762306a36Sopenharmony_ci * fdt_subnode_offset_namelen - find a subnode based on substring 45862306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 45962306a36Sopenharmony_ci * @parentoffset: structure block offset of a node 46062306a36Sopenharmony_ci * @name: name of the subnode to locate 46162306a36Sopenharmony_ci * @namelen: number of characters of name to consider 46262306a36Sopenharmony_ci * 46362306a36Sopenharmony_ci * Identical to fdt_subnode_offset(), but only examine the first 46462306a36Sopenharmony_ci * namelen characters of name for matching the subnode name. This is 46562306a36Sopenharmony_ci * useful for finding subnodes based on a portion of a larger string, 46662306a36Sopenharmony_ci * such as a full path. 46762306a36Sopenharmony_ci * 46862306a36Sopenharmony_ci * Return: offset of the subnode or -FDT_ERR_NOTFOUND if name not found. 46962306a36Sopenharmony_ci */ 47062306a36Sopenharmony_ci#ifndef SWIG /* Not available in Python */ 47162306a36Sopenharmony_ciint fdt_subnode_offset_namelen(const void *fdt, int parentoffset, 47262306a36Sopenharmony_ci const char *name, int namelen); 47362306a36Sopenharmony_ci#endif 47462306a36Sopenharmony_ci/** 47562306a36Sopenharmony_ci * fdt_subnode_offset - find a subnode of a given node 47662306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 47762306a36Sopenharmony_ci * @parentoffset: structure block offset of a node 47862306a36Sopenharmony_ci * @name: name of the subnode to locate 47962306a36Sopenharmony_ci * 48062306a36Sopenharmony_ci * fdt_subnode_offset() finds a subnode of the node at structure block 48162306a36Sopenharmony_ci * offset parentoffset with the given name. name may include a unit 48262306a36Sopenharmony_ci * address, in which case fdt_subnode_offset() will find the subnode 48362306a36Sopenharmony_ci * with that unit address, or the unit address may be omitted, in 48462306a36Sopenharmony_ci * which case fdt_subnode_offset() will find an arbitrary subnode 48562306a36Sopenharmony_ci * whose name excluding unit address matches the given name. 48662306a36Sopenharmony_ci * 48762306a36Sopenharmony_ci * returns: 48862306a36Sopenharmony_ci * structure block offset of the requested subnode (>=0), on success 48962306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, if the requested subnode does not exist 49062306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE 49162306a36Sopenharmony_ci * tag 49262306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 49362306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 49462306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 49562306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 49662306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings. 49762306a36Sopenharmony_ci */ 49862306a36Sopenharmony_ciint fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_ci/** 50162306a36Sopenharmony_ci * fdt_path_offset_namelen - find a tree node by its full path 50262306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 50362306a36Sopenharmony_ci * @path: full path of the node to locate 50462306a36Sopenharmony_ci * @namelen: number of characters of path to consider 50562306a36Sopenharmony_ci * 50662306a36Sopenharmony_ci * Identical to fdt_path_offset(), but only consider the first namelen 50762306a36Sopenharmony_ci * characters of path as the path name. 50862306a36Sopenharmony_ci * 50962306a36Sopenharmony_ci * Return: offset of the node or negative libfdt error value otherwise 51062306a36Sopenharmony_ci */ 51162306a36Sopenharmony_ci#ifndef SWIG /* Not available in Python */ 51262306a36Sopenharmony_ciint fdt_path_offset_namelen(const void *fdt, const char *path, int namelen); 51362306a36Sopenharmony_ci#endif 51462306a36Sopenharmony_ci 51562306a36Sopenharmony_ci/** 51662306a36Sopenharmony_ci * fdt_path_offset - find a tree node by its full path 51762306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 51862306a36Sopenharmony_ci * @path: full path of the node to locate 51962306a36Sopenharmony_ci * 52062306a36Sopenharmony_ci * fdt_path_offset() finds a node of a given path in the device tree. 52162306a36Sopenharmony_ci * Each path component may omit the unit address portion, but the 52262306a36Sopenharmony_ci * results of this are undefined if any such path component is 52362306a36Sopenharmony_ci * ambiguous (that is if there are multiple nodes at the relevant 52462306a36Sopenharmony_ci * level matching the given component, differentiated only by unit 52562306a36Sopenharmony_ci * address). 52662306a36Sopenharmony_ci * 52762306a36Sopenharmony_ci * returns: 52862306a36Sopenharmony_ci * structure block offset of the node with the requested path (>=0), on 52962306a36Sopenharmony_ci * success 53062306a36Sopenharmony_ci * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid 53162306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, if the requested node does not exist 53262306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 53362306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 53462306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 53562306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 53662306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings. 53762306a36Sopenharmony_ci */ 53862306a36Sopenharmony_ciint fdt_path_offset(const void *fdt, const char *path); 53962306a36Sopenharmony_ci 54062306a36Sopenharmony_ci/** 54162306a36Sopenharmony_ci * fdt_get_name - retrieve the name of a given node 54262306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 54362306a36Sopenharmony_ci * @nodeoffset: structure block offset of the starting node 54462306a36Sopenharmony_ci * @lenp: pointer to an integer variable (will be overwritten) or NULL 54562306a36Sopenharmony_ci * 54662306a36Sopenharmony_ci * fdt_get_name() retrieves the name (including unit address) of the 54762306a36Sopenharmony_ci * device tree node at structure block offset nodeoffset. If lenp is 54862306a36Sopenharmony_ci * non-NULL, the length of this name is also returned, in the integer 54962306a36Sopenharmony_ci * pointed to by lenp. 55062306a36Sopenharmony_ci * 55162306a36Sopenharmony_ci * returns: 55262306a36Sopenharmony_ci * pointer to the node's name, on success 55362306a36Sopenharmony_ci * If lenp is non-NULL, *lenp contains the length of that name 55462306a36Sopenharmony_ci * (>=0) 55562306a36Sopenharmony_ci * NULL, on error 55662306a36Sopenharmony_ci * if lenp is non-NULL *lenp contains an error code (<0): 55762306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE 55862306a36Sopenharmony_ci * tag 55962306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 56062306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 56162306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, standard meanings 56262306a36Sopenharmony_ci */ 56362306a36Sopenharmony_ciconst char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp); 56462306a36Sopenharmony_ci 56562306a36Sopenharmony_ci/** 56662306a36Sopenharmony_ci * fdt_first_property_offset - find the offset of a node's first property 56762306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 56862306a36Sopenharmony_ci * @nodeoffset: structure block offset of a node 56962306a36Sopenharmony_ci * 57062306a36Sopenharmony_ci * fdt_first_property_offset() finds the first property of the node at 57162306a36Sopenharmony_ci * the given structure block offset. 57262306a36Sopenharmony_ci * 57362306a36Sopenharmony_ci * returns: 57462306a36Sopenharmony_ci * structure block offset of the property (>=0), on success 57562306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, if the requested node has no properties 57662306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag 57762306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 57862306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 57962306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 58062306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 58162306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings. 58262306a36Sopenharmony_ci */ 58362306a36Sopenharmony_ciint fdt_first_property_offset(const void *fdt, int nodeoffset); 58462306a36Sopenharmony_ci 58562306a36Sopenharmony_ci/** 58662306a36Sopenharmony_ci * fdt_next_property_offset - step through a node's properties 58762306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 58862306a36Sopenharmony_ci * @offset: structure block offset of a property 58962306a36Sopenharmony_ci * 59062306a36Sopenharmony_ci * fdt_next_property_offset() finds the property immediately after the 59162306a36Sopenharmony_ci * one at the given structure block offset. This will be a property 59262306a36Sopenharmony_ci * of the same node as the given property. 59362306a36Sopenharmony_ci * 59462306a36Sopenharmony_ci * returns: 59562306a36Sopenharmony_ci * structure block offset of the next property (>=0), on success 59662306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, if the given property is the last in its node 59762306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag 59862306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 59962306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 60062306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 60162306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 60262306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings. 60362306a36Sopenharmony_ci */ 60462306a36Sopenharmony_ciint fdt_next_property_offset(const void *fdt, int offset); 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_ci/** 60762306a36Sopenharmony_ci * fdt_for_each_property_offset - iterate over all properties of a node 60862306a36Sopenharmony_ci * 60962306a36Sopenharmony_ci * @property: property offset (int, lvalue) 61062306a36Sopenharmony_ci * @fdt: FDT blob (const void *) 61162306a36Sopenharmony_ci * @node: node offset (int) 61262306a36Sopenharmony_ci * 61362306a36Sopenharmony_ci * This is actually a wrapper around a for loop and would be used like so: 61462306a36Sopenharmony_ci * 61562306a36Sopenharmony_ci * fdt_for_each_property_offset(property, fdt, node) { 61662306a36Sopenharmony_ci * Use property 61762306a36Sopenharmony_ci * ... 61862306a36Sopenharmony_ci * } 61962306a36Sopenharmony_ci * 62062306a36Sopenharmony_ci * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) { 62162306a36Sopenharmony_ci * Error handling 62262306a36Sopenharmony_ci * } 62362306a36Sopenharmony_ci * 62462306a36Sopenharmony_ci * Note that this is implemented as a macro and property is used as 62562306a36Sopenharmony_ci * iterator in the loop. The node variable can be constant or even a 62662306a36Sopenharmony_ci * literal. 62762306a36Sopenharmony_ci */ 62862306a36Sopenharmony_ci#define fdt_for_each_property_offset(property, fdt, node) \ 62962306a36Sopenharmony_ci for (property = fdt_first_property_offset(fdt, node); \ 63062306a36Sopenharmony_ci property >= 0; \ 63162306a36Sopenharmony_ci property = fdt_next_property_offset(fdt, property)) 63262306a36Sopenharmony_ci 63362306a36Sopenharmony_ci/** 63462306a36Sopenharmony_ci * fdt_get_property_by_offset - retrieve the property at a given offset 63562306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 63662306a36Sopenharmony_ci * @offset: offset of the property to retrieve 63762306a36Sopenharmony_ci * @lenp: pointer to an integer variable (will be overwritten) or NULL 63862306a36Sopenharmony_ci * 63962306a36Sopenharmony_ci * fdt_get_property_by_offset() retrieves a pointer to the 64062306a36Sopenharmony_ci * fdt_property structure within the device tree blob at the given 64162306a36Sopenharmony_ci * offset. If lenp is non-NULL, the length of the property value is 64262306a36Sopenharmony_ci * also returned, in the integer pointed to by lenp. 64362306a36Sopenharmony_ci * 64462306a36Sopenharmony_ci * Note that this code only works on device tree versions >= 16. fdt_getprop() 64562306a36Sopenharmony_ci * works on all versions. 64662306a36Sopenharmony_ci * 64762306a36Sopenharmony_ci * returns: 64862306a36Sopenharmony_ci * pointer to the structure representing the property 64962306a36Sopenharmony_ci * if lenp is non-NULL, *lenp contains the length of the property 65062306a36Sopenharmony_ci * value (>=0) 65162306a36Sopenharmony_ci * NULL, on error 65262306a36Sopenharmony_ci * if lenp is non-NULL, *lenp contains an error code (<0): 65362306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag 65462306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 65562306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 65662306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 65762306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 65862306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 65962306a36Sopenharmony_ci */ 66062306a36Sopenharmony_ciconst struct fdt_property *fdt_get_property_by_offset(const void *fdt, 66162306a36Sopenharmony_ci int offset, 66262306a36Sopenharmony_ci int *lenp); 66362306a36Sopenharmony_cistatic inline struct fdt_property *fdt_get_property_by_offset_w(void *fdt, 66462306a36Sopenharmony_ci int offset, 66562306a36Sopenharmony_ci int *lenp) 66662306a36Sopenharmony_ci{ 66762306a36Sopenharmony_ci return (struct fdt_property *)(uintptr_t) 66862306a36Sopenharmony_ci fdt_get_property_by_offset(fdt, offset, lenp); 66962306a36Sopenharmony_ci} 67062306a36Sopenharmony_ci 67162306a36Sopenharmony_ci/** 67262306a36Sopenharmony_ci * fdt_get_property_namelen - find a property based on substring 67362306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 67462306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to find 67562306a36Sopenharmony_ci * @name: name of the property to find 67662306a36Sopenharmony_ci * @namelen: number of characters of name to consider 67762306a36Sopenharmony_ci * @lenp: pointer to an integer variable (will be overwritten) or NULL 67862306a36Sopenharmony_ci * 67962306a36Sopenharmony_ci * Identical to fdt_get_property(), but only examine the first namelen 68062306a36Sopenharmony_ci * characters of name for matching the property name. 68162306a36Sopenharmony_ci * 68262306a36Sopenharmony_ci * Return: pointer to the structure representing the property, or NULL 68362306a36Sopenharmony_ci * if not found 68462306a36Sopenharmony_ci */ 68562306a36Sopenharmony_ci#ifndef SWIG /* Not available in Python */ 68662306a36Sopenharmony_ciconst struct fdt_property *fdt_get_property_namelen(const void *fdt, 68762306a36Sopenharmony_ci int nodeoffset, 68862306a36Sopenharmony_ci const char *name, 68962306a36Sopenharmony_ci int namelen, int *lenp); 69062306a36Sopenharmony_ci#endif 69162306a36Sopenharmony_ci 69262306a36Sopenharmony_ci/** 69362306a36Sopenharmony_ci * fdt_get_property - find a given property in a given node 69462306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 69562306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to find 69662306a36Sopenharmony_ci * @name: name of the property to find 69762306a36Sopenharmony_ci * @lenp: pointer to an integer variable (will be overwritten) or NULL 69862306a36Sopenharmony_ci * 69962306a36Sopenharmony_ci * fdt_get_property() retrieves a pointer to the fdt_property 70062306a36Sopenharmony_ci * structure within the device tree blob corresponding to the property 70162306a36Sopenharmony_ci * named 'name' of the node at offset nodeoffset. If lenp is 70262306a36Sopenharmony_ci * non-NULL, the length of the property value is also returned, in the 70362306a36Sopenharmony_ci * integer pointed to by lenp. 70462306a36Sopenharmony_ci * 70562306a36Sopenharmony_ci * returns: 70662306a36Sopenharmony_ci * pointer to the structure representing the property 70762306a36Sopenharmony_ci * if lenp is non-NULL, *lenp contains the length of the property 70862306a36Sopenharmony_ci * value (>=0) 70962306a36Sopenharmony_ci * NULL, on error 71062306a36Sopenharmony_ci * if lenp is non-NULL, *lenp contains an error code (<0): 71162306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, node does not have named property 71262306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE 71362306a36Sopenharmony_ci * tag 71462306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 71562306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 71662306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 71762306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 71862306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 71962306a36Sopenharmony_ci */ 72062306a36Sopenharmony_ciconst struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset, 72162306a36Sopenharmony_ci const char *name, int *lenp); 72262306a36Sopenharmony_cistatic inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset, 72362306a36Sopenharmony_ci const char *name, 72462306a36Sopenharmony_ci int *lenp) 72562306a36Sopenharmony_ci{ 72662306a36Sopenharmony_ci return (struct fdt_property *)(uintptr_t) 72762306a36Sopenharmony_ci fdt_get_property(fdt, nodeoffset, name, lenp); 72862306a36Sopenharmony_ci} 72962306a36Sopenharmony_ci 73062306a36Sopenharmony_ci/** 73162306a36Sopenharmony_ci * fdt_getprop_by_offset - retrieve the value of a property at a given offset 73262306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 73362306a36Sopenharmony_ci * @offset: offset of the property to read 73462306a36Sopenharmony_ci * @namep: pointer to a string variable (will be overwritten) or NULL 73562306a36Sopenharmony_ci * @lenp: pointer to an integer variable (will be overwritten) or NULL 73662306a36Sopenharmony_ci * 73762306a36Sopenharmony_ci * fdt_getprop_by_offset() retrieves a pointer to the value of the 73862306a36Sopenharmony_ci * property at structure block offset 'offset' (this will be a pointer 73962306a36Sopenharmony_ci * to within the device blob itself, not a copy of the value). If 74062306a36Sopenharmony_ci * lenp is non-NULL, the length of the property value is also 74162306a36Sopenharmony_ci * returned, in the integer pointed to by lenp. If namep is non-NULL, 74262306a36Sopenharmony_ci * the property's namne will also be returned in the char * pointed to 74362306a36Sopenharmony_ci * by namep (this will be a pointer to within the device tree's string 74462306a36Sopenharmony_ci * block, not a new copy of the name). 74562306a36Sopenharmony_ci * 74662306a36Sopenharmony_ci * returns: 74762306a36Sopenharmony_ci * pointer to the property's value 74862306a36Sopenharmony_ci * if lenp is non-NULL, *lenp contains the length of the property 74962306a36Sopenharmony_ci * value (>=0) 75062306a36Sopenharmony_ci * if namep is non-NULL *namep contiains a pointer to the property 75162306a36Sopenharmony_ci * name. 75262306a36Sopenharmony_ci * NULL, on error 75362306a36Sopenharmony_ci * if lenp is non-NULL, *lenp contains an error code (<0): 75462306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag 75562306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 75662306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 75762306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 75862306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 75962306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 76062306a36Sopenharmony_ci */ 76162306a36Sopenharmony_ci#ifndef SWIG /* This function is not useful in Python */ 76262306a36Sopenharmony_ciconst void *fdt_getprop_by_offset(const void *fdt, int offset, 76362306a36Sopenharmony_ci const char **namep, int *lenp); 76462306a36Sopenharmony_ci#endif 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_ci/** 76762306a36Sopenharmony_ci * fdt_getprop_namelen - get property value based on substring 76862306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 76962306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to find 77062306a36Sopenharmony_ci * @name: name of the property to find 77162306a36Sopenharmony_ci * @namelen: number of characters of name to consider 77262306a36Sopenharmony_ci * @lenp: pointer to an integer variable (will be overwritten) or NULL 77362306a36Sopenharmony_ci * 77462306a36Sopenharmony_ci * Identical to fdt_getprop(), but only examine the first namelen 77562306a36Sopenharmony_ci * characters of name for matching the property name. 77662306a36Sopenharmony_ci * 77762306a36Sopenharmony_ci * Return: pointer to the property's value or NULL on error 77862306a36Sopenharmony_ci */ 77962306a36Sopenharmony_ci#ifndef SWIG /* Not available in Python */ 78062306a36Sopenharmony_ciconst void *fdt_getprop_namelen(const void *fdt, int nodeoffset, 78162306a36Sopenharmony_ci const char *name, int namelen, int *lenp); 78262306a36Sopenharmony_cistatic inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset, 78362306a36Sopenharmony_ci const char *name, int namelen, 78462306a36Sopenharmony_ci int *lenp) 78562306a36Sopenharmony_ci{ 78662306a36Sopenharmony_ci return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name, 78762306a36Sopenharmony_ci namelen, lenp); 78862306a36Sopenharmony_ci} 78962306a36Sopenharmony_ci#endif 79062306a36Sopenharmony_ci 79162306a36Sopenharmony_ci/** 79262306a36Sopenharmony_ci * fdt_getprop - retrieve the value of a given property 79362306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 79462306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to find 79562306a36Sopenharmony_ci * @name: name of the property to find 79662306a36Sopenharmony_ci * @lenp: pointer to an integer variable (will be overwritten) or NULL 79762306a36Sopenharmony_ci * 79862306a36Sopenharmony_ci * fdt_getprop() retrieves a pointer to the value of the property 79962306a36Sopenharmony_ci * named @name of the node at offset @nodeoffset (this will be a 80062306a36Sopenharmony_ci * pointer to within the device blob itself, not a copy of the value). 80162306a36Sopenharmony_ci * If @lenp is non-NULL, the length of the property value is also 80262306a36Sopenharmony_ci * returned, in the integer pointed to by @lenp. 80362306a36Sopenharmony_ci * 80462306a36Sopenharmony_ci * returns: 80562306a36Sopenharmony_ci * pointer to the property's value 80662306a36Sopenharmony_ci * if lenp is non-NULL, *lenp contains the length of the property 80762306a36Sopenharmony_ci * value (>=0) 80862306a36Sopenharmony_ci * NULL, on error 80962306a36Sopenharmony_ci * if lenp is non-NULL, *lenp contains an error code (<0): 81062306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, node does not have named property 81162306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE 81262306a36Sopenharmony_ci * tag 81362306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 81462306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 81562306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 81662306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 81762306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 81862306a36Sopenharmony_ci */ 81962306a36Sopenharmony_ciconst void *fdt_getprop(const void *fdt, int nodeoffset, 82062306a36Sopenharmony_ci const char *name, int *lenp); 82162306a36Sopenharmony_cistatic inline void *fdt_getprop_w(void *fdt, int nodeoffset, 82262306a36Sopenharmony_ci const char *name, int *lenp) 82362306a36Sopenharmony_ci{ 82462306a36Sopenharmony_ci return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp); 82562306a36Sopenharmony_ci} 82662306a36Sopenharmony_ci 82762306a36Sopenharmony_ci/** 82862306a36Sopenharmony_ci * fdt_get_phandle - retrieve the phandle of a given node 82962306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 83062306a36Sopenharmony_ci * @nodeoffset: structure block offset of the node 83162306a36Sopenharmony_ci * 83262306a36Sopenharmony_ci * fdt_get_phandle() retrieves the phandle of the device tree node at 83362306a36Sopenharmony_ci * structure block offset nodeoffset. 83462306a36Sopenharmony_ci * 83562306a36Sopenharmony_ci * returns: 83662306a36Sopenharmony_ci * the phandle of the node at nodeoffset, on success (!= 0, != -1) 83762306a36Sopenharmony_ci * 0, if the node has no phandle, or another error occurs 83862306a36Sopenharmony_ci */ 83962306a36Sopenharmony_ciuint32_t fdt_get_phandle(const void *fdt, int nodeoffset); 84062306a36Sopenharmony_ci 84162306a36Sopenharmony_ci/** 84262306a36Sopenharmony_ci * fdt_get_alias_namelen - get alias based on substring 84362306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 84462306a36Sopenharmony_ci * @name: name of the alias th look up 84562306a36Sopenharmony_ci * @namelen: number of characters of name to consider 84662306a36Sopenharmony_ci * 84762306a36Sopenharmony_ci * Identical to fdt_get_alias(), but only examine the first @namelen 84862306a36Sopenharmony_ci * characters of @name for matching the alias name. 84962306a36Sopenharmony_ci * 85062306a36Sopenharmony_ci * Return: a pointer to the expansion of the alias named @name, if it exists, 85162306a36Sopenharmony_ci * NULL otherwise 85262306a36Sopenharmony_ci */ 85362306a36Sopenharmony_ci#ifndef SWIG /* Not available in Python */ 85462306a36Sopenharmony_ciconst char *fdt_get_alias_namelen(const void *fdt, 85562306a36Sopenharmony_ci const char *name, int namelen); 85662306a36Sopenharmony_ci#endif 85762306a36Sopenharmony_ci 85862306a36Sopenharmony_ci/** 85962306a36Sopenharmony_ci * fdt_get_alias - retrieve the path referenced by a given alias 86062306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 86162306a36Sopenharmony_ci * @name: name of the alias th look up 86262306a36Sopenharmony_ci * 86362306a36Sopenharmony_ci * fdt_get_alias() retrieves the value of a given alias. That is, the 86462306a36Sopenharmony_ci * value of the property named @name in the node /aliases. 86562306a36Sopenharmony_ci * 86662306a36Sopenharmony_ci * returns: 86762306a36Sopenharmony_ci * a pointer to the expansion of the alias named 'name', if it exists 86862306a36Sopenharmony_ci * NULL, if the given alias or the /aliases node does not exist 86962306a36Sopenharmony_ci */ 87062306a36Sopenharmony_ciconst char *fdt_get_alias(const void *fdt, const char *name); 87162306a36Sopenharmony_ci 87262306a36Sopenharmony_ci/** 87362306a36Sopenharmony_ci * fdt_get_path - determine the full path of a node 87462306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 87562306a36Sopenharmony_ci * @nodeoffset: offset of the node whose path to find 87662306a36Sopenharmony_ci * @buf: character buffer to contain the returned path (will be overwritten) 87762306a36Sopenharmony_ci * @buflen: size of the character buffer at buf 87862306a36Sopenharmony_ci * 87962306a36Sopenharmony_ci * fdt_get_path() computes the full path of the node at offset 88062306a36Sopenharmony_ci * nodeoffset, and records that path in the buffer at buf. 88162306a36Sopenharmony_ci * 88262306a36Sopenharmony_ci * NOTE: This function is expensive, as it must scan the device tree 88362306a36Sopenharmony_ci * structure from the start to nodeoffset. 88462306a36Sopenharmony_ci * 88562306a36Sopenharmony_ci * returns: 88662306a36Sopenharmony_ci * 0, on success 88762306a36Sopenharmony_ci * buf contains the absolute path of the node at 88862306a36Sopenharmony_ci * nodeoffset, as a NUL-terminated string. 88962306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 89062306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1) 89162306a36Sopenharmony_ci * characters and will not fit in the given buffer. 89262306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 89362306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 89462306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 89562306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, standard meanings 89662306a36Sopenharmony_ci */ 89762306a36Sopenharmony_ciint fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen); 89862306a36Sopenharmony_ci 89962306a36Sopenharmony_ci/** 90062306a36Sopenharmony_ci * fdt_supernode_atdepth_offset - find a specific ancestor of a node 90162306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 90262306a36Sopenharmony_ci * @nodeoffset: offset of the node whose parent to find 90362306a36Sopenharmony_ci * @supernodedepth: depth of the ancestor to find 90462306a36Sopenharmony_ci * @nodedepth: pointer to an integer variable (will be overwritten) or NULL 90562306a36Sopenharmony_ci * 90662306a36Sopenharmony_ci * fdt_supernode_atdepth_offset() finds an ancestor of the given node 90762306a36Sopenharmony_ci * at a specific depth from the root (where the root itself has depth 90862306a36Sopenharmony_ci * 0, its immediate subnodes depth 1 and so forth). So 90962306a36Sopenharmony_ci * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL); 91062306a36Sopenharmony_ci * will always return 0, the offset of the root node. If the node at 91162306a36Sopenharmony_ci * nodeoffset has depth D, then: 91262306a36Sopenharmony_ci * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL); 91362306a36Sopenharmony_ci * will return nodeoffset itself. 91462306a36Sopenharmony_ci * 91562306a36Sopenharmony_ci * NOTE: This function is expensive, as it must scan the device tree 91662306a36Sopenharmony_ci * structure from the start to nodeoffset. 91762306a36Sopenharmony_ci * 91862306a36Sopenharmony_ci * returns: 91962306a36Sopenharmony_ci * structure block offset of the node at node offset's ancestor 92062306a36Sopenharmony_ci * of depth supernodedepth (>=0), on success 92162306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 92262306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of 92362306a36Sopenharmony_ci * nodeoffset 92462306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 92562306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 92662306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 92762306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, standard meanings 92862306a36Sopenharmony_ci */ 92962306a36Sopenharmony_ciint fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, 93062306a36Sopenharmony_ci int supernodedepth, int *nodedepth); 93162306a36Sopenharmony_ci 93262306a36Sopenharmony_ci/** 93362306a36Sopenharmony_ci * fdt_node_depth - find the depth of a given node 93462306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 93562306a36Sopenharmony_ci * @nodeoffset: offset of the node whose parent to find 93662306a36Sopenharmony_ci * 93762306a36Sopenharmony_ci * fdt_node_depth() finds the depth of a given node. The root node 93862306a36Sopenharmony_ci * has depth 0, its immediate subnodes depth 1 and so forth. 93962306a36Sopenharmony_ci * 94062306a36Sopenharmony_ci * NOTE: This function is expensive, as it must scan the device tree 94162306a36Sopenharmony_ci * structure from the start to nodeoffset. 94262306a36Sopenharmony_ci * 94362306a36Sopenharmony_ci * returns: 94462306a36Sopenharmony_ci * depth of the node at nodeoffset (>=0), on success 94562306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 94662306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 94762306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 94862306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 94962306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, standard meanings 95062306a36Sopenharmony_ci */ 95162306a36Sopenharmony_ciint fdt_node_depth(const void *fdt, int nodeoffset); 95262306a36Sopenharmony_ci 95362306a36Sopenharmony_ci/** 95462306a36Sopenharmony_ci * fdt_parent_offset - find the parent of a given node 95562306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 95662306a36Sopenharmony_ci * @nodeoffset: offset of the node whose parent to find 95762306a36Sopenharmony_ci * 95862306a36Sopenharmony_ci * fdt_parent_offset() locates the parent node of a given node (that 95962306a36Sopenharmony_ci * is, it finds the offset of the node which contains the node at 96062306a36Sopenharmony_ci * nodeoffset as a subnode). 96162306a36Sopenharmony_ci * 96262306a36Sopenharmony_ci * NOTE: This function is expensive, as it must scan the device tree 96362306a36Sopenharmony_ci * structure from the start to nodeoffset, *twice*. 96462306a36Sopenharmony_ci * 96562306a36Sopenharmony_ci * returns: 96662306a36Sopenharmony_ci * structure block offset of the parent of the node at nodeoffset 96762306a36Sopenharmony_ci * (>=0), on success 96862306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 96962306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 97062306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 97162306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 97262306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, standard meanings 97362306a36Sopenharmony_ci */ 97462306a36Sopenharmony_ciint fdt_parent_offset(const void *fdt, int nodeoffset); 97562306a36Sopenharmony_ci 97662306a36Sopenharmony_ci/** 97762306a36Sopenharmony_ci * fdt_node_offset_by_prop_value - find nodes with a given property value 97862306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 97962306a36Sopenharmony_ci * @startoffset: only find nodes after this offset 98062306a36Sopenharmony_ci * @propname: property name to check 98162306a36Sopenharmony_ci * @propval: property value to search for 98262306a36Sopenharmony_ci * @proplen: length of the value in propval 98362306a36Sopenharmony_ci * 98462306a36Sopenharmony_ci * fdt_node_offset_by_prop_value() returns the offset of the first 98562306a36Sopenharmony_ci * node after startoffset, which has a property named propname whose 98662306a36Sopenharmony_ci * value is of length proplen and has value equal to propval; or if 98762306a36Sopenharmony_ci * startoffset is -1, the very first such node in the tree. 98862306a36Sopenharmony_ci * 98962306a36Sopenharmony_ci * To iterate through all nodes matching the criterion, the following 99062306a36Sopenharmony_ci * idiom can be used: 99162306a36Sopenharmony_ci * offset = fdt_node_offset_by_prop_value(fdt, -1, propname, 99262306a36Sopenharmony_ci * propval, proplen); 99362306a36Sopenharmony_ci * while (offset != -FDT_ERR_NOTFOUND) { 99462306a36Sopenharmony_ci * // other code here 99562306a36Sopenharmony_ci * offset = fdt_node_offset_by_prop_value(fdt, offset, propname, 99662306a36Sopenharmony_ci * propval, proplen); 99762306a36Sopenharmony_ci * } 99862306a36Sopenharmony_ci * 99962306a36Sopenharmony_ci * Note the -1 in the first call to the function, if 0 is used here 100062306a36Sopenharmony_ci * instead, the function will never locate the root node, even if it 100162306a36Sopenharmony_ci * matches the criterion. 100262306a36Sopenharmony_ci * 100362306a36Sopenharmony_ci * returns: 100462306a36Sopenharmony_ci * structure block offset of the located node (>= 0, >startoffset), 100562306a36Sopenharmony_ci * on success 100662306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the 100762306a36Sopenharmony_ci * tree after startoffset 100862306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 100962306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 101062306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 101162306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 101262306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, standard meanings 101362306a36Sopenharmony_ci */ 101462306a36Sopenharmony_ciint fdt_node_offset_by_prop_value(const void *fdt, int startoffset, 101562306a36Sopenharmony_ci const char *propname, 101662306a36Sopenharmony_ci const void *propval, int proplen); 101762306a36Sopenharmony_ci 101862306a36Sopenharmony_ci/** 101962306a36Sopenharmony_ci * fdt_node_offset_by_phandle - find the node with a given phandle 102062306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 102162306a36Sopenharmony_ci * @phandle: phandle value 102262306a36Sopenharmony_ci * 102362306a36Sopenharmony_ci * fdt_node_offset_by_phandle() returns the offset of the node 102462306a36Sopenharmony_ci * which has the given phandle value. If there is more than one node 102562306a36Sopenharmony_ci * in the tree with the given phandle (an invalid tree), results are 102662306a36Sopenharmony_ci * undefined. 102762306a36Sopenharmony_ci * 102862306a36Sopenharmony_ci * returns: 102962306a36Sopenharmony_ci * structure block offset of the located node (>= 0), on success 103062306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, no node with that phandle exists 103162306a36Sopenharmony_ci * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1) 103262306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 103362306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 103462306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 103562306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, standard meanings 103662306a36Sopenharmony_ci */ 103762306a36Sopenharmony_ciint fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle); 103862306a36Sopenharmony_ci 103962306a36Sopenharmony_ci/** 104062306a36Sopenharmony_ci * fdt_node_check_compatible - check a node's compatible property 104162306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 104262306a36Sopenharmony_ci * @nodeoffset: offset of a tree node 104362306a36Sopenharmony_ci * @compatible: string to match against 104462306a36Sopenharmony_ci * 104562306a36Sopenharmony_ci * fdt_node_check_compatible() returns 0 if the given node contains a 104662306a36Sopenharmony_ci * @compatible property with the given string as one of its elements, 104762306a36Sopenharmony_ci * it returns non-zero otherwise, or on error. 104862306a36Sopenharmony_ci * 104962306a36Sopenharmony_ci * returns: 105062306a36Sopenharmony_ci * 0, if the node has a 'compatible' property listing the given string 105162306a36Sopenharmony_ci * 1, if the node has a 'compatible' property, but it does not list 105262306a36Sopenharmony_ci * the given string 105362306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property 105462306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag 105562306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 105662306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 105762306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 105862306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, standard meanings 105962306a36Sopenharmony_ci */ 106062306a36Sopenharmony_ciint fdt_node_check_compatible(const void *fdt, int nodeoffset, 106162306a36Sopenharmony_ci const char *compatible); 106262306a36Sopenharmony_ci 106362306a36Sopenharmony_ci/** 106462306a36Sopenharmony_ci * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value 106562306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 106662306a36Sopenharmony_ci * @startoffset: only find nodes after this offset 106762306a36Sopenharmony_ci * @compatible: 'compatible' string to match against 106862306a36Sopenharmony_ci * 106962306a36Sopenharmony_ci * fdt_node_offset_by_compatible() returns the offset of the first 107062306a36Sopenharmony_ci * node after startoffset, which has a 'compatible' property which 107162306a36Sopenharmony_ci * lists the given compatible string; or if startoffset is -1, the 107262306a36Sopenharmony_ci * very first such node in the tree. 107362306a36Sopenharmony_ci * 107462306a36Sopenharmony_ci * To iterate through all nodes matching the criterion, the following 107562306a36Sopenharmony_ci * idiom can be used: 107662306a36Sopenharmony_ci * offset = fdt_node_offset_by_compatible(fdt, -1, compatible); 107762306a36Sopenharmony_ci * while (offset != -FDT_ERR_NOTFOUND) { 107862306a36Sopenharmony_ci * // other code here 107962306a36Sopenharmony_ci * offset = fdt_node_offset_by_compatible(fdt, offset, compatible); 108062306a36Sopenharmony_ci * } 108162306a36Sopenharmony_ci * 108262306a36Sopenharmony_ci * Note the -1 in the first call to the function, if 0 is used here 108362306a36Sopenharmony_ci * instead, the function will never locate the root node, even if it 108462306a36Sopenharmony_ci * matches the criterion. 108562306a36Sopenharmony_ci * 108662306a36Sopenharmony_ci * returns: 108762306a36Sopenharmony_ci * structure block offset of the located node (>= 0, >startoffset), 108862306a36Sopenharmony_ci * on success 108962306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the 109062306a36Sopenharmony_ci * tree after startoffset 109162306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag 109262306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 109362306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 109462306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 109562306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, standard meanings 109662306a36Sopenharmony_ci */ 109762306a36Sopenharmony_ciint fdt_node_offset_by_compatible(const void *fdt, int startoffset, 109862306a36Sopenharmony_ci const char *compatible); 109962306a36Sopenharmony_ci 110062306a36Sopenharmony_ci/** 110162306a36Sopenharmony_ci * fdt_stringlist_contains - check a string list property for a string 110262306a36Sopenharmony_ci * @strlist: Property containing a list of strings to check 110362306a36Sopenharmony_ci * @listlen: Length of property 110462306a36Sopenharmony_ci * @str: String to search for 110562306a36Sopenharmony_ci * 110662306a36Sopenharmony_ci * This is a utility function provided for convenience. The list contains 110762306a36Sopenharmony_ci * one or more strings, each terminated by \0, as is found in a device tree 110862306a36Sopenharmony_ci * "compatible" property. 110962306a36Sopenharmony_ci * 111062306a36Sopenharmony_ci * Return: 1 if the string is found in the list, 0 not found, or invalid list 111162306a36Sopenharmony_ci */ 111262306a36Sopenharmony_ciint fdt_stringlist_contains(const char *strlist, int listlen, const char *str); 111362306a36Sopenharmony_ci 111462306a36Sopenharmony_ci/** 111562306a36Sopenharmony_ci * fdt_stringlist_count - count the number of strings in a string list 111662306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 111762306a36Sopenharmony_ci * @nodeoffset: offset of a tree node 111862306a36Sopenharmony_ci * @property: name of the property containing the string list 111962306a36Sopenharmony_ci * 112062306a36Sopenharmony_ci * Return: 112162306a36Sopenharmony_ci * the number of strings in the given property 112262306a36Sopenharmony_ci * -FDT_ERR_BADVALUE if the property value is not NUL-terminated 112362306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND if the property does not exist 112462306a36Sopenharmony_ci */ 112562306a36Sopenharmony_ciint fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property); 112662306a36Sopenharmony_ci 112762306a36Sopenharmony_ci/** 112862306a36Sopenharmony_ci * fdt_stringlist_search - find a string in a string list and return its index 112962306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 113062306a36Sopenharmony_ci * @nodeoffset: offset of a tree node 113162306a36Sopenharmony_ci * @property: name of the property containing the string list 113262306a36Sopenharmony_ci * @string: string to look up in the string list 113362306a36Sopenharmony_ci * 113462306a36Sopenharmony_ci * Note that it is possible for this function to succeed on property values 113562306a36Sopenharmony_ci * that are not NUL-terminated. That's because the function will stop after 113662306a36Sopenharmony_ci * finding the first occurrence of @string. This can for example happen with 113762306a36Sopenharmony_ci * small-valued cell properties, such as #address-cells, when searching for 113862306a36Sopenharmony_ci * the empty string. 113962306a36Sopenharmony_ci * 114062306a36Sopenharmony_ci * return: 114162306a36Sopenharmony_ci * the index of the string in the list of strings 114262306a36Sopenharmony_ci * -FDT_ERR_BADVALUE if the property value is not NUL-terminated 114362306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND if the property does not exist or does not contain 114462306a36Sopenharmony_ci * the given string 114562306a36Sopenharmony_ci */ 114662306a36Sopenharmony_ciint fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property, 114762306a36Sopenharmony_ci const char *string); 114862306a36Sopenharmony_ci 114962306a36Sopenharmony_ci/** 115062306a36Sopenharmony_ci * fdt_stringlist_get() - obtain the string at a given index in a string list 115162306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 115262306a36Sopenharmony_ci * @nodeoffset: offset of a tree node 115362306a36Sopenharmony_ci * @property: name of the property containing the string list 115462306a36Sopenharmony_ci * @index: index of the string to return 115562306a36Sopenharmony_ci * @lenp: return location for the string length or an error code on failure 115662306a36Sopenharmony_ci * 115762306a36Sopenharmony_ci * Note that this will successfully extract strings from properties with 115862306a36Sopenharmony_ci * non-NUL-terminated values. For example on small-valued cell properties 115962306a36Sopenharmony_ci * this function will return the empty string. 116062306a36Sopenharmony_ci * 116162306a36Sopenharmony_ci * If non-NULL, the length of the string (on success) or a negative error-code 116262306a36Sopenharmony_ci * (on failure) will be stored in the integer pointer to by lenp. 116362306a36Sopenharmony_ci * 116462306a36Sopenharmony_ci * Return: 116562306a36Sopenharmony_ci * A pointer to the string at the given index in the string list or NULL on 116662306a36Sopenharmony_ci * failure. On success the length of the string will be stored in the memory 116762306a36Sopenharmony_ci * location pointed to by the lenp parameter, if non-NULL. On failure one of 116862306a36Sopenharmony_ci * the following negative error codes will be returned in the lenp parameter 116962306a36Sopenharmony_ci * (if non-NULL): 117062306a36Sopenharmony_ci * -FDT_ERR_BADVALUE if the property value is not NUL-terminated 117162306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND if the property does not exist 117262306a36Sopenharmony_ci */ 117362306a36Sopenharmony_ciconst char *fdt_stringlist_get(const void *fdt, int nodeoffset, 117462306a36Sopenharmony_ci const char *property, int index, 117562306a36Sopenharmony_ci int *lenp); 117662306a36Sopenharmony_ci 117762306a36Sopenharmony_ci/**********************************************************************/ 117862306a36Sopenharmony_ci/* Read-only functions (addressing related) */ 117962306a36Sopenharmony_ci/**********************************************************************/ 118062306a36Sopenharmony_ci 118162306a36Sopenharmony_ci/** 118262306a36Sopenharmony_ci * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells 118362306a36Sopenharmony_ci * 118462306a36Sopenharmony_ci * This is the maximum value for #address-cells, #size-cells and 118562306a36Sopenharmony_ci * similar properties that will be processed by libfdt. IEE1275 118662306a36Sopenharmony_ci * requires that OF implementations handle values up to 4. 118762306a36Sopenharmony_ci * Implementations may support larger values, but in practice higher 118862306a36Sopenharmony_ci * values aren't used. 118962306a36Sopenharmony_ci */ 119062306a36Sopenharmony_ci#define FDT_MAX_NCELLS 4 119162306a36Sopenharmony_ci 119262306a36Sopenharmony_ci/** 119362306a36Sopenharmony_ci * fdt_address_cells - retrieve address size for a bus represented in the tree 119462306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 119562306a36Sopenharmony_ci * @nodeoffset: offset of the node to find the address size for 119662306a36Sopenharmony_ci * 119762306a36Sopenharmony_ci * When the node has a valid #address-cells property, returns its value. 119862306a36Sopenharmony_ci * 119962306a36Sopenharmony_ci * returns: 120062306a36Sopenharmony_ci * 0 <= n < FDT_MAX_NCELLS, on success 120162306a36Sopenharmony_ci * 2, if the node has no #address-cells property 120262306a36Sopenharmony_ci * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid 120362306a36Sopenharmony_ci * #address-cells property 120462306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 120562306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 120662306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 120762306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 120862306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 120962306a36Sopenharmony_ci */ 121062306a36Sopenharmony_ciint fdt_address_cells(const void *fdt, int nodeoffset); 121162306a36Sopenharmony_ci 121262306a36Sopenharmony_ci/** 121362306a36Sopenharmony_ci * fdt_size_cells - retrieve address range size for a bus represented in the 121462306a36Sopenharmony_ci * tree 121562306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 121662306a36Sopenharmony_ci * @nodeoffset: offset of the node to find the address range size for 121762306a36Sopenharmony_ci * 121862306a36Sopenharmony_ci * When the node has a valid #size-cells property, returns its value. 121962306a36Sopenharmony_ci * 122062306a36Sopenharmony_ci * returns: 122162306a36Sopenharmony_ci * 0 <= n < FDT_MAX_NCELLS, on success 122262306a36Sopenharmony_ci * 1, if the node has no #size-cells property 122362306a36Sopenharmony_ci * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid 122462306a36Sopenharmony_ci * #size-cells property 122562306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 122662306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 122762306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 122862306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 122962306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 123062306a36Sopenharmony_ci */ 123162306a36Sopenharmony_ciint fdt_size_cells(const void *fdt, int nodeoffset); 123262306a36Sopenharmony_ci 123362306a36Sopenharmony_ci 123462306a36Sopenharmony_ci/**********************************************************************/ 123562306a36Sopenharmony_ci/* Write-in-place functions */ 123662306a36Sopenharmony_ci/**********************************************************************/ 123762306a36Sopenharmony_ci 123862306a36Sopenharmony_ci/** 123962306a36Sopenharmony_ci * fdt_setprop_inplace_namelen_partial - change a property's value, 124062306a36Sopenharmony_ci * but not its size 124162306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 124262306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 124362306a36Sopenharmony_ci * @name: name of the property to change 124462306a36Sopenharmony_ci * @namelen: number of characters of name to consider 124562306a36Sopenharmony_ci * @idx: index of the property to change in the array 124662306a36Sopenharmony_ci * @val: pointer to data to replace the property value with 124762306a36Sopenharmony_ci * @len: length of the property value 124862306a36Sopenharmony_ci * 124962306a36Sopenharmony_ci * Identical to fdt_setprop_inplace(), but modifies the given property 125062306a36Sopenharmony_ci * starting from the given index, and using only the first characters 125162306a36Sopenharmony_ci * of the name. It is useful when you want to manipulate only one value of 125262306a36Sopenharmony_ci * an array and you have a string that doesn't end with \0. 125362306a36Sopenharmony_ci * 125462306a36Sopenharmony_ci * Return: 0 on success, negative libfdt error value otherwise 125562306a36Sopenharmony_ci */ 125662306a36Sopenharmony_ci#ifndef SWIG /* Not available in Python */ 125762306a36Sopenharmony_ciint fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, 125862306a36Sopenharmony_ci const char *name, int namelen, 125962306a36Sopenharmony_ci uint32_t idx, const void *val, 126062306a36Sopenharmony_ci int len); 126162306a36Sopenharmony_ci#endif 126262306a36Sopenharmony_ci 126362306a36Sopenharmony_ci/** 126462306a36Sopenharmony_ci * fdt_setprop_inplace - change a property's value, but not its size 126562306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 126662306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 126762306a36Sopenharmony_ci * @name: name of the property to change 126862306a36Sopenharmony_ci * @val: pointer to data to replace the property value with 126962306a36Sopenharmony_ci * @len: length of the property value 127062306a36Sopenharmony_ci * 127162306a36Sopenharmony_ci * fdt_setprop_inplace() replaces the value of a given property with 127262306a36Sopenharmony_ci * the data in val, of length len. This function cannot change the 127362306a36Sopenharmony_ci * size of a property, and so will only work if len is equal to the 127462306a36Sopenharmony_ci * current length of the property. 127562306a36Sopenharmony_ci * 127662306a36Sopenharmony_ci * This function will alter only the bytes in the blob which contain 127762306a36Sopenharmony_ci * the given property value, and will not alter or move any other part 127862306a36Sopenharmony_ci * of the tree. 127962306a36Sopenharmony_ci * 128062306a36Sopenharmony_ci * returns: 128162306a36Sopenharmony_ci * 0, on success 128262306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, if len is not equal to the property's current length 128362306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, node does not have the named property 128462306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 128562306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 128662306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 128762306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 128862306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 128962306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 129062306a36Sopenharmony_ci */ 129162306a36Sopenharmony_ci#ifndef SWIG /* Not available in Python */ 129262306a36Sopenharmony_ciint fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, 129362306a36Sopenharmony_ci const void *val, int len); 129462306a36Sopenharmony_ci#endif 129562306a36Sopenharmony_ci 129662306a36Sopenharmony_ci/** 129762306a36Sopenharmony_ci * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property 129862306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 129962306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 130062306a36Sopenharmony_ci * @name: name of the property to change 130162306a36Sopenharmony_ci * @val: 32-bit integer value to replace the property with 130262306a36Sopenharmony_ci * 130362306a36Sopenharmony_ci * fdt_setprop_inplace_u32() replaces the value of a given property 130462306a36Sopenharmony_ci * with the 32-bit integer value in val, converting val to big-endian 130562306a36Sopenharmony_ci * if necessary. This function cannot change the size of a property, 130662306a36Sopenharmony_ci * and so will only work if the property already exists and has length 130762306a36Sopenharmony_ci * 4. 130862306a36Sopenharmony_ci * 130962306a36Sopenharmony_ci * This function will alter only the bytes in the blob which contain 131062306a36Sopenharmony_ci * the given property value, and will not alter or move any other part 131162306a36Sopenharmony_ci * of the tree. 131262306a36Sopenharmony_ci * 131362306a36Sopenharmony_ci * returns: 131462306a36Sopenharmony_ci * 0, on success 131562306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, if the property's length is not equal to 4 131662306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, node does not have the named property 131762306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 131862306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 131962306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 132062306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 132162306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 132262306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 132362306a36Sopenharmony_ci */ 132462306a36Sopenharmony_cistatic inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset, 132562306a36Sopenharmony_ci const char *name, uint32_t val) 132662306a36Sopenharmony_ci{ 132762306a36Sopenharmony_ci fdt32_t tmp = cpu_to_fdt32(val); 132862306a36Sopenharmony_ci return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 132962306a36Sopenharmony_ci} 133062306a36Sopenharmony_ci 133162306a36Sopenharmony_ci/** 133262306a36Sopenharmony_ci * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property 133362306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 133462306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 133562306a36Sopenharmony_ci * @name: name of the property to change 133662306a36Sopenharmony_ci * @val: 64-bit integer value to replace the property with 133762306a36Sopenharmony_ci * 133862306a36Sopenharmony_ci * fdt_setprop_inplace_u64() replaces the value of a given property 133962306a36Sopenharmony_ci * with the 64-bit integer value in val, converting val to big-endian 134062306a36Sopenharmony_ci * if necessary. This function cannot change the size of a property, 134162306a36Sopenharmony_ci * and so will only work if the property already exists and has length 134262306a36Sopenharmony_ci * 8. 134362306a36Sopenharmony_ci * 134462306a36Sopenharmony_ci * This function will alter only the bytes in the blob which contain 134562306a36Sopenharmony_ci * the given property value, and will not alter or move any other part 134662306a36Sopenharmony_ci * of the tree. 134762306a36Sopenharmony_ci * 134862306a36Sopenharmony_ci * returns: 134962306a36Sopenharmony_ci * 0, on success 135062306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, if the property's length is not equal to 8 135162306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, node does not have the named property 135262306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 135362306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 135462306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 135562306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 135662306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 135762306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 135862306a36Sopenharmony_ci */ 135962306a36Sopenharmony_cistatic inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset, 136062306a36Sopenharmony_ci const char *name, uint64_t val) 136162306a36Sopenharmony_ci{ 136262306a36Sopenharmony_ci fdt64_t tmp = cpu_to_fdt64(val); 136362306a36Sopenharmony_ci return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 136462306a36Sopenharmony_ci} 136562306a36Sopenharmony_ci 136662306a36Sopenharmony_ci/** 136762306a36Sopenharmony_ci * fdt_setprop_inplace_cell - change the value of a single-cell property 136862306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 136962306a36Sopenharmony_ci * @nodeoffset: offset of the node containing the property 137062306a36Sopenharmony_ci * @name: name of the property to change the value of 137162306a36Sopenharmony_ci * @val: new value of the 32-bit cell 137262306a36Sopenharmony_ci * 137362306a36Sopenharmony_ci * This is an alternative name for fdt_setprop_inplace_u32() 137462306a36Sopenharmony_ci * Return: 0 on success, negative libfdt error number otherwise. 137562306a36Sopenharmony_ci */ 137662306a36Sopenharmony_cistatic inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset, 137762306a36Sopenharmony_ci const char *name, uint32_t val) 137862306a36Sopenharmony_ci{ 137962306a36Sopenharmony_ci return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val); 138062306a36Sopenharmony_ci} 138162306a36Sopenharmony_ci 138262306a36Sopenharmony_ci/** 138362306a36Sopenharmony_ci * fdt_nop_property - replace a property with nop tags 138462306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 138562306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to nop 138662306a36Sopenharmony_ci * @name: name of the property to nop 138762306a36Sopenharmony_ci * 138862306a36Sopenharmony_ci * fdt_nop_property() will replace a given property's representation 138962306a36Sopenharmony_ci * in the blob with FDT_NOP tags, effectively removing it from the 139062306a36Sopenharmony_ci * tree. 139162306a36Sopenharmony_ci * 139262306a36Sopenharmony_ci * This function will alter only the bytes in the blob which contain 139362306a36Sopenharmony_ci * the property, and will not alter or move any other part of the 139462306a36Sopenharmony_ci * tree. 139562306a36Sopenharmony_ci * 139662306a36Sopenharmony_ci * returns: 139762306a36Sopenharmony_ci * 0, on success 139862306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, node does not have the named property 139962306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 140062306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 140162306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 140262306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 140362306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 140462306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 140562306a36Sopenharmony_ci */ 140662306a36Sopenharmony_ciint fdt_nop_property(void *fdt, int nodeoffset, const char *name); 140762306a36Sopenharmony_ci 140862306a36Sopenharmony_ci/** 140962306a36Sopenharmony_ci * fdt_nop_node - replace a node (subtree) with nop tags 141062306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 141162306a36Sopenharmony_ci * @nodeoffset: offset of the node to nop 141262306a36Sopenharmony_ci * 141362306a36Sopenharmony_ci * fdt_nop_node() will replace a given node's representation in the 141462306a36Sopenharmony_ci * blob, including all its subnodes, if any, with FDT_NOP tags, 141562306a36Sopenharmony_ci * effectively removing it from the tree. 141662306a36Sopenharmony_ci * 141762306a36Sopenharmony_ci * This function will alter only the bytes in the blob which contain 141862306a36Sopenharmony_ci * the node and its properties and subnodes, and will not alter or 141962306a36Sopenharmony_ci * move any other part of the tree. 142062306a36Sopenharmony_ci * 142162306a36Sopenharmony_ci * returns: 142262306a36Sopenharmony_ci * 0, on success 142362306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 142462306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 142562306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 142662306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 142762306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 142862306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 142962306a36Sopenharmony_ci */ 143062306a36Sopenharmony_ciint fdt_nop_node(void *fdt, int nodeoffset); 143162306a36Sopenharmony_ci 143262306a36Sopenharmony_ci/**********************************************************************/ 143362306a36Sopenharmony_ci/* Sequential write functions */ 143462306a36Sopenharmony_ci/**********************************************************************/ 143562306a36Sopenharmony_ci 143662306a36Sopenharmony_ci/* fdt_create_with_flags flags */ 143762306a36Sopenharmony_ci#define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1 143862306a36Sopenharmony_ci /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property 143962306a36Sopenharmony_ci * names in the fdt. This can result in faster creation times, but 144062306a36Sopenharmony_ci * a larger fdt. */ 144162306a36Sopenharmony_ci 144262306a36Sopenharmony_ci#define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP) 144362306a36Sopenharmony_ci 144462306a36Sopenharmony_ci/** 144562306a36Sopenharmony_ci * fdt_create_with_flags - begin creation of a new fdt 144662306a36Sopenharmony_ci * @buf: pointer to memory allocated where fdt will be created 144762306a36Sopenharmony_ci * @bufsize: size of the memory space at fdt 144862306a36Sopenharmony_ci * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0. 144962306a36Sopenharmony_ci * 145062306a36Sopenharmony_ci * fdt_create_with_flags() begins the process of creating a new fdt with 145162306a36Sopenharmony_ci * the sequential write interface. 145262306a36Sopenharmony_ci * 145362306a36Sopenharmony_ci * fdt creation process must end with fdt_finished() to produce a valid fdt. 145462306a36Sopenharmony_ci * 145562306a36Sopenharmony_ci * returns: 145662306a36Sopenharmony_ci * 0, on success 145762306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt 145862306a36Sopenharmony_ci * -FDT_ERR_BADFLAGS, flags is not valid 145962306a36Sopenharmony_ci */ 146062306a36Sopenharmony_ciint fdt_create_with_flags(void *buf, int bufsize, uint32_t flags); 146162306a36Sopenharmony_ci 146262306a36Sopenharmony_ci/** 146362306a36Sopenharmony_ci * fdt_create - begin creation of a new fdt 146462306a36Sopenharmony_ci * @buf: pointer to memory allocated where fdt will be created 146562306a36Sopenharmony_ci * @bufsize: size of the memory space at fdt 146662306a36Sopenharmony_ci * 146762306a36Sopenharmony_ci * fdt_create() is equivalent to fdt_create_with_flags() with flags=0. 146862306a36Sopenharmony_ci * 146962306a36Sopenharmony_ci * returns: 147062306a36Sopenharmony_ci * 0, on success 147162306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt 147262306a36Sopenharmony_ci */ 147362306a36Sopenharmony_ciint fdt_create(void *buf, int bufsize); 147462306a36Sopenharmony_ci 147562306a36Sopenharmony_ciint fdt_resize(void *fdt, void *buf, int bufsize); 147662306a36Sopenharmony_ciint fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size); 147762306a36Sopenharmony_ciint fdt_finish_reservemap(void *fdt); 147862306a36Sopenharmony_ciint fdt_begin_node(void *fdt, const char *name); 147962306a36Sopenharmony_ciint fdt_property(void *fdt, const char *name, const void *val, int len); 148062306a36Sopenharmony_cistatic inline int fdt_property_u32(void *fdt, const char *name, uint32_t val) 148162306a36Sopenharmony_ci{ 148262306a36Sopenharmony_ci fdt32_t tmp = cpu_to_fdt32(val); 148362306a36Sopenharmony_ci return fdt_property(fdt, name, &tmp, sizeof(tmp)); 148462306a36Sopenharmony_ci} 148562306a36Sopenharmony_cistatic inline int fdt_property_u64(void *fdt, const char *name, uint64_t val) 148662306a36Sopenharmony_ci{ 148762306a36Sopenharmony_ci fdt64_t tmp = cpu_to_fdt64(val); 148862306a36Sopenharmony_ci return fdt_property(fdt, name, &tmp, sizeof(tmp)); 148962306a36Sopenharmony_ci} 149062306a36Sopenharmony_ci 149162306a36Sopenharmony_ci#ifndef SWIG /* Not available in Python */ 149262306a36Sopenharmony_cistatic inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) 149362306a36Sopenharmony_ci{ 149462306a36Sopenharmony_ci return fdt_property_u32(fdt, name, val); 149562306a36Sopenharmony_ci} 149662306a36Sopenharmony_ci#endif 149762306a36Sopenharmony_ci 149862306a36Sopenharmony_ci/** 149962306a36Sopenharmony_ci * fdt_property_placeholder - add a new property and return a ptr to its value 150062306a36Sopenharmony_ci * 150162306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 150262306a36Sopenharmony_ci * @name: name of property to add 150362306a36Sopenharmony_ci * @len: length of property value in bytes 150462306a36Sopenharmony_ci * @valp: returns a pointer to where where the value should be placed 150562306a36Sopenharmony_ci * 150662306a36Sopenharmony_ci * returns: 150762306a36Sopenharmony_ci * 0, on success 150862306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 150962306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, standard meanings 151062306a36Sopenharmony_ci */ 151162306a36Sopenharmony_ciint fdt_property_placeholder(void *fdt, const char *name, int len, void **valp); 151262306a36Sopenharmony_ci 151362306a36Sopenharmony_ci#define fdt_property_string(fdt, name, str) \ 151462306a36Sopenharmony_ci fdt_property(fdt, name, str, strlen(str)+1) 151562306a36Sopenharmony_ciint fdt_end_node(void *fdt); 151662306a36Sopenharmony_ciint fdt_finish(void *fdt); 151762306a36Sopenharmony_ci 151862306a36Sopenharmony_ci/**********************************************************************/ 151962306a36Sopenharmony_ci/* Read-write functions */ 152062306a36Sopenharmony_ci/**********************************************************************/ 152162306a36Sopenharmony_ci 152262306a36Sopenharmony_ciint fdt_create_empty_tree(void *buf, int bufsize); 152362306a36Sopenharmony_ciint fdt_open_into(const void *fdt, void *buf, int bufsize); 152462306a36Sopenharmony_ciint fdt_pack(void *fdt); 152562306a36Sopenharmony_ci 152662306a36Sopenharmony_ci/** 152762306a36Sopenharmony_ci * fdt_add_mem_rsv - add one memory reserve map entry 152862306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 152962306a36Sopenharmony_ci * @address: 64-bit start address of the reserve map entry 153062306a36Sopenharmony_ci * @size: 64-bit size of the reserved region 153162306a36Sopenharmony_ci * 153262306a36Sopenharmony_ci * Adds a reserve map entry to the given blob reserving a region at 153362306a36Sopenharmony_ci * address address of length size. 153462306a36Sopenharmony_ci * 153562306a36Sopenharmony_ci * This function will insert data into the reserve map and will 153662306a36Sopenharmony_ci * therefore change the indexes of some entries in the table. 153762306a36Sopenharmony_ci * 153862306a36Sopenharmony_ci * returns: 153962306a36Sopenharmony_ci * 0, on success 154062306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 154162306a36Sopenharmony_ci * contain the new reservation entry 154262306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 154362306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 154462306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 154562306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 154662306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 154762306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 154862306a36Sopenharmony_ci */ 154962306a36Sopenharmony_ciint fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size); 155062306a36Sopenharmony_ci 155162306a36Sopenharmony_ci/** 155262306a36Sopenharmony_ci * fdt_del_mem_rsv - remove a memory reserve map entry 155362306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 155462306a36Sopenharmony_ci * @n: entry to remove 155562306a36Sopenharmony_ci * 155662306a36Sopenharmony_ci * fdt_del_mem_rsv() removes the n-th memory reserve map entry from 155762306a36Sopenharmony_ci * the blob. 155862306a36Sopenharmony_ci * 155962306a36Sopenharmony_ci * This function will delete data from the reservation table and will 156062306a36Sopenharmony_ci * therefore change the indexes of some entries in the table. 156162306a36Sopenharmony_ci * 156262306a36Sopenharmony_ci * returns: 156362306a36Sopenharmony_ci * 0, on success 156462306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there 156562306a36Sopenharmony_ci * are less than n+1 reserve map entries) 156662306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 156762306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 156862306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 156962306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 157062306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 157162306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 157262306a36Sopenharmony_ci */ 157362306a36Sopenharmony_ciint fdt_del_mem_rsv(void *fdt, int n); 157462306a36Sopenharmony_ci 157562306a36Sopenharmony_ci/** 157662306a36Sopenharmony_ci * fdt_set_name - change the name of a given node 157762306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 157862306a36Sopenharmony_ci * @nodeoffset: structure block offset of a node 157962306a36Sopenharmony_ci * @name: name to give the node 158062306a36Sopenharmony_ci * 158162306a36Sopenharmony_ci * fdt_set_name() replaces the name (including unit address, if any) 158262306a36Sopenharmony_ci * of the given node with the given string. NOTE: this function can't 158362306a36Sopenharmony_ci * efficiently check if the new name is unique amongst the given 158462306a36Sopenharmony_ci * node's siblings; results are undefined if this function is invoked 158562306a36Sopenharmony_ci * with a name equal to one of the given node's siblings. 158662306a36Sopenharmony_ci * 158762306a36Sopenharmony_ci * This function may insert or delete data from the blob, and will 158862306a36Sopenharmony_ci * therefore change the offsets of some existing nodes. 158962306a36Sopenharmony_ci * 159062306a36Sopenharmony_ci * returns: 159162306a36Sopenharmony_ci * 0, on success 159262306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob 159362306a36Sopenharmony_ci * to contain the new name 159462306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 159562306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 159662306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 159762306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, standard meanings 159862306a36Sopenharmony_ci */ 159962306a36Sopenharmony_ciint fdt_set_name(void *fdt, int nodeoffset, const char *name); 160062306a36Sopenharmony_ci 160162306a36Sopenharmony_ci/** 160262306a36Sopenharmony_ci * fdt_setprop - create or change a property 160362306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 160462306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 160562306a36Sopenharmony_ci * @name: name of the property to change 160662306a36Sopenharmony_ci * @val: pointer to data to set the property value to 160762306a36Sopenharmony_ci * @len: length of the property value 160862306a36Sopenharmony_ci * 160962306a36Sopenharmony_ci * fdt_setprop() sets the value of the named property in the given 161062306a36Sopenharmony_ci * node to the given value and length, creating the property if it 161162306a36Sopenharmony_ci * does not already exist. 161262306a36Sopenharmony_ci * 161362306a36Sopenharmony_ci * This function may insert or delete data from the blob, and will 161462306a36Sopenharmony_ci * therefore change the offsets of some existing nodes. 161562306a36Sopenharmony_ci * 161662306a36Sopenharmony_ci * returns: 161762306a36Sopenharmony_ci * 0, on success 161862306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 161962306a36Sopenharmony_ci * contain the new property value 162062306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 162162306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 162262306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 162362306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 162462306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 162562306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 162662306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 162762306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 162862306a36Sopenharmony_ci */ 162962306a36Sopenharmony_ciint fdt_setprop(void *fdt, int nodeoffset, const char *name, 163062306a36Sopenharmony_ci const void *val, int len); 163162306a36Sopenharmony_ci 163262306a36Sopenharmony_ci/** 163362306a36Sopenharmony_ci * fdt_setprop_placeholder - allocate space for a property 163462306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 163562306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 163662306a36Sopenharmony_ci * @name: name of the property to change 163762306a36Sopenharmony_ci * @len: length of the property value 163862306a36Sopenharmony_ci * @prop_data: return pointer to property data 163962306a36Sopenharmony_ci * 164062306a36Sopenharmony_ci * fdt_setprop_placeholer() allocates the named property in the given node. 164162306a36Sopenharmony_ci * If the property exists it is resized. In either case a pointer to the 164262306a36Sopenharmony_ci * property data is returned. 164362306a36Sopenharmony_ci * 164462306a36Sopenharmony_ci * This function may insert or delete data from the blob, and will 164562306a36Sopenharmony_ci * therefore change the offsets of some existing nodes. 164662306a36Sopenharmony_ci * 164762306a36Sopenharmony_ci * returns: 164862306a36Sopenharmony_ci * 0, on success 164962306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 165062306a36Sopenharmony_ci * contain the new property value 165162306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 165262306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 165362306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 165462306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 165562306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 165662306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 165762306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 165862306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 165962306a36Sopenharmony_ci */ 166062306a36Sopenharmony_ciint fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, 166162306a36Sopenharmony_ci int len, void **prop_data); 166262306a36Sopenharmony_ci 166362306a36Sopenharmony_ci/** 166462306a36Sopenharmony_ci * fdt_setprop_u32 - set a property to a 32-bit integer 166562306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 166662306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 166762306a36Sopenharmony_ci * @name: name of the property to change 166862306a36Sopenharmony_ci * @val: 32-bit integer value for the property (native endian) 166962306a36Sopenharmony_ci * 167062306a36Sopenharmony_ci * fdt_setprop_u32() sets the value of the named property in the given 167162306a36Sopenharmony_ci * node to the given 32-bit integer value (converting to big-endian if 167262306a36Sopenharmony_ci * necessary), or creates a new property with that value if it does 167362306a36Sopenharmony_ci * not already exist. 167462306a36Sopenharmony_ci * 167562306a36Sopenharmony_ci * This function may insert or delete data from the blob, and will 167662306a36Sopenharmony_ci * therefore change the offsets of some existing nodes. 167762306a36Sopenharmony_ci * 167862306a36Sopenharmony_ci * returns: 167962306a36Sopenharmony_ci * 0, on success 168062306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 168162306a36Sopenharmony_ci * contain the new property value 168262306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 168362306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 168462306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 168562306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 168662306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 168762306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 168862306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 168962306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 169062306a36Sopenharmony_ci */ 169162306a36Sopenharmony_cistatic inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name, 169262306a36Sopenharmony_ci uint32_t val) 169362306a36Sopenharmony_ci{ 169462306a36Sopenharmony_ci fdt32_t tmp = cpu_to_fdt32(val); 169562306a36Sopenharmony_ci return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 169662306a36Sopenharmony_ci} 169762306a36Sopenharmony_ci 169862306a36Sopenharmony_ci/** 169962306a36Sopenharmony_ci * fdt_setprop_u64 - set a property to a 64-bit integer 170062306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 170162306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 170262306a36Sopenharmony_ci * @name: name of the property to change 170362306a36Sopenharmony_ci * @val: 64-bit integer value for the property (native endian) 170462306a36Sopenharmony_ci * 170562306a36Sopenharmony_ci * fdt_setprop_u64() sets the value of the named property in the given 170662306a36Sopenharmony_ci * node to the given 64-bit integer value (converting to big-endian if 170762306a36Sopenharmony_ci * necessary), or creates a new property with that value if it does 170862306a36Sopenharmony_ci * not already exist. 170962306a36Sopenharmony_ci * 171062306a36Sopenharmony_ci * This function may insert or delete data from the blob, and will 171162306a36Sopenharmony_ci * therefore change the offsets of some existing nodes. 171262306a36Sopenharmony_ci * 171362306a36Sopenharmony_ci * returns: 171462306a36Sopenharmony_ci * 0, on success 171562306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 171662306a36Sopenharmony_ci * contain the new property value 171762306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 171862306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 171962306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 172062306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 172162306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 172262306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 172362306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 172462306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 172562306a36Sopenharmony_ci */ 172662306a36Sopenharmony_cistatic inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name, 172762306a36Sopenharmony_ci uint64_t val) 172862306a36Sopenharmony_ci{ 172962306a36Sopenharmony_ci fdt64_t tmp = cpu_to_fdt64(val); 173062306a36Sopenharmony_ci return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 173162306a36Sopenharmony_ci} 173262306a36Sopenharmony_ci 173362306a36Sopenharmony_ci/** 173462306a36Sopenharmony_ci * fdt_setprop_cell - set a property to a single cell value 173562306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 173662306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 173762306a36Sopenharmony_ci * @name: name of the property to change 173862306a36Sopenharmony_ci * @val: 32-bit integer value for the property (native endian) 173962306a36Sopenharmony_ci * 174062306a36Sopenharmony_ci * This is an alternative name for fdt_setprop_u32() 174162306a36Sopenharmony_ci * 174262306a36Sopenharmony_ci * Return: 0 on success, negative libfdt error value otherwise. 174362306a36Sopenharmony_ci */ 174462306a36Sopenharmony_cistatic inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name, 174562306a36Sopenharmony_ci uint32_t val) 174662306a36Sopenharmony_ci{ 174762306a36Sopenharmony_ci return fdt_setprop_u32(fdt, nodeoffset, name, val); 174862306a36Sopenharmony_ci} 174962306a36Sopenharmony_ci 175062306a36Sopenharmony_ci/** 175162306a36Sopenharmony_ci * fdt_setprop_string - set a property to a string value 175262306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 175362306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 175462306a36Sopenharmony_ci * @name: name of the property to change 175562306a36Sopenharmony_ci * @str: string value for the property 175662306a36Sopenharmony_ci * 175762306a36Sopenharmony_ci * fdt_setprop_string() sets the value of the named property in the 175862306a36Sopenharmony_ci * given node to the given string value (using the length of the 175962306a36Sopenharmony_ci * string to determine the new length of the property), or creates a 176062306a36Sopenharmony_ci * new property with that value if it does not already exist. 176162306a36Sopenharmony_ci * 176262306a36Sopenharmony_ci * This function may insert or delete data from the blob, and will 176362306a36Sopenharmony_ci * therefore change the offsets of some existing nodes. 176462306a36Sopenharmony_ci * 176562306a36Sopenharmony_ci * returns: 176662306a36Sopenharmony_ci * 0, on success 176762306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 176862306a36Sopenharmony_ci * contain the new property value 176962306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 177062306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 177162306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 177262306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 177362306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 177462306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 177562306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 177662306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 177762306a36Sopenharmony_ci */ 177862306a36Sopenharmony_ci#define fdt_setprop_string(fdt, nodeoffset, name, str) \ 177962306a36Sopenharmony_ci fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) 178062306a36Sopenharmony_ci 178162306a36Sopenharmony_ci 178262306a36Sopenharmony_ci/** 178362306a36Sopenharmony_ci * fdt_setprop_empty - set a property to an empty value 178462306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 178562306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 178662306a36Sopenharmony_ci * @name: name of the property to change 178762306a36Sopenharmony_ci * 178862306a36Sopenharmony_ci * fdt_setprop_empty() sets the value of the named property in the 178962306a36Sopenharmony_ci * given node to an empty (zero length) value, or creates a new empty 179062306a36Sopenharmony_ci * property if it does not already exist. 179162306a36Sopenharmony_ci * 179262306a36Sopenharmony_ci * This function may insert or delete data from the blob, and will 179362306a36Sopenharmony_ci * therefore change the offsets of some existing nodes. 179462306a36Sopenharmony_ci * 179562306a36Sopenharmony_ci * returns: 179662306a36Sopenharmony_ci * 0, on success 179762306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 179862306a36Sopenharmony_ci * contain the new property value 179962306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 180062306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 180162306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 180262306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 180362306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 180462306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 180562306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 180662306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 180762306a36Sopenharmony_ci */ 180862306a36Sopenharmony_ci#define fdt_setprop_empty(fdt, nodeoffset, name) \ 180962306a36Sopenharmony_ci fdt_setprop((fdt), (nodeoffset), (name), NULL, 0) 181062306a36Sopenharmony_ci 181162306a36Sopenharmony_ci/** 181262306a36Sopenharmony_ci * fdt_appendprop - append to or create a property 181362306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 181462306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 181562306a36Sopenharmony_ci * @name: name of the property to append to 181662306a36Sopenharmony_ci * @val: pointer to data to append to the property value 181762306a36Sopenharmony_ci * @len: length of the data to append to the property value 181862306a36Sopenharmony_ci * 181962306a36Sopenharmony_ci * fdt_appendprop() appends the value to the named property in the 182062306a36Sopenharmony_ci * given node, creating the property if it does not already exist. 182162306a36Sopenharmony_ci * 182262306a36Sopenharmony_ci * This function may insert data into the blob, and will therefore 182362306a36Sopenharmony_ci * change the offsets of some existing nodes. 182462306a36Sopenharmony_ci * 182562306a36Sopenharmony_ci * returns: 182662306a36Sopenharmony_ci * 0, on success 182762306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 182862306a36Sopenharmony_ci * contain the new property value 182962306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 183062306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 183162306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 183262306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 183362306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 183462306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 183562306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 183662306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 183762306a36Sopenharmony_ci */ 183862306a36Sopenharmony_ciint fdt_appendprop(void *fdt, int nodeoffset, const char *name, 183962306a36Sopenharmony_ci const void *val, int len); 184062306a36Sopenharmony_ci 184162306a36Sopenharmony_ci/** 184262306a36Sopenharmony_ci * fdt_appendprop_u32 - append a 32-bit integer value to a property 184362306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 184462306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 184562306a36Sopenharmony_ci * @name: name of the property to change 184662306a36Sopenharmony_ci * @val: 32-bit integer value to append to the property (native endian) 184762306a36Sopenharmony_ci * 184862306a36Sopenharmony_ci * fdt_appendprop_u32() appends the given 32-bit integer value 184962306a36Sopenharmony_ci * (converting to big-endian if necessary) to the value of the named 185062306a36Sopenharmony_ci * property in the given node, or creates a new property with that 185162306a36Sopenharmony_ci * value if it does not already exist. 185262306a36Sopenharmony_ci * 185362306a36Sopenharmony_ci * This function may insert data into the blob, and will therefore 185462306a36Sopenharmony_ci * change the offsets of some existing nodes. 185562306a36Sopenharmony_ci * 185662306a36Sopenharmony_ci * returns: 185762306a36Sopenharmony_ci * 0, on success 185862306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 185962306a36Sopenharmony_ci * contain the new property value 186062306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 186162306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 186262306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 186362306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 186462306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 186562306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 186662306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 186762306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 186862306a36Sopenharmony_ci */ 186962306a36Sopenharmony_cistatic inline int fdt_appendprop_u32(void *fdt, int nodeoffset, 187062306a36Sopenharmony_ci const char *name, uint32_t val) 187162306a36Sopenharmony_ci{ 187262306a36Sopenharmony_ci fdt32_t tmp = cpu_to_fdt32(val); 187362306a36Sopenharmony_ci return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 187462306a36Sopenharmony_ci} 187562306a36Sopenharmony_ci 187662306a36Sopenharmony_ci/** 187762306a36Sopenharmony_ci * fdt_appendprop_u64 - append a 64-bit integer value to a property 187862306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 187962306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 188062306a36Sopenharmony_ci * @name: name of the property to change 188162306a36Sopenharmony_ci * @val: 64-bit integer value to append to the property (native endian) 188262306a36Sopenharmony_ci * 188362306a36Sopenharmony_ci * fdt_appendprop_u64() appends the given 64-bit integer value 188462306a36Sopenharmony_ci * (converting to big-endian if necessary) to the value of the named 188562306a36Sopenharmony_ci * property in the given node, or creates a new property with that 188662306a36Sopenharmony_ci * value if it does not already exist. 188762306a36Sopenharmony_ci * 188862306a36Sopenharmony_ci * This function may insert data into the blob, and will therefore 188962306a36Sopenharmony_ci * change the offsets of some existing nodes. 189062306a36Sopenharmony_ci * 189162306a36Sopenharmony_ci * returns: 189262306a36Sopenharmony_ci * 0, on success 189362306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 189462306a36Sopenharmony_ci * contain the new property value 189562306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 189662306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 189762306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 189862306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 189962306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 190062306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 190162306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 190262306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 190362306a36Sopenharmony_ci */ 190462306a36Sopenharmony_cistatic inline int fdt_appendprop_u64(void *fdt, int nodeoffset, 190562306a36Sopenharmony_ci const char *name, uint64_t val) 190662306a36Sopenharmony_ci{ 190762306a36Sopenharmony_ci fdt64_t tmp = cpu_to_fdt64(val); 190862306a36Sopenharmony_ci return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); 190962306a36Sopenharmony_ci} 191062306a36Sopenharmony_ci 191162306a36Sopenharmony_ci/** 191262306a36Sopenharmony_ci * fdt_appendprop_cell - append a single cell value to a property 191362306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 191462306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 191562306a36Sopenharmony_ci * @name: name of the property to change 191662306a36Sopenharmony_ci * @val: 32-bit integer value to append to the property (native endian) 191762306a36Sopenharmony_ci * 191862306a36Sopenharmony_ci * This is an alternative name for fdt_appendprop_u32() 191962306a36Sopenharmony_ci * 192062306a36Sopenharmony_ci * Return: 0 on success, negative libfdt error value otherwise. 192162306a36Sopenharmony_ci */ 192262306a36Sopenharmony_cistatic inline int fdt_appendprop_cell(void *fdt, int nodeoffset, 192362306a36Sopenharmony_ci const char *name, uint32_t val) 192462306a36Sopenharmony_ci{ 192562306a36Sopenharmony_ci return fdt_appendprop_u32(fdt, nodeoffset, name, val); 192662306a36Sopenharmony_ci} 192762306a36Sopenharmony_ci 192862306a36Sopenharmony_ci/** 192962306a36Sopenharmony_ci * fdt_appendprop_string - append a string to a property 193062306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 193162306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to change 193262306a36Sopenharmony_ci * @name: name of the property to change 193362306a36Sopenharmony_ci * @str: string value to append to the property 193462306a36Sopenharmony_ci * 193562306a36Sopenharmony_ci * fdt_appendprop_string() appends the given string to the value of 193662306a36Sopenharmony_ci * the named property in the given node, or creates a new property 193762306a36Sopenharmony_ci * with that value if it does not already exist. 193862306a36Sopenharmony_ci * 193962306a36Sopenharmony_ci * This function may insert data into the blob, and will therefore 194062306a36Sopenharmony_ci * change the offsets of some existing nodes. 194162306a36Sopenharmony_ci * 194262306a36Sopenharmony_ci * returns: 194362306a36Sopenharmony_ci * 0, on success 194462306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 194562306a36Sopenharmony_ci * contain the new property value 194662306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 194762306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 194862306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 194962306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 195062306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 195162306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 195262306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 195362306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 195462306a36Sopenharmony_ci */ 195562306a36Sopenharmony_ci#define fdt_appendprop_string(fdt, nodeoffset, name, str) \ 195662306a36Sopenharmony_ci fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) 195762306a36Sopenharmony_ci 195862306a36Sopenharmony_ci/** 195962306a36Sopenharmony_ci * fdt_appendprop_addrrange - append a address range property 196062306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 196162306a36Sopenharmony_ci * @parent: offset of the parent node 196262306a36Sopenharmony_ci * @nodeoffset: offset of the node to add a property at 196362306a36Sopenharmony_ci * @name: name of property 196462306a36Sopenharmony_ci * @addr: start address of a given range 196562306a36Sopenharmony_ci * @size: size of a given range 196662306a36Sopenharmony_ci * 196762306a36Sopenharmony_ci * fdt_appendprop_addrrange() appends an address range value (start 196862306a36Sopenharmony_ci * address and size) to the value of the named property in the given 196962306a36Sopenharmony_ci * node, or creates a new property with that value if it does not 197062306a36Sopenharmony_ci * already exist. 197162306a36Sopenharmony_ci * If "name" is not specified, a default "reg" is used. 197262306a36Sopenharmony_ci * Cell sizes are determined by parent's #address-cells and #size-cells. 197362306a36Sopenharmony_ci * 197462306a36Sopenharmony_ci * This function may insert data into the blob, and will therefore 197562306a36Sopenharmony_ci * change the offsets of some existing nodes. 197662306a36Sopenharmony_ci * 197762306a36Sopenharmony_ci * returns: 197862306a36Sopenharmony_ci * 0, on success 197962306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 198062306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 198162306a36Sopenharmony_ci * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid 198262306a36Sopenharmony_ci * #address-cells property 198362306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 198462306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 198562306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 198662306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 198762306a36Sopenharmony_ci * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size 198862306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 198962306a36Sopenharmony_ci * contain a new property 199062306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 199162306a36Sopenharmony_ci */ 199262306a36Sopenharmony_ciint fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset, 199362306a36Sopenharmony_ci const char *name, uint64_t addr, uint64_t size); 199462306a36Sopenharmony_ci 199562306a36Sopenharmony_ci/** 199662306a36Sopenharmony_ci * fdt_delprop - delete a property 199762306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 199862306a36Sopenharmony_ci * @nodeoffset: offset of the node whose property to nop 199962306a36Sopenharmony_ci * @name: name of the property to nop 200062306a36Sopenharmony_ci * 200162306a36Sopenharmony_ci * fdt_del_property() will delete the given property. 200262306a36Sopenharmony_ci * 200362306a36Sopenharmony_ci * This function will delete data from the blob, and will therefore 200462306a36Sopenharmony_ci * change the offsets of some existing nodes. 200562306a36Sopenharmony_ci * 200662306a36Sopenharmony_ci * returns: 200762306a36Sopenharmony_ci * 0, on success 200862306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, node does not have the named property 200962306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 201062306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 201162306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 201262306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 201362306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 201462306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 201562306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 201662306a36Sopenharmony_ci */ 201762306a36Sopenharmony_ciint fdt_delprop(void *fdt, int nodeoffset, const char *name); 201862306a36Sopenharmony_ci 201962306a36Sopenharmony_ci/** 202062306a36Sopenharmony_ci * fdt_add_subnode_namelen - creates a new node based on substring 202162306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 202262306a36Sopenharmony_ci * @parentoffset: structure block offset of a node 202362306a36Sopenharmony_ci * @name: name of the subnode to create 202462306a36Sopenharmony_ci * @namelen: number of characters of name to consider 202562306a36Sopenharmony_ci * 202662306a36Sopenharmony_ci * Identical to fdt_add_subnode(), but use only the first @namelen 202762306a36Sopenharmony_ci * characters of @name as the name of the new node. This is useful for 202862306a36Sopenharmony_ci * creating subnodes based on a portion of a larger string, such as a 202962306a36Sopenharmony_ci * full path. 203062306a36Sopenharmony_ci * 203162306a36Sopenharmony_ci * Return: structure block offset of the created subnode (>=0), 203262306a36Sopenharmony_ci * negative libfdt error value otherwise 203362306a36Sopenharmony_ci */ 203462306a36Sopenharmony_ci#ifndef SWIG /* Not available in Python */ 203562306a36Sopenharmony_ciint fdt_add_subnode_namelen(void *fdt, int parentoffset, 203662306a36Sopenharmony_ci const char *name, int namelen); 203762306a36Sopenharmony_ci#endif 203862306a36Sopenharmony_ci 203962306a36Sopenharmony_ci/** 204062306a36Sopenharmony_ci * fdt_add_subnode - creates a new node 204162306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 204262306a36Sopenharmony_ci * @parentoffset: structure block offset of a node 204362306a36Sopenharmony_ci * @name: name of the subnode to locate 204462306a36Sopenharmony_ci * 204562306a36Sopenharmony_ci * fdt_add_subnode() creates a new node as a subnode of the node at 204662306a36Sopenharmony_ci * structure block offset parentoffset, with the given name (which 204762306a36Sopenharmony_ci * should include the unit address, if any). 204862306a36Sopenharmony_ci * 204962306a36Sopenharmony_ci * This function will insert data into the blob, and will therefore 205062306a36Sopenharmony_ci * change the offsets of some existing nodes. 205162306a36Sopenharmony_ci * 205262306a36Sopenharmony_ci * returns: 205362306a36Sopenharmony_ci * structure block offset of the created nodeequested subnode (>=0), on 205462306a36Sopenharmony_ci * success 205562306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, if the requested subnode does not exist 205662306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE 205762306a36Sopenharmony_ci * tag 205862306a36Sopenharmony_ci * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of 205962306a36Sopenharmony_ci * the given name 206062306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, if there is insufficient free space in the 206162306a36Sopenharmony_ci * blob to contain the new node 206262306a36Sopenharmony_ci * -FDT_ERR_NOSPACE 206362306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT 206462306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 206562306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 206662306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 206762306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 206862306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings. 206962306a36Sopenharmony_ci */ 207062306a36Sopenharmony_ciint fdt_add_subnode(void *fdt, int parentoffset, const char *name); 207162306a36Sopenharmony_ci 207262306a36Sopenharmony_ci/** 207362306a36Sopenharmony_ci * fdt_del_node - delete a node (subtree) 207462306a36Sopenharmony_ci * @fdt: pointer to the device tree blob 207562306a36Sopenharmony_ci * @nodeoffset: offset of the node to nop 207662306a36Sopenharmony_ci * 207762306a36Sopenharmony_ci * fdt_del_node() will remove the given node, including all its 207862306a36Sopenharmony_ci * subnodes if any, from the blob. 207962306a36Sopenharmony_ci * 208062306a36Sopenharmony_ci * This function will delete data from the blob, and will therefore 208162306a36Sopenharmony_ci * change the offsets of some existing nodes. 208262306a36Sopenharmony_ci * 208362306a36Sopenharmony_ci * returns: 208462306a36Sopenharmony_ci * 0, on success 208562306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 208662306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 208762306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 208862306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 208962306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 209062306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 209162306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 209262306a36Sopenharmony_ci */ 209362306a36Sopenharmony_ciint fdt_del_node(void *fdt, int nodeoffset); 209462306a36Sopenharmony_ci 209562306a36Sopenharmony_ci/** 209662306a36Sopenharmony_ci * fdt_overlay_apply - Applies a DT overlay on a base DT 209762306a36Sopenharmony_ci * @fdt: pointer to the base device tree blob 209862306a36Sopenharmony_ci * @fdto: pointer to the device tree overlay blob 209962306a36Sopenharmony_ci * 210062306a36Sopenharmony_ci * fdt_overlay_apply() will apply the given device tree overlay on the 210162306a36Sopenharmony_ci * given base device tree. 210262306a36Sopenharmony_ci * 210362306a36Sopenharmony_ci * Expect the base device tree to be modified, even if the function 210462306a36Sopenharmony_ci * returns an error. 210562306a36Sopenharmony_ci * 210662306a36Sopenharmony_ci * returns: 210762306a36Sopenharmony_ci * 0, on success 210862306a36Sopenharmony_ci * -FDT_ERR_NOSPACE, there's not enough space in the base device tree 210962306a36Sopenharmony_ci * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or 211062306a36Sopenharmony_ci * properties in the base DT 211162306a36Sopenharmony_ci * -FDT_ERR_BADPHANDLE, 211262306a36Sopenharmony_ci * -FDT_ERR_BADOVERLAY, 211362306a36Sopenharmony_ci * -FDT_ERR_NOPHANDLES, 211462306a36Sopenharmony_ci * -FDT_ERR_INTERNAL, 211562306a36Sopenharmony_ci * -FDT_ERR_BADLAYOUT, 211662306a36Sopenharmony_ci * -FDT_ERR_BADMAGIC, 211762306a36Sopenharmony_ci * -FDT_ERR_BADOFFSET, 211862306a36Sopenharmony_ci * -FDT_ERR_BADPATH, 211962306a36Sopenharmony_ci * -FDT_ERR_BADVERSION, 212062306a36Sopenharmony_ci * -FDT_ERR_BADSTRUCTURE, 212162306a36Sopenharmony_ci * -FDT_ERR_BADSTATE, 212262306a36Sopenharmony_ci * -FDT_ERR_TRUNCATED, standard meanings 212362306a36Sopenharmony_ci */ 212462306a36Sopenharmony_ciint fdt_overlay_apply(void *fdt, void *fdto); 212562306a36Sopenharmony_ci 212662306a36Sopenharmony_ci/** 212762306a36Sopenharmony_ci * fdt_overlay_target_offset - retrieves the offset of a fragment's target 212862306a36Sopenharmony_ci * @fdt: Base device tree blob 212962306a36Sopenharmony_ci * @fdto: Device tree overlay blob 213062306a36Sopenharmony_ci * @fragment_offset: node offset of the fragment in the overlay 213162306a36Sopenharmony_ci * @pathp: pointer which receives the path of the target (or NULL) 213262306a36Sopenharmony_ci * 213362306a36Sopenharmony_ci * fdt_overlay_target_offset() retrieves the target offset in the base 213462306a36Sopenharmony_ci * device tree of a fragment, no matter how the actual targeting is 213562306a36Sopenharmony_ci * done (through a phandle or a path) 213662306a36Sopenharmony_ci * 213762306a36Sopenharmony_ci * returns: 213862306a36Sopenharmony_ci * the targeted node offset in the base device tree 213962306a36Sopenharmony_ci * Negative error code on error 214062306a36Sopenharmony_ci */ 214162306a36Sopenharmony_ciint fdt_overlay_target_offset(const void *fdt, const void *fdto, 214262306a36Sopenharmony_ci int fragment_offset, char const **pathp); 214362306a36Sopenharmony_ci 214462306a36Sopenharmony_ci/**********************************************************************/ 214562306a36Sopenharmony_ci/* Debugging / informational functions */ 214662306a36Sopenharmony_ci/**********************************************************************/ 214762306a36Sopenharmony_ci 214862306a36Sopenharmony_ciconst char *fdt_strerror(int errval); 214962306a36Sopenharmony_ci 215062306a36Sopenharmony_ci#ifdef __cplusplus 215162306a36Sopenharmony_ci} 215262306a36Sopenharmony_ci#endif 215362306a36Sopenharmony_ci 215462306a36Sopenharmony_ci#endif /* LIBFDT_H */ 2155