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/platform/ext/target/arm/mps2/an519/spm_hal.c b/platform/ext/target/arm/mps2/an519/spm_hal.c
index 02cd47a..c192152 100644
--- a/platform/ext/target/arm/mps2/an519/spm_hal.c
+++ b/platform/ext/target/arm/mps2/an519/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -22,11 +22,9 @@
 extern const struct memory_region_limits memory_regions;
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                  uint32_t partition_idx,
+                  bool privileged,
                   const struct platform_data_t *platform_data)
 {
-    bool privileged = tfm_is_partition_privileged(partition_idx);
-
     if (!platform_data) {
         return TFM_PLAT_ERR_INVALID_INPUT;
     }
diff --git a/platform/ext/target/arm/mps2/an521/spm_hal.c b/platform/ext/target/arm/mps2/an521/spm_hal.c
index 58dee4d..9390b46 100644
--- a/platform/ext/target/arm/mps2/an521/spm_hal.c
+++ b/platform/ext/target/arm/mps2/an521/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -33,16 +33,15 @@
 
 #ifdef TFM_FIH_PROFILE_ON
 fih_int tfm_spm_hal_configure_default_isolation(
-                  uint32_t partition_idx,
+                  bool privileged,
                   const struct platform_data_t *platform_data)
 #else /* TFM_FIH_PROFILE_ON */
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                  uint32_t partition_idx,
+                  bool privileged,
                   const struct platform_data_t *platform_data)
 #endif /* TFM_FIH_PROFILE_ON */
 {
     fih_int fih_rc = FIH_FAILURE;
-    bool privileged = tfm_is_partition_privileged(partition_idx);
 #if defined(CONFIG_TFM_ENABLE_MEMORY_PROTECT) && (TFM_LVL != 1)
     struct mpu_armv8m_region_cfg_t region_cfg;
 #endif
diff --git a/platform/ext/target/arm/mps2/fvp_sse300/spm_hal.c b/platform/ext/target/arm/mps2/fvp_sse300/spm_hal.c
index 6b2d8a6..ff26d6f 100644
--- a/platform/ext/target/arm/mps2/fvp_sse300/spm_hal.c
+++ b/platform/ext/target/arm/mps2/fvp_sse300/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -27,11 +27,10 @@
 #endif /* CONFIG_TFM_ENABLE_MEMORY_PROTECT */
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                 uint32_t partition_idx,
+                 bool privileged,
                  const struct platform_data_t *platform_data)
 {
 #if defined(CONFIG_TFM_ENABLE_MEMORY_PROTECT) && (TFM_LVL != 1)
-    bool privileged = tfm_is_partition_privileged(partition_idx);
     struct mpu_armv8m_region_cfg_t region_cfg;
 #endif
 
diff --git a/platform/ext/target/arm/mps3/an524/spm_hal.c b/platform/ext/target/arm/mps3/an524/spm_hal.c
index 8abe9d8..30907b2 100644
--- a/platform/ext/target/arm/mps3/an524/spm_hal.c
+++ b/platform/ext/target/arm/mps3/an524/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -33,11 +33,9 @@
 extern const struct memory_region_limits memory_regions;
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                  uint32_t partition_idx,
+                  bool privileged,
                   const struct platform_data_t *platform_data)
 {
-    bool privileged = tfm_is_partition_privileged(partition_idx);
-
     if (!platform_data) {
         return TFM_PLAT_ERR_INVALID_INPUT;
     }
diff --git a/platform/ext/target/arm/mps3/an547/spm_hal.c b/platform/ext/target/arm/mps3/an547/spm_hal.c
index 840deac..e8c8c8d 100644
--- a/platform/ext/target/arm/mps3/an547/spm_hal.c
+++ b/platform/ext/target/arm/mps3/an547/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -29,11 +29,10 @@
 #endif /* CONFIG_TFM_ENABLE_MEMORY_PROTECT */
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                 uint32_t partition_idx,
+                 bool privileged,
                  const struct platform_data_t *platform_data)
 {
 #if defined(CONFIG_TFM_ENABLE_MEMORY_PROTECT) && (TFM_LVL != 1)
-    bool privileged = tfm_is_partition_privileged(partition_idx);
     struct mpu_armv8m_region_cfg_t region_cfg;
 #endif
 
diff --git a/platform/ext/target/arm/musca_b1/secure_enclave/spm_hal.c b/platform/ext/target/arm/musca_b1/secure_enclave/spm_hal.c
index b800078..207db15 100644
--- a/platform/ext/target/arm/musca_b1/secure_enclave/spm_hal.c
+++ b/platform/ext/target/arm/musca_b1/secure_enclave/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  * Copyright (c) 2019-2020, Cypress Semiconductor Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
@@ -21,12 +21,12 @@
 extern const struct memory_region_limits memory_regions;
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-        uint32_t partition_idx,
+        bool privileged,
         const struct platform_data_t *platform_data)
 {
     /* Nothing to do, there is no isolation HW in this platform to be
      * configured by Secure Enclave */
-    (void) partition_idx;
+    (void) privileged;
     (void) platform_data;
     return TFM_PLAT_ERR_SUCCESS;
 }
