cactus: macros for processing of commands

Set of macros to be used for sending and handling commands to and
from cactus.
The implemented macros use ffa direct messaging interfaces.

Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I4e02933167ce078d3a467881eece588fa460510b
diff --git a/include/runtime_services/ffa_helpers.h b/include/runtime_services/ffa_helpers.h
index e81cd13..766ea39 100644
--- a/include/runtime_services/ffa_helpers.h
+++ b/include/runtime_services/ffa_helpers.h
@@ -360,13 +360,14 @@
 	enum ffa_memory_shareability shareability, uint32_t *total_length,
 	uint32_t *fragment_length);
 
-/*
- * TODO: In the future this file should be placed in a common folder, and not
- * under tftf. The functions in this file are also used by SPs for SPM tests.
- */
 bool check_spmc_execution_level(void);
 smc_ret_values ffa_msg_send_direct_req(uint32_t source_id, uint32_t dest_id, uint32_t message);
 smc_ret_values ffa_msg_send_direct_req64(uint32_t source_id, uint32_t dest_id, uint64_t message);
+smc_ret_values ffa_msg_send_direct_req64_5args(uint32_t source_id, uint32_t dest_id,
+					   uint64_t arg0, uint64_t arg1,
+					   uint64_t arg2, uint64_t arg3,
+					   uint64_t arg4);
+
 smc_ret_values ffa_run(uint32_t dest_id, uint32_t vcpu_id);
 smc_ret_values ffa_version(uint32_t input_version);
 smc_ret_values ffa_id_get(void);
diff --git a/spm/cactus/cactus_test_cmds.h b/spm/cactus/cactus_test_cmds.h
new file mode 100644
index 0000000..6329b6d
--- /dev/null
+++ b/spm/cactus/cactus_test_cmds.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef CACTUS_TEST_CMDS
+#define CACTUS_TEST_CMDS
+
+#include <debug.h>
+#include <ffa_helpers.h>
+
+/**
+ * Success and error return to be sent over a msg response.
+ */
+#define CACTUS_SUCCESS	 0
+#define CACTUS_ERROR	-1
+
+/**
+ * Get command from struct smc_ret_values.
+ */
+#define CACTUS_GET_CMD(smc_ret) smc_ret.ret3
+
+/**
+ * Template for commands to be sent to CACTUS partitions over direct
+ * messages interfaces.
+ */
+#define CACTUS_SEND_CMD(source, dest, cmd, val0, val1, val2, val3)	\
+	ffa_msg_send_direct_req64_5args(source, dest, cmd, 		\
+					val0, val1, val2, val3)
+
+#define PRINT_CMD(smc_ret)						\
+	VERBOSE("cmd %lx; args: %lx, %lx, %lx, %lx\n",	 		\
+		smc_ret.ret3, smc_ret.ret4, smc_ret.ret5, 		\
+		smc_ret.ret6, smc_ret.ret7)
+
+/**
+ * Command to notify cactus of a memory management operation. The cmd value
+ * should be the memory management smc function id.
+ */
+#define CACTUS_MEM_SEND_CMD(source, dest, mem_func, handle) 		\
+		CACTUS_SEND_CMD(source, dest, mem_func, handle, 0, 0, 0)
+
+#define CACTUS_MEM_SEND_GET_HANDLE(smc_ret) smc_ret.ret4
+
+/**
+ * Template for responses to CACTUS commands.
+ */
+#define CACTUS_RESPONSE(source, dest, response) 			\
+		ffa_msg_send_direct_resp(source, dest, response)
+
+#define CACTUS_SUCCESS_RESP(source, dest) 				\
+		CACTUS_RESPONSE(source, dest, CACTUS_SUCCESS)
+
+#define CACTUS_ERROR_RESP(source, dest) 				\
+		CACTUS_RESPONSE(source, dest, CACTUS_ERROR)
+
+#define CACTUS_GET_RESPONSE(smc_ret) smc_ret.ret3
+
+#endif
diff --git a/tftf/tests/runtime_services/secure_service/ffa_helpers.c b/tftf/tests/runtime_services/secure_service/ffa_helpers.c
index a17b01a..78dfa42 100644
--- a/tftf/tests/runtime_services/secure_service/ffa_helpers.c
+++ b/tftf/tests/runtime_services/secure_service/ffa_helpers.c
@@ -86,7 +86,7 @@
 					      message, 0, 0, 0, 0);
 }
 
-static smc_ret_values __ffa_msg_send_direct_req64_5(uint32_t source_id,
+smc_ret_values ffa_msg_send_direct_req64_5args(uint32_t source_id,
 						     uint32_t dest_id,
 						     uint64_t arg0,
 						     uint64_t arg1,
@@ -108,7 +108,7 @@
 smc_ret_values ffa_msg_send_direct_req64(uint32_t source_id, uint32_t dest_id,
 					uint64_t message)
 {
-	return __ffa_msg_send_direct_req64_5(source_id, dest_id,
+	return ffa_msg_send_direct_req64_5args(source_id, dest_id,
 					      message, 0, 0, 0, 0);
 }