summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/rtems-fdt.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/include/rtems/rtems-fdt.h')
-rw-r--r--cpukit/include/rtems/rtems-fdt.h152
1 files changed, 137 insertions, 15 deletions
diff --git a/cpukit/include/rtems/rtems-fdt.h b/cpukit/include/rtems/rtems-fdt.h
index ebc222e4c9..e3ebfe3ba4 100644
--- a/cpukit/include/rtems/rtems-fdt.h
+++ b/cpukit/include/rtems/rtems-fdt.h
@@ -1,9 +1,28 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
/*
* COPYRIGHT (c) 2013-2017 Chris Johns <chrisj@rtems.org>
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
*
* Interface based on the libdft:
* libfdt - Flat Device Tree manipulation
@@ -45,6 +64,21 @@ typedef struct
rtems_fdt_blob* blob; /**< The blob the handle references. */
} rtems_fdt_handle;
+/**
+ * FDT Address property. It is an address an optionally a size.
+ *
+ * Only 32bit addresses and sizes on 32bit machine. Ignore the upper
+ * 32bits.
+ */
+typedef struct
+{
+ int node;
+ uint64_t address;
+ uint64_t size;
+ int address_cells;
+ int size_cells;
+} rtems_fdt_address_map;
+
/*
* The following are mappings to the standard FDT calls.
*/
@@ -146,9 +180,13 @@ typedef struct
* The blob cannot be unloaded as it is referenced.
*/
#define RTEMS_FDT_ERR_REFERENCED 104
+/**
+ * The property length is invalid
+ */
+#define RTEMS_FDT_ERR_BADLENGTH 105
#define RTEMS_FDT_ERR_RTEMS_MIN 100
-#define RTEMS_FDT_ERR_MAX 104
+#define RTEMS_FDT_ERR_MAX 105
/**
* Initialise a handle to a default state.
@@ -218,7 +256,7 @@ int rtems_fdt_register (const void* blob, rtems_fdt_handle* handle);
/**
* Unload a device tree blob or DTB file and release any memory allocated when
- * loading. The blob is removed from the list of registered.
+ * loading. The blob is removed from the list if registered.
*
* @param blob_desc A valid blob descriptor.
* @return int If less than 0 it is an error code else 0 is return on success.
@@ -258,7 +296,7 @@ int rtems_fdt_get_mem_rsv (rtems_fdt_handle* handle,
* larger string, such as a full path.
*
* @param blob_desc A valid blob descriptor.
- * @param arentoffset Structure block offset of a node
+ * @param parentoffset Structure block offset of a node
* @param name Name of the subnode to locate.
* @param namelen Number of characters of name to consider.
* @return int If less than 0 it is an error code else the node offset is
@@ -307,7 +345,9 @@ int rtems_fdt_path_offset (rtems_fdt_handle* handle, const char* path);
*
* @param handle The FDT handle to the current blob.
* @param nodeoffset Structure block offset of the starting node.
- * @param length Pointer to an integer variable (will be overwritten) or NULL.
+ * @param length Pointer to an integer variable or NULL. If non-NULL, this will
+ * be overwritten with either the length in bytes or the error
+ * code.
* @return const char* The node's name on success or NULL on error. The length
* if non-NULL will hold the error code.
*/
@@ -316,6 +356,41 @@ const char* rtems_fdt_get_name (rtems_fdt_handle* handle,
int* length);
/**
+ * Retrieve the offset for the first property for a node.
+ *
+ * @param handle The FDT handle to the current blob.
+ * @param nodeoffset Structure block offset of the starting node.
+ * @return int The offset of a node's first property.
+ */
+int rtems_fdt_first_prop_offset(rtems_fdt_handle* handle, int nodeoffset);
+
+/**
+ * Retrieve the next property of a node relative to the property
+ *
+ * @param handle The FDT handle to the current blob.
+ * @param propoffset Property offset to search from
+ * @return int Property offset or end if less than 0.
+ */
+int rtems_fdt_next_prop_offset(rtems_fdt_handle* handle, int propoffset);
+
+/**
+ * Retrieve the property value, name and length of name given a
+ * property offset.
+ *
+ * @param handle The FDT handle to the current blob.
+ * @param propoffset Property offset
+ * @param name If not NULL set the pointer to the name string.
+ * @param length Pointer to an integer variable or NULL. If non-NULL, this will
+ * be overwritten with either the length in bytes or the error
+ * code.
+ * @return const void* The node's value data.
+ */
+const void* rtems_fdt_getprop_by_offset(rtems_fdt_handle* handle,
+ int propoffset,
+ const char** name,
+ int* length);
+
+/**
* Get property value based on substring. Identical to rtems_fdt_getprop(), but
* only examine the first namelen characters of name for matching the property
* name.
@@ -324,8 +399,9 @@ const char* rtems_fdt_get_name (rtems_fdt_handle* handle,
* @param nodeoffset Offset of the node whose property to find
* @param name The name of the property to find
* @param namelen The number of characters of name to consider
- * @param length A pointer to an integer variable (will be overwritten) or
- * NULL.
+ * @param length Pointer to an integer variable or NULL. If non-NULL, this will
+ * be overwritten with either the length in bytes or the error
+ * code.
* @return const void* The node's property on success or NULL on error. The
* length if non-NULL will hold the error code.
*/
@@ -345,8 +421,9 @@ const void *rtems_fdt_getprop_namelen (rtems_fdt_handle* handle,
* @param handle The FDT handle to the current blob.
* @param nodeoffset The offset of the node whose property to find.
* @param name The name of the property to find.
- * @param length A pointer to an integer variable (will be overwritten) or
- * NULL.
+ * @param length Pointer to an integer variable or NULL. If non-NULL, this will
+ * be overwritten with either the length in bytes or the error
+ * code.
* @return const void* The node's property on success or NULL on error. The
* length if non-NULL will hold the error code.
*/
@@ -356,7 +433,7 @@ const void *rtems_fdt_getprop (rtems_fdt_handle* handle,
int* length);
/**
- * Retrieve the phandle of a given of the device tree node at structure block
+ * Retrieve the phandle of the device tree node at structure block
* offset nodeoffset.
*
* @param handle The FDT handle to the current blob.
@@ -567,6 +644,14 @@ int rtems_fdt_next_node (rtems_fdt_handle* handle, int offset, int* depth);
const char* rtems_fdt_strerror (int errval);
/**
+ * Return a parent property given a node offset. Travel up until found
+ * or the root node is reached
+ */
+bool rtems_fdt_get_parent_prop_value(rtems_fdt_handle* handle,
+ int nodeoffset,
+ const char* name,
+ uint32_t* value);
+/**
* Return a property given a path.
*/
int rtems_fdt_prop_value(const char* const path,
@@ -581,7 +666,7 @@ int rtems_fdt_prop_value(const char* const path,
int rtems_fdt_prop_map (const char* const path,
const char* const propname,
const char* const names[],
- uint32_t* values,
+ uintptr_t* values,
size_t count);
/*
@@ -590,7 +675,7 @@ int rtems_fdt_prop_map (const char* const path,
int rtems_fdt_get_value (const char* const path,
const char* const property,
size_t size,
- uint32_t* value);
+ uintptr_t* value);
/**
* Get the number of entries in an FDT handle.
@@ -610,9 +695,46 @@ const char *rtems_fdt_entry_name(rtems_fdt_handle* handle, int id);
int rtems_fdt_entry_offset(rtems_fdt_handle* handle, int id);
/*
+ * Helper function to convert the void* property result of unknown
+ * length to an unsigned int pointer value.
+ */
+uintptr_t rtems_fdt_get_offset_len_uintptr(const void* prop, int offset, int len);
+
+/*
* Helper function to convert the void* property result to a 32bit unsigned int.
*/
-uint32_t rtems_fdt_get_uint32 (const void* prop);
+uint32_t rtems_fdt_get_uint32(const void* prop);
+uint32_t rtems_fdt_get_offset_uint32(const void* prop, int offset);
+
+/*
+ * Helper function to convert the void* property result to a 64bit unsigned int.
+ */
+uint64_t rtems_fdt_get_uint64(const void* prop);
+uint64_t rtems_fdt_get_offset_uint64(const void* prop, int offset);
+
+/*
+ * Helper function to convert the void* property result to a uintptr_t
+ */
+uintptr_t rtems_fdt_get_uintptr(const void* prop);
+uintptr_t rtems_fdt_get_offset_uintptr(const void* prop, int offset);
+
+/*
+ * Find the address cells property in parent nodes.
+ */
+int rtems_fdt_getprop_address_cells(rtems_fdt_handle* handle, int nodeoffset);
+
+/*
+ * Find the size cells property in parent nodes.
+ */
+int rtems_fdt_getprop_size_cells(rtems_fdt_handle* handle, int nodeoffset);
+
+/*
+ * Get an address space property.
+ */
+int rtems_fdt_getprop_address_map(rtems_fdt_handle* handle,
+ const char* path,
+ const char* name,
+ rtems_fdt_address_map* addr_map);
#ifdef __cplusplus
}