diff --git a/platform/ext/target/arm/musca_b1/sse_200/spm_hal.c b/platform/ext/target/arm/musca_b1/sse_200/spm_hal.c
index 42c10cf..58ac546 100644
--- a/platform/ext/target/arm/musca_b1/sse_200/spm_hal.c
+++ b/platform/ext/target/arm/musca_b1/sse_200/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -33,10 +33,9 @@
 #endif /* CONFIG_TFM_ENABLE_MEMORY_PROTECT */
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                  uint32_t partition_idx,
+                  bool privileged,
                   const struct platform_data_t *platform_data)
 {
-    bool privileged = tfm_is_partition_privileged(partition_idx);
 #if defined(CONFIG_TFM_ENABLE_MEMORY_PROTECT) && (TFM_LVL != 1)
     struct mpu_armv8m_region_cfg_t region_cfg;
 #endif
diff --git a/platform/ext/target/arm/musca_s1/spm_hal.c b/platform/ext/target/arm/musca_s1/spm_hal.c
index dba2177..46f0de0 100644
--- a/platform/ext/target/arm/musca_s1/spm_hal.c
+++ b/platform/ext/target/arm/musca_s1/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -25,11 +25,9 @@
 struct mpu_armv8m_dev_t dev_mpu_s = { MPU_BASE };
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                  uint32_t partition_idx,
+                  bool privileged,
                   const struct platform_data_t *platform_data)
 {
-    bool privileged = tfm_is_partition_privileged(partition_idx);
-
     if (!platform_data) {
         return TFM_PLAT_ERR_INVALID_INPUT;
     }
diff --git a/platform/ext/target/cypress/psoc64/spm_hal.c b/platform/ext/target/cypress/psoc64/spm_hal.c
index 7b4e2fe..b996368 100644
--- a/platform/ext/target/cypress/psoc64/spm_hal.c
+++ b/platform/ext/target/cypress/psoc64/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  * Copyright (c) 2019-2020, Cypress Semiconductor Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
@@ -35,10 +35,10 @@
 extern const struct memory_region_limits memory_regions;
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-        uint32_t partition_idx,
+        bool privileged,
         const struct platform_data_t *platform_data)
 {
-    (void) partition_idx; /* Unused parameter */
+    (void) privileged; /* Unused parameter */
     if (!platform_data) {
         return TFM_PLAT_ERR_INVALID_INPUT;
     }
diff --git a/platform/ext/target/nordic_nrf/common/core/spm_hal.c b/platform/ext/target/nordic_nrf/common/core/spm_hal.c
index d38100d..5b9aa9c 100644
--- a/platform/ext/target/nordic_nrf/common/core/spm_hal.c
+++ b/platform/ext/target/nordic_nrf/common/core/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  * Copyright (c) 2020, Nordic Semiconductor ASA. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
@@ -29,7 +29,7 @@
 #endif /* CONFIG_TFM_ENABLE_MEMORY_PROTECT */
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                  uint32_t partition_idx,
+                  bool privileged,
                   const struct platform_data_t *platform_data)
 {
     if (!platform_data) {
@@ -38,7 +38,7 @@
 
 #if defined(CONFIG_TFM_ENABLE_MEMORY_PROTECT) && (TFM_LVL != 1)
 
-    if (!tfm_is_partition_privileged(partition_idx)) {
+    if (!privileged) {
         struct mpu_armv8m_region_cfg_t region_cfg;
 
         region_cfg.region_nr = PARTITION_REGION_PERIPH_START + periph_num_count;
diff --git a/platform/ext/target/nuvoton/common/spm_hal.c b/platform/ext/target/nuvoton/common/spm_hal.c
index 500593b..9772399 100644
--- a/platform/ext/target/nuvoton/common/spm_hal.c
+++ b/platform/ext/target/nuvoton/common/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -22,11 +22,9 @@
 extern const struct memory_region_limits memory_regions;
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                  uint32_t partition_idx,
+                  bool privileged,
                   const struct platform_data_t *platform_data)
 {
-    bool privileged = tfm_is_partition_privileged(partition_idx);
-
     if (!platform_data) {
         return TFM_PLAT_ERR_INVALID_INPUT;
     }
diff --git a/platform/ext/target/nxp/common/spm_hal.c b/platform/ext/target/nxp/common/spm_hal.c
index b9a6e98..fee91a9 100644
--- a/platform/ext/target/nxp/common/spm_hal.c
+++ b/platform/ext/target/nxp/common/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  * Copyright 2019-2020 NXP. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
@@ -30,10 +30,9 @@
 #endif /* CONFIG_TFM_ENABLE_MEMORY_PROTECT */
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                  uint32_t partition_idx,
+                  bool privileged,
                   const struct platform_data_t *platform_data)
 {
-    bool privileged = tfm_is_partition_privileged(partition_idx);
 #if defined(CONFIG_TFM_ENABLE_MEMORY_PROTECT) && (TFM_LVL != 1)
     struct mpu_armv8m_region_cfg_t region_cfg;
 #endif
diff --git a/platform/ext/target/stm/common/stm32l5xx/secure/spm_hal.c b/platform/ext/target/stm/common/stm32l5xx/secure/spm_hal.c
index 94cab01..638d0cf 100644
--- a/platform/ext/target/stm/common/stm32l5xx/secure/spm_hal.c
+++ b/platform/ext/target/stm/common/stm32l5xx/secure/spm_hal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -19,7 +19,7 @@
 extern const struct memory_region_limits memory_regions;
 
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                  uint32_t partition_idx,
+                  bool privileged,
                   const struct platform_data_t *platform_data)
 {
     /* plat data are ignored */
diff --git a/platform/include/tfm_spm_hal.h b/platform/include/tfm_spm_hal.h
index 11da3c9..5730492 100644
--- a/platform/include/tfm_spm_hal.h
+++ b/platform/include/tfm_spm_hal.h
@@ -51,20 +51,19 @@
 
 /**
  * \brief Configure peripherals for a partition based on the platform data and
- *        partition index from the DB
+ *        partition privilege
  *
  * This function is called during partition initialisation (before calling the
  * init function for the partition)
  *
- * \param[in] partition_idx    The index of the partition that this peripheral
- *                             is assigned to.
+ * \param[in] privileged       Whether the partition is privileged.
  * \param[in] platform_data    The platform fields of the partition DB record to
  *                             be used for configuration.
  *
  * \return Returns values as specified by FIH specific platform error code
  */
 fih_int tfm_spm_hal_configure_default_isolation(
-                 uint32_t partition_idx,
+                 bool privileged,
                  const struct platform_data_t *platform_data);
 /**
  * \brief Configures the system debug properties.
@@ -106,20 +105,19 @@
 
 /**
  * \brief Configure peripherals for a partition based on the platform data and
- *        partition index from the DB
+ *        partition privilege
  *
  * This function is called during partition initialisation (before calling the
  * init function for the partition)
  *
- * \param[in] partition_idx    The index of the partition that this peripheral
- *                             is assigned to.
+ * \param[in] privileged       Whether the partition is privileged.
  * \param[in] platform_data    The platform fields of the partition DB record to
  *                             be used for configuration.
  *
  * \return Returns values as specified by the \ref tfm_plat_err_t
  */
 enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation(
-                 uint32_t partition_idx,
+                 bool priviledged,
                  const struct platform_data_t *platform_data);
 /**
  * \brief Configures the system debug properties.