SPM: PSA API working under Thread mode when level 1

This patch redirects PSA API into a customized 'thread call' ABI to
make it execute in thread mode, when:

- Runtime backend IPC and Isolation Level 1.

This 'thread call' ABI happens in 'Thread mode', and:

- Switch to SPM stack after PSA APIs are called. The working stack
  re-uses the NS Agent stack to save runtime memory or allocated a
  dedicated stack for it if no Trustzone NS Agent is available. No
  need to make SPM working under 'Handler mode' in this case.

- Lock scheduler to ensure PSA API context is not nested because of
  scheduling. The locking is performed by setting a flag, and the
  scheduler entry checks this flag to decide schedule or not.

- When PSA API returns, switch back to the caller stack. And trigger
  scheduler in the caller stack if a scheduling is expected. This
  helps the scheduler context management.

- SPM functionalities other than PSA API are still using SVC-based
  implementation, such as SPM initialization and log info flushing.

The content of this patch:

- Define interfaces, ABI dispatcher and architecture modifications
  to support handling PSA API under thread mode.

- Related header file and source path adjustment to help the build pass.

- Adjust IDLE partition stack size to make runtime execution work, the
  original size is too compact to run under debug build of specific
  platforms.

Change-Id: I52add3f57ef0f958d25725efb4eb702617586907
Signed-off-by: Ken Liu <Ken.Liu@arm.com>
Co-authored-by: Mingyang Sun <Mingyang.Sun@arm.com>
diff --git a/interface/include/config_impl.h.template b/interface/include/config_impl.h.template
index 4210055..6ef1a2b 100644
--- a/interface/include/config_impl.h.template
+++ b/interface/include/config_impl.h.template
@@ -12,10 +12,16 @@
 
 {% if ipc_partition_num > 0 and sfn_partition_num == 0 %}
 #define {{"%-56s"|format("CONFIG_TFM_SPM_BACKEND_IPC")}} 1
+
+#if TFM_LVL > 1
 #define {{"%-56s"|format("CONFIG_TFM_PSA_API_SUPERVISOR_CALL")}} 1
+#else
+#define {{"%-56s"|format("CONFIG_TFM_PSA_API_THREAD_CALL")}} 1
+#define {{"%-56s"|format("CONFIG_TFM_SPM_THREAD_STACK_SIZE")}} 1024
+#endif
 
 {% elif sfn_partition_num > 0 and ipc_partition_num == 0 %}
-#define CONFIG_TFM_SPM_BACKEND_SFN                 1
+#define {{"%-56s"|format("CONFIG_TFM_SPM_BACKEND_SFN")}} 1
 
 #if TFM_LVL > 1
 #error "High isolation level SFN model is not supported."