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/src/psa/psa_client.c b/interface/src/psa/psa_client.c
deleted file mode 100644
index 6960ac6..0000000
--- a/interface/src/psa/psa_client.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#include <inttypes.h>
-#include "psa/client.h"
-#include "svc_num.h"
-#include "tfm_api.h"
-#include "tfm_hal_device_header.h"
-#include "tfm_psa_call_param.h"
-
-__attribute__((naked))
-uint32_t psa_framework_version(void)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_FRAMEWORK_VERSION));
-}
-
-__attribute__((naked))
-uint32_t psa_version(uint32_t sid)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_VERSION));
-}
-
-__attribute__((naked))
-psa_handle_t psa_connect(uint32_t sid, uint32_t version)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_CONNECT));
-}
-
-__attribute__((naked))
-static psa_status_t psa_call_param_pack(psa_handle_t handle,
-                                        uint32_t ctrl_param,
-                                        const psa_invec *in_vec,
-                                        psa_outvec *out_vec)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_CALL));
-}
-
-psa_status_t psa_call(psa_handle_t handle,
-                      int32_t type,
-                      const psa_invec *in_vec,
-                      size_t in_len,
-                      psa_outvec *out_vec,
-                      size_t out_len)
-{
-    if ((type > INT16_MAX) ||
-        (type < INT16_MIN) ||
-        (in_len > UINT8_MAX) ||
-        (out_len > UINT8_MAX)) {
-        return PSA_ERROR_PROGRAMMER_ERROR;
-    }
-
-    return psa_call_param_pack(handle,
-                               PARAM_PACK(type, in_len, out_len),
-                               in_vec,
-                               out_vec);
-}
-
-__attribute__((naked))
-void psa_close(psa_handle_t handle)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_CLOSE));
-}
diff --git a/interface/src/psa/psa_lifecycle.c b/interface/src/psa/psa_lifecycle.c
deleted file mode 100644
index cee7dfd..0000000
--- a/interface/src/psa/psa_lifecycle.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-#include <inttypes.h>
-#include "psa/lifecycle.h"
-#include "svc_num.h"
-#include "tfm_hal_device_header.h"
-
-__attribute__((naked))
-uint32_t psa_rot_lifecycle_state(void)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_LIFECYCLE));
-}
diff --git a/interface/src/psa/psa_service.c b/interface/src/psa/psa_service.c
deleted file mode 100644
index 211c36f..0000000
--- a/interface/src/psa/psa_service.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#include <inttypes.h>
-#include <stdio.h>
-#include "psa/client.h"
-#include "psa/service.h"
-#include "svc_num.h"
-#include "tfm_hal_device_header.h"
-
-__attribute__((naked))
-psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout)
-
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_WAIT));
-}
-
-__attribute__((naked))
-psa_status_t psa_get(psa_signal_t signal, psa_msg_t *msg)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_GET));
-}
-
-__attribute__((naked))
-void psa_set_rhandle(psa_handle_t msg_handle, void *rhandle)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_SET_RHANDLE));
-}
-
-__attribute__((naked))
-size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
-                void *buffer, size_t num_bytes)
-
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_READ));
-}
-
-__attribute__((naked))
-size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_SKIP));
-}
-
-__attribute__((naked))
-void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
-               const void *buffer, size_t num_bytes)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_WRITE));
-}
-
-__attribute__((naked))
-void psa_reply(psa_handle_t msg_handle, psa_status_t retval)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_REPLY));
-}
-
-__attribute__((naked))
-void psa_notify(int32_t partition_id)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_NOTIFY));
-}
-
-__attribute__((naked))
-void psa_clear(void)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_CLEAR));
-}
-
-__attribute__((naked))
-void psa_eoi(psa_signal_t irq_signal)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_EOI));
-}
-
-__attribute__((naked))
-void psa_panic(void)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_PANIC));
-}
-
-__attribute__((naked))
-void psa_irq_enable(psa_signal_t irq_signal)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_IRQ_ENABLE));
-}
-
-__attribute__((naked))
-psa_irq_status_t psa_irq_disable(psa_signal_t irq_signal)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_IRQ_DISABLE));
-}
-
-__attribute__((naked))
-void psa_reset_signal(psa_signal_t irq_signal)
-{
-    __ASM volatile("SVC %0           \n"
-                   "BX LR            \n"
-                   : : "I" (TFM_SVC_PSA_RESET_SIGNAL));
-}
diff --git a/interface/src/tfm_psa_call_pack.c b/interface/src/tfm_psa_call_pack.c
new file mode 100644
index 0000000..289784e
--- /dev/null
+++ b/interface/src/tfm_psa_call_pack.c
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <stdint.h>
+#include "psa/client.h"
+#include "tfm_psa_call_pack.h"
+
+psa_status_t psa_call(psa_handle_t handle,
+                      int32_t type,
+                      const psa_invec *in_vec,
+                      size_t in_len,
+                      psa_outvec *out_vec,
+                      size_t out_len)
+{
+    if ((type > INT16_MAX) ||
+        (type < INT16_MIN) ||
+        (in_len > UINT8_MAX) ||
+        (out_len > UINT8_MAX)) {
+        return PSA_ERROR_PROGRAMMER_ERROR;
+    }
+
+    return tfm_psa_call_pack(handle, PARAM_PACK(type, in_len, out_len),
+                             in_vec, out_vec);
+}
diff --git a/interface/src/tfm_psa_ns_api.c b/interface/src/tfm_psa_ns_api.c
index 751216d..4d29f1b 100644
--- a/interface/src/tfm_psa_ns_api.c
+++ b/interface/src/tfm_psa_ns_api.c
@@ -8,7 +8,7 @@
 #include "psa/client.h"
 #include "tfm_ns_interface.h"
 #include "tfm_api.h"
-#include "tfm_psa_call_param.h"
+#include "tfm_psa_call_pack.h"
 
 /**** API functions ****/