RSE: Update handling of the requested permissions

Once the authentication is success, if a reset is required, then
copy the permission mask to the shared area from which BL1 can
extract and the apply to the DCU.

Also, notify the same using the software defined
reset syndrome register.

Signed-off-by: Maulik Patel <maulik.patel@arm.com>
Change-Id: Iad9086fa1829c401452f9299558e33f8d5e6c55f
diff --git a/target/trusted-firmware-m/platform/arm/rse/common/psa_adac_platform.c b/target/trusted-firmware-m/platform/arm/rse/common/psa_adac_platform.c
index f1fa64d..2174521 100644
--- a/target/trusted-firmware-m/platform/arm/rse/common/psa_adac_platform.c
+++ b/target/trusted-firmware-m/platform/arm/rse/common/psa_adac_platform.c
@@ -17,6 +17,8 @@
 #include "crypto_hw.h"
 
 #include <string.h>
+#include <stdbool.h>
+#include "rse_debug_after_reset.h"
 
 #define ROTPK_ANCHOR_ALG PSA_ALG_SHA_512
 
@@ -71,18 +73,41 @@
     return 0;
 }
 
+static bool check_if_debug_requires_reset(uint8_t *permissions_mask,
+                                          size_t mask_len)
+{
+    //TODO: To be implemented;
+    return true;
+}
+
 int psa_adac_apply_permissions(uint8_t permissions_mask[16])
 {
-    int ret = crypto_hw_apply_debug_permissions(permissions_mask, 16);
-    if (ret) {
-        PSA_ADAC_LOG_ERR("platform", "psa_adac_to_tfm_apply_permissions "
-                          "failed\r\n");
-        return ret;
+
+    int rc;
+    bool reset_required;
+
+    reset_required = check_if_debug_requires_reset(permissions_mask, 16);
+
+    if (reset_required) {
+
+        PSA_ADAC_LOG_INFO("platform", "psa_adac_to_tfm_apply_permissions "
+                          "Requesting reset to apply permissions in BL1 \r\n");
+        rse_debug_after_reset(permissions_mask, 16);
+
+    } else {
+
+        /* Reset is not required to apply the permissions */
+        rc = crypto_hw_apply_debug_permissions(permissions_mask, 16);
+        if (rc != 0) {
+            PSA_ADAC_LOG_ERR("platform", "psa_adac_to_tfm_apply_permissions "
+                            "failed\r\n");
+            return rc;
+        }
     }
 
     PSA_ADAC_LOG_INFO("platform",
                       "\r\nPlatform unlocked for the secure debug %s\n");
-    return ret;
+    return 0;
 }
 
 int tfm_to_psa_adac_rse_secure_debug(uint8_t *secure_debug_roptpk, uint32_t len)