feat(realm): assign MECID when creating realms

This change allows TFTF to assign a MECID to every realm that is
created by passing an extra parameter to the Realm creation helpers.

Signed-off-by: Juan Pablo Conde <juanpablo.conde@arm.com>
Change-Id: I89bf08011eb005d949a195b406b073955f23f5ad
diff --git a/include/common/test_helpers.h b/include/common/test_helpers.h
index 6482d6d..6a4b412 100644
--- a/include/common/test_helpers.h
+++ b/include/common/test_helpers.h
@@ -17,6 +17,9 @@
 #include <uuid_utils.h>
 #include <uuid.h>
 
+#define TEST_MECID1	(unsigned short)1
+#define TEST_MECID2	(unsigned short)2
+
 typedef struct {
 	uintptr_t addr;
 	size_t size;
diff --git a/include/lib/aarch64/arch.h b/include/lib/aarch64/arch.h
index 2a9d0d2..f460016 100644
--- a/include/lib/aarch64/arch.h
+++ b/include/lib/aarch64/arch.h
@@ -483,6 +483,11 @@
 #define ID_AA64MMFR3_EL1_TCRX_WIDTH		U(4)
 #define ID_AA64MMFR3_EL1_TCR2_SUPPORTED		ULL(0x1)
 
+#define ID_AA64MMFR3_EL1_MEC_SHIFT              U(28)
+#define ID_AA64MMFR3_EL1_MEC_MASK               ULL(0xf)
+#define ID_AA64MMFR3_EL1_MEC_WIDTH		U(4)
+#define ID_AA64MMFR3_EL1_MEC_SUPPORTED		ULL(0x1)
+
 /* ID_AA64PFR1_EL1 definitions */
 #define ID_AA64PFR1_EL1_DF2_SHIFT		U(56)
 #define ID_AA64PFR1_EL1_DF2_WIDTH		U(4)
@@ -1825,4 +1830,10 @@
 /* RNDRRS definition */
 #define RNDRRS			S3_3_C2_C4_1
 
+/* MEC Registers */
+#define MECIDR_EL2				S3_4_C10_C8_7
+
+#define MECIDR_EL2_MECIDWidthm1_SHIFT		U(0)
+#define MECIDR_EL2_MECIDWidthm1_WIDTH		U(4)
+
 #endif /* ARCH_H */
diff --git a/include/lib/aarch64/arch_features.h b/include/lib/aarch64/arch_features.h
index 3b4fffc..fc004b3 100644
--- a/include/lib/aarch64/arch_features.h
+++ b/include/lib/aarch64/arch_features.h
@@ -583,4 +583,10 @@
 	return EXTRACT(ID_AA64DFR0_DOUBLELOCK, read_id_aa64dfr0_el1())
 			>= DOUBLELOCK_IMPLEMENTED;
 }
+
+static inline bool is_feat_mec_supported(void)
+{
+	return EXTRACT(ID_AA64MMFR3_EL1_MEC, read_id_aa64mmfr3_el1())
+		== ID_AA64MMFR3_EL1_MEC_SUPPORTED;
+}
 #endif /* ARCH_FEATURES_H */
diff --git a/include/lib/aarch64/arch_helpers.h b/include/lib/aarch64/arch_helpers.h
index f562018..6847ce3 100644
--- a/include/lib/aarch64/arch_helpers.h
+++ b/include/lib/aarch64/arch_helpers.h
@@ -733,6 +733,9 @@
 DEFINE_RENAME_SYSREG_RW_FUNCS(tpidr_el2, TPIDR_EL2)
 DEFINE_RENAME_SYSREG_RW_FUNCS(vtcr_el2, VTCR_EL2)
 
