diff mbox series

[2/5] of: reserved_mem: Implement alloc-{bottom-up,top-down}

Message ID 20230510-dt-resv-bottom-up-v1-2-3bf68873dbed@gerhold.net
State New
Headers show
Series of: reserved_mem: Provide more control about allocation behavior | expand

Commit Message

Stephan Gerhold May 15, 2023, 10:12 a.m. UTC
Use memblock_set_bottom_up() to specify an explicit allocation order for
dynamic reservations with "alloc-ranges". Since the default value varies
between architectures the previous value is saved and restored after
trying the allocations.

If neither alloc-bottom-up or alloc-top-down are specified the previous
implementation-defined allocation order is preserved.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
---
 drivers/of/of_reserved_mem.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Konrad Dybcio May 17, 2023, 7:28 p.m. UTC | #1
On 15.05.2023 12:12, Stephan Gerhold wrote:
> Use memblock_set_bottom_up() to specify an explicit allocation order for
> dynamic reservations with "alloc-ranges". Since the default value varies
> between architectures the previous value is saved and restored after
> trying the allocations.
> 
> If neither alloc-bottom-up or alloc-top-down are specified the previous
> implementation-defined allocation order is preserved.
> 
> Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
> ---
Acked-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad
>  drivers/of/of_reserved_mem.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index 948efa9f99e3..6443140deacf 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c
> @@ -89,7 +89,7 @@ static int __init __reserved_mem_alloc_size(unsigned long node,
>  	phys_addr_t base = 0, align = 0, size;
>  	int len;
>  	const __be32 *prop;
> -	bool nomap;
> +	bool nomap, prev_bottom_up;
>  	int ret;
>  
>  	prop = of_get_flat_dt_prop(node, "size", &len);
> @@ -130,6 +130,12 @@ static int __init __reserved_mem_alloc_size(unsigned long node,
>  			return -EINVAL;
>  		}
>  
> +		prev_bottom_up = memblock_bottom_up();
> +		if (of_get_flat_dt_prop(node, "alloc-bottom-up", NULL))
> +			memblock_set_bottom_up(true);
> +		if (of_get_flat_dt_prop(node, "alloc-top-down", NULL))
> +			memblock_set_bottom_up(false);
> +
>  		base = 0;
>  
>  		while (len > 0) {
> @@ -148,6 +154,7 @@ static int __init __reserved_mem_alloc_size(unsigned long node,
>  			len -= t_len;
>  		}
>  
> +		memblock_set_bottom_up(prev_bottom_up);
>  	} else {
>  		ret = early_init_dt_alloc_reserved_memory_arch(size, align,
>  							0, 0, nomap, &base);
>
diff mbox series

Patch

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 948efa9f99e3..6443140deacf 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -89,7 +89,7 @@  static int __init __reserved_mem_alloc_size(unsigned long node,
 	phys_addr_t base = 0, align = 0, size;
 	int len;
 	const __be32 *prop;
-	bool nomap;
+	bool nomap, prev_bottom_up;
 	int ret;
 
 	prop = of_get_flat_dt_prop(node, "size", &len);
@@ -130,6 +130,12 @@  static int __init __reserved_mem_alloc_size(unsigned long node,
 			return -EINVAL;
 		}
 
+		prev_bottom_up = memblock_bottom_up();
+		if (of_get_flat_dt_prop(node, "alloc-bottom-up", NULL))
+			memblock_set_bottom_up(true);
+		if (of_get_flat_dt_prop(node, "alloc-top-down", NULL))
+			memblock_set_bottom_up(false);
+
 		base = 0;
 
 		while (len > 0) {
@@ -148,6 +154,7 @@  static int __init __reserved_mem_alloc_size(unsigned long node,
 			len -= t_len;
 		}
 
+		memblock_set_bottom_up(prev_bottom_up);
 	} else {
 		ret = early_init_dt_alloc_reserved_memory_arch(size, align,
 							0, 0, nomap, &base);