HAL: Replace the 'idx' input param with 'privileged'

In tfm_spm_hal_configure_default_isolation(), a partition index
is passed in to query the partition privilege. Change to pass
in privilege directly instead of the partition index.

Change-Id: Id046431cc8e224a94e83a71564ba2843fabf8ed7
Signed-off-by: Mingyang Sun <mingyang.sun@arm.com>
diff --git a/secure_fw/spm/cmsis_func/spm_func.c b/secure_fw/spm/cmsis_func/spm_func.c
index 1144b44..62e0060 100644
--- a/secure_fw/spm/cmsis_func/spm_func.c
+++ b/secure_fw/spm/cmsis_func/spm_func.c
@@ -1224,6 +1224,7 @@
     int32_t args[4] = {0};
     fih_int fail_cnt = FIH_INT_INIT(0);
     uint32_t idx;
+    bool privileged;
     const struct platform_data_t **platform_data_p;
 #ifdef TFM_FIH_PROFILE_ON
     fih_int fih_rc = FIH_FAILURE;
@@ -1235,14 +1236,19 @@
         platform_data_p = part->platform_data_list;
         if (platform_data_p != NULL) {
             while ((*platform_data_p) != NULL) {
+                if (tfm_is_partition_privileged(idx)) {
+                    privileged = true;
+                } else {
+                    privileged = false;
+                }
 #ifdef TFM_FIH_PROFILE_ON
-                FIH_CALL(tfm_spm_hal_configure_default_isolation, fih_rc, idx,
-                         *platform_data_p);
+                FIH_CALL(tfm_spm_hal_configure_default_isolation, fih_rc,
+                         privileged, *platform_data_p);
                 if (fih_not_eq(fih_rc, fih_int_encode(TFM_PLAT_ERR_SUCCESS))) {
                     fail_cnt = fih_int_encode(fih_int_decode(fail_cnt) + 1);
                 }
 #else /* TFM_FIH_PROFILE_ON */
-                if (tfm_spm_hal_configure_default_isolation(idx,
+                if (tfm_spm_hal_configure_default_isolation(privileged,
                             *platform_data_p) != TFM_PLAT_ERR_SUCCESS) {
                     fail_cnt++;
                 }
diff --git a/secure_fw/spm/cmsis_psa/spm_ipc.c b/secure_fw/spm/cmsis_psa/spm_ipc.c
index d8d9060..b657d4e 100644
--- a/secure_fw/spm/cmsis_psa/spm_ipc.c
+++ b/secure_fw/spm/cmsis_psa/spm_ipc.c
@@ -334,14 +334,6 @@
     }
 }
 
-bool tfm_is_partition_privileged(uint32_t partition_idx)
-{
-    uint32_t flags = tfm_spm_partition_get_flags(partition_idx);
-
-    return tfm_spm_partition_get_privileged_mode(flags) ==
-           TFM_PARTITION_PRIVILEGED_MODE;
-}
-
 struct service_t *tfm_spm_get_service_by_sid(uint32_t sid)
 {
     struct service_t *p_serv = connection_services_listhead;
@@ -643,7 +635,8 @@
 
 uint32_t tfm_spm_init(void)
 {
-    uint32_t i, j, part_idx = 0;
+    uint32_t i, j;
+    bool privileged;
     struct partition_t *partition;
     struct tfm_core_thread_t *pth, *p_ns_entry_thread = NULL;
     const struct platform_data_t *platform_data_p;
@@ -671,6 +664,15 @@
         p_cmninf = partition->p_ldinf;
 
         /* Init mmio assets */
+        if (p_cmninf->nassets > 0) {
+            if (tfm_spm_partition_get_privileged_mode(p_cmninf->flags) ==
+                TFM_PARTITION_PRIVILEGED_MODE) {
+                privileged = true;
+            } else {
+                privileged = false;
+            }
+        }
+
         p_asset_load = (struct asset_desc_t *)LOAD_INFO_ASSET(p_cmninf);
         for (i = 0; i < p_cmninf->nassets; i++) {
             /* Skip the memory-based asset */
@@ -696,13 +698,13 @@
             }
 
 #ifdef TFM_FIH_PROFILE_ON
-            FIH_CALL(tfm_spm_hal_configure_default_isolation, fih_rc, part_idx,
-                     platform_data_p);
+            FIH_CALL(tfm_spm_hal_configure_default_isolation, fih_rc,
+                     privileged, platform_data_p);
             if (fih_not_eq(fih_rc, fih_int_encode(TFM_PLAT_ERR_SUCCESS))) {
                 tfm_core_panic();
             }
 #else /* TFM_FIH_PROFILE_ON */
-            if (tfm_spm_hal_configure_default_isolation(part_idx,
+            if (tfm_spm_hal_configure_default_isolation(privileged,
                 platform_data_p) != TFM_PLAT_ERR_SUCCESS) {
                 tfm_core_panic();
             }
@@ -755,8 +757,6 @@
         if (tfm_core_thrd_start(pth) != THRD_SUCCESS) {
             tfm_core_panic();
         }
-
-        part_idx++;
     }
 
     /*
diff --git a/secure_fw/spm/include/tfm_platform_core_api.h b/secure_fw/spm/include/tfm_platform_core_api.h
index f79190b..de53254 100644
--- a/secure_fw/spm/include/tfm_platform_core_api.h
+++ b/secure_fw/spm/include/tfm_platform_core_api.h
@@ -23,13 +23,4 @@
  */
 void tfm_access_violation_handler(void);
 
-/**
- * \brief Return whether a secure partition is privileged.
- *
- * \param[in] partition_idx  The index of the partition in the partition_list.
- *
- * \return True if the partition is privileged, false otherwise.
- */
-bool tfm_is_partition_privileged(uint32_t partition_idx);
-
 #endif /* __TFM_PLATFORM_CORE_API_H__ */