<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 3, 2020 at 12:43 AM Christian Mauderer <<a href="mailto:oss@c-mauderer.de">oss@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 Niteesh,<br>
<br>
On 02/11/2020 18:06, Niteesh G. S. wrote:<br>
> ping.<br>
<br>
Yes, of course you are right that it would be time to integrate it. The<br>
nasty part why I haven't started to do something into that direction is<br>
that we currently still have the old build system and the new in<br>
parallel. But I think we should start to integrate your code anyway.<br>
<br>
Please correct me if I'm wrong: Currently there are two parts:<br>
<br>
1. Adding the OFW interface.<br>
<br>
2. Using in in BBB.<br>
<br>
Is that correct?<br></blockquote><div><span class="gmail_default" style="font-size:small">There is also the FreeBSD structures </span>to make<span class="gmail_default" style="font-size:small"> </span>porting of drivers easy.<span class="gmail_default"></span></div><div><span class="gmail_default">I guess merging this after a thorough inspection </span>should also not be</div><div>an issue.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I think the first one should be not too hard. There are already some<br>
parts that use only the new build system. Wouldn't be a problem to do<br>
that with OFW too. So to all participating at the discussion: Is there<br>
any blocker left why we wouldn't integrate an updated version of the<br>
patches?<br></blockquote><div> </div><div><div class="gmail_default" style="font-size:small">The only blocker seen during the development was the license issue.</div><div class="gmail_default" style="font-size:small">But that is now resolved since we figured out that all the referenced</div><div class="gmail_default" style="font-size:small">code comes under the BSD 2 license.</div></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">
The second part is a bit harder. BBB is one of the BSPs that are quite<br>
entry friendly and therefore it should currently build with old and new<br>
build system till the old system is removed.<br></blockquote><div> </div><div><div class="gmail_default" style="font-size:small">OK. I'll wait until the old system gets removed, I still have some work left</div><div class="gmail_default" style="font-size:small">to do on the drivers.</div></div><div><br></div><div><div class="gmail_default" style="font-size:small">Thanks,</div><div class="gmail_default" style="font-size:small">Niteesh</div><br></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>
> <br>
> On Thu, Sep 24, 2020 at 9:00 AM Niteesh G. S. <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a><br>
> <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>>> wrote:<br>
> <br>
> Hello,<br>
> <br>
> On Sat, Sep 19, 2020 at 4:13 PM Christian Mauderer<br>
> <<a href="mailto:oss@c-mauderer.de" target="_blank">oss@c-mauderer.de</a> <mailto:<a href="mailto:oss@c-mauderer.de" target="_blank">oss@c-mauderer.de</a>>> wrote:<br>
> <br>
> Hello Niteesh,<br>
> <br>
> sorry for adding another delay: I think the new build system<br>
> needs a bit<br>
> of time to settle. As soon as there are some more PASS in the<br>
> table that<br>
> Sebastian created [1] (especially for beagle) we should try to<br>
> get these<br>
> patches merged. Before that I would like to avoid big changes<br>
> because it<br>
> might get hard to distinguish new bugs from build system bugs.<br>
> <br>
> <br>
> No problem. Currently, I have my university exams going on and also I am<br>
> waiting for my logic analyzer. As soon as it arrives I'll start<br>
> verifying the previous<br>
> drivers and finish refactoring the other ones.<br>
> <br>
> Thanks,<br>
> Niteesh.<br>
> <br>
> <br>
> <br>
> <br>
> Best regards<br>
> <br>
> Christian<br>
> <br>
> [1] <a href="https://devel.rtems.org/wiki/Release/6/Waf%20BSP%20Checklist" rel="noreferrer" target="_blank">https://devel.rtems.org/wiki/Release/6/Waf%20BSP%20Checklist</a><br>
> <br>
> On 16/09/2020 19:05, Niteesh G. S. wrote:<br>
> > Hello,<br>
> ><br>
> > Sorry for the delay, I was a bit occupied with my university work.<br>
> > Now since the new build system is merged I would like to get my<br>
> > GSoC work merged too.<br>
> ><br>
> > The goal of this series patches is to implement the OFW API<br>
> into RTEMS<br>
> > and modify libBSD to use this RTEMS API instead of its own.<br>
> ><br>
> > Thanks,<br>
> > Niteesh.<br>
> ><br>
> > On Wed, Sep 16, 2020 at 10:33 PM G S Niteesh Babu<br>
> <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a> <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>><br>
> > <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a> <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>>>><br>
> wrote:<br>
> ><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>
> +++++++++++++++++++++++++++<br>
> > bsps/include/ofw/ofw_compat.h | 74 ++++<br>
> > bsps/shared/ofw/ofw.c | 682<br>
> ++++++++++++++++++++++++++++++++++<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..411010be89<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<br>
> > interface.<br>
> > + * This API is created to be compatible with FreeBSD<br>
> OpenFirmWare<br>
> > interface.<br>
> > + * The main intention is to make porting of FreeBSD<br>
> drivers to<br>
> > RTEMS easier.<br>
> > + */<br>
> > +<br>
> > +/*<br>
> > + * Copyright (C) 2020 Niteesh Babu G S<br>
> <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a> <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>><br>
> > <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a> <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>>>><br>
> > + *<br>
> > + * Redistribution and use in source and binary forms,<br>
> with or without<br>
> > + * modification, are permitted provided that the<br>
> following conditions<br>
> > + * are met:<br>
> > + * 1. Redistributions of source code must retain the<br>
> above copyright<br>
> > + * notice, this list of conditions and the following<br>
> disclaimer.<br>
> > + * 2. Redistributions in binary form must reproduce the<br>
> above copyright<br>
> > + * notice, this list of conditions and the following<br>
> disclaimer<br>
> > in the<br>
> > + * documentation and/or other materials provided with the<br>
> > distribution.<br>
> > + *<br>
> > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND<br>
> > CONTRIBUTORS "AS IS"<br>
> > + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br>
> > LIMITED TO, THE<br>
> > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A<br>
> > PARTICULAR PURPOSE<br>
> > + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR<br>
> > CONTRIBUTORS BE<br>
> > + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,<br>
> EXEMPLARY, OR<br>
> > + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,<br>
> PROCUREMENT OF<br>
> > + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR<br>
> PROFITS; OR<br>
> > BUSINESS<br>
> > + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF<br>
> LIABILITY,<br>
> > WHETHER IN<br>
> > + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING<br>
> NEGLIGENCE OR<br>
> > OTHERWISE)<br>
> > + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,<br>
> EVEN IF<br>
> > 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<br>
> fdtp to<br>
> > node is used<br>
> > + * instead of fdt offset to make sure this is compatible<br>
> with OF<br>
> > 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)<br>
> 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<br>
> device tree.<br>
> > + */<br>
> > +typedef struct {<br>
> > + /** The physical address within the child bus address<br>
> space */<br>
> > + uint32_t child_bus;<br>
> > + /** The physical address within the parent bus address<br>
> 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<br>
> 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<br>
> 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<br>
> buffer<br>
> > (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<br>
> value<br>
> > 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<br>
> > 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<br>
> 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<br>
> property<br>
> > 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<br>
> buffer<br>
> > (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<br>
> property<br>
> > and fills the<br>
> > + * buffer with the first value found after converting it<br>
> to the<br>
> > 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<br>
> > 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<br>
> propname.<br>
> > + *<br>
> > + * Same as rtems_ofw_getprop, but the @a buf is allocated<br>
> in this<br>
> > 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<br>
> 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<br>
> properties with<br>
> > 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<br>
> 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<br>
> propname.<br>
> > + *<br>
> > + * Same as rtems_ofw_getprop_alloc but the value stored<br>
> in the<br>
> > 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<br>
> 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<br>
> stored in<br>
> > 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<br>
> 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<br>
> rtems_ofw_*_alloc<br>
> > 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<br>
> propname is NULL<br>
> > 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<br>
> stored in<br>
> > 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<br>
> 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<br>
> qualified path name.<br>
> > + *<br>
> > + * @param[in] dev device specifier<br>
> > + * @param[out] buf The path is filled into the<br>
> 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<br>
> to node<br>
> > 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<br>
> phandle of<br>
> > @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<br>
> > 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<br>
> 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<br>
> 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<br>
> in reg<br>
> > property of node<br>
> > + * @a node. It reads all the values of the property and<br>
> fills the<br>
> > buffer to max<br>
> > + * size.<br>
> > + * This routine is local to RTEMS OFW and does not have an<br>
> > corresponding<br>
> > + * FreeBSD OFW pair.<br>
> > + *<br>
> > + * @param[in] node Node offset<br>
> > + * @param[out] buf Register values are stored in this<br>
> > 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<br>
> interrupt number.<br>
> > 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<br>
> > corresponding<br>
> > + * FreeBSD OFW pair.<br>
> > + *<br>
> > + * @param[in] node Node offset<br>
> > + * @param[out] buf Interrupt values are stored in this<br>
> > 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<br>
> > 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<br>
> > corresponding<br>
> > + * FreeBSD OFW pair.<br>
> > + *<br>
> > + * @param[in] compat Compatible string<br>
> > + *<br>
> > + * @retval 0 Node with @a compat as compatible string not<br>
> found<br>
> > + * @retval Node phandle on success.<br>
> > + */<br>
> > +phandle_t rtems_ofw_find_device_by_compat( const char<br>
> *compat );<br>
> > +<br>
> > +#ifdef __cplusplus<br>
> > +}<br>
> > +#endif<br>
> > +<br>
> > +#endif /* _OFW_H */<br>
> > diff --git a/bsps/include/ofw/ofw_compat.h<br>
> > 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<br>
> OFW API<br>
> > compatible<br>
> > + * with FreeBSD OFW.<br>
> > + */<br>
> > +<br>
> > +/*<br>
> > + * Copyright (C) 2020 Niteesh Babu G S<br>
> <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a> <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>><br>
> > <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a> <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>>>><br>
> > + *<br>
> > + * Redistribution and use in source and binary forms,<br>
> with or without<br>
> > + * modification, are permitted provided that the<br>
> following conditions<br>
> > + * are met:<br>
> > + * 1. Redistributions of source code must retain the<br>
> above copyright<br>
> > + * notice, this list of conditions and the following<br>
> disclaimer.<br>
> > + * 2. Redistributions in binary form must reproduce the<br>
> above copyright<br>
> > + * notice, this list of conditions and the following<br>
> disclaimer<br>
> > in the<br>
> > + * documentation and/or other materials provided with the<br>
> > distribution.<br>
> > + *<br>
> > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND<br>
> > CONTRIBUTORS "AS IS"<br>
> > + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br>
> > LIMITED TO, THE<br>
> > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A<br>
> > PARTICULAR PURPOSE<br>
> > + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR<br>
> > CONTRIBUTORS BE<br>
> > + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,<br>
> EXEMPLARY, OR<br>
> > + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,<br>
> PROCUREMENT OF<br>
> > + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR<br>
> PROFITS; OR<br>
> > BUSINESS<br>
> > + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF<br>
> LIABILITY,<br>
> > WHETHER IN<br>
> > + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING<br>
> NEGLIGENCE OR<br>
> > OTHERWISE)<br>
> > + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,<br>
> EVEN IF<br>
> > 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 <br>
> rtems_ofw_get_prop_alloc_multi<br>
> > +#define OF_getencprop_alloc_multi<br>
> rtems_ofw_get_enc_prop_alloc_multi<br>
> > +#define OF_getencprop_alloc <br>
> 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 <br>
> 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..2b1dff8bf8<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<br>
> <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a> <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>><br>
> > <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a> <mailto:<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</a>>>><br>
> > + *<br>
> > + * Redistribution and use in source and binary forms,<br>
> with or without<br>
> > + * modification, are permitted provided that the<br>
> following conditions<br>
> > + * are met:<br>
> > + * 1. Redistributions of source code must retain the<br>
> above copyright<br>
> > + * notice, this list of conditions and the following<br>
> disclaimer.<br>
> > + * 2. Redistributions in binary form must reproduce the<br>
> above copyright<br>
> > + * notice, this list of conditions and the following<br>
> disclaimer<br>
> > in the<br>
> > + * documentation and/or other materials provided with the<br>
> > distribution.<br>
> > + *<br>
> > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND<br>
> > CONTRIBUTORS "AS IS"<br>
> > + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br>
> > LIMITED TO, THE<br>
> > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A<br>
> > PARTICULAR PURPOSE<br>
> > + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR<br>
> > CONTRIBUTORS BE<br>
> > + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,<br>
> EXEMPLARY, OR<br>
> > + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,<br>
> PROCUREMENT OF<br>
> > + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR<br>
> PROFITS; OR<br>
> > BUSINESS<br>
> > + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF<br>
> LIABILITY,<br>
> > WHETHER IN<br>
> > + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING<br>
> NEGLIGENCE OR<br>
> > OTHERWISE)<br>
> > + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,<br>
> EVEN IF<br>
> > 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,<br>
> 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,<br>
> len) !=<br>
> > -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) ==<br>
> -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) ==<br>
> -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)<br>
> == -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)<br>
> == -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<br>
> > **)&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<br>
> **)&name,<br>
> > &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 =<br>
> > 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,<br>
> sizeof(ref))<br>
> > == -1 &&<br>
> > + rtems_ofw_get_enc_prop(child, "ibm,phandle", &ref,<br>
> > sizeof(ref)) == -1 &&<br>
> > + rtems_ofw_get_enc_prop(child, "linux,phandle", &ref,<br>
> > 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 =<br>
> rtems_ofw_get_effective_phandle(rtems_ofw_peer(0),<br>
> > 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,<br>
> sizeof(ref))<br>
> > == -1 &&<br>
> > + rtems_ofw_get_enc_prop(node, "ibm,phandle", &ref,<br>
> > sizeof(ref)) == -1 &&<br>
> > + rtems_ofw_get_enc_prop(node, "linux,phandle", &ref,<br>
> > 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<br>
> *)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],<br>
> 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<br>
> *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 8809238057..0ea07fc83d 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/am29lv160.h<br>
> > @@ -104,4 +108,5 @@ source:<br>
> > - bsps/shared/dev/serial/z85c30_reg.c<br>
> > - bsps/shared/start/bootcard.c<br>
> > - bsps/shared/rtems-version.c<br>
> > +- bsps/shared/ofw/ofw.c<br>
> > type: build<br>
> > --<br>
> > 2.17.1<br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > devel mailing list<br>
> > <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a> <mailto:<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a>><br>
> > <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
> ><br>
> <br>
</blockquote></div></div>