[Pdbg] [PATCH v4 15/30] libpdbg: Add functions to get parent in backend or system tree
Amitay Isaacs
amitay at ozlabs.org
Thu Oct 3 14:18:54 AEST 2019
When using backend targets, the parent should be calculated based on
backend tree and not system tree (e.g. cfam).
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
libpdbg/cfam.c | 4 ++--
libpdbg/libpdbg.c | 24 +++++++++++++++++-------
libpdbg/target.h | 2 ++
3 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/libpdbg/cfam.c b/libpdbg/cfam.c
index 868ca76..da4c5fc 100644
--- a/libpdbg/cfam.c
+++ b/libpdbg/cfam.c
@@ -294,7 +294,7 @@ DECLARE_HW_UNIT(p8_opb_hmfsi);
static int cfam_hmfsi_read(struct fsi *fsi, uint32_t addr, uint32_t *data)
{
- struct pdbg_target *parent_fsi = pdbg_target_require_parent("fsi", &fsi->target);
+ struct pdbg_target *parent_fsi = require_target_parent("fsi", &fsi->target, false);
addr += pdbg_target_address(&fsi->target, NULL);
@@ -303,7 +303,7 @@ static int cfam_hmfsi_read(struct fsi *fsi, uint32_t addr, uint32_t *data)
static int cfam_hmfsi_write(struct fsi *fsi, uint32_t addr, uint32_t data)
{
- struct pdbg_target *parent_fsi = pdbg_target_require_parent("fsi", &fsi->target);
+ struct pdbg_target *parent_fsi = require_target_parent("fsi", &fsi->target, false);
addr += pdbg_target_address(&fsi->target, NULL);
diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c
index 7e72024..eaf2782 100644
--- a/libpdbg/libpdbg.c
+++ b/libpdbg/libpdbg.c
@@ -198,34 +198,44 @@ uint32_t pdbg_target_index(struct pdbg_target *target)
}
/* Find a target parent from the given class */
-struct pdbg_target *pdbg_target_parent(const char *class, struct pdbg_target *target)
+struct pdbg_target *target_parent(const char *klass, struct pdbg_target *target, bool system)
{
struct pdbg_target *parent;
- if (!class)
- return get_parent(target, true);
+ if (!klass)
+ return get_parent(target, system);
- for (parent = get_parent(target, true); parent && get_parent(parent, true); parent = get_parent(parent, true)) {
+ for (parent = get_parent(target, system); parent && get_parent(parent, system); parent = get_parent(parent, system)) {
const char *tclass = pdbg_target_class_name(parent);
if (!tclass)
continue;
- if (!strcmp(class, tclass))
+ if (!strcmp(klass, tclass))
return parent;
}
return NULL;
}
-struct pdbg_target *pdbg_target_require_parent(const char *class, struct pdbg_target *target)
+struct pdbg_target *pdbg_target_parent(const char *klass, struct pdbg_target *target)
{
- struct pdbg_target *parent = pdbg_target_parent(class, target);
+ return target_parent(klass, target, true);
+}
+
+struct pdbg_target *require_target_parent(const char *klass, struct pdbg_target *target, bool system)
+{
+ struct pdbg_target *parent = target_parent(klass, target, system);
assert(parent);
return parent;
}
+struct pdbg_target *pdbg_target_require_parent(const char *klass, struct pdbg_target *target)
+{
+ return require_target_parent(klass, target, true);
+}
+
/* Searched up the tree for the first target of the right class and returns its index */
uint32_t pdbg_parent_index(struct pdbg_target *target, char *class)
{
diff --git a/libpdbg/target.h b/libpdbg/target.h
index a8b0d3d..df4f3f8 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -54,6 +54,8 @@ struct pdbg_target {
};
struct pdbg_target *get_parent(struct pdbg_target *target, bool system);
+struct pdbg_target *target_parent(const char *klass, struct pdbg_target *target, bool system);
+struct pdbg_target *require_target_parent(const char *klass, struct pdbg_target *target, bool system);
struct pdbg_target_class *find_target_class(const char *name);
struct pdbg_target_class *require_target_class(const char *name);
struct pdbg_target_class *get_target_class(struct pdbg_target *target);
--
2.21.0
More information about the Pdbg
mailing list