[Pdbg] [PATCH v2 12/16] libpdbg: Rework target addressing

Amitay Isaacs amitay at ozlabs.org
Wed Nov 7 17:39:36 AEDT 2018


Reviewed-by: Amitay Isaacs <amitay at ozlabs.org>

On Wed, 2018-11-07 at 16:39 +1100, Alistair Popple wrote:
> Clean up the target addressing functions and rename them to be
> consistent with other libpdbg function names.
> 
> Signed-off-by: Alistair Popple <alistair at popple.id.au>
> ---
>  libpdbg/cfam.c    |  4 ++--
>  libpdbg/device.c  | 11 +++++------
>  libpdbg/device.h  |  7 -------
>  libpdbg/i2c.c     |  2 +-
>  libpdbg/libpdbg.h |  4 +++-
>  libpdbg/p8chip.c  |  4 ++--
>  libpdbg/p9chip.c  |  2 +-
>  libpdbg/target.c  |  2 +-
>  8 files changed, 15 insertions(+), 21 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 a7212a6..5cd8302 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.h b/libpdbg/libpdbg.h
> index 4a21671..f8fe3e8 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 at 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 at 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 d8d699f..5599d78 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;
> -- 
> 2.11.0
> 

Amitay.
-- 

FAT is now known as the "Legacy" file system.



More information about the Pdbg mailing list