Message ID | 1556658172-8824-6-git-send-email-sstabellini@kernel.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v2,01/10] xen: add a p2mt parameter to map_mmio_regions | expand |
Hi Stefano, On 4/30/19 10:02 PM, Stefano Stabellini wrote: > Add two new paramters to device_tree_for_each_node: node and depth. NIT: s/paramters/parameters/ > Node is the node to start the search from and depth is the min depth of > the search. > > Passing 0, 0 triggers the old behavior. It would be good to explain in the commit message why we need this. > > Signed-off-by: Stefano Stabellini <stefanos@xilinx.com> > --- > Changes in v2: > - new > --- > xen/arch/arm/acpi/boot.c | 2 +- > xen/arch/arm/bootfdt.c | 12 ++++++------ > xen/include/xen/device_tree.h | 5 +++-- > 3 files changed, 10 insertions(+), 9 deletions(-) > > diff --git a/xen/arch/arm/acpi/boot.c b/xen/arch/arm/acpi/boot.c > index 9b29769..cfc85c2 100644 > --- a/xen/arch/arm/acpi/boot.c > +++ b/xen/arch/arm/acpi/boot.c > @@ -248,7 +248,7 @@ int __init acpi_boot_table_init(void) > */ > if ( param_acpi_off || ( !param_acpi_force > && device_tree_for_each_node(device_tree_flattened, > - dt_scan_depth1_nodes, NULL))) > + 0, 0, dt_scan_depth1_nodes, NULL))) > goto disable; > > /* > diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c > index 891b4b6..e7b08ed 100644 > --- a/xen/arch/arm/bootfdt.c > +++ b/xen/arch/arm/bootfdt.c > @@ -77,6 +77,8 @@ static u32 __init device_tree_get_u32(const void *fdt, int node, > /** > * device_tree_for_each_node - iterate over all device tree nodes > * @fdt: flat device tree. > + * @node: node to start the search from > + * @depth: min depth of the search The interface is not clear, which node is it? The parent node or the first child? Similarly, which depth is it? But then, is the depth really necessary? You basically want to browse all the child of the parent node. > * @func: function to call for each node. > * @data: data to pass to @func. > * > @@ -86,17 +88,15 @@ static u32 __init device_tree_get_u32(const void *fdt, int node, > * returns a value different from 0, that value is returned immediately. > */ > int __init device_tree_for_each_node(const void *fdt, > + int node, int depth, > device_tree_node_func func, > void *data) > { > - int node; > - int depth; > u32 address_cells[DEVICE_TREE_MAX_DEPTH]; > u32 size_cells[DEVICE_TREE_MAX_DEPTH]; > - int ret; > + int ret, min_depth = depth; > > - for ( node = 0, depth = 0; > - node >=0 && depth >= 0; > + for ( ; node >=0 && depth >= min_depth; NIT: While you modify the code, can you please add the missing space between > and 0? Also, the code below is looking at {address, size}_cells[depth - 1]. On the first loop, they will not be initialized and will contain garbage. Note that with my suggestion about dropping the parameter depth, the address/size cells would still be wrongly initialized. > node = fdt_next_node(fdt, node, &depth) ) > { > const char *name = fdt_get_name(fdt, node, NULL); > @@ -357,7 +357,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, 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 7408a6c..4ff78ba 100644 > --- a/xen/include/xen/device_tree.h > +++ b/xen/include/xen/device_tree.h > @@ -159,8 +159,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 node, int depth, > + device_tree_node_func func, > + void *data); > > /** > * dt_unflatten_host_device_tree - Unflatten the host device tree > Cheers,
diff --git a/xen/arch/arm/acpi/boot.c b/xen/arch/arm/acpi/boot.c index 9b29769..cfc85c2 100644 --- a/xen/arch/arm/acpi/boot.c +++ b/xen/arch/arm/acpi/boot.c @@ -248,7 +248,7 @@ int __init acpi_boot_table_init(void) */ if ( param_acpi_off || ( !param_acpi_force && device_tree_for_each_node(device_tree_flattened, - dt_scan_depth1_nodes, NULL))) + 0, 0, dt_scan_depth1_nodes, NULL))) goto disable; /* diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 891b4b6..e7b08ed 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -77,6 +77,8 @@ static u32 __init device_tree_get_u32(const void *fdt, int node, /** * device_tree_for_each_node - iterate over all device tree nodes * @fdt: flat device tree. + * @node: node to start the search from + * @depth: min depth of the search * @func: function to call for each node. * @data: data to pass to @func. * @@ -86,17 +88,15 @@ static u32 __init device_tree_get_u32(const void *fdt, int node, * returns a value different from 0, that value is returned immediately. */ int __init device_tree_for_each_node(const void *fdt, + int node, int depth, device_tree_node_func func, void *data) { - int node; - int depth; u32 address_cells[DEVICE_TREE_MAX_DEPTH]; u32 size_cells[DEVICE_TREE_MAX_DEPTH]; - int ret; + int ret, min_depth = depth; - for ( node = 0, depth = 0; - node >=0 && depth >= 0; + for ( ; node >=0 && depth >= min_depth; node = fdt_next_node(fdt, node, &depth) ) { const char *name = fdt_get_name(fdt, node, NULL); @@ -357,7 +357,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, 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 7408a6c..4ff78ba 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -159,8 +159,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 node, int depth, + device_tree_node_func func, + void *data); /** * dt_unflatten_host_device_tree - Unflatten the host device tree
Add two new paramters to device_tree_for_each_node: node and depth. Node is the node to start the search from and depth is the min depth of the search. Passing 0, 0 triggers the old behavior. Signed-off-by: Stefano Stabellini <stefanos@xilinx.com> --- Changes in v2: - new --- xen/arch/arm/acpi/boot.c | 2 +- xen/arch/arm/bootfdt.c | 12 ++++++------ xen/include/xen/device_tree.h | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-)