SPM: Implementation error codes update

Even SPM care only about the error code returned from implementation
functions is successful or not, the returned error code still can be
logged somewhere for debug/logging purpose. 'bool' is not a good
candidate for the return type, in case the implementation has rich
internal error codes.

Create an implementation error code base, and implementation could
expand its own error codes base on this base.

Change-Id: I33ede91801d29ae0fd66296ca7e7fd0fa59364cc
Signed-off-by: Ken Liu <Ken.Liu@arm.com>
diff --git a/secure_fw/spm/ffm/psa_client_service_apis.c b/secure_fw/spm/ffm/psa_client_service_apis.c
index be24561..9fba6ee 100644
--- a/secure_fw/spm/ffm/psa_client_service_apis.c
+++ b/secure_fw/spm/ffm/psa_client_service_apis.c
@@ -15,7 +15,7 @@
 #endif
 #include "tfm_core_utils.h"
 #include "tfm_hal_platform.h"
-#include "tfm_internal_defines.h"
+#include "ffm/spm_error_base.h"
 #include "tfm_rpc.h"
 #include "tfm_spm_hal.h"
 
@@ -84,7 +84,7 @@
      */
     if (tfm_memory_check((const void *)args[1],
         sizeof(struct tfm_control_parameter_t), ns_caller,
-        TFM_MEMORY_ACCESS_RW, privileged) != IPC_SUCCESS) {
+        TFM_MEMORY_ACCESS_RW, privileged) != SPM_SUCCESS) {
         TFM_PROGRAMMER_ERROR(ns_caller, PSA_ERROR_PROGRAMMER_ERROR);
     }
 
@@ -199,7 +199,7 @@
      * input msg pointer is not a valid memory reference or not read-write.
      */
     if (tfm_memory_check(msg, sizeof(psa_msg_t), false, TFM_MEMORY_ACCESS_RW,
-        privileged) != IPC_SUCCESS) {
+        privileged) != SPM_SUCCESS) {
         tfm_core_panic();
     }
 
@@ -314,7 +314,7 @@
      * if the memory reference for buffer is invalid or not read-write.
      */
     if (tfm_memory_check(buffer, num_bytes, false,
-        TFM_MEMORY_ACCESS_RW, privileged) != IPC_SUCCESS) {
+        TFM_MEMORY_ACCESS_RW, privileged) != SPM_SUCCESS) {
         tfm_core_panic();
     }
 
@@ -441,7 +441,7 @@
      * if the memory reference for buffer is invalid or not readable.
      */
     if (tfm_memory_check(buffer, num_bytes, false,
-        TFM_MEMORY_ACCESS_RO, privileged) != IPC_SUCCESS) {
+        TFM_MEMORY_ACCESS_RO, privileged) != SPM_SUCCESS) {
         tfm_core_panic();
     }
 
diff --git a/secure_fw/spm/ffm/spm_psa_client_call.c b/secure_fw/spm/ffm/spm_psa_client_call.c
index d054705..c37913e 100644
--- a/secure_fw/spm/ffm/spm_psa_client_call.c
+++ b/secure_fw/spm/ffm/spm_psa_client_call.c
@@ -8,12 +8,12 @@
 #include "psa/service.h"
 #include "spm_ipc.h"
 #include "tfm_core_utils.h"
-#include "tfm_internal_defines.h"
 #include "tfm_memory_utils.h"
 #include "spm_psa_client_call.h"
 #include "utilities.h"
 #include "tfm_wait.h"
 #include "tfm_nspm.h"
