Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:14

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 2013-2017 Chris Johns <chrisj@rtems.org>
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  *
0027  *  Interface based on the libdft:
0028  *    libfdt - Flat Device Tree manipulation
0029  *    Copyright (C) 2006 David Gibson, IBM Corporation.
0030  */
0031 /**
0032  * @file
0033  *
0034  * @ingroup rtems_fdt
0035  *
0036  * @brief RTEMS Flattened Device Tree
0037  *
0038  * Support for loading, managing and accessing FDT blobs in RTEMS.
0039  */
0040 
0041 #if !defined (_RTEMS_FDT_H_)
0042 #define _RTEMS_FDT_H_
0043 
0044 #include <rtems.h>
0045 #include <rtems/chain.h>
0046 
0047 #ifdef __cplusplus
0048 extern "C" {
0049 #endif /* __cplusplus */
0050 
0051 /**
0052  * A blob.
0053  */
0054 struct rtems_fdt_blob;
0055 typedef struct rtems_fdt_blob rtems_fdt_blob;
0056 
0057 /**
0058  * A blob handle is a way to manage access to the FDT blobs. The blob is
0059  * referenced via the handle to allow searches across loaded DTB's to return
0060  * the referenced DTB.
0061  */
0062 typedef struct
0063 {
0064   rtems_fdt_blob* blob;  /**< The blob the handle references. */
0065 } rtems_fdt_handle;
0066 
0067 /**
0068  * FDT Address property. It is an address an optionally a size.
0069  *
0070  * Only 32bit addresses and sizes on 32bit machine. Ignore the upper
0071  * 32bits.
0072  */
0073 typedef struct
0074 {
0075   int node;
0076   uint64_t address;
0077   uint64_t size;
0078   int      address_cells;
0079   int      size_cells;
0080 } rtems_fdt_address_map;
0081 
0082 /*
0083  * The following are mappings to the standard FDT calls.
0084  */
0085 
0086 /**
0087  * RTEMS_FDT_ERR_NOTFOUND: The requested node or property does not exist
0088  */
0089 #define RTEMS_FDT_ERR_NOTFOUND  1
0090 /**
0091  * RTEMS_FDT_ERR_EXISTS: Attemped to create a node or property which already
0092  * exists */
0093 #define RTEMS_FDT_ERR_EXISTS    2
0094 /**
0095  * RTEMS_FDT_ERR_NOSPACE: Operation needed to expand the device tree, but its
0096  * buffer did not have sufficient space to contain the expanded tree. Use
0097  * rtems_fdt_open_into() to move the device tree to a buffer with more space.
0098  */
0099 #define RTEMS_FDT_ERR_NOSPACE    3
0100 
0101 /* Error codes: codes for bad parameters */
0102 /**
0103  * RTEMS_FDT_ERR_BADOFFSET: Function was passed a structure block offset which
0104  * is out-of-bounds, or which points to an unsuitable part of the structure for
0105  * the operation.
0106  */
0107 #define RTEMS_FDT_ERR_BADOFFSET  4
0108 /**
0109  * RTEMS_FDT_ERR_BADPATH: Function was passed a badly formatted path
0110  * (e.g. missing a leading / for a function which requires an absolute path)
0111 */
0112 #define RTEMS_FDT_ERR_BADPATH    5
0113 /**
0114  * RTEMS_FDT_ERR_BADPHANDLE: Function was passed an invalid phandle value.
0115  * phandle values of 0 and -1 are not permitted.
0116  */
0117 #define RTEMS_FDT_ERR_BADPHANDLE  6
0118 /**
0119  * RTEMS_FDT_ERR_BADSTATE: Function was passed an incomplete device tree
0120  * created by the sequential-write functions, which is not sufficiently
0121  * complete for the requested operation.
0122  */
0123 #define RTEMS_FDT_ERR_BADSTATE  7
0124 
0125 /* Error codes: codes for bad device tree blobs */
0126 
0127 /**
0128  * RTEMS_FDT_ERR_TRUNCATED: Structure block of the given device tree ends
0129  * without an RTEMS_FDT_END tag.
0130  */
0131 #define RTEMS_FDT_ERR_TRUNCATED  8
0132 /**
0133  * RTEMS_FDT_ERR_BADMAGIC: Given "device tree" appears not to be a device tree
0134  * at all - it is missing the flattened device tree magic number.
0135  */
0136 #define RTEMS_FDT_ERR_BADMAGIC  9
0137 /** RTEMS_FDT_ERR_BADVERSION: Given device tree has a version which can't be
0138  * handled by the requested operation.  For read-write functions, this may mean
0139  * that rtems_fdt_open_into() is required to convert the tree to the expected
0140  * version.
0141  */
0142 #define RTEMS_FDT_ERR_BADVERSION  10
0143 /**
0144  * RTEMS_FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt structure block
0145  * or other serious error (e.g. misnested nodes, or subnodes preceding
0146  * properties).
0147  */
0148 #define RTEMS_FDT_ERR_BADSTRUCTURE  11
0149 /**
0150  * RTEMS_FDT_ERR_BADLAYOUT: For read-write functions, the given device tree has
0151  * it's sub-blocks in an order that the function can't handle (memory reserve
0152  * map, then structure, then strings).  Use rtems_fdt_open_into() to reorganize
0153  * the tree into a form suitable for the read-write operations.
0154  */
0155 #define RTEMS_FDT_ERR_BADLAYOUT  12
0156 /**
0157  * "Can't happen" error indicating a bug in libfdt
0158  */
0159 #define RTEMS_FDT_ERR_INTERNAL  13
0160 
0161 /* RTEMS error codes. */
0162 
0163 /**
0164  * Invalid handle.
0165  */
0166 #define RTEMS_FDT_ERR_INVALID_HANDLE 100
0167 /**
0168  * No memory.
0169  */
0170 #define RTEMS_FDT_ERR_NO_MEMORY      101
0171 /**
0172  * File not found.
0173  */
0174 #define RTEMS_FDT_ERR_NOT_FOUND      102
0175 /**
0176  * Cannot read the DTB into memory.
0177  */
0178 #define RTEMS_FDT_ERR_READ_FAIL      103
0179 /**
0180  * The blob cannot be unloaded as it is referenced.
0181  */
0182 #define RTEMS_FDT_ERR_REFERENCED     104
0183 /**
0184  * The property length is invalid
0185  */
0186 #define RTEMS_FDT_ERR_BADLENGTH      105
0187 
0188 #define RTEMS_FDT_ERR_RTEMS_MIN      100
0189 #define RTEMS_FDT_ERR_MAX            105
0190 
0191 /**
0192  * Initialise a handle to a default state.
0193  *
0194  * @param handle The handle to initialise.
0195  */
0196 void rtems_fdt_init_handle (rtems_fdt_handle* handle);
0197 
0198 /**
0199  * Duplicate a handle. The copy must be released.
0200  *
0201  * @param from Duplicate from this handle.
0202  * @param to   Duplicate to this handle.
0203  */
0204 void rtems_fdt_dup_handle (rtems_fdt_handle* from, rtems_fdt_handle* to);
0205 
0206 /**
0207  * Release a blob from a handle and clear it.
0208  *
0209  * @param handle The handle to check.
0210  */
0211 void rtems_fdt_release_handle (rtems_fdt_handle* handle);
0212 
0213 /**
0214  * Check if a handle had a valid blob assigned.
0215  *
0216  * @param handle The handle to check.
0217  * @retval true The handle has a valid blob.
0218  * @retval false The handle does not have a valid blob.
0219  */
0220 bool rtems_fdt_valid_handle (const rtems_fdt_handle* handle);
0221 
0222 /**
0223  * Find a tree node by its full path looking across of loaded blobs.. Each path
0224  * component may omit the unit address portion, but the results of this are
0225  * undefined if any such path component is ambiguous (that is if there are
0226  * multiple nodes at the relevant level matching the given component,
0227  * differentiated only by unit address).
0228  *
0229  * If the handle points to a valid blob it is release and the search starts
0230  * from the first blob.
0231  *
0232  * @param handle The FDT handle assigned to the blob if found else left invalid.
0233  * @param path Full path of the node to locate.
0234  * @param int If less than 0 an error code else the node offset is returned.
0235  */
0236 int rtems_fdt_find_path_offset (rtems_fdt_handle* handle, const char* path);
0237 
0238 /**
0239  * Load a device tree blob or DTB file into memory and register it on the chain
0240  * of blobs.
0241  *
0242  * @param filename The name of the blob file to load.
0243  * @param handle The handle returns the reference to the blob once load.
0244  * @return int If less than 0 it is an error code else it is the blob descriptor.
0245  */
0246 int rtems_fdt_load (const char* const filename, rtems_fdt_handle* handle);
0247 
0248 /**
0249  * Register a device tree blob or DTB on to the chain of blobs.
0250  *
0251  * @param blob_desc A pointer to the blob.
0252  * @param handle The handle returns the reference to the blob once load.
0253  * @return int If less than 0 it is an error code else it is the blob descriptor.
0254  */
0255 int rtems_fdt_register (const void* blob, rtems_fdt_handle* handle);
0256 
0257 /**
0258  * Unload a device tree blob or DTB file and release any memory allocated when
0259  * loading. The blob is removed from the list if registered.
0260  *
0261  * @param blob_desc A valid blob descriptor.
0262  * @return int If less than 0 it is an error code else 0 is return on success.
0263  */
0264 int rtems_fdt_unload (rtems_fdt_handle* handle);
0265 
0266 /**
0267  * Returns the number of entries in the device tree blob's memory
0268  * reservation map.  This does not include the terminating 0,0 entry
0269  * or any other (0,0) entries reserved for expansion.
0270  *
0271  * @param blob_desc A valid blob descriptor.
0272  * @return int The number of entries.
0273  */
0274 int rtems_fdt_num_mem_rsv (rtems_fdt_handle* handle);
0275 
0276 /**
0277  * Retrieve one memory reserve map entry. On success, *address and *size will
0278  * contain the address and size of the n-th reserve map entry from the device
0279  * tree blob, in native-endian format.
0280  *
0281  * @param blob_desc A valid blob descriptor.
0282  * @param address Pointer to 64-bit variables to hold the addresses.
0283  * @param size Pointer to 64-bit variables to hold the size.
0284  * @return int If less than 0 it is an error code else 0 is returned on
0285  *             success.
0286  */
0287 int rtems_fdt_get_mem_rsv (rtems_fdt_handle* handle,
0288                            int               n,
0289                            uint64_t*         address,
0290                            uint64_t*         size);
0291 
0292 /**
0293  * Find a subnode based on substring. Identical to rtems_fdt_subnode_offset(),
0294  * but only examine the first namelen characters of name for matching the
0295  * subnode name. This is useful for finding subnodes based on a portion of a
0296  * larger string, such as a full path.
0297  *
0298  * @param blob_desc A valid blob descriptor.
0299  * @param parentoffset Structure block offset of a node
0300  * @param name Name of the subnode to locate.
0301  * @param namelen Number of characters of name to consider.
0302  * @return int If less than 0 it is an error code else the node offset is
0303  *             returned.
0304  */
0305 int rtems_fdt_subnode_offset_namelen (rtems_fdt_handle* handle,
0306                                       int               parentoffset,
0307                                       const char* const name,
0308                                       int               namelen);
0309 
0310 /**
0311  * Find a subnode of a given node at structure block offset parentoffset with
0312  * the given name. The name may include a unit address, in which case
0313  * rtems_fdt_subnode_offset() will find the subnode with that unit address, or
0314  * the unit address may be omitted, in which case rtems_fdt_subnode_offset()
0315  * will find an arbitrary subnode whose name excluding unit address matches the
0316  * given name.
0317  *
0318  * @param blob_desc A valid blob descriptor.
0319  * @param parentoffset Structure block offset of a node.
0320  * @param name The name of the subnode to locate.
0321  * @return int If less than 0 it is an error code else the subnode offset is
0322  *             returned.
0323  */
0324 int rtems_fdt_subnode_offset (rtems_fdt_handle* handle,
0325                               int               parentoffset,
0326                               const char* const name);
0327 
0328 /**
0329  * Find a tree node by its full path. Each path component may omit the unit
0330  * address portion, but the results of this are undefined if any such path
0331  * component is ambiguous (that is if there are multiple nodes at the relevant
0332  * level matching the given component, differentiated only by unit address).
0333  *
0334  * @param handle The FDT handle to the current blob.
0335  * @param path Full path of the node to locate.
0336  * @param int If less than 0 an error code else the node offset is returned.
0337  */
0338 int rtems_fdt_path_offset (rtems_fdt_handle* handle, const char* path);
0339 
0340 /**
0341  * Retrieve the name of a given node (including unit address) of the device
0342  * tree node at structure block offset @nodeoffset.  If @length is non-NULL,
0343  * the length of this name is also returned, in the integer pointed to by
0344  * @length.
0345  *
0346  * @param handle The FDT handle to the current blob.
0347  * @param nodeoffset Structure block offset of the starting node.
0348  * @param length Pointer to an integer variable or NULL. If non-NULL, this will
0349  *               be overwritten with either the length in bytes or the error
0350  *               code.
0351  * @return const char* The node's name on success or NULL on error. The length
0352  *                     if non-NULL will hold the error code.
0353  */
0354 const char* rtems_fdt_get_name (rtems_fdt_handle* handle,
0355                                 int               nodeoffset,
0356                                 int*              length);
0357 
0358 /**
0359  * Retrieve the offset for the first property for a node.
0360  *
0361  * @param handle The FDT handle to the current blob.
0362  * @param nodeoffset Structure block offset of the starting node.
0363  * @return int The offset of a node's first property.
0364  */
0365 int rtems_fdt_first_prop_offset(rtems_fdt_handle* handle, int nodeoffset);
0366 
0367 /**
0368  * Retrieve the next property of a node relative to the property
0369  *
0370  * @param handle The FDT handle to the current blob.
0371  * @param propoffset Property offset to search from
0372  * @return int Property offset or end if less than 0.
0373  */
0374 int rtems_fdt_next_prop_offset(rtems_fdt_handle* handle, int propoffset);
0375 
0376 /**
0377  * Retrieve the property value, name and length of name given a
0378  * property offset.
0379  *
0380  * @param handle The FDT handle to the current blob.
0381  * @param propoffset Property offset
0382  * @param name If not NULL set the pointer to the name string.
0383  * @param length Pointer to an integer variable or NULL. If non-NULL, this will
0384  *               be overwritten with either the length in bytes or the error
0385  *               code.
0386  * @return const void* The node's value data.
0387  */
0388 const void* rtems_fdt_getprop_by_offset(rtems_fdt_handle* handle,
0389                                         int               propoffset,
0390                                         const char**      name,
0391                                         int*              length);
0392 
0393 /**
0394  * Get property value based on substring. Identical to rtems_fdt_getprop(), but
0395  * only examine the first namelen characters of name for matching the property
0396  * name.
0397  *
0398  * @param handle The FDT handle to the current blob.
0399  * @param nodeoffset Offset of the node whose property to find
0400  * @param name The name of the property to find
0401  * @param namelen The number of characters of name to consider
0402  * @param length Pointer to an integer variable or NULL. If non-NULL, this will
0403  *               be overwritten with either the length in bytes or the error
0404  *               code.
0405  * @return const void* The node's property on success or NULL on error. The
0406  *                     length if non-NULL will hold the error code.
0407  */
0408 const void *rtems_fdt_getprop_namelen (rtems_fdt_handle* handle,
0409                                        int               nodeoffset,
0410                                        const char* const name,
0411                                        int               namelen,
0412                                        int*              length);
0413 
0414 /**
0415  * Retrieve the value of a given property. Retrieves a pointer to the value of
0416  * the property named 'name' of the node at offset nodeoffset (this will be a
0417  * pointer to within the device blob itself, not a copy of the value).  If lenp
0418  * is non-NULL, the length of the property value is also returned, in the
0419  * integer pointed to by @length.
0420  *
0421  * @param handle The FDT handle to the current blob.
0422  * @param nodeoffset The offset of the node whose property to find.
0423  * @param name The name of the property to find.
0424  * @param length Pointer to an integer variable or NULL. If non-NULL, this will
0425  *               be overwritten with either the length in bytes or the error
0426  *               code.
0427  * @return const void* The node's property on success or NULL on error. The
0428  *                     length if non-NULL will hold the error code.
0429  */
0430 const void *rtems_fdt_getprop (rtems_fdt_handle* handle,
0431                                int               nodeoffset,
0432                                const char* const name,
0433                                int*              length);
0434 
0435 /**
0436  * Retrieve the phandle of the device tree node at structure block
0437  * offset nodeoffset.
0438  *
0439  * @param handle The FDT handle to the current blob.
0440  * @oaram nodeoffset The structure block offset of the node.
0441  * return uint32_t The phandle of the node at nodeoffset, on success (!= 0, !=
0442  *                  -1) 0, if the node has no phandle, or another error occurs.
0443  */
0444 uint32_t rtems_fdt_get_phandle (rtems_fdt_handle* handle, int nodeoffset);
0445 
0446 /**
0447  * Get alias based on substring. Identical to rtems_fdt_get_alias(), but only
0448  * examine the first namelen characters of name for matching the alias name.
0449  *
0450  * @param handle The FDT handle to the current blob.
0451  * @param name The name of the alias th look up.
0452  * @param namelen The number of characters of name to consider.
0453  * @return const char* The alias or NULL.
0454  */
0455 const char *rtems_fdt_get_alias_namelen (rtems_fdt_handle* handle,
0456                                          const char* const name,
0457                                          int               namelen);
0458 
0459 /**
0460  * Retreive the path referenced by a given alias. That is, the value of the
0461  * property named 'name' in the node /aliases.
0462  *
0463  * @param handle The FDT handle to the current blob.
0464  * @param name The name of the alias to look up.
0465  * @return const char* A pointer to the expansion of the alias named 'name', of
0466  *                     it exists NULL, if the given alias or the /aliases node
0467  *                     does not exist
0468  */
0469 const char* rtems_fdt_get_alias (rtems_fdt_handle* handle, const char* name);
0470 
0471 /**
0472  * Determine the full path of a node. This function is expensive, as it must
0473  * scan the device tree structure from the start to nodeoffset. It computes the
0474  * full path of the node at offset nodeoffset, and records that path in the
0475  * buffer at buf.
0476  *
0477  * @param handle The FDT handle to the current blob.
0478  * @param nodeoffset The offset of the node whose path to find.
0479  * @param buf A character buffer to contain the returned path (will be
0480  *            overwritten)
0481  * @param buflen The size of the character buffer at buf.
0482  * @return int 0 on success of an error code.
0483  */
0484 int rtems_fdt_get_path (rtems_fdt_handle* handle,
0485                         int               nodeoffset,
0486                         char*             buf,
0487                         int               buflen);
0488 
0489 /**
0490  * Find a specific ancestor of a node at a specific depth from the root (where
0491  * the root itself has depth 0, its immediate subnodes depth 1 and so forth).
0492  * So rtems_fdt_supernode_atdepth_offset(blob, nodeoffset, 0, NULL); will
0493  * always return 0, the offset of the root node. If the node at nodeoffset has
0494  * depth D, then:
0495  *  rtems_fdt_supernode_atdepth_offset(blob, nodeoffset, D, NULL);
0496  * will return nodeoffset itself.
0497  *
0498  * @param handle The FDT handle to the current blob.
0499  * @param nodeoffset The offset of the node whose parent to find.
0500  * @param supernodedepth The depth of the ancestor to find.
0501  * @oaram nodedepth The pointer to an integer variable (will be overwritten) or
0502  *                  NULL
0503  * @return int If less than 0 an error else the node offset.
0504  */
0505 int rtems_fdt_supernode_atdepth_offset (rtems_fdt_handle* handle,
0506                                         int               nodeoffset,
0507                                         int               supernodedepth,
0508                                         int*              nodedepth);
0509 
0510 /**
0511  * Find the depth of a given node. The root node has depth 0, its immediate
0512  * subnodes depth 1 and so forth.
0513  *
0514  * @note This function is expensive, as it must scan the device tree structure
0515  * from the start to nodeoffset.
0516  *
0517  * @param handle The FDT handle to the current blob.
0518  * @param nodeoffset The offset of the node whose parent to find.
0519  * @return int If less than 0 an error else the node offset.
0520  */
0521 int rtems_fdt_node_depth (rtems_fdt_handle* handle, int nodeoffset);
0522 
0523 /**
0524  * Find the parent of a given node. This funciton locates the parent node of a
0525  * given node (that is, it finds the offset of the node which contains the node
0526  * at nodeoffset as a subnode).
0527  *
0528  * @note This function is expensive, as it must scan the device tree structure
0529  * from the start to nodeoffset, *twice*.
0530  *
0531  * @param handle The FDT handle to the current blob.
0532  * @param nodeoffset The offset of the node whose parent to find.
0533  * @return int If less than 0 an error else the node offset.
0534  */
0535 int rtems_fdt_parent_offset (rtems_fdt_handle* handle, int nodeoffset);
0536 
0537 /**
0538  * Find nodes with a given property value. This funtion returns the offset of
0539  * the first node after startoffset, which has a property named propname whose
0540  * value is of length proplen and has value equal to propval; or if startoffset
0541  * is -1, the very first such node in the tree.
0542  *
0543  * To iterate through all nodes matching the criterion, the following idiom can
0544  * be used:
0545  *  offset = rtemsfdt_node_offset_by_prop_value(blob, -1, propname,
0546  *                                              propval, proplen);
0547  *  while (offset != -RTEMS_FDT_ERR_NOTFOUND) {
0548  *    // other code here
0549  *    offset = rtems_fdt_node_offset_by_prop_value(fdt, offset, propname,
0550  *                                                 propval, proplen);
0551  *  }
0552  *
0553  * @note The -1 in the first call to the function, if 0 is used here
0554  * instead, the function will never locate the root node, even if it
0555  * matches the criterion.
0556  *
0557  * @param handle The FDT handle to the current blob.
0558  * @param startoffset Only find nodes after this offset.
0559  * @param propname The property name to check.
0560  * @param propval The property value to search for.
0561  * @param proplen The length of the value in propval.
0562  * @return int The structure block offset of the located node (>= 0,
0563  *             >startoffset), on success and an error code is less
0564  *             than 0.
0565  */
0566 int rtems_fdt_node_offset_by_prop_value (rtems_fdt_handle* handle,
0567                                          int               startoffset,
0568                                          const char* const propname,
0569                                          const void*       propval,
0570                                          int               proplen);
0571 
0572 /**
0573  * Find the node with a given phandle returning the offset of the node which
0574  * has the given phandle value. If there is more than one node in the tree
0575  * with the given phandle (an invalid tree), results are undefined.
0576  *
0577  * @param handle The FDT handle to the current blob.
0578  * @param phandle The phandle value.
0579  * @return int If less than 0 an error else the node offset.
0580  */
0581 int rtems_fdt_node_offset_by_phandle (rtems_fdt_handle* handle,
0582                                       uint32_t          phandle);
0583 
0584 /**
0585  * Check a node's compatible property returning 0 if the given node contains a
0586  * 'compatible' property with the given string as one of its elements, it
0587  * returns non-zero otherwise, or on error.
0588  *
0589  * @param handle The FDT handle to the current blob.
0590  * @param nodeoffset The offset of a tree node.
0591  * @param compatible The string to match against.
0592  * @retval 0, if the node has a 'compatible' property listing the given string.
0593  * @retval 1, if the node has a 'compatible' property, but it does not list the
0594  *            given string
0595  */
0596 int rtems_fdt_node_check_compatible (rtems_fdt_handle* handle,
0597                                      int               nodeoffset,
0598                                      const char* const compatible);
0599 
0600 /**
0601  * Find nodes with a given 'compatible' value returning the offset of the first
0602  * node after startoffset, which has a 'compatible' property which lists the
0603  * given compatible string; or if startoffset is -1, the very first such node
0604  * in the tree.
0605  *
0606  * To iterate through all nodes matching the criterion, the following idiom can
0607  * be used:
0608  *
0609  *  offset = rtems_fdt_node_offset_by_compatible(blob, -1, compatible);
0610  *  while (offset != -RTEMS_FDT_ERR_NOTFOUND) {
0611  *    // other code here
0612  *    offset = rtems_fdt_node_offset_by_compatible(blob, offset, compatible);
0613  *  }
0614  *
0615  * @note The -1 in the first call to the function, if 0 is used here instead,
0616  * the function will never locate the root node, even if it matches the
0617  * criterion.
0618  *
0619  * @param handle The FDT handle to the current blob.
0620  * @param startoffset Only find nodes after this offset.
0621  * @param compatible The 'compatible' string to match against.
0622  * @return int If less than 0 an error else the node offset.
0623  */
0624 int rtems_fdt_node_offset_by_compatible(rtems_fdt_handle* handle,
0625                                         int               startoffset,
0626                                         const char*       compatible);
0627 
0628 /**
0629  * Traverse to the next node.
0630  *
0631  * @param handle The FDT handle to the current blob.
0632  * @param offset The offset in the blob to start looking for the next node.
0633  * @param depth Pointer to return the depth the node is.
0634  * @return int If less than 0 an error else the node offset.
0635  */
0636 int rtems_fdt_next_node (rtems_fdt_handle* handle, int offset, int* depth);
0637 
0638 /**
0639  * Return an error string given an error value.
0640  *
0641  * @param errval The error value.
0642  * @return const char* The error string.
0643  */
0644 const char* rtems_fdt_strerror (int errval);
0645 
0646 /**
0647  * Return a parent property given a node offset. Travel up until found
0648  * or the root node is reached
0649  */
0650 bool rtems_fdt_get_parent_prop_value(rtems_fdt_handle* handle,
0651                                      int               nodeoffset,
0652                                      const char*       name,
0653                                      uint32_t*         value);
0654 /**
0655  * Return a property given a path.
0656  */
0657 int rtems_fdt_prop_value(const char* const path,
0658                          const char* const propname,
0659                          void*             value,
0660                          size_t*           size);
0661 
0662 /**
0663  * Create a map given a path the property name and the names of the subnodes of
0664  * the path.
0665  */
0666 int rtems_fdt_prop_map (const char* const path,
0667                         const char* const propname,
0668                         const char* const names[],
0669                         uintptr_t*        values,
0670                         size_t            count);
0671 
0672 /*
0673  * Get a value given a path and a property.
0674  */
0675 int rtems_fdt_get_value (const char* const path,
0676                          const char* const property,
0677                          size_t            size,
0678                          uintptr_t*        value);
0679 
0680 /**
0681  * Get the number of entries in an FDT handle.
0682  */
0683 int rtems_fdt_num_entries(rtems_fdt_handle* handle);
0684 
0685 /**
0686  * Get the numbered entry name. Note that the id isn't the same as
0687  * the offset - it's numbered 0, 1, 2 ... num_entries-1
0688  */
0689 const char *rtems_fdt_entry_name(rtems_fdt_handle* handle, int id);
0690 
0691 /**
0692  * Get the numbered entry offset. Note that the id isn't the same as
0693  * the offset - it's numbered 0, 1, 2 ... num_entries-1
0694  */
0695 int rtems_fdt_entry_offset(rtems_fdt_handle* handle, int id);
0696 
0697 /*
0698  * Helper function to convert the void* property result of unknown
0699  * length to an unsigned int pointer value.
0700  */
0701 uintptr_t rtems_fdt_get_offset_len_uintptr(const void* prop, int offset, int len);
0702 
0703 /*
0704  * Helper function to convert the void* property result to a 32bit unsigned int.
0705  */
0706 uint32_t rtems_fdt_get_uint32(const void* prop);
0707 uint32_t rtems_fdt_get_offset_uint32(const void* prop, int offset);
0708 
0709 /*
0710  * Helper function to convert the void* property result to a 64bit unsigned int.
0711  */
0712 uint64_t rtems_fdt_get_uint64(const void* prop);
0713 uint64_t rtems_fdt_get_offset_uint64(const void* prop, int offset);
0714 
0715 /*
0716  * Helper function to convert the void* property result to a uintptr_t
0717  */
0718 uintptr_t rtems_fdt_get_uintptr(const void* prop);
0719 uintptr_t rtems_fdt_get_offset_uintptr(const void* prop, int offset);
0720 
0721 /*
0722  * Find the address cells property in parent nodes.
0723  */
0724 int rtems_fdt_getprop_address_cells(rtems_fdt_handle* handle, int nodeoffset);
0725 
0726 /*
0727  * Find the size cells property in parent nodes.
0728  */
0729 int rtems_fdt_getprop_size_cells(rtems_fdt_handle* handle, int nodeoffset);
0730 
0731 /*
0732  * Get an address space property.
0733  */
0734 int rtems_fdt_getprop_address_map(rtems_fdt_handle*      handle,
0735                                   const char*            path,
0736                                   const char*            name,
0737                                   rtems_fdt_address_map* addr_map);
0738 
0739 #ifdef __cplusplus
0740 }
0741 #endif /* __cplusplus */
0742 
0743 #endif