From patchwork Wed Nov 7 05:39:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994114 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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZz74Dryz9s8T for ; Wed, 7 Nov 2018 16:41:23 +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 42qZz7258GzF3FX for ; Wed, 7 Nov 2018 16:41:23 +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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxY5XsqzF3GW for ; Wed, 7 Nov 2018 16:40:01 +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 42qZxX5DJ1z9s8T; Wed, 7 Nov 2018 16:40:00 +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: Wed, 7 Nov 2018 16:39:35 +1100 Message-Id: <20181107053943.4307-9-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 08/16] 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 Reviewed-by: Amitay Isaacs --- 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..2f1a97b 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_from_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 7712e87..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_from_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 7468863..d8d699f 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -278,12 +278,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)