From patchwork Thu Oct 25 06:21:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gcTk0h6Wz9sBk for ; Thu, 25 Oct 2018 17:21:46 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42gcTj59SBzDrYZ for ; Thu, 25 Oct 2018 17:21:45 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42gcTW5G6TzDrS4 for ; Thu, 25 Oct 2018 17:21:35 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42gcTW2jvFz9sBh; Thu, 25 Oct 2018 17:21:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Thu, 25 Oct 2018 17:21:22 +1100 Message-Id: <20181025062131.18873-2-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181025062131.18873-1-alistair@popple.id.au> References: <20181025062131.18873-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 01/10] libpdbg: Remove unused code X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Much of the code in device.c was originally copied over from Skiboot and is not applicable or used by pdbg. Signed-off-by: Alistair Popple --- libpdbg/device.c | 266 +----------------------------------------------------- libpdbg/device.h | 89 ------------------ libpdbg/libpdbg.c | 27 ------ libpdbg/libpdbg.h | 1 - 4 files changed, 4 insertions(+), 379 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 7442e29..cdb3481 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -34,7 +34,6 @@ u32 last_phandle = 0; struct pdbg_target *dt_root; -struct pdbg_target *dt_chosen; static const char *take_name(const char *name) { @@ -283,22 +282,6 @@ struct pdbg_target *dt_find_by_path(struct pdbg_target *root, const char *path) return root; } -struct pdbg_target *dt_find_by_name(struct pdbg_target *root, const char *name) -{ - struct pdbg_target *child, *match; - - list_for_each(&root->children, child, list) { - if (!strcmp(child->dn_name, name)) - return child; - - match = dt_find_by_name(child, name); - if (match) - return match; - } - - return NULL; -} - static struct dt_property *new_property(struct pdbg_target *node, const char *name, size_t size) { @@ -363,107 +346,6 @@ void dt_resize_property(struct dt_property **prop, size_t len) (*prop)->list.prev->next = &(*prop)->list; } -struct dt_property *dt_add_property_string(struct pdbg_target *node, - const char *name, - const char *value) -{ - return dt_add_property(node, name, value, strlen(value)+1); -} - -struct dt_property *dt_add_property_nstr(struct pdbg_target *node, - const char *name, - const char *value, unsigned int vlen) -{ - struct dt_property *p; - char *tmp = zalloc(vlen + 1); - - if (!tmp) - return NULL; - - strncpy(tmp, value, vlen); - p = dt_add_property(node, name, tmp, strlen(tmp)+1); - free(tmp); - - return p; -} - -struct dt_property *__dt_add_property_cells(struct pdbg_target *node, - const char *name, - int count, ...) -{ - struct dt_property *p; - u32 *val; - unsigned int i; - va_list args; - - p = new_property(node, name, count * sizeof(u32)); - val = (u32 *)p->prop; - va_start(args, count); - for (i = 0; i < count; i++) - val[i] = cpu_to_fdt32(va_arg(args, u32)); - va_end(args); - return p; -} - -struct dt_property *__dt_add_property_u64s(struct pdbg_target *node, - const char *name, - int count, ...) -{ - struct dt_property *p; - u64 *val; - unsigned int i; - va_list args; - - p = new_property(node, name, count * sizeof(u64)); - val = (u64 *)p->prop; - va_start(args, count); - for (i = 0; i < count; i++) - val[i] = cpu_to_fdt64(va_arg(args, u64)); - va_end(args); - return p; -} - -struct dt_property *__dt_add_property_strings(struct pdbg_target *node, - const char *name, - int count, ...) -{ - struct dt_property *p; - unsigned int i, size; - va_list args; - const char *sstr; - char *s; - - va_start(args, count); - for (i = size = 0; i < count; i++) { - sstr = va_arg(args, const char *); - if (sstr) - size += strlen(sstr) + 1; - } - va_end(args); - if (!size) - size = 1; - p = new_property(node, name, size); - s = (char *)p->prop; - *s = 0; - va_start(args, count); - for (i = 0; i < count; i++) { - sstr = va_arg(args, const char *); - if (sstr) { - strcpy(s, sstr); - s = s + strlen(sstr) + 1; - } - } - va_end(args); - return p; -} - -void dt_del_property(struct pdbg_target *node, struct dt_property *prop) -{ - list_del_from(&node->properties, &prop->list); - free_name(prop->name); - free(prop); -} - u32 dt_property_get_cell(const struct dt_property *prop, u32 index) { assert(prop->len >= (index+1)*sizeof(u32)); @@ -497,16 +379,6 @@ struct pdbg_target *dt_next(const struct pdbg_target *root, return NULL; } -struct dt_property *__dt_find_property(struct pdbg_target *node, const char *name) -{ - struct dt_property *i; - - list_for_each(&node->properties, i, list) - if (strcmp(i->name, name) == 0) - return i; - return NULL; -} - struct dt_property *dt_find_property(const struct pdbg_target *node, const char *name) { @@ -518,14 +390,6 @@ struct dt_property *dt_find_property(const struct pdbg_target *node, return NULL; } -void dt_check_del_prop(struct pdbg_target *node, const char *name) -{ - struct dt_property *p; - - p = __dt_find_property(node, name); - if (p) - dt_del_property(node, p); -} const struct dt_property *dt_require_property(const struct pdbg_target *node, const char *name, int wanted_len) { @@ -551,19 +415,6 @@ const struct dt_property *dt_require_property(const struct pdbg_target *node, return p; } -bool dt_has_node_property(const struct pdbg_target *node, - const char *name, const char *val) -{ - const struct dt_property *p = dt_find_property(node, name); - - if (!p) - return false; - if (!val) - return true; - - return p->len == strlen(val) + 1 && memcmp(p->prop, val, p->len) == 0; -} - bool dt_prop_find_string(const struct dt_property *p, const char *s) { const char *c, *end; @@ -601,25 +452,6 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, return NULL; } -u64 dt_prop_get_u64(const struct pdbg_target *node, const char *prop) -{ - const struct dt_property *p = dt_require_property(node, prop, 8); - - return ((u64)dt_property_get_cell(p, 0) << 32) - | dt_property_get_cell(p, 1); -} - -u64 dt_prop_get_u64_def(const struct pdbg_target *node, const char *prop, u64 def) -{ - const struct dt_property *p = dt_find_property(node, prop); - - if (!p) - return def; - - return ((u64)dt_property_get_cell(p, 0) << 32) - | dt_property_get_cell(p, 1); -} - u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop) { const struct dt_property *p = dt_require_property(node, prop, 4); @@ -629,12 +461,12 @@ u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop) u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) { - const struct dt_property *p = dt_find_property(node, prop); + const struct dt_property *p = dt_find_property(node, prop); - if (!p) - return def; + if (!p) + return def; - return dt_property_get_cell(p, 0); + return dt_property_get_cell(p, 0); } u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index) @@ -659,17 +491,6 @@ const void *dt_prop_get_def(const struct pdbg_target *node, const char *prop, return p ? p->prop : def; } -const void *dt_prop_get_def_size(const struct pdbg_target *node, const char *prop, - void *def, size_t *len) -{ - const struct dt_property *p = dt_find_property(node, prop); - *len = 0; - if (p) - *len = p->len; - - return p ? p->prop : def; -} - u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell) { const struct dt_property *p = dt_require_property(node, prop, -1); @@ -677,35 +498,6 @@ u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell) return dt_property_get_cell(p, cell); } -u32 dt_prop_get_cell_def(const struct pdbg_target *node, const char *prop, - u32 cell, u32 def) -{ - const struct dt_property *p = dt_find_property(node, prop); - - if (!p) - return def; - - return dt_property_get_cell(p, cell); -} - -void dt_free(struct pdbg_target *node) -{ - struct pdbg_target *child; - struct dt_property *p; - - while ((child = list_top(&node->children, struct pdbg_target, list))) - dt_free(child); - - while ((p = list_pop(&node->properties, struct dt_property, list))) { - free_name(p->name); - free(p); - } - - if (node->parent) - list_del_from(&node->parent->children, &node->list); - dt_destroy(node); -} - enum pdbg_target_status str_to_status(const char *status) { if (!strcmp(status, "enabled")) { @@ -852,53 +644,3 @@ u32 dt_get_chip_id(const struct pdbg_target *node) assert(id != 0xffffffff); return id; } - -struct pdbg_target *dt_find_compatible_node_on_chip(struct pdbg_target *root, - struct pdbg_target *prev, - const char *compat, - uint32_t chip_id) -{ - struct pdbg_target *node; - - node = prev ? dt_next(root, prev) : root; - for (; node; node = dt_next(root, node)) { - u32 cid = __dt_get_chip_id(node); - if (cid == chip_id && - dt_node_is_compatible(node, compat)) - return node; - } - return NULL; -} - -unsigned int dt_count_addresses(const struct pdbg_target *node) -{ - const struct dt_property *p; - u32 na = dt_n_address_cells(node); - u32 ns = dt_n_size_cells(node); - u32 n; - - p = dt_require_property(node, "reg", -1); - n = (na + ns) * sizeof(u32); - - if (n == 0) - return 0; - - return p->len / n; -} - -u64 dt_translate_address(const struct pdbg_target *node, unsigned int index, - u64 *out_size) -{ - /* XXX TODO */ - return dt_get_address(node, index, out_size); -} - -bool dt_node_is_enabled(struct pdbg_target *node) -{ - const struct dt_property *p = dt_find_property(node, "status"); - - if (!p) - return true; - - return p->len > 1 && p->prop[0] == 'o' && p->prop[1] == 'k'; -} diff --git a/libpdbg/device.h b/libpdbg/device.h index cb5bc10..5786d99 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -44,7 +44,6 @@ struct dt_property { extern u32 last_phandle; extern struct pdbg_target *dt_root; -extern struct pdbg_target *dt_chosen; /* Create a new node. */ struct pdbg_target *dt_new_node(const char *name, const void *fdt, int offset); @@ -56,51 +55,6 @@ bool dt_attach_root(struct pdbg_target *parent, struct pdbg_target *root); struct dt_property *dt_add_property(struct pdbg_target *node, const char *name, const void *val, size_t size); -struct dt_property *dt_add_property_string(struct pdbg_target *node, - const char *name, - const char *value); -struct dt_property *dt_add_property_nstr(struct pdbg_target *node, - const char *name, - const char *value, unsigned int vlen); - -/* Given out enough GCC extensions, we will achieve enlightenment! */ -#define dt_add_property_strings(node, name, ...) \ - __dt_add_property_strings((node), ((name)), \ - sizeof((const char *[]) { __VA_ARGS__ })/sizeof(const char *), \ - __VA_ARGS__) - -struct dt_property *__dt_add_property_strings(struct pdbg_target *node, - const char *name, - int count, ...); - -/* Given out enough GCC extensions, we will achieve enlightenment! */ -#define dt_add_property_cells(node, name, ...) \ - __dt_add_property_cells((node), ((name)), \ - sizeof((u32[]) { __VA_ARGS__ })/sizeof(u32), \ - __VA_ARGS__) - -struct dt_property *__dt_add_property_cells(struct pdbg_target *node, - const char *name, - int count, ...); - -#define dt_add_property_u64s(node, name, ...) \ - __dt_add_property_u64s((node), ((name)), \ - sizeof((u64[]) { __VA_ARGS__ })/sizeof(u64), \ - __VA_ARGS__) - -struct dt_property *__dt_add_property_u64s(struct pdbg_target *node, - const char *name, - int count, ...); - -static inline struct dt_property *dt_add_property_u64(struct pdbg_target *node, - const char *name, u64 val) -{ - return dt_add_property_cells(node, name, (u32)(val >> 32), (u32)val); -} - -void dt_del_property(struct pdbg_target *node, struct dt_property *prop); - -void dt_check_del_prop(struct pdbg_target *node, const char *name); /* Warning: moves *prop! */ void dt_resize_property(struct dt_property **prop, size_t len); @@ -113,10 +67,6 @@ struct pdbg_target *dt_first(const struct pdbg_target *root); /* Return next node, or NULL. */ struct pdbg_target *dt_next(const struct pdbg_target *root, const struct pdbg_target *prev); -/* Iterate nodes */ -#define dt_for_each_node(root, node) \ - for (node = dt_first(root); node; node = dt_next(root, node)) - #define dt_for_each_child(parent, node) \ list_for_each(&parent->children, node, list) @@ -135,18 +85,6 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, for (node = NULL; \ (node = dt_find_compatible_node(root, node, compat)) != NULL;) -struct pdbg_target *dt_find_compatible_node_on_chip(struct pdbg_target *root, - struct pdbg_target *prev, - const char *compat, - uint32_t chip_id); - -#define dt_for_each_compatible_on_chip(root, node, compat, chip_id) \ - for (node = NULL; \ - (node = dt_find_compatible_node_on_chip(root, node,\ - compat, chip_id)) != NULL;) -/* Check status property */ -bool dt_node_is_enabled(struct pdbg_target *node); - /* Build the full path for a node. Return a new block of memory, caller * shall free() it */ @@ -164,33 +102,18 @@ struct dt_property *dt_find_property(const struct pdbg_target *node,\ const struct dt_property *dt_require_property(const struct pdbg_target *node, const char *name, int wanted_len); -/* non-const variant */ -struct dt_property *__dt_find_property(struct pdbg_target *node, const char *name); - -/* Find a property by name, check if it's the same as val. */ -bool dt_has_node_property(const struct pdbg_target *node, - const char *name, const char *val); - -/* Free a node (and any children). */ -void dt_free(struct pdbg_target *node); - /* Parse an initial fdt */ void dt_expand(const void *fdt); int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) __warn_unused_result; /* Simplified accessors */ -u64 dt_prop_get_u64(const struct pdbg_target *node, const char *prop); -u64 dt_prop_get_u64_def(const struct pdbg_target *node, const char *prop, u64 def); u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop); u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def); u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index); 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); -const void *dt_prop_get_def_size(const struct pdbg_target *node, const char *prop, - void *def, size_t *len); u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell); -u32 dt_prop_get_cell_def(const struct pdbg_target *node, const char *prop, u32 cell, u32 def); /* Parsing helpers */ u32 dt_n_address_cells(const struct pdbg_target *node); @@ -208,18 +131,6 @@ u32 dt_get_chip_id(const struct pdbg_target *node); u64 dt_get_address(const struct pdbg_target *node, unsigned int index, u64 *out_size); -/* Count "reg" property entries */ -unsigned int dt_count_addresses(const struct pdbg_target *node); - -/* Address translation - * - * WARNING: Current implementation is simplified and will not - * handle complex address formats with address space indicators - * nor will it handle "ranges" translations yet... (XX TODO) - */ -u64 dt_translate_address(const struct pdbg_target *node, unsigned int index, - u64 *out_size); - /* compare function used to sort child nodes by name when added to the * tree. This is mainly here for testing. */ diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 106cb58..8ebafcd 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -184,21 +184,6 @@ uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size) return dt_get_address(target, 0, size); } -/* Difference from below is that it doesn't search up the tree for the given - * property. As nothing uses this yet we don't export it for use, but we may in - * future */ -static int pdbg_get_target_u64_property(struct pdbg_target *target, const char *name, uint64_t *val) -{ - struct dt_property *p; - - p = dt_find_property(target, name); - if (!p) - return -1; - - *val = dt_get_number(p->prop, 2); - return 0; -} - int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val) { struct dt_property *p; @@ -211,18 +196,6 @@ int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, u return 0; } -int pdbg_get_u64_property(struct pdbg_target *target, const char *name, uint64_t *val) -{ - struct pdbg_target *dn; - - for (dn = target; dn; dn = dn->parent) { - if (!pdbg_get_target_u64_property(dn, name, val)) - return 0; - } - - return -1; -} - void pdbg_progress_tick(uint64_t cur, uint64_t end) { if (progress_tick) diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index fded62c..a86265a 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -73,7 +73,6 @@ void pdbg_set_target_property(struct pdbg_target *target, const char *name, cons /* Get the given property and return the size */ void *pdbg_get_target_property(struct pdbg_target *target, const char *name, size_t *size); int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val); -int pdbg_get_u64_property(struct pdbg_target *target, const char *name, uint64_t *val); uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size); /* Misc. */ From patchwork Thu Oct 25 06:21:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gcTn4zVcz9sBZ for ; Thu, 25 Oct 2018 17:21:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42gcTn3HSdzDrhl for ; Thu, 25 Oct 2018 17:21:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42gcTX0PDLzDrPt for ; Thu, 25 Oct 2018 17:21:36 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42gcTW5GSrz9sBZ; Thu, 25 Oct 2018 17:21:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Thu, 25 Oct 2018 17:21:23 +1100 Message-Id: <20181025062131.18873-3-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181025062131.18873-1-alistair@popple.id.au> References: <20181025062131.18873-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 02/10] libpdbg: Make more declarations static X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Many of the functions in device.c are only used within that file and should be made static. Signed-off-by: Alistair Popple --- libpdbg/device.c | 56 ++++++++++++++++++++++++++++++++++++++----------------- libpdbg/device.h | 51 -------------------------------------------------- libpdbg/libpdbg.c | 13 ------------- libpdbg/target.c | 6 ------ 4 files changed, 39 insertions(+), 87 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index cdb3481..10d3e96 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -30,8 +30,11 @@ #define prerror printf #define is_rodata(p) false +#define dt_for_each_child(parent, node) \ + list_for_each(&parent->children, node, list) + /* Used to give unique handles. */ -u32 last_phandle = 0; +static u32 last_phandle = 0; struct pdbg_target *dt_root; @@ -50,7 +53,7 @@ static void free_name(const char *name) free((char *)name); } -struct pdbg_target *dt_new_node(const char *name, const void *fdt, int node_offset) +static struct pdbg_target *dt_new_node(const char *name, const void *fdt, int node_offset) { struct hw_unit_info *hw_info = NULL; const struct fdt_property *prop; @@ -117,7 +120,7 @@ static const char *get_unitname(const struct pdbg_target *node) return c + 1; } -int dt_cmp_subnodes(const struct pdbg_target *a, const struct pdbg_target *b) +static int dt_cmp_subnodes(const struct pdbg_target *a, const struct pdbg_target *b) { const char *a_unit = get_unitname(a); const char *b_unit = get_unitname(b); @@ -140,7 +143,7 @@ int dt_cmp_subnodes(const struct pdbg_target *a, const struct pdbg_target *b) return strcmp(a->dn_name, b->dn_name); } -bool dt_attach_root(struct pdbg_target *parent, struct pdbg_target *root) +static bool dt_attach_root(struct pdbg_target *parent, struct pdbg_target *root) { struct pdbg_target *node; @@ -184,7 +187,7 @@ static inline void dt_destroy(struct pdbg_target *dn) free(dn); } -char *dt_get_path(const struct pdbg_target *node) +static char *dt_get_path(const struct pdbg_target *node) { unsigned int len = 0; const struct pdbg_target *n; @@ -246,7 +249,7 @@ static const char *__dt_path_split(const char *p, return sl; } -struct pdbg_target *dt_find_by_path(struct pdbg_target *root, const char *path) +static struct pdbg_target *dt_find_by_path(struct pdbg_target *root, const char *path) { struct pdbg_target *n; const char *pn, *pa = NULL, *p = path, *nn = NULL, *na = NULL; @@ -346,7 +349,7 @@ void dt_resize_property(struct dt_property **prop, size_t len) (*prop)->list.prev->next = &(*prop)->list; } -u32 dt_property_get_cell(const struct dt_property *prop, u32 index) +static u32 dt_property_get_cell(const struct dt_property *prop, u32 index) { assert(prop->len >= (index+1)*sizeof(u32)); /* Always aligned, so this works. */ @@ -354,13 +357,13 @@ u32 dt_property_get_cell(const struct dt_property *prop, u32 index) } /* First child of this node. */ -struct pdbg_target *dt_first(const struct pdbg_target *root) +static struct pdbg_target *dt_first(const struct pdbg_target *root) { return list_top(&root->children, struct pdbg_target, list); } /* Return next node, or NULL. */ -struct pdbg_target *dt_next(const struct pdbg_target *root, +static struct pdbg_target *dt_next(const struct pdbg_target *root, const struct pdbg_target *prev) { /* Children? */ @@ -390,8 +393,8 @@ struct dt_property *dt_find_property(const struct pdbg_target *node, return NULL; } -const struct dt_property *dt_require_property(const struct pdbg_target *node, - const char *name, int wanted_len) +static const struct dt_property *dt_require_property(const struct pdbg_target *node, + const char *name, int wanted_len) { const struct dt_property *p = dt_find_property(node, name); @@ -459,7 +462,7 @@ u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop) return dt_property_get_cell(p, 0); } -u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) +static u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) { const struct dt_property *p = dt_find_property(node, prop); @@ -498,7 +501,7 @@ u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell) return dt_property_get_cell(p, cell); } -enum pdbg_target_status str_to_status(const char *status) +static enum pdbg_target_status str_to_status(const char *status) { if (!strcmp(status, "enabled")) { /* There isn't really a use case for this at the moment except @@ -520,7 +523,7 @@ enum pdbg_target_status str_to_status(const char *status) assert(0); } -int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) +static int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) { const struct fdt_property *prop; int offset, nextoffset, err; @@ -577,7 +580,7 @@ int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) return nextoffset; } -void dt_expand(const void *fdt) +static void dt_expand(const void *fdt) { PR_DEBUG("FDT: Parsing fdt @%p\n", fdt); @@ -595,14 +598,14 @@ u64 dt_get_number(const void *pdata, unsigned int cells) return ret; } -u32 dt_n_address_cells(const struct pdbg_target *node) +static u32 dt_n_address_cells(const struct pdbg_target *node) { if (!node->parent) return 0; return dt_prop_get_u32_def(node->parent, "#address-cells", 2); } -u32 dt_n_size_cells(const struct pdbg_target *node) +static u32 dt_n_size_cells(const struct pdbg_target *node) { if (!node->parent) return 0; @@ -644,3 +647,22 @@ u32 dt_get_chip_id(const struct pdbg_target *node) assert(id != 0xffffffff); return id; } + +void pdbg_targets_init(void *fdt) +{ + dt_root = dt_new_node("", NULL, 0); + dt_expand(fdt); +} + +char *pdbg_target_path(const struct pdbg_target *target) +{ + return dt_get_path(target); +} + +struct pdbg_target *pdbg_target_find_by_path(struct pdbg_target *target, const char *path) +{ + if (!target) + target = dt_root; + + return dt_find_by_path(target, path); +} diff --git a/libpdbg/device.h b/libpdbg/device.h index 5786d99..098f7f4 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -38,19 +38,8 @@ struct dt_property { char prop[/* len */]; }; -/* This is shared with device_tree.c .. make it static when - * the latter is gone (hopefully soon) - */ -extern u32 last_phandle; - extern struct pdbg_target *dt_root; -/* Create a new node. */ -struct pdbg_target *dt_new_node(const char *name, const void *fdt, int offset); - -/* Graft a root node into this tree. */ -bool dt_attach_root(struct pdbg_target *parent, struct pdbg_target *root); - /* Add a property node, various forms. */ struct dt_property *dt_add_property(struct pdbg_target *node, const char *name, @@ -59,20 +48,6 @@ struct dt_property *dt_add_property(struct pdbg_target *node, /* Warning: moves *prop! */ void dt_resize_property(struct dt_property **prop, size_t len); -u32 dt_property_get_cell(const struct dt_property *prop, u32 index); - -/* First child of this node. */ -struct pdbg_target *dt_first(const struct pdbg_target *root); - -/* Return next node, or NULL. */ -struct pdbg_target *dt_next(const struct pdbg_target *root, const struct pdbg_target *prev); - -#define dt_for_each_child(parent, node) \ - list_for_each(&parent->children, node, list) - -/* Find a string in a string list */ -bool dt_prop_find_string(const struct dt_property *p, const char *s); - /* Check a compatible property */ bool dt_node_is_compatible(const struct pdbg_target *node, const char *compat); @@ -85,39 +60,18 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, for (node = NULL; \ (node = dt_find_compatible_node(root, node, compat)) != NULL;) -/* Build the full path for a node. Return a new block of memory, caller - * shall free() it - */ -char *dt_get_path(const struct pdbg_target *node); - -/* Find a node by path */ -struct pdbg_target *dt_find_by_path(struct pdbg_target *root, const char *path); - -/* Find a child node by name */ -struct pdbg_target *dt_find_by_name(struct pdbg_target *root, const char *name); - /* Find a property by name. */ struct dt_property *dt_find_property(const struct pdbg_target *node,\ const char *name); -const struct dt_property *dt_require_property(const struct pdbg_target *node, - const char *name, int wanted_len); - -/* Parse an initial fdt */ -void dt_expand(const void *fdt); -int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) __warn_unused_result; /* Simplified accessors */ u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop); -u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def); u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index); 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); -u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell); /* Parsing helpers */ -u32 dt_n_address_cells(const struct pdbg_target *node); -u32 dt_n_size_cells(const struct pdbg_target *node); u64 dt_get_number(const void *pdata, unsigned int cells); /* Find an chip-id property in this node; if not found, walk up the parent @@ -131,9 +85,4 @@ u32 dt_get_chip_id(const struct pdbg_target *node); u64 dt_get_address(const struct pdbg_target *node, unsigned int index, u64 *out_size); -/* compare function used to sort child nodes by name when added to the - * tree. This is mainly here for testing. - */ -int dt_cmp_subnodes(const struct pdbg_target *a, const struct pdbg_target *b); - #endif /* __DEVICE_H */ diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 8ebafcd..8aa22e1 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -135,19 +135,6 @@ const char *pdbg_target_dn_name(struct pdbg_target *target) return target->dn_name; } -char *pdbg_target_path(const struct pdbg_target *target) -{ - return dt_get_path(target); -} - -struct pdbg_target *pdbg_target_find_by_path(struct pdbg_target *target, const char *path) -{ - if (!target) - target = dt_root; - - return dt_find_by_path(target, path); -} - void pdbg_set_target_property(struct pdbg_target *target, const char *name, const void *val, size_t size) { struct dt_property *p; diff --git a/libpdbg/target.c b/libpdbg/target.c index 8e8c381..1b6b05c 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -288,12 +288,6 @@ struct hw_unit_info *find_compatible_target(const char *compat) return NULL; } -void pdbg_targets_init(void *fdt) -{ - dt_root = dt_new_node("", NULL, 0); - dt_expand(fdt); -} - /* We walk the tree root down disabling targets which might/should * exist but don't */ enum pdbg_target_status pdbg_target_probe(struct pdbg_target *target) From patchwork Thu Oct 25 06:21:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gcTs3r9Kz9sMM for ; Thu, 25 Oct 2018 17:21:53 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42gcTs23jHzDrYZ for ; Thu, 25 Oct 2018 17:21:53 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42gcTX2RmszDrS4 for ; Thu, 25 Oct 2018 17:21:36 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42gcTX0KFcz9sBh; Thu, 25 Oct 2018 17:21:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Thu, 25 Oct 2018 17:21:24 +1100 Message-Id: <20181025062131.18873-4-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181025062131.18873-1-alistair@popple.id.au> References: <20181025062131.18873-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 03/10] libpdbg: Move property code into libpdbg/device.c X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Alistair Popple --- libpdbg/device.c | 72 +++++++++++++++++++++++++++++++++++++++++++++---------- libpdbg/device.h | 30 ----------------------- libpdbg/libpdbg.c | 46 +++++++---------------------------- 3 files changed, 68 insertions(+), 80 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 10d3e96..51ae028 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -38,6 +38,21 @@ static u32 last_phandle = 0; struct pdbg_target *dt_root; +/* + * An in-memory representation of a node in the device tree. + * + * This is trivially flattened into an fdt. + * + * Note that the add_* routines will make a copy of the name if it's not + * a read-only string (ie. usually a string literal). + */ +struct dt_property { + struct list_node list; + const char *name; + size_t len; + char prop[/* len */]; +}; + static const char *take_name(const char *name) { if (!is_rodata(name) && !(name = strdup(name))) { @@ -285,6 +300,17 @@ static struct pdbg_target *dt_find_by_path(struct pdbg_target *root, const char return root; } +static struct dt_property *dt_find_property(const struct pdbg_target *node, + const char *name) +{ + struct dt_property *i; + + list_for_each(&node->properties, i, list) + if (strcmp(i->name, name) == 0) + return i; + return NULL; +} + static struct dt_property *new_property(struct pdbg_target *node, const char *name, size_t size) { @@ -313,7 +339,7 @@ static struct dt_property *new_property(struct pdbg_target *node, return p; } -struct dt_property *dt_add_property(struct pdbg_target *node, +static struct dt_property *dt_add_property(struct pdbg_target *node, const char *name, const void *val, size_t size) { @@ -338,7 +364,7 @@ struct dt_property *dt_add_property(struct pdbg_target *node, return p; } -void dt_resize_property(struct dt_property **prop, size_t len) +static void dt_resize_property(struct dt_property **prop, size_t len) { size_t new_len = sizeof(**prop) + len; @@ -349,6 +375,37 @@ void dt_resize_property(struct dt_property **prop, size_t len) (*prop)->list.prev->next = &(*prop)->list; } +void pdbg_set_target_property(struct pdbg_target *target, const char *name, const void *val, size_t size) +{ + struct dt_property *p; + + if ((p = dt_find_property(target, name))) { + if (size > p->len) { + dt_resize_property(&p, size); + p->len = size; + } + + memcpy(p->prop, val, size); + } else { + dt_add_property(target, name, val, size); + } +} + +void *pdbg_get_target_property(struct pdbg_target *target, const char *name, size_t *size) +{ + struct dt_property *p; + + p = dt_find_property(target, name); + if (p) { + if (size) + *size = p->len; + return p->prop; + } else if (size) + *size = 0; + + return NULL; +} + static u32 dt_property_get_cell(const struct dt_property *prop, u32 index) { assert(prop->len >= (index+1)*sizeof(u32)); @@ -382,17 +439,6 @@ static struct pdbg_target *dt_next(const struct pdbg_target *root, return NULL; } -struct dt_property *dt_find_property(const struct pdbg_target *node, - const char *name) -{ - struct dt_property *i; - - list_for_each(&node->properties, i, list) - if (strcmp(i->name, name) == 0) - return i; - return NULL; -} - static const struct dt_property *dt_require_property(const struct pdbg_target *node, const char *name, int wanted_len) { diff --git a/libpdbg/device.h b/libpdbg/device.h index 098f7f4..f487443 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -23,31 +23,8 @@ /* Any property or node with this prefix will not be passed to the kernel. */ #define DT_PRIVATE "skiboot," -/* - * An in-memory representation of a node in the device tree. - * - * This is trivially flattened into an fdt. - * - * Note that the add_* routines will make a copy of the name if it's not - * a read-only string (ie. usually a string literal). - */ -struct dt_property { - struct list_node list; - const char *name; - size_t len; - char prop[/* len */]; -}; - extern struct pdbg_target *dt_root; -/* Add a property node, various forms. */ -struct dt_property *dt_add_property(struct pdbg_target *node, - const char *name, - const void *val, size_t size); - -/* Warning: moves *prop! */ -void dt_resize_property(struct dt_property **prop, size_t len); - /* Check a compatible property */ bool dt_node_is_compatible(const struct pdbg_target *node, const char *compat); @@ -60,10 +37,6 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, for (node = NULL; \ (node = dt_find_compatible_node(root, node, compat)) != NULL;) -/* Find a property by name. */ -struct dt_property *dt_find_property(const struct pdbg_target *node,\ - const char *name); - /* Simplified accessors */ u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop); u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index); @@ -71,9 +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); -/* Parsing helpers */ -u64 dt_get_number(const void *pdata, unsigned int cells); - /* 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); diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 8aa22e1..3c96d3a 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -135,37 +135,6 @@ const char *pdbg_target_dn_name(struct pdbg_target *target) return target->dn_name; } -void pdbg_set_target_property(struct pdbg_target *target, const char *name, const void *val, size_t size) -{ - struct dt_property *p; - - if ((p = dt_find_property(target, name))) { - if (size > p->len) { - dt_resize_property(&p, size); - p->len = size; - } - - memcpy(p->prop, val, size); - } else { - dt_add_property(target, name, val, size); - } -} - -void *pdbg_get_target_property(struct pdbg_target *target, const char *name, size_t *size) -{ - struct dt_property *p; - - p = dt_find_property(target, name); - if (p) { - if (size) - *size = p->len; - return p->prop; - } else if (size) - *size = 0; - - return NULL; -} - uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size) { return dt_get_address(target, 0, size); @@ -173,14 +142,17 @@ uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size) int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val) { - struct dt_property *p; + uint32_t *p; + size_t size; - p = dt_find_property(target, name); - if (!p) - return -1; + p = pdbg_get_target_property(target, name, &size); + if (!p) + return -1; + + assert(size == 4); + *val = be32toh(*p); - *val = dt_get_number(p->prop, 1); - return 0; + return 0; } void pdbg_progress_tick(uint64_t cur, uint64_t end) From patchwork Thu Oct 25 06:21:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988913 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gcTw1ylmz9sBh for ; Thu, 25 Oct 2018 17:21:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42gcTw0Gx3zDrTk for ; Thu, 25 Oct 2018 17:21:56 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42gcTX56ktzDrPt for ; Thu, 25 Oct 2018 17:21:36 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42gcTX2Pjnz9sBk; Thu, 25 Oct 2018 17:21:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Thu, 25 Oct 2018 17:21:25 +1100 Message-Id: <20181025062131.18873-5-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181025062131.18873-1-alistair@popple.id.au> References: <20181025062131.18873-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 04/10] libpdbg: Rename property functions X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Some of the functions dealing with target properties have somewhat inconsistent naming. This patch renames them and adds #defines for backwards compatibility for external projects. These will be removed once older projects have moved over to the new names. Signed-off-by: Alistair Popple --- libpdbg/device.c | 6 +++--- libpdbg/libpdbg.c | 4 ++-- libpdbg/libpdbg.h | 13 ++++++++++--- libpdbg/xbus.c | 2 +- src/main.c | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 51ae028..2128fa7 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -375,7 +375,7 @@ static void dt_resize_property(struct dt_property **prop, size_t len) (*prop)->list.prev->next = &(*prop)->list; } -void pdbg_set_target_property(struct pdbg_target *target, const char *name, const void *val, size_t size) +void pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size) { struct dt_property *p; @@ -391,7 +391,7 @@ void pdbg_set_target_property(struct pdbg_target *target, const char *name, cons } } -void *pdbg_get_target_property(struct pdbg_target *target, const char *name, size_t *size) +void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size) { struct dt_property *p; @@ -634,7 +634,7 @@ static void dt_expand(const void *fdt) abort(); } -u64 dt_get_number(const void *pdata, unsigned int cells) +static u64 dt_get_number(const void *pdata, unsigned int cells) { const u32 *p = pdata; u64 ret = 0; diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 3c96d3a..edf303c 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -140,12 +140,12 @@ uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size) return dt_get_address(target, 0, size); } -int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val) +int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val) { uint32_t *p; size_t size; - p = pdbg_get_target_property(target, name, &size); + p = pdbg_target_property(target, name, &size); if (!p) return -1; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index a86265a..78930e9 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -68,13 +68,20 @@ struct pdbg_target *pdbg_target_parent(const char *klass, struct pdbg_target *ta struct pdbg_target *pdbg_target_require_parent(const char *klass, struct pdbg_target *target); /* Set the given property. Will automatically add one if one doesn't exist */ -void pdbg_set_target_property(struct pdbg_target *target, const char *name, const void *val, size_t size); +void pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size); /* Get the given property and return the size */ -void *pdbg_get_target_property(struct pdbg_target *target, const char *name, size_t *size); -int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val); +void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size); +int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val); uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size); +/* Old deprecated for names for the above. Do not use for new projects + * as these will be removed at some future point. */ +#define pdbg_set_target_property(target, name, val, size) \ + pdbg_target_set_property(target, name, val, size) +#define pdbg_get_target_property(target, name, size) \ + pdbg_target_property(target, name, size) + /* Misc. */ void pdbg_targets_init(void *fdt); void pdbg_target_probe_all(struct pdbg_target *parent); diff --git a/libpdbg/xbus.c b/libpdbg/xbus.c index 69489bb..661b9a3 100644 --- a/libpdbg/xbus.c +++ b/libpdbg/xbus.c @@ -41,7 +41,7 @@ static int xbus_probe(struct pdbg_target *target) { struct xbus *xbus = target_to_xbus(target); - if (pdbg_get_target_u32_property(&xbus->target, "ring-id", &xbus->ring_id)) { + if (pdbg_target_u32_property(&xbus->target, "ring-id", &xbus->ring_id)) { printf("Unknown ring-id on %s@%d\n", pdbg_target_name(&xbus->target), pdbg_target_index(&xbus->target)); return -1; diff --git a/src/main.c b/src/main.c index 4966d51..faa4868 100644 --- a/src/main.c +++ b/src/main.c @@ -675,7 +675,7 @@ static int target_selection(void) int proc_index = pdbg_target_index(pib); if (backend == I2C && device_node) - pdbg_set_target_property(pib, "bus", device_node, strlen(device_node) + 1); + pdbg_target_set_property(pib, "bus", device_node, strlen(device_node) + 1); if (processorsel[proc_index]) { target_select(pib); From patchwork Thu Oct 25 06:21:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988914 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gcTy6Hbtz9sBZ for ; Thu, 25 Oct 2018 17:21:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42gcTy3VS9zDrTy for ; Thu, 25 Oct 2018 17:21:58 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42gcTY0MbrzDrS4 for ; Thu, 25 Oct 2018 17:21:37 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42gcTX51vZz9sBh; Thu, 25 Oct 2018 17:21:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Thu, 25 Oct 2018 17:21:26 +1100 Message-Id: <20181025062131.18873-6-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181025062131.18873-1-alistair@popple.id.au> References: <20181025062131.18873-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 05/10] libpdbg: Rework chip-id functions X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" 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 --- 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 --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); From patchwork Thu Oct 25 06:21:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gcV22Lm8z9sBh for ; Thu, 25 Oct 2018 17:22:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42gcV20glbzDrSg for ; Thu, 25 Oct 2018 17:22:02 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42gcTY39SrzDrPt for ; Thu, 25 Oct 2018 17:21:37 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42gcTY0MRzz9sBZ; Thu, 25 Oct 2018 17:21:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Thu, 25 Oct 2018 17:21:27 +1100 Message-Id: <20181025062131.18873-7-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181025062131.18873-1-alistair@popple.id.au> References: <20181025062131.18873-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 06/10] libpdbg: Rework target addressing X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Clean up the target addressing functions and rename them to be consistent with other libpdbg function names. Signed-off-by: Alistair Popple --- libpdbg/cfam.c | 4 ++-- libpdbg/device.c | 11 +++++------ libpdbg/device.h | 7 ------- libpdbg/i2c.c | 2 +- libpdbg/libpdbg.c | 5 ----- libpdbg/libpdbg.h | 4 +++- libpdbg/p8chip.c | 4 ++-- libpdbg/p9chip.c | 2 +- libpdbg/target.c | 2 +- 9 files changed, 15 insertions(+), 26 deletions(-) diff --git a/libpdbg/cfam.c b/libpdbg/cfam.c index 1f0c938..67ab22e 100644 --- a/libpdbg/cfam.c +++ b/libpdbg/cfam.c @@ -295,7 +295,7 @@ 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); - addr += dt_get_address(&fsi->target, 0, NULL); + addr += pdbg_target_address(&fsi->target, NULL); return fsi_read(parent_fsi, addr, data); } @@ -304,7 +304,7 @@ 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); - addr += dt_get_address(&fsi->target, 0, NULL); + addr += pdbg_target_address(&fsi->target, NULL); return fsi_write(parent_fsi, addr, data); } diff --git a/libpdbg/device.c b/libpdbg/device.c index 2781b5b..c8ba037 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -658,17 +658,16 @@ static u32 dt_n_size_cells(const struct pdbg_target *node) return dt_prop_get_u32_def(node->parent, "#size-cells", 1); } -u64 dt_get_address(const struct pdbg_target *node, unsigned int index, - u64 *out_size) +uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *out_size) { const struct dt_property *p; - u32 na = dt_n_address_cells(node); - u32 ns = dt_n_size_cells(node); + u32 na = dt_n_address_cells(target); + u32 ns = dt_n_size_cells(target); u32 pos, n; - p = dt_require_property(node, "reg", -1); + p = dt_require_property(target, "reg", -1); n = (na + ns) * sizeof(u32); - pos = n * index; + pos = n; assert((pos + n) <= p->len); if (out_size) *out_size = dt_get_number(p->prop + pos + na * sizeof(u32), ns); diff --git a/libpdbg/device.h b/libpdbg/device.h index a050a23..29224a2 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -44,11 +44,4 @@ 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); -/* Address accessors ("reg" properties parsing). No translation, - * only support "simple" address forms (1 or 2 cells). Asserts - * if address doesn't exist - */ -u64 dt_get_address(const struct pdbg_target *node, unsigned int index, - u64 *out_size); - #endif /* __DEVICE_H */ diff --git a/libpdbg/i2c.c b/libpdbg/i2c.c index b1580e1..9cb6271 100644 --- a/libpdbg/i2c.c +++ b/libpdbg/i2c.c @@ -131,7 +131,7 @@ int i2c_target_probe(struct pdbg_target *target) int addr; bus = dt_prop_get_def(&pib->target, "bus", "/dev/i2c4"); - addr = dt_get_address(&pib->target, 0, NULL); + addr = pdbg_target_address(&pib->target, NULL); assert(addr); i2c_data = malloc(sizeof(*i2c_data)); diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 47fb486..07947cb 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -135,11 +135,6 @@ const char *pdbg_target_dn_name(struct pdbg_target *target) return target->dn_name; } -uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size) -{ - return dt_get_address(target, 0, size); -} - int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val) { uint32_t *p; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index b11e071..377f56e 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -73,7 +73,7 @@ void pdbg_target_set_property(struct pdbg_target *target, const char *name, cons /* Get the given property and return the size */ void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size); int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val); -uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size); +uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *size); /* Old deprecated for names for the above. Do not use for new projects * as these will be removed at some future point. */ @@ -81,6 +81,8 @@ uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size); pdbg_target_set_property(target, name, val, size) #define pdbg_get_target_property(target, name, size) \ pdbg_target_property(target, name, size) +#define pdbg_get_address(target, index, size) \ + (index == 0 ? pdbg_target_address(target, size) : assert(0)) /* Find an chip-id property in this node; if not found, walk up the parent * nodes. Returns -1 if no chip-id property exists. */ diff --git a/libpdbg/p8chip.c b/libpdbg/p8chip.c index f6df925..f3e71a0 100644 --- a/libpdbg/p8chip.c +++ b/libpdbg/p8chip.c @@ -155,7 +155,7 @@ static int assert_special_wakeup(struct core *chip) if (i++ > SPECIAL_WKUP_TIMEOUT) { PR_ERROR("Timeout waiting for special wakeup on %s@0x%08" PRIx64 "\n", chip->target.name, - dt_get_address(&chip->target, 0, NULL)); + pdbg_target_address(&chip->target, NULL)); return -1; } } while (!(gp0 & SPECIAL_WKUP_DONE)); @@ -479,7 +479,7 @@ static int p8_thread_probe(struct pdbg_target *target) { struct thread *thread = target_to_thread(target); - thread->id = (dt_get_address(target, 0, NULL) >> 4) & 0xf; + thread->id = (pdbg_target_address(target, NULL) >> 4) & 0xf; thread->status = get_thread_status(thread); return 0; diff --git a/libpdbg/p9chip.c b/libpdbg/p9chip.c index 6a2f434..2411103 100644 --- a/libpdbg/p9chip.c +++ b/libpdbg/p9chip.c @@ -527,7 +527,7 @@ static int p9_core_probe(struct pdbg_target *target) if (i++ > SPECIAL_WKUP_TIMEOUT) { PR_ERROR("Timeout waiting for special wakeup on %s@0x%08" PRIx64 "\n", target->name, - dt_get_address(target, 0, NULL)); + pdbg_target_address(target, NULL)); break; } } while (!(value & SPECIAL_WKUP_DONE)); diff --git a/libpdbg/target.c b/libpdbg/target.c index 1b6b05c..ba4d425 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -24,7 +24,7 @@ static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, con if (target->translate) *addr = target->translate(target, *addr); else - *addr += dt_get_address(target, 0, NULL); + *addr += pdbg_target_address(target, NULL); /* Keep walking the tree translating addresses */ target = target->parent; From patchwork Thu Oct 25 06:21:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gcV458Qfz9sBZ for ; Thu, 25 Oct 2018 17:22:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42gcV43Gz6zDrcP for ; Thu, 25 Oct 2018 17:22:04 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42gcTY5Hf3zDrS4 for ; Thu, 25 Oct 2018 17:21:37 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42gcTY2hbhz9sBk; Thu, 25 Oct 2018 17:21:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Thu, 25 Oct 2018 17:21:28 +1100 Message-Id: <20181025062131.18873-8-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181025062131.18873-1-alistair@popple.id.au> References: <20181025062131.18873-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 07/10] libpdbg: Remove old dt_prop functions X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" The dt_prop functions were copied over from Skiboot. Rework and rename these to make use of the existing libpdbg property functions. These should not have been used by external projects so maintaining backwards compatibility is not a concern. Signed-off-by: Alistair Popple --- libpdbg/bmcfsi.c | 37 ++++++++++++++++++++++++------------- libpdbg/cfam.c | 2 +- libpdbg/device.c | 38 +------------------------------------- libpdbg/device.h | 7 ------- libpdbg/i2c.c | 5 ++++- libpdbg/libpdbg.c | 16 ++++++++++++++++ libpdbg/libpdbg.h | 1 + libpdbg/p9chip.c | 4 +++- 8 files changed, 50 insertions(+), 60 deletions(-) diff --git a/libpdbg/bmcfsi.c b/libpdbg/bmcfsi.c index b57e029..a233106 100644 --- a/libpdbg/bmcfsi.c +++ b/libpdbg/bmcfsi.c @@ -42,7 +42,7 @@ * address offset */ struct gpio_pin { uint32_t offset; - int bit; + uint32_t bit; }; enum gpio { @@ -71,7 +71,7 @@ enum fsi_result { FSI_ERR_C = 0x3, }; -static int clock_delay = 0; +static uint32_t clock_delay = 0; #define FSI_DATA0_REG 0x1000 #define FSI_DATA1_REG 0x1001 @@ -459,17 +459,28 @@ int bmcfsi_probe(struct pdbg_target *target) } if (!gpio_reg) { - gpio_pins[GPIO_FSI_CLK].offset = dt_prop_get_u32_index(target, "fsi_clk", 0); - gpio_pins[GPIO_FSI_CLK].bit = dt_prop_get_u32_index(target, "fsi_clk", 1); - gpio_pins[GPIO_FSI_DAT].offset = dt_prop_get_u32_index(target, "fsi_dat", 0); - gpio_pins[GPIO_FSI_DAT].bit = dt_prop_get_u32_index(target, "fsi_dat", 1); - gpio_pins[GPIO_FSI_DAT_EN].offset = dt_prop_get_u32_index(target, "fsi_dat_en", 0); - gpio_pins[GPIO_FSI_DAT_EN].bit = dt_prop_get_u32_index(target, "fsi_dat_en", 1); - gpio_pins[GPIO_FSI_ENABLE].offset = dt_prop_get_u32_index(target, "fsi_enable", 0); - gpio_pins[GPIO_FSI_ENABLE].bit = dt_prop_get_u32_index(target, "fsi_enable", 1); - gpio_pins[GPIO_CRONUS_SEL].offset = dt_prop_get_u32_index(target, "cronus_sel", 0); - gpio_pins[GPIO_CRONUS_SEL].bit = dt_prop_get_u32_index(target, "cronus_sel", 1); - clock_delay = dt_prop_get_u32(target, "clock_delay"); + assert(!(pdbg_target_u32_index(target, "fsi_clk", 0, + &gpio_pins[GPIO_FSI_CLK].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_clk", 1, + &gpio_pins[GPIO_FSI_CLK].bit))); + assert(!(pdbg_target_u32_index(target, "fsi_dat", 0, + &gpio_pins[GPIO_FSI_DAT].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_dat", 1, + &gpio_pins[GPIO_FSI_DAT].bit))); + assert(!(pdbg_target_u32_index(target, "fsi_dat_en", 0, + &gpio_pins[GPIO_FSI_DAT_EN].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_dat_en", 1, + &gpio_pins[GPIO_FSI_DAT_EN].bit))); + assert(!(pdbg_target_u32_index(target, "fsi_enable", 0, + &gpio_pins[GPIO_FSI_ENABLE].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_enable", 1, + &gpio_pins[GPIO_FSI_ENABLE].bit))); + assert(!(pdbg_target_u32_index(target, "cronus_sel", 0, + &gpio_pins[GPIO_CRONUS_SEL].offset))); + assert(!(pdbg_target_u32_index(target, "cronus_sel", 1, + &gpio_pins[GPIO_CRONUS_SEL].bit))); + assert(!(pdbg_target_u32_property(target, "clock_delay", + &clock_delay))); /* We only have to do this init once per backend */ gpio_reg = mmap(NULL, getpagesize(), diff --git a/libpdbg/cfam.c b/libpdbg/cfam.c index 67ab22e..c9bdf3b 100644 --- a/libpdbg/cfam.c +++ b/libpdbg/cfam.c @@ -317,7 +317,7 @@ static int cfam_hmfsi_probe(struct pdbg_target *target) int rc; /* Enable the port in the upstream control register */ - port = dt_prop_get_u32(target, "port"); + assert(!(pdbg_target_u32_property(target, "port", &port))); fsi_read(fsi_parent, 0x3404, &value); value |= 1 << (31 - port); if ((rc = fsi_write(fsi_parent, 0x3404, value))) { diff --git a/libpdbg/device.c b/libpdbg/device.c index c8ba037..f8115d2 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -501,14 +501,7 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, return NULL; } -u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop) -{ - const struct dt_property *p = dt_require_property(node, prop, 4); - - return dt_property_get_cell(p, 0); -} - -static u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) +static uint32_t dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) { const struct dt_property *p = dt_find_property(node, prop); @@ -518,35 +511,6 @@ static u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, return dt_property_get_cell(p, 0); } -u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index) -{ - const struct dt_property *p = dt_require_property(node, prop, -1); - - return dt_property_get_cell(p, index); -} - -const void *dt_prop_get(const struct pdbg_target *node, const char *prop) -{ - const struct dt_property *p = dt_require_property(node, prop, -1); - - return p->prop; -} - -const void *dt_prop_get_def(const struct pdbg_target *node, const char *prop, - void *def) -{ - const struct dt_property *p = dt_find_property(node, prop); - - return p ? p->prop : def; -} - -u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell) -{ - const struct dt_property *p = dt_require_property(node, prop, -1); - - return dt_property_get_cell(p, cell); -} - static enum pdbg_target_status str_to_status(const char *status) { if (!strcmp(status, "enabled")) { diff --git a/libpdbg/device.h b/libpdbg/device.h index 29224a2..ac265e9 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -37,11 +37,4 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, for (node = NULL; \ (node = dt_find_compatible_node(root, node, compat)) != NULL;) -/* Simplified accessors */ -u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop); -u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index); -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); - #endif /* __DEVICE_H */ diff --git a/libpdbg/i2c.c b/libpdbg/i2c.c index 9cb6271..f1c6ea9 100644 --- a/libpdbg/i2c.c +++ b/libpdbg/i2c.c @@ -130,7 +130,10 @@ int i2c_target_probe(struct pdbg_target *target) const char *bus; int addr; - bus = dt_prop_get_def(&pib->target, "bus", "/dev/i2c4"); + bus = pdbg_target_property(&pib->target, "bus", NULL); + if (!bus) + bus = "/dev/i2c4"; + addr = pdbg_target_address(&pib->target, NULL); assert(addr); diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 07947cb..b59590d 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -150,6 +150,22 @@ int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint3 return 0; } +int pdbg_target_u32_index(struct pdbg_target *target, const char *name, int index, uint32_t *val) +{ + size_t len; + void *p; + + p = pdbg_get_target_property(target, name, &len); + if (!p) + return -1; + + assert(len >= (index+1)*sizeof(u32)); + + /* Always aligned, so this works. */ + *val = be32toh(((const u32 *)p)[index]); + return 0; +} + uint32_t pdbg_target_chip_id(struct pdbg_target *target) { uint32_t id; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 377f56e..d1720f4 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -73,6 +73,7 @@ void pdbg_target_set_property(struct pdbg_target *target, const char *name, cons /* Get the given property and return the size */ void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size); int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val); +int pdbg_target_u32_index(struct pdbg_target *target, const char *name, int index, uint32_t *val); uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *size); /* Old deprecated for names for the above. Do not use for new projects diff --git a/libpdbg/p9chip.c b/libpdbg/p9chip.c index 2411103..9d43725 100644 --- a/libpdbg/p9chip.c +++ b/libpdbg/p9chip.c @@ -118,8 +118,10 @@ static struct thread_state p9_get_thread_status(struct thread *thread) static int p9_thread_probe(struct pdbg_target *target) { struct thread *thread = target_to_thread(target); + uint32_t tid; - thread->id = dt_prop_get_u32(target, "tid"); + assert(!pdbg_target_u32_property(target, "tid", &tid)); + thread->id = tid; thread->status = p9_get_thread_status(thread); return 0; From patchwork Thu Oct 25 06:21:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gcV66n1dz9sBZ for ; Thu, 25 Oct 2018 17:22:06 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42gcV64xv3zDrp4 for ; Thu, 25 Oct 2018 17:22:06 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42gcTZ0qP0zDrPt for ; Thu, 25 Oct 2018 17:21:38 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42gcTY5J5tz9sMM; Thu, 25 Oct 2018 17:21:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Thu, 25 Oct 2018 17:21:29 +1100 Message-Id: <20181025062131.18873-9-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181025062131.18873-1-alistair@popple.id.au> References: <20181025062131.18873-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 08/10] libpdbg: Rework target compatible X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Rework the target compatible code to reuse existing libpdbg code where possible. Renames and exports these functions for use by external libraries. Signed-off-by: Alistair Popple --- libpdbg/device.c | 48 ++++++++++++++++++++++-------------------------- libpdbg/device.h | 12 ------------ libpdbg/htm.c | 8 ++++---- libpdbg/libpdbg.h | 8 ++++++++ libpdbg/p8chip.c | 2 +- 5 files changed, 35 insertions(+), 43 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index f8115d2..313b924 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -464,41 +464,37 @@ static const struct dt_property *dt_require_property(const struct pdbg_target *n return p; } -bool dt_prop_find_string(const struct dt_property *p, const char *s) +bool pdbg_target_compatible(struct pdbg_target *target, const char *compatible) { - const char *c, *end; + char *c, *end; + size_t len; - if (!p) - return false; - c = p->prop; - end = c + p->len; + c = pdbg_get_target_property(target, "compatible", &len); + if (!c) + return false; - while(c < end) { - if (!strcasecmp(s, c)) - return true; - c += strlen(c) + 1; - } - return false; -} + end = c + len; + while(c < end) { + if (!strcasecmp(compatible, c)) + return true; -bool dt_node_is_compatible(const struct pdbg_target *node, const char *compat) -{ - const struct dt_property *p = dt_find_property(node, "compatible"); + c += strlen(c) + 1; + } - return dt_prop_find_string(p, compat); + return false; } -struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, - struct pdbg_target *prev, - const char *compat) +struct pdbg_target *__pdbg_next_compatible_node(struct pdbg_target *root, + struct pdbg_target *prev, + const char *compat) { - struct pdbg_target *node; + struct pdbg_target *target; - node = prev ? dt_next(root, prev) : root; - for (; node; node = dt_next(root, node)) - if (dt_node_is_compatible(node, compat)) - return node; - return NULL; + target = prev ? dt_next(root, prev) : root; + for (; target; target = dt_next(root, target)) + if (pdbg_target_compatible(target, compat)) + return target; + return NULL; } static uint32_t dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) diff --git a/libpdbg/device.h b/libpdbg/device.h index ac265e9..92d7da3 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -25,16 +25,4 @@ extern struct pdbg_target *dt_root; -/* Check a compatible property */ -bool dt_node_is_compatible(const struct pdbg_target *node, const char *compat); - -/* Find a node based on compatible property */ -struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, - struct pdbg_target *prev, - const char *compat); - -#define dt_for_each_compatible(root, node, compat) \ - for (node = NULL; \ - (node = dt_find_compatible_node(root, node, compat)) != NULL;) - #endif /* __DEVICE_H */ diff --git a/libpdbg/htm.c b/libpdbg/htm.c index 1ea2c3a..5f9dd85 100644 --- a/libpdbg/htm.c +++ b/libpdbg/htm.c @@ -520,7 +520,7 @@ static int configure_nhtm(struct htm *htm, bool wrap) NHTM_TTYPE_SIZE_MASK ))) /* no pattern matching */ return -1; - if (dt_node_is_compatible(&htm->target, "ibm,power9-nhtm")) { + if (pdbg_target_compatible(&htm->target, "ibm,power9-nhtm")) { if (HTM_ERR(pib_read(&htm->target, NHTM_FLEX_MUX, &val))) return -1; @@ -740,7 +740,7 @@ static int htm_toggle_debug_bit(struct htm *htm) return 0; /* nhtm case */ /* FIXME: this is a hack for P8 */ - if (!dt_node_is_compatible(core, "ibm,power8-core")) { + if (!pdbg_target_compatible(core, "ibm,power8-core")) { PR_ERROR("HTM is POWER8 only currently\n"); return -1; } @@ -867,7 +867,7 @@ static int do_htm_status(struct htm *htm) uint64_t val, total; int i, regs = 9; - if (dt_node_is_compatible(&htm->target, "ibm,power9-nhtm")) + if (pdbg_target_compatible(&htm->target, "ibm,power9-nhtm")) regs++; PR_INFO("HTM register dump:\n"); @@ -1101,7 +1101,7 @@ static int nhtm_probe(struct pdbg_target *target) if (!is_debugfs_memtrace_ok() || !is_debugfs_scom_ok()) return -1; - if (dt_node_is_compatible(target, "ibm,power9-nhtm")) { + if (pdbg_target_compatible(target, "ibm,power9-nhtm")) { pib_read(target, NHTM_FLEX_MUX, &val); if (GETFIELD(NHTM_FLEX_MUX_MASK, val) != NHTM_FLEX_DEFAULT) { PR_DEBUG("FLEX_MUX not default\n"); diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index d1720f4..b825dc8 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -12,6 +12,9 @@ struct pdbg_target; struct pdbg_target_class; /* loops/iterators */ +struct pdbg_target *__pdbg_next_compatible_node(struct pdbg_target *root, + struct pdbg_target *prev, + const char *compat); struct pdbg_target *__pdbg_next_target(const char *klass, struct pdbg_target *parent, struct pdbg_target *last); struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct pdbg_target *last); @@ -45,6 +48,10 @@ enum pdbg_target_status {PDBG_TARGET_UNKNOWN = 0, PDBG_TARGET_ENABLED, PDBG_TARGET_DISABLED, PDBG_TARGET_MUSTEXIST, PDBG_TARGET_NONEXISTENT, PDBG_TARGET_RELEASED}; +#define pdbg_for_each_compatible(parent, target, compat) \ + for (target = NULL; \ + (target = __pdbg_next_compatible_node(parent, target, compat)) != NULL;) + #define pdbg_for_each_target(class, parent, target) \ for (target = __pdbg_next_target(class, parent, NULL); \ target; \ @@ -107,6 +114,7 @@ void *pdbg_target_priv(struct pdbg_target *target); void pdbg_target_priv_set(struct pdbg_target *target, void *priv); struct pdbg_target *pdbg_target_root(void); struct pdbg_target *pdbg_class_target_addr(struct pdbg_target *target, const char *name, uint64_t *addr); +bool pdbg_target_compatible(struct pdbg_target *target, const char *compatible); /* Procedures */ int fsi_read(struct pdbg_target *target, uint32_t addr, uint32_t *val); diff --git a/libpdbg/p8chip.c b/libpdbg/p8chip.c index f3e71a0..914c335 100644 --- a/libpdbg/p8chip.c +++ b/libpdbg/p8chip.c @@ -355,7 +355,7 @@ static int p8_ram_setup(struct thread *thread) /* We can only ram a thread if all the threads on the core/chip are * quiesced */ - dt_for_each_compatible(&chip->target, target, "ibm,power8-thread") { + pdbg_for_each_compatible(&chip->target, target, "ibm,power8-thread") { struct thread *tmp; /* If this thread wasn't enabled it may not yet have been probed From patchwork Thu Oct 25 06:21:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gcV91Bflz9sBZ for ; Thu, 25 Oct 2018 17:22:09 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42gcV86TZSzDrSg for ; Thu, 25 Oct 2018 17:22:08 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42gcTZ2cfPzDrS4 for ; Thu, 25 Oct 2018 17:21:38 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42gcTZ0qcVz9sBZ; Thu, 25 Oct 2018 17:21:38 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Thu, 25 Oct 2018 17:21:30 +1100 Message-Id: <20181025062131.18873-10-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181025062131.18873-1-alistair@popple.id.au> References: <20181025062131.18873-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 09/10] libpdbg: Make dt_root private X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Alistair Popple --- libpdbg/device.c | 13 +++++++++---- libpdbg/device.h | 2 -- libpdbg/target.c | 9 ++------- src/main.c | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 313b924..11afa11 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -36,7 +36,7 @@ /* Used to give unique handles. */ static u32 last_phandle = 0; -struct pdbg_target *dt_root; +static struct pdbg_target *pdbg_dt_root; /* * An in-memory representation of a node in the device tree. @@ -590,7 +590,7 @@ static void dt_expand(const void *fdt) { PR_DEBUG("FDT: Parsing fdt @%p\n", fdt); - if (dt_expand_node(dt_root, fdt, 0) < 0) + if (dt_expand_node(pdbg_dt_root, fdt, 0) < 0) abort(); } @@ -636,7 +636,7 @@ uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *out_size) void pdbg_targets_init(void *fdt) { - dt_root = dt_new_node("", NULL, 0); + pdbg_dt_root = dt_new_node("", NULL, 0); dt_expand(fdt); } @@ -648,7 +648,12 @@ char *pdbg_target_path(const struct pdbg_target *target) struct pdbg_target *pdbg_target_find_by_path(struct pdbg_target *target, const char *path) { if (!target) - target = dt_root; + target = pdbg_dt_root; return dt_find_by_path(target, path); } + +struct pdbg_target *pdbg_target_root(void) +{ + return pdbg_dt_root; +} diff --git a/libpdbg/device.h b/libpdbg/device.h index 92d7da3..4a4a06f 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -23,6 +23,4 @@ /* Any property or node with this prefix will not be passed to the kernel. */ #define DT_PRIVATE "skiboot," -extern struct pdbg_target *dt_root; - #endif /* __DEVICE_H */ diff --git a/libpdbg/target.c b/libpdbg/target.c index ba4d425..744d289 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -31,7 +31,7 @@ static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, con /* The root node doesn't have an address space so it's * an error in the device tree if we hit this. */ - assert(target != dt_root); + assert(target != pdbg_target_root()); } return target; @@ -375,7 +375,7 @@ void pdbg_target_probe_all(struct pdbg_target *parent) struct pdbg_target *child; if (!parent) - parent = dt_root; + parent = pdbg_target_root(); pdbg_for_each_child_target(parent, child) { pdbg_target_probe_all(child); @@ -399,8 +399,3 @@ void pdbg_target_priv_set(struct pdbg_target *target, void *priv) { target->priv = priv; } - -struct pdbg_target *pdbg_target_root(void) -{ - return dt_root; -} diff --git a/src/main.c b/src/main.c index faa4868..39996d9 100644 --- a/src/main.c +++ b/src/main.c @@ -789,7 +789,7 @@ OPTCMD_DEFINE_CMD(probe, probe); */ static void atexit_release(void) { - pdbg_target_release(dt_root); + pdbg_target_release(pdbg_target_root()); } int main(int argc, char *argv[]) From patchwork Thu Oct 25 06:21:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gcVC1N3bz9sBh for ; Thu, 25 Oct 2018 17:22:11 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42gcVB6RZSzDrvF for ; Thu, 25 Oct 2018 17:22:10 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42gcTZ4LpNzDrPt for ; Thu, 25 Oct 2018 17:21:38 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42gcTZ2YvBz9sBh; Thu, 25 Oct 2018 17:21:38 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Thu, 25 Oct 2018 17:21:31 +1100 Message-Id: <20181025062131.18873-11-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181025062131.18873-1-alistair@popple.id.au> References: <20181025062131.18873-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 10/10] libpdbg: Remove device.h X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Alistair Popple --- Makefile.am | 1 - libpdbg/bmcfsi.c | 1 - libpdbg/device.c | 6 ++++-- libpdbg/device.h | 26 -------------------------- libpdbg/libpdbg.c | 1 - libpdbg/libpdbg.h | 2 ++ libpdbg/target.c | 1 - libpdbg/target.h | 1 - src/htm.c | 1 - 9 files changed, 6 insertions(+), 34 deletions(-) delete mode 100644 libpdbg/device.h diff --git a/Makefile.am b/Makefile.am index 4e5968f..61bee4d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -135,7 +135,6 @@ libpdbg_la_SOURCES = \ libpdbg/bitutils.h \ libpdbg/compiler.h \ libpdbg/debug.h \ - libpdbg/device.h \ libpdbg/operations.h \ libpdbg/libpdbg.h \ libpdbg/target.h diff --git a/libpdbg/bmcfsi.c b/libpdbg/bmcfsi.c index a233106..f9cee3d 100644 --- a/libpdbg/bmcfsi.c +++ b/libpdbg/bmcfsi.c @@ -27,7 +27,6 @@ #include "bitutils.h" #include "operations.h" -#include "device.h" #include "target.h" #include "debug.h" diff --git a/libpdbg/device.c b/libpdbg/device.c index 11afa11..b6710e9 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -14,17 +14,19 @@ * limitations under the License. */ -#include "device.h" #include #include #include #include "target.h" #include #include +#include +#include #include #include #include "debug.h" +#include "compiler.h" #define zalloc(size) calloc(1, size) #define prerror printf @@ -34,7 +36,7 @@ list_for_each(&parent->children, node, list) /* Used to give unique handles. */ -static u32 last_phandle = 0; +static uint32_t last_phandle = 0; static struct pdbg_target *pdbg_dt_root; diff --git a/libpdbg/device.h b/libpdbg/device.h deleted file mode 100644 index 4a4a06f..0000000 --- a/libpdbg/device.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2013-2014 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __DEVICE_H -#define __DEVICE_H -#include -#include -#include "compiler.h" - -/* Any property or node with this prefix will not be passed to the kernel. */ -#define DT_PRIVATE "skiboot," - -#endif /* __DEVICE_H */ diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index b59590d..13acaa8 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -1,7 +1,6 @@ #include #include "target.h" -#include "device.h" #include "libpdbg.h" static pdbg_progress_tick_t progress_tick; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index b825dc8..b42555b 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -8,6 +8,8 @@ #include +#include + struct pdbg_target; struct pdbg_target_class; diff --git a/libpdbg/target.c b/libpdbg/target.c index 744d289..b2ff877 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -7,7 +7,6 @@ #include "bitutils.h" #include "target.h" -#include "device.h" #include "operations.h" #include "debug.h" diff --git a/libpdbg/target.h b/libpdbg/target.h index 258c576..7cc855d 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -21,7 +21,6 @@ #include #include #include "compiler.h" -#include "device.h" #include "libpdbg.h" enum chip_type {CHIP_UNKNOWN, CHIP_P8, CHIP_P8NV, CHIP_P9}; diff --git a/src/htm.c b/src/htm.c index 8dd7303..10e35ae 100644 --- a/src/htm.c +++ b/src/htm.c @@ -34,7 +34,6 @@ #include #include -#include #include #include "main.h"