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_ipc.c b/secure_fw/spm/spm_ipc.c
index d6e707d..ea1f735 100644
--- a/secure_fw/spm/spm_ipc.c
+++ b/secure_fw/spm/spm_ipc.c
@@ -32,6 +32,7 @@
 #include "tfm_list.h"
 #include "tfm_pools.h"
 #include "region_defs.h"
+#include "tfm_spm_services_api.h"
 
 #include "secure_fw/services/tfm_service_list.inc"
 
@@ -1590,3 +1591,37 @@
         tfm_core_panic();
     }
 }
+
+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;
+    const struct spm_partition_desc_t *partition = NULL;
+
+    /* Check permissions on request type basis */
+
+    switch (svc_ctx->r0) {
+    case TFM_SPM_REQUEST_RESET_VOTE:
+        partition = tfm_spm_get_running_partition();
+        if (!partition) {
+            tfm_core_panic();
+        }
+        running_partition_flags = partition->static_data->partition_flags;
+
+        /* 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;
+    }
+}