All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] ti: k3: abstract common fdt api for reserved mem fixups
@ 2025-05-22 15:09 Anshul Dalal
  2025-06-04 17:57 ` Tom Rini
  0 siblings, 1 reply; 3+ messages in thread
From: Anshul Dalal @ 2025-05-22 15:09 UTC (permalink / raw)
  To: u-boot; +Cc: Anshul Dalal, vigneshr, trini

The usage of fdt_fixup_reserved is repeated for ATF and OP-TEE for
multiple platforms, this patch creates a single fdt API for fixing up
the reserved-memory node with added error handling.

All k3 platforms already share a common tispl template which ensures
binaries are loaded as per the respective CONFIG_*_LOAD_ADDR. And the
provided new_size for the fixup is overridden by the size from fdt node
anyways. This allows for safe abstraction of the reserved memory fixups
for all current platforms.

fdt_fixup_reserved now abstracts the ATF and OP-TEE fixups by calling
the renamed static fdt_fixup_reserved_memory function with the required
parameters.

Signed-off-by: Anshul Dalal <anshuld@ti.com>
---
 arch/arm/mach-k3/am62ax/am62a7_fdt.c |  5 +----
 arch/arm/mach-k3/am62px/am62p5_fdt.c |  5 +----
 arch/arm/mach-k3/am62x/am625_fdt.c   |  5 +----
 arch/arm/mach-k3/common_fdt.c        | 22 ++++++++++++++++++++--
 arch/arm/mach-k3/common_fdt.h        |  3 +--
 arch/arm/mach-k3/j722s/j722s_fdt.c   |  5 +----
 6 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/arch/arm/mach-k3/am62ax/am62a7_fdt.c b/arch/arm/mach-k3/am62ax/am62a7_fdt.c
index 7f764ab36b5..9a4599432ff 100644
--- a/arch/arm/mach-k3/am62ax/am62a7_fdt.c
+++ b/arch/arm/mach-k3/am62ax/am62a7_fdt.c
@@ -10,8 +10,5 @@
 
 int ft_system_setup(void *blob, struct bd_info *bd)
 {
-	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
-	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
-
-	return 0;
+	return fdt_fixup_reserved(blob);
 }
diff --git a/arch/arm/mach-k3/am62px/am62p5_fdt.c b/arch/arm/mach-k3/am62px/am62p5_fdt.c
index 2c40fa5a594..9f4b1663864 100644
--- a/arch/arm/mach-k3/am62px/am62p5_fdt.c
+++ b/arch/arm/mach-k3/am62px/am62p5_fdt.c
@@ -92,8 +92,5 @@ int ft_system_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_canfd_nodes_am62p(blob, k3_has_canfd());
 	fdt_fixup_thermal_zone_nodes_am62p(blob, k3_get_max_temp());
 	fdt_fixup_cpu_freq_nodes_am62p(blob, k3_get_a53_max_frequency());
-	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
-	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
-
-	return 0;
+	return fdt_fixup_reserved(blob);
 }
diff --git a/arch/arm/mach-k3/am62x/am625_fdt.c b/arch/arm/mach-k3/am62x/am625_fdt.c
index 11152194ed0..e4382508dc3 100644
--- a/arch/arm/mach-k3/am62x/am625_fdt.c
+++ b/arch/arm/mach-k3/am62x/am625_fdt.c
@@ -118,8 +118,5 @@ int ft_system_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_pru_node_am625(blob, k3_has_pru());
 	fdt_fixup_thermal_zone_nodes_am625(blob, k3_get_max_temp());
 	fdt_fixup_thermal_cooling_device_cpus_am625(blob, k3_get_core_nr());
-	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
-	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
-
-	return 0;
+	return fdt_fixup_reserved(blob);
 }
diff --git a/arch/arm/mach-k3/common_fdt.c b/arch/arm/mach-k3/common_fdt.c
index 75f0469f456..5b89b85a852 100644
--- a/arch/arm/mach-k3/common_fdt.c
+++ b/arch/arm/mach-k3/common_fdt.c
@@ -115,8 +115,9 @@ int fdt_del_node_path(void *blob, const char *path)
 	return ret;
 }
 
-int fdt_fixup_reserved(void *blob, const char *name,
-		       unsigned int new_address, unsigned int new_size)
+static int fdt_fixup_reserved_memory(void *blob, const char *name,
+				     unsigned int new_address,
+				     unsigned int new_size)
 {
 	int nodeoffset, subnode;
 	int ret;
@@ -167,3 +168,20 @@ add_carveout:
 
 	return 0;
 }
+
+int fdt_fixup_reserved(void *blob)
+{
+	int ret;
+
+	ret = fdt_fixup_reserved_memory(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR,
+					0x80000);
+	if (ret)
+		return ret;
+
+	ret = fdt_fixup_reserved_memory(blob, "optee",
+					CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
+	if (ret)
+		return ret;
+
+	return 0;
+}
diff --git a/arch/arm/mach-k3/common_fdt.h b/arch/arm/mach-k3/common_fdt.h
index 52c07957483..e2f26983a73 100644
--- a/arch/arm/mach-k3/common_fdt.h
+++ b/arch/arm/mach-k3/common_fdt.h
@@ -8,7 +8,6 @@
 
 int fdt_fixup_msmc_ram_k3(void *blob);
 int fdt_del_node_path(void *blob, const char *path);
-int fdt_fixup_reserved(void *blob, const char *name,
-		       unsigned int new_address, unsigned int new_size);
+int fdt_fixup_reserved(void *blob);
 
 #endif /* _COMMON_FDT_H */
diff --git a/arch/arm/mach-k3/j722s/j722s_fdt.c b/arch/arm/mach-k3/j722s/j722s_fdt.c
index 29c832d28ac..97d34f50539 100644
--- a/arch/arm/mach-k3/j722s/j722s_fdt.c
+++ b/arch/arm/mach-k3/j722s/j722s_fdt.c
@@ -9,8 +9,5 @@
 
 int ft_system_setup(void *blob, struct bd_info *bd)
 {
-	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
-	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
-
-	return 0;
+	return fdt_fixup_reserved(blob);
 }
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] ti: k3: abstract common fdt api for reserved mem fixups
  2025-05-22 15:09 [PATCH v1] ti: k3: abstract common fdt api for reserved mem fixups Anshul Dalal
@ 2025-06-04 17:57 ` Tom Rini
  2025-06-05  4:05   ` Anshul Dalal
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Rini @ 2025-06-04 17:57 UTC (permalink / raw)
  To: Anshul Dalal; +Cc: u-boot, vigneshr

[-- Attachment #1: Type: text/plain, Size: 2640 bytes --]

On Thu, May 22, 2025 at 08:39:40PM +0530, Anshul Dalal wrote:

> The usage of fdt_fixup_reserved is repeated for ATF and OP-TEE for
> multiple platforms, this patch creates a single fdt API for fixing up
> the reserved-memory node with added error handling.
> 
> All k3 platforms already share a common tispl template which ensures
> binaries are loaded as per the respective CONFIG_*_LOAD_ADDR. And the
> provided new_size for the fixup is overridden by the size from fdt node
> anyways. This allows for safe abstraction of the reserved memory fixups
> for all current platforms.
> 
> fdt_fixup_reserved now abstracts the ATF and OP-TEE fixups by calling
> the renamed static fdt_fixup_reserved_memory function with the required
> parameters.
> 
> Signed-off-by: Anshul Dalal <anshuld@ti.com>
[snip]

I think this shows the start of fixing up some problems, but that we
need to do more.

> diff --git a/arch/arm/mach-k3/am62ax/am62a7_fdt.c b/arch/arm/mach-k3/am62ax/am62a7_fdt.c
> index 7f764ab36b5..9a4599432ff 100644
> --- a/arch/arm/mach-k3/am62ax/am62a7_fdt.c
> +++ b/arch/arm/mach-k3/am62ax/am62a7_fdt.c
> @@ -10,8 +10,5 @@
>  
>  int ft_system_setup(void *blob, struct bd_info *bd)
>  {
> -	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
> -	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
> -
> -	return 0;
> +	return fdt_fixup_reserved(blob);
>  }

This is good.

> diff --git a/arch/arm/mach-k3/am62px/am62p5_fdt.c b/arch/arm/mach-k3/am62px/am62p5_fdt.c
> index 2c40fa5a594..9f4b1663864 100644
> --- a/arch/arm/mach-k3/am62px/am62p5_fdt.c
> +++ b/arch/arm/mach-k3/am62px/am62p5_fdt.c
> @@ -92,8 +92,5 @@ int ft_system_setup(void *blob, struct bd_info *bd)
>  	fdt_fixup_canfd_nodes_am62p(blob, k3_has_canfd());
>  	fdt_fixup_thermal_zone_nodes_am62p(blob, k3_get_max_temp());
>  	fdt_fixup_cpu_freq_nodes_am62p(blob, k3_get_a53_max_frequency());

Is it really OK for any of the above fixups to fail to happen and be
silently ignored? fdt_fixup_thermal_zone_nodes_am62p() for example looks
like it throws away error conditions from functions it calls. And other
boards are doing similar things.

[sniip]
> +int fdt_fixup_reserved(void *blob)
> +{
> +	int ret;
> +
> +	ret = fdt_fixup_reserved_memory(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR,
> +					0x80000);
> +	if (ret)
> +		return ret;

Good.

> +	ret = fdt_fixup_reserved_memory(blob, "optee",
> +					CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
> +	if (ret)
> +		return ret;
> +
> +	return 0;

But we can just return fdt_fixup_reserved_memory(...) here.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] ti: k3: abstract common fdt api for reserved mem fixups
  2025-06-04 17:57 ` Tom Rini
