From patchwork Tue Oct 23 03:35:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 988010 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42fJvX4F9Sz9sDb for ; Tue, 23 Oct 2018 14:36:08 +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 42fJvX1y63zDrqN for ; Tue, 23 Oct 2018 14:36: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 [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42fJtx0203zDrqN for ; Tue, 23 Oct 2018 14:35:37 +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 42fJtw3qGHz9sDb; Tue, 23 Oct 2018 14:35:36 +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: Tue, 23 Oct 2018 14:35:25 +1100 Message-Id: <20181023033528.31256-7-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 Subject: [Pdbg] [PATCH] 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: , 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 --- 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 fbcf792..8e8c381 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 c8da048..1cb6b13 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;