+#include "ffm/spm_error_base.h"
 
 uint32_t tfm_spm_client_psa_framework_version(void)
 {
@@ -37,7 +37,7 @@
      * It should return PSA_VERSION_NONE if the caller is not authorized
      * to access the RoT Service.
      */
-    if (tfm_spm_check_authorization(sid, service, ns_caller) != IPC_SUCCESS) {
+    if (tfm_spm_check_authorization(sid, service, ns_caller) != SPM_SUCCESS) {
         return PSA_VERSION_NONE;
     }
 
@@ -69,7 +69,7 @@
      * It is a PROGRAMMER ERROR if the caller is not authorized to access the RoT
      * Service.
      */
-    if (tfm_spm_check_authorization(sid, service, ns_caller) != IPC_SUCCESS) {
+    if (tfm_spm_check_authorization(sid, service, ns_caller) != SPM_SUCCESS) {
         TFM_PROGRAMMER_ERROR(ns_caller, PSA_ERROR_CONNECTION_REFUSED);
     }
 
@@ -86,7 +86,7 @@
      * It is a PROGRAMMER ERROR if the version of the RoT Service requested is not
      * supported on the platform.
      */
-    if (tfm_spm_check_client_version(service, version) != IPC_SUCCESS) {
+    if (tfm_spm_check_client_version(service, version) != SPM_SUCCESS) {
         TFM_PROGRAMMER_ERROR(ns_caller, PSA_ERROR_CONNECTION_REFUSED);
     }
 
@@ -138,7 +138,7 @@
 
     conn_handle = tfm_spm_to_handle_instance(handle);
     /* It is a PROGRAMMER ERROR if an invalid handle was passed. */
-    if (tfm_spm_validate_conn_handle(conn_handle, client_id) != IPC_SUCCESS) {
+    if (tfm_spm_validate_conn_handle(conn_handle, client_id) != SPM_SUCCESS) {
         TFM_PROGRAMMER_ERROR(ns_caller, PSA_ERROR_PROGRAMMER_ERROR);
     }
 
@@ -167,7 +167,7 @@
      * readable.
      */
     if (tfm_memory_check(inptr, in_num * sizeof(psa_invec), ns_caller,
-        TFM_MEMORY_ACCESS_RO, privileged) != IPC_SUCCESS) {
+        TFM_MEMORY_ACCESS_RO, privileged) != SPM_SUCCESS) {
         TFM_PROGRAMMER_ERROR(ns_caller, PSA_ERROR_PROGRAMMER_ERROR);
     }
 
@@ -177,7 +177,7 @@
      * the wrap output vector is invalid or not read-write.
      */
     if (tfm_memory_check(outptr, out_num * sizeof(psa_outvec), ns_caller,
-        TFM_MEMORY_ACCESS_RW, privileged) != IPC_SUCCESS) {
+        TFM_MEMORY_ACCESS_RW, privileged) != SPM_SUCCESS) {
         TFM_PROGRAMMER_ERROR(ns_caller, PSA_ERROR_PROGRAMMER_ERROR);
     }
 
@@ -194,7 +194,7 @@
      */
     for (i = 0; i < in_num; i++) {
         if (tfm_memory_check(invecs[i].base, invecs[i].len, ns_caller,
-            TFM_MEMORY_ACCESS_RO, privileged) != IPC_SUCCESS) {
+            TFM_MEMORY_ACCESS_RO, privileged) != SPM_SUCCESS) {
             TFM_PROGRAMMER_ERROR(ns_caller, PSA_ERROR_PROGRAMMER_ERROR);
         }
     }
@@ -221,7 +221,7 @@
      */
     for (i = 0; i < out_num; i++) {
         if (tfm_memory_check(outvecs[i].base, outvecs[i].len,
-            ns_caller, TFM_MEMORY_ACCESS_RW, privileged) != IPC_SUCCESS) {
+            ns_caller, TFM_MEMORY_ACCESS_RW, privileged) != SPM_SUCCESS) {
             TFM_PROGRAMMER_ERROR(ns_caller, PSA_ERROR_PROGRAMMER_ERROR);
         }
     }
@@ -243,7 +243,7 @@
      * Send message and wake up the SP who is waiting on message queue,
      * and scheduler triggered
      */
-    if (tfm_spm_send_event(service, msg) != IPC_SUCCESS) {
+    if (tfm_spm_send_event(service, msg) != SPM_SUCCESS) {
         /* FixMe: Need to refine failure process here. */
         tfm_core_panic();
     }
@@ -273,7 +273,7 @@
      * It is a PROGRAMMER ERROR if an invalid handle was provided that is not
      * the null handle.
      */
-    if (tfm_spm_validate_conn_handle(conn_handle, client_id) != IPC_SUCCESS) {
+    if (tfm_spm_validate_conn_handle(conn_handle, client_id) != SPM_SUCCESS) {
         TFM_PROGRAMMER_ERROR(ns_caller, PROGRAMMER_ERROR_NULL);
     }
 
diff --git a/secure_fw/spm/ffm/tfm_boot_data.c b/secure_fw/spm/ffm/tfm_boot_data.c
index 2dc67f0..f05e0e3 100644
--- a/secure_fw/spm/ffm/tfm_boot_data.c
+++ b/secure_fw/spm/ffm/tfm_boot_data.c
@@ -13,7 +13,7 @@
 #include "tfm_core_utils.h"
 #include "spm_partition_defs.h"
 #ifdef TFM_PSA_API
-#include "tfm_internal_defines.h"
+#include "internal_errors.h"
 #include "utilities.h"
 #include "psa/service.h"
 #include "tfm_thread.h"
@@ -175,7 +175,7 @@
         tfm_spm_partition_get_privileged_mode(partition->p_static->flags);
 
     if (tfm_memory_check(buf_start, buf_size, false, TFM_MEMORY_ACCESS_RW,
-        privileged) != IPC_SUCCESS) {
+        privileged) != SPM_SUCCESS) {
         /* Not in accessible range, return error */
         args[0] = (uint32_t)TFM_ERROR_INVALID_PARAMETER;
         return;