[2/2] libpdbg: Allow programs to register their own hardware units
diff mbox series

Message ID 20190903075934.3525-2-alistair@popple.id.au
State New
Headers show
Series
  • [1/2] libpdbg: Create struct pdbg_target_priv
Related show

Checks

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

Commit Message

Alistair Popple Sept. 3, 2019, 7:59 a.m. UTC
Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
 libpdbg/hwunit.c  |  3 ---
 libpdbg/hwunit.h  | 18 ------------------
 libpdbg/libpdbg.h | 35 ++++++++++++++++++++++++++++++++++-
 libpdbg/target.h  | 10 ----------
 4 files changed, 34 insertions(+), 32 deletions(-)

Comments

Amitay Isaacs Sept. 4, 2019, 3:41 a.m. UTC | #1
Hi Alistair,

This will require some modifications to pdbg_hwunit_register() to check
if there is a clash in the class names and may be even compatible
string.

Also, we can include the strucutre element check (done in
DELCARE_HW_UNIT) in the definition of pdbg_hwunit_register, by
converting that into a macro instead.

The following sequence though works:

   struct foobar {
   };

   DECLARE_HW_UNIT(foobar);
   pdbg_hwunit_register(foobar_hw_unit);

might be easier with:

  struct foobar {
  };

  pdbg_hwunit_register(struct foobar);

Amitay.

