From: Stefano Stabellini <sstabellini@kernel.org>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <stefanos@xilinx.com>,
julien.grall@arm.com, sstabellini@kernel.org,
Volodymyr_Babchuk@epam.com
Subject: [Xen-devel] [PATCH v7 1/8] xen/arm: pass node to device_tree_for_each_node
Date: Mon, 19 Aug 2019 10:43:31 -0700 [thread overview]
Message-ID: <20190819174338.10466-1-sstabellini@kernel.org> (raw)
In-Reply-To: <alpine.DEB.2.21.1908191011060.20094@sstabellini-ThinkPad-T480s>
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 <stefanos@xilinx.com>
---
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 node)
* and ACPI has not been force enabled (acpi=force)
*/
- if ( param_acpi_off || ( !param_acpi_force
- && device_tree_for_each_node(device_tree_flattened,
- dt_scan_depth1_nodes, NULL)))
+ 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;
/*
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, int node,
}
/**
- * 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 = 0;
+ const int min_depth = depth;
+ const int first_node = node;
u32 address_cells[DEVICE_TREE_MAX_DEPTH];
u32 size_cells[DEVICE_TREE_MAX_DEPTH];
int ret;
- for ( node = 0, depth = 0;
- node >=0 && depth >= 0;
- node = fdt_next_node(fdt, node, &depth) )
- {
+ do {
const char *name = fdt_get_name(fdt, node, NULL);
u32 as, ss;
@@ -117,10 +120,17 @@ int __init device_tree_for_each_node(const void *fdt,
size_cells[depth] = device_tree_get_u32(fdt, node,
"#size-cells", ss);
- ret = func(fdt, node, name, depth, as, ss, data);
- if ( ret != 0 )
- return ret;
- }
+ /* skip the first node */
+ if ( node != first_node )
+ {
+ ret = func(fdt, node, name, depth, as, ss, data);
+ if ( ret != 0 )
+ return ret;
+ }
+
+ node = fdt_next_node(fdt, node, &depth);
+ } while ( node >= 0 && depth > min_depth );
+
return 0;
}
@@ -357,7 +367,7 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)
add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false);
- 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();
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,
extern const void *device_tree_flattened;
-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);
/**
* dt_unflatten_host_device_tree - Unflatten the host device tree
--
2.17.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-08-19 17:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-19 17:43 [Xen-devel] [PATCH v7 0/8] reserved-memory in dom0 Stefano Stabellini
2019-08-19 17:43 ` Stefano Stabellini [this message]
2019-08-19 17:56 ` [Xen-devel] [PATCH v7 1/8] xen/arm: pass node to device_tree_for_each_node Julien Grall
2019-08-19 17:43 ` [Xen-devel] [PATCH v7 2/8] xen/arm: make process_memory_node a device_tree_node_func Stefano Stabellini
2019-08-19 18:03 ` Julien Grall
2019-08-19 17:43 ` [Xen-devel] [PATCH v7 3/8] xen/arm: keep track of reserved-memory regions Stefano Stabellini
2019-08-19 17:43 ` [Xen-devel] [PATCH v7 4/8] xen/arm: fix indentation in early_print_info Stefano Stabellini
2019-08-19 17:43 ` [Xen-devel] [PATCH v7 5/8] xen/arm: early_print_info print reserved_mem Stefano Stabellini
2019-08-19 17:43 ` [Xen-devel] [PATCH v7 6/8] xen/arm: handle reserved-memory in consider_modules and dt_unreserved_regions Stefano Stabellini
2019-08-19 17:43 ` [Xen-devel] [PATCH v7 7/8] xen/arm: don't iomem_permit_access for reserved-memory regions Stefano Stabellini
2019-08-19 18:38 ` Julien Grall
2019-08-19 17:43 ` [Xen-devel] [PATCH v7 8/8] xen/arm: add reserved-memory regions to the dom0 memory node Stefano Stabellini
2019-08-20 15:28 ` Oleksandr
2019-08-20 17:49 ` Julien Grall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190819174338.10466-1-sstabellini@kernel.org \
--to=sstabellini@kernel.org \
--cc=Volodymyr_Babchuk@epam.com \
--cc=julien.grall@arm.com \
--cc=stefanos@xilinx.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.