From patchwork Mon Oct 14 05:17:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1175963 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 46s6L01ddkz9sQy for ; Mon, 14 Oct 2019 16:19:04 +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.b="v5iZeHbU"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46s6Kz1B5HzDqWy for ; Mon, 14 Oct 2019 16:19:03 +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 46s6Jx6gP1zDqW5 for ; Mon, 14 Oct 2019 16:18:09 +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.b="v5iZeHbU"; 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 46s6Jx4GJDz9sPp; Mon, 14 Oct 2019 16:18:09 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1571030289; bh=fcLUmWRB7A9k6np9EcWpZxSJ3Siq+puiUCfmh8z1AYw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v5iZeHbU84bNe0W+CteK/wWkjwDI0l2V0+TnJyfmXkKBmnqt6/UkuUJ5uRlsxwbF3 NqtW9DvWt0QI1d/aC/8/UUT/g2j/E4qrA5zbPEg7X4v7duOOUFodhGHCWnoz2+Hnxp smrjYc+Y8n/QpDTb+6wzm7vw03cdiTs87NMmtQ5Y6+Rl+vcS4NqauQY4jqvRBCea4H jUfa7PvH2pjAHvo95scWMmOfUbXoW24HcDBh1eMZW7bqXlt2qchtc56IDaf8Vl0xdM eJW4wVQYsE32IZOYQxajpzcQObO7SoHvphkiymF+ossi+L0kG8E/7K0Y1Di40yoivo uVcWpG44ClP5Q== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Mon, 14 Oct 2019 16:17:30 +1100 Message-Id: <20191014051748.20190-13-amitay@ozlabs.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191014051748.20190-1-amitay@ozlabs.org> References: <20191014051748.20190-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v5 12/30] libpdbg: Create virtual nodes based on system-path 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" To create a virtual node, "system-path" property is used to denote the attachment point in the system device tree view. It's also possible to create virtual nodes from backend device tree as nodes without compatible property. If a virtual node is mapped to a real node, then copy any properties (except #address-cells and #size-cells) to the real node. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/device.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/libpdbg/device.c b/libpdbg/device.c index 8d603e4..f357e99 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -651,6 +651,102 @@ uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *out_size) return dt_get_number(p->prop, na); } +static struct pdbg_target *dt_new_virtual(struct pdbg_target *root, const char *system_path) +{ + char *parent_path, *sep; + struct pdbg_target *parent, *vnode; + + parent_path = strdup(system_path); + assert(parent_path); + + sep = strrchr(parent_path, '/'); + if (!sep || sep[1] == '\0') { + PR_ERROR("Invalid path reference \"%s\"\n", system_path); + free(parent_path); + return NULL; + } + + *sep = '\0'; + + parent = dt_find_by_path(root, parent_path); + if (!parent) { + PR_ERROR("Invalid path reference \"%s\"\n", system_path); + free(parent_path); + return NULL; + } + + vnode = dt_new_node(sep+1, NULL, 0); + assert(vnode); + + free(parent_path); + + if (!dt_attach_node(parent, vnode)) { + free(vnode); + return NULL; + } + + PR_DEBUG("Created virtual node %s\n", system_path); + return vnode; +} + +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) +{ + struct pdbg_target *vnode, *child = NULL; + const char *system_path; + size_t len; + + system_path = (const char *)pdbg_target_property(node, "system-path", &len); + if (!system_path) + goto skip; + + /* + * A virtual node identifies the attachment point of a node in the + * system tree. + */ + vnode = dt_find_by_path(root, system_path); + if (!vnode) + vnode = dt_new_virtual(root, system_path); + + /* If virtual node does not exist, or cannot be created, skip */ + if (!vnode) + goto skip; + + assert(target_is_virtual(vnode)); + + /* + * If virtual node is not linked, then link with node; + * otherwise skip + */ + if (!vnode->vnode) + dt_link_virtual(node, vnode); + +skip: + list_for_each(&node->children, child, list) { + /* If a virtual node is already linked, skip */ + if (target_is_virtual(child) && child->vnode) + continue; + + pdbg_targets_init_virtual(child, root); + } +} + void pdbg_targets_init(void *fdt) { /* Root node needs to be valid when this function returns */ @@ -665,6 +761,7 @@ void pdbg_targets_init(void *fdt) } dt_expand(pdbg_dt_root, fdt); + pdbg_targets_init_virtual(pdbg_dt_root, pdbg_dt_root); } char *pdbg_target_path(struct pdbg_target *target)