[Pdbg] [RFC 09/12] libpdbg: Initialise target class from device-tree

Alistair Popple alistair at popple.id.au
Tue Aug 6 11:37:20 AEST 2019


The target class is usually initialised from the hardware unit
description. However if no hardware unit is found no class is
assigned. This patch makes it possible to assign one in cases when no
hardware unit is available.

This is primarily useful for busses and other targets that have
drivers assigned via the backend selection logic.

Signed-off-by: Alistair Popple <alistair at popple.id.au>
---
 libpdbg/device.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/libpdbg/device.c b/libpdbg/device.c
index f6d27db..428d946 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -118,6 +118,8 @@ static struct pdbg_target *pdbg_target_new(const void *fdt, int node_offset)
 
 static struct pdbg_target *dt_new_node(const char *name, const void *fdt, int node_offset)
 {
+	struct pdbg_target_class *target_class;
+	const struct fdt_property *prop;
 	struct pdbg_target *node = NULL;
 	size_t size = sizeof(*node);
 
@@ -132,6 +134,15 @@ static struct pdbg_target *dt_new_node(const char *name, const void *fdt, int no
 		abort();
 	}
 
+	if (fdt && !node->class) {
+		prop = fdt_get_property(fdt, node_offset, "class", NULL);
+		if (prop) {
+			node->class = (char *) &prop->data[0];
+			target_class = get_target_class(node);
+			list_add_tail(&target_class->targets, &node->class_link);
+		}
+	}
+
 	node->dn_name = take_name(name);
 	node->parent = NULL;
 	list_head_init(&node->properties);
-- 
2.20.1



More information about the Pdbg mailing list