[coreboot-gerrit] Change in coreboot[master]: lib/device_tree: Add method to get phandle

Patrick Rudolph (Code Review) gerrit at coreboot.org
Wed May 9 14:21:41 CEST 2018


Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/26191


Change subject: lib/device_tree: Add method to get phandle
......................................................................

lib/device_tree: Add method to get phandle

Add a method to retrieve a node's phandle.
Useful for board specific devicetree manipulations.

Change-Id: I966151ad7e82fc678ab4f56cf9b5868ef39398e0
Signed-off-by: Patrick Rudolph <patrick.rudolph at 9elements.com>
---
M src/include/device_tree.h
M src/lib/device_tree.c
2 files changed, 26 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/91/26191/1

diff --git a/src/include/device_tree.h b/src/include/device_tree.h
index 107fcf6..5c62ff6 100644
--- a/src/include/device_tree.h
+++ b/src/include/device_tree.h
@@ -147,6 +147,8 @@
 // Look up a node relative to a parent node, through its property value.
 struct device_tree_node *dt_find_prop_value(struct device_tree_node *parent, const char *name,
 				   void *data, size_t size);
+// Return the phandle
+uint32_t dt_get_phandle(struct device_tree_node *parent);
 // Write src into *dest as a 'length'-byte big-endian integer.
 void dt_write_int(u8 *dest, u64 src, size_t length);
 // Add different kinds of properties to a node, or update existing ones.
diff --git a/src/lib/device_tree.c b/src/lib/device_tree.c
index 0a88c1f..bbb892a 100644
--- a/src/lib/device_tree.c
+++ b/src/lib/device_tree.c
@@ -725,6 +725,30 @@
 	return NULL;
 }
 
+/**
+ * Find the phandle of a node.
+ *
+ * @param parent Pointer to node containing the phandle
+ * @return Zero on error, the phandle on success
+ */
+uint32_t dt_get_phandle(struct device_tree_node *parent)
+{
+	uint32_t *phandle = NULL;
+	size_t len = 0;
+
+	dt_find_bin_prop(parent, "phandle", (void **)&phandle, &len);
+	if (phandle != NULL && len == sizeof(*phandle))
+		return be32_to_cpu(*phandle);
+
+	phandle = NULL;
+	len = 0;
+	dt_find_bin_prop(parent, "linux,phandle", (void **)&phandle, &len);
+	if (phandle != NULL && len == sizeof(*phandle))
+		return be32_to_cpu(*phandle);
+
+	return 0;
+}
+
 /*
  * Write an arbitrary sized big-endian integer into a pointer.
  *

-- 
To view, visit https://review.coreboot.org/26191
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I966151ad7e82fc678ab4f56cf9b5868ef39398e0
Gerrit-Change-Number: 26191
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <patrick.rudolph at 9elements.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180509/fd7cafeb/attachment-0001.html>


More information about the coreboot-gerrit mailing list