From patchwork Tue Sep 3 07:59:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 1156860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46Mzrn3njSz9sBF for ; Tue, 3 Sep 2019 18:00:09 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46Mzrn1RQXzDqgH for ; Tue, 3 Sep 2019 18:00:09 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46MzrZ3STvzDqZw for ; Tue, 3 Sep 2019 17:59:58 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 46MzrY3M0fz9sBF; Tue, 3 Sep 2019 17:59:57 +1000 (AEST) From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Tue, 3 Sep 2019 17:59:34 +1000 Message-Id: <20190903075934.3525-2-alistair@popple.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190903075934.3525-1-alistair@popple.id.au> References: <20190903075934.3525-1-alistair@popple.id.au> MIME-Version: 1.0 Subject: [Pdbg] [PATCH 2/2] libpdbg: Allow programs to register their own hardware units X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Alistair Popple --- 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;