aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/runtime_services/ffa_helpers.h6
-rw-r--r--include/runtime_services/spm_common.h9
-rw-r--r--spm/cactus/cactus_tests/cactus_test_direct_messaging.c2
-rw-r--r--spm/cactus/cactus_tests/cactus_test_memory_sharing.c7
-rw-r--r--tftf/tests/runtime_services/secure_service/ffa_helpers.c2
-rw-r--r--tftf/tests/runtime_services/secure_service/spm_common.c51
-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.c7
-rw-r--r--tftf/tests/runtime_services/secure_service/test_spm_cpu_features.c2
9 files changed, 63 insertions, 33 deletions
diff --git a/include/runtime_services/ffa_helpers.h b/include/runtime_services/ffa_helpers.h
index e2962995..4af051b8 100644
--- a/include/runtime_services/ffa_helpers.h
+++ b/include/runtime_services/ffa_helpers.h
@@ -392,12 +392,6 @@ smc_ret_values ffa_msg_send_direct_resp32(ffa_vm_id_t source_id,
uint32_t arg1, uint32_t arg2,
uint32_t arg3, uint32_t arg4);
-static inline bool is_ffa_direct_response(smc_ret_values ret)
-{
- return (ffa_func_id(ret) == FFA_MSG_SEND_DIRECT_RESP_SMC32) ||
- (ffa_func_id(ret) == FFA_MSG_SEND_DIRECT_RESP_SMC64);
-}
-
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/include/runtime_services/spm_common.h b/include/runtime_services/spm_common.h
index 74a2b274..dbb113ba 100644
--- a/include/runtime_services/spm_common.h
+++ b/include/runtime_services/spm_common.h
@@ -53,11 +53,18 @@ struct mailbox_buffers {
CONFIGURE_MAILBOX(mb_name, buffers_size); \
smc_ret = ffa_rxtx_map( \
(uintptr_t)mb_name.send, \
- (uintptr_t)mb_name.recv, \
+ (uintptr_t)mb_name.recv, \
buffers_size / PAGE_SIZE \
); \
} while (false)
+/**
+ * Helpers to evaluate returns of FF-A calls.
+ */
+bool is_ffa_call_error(smc_ret_values val);
+bool is_ffa_direct_response(smc_ret_values ret);
+bool is_expected_ffa_return(smc_ret_values ret, uint32_t func_id);
+
/*
* Vector length:
* SIMD: 128 bits = 16 bytes
diff --git a/spm/cactus/cactus_tests/cactus_test_direct_messaging.c b/spm/cactus/cactus_tests/cactus_test_direct_messaging.c
index f4c78901..31324b62 100644
--- a/spm/cactus/cactus_tests/cactus_test_direct_messaging.c
+++ b/spm/cactus/cactus_tests/cactus_test_direct_messaging.c
@@ -33,8 +33,6 @@ CACTUS_CMD_HANDLER(req_echo_cmd, CACTUS_REQ_ECHO_CMD)
ffa_ret = cactus_echo_send_cmd(vm_id, echo_dest, echo_val);
if (!is_ffa_direct_response(ffa_ret)) {
- ERROR("Failed to send message. error: %x\n",
- ffa_error_code(ffa_ret));
return cactus_error_resp(vm_id, ffa_dir_msg_source(*args),
CACTUS_ERROR_FFA_CALL);
}
diff --git a/spm/cactus/cactus_tests/cactus_test_memory_sharing.c b/spm/cactus/cactus_tests/cactus_test_memory_sharing.c
index 82cdac39..f7d9235c 100644
--- a/spm/cactus/cactus_tests/cactus_test_memory_sharing.c
+++ b/spm/cactus/cactus_tests/cactus_test_memory_sharing.c
@@ -137,9 +137,6 @@ CACTUS_CMD_HANDLER(req_mem_send_cmd, CACTUS_REQ_MEM_SEND_CMD)
ffa_ret = cactus_mem_send_cmd(vm_id, receiver, mem_func, handle);
if (!is_ffa_direct_response(ffa_ret)) {
- ERROR("Failed to send message. ret: %x error: %x\n",
- ffa_func_id(ffa_ret),
- ffa_error_code(ffa_ret));
return cactus_error_resp(vm_id, source, CACTUS_ERROR_FFA_CALL);
}
@@ -156,9 +153,7 @@ CACTUS_CMD_HANDLER(req_mem_send_cmd, CACTUS_REQ_MEM_SEND_CMD)
* permanently given up access to the memory region.
*/
ffa_ret = ffa_mem_reclaim(handle, 0);
- if (ffa_func_id(ffa_ret) == FFA_ERROR) {
- ERROR("Failed to reclaim memory! error: %x\n",
- ffa_error_code(ffa_ret));
+ if (is_ffa_call_error(ffa_ret)) {
return cactus_error_resp(vm_id, source,
CACTUS_ERROR_TEST);
}
diff --git a/tftf/tests/runtime_services/secure_service/ffa_helpers.c b/tftf/tests/runtime_services/secure_service/ffa_helpers.c
index 41dd94b1..8e7b58c6 100644
--- a/tftf/tests/runtime_services/secure_service/ffa_helpers.c
+++ b/tftf/tests/runtime_services/secure_service/ffa_helpers.c
@@ -3,8 +3,6 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
-
-#include <debug.h>
#include <smccc.h>
#include <ffa_endpoints.h>
diff --git a/tftf/tests/runtime_services/secure_service/spm_common.c b/tftf/tests/runtime_services/secure_service/spm_common.c
index 7e54a3ad..12b70a9a 100644
--- a/tftf/tests/runtime_services/secure_service/spm_common.c
+++ b/tftf/tests/runtime_services/secure_service/spm_common.c
@@ -13,6 +13,52 @@
#define STR(x) __STR(x)
#define SIMD_TWO_VECTORS_BYTES_STR (2 * SIMD_VECTOR_LEN_BYTES)
+/**
+ * Helper to log errors after FF-A calls.
+ */
+bool is_ffa_call_error(smc_ret_values ret)
+{
+ if (ffa_func_id(ret) == FFA_ERROR) {
+ ERROR("FF-A call returned error (%x): %d\n",
+ ffa_func_id(ret), ffa_error_code(ret));
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Helper to verify return of FF-A call is an FFA_MSG_SEND_DIRECT_RESP.
+ * Should be used after FFA_MSG_SEND_DIRECT_REQ, or after sending a test command
+ * to an SP.
+ */
+bool is_ffa_direct_response(smc_ret_values ret)
+{
+ if ((ffa_func_id(ret) == FFA_MSG_SEND_DIRECT_RESP_SMC32) ||
+ (ffa_func_id(ret) == FFA_MSG_SEND_DIRECT_RESP_SMC64)) {
+ return true;
+ }
+
+ ERROR("%x is not FF-A response.\n", ffa_func_id(ret));
+ /* To log error in case it is FFA_ERROR*/
+ is_ffa_call_error(ret);
+
+ return false;
+}
+
+/**
+ * Helper to check the return value of FF-A call is as expected.
+ */
+bool is_expected_ffa_return(smc_ret_values ret, uint32_t func_id)
+{
+ if (ffa_func_id(ret) == func_id) {
+ return true;
+ }
+
+ ERROR("Expecting %x, FF-A return was %x\n", func_id, ffa_func_id(ret));
+
+ return false;
+}
+
void fill_simd_vector_regs(const simd_vector_t v[SIMD_NUM_VECTORS])
{
#ifdef __aarch64__
@@ -275,9 +321,8 @@ ffa_memory_handle_t memory_send(
return FFA_MEMORY_HANDLE_INVALID;
}
- if (ffa_func_id(ret) != FFA_SUCCESS_SMC32) {
- ERROR("Failed to send memory to %x, error: %x.\n",
- receiver, ffa_error_code(ret));
+ if (is_ffa_call_error(ret)) {
+ ERROR("Failed to send message to: %x\n", receiver);
return FFA_MEMORY_HANDLE_INVALID;
}
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 72daae46..83510b06 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
@@ -29,9 +29,11 @@ static test_result_t send_cactus_echo_cmd(ffa_vm_id_t sender,
smc_ret_values ret;
ret = cactus_echo_send_cmd(sender, dest, value);
+ /*
+ * Return responses may be FFA_MSG_SEND_DIRECT_RESP or FFA_INTERRUPT,
+ * but only expect the former. Expect SMC32 convention from SP.
+ */
if (!is_ffa_direct_response(ret)) {
- ERROR("Failed to send message. error: %x\n",
- ffa_error_code(ret));
return TEST_RESULT_FAIL;
}
@@ -95,8 +97,6 @@ static test_result_t send_cactus_req_echo_cmd(ffa_vm_id_t sender,
ret = cactus_req_echo_send_cmd(sender, dest, echo_dest, value);
if (!is_ffa_direct_response(ret)) {
- ERROR("Failed to send message. error: %x\n",
- ffa_error_code(ret));
return TEST_RESULT_FAIL;
}
@@ -147,8 +147,6 @@ test_result_t test_ffa_sp_to_sp_deadlock(void)
ret = cactus_req_deadlock_send_cmd(HYP_ID, SP_ID(1), SP_ID(2), SP_ID(3));
if (!is_ffa_direct_response(ret)) {
- ERROR("Failed to send message. error: %x\n",
- ffa_error_code(ret));
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 61b6edd5..f126c57d 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
@@ -10,6 +10,7 @@
#include <ffa_endpoints.h>
#include <test_helpers.h>
#include <tftf_lib.h>
+#include <spm_common.h>
#include <xlat_tables_defs.h>
#define MAILBOX_SIZE PAGE_SIZE
@@ -80,8 +81,6 @@ static test_result_t test_memory_send_sp(uint32_t mem_func)
ret = cactus_mem_send_cmd(SENDER, RECEIVER, mem_func, handle);
if (!is_ffa_direct_response(ret)) {
- ERROR("Failed to send message. error: %x\n",
- ffa_error_code(ret));
return TEST_RESULT_FAIL;
}
@@ -103,7 +102,7 @@ static test_result_t test_memory_send_sp(uint32_t mem_func)
(void)ptr;
if (mem_func != FFA_MEM_DONATE_SMC32 &&
- ffa_mem_reclaim(handle, 0).ret0 == FFA_ERROR) {
+ is_ffa_call_error(ffa_mem_reclaim(handle, 0))) {
tftf_testcase_printf("Couldn't reclaim memory\n");
return TEST_RESULT_FAIL;
}
@@ -145,8 +144,6 @@ static test_result_t test_req_mem_send_sp_to_sp(uint32_t mem_func,
receiver_sp);
if (!is_ffa_direct_response(ret)) {
- ERROR("Failed to send message. error: %x\n",
- ffa_error_code(ret));
return TEST_RESULT_FAIL;
}
diff --git a/tftf/tests/runtime_services/secure_service/test_spm_cpu_features.c b/tftf/tests/runtime_services/secure_service/test_spm_cpu_features.c
index 8ce4cc3b..f57fa243 100644
--- a/tftf/tests/runtime_services/secure_service/test_spm_cpu_features.c
+++ b/tftf/tests/runtime_services/secure_service/test_spm_cpu_features.c
@@ -56,8 +56,6 @@ test_result_t test_simd_vectors_preserved(void)
smc_ret_values ret = cactus_req_simd_fill_send_cmd(SENDER, RECEIVER);
if (!is_ffa_direct_response(ret)) {
- ERROR("Failed to send message. error: %x\n",
- ffa_error_code(ret));
return TEST_RESULT_FAIL;
}