Core: Refine tfm_core_spm_request_handler function

- Move 'tfm_core_spm_request_handler' to spm module and rename it to
  'tfm_spm_request_handler' since it is an SPM function.
- Remove un-used included headers from tfm_core.c and sort them in order.

Change-Id: I3e2aa9d247278ffc62a76cba4bf79c0e0dbd159b
Signed-off-by: Summer Qin <summer.qin@arm.com>
diff --git a/secure_fw/spm/spm_func.c b/secure_fw/spm/spm_func.c
index afb0479..696fdcf 100644
--- a/secure_fw/spm/spm_func.c
+++ b/secure_fw/spm/spm_func.c
@@ -21,6 +21,7 @@
 #include "spm_db.h"
 #include "region_defs.h"
 #include "region.h"
+#include "tfm_spm_services_api.h"
 
 #define EXC_RETURN_SECURE_FUNCTION 0xFFFFFFFD
 #define EXC_RETURN_SECURE_HANDLER  0xFFFFFFF1
@@ -1284,3 +1285,36 @@
     }
     partition->runtime_data.orig_outvec = 0;
 }
+
+void tfm_spm_request_handler(const struct tfm_state_context_t *svc_ctx)
+{
+    uint32_t *res_ptr = (uint32_t *)&svc_ctx->r0;
+    uint32_t running_partition_flags = 0;
+    uint32_t running_partition_idx;
+
+    /* Check permissions on request type basis */
+
+    switch (svc_ctx->r0) {
+    case TFM_SPM_REQUEST_RESET_VOTE:
+        running_partition_idx =
+            tfm_spm_partition_get_running_partition_idx();
+        running_partition_flags = tfm_spm_partition_get_flags(
+                                                         running_partition_idx);
+
+        /* Currently only PSA Root of Trust services are allowed to make Reset
+         * vote request
+         */
+        if ((running_partition_flags & SPM_PART_FLAG_PSA_ROT) == 0) {
+            *res_ptr = (uint32_t)TFM_ERROR_GENERIC;
+        }
+
+        /* FixMe: this is a placeholder for checks to be performed before
+         * allowing execution of reset
+         */
+        *res_ptr = (uint32_t)TFM_SUCCESS;
+
+        break;
+    default:
+        *res_ptr = (uint32_t)TFM_ERROR_INVALID_PARAMETER;
+    }
+}