Platform: Change the HAL prototype to report status

Change the return type of tfm_spm_hal_configure_default_isolation() from
"void" to "enum tfm_plat_err_t" to report errors to caller.

Change-Id: Iadfd82e546a5141f0db1624358f09111fd7530c1
Signed-off-by: Edison Ai <edison.ai@arm.com>
diff --git a/platform/ext/target/cypress/psoc64/spm_hal.c b/platform/ext/target/cypress/psoc64/spm_hal.c
index 23eb655..d911020 100644
--- a/platform/ext/target/cypress/psoc64/spm_hal.c
+++ b/platform/ext/target/cypress/psoc64/spm_hal.c
@@ -43,15 +43,18 @@
     return TFM_PLAT_ERR_SUCCESS;
 }
 
-void tfm_spm_hal_configure_default_isolation(
+enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
         uint32_t partition_idx,
         const struct tfm_spm_partition_platform_data_t *platform_data)
 {
     (void) partition_idx; /* Unused parameter */
     printf("In %s()\n", __func__);
-    if (platform_data) {
-        /* TBD */
+    if (!platform_data) {
+        return TFM_PLAT_ERR_INVALID_INPUT;
     }
+    /* TBD */
+
+    return TFM_PLAT_ERR_SUCCESS;
 }
 
 #if TFM_LVL != 1
diff --git a/platform/ext/target/mps2/an519/spm_hal.c b/platform/ext/target/mps2/an519/spm_hal.c
index 19a52c2..e1a8d12 100644
--- a/platform/ext/target/mps2/an519/spm_hal.c
+++ b/platform/ext/target/mps2/an519/spm_hal.c
@@ -40,24 +40,28 @@
     return TFM_PLAT_ERR_SUCCESS;
 }
 
-void tfm_spm_hal_configure_default_isolation(
+enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
                   uint32_t partition_idx,
                   const struct tfm_spm_partition_platform_data_t *platform_data)
 {
     bool privileged = tfm_is_partition_privileged(partition_idx);
-    if (platform_data) {
-        if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
-            ppc_configure_to_secure(platform_data->periph_ppc_bank,
-                                    platform_data->periph_ppc_loc);
-            if (privileged) {
-                ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
-                                      platform_data->periph_ppc_loc);
-            } else {
-                ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
-                                     platform_data->periph_ppc_loc);
-            }
+
+    if (!platform_data) {
+        return TFM_PLAT_ERR_INVALID_INPUT;
+    }
+
+    if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
+        ppc_configure_to_secure(platform_data->periph_ppc_bank,
+                                platform_data->periph_ppc_loc);
+        if (privileged) {
+            ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
+                                  platform_data->periph_ppc_loc);
+        } else {
+            ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
+                                 platform_data->periph_ppc_loc);
         }
     }
+    return TFM_PLAT_ERR_SUCCESS;
 }
 
 #if TFM_LVL != 1
diff --git a/platform/ext/target/mps2/an521/spm_hal.c b/platform/ext/target/mps2/an521/spm_hal.c
index 19a52c2..e1a8d12 100644
--- a/platform/ext/target/mps2/an521/spm_hal.c
+++ b/platform/ext/target/mps2/an521/spm_hal.c
@@ -40,24 +40,28 @@
     return TFM_PLAT_ERR_SUCCESS;
 }
 
-void tfm_spm_hal_configure_default_isolation(
+enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
                   uint32_t partition_idx,
                   const struct tfm_spm_partition_platform_data_t *platform_data)
 {
     bool privileged = tfm_is_partition_privileged(partition_idx);
-    if (platform_data) {
-        if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
-            ppc_configure_to_secure(platform_data->periph_ppc_bank,
-                                    platform_data->periph_ppc_loc);
-            if (privileged) {
-                ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
-                                      platform_data->periph_ppc_loc);
-            } else {
-                ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
-                                     platform_data->periph_ppc_loc);
-            }
+
+    if (!platform_data) {
+        return TFM_PLAT_ERR_INVALID_INPUT;
+    }
+
+    if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
+        ppc_configure_to_secure(platform_data->periph_ppc_bank,
+                                platform_data->periph_ppc_loc);
+        if (privileged) {
+            ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
+                                  platform_data->periph_ppc_loc);
+        } else {
+            ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
+                                 platform_data->periph_ppc_loc);
         }
     }
