diff options
| author | Alistair Popple <alistair@popple.id.au> | 2018-10-25 15:24:54 +1100 |
|---|---|---|
| committer | Alistair Popple <alistair@popple.id.au> | 2018-11-09 11:24:35 +1100 |
| commit | 7bbd360cf6e3ee70440bf85682b862a877a643b0 (patch) | |
| tree | 961f8869f0012ff04415c85091f827bda8b427a0 /libpdbg | |
| parent | 1294e17b498c27425e44a922f00ce7acebbd2df2 (diff) | |
| download | pdbg-7bbd360cf6e3ee70440bf85682b862a877a643b0.tar.gz pdbg-7bbd360cf6e3ee70440bf85682b862a877a643b0.zip | |
libpdbg: Rework chip-id functions
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>
Reviewed-by: Amitay Isaacs <amitay@ozlabs.org>
Diffstat (limited to 'libpdbg')
| -rw-r--r-- | libpdbg/device.c | 19 | ||||
| -rw-r--r-- | libpdbg/device.h | 4 | ||||
| -rw-r--r-- | libpdbg/host.c | 4 | ||||
| -rw-r--r-- | libpdbg/htm.c | 12 | ||||
| -rw-r--r-- | libpdbg/libpdbg.c | 15 | ||||
| -rw-r--r-- | libpdbg/libpdbg.h | 4 |
6 files changed, 21 insertions, 37 deletions
diff --git a/libpdbg/device.c b/libpdbg/device.c index 226cf12..a7212a6 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..9d82618 100644 --- a/libpdbg/host.c +++ b/libpdbg/host.c @@ -91,9 +91,7 @@ static int host_pib_probe(struct pdbg_target *target) if (!fd) return -1; - chip_id = dt_get_chip_id(target); - if (chip_id == -1) - goto out; + chip_id = pdbg_target_chip_id(target); /* This check should probably be done earlier */ if (access(XSCOM_BASE_PATH, F_OK) == -1) diff --git a/libpdbg/htm.c b/libpdbg/htm.c index f9013e5..40d54d3 100644 --- a/libpdbg/htm.c +++ b/libpdbg/htm.c @@ -551,12 +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); - if (chip_id == -1) { - PR_ERROR("Couldn't find a chip id\n"); - return NULL; - } - + chip_id = pdbg_target_chip_id(&htm->target); if (asprintf(&filename, "%s/%08x/%s", DEBUGFS_MEMTRACE, chip_id, file) == -1) { PR_ERROR("Couldn't asprintf() '%s/%08x/size': %m\n", DEBUGFS_MEMTRACE, chip_id); @@ -975,7 +970,6 @@ static int do_htm_dump(struct htm *htm, char *filename) uint64_t last, end, trace_size; int trace_fd, dump_fd; uint32_t eyecatcher; - uint32_t chip_id; size_t r; bool wrapped; @@ -990,10 +984,6 @@ static int do_htm_dump(struct htm *htm, char *filename) return -1; } - chip_id = dt_get_chip_id(&htm->target); - if (chip_id == -1) - return -1; - trace_file = get_debugfs_file(htm, "trace"); if (!trace_file) return -1; diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 5e0ba35..ff1838b 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -150,6 +150,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 8d8f0a3..47c8808 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 *target); + /* Misc. */ void pdbg_targets_init(void *fdt); void pdbg_target_probe_all(struct pdbg_target *parent); |