+/* Memory Encryption Contexts (MEC) */
+DEFINE_RENAME_SYSREG_READ_FUNC(mecidr_el2, MECIDR_EL2)
+
 static inline u_register_t read_sp(void)
 {
 	u_register_t v;
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 3c94d02..d2d2fc1 100644
--- a/include/runtime_services/host_realm_managment/host_realm_helper.h
+++ b/include/runtime_services/host_realm_managment/host_realm_helper.h
@@ -21,7 +21,8 @@
 		long sl,
 		const u_register_t *rec_flag,
 		unsigned int rec_count,
-		unsigned int num_aux_planes);
+		unsigned int num_aux_planes,
+		unsigned short mecid);
 
 /*
  * Creates realm, initializes heap, creates RTTs and also
@@ -34,7 +35,8 @@
 		long sl,
 		const u_register_t *rec_flag,
 		unsigned int rec_count,
-		unsigned int num_aux_planes);
+		unsigned int num_aux_planes,
+		unsigned short mecid);
 
 /*
  * Creates realm, initializes heap, creates RTTs,
@@ -47,7 +49,8 @@
 		long sl,
 		const u_register_t *rec_flag,
 		unsigned int rec_count,
-		unsigned int num_aux_planes);
+		unsigned int num_aux_planes,
+		unsigned short mecid);
 bool host_destroy_realm(struct realm *realm_ptr);
 void host_rec_send_sgi(struct realm *realm_ptr,
 		unsigned int sgi, unsigned int rec_num);
diff --git a/include/runtime_services/host_realm_managment/host_realm_rmi.h b/include/runtime_services/host_realm_managment/host_realm_rmi.h
index 05570fd..f018f9a 100644
--- a/include/runtime_services/host_realm_managment/host_realm_rmi.h
+++ b/include/runtime_services/host_realm_managment/host_realm_rmi.h
@@ -1363,6 +1363,7 @@
 	u_register_t     host_mpidr[MAX_REC_COUNT];
 	u_register_t     num_aux;
 	u_register_t     rmm_feat_reg0;
+	u_register_t     rmm_feat_reg1;
 	u_register_t     ipa_ns_buffer;
 	u_register_t     ns_buffer_size;
 	u_register_t     aux_pages_all_rec[MAX_REC_COUNT][REC_PARAMS_AUX_GRANULES];
@@ -1375,6 +1376,7 @@
 	bool             rtt_tree_single;
 	bool		 rtt_s2ap_enc_indirect;
 	unsigned short   vmid;
+	unsigned short   mecid;
 	enum realm_state state;
 	long start_level;
 	u_register_t     aux_rtt_addr[MAX_AUX_PLANE_COUNT];
diff --git a/include/runtime_services/host_realm_managment/realm_def.h b/include/runtime_services/host_realm_managment/realm_def.h
index 5d3a196..6fca05c 100644
--- a/include/runtime_services/host_realm_managment/realm_def.h
+++ b/include/runtime_services/host_realm_managment/realm_def.h
@@ -107,4 +107,6 @@
 
 #define REALM_TOKEN_BUF_SIZE		GRANULE_SIZE
 
+#define DEFAULT_MECID			(unsigned short)0
+
 #endif /* REALM_DEF_H */
diff --git a/tftf/tests/runtime_services/host_realm_managment/host_da_helper.c b/tftf/tests/runtime_services/host_realm_managment/host_da_helper.c
index c9a82c2..dc1121f 100644
--- a/tftf/tests/runtime_services/host_realm_managment/host_da_helper.c
+++ b/tftf/tests/runtime_services/host_realm_managment/host_da_helper.c
@@ -695,7 +695,8 @@
 	if (!host_create_activate_realm_payload(realm,
 						(u_register_t)REALM_IMAGE_BASE,
 						feature_flag, 0UL, sl,
-						rec_flag, 1U, 0U)) {
+						rec_flag, 1U, 0U,
+						TEST_MECID1)) {
 		return -1;
 	}
 
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 7fe3f7e..583e612 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
@@ -125,7 +125,8 @@
 			       long sl,
 			       const u_register_t *rec_flag,
 			       unsigned int rec_count,
-			       unsigned int num_aux_planes)
+			       unsigned int num_aux_planes,
+			       unsigned short mecid)
 {
 	int8_t value;
 
@@ -232,6 +233,26 @@
 						feature_flag));
 	}
 
