spm-mm: Refactor spm_svc.h and its contents

Change-Id: I91c192924433226b54d33e57d56d146c1c6df81b
Signed-off-by: Paul Beesley <paul.beesley@arm.com>
diff --git a/services/std_svc/spm_mm/spm_main.c b/services/std_svc/spm_mm/spm_main.c
index b2f93a6..ff0d001 100644
--- a/services/std_svc/spm_mm/spm_main.c
+++ b/services/std_svc/spm_mm/spm_main.c
@@ -20,7 +20,7 @@
 #include <plat/common/platform.h>
 #include <services/mm_svc.h>
 #include <services/spm_mm_partition.h>
-#include <services/spm_svc.h>
+#include <services/spm_mm_svc.h>
 #include <smccc_helpers.h>
 
 #include "spm_private.h"
@@ -157,7 +157,7 @@
 /*******************************************************************************
  * Initialize contexts of all Secure Partitions.
  ******************************************************************************/
-int32_t spm_setup(void)
+int32_t spm_mm_setup(void)
 {
 	sp_context_t *ctx;
 
@@ -185,7 +185,7 @@
 /*******************************************************************************
  * Function to perform a call to a Secure Partition.
  ******************************************************************************/
-uint64_t spm_sp_call(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3)
+uint64_t spm_mm_sp_call(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3)
 {
 	uint64_t rc;
 	sp_context_t *sp_ptr = &sp_ctx;
@@ -223,12 +223,12 @@
 	/* Cookie. Reserved for future use. It must be zero. */
 	if (mm_cookie != 0U) {
 		ERROR("MM_COMMUNICATE: cookie is not zero\n");
-		SMC_RET1(handle, SPM_INVALID_PARAMETER);
+		SMC_RET1(handle, SPM_MM_INVALID_PARAMETER);
 	}
 
 	if (comm_buffer_address == 0U) {
 		ERROR("MM_COMMUNICATE: comm_buffer_address is zero\n");
-		SMC_RET1(handle, SPM_INVALID_PARAMETER);
+		SMC_RET1(handle, SPM_MM_INVALID_PARAMETER);
 	}
 
 	if (comm_size_address != 0U) {
@@ -251,8 +251,8 @@
 	/* Save the Normal world context */
 	cm_el1_sysregs_context_save(NON_SECURE);
 
-	rc = spm_sp_call(smc_fid, comm_buffer_address, comm_size_address,
-			 plat_my_core_pos());
+	rc = spm_mm_sp_call(smc_fid, comm_buffer_address, comm_size_address,
+			    plat_my_core_pos());
 
 	/* Restore non-secure state */
 	cm_el1_sysregs_context_restore(NON_SECURE);
@@ -270,7 +270,7 @@
 /*******************************************************************************
  * Secure Partition Manager SMC handler.
  ******************************************************************************/
-uint64_t spm_smc_handler(uint32_t smc_fid,
+uint64_t spm_mm_smc_handler(uint32_t smc_fid,
 			 uint64_t x1,
 			 uint64_t x2,
 			 uint64_t x3,
@@ -295,29 +295,29 @@
 
 		switch (smc_fid) {
 
-		case SPM_VERSION_AARCH32:
-			SMC_RET1(handle, SPM_VERSION_COMPILED);
+		case SPM_MM_VERSION_AARCH32:
+			SMC_RET1(handle, SPM_MM_VERSION_COMPILED);
 
-		case SP_EVENT_COMPLETE_AARCH64:
+		case MM_SP_EVENT_COMPLETE_AARCH64:
 			spm_sp_synchronous_exit(x1);
 
-		case SP_MEMORY_ATTRIBUTES_GET_AARCH64:
-			INFO("Received SP_MEMORY_ATTRIBUTES_GET_AARCH64 SMC\n");
+		case MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64:
+			INFO("Received MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64 SMC\n");
 
 			if (sp_ctx.state != SP_STATE_RESET) {
-				WARN("SP_MEMORY_ATTRIBUTES_GET_AARCH64 is available at boot time only\n");
-				SMC_RET1(handle, SPM_NOT_SUPPORTED);
+				WARN("MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64 is available at boot time only\n");
+				SMC_RET1(handle, SPM_MM_NOT_SUPPORTED);
 			}
 			SMC_RET1(handle,
 				 spm_memory_attributes_get_smc_handler(
 					 &sp_ctx, x1));
 
-		case SP_MEMORY_ATTRIBUTES_SET_AARCH64:
-			INFO("Received SP_MEMORY_ATTRIBUTES_SET_AARCH64 SMC\n");
+		case MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64:
+			INFO("Received MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64 SMC\n");
 
 			if (sp_ctx.state != SP_STATE_RESET) {
-				WARN("SP_MEMORY_ATTRIBUTES_SET_AARCH64 is available at boot time only\n");
-				SMC_RET1(handle, SPM_NOT_SUPPORTED);
+				WARN("MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64 is available at boot time only\n");
+				SMC_RET1(handle, SPM_MM_NOT_SUPPORTED);
 			}
 			SMC_RET1(handle,
 				 spm_memory_attributes_set_smc_handler(
@@ -340,10 +340,10 @@
 		case MM_COMMUNICATE_AARCH64:
 			return mm_communicate(smc_fid, x1, x2, x3, handle);
 
-		case SP_MEMORY_ATTRIBUTES_GET_AARCH64:
-		case SP_MEMORY_ATTRIBUTES_SET_AARCH64:
+		case MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64:
+		case MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64:
 			/* SMC interfaces reserved for secure callers. */
-			SMC_RET1(handle, SPM_NOT_SUPPORTED);
+			SMC_RET1(handle, SPM_MM_NOT_SUPPORTED);
 
 		default:
 			break;
diff --git a/services/std_svc/spm_mm/spm_xlat.c b/services/std_svc/spm_mm/spm_xlat.c
index a2df1af..0c2399c 100644
--- a/services/std_svc/spm_mm/spm_xlat.c
+++ b/services/std_svc/spm_mm/spm_xlat.c
@@ -12,7 +12,7 @@
 #include <platform_def.h>
 #include <plat/common/platform.h>
 #include <services/spm_mm_partition.h>
-#include <services/spm_svc.h>
+#include <services/spm_mm_svc.h>
 
 #include "spm_private.h"
 #include "spm_shim_private.h"
@@ -50,21 +50,21 @@
 {
 	unsigned int tf_attr = 0U;
 
-	unsigned int access = (attributes & SP_MEMORY_ATTRIBUTES_ACCESS_MASK)
-			      >> SP_MEMORY_ATTRIBUTES_ACCESS_SHIFT;
+	unsigned int access = (attributes & MM_SP_MEMORY_ATTRIBUTES_ACCESS_MASK)
+			      >> MM_SP_MEMORY_ATTRIBUTES_ACCESS_SHIFT;
 
-	if (access == SP_MEMORY_ATTRIBUTES_ACCESS_RW) {
+	if (access == MM_SP_MEMORY_ATTRIBUTES_ACCESS_RW) {
 		tf_attr |= MT_RW | MT_USER;
-	} else if (access ==  SP_MEMORY_ATTRIBUTES_ACCESS_RO) {
+	} else if (access ==  MM_SP_MEMORY_ATTRIBUTES_ACCESS_RO) {
 		tf_attr |= MT_RO | MT_USER;
 	} else {
 		/* Other values are reserved. */
-		assert(access ==  SP_MEMORY_ATTRIBUTES_ACCESS_NOACCESS);
+		assert(access == MM_SP_MEMORY_ATTRIBUTES_ACCESS_NOACCESS);
 		/* The only requirement is that there's no access from EL0 */
 		tf_attr |= MT_RO | MT_PRIVILEGED;
 	}
 
-	if ((attributes & SP_MEMORY_ATTRIBUTES_NON_EXEC) == 0) {
+	if ((attributes & MM_SP_MEMORY_ATTRIBUTES_NON_EXEC) == 0) {
 		tf_attr |= MT_EXECUTE;
 	} else {
 		tf_attr |= MT_EXECUTE_NEVER;
@@ -85,21 +85,21 @@
 
 	if ((attr & MT_USER) == 0) {
 		/* No access from EL0. */
-		data_access = SP_MEMORY_ATTRIBUTES_ACCESS_NOACCESS;
+		data_access = MM_SP_MEMORY_ATTRIBUTES_ACCESS_NOACCESS;
 	} else {
 		if ((attr & MT_RW) != 0) {
 			assert(MT_TYPE(attr) != MT_DEVICE);
-			data_access = SP_MEMORY_ATTRIBUTES_ACCESS_RW;
+			data_access = MM_SP_MEMORY_ATTRIBUTES_ACCESS_RW;
 		} else {
-			data_access = SP_MEMORY_ATTRIBUTES_ACCESS_RO;
+			data_access = MM_SP_MEMORY_ATTRIBUTES_ACCESS_RO;
 		}
 	}
 
-	smc_attr |= (data_access & SP_MEMORY_ATTRIBUTES_ACCESS_MASK)
-		    << SP_MEMORY_ATTRIBUTES_ACCESS_SHIFT;
+	smc_attr |= (data_access & MM_SP_MEMORY_ATTRIBUTES_ACCESS_MASK)
+		    << MM_SP_MEMORY_ATTRIBUTES_ACCESS_SHIFT;
 
 	if ((attr & MT_EXECUTE_NEVER) != 0U) {
-		smc_attr |= SP_MEMORY_ATTRIBUTES_NON_EXEC;
+		smc_attr |= MM_SP_MEMORY_ATTRIBUTES_NON_EXEC;
 	}
 
 	return smc_attr;
@@ -123,7 +123,7 @@
 	if (rc == 0) {
 		return (int32_t) smc_mmap_to_smc_attr(attributes);
 	} else {
-		return SPM_INVALID_PARAMETER;
+		return SPM_MM_INVALID_PARAMETER;
 	}
 }
 
@@ -151,5 +151,5 @@
 	/* Convert error codes of xlat_change_mem_attributes_ctx() into SPM. */
 	assert((ret == 0) || (ret == -EINVAL));
 
-	return (ret == 0) ? SPM_SUCCESS : SPM_INVALID_PARAMETER;
+	return (ret == 0) ? SPM_MM_SUCCESS : SPM_MM_INVALID_PARAMETER;
 }
diff --git a/services/std_svc/std_svc_setup.c b/services/std_svc/std_svc_setup.c
index 7a95c5b..7787a2f 100644
--- a/services/std_svc/std_svc_setup.c
+++ b/services/std_svc/std_svc_setup.c
@@ -14,7 +14,7 @@
 #include <lib/psci/psci.h>
 #include <lib/runtime_instr.h>
 #include <services/sdei.h>
-#include <services/spm_svc.h>
+#include <services/spm_mm_svc.h>
 #include <services/std_svc.h>
 #include <smccc_helpers.h>
 #include <tools_share/uuid.h>
@@ -46,7 +46,7 @@
 	}
 
 #if SPM_MM
-	if (spm_setup() != 0) {
+	if (spm_mm_setup() != 0) {
 		ret = 1;
 	}
 #endif
@@ -108,9 +108,9 @@
 	 * Dispatch SPM calls to SPM SMC handler and return its return
 	 * value
 	 */
-	if (is_spm_fid(smc_fid)) {
-		return spm_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
-				       handle, flags);
+	if (is_spm_mm_fid(smc_fid)) {
+		return spm_mm_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
+					  handle, flags);
 	}
 #endif