1From b70dd14eed59d7c5833ded8469cf99e631951e14 Mon Sep 17 00:00:00 2001
2From: Emekcan Aras <emekcan.aras@arm.com>
3Date: Wed, 15 Nov 2023 09:52:19 +0000
4Subject: [PATCH] platform: corstone1000: fix synchronization issue on openamp
5 notification
6
7This fixes a race that is observed rarely in the FVP. It occurs in FVP
8when tfm sends the notication ack in openamp, and then reset the access
9request which resets the mhu registers before received by the host
10processor. This solution introduces polling on the status register of
11mhu until the notificaiton is read by the host processor. (Inspired by
12signal_and_wait_for_signal function in mhu_wrapper_v2_x.c in trusted-firmware-m
13https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/tree/platform/ext/target/arm/rss/common/native_drivers/mhu_wrapper_v2_x.c#n61)
14
15Signed-off-by: Emekcan Aras <emekcan.aras@arm.com>
16Upstream-Status: Pending [Not submitted to upstream yet]
17---
18 .../corstone1000/openamp/platform_spe_dual_core_hal.c    | 9 ++++++++-
19 1 file changed, 8 insertions(+), 1 deletion(-)
20
21diff --git a/platform/ext/target/arm/corstone1000/openamp/platform_spe_dual_core_hal.c b/platform/ext/target/arm/corstone1000/openamp/platform_spe_dual_core_hal.c
22index 7613345ffc..b58088032f 100644
23--- a/platform/ext/target/arm/corstone1000/openamp/platform_spe_dual_core_hal.c
24+++ b/platform/ext/target/arm/corstone1000/openamp/platform_spe_dual_core_hal.c
25@@ -83,7 +83,7 @@ enum tfm_plat_err_t tfm_dual_core_hal_init(void)
26
27 enum tfm_plat_err_t tfm_hal_notify_peer(void)
28 {
29-    uint32_t access_ready;
30+    uint32_t access_ready,val;
31     enum mhu_v2_x_error_t status;
32     struct mhu_v2_x_dev_t* dev = &MHU1_SE_TO_HOST_DEV;
33
34@@ -108,6 +108,13 @@ enum tfm_plat_err_t tfm_hal_notify_peer(void)
35         return TFM_PLAT_ERR_SYSTEM_ERR;
36     }
37
38+    do {
39+        status = mhu_v2_x_channel_poll(dev, MHU1_SEH_NOTIFY_CH, &val);
40+        if (status != MHU_V_2_X_ERR_NONE) {
41+            break;
42+        }
43+    } while(val != 0);
44+
45     status = mhu_v2_x_reset_access_request(dev);
46     if (status != MHU_V_2_X_ERR_NONE) {
47         SPMLOG_ERRMSGVAL("mhu_v2_x_reset_access_request : ", status);
48--
492.25.1
50
51