[Skiboot] [PATCH v10 05/11] skiboot/dt: Add phandle fixup helpers

Madhavan Srinivasan maddy at linux.vnet.ibm.com
Thu May 4 14:42:08 AEST 2017


New subtree needs would have "phandle" already
assigned to some of it's nodes. If this new
subtree is attached to main dt, will lead to
possible phandle duplicate errors.

New subtree could also have "properties" refering to
the phandle. So these "properties" should also
get updated accordingly when fixing the "phandle".

New helper dt_adjust_subtree_phandle() added to
core/device.c to do both. It does phandle fixup
with a single pass through the subtree.

Signed-off-by: Madhavan Srinivasan <maddy at linux.vnet.ibm.com>
---
 core/device.c    | 36 ++++++++++++++++++++++++++++++++++++
 include/device.h |  4 ++++
 2 files changed, 40 insertions(+)

diff --git a/core/device.c b/core/device.c
index 7211570e1b3c..8a6a88d3f991 100644
--- a/core/device.c
+++ b/core/device.c
@@ -1069,3 +1069,39 @@ bool dt_node_is_enabled(struct dt_node *node)
 
 	return p->len > 1 && p->prop[0] == 'o' && p->prop[1] == 'k';
 }
+
+/*
+ * Function to fixup the phandle in the subtree.
+ */
+void dt_adjust_subtree_phandle(struct dt_node *dev,
+			const char** (get_properties_to_fix)(struct dt_node *n))
+{
+	struct dt_node *node;
+	struct dt_property *prop;
+	u32 phandle, max_phandle = 0, import_phandle = new_phandle();
+	const char **name;
+
+	dt_for_each_node(dev, node) {
+		const char **props_to_update;
+		node->phandle += import_phandle;
+
+		/*
+		 * calculate max_phandle(new_tree), needed to update
+		 * last_phandle.
+		 */
+		if (node->phandle >= max_phandle)
+			max_phandle = node->phandle;
+
+		props_to_update = get_properties_to_fix(node);
+		if (props_to_update) {
+			for (name = props_to_update; *name != NULL; name++) {
+				prop = __dt_find_property(node, *name);
+				phandle = dt_prop_get_u32(node, *name);
+				phandle += import_phandle;
+				memcpy((char *)&prop->prop, &phandle, prop->len);
+			}
+		}
+       }
+
+       set_last_phandle(max_phandle);
+}
diff --git a/include/device.h b/include/device.h
index c51b3eea298e..1e5875dca584 100644
--- a/include/device.h
+++ b/include/device.h
@@ -268,4 +268,8 @@ struct dt_node *__dt_find_by_name_addr(struct dt_node *parent, const char *name,
 struct dt_node *dt_find_by_name_addr(struct dt_node *parent, const char *name,
 				uint64_t addr);
 
+/* phandle fixup helper */
+void dt_adjust_subtree_phandle(struct dt_node *subtree,
+				const char** (get_properties_to_fix)(struct dt_node *n));
+
 #endif /* __DEVICE_H */
-- 
2.7.4



More information about the Skiboot mailing list