diff mbox series

[05/10] libpdbg: Rework chip-id functions

Message ID 20181025062131.18873-6-alistair@popple.id.au
State Superseded
Headers show
Series Cleanup of old code | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch warning master/apply_patch Patch failed to apply
snowpatch_ozlabs/apply_patch fail Failed to apply to any branch

Commit Message

Alistair Popple Oct. 25, 2018, 6:21 a.m. UTC
Rename the chip-id functions to be consistent with other libpdbg
function names and move them in with the rest of the general libpdbg
code.

Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
 libpdbg/device.c  | 19 -------------------
 libpdbg/device.h  |  4 ----
 libpdbg/host.c    |  2 +-
 libpdbg/htm.c     |  4 ++--
 libpdbg/libpdbg.c | 15 +++++++++++++++
 libpdbg/libpdbg.h |  4 ++++
 6 files changed, 22 insertions(+), 26 deletions(-)
diff mbox series

Patch

diff --git a/libpdbg/device.c b/libpdbg/device.c
index 2128fa7..2781b5b 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -675,25 +675,6 @@  u64 dt_get_address(const struct pdbg_target *node, unsigned int index,
 	return dt_get_number(p->prop + pos, na);
 }
 
-static u32 __dt_get_chip_id(const struct pdbg_target *node)
-{
-	const struct dt_property *prop;
-
-	for (; node; node = node->parent) {
-		prop = dt_find_property(node, "chip-id");
-		if (prop)
-			return dt_property_get_cell(prop, 0);
-	}
-	return 0xffffffff;
-}
-
-u32 dt_get_chip_id(const struct pdbg_target *node)
-{
-	u32 id = __dt_get_chip_id(node);
-	assert(id != 0xffffffff);
-	return id;
-}
-
 void pdbg_targets_init(void *fdt)
 {
 	dt_root = dt_new_node("", NULL, 0);
diff --git a/libpdbg/device.h b/libpdbg/device.h
index f487443..a050a23 100644
--- a/libpdbg/device.h
+++ b/libpdbg/device.h
@@ -44,10 +44,6 @@  const void *dt_prop_get(const struct pdbg_target *node, const char *prop);
 const void *dt_prop_get_def(const struct pdbg_target *node, const char *prop,
 			    void *def);
 
-/* Find an chip-id property in this node; if not found, walk up the parent
- * nodes. Returns -1 if no chip-id property exists. */
-u32 dt_get_chip_id(const struct pdbg_target *node);
-
 /* Address accessors ("reg" properties parsing). No translation,
  * only support "simple" address forms (1 or 2 cells). Asserts
  * if address doesn't exist
diff --git a/libpdbg/host.c b/libpdbg/host.c
index eb627be..15e28a0 100644
--- a/libpdbg/host.c
+++ b/libpdbg/host.c
@@ -91,7 +91,7 @@  static int host_pib_probe(struct pdbg_target *target)
 	if (!fd)
 		return -1;
 
-	chip_id = dt_get_chip_id(target);
+	chip_id = pdbg_target_chip_id(target);
 	if (chip_id == -1)
 		goto out;
 
diff --git a/libpdbg/htm.c b/libpdbg/htm.c
index f9013e5..1ea2c3a 100644
--- a/libpdbg/htm.c
+++ b/libpdbg/htm.c
@@ -551,7 +551,7 @@  static char *get_debugfs_file(struct htm *htm, const char *file)
 	uint32_t chip_id;
 	char *filename;
 
-	chip_id = dt_get_chip_id(&htm->target);
+	chip_id = pdbg_target_chip_id(&htm->target);
 	if (chip_id == -1) {
 		PR_ERROR("Couldn't find a chip id\n");
 		return NULL;
@@ -990,7 +990,7 @@  static int do_htm_dump(struct htm *htm, char *filename)
 		return -1;
 	}
 
-	chip_id = dt_get_chip_id(&htm->target);
+	chip_id = pdbg_target_chip_id(&htm->target);
 	if (chip_id == -1)
 		return -1;
 
diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c
index edf303c..47fb486 100644
--- a/libpdbg/libpdbg.c
+++ b/libpdbg/libpdbg.c
@@ -155,6 +155,21 @@  int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint3
         return 0;
 }
 
+uint32_t pdbg_target_chip_id(struct pdbg_target *target)
+{
+        uint32_t id;
+
+	while (pdbg_target_u32_property(target, "chip-id", &id)) {
+		target = target->parent;
+
+		/* If we hit this we've reached the top of the tree
+		 * and haven't found chip-id */
+		assert(target);
+	}
+
+	return id;
+}
+
 void pdbg_progress_tick(uint64_t cur, uint64_t end)
 {
 	if (progress_tick)
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index 78930e9..b11e071 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -82,6 +82,10 @@  uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size);
 #define pdbg_get_target_property(target, name, size) \
 	pdbg_target_property(target, name, size)
 
+/* Find an chip-id property in this node; if not found, walk up the parent
+ * nodes. Returns -1 if no chip-id property exists. */
+uint32_t pdbg_target_chip_id(struct pdbg_target *node);
+
 /* Misc. */
 void pdbg_targets_init(void *fdt);
 void pdbg_target_probe_all(struct pdbg_target *parent);