From patchwork Wed Jan 15 05:18:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223177 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFxl36kwz9sRV for ; Wed, 15 Jan 2020 16:19:39 +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=jgTcJTDM; 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 47yFxl1KLHzDqFS for ; Wed, 15 Jan 2020 16:19:39 +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) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47yFxJ2jdGzDqDt for ; Wed, 15 Jan 2020 16:19:16 +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=jgTcJTDM; 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 47yFxH4h2Dz9sR0; Wed, 15 Jan 2020 16:19:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065555; bh=1+t/10GFgPymrk1k+mY6k4TYOuMfp+x5hdNYDbIUHTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jgTcJTDMO207EYEV/WKIa3ze1GOTsCG86IneUDXzz/38NF9Ui8yHWJ7eBz7n1xphw 3QF2CNz0Sogk9h7UXBmc519NWGC4UdqOClkB0yYKtkdv/Ae+SemDmReOjDScGlHUoC 4yz1MDiBCAGrfgqvuRzFf3jL15yhdicdbUYhuKOx4jn6IFEMqnzcnMoyyG34SDbTz1 Gy+8rrQ040D8cEFW/yhkeMRMitTPDKxdGLCmoDZxChipPqNU9FiB1b0OnuNP8MrrMu XChxdD3SH+TFb8zJ2zhtfvijymkRWjXmtTO029pqlZkDKsAUxhgIGOCxFDLUB4mlKT KWdnKsiV8bfQg== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:49 +1100 Message-Id: <20200115051901.17514-2-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 01/13] libpdbg: Cache device tree pointer and offset for each node 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 | 9 ++++++--- libpdbg/target.h | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index ad498dc..ac2351d 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -115,7 +115,7 @@ static struct pdbg_target *dt_pdbg_target_new(const void *fdt, int node_offset) return target; } -static 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, void *fdt, int node_offset) { struct pdbg_target *node = NULL; size_t size = sizeof(*node); @@ -131,6 +131,9 @@ static struct pdbg_target *dt_new_node(const char *name, const void *fdt, int no abort(); } + node->fdt = fdt; + node->fdt_offset = fdt ? node_offset : -1; + node->dn_name = take_name(name); node->parent = NULL; list_head_init(&node->properties); @@ -547,7 +550,7 @@ static enum pdbg_target_status str_to_status(const char *status) assert(0); } -static int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_node) +static int dt_expand_node(struct pdbg_target *node, void *fdt, int fdt_node) { const struct fdt_property *prop; int offset, nextoffset, err; @@ -604,7 +607,7 @@ static int dt_expand_node(struct pdbg_target *node, const void *fdt, int fdt_nod return nextoffset; } -static void dt_expand(struct pdbg_target *root, const void *fdt) +static void dt_expand(struct pdbg_target *root, void *fdt) { PR_DEBUG("FDT: Parsing fdt @%p\n", fdt); diff --git a/libpdbg/target.h b/libpdbg/target.h index a8f777d..9e25a43 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -39,6 +39,8 @@ struct pdbg_target { int (*probe)(struct pdbg_target *target); void (*release)(struct pdbg_target *target); uint64_t (*translate)(struct pdbg_target *target, uint64_t addr); + void *fdt; + int fdt_offset; int index; enum pdbg_target_status status; const char *dn_name; From patchwork Wed Jan 15 05:18:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223175 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFxd0ttRz9sRV for ; Wed, 15 Jan 2020 16:19:33 +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=gBq4qyUd; 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 47yFxc6mgkzDqRs for ; Wed, 15 Jan 2020 16:19:32 +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 47yFxJ4jmZzDqF7 for ; Wed, 15 Jan 2020 16:19:16 +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=gBq4qyUd; 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 47yFxJ0JGtz9sRQ; Wed, 15 Jan 2020 16:19:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065556; bh=JY18HdekopakfI76J5jb7sQ+jvYlWgVoHcV5sKheZt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gBq4qyUd0YuZla2WX09PDxz3+2+/LBf+N3OEkb5Gylemimur53ghzO6ViiJWSgkSa TYtyGLZIPL5BZ8onc34VUycSB5F7FcplcOU554n7tjlB7Wi7Mhr74PVo2q7eI0hHHf Av4wTAQeampOD3rZ9B+U8NnOErghtrBbcpzcRD4xYMd4nnhmU2Uxzg0jNv3YP+pppz RwkQBiTfZvgn2ygADYLgrCTEnyGsezmd967dO38zJBIOQllDEdQC0WfZeyKEFHDkVC RyxHcwawRySzUQFrCY9kmRMYFUwgYMCW0ZsYu1dn9Vfx9YFsE+gY70mLu635Dy6Y5y YkLSGpbiYTLXg== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:50 +1100 Message-Id: <20200115051901.17514-3-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 02/13] libpdbg: Map external device trees read-write by default 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/dtb.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index 53f4393..18b5a6f 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -220,13 +220,16 @@ static void bmc_target(struct pdbg_dtb *dtb) } /* Opens a dtb at the given path */ -static void *mmap_dtb(char *file) +static void *mmap_dtb(char *file, bool readonly) { int fd; void *dtb; struct stat statbuf; - fd = open(file, O_RDONLY); + if (readonly) + fd = open(file, O_RDONLY); + else + fd = open(file, O_RDWR); if (fd < 0) { pdbg_log(PDBG_ERROR, "Unable to open dtb file '%s'\n", file); return NULL; @@ -237,7 +240,10 @@ static void *mmap_dtb(char *file) goto fail; } - dtb = mmap(NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (readonly) + dtb = mmap(NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + else + dtb = mmap(NULL, statbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (dtb == MAP_FAILED) { pdbg_log(PDBG_ERROR, "Failed top mmap file '%s'\n", file); goto fail; @@ -281,11 +287,11 @@ void pdbg_default_dtb(struct pdbg_dtb *dtb, void *system_fdt) fdt = getenv("PDBG_BACKEND_DTB"); if (fdt) - dtb->backend = mmap_dtb(fdt); + dtb->backend = mmap_dtb(fdt, false); fdt = getenv("PDBG_DTB"); if (fdt) - dtb->system = mmap_dtb(fdt); + dtb->system = mmap_dtb(fdt, false); if (dtb->backend && dtb->system) return; From patchwork Wed Jan 15 05:18:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223176 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFxh70Jtz9sR0 for ; Wed, 15 Jan 2020 16:19:36 +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=pRqSGFnJ; 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 47yFxh5dGSzDqRg for ; Wed, 15 Jan 2020 16:19:36 +1100 (AEDT) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47yFxJ6jy9zDqFF for ; Wed, 15 Jan 2020 16:19:16 +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=pRqSGFnJ; 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 47yFxJ473Xz9sRV; 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=1579065556; bh=3ahlkONwBpUzi4R/szJ8siAWUf30BxLJGYJosTsNCUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pRqSGFnJUNcGUZEy2Vxnw8h+yWEOGoS3OeBAcQ/oiBI0SV5uukGG9OzFk8oXpAaik KKnrsHfETcAsPXTZLBNW/4CEjAKZvKI2Yd+N1cyvL/aY0CjJmGJpE43Fgi//OLvJOD X0o5U2zWkmtdPzgfRCBi80wu1p4dLmQPj9CQgPI236+j/w8DH3sKed/hiUb/KVKksD JxTn39WbS5IIwzTYbSJWSC6H+tJ3G74TjydaO7XKC+YF9r8FsJ53nES6uxgZpCOG9b V0obRLl0lmQbuuwVKzE58tWj6LbxCaWBOQcmHCymey1u72NZGOVgGCBFq2/aWIodwc MHC/8X9/7f+HA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:51 +1100 Message-Id: <20200115051901.17514-4-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 03/13] Revert "libpdbg.h: Expose method to read fdt pointer" 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" This reverts commit 376e498fb5a69afd5a2a0349bd3a37dd774a225e. Instead of exposing the internal structures, add an api to get system device tree. Reviewed-by: Alistair Popple --- libpdbg/libpdbg.h | 5 ----- libpdbg/target.h | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 6fd16f3..4a8f1cf 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -102,11 +102,6 @@ uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *size); (index == 0 ? pdbg_target_address(target, size) : assert(0)) /* Misc. */ -struct pdbg_dtb { - void *backend; - void *system; -}; -void pdbg_default_dtb(struct pdbg_dtb *pdtb, void *system_fdt); bool pdbg_targets_init(void *fdt); void pdbg_target_probe_all(struct pdbg_target *parent); enum pdbg_target_status pdbg_target_probe(struct pdbg_target *target); diff --git a/libpdbg/target.h b/libpdbg/target.h index 9e25a43..f068e8d 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -55,6 +55,11 @@ struct pdbg_target { struct pdbg_target *vnode; }; +struct pdbg_dtb { + void *backend; + void *system; +}; + struct pdbg_target *get_parent(struct pdbg_target *target, bool system); struct pdbg_target *target_parent(const char *klass, struct pdbg_target *target, bool system); struct pdbg_target *require_target_parent(const char *klass, struct pdbg_target *target, bool system); @@ -66,6 +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); const char *pdbg_get_backend_option(void); struct chipop *pib_to_chipop(struct pdbg_target *target); 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); From patchwork Wed Jan 15 05:18:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223179 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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFxt2jDtz9sR0 for ; Wed, 15 Jan 2020 16:19:46 +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=vbPcylA+; 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 47yFxt03TKzDqDl for ; Wed, 15 Jan 2020 16:19:46 +1100 (AEDT) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47yFxL1fCPzDqDt for ; Wed, 15 Jan 2020 16:19:18 +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=vbPcylA+; 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 47yFxK3b49z9sNx; Wed, 15 Jan 2020 16:19:17 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065557; bh=7u7S3BoWW8u543r1I4lAMp+bguudDtd+34O/7kfj9TE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vbPcylA+KcRAf9GI+Ly5smvhcYoNDuQVvhPTEMxMVvd70VctUs9L5FVs6v97QoBuf laNdnXhBDEE0+rZWfNP/SpWjZPnSm7soJPDaZj10r/kOnWmdkRDsruUiKCTbM8c3aT mIzH7YfGrBva4a/tMj9LcCZUCcgxnuXhRSMrJrJ454FV2woLgtVQN5ekVFBjdd2s52 ruF8IfIMAdIPSZnIj0kPcj/OAqKVrSTHNQ5PjvhSIcE34HtrVDAZN2qhTVplBZ6z44 ytV0qGkA5tE7vXutdNUo8mVEP+nGGFiTmmCygKU1/si+WQqZYhXT4rb4fHnyfad4ZK ZQf9BdTvaFpjw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:53 +1100 Message-Id: <20200115051901.17514-6-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 05/13] libpdbg: Add an api to get system device tree 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 --- libpdbg/dtb.c | 5 +++++ libpdbg/libpdbg.h | 1 + 2 files changed, 6 insertions(+) diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index ab5ef4c..6825055 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -388,3 +388,8 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) done: return dtb; } + +void *pdbg_system_fdt(void) +{ + return pdbg_dtb.system; +} diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 4a8f1cf..be0aa09 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -103,6 +103,7 @@ uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *size); /* Misc. */ bool pdbg_targets_init(void *fdt); +void *pdbg_system_fdt(void); void pdbg_target_probe_all(struct pdbg_target *parent); enum pdbg_target_status pdbg_target_probe(struct pdbg_target *target); void pdbg_target_release(struct pdbg_target *target); From patchwork Wed Jan 15 05:18:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223180 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFxz4LKhz9sR0 for ; Wed, 15 Jan 2020 16:19:51 +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=QxfdGQ60; 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 47yFxz3CLdzDqJt for ; Wed, 15 Jan 2020 16:19:51 +1100 (AEDT) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47yFxL5vFCzDqDl for ; Wed, 15 Jan 2020 16:19:18 +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=QxfdGQ60; 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 47yFxL317dz9sRQ; Wed, 15 Jan 2020 16:19:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065558; bh=1pji8siBD021UxUzWYB+4McDw+DYAzFLEgOQrl7c95o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QxfdGQ60pBQdnJJ7FjQ3NVANezqUOzTpM8WnvmNrsN9nzrqg4bGfnL0jfO56QChn3 lqEvGePtUNUyT8PxB+59emU5ZsKauiHbM2/gZPY9MCbXjzKMOgj+38eKBsRGRvSEyb IiW8VQ6dkIEWZtiEvyr4jDZrG3/UdRiSXhwGaFhs7NyYACQKpwUtAU6eMDoBUoqM8l HkcNJL+HFrMeLbzIosTrKP/Feo7BWIgXfxDGZyNTYYh1076pvqVe0MZCX7RAAMHTaG tPx7joc0OJdXohzlLRP4LFYOpd1nnr0TQDyH7uBlggWm2Tht0sV9TTKC6K/3oqjqD4 qfFiaq1foDEcw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:54 +1100 Message-Id: <20200115051901.17514-7-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 06/13] libpdbg: Restrict set_property to updating existing 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 Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Device tree properties are going to be always accessed from dtb, so unless the property already exists and has the exact size, it cannot be updated. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/device.c | 22 ++++++---------------- libpdbg/libpdbg.h | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 6599171..91ad258 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -384,31 +384,21 @@ static struct dt_property *dt_add_property(struct pdbg_target *node, return p; } -static void dt_resize_property(struct dt_property **prop, size_t len) -{ - size_t new_len = sizeof(**prop) + len; - - *prop = realloc(*prop, new_len); - - /* Fix up linked lists in case we moved. (note: not an empty list). */ - (*prop)->list.next->prev = &(*prop)->list; - (*prop)->list.prev->next = &(*prop)->list; -} - -void pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size) +bool pdbg_target_set_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; + if (size != p->len) { + return false; } memcpy(p->prop, val, size); } else { - dt_add_property(target, name, val, size); + return false; } + + return true; } void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size) diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index be0aa09..d28fd90 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -84,7 +84,7 @@ struct pdbg_target *pdbg_target_parent_virtual(const char *klass, struct pdbg_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_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size); +bool 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_target_property(struct pdbg_target *target, const char *name, size_t *size); From patchwork Wed Jan 15 05:18:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223181 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) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFy45bczz9sRm for ; Wed, 15 Jan 2020 16:19:56 +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=wo4tNGHD; 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 47yFy447SnzDqJt for ; Wed, 15 Jan 2020 16:19:56 +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 47yFxM2k1mzDqDl for ; Wed, 15 Jan 2020 16:19:19 +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=wo4tNGHD; 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 47yFxM0KFnz9sNx; Wed, 15 Jan 2020 16:19:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065559; bh=8KCpcMrKySd0KuiJlt9WFxgF7JWZH8xQ29OmOF0sMhI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wo4tNGHDEsauLVfv/qSOcNJNXxRY1bbBpa8kWbemXW33T40oQ+FTTcRoLNMFb2Ujp V3Oxo7/aR0f3qhofsh/Omf7qLEOUYjuQ8OaL6rnAwsjsX/bfCi62ADv8HkCd4toRES PoWSqlrzLVXICWmMHUsjKHoLIif525/ciF2t8k98IOyLkr/iq9r4xr5Z84kll+ZgnQ oJuAFXKXC2lJAX/uzaJpED2Mf2V94olVuY+vcOxarO2+HDx0xhCQwwrrv/Vyk3c76I e6g5q3ti3dYaoGwJ+Iw6IoVIJlUQYFKCogWLwPYfpnWIjZRLqr6CidLFkogUCYtLCR w88ZgOrrJen5g== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:55 +1100 Message-Id: <20200115051901.17514-8-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 07/13] libpdbg: Do not store properties in linked list 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" ... instead the properties will be accessed directly from the device tree. dt_add_property(), in addition to adding properties to a linked list, assigned value to phandle if defined in device tree. So change the name of the function to reflect the functionality. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/device.c | 54 +++--------------------------------------------- 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 91ad258..c5fdc4e 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -331,40 +331,9 @@ static struct dt_property *dt_find_property(const struct pdbg_target *node, return NULL; } -static struct dt_property *new_property(struct pdbg_target *node, - const char *name, size_t size) +static void dt_add_phandle(struct pdbg_target *node, const char *name, + const void *val, size_t size) { - struct dt_property *p = malloc(sizeof(*p) + size); - char *path; - - if (!p) { - path = dt_get_path(node); - prerror("Failed to allocate property \"%s\" for %s of %zu bytes\n", - name, path, size); - free(path); - abort(); - } - if (dt_find_property(node, name)) { - path = dt_get_path(node); - prerror("Duplicate property \"%s\" in node %s\n", - name, path); - free(path); - abort(); - - } - - p->name = take_name(name); - p->len = size; - list_add_tail(&node->properties, &p->list); - return p; -} - -static struct dt_property *dt_add_property(struct pdbg_target *node, - const char *name, - const void *val, size_t size) -{ - struct dt_property *p; - /* * Filter out phandle properties, we re-generate them * when flattening @@ -375,13 +344,7 @@ static struct dt_property *dt_add_property(struct pdbg_target *node, node->phandle = *(const u32 *)val; if (node->phandle >= last_phandle) last_phandle = node->phandle; - return NULL; } - - p = new_property(node, name, size); - if (size) - memcpy(p->prop, val, size); - return p; } bool pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size) @@ -573,7 +536,7 @@ static int dt_expand_node(struct pdbg_target *node, void *fdt, int fdt_node) if (strcmp("status", name) == 0) node->status = str_to_status(prop->data); - dt_add_property(node, name, prop->data, + dt_add_phandle(node, name, prop->data, fdt32_to_cpu(prop->len)); break; case FDT_BEGIN_NODE: @@ -684,19 +647,8 @@ static struct pdbg_target *dt_new_virtual(struct pdbg_target *root, const char * static void dt_link_virtual(struct pdbg_target *node, struct pdbg_target *vnode) { - struct dt_property *prop = NULL, *next; - node->vnode = vnode; vnode->vnode = node; - - /* Move any properties on virtual node to real node */ - list_for_each_safe(&vnode->properties, prop, next, list) { - if (!strcmp(prop->name, "#address-cells") || !strcmp(prop->name, "#size-cells")) - continue; - - list_del(&prop->list); - list_add_tail(&node->properties, &prop->list); - } } static void pdbg_targets_init_virtual(struct pdbg_target *node, struct pdbg_target *root) From patchwork Wed Jan 15 05:18:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223182 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) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFy74rCcz9sRV for ; Wed, 15 Jan 2020 16:19:59 +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=fzbXnowQ; 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 47yFy71TNzzDqQd for ; Wed, 15 Jan 2020 16:19:59 +1100 (AEDT) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47yFxM65VZzDqDl for ; Wed, 15 Jan 2020 16:19:19 +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=fzbXnowQ; 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 47yFxM3Jv3z9sRQ; Wed, 15 Jan 2020 16:19:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065559; bh=dgFTnDP8qd7xQ5xBLdp8KPackcGma3kBSzoV6OaNm04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fzbXnowQvVcMLTFOtd7Oew80y+2f31+T0ULyhz2cpGeNnjcTMBqKW+208dAqGbsDY Ble4G1rVat0G8VA+ofvPauvELVCI0FW11gu6ymawb0QGch0zsoZ+eTAJ+nS2rRidNI v2NC7ZMEDj3FV7qrsk2XKLRqgWMOolKjaQlzgEKzWTHsH4wCbW58HEeT+0h+vOQwSP iXKWuLNJJjR2MVeBIufccJ/XyriY9/6ooAYA0idHN/NOsQ+7qJ9XXcwqukIbaZsg7r qR7/AGHWf5SvTBTNmd1sUAknlno1cPT4H8xP4bq+Ci2y/d/KFiqPiMMQ9KAoN/kZJ2 gJww+rDb1HZUA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:56 +1100 Message-Id: <20200115051901.17514-9-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 08/13] libpdbg: Read/write properties directly from/to device tree 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 | 46 +++++++++++++++++++++++++++------------------- libpdbg/libpdbg.c | 8 ++++---- libpdbg/libpdbg.h | 2 +- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index c5fdc4e..76d6b3e 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -349,34 +349,42 @@ static void dt_add_phandle(struct pdbg_target *node, const char *name, bool pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size) { - struct dt_property *p; + const void *p; + size_t len; + int ret; - if ((p = dt_find_property(target, name))) { - if (size != p->len) { - return false; - } + p = pdbg_target_property(target, name, &len); + if (!p) + return false; - memcpy(p->prop, val, size); - } else { + if (len != size) + return false; + + ret = fdt_setprop_inplace(target->fdt, target->fdt_offset, name, val, size); + if (ret) return false; - } return true; } -void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size) +const void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size) { - struct dt_property *p; + const void *buf; + int buflen; - p = dt_find_property(target, name); - if (p) { - if (size) - *size = p->len; - return p->prop; - } else if (size) + if (target->fdt_offset == -1) { *size = 0; + return NULL; + } - return NULL; + buf = fdt_getprop(target->fdt, target->fdt_offset, name, &buflen); + if (!buf) { + *size = 0; + return NULL; + } + + *size = buflen; + return buf; } static u32 dt_property_get_cell(const struct dt_property *prop, u32 index) @@ -439,10 +447,10 @@ static const struct dt_property *dt_require_property(struct pdbg_target *node, bool pdbg_target_compatible(struct pdbg_target *target, const char *compatible) { - char *c, *end; + const char *c, *end; size_t len; - c = pdbg_target_property(target, "compatible", &len); + c = (const char *)pdbg_target_property(target, "compatible", &len); if (!c) return false; diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 9f7b4cc..8af6a02 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -270,7 +270,7 @@ const char *pdbg_target_dn_name(struct pdbg_target *target) int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint32_t *val) { - uint32_t *p; + const void *p; size_t size; p = pdbg_get_target_property(target, name, &size); @@ -278,15 +278,15 @@ int pdbg_target_u32_property(struct pdbg_target *target, const char *name, uint3 return -1; assert(size == 4); - *val = be32toh(*p); + *val = be32toh(*(uint32_t *)p); return 0; } int pdbg_target_u32_index(struct pdbg_target *target, const char *name, int index, uint32_t *val) { + const void *p; size_t len; - uint32_t *p; p = pdbg_get_target_property(target, name, &len); if (!p) @@ -298,7 +298,7 @@ int pdbg_target_u32_index(struct pdbg_target *target, const char *name, int inde assert(!((uintptr_t) p & 0x3)); /* Always aligned, so this works. */ - *val = be32toh(p[index]); + *val = be32toh(((uint32_t *)p)[index]); return 0; } diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index d28fd90..f07d7d1 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -87,7 +87,7 @@ struct pdbg_target *pdbg_target_require_parent(const char *klass, struct pdbg_ta bool 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_target_property(struct pdbg_target *target, const char *name, size_t *size); +const 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); From patchwork Wed Jan 15 05:18:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223183 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) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFyJ6qSRz9sNx for ; Wed, 15 Jan 2020 16:20:08 +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=gfDwQttT; 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 47yFyJ04HmzDqS0 for ; Wed, 15 Jan 2020 16:20:08 +1100 (AEDT) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47yFxN39mrzDqDl for ; Wed, 15 Jan 2020 16:19:20 +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=gfDwQttT; 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 47yFxM6rpMz9sNx; Wed, 15 Jan 2020 16:19:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065560; bh=HQxsyKrssLKkokS2oDnU6+xBmvZf4FRP1TbyKSLnPWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gfDwQttTD+Lo8FOkPod7Ek/OB2A/G9QV15d7iDabmIiPQwZ/Tb+koSOPHDgSopIs5 6qJR6Sy2zJhQbZ1JTVJTjwN9WkbdOJQSZNpg1DIurlVH7d8DTWzC+iAwawJEYq9PD0 QeK96+RcJ6TO+ljk7XMpZngj6lAx8GXv4VsT+Ah7kxNhotxrVZ7TmV0KYlYQTKEIvK 0+tbE6Cpj9DM4+29/m2BFtRIWiFwWgWGgB6v28HAiba1D5PeO6Hwp85pjFvXqLZQZ/ BpbK6+5XT5n5IDeQj0QASaHVohVUiSEvh6YX2qz2VsnV+IlpboQh3DVa4DXmOcAnSV +iVfw2q2N5o7A== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:57 +1100 Message-Id: <20200115051901.17514-10-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 09/13] libpdbg: Instead of dt_find_property(), use pdbg_target_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 Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" This avoids the use of struct dt_property, which will be removed later. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/device.c | 54 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 76d6b3e..b60b0aa 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -320,17 +320,6 @@ again: return target_to_real(root, false); } -static struct dt_property *dt_find_property(const struct pdbg_target *node, - const char *name) -{ - struct dt_property *i = NULL; - - list_for_each(&node->properties, i, list) - if (strcmp(i->name, name) == 0) - return i; - return NULL; -} - static void dt_add_phandle(struct pdbg_target *node, const char *name, const void *val, size_t size) { @@ -387,11 +376,11 @@ const void *pdbg_target_property(struct pdbg_target *target, const char *name, s return buf; } -static u32 dt_property_get_cell(const struct dt_property *prop, u32 index) +static u32 dt_property_get_cell(const void *prop, size_t len, u32 index) { - assert(prop->len >= (index+1)*sizeof(u32)); + assert(len >= (index+1)*sizeof(u32)); /* Always aligned, so this works. */ - return fdt32_to_cpu(((const u32 *)prop->prop)[index]); + return fdt32_to_cpu(((const u32 *)prop)[index]); } /* First child of this node. */ @@ -420,11 +409,14 @@ static struct pdbg_target *dt_next(const struct pdbg_target *root, return NULL; } -static const struct dt_property *dt_require_property(struct pdbg_target *node, - const char *name, int wanted_len) +static const void *dt_require_property(struct pdbg_target *node, + const char *name, int wanted_len, + size_t *prop_len) { - const struct dt_property *p = dt_find_property(node, name); + const void *p; + size_t len; + p = pdbg_target_property(node, name, &len); if (!p) { const char *path = dt_get_path(node); @@ -432,16 +424,19 @@ static const struct dt_property *dt_require_property(struct pdbg_target *node, path, name); assert(false); } - if (wanted_len >= 0 && p->len != wanted_len) { + if (wanted_len >= 0 && len != wanted_len) { const char *path = dt_get_path(node); prerror("DT: Unexpected property length %s/%s\n", path, name); prerror("DT: Expected len: %d got len: %zu\n", - wanted_len, p->len); + wanted_len, len); assert(false); } + if (prop_len) { + *prop_len = len; + } return p; } @@ -478,15 +473,18 @@ struct pdbg_target *__pdbg_next_compatible_node(struct pdbg_target *root, return NULL; } -static uint32_t dt_prop_get_u32_def(const struct pdbg_target *node, +static uint32_t dt_prop_get_u32_def(struct pdbg_target *node, const char *prop, uint32_t def) { - const struct dt_property *p = dt_find_property(node, prop); + const void *p; + size_t len; + p = pdbg_target_property(node, prop, &len); if (!p) return def; - return dt_property_get_cell(p, 0); + + return dt_property_get_cell(p, len, 0); } static enum pdbg_target_status str_to_status(const char *status) @@ -602,17 +600,19 @@ static u32 dt_n_size_cells(const struct pdbg_target *node) uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *out_size) { - const struct dt_property *p; + const void *p; + size_t len; + u32 na = dt_n_address_cells(target); u32 ns = dt_n_size_cells(target); u32 n; - p = dt_require_property(target, "reg", -1); + p = dt_require_property(target, "reg", -1, &len); n = (na + ns) * sizeof(u32); - assert(n <= p->len); + assert(n <= len); if (out_size) - *out_size = dt_get_number(p->prop + na * sizeof(u32), ns); - return dt_get_number(p->prop, na); + *out_size = dt_get_number(p + na * sizeof(u32), ns); + return dt_get_number(p, na); } static struct pdbg_target *dt_new_virtual(struct pdbg_target *root, const char *system_path) From patchwork Wed Jan 15 05:18:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223184 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) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFyM0LwQz9sNx for ; Wed, 15 Jan 2020 16:20:11 +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=v57rExiH; 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 47yFyL6wBRzDqSB for ; Wed, 15 Jan 2020 16:20:10 +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 47yFxN6QwqzDqDl for ; Wed, 15 Jan 2020 16:19:20 +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=v57rExiH; 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 47yFxN45sZz9sRQ; Wed, 15 Jan 2020 16:19:20 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065560; bh=YtNEgIecSyv4YsxrnHnp0Gg7m9jVsJqw+Q6zWh/nujA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v57rExiHVNvnMACaCjyYM0tcbaOhpD4DhacWRVSZmuxHB3hopnS4/VENh2Bgh9ofg o/iMbJv0T/hu6Wd4yl/cc2JfwlvU5IH/mlvIifEHeRdwydqpdncXS190x9NNPHoz/d cG9uVQ2/GTCSbzBNB9Ogdmlg7vi4DVm1c6PcF7eEak5ZzHpXch7RLM5Gu1iod6xNDt Uc2vKmroSsQ5GVJGoJwzHd3x+KZeuF+dTVltJ9q/BeTy2yeGvbsv6lFD75D+G0iayx lX+lsZoJddwyyTn/M1XXDYa/1JGfwMNmeFNh+plwZ+tscMmMudOjZ4bESuwl6xSzpJ Y9M9fEjLo2Zrg== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:58 +1100 Message-Id: <20200115051901.17514-11-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 10/13] libpdbg: Drop unused struct dt_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 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 | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index b60b0aa..6deeec5 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -40,21 +40,6 @@ static uint32_t last_phandle = 0; static struct pdbg_target *pdbg_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))) { From patchwork Wed Jan 15 05:18:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223185 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) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFyQ5BGXz9sR0 for ; Wed, 15 Jan 2020 16:20:14 +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=mySSLxH3; 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 47yFyQ0wfczDqS2 for ; Wed, 15 Jan 2020 16:20:14 +1100 (AEDT) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47yFxP6BxRzDqDt for ; Wed, 15 Jan 2020 16:19:21 +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=mySSLxH3; 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 47yFxP0M8qz9sNx; Wed, 15 Jan 2020 16:19:20 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065561; bh=H6k5EovpAE7IL+zKAXVLHfgdsPwwZcv9HB9dspMgP60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mySSLxH35ig2iUcFpTh5cIcrNaKRulNUln/lig188o0SRnG97kd70AUVXx5Q7mcQ4 EOej7UlL2ValflyDXifHarkXMEUODPMHSL6eaa/kfiHUDTlZT1k1/FJD63EJzbvgI0 ZViDhtsOC5WwhY5m/TznPQXFVXnCecieuyCokzlr8Wtn4XBqZW+iF1DgRb9YrCb17I 2T3DPncpTPydIxlcUBeuFJB/YV525nPIpaIrowE6z4aEMjhi4/26jogRjTgT431CX6 rrrXXfsWEzQeCThbdQDsd6ywAKiWonn8KVeeb88O7Lzso91W6wqBmWJFQUROLyJnQV 9kHRSsmNOOhrg== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:18:59 +1100 Message-Id: <20200115051901.17514-12-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 11/13] libpdbg: Properly close the mmaped files on exit 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 | 8 +-- libpdbg/dtb.c | 180 ++++++++++++++++++++++++++++------------------- libpdbg/target.h | 10 ++- 3 files changed, 118 insertions(+), 80 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index 6deeec5..6c11836 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -698,7 +698,7 @@ bool pdbg_targets_init(void *fdt) return false; } - if (!dtb->system) { + if (!dtb->system.fdt) { pdbg_log(PDBG_ERROR, "Could not find a system device tree\n"); return false; } @@ -708,10 +708,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.fdt) + dt_expand(pdbg_dt_root, dtb->backend.fdt); - dt_expand(pdbg_dt_root, dtb->system); + dt_expand(pdbg_dt_root, dtb->system.fdt); pdbg_targets_init_virtual(pdbg_dt_root, pdbg_dt_root); return true; diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index 6825055..6fdce00 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -58,7 +58,16 @@ static enum pdbg_backend pdbg_backend = PDBG_DEFAULT_BACKEND; static const char *pdbg_backend_option; -static struct pdbg_dtb pdbg_dtb; +static struct pdbg_dtb pdbg_dtb = { + .backend = { + .fd = -1, + .len = -1, + }, + .system = { + .fd = -1, + .len = -1, + }, +}; /* Determines the most appropriate backend for the host system we are * running on. */ @@ -90,15 +99,15 @@ static void ppc_target(struct pdbg_dtb *dtb) if (pdbg_backend_option) { if (!strcmp(pdbg_backend_option, "p8")) { - if (!dtb->backend) - dtb->backend = &_binary_p8_host_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p8_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p8_host_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p8_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p9")) { - if (!dtb->backend) - dtb->backend = &_binary_p9_host_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p9_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p9_host_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; } else { pdbg_log(PDBG_ERROR, "Invalid system type %s\n", pdbg_backend_option); pdbg_log(PDBG_ERROR, "Use 'p8' or 'p9'\n"); @@ -132,16 +141,16 @@ static void ppc_target(struct pdbg_dtb *dtb) if (strncmp(pos, "POWER8", 6) == 0) { pdbg_log(PDBG_INFO, "Found a POWER8 PPC host system\n"); - if (!dtb->backend) - dtb->backend = &_binary_p8_host_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p8_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p8_host_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p8_dtb_o_start; } else if (strncmp(pos, "POWER9", 6) == 0) { pdbg_log(PDBG_INFO, "Found a POWER9 PPC host system\n"); - if (!dtb->backend) - dtb->backend = &_binary_p9_host_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p9_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p9_host_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; } else { pdbg_log(PDBG_ERROR, "Unsupported CPU type '%s'\n", pos); } @@ -157,15 +166,15 @@ static void bmc_target(struct pdbg_dtb *dtb) if (pdbg_backend_option) { if (!strcmp(pdbg_backend_option, "p8")) { - if (!dtb->backend) - dtb->backend = &_binary_p8_kernel_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p8_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p8_kernel_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p8_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p9")) { - if (!dtb->backend) - dtb->backend = &_binary_p9_kernel_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p9_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p9_kernel_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; } else { pdbg_log(PDBG_ERROR, "Invalid system type %s\n", pdbg_backend_option); pdbg_log(PDBG_ERROR, "Use 'p8' or 'p9'\n"); @@ -200,19 +209,19 @@ static void bmc_target(struct pdbg_dtb *dtb) switch(chip_id) { case CHIP_ID_P9: pdbg_log(PDBG_INFO, "Found a POWER9 OpenBMC based system\n"); - if (!dtb->backend) - dtb->backend = &_binary_p9_kernel_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p9_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p9_kernel_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; break; case CHIP_ID_P8: case CHIP_ID_P8P: pdbg_log(PDBG_INFO, "Found a POWER8/8+ OpenBMC based system\n"); - if (!dtb->backend) - dtb->backend = &_binary_p8_kernel_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p8_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p8_kernel_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p8_dtb_o_start; break; default: @@ -221,19 +230,24 @@ static void bmc_target(struct pdbg_dtb *dtb) } /* Opens a dtb at the given path */ -static void *mmap_dtb(char *file, bool readonly) +static void mmap_dtb(char *file, bool readonly, struct pdbg_mfile *mfile) { int fd; void *dtb; struct stat statbuf; + *mfile = (struct pdbg_mfile) { + .fd = -1, + .len = -1, + }; + if (readonly) fd = open(file, O_RDONLY); else fd = open(file, O_RDWR); if (fd < 0) { pdbg_log(PDBG_ERROR, "Unable to open dtb file '%s'\n", file); - return NULL; + return; } if (fstat(fd, &statbuf) == -1) { @@ -250,11 +264,15 @@ static void *mmap_dtb(char *file, bool readonly) goto fail; } - return dtb; + *mfile = (struct pdbg_mfile) { + .fd = fd, + .len = statbuf.st_size, + .fdt = dtb, + }; + return; fail: close(fd); - return NULL; } bool pdbg_set_backend(enum pdbg_backend backend, const char *backend_option) @@ -282,20 +300,18 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) struct pdbg_dtb *dtb = &pdbg_dtb; char *fdt; - *dtb = (struct pdbg_dtb) { - .backend = NULL, - .system = system_fdt, - }; + dtb->backend.fdt = NULL; + dtb->system.fdt = system_fdt; fdt = getenv("PDBG_BACKEND_DTB"); if (fdt) - dtb->backend = mmap_dtb(fdt, false); + mmap_dtb(fdt, false, &dtb->backend); fdt = getenv("PDBG_DTB"); if (fdt) - dtb->system = mmap_dtb(fdt, false); + mmap_dtb(fdt, false, &dtb->system); - if (dtb->backend && dtb->system) + if (dtb->backend.fdt && dtb->system.fdt) goto done; if (!pdbg_backend) @@ -308,12 +324,12 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) case PDBG_BACKEND_I2C: /* I2C is only supported on POWER8 */ - if (!dtb->backend) { + if (!dtb->backend.fdt) { pdbg_log(PDBG_INFO, "Found a POWER8 AMI BMC based system\n"); - dtb->backend = &_binary_p8_i2c_dtb_o_start; + dtb->backend.fdt = &_binary_p8_i2c_dtb_o_start; } - if (!dtb->system) - dtb->system = &_binary_p8_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p8_dtb_o_start; break; case PDBG_BACKEND_KERNEL: @@ -328,25 +344,25 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) } if (!strcmp(pdbg_backend_option, "p8")) { - if (!dtb->backend) - dtb->backend = &_binary_p8_fsi_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p8_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p8_fsi_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p8_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p9w")) { - if (!dtb->backend) - dtb->backend = &_binary_p9w_fsi_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p9_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p9w_fsi_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p9r")) { - if (!dtb->backend) - dtb->backend = &_binary_p9r_fsi_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p9_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p9r_fsi_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p9z")) { - if (!dtb->backend) - dtb->backend = &_binary_p9z_fsi_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p9_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p9z_fsi_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; } else { pdbg_log(PDBG_ERROR, "Invalid system type %s\n", pdbg_backend_option); pdbg_log(PDBG_ERROR, "Use 'p8' or 'p9r/p9w/p9z'\n"); @@ -361,15 +377,15 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) } if (!strncmp(pdbg_backend_option, "p8", 2)) { - if (!dtb->backend) - dtb->backend = &_binary_p8_cronus_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p8_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p8_cronus_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p8_dtb_o_start; } else if (!strncmp(pdbg_backend_option, "p9", 2)) { - if (!dtb->backend) - dtb->backend = &_binary_p9_cronus_dtb_o_start; - if (!dtb->system) - dtb->system = &_binary_p9_dtb_o_start; + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_p9_cronus_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; } else { pdbg_log(PDBG_ERROR, "Invalid system type %s\n", pdbg_backend_option); pdbg_log(PDBG_ERROR, "Use p8@ or p9@\n"); @@ -381,7 +397,8 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) /* Fall through */ case PDBG_BACKEND_FAKE: - dtb->system = &_binary_fake_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_fake_dtb_o_start; break; } @@ -391,5 +408,20 @@ done: void *pdbg_system_fdt(void) { - return pdbg_dtb.system; + return pdbg_dtb.system.fdt; +} + +static void close_dtb(struct pdbg_mfile *mfile) +{ + if (mfile->fd != -1 && mfile->len != -1 && mfile->fdt) { + munmap(mfile->fdt, mfile->len); + close(mfile->fd); + } +} + +__attribute__((destructor)) +static void pdbg_close_targets(void) +{ + close_dtb(&pdbg_dtb.backend); + close_dtb(&pdbg_dtb.system); } diff --git a/libpdbg/target.h b/libpdbg/target.h index 25fdbad..1c08363 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -55,9 +55,15 @@ struct pdbg_target { struct pdbg_target *vnode; }; +struct pdbg_mfile { + int fd; + ssize_t len; + void *fdt; +}; + struct pdbg_dtb { - void *backend; - void *system; + struct pdbg_mfile backend; + struct pdbg_mfile system; }; struct pdbg_target *get_parent(struct pdbg_target *target, bool system); From patchwork Wed Jan 15 05:19:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223186 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) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFyT3zhyz9sRV for ; Wed, 15 Jan 2020 16:20:17 +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=ebpLNn/I; 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 47yFyT2tdczDqS3 for ; Wed, 15 Jan 2020 16:20:17 +1100 (AEDT) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47yFxQ3cYHzDqDl for ; Wed, 15 Jan 2020 16:19:22 +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=ebpLNn/I; 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 47yFxQ03X9z9sRm; Wed, 15 Jan 2020 16:19:21 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065562; bh=kFC5yTegi64nIyPWTZkWr487LmVS1oWks4t6tYQyVgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ebpLNn/INU3YSsG79y3VqTuoRjW7DPKdiKpblOO9yOsxhSxgagrLnFYKHaa2vsKvz xl4ltigbfbQJLjrAWJgnrMfBGS64wvmmIXMZ0TA9uGw1WgBNF+ndIeSCGmNLqgnPf8 96UhLg25uzd5TeJwTdrLaYvAypeAhDZYROxgDRyo4m1LwjyGo5cLlvJG3VyBTeeByI Lv9a5SZm3A55rvg7dU8UyzISGdejSWdgoDJYxVUgykhWFhh+rD15wciC22P8cAGGxX S/jfOWNvFRJ9YKxxRwvBwipfkL9rIgrhSpzye0K10/ofYYPMILE5Bg4cOGyRKM4nL6 6z7Z1IhX7HFGg== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:19:00 +1100 Message-Id: <20200115051901.17514-13-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 12/13] libpdbg: Add a check if device tree is writeable 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 | 3 +++ libpdbg/dtb.c | 20 ++++++++++++++++++++ libpdbg/target.h | 1 + 3 files changed, 24 insertions(+) diff --git a/libpdbg/device.c b/libpdbg/device.c index 6c11836..f1c1f6b 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -327,6 +327,9 @@ bool pdbg_target_set_property(struct pdbg_target *target, const char *name, cons size_t len; int ret; + if (!target->fdt || !pdbg_fdt_is_writeable(target->fdt)) + return false; + p = pdbg_target_property(target, name, &len); if (!p) return false; diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index 6fdce00..6e05663 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -411,6 +411,26 @@ void *pdbg_system_fdt(void) return pdbg_dtb.system.fdt; } +static bool is_fdt_mapped(void *fdt, struct pdbg_mfile *mfile) +{ + if (mfile->fdt == fdt && mfile->fd != -1 && mfile->len != -1) { + return true; + } + + return false; +} + +bool pdbg_fdt_is_writeable(void *fdt) +{ + bool ok; + + ok = is_fdt_mapped(fdt, &pdbg_dtb.system); + if (!ok) + ok = is_fdt_mapped(fdt, &pdbg_dtb.backend); + + return ok; +} + static void close_dtb(struct pdbg_mfile *mfile) { if (mfile->fd != -1 && mfile->len != -1 && mfile->fdt) { diff --git a/libpdbg/target.h b/libpdbg/target.h index 1c08363..2ecdfce 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -79,6 +79,7 @@ extern struct list_head target_classes; struct pdbg_dtb *pdbg_default_dtb(void *system_fdt); const char *pdbg_get_backend_option(void); +bool pdbg_fdt_is_writeable(void *fdt); struct chipop *pib_to_chipop(struct pdbg_target *target); bool target_is_virtual(struct pdbg_target *target); From patchwork Wed Jan 15 05:19:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1223187 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yFyY28Cqz9sRV for ; Wed, 15 Jan 2020 16:20:21 +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=Js6kwF6R; 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 47yFyY0VZ1zDqFF for ; Wed, 15 Jan 2020 16:20:21 +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 47yFxR0RQQzDqDl for ; Wed, 15 Jan 2020 16:19:23 +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=Js6kwF6R; 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 47yFxQ59dgz9sNx; Wed, 15 Jan 2020 16:19:22 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1579065562; bh=BHBCJQpyLzqGDTb5Yw39FFAW9ZnfGFKHsa0nGSO2AuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Js6kwF6Ru6Pw69CtipsQ51fmayODIdTj1end3b9X6NxjyMdzbxRtCX0cvmV4Y54qE VnfcgNZ3y6XDb2hy6m3sCj+vKEw3yTDvBmDWtTmlCZzzQUjxRB1KQrlauFMQN4GWgu V1pq4jUTCcJNHMWrtooPLyGZCnPfzWMLcwDw3sCihUh3w/MUibBiC/IybnfPI1IzJs t3NLGnF4VaRz7ek0IH2C0u2jFoiiu+WtLwfym1RqEAzgOUqk/bjMB8JGvHcPeipdcM JLLGmXs1PvXhuJr4UdAlcWkJUWWDfCgSo636ox9ixegaTra097dW6i/9kXlf23gRQb GcXEzzQtYvyrA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 15 Jan 2020 16:19:01 +1100 Message-Id: <20200115051901.17514-14-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 13/13] tests: Add test for libpdbg property api 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 --- Makefile.am | 10 ++- fake.dts.m4 | 2 + src/tests/libpdbg_prop_test.c | 120 ++++++++++++++++++++++++++++++++++ tests/test_prop.sh | 55 ++++++++++++++++ 4 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/tests/libpdbg_prop_test.c create mode 100755 tests/test_prop.sh diff --git a/Makefile.am b/Makefile.am index db93faf..a4ca5f3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,7 +17,8 @@ libpdbg_tests = libpdbg_target_test \ bin_PROGRAMS = pdbg check_PROGRAMS = $(libpdbg_tests) libpdbg_dtree_test \ libpdbg_p9_fapi_translation_test \ - optcmd_test hexdump_test cronus_proxy + optcmd_test hexdump_test cronus_proxy \ + libpdbg_prop_test PDBG_TESTS = \ tests/test_selection.sh \ @@ -26,11 +27,13 @@ PDBG_TESTS = \ tests/test_hexdump.sh \ tests/test_tree.sh \ tests/test_tree2.sh \ + tests/test_prop.sh \ tests/test_p9_fapi_translation.sh TESTS = $(libpdbg_tests) optcmd_test $(PDBG_TESTS) tests/test_tree2.sh: fake2.dtb +tests/test_prop.sh: fake.dtb test: $(libpdbg_tests) @@ -266,6 +269,11 @@ libpdbg_p9_fapi_translation_test_LDFLAGS = $(libpdbg_test_ldflags) libpdbg_p9_fapi_translation_test_LDADD = $(libpdbg_test_ldadd) EXTRA_libpdbg_p9_fapi_translation_test_DEPENDENCIES = p9.dtb p9-kernel.dtb +libpdbg_prop_test_SOURCES = src/tests/libpdbg_prop_test.c +libpdbg_prop_test_CFLAGS = $(libpdbg_test_cflags) +libpdbg_prop_test_LDFLAGS = $(libpdbg_test_ldflags) +libpdbg_prop_test_LDADD = $(libpdbg_test_ldadd) + M4_V = $(M4_V_$(V)) M4_V_ = $(M4_V_$(AM_DEFAULT_VERBOSITY)) M4_V_0 = @echo " M4 " $@; diff --git a/fake.dts.m4 b/fake.dts.m4 index a099154..3d49bef 100644 --- a/fake.dts.m4 +++ b/fake.dts.m4 @@ -91,6 +91,8 @@ define(`dump_backend',dnl system-path = "/proc$1/pib"; reg = ; index = <0x$1>; + ATTR1 = <0xc0ffee>; + ATTR2 = "processor$1"; }; }; diff --git a/src/tests/libpdbg_prop_test.c b/src/tests/libpdbg_prop_test.c new file mode 100644 index 0000000..c916dcc --- /dev/null +++ b/src/tests/libpdbg_prop_test.c @@ -0,0 +1,120 @@ +/* Copyright 2020 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 + +static void usage(void) +{ + fprintf(stderr, "Usage: libpdbg_fdt_test read char|int\n"); + fprintf(stderr, " libpdbg_fdt_test write char|int \n"); + exit(1); +} + +int main(int argc, const char **argv) +{ + struct pdbg_target *target; + const char *path, *prop, *prop_value = NULL; + bool do_read = false, do_write = false; + bool is_int; + + if (argc < 5) + usage(); + + path = argv[1]; + + if (strcmp(argv[2], "read") == 0) + do_read = true; + else if (strcmp(argv[2], "write") == 0) + do_write = true; + else + usage(); + + prop = argv[3]; + + if (strcmp(argv[4], "int") == 0) + is_int = true; + else if (strcmp(argv[4], "char") == 0) + is_int = false; + else + usage(); + + if (do_read && argc != 5) + usage(); + + if (do_write && argc != 6) + usage(); + else + prop_value = argv[5]; + + + pdbg_set_backend(PDBG_BACKEND_FAKE, NULL); + assert(pdbg_targets_init(NULL)); + + target = pdbg_target_from_path(NULL, path); + if (!target) + exit(1); + + if (do_read) { + if (is_int) { + uint32_t value; + int ret; + + ret = pdbg_target_u32_property(target, prop, &value); + if (ret) + exit(88); + + printf("0x%08x\n", value); + } else { + const void *buf; + size_t buflen; + + buf = pdbg_target_property(target, prop, &buflen); + if (!buf) + exit(88); + + printf("%s<%zu>\n", (const char *)buf, buflen); + } + + } + + if (do_write) { + bool ok; + + if (is_int) { + uint32_t value; + + value = strtoul(prop_value, NULL, 0); + value = htobe32(value); + + ok = pdbg_target_set_property(target, prop, &value, 4); + } else { + size_t len = strlen(prop_value) + 1; + + ok = pdbg_target_set_property(target, prop, prop_value, len); + } + + if (!ok) + exit(99); + } + + return 0; +} diff --git a/tests/test_prop.sh b/tests/test_prop.sh new file mode 100755 index 0000000..e2e511f --- /dev/null +++ b/tests/test_prop.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +. $(dirname "$0")/driver.sh + +test_group "libpdbg property tests" + +test_result 88 -- +test_run libpdbg_prop_test /proc0/pib read ATTR0 int + +test_result 88 -- +test_run libpdbg_prop_test /proc1/pib read ATTR0 char + +test_result 0 < +EOF +test_run libpdbg_prop_test /proc0/pib read ATTR2 char + +test_result 0 < +EOF +test_run libpdbg_prop_test /proc1/pib read ATTR2 char + +test_result 99 -- +test_run libpdbg_prop_test /proc0/pib write ATTR1 int 0xdeadbeef + +test_result 99 -- +test_run libpdbg_prop_test /proc0/pib write ATTR2 char PROCESSOR0 + +export PDBG_DTB=fake.dtb + +test_result 0 -- +test_run libpdbg_prop_test /proc1/pib write ATTR1 int 0xdeadbeef + +test_result 0 -- +test_run libpdbg_prop_test /proc1/pib write ATTR2 char PROCESSOR0 + +test_result 0 < +EOF +test_run libpdbg_prop_test /proc1/pib read ATTR2 char