From patchwork Wed Nov 7 05:39:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994106 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZyj1fNqz9sCX for ; Wed, 7 Nov 2018 16:41:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZyg3tPHzF3GD for ; Wed, 7 Nov 2018 16:40:59 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxT0MkjzF3GW for ; Wed, 7 Nov 2018 16:39:57 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxS5CKcz9s8T; Wed, 7 Nov 2018 16:39:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:28 +1100 Message-Id: <20181107053943.4307-2-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 01/16] libpdbg: Add api to get 32-bit device tree property 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" --- libpdbg/libpdbg.c | 12 ++++++++++++ libpdbg/libpdbg.h | 1 + 2 files changed, 13 insertions(+) diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 810e045..ccaad3e 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -186,6 +186,18 @@ static int pdbg_get_target_u64_property(struct pdbg_target *target, const char * return 0; } +int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val) +{ + struct dt_property *p; + + p = dt_find_property(target, name); + if (!p) + return -1; + + *val = dt_get_number(p->prop, 1); + return 0; +} + int pdbg_get_u64_property(struct pdbg_target *target, const char *name, uint64_t *val) { struct pdbg_target *dn; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 1977c75..138521c 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -72,6 +72,7 @@ void pdbg_set_target_property(struct pdbg_target *target, const char *name, cons /* Get the given property and return the size */ void *pdbg_get_target_property(struct pdbg_target *target, const char *name, size_t *size); +int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val); int pdbg_get_u64_property(struct pdbg_target *target, const char *name, uint64_t *val); uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size); From patchwork Wed Nov 7 05:39:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994108 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZyl31S5z9sDB for ; Wed, 7 Nov 2018 16:41:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZyl1GJCzF3G7 for ; Wed, 7 Nov 2018 16:41:03 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxT4VKRzF3GW for ; Wed, 7 Nov 2018 16:39:57 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxT1gsyz9sCX; Wed, 7 Nov 2018 16:39:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:29 +1100 Message-Id: <20181107053943.4307-3-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 02/16] libpdbg: fix a bug in get_class_target_addr 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" The root device tree node does not have a class. Therefore this assert was not useful as the strcmp() may cause a segfault comparing the root node class. Signed-off-by: Alistair Popple Reviewed-by: Amitay Isaacs --- libpdbg/target.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libpdbg/target.c b/libpdbg/target.c index 317a6c6..975ecec 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -24,10 +24,9 @@ static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, con *addr += dt_get_address(target, 0, NULL); target = target->parent; - /* The should always be a parent. If there isn't it - * means we traversed up the whole device tree and - * didn't find a parent matching the given class. */ - assert(target); + /* The root node doesn't have an address space so it's + * an error in the device tree if we hit this. */ + assert(target != dt_root); } return target; From patchwork Wed Nov 7 05:39:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZys2f27z9sDB for ; Wed, 7 Nov 2018 16:41:09 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZyr6hk1zF3GT for ; Wed, 7 Nov 2018 16:41:08 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxV1FbyzF3Gb for ; Wed, 7 Nov 2018 16:39:58 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxT5nVRz9sDC; Wed, 7 Nov 2018 16:39:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:30 +1100 Message-Id: <20181107053943.4307-4-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 03/16] libpdbg: Add API to get device tree path and find target via path 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Alistair Popple Reviewed-by: Amitay Isaacs --- libpdbg/libpdbg.c | 13 +++++++++++++ libpdbg/libpdbg.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index ccaad3e..f77138a 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -135,6 +135,19 @@ const char *pdbg_target_dn_name(struct pdbg_target *target) return target->dn_name; } +char *pdbg_target_path(const struct pdbg_target *target) +{ + return dt_get_path(target); +} + +struct pdbg_target *pdbg_target_from_path(struct pdbg_target *target, const char *path) +{ + if (!target) + target = dt_root; + + return dt_find_by_path(target, path); +} + void pdbg_set_target_property(struct pdbg_target *target, const char *name, const void *val, size_t size) { struct dt_property *p; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 138521c..b11866a 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -84,6 +84,8 @@ void pdbg_target_release(struct pdbg_target *target); enum pdbg_target_status pdbg_target_status(struct pdbg_target *target); void pdbg_target_status_set(struct pdbg_target *target, enum pdbg_target_status status); uint32_t pdbg_target_index(struct pdbg_target *target); +char *pdbg_target_path(const struct pdbg_target *target); +struct pdbg_target *pdbg_target_from_path(struct pdbg_target *target, const char *path); uint32_t pdbg_parent_index(struct pdbg_target *target, char *klass); char *pdbg_target_class_name(struct pdbg_target *target); char *pdbg_target_name(struct pdbg_target *target); From patchwork Wed Nov 7 05:39:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZyw0FyQz9s8T for ; Wed, 7 Nov 2018 16:41:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZyv5hQRzF3FL for ; Wed, 7 Nov 2018 16:41:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxV5fnxzF3Gf for ; Wed, 7 Nov 2018 16:39:58 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxV2mctz9s8T; Wed, 7 Nov 2018 16:39:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:31 +1100 Message-Id: <20181107053943.4307-5-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 04/16] libpdbg: Add indirect address translation via callback 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Some hardware targets have more complicated addressing schemes than a simple base address + offset. It may be possible to determine a device-tree representation for these schemes but for the moment it is more straight forward to define a callback to do the translation. Signed-off-by: Alistair Popple Reviewed-by: Amitay Isaacs --- libpdbg/target.c | 7 ++++++- libpdbg/target.h | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libpdbg/target.c b/libpdbg/target.c index 975ecec..7468863 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -20,8 +20,13 @@ static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, con { /* Check class */ while (strcmp(target->class, name)) { + + if (target->translate) + *addr = target->translate(target, *addr); + else + *addr += dt_get_address(target, 0, NULL); + /* Keep walking the tree translating addresses */ - *addr += dt_get_address(target, 0, NULL); target = target->parent; /* The root node doesn't have an address space so it's diff --git a/libpdbg/target.h b/libpdbg/target.h index d1a6aec..289c1ee 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -38,6 +38,7 @@ struct pdbg_target { char *class; int (*probe)(struct pdbg_target *target); void (*release)(struct pdbg_target *target); + uint64_t (*translate)(struct pdbg_target *target, uint64_t addr); int index; enum pdbg_target_status status; const char *dn_name; @@ -57,6 +58,12 @@ struct pdbg_target_class *require_target_class(const char *name); struct pdbg_target_class *get_target_class(const char *name); bool pdbg_target_is_class(struct pdbg_target *target, const char *class); +/* This works and should be safe because struct pdbg_target is guaranteed to be + * the first member of the specialised type (see the DECLARE_HW_UNIT definition + * below). I'm not sure how sane it is though. Probably not very but it does + * remove a bunch of tedious container_of() typing */ +#define translate_cast(x) (uint64_t (*)(struct pdbg_target *, uint64_t)) (x) + extern struct list_head empty_list; extern struct list_head target_classes; From patchwork Wed Nov 7 05:39:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZyz32vTz9s8T for ; Wed, 7 Nov 2018 16:41:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZyz15y3zF3Gd for ; Wed, 7 Nov 2018 16:41:15 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxW3G5fzF3Gf for ; Wed, 7 Nov 2018 16:39:59 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxV71fnz9sCX; Wed, 7 Nov 2018 16:39:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:32 +1100 Message-Id: <20181107053943.4307-6-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 05/16] libpdbg: Add xbus hardware unit 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Alistair Popple --- Makefile.am | 3 ++- libpdbg/target.h | 5 +++++ libpdbg/xbus.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 libpdbg/xbus.c diff --git a/Makefile.am b/Makefile.am index 41a030d..94a112d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -163,7 +163,8 @@ libpdbg_la_SOURCES = \ libpdbg/p8chip.c \ libpdbg/p9chip.c \ libpdbg/target.c \ - libpdbg/target.h + libpdbg/target.h \ + libpdbg/xbus.c libpdbg_la_LIBADD = libfdt.la diff --git a/libpdbg/target.h b/libpdbg/target.h index 289c1ee..258c576 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -173,4 +173,9 @@ struct chiplet { }; #define target_to_chiplet(x) container_of(x, struct chiplet, target) +struct xbus { + struct pdbg_target target; + uint32_t ring_id; +}; +#define target_to_xbus(x) container_of(x, struct xbus, target) #endif diff --git a/libpdbg/xbus.c b/libpdbg/xbus.c new file mode 100644 index 0000000..69489bb --- /dev/null +++ b/libpdbg/xbus.c @@ -0,0 +1,62 @@ +/* Copyright 2018 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include + +#include "target.h" +#include "bitutils.h" + +/* XBus addressing is more complicated. This comes from p9_scominfo.C + * in the ekb. */ +static uint64_t xbus_translate(struct xbus *xbus, uint64_t addr) +{ + uint64_t ring = (addr >> 10) & 0xf; + + if (ring >= 0x3 && ring <= 0x5) + addr = SETFIELD(PPC_BITMASK(50, 53), addr, 0x3 + xbus->ring_id); + else if (ring >= 0x6 && ring <= 8) + addr = SETFIELD(PPC_BITMASK(50, 53), addr, 0x6 + xbus->ring_id); + + return addr; +} + +static int xbus_probe(struct pdbg_target *target) +{ + struct xbus *xbus = target_to_xbus(target); + + if (pdbg_get_target_u32_property(&xbus->target, "ring-id", &xbus->ring_id)) { + printf("Unknown ring-id on %s@%d\n", pdbg_target_name(&xbus->target), + pdbg_target_index(&xbus->target)); + return -1; + } + + return 0; +} + +struct xbus p9_xbus = { + .target = { + .name = "POWER9 XBus", + .compatible = "ibm,xbus", + .class = "xbus", + .probe = xbus_probe, + .translate = translate_cast(xbus_translate), + }, +}; +DECLARE_HW_UNIT(p9_xbus); From patchwork Wed Nov 7 05:39:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZz14ZnJz9s8T for ; Wed, 7 Nov 2018 16:41:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZz12kPyzF3Fb for ; Wed, 7 Nov 2018 16:41:17 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxX07p4zF3G9 for ; Wed, 7 Nov 2018 16:40:00 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxW4TXYz9s8T; Wed, 7 Nov 2018 16:39:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:33 +1100 Message-Id: <20181107053943.4307-7-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 06/16] build: Allow device tree headers to be generated in subdirs 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" From: Amitay Isaacs Using dts avoids unnecessary prefixes in case building device tree headers in subdirs. Signed-off-by: Amitay Isaacs --- Makefile.am | 4 ++-- generate_dt_header.sh | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index 94a112d..ad2bbec 100644 --- a/Makefile.am +++ b/Makefile.am @@ -242,11 +242,11 @@ p9z-fsi.dts: p9z-fsi.dts.m4 p9-fsi.dtsi %.dtb: %.dts $(DTC_V)$(DTC) -i$(dir $@) -I dts $< -O dtb > $@ -%.dt.h: %.dtb +%.dt.h: %.dts $(GEN_V)$(srcdir)/generate_dt_header.sh $< > $@ %.dtb.o: %.dtb - $(AM_V_CC)$(CC) -c $(srcdir)/template.S -DSYMBOL_PREFIX=$(shell echo $@ | tr '.-' '_') -DFILENAME=\"$<\" -o $@ + $(AM_V_CC)$(CC) -c $(srcdir)/template.S -DSYMBOL_PREFIX=$(shell basename $@ | tr '.-' '_') -DFILENAME=\"$<\" -o $@ %.c: %.rl $(RAGEL_V)$(RAGEL) -o $@ $< diff --git a/generate_dt_header.sh b/generate_dt_header.sh index 7f61d1f..b7abfb5 100755 --- a/generate_dt_header.sh +++ b/generate_dt_header.sh @@ -1,15 +1,14 @@ #!/bin/sh if [ $# -ne 1 ] ; then - echo "Usage: $0 " + echo "Usage: $0 " exit 1 fi -SYMBOL=$(echo "$1" | tr '.-' '_') +SYMBOL=$(basename "$1" | sed 's/dts/dtb/' | tr '.-' '_') SYM_START="_binary_${SYMBOL}_o_start" SYM_END="_binary_${SYMBOL}_o_end" SYM_SIZE="_binary_${SYMBOL}_o_size" -HEADER="$f.h" cat - < X-Patchwork-Id: 994113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZz4139Sz9sDB for ; Wed, 7 Nov 2018 16:41:20 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZz36cDkzF3Gl for ; Wed, 7 Nov 2018 16:41:19 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxX3zTQzF3GP for ; Wed, 7 Nov 2018 16:40:00 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxX1W0hz9sDB; Wed, 7 Nov 2018 16:40:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:34 +1100 Message-Id: <20181107053943.4307-8-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 07/16] libpdbg: Remove unused code 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Much of the code in device.c was originally copied over from Skiboot and is not applicable or used by pdbg. Signed-off-by: Alistair Popple Reviewed-by: Amitay Isaacs --- libpdbg/device.c | 266 +----------------------------------------------------- libpdbg/device.h | 89 ------------------ libpdbg/libpdbg.c | 27 ------ libpdbg/libpdbg.h | 1 - 4 files changed, 4 insertions(+), 379 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 7442e29..cdb3481 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -34,7 +34,6 @@ u32 last_phandle = 0; struct pdbg_target *dt_root; -struct pdbg_target *dt_chosen; static const char *take_name(const char *name) { @@ -283,22 +282,6 @@ struct pdbg_target *dt_find_by_path(struct pdbg_target *root, const char *path) return root; } -struct pdbg_target *dt_find_by_name(struct pdbg_target *root, const char *name) -{ - struct pdbg_target *child, *match; - - list_for_each(&root->children, child, list) { - if (!strcmp(child->dn_name, name)) - return child; - - match = dt_find_by_name(child, name); - if (match) - return match; - } - - return NULL; -} - static struct dt_property *new_property(struct pdbg_target *node, const char *name, size_t size) { @@ -363,107 +346,6 @@ void dt_resize_property(struct dt_property **prop, size_t len) (*prop)->list.prev->next = &(*prop)->list; } -struct dt_property *dt_add_property_string(struct pdbg_target *node, - const char *name, - const char *value) -{ - return dt_add_property(node, name, value, strlen(value)+1); -} - -struct dt_property *dt_add_property_nstr(struct pdbg_target *node, - const char *name, - const char *value, unsigned int vlen) -{ - struct dt_property *p; - char *tmp = zalloc(vlen + 1); - - if (!tmp) - return NULL; - - strncpy(tmp, value, vlen); - p = dt_add_property(node, name, tmp, strlen(tmp)+1); - free(tmp); - - return p; -} - -struct dt_property *__dt_add_property_cells(struct pdbg_target *node, - const char *name, - int count, ...) -{ - struct dt_property *p; - u32 *val; - unsigned int i; - va_list args; - - p = new_property(node, name, count * sizeof(u32)); - val = (u32 *)p->prop; - va_start(args, count); - for (i = 0; i < count; i++) - val[i] = cpu_to_fdt32(va_arg(args, u32)); - va_end(args); - return p; -} - -struct dt_property *__dt_add_property_u64s(struct pdbg_target *node, - const char *name, - int count, ...) -{ - struct dt_property *p; - u64 *val; - unsigned int i; - va_list args; - - p = new_property(node, name, count * sizeof(u64)); - val = (u64 *)p->prop; - va_start(args, count); - for (i = 0; i < count; i++) - val[i] = cpu_to_fdt64(va_arg(args, u64)); - va_end(args); - return p; -} - -struct dt_property *__dt_add_property_strings(struct pdbg_target *node, - const char *name, - int count, ...) -{ - struct dt_property *p; - unsigned int i, size; - va_list args; - const char *sstr; - char *s; - - va_start(args, count); - for (i = size = 0; i < count; i++) { - sstr = va_arg(args, const char *); - if (sstr) - size += strlen(sstr) + 1; - } - va_end(args); - if (!size) - size = 1; - p = new_property(node, name, size); - s = (char *)p->prop; - *s = 0; - va_start(args, count); - for (i = 0; i < count; i++) { - sstr = va_arg(args, const char *); - if (sstr) { - strcpy(s, sstr); - s = s + strlen(sstr) + 1; - } - } - va_end(args); - return p; -} - -void dt_del_property(struct pdbg_target *node, struct dt_property *prop) -{ - list_del_from(&node->properties, &prop->list); - free_name(prop->name); - free(prop); -} - u32 dt_property_get_cell(const struct dt_property *prop, u32 index) { assert(prop->len >= (index+1)*sizeof(u32)); @@ -497,16 +379,6 @@ struct pdbg_target *dt_next(const struct pdbg_target *root, return NULL; } -struct dt_property *__dt_find_property(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; -} - struct dt_property *dt_find_property(const struct pdbg_target *node, const char *name) { @@ -518,14 +390,6 @@ struct dt_property *dt_find_property(const struct pdbg_target *node, return NULL; } -void dt_check_del_prop(struct pdbg_target *node, const char *name) -{ - struct dt_property *p; - - p = __dt_find_property(node, name); - if (p) - dt_del_property(node, p); -} const struct dt_property *dt_require_property(const struct pdbg_target *node, const char *name, int wanted_len) { @@ -551,19 +415,6 @@ const struct dt_property *dt_require_property(const struct pdbg_target *node, return p; } -bool dt_has_node_property(const struct pdbg_target *node, - const char *name, const char *val) -{ - const struct dt_property *p = dt_find_property(node, name); - - if (!p) - return false; - if (!val) - return true; - - return p->len == strlen(val) + 1 && memcmp(p->prop, val, p->len) == 0; -} - bool dt_prop_find_string(const struct dt_property *p, const char *s) { const char *c, *end; @@ -601,25 +452,6 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, return NULL; } -u64 dt_prop_get_u64(const struct pdbg_target *node, const char *prop) -{ - const struct dt_property *p = dt_require_property(node, prop, 8); - - return ((u64)dt_property_get_cell(p, 0) << 32) - | dt_property_get_cell(p, 1); -} - -u64 dt_prop_get_u64_def(const struct pdbg_target *node, const char *prop, u64 def) -{ - const struct dt_property *p = dt_find_property(node, prop); - - if (!p) - return def; - - return ((u64)dt_property_get_cell(p, 0) << 32) - | dt_property_get_cell(p, 1); -} - u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop) { const struct dt_property *p = dt_require_property(node, prop, 4); @@ -629,12 +461,12 @@ u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop) u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) { - const struct dt_property *p = dt_find_property(node, prop); + const struct dt_property *p = dt_find_property(node, prop); - if (!p) - return def; + if (!p) + return def; - return dt_property_get_cell(p, 0); + return dt_property_get_cell(p, 0); } u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index) @@ -659,17 +491,6 @@ const void *dt_prop_get_def(const struct pdbg_target *node, const char *prop, return p ? p->prop : def; } -const void *dt_prop_get_def_size(const struct pdbg_target *node, const char *prop, - void *def, size_t *len) -{ - const struct dt_property *p = dt_find_property(node, prop); - *len = 0; - if (p) - *len = p->len; - - return p ? p->prop : def; -} - u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell) { const struct dt_property *p = dt_require_property(node, prop, -1); @@ -677,35 +498,6 @@ u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell) return dt_property_get_cell(p, cell); } -u32 dt_prop_get_cell_def(const struct pdbg_target *node, const char *prop, - u32 cell, u32 def) -{ - const struct dt_property *p = dt_find_property(node, prop); - - if (!p) - return def; - - return dt_property_get_cell(p, cell); -} - -void dt_free(struct pdbg_target *node) -{ - struct pdbg_target *child; - struct dt_property *p; - - while ((child = list_top(&node->children, struct pdbg_target, list))) - dt_free(child); - - while ((p = list_pop(&node->properties, struct dt_property, list))) { - free_name(p->name); - free(p); - } - - if (node->parent) - list_del_from(&node->parent->children, &node->list); - dt_destroy(node); -} - enum pdbg_target_status str_to_status(const char *status) { if (!strcmp(status, "enabled")) { @@ -852,53 +644,3 @@ u32 dt_get_chip_id(const struct pdbg_target *node) assert(id != 0xffffffff); return id; } - -struct pdbg_target *dt_find_compatible_node_on_chip(struct pdbg_target *root, - struct pdbg_target *prev, - const char *compat, - uint32_t chip_id) -{ - struct pdbg_target *node; - - node = prev ? dt_next(root, prev) : root; - for (; node; node = dt_next(root, node)) { - u32 cid = __dt_get_chip_id(node); - if (cid == chip_id && - dt_node_is_compatible(node, compat)) - return node; - } - return NULL; -} - -unsigned int dt_count_addresses(const struct pdbg_target *node) -{ - const struct dt_property *p; - u32 na = dt_n_address_cells(node); - u32 ns = dt_n_size_cells(node); - u32 n; - - p = dt_require_property(node, "reg", -1); - n = (na + ns) * sizeof(u32); - - if (n == 0) - return 0; - - return p->len / n; -} - -u64 dt_translate_address(const struct pdbg_target *node, unsigned int index, - u64 *out_size) -{ - /* XXX TODO */ - return dt_get_address(node, index, out_size); -} - -bool dt_node_is_enabled(struct pdbg_target *node) -{ - const struct dt_property *p = dt_find_property(node, "status"); - - if (!p) - return true; - - return p->len > 1 && p->prop[0] == 'o' && p->prop[1] == 'k'; -} diff --git a/libpdbg/device.h b/libpdbg/device.h index cb5bc10..5786d99 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -44,7 +44,6 @@ struct dt_property { extern u32 last_phandle; extern struct pdbg_target *dt_root; -extern struct pdbg_target *dt_chosen; /* Create a new node. */ struct pdbg_target *dt_new_node(const char *name, const void *fdt, int offset); @@ -56,51 +55,6 @@ bool dt_attach_root(struct pdbg_target *parent, struct pdbg_target *root); struct dt_property *dt_add_property(struct pdbg_target *node, const char *name, const void *val, size_t size); -struct dt_property *dt_add_property_string(struct pdbg_target *node, - const char *name, - const char *value); -struct dt_property *dt_add_property_nstr(struct pdbg_target *node, - const char *name, - const char *value, unsigned int vlen); - -/* Given out enough GCC extensions, we will achieve enlightenment! */ -#define dt_add_property_strings(node, name, ...) \ - __dt_add_property_strings((node), ((name)), \ - sizeof((const char *[]) { __VA_ARGS__ })/sizeof(const char *), \ - __VA_ARGS__) - -struct dt_property *__dt_add_property_strings(struct pdbg_target *node, - const char *name, - int count, ...); - -/* Given out enough GCC extensions, we will achieve enlightenment! */ -#define dt_add_property_cells(node, name, ...) \ - __dt_add_property_cells((node), ((name)), \ - sizeof((u32[]) { __VA_ARGS__ })/sizeof(u32), \ - __VA_ARGS__) - -struct dt_property *__dt_add_property_cells(struct pdbg_target *node, - const char *name, - int count, ...); - -#define dt_add_property_u64s(node, name, ...) \ - __dt_add_property_u64s((node), ((name)), \ - sizeof((u64[]) { __VA_ARGS__ })/sizeof(u64), \ - __VA_ARGS__) - -struct dt_property *__dt_add_property_u64s(struct pdbg_target *node, - const char *name, - int count, ...); - -static inline struct dt_property *dt_add_property_u64(struct pdbg_target *node, - const char *name, u64 val) -{ - return dt_add_property_cells(node, name, (u32)(val >> 32), (u32)val); -} - -void dt_del_property(struct pdbg_target *node, struct dt_property *prop); - -void dt_check_del_prop(struct pdbg_target *node, const char *name); /* Warning: moves *prop! */ void dt_resize_property(struct dt_property **prop, size_t len); @@ -113,10 +67,6 @@ struct pdbg_target *dt_first(const struct pdbg_target *root); /* Return next node, or NULL. */ struct pdbg_target *dt_next(const struct pdbg_target *root, const struct pdbg_target *prev); -/* Iterate nodes */ -#define dt_for_each_node(root, node) \ - for (node = dt_first(root); node; node = dt_next(root, node)) - #define dt_for_each_child(parent, node) \ list_for_each(&parent->children, node, list) @@ -135,18 +85,6 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, for (node = NULL; \ (node = dt_find_compatible_node(root, node, compat)) != NULL;) -struct pdbg_target *dt_find_compatible_node_on_chip(struct pdbg_target *root, - struct pdbg_target *prev, - const char *compat, - uint32_t chip_id); - -#define dt_for_each_compatible_on_chip(root, node, compat, chip_id) \ - for (node = NULL; \ - (node = dt_find_compatible_node_on_chip(root, node,\ - compat, chip_id)) != NULL;) -/* Check status property */ -bool dt_node_is_enabled(struct pdbg_target *node); - /* Build the full path for a node. Return a new block of memory, caller * shall free() it */ @@ -164,33 +102,18 @@ struct dt_property *dt_find_property(const struct pdbg_target *node,\ const struct dt_property *dt_require_property(const struct pdbg_target *node, const char *name, int wanted_len); -/* non-const variant */ -struct dt_property *__dt_find_property(struct pdbg_target *node, const char *name); - -/* Find a property by name, check if it's the same as val. */ -bool dt_has_node_property(const struct pdbg_target *node, - const char *name, const char *val); - -/* Free a node (and any children). */ -void dt_free(struct pdbg_target *node); - /* Parse an initial fdt */ void dt_expand(const void *fdt); int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) __warn_unused_result; /* Simplified accessors */ -u64 dt_prop_get_u64(const struct pdbg_target *node, const char *prop); -u64 dt_prop_get_u64_def(const struct pdbg_target *node, const char *prop, u64 def); u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop); u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def); u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index); 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); -const void *dt_prop_get_def_size(const struct pdbg_target *node, const char *prop, - void *def, size_t *len); u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell); -u32 dt_prop_get_cell_def(const struct pdbg_target *node, const char *prop, u32 cell, u32 def); /* Parsing helpers */ u32 dt_n_address_cells(const struct pdbg_target *node); @@ -208,18 +131,6 @@ u32 dt_get_chip_id(const struct pdbg_target *node); u64 dt_get_address(const struct pdbg_target *node, unsigned int index, u64 *out_size); -/* Count "reg" property entries */ -unsigned int dt_count_addresses(const struct pdbg_target *node); - -/* Address translation - * - * WARNING: Current implementation is simplified and will not - * handle complex address formats with address space indicators - * nor will it handle "ranges" translations yet... (XX TODO) - */ -u64 dt_translate_address(const struct pdbg_target *node, unsigned int index, - u64 *out_size); - /* compare function used to sort child nodes by name when added to the * tree. This is mainly here for testing. */ diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index f77138a..7712e87 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -184,21 +184,6 @@ uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size) return dt_get_address(target, 0, size); } -/* Difference from below is that it doesn't search up the tree for the given - * property. As nothing uses this yet we don't export it for use, but we may in - * future */ -static int pdbg_get_target_u64_property(struct pdbg_target *target, const char *name, uint64_t *val) -{ - struct dt_property *p; - - p = dt_find_property(target, name); - if (!p) - return -1; - - *val = dt_get_number(p->prop, 2); - return 0; -} - int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val) { struct dt_property *p; @@ -211,18 +196,6 @@ int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, u return 0; } -int pdbg_get_u64_property(struct pdbg_target *target, const char *name, uint64_t *val) -{ - struct pdbg_target *dn; - - for (dn = target; dn; dn = dn->parent) { - if (!pdbg_get_target_u64_property(dn, name, val)) - return 0; - } - - return -1; -} - void pdbg_progress_tick(uint64_t cur, uint64_t end) { if (progress_tick) diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index b11866a..959c2ef 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -73,7 +73,6 @@ void pdbg_set_target_property(struct pdbg_target *target, const char *name, cons /* Get the given property and return the size */ void *pdbg_get_target_property(struct pdbg_target *target, const char *name, size_t *size); int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val); -int pdbg_get_u64_property(struct pdbg_target *target, const char *name, uint64_t *val); uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size); /* Misc. */ From patchwork Wed Nov 7 05:39:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994114 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZz74Dryz9s8T for ; Wed, 7 Nov 2018 16:41:23 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZz7258GzF3FX for ; Wed, 7 Nov 2018 16:41:23 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxY5XsqzF3GW for ; Wed, 7 Nov 2018 16:40:01 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxX5DJ1z9s8T; Wed, 7 Nov 2018 16:40:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:35 +1100 Message-Id: <20181107053943.4307-9-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 08/16] libpdbg: Make more declarations static 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Many of the functions in device.c are only used within that file and should be made static. Signed-off-by: Alistair Popple Reviewed-by: Amitay Isaacs --- libpdbg/device.c | 56 ++++++++++++++++++++++++++++++++++++++----------------- libpdbg/device.h | 51 -------------------------------------------------- libpdbg/libpdbg.c | 13 ------------- libpdbg/target.c | 6 ------ 4 files changed, 39 insertions(+), 87 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index cdb3481..2f1a97b 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -30,8 +30,11 @@ #define prerror printf #define is_rodata(p) false +#define dt_for_each_child(parent, node) \ + list_for_each(&parent->children, node, list) + /* Used to give unique handles. */ -u32 last_phandle = 0; +static u32 last_phandle = 0; struct pdbg_target *dt_root; @@ -50,7 +53,7 @@ static void free_name(const char *name) free((char *)name); } -struct pdbg_target *dt_new_node(const char *name, const void *fdt, int node_offset) +static struct pdbg_target *dt_new_node(const char *name, const void *fdt, int node_offset) { struct hw_unit_info *hw_info = NULL; const struct fdt_property *prop; @@ -117,7 +120,7 @@ static const char *get_unitname(const struct pdbg_target *node) return c + 1; } -int dt_cmp_subnodes(const struct pdbg_target *a, const struct pdbg_target *b) +static int dt_cmp_subnodes(const struct pdbg_target *a, const struct pdbg_target *b) { const char *a_unit = get_unitname(a); const char *b_unit = get_unitname(b); @@ -140,7 +143,7 @@ int dt_cmp_subnodes(const struct pdbg_target *a, const struct pdbg_target *b) return strcmp(a->dn_name, b->dn_name); } -bool dt_attach_root(struct pdbg_target *parent, struct pdbg_target *root) +static bool dt_attach_root(struct pdbg_target *parent, struct pdbg_target *root) { struct pdbg_target *node; @@ -184,7 +187,7 @@ static inline void dt_destroy(struct pdbg_target *dn) free(dn); } -char *dt_get_path(const struct pdbg_target *node) +static char *dt_get_path(const struct pdbg_target *node) { unsigned int len = 0; const struct pdbg_target *n; @@ -246,7 +249,7 @@ static const char *__dt_path_split(const char *p, return sl; } -struct pdbg_target *dt_find_by_path(struct pdbg_target *root, const char *path) +static struct pdbg_target *dt_find_by_path(struct pdbg_target *root, const char *path) { struct pdbg_target *n; const char *pn, *pa = NULL, *p = path, *nn = NULL, *na = NULL; @@ -346,7 +349,7 @@ void dt_resize_property(struct dt_property **prop, size_t len) (*prop)->list.prev->next = &(*prop)->list; } -u32 dt_property_get_cell(const struct dt_property *prop, u32 index) +static u32 dt_property_get_cell(const struct dt_property *prop, u32 index) { assert(prop->len >= (index+1)*sizeof(u32)); /* Always aligned, so this works. */ @@ -354,13 +357,13 @@ u32 dt_property_get_cell(const struct dt_property *prop, u32 index) } /* First child of this node. */ -struct pdbg_target *dt_first(const struct pdbg_target *root) +static struct pdbg_target *dt_first(const struct pdbg_target *root) { return list_top(&root->children, struct pdbg_target, list); } /* Return next node, or NULL. */ -struct pdbg_target *dt_next(const struct pdbg_target *root, +static struct pdbg_target *dt_next(const struct pdbg_target *root, const struct pdbg_target *prev) { /* Children? */ @@ -390,8 +393,8 @@ struct dt_property *dt_find_property(const struct pdbg_target *node, return NULL; } -const struct dt_property *dt_require_property(const struct pdbg_target *node, - const char *name, int wanted_len) +static const struct dt_property *dt_require_property(const struct pdbg_target *node, + const char *name, int wanted_len) { const struct dt_property *p = dt_find_property(node, name); @@ -459,7 +462,7 @@ u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop) return dt_property_get_cell(p, 0); } -u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) +static u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) { const struct dt_property *p = dt_find_property(node, prop); @@ -498,7 +501,7 @@ u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell) return dt_property_get_cell(p, cell); } -enum pdbg_target_status str_to_status(const char *status) +static enum pdbg_target_status str_to_status(const char *status) { if (!strcmp(status, "enabled")) { /* There isn't really a use case for this at the moment except @@ -520,7 +523,7 @@ enum pdbg_target_status str_to_status(const char *status) assert(0); } -int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) +static int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) { const struct fdt_property *prop; int offset, nextoffset, err; @@ -577,7 +580,7 @@ int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) return nextoffset; } -void dt_expand(const void *fdt) +static void dt_expand(const void *fdt) { PR_DEBUG("FDT: Parsing fdt @%p\n", fdt); @@ -595,14 +598,14 @@ u64 dt_get_number(const void *pdata, unsigned int cells) return ret; } -u32 dt_n_address_cells(const struct pdbg_target *node) +static u32 dt_n_address_cells(const struct pdbg_target *node) { if (!node->parent) return 0; return dt_prop_get_u32_def(node->parent, "#address-cells", 2); } -u32 dt_n_size_cells(const struct pdbg_target *node) +static u32 dt_n_size_cells(const struct pdbg_target *node) { if (!node->parent) return 0; @@ -644,3 +647,22 @@ u32 dt_get_chip_id(const struct pdbg_target *node) assert(id != 0xffffffff); return id; } + +void pdbg_targets_init(void *fdt) +{ + dt_root = dt_new_node("", NULL, 0); + dt_expand(fdt); +} + +char *pdbg_target_path(const struct pdbg_target *target) +{ + return dt_get_path(target); +} + +struct pdbg_target *pdbg_target_from_path(struct pdbg_target *target, const char *path) +{ + if (!target) + target = dt_root; + + return dt_find_by_path(target, path); +} diff --git a/libpdbg/device.h b/libpdbg/device.h index 5786d99..098f7f4 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -38,19 +38,8 @@ struct dt_property { char prop[/* len */]; }; -/* This is shared with device_tree.c .. make it static when - * the latter is gone (hopefully soon) - */ -extern u32 last_phandle; - extern struct pdbg_target *dt_root; -/* Create a new node. */ -struct pdbg_target *dt_new_node(const char *name, const void *fdt, int offset); - -/* Graft a root node into this tree. */ -bool dt_attach_root(struct pdbg_target *parent, struct pdbg_target *root); - /* Add a property node, various forms. */ struct dt_property *dt_add_property(struct pdbg_target *node, const char *name, @@ -59,20 +48,6 @@ struct dt_property *dt_add_property(struct pdbg_target *node, /* Warning: moves *prop! */ void dt_resize_property(struct dt_property **prop, size_t len); -u32 dt_property_get_cell(const struct dt_property *prop, u32 index); - -/* First child of this node. */ -struct pdbg_target *dt_first(const struct pdbg_target *root); - -/* Return next node, or NULL. */ -struct pdbg_target *dt_next(const struct pdbg_target *root, const struct pdbg_target *prev); - -#define dt_for_each_child(parent, node) \ - list_for_each(&parent->children, node, list) - -/* Find a string in a string list */ -bool dt_prop_find_string(const struct dt_property *p, const char *s); - /* Check a compatible property */ bool dt_node_is_compatible(const struct pdbg_target *node, const char *compat); @@ -85,39 +60,18 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, for (node = NULL; \ (node = dt_find_compatible_node(root, node, compat)) != NULL;) -/* Build the full path for a node. Return a new block of memory, caller - * shall free() it - */ -char *dt_get_path(const struct pdbg_target *node); - -/* Find a node by path */ -struct pdbg_target *dt_find_by_path(struct pdbg_target *root, const char *path); - -/* Find a child node by name */ -struct pdbg_target *dt_find_by_name(struct pdbg_target *root, const char *name); - /* Find a property by name. */ struct dt_property *dt_find_property(const struct pdbg_target *node,\ const char *name); -const struct dt_property *dt_require_property(const struct pdbg_target *node, - const char *name, int wanted_len); - -/* Parse an initial fdt */ -void dt_expand(const void *fdt); -int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) __warn_unused_result; /* Simplified accessors */ u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop); -u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def); u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index); 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); -u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell); /* Parsing helpers */ -u32 dt_n_address_cells(const struct pdbg_target *node); -u32 dt_n_size_cells(const struct pdbg_target *node); 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 @@ -131,9 +85,4 @@ u32 dt_get_chip_id(const struct pdbg_target *node); u64 dt_get_address(const struct pdbg_target *node, unsigned int index, u64 *out_size); -/* compare function used to sort child nodes by name when added to the - * tree. This is mainly here for testing. - */ -int dt_cmp_subnodes(const struct pdbg_target *a, const struct pdbg_target *b); - #endif /* __DEVICE_H */ diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 7712e87..8aa22e1 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -135,19 +135,6 @@ const char *pdbg_target_dn_name(struct pdbg_target *target) return target->dn_name; } -char *pdbg_target_path(const struct pdbg_target *target) -{ - return dt_get_path(target); -} - -struct pdbg_target *pdbg_target_from_path(struct pdbg_target *target, const char *path) -{ - if (!target) - target = dt_root; - - return dt_find_by_path(target, path); -} - void pdbg_set_target_property(struct pdbg_target *target, const char *name, const void *val, size_t size) { struct dt_property *p; diff --git a/libpdbg/target.c b/libpdbg/target.c index 7468863..d8d699f 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -278,12 +278,6 @@ struct hw_unit_info *find_compatible_target(const char *compat) return NULL; } -void pdbg_targets_init(void *fdt) -{ - dt_root = dt_new_node("", NULL, 0); - dt_expand(fdt); -} - /* We walk the tree root down disabling targets which might/should * exist but don't */ enum pdbg_target_status pdbg_target_probe(struct pdbg_target *target) From patchwork Wed Nov 7 05:39:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZzB1vpnz9s8T for ; Wed, 7 Nov 2018 16:41:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZz975fVzF3Fb for ; Wed, 7 Nov 2018 16:41:25 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxY6MKwzF3GX for ; Wed, 7 Nov 2018 16:40:01 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxY2gzFz9sCX; Wed, 7 Nov 2018 16:40:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:36 +1100 Message-Id: <20181107053943.4307-10-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 09/16] libpdbg: Move property code into libpdbg/device.c 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Alistair Popple Reviewed-by: Amitay Isaacs --- libpdbg/device.c | 72 +++++++++++++++++++++++++++++++++++++++++++++---------- libpdbg/device.h | 30 ----------------------- libpdbg/libpdbg.c | 51 +++++++-------------------------------- 3 files changed, 68 insertions(+), 85 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..8af216c 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -135,52 +135,19 @@ 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); - if (!p) - return -1; + p = pdbg_get_target_property(target, name, &size); + if (!p) + return -1; + + assert(size == 4); + *val = be32toh(*p); - *val = dt_get_number(p->prop, 1); - return 0; + return 0; } void pdbg_progress_tick(uint64_t cur, uint64_t end) From patchwork Wed Nov 7 05:39:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994116 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZzD6h4zz9s8T for ; Wed, 7 Nov 2018 16:41:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZzD4cK4zF3G0 for ; Wed, 7 Nov 2018 16:41:28 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxZ2b7wzF3GW for ; Wed, 7 Nov 2018 16:40:02 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxZ0QX6z9sDB; Wed, 7 Nov 2018 16:40:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:37 +1100 Message-Id: <20181107053943.4307-11-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 10/16] libpdbg: Rename property functions 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Some of the functions dealing with target properties have somewhat inconsistent naming. This patch renames them and adds #defines for backwards compatibility for external projects. These will be removed once older projects have moved over to the new names. Signed-off-by: Alistair Popple Reviewed-by: Amitay Isaacs --- libpdbg/device.c | 6 +++--- libpdbg/libpdbg.c | 4 ++-- libpdbg/libpdbg.h | 13 ++++++++++--- libpdbg/xbus.c | 2 +- src/main.c | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index af2973b..226cf12 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -375,7 +375,7 @@ static 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) +void pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size) { struct dt_property *p; @@ -391,7 +391,7 @@ void pdbg_set_target_property(struct pdbg_target *target, const char *name, cons } } -void *pdbg_get_target_property(struct pdbg_target *target, const char *name, size_t *size) +void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size) { struct dt_property *p; @@ -634,7 +634,7 @@ static void dt_expand(const void *fdt) abort(); } -u64 dt_get_number(const void *pdata, unsigned int cells) +static u64 dt_get_number(const void *pdata, unsigned int cells) { const u32 *p = pdata; u64 ret = 0; diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 8af216c..f638fd2 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -135,12 +135,12 @@ const char *pdbg_target_dn_name(struct pdbg_target *target) return target->dn_name; } -int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val) +int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val) { uint32_t *p; size_t size; - p = pdbg_get_target_property(target, name, &size); + p = pdbg_target_property(target, name, &size); if (!p) return -1; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 959c2ef..8d8f0a3 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -68,13 +68,20 @@ struct pdbg_target *pdbg_target_parent(const char *klass, struct pdbg_target *ta struct pdbg_target *pdbg_target_require_parent(const char *klass, struct pdbg_target *target); /* Set the given property. Will automatically add one if one doesn't exist */ -void pdbg_set_target_property(struct pdbg_target *target, const char *name, const void *val, size_t size); +void pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size); /* Get the given property and return the size */ -void *pdbg_get_target_property(struct pdbg_target *target, const char *name, size_t *size); -int pdbg_get_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val); +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); +/* Old deprecated for names for the above. Do not use for new projects + * as these will be removed at some future point. */ +#define pdbg_set_target_property(target, name, val, size) \ + pdbg_target_set_property(target, name, val, size) +#define pdbg_get_target_property(target, name, size) \ + pdbg_target_property(target, name, size) + /* Misc. */ void pdbg_targets_init(void *fdt); void pdbg_target_probe_all(struct pdbg_target *parent); diff --git a/libpdbg/xbus.c b/libpdbg/xbus.c index 69489bb..661b9a3 100644 --- a/libpdbg/xbus.c +++ b/libpdbg/xbus.c @@ -41,7 +41,7 @@ static int xbus_probe(struct pdbg_target *target) { struct xbus *xbus = target_to_xbus(target); - if (pdbg_get_target_u32_property(&xbus->target, "ring-id", &xbus->ring_id)) { + if (pdbg_target_u32_property(&xbus->target, "ring-id", &xbus->ring_id)) { printf("Unknown ring-id on %s@%d\n", pdbg_target_name(&xbus->target), pdbg_target_index(&xbus->target)); return -1; diff --git a/src/main.c b/src/main.c index 8ee0e38..40fa48b 100644 --- a/src/main.c +++ b/src/main.c @@ -677,7 +677,7 @@ static int target_selection(void) int proc_index = pdbg_target_index(pib); if (backend == I2C && device_node) - pdbg_set_target_property(pib, "bus", device_node, strlen(device_node) + 1); + pdbg_target_set_property(pib, "bus", device_node, strlen(device_node) + 1); if (processorsel[proc_index]) { target_select(pib); From patchwork Wed Nov 7 05:39:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994117 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZzH1XFjz9s8T for ; Wed, 7 Nov 2018 16:41:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZzG70b8zF3GW for ; Wed, 7 Nov 2018 16:41:30 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxZ6vrHzF3GX for ; Wed, 7 Nov 2018 16:40:02 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxZ40CSz9s8T; Wed, 7 Nov 2018 16:40:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:38 +1100 Message-Id: <20181107053943.4307-12-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 11/16] libpdbg: Rework chip-id functions 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Rename the chip-id functions to be consistent with other libpdbg function names and move them in with the rest of the general libpdbg code. Signed-off-by: Alistair Popple --- libpdbg/device.c | 19 ------------------- libpdbg/device.h | 4 ---- libpdbg/host.c | 2 +- libpdbg/htm.c | 4 ++-- libpdbg/libpdbg.c | 15 +++++++++++++++ libpdbg/libpdbg.h | 4 ++++ 6 files changed, 22 insertions(+), 26 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 226cf12..a7212a6 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -675,25 +675,6 @@ u64 dt_get_address(const struct pdbg_target *node, unsigned int index, return dt_get_number(p->prop + pos, na); } -static u32 __dt_get_chip_id(const struct pdbg_target *node) -{ - const struct dt_property *prop; - - for (; node; node = node->parent) { - prop = dt_find_property(node, "chip-id"); - if (prop) - return dt_property_get_cell(prop, 0); - } - return 0xffffffff; -} - -u32 dt_get_chip_id(const struct pdbg_target *node) -{ - u32 id = __dt_get_chip_id(node); - assert(id != 0xffffffff); - return id; -} - void pdbg_targets_init(void *fdt) { dt_root = dt_new_node("", NULL, 0); diff --git a/libpdbg/device.h b/libpdbg/device.h index f487443..a050a23 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -44,10 +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); -/* 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); - /* Address accessors ("reg" properties parsing). No translation, * only support "simple" address forms (1 or 2 cells). Asserts * if address doesn't exist diff --git a/libpdbg/host.c b/libpdbg/host.c index eb627be..15e28a0 100644 --- a/libpdbg/host.c +++ b/libpdbg/host.c @@ -91,7 +91,7 @@ static int host_pib_probe(struct pdbg_target *target) if (!fd) return -1; - chip_id = dt_get_chip_id(target); + chip_id = pdbg_target_chip_id(target); if (chip_id == -1) goto out; diff --git a/libpdbg/htm.c b/libpdbg/htm.c index f9013e5..1ea2c3a 100644 --- a/libpdbg/htm.c +++ b/libpdbg/htm.c @@ -551,7 +551,7 @@ static char *get_debugfs_file(struct htm *htm, const char *file) uint32_t chip_id; char *filename; - chip_id = dt_get_chip_id(&htm->target); + chip_id = pdbg_target_chip_id(&htm->target); if (chip_id == -1) { PR_ERROR("Couldn't find a chip id\n"); return NULL; @@ -990,7 +990,7 @@ static int do_htm_dump(struct htm *htm, char *filename) return -1; } - chip_id = dt_get_chip_id(&htm->target); + chip_id = pdbg_target_chip_id(&htm->target); if (chip_id == -1) return -1; diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index f638fd2..07947cb 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -150,6 +150,21 @@ int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint3 return 0; } +uint32_t pdbg_target_chip_id(struct pdbg_target *target) +{ + uint32_t id; + + while (pdbg_target_u32_property(target, "chip-id", &id)) { + target = target->parent; + + /* If we hit this we've reached the top of the tree + * and haven't found chip-id */ + assert(target); + } + + return id; +} + void pdbg_progress_tick(uint64_t cur, uint64_t end) { if (progress_tick) diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 8d8f0a3..4a21671 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -82,6 +82,10 @@ uint64_t pdbg_get_address(struct pdbg_target *target, uint64_t *size); #define pdbg_get_target_property(target, name, size) \ pdbg_target_property(target, name, size) +/* Find an chip-id property in this node; if not found, walk up the parent + * nodes. Returns -1 if no chip-id property exists. */ +uint32_t pdbg_target_chip_id(struct pdbg_target *node); + /* Misc. */ void pdbg_targets_init(void *fdt); void pdbg_target_probe_all(struct pdbg_target *parent); From patchwork Wed Nov 7 05:39:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994118 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZzM0qLzz9sCX for ; Wed, 7 Nov 2018 16:41:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZzL60v9zF3FX for ; Wed, 7 Nov 2018 16:41:34 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxb4hRJzF3GX for ; Wed, 7 Nov 2018 16:40:03 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxb1MK0z9sCX; Wed, 7 Nov 2018 16:40:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:39 +1100 Message-Id: <20181107053943.4307-13-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 12/16] libpdbg: Rework target addressing 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Clean up the target addressing functions and rename them to be consistent with other libpdbg function names. Signed-off-by: Alistair Popple Reviewed-by: Amitay Isaacs --- 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@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@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; From patchwork Wed Nov 7 05:39:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZzP0yvTz9s8T for ; Wed, 7 Nov 2018 16:41:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZzN6M6RzF3Gl for ; Wed, 7 Nov 2018 16:41:36 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxc28xVzF3GT for ; Wed, 7 Nov 2018 16:40:04 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxb63Cpz9s8T; Wed, 7 Nov 2018 16:40:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:40 +1100 Message-Id: <20181107053943.4307-14-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 13/16] libpdbg: Remove old dt_prop functions 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" The dt_prop functions were copied over from Skiboot. Rework and rename these to make use of the existing libpdbg property functions. These should not have been used by external projects so maintaining backwards compatibility is not a concern. Signed-off-by: Alistair Popple --- libpdbg/bmcfsi.c | 37 ++++++++++++++++++++++++------------- libpdbg/cfam.c | 2 +- libpdbg/device.c | 38 +------------------------------------- libpdbg/device.h | 7 ------- libpdbg/i2c.c | 5 ++++- libpdbg/libpdbg.c | 16 ++++++++++++++++ libpdbg/libpdbg.h | 1 + libpdbg/p9chip.c | 4 +++- 8 files changed, 50 insertions(+), 60 deletions(-) diff --git a/libpdbg/bmcfsi.c b/libpdbg/bmcfsi.c index b57e029..a233106 100644 --- a/libpdbg/bmcfsi.c +++ b/libpdbg/bmcfsi.c @@ -42,7 +42,7 @@ * address offset */ struct gpio_pin { uint32_t offset; - int bit; + uint32_t bit; }; enum gpio { @@ -71,7 +71,7 @@ enum fsi_result { FSI_ERR_C = 0x3, }; -static int clock_delay = 0; +static uint32_t clock_delay = 0; #define FSI_DATA0_REG 0x1000 #define FSI_DATA1_REG 0x1001 @@ -459,17 +459,28 @@ int bmcfsi_probe(struct pdbg_target *target) } if (!gpio_reg) { - gpio_pins[GPIO_FSI_CLK].offset = dt_prop_get_u32_index(target, "fsi_clk", 0); - gpio_pins[GPIO_FSI_CLK].bit = dt_prop_get_u32_index(target, "fsi_clk", 1); - gpio_pins[GPIO_FSI_DAT].offset = dt_prop_get_u32_index(target, "fsi_dat", 0); - gpio_pins[GPIO_FSI_DAT].bit = dt_prop_get_u32_index(target, "fsi_dat", 1); - gpio_pins[GPIO_FSI_DAT_EN].offset = dt_prop_get_u32_index(target, "fsi_dat_en", 0); - gpio_pins[GPIO_FSI_DAT_EN].bit = dt_prop_get_u32_index(target, "fsi_dat_en", 1); - gpio_pins[GPIO_FSI_ENABLE].offset = dt_prop_get_u32_index(target, "fsi_enable", 0); - gpio_pins[GPIO_FSI_ENABLE].bit = dt_prop_get_u32_index(target, "fsi_enable", 1); - gpio_pins[GPIO_CRONUS_SEL].offset = dt_prop_get_u32_index(target, "cronus_sel", 0); - gpio_pins[GPIO_CRONUS_SEL].bit = dt_prop_get_u32_index(target, "cronus_sel", 1); - clock_delay = dt_prop_get_u32(target, "clock_delay"); + assert(!(pdbg_target_u32_index(target, "fsi_clk", 0, + &gpio_pins[GPIO_FSI_CLK].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_clk", 1, + &gpio_pins[GPIO_FSI_CLK].bit))); + assert(!(pdbg_target_u32_index(target, "fsi_dat", 0, + &gpio_pins[GPIO_FSI_DAT].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_dat", 1, + &gpio_pins[GPIO_FSI_DAT].bit))); + assert(!(pdbg_target_u32_index(target, "fsi_dat_en", 0, + &gpio_pins[GPIO_FSI_DAT_EN].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_dat_en", 1, + &gpio_pins[GPIO_FSI_DAT_EN].bit))); + assert(!(pdbg_target_u32_index(target, "fsi_enable", 0, + &gpio_pins[GPIO_FSI_ENABLE].offset))); + assert(!(pdbg_target_u32_index(target, "fsi_enable", 1, + &gpio_pins[GPIO_FSI_ENABLE].bit))); + assert(!(pdbg_target_u32_index(target, "cronus_sel", 0, + &gpio_pins[GPIO_CRONUS_SEL].offset))); + assert(!(pdbg_target_u32_index(target, "cronus_sel", 1, + &gpio_pins[GPIO_CRONUS_SEL].bit))); + assert(!(pdbg_target_u32_property(target, "clock_delay", + &clock_delay))); /* We only have to do this init once per backend */ gpio_reg = mmap(NULL, getpagesize(), diff --git a/libpdbg/cfam.c b/libpdbg/cfam.c index 67ab22e..c9bdf3b 100644 --- a/libpdbg/cfam.c +++ b/libpdbg/cfam.c @@ -317,7 +317,7 @@ static int cfam_hmfsi_probe(struct pdbg_target *target) int rc; /* Enable the port in the upstream control register */ - port = dt_prop_get_u32(target, "port"); + assert(!(pdbg_target_u32_property(target, "port", &port))); fsi_read(fsi_parent, 0x3404, &value); value |= 1 << (31 - port); if ((rc = fsi_write(fsi_parent, 0x3404, value))) { diff --git a/libpdbg/device.c b/libpdbg/device.c index 5cd8302..288891b 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -501,14 +501,7 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, return NULL; } -u32 dt_prop_get_u32(const struct pdbg_target *node, const char *prop) -{ - const struct dt_property *p = dt_require_property(node, prop, 4); - - return dt_property_get_cell(p, 0); -} - -static u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) +static uint32_t dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) { const struct dt_property *p = dt_find_property(node, prop); @@ -518,35 +511,6 @@ static u32 dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, return dt_property_get_cell(p, 0); } -u32 dt_prop_get_u32_index(const struct pdbg_target *node, const char *prop, u32 index) -{ - const struct dt_property *p = dt_require_property(node, prop, -1); - - return dt_property_get_cell(p, index); -} - -const void *dt_prop_get(const struct pdbg_target *node, const char *prop) -{ - const struct dt_property *p = dt_require_property(node, prop, -1); - - return p->prop; -} - -const void *dt_prop_get_def(const struct pdbg_target *node, const char *prop, - void *def) -{ - const struct dt_property *p = dt_find_property(node, prop); - - return p ? p->prop : def; -} - -u32 dt_prop_get_cell(const struct pdbg_target *node, const char *prop, u32 cell) -{ - const struct dt_property *p = dt_require_property(node, prop, -1); - - return dt_property_get_cell(p, cell); -} - static enum pdbg_target_status str_to_status(const char *status) { if (!strcmp(status, "enabled")) { diff --git a/libpdbg/device.h b/libpdbg/device.h index 29224a2..ac265e9 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -37,11 +37,4 @@ struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, for (node = NULL; \ (node = dt_find_compatible_node(root, node, compat)) != NULL;) -/* 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); -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); - #endif /* __DEVICE_H */ diff --git a/libpdbg/i2c.c b/libpdbg/i2c.c index 9cb6271..f1c6ea9 100644 --- a/libpdbg/i2c.c +++ b/libpdbg/i2c.c @@ -130,7 +130,10 @@ int i2c_target_probe(struct pdbg_target *target) const char *bus; int addr; - bus = dt_prop_get_def(&pib->target, "bus", "/dev/i2c4"); + bus = pdbg_target_property(&pib->target, "bus", NULL); + if (!bus) + bus = "/dev/i2c4"; + addr = pdbg_target_address(&pib->target, NULL); assert(addr); diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 07947cb..b59590d 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -150,6 +150,22 @@ int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint3 return 0; } +int pdbg_target_u32_index(struct pdbg_target *target, const char *name, int index, uint32_t *val) +{ + size_t len; + void *p; + + p = pdbg_get_target_property(target, name, &len); + if (!p) + return -1; + + assert(len >= (index+1)*sizeof(u32)); + + /* Always aligned, so this works. */ + *val = be32toh(((const u32 *)p)[index]); + return 0; +} + uint32_t pdbg_target_chip_id(struct pdbg_target *target) { uint32_t id; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index f8fe3e8..6108af9 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -73,6 +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); +int pdbg_target_u32_index(struct pdbg_target *target, const char *name, int index, uint32_t *val); 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 diff --git a/libpdbg/p9chip.c b/libpdbg/p9chip.c index 2411103..9d43725 100644 --- a/libpdbg/p9chip.c +++ b/libpdbg/p9chip.c @@ -118,8 +118,10 @@ static struct thread_state p9_get_thread_status(struct thread *thread) static int p9_thread_probe(struct pdbg_target *target) { struct thread *thread = target_to_thread(target); + uint32_t tid; - thread->id = dt_prop_get_u32(target, "tid"); + assert(!pdbg_target_u32_property(target, "tid", &tid)); + thread->id = tid; thread->status = p9_get_thread_status(thread); return 0; From patchwork Wed Nov 7 05:39:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994120 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZzR1zwnz9s8T for ; Wed, 7 Nov 2018 16:41:39 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZzR0JddzF3Gn for ; Wed, 7 Nov 2018 16:41:39 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxc5fljzF3GP for ; Wed, 7 Nov 2018 16:40:04 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxc3WFWz9sCX; Wed, 7 Nov 2018 16:40:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:41 +1100 Message-Id: <20181107053943.4307-15-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 14/16] libpdbg: Rework target compatible 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Rework the target compatible code to reuse existing libpdbg code where possible. Renames and exports these functions for use by external libraries. Signed-off-by: Alistair Popple --- libpdbg/device.c | 48 ++++++++++++++++++++++-------------------------- libpdbg/device.h | 12 ------------ libpdbg/htm.c | 8 ++++---- libpdbg/libpdbg.h | 8 ++++++++ libpdbg/p8chip.c | 2 +- 5 files changed, 35 insertions(+), 43 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 288891b..acc6da2 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -464,41 +464,37 @@ static const struct dt_property *dt_require_property(const struct pdbg_target *n return p; } -bool dt_prop_find_string(const struct dt_property *p, const char *s) +bool pdbg_target_compatible(struct pdbg_target *target, const char *compatible) { - const char *c, *end; + char *c, *end; + size_t len; - if (!p) - return false; - c = p->prop; - end = c + p->len; + c = pdbg_get_target_property(target, "compatible", &len); + if (!c) + return false; - while(c < end) { - if (!strcasecmp(s, c)) - return true; - c += strlen(c) + 1; - } - return false; -} + end = c + len; + while(c < end) { + if (!strcasecmp(compatible, c)) + return true; -bool dt_node_is_compatible(const struct pdbg_target *node, const char *compat) -{ - const struct dt_property *p = dt_find_property(node, "compatible"); + c += strlen(c) + 1; + } - return dt_prop_find_string(p, compat); + return false; } -struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, - struct pdbg_target *prev, - const char *compat) +struct pdbg_target *__pdbg_next_compatible_node(struct pdbg_target *root, + struct pdbg_target *prev, + const char *compat) { - struct pdbg_target *node; + struct pdbg_target *target; - node = prev ? dt_next(root, prev) : root; - for (; node; node = dt_next(root, node)) - if (dt_node_is_compatible(node, compat)) - return node; - return NULL; + target = prev ? dt_next(root, prev) : root; + for (; target; target = dt_next(root, target)) + if (pdbg_target_compatible(target, compat)) + return target; + return NULL; } static uint32_t dt_prop_get_u32_def(const struct pdbg_target *node, const char *prop, u32 def) diff --git a/libpdbg/device.h b/libpdbg/device.h index ac265e9..92d7da3 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -25,16 +25,4 @@ extern struct pdbg_target *dt_root; -/* Check a compatible property */ -bool dt_node_is_compatible(const struct pdbg_target *node, const char *compat); - -/* Find a node based on compatible property */ -struct pdbg_target *dt_find_compatible_node(struct pdbg_target *root, - struct pdbg_target *prev, - const char *compat); - -#define dt_for_each_compatible(root, node, compat) \ - for (node = NULL; \ - (node = dt_find_compatible_node(root, node, compat)) != NULL;) - #endif /* __DEVICE_H */ diff --git a/libpdbg/htm.c b/libpdbg/htm.c index 1ea2c3a..5f9dd85 100644 --- a/libpdbg/htm.c +++ b/libpdbg/htm.c @@ -520,7 +520,7 @@ static int configure_nhtm(struct htm *htm, bool wrap) NHTM_TTYPE_SIZE_MASK ))) /* no pattern matching */ return -1; - if (dt_node_is_compatible(&htm->target, "ibm,power9-nhtm")) { + if (pdbg_target_compatible(&htm->target, "ibm,power9-nhtm")) { if (HTM_ERR(pib_read(&htm->target, NHTM_FLEX_MUX, &val))) return -1; @@ -740,7 +740,7 @@ static int htm_toggle_debug_bit(struct htm *htm) return 0; /* nhtm case */ /* FIXME: this is a hack for P8 */ - if (!dt_node_is_compatible(core, "ibm,power8-core")) { + if (!pdbg_target_compatible(core, "ibm,power8-core")) { PR_ERROR("HTM is POWER8 only currently\n"); return -1; } @@ -867,7 +867,7 @@ static int do_htm_status(struct htm *htm) uint64_t val, total; int i, regs = 9; - if (dt_node_is_compatible(&htm->target, "ibm,power9-nhtm")) + if (pdbg_target_compatible(&htm->target, "ibm,power9-nhtm")) regs++; PR_INFO("HTM register dump:\n"); @@ -1101,7 +1101,7 @@ static int nhtm_probe(struct pdbg_target *target) if (!is_debugfs_memtrace_ok() || !is_debugfs_scom_ok()) return -1; - if (dt_node_is_compatible(target, "ibm,power9-nhtm")) { + if (pdbg_target_compatible(target, "ibm,power9-nhtm")) { pib_read(target, NHTM_FLEX_MUX, &val); if (GETFIELD(NHTM_FLEX_MUX_MASK, val) != NHTM_FLEX_DEFAULT) { PR_DEBUG("FLEX_MUX not default\n"); diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 6108af9..b61a75c 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -12,6 +12,9 @@ struct pdbg_target; struct pdbg_target_class; /* loops/iterators */ +struct pdbg_target *__pdbg_next_compatible_node(struct pdbg_target *root, + struct pdbg_target *prev, + const char *compat); struct pdbg_target *__pdbg_next_target(const char *klass, struct pdbg_target *parent, struct pdbg_target *last); struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct pdbg_target *last); @@ -45,6 +48,10 @@ enum pdbg_target_status {PDBG_TARGET_UNKNOWN = 0, PDBG_TARGET_ENABLED, PDBG_TARGET_DISABLED, PDBG_TARGET_MUSTEXIST, PDBG_TARGET_NONEXISTENT, PDBG_TARGET_RELEASED}; +#define pdbg_for_each_compatible(parent, target, compat) \ + for (target = NULL; \ + (target = __pdbg_next_compatible_node(parent, target, compat)) != NULL;) + #define pdbg_for_each_target(class, parent, target) \ for (target = __pdbg_next_target(class, parent, NULL); \ target; \ @@ -106,6 +113,7 @@ const char *pdbg_target_dn_name(struct pdbg_target *target); void *pdbg_target_priv(struct pdbg_target *target); void pdbg_target_priv_set(struct pdbg_target *target, void *priv); struct pdbg_target *pdbg_target_root(void); +bool pdbg_target_compatible(struct pdbg_target *target, const char *compatible); /* Procedures */ int fsi_read(struct pdbg_target *target, uint32_t addr, uint32_t *val); diff --git a/libpdbg/p8chip.c b/libpdbg/p8chip.c index f3e71a0..914c335 100644 --- a/libpdbg/p8chip.c +++ b/libpdbg/p8chip.c @@ -355,7 +355,7 @@ static int p8_ram_setup(struct thread *thread) /* We can only ram a thread if all the threads on the core/chip are * quiesced */ - dt_for_each_compatible(&chip->target, target, "ibm,power8-thread") { + pdbg_for_each_compatible(&chip->target, target, "ibm,power8-thread") { struct thread *tmp; /* If this thread wasn't enabled it may not yet have been probed From patchwork Wed Nov 7 05:39:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994121 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZzT25s7z9sCX for ; Wed, 7 Nov 2018 16:41:41 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZzT0DzRzF3Gn for ; Wed, 7 Nov 2018 16:41:41 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxd31DqzF3GP for ; Wed, 7 Nov 2018 16:40:05 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxc70Gmz9s8T; Wed, 7 Nov 2018 16:40:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:42 +1100 Message-Id: <20181107053943.4307-16-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 15/16] libpdbg: Make dt_root private 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Alistair Popple Reviewed-by: Amitay Isaacs --- libpdbg/device.c | 13 +++++++++---- libpdbg/device.h | 2 -- libpdbg/target.c | 9 ++------- src/main.c | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index acc6da2..8e58135 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -36,7 +36,7 @@ /* Used to give unique handles. */ static u32 last_phandle = 0; -struct pdbg_target *dt_root; +static struct pdbg_target *pdbg_dt_root; /* * An in-memory representation of a node in the device tree. @@ -590,7 +590,7 @@ static void dt_expand(const void *fdt) { PR_DEBUG("FDT: Parsing fdt @%p\n", fdt); - if (dt_expand_node(dt_root, fdt, 0) < 0) + if (dt_expand_node(pdbg_dt_root, fdt, 0) < 0) abort(); } @@ -636,7 +636,7 @@ uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *out_size) void pdbg_targets_init(void *fdt) { - dt_root = dt_new_node("", NULL, 0); + pdbg_dt_root = dt_new_node("", NULL, 0); dt_expand(fdt); } @@ -648,7 +648,12 @@ char *pdbg_target_path(const struct pdbg_target *target) struct pdbg_target *pdbg_target_from_path(struct pdbg_target *target, const char *path) { if (!target) - target = dt_root; + target = pdbg_dt_root; return dt_find_by_path(target, path); } + +struct pdbg_target *pdbg_target_root(void) +{ + return pdbg_dt_root; +} diff --git a/libpdbg/device.h b/libpdbg/device.h index 92d7da3..4a4a06f 100644 --- a/libpdbg/device.h +++ b/libpdbg/device.h @@ -23,6 +23,4 @@ /* Any property or node with this prefix will not be passed to the kernel. */ #define DT_PRIVATE "skiboot," -extern struct pdbg_target *dt_root; - #endif /* __DEVICE_H */ diff --git a/libpdbg/target.c b/libpdbg/target.c index 5599d78..5ebe71d 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -31,7 +31,7 @@ static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, con /* The root node doesn't have an address space so it's * an error in the device tree if we hit this. */ - assert(target != dt_root); + assert(target != pdbg_target_root()); } return target; @@ -365,7 +365,7 @@ void pdbg_target_probe_all(struct pdbg_target *parent) struct pdbg_target *child; if (!parent) - parent = dt_root; + parent = pdbg_target_root(); pdbg_for_each_child_target(parent, child) { pdbg_target_probe_all(child); @@ -389,8 +389,3 @@ void pdbg_target_priv_set(struct pdbg_target *target, void *priv) { target->priv = priv; } - -struct pdbg_target *pdbg_target_root(void) -{ - return dt_root; -} diff --git a/src/main.c b/src/main.c index 40fa48b..5d0c0e3 100644 --- a/src/main.c +++ b/src/main.c @@ -791,7 +791,7 @@ OPTCMD_DEFINE_CMD(probe, probe); */ static void atexit_release(void) { - pdbg_target_release(dt_root); + pdbg_target_release(pdbg_target_root()); } int main(int argc, char *argv[]) From patchwork Wed Nov 7 05:39:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 994122 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qZzW1KyLz9sDB for ; Wed, 7 Nov 2018 16:41:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42qZzV6lKvzF3Gd for ; Wed, 7 Nov 2018 16:41:42 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42qZxf0QbJzF3G9 for ; Wed, 7 Nov 2018 16:40:06 +1100 (AEDT) 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42qZxd4Jqcz9sCX; Wed, 7 Nov 2018 16:40:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 7 Nov 2018 16:39:43 +1100 Message-Id: <20181107053943.4307-17-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181107053943.4307-1-alistair@popple.id.au> References: <20181107053943.4307-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH v2 16/16] libpdbg: Remove device.h 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: , Cc: amitay@ozlabs.org MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Alistair Popple Reviewed-by: Amitay Isaacs --- Makefile.am | 1 - libpdbg/bmcfsi.c | 1 - libpdbg/device.c | 6 ++++-- libpdbg/device.h | 26 -------------------------- libpdbg/libpdbg.c | 1 - libpdbg/libpdbg.h | 2 ++ libpdbg/target.c | 1 - libpdbg/target.h | 1 - src/htm.c | 1 - 9 files changed, 6 insertions(+), 34 deletions(-) delete mode 100644 libpdbg/device.h diff --git a/Makefile.am b/Makefile.am index ad2bbec..b8f38ca 100644 --- a/Makefile.am +++ b/Makefile.am @@ -151,7 +151,6 @@ libpdbg_la_SOURCES = \ libpdbg/debug.c \ libpdbg/debug.h \ libpdbg/device.c \ - libpdbg/device.h \ libpdbg/fake.c \ libpdbg/host.c \ libpdbg/htm.c \ diff --git a/libpdbg/bmcfsi.c b/libpdbg/bmcfsi.c index a233106..f9cee3d 100644 --- a/libpdbg/bmcfsi.c +++ b/libpdbg/bmcfsi.c @@ -27,7 +27,6 @@ #include "bitutils.h" #include "operations.h" -#include "device.h" #include "target.h" #include "debug.h" diff --git a/libpdbg/device.c b/libpdbg/device.c index 8e58135..cce5ccf 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -14,17 +14,19 @@ * limitations under the License. */ -#include "device.h" #include #include #include #include "target.h" #include #include +#include +#include #include #include #include "debug.h" +#include "compiler.h" #define zalloc(size) calloc(1, size) #define prerror printf @@ -34,7 +36,7 @@ list_for_each(&parent->children, node, list) /* Used to give unique handles. */ -static u32 last_phandle = 0; +static uint32_t last_phandle = 0; static struct pdbg_target *pdbg_dt_root; diff --git a/libpdbg/device.h b/libpdbg/device.h deleted file mode 100644 index 4a4a06f..0000000 --- a/libpdbg/device.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2013-2014 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __DEVICE_H -#define __DEVICE_H -#include -#include -#include "compiler.h" - -/* Any property or node with this prefix will not be passed to the kernel. */ -#define DT_PRIVATE "skiboot," - -#endif /* __DEVICE_H */ diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index b59590d..13acaa8 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -1,7 +1,6 @@ #include #include "target.h" -#include "device.h" #include "libpdbg.h" static pdbg_progress_tick_t progress_tick; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index b61a75c..069f87e 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -8,6 +8,8 @@ #include +#include + struct pdbg_target; struct pdbg_target_class; diff --git a/libpdbg/target.c b/libpdbg/target.c index 5ebe71d..1fc8457 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -7,7 +7,6 @@ #include "bitutils.h" #include "target.h" -#include "device.h" #include "operations.h" #include "debug.h" diff --git a/libpdbg/target.h b/libpdbg/target.h index 258c576..7cc855d 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -21,7 +21,6 @@ #include #include #include "compiler.h" -#include "device.h" #include "libpdbg.h" enum chip_type {CHIP_UNKNOWN, CHIP_P8, CHIP_P8NV, CHIP_P9}; diff --git a/src/htm.c b/src/htm.c index 8dd7303..10e35ae 100644 --- a/src/htm.c +++ b/src/htm.c @@ -34,7 +34,6 @@ #include #include -#include #include #include "main.h"