+    return TFM_PLAT_ERR_SUCCESS;
 }
 
 #if TFM_LVL != 1
diff --git a/platform/ext/target/mps2/an539/spm_hal.c b/platform/ext/target/mps2/an539/spm_hal.c
index de95e2f..aeaebc9 100644
--- a/platform/ext/target/mps2/an539/spm_hal.c
+++ b/platform/ext/target/mps2/an539/spm_hal.c
@@ -52,24 +52,28 @@
     return TFM_PLAT_ERR_SUCCESS;
 }
 
-void tfm_spm_hal_configure_default_isolation(
+enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
                   uint32_t partition_idx,
                   const struct tfm_spm_partition_platform_data_t *platform_data)
 {
     bool privileged = tfm_is_partition_privileged(partition_idx);
-    if (platform_data) {
-        if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
-            ppc_configure_to_secure(platform_data->periph_ppc_bank,
-                                    platform_data->periph_ppc_loc);
-            if (privileged) {
-                ppc_configure_to_secure_priv(platform_data->periph_ppc_bank,
-                                             platform_data->periph_ppc_loc);
-            } else {
-                ppc_configure_to_secure_unpriv(platform_data->periph_ppc_bank,
-                                               platform_data->periph_ppc_loc);
-            }
+
+    if (!platform_data) {
+        return TFM_PLAT_ERR_INVALID_INPUT;
+    }
+
+    if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
+        ppc_configure_to_secure(platform_data->periph_ppc_bank,
+                                platform_data->periph_ppc_loc);
+        if (privileged) {
+            ppc_configure_to_secure_priv(platform_data->periph_ppc_bank,
+                                         platform_data->periph_ppc_loc);
+        } else {
+            ppc_configure_to_secure_unpriv(platform_data->periph_ppc_bank,
+                                           platform_data->periph_ppc_loc);
         }
     }
+    return TFM_PLAT_ERR_SUCCESS;
 }
 
 #if TFM_LVL != 1
diff --git a/platform/ext/target/mps3/an524/spm_hal.c b/platform/ext/target/mps3/an524/spm_hal.c
index 5fa18cd..debdae2 100644
--- a/platform/ext/target/mps3/an524/spm_hal.c
+++ b/platform/ext/target/mps3/an524/spm_hal.c
@@ -48,22 +48,26 @@
     return TFM_PLAT_ERR_SUCCESS;
 }
 
-void tfm_spm_hal_configure_default_isolation(
+enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
                   uint32_t partition_idx,
                   const struct tfm_spm_partition_platform_data_t *platform_data)
 {
     bool privileged = tfm_is_partition_privileged(partition_idx);
-    if (platform_data) {
-        if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
-            if (privileged) {
-                ppc_configure_to_secure_priv(platform_data->periph_ppc_bank,
-                                             platform_data->periph_ppc_loc);
-            } else {
-                ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
-                                     platform_data->periph_ppc_loc);
-            }
+
+    if (!platform_data) {
+        return TFM_PLAT_ERR_INVALID_INPUT;
+    }
+
+    if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
+        if (privileged) {
+            ppc_configure_to_secure_priv(platform_data->periph_ppc_bank,
+                                         platform_data->periph_ppc_loc);
+        } else {
+            ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
+                                 platform_data->periph_ppc_loc);
         }
     }
+    return TFM_PLAT_ERR_SUCCESS;
 }
 
 #if TFM_LVL != 1
diff --git a/platform/ext/target/musca_a/spm_hal.c b/platform/ext/target/musca_a/spm_hal.c
index e8682f9..7125264 100644
--- a/platform/ext/target/musca_a/spm_hal.c
+++ b/platform/ext/target/musca_a/spm_hal.c
@@ -38,24 +38,28 @@
     return TFM_PLAT_ERR_SUCCESS;
 }
 
