summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Gerhold <stephan@gerhold.net>2023-04-06 21:43:37 +0200
committerManish V Badarkhe <manish.badarkhe@arm.com>2023-05-09 21:46:27 +0200
commit7e002c8a13172c44f55ab49062861479b6622884 (patch)
tree3b4f2deb6392a5c842f92a348936571c977d0366
parenta27e3f769832b8db21115a2b71d4f56fc0160e66 (diff)
downloadarm-trusted-firmware-7e002c8a13172c44f55ab49062861479b6622884.tar.gz
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 <stephan@gerhold.net>
-rw-r--r--plat/qti/msm8916/aarch64/msm8916_helpers.S13
-rw-r--r--plat/qti/msm8916/aarch64/uartdm_console.S18
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 <stephan@gerhold.net>
+ * Copyright (c) 2021-2023, Stephan Gerhold <stephan@gerhold.net>
*
* 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 <stephan@gerhold.net>
+ * Copyright (c) 2021-2023, Stephan Gerhold <stephan@gerhold.net>
*
* 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]