[Skiboot] [PATCH v6 01/10] skiboot: Add helper function for last_phandle updates

Madhavan Srinivasan maddy at linux.vnet.ibm.com
Wed Mar 1 01:53:28 AEDT 2017


Add helper functions for "last_phandle" access/update
and add code to use the same

Signed-off-by: Madhavan Srinivasan <maddy at linux.vnet.ibm.com>
---
 core/device.c    |  4 ++--
 core/fdt.c       |  8 ++++----
 include/device.h | 16 ++++++++++++++++
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/core/device.c b/core/device.c
index 30b31f461c45..1b9d2caf41ed 100644
--- a/core/device.c
+++ b/core/device.c
@@ -56,7 +56,7 @@ static struct dt_node *new_node(const char *name)
 	list_head_init(&node->properties);
 	list_head_init(&node->children);
 	/* FIXME: locking? */
-	node->phandle = ++last_phandle;
+	node->phandle = increment_return_last_phandle();
 	return node;
 }
 
@@ -419,7 +419,7 @@ struct dt_property *dt_add_property(struct dt_node *node,
 		assert(size == 4);
 		node->phandle = *(const u32 *)val;
 		if (node->phandle >= last_phandle)
-			last_phandle = node->phandle;
+			update_last_phandle(node->phandle);
 		return NULL;
 	}
 
diff --git a/core/fdt.c b/core/fdt.c
index eabbd5411a47..bc74b909f4b1 100644
--- a/core/fdt.c
+++ b/core/fdt.c
@@ -188,11 +188,11 @@ void *create_dtb(const struct dt_node *root, bool exclusive)
 {
 	void *fdt = NULL;
 	size_t len = DEVICE_TREE_MAX_SIZE;
-	uint32_t old_last_phandle = last_phandle;
+	uint32_t old_last_phandle = get_last_phandle();
 	int ret;
 
 	do {
-		last_phandle = old_last_phandle;
+		update_last_phandle(old_last_phandle);
 		fdt_error = 0;
 		fdt = malloc(len);
 		if (!fdt) {
@@ -241,10 +241,10 @@ static int64_t opal_get_device_tree(uint32_t phandle,
 		return OPAL_PARAMETER;
 
 	fdt_error = 0;
-	old_last_phandle = last_phandle;
+	old_last_phandle = get_last_phandle();
 	ret = __create_dtb(fdt, len, root, true);
 	if (ret) {
-		last_phandle = old_last_phandle;
+		update_last_phandle(old_last_phandle);
 		if (ret == -FDT_ERR_NOSPACE)
 			return OPAL_NO_MEM;
 
diff --git a/include/device.h b/include/device.h
index 1ad403f18450..f659675764df 100644
--- a/include/device.h
+++ b/include/device.h
@@ -61,6 +61,22 @@ struct dt_node *dt_new_root(const char *name);
 /* Graft a root node into this tree. */
 bool dt_attach_root(struct dt_node *parent, struct dt_node *root);
 
+/* Wrappers for last_phandle operations */
+static inline u32 get_last_phandle(void)
+{
+	return last_phandle;
+}
+
+static inline void update_last_phandle(u32 phandle)
+{
+	last_phandle = phandle;
+}
+
+static inline u32 increment_return_last_phandle(void)
+{
+	return ++last_phandle;
+}
+
 /* Add a child node. */
 struct dt_node *dt_new(struct dt_node *parent, const char *name);
 struct dt_node *dt_new_addr(struct dt_node *parent, const char *name,
-- 
2.7.4



More information about the Skiboot mailing list