Initial support of Trusted Foundations on Tegra30
Subsystems (3)
cover Initial support of Trusted Foundations on Tegra30
Hello,
This series of patches brings initial support of Trusted Foundations to Tegra30, that is to the consumer-grade Tegra30 devices which do not allow to easily replace the proprietary bootloader. Support is initial because this series implements only a proper CPU boot-up (main + secondary cores) and a basic L2 cache maintenance that is done using the TF firmware. Suspend-resume support is missing yet as I couldn't get it to work (CPU hangs on resume from suspend after awhile and seems that is related to inappropriately done cache maintenance during of suspend-resume using the firmware), it is work-in-progress for now.
This patchset is partially based on the work done by Micha? Miros?aw [0].
Please review, thanks.
[0] https://www.spinics.net/lists/linux-tegra/msg30368.html
Dmitry Osipenko (5):
ARM: trusted_foundations: Implement L2 cache initialization callback
ARM: trusted_foundations: Provide information about whether firmware
is registered
ARM: tegra: Setup L2 cache using Trusted Foundations firmware
ARM: tegra: Don't apply CPU erratas in insecure mode
ARM: tegra: Always boot CPU in ARM-mode
arch/arm/firmware/trusted_foundations.c | 28 ++++++++++++++++++++++ arch/arm/include/asm/trusted_foundations.h | 7 ++++++ arch/arm/mach-tegra/reset-handler.S | 28 +++++++++++++++------- arch/arm/mach-tegra/reset.c | 5 +++- arch/arm/mach-tegra/reset.h | 4 +++- arch/arm/mach-tegra/tegra.c | 15 ++++++++++++ 6 files changed, 77 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.0
PATCH 1/5 ARM: trusted_foundations: Implement L2 cache initialization callback
Implement L2 cache initialization firmware callback that should be invoked early in boot to enable cache HW.
--- arch/arm/firmware/trusted_foundations.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
arch/arm/firmware/trusted_foundations.c +23 -0
@@ -18,8 +18,13 @@#include <linux/init.h> #include <linux/of.h> #include <asm/firmware.h> +#include <asm/outercache.h> #include <asm/trusted_foundations.h> +#define TF_CACHE_MAINT 0xfffff100 + +#define TF_CACHE_INIT 1 +#define TF_SET_CPU_BOOT_ADDR_SMC 0xfffff200#define TF_CPU_PM 0xfffffffc
@@ -63,9 +68,27 @@ static int tf_prepare_idle(void)return 0 ; } +#ifdef CONFIG_CACHE_L2X0 +static void tf_cache_write_sec (unsigned long val,unsigned int reg) +{ +pr_warn ("%s: Ignoring write [0x%x]: 0x%08lx\n" , __func__, reg, val); +} + +static int tf_init_cache (void ) +{ + outer_cache.write_sec = tf_cache_write_sec; +tf_generic_smc (TF_CACHE_MAINT ,TF_CACHE_INIT ,0 ); + +return 0 ; +} +#endif /* CONFIG_CACHE_L2X0 */ +static const struct firmware_ops trusted_foundations_ops = { .set_cpu_boot_addr = tf_set_cpu_boot_addr, .prepare_idle = tf_prepare_idle, +#ifdef CONFIG_CACHE_L2X0 + .l2x0_init = tf_init_cache, +#endif };void register_trusted_foundations (struct trusted_foundations_platform_data *pd)
Signature · 1 line
2.17.0
PATCH 2/5 ARM: trusted_foundations: Provide information about whether firmware is registered
In reply to Dmitry OsipenkoAdd a helper that provides information about whether Trusted Foundations firmware operations have been registered.
--- arch/arm/firmware/trusted_foundations.c | 5 +++++ arch/arm/include/asm/trusted_foundations.h | 7 +++++++ 2 files changed, 12 insertions(+)
arch/arm/firmware/trusted_foundations.c +5 -0
@@ -120,3 +120,8 @@ void of_register_trusted_foundations(void)panic ("Trusted Foundation: missing version-minor property\n" );register_trusted_foundations (&pdata); } + +bool trusted_foundations_registered (void ) +{ +return firmware_ops == &trusted_foundations_ops; +}
arch/arm/include/asm/trusted_foundations.h +7 -0
@@ -31,6 +31,7 @@#include <linux/of.h> #include <linux/cpu.h> #include <linux/smp.h> +#include <linux/types.h> struct trusted_foundations_platform_data {unsigned int version_major;
@@ -41,6 +42,7 @@ struct trusted_foundations_platform_data {void register_trusted_foundations (struct trusted_foundations_platform_data *pd);void of_register_trusted_foundations (void ); +bool trusted_foundations_registered (void );#else /* CONFIG_TRUSTED_FOUNDATIONS */
@@ -68,6 +70,11 @@ static inline void of_register_trusted_foundations(void)if (of_find_compatible_node (NULL ,NULL ,"tlm,trusted-foundations" ))register_trusted_foundations (NULL ); } + +static inline bool trusted_foundations_registered (void ) +{ +return false; +}#endif /* CONFIG_TRUSTED_FOUNDATIONS */ #endif
Signature · 1 line
2.17.0
PATCH 3/5 ARM: tegra: Setup L2 cache using Trusted Foundations firmware
In reply to Dmitry OsipenkoOn Tegra20/30 L2 cache must be initialized using firmware call if CPU is running in insecure mode. Initialize L2 cache and setup the outer-cache callbacks in early boot using the firmware API.
--- arch/arm/mach-tegra/tegra.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm/mach-tegra/tegra.c +15 -0
@@ -38,6 +38,7 @@#include <soc/tegra/fuse.h> #include <soc/tegra/pmc.h> +#include <asm/firmware.h> #include <asm/hardware/cache-l2x0.h> #include <asm/mach/arch.h> #include <asm/mach/time.h>
@@ -70,9 +71,23 @@ u32 tegra_uart_config[3] = { 0, }; +static void __init tegra_trusted_foundations_l2x0_cache_init (void ) +{ +if (IS_ENABLED (CONFIG_CACHE_L2X0 ) && +IS_ENABLED (CONFIG_ARCH_TEGRA_2x_SOC) && +of_machine_is_compatible ("nvidia,tegra20" )) +call_firmware_op (l2x0_init); + +if (IS_ENABLED (CONFIG_CACHE_L2X0 ) && +IS_ENABLED (CONFIG_ARCH_TEGRA_3x_SOC) && +of_machine_is_compatible ("nvidia,tegra30" )) +call_firmware_op (l2x0_init); +} +static void __init tegra_init_early (void ) {of_register_trusted_foundations (); +tegra_trusted_foundations_l2x0_cache_init ();tegra_cpu_reset_handler_init (); }
Signature · 1 line
2.17.0
PATCH 4/5 ARM: tegra: Don't apply CPU erratas in insecure mode
In reply to Dmitry OsipenkoCPU isn't allowed to touch secure registers while running under secure monitor. Hence skip applying CPU erratas in the reset handler if Trusted Foundations firmware presents.
--- arch/arm/mach-tegra/reset-handler.S | 27 +++++++++++++++++++-------- arch/arm/mach-tegra/reset.c | 3 +++ arch/arm/mach-tegra/reset.h | 4 +++- 3 files changed, 25 insertions(+), 9 deletions(-)
arch/arm/mach-tegra/reset-handler.S +19 -8
@@ -121,6 +121,12 @@ ENTRY(__tegra_cpu_reset_handler) cpsid aif, 0x13 @ SVC mode, interrupts disabled tegra_get_soc_id TEGRA_APB_MISC_BASE, r6 + + adr r12, __tegra_cpu_reset_handler_data + ldr r0, [r12, #RESET_DATA(TF_PRESENT)] + cmp r0, #0 + bne after_errata + #ifdef CONFIG_ARCH_TEGRA_2x_SOC t20_check: cmp r6, #TEGRA20
@@ -155,7 +161,6 @@ after_errata: and r10, r10, #0x3 @ R10 = CPU number mov r11, #1 mov r11, r11, lsl r10 @ R11 = CPU mask - adr r12, __tegra_cpu_reset_handler_data #ifdef CONFIG_SMP /* Does the OS know about this CPU? */
@@ -169,10 +174,9 @@ after_errata: cmp r6, #TEGRA20 bne 1f /* If not CPU0, don't let CPU0 reset CPU1 now that CPU1 is coming up. */ - mov32 r5, TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET mov r0, #CPU_NOT_RESETTABLE cmp r10, #0 - strneb r0, [r5, #__tegra20_cpu1_resettable_status_offset] + strneb r0, [r12, #RESET_DATA(RESETTABLE_STATUS)] 1: #endif
@@ -278,13 +282,20 @@ ENDPROC(__tegra_cpu_reset_handler) .type __tegra_cpu_reset_handler_data, %object .globl __tegra_cpu_reset_handler_data __tegra_cpu_reset_handler_data: - .rept TEGRA_RESET_DATA_SIZE - .long 0 - .endr + .long 0 /* TEGRA_RESET_MASK_PRESENT */ + .long 0 /* TEGRA_RESET_MASK_LP1 */ + .long 0 /* TEGRA_RESET_MASK_LP2 */ + .long 0 /* TEGRA_RESET_STARTUP_SECONDARY */ + .long 0 /* TEGRA_RESET_STARTUP_LP2 */ + .long 0 /* TEGRA_RESET_STARTUP_LP1 */ + .globl __tegra20_cpu1_resettable_status_offset .equ __tegra20_cpu1_resettable_status_offset, \ . - __tegra_cpu_reset_handler_start - .byte 0 - .align L1_CACHE_SHIFT + .long 0 /* TEGRA_RESET_RESETTABLE_STATUS */ + .globl __tegra_tf_present + .equ __tegra_tf_present, . - __tegra_cpu_reset_handler_start + .long 0 /* TEGRA_RESET_TF_PRESENT */ + .align L1_CACHE_SHIFT ENTRY(__tegra_cpu_reset_handler_end)
arch/arm/mach-tegra/reset.c +3 -0
@@ -24,6 +24,7 @@#include <asm/cacheflush.h> #include <asm/firmware.h> #include <asm/hardware/cache-l2x0.h> +#include <asm/trusted_foundations.h> #include "iomap.h" #include "irammap.h"
@@ -89,6 +90,8 @@ static void __init tegra_cpu_reset_handler_enable(void)void __init tegra_cpu_reset_handler_init (void ) { + __tegra_cpu_reset_handler_data[TEGRA_RESET_TF_PRESENT ] = +trusted_foundations_registered ();#ifdef CONFIG_SMP __tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_PRESENT] =
arch/arm/mach-tegra/reset.h +3 -1
@@ -25,7 +25,9 @@#define TEGRA_RESET_STARTUP_SECONDARY 3#define TEGRA_RESET_STARTUP_LP2 4#define TEGRA_RESET_STARTUP_LP1 5 -#define TEGRA_RESET_DATA_SIZE 6 +#define TEGRA_RESET_RESETTABLE_STATUS 6 +#define TEGRA_RESET_TF_PRESENT 7 +#define TEGRA_RESET_DATA_SIZE 8#ifndef __ASSEMBLY__
Signature · 1 line
2.17.0
PATCH 5/5 ARM: tegra: Always boot CPU in ARM-mode
In reply to Dmitry OsipenkoCPU always jumps into the reset handler in ARM-mode from the Trusted Foundations firmware, hence make CPU to always jump into kernel in ARM-mode regardless of the firmware presence to support Thumb2 kernel + TF case.
--- arch/arm/mach-tegra/reset-handler.S | 1 + arch/arm/mach-tegra/reset.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-tegra/reset-handler.S +1 -0
@@ -115,6 +115,7 @@ ENTRY(__tegra_cpu_reset_handler_start) * must be position-independent. */ + .arm .align L1_CACHE_SHIFT ENTRY(__tegra_cpu_reset_handler)
arch/arm/mach-tegra/reset.c +1 -1
@@ -97,7 +97,7 @@ void __init tegra_cpu_reset_handler_init(void) __tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_PRESENT ] = *((u32 *)cpu_possible_mask); __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_SECONDARY ] = -__pa_symbol ((void *)secondary_startup); +__pa_symbol ((void *)secondary_startup_arm);#endif #ifdef CONFIG_PM_SLEEP
Signature · 1 line
2.17.0
Russell King - ARM Linux
maintainerRe: [PATCH v1 1/5] ARM: trusted_foundations: Implement L2 cache initialization callback
In reply to Dmitry OsipenkoQuoted 27 lines · Dmitry Osipenko
Implement L2 cache initialization firmware callback that should be invoked early in boot to enable cache HW.
Signed-off-by Dmitry Osipenko <[email protected]>--- arch/arm/firmware/trusted_foundations.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)arch/arm/firmware/trusted_foundations.c +5
-0@@ -18,8 +18,13 @@#include <linux/init.h> #include <linux/of.h> #include <asm/firmware.h> +#include <asm/outercache.h> #include <asm/trusted_foundations.h> +#define TF_CACHE_MAINT 0xfffff100 + +#define TF_CACHE_INIT 1 +#define TF_SET_CPU_BOOT_ADDR_SMC 0xfffff200#define TF_CPU_PM 0xfffffffc
arch/arm/firmware/trusted_foundations.c static int tf_prepare_idle(void) · line 74
Quoted 7 lines
arch/arm/firmware/trusted_foundations.c +4
-0@@ -63,9 +68,27 @@ static int tf_prepare_idle(void)return 0 ; } +#ifdef CONFIG_CACHE_L2X0 +static void tf_cache_write_sec (unsigned long val,unsigned int reg) +{ +pr_warn ("%s: Ignoring write [0x%x]: 0x%08lx\n" , __func__, reg, val);
Why at warning level? Is this some issue that the user needs to be warned about?
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up
Re: [PATCH v1 1/5] ARM: trusted_foundations: Implement L2 cache initialization callback
Quoted 31 lines · Russell King - ARM Linux
Quoted 30 lines · Dmitry Osipenko
Implement L2 cache initialization firmware callback that should be invoked early in boot to enable cache HW.
Signed-off-by Dmitry Osipenko <[email protected]>--- arch/arm/firmware/trusted_foundations.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)arch/arm/firmware/trusted_foundations.c +5
-0@@ -18,8 +18,13 @@#include <linux/init.h> #include <linux/of.h> #include <asm/firmware.h> +#include <asm/outercache.h> #include <asm/trusted_foundations.h> +#define TF_CACHE_MAINT 0xfffff100 + +#define TF_CACHE_INIT 1 +#define TF_SET_CPU_BOOT_ADDR_SMC 0xfffff200#define TF_CPU_PM 0xfffffffc@@ -63,9 +68,27 @@ static int tf_prepare_idle(void)return 0 ; }
Quoted 8 lines
arch/arm/firmware/trusted_foundations.c static int tf_prepare_idle(void) · line 74
Quoted 4 lines
arch/arm/firmware/trusted_foundations.c +4
-0+#ifdef CONFIG_CACHE_L2X0 +static void tf_cache_write_sec (unsigned long val,unsigned int reg) +{ +pr_warn ("%s: Ignoring write [0x%x]: 0x%08lx\n" , __func__, reg, val);Why at warning level? Is this some issue that the user needs to be warned about?
If cache-l2x0 code will be changed in the future in a way that it will try to do something using the secure-registers, then user should be informed about that incident as we are ignoring the accesses to secure-registers and this may lead to an undesired consequences. If a such change in cache-l2x0 will happen, then we will have to take some action by either fixing the invalid accesses or silencing the warning message if will be appropriate. For now I'd prefer to have verbosity in the KMSG to masking the potential problems.
Re: [PATCH v1 4/5] ARM: tegra: Don't apply CPU erratas in insecure mode
In reply to Dmitry OsipenkoQuoted 61 lines · Dmitry Osipenko
CPU isn't allowed to touch secure registers while running under secure monitor. Hence skip applying CPU erratas in the reset handler if Trusted Foundations firmware presents.
Signed-off-by Dmitry Osipenko <[email protected]>--- arch/arm/mach-tegra/reset-handler.S | 27 +++++++++++++++++++-------- arch/arm/mach-tegra/reset.c | 3 +++ arch/arm/mach-tegra/reset.h | 4 +++- 3 files changed, 25 insertions(+), 9 deletions(-)arch/arm/mach-tegra/reset-handler.S +13
-6@@ -121,6 +121,12 @@ ENTRY(__tegra_cpu_reset_handler) cpsid aif, 0x13 @ SVC mode, interrupts disabled tegra_get_soc_id TEGRA_APB_MISC_BASE, r6 + + adr r12, __tegra_cpu_reset_handler_data + ldr r0, [r12, #RESET_DATA(TF_PRESENT)] + cmp r0, #0 + bne after_errata + #ifdef CONFIG_ARCH_TEGRA_2x_SOC t20_check: cmp r6, #TEGRA20@@ -155,7 +161,6 @@ after_errata: and r10, r10, #0x3 @ R10 = CPU number mov r11, #1 mov r11, r11, lsl r10 @ R11 = CPU mask - adr r12, __tegra_cpu_reset_handler_data #ifdef CONFIG_SMP /* Does the OS know about this CPU? */@@ -169,10 +174,9 @@ after_errata: cmp r6, #TEGRA20 bne 1f /* If not CPU0, don't let CPU0 reset CPU1 now that CPU1 is coming up. */ - mov32 r5, TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET mov r0, #CPU_NOT_RESETTABLE cmp r10, #0 - strneb r0, [r5, #__tegra20_cpu1_resettable_status_offset] + strneb r0, [r12, #RESET_DATA(RESETTABLE_STATUS)] 1: #endif@@ -278,13 +282,20 @@ ENDPROC(__tegra_cpu_reset_handler) .type __tegra_cpu_reset_handler_data, %object .globl __tegra_cpu_reset_handler_data __tegra_cpu_reset_handler_data: - .rept TEGRA_RESET_DATA_SIZE - .long 0 - .endr + .long 0 /* TEGRA_RESET_MASK_PRESENT */ + .long 0 /* TEGRA_RESET_MASK_LP1 */ + .long 0 /* TEGRA_RESET_MASK_LP2 */ + .long 0 /* TEGRA_RESET_STARTUP_SECONDARY */ + .long 0 /* TEGRA_RESET_STARTUP_LP2 */ + .long 0 /* TEGRA_RESET_STARTUP_LP1 */
arch/arm/mach-tegra/reset-handler.S ENDPROC(__tegra_cpu_reset_handler) · line 298
Quoted 10 lines
arch/arm/mach-tegra/reset-handler.S +4
-2+ .globl __tegra20_cpu1_resettable_status_offset .equ __tegra20_cpu1_resettable_status_offset, \ . - __tegra_cpu_reset_handler_start - .byte 0 - .align L1_CACHE_SHIFT + .long 0 /* TEGRA_RESET_RESETTABLE_STATUS */ + .globl __tegra_tf_present + .equ __tegra_tf_present, . - __tegra_cpu_reset_handler_start
I've noticed that __tegra_tf_present shouldn't belong to this patch, I've missed to remove it while was rebasing.
Also, it occurred to me that it will be much better to remove the whole array __tegra_cpu_reset_handler_data definition in the asm and get back to the
original ".rept TEGRA_RESET_DATA_SIZE" instead. That will make this part of
code much nicer, I'll change that in v2.
Russell / Thierry, please give you acks-reviews where appropriate and let me know if I should change anything else in v2, thanks.
Quoted 40 lines
arch/arm/mach-tegra/reset-handler.S +2
-0+ .long 0 /* TEGRA_RESET_TF_PRESENT */ + .align L1_CACHE_SHIFT ENTRY(__tegra_cpu_reset_handler_end)arch/arm/mach-tegra/reset.c +3
-0@@ -24,6 +24,7 @@#include <asm/cacheflush.h> #include <asm/firmware.h> #include <asm/hardware/cache-l2x0.h> +#include <asm/trusted_foundations.h> #include "iomap.h" #include "irammap.h" @@ -89,6 +90,8 @@ static void __init tegra_cpu_reset_handler_enable(void)void __init tegra_cpu_reset_handler_init (void ) { + __tegra_cpu_reset_handler_data[TEGRA_RESET_TF_PRESENT ] = +trusted_foundations_registered ();#ifdef CONFIG_SMP __tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_PRESENT] =arch/arm/mach-tegra/reset.h +3
-1@@ -25,7 +25,9 @@#define TEGRA_RESET_STARTUP_SECONDARY 3#define TEGRA_RESET_STARTUP_LP2 4#define TEGRA_RESET_STARTUP_LP1 5 -#define TEGRA_RESET_DATA_SIZE 6 +#define TEGRA_RESET_RESETTABLE_STATUS 6 +#define TEGRA_RESET_TF_PRESENT 7 +#define TEGRA_RESET_DATA_SIZE 8#ifndef __ASSEMBLY__