test(realm): perform LFA of RMM with Realm Payload

Add a test to execute the Realm payload with the existing RMM,
then perform LFA of RMM, and finally execute the Realm payload
again to ensure it runs with the newly activated RMM.

Change-Id: Ifbba462506c6b1c0c86aba1ac22a19cd414f54d9
Signed-off-by: Manish V Badarkhe <Manish.Badarkhe@arm.com>
diff --git a/include/runtime_services/host_realm_managment/host_realm_lfa.h b/include/runtime_services/host_realm_managment/host_realm_lfa.h
new file mode 100644
index 0000000..868b004
--- /dev/null
+++ b/include/runtime_services/host_realm_managment/host_realm_lfa.h
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2025, Arm Limited. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef HOST_REALM_LFA_H
+#define HOST_REALM_LFA_H
+
+test_result_t test_lfa_activate_rmm(void);
+test_result_t test_lfa_version(void);
+
+#endif /* HOST_REALM_LFA_H */
diff --git a/tftf/tests/runtime_services/realm_payload/host_realm_lfa.c b/tftf/tests/runtime_services/realm_payload/host_realm_lfa.c
new file mode 100644
index 0000000..0da1be9
--- /dev/null
+++ b/tftf/tests/runtime_services/realm_payload/host_realm_lfa.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2025, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include <arch_features.h>
+#include <debug.h>
+#include <host_realm_helper.h>
+#include <host_realm_lfa.h>
+#include <host_realm_mem_layout.h>
+#include <host_shared_data.h>
+#include <test_helpers.h>
+
+test_result_t host_test_realm_rsi_version_with_lfa(void)
+{
+	test_result_t lfa_ret;
+	u_register_t rec_flag[] = {RMI_RUNNABLE};
+	struct realm realm;
+	u_register_t feature_flag0 = 0U;
+	long sl = RTT_MIN_LEVEL;
+	bool ret1, ret2;
+
+	SKIP_TEST_IF_RME_NOT_SUPPORTED_OR_RMM_IS_TRP();
+
+	lfa_ret = test_lfa_version();
+	if (lfa_ret != TEST_RESULT_SUCCESS) {
+		ERROR("%s(): LFA is not supported=%d\n", __func__, lfa_ret);
+		return TEST_RESULT_SKIPPED;
+	}
+
+	if (is_feat_52b_on_4k_2_supported()) {
+		feature_flag0 = RMI_FEATURE_REGISTER_0_LPA2;
+		sl = RTT_MIN_LEVEL_LPA2;
+	}
+
+	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
+				feature_flag0, 0U, sl, rec_flag, 1U, 0U, get_test_mecid())) {
+		return TEST_RESULT_FAIL;
+	}
+
+	ret1 = host_enter_realm_execute(&realm, REALM_GET_RSI_VERSION, RMI_EXIT_HOST_CALL, 0U);
+	if (!ret1) {
+		ERROR("%s(): Initial enter failed\n", __func__);
+		goto cleanup;
+	}
+
+	/* Activate new RMM and then request RSI version again */
+	lfa_ret = test_lfa_activate_rmm();
+	if (lfa_ret != TEST_RESULT_SUCCESS) {
+		ERROR("%s(): LFA of RMM failed=%d\n", __func__, lfa_ret);
+		goto cleanup;
+	}
+
+	ret1 = host_enter_realm_execute(&realm, REALM_GET_RSI_VERSION, RMI_EXIT_HOST_CALL, 0U);
+	if (!ret1) {
+		ERROR("%s(): Enter Realm with newly activated RMM failed\n", __func__);
+	}
+
+cleanup:
+	ret2 = host_destroy_realm(&realm);
+	if (!ret2) {
+		ERROR("%s(): Realm destroy failed\n", __func__);
+	}
+
+	return (ret1 && ret2) ? host_cmp_result() : TEST_RESULT_FAIL;
+}
diff --git a/tftf/tests/tests-realm-payload.mk b/tftf/tests/tests-realm-payload.mk
index b5e245b..7e4ac6c 100644
--- a/tftf/tests/tests-realm-payload.mk
+++ b/tftf/tests/tests-realm-payload.mk
@@ -19,6 +19,7 @@
 		host_realm_mpam_tests.c					\
 		host_realm_brbe_tests.c					\
 		host_realm_mec_tests.c					\
+		host_realm_lfa.c					\
 	)
 
 TESTS_SOURCES	+=							\
@@ -66,7 +67,14 @@
 		pcie_dvsec_rmeda.c	\
 	)
 
+TESTS_SOURCES	+=		\
+	$(addprefix tftf/tests/runtime_services/lfa/,	\
+		test_lfa_single_cpu.c \
+		test_lfa_multi_cpu.c \
+	)
+
 ifeq (${ENABLE_REALM_PAYLOAD_TESTS},1)
 include lib/ext_mbedtls/mbedtls.mk
 endif
+
 endif
diff --git a/tftf/tests/tests-realm-payload.xml b/tftf/tests/tests-realm-payload.xml
index ee3f846..8ac98a1 100644
--- a/tftf/tests/tests-realm-payload.xml
+++ b/tftf/tests/tests-realm-payload.xml
@@ -184,5 +184,8 @@
 	  <!-- Invoke DA workflow on PCIe off-chip device -->
 	  <testcase name="DA workflow on all PCIe off-chip devices"
 	  function="host_da_workflow_on_all_offchip_devices" />
+	  <!-- Test case for LFA with Realm Payload -->
+	  <testcase name="Test Live Firmware Activation of RMM with Realm Payload"
+	  function="host_test_realm_rsi_version_with_lfa" />
   </testsuite>
 </testsuites>