[v2,3/7] x86/of: Unconditionally call unflatten_and_copy_device_tree()

Message ID 20240130004508.1700335-4-sboyd@kernel.org
State New
Headers
Series of: populate of_root node if bootloader doesn't |

Commit Message

Stephen Boyd Jan. 30, 2024, 12:45 a.m. UTC
  Call this function unconditionally so that we can populate an empty DTB
on platforms that don't boot with a firmware provided or builtin DTB.

Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: <x86@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Saurabh Sengar <ssengar@linux.microsoft.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
---
 arch/x86/kernel/devicetree.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
  

Comments

Saurabh Singh Sengar Jan. 30, 2024, 1:30 p.m. UTC | #1
On Mon, Jan 29, 2024 at 04:45:02PM -0800, Stephen Boyd wrote:
> Call this function unconditionally so that we can populate an empty DTB
> on platforms that don't boot with a firmware provided or builtin DTB.
> 
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: <x86@kernel.org>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Saurabh Sengar <ssengar@linux.microsoft.com>
> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
> ---
>  arch/x86/kernel/devicetree.c | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
> index afd09924094e..650752d112a6 100644
> --- a/arch/x86/kernel/devicetree.c
> +++ b/arch/x86/kernel/devicetree.c
> @@ -283,22 +283,24 @@ void __init x86_flattree_get_config(void)
>  	u32 size, map_len;
>  	void *dt;
>  
> -	if (!initial_dtb)
> -		return;
> +	if (initial_dtb) {
> +		map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK), (u64)128);
>  
> -	map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK), (u64)128);
> +		dt = early_memremap(initial_dtb, map_len);
> +		size = fdt_totalsize(dt);
> +		if (map_len < size) {
> +			early_memunmap(dt, map_len);
> +			dt = early_memremap(initial_dtb, size);
> +			map_len = size;
> +		}
>  
> -	dt = early_memremap(initial_dtb, map_len);
> -	size = fdt_totalsize(dt);
> -	if (map_len < size) {
> -		early_memunmap(dt, map_len);
> -		dt = early_memremap(initial_dtb, size);
> -		map_len = size;
> +		early_init_dt_verify(dt);
>  	}
>  
> -	early_init_dt_verify(dt);
>  	unflatten_and_copy_device_tree();
> -	early_memunmap(dt, map_len);
> +
> +	if (initial_dtb)
> +		early_memunmap(dt, map_len);
>  }
>  #endif
>  
> -- 
> https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/
> https://git.kernel.org/pub/scm/linux/kernel/git/sboyd/spmi.git


Tested the series in Hyper-V environment. Please feel free to add:
Tested-by: Saurabh Sengar <ssengar@linux.microsoft.com>
  

Patch

diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
index afd09924094e..650752d112a6 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -283,22 +283,24 @@  void __init x86_flattree_get_config(void)
 	u32 size, map_len;
 	void *dt;
 
-	if (!initial_dtb)
-		return;
+	if (initial_dtb) {
+		map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK), (u64)128);
 
-	map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK), (u64)128);
+		dt = early_memremap(initial_dtb, map_len);
+		size = fdt_totalsize(dt);
+		if (map_len < size) {
+			early_memunmap(dt, map_len);
+			dt = early_memremap(initial_dtb, size);
+			map_len = size;
+		}
 
-	dt = early_memremap(initial_dtb, map_len);
-	size = fdt_totalsize(dt);
-	if (map_len < size) {
-		early_memunmap(dt, map_len);
-		dt = early_memremap(initial_dtb, size);
-		map_len = size;
+		early_init_dt_verify(dt);
 	}
 
-	early_init_dt_verify(dt);
 	unflatten_and_copy_device_tree();
-	early_memunmap(dt, map_len);
+
+	if (initial_dtb)
+		early_memunmap(dt, map_len);
 }
 #endif