+	/* Assign a MECID to the realm */
+	/*
+	 * Check if FEAT_MEC is supported and RMM supports MECIDs other than the
+	 * default MECID (0) first. Otherwise, assign the default MECID.
+	 */
+	if (is_feat_mec_supported() &&
+			(host_rmi_features(1UL, &realm_ptr->rmm_feat_reg1)
+				== REALM_SUCCESS) &&
+			((unsigned short)realm_ptr->rmm_feat_reg1 != DEFAULT_MECID)) {
+		if (mecid > (unsigned short)realm_ptr->rmm_feat_reg1) {
+			ERROR("Invalid MECID: %hu\n. Max MECID is %hu.",
+				mecid, (unsigned short)realm_ptr->rmm_feat_reg1);
+			return false;
+		}
+
+		realm_ptr->mecid = mecid;
+	} else {
+		realm_ptr->mecid = DEFAULT_MECID;
+	}
+
 	if (realm_ptr->rec_count > MAX_REC_COUNT) {
 		ERROR("Invalid Rec Count\n");
 		return false;
@@ -303,7 +324,8 @@
 			       long sl,
 			       const u_register_t *rec_flag,
 			       unsigned int rec_count,
-			       unsigned int num_aux_planes)
+			       unsigned int num_aux_planes,
+			       unsigned short mecid)
 {
 	bool ret;
 
@@ -314,7 +336,8 @@
 			sl,
 			rec_flag,
 			rec_count,
-			num_aux_planes);
+			num_aux_planes,
+			mecid);
 	if (!ret) {
 		goto destroy_realm;
 	} else {
@@ -351,7 +374,8 @@
 			long sl,
 			const u_register_t *rec_flag,
 			unsigned int rec_count,
-			unsigned int num_aux_planes)
+			unsigned int num_aux_planes,
+			unsigned short mecid)
 
 {
 	bool ret;
@@ -363,7 +387,8 @@
 			sl,
 			rec_flag,
 			rec_count,
-			num_aux_planes);
+			num_aux_planes,
+			mecid);
 	if (!ret) {
 		goto destroy_realm;
 	} else {
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 376695e..d622721 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
@@ -1212,6 +1212,7 @@
 	params->rtt_level_start = realm->start_level;
 	params->algorithm = RMI_HASH_SHA_256;
 	params->vmid = vmid++;
+	params->mecid = realm->mecid;
 	params->rtt_base = realm->rtt_addr;
 	params->rtt_num_start = 1U;
 
diff --git a/tftf/tests/runtime_services/host_realm_managment/rmi_dev_mem_map_tests.c b/tftf/tests/runtime_services/host_realm_managment/rmi_dev_mem_map_tests.c
index 1a28d4f..d021cc9 100644
--- a/tftf/tests/runtime_services/host_realm_managment/rmi_dev_mem_map_tests.c
+++ b/tftf/tests/runtime_services/host_realm_managment/rmi_dev_mem_map_tests.c
@@ -160,7 +160,8 @@
 
 	if (!host_create_activate_realm_payload(&realm,
 						(u_register_t)REALM_IMAGE_BASE,
-						feature_flag, 0U, sl, rec_flag, 1U, 0U)) {
+						feature_flag, 0U, sl, rec_flag,
+						1U, 0U, TEST_MECID1)) {
 		ERROR("Realm creation failed\n");
 		return TEST_RESULT_FAIL;
 	}
diff --git a/tftf/tests/runtime_services/realm_payload/host_realm_brbe_tests.c b/tftf/tests/runtime_services/realm_payload/host_realm_brbe_tests.c
index 3816422..472a6cc 100644
--- a/tftf/tests/runtime_services/realm_payload/host_realm_brbe_tests.c
+++ b/tftf/tests/runtime_services/realm_payload/host_realm_brbe_tests.c
@@ -36,7 +36,8 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-						feature_flag, feature_flag1, sl, rec_flag, 1U, 0U)) {
+						feature_flag, feature_flag1, sl, rec_flag, 1U, 0U,
+						TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
diff --git a/tftf/tests/runtime_services/realm_payload/host_realm_lpa2_tests.c b/tftf/tests/runtime_services/realm_payload/host_realm_lpa2_tests.c
index af5a9ac..fe0699b 100644
--- a/tftf/tests/runtime_services/realm_payload/host_realm_lpa2_tests.c
+++ b/tftf/tests/runtime_services/realm_payload/host_realm_lpa2_tests.c
@@ -22,7 +22,7 @@
 	SKIP_TEST_IF_RME_NOT_SUPPORTED_OR_RMM_IS_TRP();
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			0UL, 0UL, RTT_MIN_LEVEL_LPA2, rec_flag, 1U, 0U)) {
+			0UL, 0UL, RTT_MIN_LEVEL_LPA2, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_SUCCESS;
 	}
 