@ 2025-06-05  4:05   ` Anshul Dalal
  0 siblings, 0 replies; 3+ messages in thread
From: Anshul Dalal @ 2025-06-05  4:05 UTC (permalink / raw)
  To: Tom Rini; +Cc: u-boot, vigneshr

On Wed Jun 4, 2025 at 11:27 PM IST, Tom Rini wrote:
> On Thu, May 22, 2025 at 08:39:40PM +0530, Anshul Dalal wrote:
>
>> The usage of fdt_fixup_reserved is repeated for ATF and OP-TEE for
>> multiple platforms, this patch creates a single fdt API for fixing up
>> the reserved-memory node with added error handling.
>> 
>> All k3 platforms already share a common tispl template which ensures
>> binaries are loaded as per the respective CONFIG_*_LOAD_ADDR. And the
>> provided new_size for the fixup is overridden by the size from fdt node
>> anyways. This allows for safe abstraction of the reserved memory fixups
>> for all current platforms.
>> 
>> fdt_fixup_reserved now abstracts the ATF and OP-TEE fixups by calling
>> the renamed static fdt_fixup_reserved_memory function with the required
>> parameters.
>> 
>> Signed-off-by: Anshul Dalal <anshuld@ti.com>
> [snip]
>
> I think this shows the start of fixing up some problems, but that we
> need to do more.
>
>> diff --git a/arch/arm/mach-k3/am62ax/am62a7_fdt.c b/arch/arm/mach-k3/am62ax/am62a7_fdt.c
>> index 7f764ab36b5..9a4599432ff 100644
>> --- a/arch/arm/mach-k3/am62ax/am62a7_fdt.c
>> +++ b/arch/arm/mach-k3/am62ax/am62a7_fdt.c
>> @@ -10,8 +10,5 @@
>>  
>>  int ft_system_setup(void *blob, struct bd_info *bd)
>>  {
>> -	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
>> -	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
>> -
>> -	return 0;
>> +	return fdt_fixup_reserved(blob);
>>  }
>
> This is good.
>
>> diff --git a/arch/arm/mach-k3/am62px/am62p5_fdt.c b/arch/arm/mach-k3/am62px/am62p5_fdt.c
>> index 2c40fa5a594..9f4b1663864 100644
>> --- a/arch/arm/mach-k3/am62px/am62p5_fdt.c
>> +++ b/arch/arm/mach-k3/am62px/am62p5_fdt.c
>> @@ -92,8 +92,5 @@ int ft_system_setup(void *blob, struct bd_info *bd)
>>  	fdt_fixup_canfd_nodes_am62p(blob, k3_has_canfd());
>>  	fdt_fixup_thermal_zone_nodes_am62p(blob, k3_get_max_temp());
>>  	fdt_fixup_cpu_freq_nodes_am62p(blob, k3_get_a53_max_frequency());
>
> Is it really OK for any of the above fixups to fail to happen and be
> silently ignored? fdt_fixup_thermal_zone_nodes_am62p() for example looks
> like it throws away error conditions from functions it calls. And other
> boards are doing similar things.
>

Yeah, all fdt_fixup_* currently don't propogate the errors to the caller
(ft_system_setup). I will refactor the fdt_fixup_* functions to return
errors instead, we can then decide in ft_system_setup whether to ignore
them with a warning log or fail booting by propogating the error
upwards.

[snip]
>> +	ret = fdt_fixup_reserved_memory(blob, "optee",
>> +					CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
>> +	if (ret)
>> +		return ret;
>> +
>> +	return 0;
>
> But we can just return fdt_fixup_reserved_memory(...) here.

You're right, will be fixed in the next revision.

Thanks for the review Tom,
Anshul

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-05  4:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-22 15:09 [PATCH v1] ti: k3: abstract common fdt api for reserved mem fixups Anshul Dalal
2025-06-04 17:57 ` Tom Rini
2025-06-05  4:05   ` Anshul Dalal

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.