Interface: Split PSA NS APIs for connection based services only

This patch splits PSA NS APIs which are only for connection based
services into a single file.

CONFIG_TFM_CONNECTION_BASED_SERVICE_API is also defined in CMake so that
tfm_psa_ns_connection_api.c will be compiled and installed only when
connection based service exists.

Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: I4656e71d762b4524f113ff8830f072848c651493
diff --git a/cmake/install.cmake b/cmake/install.cmake
index 5d9cf4b..83179cc 100644
--- a/cmake/install.cmake
+++ b/cmake/install.cmake
@@ -126,6 +126,10 @@
 if (TFM_PARTITION_NS_AGENT_TZ)
     install(FILES       ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
             DESTINATION ${INSTALL_INTERFACE_SRC_DIR})
+    if (CONFIG_TFM_CONNECTION_BASED_SERVICE_API)
+        install(FILES       ${INTERFACE_SRC_DIR}/tfm_psa_ns_connection_api.c
+                DESTINATION ${INSTALL_INTERFACE_SRC_DIR})
+    endif()
 endif()
 
 if (CONFIG_TFM_USE_TRUSTZONE)
diff --git a/interface/src/tfm_psa_ns_api.c b/interface/src/tfm_psa_ns_api.c
index 2212931..9743c27 100644
--- a/interface/src/tfm_psa_ns_api.c
+++ b/interface/src/tfm_psa_ns_api.c
@@ -5,8 +5,6 @@
  *
  */
 
-#include "config_impl.h"
-
 #include "psa/client.h"
 #include "tfm_ns_interface.h"
 #include "tfm_api.h"
@@ -54,26 +52,3 @@
                                 (uint32_t)in_vec,
                                 (uint32_t)out_vec);
 }
-
-/* Following veneers are only needed by connection-based services */
-#if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
-psa_handle_t psa_connect(uint32_t sid, uint32_t version)
-{
-    return tfm_ns_interface_dispatch(
-                                (veneer_fn)tfm_psa_connect_veneer,
-                                sid,
-                                version,
-                                0,
-                                0);
-}
-
-void psa_close(psa_handle_t handle)
-{
-    (void)tfm_ns_interface_dispatch(
-                         (veneer_fn)tfm_psa_close_veneer,
-                         (uint32_t)handle,
-                         0,
-                         0,
-                         0);
-}
-#endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 */
diff --git a/interface/src/tfm_psa_ns_connection_api.c b/interface/src/tfm_psa_ns_connection_api.c
new file mode 100644
index 0000000..dbbd52c
--- /dev/null
+++ b/interface/src/tfm_psa_ns_connection_api.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "psa/client.h"
+#include "tfm_ns_interface.h"
+#include "tfm_api.h"
+#include "tfm_psa_call_pack.h"
+
+/* API functions for connection based services */
+
+psa_handle_t psa_connect(uint32_t sid, uint32_t version)
+{
+    return tfm_ns_interface_dispatch((veneer_fn)tfm_psa_connect_veneer, sid, version, 0, 0);
+}
+
+void psa_close(psa_handle_t handle)
+{
+    (void)tfm_ns_interface_dispatch((veneer_fn)tfm_psa_close_veneer, (uint32_t)handle, 0, 0, 0);
+}
diff --git a/tools/config_impl.cmake.template b/tools/config_impl.cmake.template
index acee982..899a132 100644
--- a/tools/config_impl.cmake.template
+++ b/tools/config_impl.cmake.template
@@ -8,9 +8,11 @@
 
 ########{{utilities.donotedit_warning}}########
 
-set(CONFIG_TFM_PSA_API_SFN_CALL        {{config_impl['CONFIG_TFM_PSA_API_SFN_CALL']}}        PARENT_SCOPE)
-set(CONFIG_TFM_PSA_API_CROSS_CALL      {{config_impl['CONFIG_TFM_PSA_API_CROSS_CALL']}}      PARENT_SCOPE)
-set(CONFIG_TFM_PSA_API_SUPERVISOR_CALL {{config_impl['CONFIG_TFM_PSA_API_SUPERVISOR_CALL']}} PARENT_SCOPE)
+set(CONFIG_TFM_CONNECTION_BASED_SERVICE_API {{config_impl['CONFIG_TFM_CONNECTION_BASED_SERVICE_API']}} PARENT_SCOPE)
+
+set(CONFIG_TFM_PSA_API_SFN_CALL             {{config_impl['CONFIG_TFM_PSA_API_SFN_CALL']}}             PARENT_SCOPE)
+set(CONFIG_TFM_PSA_API_CROSS_CALL           {{config_impl['CONFIG_TFM_PSA_API_CROSS_CALL']}}           PARENT_SCOPE)
+set(CONFIG_TFM_PSA_API_SUPERVISOR_CALL      {{config_impl['CONFIG_TFM_PSA_API_SUPERVISOR_CALL']}}      PARENT_SCOPE)
 
 if((CONFIG_TFM_FLOAT_ABI GREATER 0) AND CONFIG_TFM_SPM_BACKEND_SFN)
     message(FATAL_ERROR "FP is not supported for SFN model.")