FF-A: Accessors for arguments from FF-A calls

Defined some accessors for arguments from FF-A calls, namely for
func id, error code, and direct message destination/source.
This should help make consistent how they were being handled,
enforcing also adequate type checking.
Replace the accesses to those FF-A arguments with respective wrapper
calls.

Change-Id: I99d8e77f3b24728c30eafa3e76a830246790ec5f
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index 87ef837..11d7b99 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -57,27 +57,27 @@
 	ffa_ret = ffa_msg_wait();
 
 	for (;;) {
-		VERBOSE("Woke up with func id: %lx\n", ffa_ret.ret0);
+		VERBOSE("Woke up with func id: %x\n", ffa_func_id(ffa_ret));
 
-		if (ffa_ret.ret0 == FFA_ERROR) {
-			ERROR("Error: %lx\n", ffa_ret.ret2);
+		if (ffa_func_id(ffa_ret) == FFA_ERROR) {
+			ERROR("Error: %x\n", ffa_error_code(ffa_ret));
 			break;
 		}
 
-		if (ffa_ret.ret0 != FFA_MSG_SEND_DIRECT_REQ_SMC32 &&
-		    ffa_ret.ret0 != FFA_MSG_SEND_DIRECT_REQ_SMC64) {
-			ERROR("%s(%u) unknown func id 0x%lx\n",
-				__func__, vm_id, ffa_ret.ret0);
+		if (ffa_func_id(ffa_ret) != FFA_MSG_SEND_DIRECT_REQ_SMC32 &&
+		    ffa_func_id(ffa_ret) != FFA_MSG_SEND_DIRECT_REQ_SMC64) {
+			ERROR("%s(%u) unknown func id 0x%x\n",
+				__func__, vm_id, ffa_func_id(ffa_ret));
 			break;
 		}
 
-		destination = ffa_ret.ret1 & U(0xFFFF);
+		destination = ffa_dir_msg_dest(ffa_ret);
 
-		source = ffa_ret.ret1 >> 16;
+		source = ffa_dir_msg_source(ffa_ret);
 
 		if (destination != vm_id) {
-			ERROR("%s(%u) invalid vm id 0x%lx\n",
-				__func__, vm_id, ffa_ret.ret1);
+			ERROR("%s(%u) invalid vm id 0x%x\n",
+				__func__, vm_id, destination);
 			break;
 		}
 
@@ -134,9 +134,10 @@
 			ffa_ret = cactus_mem_send_cmd(vm_id, receiver, mem_func,
 						      handle);
 
-			if (ffa_ret.ret0 != FFA_MSG_SEND_DIRECT_RESP_SMC32) {
-				ERROR("Failed to send message. error: %lx\n",
-					ffa_ret.ret2);
+			if (ffa_func_id(ffa_ret) !=
+					FFA_MSG_SEND_DIRECT_RESP_SMC32) {
+				ERROR("Failed to send message. error: %x\n",
+					ffa_error_code(ffa_ret));
 				ffa_ret = cactus_error_resp(vm_id, source);
 				break;
 			}
@@ -188,9 +189,9 @@
 		{
 			uint64_t echo_val = cactus_echo_get_val(ffa_ret);
 
-			VERBOSE("Received echo at %x, value %llx.\n",
-				destination, echo_val);
-			ffa_ret = cactus_response(vm_id, source, echo_val);
+			VERBOSE("Received echo at %x, value %llx from %x.\n",
+				destination, echo_val, source);
+			ffa_ret = cactus_response(destination, source, echo_val);
 			break;
 		}
 		case CACTUS_REQ_ECHO_CMD:
@@ -206,9 +207,10 @@
 			ffa_ret = cactus_echo_send_cmd(vm_id, echo_dest,
 							echo_val);
 
-			if (ffa_ret.ret0 != FFA_MSG_SEND_DIRECT_RESP_SMC32) {
-				ERROR("Failed to send message. error: %lx\n",
-					ffa_ret.ret2);
+			if (ffa_func_id(ffa_ret) !=
+			    FFA_MSG_SEND_DIRECT_RESP_SMC32) {
+				ERROR("Failed to send message. error: %x\n",
+					ffa_error_code(ffa_ret));
 				success = false;
 			}
 
@@ -248,8 +250,8 @@
 			 * an FF-A direct message, to the first partition.
 			 */
 			bool is_deadlock_detected =
-				(ffa_ret.ret0 == FFA_ERROR) &&
-				(ffa_ret.ret2 == FFA_ERROR_BUSY);
+				(ffa_func_id(ffa_ret) == FFA_ERROR) &&
+				(ffa_error_code(ffa_ret) == FFA_ERROR_BUSY);
 
 			/*
 			 * Should be true after the deadlock has been detected
@@ -257,13 +259,14 @@
 			 * request chain.
 			 */
 			bool is_returning_from_deadlock =
-				(ffa_ret.ret0 == FFA_MSG_SEND_DIRECT_RESP_SMC32)
+				(ffa_func_id(ffa_ret) ==
+				 FFA_MSG_SEND_DIRECT_RESP_SMC32)
 				&&
 				(cactus_get_response(ffa_ret) == CACTUS_SUCCESS);
 
 			if (is_deadlock_detected) {
-				NOTICE("Attempting dealock but got error %lx\n",
-					ffa_ret.ret2);
+				NOTICE("Attempting dealock but got error %x\n",
+					ffa_error_code(ffa_ret));
 			}
 
 			if (is_deadlock_detected ||
@@ -390,7 +393,7 @@
 
 	/* Get current FFA id */
 	smc_ret_values ffa_id_ret = ffa_id_get();
-	if (ffa_id_ret.ret0 != FFA_SUCCESS_SMC32) {
+	if (ffa_func_id(ffa_id_ret) != FFA_SUCCESS_SMC32) {
 		ERROR("FFA_ID_GET failed.\n");
 		panic();
 	}
@@ -422,10 +425,10 @@
 		if (ffa_id == (SPM_VM_ID_FIRST + 2)) {
 			VERBOSE("Mapping RXTX Region\n");
 			CONFIGURE_AND_MAP_MAILBOX(mb, PAGE_SIZE, ret);
-			if (ret.ret0 != FFA_SUCCESS_SMC32) {
+			if (ffa_func_id(ret) != FFA_SUCCESS_SMC32) {
 				ERROR(
-				    "Failed to map RXTX buffers. Error: %lx\n",
-				    ret.ret2);
+				    "Failed to map RXTX buffers. Error: %x\n",
+				    ffa_error_code(ret));
 				panic();
 			}
 		}