[Pdbg] [PATCH v3 07/16] libpdbg: Remove unused code

Alistair Popple alistair at popple.id.au
Thu Nov 8 12:10:54 AEDT 2018


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 <alistair at popple.id.au>
Reviewed-by: Amitay Isaacs <amitay at ozlabs.org>
---
 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 f77138a..7712e87 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 b11866a..959c2ef 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. */
-- 
2.11.0



More information about the Pdbg mailing list