@@ -41,7 +41,7 @@
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
 			INPLACE(RMI_FEATURE_REGISTER_0_S2SZ, 50UL), 0UL,
-			RTT_MIN_LEVEL, rec_flag, 1U, 0U)) {
+			RTT_MIN_LEVEL, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_SUCCESS;
 	}
 
@@ -67,7 +67,7 @@
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
 			INPLACE(RMI_FEATURE_REGISTER_0_S2SZ, 48UL), 0UL,
-			RTT_MIN_LEVEL, rec_flag, 1U, 0U)) {
+			RTT_MIN_LEVEL, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -99,7 +99,7 @@
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
 			INPLACE(RMI_FEATURE_REGISTER_0_S2SZ, 48UL), 0UL,
-			RTT_MIN_LEVEL, rec_flag, 1U, 0U)) {
+			RTT_MIN_LEVEL, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -155,7 +155,8 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0UL, RTT_MIN_LEVEL, rec_flag, 1U, 0U)) {
+			feature_flag0, 0UL, RTT_MIN_LEVEL, rec_flag, 1U, 0U,
+			TEST_MECID1)) {
 		return TEST_RESULT_SUCCESS;
 	}
 
diff --git a/tftf/tests/runtime_services/realm_payload/host_realm_mpam_tests.c b/tftf/tests/runtime_services/realm_payload/host_realm_mpam_tests.c
index 7fb3a1f..ba01c98 100644
--- a/tftf/tests/runtime_services/realm_payload/host_realm_mpam_tests.c
+++ b/tftf/tests/runtime_services/realm_payload/host_realm_mpam_tests.c
@@ -29,7 +29,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0UL, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0UL, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
diff --git a/tftf/tests/runtime_services/realm_payload/host_realm_payload_multiple_rec_tests.c b/tftf/tests/runtime_services/realm_payload/host_realm_payload_multiple_rec_tests.c
index 951a1f6..7c2bd49 100644
--- a/tftf/tests/runtime_services/realm_payload/host_realm_payload_multiple_rec_tests.c
+++ b/tftf/tests/runtime_services/realm_payload/host_realm_payload_multiple_rec_tests.c
@@ -48,7 +48,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag, 0U, sl, rec_flag, MAX_REC_COUNT, 0U)) {
+			feature_flag, 0U, sl, rec_flag, MAX_REC_COUNT, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -115,7 +115,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag, 0U, sl, rec_flag, 3U, 0U)) {
+			feature_flag, 0U, sl, rec_flag, 3U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -260,7 +260,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, rec_count, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, rec_count, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -385,7 +385,8 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, feature_flag1, sl, rec_flag, rec_count, num_aux_planes)) {
+			feature_flag0, feature_flag1, sl, rec_flag, rec_count, num_aux_planes,
+			TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -563,7 +564,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag, 0U, sl, rec_flag, rec_count, 0U)) {
+			feature_flag, 0U, sl, rec_flag, rec_count, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -701,12 +702,12 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag, 0UL, sl, rec_flag, MAX_REC_COUNT, 0U)) {
+			feature_flag, 0UL, sl, rec_flag, MAX_REC_COUNT, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
 	if (!host_create_activate_realm_payload(&realm2, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag, 0U, sl, rec_flag, 1U, 0U, TEST_MECID2)) {
 		ret2 = host_destroy_realm(&realm);
 		return TEST_RESULT_FAIL;
 	}
@@ -885,7 +886,8 @@
 
 		/* Request more event counters than total, expect failure */
 		if (host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-							feature_flag, 0UL, sl, rec_flag, 1U, 0U)) {
+							feature_flag, 0UL, sl, rec_flag, 1U, 0U,
+							TEST_MECID1)) {
 			ERROR("Realm create should have failed\n");
 			host_destroy_realm(&realm);
 			return TEST_RESULT_FAIL;
@@ -901,7 +903,8 @@
 	}
 
 	ret1 = host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-						feature_flag, 0U, sl, rec_flag, 1U, 0U);
