Support Trusted Foundations firmware on Tegra30
Subsystems (3)
v10 cover Support Trusted Foundations firmware on Tegra30
Hello,
This patchset adds support for the Trusted Foundations firmware on NVIDIA Tegra30. Pretty much all of Tegra30 consumer devices have that firmware and upstream kernel can't boot on those devices without the firmware support. This series was tested on Nexus 7, TF300T and Ouya Tegra30 devices.
Changelog:
v10: - Removed duplicated message about keeping L2C disabled when
CONFIG_TRUSTED_FOUNDATIONS=n as was suggested by Michał Mirosław in the review comment to v9.
v9: - Rebased on recent linux-next, resolved one conflict.
v8: - Replaced BIT() macro with a definition provided by cache-l2x0.h
in the "Support L2 cache maintenance" patch as was suggested by Russell King in the review comment to v7.
v7: - Fixed kernel booting with CONFIG_TRUSTED_FOUNDATIONS=n by
providing a dummy L2C write_sec implementation in the "Support L2 cache maintenance" patch.
- Minor clean up: no static variables anymore, replaced white spaces with a tab in one place, etc.
- Added Michał's and Robert's Tested-by/Signed-off-by to the patches.
v6: - One patch got messed up accidentally in v5, this is fixed now.
- Squashed "Support L2 cache maintenance done via firmware" patch into the "Add firmware calls..." patch.
- The l2x0_init() firmware callback is now invoked unconditionally because it is always a NO-OP on T114+ and is a NO-OP on T20/30 if firmware node is missed in device-tree, hence there is no need to check the machine's DT compatible as it was done in the previous versions of the series.
v5: - Fixed machine hanging on disabling D-cache during suspend,
turned out there are slight variations in behaviour between firmware version in regards to cache-management. Thanks to Robert Yang for reporting the problem and helping with the solution.
v4: - Fixed Thumb2-kernel hanging on Tegra20, turned out it was not a
good idea to switch CPU into Thumb2 mode right after jumping into the reset handler.
- Moved LP2-mode-set firmware call invocation to a later stage to better replicate what downstream kernel does. This change was suggested by Robert Yang and fixes system hang on Ouya game console.
- Added references to the original work made by Michał Mirosław into commit messages of the relevant patches.
v3: - Implemented suspend-resume support.
- Reworked arm/firmware/trusted_foundations.c a tad. Now cache is getting properly initialized, cache enabling / disabling is supported.
v2:
- The "Don't apply CPU erratas in insecure mode" patch got some cleanup, in particular resolved the messiness in __tegra_cpu_reset_handler_data.
- Added a comment to tf_cache_write_sec(), justifying the warning message.
Dmitry Osipenko (7):
ARM: trusted_foundations: Support L2 cache maintenance
ARM: trusted_foundations: Make prepare_idle call to take mode argument
ARM: trusted_foundations: Provide information about whether firmware
is registered
ARM: tegra: Set up L2 cache using Trusted Foundations firmware
ARM: tegra: Don't apply CPU erratas in insecure mode
ARM: tegra: Always boot CPU in ARM-mode
ARM: tegra: Add firmware calls required for suspend-resume on Tegra30
arch/arm/firmware/trusted_foundations.c | 75 +++++++++++++++++++++- arch/arm/include/asm/firmware.h | 2 +- arch/arm/include/asm/trusted_foundations.h | 23 +++++++ arch/arm/mach-tegra/cpuidle-tegra114.c | 3 +- arch/arm/mach-tegra/pm.c | 49 ++++++++++++++ arch/arm/mach-tegra/reset-handler.S | 50 +++++++++++---- arch/arm/mach-tegra/reset.c | 3 + arch/arm/mach-tegra/reset.h | 9 ++- arch/arm/mach-tegra/sleep-tegra20.S | 4 ++ arch/arm/mach-tegra/sleep.S | 14 ++-- arch/arm/mach-tegra/tegra.c | 2 + 11 files changed, 212 insertions(+), 22 deletions(-)
Signature · 1 line
2.20.1
PATCH v10 1/7 ARM: trusted_foundations: Support L2 cache maintenance
Implement L2 cache initialization firmware callback that should be invoked early during boot in order to set up the required outer cache driver's callbacks and add the callback required for L2X0 maintenance.
Partially based on work done by Michał Mirosław [1].
[1] https://www.spinics.net/lists/arm-kernel/msg594765.html
--- arch/arm/firmware/trusted_foundations.c | 41 ++++++++++++++++++++++ arch/arm/include/asm/trusted_foundations.h | 10 ++++++ 2 files changed, 51 insertions(+)
arch/arm/firmware/trusted_foundations.c +41 -0
@@ -18,8 +18,15 @@#include <linux/init.h> #include <linux/of.h> #include <asm/firmware.h> +#include <asm/hardware/cache-l2x0.h> +#include <asm/outercache.h> #include <asm/trusted_foundations.h> +#define TF_CACHE_MAINT 0xfffff100 + +#define TF_CACHE_ENABLE 1 +#define TF_CACHE_DISABLE 2 +#define TF_SET_CPU_BOOT_ADDR_SMC 0xfffff200#define TF_CPU_PM 0xfffffffc
@@ -67,9 +74,43 @@ static int tf_prepare_idle(void)return 0 ; } +#ifdef CONFIG_CACHE_L2X0 +static void tf_cache_write_sec (unsigned long val,unsigned int reg) +{ +u32 l2x0_way_mask =0xff ; + +switch (reg) { +case L2X0_CTRL : +if (l2x0_saved_regs.aux_ctrl &L310_AUX_CTRL_ASSOCIATIVITY_16 ) + l2x0_way_mask =0xffff ; + +if (val ==L2X0_CTRL_EN ) +tf_generic_smc (TF_CACHE_MAINT ,TF_CACHE_ENABLE , + l2x0_saved_regs.aux_ctrl); +else +tf_generic_smc (TF_CACHE_MAINT ,TF_CACHE_DISABLE , + l2x0_way_mask); +break ; + +default : +break ; + } +} + +static int tf_init_cache (void ) +{ + outer_cache.write_sec = tf_cache_write_sec; + +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)
arch/arm/include/asm/trusted_foundations.h +10 -0
@@ -32,6 +32,9 @@#include <linux/cpu.h> #include <linux/smp.h> +#include <asm/hardware/cache-l2x0.h> +#include <asm/outercache.h> +struct trusted_foundations_platform_data {unsigned int version_major;unsigned int version_minor;
@@ -43,6 +46,9 @@ void register_trusted_foundations(struct trusted_foundations_platform_data *pd);void of_register_trusted_foundations (void );#else /* CONFIG_TRUSTED_FOUNDATIONS */ +static inline void tf_dummy_write_sec (unsigned long val,unsigned int reg) +{ +}static inline void register_trusted_foundations (struct trusted_foundations_platform_data *pd)
@@ -53,6 +59,10 @@ static inline void register_trusted_foundations(*/ pr_err ("No support for Trusted Foundations, continuing in degraded mode.\n" );pr_err ("Secondary processors as well as CPU PM will be disabled.\n" ); +#if IS_ENABLED (CONFIG_CACHE_L2X0 ) +pr_err ("L2X0 cache will be kept disabled.\n" ); + outer_cache.write_sec = tf_dummy_write_sec; +#endif #if IS_ENABLED (CONFIG_SMP ) setup_max_cpus =0 ;#endif
Signature · 1 line
2.20.1
PATCH v10 2/7 ARM: trusted_foundations: Make prepare_idle call to take mode argument
In reply to Dmitry OsipenkoThe Trusted Foundations firmware call varies depending on the required suspend-mode. Make the firmware API to take the mode argument in order to expose all of the modes to firmware user.
--- arch/arm/firmware/trusted_foundations.c | 29 ++++++++++++++++++++-- arch/arm/include/asm/firmware.h | 2 +- arch/arm/include/asm/trusted_foundations.h | 6 +++++ arch/arm/mach-tegra/cpuidle-tegra114.c | 3 ++- 4 files changed, 36 insertions(+), 4 deletions(-)
arch/arm/firmware/trusted_foundations.c +27 -2
@@ -67,9 +67,34 @@ static int tf_set_cpu_boot_addr(int cpu, unsigned long boot_addr)return 0 ; } -static int tf_prepare_idle (void ) +static int tf_prepare_idle (unsigned long mode) { -tf_generic_smc (TF_CPU_PM ,TF_CPU_PM_S1_NOFLUSH_L2 , cpu_boot_addr); +switch (mode) { +case TF_PM_MODE_LP0 : +tf_generic_smc (TF_CPU_PM ,TF_CPU_PM_S3 , cpu_boot_addr); +break ; + +case TF_PM_MODE_LP1 : +tf_generic_smc (TF_CPU_PM ,TF_CPU_PM_S2 , cpu_boot_addr); +break ; + +case TF_PM_MODE_LP1_NO_MC_CLK : +tf_generic_smc (TF_CPU_PM ,TF_CPU_PM_S2_NO_MC_CLK , + cpu_boot_addr); +break ; + +case TF_PM_MODE_LP2 : +tf_generic_smc (TF_CPU_PM ,TF_CPU_PM_S1 , cpu_boot_addr); +break ; + +case TF_PM_MODE_LP2_NOFLUSH_L2 : +tf_generic_smc (TF_CPU_PM ,TF_CPU_PM_S1_NOFLUSH_L2 , + cpu_boot_addr); +break ; + +default : +return -EINVAL ; + }return 0 ; }
arch/arm/include/asm/firmware.h +1 -1
@@ -24,7 +24,7 @@ struct firmware_ops {/* * Inform the firmware we intend to enter CPU idle mode */ -int (*prepare_idle)(void ); +int (*prepare_idle)(unsigned long mode);/* * Enters CPU idle mode */
arch/arm/include/asm/trusted_foundations.h +6 -0
@@ -35,6 +35,12 @@#include <asm/hardware/cache-l2x0.h> #include <asm/outercache.h> +#define TF_PM_MODE_LP0 0 +#define TF_PM_MODE_LP1 1 +#define TF_PM_MODE_LP1_NO_MC_CLK 2 +#define TF_PM_MODE_LP2 3 +#define TF_PM_MODE_LP2_NOFLUSH_L2 4 +struct trusted_foundations_platform_data {unsigned int version_major;unsigned int version_minor;
arch/arm/mach-tegra/cpuidle-tegra114.c +2 -1
@@ -24,6 +24,7 @@#include <asm/cpuidle.h> #include <asm/smp_plat.h> #include <asm/suspend.h> +#include <asm/trusted_foundations.h> #include <asm/psci.h> #include "cpuidle.h"
@@ -46,7 +47,7 @@ static int tegra114_idle_power_down(struct cpuidle_device *dev,tegra_set_cpu_in_lp2 ();cpu_pm_enter (); -call_firmware_op (prepare_idle); +call_firmware_op (prepare_idle,TF_PM_MODE_LP2_NOFLUSH_L2 );/* Do suspend by ourselves if the firmware does not implement it */ if (call_firmware_op (do_idle,0 ) == -ENOSYS )
Signature · 1 line
2.20.1
PATCH v10 3/7 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
@@ -167,3 +167,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> #include <asm/hardware/cache-l2x0.h> #include <asm/outercache.h>
@@ -50,6 +51,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 */ static inline void tf_dummy_write_sec (unsigned long val,unsigned int reg)
@@ -84,6 +86,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.20.1
PATCH v10 4/7 ARM: tegra: Set up L2 cache using Trusted Foundations firmware
In reply to Dmitry OsipenkoOn Tegra30 L2 cache should be initialized using firmware call if CPU is running in insecure mode. Set up the required outer-cache write_sec() callback early during boot using the firmware API, it is always a NO-OP on T114+ and is NO-OP on T20/30 if Trusted Foundations firmware node isn't present in device-tree.
--- arch/arm/mach-tegra/tegra.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/mach-tegra/tegra.c +2 -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>
@@ -74,6 +75,7 @@ static void __init tegra_init_early(void) {of_register_trusted_foundations ();tegra_cpu_reset_handler_init (); +call_firmware_op (l2x0_init); }static void __init tegra_dt_init_irq (void )
Signature · 1 line
2.20.1
PATCH v10 5/7 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 of CPU erratas in the reset handler if Trusted Foundations firmware presents.
Partially based on work done by Michał Mirosław [1].
[1] https://www.spinics.net/lists/arm-kernel/msg594768.html
--- arch/arm/mach-tegra/reset-handler.S | 23 ++++++++++++----------- arch/arm/mach-tegra/reset.c | 3 +++ arch/arm/mach-tegra/reset.h | 9 +++++++-- arch/arm/mach-tegra/sleep-tegra20.S | 4 ++++ 4 files changed, 26 insertions(+), 13 deletions(-)
arch/arm/mach-tegra/reset-handler.S +12 -11
@@ -29,8 +29,6 @@ #define PMC_SCRATCH41 0x140 -#define RESET_DATA(x) ((TEGRA_RESET_##x)*4) - #ifdef CONFIG_PM_SLEEP /* * tegra_resume
@@ -121,6 +119,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 r5, [r12, #RESET_DATA(TF_PRESENT)] + cmp r5, #0 + bne after_errata + #ifdef CONFIG_ARCH_TEGRA_2x_SOC t20_check: cmp r6, #TEGRA20
@@ -155,7 +159,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 +172,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 - strbne r0, [r5, #__tegra20_cpu1_resettable_status_offset] + strbne r0, [r12, #RESET_DATA(RESETTABLE_STATUS)] 1: #endif
@@ -277,14 +279,13 @@ ENDPROC(__tegra_cpu_reset_handler) .align L1_CACHE_SHIFT .type __tegra_cpu_reset_handler_data, %object .globl __tegra_cpu_reset_handler_data + .globl __tegra_cpu_reset_handler_data_offset + .equ __tegra_cpu_reset_handler_data_offset, \ + . - __tegra_cpu_reset_handler_start __tegra_cpu_reset_handler_data: - .rept TEGRA_RESET_DATA_SIZE - .long 0 + .rept TEGRA_RESET_DATA_SIZE + .long 0 .endr - .globl __tegra20_cpu1_resettable_status_offset - .equ __tegra20_cpu1_resettable_status_offset, \ - . - __tegra_cpu_reset_handler_start - .byte 0 .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 +7 -2
@@ -25,7 +25,11 @@#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 + +#define RESET_DATA (x) ((TEGRA_RESET_##x)*4)#ifndef __ASSEMBLY__
@@ -49,7 +53,8 @@ void __tegra_cpu_reset_handler_end(void); (u32)__tegra_cpu_reset_handler_start)))#define tegra20_cpu1_resettable_status \ (IO_ADDRESS(TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET + \ - (u32)__tegra20_cpu1_resettable_status_offset)) + ((u32)&__tegra_cpu_reset_handler_data[TEGRA_RESET_RESETTABLE_STATUS] - \ + (u32)__tegra_cpu_reset_handler_start)))#endif #define tegra_cpu_reset_handler_offset \
arch/arm/mach-tegra/sleep-tegra20.S +4 -0
@@ -28,6 +28,7 @@ #include <asm/cache.h> #include "irammap.h" +#include "reset.h" #include "sleep.h" #define EMC_CFG 0xc
@@ -53,6 +54,9 @@ #define APB_MISC_XM2CFGCPADCTRL2 0x8e4 #define APB_MISC_XM2CFGDPADCTRL2 0x8e8 +#define __tegra20_cpu1_resettable_status_offset \ + (__tegra_cpu_reset_handler_data_offset + RESET_DATA(RESETTABLE_STATUS)) + .macro pll_enable, rd, r_car_base, pll_base ldr \rd, [\r_car_base, #\pll_base] tst \rd, #(1 << 30)
Signature · 1 line
2.20.1
PATCH v10 6/7 ARM: tegra: Always boot CPU in ARM-mode
In reply to Dmitry OsipenkoCPU always jumps into reset handler in ARM-mode from the Trusted Foundations firmware, hence let's make CPU to always jump into kernel in ARM-mode regardless of the firmware presence. This is required to make Thumb-2 kernel working with the Trusted Foundations firmware on Tegra30.
--- arch/arm/mach-tegra/reset-handler.S | 1 + 1 file changed, 1 insertion(+)
arch/arm/mach-tegra/reset-handler.S +1 -0
@@ -113,6 +113,7 @@ ENTRY(__tegra_cpu_reset_handler_start) * must be position-independent. */ + .arm .align L1_CACHE_SHIFT ENTRY(__tegra_cpu_reset_handler)
Signature · 1 line
2.20.1
PATCH v10 7/7 ARM: tegra: Add firmware calls required for suspend-resume on Tegra30
In reply to Dmitry OsipenkoIn order to suspend-resume CPU with Trusted Foundations firmware being present on Tegra30, the LP1/LP2 boot vectors and CPU caches need to be set up using the firmware calls and then suspend code shall avoid re-disabling parts that were disabled by the firmware.
--- arch/arm/mach-tegra/pm.c | 49 +++++++++++++++++++++++++++++ arch/arm/mach-tegra/reset-handler.S | 26 +++++++++++++++ arch/arm/mach-tegra/sleep.S | 14 ++++++--- 3 files changed, 84 insertions(+), 5 deletions(-)
arch/arm/mach-tegra/pm.c +49 -0
@@ -33,11 +33,13 @@#include <soc/tegra/pmc.h> #include <asm/cacheflush.h> +#include <asm/firmware.h> #include <asm/idmap.h> #include <asm/proc-fns.h> #include <asm/smp_plat.h> #include <asm/suspend.h> #include <asm/tlbflush.h> +#include <asm/trusted_foundations.h> #include "iomap.h" #include "pm.h"
@@ -159,6 +161,28 @@ int tegra_cpu_do_idle(void)static int tegra_sleep_cpu (unsigned long v2p) { +/* +* L2 cache disabling using kernel API only allowed when all +* secondary CPU's are offline. Cache have to be disabled with +* MMU-on if cache maintenance is done via Trusted Foundations +* firmware. Note that CPUIDLE won't ever enter powergate on Tegra30 +* if any of secondary CPU's is online and this is the LP2-idle +* code-path only for Tegra20/30. +*/ +if (trusted_foundations_registered ()) +outer_disable (); + +/* +* Note that besides of setting up CPU reset vector this firmware +* call may also do the following, depending on the FW version: +* 1) Disable L2. But this doesn't matter since we already +* disabled the L2. +* 2) Disable D-cache. This need to be taken into account in +* particular by the tegra_disable_clean_inv_dcache() which +* shall avoid the re-disable. +*/ +call_firmware_op (prepare_idle,TF_PM_MODE_LP2 ); +setup_mm_for_reboot ();tegra_sleep_cpu_finish (v2p);
@@ -197,6 +221,14 @@ void tegra_idle_lp2_last(void)cpu_suspend (PHYS_OFFSET -PAGE_OFFSET , &tegra_sleep_cpu); +/* +* Resume L2 cache if it wasn't re-enabled early during resume, +* which is the case for Tegra30 that has to re-enable the cache +* via firmware call. In other cases cache is already enabled and +* hence re-enabling is a no-op. This is always a no-op on Tegra114+. +*/ +outer_resume (); +restore_cpu_complex ();cpu_cluster_pm_exit (); }
@@ -215,6 +247,15 @@ enum tegra_suspend_mode tegra_pm_validate_suspend_mode(static int tegra_sleep_core (unsigned long v2p) { +/* +* Cache have to be disabled with MMU-on if cache maintenance is done +* via Trusted Foundations firmware. This is a no-op on Tegra114+. +*/ +if (trusted_foundations_registered ()) +outer_disable (); + +call_firmware_op (prepare_idle,TF_PM_MODE_LP1 ); +setup_mm_for_reboot ();tegra_sleep_core_finish (v2p);
@@ -342,6 +383,14 @@ static int tegra_suspend_enter(suspend_state_t state)cpu_suspend (PHYS_OFFSET -PAGE_OFFSET , tegra_sleep_func); +/* +* Resume L2 cache if it wasn't re-enabled early during resume, +* which is the case for Tegra30 that has to re-enable the cache +* via firmware call. In other cases cache is already enabled and +* hence re-enabling is a no-op. +*/ +outer_resume (); +switch (mode) {case TEGRA_SUSPEND_LP1 :tegra_suspend_exit_lp1 ();
arch/arm/mach-tegra/reset-handler.S +26 -0
@@ -20,6 +20,7 @@ #include <soc/tegra/flowctrl.h> #include <soc/tegra/fuse.h> +#include <asm/assembler.h> #include <asm/asm-offsets.h> #include <asm/cache.h>
@@ -76,6 +77,7 @@ ENTRY(tegra_resume) orr r1, r1, #1 str r1, [r0] #endif + bl tegra_resume_trusted_foundations #ifdef CONFIG_CACHE_L2X0 /* L2 cache resume & re-enable */
@@ -88,6 +90,30 @@ end_ca9_scu_l2_resume: b cpu_resume ENDPROC(tegra_resume) + +/* + * tegra_resume_trusted_foundations + * + * Trusted Foundations firmware initialization. + * + * Doesn't return if firmware presents. + * Corrupted registers: r1, r2 + */ +ENTRY(tegra_resume_trusted_foundations) + /* Check whether Trusted Foundations firmware presents. */ + mov32 r2, TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET + ldr r1, =__tegra_cpu_reset_handler_data_offset + \ + RESET_DATA(TF_PRESENT) + ldr r1, [r2, r1] + cmp r1, #0 + reteq lr + + .arch_extension sec + /* First call after suspend wakes firmware. No arguments required. */ + smc #0 + + b cpu_resume +ENDPROC(tegra_resume_trusted_foundations) #endif .align L1_CACHE_SHIFT
arch/arm/mach-tegra/sleep.S +9 -5
@@ -49,8 +49,9 @@ ENTRY(tegra_disable_clean_inv_dcache) /* Disable the D-cache */ mrc p15, 0, r2, c1, c0, 0 + tst r2, #CR_C @ see tegra_sleep_cpu() bic r2, r2, #CR_C - mcr p15, 0, r2, c1, c0, 0 + mcrne p15, 0, r2, c1, c0, 0 isb /* Flush the D-cache */
@@ -132,10 +133,13 @@ ENTRY(tegra_shut_off_mmu) #ifdef CONFIG_CACHE_L2X0 /* Disable L2 cache */ check_cpu_part_num 0xc09, r9, r10 - movweq r2, #:lower16:(TEGRA_ARM_PERIF_BASE + 0x3000) - movteq r2, #:upper16:(TEGRA_ARM_PERIF_BASE + 0x3000) - moveq r3, #0 - streq r3, [r2, #L2X0_CTRL] + retne r0 + + mov32 r2, TEGRA_ARM_PERIF_BASE + 0x3000 + ldr r3, [r2, #L2X0_CTRL] + tst r3, #L2X0_CTRL_EN @ see tegra_sleep_cpu() + mov r3, #0 + strne r3, [r2, #L2X0_CTRL] #endif ret r0 ENDPROC(tegra_shut_off_mmu)
Signature · 1 line
2.20.1
18.03.2019 1:52, Dmitry Osipenko пишет:
Quoted 7 lines
Hello,
This patchset adds support for the Trusted Foundations firmware on NVIDIA Tegra30. Pretty much all of Tegra30 consumer devices have that firmware and upstream kernel can't boot on those devices without the firmware support. This series was tested on Nexus 7, TF300T and Ouya Tegra30 devices.
Russell, could you please give yours ACK to the firmware patches so that Thierry could pick up the patchset to the Tegra's tree? Alternatively we may take your silence as an implicit ACK and move on if you won't answer.
Quoted 83 lines · Dmitry Osipenko
Hello,
This patchset adds support for the Trusted Foundations firmware on NVIDIA Tegra30. Pretty much all of Tegra30 consumer devices have that firmware and upstream kernel can't boot on those devices without the firmware support. This series was tested on Nexus 7, TF300T and Ouya Tegra30 devices.
Changelog:
v10: - Removed duplicated message about keeping L2C disabled when
CONFIG_TRUSTED_FOUNDATIONS=nas was suggested by Michał Mirosław in the review comment to v9.v9: - Rebased on recent linux-next, resolved one conflict.
v8: - Replaced
BIT()macro with a definition provided bycache-l2x0.h
in the "Support L2 cache maintenance" patch as was suggested by Russell King in the review comment to v7.v7: - Fixed kernel booting with
CONFIG_TRUSTED_FOUNDATIONS=nby
providing a dummy L2Cwrite_secimplementation in the "Support L2 cache maintenance" patch.- Minor clean up: no static variables anymore, replaced white spaces with a tab in one place, etc.
- Added Michał's and Robert's Tested-by/Signed-off-by to the patches.
v6: - One patch got messed up accidentally in v5, this is fixed now.
- Squashed "Support L2 cache maintenance done via firmware" patch into the "Add firmware calls..." patch.
- The
l2x0_init()firmware callback is now invoked unconditionally because it is always a NO-OP on T114+ and is a NO-OP on T20/30 if firmware node is missed in device-tree, hence there is no need to check the machine's DT compatible as it was done in the previous versions of the series.v5: - Fixed machine hanging on disabling D-cache during suspend,
turned out there are slight variations in behaviour between firmware version in regards to cache-management. Thanks to Robert Yang for reporting the problem and helping with the solution.v4: - Fixed Thumb2-kernel hanging on Tegra20, turned out it was not a
good idea to switch CPU into Thumb2 mode right after jumping into the reset handler.- Moved LP2-mode-set firmware call invocation to a later stage to better replicate what downstream kernel does. This change was suggested by Robert Yang and fixes system hang on Ouya game console.
- Added references to the original work made by Michał Mirosław into commit messages of the relevant patches.
v3: - Implemented suspend-resume support.
- Reworked
arm/firmware/trusted_foundations.ca tad. Now cache is getting properly initialized, cache enabling / disabling is supported.v2:
- The "Don't apply CPU erratas in insecure mode" patch got some cleanup, in particular resolved the messiness in__tegra_cpu_reset_handler_data.- Added a comment to
tf_cache_write_sec(), justifying the warning message.Dmitry Osipenko (7):
ARM:trusted_foundations: Support L2 cache maintenance
ARM:trusted_foundations: Makeprepare_idlecall to take mode argument
ARM:trusted_foundations: Provide information about whether firmware
is registered
ARM: tegra: Set up L2 cache using Trusted Foundations firmware
ARM: tegra: Don't apply CPU erratas in insecure mode
ARM: tegra: Always boot CPU in ARM-mode
ARM: tegra: Add firmware calls required for suspend-resume on Tegra30
Quoted 12 lines
arch/arm/firmware/trusted_foundations.c | 75 +++++++++++++++++++++- arch/arm/include/asm/firmware.h | 2 +- arch/arm/include/asm/trusted_foundations.h | 23 +++++++ arch/arm/mach-tegra/cpuidle-tegra114.c | 3 +- arch/arm/mach-tegra/pm.c | 49 ++++++++++++++ arch/arm/mach-tegra/reset-handler.S | 50 +++++++++++---- arch/arm/mach-tegra/reset.c | 3 + arch/arm/mach-tegra/reset.h | 9 ++- arch/arm/mach-tegra/sleep-tegra20.S | 4 ++ arch/arm/mach-tegra/sleep.S | 14 ++-- arch/arm/mach-tegra/tegra.c | 2 + 11 files changed, 212 insertions(+), 22 deletions(-)
Hi Russell,
I've picked these up into the Tegra tree so that they can get more exposure. Let me know if you have any objections to me carrying these in the Tegra tree.
Thanks,
Thierry