FFA: Set and verify allocator of memory handle
Change-Id: I19dff61311228399cdf8f26a855e91981473a8a7
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/inc/hf/arch/ffa_memory_handle.h b/inc/hf/arch/ffa_memory_handle.h
new file mode 100644
index 0000000..9eba5d4
--- /dev/null
+++ b/inc/hf/arch/ffa_memory_handle.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2021 The Hafnium Authors.
+ *
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file or at
+ * https://opensource.org/licenses/BSD-3-Clause.
+ */
+
+#ifndef FFA_MEMORY_HANDLE_H
+#define FFA_MEMORY_HANDLE_H
+
+#include "hf/ffa.h"
+
+/**
+ * Encodes memory handle according to section 5.10.2 of the FF-A v1.0 spec.
+ */
+ffa_memory_handle_t ffa_memory_handle_make(uint64_t index);
+
+/**
+ * Checks whether given handle was allocated by current world, according to
+ * handle encoding rules.
+ */
+bool ffa_memory_handle_allocated_by_current_world(ffa_memory_handle_t handle);
+
+#endif
diff --git a/inc/vmapi/hf/ffa.h b/inc/vmapi/hf/ffa.h
index b7d85a0..2cb0514 100644
--- a/inc/vmapi/hf/ffa.h
+++ b/inc/vmapi/hf/ffa.h
@@ -184,21 +184,23 @@
ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t,
FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK)
-#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
- ((ffa_memory_handle_t)(UINT64_C(1) << 63))
-#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \
- ((ffa_memory_handle_t)(UINT64_C(1) << 63))
-#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
-
-/** The ID of a VM. These are assigned sequentially starting with an offset. */
-typedef uint16_t ffa_vm_id_t;
-
/**
* A globally-unique ID assigned by the hypervisor for a region of memory being
* sent between VMs.
*/
typedef uint64_t ffa_memory_handle_t;
+#define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \
+ ((ffa_memory_handle_t)(UINT64_C(1) << 63))
+#define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \
+ ((ffa_memory_handle_t)(UINT64_C(1) << 63))
+
+#define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63)
+#define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0))
+
+/** The ID of a VM. These are assigned sequentially starting with an offset. */
+typedef uint16_t ffa_vm_id_t;
+
/**
* A count of VMs. This has the same range as the VM IDs but we give it a
* different name to make the different semantics clear.