+						feature_flag, 0U, sl, rec_flag, 1U, 0U,
+						TEST_MECID1);
 	host_destroy_realm(&realm);
 
 	if (!get_feat_hpmn0_supported()) {
@@ -926,7 +929,7 @@
 
 	/* Prepare realm, create recs later */
 	if (!host_prepare_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag, 0UL, sl, rec_flag, rec_count, 0U)) {
+			feature_flag, 0UL, sl, rec_flag, rec_count, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -944,7 +947,8 @@
 	}
 
 	ret1 = host_create_activate_realm_payload(&realm1, (u_register_t)REALM_IMAGE_BASE,
-					feature_flag, 0U, sl, rec_flag, rec_count, 0U);
+					feature_flag, 0U, sl, rec_flag, rec_count, 0U,
+					TEST_MECID2);
 	if (!ret1) {
 		goto test_exit;
 	}
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 2f864ca..636aea1 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
@@ -67,7 +67,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 1U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 1U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -129,12 +129,13 @@
 	/* Test invalid combination Tree per plane with s2ap indirect */
 	if (host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
 			feature_flag0, RMI_REALM_FLAGS1_RTT_S2AP_ENCODING_INDIRECT,
-			sl, rec_flag, 1U, MAX_AUX_PLANE_COUNT)) {
+			sl, rec_flag, 1U, MAX_AUX_PLANE_COUNT, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, MAX_AUX_PLANE_COUNT)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, MAX_AUX_PLANE_COUNT,
+			TEST_MECID2)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -236,7 +237,8 @@
 	feature_flag1 = RMI_REALM_FLAGS1_RTT_S2AP_ENCODING_INDIRECT;
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, feature_flag1, sl, &rec_flag, 1U, MAX_AUX_PLANE_COUNT)) {
+			feature_flag0, feature_flag1, sl, &rec_flag, 1U, MAX_AUX_PLANE_COUNT,
+			TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -344,7 +346,8 @@
 	feature_flag0 = INPLACE(RMI_FEATURE_REGISTER_0_S2SZ, s2sz - 5U);
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, RTT_MIN_LEVEL, rec_flag, 2U, 1U)) {
+			feature_flag0, 0U, RTT_MIN_LEVEL, rec_flag, 2U, 1U,
+			TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -480,7 +483,8 @@
 		unsigned int run_num = (unsigned int)rand() % MAX_REC_COUNT;
 
 		if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-				feature_flag0, feature_flag1, sl, rec_flag, MAX_REC_COUNT, 0U)) {
+				feature_flag0, feature_flag1, sl, rec_flag, MAX_REC_COUNT, 0U,
+				TEST_MECID1)) {
 			return TEST_RESULT_FAIL;
 		}
 
@@ -520,7 +524,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -564,7 +568,8 @@
 
 	pauth_test_lib_fill_regs_and_template(pauth_keys_before);
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-				feature_flag0, 0U, sl, rec_flag, MAX_REC_COUNT, 0U)) {
+				feature_flag0, 0U, sl, rec_flag, MAX_REC_COUNT, 0U,
+				TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -626,7 +631,7 @@
 	SKIP_TEST_IF_RME_NOT_SUPPORTED_OR_RMM_IS_TRP();
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-				feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+				feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -730,7 +735,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -879,7 +884,7 @@
 		ret = host_create_activate_realm_payload(&realm[num],
 							(u_register_t)REALM_IMAGE_BASE,
 							feature_flag0, 0U, sl, rec_flag,
-							MAX_REC_COUNT, 0U);
+							MAX_REC_COUNT, 0U, TEST_MECID1);
 		if (!ret) {
 			goto destroy_realms;
 		}
