diff options
| author | Alistair Popple <alistair@popple.id.au> | 2018-10-25 14:54:48 +1100 |
|---|---|---|
| committer | Alistair Popple <alistair@popple.id.au> | 2018-11-09 11:22:36 +1100 |
| commit | 02c9c3f0d853e8f694e35a373a133d596bb7a74a (patch) | |
| tree | d2d52f6f9110d7cbf7304b61e53b337a0da7ed00 /libpdbg | |
| parent | e81a9f73ce720b783613cef56a84b17796612ce3 (diff) | |
| download | pdbg-02c9c3f0d853e8f694e35a373a133d596bb7a74a.tar.gz pdbg-02c9c3f0d853e8f694e35a373a133d596bb7a74a.zip | |
libpdbg: Move property code into libpdbg/device.c
Signed-off-by: Alistair Popple <alistair@popple.id.au>
Reviewed-by: Amitay Isaacs <amitay@ozlabs.org>
Diffstat (limited to 'libpdbg')
| -rw-r--r-- | libpdbg/device.c | 72 | ||||
| -rw-r--r-- | libpdbg/device.h | 30 | ||||
| -rw-r--r-- | libpdbg/libpdbg.c | 45 |
3 files changed, 65 insertions, 82 deletions
diff --git a/libpdbg/device.c b/libpdbg/device.c index 2f1a97b..af2973b 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..415dc9f 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -135,51 +135,18 @@ 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); -} - 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); + p = pdbg_get_target_property(target, name, &size); if (!p) return -1; - *val = dt_get_number(p->prop, 1); + assert(size == 4); + *val = be32toh(*p); + return 0; } |

