refactor(plat/ffa): memory handle refactorings

Replace the need for each platform to provide a definition of
`plat_ffa_memory_handle_make` and
`plat_ffa_memory_handle_allocated_by_current_world`. Instead, they only
need to provide a value for `plat_ffa_memory_handle_allocator`.

Move `FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR` and
`FFA_MEMORY_HANDLE_ALLOCATOR_SPMC` constants into an enum.

Add helper functions for getting a memory handle's allocator and index.

Change-Id: I4f4661a2e7e37769e947383b4b45718fb0ddfa1a
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
diff --git a/src/arch/aarch64/plat/ffa/absent.c b/src/arch/aarch64/plat/ffa/absent.c
index 4fb34c4..9628b17 100644
--- a/src/arch/aarch64/plat/ffa/absent.c
+++ b/src/arch/aarch64/plat/ffa/absent.c
@@ -161,19 +161,6 @@
 	return false;
 }
 
-ffa_memory_handle_t plat_ffa_memory_handle_make(uint64_t index)
-{
-	return index | FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR;
-}
-
-bool plat_ffa_memory_handle_allocated_by_current_world(
-	ffa_memory_handle_t handle)
-{
-	(void)handle;
-
-	return false;
-}
-
 uint32_t plat_ffa_other_world_mode(void)
 {
 	return 0U;
diff --git a/src/arch/aarch64/plat/ffa/hypervisor/ffa_memory.c b/src/arch/aarch64/plat/ffa/hypervisor/ffa_memory.c
index 76feee9..6e588cf 100644
--- a/src/arch/aarch64/plat/ffa/hypervisor/ffa_memory.c
+++ b/src/arch/aarch64/plat/ffa/hypervisor/ffa_memory.c
@@ -18,6 +18,11 @@
 #include "hypervisor.h"
 #include "sysregs.h"
 
+enum ffa_memory_handle_allocator plat_ffa_memory_handle_allocator(void)
+{
+	return FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR;
+}
+
 static struct ffa_value ffa_other_world_mem_reclaim(
 	ffa_memory_handle_t handle, ffa_memory_region_flags_t flags)
 {
@@ -49,18 +54,6 @@
 	return true;
 }
 
-ffa_memory_handle_t plat_ffa_memory_handle_make(uint64_t index)
-{
-	return index | FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR;
-}
-
-bool plat_ffa_memory_handle_allocated_by_current_world(
-	ffa_memory_handle_t handle)
-{
-	return (handle & FFA_MEMORY_HANDLE_ALLOCATOR_MASK) ==
-	       FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR;
-}
-
 uint32_t plat_ffa_other_world_mode(void)
 {
 	return 0U;
diff --git a/src/arch/aarch64/plat/ffa/spmc/ffa_memory.c b/src/arch/aarch64/plat/ffa/spmc/ffa_memory.c
index 5126253..57d7834 100644
--- a/src/arch/aarch64/plat/ffa/spmc/ffa_memory.c
+++ b/src/arch/aarch64/plat/ffa/spmc/ffa_memory.c
@@ -16,6 +16,11 @@
 
 #include "sysregs.h"
 
+enum ffa_memory_handle_allocator plat_ffa_memory_handle_allocator(void)
+{
+	return FFA_MEMORY_HANDLE_ALLOCATOR_SPMC;
+}
+
 /** Check validity of the FF-A memory send function attempt. */
 bool plat_ffa_is_memory_send_valid(ffa_id_t receiver, ffa_id_t sender,
 				   uint32_t share_func, bool multiple_borrower)
@@ -57,19 +62,6 @@
 	}
 }
 
-ffa_memory_handle_t plat_ffa_memory_handle_make(uint64_t index)
-{
-	return (index & ~FFA_MEMORY_HANDLE_ALLOCATOR_MASK) |
-	       FFA_MEMORY_HANDLE_ALLOCATOR_SPMC;
-}
-
-bool plat_ffa_memory_handle_allocated_by_current_world(
-	ffa_memory_handle_t handle)
-{
-	return (handle & FFA_MEMORY_HANDLE_ALLOCATOR_MASK) ==
-	       FFA_MEMORY_HANDLE_ALLOCATOR_SPMC;
-}
-
 uint32_t plat_ffa_other_world_mode(void)
 {
 	return MM_MODE_NS;
diff --git a/src/arch/fake/hypervisor/ffa.c b/src/arch/fake/hypervisor/ffa.c
index 69effef..71fae1d 100644
--- a/src/arch/fake/hypervisor/ffa.c
+++ b/src/arch/fake/hypervisor/ffa.c
@@ -134,18 +134,6 @@
 	return false;
 }
 
-ffa_memory_handle_t plat_ffa_memory_handle_make(uint64_t index)
-{
-	return index;
-}
-
-bool plat_ffa_memory_handle_allocated_by_current_world(
-	ffa_memory_handle_t handle)
-{
-	(void)handle;
-	return false;
-}
-
 uint32_t plat_ffa_other_world_mode(void)
 {
 	return 0U;
diff --git a/src/ffa_memory.c b/src/ffa_memory.c
index 802d26f..fd92e9f 100644
--- a/src/ffa_memory.c
+++ b/src/ffa_memory.c
@@ -70,14 +70,6 @@
 }
 
 /**
- * Extracts the index from a memory handle allocated by Hafnium's current world.
- */
-uint64_t ffa_memory_handle_get_index(ffa_memory_handle_t handle)
-{
-	return handle & ~FFA_MEMORY_HANDLE_ALLOCATOR_MASK;
-}
-
-/**
  * Initialises the next available `struct ffa_memory_share_state`. If `handle`
  * is `FFA_MEMORY_HANDLE_INVALID` then allocates an appropriate handle,
  * otherwise uses the provided handle which is assumed to be globally unique.
@@ -161,7 +153,7 @@
 	 * handle is based on the index.
 	 */
 	if (plat_ffa_memory_handle_allocated_by_current_world(handle)) {
-		uint64_t index = ffa_memory_handle_get_index(handle);
+		uint64_t index = ffa_memory_handle_index(handle);
 
 		if (index < MAX_MEM_SHARES) {
 			share_state = &share_states.share_states[index];