-void tfm_spm_hal_configure_default_isolation(
+enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
                   uint32_t partition_idx,
                   const struct tfm_spm_partition_platform_data_t *platform_data)
 {
     bool privileged = tfm_is_partition_privileged(partition_idx);
-    if (platform_data) {
-        if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
-            ppc_configure_to_secure(platform_data->periph_ppc_bank,
-                                    platform_data->periph_ppc_loc);
-            if (privileged) {
-                ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
-                                      platform_data->periph_ppc_loc);
-            } else {
-                ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
-                                     platform_data->periph_ppc_loc);
-            }
+
+    if (!platform_data) {
+        return TFM_PLAT_ERR_INVALID_INPUT;
+    }
+
+    if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
+        ppc_configure_to_secure(platform_data->periph_ppc_bank,
+                                platform_data->periph_ppc_loc);
+        if (privileged) {
+            ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
+                                  platform_data->periph_ppc_loc);
+        } else {
+            ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
+                                 platform_data->periph_ppc_loc);
         }
     }
+    return TFM_PLAT_ERR_SUCCESS;
 }
 
 #if TFM_LVL != 1
diff --git a/platform/ext/target/musca_b1/spm_hal.c b/platform/ext/target/musca_b1/spm_hal.c
index 2b9ee6e..da07050 100644
--- a/platform/ext/target/musca_b1/spm_hal.c
+++ b/platform/ext/target/musca_b1/spm_hal.c
@@ -42,22 +42,26 @@
     return TFM_PLAT_ERR_SUCCESS;
 }
 
-void tfm_spm_hal_configure_default_isolation(
+enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
                   uint32_t partition_idx,
                   const struct tfm_spm_partition_platform_data_t *platform_data)
 {
     bool privileged = tfm_is_partition_privileged(partition_idx);
-    if (platform_data) {
-        if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
-            if (privileged) {
-                ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
-                                      platform_data->periph_ppc_loc);
-            } else {
-                ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
-                                     platform_data->periph_ppc_loc);
-            }
+
+    if (!platform_data) {
+        return TFM_PLAT_ERR_INVALID_INPUT;
+    }
+
+    if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
+        if (privileged) {
+            ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
+                                  platform_data->periph_ppc_loc);
+        } else {
+            ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
+                                 platform_data->periph_ppc_loc);
         }
     }
+    return TFM_PLAT_ERR_SUCCESS;
 }
 
 #if TFM_LVL != 1
diff --git a/platform/ext/target/musca_s1/spm_hal.c b/platform/ext/target/musca_s1/spm_hal.c
index d7ec07e..5d3ba3c 100644
--- a/platform/ext/target/musca_s1/spm_hal.c
+++ b/platform/ext/target/musca_s1/spm_hal.c
@@ -41,22 +41,26 @@
     return TFM_PLAT_ERR_SUCCESS;
 }
 
-void tfm_spm_hal_configure_default_isolation(
+enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
                   uint32_t partition_idx,
                   const struct tfm_spm_partition_platform_data_t *platform_data)
 {
     bool privileged = tfm_is_partition_privileged(partition_idx);
-    if (platform_data) {
-        if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
-            if (privileged) {
-                ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
-                                      platform_data->periph_ppc_loc);
-            } else {
-                ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
-                                     platform_data->periph_ppc_loc);
-            }
+
+    if (!platform_data) {
+        return TFM_PLAT_ERR_INVALID_INPUT;
+    }
+
+    if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
+        if (privileged) {
+            ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
+                                  platform_data->periph_ppc_loc);
+        } else {
+            ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
+                                 platform_data->periph_ppc_loc);
         }
     }
+    return TFM_PLAT_ERR_SUCCESS;
 }
 
 #if TFM_LVL != 1
