aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ-Alves <joao.alves@arm.com>2020-11-18 14:51:57 +0000
committerJ-Alves <joao.alves@arm.com>2021-01-21 14:41:47 +0000
commit5339201417a3f37b9fc64fdaf1d677413203b799 (patch)
tree2281af86c56a88f834d407b73f604a5a63bee1a3
parent4904c8632c255b6ac3fb77109f807b3a11cb910b (diff)
downloadtf-a-tests-5339201417a3f37b9fc64fdaf1d677413203b799.tar.gz
Cactus: refactor of cactus_test_cmds.h
Change from macros to static inline functions, to enforce type checking. Signed-off-by: J-Alves <joao.alves@arm.com> Change-Id: I2cbaf99683ca5b2a5689256240894ed05d99e0d8
-rw-r--r--spm/cactus/cactus_main.c59
-rw-r--r--spm/cactus/cactus_test_cmds.h151
-rw-r--r--tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c10
-rw-r--r--tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c12
4 files changed, 143 insertions, 89 deletions
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index de1e555b..e1bfd1fd 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -84,27 +84,28 @@ static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb)
PRINT_CMD(ffa_ret);
- cactus_cmd = CACTUS_GET_CMD(ffa_ret);
+ cactus_cmd = cactus_get_cmd(ffa_ret);
switch (cactus_cmd) {
case CACTUS_MEM_SEND_CMD:
ffa_memory_management_test(
mb, vm_id, source,
- CACTUS_MEM_SEND_GET_FUNC(ffa_ret),
- CACTUS_MEM_SEND_GET_HANDLE(ffa_ret));
+ cactus_req_mem_send_get_mem_func(
+ ffa_ret),
+ cactus_mem_send_get_handle(ffa_ret));
/*
* If execution gets to this point means all operations
* with memory retrieval went well, as such replying
*/
- ffa_ret = CACTUS_SUCCESS_RESP(vm_id, source);
+ ffa_ret = cactus_success_resp(vm_id, source);
break;
case CACTUS_REQ_MEM_SEND_CMD:
{
uint32_t mem_func =
- CACTUS_REQ_MEM_SEND_GET_MEM_FUNC(ffa_ret);
+ cactus_req_mem_send_get_mem_func(ffa_ret);
ffa_vm_id_t receiver =
- CACTUS_REQ_MEM_SEND_GET_RECEIVER(ffa_ret);
+ cactus_req_mem_send_get_receiver(ffa_ret);
ffa_memory_handle_t handle;
VERBOSE("%x requested to send memory to %x (func: %x)\n",
@@ -131,20 +132,20 @@ static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb)
*/
expect(handle != FFA_MEMORY_HANDLE_INVALID, true);
- ffa_ret = CACTUS_MEM_SEND_CMD_SEND(vm_id, receiver,
- mem_func, handle);
+ 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);
- ffa_ret = CACTUS_ERROR_RESP(vm_id, source);
+ ffa_ret = cactus_error_resp(vm_id, source);
break;
}
/* If anything went bad on the receiver's end. */
- if (CACTUS_IS_ERROR_RESP(ffa_ret)) {
+ if (cactus_get_response(ffa_ret) == CACTUS_ERROR) {
ERROR("Received error from receiver!\n");
- ffa_ret = CACTUS_ERROR_RESP(vm_id, source);
+ ffa_ret = cactus_error_resp(vm_id, source);
break;
}
@@ -158,7 +159,7 @@ static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb)
if (ffa_mem_reclaim(handle, 0)
.ret0 == FFA_ERROR) {
ERROR("Failed to reclaim memory!\n");
- ffa_ret = CACTUS_ERROR_RESP(vm_id,
+ ffa_ret = cactus_error_resp(vm_id,
source);
break;
}
@@ -181,29 +182,29 @@ static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb)
#endif
}
- ffa_ret = CACTUS_SUCCESS_RESP(vm_id, source);
+ ffa_ret = cactus_success_resp(vm_id, source);
+ break;
}
- break;
case CACTUS_ECHO_CMD:
{
- uint64_t echo_val = CACTUS_ECHO_GET_VAL(ffa_ret);
+ 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);
+ ffa_ret = cactus_response(vm_id, source, echo_val);
break;
}
case CACTUS_REQ_ECHO_CMD:
{
ffa_vm_id_t echo_dest =
- CACTUS_REQ_ECHO_GET_ECHO_DEST(ffa_ret);
- uint64_t echo_val = CACTUS_ECHO_GET_VAL(ffa_ret);
+ cactus_req_echo_get_echo_dest(ffa_ret);
+ uint64_t echo_val = cactus_echo_get_val(ffa_ret);
bool success = true;
VERBOSE("%x requested to send echo to %x, value %llx\n",
source, echo_dest, echo_val);
- ffa_ret = CACTUS_ECHO_SEND_CMD(vm_id, echo_dest,
+ ffa_ret = cactus_echo_send_cmd(vm_id, echo_dest,
echo_val);
if (ffa_ret.ret0 != FFA_MSG_SEND_DIRECT_RESP_SMC32) {
@@ -212,20 +213,20 @@ static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb)
success = false;
}
- if (CACTUS_GET_RESPONSE(ffa_ret) != echo_val) {
+ if (cactus_get_response(ffa_ret) != echo_val) {
ERROR("Echo Failed!\n");
success = false;
}
- ffa_ret = success ? CACTUS_SUCCESS_RESP(vm_id, source) :
- CACTUS_ERROR_RESP(vm_id, source);
+ ffa_ret = success ? cactus_success_resp(vm_id, source) :
+ cactus_error_resp(vm_id, source);
break;
}
case CACTUS_DEADLOCK_CMD:
case CACTUS_REQ_DEADLOCK_CMD:
{
ffa_vm_id_t deadlock_dest =
- CACTUS_DEADLOCK_GET_NEXT_DEST(ffa_ret);
+ cactus_deadlock_get_next_dest(ffa_ret);
ffa_vm_id_t deadlock_next_dest = source;
if (cactus_cmd == CACTUS_DEADLOCK_CMD) {
@@ -237,10 +238,10 @@ static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb)
source, deadlock_dest, deadlock_next_dest);
deadlock_next_dest =
- CACTUS_DEADLOCK_GET_NEXT_DEST2(ffa_ret);
+ cactus_deadlock_get_next_dest2(ffa_ret);
}
- ffa_ret = CACTUS_DEADLOCK_SEND_CMD(vm_id, deadlock_dest,
+ ffa_ret = cactus_deadlock_send_cmd(vm_id, deadlock_dest,
deadlock_next_dest);
/*
@@ -258,7 +259,8 @@ static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb)
*/
bool is_returning_from_deadlock =
(ffa_ret.ret0 == FFA_MSG_SEND_DIRECT_RESP_SMC32)
- && (CACTUS_IS_SUCCESS_RESP(ffa_ret));
+ &&
+ (cactus_get_response(ffa_ret) == CACTUS_SUCCESS);
if (is_deadlock_detected) {
NOTICE("Attempting dealock but got error %lx\n",
@@ -272,14 +274,13 @@ static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb)
* created the deadlock. As such, reply back
* to the partitions.
*/
- ffa_ret = CACTUS_SUCCESS_RESP(vm_id, source);
+ ffa_ret = cactus_success_resp(vm_id, source);
break;
}
/* Shouldn't get to this point */
ERROR("Deadlock test went wrong!\n");
- ffa_ret = CACTUS_ERROR_RESP(vm_id, source);
-
+ ffa_ret = cactus_error_resp(vm_id, source);
break;
}
default:
diff --git a/spm/cactus/cactus_test_cmds.h b/spm/cactus/cactus_test_cmds.h
index 7555b8b2..0db523e6 100644
--- a/spm/cactus/cactus_test_cmds.h
+++ b/spm/cactus/cactus_test_cmds.h
@@ -19,15 +19,22 @@
/**
* Get command from struct smc_ret_values.
*/
-#define CACTUS_GET_CMD(smc_ret) smc_ret.ret3
+static inline uint64_t cactus_get_cmd(smc_ret_values ret)
+{
+ return (uint64_t)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)
+static inline smc_ret_values cactus_send_cmd(
+ ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t cmd, uint64_t val0,
+ uint64_t val1, uint64_t val2, uint64_t val3)
+{
+ return 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", \
@@ -42,11 +49,17 @@
*/
#define CACTUS_ECHO_CMD U(0x6563686f)
-#define CACTUS_ECHO_SEND_CMD(source, dest, echo_val) \
- CACTUS_SEND_CMD(source, dest, CACTUS_ECHO_CMD, echo_val,\
- 0, 0, 0)
+static inline smc_ret_values cactus_echo_send_cmd(
+ ffa_vm_id_t source, ffa_vm_id_t dest, uint64_t echo_val)
+{
+ return cactus_send_cmd(source, dest, CACTUS_ECHO_CMD, echo_val, 0, 0,
+ 0);
+}
-#define CACTUS_ECHO_GET_VAL(smc_ret) smc_ret.ret4
+static inline uint64_t cactus_echo_get_val(smc_ret_values ret)
+{
+ return (uint64_t)ret.ret4;
+}
/**
* Command to request a cactus secure partition to send an echo command to
@@ -57,11 +70,18 @@
*/
#define CACTUS_REQ_ECHO_CMD (CACTUS_ECHO_CMD + 1)
-#define CACTUS_REQ_ECHO_SEND_CMD(source, dest, echo_dest, echo_val) \
- CACTUS_SEND_CMD(source, dest, CACTUS_REQ_ECHO_CMD, echo_val, \
- echo_dest, 0, 0)
+static inline smc_ret_values cactus_req_echo_send_cmd(
+ ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t echo_dest,
+ uint64_t echo_val)
+{
+ return cactus_send_cmd(source, dest, CACTUS_REQ_ECHO_CMD, echo_val,
+ echo_dest, 0, 0);
+}
-#define CACTUS_REQ_ECHO_GET_ECHO_DEST(smc_ret) smc_ret.ret5
+static inline ffa_vm_id_t cactus_req_echo_get_echo_dest(smc_ret_values ret)
+{
+ return (ffa_vm_id_t)ret.ret5;
+}
/**
* Command to create a cyclic dependency between SPs, which could result in
@@ -74,11 +94,17 @@
*/
#define CACTUS_DEADLOCK_CMD U(0x64656164)
-#define CACTUS_DEADLOCK_SEND_CMD(source, dest, next_dest) \
- CACTUS_SEND_CMD(source, dest, CACTUS_DEADLOCK_CMD, next_dest, \
- 0, 0, 0)
+static inline smc_ret_values cactus_deadlock_send_cmd(
+ ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest)
+{
+ return cactus_send_cmd(source, dest, CACTUS_DEADLOCK_CMD, next_dest, 0,
+ 0, 0);
+}
-#define CACTUS_DEADLOCK_GET_NEXT_DEST(smc_ret) smc_ret.ret4
+static inline ffa_vm_id_t cactus_deadlock_get_next_dest(smc_ret_values ret)
+{
+ return (ffa_vm_id_t)ret.ret4;
+}
/**
* Command to request a sequence CACTUS_DEADLOCK_CMD between the partitions
@@ -86,12 +112,19 @@
*/
#define CACTUS_REQ_DEADLOCK_CMD (CACTUS_DEADLOCK_CMD + 1)
-#define CACTUS_REQ_DEADLOCK_SEND_CMD(source, dest, next_dest1, next_dest2) \
- CACTUS_SEND_CMD(source, dest, CACTUS_REQ_DEADLOCK_CMD, \
- next_dest1, next_dest2, 0, 0)
+static inline smc_ret_values cactus_req_deadlock_send_cmd(
+ ffa_vm_id_t source, ffa_vm_id_t dest, ffa_vm_id_t next_dest1,
+ ffa_vm_id_t next_dest2)
+{
+ return cactus_send_cmd(source, dest, CACTUS_REQ_DEADLOCK_CMD,
+ next_dest1, next_dest2, 0, 0);
+}
-/*To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST*/
-#define CACTUS_DEADLOCK_GET_NEXT_DEST2(smc_ret) smc_ret.ret5
+/* To get next_dest1 use CACTUS_DEADLOCK_GET_NEXT_DEST */
+static inline ffa_vm_id_t cactus_deadlock_get_next_dest2(smc_ret_values ret)
+{
+ return (ffa_vm_id_t)ret.ret5;
+}
/**
* Command to notify cactus of a memory management operation. The cmd value
@@ -101,13 +134,18 @@
*/
#define CACTUS_MEM_SEND_CMD U(0x6d656d)
-#define CACTUS_MEM_SEND_CMD_SEND(source, dest, mem_func, handle) \
- CACTUS_SEND_CMD(source, dest, CACTUS_MEM_SEND_CMD, \
- mem_func, handle, 0, 0)
+static inline smc_ret_values cactus_mem_send_cmd(
+ ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func,
+ ffa_memory_handle_t handle)
+{
+ return cactus_send_cmd(source, dest, CACTUS_MEM_SEND_CMD, mem_func,
+ handle, 0, 0);
+}
-#define CACTUS_MEM_SEND_GET_FUNC(smc_ret) smc_ret.ret4
-
-#define CACTUS_MEM_SEND_GET_HANDLE(smc_ret) smc_ret.ret5
+static inline ffa_memory_handle_t cactus_mem_send_get_handle(smc_ret_values ret)
+{
+ return (ffa_memory_handle_t)ret.ret5;
+}
/**
* Command to request a memory management operation. The 'mem_func' argument
@@ -118,31 +156,48 @@
*/
#define CACTUS_REQ_MEM_SEND_CMD U(0x6d656d6f7279)
-#define CACTUS_REQ_MEM_SEND_SEND_CMD(source, dest, mem_func, receiver) \
- CACTUS_SEND_CMD(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func, \
- receiver, 0, 0)
+static inline smc_ret_values cactus_req_mem_send_send_cmd(
+ ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t mem_func,
+ ffa_vm_id_t receiver)
+{
+ return cactus_send_cmd(source, dest, CACTUS_REQ_MEM_SEND_CMD, mem_func,
+ receiver, 0, 0);
+}
+
+static inline uint32_t cactus_req_mem_send_get_mem_func(smc_ret_values ret)
+{
+ return (uint32_t)ret.ret4;
+}
-#define CACTUS_REQ_MEM_SEND_GET_MEM_FUNC(smc_ret) smc_ret.ret4
-#define CACTUS_REQ_MEM_SEND_GET_RECEIVER(smc_ret) smc_ret.ret5
+static inline ffa_vm_id_t cactus_req_mem_send_get_receiver(smc_ret_values ret)
+{
+ return (ffa_vm_id_t)ret.ret5;
+}
/**
* 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
-
-#define CACTUS_IS_SUCCESS_RESP(smc_ret) \
- (CACTUS_GET_RESPONSE(smc_ret) == CACTUS_SUCCESS)
-
-#define CACTUS_IS_ERROR_RESP(smc_ret) \
- (CACTUS_GET_RESPONSE(smc_ret) == CACTUS_ERROR)
+static inline smc_ret_values cactus_response(
+ ffa_vm_id_t source, ffa_vm_id_t dest, uint32_t response)
+{
+ return ffa_msg_send_direct_resp(source, dest, response);
+}
+
+static inline smc_ret_values cactus_success_resp(
+ ffa_vm_id_t source, ffa_vm_id_t dest)
+{
+ return cactus_response(source, dest, CACTUS_SUCCESS);
+}
+
+static inline smc_ret_values cactus_error_resp(
+ ffa_vm_id_t source, ffa_vm_id_t dest)
+{
+ return cactus_response(source, dest, CACTUS_ERROR);
+}
+
+static inline uint32_t cactus_get_response(smc_ret_values ret)
+{
+ return (uint32_t)ret.ret3;
+}
#endif
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c b/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c
index aeeb19b1..36bc3e73 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c
@@ -103,7 +103,7 @@ static test_result_t send_cactus_req_echo_cmd(ffa_vm_id_t sender,
{
smc_ret_values ret;
- ret = CACTUS_REQ_ECHO_SEND_CMD(sender, dest, echo_dest, value);
+ ret = cactus_req_echo_send_cmd(sender, dest, echo_dest, value);
if (ret.ret0 != FFA_MSG_SEND_DIRECT_RESP_SMC32) {
ERROR("Failed to send message. error: %lx\n",
@@ -111,7 +111,7 @@ static test_result_t send_cactus_req_echo_cmd(ffa_vm_id_t sender,
return TEST_RESULT_FAIL;
}
- if (CACTUS_GET_RESPONSE(ret) == CACTUS_ERROR) {
+ if (cactus_get_response(ret) == CACTUS_ERROR) {
return TEST_RESULT_FAIL;
}
@@ -155,8 +155,7 @@ test_result_t test_ffa_sp_to_sp_deadlock(void)
**********************************************************************/
CHECK_HAFNIUM_SPMC_TESTING_SETUP(1, 0, expected_sp_uuids);
- ret = CACTUS_REQ_DEADLOCK_SEND_CMD(HYP_ID, SP_ID(1), SP_ID(2),
- SP_ID(3));
+ ret = cactus_req_deadlock_send_cmd(HYP_ID, SP_ID(1), SP_ID(2), SP_ID(3));
if (ret.ret0 != FFA_MSG_SEND_DIRECT_RESP_SMC32) {
ERROR("Failed to send message. error: %lx\n",
@@ -164,8 +163,7 @@ test_result_t test_ffa_sp_to_sp_deadlock(void)
return TEST_RESULT_FAIL;
}
- if (CACTUS_GET_RESPONSE(ret) == CACTUS_ERROR) {
- ERROR("cactus SP response is CACTUS_ERROR!\n");
+ if (cactus_get_response(ret) == CACTUS_ERROR) {
return TEST_RESULT_FAIL;
}
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c b/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c
index 61f1aaa3..4afe170c 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c
@@ -77,7 +77,7 @@ static test_result_t test_memory_send_sp(uint32_t mem_func)
ptr = (uint32_t *)constituents[0].address;
- ret = CACTUS_MEM_SEND_CMD_SEND(SENDER, RECEIVER, mem_func, handle);
+ ret = cactus_mem_send_cmd(SENDER, RECEIVER, mem_func, handle);
if (ret.ret0 != FFA_MSG_SEND_DIRECT_RESP_SMC32) {
ERROR("Failed to send message. error: %lx\n",
@@ -85,7 +85,7 @@ static test_result_t test_memory_send_sp(uint32_t mem_func)
return TEST_RESULT_FAIL;
}
- if (CACTUS_GET_RESPONSE(ret) != CACTUS_SUCCESS) {
+ if (cactus_get_response(ret) != CACTUS_SUCCESS) {
ERROR("Failed memory send operation!\n");
return TEST_RESULT_FAIL;
}
@@ -141,7 +141,7 @@ static test_result_t test_req_mem_send_sp_to_sp(uint32_t mem_func,
**********************************************************************/
CHECK_HAFNIUM_SPMC_TESTING_SETUP(1, 0, expected_sp_uuids);
- ret = CACTUS_REQ_MEM_SEND_SEND_CMD(HYP_ID, sender_sp, mem_func,
+ ret = cactus_req_mem_send_send_cmd(HYP_ID, sender_sp, mem_func,
receiver_sp);
if (ret.ret0 != FFA_MSG_SEND_DIRECT_RESP_SMC32) {
@@ -149,7 +149,7 @@ static test_result_t test_req_mem_send_sp_to_sp(uint32_t mem_func,
return TEST_RESULT_FAIL;
}
- if (CACTUS_IS_ERROR_RESP(ret)) {
+ if (cactus_get_response(ret) == CACTUS_ERROR) {
return TEST_RESULT_FAIL;
}
@@ -164,8 +164,8 @@ test_result_t test_req_mem_share_sp_to_sp(void)
test_result_t test_req_mem_lend_sp_to_sp(void)
{
- return test_req_mem_send_sp_to_sp(FFA_MEM_LEND_SMC32, SP_ID(2),
- SP_ID(1));
+ return test_req_mem_send_sp_to_sp(FFA_MEM_LEND_SMC32, SP_ID(3),
+ SP_ID(2));
}
test_result_t test_req_mem_donate_sp_to_sp(void)