From 3fb7e40a21b1570a8ce1cd1708134fa7a05d94fb Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Tue, 23 Aug 2022 22:33:11 +0200 Subject: fix(msm8916): print \r before \n on UART console UART drivers in TF-A are expected to print \r before \n. Some terminal emulators expect \r\n as line endings by default so not doing this causes broken line breaks. Change-Id: I271a35a7c6907441bc71713b0b6a1da19da96878 Signed-off-by: Stephan Gerhold --- plat/qti/msm8916/aarch64/uartdm_console.S | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plat/qti/msm8916/aarch64/uartdm_console.S b/plat/qti/msm8916/aarch64/uartdm_console.S index c69c1932a..e14217939 100644 --- a/plat/qti/msm8916/aarch64/uartdm_console.S +++ b/plat/qti/msm8916/aarch64/uartdm_console.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Stephan Gerhold + * Copyright (c) 2021-2022, Stephan Gerhold * * Based on aarch64/skeleton_console.S: * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved. @@ -113,10 +113,21 @@ endfunc console_uartdm_putc * ----------------------------------------------------------- */ func console_uartdm_core_putc + cmp w0, #'\n' + b.ne 2f + 1: /* Loop until TX FIFO has space */ ldr w2, [x1, #UART_DM_SR] tbz w2, #UART_DM_SR_TXRDY_BIT, 1b + /* Prepend '\r' to '\n' */ + mov w2, #'\r' + str w2, [x1, #UART_DM_TF] + +2: /* Loop until TX FIFO has space */ + ldr w2, [x1, #UART_DM_SR] + tbz w2, #UART_DM_SR_TXRDY_BIT, 2b + /* Write character to FIFO */ str w0, [x1, #UART_DM_TF] ret -- cgit v1.2.1 From 01ba69cd9b833047653186858a6929e6c9379989 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Sat, 17 Sep 2022 18:21:20 +0200 Subject: fix(msm8916): flush dcache after writing msm8916_entry_point msm8916_entry_point is read with caches off (and even from two different physical addresses when read through the "boot remapper"), so it should be flushed to RAM after writing it. Change-Id: I5c8193954bb28043b0a46fb2038f629bd8796c74 Signed-off-by: Stephan Gerhold --- plat/qti/msm8916/msm8916_pm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plat/qti/msm8916/msm8916_pm.c b/plat/qti/msm8916/msm8916_pm.c index 6891e3800..792a09688 100644 --- a/plat/qti/msm8916/msm8916_pm.c +++ b/plat/qti/msm8916/msm8916_pm.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2021, Stephan Gerhold + * Copyright (c) 2021-2022, Stephan Gerhold * * SPDX-License-Identifier: BSD-3-Clause */ #include +#include #include #include #include @@ -53,7 +54,14 @@ extern uintptr_t msm8916_entry_point; int plat_setup_psci_ops(uintptr_t sec_entrypoint, const plat_psci_ops_t **psci_ops) { + /* + * The entry point is read with caches off (and even from two different + * physical addresses when read through the "boot remapper"), so make + * sure it is flushed to memory. + */ msm8916_entry_point = sec_entrypoint; + flush_dcache_range((uintptr_t)&msm8916_entry_point, sizeof(uintptr_t)); + *psci_ops = &msm8916_psci_ops; return 0; } -- cgit v1.2.1 From 4a3e2cb355dfa3e243d2546b96c7e0d112030bc8 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Tue, 14 Mar 2023 11:09:44 +0100 Subject: build(msm8916): disable unneeded workarounds The Cortex-A53 cores used in the msm8916 platform are not affected by CVE-2017-5715 and CVE-2022-23960, so disable the workarounds for them to drop the unused code from the compiled binary. Change-Id: I9df5a4657c4fd90702b4db4e82d4ee1a2f60303c Signed-off-by: Stephan Gerhold --- plat/qti/msm8916/platform.mk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plat/qti/msm8916/platform.mk b/plat/qti/msm8916/platform.mk index 2baf2032a..107296b0a 100644 --- a/plat/qti/msm8916/platform.mk +++ b/plat/qti/msm8916/platform.mk @@ -1,5 +1,5 @@ # -# Copyright (c) 2021, Stephan Gerhold +# Copyright (c) 2021-2023, Stephan Gerhold # # SPDX-License-Identifier: BSD-3-Clause # @@ -46,6 +46,10 @@ WARMBOOT_ENABLE_DCACHE_EARLY := 1 ENABLE_SPE_FOR_NS := 0 ENABLE_SVE_FOR_NS := 0 +# Disable workarounds unnecessary for Cortex-A53 +WORKAROUND_CVE_2017_5715 := 0 +WORKAROUND_CVE_2022_23960 := 0 + # MSM8916 uses ARM Cortex-A53 r0p0 so likely all the errata apply ERRATA_A53_819472 := 1 ERRATA_A53_824069 := 1 -- cgit v1.2.1 From d833af3ab50cd2cfecb8868c3d5340df1572f042 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Wed, 22 Mar 2023 18:15:15 +0100 Subject: fix(msm8916): drop unneeded initialization of CNTACR Normal world software is responsible to initialize CNTACR as needed. There is no existing software for msm8916 that depends on having this initialization in BL31 so drop it before anything starts to rely on it. Related issue: https://github.com/ARM-software/tf-issues/issues/170 Change-Id: I9d037ab218c0c1c8a5d5523722013eba531f4728 Signed-off-by: Stephan Gerhold --- plat/qti/msm8916/msm8916_bl31_setup.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plat/qti/msm8916/msm8916_bl31_setup.c b/plat/qti/msm8916/msm8916_bl31_setup.c index 638cd09d0..d24fb349b 100644 --- a/plat/qti/msm8916/msm8916_bl31_setup.c +++ b/plat/qti/msm8916/msm8916_bl31_setup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Stephan Gerhold + * Copyright (c) 2021-2023, Stephan Gerhold * * SPDX-License-Identifier: BSD-3-Clause */ @@ -121,10 +121,6 @@ static void msm8916_configure_timer(void) /* Make frame 0 available to non-secure world */ mmio_write_32(APCS_QTMR + CNTNSAR, BIT_32(CNTNSAR_NS_SHIFT(0))); - mmio_write_32(APCS_QTMR + CNTACR_BASE(0), - BIT_32(CNTACR_RPCT_SHIFT) | BIT_32(CNTACR_RVCT_SHIFT) | - BIT_32(CNTACR_RFRQ_SHIFT) | BIT_32(CNTACR_RVOFF_SHIFT) | - BIT_32(CNTACR_RWVT_SHIFT) | BIT_32(CNTACR_RWPT_SHIFT)); } /* -- cgit v1.2.1 From 1781bf1c40594e3a3f36404da793d5c7a6bca533 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Wed, 22 Mar 2023 18:15:15 +0100 Subject: feat(msm8916): expose more timer frames The memory-mapped generic timer on msm8916 has 7 timer frames, but currently only one is exposed for usage in the non-secure world. The platform port is currently only designed to be used as minimal PSCI implementation, without secure world that could make use of the other timer frames. Let's make all of them available to the normal world. If needed this could still be changed later by reserving some timer frames conditionally to a specific SPD being enabled in the build. Change-Id: Ib59df16aa1fd3dbc875ab6369c133737830c98c6 Signed-off-by: Stephan Gerhold --- plat/qti/msm8916/msm8916_bl31_setup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plat/qti/msm8916/msm8916_bl31_setup.c b/plat/qti/msm8916/msm8916_bl31_setup.c index d24fb349b..8cba5c521 100644 --- a/plat/qti/msm8916/msm8916_bl31_setup.c +++ b/plat/qti/msm8916/msm8916_bl31_setup.c @@ -119,8 +119,8 @@ static void msm8916_configure_timer(void) /* Set timer frequency */ mmio_write_32(APCS_QTMR + CNTCTLBASE_CNTFRQ, plat_get_syscnt_freq2()); - /* Make frame 0 available to non-secure world */ - mmio_write_32(APCS_QTMR + CNTNSAR, BIT_32(CNTNSAR_NS_SHIFT(0))); + /* Make all timer frames available to non-secure world */ + mmio_write_32(APCS_QTMR + CNTNSAR, GENMASK_32(7, 0)); } /* -- cgit v1.2.1 From a27e3f769832b8db21115a2b71d4f56fc0160e66 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Sun, 26 Mar 2023 13:07:25 +0200 Subject: style(msm8916): use size macros Use the pre-defined size macros (SZ_*) for more clarity and to avoid having to add comments to each size represented by hexadecimal numbers. Change-Id: I6aebe2caf1365279670955b9b507dec7d7b04457 Signed-off-by: Stephan Gerhold --- plat/qti/msm8916/include/msm8916_mmap.h | 4 ++-- plat/qti/msm8916/include/platform_def.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plat/qti/msm8916/include/msm8916_mmap.h b/plat/qti/msm8916/include/msm8916_mmap.h index 406ae6b4e..d20153682 100644 --- a/plat/qti/msm8916/include/msm8916_mmap.h +++ b/plat/qti/msm8916/include/msm8916_mmap.h @@ -8,9 +8,9 @@ #define MSM8916_MMAP_H #define PCNOC_BASE 0x00000000 -#define PCNOC_SIZE 0x8000000 /* 128 MiB */ +#define PCNOC_SIZE SZ_128M #define APCS_BASE 0x0b000000 -#define APCS_SIZE 0x800000 /* 8 MiB */ +#define APCS_SIZE SZ_8M #define MPM_BASE (PCNOC_BASE + 0x04a0000) #define MPM_PS_HOLD (MPM_BASE + 0xb000) diff --git a/plat/qti/msm8916/include/platform_def.h b/plat/qti/msm8916/include/platform_def.h index bfade70a3..6d5ff2b33 100644 --- a/plat/qti/msm8916/include/platform_def.h +++ b/plat/qti/msm8916/include/platform_def.h @@ -16,11 +16,11 @@ * the overall limit to 128 KiB. This could be increased if needed by placing * the "msm8916_entry_point" variable explicitly in the first 64 KiB of BL31. */ -#define BL31_LIMIT (BL31_BASE + 0x20000) /* 128 KiB */ -#define BL31_PROGBITS_LIMIT (BL31_BASE + 0x10000) /* 64 KiB */ +#define BL31_LIMIT (BL31_BASE + SZ_128K) +#define BL31_PROGBITS_LIMIT (BL31_BASE + SZ_64K) #define CACHE_WRITEBACK_GRANULE U(64) -#define PLATFORM_STACK_SIZE U(0x1000) +#define PLATFORM_STACK_SIZE SZ_4K /* CPU topology: single cluster with 4 cores */ #define PLATFORM_CLUSTER_COUNT U(1) -- cgit v1.2.1 From 7e002c8a13172c44f55ab49062861479b6622884 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Thu, 6 Apr 2023 21:43:37 +0200 Subject: fix(msm8916): add timeout for crash console TX flush Resetting the UART DM controller while there are still remaining characters in the FIFO often results in corruption on the UART receiver side. To avoid this the msm8916 crash console implementation tries to wait until the TX FIFO is empty. Unfortunately this might spin forever if the transmitter was disabled before it has fully finished transmitting. In this case the TXEMT bit console_uartdm_core_flush is waiting for will never get set. There seems to be no good way to detect if the transmitter is actually enabled via the status registers. However, the TX FIFO is fairly small and should not take too long to get flushed, so fix this by simply limiting the amount of iterations with a short timeout. Move the code to console_uartdm_core_init to ensure that this always happens before resetting the transmitter (also during initialization). Change-Id: I5bb43cb0b6c029bcd15e253d60d36c0b310e108b Signed-off-by: Stephan Gerhold --- plat/qti/msm8916/aarch64/msm8916_helpers.S | 13 +------------ plat/qti/msm8916/aarch64/uartdm_console.S | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/plat/qti/msm8916/aarch64/msm8916_helpers.S b/plat/qti/msm8916/aarch64/msm8916_helpers.S index dad9968ad..528c5a42e 100644 --- a/plat/qti/msm8916/aarch64/msm8916_helpers.S +++ b/plat/qti/msm8916/aarch64/msm8916_helpers.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Stephan Gerhold + * Copyright (c) 2021-2023, Stephan Gerhold * * SPDX-License-Identifier: BSD-3-Clause */ @@ -31,17 +31,6 @@ */ func plat_crash_console_init mov x1, #BLSP_UART2_BASE - - /* - * If the non-secure world has been actively using the UART there might - * be still some characters left to be sent in the FIFO. In that case, - * resetting the transmitter too early might cause all output to become - * corrupted. To avoid that, try to flush (wait until FIFO empty) first. - */ - mov x4, lr - bl console_uartdm_core_flush - mov lr, x4 - mov x0, #1 b console_uartdm_core_init endfunc plat_crash_console_init diff --git a/plat/qti/msm8916/aarch64/uartdm_console.S b/plat/qti/msm8916/aarch64/uartdm_console.S index e14217939..6c65daf04 100644 --- a/plat/qti/msm8916/aarch64/uartdm_console.S +++ b/plat/qti/msm8916/aarch64/uartdm_console.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Stephan Gerhold + * Copyright (c) 2021-2023, Stephan Gerhold * * Based on aarch64/skeleton_console.S: * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved. @@ -65,7 +65,21 @@ endfunc console_uartdm_register * ----------------------------------------------------------- */ func console_uartdm_core_init - /* Reset receiver */ + /* + * Try to flush remaining characters from the TX FIFO before resetting + * the transmitter. Unfortunately there is no good way to check if + * the transmitter is actually enabled (and will finish eventually), + * so use a timeout to avoid looping forever. + */ + mov w2, #65536 +1: + ldr w3, [x1, #UART_DM_SR] + tbnz w3, #UART_DM_SR_TXEMT_BIT, 2f + subs w2, w2, #1 + b.ne 1b + /* Timeout */ + +2: /* Reset receiver */ mov w3, #UART_DM_CR_RESET_RX str w3, [x1, #UART_DM_CR] -- cgit v1.2.1