diff --git a/platform/ext/target/sse-200_aws/spm_hal.c b/platform/ext/target/sse-200_aws/spm_hal.c
index f3e0fbd..1e8e833 100644
--- a/platform/ext/target/sse-200_aws/spm_hal.c
+++ b/platform/ext/target/sse-200_aws/spm_hal.c
@@ -40,24 +40,28 @@
     return TFM_PLAT_ERR_SUCCESS;
 }
 
-void tfm_spm_hal_configure_default_isolation(
+enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
                   uint32_t partition_idx,
                   const struct tfm_spm_partition_platform_data_t *platform_data)
 {
     bool privileged = tfm_is_partition_privileged(partition_idx);
-    if (platform_data) {
-        if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
-            ppc_configure_to_secure(platform_data->periph_ppc_bank,
-                                    platform_data->periph_ppc_loc);
-            if (privileged) {
-                ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
-                                      platform_data->periph_ppc_loc);
-            } else {
-                ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
-                                     platform_data->periph_ppc_loc);
-            }
+
+    if (!platform_data) {
+        return TFM_PLAT_ERR_INVALID_INPUT;
+    }
+
+    if (platform_data->periph_ppc_bank != PPC_SP_DO_NOT_CONFIGURE) {
+        ppc_configure_to_secure(platform_data->periph_ppc_bank,
+                                platform_data->periph_ppc_loc);
+        if (privileged) {
+            ppc_clr_secure_unpriv(platform_data->periph_ppc_bank,
+                                  platform_data->periph_ppc_loc);
+        } else {
+            ppc_en_secure_unpriv(platform_data->periph_ppc_bank,
+                                 platform_data->periph_ppc_loc);
         }
     }
+    return TFM_PLAT_ERR_SUCCESS;
 }
 
 #if TFM_LVL != 1
diff --git a/platform/include/tfm_spm_hal.h b/platform/include/tfm_spm_hal.h
index b12df11..0435212 100644
--- a/platform/include/tfm_spm_hal.h
+++ b/platform/include/tfm_spm_hal.h
@@ -126,9 +126,11 @@
  * \param[in] partition_idx    The index of the partition that this peripheral
  *                             is assigned to.
  * \param[in] platform_data    The platform fields of the partition DB record to
- *                             be used for configuration. Can be NULL.
+ *                             be used for configuration.
+ *
+ * \return Returns values as specified by the \ref tfm_plat_err_t
  */
-void tfm_spm_hal_configure_default_isolation(
+enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
                  uint32_t partition_idx,
                  const struct tfm_spm_partition_platform_data_t *platform_data);
 /**
diff --git a/secure_fw/spm/spm_api_func.c b/secure_fw/spm/spm_api_func.c
index be71ec9..d855256 100644
--- a/secure_fw/spm/spm_api_func.c
+++ b/secure_fw/spm/spm_api_func.c
@@ -58,7 +58,10 @@
         platform_data_p = part->platform_data_list;
         if (platform_data_p != NULL) {
             while ((*platform_data_p) != NULL) {
-                tfm_spm_hal_configure_default_isolation(idx, *platform_data_p);
+                if (tfm_spm_hal_configure_default_isolation(idx,
+                            *platform_data_p) != TFM_PLAT_ERR_SUCCESS) {
+                    fail_cnt++;
+                }
                 ++platform_data_p;
             }
         }
diff --git a/secure_fw/spm/spm_api_ipc.c b/secure_fw/spm/spm_api_ipc.c
index 19f1d9a..b88d4a8 100644
--- a/secure_fw/spm/spm_api_ipc.c
+++ b/secure_fw/spm/spm_api_ipc.c
@@ -542,7 +542,10 @@
         platform_data_p = partition->platform_data_list;
         if (platform_data_p != NULL) {
             while ((*platform_data_p) != NULL) {
-                tfm_spm_hal_configure_default_isolation(i, *platform_data_p);
+                if (tfm_spm_hal_configure_default_isolation(i,
+                            *platform_data_p) != TFM_PLAT_ERR_SUCCESS) {
+                    tfm_core_panic();
+                }
                 ++platform_data_p;
             }
         }