summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ-Alves <joao.alves@arm.com>2021-10-27 15:15:16 +0100
committerJ-Alves <joao.alves@arm.com>2021-11-10 11:26:13 +0000
commit79c08f110715360288554e93b6c994c02090a06b (patch)
tree79d4c400ee827c3e6bfc91a8ae512af48fe8fbda
parentbd909ac2ae1c2df76f0696702e583d416b4f4141 (diff)
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
-rw-r--r--include/common/test_helpers.h6
-rw-r--r--include/plat/common/platform.h9
-rw-r--r--include/runtime_services/spm_common.h5
-rw-r--r--spm/cactus/cactus_tests/cactus_test_notifications.c1
-rw-r--r--tftf/tests/common/test_helpers.c20
-rw-r--r--tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c3
-rw-r--r--tftf/tests/runtime_services/secure_service/test_ffa_notifications.c25
-rw-r--r--tftf/tests/runtime_services/secure_service/test_spci_blocking_request.c3
8 files changed, 46 insertions, 26 deletions
diff --git a/include/common/test_helpers.h b/include/common/test_helpers.h
index 8220244..0881f00 100644
--- a/include/common/test_helpers.h
+++ b/include/common/test_helpers.h
@@ -353,6 +353,12 @@ test_result_t spm_run_multi_core_test(uintptr_t cpu_on_handler,
event_t *cpu_booted);
/**
+ * Call FFA_RUN in the designated SP to make it reach the message loop.
+ * Used within CPU_ON handlers, to bring up the SP in the current core.
+ */
+bool spm_core_sp_init(ffa_id_t sp_id);
+
+/**
* Enable/Disable managed exit interrupt for the provided SP.
*/
bool spm_set_managed_exit_int(ffa_id_t sp_id, bool enable);
diff --git a/include/plat/common/platform.h b/include/plat/common/platform.h
index f3536ba..c8b785c 100644
--- a/include/plat/common/platform.h
+++ b/include/plat/common/platform.h
@@ -8,6 +8,7 @@
#define __PLATFORM_H__
#include <stdint.h>
+#include <arch_helpers.h>
#include <timer.h>
#include <xlat_tables_v2.h>
@@ -184,4 +185,12 @@ int plat_get_image_source(unsigned int image_id,
void plat_fwu_io_setup(void);
+/**
+ * Returns current executing core.
+ */
+static inline uint32_t get_current_core_id(void)
+{
+ return platform_get_core_pos(read_mpidr_el1() & MPID_MASK);
+}
+
#endif /* __PLATFORM_H__ */
diff --git a/include/runtime_services/spm_common.h b/include/runtime_services/spm_common.h
index 2393dc6..f4b5a75 100644
--- a/include/runtime_services/spm_common.h
+++ b/include/runtime_services/spm_common.h
@@ -7,10 +7,13 @@
#ifndef SPM_COMMON_H
#define SPM_COMMON_H
-#include <ffa_helpers.h>
+#include <plat/common/platform.h>
+
#include <stdint.h>
#include <string.h>
+#include <ffa_helpers.h>
+
/* Hypervisor ID at physical FFA instance */
#define HYP_ID (0)
/* SPMC ID */
diff --git a/spm/cactus/cactus_tests/cactus_test_notifications.c b/spm/cactus/cactus_tests/cactus_test_notifications.c
index 52c226b..57375e7 100644
--- a/spm/cactus/cactus_tests/cactus_test_notifications.c
+++ b/spm/cactus/cactus_tests/cactus_test_notifications.c
@@ -9,7 +9,6 @@
#include "cactus_tests.h"
#include <ffa_helpers.h>
#include <debug.h>
-#include <platform.h>
/* Booleans to keep track of which CPUs handled NPI. */
static bool npi_handled[PLATFORM_CORE_COUNT];
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 @@ test_result_t spm_run_multi_core_test(uintptr_t cpu_on_handler,
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 @@ test_result_t test_ffa_sp_to_sp_deadlock(void)
*/
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 @@ test_result_t test_ffa_notifications_info_get_none(void)
*/
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 @@ static test_result_t request_notification_get_per_vcpu_on_handler(void)
* 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 @@ test_result_t test_ffa_notifications_sp_signals_sp_per_vcpu(void)
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 @@ static test_result_t test_spci_blocking_multicore_fn(void)
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]);