@@ -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);
+}
@@ -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 */
@@ -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;
@@ -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)
Many of the functions in device.c are only used within that file and should be made static. Signed-off-by: Alistair Popple <alistair@popple.id.au> --- libpdbg/device.c | 56 ++++++++++++++++++++++++++++++++++++++----------------- libpdbg/device.h | 51 -------------------------------------------------- libpdbg/libpdbg.c | 13 ------------- libpdbg/target.c | 6 ------ 4 files changed, 39 insertions(+), 87 deletions(-)