From nobody Tue Nov 11 10:07:48 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1566236684; cv=none; d=zoho.com; s=zohoarc; b=A1aTisAv164+co41sWJqKzHxZGvCxSz4tP/+YUU+nw4PlRuQjJe7UrvhsMIu7EslvlyFAefKfIlFqtN3brOFqtg3bTjQ7yAhsU0lzpmw/JRs2bl1HP4vq0pgMkwM4qiEcFETSDGk+i526twa+KroXQPsbrSEhLsAg7sHdWrOGMY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566236684; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=qSybQxqmSIUUQ6EdJ7X6g4AnRu6aMCJ8NWcPRIFg8Vw=; b=PiP+oG4PPC+BrZezPLePs+r1C25b1ebr1BKecJw1y5GW3snfGPGc14MPjwFxJznsGlVW3bzobOYkWHsq5eIyjNkbBtpSRRt64mwoxOJbYZdV/rdAJZV7QWGTjtBMFkvxUaDopcQ4myVnYUXIbYIcQLs0nE0ztnnu6hlZDUyU45k= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1566236684744255.1746914682377; Mon, 19 Aug 2019 10:44:44 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzlh0-0007cG-3w; Mon, 19 Aug 2019 17:43:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzlgz-0007c9-DT for xen-devel@lists.xenproject.org; Mon, 19 Aug 2019 17:43:41 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e1768f58-c2a8-11e9-a661-bc764e2007e4; Mon, 19 Aug 2019 17:43:40 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.xilinx.com (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E995822CE9; Mon, 19 Aug 2019 17:43:39 +0000 (UTC) X-Inumbo-ID: e1768f58-c2a8-11e9-a661-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566236620; bh=844nyVFBsPArCfQb/Y6AXHrw7gwHIR98vGwgWYnfApo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zl/DCfADQSa0bYPxF4qS2YfSk6k1u5KP2BtGDcqeWXpTqLTmwIfMf1cCX6QV2oJDJ eo2sCr84I0ztezaa/Hc1lPjXEf9DjcLTgLs3FEkm1Rtgnx8WvqHpmN6m3tLPw/zyN2 76zLZzc72i8OQ2PAexA4kxGXoKSvge7wMkCCjMwo= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Mon, 19 Aug 2019 10:43:31 -0700 Message-Id: <20190819174338.10466-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v7 1/8] xen/arm: pass node to device_tree_for_each_node X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , julien.grall@arm.com, sstabellini@kernel.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Add a new parameter to device_tree_for_each_node: node, the node to start the search from. To avoid scanning device tree, and given that we only care about relative increments of depth compared to the depth of the initial node, we set the initial depth to 0. Then, we call func() for every node with depth > 0. Don't call func() on the parent node passed as an argument. Clarify the change in the comment on top of the function. The current callers pass the root node as argument: it is OK to skip the root node because no relevant properties are in it, only subnodes. Signed-off-by: Stefano Stabellini Acked-by: Julien Grall --- Changes in v7: - fix commit message - use const - init depth and min_depth to 0 Changes in v6: - fix code style - don't call func() on the first node Changes in v5: - go back to v3 - code style improvement in acpi/boot.c - improve comments and commit message - increase min_depth to avoid parsing siblings - replace for with do/while loop and increase min_depth to avoid scanning siblings of the initial node - pass only node, calculate depth Changes in v3: - improve commit message - improve in-code comments - improve code style Changes in v2: - new --- xen/arch/arm/acpi/boot.c | 8 +++++--- xen/arch/arm/bootfdt.c | 38 ++++++++++++++++++++++------------- xen/include/xen/device_tree.h | 6 +++--- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/acpi/boot.c b/xen/arch/arm/acpi/boot.c index 9b29769a10..bf9c78b02c 100644 --- a/xen/arch/arm/acpi/boot.c +++ b/xen/arch/arm/acpi/boot.c @@ -246,9 +246,11 @@ int __init acpi_boot_table_init(void) * - the device tree is not empty (it has more than just a /chosen nod= e) * and ACPI has not been force enabled (acpi=3Dforce) */ - if ( param_acpi_off || ( !param_acpi_force - && device_tree_for_each_node(device_tree_flat= tened, - dt_scan_depth1_nodes, N= ULL))) + if ( param_acpi_off) + goto disable; + if ( !param_acpi_force && + device_tree_for_each_node(device_tree_flattened, 0, + dt_scan_depth1_nodes, NULL) ) goto disable; =20 /* diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 891b4b66ff..0ca3c20f05 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -75,9 +75,10 @@ static u32 __init device_tree_get_u32(const void *fdt, i= nt node, } =20 /** - * device_tree_for_each_node - iterate over all device tree nodes + * device_tree_for_each_node - iterate over all device tree sub-nodes * @fdt: flat device tree. - * @func: function to call for each node. + * @node: parent node to start the search from + * @func: function to call for each sub-node. * @data: data to pass to @func. * * Any nodes nested at DEVICE_TREE_MAX_DEPTH or deeper are ignored. @@ -85,20 +86,22 @@ static u32 __init device_tree_get_u32(const void *fdt, = int node, * Returns 0 if all nodes were iterated over successfully. If @func * returns a value different from 0, that value is returned immediately. */ -int __init device_tree_for_each_node(const void *fdt, +int __init device_tree_for_each_node(const void *fdt, int node, device_tree_node_func func, void *data) { - int node; - int depth; + /* + * We only care about relative depth increments, assume depth of + * node is 0 for simplicity. + */ + int depth =3D 0; + const int min_depth =3D depth; + const int first_node =3D node; u32 address_cells[DEVICE_TREE_MAX_DEPTH]; u32 size_cells[DEVICE_TREE_MAX_DEPTH]; int ret; =20 - for ( node =3D 0, depth =3D 0; - node >=3D0 && depth >=3D 0; - node =3D fdt_next_node(fdt, node, &depth) ) - { + do { const char *name =3D fdt_get_name(fdt, node, NULL); u32 as, ss; =20 @@ -117,10 +120,17 @@ int __init device_tree_for_each_node(const void *fdt, size_cells[depth] =3D device_tree_get_u32(fdt, node, "#size-cells", ss); =20 - ret =3D func(fdt, node, name, depth, as, ss, data); - if ( ret !=3D 0 ) - return ret; - } + /* skip the first node */ + if ( node !=3D first_node ) + { + ret =3D func(fdt, node, name, depth, as, ss, data); + if ( ret !=3D 0 ) + return ret; + } + + node =3D fdt_next_node(fdt, node, &depth); + } while ( node >=3D 0 && depth > min_depth ); + return 0; } =20 @@ -357,7 +367,7 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t pa= ddr) =20 add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false); =20 - device_tree_for_each_node((void *)fdt, early_scan_node, NULL); + device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL); early_print_info(); =20 return fdt_totalsize(fdt); diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 83156297e2..9a7a8f2dab 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -158,9 +158,9 @@ typedef int (*device_tree_node_func)(const void *fdt, =20 extern const void *device_tree_flattened; =20 -int device_tree_for_each_node(const void *fdt, - device_tree_node_func func, - void *data); +int device_tree_for_each_node(const void *fdt, int node, + device_tree_node_func func, + void *data); =20 /** * dt_unflatten_host_device_tree - Unflatten the host device tree --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel