<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hello Christian,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 17, 2020 at 12:10 AM Christian Mauderer <<a href="mailto:contact@c-mauderer.de">contact@c-mauderer.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
sorry for the long delay. I tested it on xilinx-zynq-a9-qemu (which<br>
doesn't have a FDT) and the test seems to run fine. So I'm OK with the<br>
patches. If no one objects in the next two days, I'll commit them.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Thanks for testing the patches.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Thanks,</div><div class="gmail_default" style="font-size:small">Niteesh.</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Best regards<br>
<br>
Christian<br>
<br>
On 03/11/2020 19:18, G S Niteesh Babu wrote:<br>
> RTEMS OFW is a FDT only implementation of the OpenFirmWare<br>
> interface. This API is created to be compatible with FreeBSD<br>
> OpenFirmWare interface. The main intention is to make<br>
> porting of FreeBSD drivers to RTEMS easier.<br>
> <br>
> Most functions implemented have an direct one-one mapping<br>
> with the original OFW API and some extra auxiliary functions<br>
> were implemented to make working with device trees easier in<br>
> RTEMS.<br>
> <br>
> Update #3784<br>
> ---<br>
> bsps/include/ofw/ofw.h | 548 +++++++++++++++++++++++++++<br>
> bsps/include/ofw/ofw_compat.h | 74 ++++<br>
> bsps/shared/ofw/ofw.c | 682 ++++++++++++++++++++++++++++++++++<br>
> spec/build/bsps/obj.yml | 5 +<br>
> 4 files changed, 1309 insertions(+)<br>
> create mode 100644 bsps/include/ofw/ofw.h<br>
> create mode 100644 bsps/include/ofw/ofw_compat.h<br>
> create mode 100644 bsps/shared/ofw/ofw.c<br>
> <br>
> diff --git a/bsps/include/ofw/ofw.h b/bsps/include/ofw/ofw.h<br>
> new file mode 100644<br>
> index 0000000000..4c402671a4<br>
> --- /dev/null<br>
> +++ b/bsps/include/ofw/ofw.h<br>
> @@ -0,0 +1,548 @@<br>
> +/* SPDX-License-Identifier: BSD-2-Clause */<br>
> +<br>
> +/**<br>
> + * @file<br>
> + *<br>
> + * @ingroup ofw<br>
> + *<br>
> + * RTEMS FDT implementation of OpenFirmWare Interface.<br>
> + *<br>
> + * RTEMS OFW is a FDT only implementation of the OpenFirmWare interface.<br>
> + * This API is created to be compatible with FreeBSD OpenFirmWare interface.<br>
> + * The main intention is to make porting of FreeBSD drivers to RTEMS easier.<br>
> + */<br>
> +<br>
> +/*<br>
> + * Copyright (C) 2020 Niteesh Babu G S <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>><br>
> + *<br>
> + * Redistribution and use in source and binary forms, with or without<br>
> + * modification, are permitted provided that the following conditions<br>
> + * are met:<br>
> + * 1. Redistributions of source code must retain the above copyright<br>
> + * notice, this list of conditions and the following disclaimer.<br>
> + * 2. Redistributions in binary form must reproduce the above copyright<br>
> + * notice, this list of conditions and the following disclaimer in the<br>
> + * documentation and/or other materials provided with the distribution.<br>
> + *<br>
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
> + * POSSIBILITY OF SUCH DAMAGE.<br>
> + */<br>
> +<br>
> +#ifndef _OFW_H<br>
> +#define _OFW_H<br>
> +<br>
> +#ifdef __cplusplus<br>
> +extern "C" {<br>
> +#endif<br>
> +<br>
> +#include <rtems.h><br>
> +#include <stdint.h><br>
> +#include <sys/types.h><br>
> +<br>
> +/**<br>
> + * Represents a node in the device tree. The offset from fdtp to node is used<br>
> + * instead of fdt offset to make sure this is compatible with OF interface in<br>
> + * FreeBSD.<br>
> + */<br>
> +typedef uint32_t phandle_t;<br>
> +/**<br>
> + * Represents the effective phandle of the node.<br>
> + */<br>
> +typedef uint32_t ihandle_t;<br>
> +/**<br>
> + * Represents the data type of the buffer.<br>
> + */<br>
> +typedef uint32_t pcell_t;<br>
> +<br>
> +/**<br>
> + * @struct rtems_ofw_memory_area<br>
> + *<br>
> + * This is used to represent elements(FDT properties) that define<br>
> + * region of memory address.<br>
> + */<br>
> +typedef struct {<br>
> + /** The start address of the memory region. */<br>
> + uint32_t start;<br>
> + /** The size of the memory region. */<br>
> + uint32_t size;<br>
> +} rtems_ofw_memory_area;<br>
> +<br>
> +/**<br>
> + * @struct rtems_ofw_ranges<br>
> + *<br>
> + * This is used to represent the ranges property in the device tree.<br>
> + */<br>
> +typedef struct {<br>
> + /** The physical address within the child bus address space */<br>
> + uint32_t child_bus;<br>
> + /** The physical address within the parent bus address space */<br>
> + uint32_t parent_bus;<br>
> + /** The size of the range in the child’s address space */<br>
> + uint32_t size;<br>
> +} rtems_ofw_ranges;<br>
> +<br>
> +/**<br>
> + * @brief Gets the node that is next to @a node.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + *<br>
> + * @retval Peer node offset Successful operation.<br>
> + * @retval 0 No peer node or invalid node handle<br>
> + */<br>
> +phandle_t rtems_ofw_peer(<br>
> + phandle_t node<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Gets the node that is the child of @a node.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + *<br>
> + * @retval child node offset Successful operation.<br>
> + * @retval 0 No child node or invalid node handle<br>
> + */<br>
> +phandle_t rtems_ofw_child(<br>
> + phandle_t node<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Gets the node that is the parent of @a node.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + *<br>
> + * @retval child node offset Successful operation.<br>
> + * @retval 0 No child node or invalid node handle<br>
> + */<br>
> +phandle_t rtems_ofw_parent(<br>
> + phandle_t node<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Gets the length of the property mentioned in @a propname.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] prop Property name<br>
> + *<br>
> + * @retval -1 Invalid node or property<br>
> + * @retval Length of property on successful operation<br>
> + */<br>
> +ssize_t rtems_ofw_get_prop_len(<br>
> + phandle_t node,<br>
> + const char *propname<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Gets the value of property mentioned in @a propname.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] prop Property name<br>
> + * @param[out] buf The property value gets stored in this buffer (Pre-allocated)<br>
> + * @param[in] len Length of the buffer<br>
> +<br>
> + * @retval -1 Invalid node or property<br>
> + * @retval Length of property on successful operation<br>
> + */<br>
> +ssize_t rtems_ofw_get_prop(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + void *buf,<br>
> + size_t len<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Gets the value of property mentioned in @a prop.<br>
> + *<br>
> + * Gets the value of property of @a node and converts the value into the host's<br>
> + * endianness.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] prop Property name<br>
> + * @param[out] buf The property value gets stored in this buffer(Pre-allocated)<br>
> + * after converted to the host's endianness<br>
> + * @param[in] len Length of the buffer<br>
> + *<br>
> + * @retval -1 Invalid node or property<br>
> + * @retval Length of property on successful operation<br>
> + */<br>
> +ssize_t rtems_ofw_get_enc_prop(<br>
> + phandle_t node,<br>
> + const char *prop,<br>
> + pcell_t *buf,<br>
> + size_t len<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Checks if the property @a propname is present in @a node.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] propname Property name<br>
> + *<br>
> + * @retval 0 Property not present.<br>
> + * @retval 1 Property is present.<br>
> + */<br>
> +int rtems_ofw_has_prop(<br>
> + phandle_t node,<br>
> + const char *propname<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Searches for property @a propname in @a node.<br>
> + *<br>
> + * Searches the node and its parent recursively for the property and fills the<br>
> + * buffer with the first found value.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] propname Property name<br>
> + * @param[out] buf The property value gets stored in this buffer (Pre-allocated)<br>
> + * @param[in] len Length of the buffer<br>
> + *<br>
> + * @retval Length of the property if property is found.<br>
> + * @retval -1 Property is not found.<br>
> + */<br>
> +ssize_t rtems_ofw_search_prop(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + void *buf,<br>
> + size_t len<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Searches for property @a propname in @a node.<br>
> + *<br>
> + * Searches the node and its parent recursively for the property and fills the<br>
> + * buffer with the first value found after converting it to the endianness of<br>
> + * the host.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] propname Property name<br>
> + * @param[out] buf The property value gets stored in this buffer(Pre-allocated)<br>
> + * after converted to the host's endianness<br>
> + * @param[in] len Length of the buffer<br>
> + *<br>
> + * @retval Length of the property if property is found.<br>
> + * @retval -1 Property is not found.<br>
> + */<br>
> +ssize_t rtems_ofw_search_enc_prop(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + pcell_t *buf,<br>
> + size_t len<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Gets the value of property mentioned in @a propname.<br>
> + *<br>
> + * Same as rtems_ofw_getprop, but the @a buf is allocated in this routine and<br>
> + * the user is responsible for freeing it.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] propname Property name<br>
> + * @param[out] buf The buffer is allocated in this routine and user is<br>
> + * responsible for freeing.<br>
> + *<br>
> + * @retval -1 Property is not found.<br>
> + * @retval Length of the property if property is found.<br>
> + */<br>
> +ssize_t rtems_ofw_get_prop_alloc(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + void **buf<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Gets multiple values of the property @a propname.<br>
> + *<br>
> + * Same as rtems_ofw_getprop_alloc but it can read properties with multiple<br>
> + * values.<br>
> + * For eg: reg = <0x1000 0x10 0x2000 0x20><br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] propname Property name<br>
> + * @param[in] elsz Size of the single value<br>
> + * @param[out] buf The buffer is allocated in this routine and user is<br>
> + * responsible for freeing.<br>
> + *<br>
> + * @retval -1 Property is not found.<br>
> + * @retval Number of values read.<br>
> + */<br>
> +ssize_t rtems_ofw_get_prop_alloc_multi(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + int elsz,<br>
> + void **buf<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Gets the value of property mentioned in @a propname.<br>
> + *<br>
> + * Same as rtems_ofw_getprop_alloc but the value stored in the buffer is<br>
> + * converted into the host's endianness.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] propname Property name<br>
> + * @param[out] buf The buffer is allocated in this routine and user is<br>
> + * responsible for freeing.<br>
> + *<br>
> + * @retval -1 Property is not found.<br>
> + * @retval Length of the property if property is found.<br>
> + */<br>
> +ssize_t rtems_ofw_get_enc_prop_alloc(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + void **buf<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Gets multiple values of the property @a propname.<br>
> + *<br>
> + * Same as rtems_ofw_getprop_alloc_multi but the values stored in the buffer<br>
> + * are converted to the host's endianness.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] propname Property name<br>
> + * @param[in] elsz Size of the single value<br>
> + * @param[out] buf The buffer is allocated in this routine and user is<br>
> + * responsible for freeing.<br>
> + *<br>
> + * @retval -1 Property is not found.<br>
> + * @retval Number of values read.<br>
> + */<br>
> +ssize_t rtems_ofw_get_enc_prop_alloc_multi(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + int elsz,<br>
> + void **buf<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Free's the buffers allocated by the rtems_ofw_*_alloc functions.<br>
> + *<br>
> + * @param[in] buf Buffer to be freed<br>
> + */<br>
> +void rtems_ofw_free(<br>
> + void *buf<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Finds the next property of @a node.<br>
> + *<br>
> + * Finds the next property of the node and when @a propname is NULL it returns<br>
> + * the value in the first property.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] previous Previous property name<br>
> + * @param[out] buf The value of the next property gets stored in this buffer<br>
> + * (Pre-allocated)<br>
> + * @param[in] len Length of the buffer<br>
> + *<br>
> + * @retval -1 node or previous property does not exist<br>
> + * @retval 0 no more properties<br>
> + * @retval 1 success<br>
> + */<br>
> +int rtems_ofw_next_prop(<br>
> + phandle_t node,<br>
> + const char *previous,<br>
> + char *buf,<br>
> + size_t len<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Sets the property @name of @a node to @a buf.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[in] name Property name<br>
> + * @param[in] buf Buffer contains the value to be set.<br>
> + * @param[in] len Length of the buffer<br>
> + *<br>
> + * @retval -1 node does not exist<br>
> + * @retval 0 on success<br>
> + * @retval libFDT error codes on unsuccessful setting operation<br>
> + */<br>
> +int rtems_ofw_set_prop(<br>
> + phandle_t node,<br>
> + const char *name,<br>
> + const void *buf,<br>
> + size_t len<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Converts a device specifier to a fully qualified path name.<br>
> + *<br>
> + * @param[in] dev device specifier<br>
> + * @param[out] buf The path is filled into the buffer(Pre-allocated)<br>
> + * @param[in] length of the buffer<br>
> + *<br>
> + * @retval -1 always. Unimplemented.<br>
> + */<br>
> +ssize_t rtems_ofw_canon(<br>
> + const char *dev,<br>
> + char *buf,<br>
> + size_t len<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Finds the node at the given path<br>
> + *<br>
> + * @param[in] path to the node from root<br>
> + *<br>
> + * @retval -1 node does not exist<br>
> + * @retval node handle on success<br>
> + */<br>
> +phandle_t rtems_ofw_find_device(<br>
> + const char *path<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief This routine converts effective phandle @a xref to node offset.<br>
> + *<br>
> + * @param[in] xref Node phandle<br>
> + *<br>
> + * @retval Node offset on success<br>
> + * @retval Node phandle on failure<br>
> + */<br>
> +phandle_t rtems_ofw_node_from_xref(<br>
> + phandle_t xref<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief This routine converts node offset to effective phandle of @a node.<br>
> + *<br>
> + * @retval Node phandle on success<br>
> + * @retval Node offset on failure<br>
> + */<br>
> +phandle_t rtems_ofw_xref_from_node(<br>
> + phandle_t node<br>
> +);<br>
> +<br>
> +/*<br>
> + * instance handles(ihandle_t) as same as phandles in the FDT implementation<br>
> + * of OF interface.<br>
> + */<br>
> +<br>
> +/**<br>
> + * @brief Converts @a instance handle to phandle.<br>
> + *<br>
> + * instance are same as node offsets in FDT.<br>
> + *<br>
> + * @param[in] instance Node offset<br>
> + *<br>
> + * @retval phandle of node on success.<br>
> + * @retval instance of node on failure.<br>
> + */<br>
> +phandle_t rtems_ofw_instance_to_package(<br>
> + ihandle_t instance<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Find the node's path from phandle.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[out] buf Path is filled into this buffer(Pre-allocated).<br>
> + * @param[in] len Length of the buffer.<br>
> + *<br>
> + * @retval -1 always. Unimplemented.<br>
> + */<br>
> +ssize_t rtems_ofw_package_to_path(<br>
> + phandle_t node,<br>
> + char *buf,<br>
> + size_t len<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Find the node's path from ihandle.<br>
> + *<br>
> + * @param[in] instance Node offset<br>
> + * @param[out] buf Path is filled into this buffer(Pre-allocated).<br>
> + * @param[in] len Length of the buffer.<br>
> + *<br>
> + * @retval -1 always. Unimplemented.<br>
> + */<br>
> +ssize_t rtems_ofw_instance_to_path(<br>
> + ihandle_t instance,<br>
> + char *buf,<br>
> + size_t len<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Queries the node's reg value.<br>
> + *<br>
> + * This routine fills the buffer @a buf with the values in reg property of node<br>
> + * @a node. It reads all the values of the property and fills the buffer to max<br>
> + * size.<br>
> + * This routine is local to RTEMS OFW and does not have an corresponding<br>
> + * FreeBSD OFW pair.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[out] buf Register values are stored in this buffer(Pre-allocated).<br>
> + * @param[in] size Length of the buffer.<br>
> + *<br>
> + * @retval -1 If reg property is missing.<br>
> + * @retval Length of the reg property in bytes.<br>
> + */<br>
> +int rtems_ofw_get_reg(<br>
> + phandle_t node,<br>
> + rtems_ofw_memory_area *buf,<br>
> + size_t size<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Queries the node's interrupt value.<br>
> + *<br>
> + * This routine fills the buffer @a buf with the interrupt number. In case of<br>
> + * multiple numbers it fills the buffer to its full extent.<br>
> + * This routine is local to RTEMS OFW and does not have an corresponding<br>
> + * FreeBSD OFW pair.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + * @param[out] buf Interrupt values are stored in this buffer(Pre-allocated).<br>
> + * @param[in] size Length of the buffer.<br>
> + *<br>
> + * @retval -1 If interrupts property is missing.<br>
> + * @retval The number of interrupt numbers read.<br>
> + */<br>
> +int rtems_ofw_get_interrupts(<br>
> + phandle_t node,<br>
> + rtems_vector_number *buf,<br>
> + size_t size<br>
> +);<br>
> +<br>
> +/**<br>
> + * @brief Queries the node's status.<br>
> + *<br>
> + * This routine is local to RTEMS OFW and does not have an corresponding<br>
> + * FreeBSD OFW pair.<br>
> + *<br>
> + * @param[in] node Node offset<br>
> + *<br>
> + * @retval true Status is OK or empty.<br>
> + * @retval false Status is not OK or missing.<br>
> + */<br>
> +bool rtems_ofw_node_status( phandle_t node );<br>
> +<br>
> +/**<br>
> + * @brief Gets node phandle from compatible property.<br>
> + *<br>
> + * This routine is local to RTEMS OFW and does not have an corresponding<br>
> + * FreeBSD OFW pair.<br>
> + *<br>
> + * @param[in] compat Compatible string<br>
> + *<br>
> + * @retval 0 Node with @a compat as compatible string not found<br>
> + * @retval Node phandle on success.<br>
> + */<br>
> +phandle_t rtems_ofw_find_device_by_compat( const char *compat );<br>
> +<br>
> +#ifdef __cplusplus<br>
> +}<br>
> +#endif<br>
> +<br>
> +#endif /* _OFW_H */<br>
> diff --git a/bsps/include/ofw/ofw_compat.h b/bsps/include/ofw/ofw_compat.h<br>
> new file mode 100644<br>
> index 0000000000..be4a5ea3ce<br>
> --- /dev/null<br>
> +++ b/bsps/include/ofw/ofw_compat.h<br>
> @@ -0,0 +1,74 @@<br>
> +/* SPDX-License-Identifier: BSD-2-Clause */<br>
> +<br>
> +/**<br>
> + * @file<br>
> + *<br>
> + * @ingroup ofw<br>
> + *<br>
> + * This file defines necessary symbols to make the RTEMS OFW API compatible<br>
> + * with FreeBSD OFW.<br>
> + */<br>
> +<br>
> +/*<br>
> + * Copyright (C) 2020 Niteesh Babu G S <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>><br>
> + *<br>
> + * Redistribution and use in source and binary forms, with or without<br>
> + * modification, are permitted provided that the following conditions<br>
> + * are met:<br>
> + * 1. Redistributions of source code must retain the above copyright<br>
> + * notice, this list of conditions and the following disclaimer.<br>
> + * 2. Redistributions in binary form must reproduce the above copyright<br>
> + * notice, this list of conditions and the following disclaimer in the<br>
> + * documentation and/or other materials provided with the distribution.<br>
> + *<br>
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
> + * POSSIBILITY OF SUCH DAMAGE.<br>
> + */<br>
> +<br>
> +#ifndef _OFW_COMPAT_H<br>
> +#define _OFW_COMPAT_H<br>
> +<br>
> +#ifdef __cplusplus<br>
> +extern "C" {<br>
> +#endif<br>
> +<br>
> +#include <ofw/ofw.h><br>
> +<br>
> +#define OF_peer rtems_ofw_peer<br>
> +#define OF_child rtems_ofw_child<br>
> +#define OF_parent rtems_ofw_parent<br>
> +#define OF_getproplen rtems_ofw_get_prop_len<br>
> +#define OF_getprop rtems_ofw_get_prop<br>
> +#define OF_getencprop rtems_ofw_get_enc_prop<br>
> +#define OF_hasprop rtems_ofw_has_prop<br>
> +#define OF_searchprop rtems_ofw_search_prop<br>
> +#define OF_searchencprop rtems_ofw_search_enc_prop<br>
> +#define OF_getprop_alloc rtems_ofw_get_prop_alloc<br>
> +#define OF_getprop_alloc_multi rtems_ofw_get_prop_alloc_multi<br>
> +#define OF_getencprop_alloc_multi rtems_ofw_get_enc_prop_alloc_multi<br>
> +#define OF_getencprop_alloc rtems_ofw_get_enc_prop_alloc<br>
> +#define OF_prop_free rtems_ofw_free<br>
> +#define OF_nextprop rtems_ofw_next_prop<br>
> +#define OF_setprop rtems_ofw_set_prop<br>
> +#define OF_canon rtems_ofw_canon<br>
> +#define OF_finddevice rtems_ofw_find_device<br>
> +#define OF_package_to_path rtems_ofw_package_to_path<br>
> +#define OF_node_from_xref rtems_ofw_node_from_xref<br>
> +#define OF_xref_from_node rtems_ofw_xref_from_node<br>
> +#define OF_instance_to_package rtems_ofw_instance_to_package<br>
> +#define OF_instance_to_path rtems_ofw_instance_to_path<br>
> +<br>
> +#ifdef __cplusplus<br>
> +}<br>
> +#endif<br>
> +<br>
> +#endif /* _OFW_COMPAT_H */<br>
> diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c<br>
> new file mode 100644<br>
> index 0000000000..c18ee766e1<br>
> --- /dev/null<br>
> +++ b/bsps/shared/ofw/ofw.c<br>
> @@ -0,0 +1,682 @@<br>
> +/* SPDX-License-Identifier: BSD-2-Clause */<br>
> +<br>
> +/**<br>
> + * @file<br>
> + *<br>
> + * @ingroup ofw<br>
> + */<br>
> +<br>
> +/*<br>
> + * Copyright (C) 2020 Niteesh Babu G S <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>><br>
> + *<br>
> + * Redistribution and use in source and binary forms, with or without<br>
> + * modification, are permitted provided that the following conditions<br>
> + * are met:<br>
> + * 1. Redistributions of source code must retain the above copyright<br>
> + * notice, this list of conditions and the following disclaimer.<br>
> + * 2. Redistributions in binary form must reproduce the above copyright<br>
> + * notice, this list of conditions and the following disclaimer in the<br>
> + * documentation and/or other materials provided with the distribution.<br>
> + *<br>
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
> + * POSSIBILITY OF SUCH DAMAGE.<br>
> + */<br>
> +<br>
> +#ifdef HAVE_CONFIG_H<br>
> +#include "config.h"<br>
> +#endif<br>
> +<br>
> +#include <bsp/fdt.h><br>
> +#include <sys/param.h><br>
> +#include <ofw/ofw.h><br>
> +#include <libfdt.h><br>
> +#include <assert.h><br>
> +#include <rtems/sysinit.h><br>
> +<br>
> +const void *fdtp = NULL;<br>
> +<br>
> +static phandle_t rtems_fdt_offset_to_phandle( int offset )<br>
> +{<br>
> + if (offset < 0) {<br>
> + return 0;<br>
> + }<br>
> +<br>
> + return (phandle_t)offset + fdt_off_dt_struct(fdtp);<br>
> +}<br>
> +<br>
> +static int rtems_fdt_phandle_to_offset( phandle_t handle )<br>
> +{<br>
> + int off;<br>
> + int fdt_off;<br>
> +<br>
> + off = (int) handle;<br>
> + fdt_off = fdt_off_dt_struct(fdtp);<br>
> +<br>
> + if (off < fdt_off) {<br>
> + return -1;<br>
> +<br>
> + }<br>
> +<br>
> + return off - fdt_off;<br>
> +}<br>
> +<br>
> +static void rtems_ofw_init( void ) {<br>
> + int rv;<br>
> + const void *fdt;<br>
> +<br>
> + fdt = bsp_fdt_get();<br>
> +<br>
> + rv = fdt_check_header(fdt);<br>
> +<br>
> + /*<br>
> + * If the FDT is invalid exit through fatal.<br>
> + */<br>
> + if (rv != 0) {<br>
> + rtems_fatal_error_occurred(RTEMS_NOT_CONFIGURED);<br>
> + }<br>
> +<br>
> + fdtp = fdt;<br>
> +}<br>
> +<br>
> +RTEMS_SYSINIT_ITEM(<br>
> + rtems_ofw_init,<br>
> + RTEMS_SYSINIT_BSP_PRE_DRIVERS,<br>
> + RTEMS_SYSINIT_ORDER_FIRST<br>
> +);<br>
> +<br>
> +phandle_t rtems_ofw_peer( phandle_t node )<br>
> +{<br>
> + int offset;<br>
> +<br>
> + if (node == 0) {<br>
> + int root = fdt_path_offset(fdtp, "/");<br>
> + return rtems_fdt_offset_to_phandle(root);<br>
> + }<br>
> +<br>
> + offset = rtems_fdt_phandle_to_offset(node);<br>
> + if (offset < 0) {<br>
> + return 0;<br>
> + }<br>
> +<br>
> + offset = fdt_next_subnode(fdtp, offset);<br>
> + return rtems_fdt_offset_to_phandle(offset);<br>
> +}<br>
> +<br>
> +phandle_t rtems_ofw_child( phandle_t node )<br>
> +{<br>
> + int offset;<br>
> +<br>
> + offset = rtems_fdt_phandle_to_offset(node);<br>
> +<br>
> + if (offset < 0) {<br>
> + return 0;<br>
> + }<br>
> +<br>
> + offset = fdt_first_subnode(fdtp, offset);<br>
> + return rtems_fdt_offset_to_phandle(offset);<br>
> +}<br>
> +<br>
> +phandle_t rtems_ofw_parent( phandle_t node )<br>
> +{<br>
> + int offset;<br>
> +<br>
> + offset = rtems_fdt_phandle_to_offset(node);<br>
> +<br>
> + if (offset < 0) {<br>
> + return 0;<br>
> + }<br>
> +<br>
> + offset = fdt_parent_offset(fdtp, offset);<br>
> + return rtems_fdt_offset_to_phandle(offset);<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_get_prop_len(<br>
> + phandle_t node,<br>
> + const char *propname<br>
> +)<br>
> +{<br>
> + int offset;<br>
> + int len;<br>
> + const void *prop;<br>
> +<br>
> + offset = rtems_fdt_phandle_to_offset(node);<br>
> +<br>
> + if (offset < 0) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + prop = fdt_getprop(fdtp, offset, propname, &len);<br>
> +<br>
> + if (prop == NULL && strcmp(propname, "name") == 0) {<br>
> + fdt_get_name(fdtp, offset, &len);<br>
> + return len + 1;<br>
> + }<br>
> +<br>
> + if (prop == NULL && strcmp(propname, "/chosen") == 0) {<br>
> + if (strcmp(propname, "fdtbootcpu") == 0)<br>
> + return sizeof(pcell_t);<br>
> + if (strcmp(propname, "fdtmemreserv") == 0)<br>
> + return 2 * sizeof(uint64_t) * fdt_num_mem_rsv(fdtp);<br>
> + }<br>
> +<br>
> + if (prop == NULL) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + return len;<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_get_prop(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + void *buf,<br>
> + size_t bufsize<br>
> +)<br>
> +{<br>
> + const void *prop;<br>
> + int offset;<br>
> + int len;<br>
> + uint32_t cpuid;<br>
> +<br>
> + offset = rtems_fdt_phandle_to_offset(node);<br>
> +<br>
> + if (offset < 0) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + prop = fdt_getprop(fdtp, offset, propname, &len);<br>
> +<br>
> + if (prop == NULL && strcmp(propname, "name") == 0) {<br>
> + prop = fdt_get_name(fdtp, offset, &len);<br>
> + strncpy(buf, prop, bufsize);<br>
> + return len + 1;<br>
> + }<br>
> +<br>
> + if (prop == NULL && strcmp(propname, "/chosen") == 0) {<br>
> + if (strcmp(propname, "fdtbootcpu") == 0) {<br>
> + cpuid = cpu_to_fdt32(fdt_boot_cpuid_phys(fdtp));<br>
> + len = sizeof(cpuid);<br>
> + prop = &cpuid;<br>
> + }<br>
> + if (strcmp(propname, "fdtmemreserv") == 0) {<br>
> + prop = (char *)fdtp + fdt_off_mem_rsvmap(fdtp);<br>
> + len = sizeof(uint64_t)*2*fdt_num_mem_rsv(fdtp);<br>
> + }<br>
> + }<br>
> +<br>
> + if (prop == NULL) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + bcopy(prop, buf, MIN(len, bufsize));<br>
> +<br>
> + return len;<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_get_enc_prop(<br>
> + phandle_t node,<br>
> + const char *prop,<br>
> + pcell_t *buf,<br>
> + size_t len<br>
> +)<br>
> +{<br>
> + ssize_t rv;<br>
> +<br>
> + assert(len % 4 == 0);<br>
> + rv = rtems_ofw_get_prop(node, prop, buf, len);<br>
> +<br>
> + if (rv < 0) {<br>
> + return rv;<br>
> + }<br>
> +<br>
> + for (int i = 0; i < (len / 4); i++) {<br>
> + buf[i] = fdt32_to_cpu(buf[i]);<br>
> + }<br>
> +<br>
> + return rv;<br>
> +}<br>
> +<br>
> +int rtems_ofw_has_prop(<br>
> + phandle_t node,<br>
> + const char *propname<br>
> +)<br>
> +{<br>
> + ssize_t rv;<br>
> +<br>
> + rv = rtems_ofw_get_prop_len(node, propname);<br>
> + return rv >= 0 ? 1 : 0;<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_search_prop(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + void *buf,<br>
> + size_t len<br>
> +)<br>
> +{<br>
> + ssize_t rv;<br>
> +<br>
> + for (; node != 0; node = rtems_ofw_parent(node)) {<br>
> + if ((rv = rtems_ofw_get_prop(node, propname, buf, len) != -1)) {<br>
> + return rv;<br>
> + }<br>
> + }<br>
> +<br>
> + return -1;<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_search_enc_prop(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + pcell_t *buf,<br>
> + size_t len<br>
> +)<br>
> +{<br>
> + ssize_t rv;<br>
> +<br>
> + for (; node != 0; node = rtems_ofw_parent(node)) {<br>
> + if ((rv = rtems_ofw_get_enc_prop(node, propname, buf, len) != -1)) {<br>
> + return rv;<br>
> + }<br>
> + }<br>
> +<br>
> + return -1;<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_get_prop_alloc(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + void **buf<br>
> +)<br>
> +{<br>
> + ssize_t len;<br>
> +<br>
> + *buf = NULL;<br>
> + if ((len = rtems_ofw_get_prop_len(node, propname)) == -1) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (len > 0) {<br>
> + *buf = malloc(len);<br>
> + if (*buf == NULL) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {<br>
> + rtems_ofw_free(buf);<br>
> + *buf = NULL;<br>
> + return -1;<br>
> + }<br>
> + }<br>
> +<br>
> + return len;<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_get_prop_alloc_multi(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + int elsz,<br>
> + void **buf<br>
> +)<br>
> +{<br>
> + ssize_t len;<br>
> +<br>
> + *buf = NULL;<br>
> + if ((len = rtems_ofw_get_prop_len(node, propname)) == -1 ||<br>
> + (len % elsz != 0)) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (len > 0) {<br>
> + *buf = malloc(len);<br>
> + if (*buf == NULL) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {<br>
> + rtems_ofw_free(buf);<br>
> + *buf = NULL;<br>
> + return -1;<br>
> + }<br>
> + }<br>
> +<br>
> + return (len / elsz);<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_get_enc_prop_alloc(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + void **buf<br>
> +)<br>
> +{<br>
> + ssize_t len;<br>
> +<br>
> + *buf = NULL;<br>
> + if ((len = rtems_ofw_get_prop_len(node, propname)) == -1) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (len > 0) {<br>
> + *buf = malloc(len);<br>
> + if (*buf == NULL) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {<br>
> + rtems_ofw_free(buf);<br>
> + *buf = NULL;<br>
> + return -1;<br>
> + }<br>
> + }<br>
> +<br>
> + return len;<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_get_enc_prop_alloc_multi(<br>
> + phandle_t node,<br>
> + const char *propname,<br>
> + int elsz,<br>
> + void **buf<br>
> +)<br>
> +{<br>
> + ssize_t len;<br>
> +<br>
> + *buf = NULL;<br>
> + if ((len = rtems_ofw_get_prop_len(node, propname)) == -1 ||<br>
> + (len % elsz != 0)) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (len > 0) {<br>
> + *buf = malloc(len);<br>
> + if (*buf == NULL) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {<br>
> + rtems_ofw_free(buf);<br>
> + *buf = NULL;<br>
> + return -1;<br>
> + }<br>
> + }<br>
> +<br>
> + return (len / elsz);<br>
> +}<br>
> +<br>
> +void rtems_ofw_free( void *buf )<br>
> +{<br>
> + free(buf);<br>
> +}<br>
> +<br>
> +int rtems_ofw_next_prop(<br>
> + phandle_t node,<br>
> + const char *previous,<br>
> + char *buf,<br>
> + size_t len<br>
> +)<br>
> +{<br>
> + const void *name;<br>
> + const void *prop;<br>
> + int offset;<br>
> +<br>
> + offset = rtems_fdt_phandle_to_offset(node);<br>
> +<br>
> + if (offset < 0) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (previous == NULL) {<br>
> + offset = fdt_first_property_offset(fdtp, offset);<br>
> + } else {<br>
> + fdt_for_each_property_offset(offset, fdtp, offset) {<br>
> + prop = fdt_getprop_by_offset(fdtp, offset, (const char **)&name, NULL);<br>
> + if (prop == NULL)<br>
> + return -1;<br>
> +<br>
> + if (strcmp(previous, name) != 0)<br>
> + continue;<br>
> +<br>
> + offset = fdt_next_property_offset(fdtp, offset);<br>
> + break;<br>
> + }<br>
> + }<br>
> +<br>
> + if (offset < 0)<br>
> + return 0;<br>
> +<br>
> + prop = fdt_getprop_by_offset(fdtp, offset, (const char **)&name, &offset);<br>
> + if (prop == NULL)<br>
> + return -1;<br>
> +<br>
> + strncpy(buf, name, len);<br>
> +<br>
> + return 1;<br>
> +}<br>
> +<br>
> +int rtems_ofw_set_prop(<br>
> + phandle_t node,<br>
> + const char *name,<br>
> + const void *buf,<br>
> + size_t len<br>
> +)<br>
> +{<br>
> + int offset;<br>
> +<br>
> + offset = rtems_fdt_phandle_to_offset(node);<br>
> +<br>
> + if (offset < 0)<br>
> + return -1;<br>
> +<br>
> + if (fdt_setprop_inplace(fdtp, offset, name, buf, len) != 0)<br>
> + return (fdt_setprop(fdtp, offset, name, buf, len));<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +phandle_t rtems_ofw_find_device( const char *path )<br>
> +{<br>
> + int offset;<br>
> +<br>
> + offset = fdt_path_offset(fdtp, path);<br>
> + if (offset < 0)<br>
> + return -1;<br>
> +<br>
> + return rtems_fdt_offset_to_phandle(offset);<br>
> +}<br>
> +<br>
> +static phandle_t rtems_ofw_get_effective_phandle(<br>
> + phandle_t node,<br>
> + phandle_t xref<br>
> +)<br>
> +{<br>
> + phandle_t child;<br>
> + phandle_t ref;<br>
> +<br>
> + for (child = rtems_ofw_child(node); child != 0; child = rtems_ofw_peer(child)) {<br>
> + ref = rtems_ofw_get_effective_phandle(child, xref);<br>
> + if (ref != -1)<br>
> + return ref;<br>
> +<br>
> + if (rtems_ofw_get_enc_prop(child, "phandle", &ref, sizeof(ref)) == -1 &&<br>
> + rtems_ofw_get_enc_prop(child, "ibm,phandle", &ref, sizeof(ref)) == -1 &&<br>
> + rtems_ofw_get_enc_prop(child, "linux,phandle", &ref, sizeof(ref)) == -1<br>
> + ) {<br>
> + continue;<br>
> + }<br>
> +<br>
> + if (ref == xref)<br>
> + return child;<br>
> + }<br>
> +<br>
> + return -1;<br>
> +}<br>
> +<br>
> +phandle_t rtems_ofw_node_from_xref( phandle_t xref )<br>
> +{<br>
> + phandle_t node;<br>
> +<br>
> + if ((node = rtems_ofw_get_effective_phandle(rtems_ofw_peer(0), xref)) == -1)<br>
> + return xref;<br>
> +<br>
> + return node;<br>
> +}<br>
> +<br>
> +phandle_t rtems_ofw_xref_from_node( phandle_t node )<br>
> +{<br>
> + phandle_t ref;<br>
> +<br>
> + if (rtems_ofw_get_enc_prop(node, "phandle", &ref, sizeof(ref)) == -1 &&<br>
> + rtems_ofw_get_enc_prop(node, "ibm,phandle", &ref, sizeof(ref)) == -1 &&<br>
> + rtems_ofw_get_enc_prop(node, "linux,phandle", &ref, sizeof(ref)) == -1)<br>
> + {<br>
> + return node;<br>
> + }<br>
> +<br>
> + return ref;<br>
> +}<br>
> +<br>
> +phandle_t rtems_ofw_instance_to_package( ihandle_t instance )<br>
> +{<br>
> + return rtems_ofw_node_from_xref(instance);<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_package_to_path(<br>
> + phandle_t node,<br>
> + char *buf,<br>
> + size_t len<br>
> +)<br>
> +{<br>
> + int offset;<br>
> + int rv;<br>
> +<br>
> + offset = rtems_fdt_phandle_to_offset(node);<br>
> +<br>
> + rv = fdt_get_path(fdtp, offset, buf, len);<br>
> + if (rv != 0)<br>
> + return -1;<br>
> +<br>
> + return rv;<br>
> +}<br>
> +<br>
> +ssize_t rtems_ofw_instance_to_path(<br>
> + ihandle_t instance,<br>
> + char *buf,<br>
> + size_t len<br>
> +)<br>
> +{<br>
> + int offset;<br>
> + int rv;<br>
> +<br>
> + offset = rtems_ofw_instance_to_package(instance);<br>
> + offset = rtems_fdt_phandle_to_offset(offset);<br>
> +<br>
> + rv = fdt_get_path(fdtp, offset, buf, len);<br>
> + if (rv != 0)<br>
> + return -1;<br>
> +<br>
> + return rv;<br>
> +}<br>
> +<br>
> +int rtems_ofw_get_reg(<br>
> + phandle_t node,<br>
> + rtems_ofw_memory_area *buf,<br>
> + size_t size<br>
> +)<br>
> +{<br>
> + int len;<br>
> + int offset;<br>
> + int nranges;<br>
> + int nregs;<br>
> + phandle_t parent;<br>
> + rtems_ofw_ranges range;<br>
> + const rtems_ofw_ranges *ptr;<br>
> +<br>
> + len = rtems_ofw_get_enc_prop(node, "reg", (pcell_t *)buf, size);<br>
> + if (len <= 0) {<br>
> + return len;<br>
> + }<br>
> +<br>
> + nregs = MIN(len, size) / sizeof(rtems_ofw_memory_area);<br>
> +<br>
> + for (parent = rtems_ofw_parent(node); parent > 0;<br>
> + parent = rtems_ofw_parent(parent)) {<br>
> +<br>
> + offset = rtems_fdt_phandle_to_offset(parent);<br>
> + ptr = fdt_getprop(fdtp, offset, "ranges", &len);<br>
> +<br>
> + if (len < 0) {<br>
> + break;<br>
> + }<br>
> +<br>
> + nranges = len / sizeof(rtems_ofw_ranges);<br>
> +<br>
> + offset = 0;<br>
> + for (int i=0; i < nregs; i++) {<br>
> + for (int j=0; j < nranges; j++) {<br>
> +<br>
> + range.parent_bus = fdt32_to_cpu(ptr[j].parent_bus);<br>
> + range.child_bus = fdt32_to_cpu(ptr[j].child_bus);<br>
> + range.size = fdt32_to_cpu(ptr[j].size);<br>
> +<br>
> + if (buf[i].start >= range.child_bus &&<br>
> + buf[i].start < range.child_bus + range.size) {<br>
> + offset = range.parent_bus - range.child_bus;<br>
> + break;<br>
> + }<br>
> +<br>
> + }<br>
> + buf[i].start += offset;<br>
> + }<br>
> + }<br>
> +<br>
> + return nregs;<br>
> +}<br>
> +<br>
> +int rtems_ofw_get_interrupts(<br>
> + phandle_t node,<br>
> + rtems_vector_number *buf,<br>
> + size_t size<br>
> +)<br>
> +{<br>
> + int rv;<br>
> +<br>
> + rv = rtems_ofw_get_enc_prop(node, "interrupts", buf, size);<br>
> +<br>
> + if (rv <= 0) {<br>
> + return rv;<br>
> + }<br>
> +<br>
> + return MIN(size, rv) / sizeof(rtems_vector_number);<br>
> +}<br>
> +<br>
> +bool rtems_ofw_node_status( phandle_t node )<br>
> +{<br>
> + int len;<br>
> + const char buf[10];<br>
> +<br>
> + len = rtems_ofw_get_prop(node, "status", &buf[0], sizeof(buf));<br>
> + if ((len == -1) ||<br>
> + (strncmp(buf, "okay", MIN(5, len)) == 0) ||<br>
> + (strncmp(buf, "ok", MIN(3, len)) == 0)) {<br>
> + return true;<br>
> + }<br>
> +<br>
> + return false;<br>
> +}<br>
> +<br>
> +phandle_t rtems_ofw_find_device_by_compat( const char *compat )<br>
> +{<br>
> + int offset;<br>
> +<br>
> + offset = fdt_node_offset_by_compatible(fdtp, -1, compat);<br>
> + return rtems_fdt_offset_to_phandle(offset);<br>
> +}<br>
> diff --git a/spec/build/bsps/obj.yml b/spec/build/bsps/obj.yml<br>
> index a454783d51..b598d54d16 100644<br>
> --- a/spec/build/bsps/obj.yml<br>
> +++ b/spec/build/bsps/obj.yml<br>
> @@ -24,6 +24,10 @@ install:<br>
> - bsps/include/bsp/u-boot.h<br>
> - bsps/include/bsp/uart-output-char.h<br>
> - bsps/include/bsp/utility.h<br>
> +- destination: ${BSP_INCLUDEDIR}/ofw<br>
> + source:<br>
> + - bsps/include/ofw/ofw.h<br>
> + - bsps/include/ofw/ofw_compat.h<br>
> - destination: ${BSP_INCLUDEDIR}/libchip<br>
> source:<br>
> - bsps/include/libchip/ata.h<br>
> @@ -96,4 +100,5 @@ source:<br>
> - bsps/shared/dev/serial/serprobe.c<br>
> - bsps/shared/start/bootcard.c<br>
> - bsps/shared/rtems-version.c<br>
> +- bsps/shared/ofw/ofw.c<br>
> type: build<br>
> <br>
</blockquote></div></div>