feat: spm helper functions for MP tests
Added two helper functions to help with SPM tests in a MP setup.
- spm_core_sp_init: to initialize an SP in a given core.
- get_current_core_id: to get the current core ID.
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: Iad10d43f258f5ed05ce52b87c94a9333c228f26d
diff --git a/tftf/tests/common/test_helpers.c b/tftf/tests/common/test_helpers.c
index 73d59bd..b7eeb15 100644
--- a/tftf/tests/common/test_helpers.c
+++ b/tftf/tests/common/test_helpers.c
@@ -221,6 +221,26 @@
return TEST_RESULT_SUCCESS;
}
+bool spm_core_sp_init(ffa_id_t sp_id)
+{
+ /*
+ * Secure Partitions secondary ECs need one round of ffa_run to reach
+ * the message loop.
+ */
+ if (sp_id != SP_ID(1)) {
+ uint32_t core_pos = get_current_core_id();
+ smc_ret_values ret = ffa_run(sp_id, core_pos);
+
+ if (ffa_func_id(ret) != FFA_MSG_WAIT) {
+ ERROR("Failed to run SP%x on core %u\n",
+ sp_id, core_pos);
+ return false;
+ }
+ }
+
+ return true;
+}
+
bool spm_set_managed_exit_int(ffa_id_t sp_id, bool enable)
{
smc_ret_values ret;
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 fb76362..2fd8831 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
@@ -167,8 +167,7 @@
*/
static test_result_t cpu_on_handler(void)
{
- unsigned int mpid = read_mpidr_el1() & MPID_MASK;
- unsigned int core_pos = platform_get_core_pos(mpid);
+ unsigned int core_pos = get_current_core_id();
test_result_t ret = TEST_RESULT_SUCCESS;
smc_ret_values ffa_ret;
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_notifications.c b/tftf/tests/runtime_services/secure_service/test_ffa_notifications.c
index 1f3c172..89841aa 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_notifications.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_notifications.c
@@ -910,9 +910,7 @@
*/
static test_result_t request_notification_get_per_vcpu_on_handler(void)
{
- unsigned int mpid = read_mpidr_el1() & MPID_MASK;
- unsigned int core_pos = platform_get_core_pos(mpid);
- smc_ret_values ret;
+ unsigned int core_pos = get_current_core_id();
test_result_t result = TEST_RESULT_FAIL;
uint64_t exp_from_vm = 0;
@@ -931,14 +929,8 @@
* Secure Partitions secondary ECs need one round of ffa_run to reach
* the message loop.
*/
- if (per_vcpu_receiver != SP_ID(1)) {
- ret = ffa_run(per_vcpu_receiver, core_pos);
-
- if (ffa_func_id(ret) != FFA_MSG_WAIT) {
- ERROR("Failed to run SP%x on core %u\n",
- per_vcpu_receiver, core_pos);
- goto out;
- }
+ if (!spm_core_sp_init(per_vcpu_receiver)) {
+ goto out;
}
/* Request to get notifications sent to the respective vCPU. */
@@ -1077,20 +1069,13 @@
static test_result_t notification_get_per_vcpu_on_handler(void)
{
- unsigned int mpid = read_mpidr_el1() & MPID_MASK;
- unsigned int core_pos = platform_get_core_pos(mpid);
- smc_ret_values ret;
+ unsigned int core_pos = get_current_core_id();
test_result_t result = TEST_RESULT_SUCCESS;
VERBOSE("Getting per-vCPU notifications from %x, core: %u.\n",
per_vcpu_receiver, core_pos);
- ret = ffa_run(per_vcpu_sender, core_pos);
-
- if (ffa_func_id(ret) != FFA_MSG_WAIT) {
- ERROR("Failed to run SP%x on core %u\n",
- per_vcpu_sender, core_pos);
- result = TEST_RESULT_FAIL;
+ if (!spm_core_sp_init(per_vcpu_sender)) {
goto out;
}
diff --git a/tftf/tests/runtime_services/secure_service/test_spci_blocking_request.c b/tftf/tests/runtime_services/secure_service/test_spci_blocking_request.c
index 6d24842..d2aa20b 100644
--- a/tftf/tests/runtime_services/secure_service/test_spci_blocking_request.c
+++ b/tftf/tests/runtime_services/secure_service/test_spci_blocking_request.c
@@ -29,8 +29,7 @@
u_register_t rx1, rx2, rx3;
test_result_t result = TEST_RESULT_SUCCESS;
- u_register_t cpu_mpid = read_mpidr_el1() & MPID_MASK;
- unsigned int core_pos = platform_get_core_pos(cpu_mpid);
+ unsigned int core_pos = get_current_core_id();
tftf_send_event(&cpu_has_entered_test[core_pos]);