SPM: Make PSA interface redirect-able

The existing PSA interface is based on Supervisor call, it is
feasible to make it based on other ABI type such as direct
function call. Create an ABI type indicator for the existing
PSA Interfaces, redirect the prototypes in PSA headers to a
final definition with the '_svc' suffix.

- Involve 'psa_config.h' and make secure PSA interface redirect-able.
- Define a flag 'CONFIG_TFM_BUILDING_SPE' to indicate which PE build
  is ongoing.
- Define 'CONFIG_TFM_PSA_API_SUPERVISOR_CALL' to indicate the current
  redirecting ABI for PSA interface.
- Other adjustments to support the changes.

Change-Id: Id58b12df84c0e8fd1d029e8e72c2eb8340a89a52
Signed-off-by: Ken Liu <Ken.Liu@arm.com>
diff --git a/interface/include/config_impl.h.template b/interface/include/config_impl.h.template
index e021242..4210055 100644
--- a/interface/include/config_impl.h.template
+++ b/interface/include/config_impl.h.template
@@ -11,9 +11,11 @@
 #define __CONFIG_IMPL_H__
 
 {% if ipc_partition_num > 0 and sfn_partition_num == 0 %}
-#define BACKEND_IPC                 1
+#define {{"%-56s"|format("CONFIG_TFM_SPM_BACKEND_IPC")}} 1
+#define {{"%-56s"|format("CONFIG_TFM_PSA_API_SUPERVISOR_CALL")}} 1
+
 {% elif sfn_partition_num > 0 and ipc_partition_num == 0 %}
-#define BACKEND_SFN                 1
+#define CONFIG_TFM_SPM_BACKEND_SFN                 1
 
 #if TFM_LVL > 1
 #error "High isolation level SFN model is not supported."
@@ -22,7 +24,8 @@
 {% elif sfn_partition_num > 0 and ipc_partition_num > 0 %}
 #error "IPC and SFN co-work not supported yet."
 {% else %}
-#error "Invalid partition number inputted, check configurations."
+#error "Invalid partition number input, check configurations."
 {% endif %}
+#include "psa_interface_redirect.h"
 
 #endif /* __CONFIG_IMPL_H__ */
diff --git a/interface/include/psa/client.h b/interface/include/psa/client.h
index 7aee1e5..1d79e49 100644
--- a/interface/include/psa/client.h
+++ b/interface/include/psa/client.h
@@ -11,6 +11,7 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#include "psa_config.h"
 #include "psa/error.h"
 
 #ifdef __cplusplus
diff --git a/interface/include/psa/lifecycle.h b/interface/include/psa/lifecycle.h
index a892c49..64f22d1 100644
--- a/interface/include/psa/lifecycle.h
+++ b/interface/include/psa/lifecycle.h
@@ -8,6 +8,8 @@
 #ifndef __PSA_LIFECYCLE_H__
 #define __PSA_LIFECYCLE_H__
 
+#include "psa_config.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/interface/include/psa/service.h b/interface/include/psa/service.h
index 12efd2e..2c94f4c 100644
--- a/interface/include/psa/service.h
+++ b/interface/include/psa/service.h
@@ -11,8 +11,9 @@
 #include <stddef.h>
 #include <stdint.h>
 
-#include "psa/error.h"
 #include "psa/client.h"
+#include "psa_config.h"
+#include "psa/error.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/interface/include/psa_config.h b/interface/include/psa_config.h
new file mode 100644
index 0000000..d215fba
--- /dev/null
+++ b/interface/include/psa_config.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __PSA_CONFIG_H__
+#define __PSA_CONFIG_H__
+
+/*
+ * This is an implementation-specific file that supporting PSA standard
+ * files. The reason to name with prefix 'psa' is to showcase a straight
+ * reference configuration. Because both NSPE and SPE clients are using
+ * the same API but link with the different declarations, this file can
+ * help to indicate the current building to apply PE-specific or
+ * configuration-specific settings.
+ */
+
+/*
+ * A customized flag indicating SPE build. Systems like CMSIS may use
+ * 'DOMAIN_NS' as the indicator. As NSPE is not guaranteed to be
+ * CMSIS compatible, a customized flag provides availability.
+ */
+#if defined(CONFIG_TFM_BUILDING_SPE)
+
+/* SPE has specific configurations. */
+#include "config_impl.h"
+
+#endif
+
+#endif /* __PSA_CONFIG_H__ */
diff --git a/interface/include/tfm_psa_call_param.h b/interface/include/tfm_psa_call_pack.h
similarity index 65%
rename from interface/include/tfm_psa_call_param.h
rename to interface/include/tfm_psa_call_pack.h
index ed51da7..3b14fbc 100644
--- a/interface/include/tfm_psa_call_param.h
+++ b/interface/include/tfm_psa_call_pack.h
@@ -5,8 +5,11 @@
  *
  */
 
-#ifndef __TFM_PSA_CALL_PARAM_H__
-#define __TFM_PSA_CALL_PARAM_H__
+#ifndef __TFM_PSA_CALL_PACK_H__
+#define __TFM_PSA_CALL_PACK_H__
+
+#include "psa_config.h"
+#include "psa/client.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -24,8 +27,13 @@
          ((((uint32_t)in_len) << IN_LEN_OFFSET) & IN_LEN_MASK) | \
          ((((uint32_t)out_len) << OUT_LEN_OFFSET) & OUT_LEN_MASK))
 
+psa_status_t tfm_psa_call_pack(psa_handle_t handle,
+                               uint32_t ctrl_param,
+                               const psa_invec *in_vec,
+                               psa_outvec *out_vec);
+
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* __TFM_PSA_CALL_PARAM_H__ */
+#endif /* __TFM_PSA_CALL_PACK_H__ */