diff mbox series

[RFC,04/12] libpdbg: Introduce a backend field

Message ID 20190806013723.4047-5-alistair@popple.id.au
State Superseded
Headers show
Series Split backends from system description | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (3a46123baa267a1bc6e03c50449a42e8d321bf86)
snowpatch_ozlabs/build-multiarch fail Test build-multiarch on branch master

Commit Message

Alistair Popple Aug. 6, 2019, 1:37 a.m. UTC
It is useful to be able to override a particular targets access
methods with methods specific to a specific runtime environment. This
patch introduces a field to every target which can be used for this
purpose without affecting the current behaviour.

Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
 libpdbg/target.c | 12 +++++++++---
 libpdbg/target.h |  1 +
 2 files changed, 10 insertions(+), 3 deletions(-)

Comments

Amitay Isaacs Aug. 20, 2019, 3:52 a.m. UTC | #1
As we discussed the new scheme for device trees, we do need a field (of
type struct pdbg_target) to tie the virtual node and the real node. 
But we can add that later with the virtual node patches.


On Tue, 2019-08-06 at 11:37 +1000, Alistair Popple wrote:
> It is useful to be able to override a particular targets access
> methods with methods specific to a specific runtime environment. This
> patch introduces a field to every target which can be used for this
> purpose without affecting the current behaviour.
> 
> Signed-off-by: Alistair Popple <alistair@popple.id.au>
> ---
>  libpdbg/target.c | 12 +++++++++---
>  libpdbg/target.h |  1 +
>  2 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/libpdbg/target.c b/libpdbg/target.c
> index 61353bc..e822d70 100644
> --- a/libpdbg/target.c
> +++ b/libpdbg/target.c
> @@ -14,8 +14,8 @@
>  struct list_head empty_list = LIST_HEAD_INIT(empty_list);
>  struct list_head target_classes = LIST_HEAD_INIT(target_classes);
>  
> -/* Work out the address to access based on the current target and
> - * final class name */
> +/* Work out the target and address to call call access methods on
> + * based on the current target and final class name */
>  static struct pdbg_target *get_class_target_addr(struct pdbg_target
> *target, const char *name, uint64_t *addr)
>  {
>  	/* Check class */
> @@ -34,7 +34,13 @@ static struct pdbg_target
> *get_class_target_addr(struct pdbg_target *target, con
>  		assert(target != pdbg_target_root());
>  	}
>  
> -	return target;
> +	if (target->backend) {
> +		/* The backend must implement the same interfaces */
> +		assert(!strcmp(target->class, target->backend->class));
> +		return target->backend;
> +	} else {
> +		return target;
> +	}
>  }
>  
>  struct pdbg_target *pdbg_address_absolute(struct pdbg_target
> *target, uint64_t *addr)
> diff --git a/libpdbg/target.h b/libpdbg/target.h
> index 9394447..2c76bf9 100644
> --- a/libpdbg/target.h
> +++ b/libpdbg/target.h
> @@ -46,6 +46,7 @@ struct pdbg_target {
>  	struct list_head properties;
>  	struct list_head children;
>  	struct pdbg_target *parent;
> +	struct pdbg_target *backend;
>  	u32 phandle;
>  	bool probed;
>  	struct list_node class_link;
> -- 
> 2.20.1
> 

Amitay.
diff mbox series

Patch

diff --git a/libpdbg/target.c b/libpdbg/target.c
index 61353bc..e822d70 100644
--- a/libpdbg/target.c
+++ b/libpdbg/target.c
@@ -14,8 +14,8 @@ 
 struct list_head empty_list = LIST_HEAD_INIT(empty_list);
 struct list_head target_classes = LIST_HEAD_INIT(target_classes);
 
-/* Work out the address to access based on the current target and
- * final class name */
+/* Work out the target and address to call call access methods on
+ * based on the current target and final class name */
 static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, const char *name, uint64_t *addr)
 {
 	/* Check class */
@@ -34,7 +34,13 @@  static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, con
 		assert(target != pdbg_target_root());
 	}
 
-	return target;
+	if (target->backend) {
+		/* The backend must implement the same interfaces */
+		assert(!strcmp(target->class, target->backend->class));
+		return target->backend;
+	} else {
+		return target;
+	}
 }
 
 struct pdbg_target *pdbg_address_absolute(struct pdbg_target *target, uint64_t *addr)
diff --git a/libpdbg/target.h b/libpdbg/target.h
index 9394447..2c76bf9 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -46,6 +46,7 @@  struct pdbg_target {
 	struct list_head properties;
 	struct list_head children;
 	struct pdbg_target *parent;
+	struct pdbg_target *backend;
 	u32 phandle;
 	bool probed;
 	struct list_node class_link;