@@ -944,7 +949,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -1043,7 +1048,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -1127,7 +1132,8 @@
 	}
 
 	if (!host_create_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, feature_flag1, sl, rec_flag, 4U, num_aux_planes)) {
+			feature_flag0, feature_flag1, sl, rec_flag, 4U, num_aux_planes,
+			TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -1324,7 +1330,8 @@
 	}
 
 	if (!host_create_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, feature_flag1, sl, rec_flag, 4U, num_aux_planes)) {
+			feature_flag0, feature_flag1, sl, rec_flag, 4U, num_aux_planes,
+			TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -1519,7 +1526,8 @@
 	}
 
 	if (!host_create_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, feature_flag1, sl, rec_flag, 4U, num_aux_planes)) {
+			feature_flag0, feature_flag1, sl, rec_flag, 4U, num_aux_planes,
+			TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -1726,7 +1734,8 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, feature_flag1, sl, rec_flag, 8U, num_aux_planes)) {
+			feature_flag0, feature_flag1, sl, rec_flag, 8U, num_aux_planes,
+			TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -2023,7 +2032,8 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, feature_flag1, sl, rec_flag, 4U, num_aux_planes)) {
+			feature_flag0, feature_flag1, sl, rec_flag, 4U, num_aux_planes,
+			TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -2213,7 +2223,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, MAX_REC_COUNT, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, MAX_REC_COUNT, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -2443,7 +2453,7 @@
 	}
 
 	if (!host_create_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 2U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 2U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -2629,7 +2639,7 @@
 	}
 
 	if (!host_create_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		goto destroy_realm;
 	}
 
@@ -2675,7 +2685,7 @@
 	feature_flag0 = INPLACE(RMI_FEATURE_REGISTER_0_S2SZ, 0x2CU);
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, RTT_MIN_LEVEL, rec_flag, 4U, 0U)) {
+			feature_flag0, 0U, RTT_MIN_LEVEL, rec_flag, 4U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -2822,7 +2832,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		ERROR("Realm creation failed\n");
 		goto destroy_realm;
 	}
@@ -2979,7 +2989,7 @@
 	}
 
 	if (!host_create_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		ERROR("Realm creation failed\n");
 		goto destroy_realm;
 	}
@@ -3154,7 +3164,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		ERROR("Realm creation failed\n");
 		goto destroy_realm;
 	}
@@ -3269,7 +3279,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		ERROR("Realm creation failed\n");
 		goto destroy_realm;
 	}
@@ -3382,7 +3392,7 @@
 	}
 
 	if (!host_create_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		ERROR("Realm creation failed\n");
 		goto destroy_realm;
 	}
@@ -3498,7 +3508,7 @@
 
 	if (!host_create_activate_realm_payload(&realm,
 					(u_register_t)REALM_IMAGE_BASE,
-				feature_flag0, 0U, sl, &rec_flag, 1U, 0U)) {
+				feature_flag0, 0U, sl, &rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -3558,7 +3568,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-				feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+				feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -3599,7 +3609,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-				feature_flag0, 0U, sl, rec_flag, 1U, 0U)) {
+				feature_flag0, 0U, sl, rec_flag, 1U, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -3654,7 +3664,7 @@
 	}
 
 	if (!host_create_activate_realm_payload(&realm, (u_register_t)REALM_IMAGE_BASE,
-			feature_flag0, 0U, sl, rec_flag, 2, 0U)) {
+			feature_flag0, 0U, sl, rec_flag, 2, 0U, TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}
 
diff --git a/tftf/tests/runtime_services/realm_payload/host_realm_simd_common.c b/tftf/tests/runtime_services/realm_payload/host_realm_simd_common.c
index e999cc9..ffbdd20 100644
--- a/tftf/tests/runtime_services/realm_payload/host_realm_simd_common.c
+++ b/tftf/tests/runtime_services/realm_payload/host_realm_simd_common.c
@@ -5,10 +5,12 @@
 
 #include <arch_features.h>
 #include <tftf.h>
+
 #include <host_realm_rmi.h>
 #include <host_realm_helper.h>
 #include <host_realm_mem_layout.h>
 #include <lib/extensions/sve.h>
+#include <test_helpers.h>
 
 #include "host_realm_simd_common.h"
 
@@ -39,7 +41,8 @@
 	/* Initialise Realm payload */
 	if (!host_create_activate_realm_payload(realm,
 				       (u_register_t)REALM_IMAGE_BASE,
-				       feature_flag0, 0UL, sl, rec_flag, 1U, 0U)) {
+				       feature_flag0, 0UL, sl, rec_flag, 1U, 0U,
+				       TEST_MECID1)) {
 		return TEST_RESULT_FAIL;
 	}