fix(ff-a): memory sharing clear memory flag use

This patch insures the borrower of a memory region can request to have
the memory cleared in FFA_MEM_RETRIEVE_REQ call, only if memory sender
has set the equivalent flag in the memory transaction descriptor
upon calling either FFA_MEM_DONATE or FFA_MEM_LEND.
This is defined by the FF-A v1.1 Beta0 specification, in the table
10.22.

Change-Id: Ibf3e5cab9512c1bea3f83f939c0b7d1ae9cc74fd
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/src/ffa_memory.c b/src/ffa_memory.c
index 51a73ec..f51bbd8 100644
--- a/src/ffa_memory.c
+++ b/src/ffa_memory.c
@@ -2269,6 +2269,21 @@
 	}
 
 	/*
+	 * If the borrower needs the memory to be cleared before mapping to its
+	 * address space, the sender should have set the flag when calling
+	 * FFA_MEM_LEND/FFA_MEM_DONATE, else return FFA_DENIED.
+	 */
+	if ((retrieve_request->flags & FFA_MEMORY_REGION_FLAG_CLEAR) != 0U &&
+	    (share_state->memory_region->flags &
+	     FFA_MEMORY_REGION_FLAG_CLEAR) == 0U) {
+		dlog_verbose(
+			"Borrower needs memory cleared. Sender needs to set "
+			"flag for clearing memory.\n");
+		ret = ffa_error(FFA_DENIED);
+		goto out;
+	}
+
+	/*
 	 * Check permissions from sender against permissions requested by
 	 * receiver.
 	 */