test(realm): add testcase to enter all planes
Testcase creates realm with all 4 planes.
Enters all planes.
Signed-off-by: Shruti Gupta <shruti.gupta@arm.com>
Change-Id: I7a3b9103e1fbcfe98117c02827624a2fc2d24fc2
diff --git a/include/runtime_services/host_realm_managment/host_realm_helper.h b/include/runtime_services/host_realm_managment/host_realm_helper.h
index be2617e..6ea9b72 100644
--- a/include/runtime_services/host_realm_managment/host_realm_helper.h
+++ b/include/runtime_services/host_realm_managment/host_realm_helper.h
@@ -53,4 +53,10 @@
void realm_print_handler(struct realm *realm_ptr, unsigned int plane_num, unsigned int rec_num);
bool host_ipa_is_ns(u_register_t addr, u_register_t rmm_feat_reg0);
+/*
+ * This functions sets the shared data args needed for entering aux plane,
+ * using REALM_ENTER_PLANE_N_CMD
+ */
+void host_realm_set_aux_plane_args(struct realm *realm_ptr, unsigned int plane_num);
+
#endif /* HOST_REALM_HELPER_H */
diff --git a/include/runtime_services/host_realm_managment/host_shared_data.h b/include/runtime_services/host_realm_managment/host_shared_data.h
index 5f58887..05d22da 100644
--- a/include/runtime_services/host_realm_managment/host_shared_data.h
+++ b/include/runtime_services/host_realm_managment/host_shared_data.h
@@ -74,7 +74,8 @@
REALM_SME_UNDEF_ABORT,
REALM_FEAT_DOUBLEFAULT2_TEST,
REALM_ATTESTATION,
- REALM_ATTESTATION_FAULT
+ REALM_ATTESTATION_FAULT,
+ REALM_ENTER_PLANE_N_CMD
};
/*
@@ -83,7 +84,8 @@
enum host_param_index {
HOST_CMD_INDEX = 0U,
HOST_ARG1_INDEX,
- HOST_ARG2_INDEX
+ HOST_ARG2_INDEX,
+ HOST_ARG3_INDEX
};
enum host_call_cmd {
diff --git a/realm/realm_payload_main.c b/realm/realm_payload_main.c
index 2556c11..4ad1b6c 100644
--- a/realm/realm_payload_main.c
+++ b/realm/realm_payload_main.c
@@ -24,6 +24,7 @@
static fpu_state_t rl_fpu_state_write;
static fpu_state_t rl_fpu_state_read;
+static rsi_plane_run run __aligned(PAGE_SIZE);
/*
* This function reads sleep time in ms from shared buffer and spins PE
@@ -44,6 +45,18 @@
}
}
+static bool test_realm_enter_plane_n(void)
+{
+ u_register_t base, plane_index, perm_index, flags = 0U;
+
+ plane_index = realm_shared_data_get_my_host_val(HOST_ARG1_INDEX);
+ base = realm_shared_data_get_my_host_val(HOST_ARG2_INDEX);
+ perm_index = plane_index + 1U;
+
+ realm_printf("Entering plane %ld, ep=0x%lx run=0x%lx\n", plane_index, base, &run);
+ return realm_plane_enter(plane_index, perm_index, base, flags, &run);
+}
+
/*
* This function requests RSI/ABI version from RMM.
*/
@@ -284,6 +297,9 @@
realm_loop_cmd();
test_succeed = true;
break;
+ case REALM_ENTER_PLANE_N_CMD:
+ test_succeed = test_realm_enter_plane_n();
+ break;
case REALM_MULTIPLE_REC_PSCI_DENIED_CMD:
test_succeed = test_realm_multiple_rec_psci_denied_cmd();
break;
diff --git a/tftf/tests/runtime_services/host_realm_managment/host_realm_helper.c b/tftf/tests/runtime_services/host_realm_managment/host_realm_helper.c
index 553bda1..c1edd79 100644
--- a/tftf/tests/runtime_services/host_realm_managment/host_realm_helper.c
+++ b/tftf/tests/runtime_services/host_realm_managment/host_realm_helper.c
@@ -485,3 +485,19 @@
tftf_send_sgi(sgi, core_pos);
}
}
+
+/*
+ * Set Args for Aux Plane Enter
+ * Realm helpers copy the same realm image for each plane
+ * Entrypoint for aux plane = realm.par_base + (plane_num * realm..par_size)
+ */
+void host_realm_set_aux_plane_args(struct realm *realm_ptr,
+ unsigned int plane_num)
+{
+ /* Plane Index */
+ host_shared_data_set_host_val(realm_ptr, PRIMARY_PLANE_ID, 0U, HOST_ARG1_INDEX, plane_num);
+
+ /* Plane entrypoint */
+ host_shared_data_set_host_val(realm_ptr, PRIMARY_PLANE_ID, 0U, HOST_ARG2_INDEX,
+ realm_ptr->par_base + (plane_num * realm_ptr->par_size));
+}
diff --git a/tftf/tests/runtime_services/host_realm_managment/host_realm_rmi.c b/tftf/tests/runtime_services/host_realm_managment/host_realm_rmi.c
index 62b360a..27b03e8 100644
--- a/tftf/tests/runtime_services/host_realm_managment/host_realm_rmi.c
+++ b/tftf/tests/runtime_services/host_realm_managment/host_realm_rmi.c
@@ -1082,6 +1082,9 @@
* Allocate memory for PAR - Realm image for each Plane.
* Granule delegation
* of PAR will be performed during rtt creation.
+ * realm->par_size is size if single Plane image.
+ * Same image is copied for each plane.
+ * Offset for Plane N will be realm->par_base + (N*realm->par_size)
*/
realm->par_base = (u_register_t)page_alloc((realm->par_size) *
(realm->num_aux_planes + 1U));
diff --git a/tftf/tests/runtime_services/realm_payload/host_realm_payload_tests.c b/tftf/tests/runtime_services/realm_payload/host_realm_payload_tests.c
index 632bad8..f1ea9ef 100644
--- a/tftf/tests/runtime_services/realm_payload/host_realm_payload_tests.c
+++ b/tftf/tests/runtime_services/realm_payload/host_realm_payload_tests.c
@@ -21,7 +21,7 @@
#include <host_realm_pmu.h>
#include <host_shared_data.h>
-#define SLEEP_TIME_MS 20U
+#define SLEEP_TIME_MS 2U
extern const char *rmi_exit[];
@@ -32,6 +32,91 @@
static uint128_t pauth_keys_after[NUM_KEYS];
#endif
+bool are_planes_supported(void)
+{
+ u_register_t feature_flag;
+
+ /* Read Realm Feature Reg 0 */
+ if (host_rmi_features(0UL, &feature_flag) != REALM_SUCCESS) {
+ ERROR("%s() failed\n", "host_rmi_features");
+ return false;
+ }
+
+ if (EXTRACT(RMI_FEATURE_REGISTER_0_MAX_NUM_AUX_PLANES, feature_flag) > 0UL) {
+ return true;
+ }
+
+ return false;
+}
+
+/*
+ * @Test_Aim@ Test realm payload creation with 3 Aux Planes, enter all Planes
+ * Host cannot enter Aux Planes directly,
+ * Host will enter P0, P0 will enter aux plane
+ */
+test_result_t host_test_realm_create_planes_enter(void)
+{
+ bool ret1, ret2;
+ u_register_t rec_flag[MAX_REC_COUNT];
+ struct realm realm;
+ u_register_t feature_flag = 0UL;
+ long sl = RTT_MIN_LEVEL;
+ struct rmi_rec_run *run;
+
+ SKIP_TEST_IF_RME_NOT_SUPPORTED_OR_RMM_IS_TRP();
+
+ if (!are_planes_supported()) {
+ return TEST_RESULT_SKIPPED;
+ }
+
+ if (is_feat_52b_on_4k_2_supported() == true) {
+ feature_flag = RMI_FEATURE_REGISTER_0_LPA2;
+ sl = RTT_MIN_LEVEL_LPA2;
+ }
+
+ for (unsigned int i = 0U; i < MAX_REC_COUNT; i++) {
+ rec_flag[i] = RMI_RUNNABLE;
+ }
+
+ if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
+ feature_flag, sl, rec_flag, 1U, MAX_AUX_PLANE_COUNT)) {
+ return TEST_RESULT_FAIL;
+ }
+
+ /* CMD for Plane N */
+ for (unsigned int j = 1U; j <= MAX_AUX_PLANE_COUNT; j++) {
+ host_shared_data_set_realm_cmd(&realm, REALM_SLEEP_CMD, j, 0U);
+ host_shared_data_set_host_val(&realm, j, 0U,
+ HOST_ARG1_INDEX, SLEEP_TIME_MS);
+ }
+
+ for (unsigned int j = 1U; j <= MAX_AUX_PLANE_COUNT; j++) {
+ run = (struct rmi_rec_run *)realm.run[0U];
+
+ host_realm_set_aux_plane_args(&realm, j);
+ ret1 = host_enter_realm_execute(&realm, REALM_ENTER_PLANE_N_CMD,
+ RMI_EXIT_HOST_CALL, 0U);
+
+
+ if (run->exit.exit_reason != RMI_EXIT_HOST_CALL) {
+ ERROR("Rec0 error exit=0x%lx ret1=%d HPFAR=0x%lx \
+ esr=0x%lx far=0x%lx\n",
+ run->exit.exit_reason, ret1,
+ run->exit.hpfar,
+ run->exit.esr, run->exit.far);
+ }
+ }
+ ret2 = host_destroy_realm(&realm);
+
+ if (!ret1 || !ret2) {
+ ERROR("%s(): enter=%d destroy=%d\n",
+ __func__, ret1, ret2);
+ return TEST_RESULT_FAIL;
+ }
+
+ return host_cmp_result();
+}
+
/*
* @Test_Aim@ Test realm payload creation, execution and destruction iteratively
*/
diff --git a/tftf/tests/tests-realm-payload.xml b/tftf/tests/tests-realm-payload.xml
index da88701..ea0d27c 100644
--- a/tftf/tests/tests-realm-payload.xml
+++ b/tftf/tests/tests-realm-payload.xml
@@ -8,6 +8,8 @@
<testsuites>
<testsuite name="Realm payload at EL1" description="Test Realm EL1 framework capabilities" >
+ <testcase name="Realm Planes execution test"
+ function="host_test_realm_create_planes_enter" />
<testcase name="Realm EL1 creation and execution test"
function="host_test_realm_create_enter" />
<testcase name="Realm RTT fold unfold test Unassigned Empty"