From patchwork Wed Jan 15 05:18:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFxX6Yr8z9sR0 for ; Wed, 15 Jan 2020 16:19:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=dC6AlaGg; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47yFxX5Gl9zDqRg for ; Wed, 15 Jan 2020 16:19:28 +1100 (AEDT) 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) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47yFxK2Mm9zDqFS for ; Wed, 15 Jan 2020 16:19:17 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=dC6AlaGg; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 47yFxJ75g4z9sRm; Wed, 15 Jan 2020 16:19:16 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065557; bh=yyt4lY4j6060Lq9vWz4gedLV8XxzErvfgSMs9hsEJyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dC6AlaGgN4RIPU47K5Rt2TVQg+Ak6ydOJnNI7f2DQzL9msrFYF46uktxYmGTVLSEV GPFetopmakermW/rVax7nRsouFn30AQAXu0rgFneuWR3zNxphyzxZBYABLxgPxppoS ww0+i0FzU3OhLvaAYGM1q8Cke/wrLPOxObj33oTKZWHC21Jlj+7/qptp2GxH6+R3Ea ETdCM9WZdUapuRFQIxO3miL7J7XzdiXeKLEwnGFtXU7AGp8MmkKvh+lcjElG4PBQKz xsSLt4+bdLXA66wnfH+BVBZc90U/AON5n7s7lRARjwPOdu+DgGsrYmAMIZ8a3aGBqj NYgOBVT1WjDdA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:52 +1100 Message-Id: <20200115051901.17514-5-amitay@ozlabs.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200115051901.17514-1-amitay@ozlabs.org> References: <20200115051901.17514-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH 04/13] libpdbg: Cache device trees globally 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 Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/device.c | 17 +++++++++++------ libpdbg/dtb.c | 13 +++++++++---- libpdbg/target.h | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index ac2351d..6599171 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -754,11 +754,16 @@ skip: bool pdbg_targets_init(void *fdt) { - struct pdbg_dtb dtb; + struct pdbg_dtb *dtb; - pdbg_default_dtb(&dtb, fdt); + dtb = pdbg_default_dtb(fdt); - if (!dtb.system) { + if (!dtb) { + pdbg_log(PDBG_ERROR, "Could not determine system\n"); + return false; + } + + if (!dtb->system) { pdbg_log(PDBG_ERROR, "Could not find a system device tree\n"); return false; } @@ -768,10 +773,10 @@ bool pdbg_targets_init(void *fdt) if (!pdbg_dt_root) return false; - if (dtb.backend) - dt_expand(pdbg_dt_root, dtb.backend); + if (dtb->backend) + dt_expand(pdbg_dt_root, dtb->backend); - dt_expand(pdbg_dt_root, dtb.system); + dt_expand(pdbg_dt_root, dtb->system); pdbg_targets_init_virtual(pdbg_dt_root, pdbg_dt_root); return true; diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index 18b5a6f..ab5ef4c 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -58,6 +58,7 @@ static enum pdbg_backend pdbg_backend = PDBG_DEFAULT_BACKEND; static const char *pdbg_backend_option; +static struct pdbg_dtb pdbg_dtb; /* Determines the most appropriate backend for the host system we are * running on. */ @@ -276,8 +277,9 @@ const char *pdbg_get_backend_option(void) /* Determines what platform we are running on and returns a pointer to * the fdt that is most likely to work on the system. */ -void pdbg_default_dtb(struct pdbg_dtb *dtb, void *system_fdt) +struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) { + struct pdbg_dtb *dtb = &pdbg_dtb; char *fdt; *dtb = (struct pdbg_dtb) { @@ -294,7 +296,7 @@ void pdbg_default_dtb(struct pdbg_dtb *dtb, void *system_fdt) dtb->system = mmap_dtb(fdt, false); if (dtb->backend && dtb->system) - return; + goto done; if (!pdbg_backend) pdbg_backend = default_backend(); @@ -322,7 +324,7 @@ void pdbg_default_dtb(struct pdbg_dtb *dtb, void *system_fdt) if (!pdbg_backend_option) { pdbg_log(PDBG_ERROR, "No system type specified\n"); pdbg_log(PDBG_ERROR, "Use 'p8' or 'p9r/p9w/p9z'\n"); - return; + return NULL; } if (!strcmp(pdbg_backend_option, "p8")) { @@ -355,7 +357,7 @@ void pdbg_default_dtb(struct pdbg_dtb *dtb, void *system_fdt) if (!pdbg_backend_option) { pdbg_log(PDBG_ERROR, "No system type specified\n"); pdbg_log(PDBG_ERROR, "Use p8@ or p9@\n"); - return; + return NULL; } if (!strncmp(pdbg_backend_option, "p8", 2)) { @@ -382,4 +384,7 @@ void pdbg_default_dtb(struct pdbg_dtb *dtb, void *system_fdt) dtb->system = &_binary_fake_dtb_o_start; break; } + +done: + return dtb; } diff --git a/libpdbg/target.h b/libpdbg/target.h index f068e8d..25fdbad 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -71,7 +71,7 @@ bool pdbg_target_is_class(struct pdbg_target *target, const char *class); extern struct list_head empty_list; extern struct list_head target_classes; -void pdbg_default_dtb(struct pdbg_dtb *pdtb, void *system_fdt); +struct pdbg_dtb *pdbg_default_dtb(void *system_fdt); const char *pdbg_get_backend_option(void); struct chipop *pib_to_chipop(struct pdbg_target *target);