On Tue, 2019-09-03 at 17:59 +1000, Alistair Popple wrote:
> Signed-off-by: Alistair Popple <alistair@popple.id.au>
> ---
>  libpdbg/hwunit.c  |  3 ---
>  libpdbg/hwunit.h  | 18 ------------------
>  libpdbg/libpdbg.h | 35 ++++++++++++++++++++++++++++++++++-
>  libpdbg/target.h  | 10 ----------
>  4 files changed, 34 insertions(+), 32 deletions(-)
> 
> diff --git a/libpdbg/hwunit.c b/libpdbg/hwunit.c
> index 5c40d23..c7ec63d 100644
> --- a/libpdbg/hwunit.c
> +++ b/libpdbg/hwunit.c
> @@ -21,9 +21,6 @@
>  
>  #define MAX_HW_UNITS	1024
>  
> -struct pdbg_target pdbg_target_size;
> -uint8_t pdbg_target_size_test[sizeof(struct pdbg_target)];
> -
>  static const struct hw_unit_info *g_hw_unit[MAX_HW_UNITS];
>  static int g_hw_unit_count;
>  
> diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
> index a359af0..be88701 100644
> --- a/libpdbg/hwunit.h
> +++ b/libpdbg/hwunit.h
> @@ -26,26 +26,8 @@
>   * remove a bunch of tedious container_of() typing */
>  #define translate_cast(x) (uint64_t (*)(struct pdbg_target *,
> uint64_t)) (x)
>  
> -struct hw_unit_info {
> -	void *hw_unit;
> -	size_t size;
> -};
> -
> -void pdbg_hwunit_register(const struct hw_unit_info *hw_unit);
>  const struct hw_unit_info *pdbg_hwunit_find_compatible(const char
> *compat);
>  
> -/*
> - * If this macro fails to compile for you, you've probably not
> - * declared the struct pdbg_target as the first member of the
> - * container struct. Not doing so will break other assumptions.
> - */
> -#define DECLARE_HW_UNIT(name)					
> 	\
> -	__attribute__((unused)) static inline void name
> ##_hw_unit_check(void) {	\
> -		((void)sizeof(char[1 - 2 * (container_off(typeof(name),
> target) != 0)])); \
> -	}								\
> -	const struct hw_unit_info __used name ##_hw_unit
> =              \
> -	{ .hw_unit = &name, .size = sizeof(name) };
> -
>  struct htm {
>  	struct pdbg_target target;
>  	int (*start)(struct htm *);
> diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
> index e752681..534a803 100644
> --- a/libpdbg/libpdbg.h
> +++ b/libpdbg/libpdbg.h
> @@ -12,9 +12,42 @@
>  extern "C" {
>  #endif
>  
> -struct pdbg_target;
> +struct pdbg_target {
> +	char *name;
> +	char *compatible;
> +	char *class;
> +	int (*probe)(struct pdbg_target *target);
> +	void (*release)(struct pdbg_target *target);
> +	uint64_t (*translate)(struct pdbg_target *target, uint64_t
> addr);
> +	struct pdbg_target *parent;
> +	void *priv;
> +};
> +
>  struct pdbg_target_class;
>  
> +struct hw_unit_info {
> +	void *hw_unit;
> +	size_t size;
> +};
> +
> +/*
> + * If this macro fails to compile for you, you've probably not
> + * declared the struct pdbg_target as the first member of the
> + * container struct. Not doing so will break other assumptions.
> + */
> +#define DECLARE_HW_UNIT(name)					
> 	\
> +	__attribute__((unused)) static inline void name
> ##_hw_unit_check(void) {	\
> +		((void)sizeof(char[1 - 2 * (container_off(typeof(name),
> target) != 0)])); \
> +	}								\
> +	const struct hw_unit_info __used name ##_hw_unit
> =              \
> +	{ .hw_unit = &name, .size = sizeof(name) };
> +
> +/*
> + * Registers a hardware unit implementation. Must be called
> + * prior to pdbg_targets_init().
> + */
> +void pdbg_hwunit_register(const struct hw_unit_info *hw_unit);
> +
>  /* loops/iterators */
>  struct pdbg_target *__pdbg_next_compatible_node(struct pdbg_target
> *root,
>                                                  struct pdbg_target
> *prev,
> diff --git a/libpdbg/target.h b/libpdbg/target.h
> index ba2b20d..7d88d23 100644
> --- a/libpdbg/target.h
> +++ b/libpdbg/target.h
> @@ -32,16 +32,6 @@ struct pdbg_target_class {
>  	struct list_node class_head_link;
>  };
>  
> -struct pdbg_target {
> -	char *name;
> -	char *compatible;
> -	char *class;
> -	int (*probe)(struct pdbg_target *target);
> -	void (*release)(struct pdbg_target *target);
> -	uint64_t (*translate)(struct pdbg_target *target, uint64_t
> addr);
> -	struct pdbg_target *parent;
> -};
> -
>  struct pdbg_target_priv {
>  	int index;
>  	enum pdbg_target_status status;
> -- 
> 2.20.1
> 

Amitay.

Patch
diff mbox series

diff --git a/libpdbg/hwunit.c b/libpdbg/hwunit.c
index 5c40d23..c7ec63d 100644
--- a/libpdbg/hwunit.c
+++ b/libpdbg/hwunit.c
@@ -21,9 +21,6 @@ 
 
 #define MAX_HW_UNITS	1024
 
-struct pdbg_target pdbg_target_size;
-uint8_t pdbg_target_size_test[sizeof(struct pdbg_target)];
-
 static const struct hw_unit_info *g_hw_unit[MAX_HW_UNITS];
 static int g_hw_unit_count;
 
diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
index a359af0..be88701 100644
--- a/libpdbg/hwunit.h
+++ b/libpdbg/hwunit.h
@@ -26,26 +26,8 @@ 
  * remove a bunch of tedious container_of() typing */
 #define translate_cast(x) (uint64_t (*)(struct pdbg_target *, uint64_t)) (x)
 
-struct hw_unit_info {
-	void *hw_unit;
-	size_t size;
-};
-
-void pdbg_hwunit_register(const struct hw_unit_info *hw_unit);
 const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat);
 
-/*
- * If this macro fails to compile for you, you've probably not
- * declared the struct pdbg_target as the first member of the
- * container struct. Not doing so will break other assumptions.
- */
-#define DECLARE_HW_UNIT(name)						\
-	__attribute__((unused)) static inline void name ##_hw_unit_check(void) {	\
-		((void)sizeof(char[1 - 2 * (container_off(typeof(name), target) != 0)])); \
-	}								\
-	const struct hw_unit_info __used name ##_hw_unit =              \
-	{ .hw_unit = &name, .size = sizeof(name) };
-
 struct htm {
 	struct pdbg_target target;
 	int (*start)(struct htm *);
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index e752681..534a803 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -12,9 +12,42 @@ 
 extern "C" {
 #endif
 
-struct pdbg_target;
+struct pdbg_target {
+	char *name;
+	char *compatible;
+	char *class;
+	int (*probe)(struct pdbg_target *target);
+	void (*release)(struct pdbg_target *target);
+	uint64_t (*translate)(struct pdbg_target *target, uint64_t addr);
+	struct pdbg_target *parent;
+	void *priv;
+};
+
 struct pdbg_target_class;
 
+struct hw_unit_info {
+	void *hw_unit;
+	size_t size;
+};
+
+/*
+ * If this macro fails to compile for you, you've probably not
+ * declared the struct pdbg_target as the first member of the
+ * container struct. Not doing so will break other assumptions.
+ */
+#define DECLARE_HW_UNIT(name)						\
+	__attribute__((unused)) static inline void name ##_hw_unit_check(void) {	\
+		((void)sizeof(char[1 - 2 * (container_off(typeof(name), target) != 0)])); \
+	}								\
+	const struct hw_unit_info __used name ##_hw_unit =              \
+	{ .hw_unit = &name, .size = sizeof(name) };
+
+/*
+ * Registers a hardware unit implementation. Must be called
+ * prior to pdbg_targets_init().
+ */
+void pdbg_hwunit_register(const struct hw_unit_info *hw_unit);
+
 /* loops/iterators */
 struct pdbg_target *__pdbg_next_compatible_node(struct pdbg_target *root,
                                                 struct pdbg_target *prev,
diff --git a/libpdbg/target.h b/libpdbg/target.h
index ba2b20d..7d88d23 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -32,16 +32,6 @@  struct pdbg_target_class {
 	struct list_node class_head_link;
 };
 
-struct pdbg_target {
-	char *name;
-	char *compatible;
-	char *class;
-	int (*probe)(struct pdbg_target *target);
-	void (*release)(struct pdbg_target *target);
-	uint64_t (*translate)(struct pdbg_target *target, uint64_t addr);
-	struct pdbg_target *parent;
-};
-
 struct pdbg_target_priv {
 	int index;
 	enum pdbg_target_status status;