[rtems commit] bsps/shared/ofw: Add rtems_ofw_is_node_compatible

Christian Mauderer christianm at rtems.org
Sun Mar 21 11:37:29 UTC 2021


Module:    rtems
Branch:    master
Commit:    fc7129067d7b94b620302378677c5a48a47cdbad
Changeset: http://git.rtems.org/rtems/commit/?id=fc7129067d7b94b620302378677c5a48a47cdbad

Author:    G S Niteesh Babu <niteesh.gs at gmail.com>
Date:      Sat Mar 13 16:50:00 2021 +0530

bsps/shared/ofw: Add rtems_ofw_is_node_compatible

This patch extends the RTEMS OFW API by adding
rtems_ofw_find_device_by_compat

This function checks if a node has the expected compatible
property.

---

 bsps/include/ofw/ofw.h | 17 +++++++++++++++++
 bsps/shared/ofw/ofw.c  | 12 ++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/bsps/include/ofw/ofw.h b/bsps/include/ofw/ofw.h
index 411010b..bfd91d2 100644
--- a/bsps/include/ofw/ofw.h
+++ b/bsps/include/ofw/ofw.h
@@ -541,6 +541,23 @@ bool rtems_ofw_node_status( phandle_t node );
  */
 phandle_t rtems_ofw_find_device_by_compat( const char *compat );
 
+/**
+ * @brief check a nodes compatible property.
+ *
+ * This routine is local to RTEMS OFW and does not have an corresponding
+ * FreeBSD OFW pair.
+ *
+ * Return true if @a compat equals @a node compatible property
+ *
+ * @param[in] node phandle of node
+ * @param[in] compat Compatible string
+ *
+ * @retval 1 If node contains the @a compat as a element in compatible
+ * property.
+ * @retval 0 Otherwise.
+ */
+bool rtems_ofw_is_node_compatible( phandle_t node, const char *compat );
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index 1c3a817..f4b8b63 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -690,3 +690,15 @@ phandle_t rtems_ofw_find_device_by_compat( const char *compat )
   offset = fdt_node_offset_by_compatible(fdtp, -1, compat);
   return rtems_fdt_offset_to_phandle(offset);
 }
+
+bool rtems_ofw_is_node_compatible(
+  phandle_t node,
+  const char *compat
+)
+{
+  int offset;
+
+  offset = rtems_fdt_phandle_to_offset(node);
+
+  return fdt_node_check_compatible(fdtp, offset, compat) == 0;
+}



More information about the vc mailing list