feat(rmm): add support for multiple rec and cpu

Changes to support creating and
executing  multiple rec on multiple cpus.
Added per REC shared buffer between Host and Rec.

Signed-off-by: Shruti Gupta <shruti.gupta@arm.com>
Change-Id: Ib6dbd814ee9f68df4a53f9cfdc8b7f9c905c35fe
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 8e6d602..c22bf27 100644
--- a/include/runtime_services/host_realm_managment/host_realm_helper.h
+++ b/include/runtime_services/host_realm_managment/host_realm_helper.h
@@ -14,12 +14,15 @@
 		u_register_t plat_mem_pool_adr,
 		u_register_t plat_mem_pool_size,
 		u_register_t realm_pages_size,
-		u_register_t feature_flag);
+		u_register_t feature_flag,
+		const u_register_t *rec_flag,
+		unsigned int rec_count);
 bool host_create_shared_mem(
 		u_register_t ns_shared_mem_adr,
 		u_register_t ns_shared_mem_size);
 bool host_destroy_realm(void);
-bool host_enter_realm_execute(uint8_t cmd, struct realm **realm_ptr, int test_exit_reason);
+bool host_enter_realm_execute(uint8_t cmd, struct realm **realm_ptr,
+		int test_exit_reason, unsigned int rec_num);
 test_result_t host_cmp_result(void);
 
 #endif /* HOST_REALM_HELPER_H */
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 e4915cc..842ccb5 100644
--- a/include/runtime_services/host_realm_managment/host_realm_rmi.h
+++ b/include/runtime_services/host_realm_managment/host_realm_rmi.h
@@ -11,6 +11,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 
+#include <realm_def.h>
 #include <smccc.h>
 #include <utils_def.h>
 
@@ -498,17 +499,20 @@
 };
 
 struct realm {
+	unsigned int rec_count;
 	u_register_t par_base;
 	u_register_t par_size;
 	u_register_t rd;
 	u_register_t rtt_addr;
-	u_register_t rec;
-	u_register_t run;
+	u_register_t rec[MAX_REC_COUNT];
+	u_register_t run[MAX_REC_COUNT];
+	u_register_t rec_flag[MAX_REC_COUNT];
+	u_register_t mpidr[MAX_REC_COUNT];
 	u_register_t num_aux;
 	u_register_t rmm_feat_reg0;
 	u_register_t ipa_ns_buffer;
 	u_register_t ns_buffer_size;
-	u_register_t aux_pages[REC_PARAMS_AUX_GRANULES];
+	u_register_t aux_pages_all_rec[MAX_REC_COUNT][REC_PARAMS_AUX_GRANULES];
 	uint8_t      sve_vl;
 	uint8_t      num_bps;
 	uint8_t      num_wps;
@@ -532,13 +536,17 @@
 					u_register_t ns_shared_mem_adr,
 					u_register_t ns_shared_mem_size);
 u_register_t host_realm_rec_create(struct realm *realm);
+unsigned int host_realm_find_rec_by_mpidr(unsigned int mpidr, struct realm *realm);
 u_register_t host_realm_activate(struct realm *realm);
 u_register_t host_realm_destroy(struct realm *realm);
 u_register_t host_realm_rec_enter(struct realm *realm,
 					u_register_t *exit_reason,
-					unsigned int *host_call_result);
+					unsigned int *host_call_result,
+					unsigned int rec_num);
 u_register_t host_realm_init_ipa_state(struct realm *realm, u_register_t level,
 					u_register_t start, uint64_t end);
+u_register_t host_rmi_psci_complete(u_register_t calling_rec, u_register_t target_rec,
+		unsigned long status);
 void host_rmi_init_cmp_result(void);
 bool host_rmi_get_cmp_result(void);
 
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 821a62f..e8dae1d 100644
--- a/include/runtime_services/host_realm_managment/host_shared_data.h
+++ b/include/runtime_services/host_realm_managment/host_shared_data.h
@@ -34,9 +34,6 @@
 
 	/* Buffer to save Realm command results */
 	uint8_t realm_cmd_output_buffer[REALM_CMD_BUFFER_SIZE];
-
-	/* Lock to avoid concurrent accesses to log_buffer */
-	spinlock_t printf_lock;
 } host_shared_data_t;
 
 /*
@@ -72,18 +69,32 @@
 enum host_call_cmd {
         HOST_CALL_GET_SHARED_BUFF_CMD = 1U,
         HOST_CALL_EXIT_SUCCESS_CMD,
-        HOST_CALL_EXIT_FAILED_CMD
+	HOST_CALL_EXIT_FAILED_CMD
 };
 
+/***************************************
+ *  APIs to be invoked from Host side  *
+ ***************************************/
+
 /*
  * Return shared buffer pointer mapped as host_shared_data_t structure
  */
-host_shared_data_t *host_get_shared_structure(void);
+host_shared_data_t *host_get_shared_structure(unsigned int rec_num);
 
 /*
  * Set data to be shared from Host to realm
  */
-void realm_shared_data_set_host_val(uint8_t index, u_register_t val);
+void host_shared_data_set_host_val(unsigned int rec_num, uint8_t index, u_register_t val);
+
+/*
+ * Set command to be send from Host to realm
+ */
+void host_shared_data_set_realm_cmd(uint8_t cmd, unsigned int rec_num);
+
+
+/****************************************
+ *  APIs to be invoked from Realm side  *
+ ****************************************/
 
 /*
  * Set guest mapped shared buffer pointer
@@ -93,41 +104,21 @@
 /*
  * Get guest mapped shared buffer pointer
  */
-host_shared_data_t *realm_get_shared_structure(void);
-
-/*
- * Set data to be shared from Realm to Host
- */
-void realm_shared_data_set_realm_val(uint8_t index, u_register_t val);
+host_shared_data_t *realm_get_my_shared_structure(void);
 
 /*
  * Return Host's data at index
  */
-u_register_t realm_shared_data_get_host_val(uint8_t index);
+u_register_t realm_shared_data_get_my_host_val(uint8_t index);
 
 /*
- * Return Realm's data at index
+ * Get command sent from Host to my Rec
  */
-u_register_t realm_shared_data_get_realm_val(uint8_t index);
+uint8_t realm_shared_data_get_my_realm_cmd(void);
 
 /*
- * Clear shared realm data
+ * Set data to be shared from my Rec to Host
  */
-void realm_shared_data_clear_realm_val(void);
-
-/*
- * Clear shared Host data
- */
-void realm_shared_data_clear_host_val(void);
-
-/*
- * Get command sent from Host to realm
- */
-uint8_t realm_shared_data_get_realm_cmd(void);
-
-/*
- * Set command to be send from Host to realm
- */
-void realm_shared_data_set_realm_cmd(uint8_t cmd);
+void realm_shared_data_set_my_realm_val(uint8_t index, u_register_t val);
 
 #endif /* HOST_SHARED_DATA_H */
diff --git a/include/runtime_services/host_realm_managment/realm_def.h b/include/runtime_services/host_realm_managment/realm_def.h
index 618007e..777b837 100644
--- a/include/runtime_services/host_realm_managment/realm_def.h
+++ b/include/runtime_services/host_realm_managment/realm_def.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022, Arm Limited. All rights reserved.
+ * Copyright (c) 2022-2023, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -17,6 +17,7 @@
 #define DATA_PATTERN_2			0x11223344U
 #define REALM_SUCCESS			0U
 #define REALM_ERROR			1U
+#define MAX_REC_COUNT			8U
 
 /* Only support 4KB at the moment */
 
diff --git a/include/runtime_services/psci.h b/include/runtime_services/psci.h
index caa74a9..0e56bdc 100644
--- a/include/runtime_services/psci.h
+++ b/include/runtime_services/psci.h
@@ -16,7 +16,6 @@
 
 #ifndef __ASSEMBLY__
 #include <assert.h>
-#include <platform_def.h>
 #include <stdbool.h>
 #include <stdint.h>
 #endif
diff --git a/realm/aarch64/realm_entrypoint.S b/realm/aarch64/realm_entrypoint.S
index e0638f0..73406f9 100644
--- a/realm/aarch64/realm_entrypoint.S
+++ b/realm/aarch64/realm_entrypoint.S
@@ -11,14 +11,20 @@
 	.globl	realm_entrypoint
 
 .section .bss.stacks
-.align 8
-	.fill	REALM_STACK_SIZE
+.align 16
+	.fill	REALM_STACK_SIZE * MAX_REC_COUNT
 stacks_end:
 
 func realm_entrypoint
+	mrs	x0, mpidr_el1
+	mov_imm	x1, MPID_MASK
+	and	x0, x0, x1
+
 	/* Setup the stack pointer. */
-	adr	x1, stacks_end
-	mov	sp, x1
+	bl	realm_setup_my_stack
+
+	/* mpidr 0 is assumed to be primary CPU, jump to warmboot otherwise */
+	cbnz	x0, realm_warmboot_endpoint
 
 	/* Clear BSS */
 	ldr	x0, =__REALM_BSS_START__
@@ -39,9 +45,6 @@
 	sub	x1, x1, x0
 	bl	inv_dcache_range
 
-	/* Initialize architectural state. */
-	bl	arch_init
-
 	/* Relocate symbols */
 pie_fixup:
 	ldr	x0, =pie_fixup
@@ -49,6 +52,10 @@
 	mov	x1, REALM_MAX_LOAD_IMG_SIZE
 	add	x1, x1, x0
 	bl	fixup_gdt_reloc
+
+realm_warmboot_endpoint:
+	/* Initialize architectural state. */
+	bl	arch_init
 #if ENABLE_PAUTH
 	bl	pauth_init_enable
 #endif
@@ -59,6 +66,19 @@
 	b	loop
 endfunc realm_entrypoint
 
+/*
+ * Setup the stack pointer.
+ * x0 = mpidr
+ * clobbers x1,x2
+ */
+func realm_setup_my_stack
+	adr	x1, stacks_end
+	mov	x2, REALM_STACK_SIZE
+	mul	x2, x0, x2
+	sub	sp, x1, x2
+	ret
+endfunc	realm_setup_my_stack
+
 /* Initialize architectural state. */
 func arch_init
 	/* Set the exception vectors. */
diff --git a/realm/realm_debug.c b/realm/realm_debug.c
index e9eb61e..d7989ca 100644
--- a/realm/realm_debug.c
+++ b/realm/realm_debug.c
@@ -19,19 +19,17 @@
  */
 void realm_printf(const char *fmt, ...)
 {
-	host_shared_data_t *guest_shared_data = realm_get_shared_structure();
+	host_shared_data_t *guest_shared_data = realm_get_my_shared_structure();
 	char *log_buffer = (char *)guest_shared_data->log_buffer;
 	va_list args;
 
 	va_start(args, fmt);
-	spin_lock((spinlock_t *)&guest_shared_data->printf_lock);
 	if (strnlen((const char *)log_buffer, MAX_BUF_SIZE) == MAX_BUF_SIZE) {
 		(void)memset((char *)log_buffer, 0, MAX_BUF_SIZE);
 	}
 	(void)vsnprintf((char *)log_buffer +
 			strnlen((const char *)log_buffer, MAX_BUF_SIZE),
 			MAX_BUF_SIZE, fmt, args);
-	spin_unlock((spinlock_t *)&guest_shared_data->printf_lock);
 	va_end(args);
 }
 
@@ -46,18 +44,16 @@
 /* This is used from printf() when crash dump is reached */
 int console_putc(int c)
 {
-	host_shared_data_t *guest_shared_data = realm_get_shared_structure();
+	host_shared_data_t *guest_shared_data = realm_get_my_shared_structure();
 	char *log_buffer = (char *)guest_shared_data->log_buffer;
 
 	if ((c < 0) || (c > 127)) {
 		return -1;
 	}
-	spin_lock((spinlock_t *)&guest_shared_data->printf_lock);
 	if (strnlen((const char *)log_buffer, MAX_BUF_SIZE) == MAX_BUF_SIZE) {
 		(void)memset((char *)log_buffer, 0, MAX_BUF_SIZE);
 	}
 	*((char *)log_buffer + strnlen((const char *)log_buffer, MAX_BUF_SIZE)) = c;
-	spin_unlock((spinlock_t *)&guest_shared_data->printf_lock);
 
 	return c;
 }
diff --git a/realm/realm_payload_main.c b/realm/realm_payload_main.c
index e867546..586d400 100644
--- a/realm/realm_payload_main.c
+++ b/realm/realm_payload_main.c
@@ -25,7 +25,7 @@
  */
 static void realm_sleep_cmd(void)
 {
-	uint64_t sleep = realm_shared_data_get_host_val(HOST_SLEEP_INDEX);
+	uint64_t sleep = realm_shared_data_get_my_host_val(HOST_SLEEP_INDEX);
 
 	realm_printf("Realm: going to sleep for %llums\n", sleep);
 	waitms(sleep);
@@ -64,8 +64,8 @@
 	bool test_succeed = false;
 
 	realm_set_shared_structure((host_shared_data_t *)rsi_get_ns_buffer());
-	if (realm_get_shared_structure() != NULL) {
-		uint8_t cmd = realm_shared_data_get_realm_cmd();
+	if (realm_get_my_shared_structure() != NULL) {
+		uint8_t cmd = realm_shared_data_get_my_realm_cmd();
 
 		switch (cmd) {
 		case REALM_SLEEP_CMD:
diff --git a/realm/realm_shared_data.c b/realm/realm_shared_data.c
index da09b53..2d09f78 100644
--- a/realm/realm_shared_data.c
+++ b/realm/realm_shared_data.c
@@ -5,6 +5,8 @@
  */
 
 #include <string.h>
+#include <arch_helpers.h>
+#include <assert.h>
 #include <host_shared_data.h>
 
 /**
@@ -26,24 +28,34 @@
 /*
  * Get guest mapped shared buffer pointer
  */
-host_shared_data_t *realm_get_shared_structure(void)
+host_shared_data_t *realm_get_my_shared_structure(void)
 {
-	return guest_shared_data;
+	return &guest_shared_data[read_mpidr_el1() & MPID_MASK];
 }
 
 /*
  * Return Host's data at index
  */
-u_register_t realm_shared_data_get_host_val(uint8_t index)
+u_register_t realm_shared_data_get_my_host_val(uint8_t index)
 {
-	return guest_shared_data->host_param_val[(index >= MAX_DATA_SIZE) ?
-		(MAX_DATA_SIZE - 1) : index];
+	assert(index < MAX_DATA_SIZE);
+	return guest_shared_data[read_mpidr_el1() & MPID_MASK].host_param_val[index];
 }
 
 /*
- * Get command sent from Host to realm
+ * Get command sent from Host to this rec
  */
-uint8_t realm_shared_data_get_realm_cmd(void)
+uint8_t realm_shared_data_get_my_realm_cmd(void)
 {
-	return guest_shared_data->realm_cmd;
+	return guest_shared_data[read_mpidr_el1() & MPID_MASK].realm_cmd;
 }
+
+/*
+ * Set data to be shared from this rec to Host
+ */
+void realm_shared_data_set_my_realm_val(uint8_t index, u_register_t val)
+{
+	assert(index < MAX_DATA_SIZE);
+	guest_shared_data[read_mpidr_el1() & MPID_MASK].realm_out_val[index] = val;
+}
+
diff --git a/realm/realm_sve.c b/realm/realm_sve.c
index d5ef8c1..0512789 100644
--- a/realm/realm_sve.c
+++ b/realm/realm_sve.c
@@ -25,7 +25,7 @@
 /* Returns the maximum supported VL. This test is called only by sve Realm */
 bool test_realm_sve_rdvl(void)
 {
-	host_shared_data_t *sd = realm_get_shared_structure();
+	host_shared_data_t *sd = realm_get_my_shared_structure();
 	struct sve_cmd_rdvl *output;
 
 	assert(is_armv8_2_sve_present());
@@ -45,7 +45,7 @@
  */
 bool test_realm_sve_read_id_registers(void)
 {
-	host_shared_data_t *sd = realm_get_shared_structure();
+	host_shared_data_t *sd = realm_get_my_shared_structure();
 	struct sve_cmd_id_regs *output;
 
 	output = (struct sve_cmd_id_regs *)sd->realm_cmd_output_buffer;
@@ -65,7 +65,7 @@
  */
 bool test_realm_sve_probe_vl(void)
 {
-	host_shared_data_t *sd = realm_get_shared_structure();
+	host_shared_data_t *sd = realm_get_my_shared_structure();
 	struct sve_cmd_probe_vl *output;
 
 	assert(is_armv8_2_sve_present());
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 09ac9a0..d3b50d3 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
@@ -44,32 +44,24 @@
  * The function handler to print the Realm logged buffer,
  * executed by the secondary core
  */
-static inline test_result_t timer_handler(void)
+void realm_print_handler(unsigned int rec_num)
 {
 	size_t str_len = 0UL;
-	host_shared_data_t *host_shared_data = host_get_shared_structure();
+	host_shared_data_t *host_shared_data = host_get_shared_structure(rec_num);
 	char *log_buffer = (char *)host_shared_data->log_buffer;
 
-	do {
-		spin_lock((spinlock_t *)&host_shared_data->printf_lock);
-		str_len = strlen((const char *)log_buffer);
+	str_len = strlen((const char *)log_buffer);
 
-		/*
-		 * Read Realm message from shared printf location and print
-		 * them using UART
-		 */
-		if (str_len != 0UL) {
-			/* Avoid memory overflow */
-			log_buffer[MAX_BUF_SIZE - 1] = 0U;
-
-			mp_printf("%s", log_buffer);
-			(void)memset((char *)log_buffer, 0, MAX_BUF_SIZE);
-		}
-		spin_unlock((spinlock_t *)&host_shared_data->printf_lock);
-
-	} while ((timer_enabled || (str_len != 0UL)));
-
-	return TEST_RESULT_SUCCESS;
+	/*
+	 * Read Realm message from shared printf location and print
+	 * them using UART
+	 */
+	if (str_len != 0UL) {
+		/* Avoid memory overflow */
+		log_buffer[MAX_BUF_SIZE - 1] = 0U;
+		mp_printf("%s", log_buffer);
+		(void)memset((char *)log_buffer, 0, MAX_BUF_SIZE);
+	}
 }
 
 /*
@@ -77,36 +69,18 @@
  * and try to find another CPU other than the lead one to
  * handle the Realm message logging.
  */
-void host_init_realm_print_buffer(void)
+static void host_init_realm_print_buffer(void)
 {
-	u_register_t other_mpidr, my_mpidr;
-	host_shared_data_t *host_shared_data = host_get_shared_structure();
-	int ret;
+	host_shared_data_t *host_shared_data;
 
-	(void)memset((char *)host_shared_data, 0, sizeof(host_shared_data_t));
-
-	/* Program timer */
-	timer_enabled = false;
-
-	/* Find a valid CPU to power on */
-	my_mpidr = read_mpidr_el1() & MPID_MASK;
-	other_mpidr = tftf_find_any_cpu_other_than(my_mpidr);
-	if (other_mpidr == INVALID_MPID) {
-		ERROR("Couldn't find a valid other CPU\n");
-		return;
+	for (unsigned int i = 0U; i < realm.rec_count; i++) {
+		host_shared_data = host_get_shared_structure(i);
+		(void)memset((char *)host_shared_data, 0, sizeof(host_shared_data_t));
 	}
-
-	/* Power on the other CPU */
-	ret = tftf_cpu_on(other_mpidr, (uintptr_t)timer_handler, 0);
-	if (ret != PSCI_E_SUCCESS) {
-		ERROR("Powering on %lx failed\n", other_mpidr);
-		return;
-	}
-	timer_enabled = true;
 }
 
 static bool host_enter_realm(u_register_t *exit_reason,
-				unsigned int *host_call_result)
+		unsigned int *host_call_result, unsigned int rec_num)
 {
 	u_register_t ret;
 
@@ -120,15 +94,9 @@
 	}
 
 	/* Enter Realm */
-	ret = host_realm_rec_enter(&realm, exit_reason, host_call_result);
+	ret = host_realm_rec_enter(&realm, exit_reason, host_call_result, rec_num);
 	if (ret != REALM_SUCCESS) {
 		ERROR("%s() failed, ret=%lx\n", "host_realm_rec_enter", ret);
-
-		/* Free test resources */
-		if (host_realm_destroy(&realm) != REALM_SUCCESS) {
-			ERROR("%s() failed\n", "host_realm_destroy");
-		}
-		realm_payload_created = false;
 		return false;
 	}
 
@@ -139,7 +107,9 @@
 				u_register_t plat_mem_pool_adr,
 				u_register_t plat_mem_pool_size,
 				u_register_t realm_pages_size,
-				u_register_t feature_flag)
+				u_register_t feature_flag,
+				const u_register_t *rec_flag,
+				unsigned int rec_count)
 {
 	int8_t value;
 
@@ -221,6 +191,21 @@
 						feature_flag));
 	}
 
+	if (realm.rec_count > MAX_REC_COUNT) {
+		ERROR("Invalid Rec Count\n");
+		return false;
+	}
+	realm.rec_count = rec_count;
+	for (unsigned int i = 0U; i < rec_count; i++) {
+		if (rec_flag[i] == RMI_RUNNABLE ||
+				rec_flag[i] == RMI_NOT_RUNNABLE) {
+			realm.rec_flag[i] = rec_flag[i];
+		} else {
+			ERROR("Invalid Rec Flag\n");
+			return false;
+		}
+	}
+
 	/* Create Realm */
 	if (host_realm_create(&realm) != REALM_SUCCESS) {
 		ERROR("%s() failed\n", "host_realm_create");
@@ -277,8 +262,8 @@
 		return false;
 	}
 
+	memset((void *)ns_shared_mem_adr, 0, (size_t)ns_shared_mem_size);
 	host_init_realm_print_buffer();
-	realm_shared_data_clear_realm_val();
 	shared_mem_created = true;
 
 	return shared_mem_created;
@@ -304,13 +289,18 @@
 	return true;
 }
 
-bool host_enter_realm_execute(uint8_t cmd, struct realm **realm_ptr, int test_exit_reason)
+bool host_enter_realm_execute(uint8_t cmd, struct realm **realm_ptr,
+		int test_exit_reason, unsigned int rec_num)
 {
 	u_register_t exit_reason = RMI_EXIT_INVALID;
 	unsigned int host_call_result = TEST_RESULT_FAIL;
 
-	realm_shared_data_set_realm_cmd(cmd);
-	if (!host_enter_realm(&exit_reason, &host_call_result)) {
+	if (rec_num >= realm.rec_count) {
+		ERROR("Invalid Rec Count\n");
+		return false;
+	}
+	host_shared_data_set_realm_cmd(cmd, rec_num);
+	if (!host_enter_realm(&exit_reason, &host_call_result, rec_num)) {
 		return false;
 	}
 
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 82e92e3..8516fab 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
@@ -103,6 +103,13 @@
 	return rmi_cmp_result;
 }
 
+u_register_t host_rmi_psci_complete(u_register_t calling_rec, u_register_t target_rec,
+		unsigned long status)
+{
+	return (host_rmi_handler(&(smc_args) {RMI_PSCI_COMPLETE, calling_rec,
+				target_rec, status}, 4U)).ret0;
+}
+
 static inline u_register_t host_rmi_data_create(bool unknown,
 						u_register_t rd,
 						u_register_t data,
@@ -504,7 +511,7 @@
 	u_register_t phys = ns_pa;
 	u_register_t map_addr = ns_pa |
 			(1UL << (EXTRACT(RMI_FEATURE_REGISTER_0_S2SZ,
-			realm->rmm_feat_reg0) - 1UL)) ;
+			realm->rmm_feat_reg0) - 1UL));
 
 	if (!IS_ALIGNED(map_addr, map_size)) {
 		return REALM_ERROR;
@@ -942,130 +949,149 @@
 	return REALM_SUCCESS;
 }
 
-static void host_realm_free_rec_aux(u_register_t *aux_pages,
-					unsigned int num_aux)
+/* Free AUX pages for rec0 to rec_num */
+static void host_realm_free_rec_aux(u_register_t
+		(*aux_pages)[REC_PARAMS_AUX_GRANULES],
+		unsigned int num_aux, unsigned int rec_num)
 {
 	u_register_t ret;
 
-	for (unsigned int i = 0U; i < num_aux; i++) {
-		ret = host_rmi_granule_undelegate(aux_pages[i]);
-		if (ret != RMI_SUCCESS) {
-			WARN("%s() failed, index=%u ret=0x%lx\n",
-				"host_rmi_granule_undelegate", i, ret);
+	assert(rec_num < MAX_REC_COUNT);
+	assert(num_aux <= REC_PARAMS_AUX_GRANULES);
+	for (unsigned int i = 0U; i <= rec_num; i++) {
+		for (unsigned int j = 0U; j < num_aux &&
+					aux_pages[i][j] != 0U; j++) {
+			ret = host_rmi_granule_undelegate(aux_pages[i][j]);
+			if (ret != RMI_SUCCESS) {
+				WARN("%s() failed, index=%u,%u ret=0x%lx\n",
+				"host_rmi_granule_undelegate", i, j, ret);
+			}
+			page_free(aux_pages[i][j]);
 		}
-		page_free(aux_pages[i]);
 	}
 }
 
 static u_register_t host_realm_alloc_rec_aux(struct realm *realm,
-						struct rmi_rec_params *params)
+		struct rmi_rec_params *params, u_register_t rec_num)
 {
 	u_register_t ret;
-	unsigned int i;
+	unsigned int j;
 
-	for (i = 0U; i < realm->num_aux; i++) {
-		params->aux[i] = (u_register_t)page_alloc(PAGE_SIZE);
-		if (params->aux[i] == HEAP_NULL_PTR) {
+	assert(rec_num < MAX_REC_COUNT);
+	for (j = 0U; j < realm->num_aux; j++) {
+		params->aux[j] = (u_register_t)page_alloc(PAGE_SIZE);
+		if (params->aux[j] == HEAP_NULL_PTR) {
 			ERROR("Failed to allocate memory for aux rec\n");
-			goto err_free_mem;
+			return RMI_ERROR_REALM;
 		}
-		ret = host_rmi_granule_delegate(params->aux[i]);
+		ret = host_rmi_granule_delegate(params->aux[j]);
 		if (ret != RMI_SUCCESS) {
 			ERROR("%s() failed, index=%u ret=0x%lx\n",
-				"host_rmi_granule_delegate", i, ret);
-			goto err_free_mem;
+				"host_rmi_granule_delegate", j, ret);
+			/*
+			 * Free current page,
+			 * prev pages freed at host_realm_free_rec_aux
+			 */
+			page_free(params->aux[j]);
+			params->aux[j] = 0UL;
+			return RMI_ERROR_REALM;
 		}
 
 		/* We need a copy in Realm object for final destruction */
-		realm->aux_pages[i] = params->aux[i];
+		realm->aux_pages_all_rec[rec_num][j] = params->aux[j];
 	}
 	return RMI_SUCCESS;
-err_free_mem:
-	host_realm_free_rec_aux(params->aux, i);
-	return ret;
 }
 
 u_register_t host_realm_rec_create(struct realm *realm)
 {
-	struct rmi_rec_params *rec_params = HEAP_NULL_PTR;
+	struct rmi_rec_params *rec_params;
 	u_register_t ret;
+	unsigned int i;
 
-	/* Allocate memory for run object */
-	realm->run = (u_register_t)page_alloc(PAGE_SIZE);
-	if (realm->run == HEAP_NULL_PTR) {
-		ERROR("Failed to allocate memory for run\n");
-		return REALM_ERROR;
+	for (i = 0U; i < realm->rec_count; i++) {
+		realm->run[i] = 0U;
+		realm->rec[i] = 0U;
+		realm->mpidr[i] = 0U;
 	}
-	(void)memset((void *)realm->run, 0x0, PAGE_SIZE);
-
-	/* Allocate and delegate REC */
-	realm->rec = (u_register_t)page_alloc(PAGE_SIZE);
-	if (realm->rec == HEAP_NULL_PTR) {
-		ERROR("Failed to allocate memory for REC\n");
-		goto err_free_mem;
-	} else {
-		ret = host_rmi_granule_delegate(realm->rec);
-		if (ret != RMI_SUCCESS) {
-			ERROR("%s() failed, rec=0x%lx ret=0x%lx\n",
-				"host_rmi_granule_delegate", realm->rd, ret);
-			goto err_free_mem;
-		}
-	}
+	(void)memset(realm->aux_pages_all_rec, 0x0, sizeof(u_register_t) *
+			realm->num_aux*realm->rec_count);
 
 	/* Allocate memory for rec_params */
 	rec_params = (struct rmi_rec_params *)page_alloc(PAGE_SIZE);
 	if (rec_params == NULL) {
 		ERROR("Failed to allocate memory for rec_params\n");
-		goto err_undelegate_rec;
-	}
-	(void)memset(rec_params, 0x0, PAGE_SIZE);
-
-	/* Populate rec_params */
-	for (unsigned int i = 0U; i < (sizeof(rec_params->gprs) /
-			sizeof(rec_params->gprs[0]));
-			i++) {
-		rec_params->gprs[i] = 0x0UL;
+		return REALM_ERROR;
 	}
 
-	/* Delegate the required number of auxiliary Granules  */
-	ret = host_realm_alloc_rec_aux(realm, rec_params);
-	if (ret != RMI_SUCCESS) {
-		ERROR("%s() failed, ret=0x%lx\n", "host_realm_alloc_rec_aux",
+	for (i = 0U; i < realm->rec_count; i++) {
+		(void)memset(rec_params, 0x0, PAGE_SIZE);
+
+		/* Allocate memory for run object */
+		realm->run[i] = (u_register_t)page_alloc(PAGE_SIZE);
+		if (realm->run[i] == HEAP_NULL_PTR) {
+			ERROR("Failed to allocate memory for run\n");
+			goto err_free_mem;
+		}
+		(void)memset((void *)realm->run[i], 0x0, PAGE_SIZE);
+
+		/* Allocate and delegate REC */
+		realm->rec[i] = (u_register_t)page_alloc(PAGE_SIZE);
+		if (realm->rec[i] == HEAP_NULL_PTR) {
+			ERROR("Failed to allocate memory for REC\n");
+			goto err_free_mem;
+		} else {
+			ret = host_rmi_granule_delegate(realm->rec[i]);
+			if (ret != RMI_SUCCESS) {
+				ERROR("%s() failed, rec=0x%lx ret=0x%lx\n",
+				"host_rmi_granule_delegate", realm->rd, ret);
+				goto err_free_mem;
+			}
+		}
+
+		/* Delegate the required number of auxiliary Granules  */
+		ret = host_realm_alloc_rec_aux(realm, rec_params, i);
+		if (ret != RMI_SUCCESS) {
+			ERROR("%s() failed, ret=0x%lx\n", "host_realm_alloc_rec_aux",
 			ret);
-		goto err_free_mem;
+			goto err_free_aux;
+		}
+
+		/* Populate rec_params */
+		rec_params->pc = realm->par_base;
+		rec_params->flags = realm->rec_flag[i];
+
+		rec_params->mpidr = (u_register_t)i;
+		rec_params->num_aux = realm->num_aux;
+		realm->mpidr[i] = (u_register_t)i;
+
+		/* Create REC  */
+		ret = host_rmi_rec_create(realm->rd, realm->rec[i],
+				(u_register_t)rec_params);
+		if (ret != RMI_SUCCESS) {
+			ERROR("%s() failed,index=%u, ret=0x%lx\n",
+					"host_rmi_rec_create", i, ret);
+			goto err_free_aux;
+		}
 	}
-
-	rec_params->pc = realm->par_base;
-	rec_params->flags = RMI_RUNNABLE;
-	rec_params->mpidr = 0x0UL;
-	rec_params->num_aux = realm->num_aux;
-
-	/* Create REC  */
-	ret = host_rmi_rec_create(realm->rd, realm->rec, (u_register_t)rec_params);
-	if (ret != RMI_SUCCESS) {
-		ERROR("%s() failed, ret=0x%lx\n", "host_rmi_rec_create", ret);
-		goto err_free_rec_aux;
-	}
-
 	/* Free rec_params */
 	page_free((u_register_t)rec_params);
 	return REALM_SUCCESS;
 
-err_free_rec_aux:
-	host_realm_free_rec_aux(rec_params->aux, realm->num_aux);
-
-err_undelegate_rec:
-	ret = host_rmi_granule_undelegate(realm->rec);
-	if (ret != RMI_SUCCESS) {
-		WARN("%s() failed, rec=0x%lx ret=0x%lx\n",
-			"host_rmi_granule_undelegate", realm->rec, ret);
-	}
+err_free_aux:
+	host_realm_free_rec_aux(realm->aux_pages_all_rec, realm->num_aux, i);
 
 err_free_mem:
-	page_free(realm->run);
-	page_free(realm->rec);
+	for (unsigned int j = 0U; j <= i ; j++) {
+		ret = host_rmi_granule_undelegate(realm->rec[j]);
+		if (ret != RMI_SUCCESS) {
+			WARN("%s() failed, rec=0x%lx ret=0x%lx\n",
+			"host_rmi_granule_undelegate", realm->rec[j], ret);
+		}
+		page_free(realm->run[j]);
+		page_free(realm->rec[j]);
+	}
 	page_free((u_register_t)rec_params);
-
 	return REALM_ERROR;
 }
 
@@ -1103,26 +1129,30 @@
 		return REALM_ERROR;
 	}
 
-	/* For each REC - Destroy, undelegate and free */
-	ret = host_rmi_rec_destroy(realm->rec);
-	if (ret != RMI_SUCCESS) {
-		ERROR("%s() failed, rec=0x%lx ret=0x%lx\n",
-			"host_rmi_rec_destroy", realm->rec, ret);
-		return REALM_ERROR;
+	for (unsigned int i = 0U; i < realm->rec_count; i++) {
+		/* For each REC - Destroy, undelegate and free */
+		ret = host_rmi_rec_destroy(realm->rec[i]);
+		if (ret != RMI_SUCCESS) {
+			ERROR("%s() failed, rec=0x%lx ret=0x%lx\n",
+				"host_rmi_rec_destroy", realm->rec[i], ret);
+			return REALM_ERROR;
+		}
+
+		ret = host_rmi_granule_undelegate(realm->rec[i]);
+		if (ret != RMI_SUCCESS) {
+			ERROR("%s() failed, rec=0x%lx ret=0x%lx\n",
+				"host_rmi_granule_undelegate", realm->rec[i], ret);
+			return REALM_ERROR;
+		}
+
+		page_free(realm->rec[i]);
+
+		/* Free run object */
+		page_free(realm->run[i]);
 	}
 
-	ret = host_rmi_granule_undelegate(realm->rec);
-	if (ret != RMI_SUCCESS) {
-		ERROR("%s() failed, rec=0x%lx ret=0x%lx\n",
-			"host_rmi_granule_undelegate", realm->rec, ret);
-		return REALM_ERROR;
-	}
-
-	host_realm_free_rec_aux(realm->aux_pages, realm->num_aux);
-	page_free(realm->rec);
-
-	/* Free run object */
-	page_free(realm->run);
+	host_realm_free_rec_aux(realm->aux_pages_all_rec,
+			realm->num_aux, realm->rec_count - 1U);
 
 	/*
 	 * For each data granule - Destroy, undelegate and free
@@ -1177,21 +1207,37 @@
 	return REALM_SUCCESS;
 }
 
+unsigned int host_realm_find_rec_by_mpidr(unsigned int mpidr, struct realm *realm)
+{
+	for (unsigned int i = 0U; i < MAX_REC_COUNT; i++) {
+		if (realm->run[i] != 0U && realm->mpidr[i] == mpidr) {
+			return i;
+		}
+	}
+	return MAX_REC_COUNT;
+}
+
 u_register_t host_realm_rec_enter(struct realm *realm,
 				  u_register_t *exit_reason,
-				  unsigned int *host_call_result)
+				  unsigned int *host_call_result,
+				  unsigned int rec_num)
 {
-	struct rmi_rec_run *run = (struct rmi_rec_run *)realm->run;
+	struct rmi_rec_run *run;
 	u_register_t ret;
 	bool re_enter_rec;
 
+	if (rec_num >= realm->rec_count) {
+		return RMI_ERROR_INPUT;
+	}
+
+	run = (struct rmi_rec_run *)realm->run[rec_num];
 	do {
 		re_enter_rec = false;
 		ret = host_rmi_handler(&(smc_args) {RMI_REC_ENTER,
-					realm->rec, realm->run}, 3U).ret0;
-		VERBOSE("%s() run->exit.exit_reason=%lu "
+					realm->rec[rec_num], realm->run[rec_num]}, 3U).ret0;
+		VERBOSE("%s() ret=%lu run->exit.exit_reason=%lu "
 			"run->exit.esr=0x%lx EC_BITS=%u ISS_DFSC_MASK=0x%lx\n",
-			__func__, run->exit.exit_reason, run->exit.esr,
+			__func__, ret, run->exit.exit_reason, run->exit.esr,
 			((EC_BITS(run->exit.esr) == EC_DABORT_CUR_EL)),
 			(ISS_BITS(run->exit.esr) & ISS_DFSC_MASK));
 
diff --git a/tftf/tests/runtime_services/host_realm_managment/host_shared_data.c b/tftf/tests/runtime_services/host_realm_managment/host_shared_data.c
index bd571c7..b6e548c 100644
--- a/tftf/tests/runtime_services/host_realm_managment/host_shared_data.c
+++ b/tftf/tests/runtime_services/host_realm_managment/host_shared_data.c
@@ -5,103 +5,57 @@
  */
 
 #include <string.h>
-
+#include <assert.h>
+#include <cassert.h>
 #include <host_realm_mem_layout.h>
 #include <host_shared_data.h>
 
-static host_shared_data_t *host_shared_data =
-		((host_shared_data_t *)(NS_REALM_SHARED_MEM_BASE));
-static host_shared_data_t *guest_shared_data;
+static host_shared_data_t *host_shared_data = (host_shared_data_t *) NS_REALM_SHARED_MEM_BASE;
+
+/*
+ * Currently we support only creation of a single Realm in TFTF.
+ * Hence we can assume that Shared area should be sufficient for all
+ * the RECs of this Realm.
+ * TODO: This API will need to change for multi realm support.
+ */
+CASSERT(NS_REALM_SHARED_MEM_SIZE > (MAX_REC_COUNT * sizeof(host_shared_data_t)),
+		too_small_realm_shared_mem_size);
+
 /*
  * Return shared buffer pointer mapped as host_shared_data_t structure
  */
-host_shared_data_t *host_get_shared_structure(void)
+host_shared_data_t *host_get_shared_structure(unsigned int rec_num)
 {
-	return host_shared_data;
-}
-
-/*
- * Set guest mapped shared buffer pointer
- */
-void realm_set_shared_structure(host_shared_data_t *ptr)
-{
-	guest_shared_data = ptr;
-}
-
-/*
- * Get guest mapped shared buffer pointer
- */
-host_shared_data_t *realm_get_shared_structure(void)
-{
-	return guest_shared_data;
+	assert(rec_num < MAX_REC_COUNT);
+	return &host_shared_data[rec_num];
 }
 
 /*
  * Set data to be shared from Host to realm
  */
-void realm_shared_data_set_host_val(uint8_t index, u_register_t val)
+void host_shared_data_set_host_val(unsigned int rec_num, uint8_t index, u_register_t val)
 {
-	host_shared_data->host_param_val[(index >= MAX_DATA_SIZE) ?
-		(MAX_DATA_SIZE - 1) : index] = val;
+	assert(rec_num < MAX_REC_COUNT);
+	assert(index < MAX_DATA_SIZE);
+	host_shared_data[rec_num].host_param_val[index] = val;
 }
 
 /*
- * Set data to be shared from realm to Host
+ * Return data shared by realm in realm_out_val.
  */
-void realm_shared_data_set_realm_val(uint8_t index, u_register_t val)
+u_register_t host_shared_data_get_realm_val(unsigned int rec_num, uint8_t index)
 {
-	host_shared_data->realm_out_val[(index >= MAX_DATA_SIZE) ?
-		(MAX_DATA_SIZE - 1) : index] = val;
-}
-
-/*
- * Return Host's data at index
- */
-u_register_t realm_shared_data_get_host_val(uint8_t index)
-{
-	return guest_shared_data->host_param_val[(index >= MAX_DATA_SIZE) ?
-		(MAX_DATA_SIZE - 1) : index];
-}
-
-/*
- * Return Realm's data at index
- */
-u_register_t realm_shared_data_get_realm_val(uint8_t index)
-{
-	return host_shared_data->realm_out_val[(index >= MAX_DATA_SIZE) ?
-		(MAX_DATA_SIZE - 1) : index];
-}
-
-/*
- * Clear shared realm data
- */
-void realm_shared_data_clear_realm_val(void)
-{
-	(void)memset((char *)host_shared_data->realm_out_val, 0,
-	MAX_DATA_SIZE * sizeof(host_shared_data->realm_out_val[0]));
-}
-
-/*
- * Clear shared Host data
- */
-void realm_shared_data_clear_host_val(void)
-{
-	(void)memset((char *)host_shared_data->host_param_val, 0,
-	MAX_DATA_SIZE * sizeof(host_shared_data->host_param_val[0]));
-}
-
-/*
- * Get command sent from Host to realm
- */
-uint8_t realm_shared_data_get_realm_cmd(void)
-{
-	return guest_shared_data->realm_cmd;
+	assert(rec_num < MAX_REC_COUNT);
+	assert(index < MAX_DATA_SIZE);
+	return host_shared_data[rec_num].realm_out_val[index];
 }
 
 /*
  * Set command to be send from Host to realm
  */
-void realm_shared_data_set_realm_cmd(uint8_t cmd)
+void host_shared_data_set_realm_cmd(uint8_t cmd, unsigned int rec_num)
 {
-	host_shared_data->realm_cmd = cmd;
+	assert(rec_num < MAX_REC_COUNT);
+	host_shared_data[rec_num].realm_cmd = cmd;
 }
+
diff --git a/tftf/tests/runtime_services/realm_payload/host_realm_payload_sve_tests.c b/tftf/tests/runtime_services/realm_payload/host_realm_payload_sve_tests.c
index 8782c9e..358c8bb 100644
--- a/tftf/tests/runtime_services/realm_payload/host_realm_payload_sve_tests.c
+++ b/tftf/tests/runtime_services/realm_payload/host_realm_payload_sve_tests.c
@@ -46,6 +46,7 @@
 static test_result_t host_create_sve_realm_payload(bool sve_en, uint8_t sve_vq)
 {
 	u_register_t feature_flag;
+	u_register_t rec_flag[1] = {RMI_RUNNABLE};
 
 	if (sve_en) {
 		feature_flag = RMI_FEATURE_REGISTER_0_SVE_EN |
@@ -60,7 +61,7 @@
 				       (u_register_t)(PAGE_POOL_MAX_SIZE +
 						      NS_REALM_SHARED_MEM_SIZE),
 				       (u_register_t)PAGE_POOL_MAX_SIZE,
-				       feature_flag)) {
+				       feature_flag, rec_flag, 1U)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -129,14 +130,14 @@
 	}
 
 	realm_rc = host_enter_realm_execute(REALM_SVE_RDVL, NULL,
-					    RMI_EXIT_HOST_CALL);
+					    RMI_EXIT_HOST_CALL, 0U);
 	if (realm_rc != true) {
 		rc = TEST_RESULT_FAIL;
 		goto rm_realm;
 	}
 
 	/* Check if rdvl matches the SVE VL created */
-	sd = host_get_shared_structure();
+	sd = host_get_shared_structure(0U);
 	rl_output = (struct sve_cmd_rdvl *)sd->realm_cmd_output_buffer;
 	rl_max_sve_vq = SVE_VL_TO_VQ(rl_output->rdvl);
 	if (sve_vq == rl_max_sve_vq) {
@@ -205,13 +206,13 @@
 	}
 
 	realm_rc = host_enter_realm_execute(REALM_SVE_ID_REGISTERS, NULL,
-					    RMI_EXIT_HOST_CALL);
+					    RMI_EXIT_HOST_CALL, 0U);
 	if (!realm_rc) {
 		rc = TEST_RESULT_FAIL;
 		goto rm_realm;
 	}
 
-	sd = host_get_shared_structure();
+	sd = host_get_shared_structure(0U);
 	r_regs = (struct sve_cmd_id_regs *)sd->realm_cmd_output_buffer;
 
 	/* Check ID register SVE flags */
@@ -292,13 +293,13 @@
 	vl_bitmap_expected = sve_probe_vl(sve_vq);
 
 	realm_rc = host_enter_realm_execute(REALM_SVE_PROBE_VL, NULL,
-					    RMI_EXIT_HOST_CALL);
+					    RMI_EXIT_HOST_CALL, 0U);
 	if (!realm_rc) {
 		rc = TEST_RESULT_FAIL;
 		goto rm_realm;
 	}
 
-	sd = host_get_shared_structure();
+	sd = host_get_shared_structure(0U);
 	rl_output = (struct sve_cmd_probe_vl *)sd->realm_cmd_output_buffer;
 
 	INFO("Supported SVE vector length in bits (expected):\n");
@@ -353,7 +354,7 @@
 
 		/* Call Realm to run SVE command */
 		realm_rc = host_enter_realm_execute(REALM_SVE_RDVL, NULL,
-						    RMI_EXIT_HOST_CALL);
+						    RMI_EXIT_HOST_CALL, 0U);
 		if (!realm_rc) {
 			ERROR("Realm command REALM_SVE_RDVL failed\n");
 			rc = TEST_RESULT_FAIL;
@@ -384,9 +385,10 @@
  */
 static bool callback_enter_realm(void)
 {
+
 	return !host_enter_realm_execute(REALM_SVE_OPS, NULL,
-					    RMI_EXIT_HOST_CALL);
-	}
+					 RMI_EXIT_HOST_CALL, 0U);
+}
 
 /* Intermittently switch to Realm while doing NS SVE ops */
 test_result_t host_sve_realm_check_vectors_operations(void)
@@ -503,7 +505,7 @@
 
 	/* 4. Call Realm to fill in Z registers */
 	realm_rc = host_enter_realm_execute(REALM_SVE_FILL_REGS, NULL,
-					    RMI_EXIT_HOST_CALL);
+					    RMI_EXIT_HOST_CALL, 0U);
 	if (!realm_rc) {
 		rc = TEST_RESULT_FAIL;
 		goto rm_realm;
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 429b19d..b2bf475 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
@@ -30,6 +30,7 @@
 test_result_t host_test_realm_create_enter(void)
 {
 	bool ret1, ret2;
+	u_register_t rec_flag[1] = {RMI_RUNNABLE};
 
 	SKIP_TEST_IF_RME_NOT_SUPPORTED_OR_RMM_IS_TRP();
 
@@ -37,7 +38,8 @@
 			(u_register_t)PAGE_POOL_BASE,
 			(u_register_t)(PAGE_POOL_MAX_SIZE +
 			NS_REALM_SHARED_MEM_SIZE),
-			(u_register_t)PAGE_POOL_MAX_SIZE, 0UL)) {
+			(u_register_t)PAGE_POOL_MAX_SIZE,
+			0UL, rec_flag, 1U)) {
 		return TEST_RESULT_FAIL;
 	}
 	if (!host_create_shared_mem(NS_REALM_SHARED_MEM_BASE,
@@ -45,8 +47,8 @@
 		return TEST_RESULT_FAIL;
 	}
 
-	realm_shared_data_set_host_val(HOST_SLEEP_INDEX, SLEEP_TIME_MS);
-	ret1 = host_enter_realm_execute(REALM_SLEEP_CMD, NULL, RMI_EXIT_HOST_CALL);
+	host_shared_data_set_host_val(0U, HOST_SLEEP_INDEX, SLEEP_TIME_MS);
+	ret1 = host_enter_realm_execute(REALM_SLEEP_CMD, NULL, RMI_EXIT_HOST_CALL, 0U);
 	ret2 = host_destroy_realm();
 
 	if (!ret1 || !ret2) {
@@ -67,6 +69,7 @@
 	return TEST_RESULT_SKIPPED;
 #else
 	bool ret1, ret2;
+	u_register_t rec_flag[1] = {RMI_RUNNABLE};
 
 	SKIP_TEST_IF_RME_NOT_SUPPORTED_OR_RMM_IS_TRP();
 
@@ -76,7 +79,7 @@
 				(u_register_t)(PAGE_POOL_MAX_SIZE +
 					NS_REALM_SHARED_MEM_SIZE),
 				(u_register_t)PAGE_POOL_MAX_SIZE,
-				0UL)) {
+				0UL, rec_flag, 1U)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -85,11 +88,12 @@
 		return TEST_RESULT_FAIL;
 	}
 
-	ret1 = host_enter_realm_execute(REALM_PAUTH_SET_CMD, NULL, RMI_EXIT_HOST_CALL);
+	ret1 = host_enter_realm_execute(REALM_PAUTH_SET_CMD, NULL, RMI_EXIT_HOST_CALL, 0U);
 
 	if (ret1) {
 		/* Re-enter Realm to compare PAuth registers. */
-		ret1 = host_enter_realm_execute(REALM_PAUTH_CHECK_CMD, NULL, RMI_EXIT_HOST_CALL);
+		ret1 = host_enter_realm_execute(REALM_PAUTH_CHECK_CMD, NULL,
+				RMI_EXIT_HOST_CALL, 0U);
 	}
 
 	ret2 = host_destroy_realm();
@@ -120,6 +124,7 @@
 	return TEST_RESULT_SKIPPED;
 #else
 	bool ret1, ret2;
+	u_register_t rec_flag[1] = {RMI_RUNNABLE};
 
 	SKIP_TEST_IF_RME_NOT_SUPPORTED_OR_RMM_IS_TRP();
 	if (!host_create_realm_payload((u_register_t)REALM_IMAGE_BASE,
@@ -127,7 +132,7 @@
 				(u_register_t)(PAGE_POOL_MAX_SIZE +
 					NS_REALM_SHARED_MEM_SIZE),
 				(u_register_t)PAGE_POOL_MAX_SIZE,
-				0UL)) {
+				0UL, rec_flag, 1U)) {
 		return TEST_RESULT_FAIL;
 	}
 	if (!host_create_shared_mem(NS_REALM_SHARED_MEM_BASE,
@@ -135,7 +140,7 @@
 		return TEST_RESULT_FAIL;
 	}
 
-	ret1 = host_enter_realm_execute(REALM_PAUTH_FAULT, NULL, RMI_EXIT_HOST_CALL);
+	ret1 = host_enter_realm_execute(REALM_PAUTH_FAULT, NULL, RMI_EXIT_HOST_CALL, 0U);
 	ret2 = host_destroy_realm();
 
 	if (!ret1) {
@@ -158,9 +163,10 @@
  *
  * @return true in case of PMU interrupt, false otherwise.
  */
-static bool host_realm_handle_irq_exit(struct realm *realm_ptr)
+static bool host_realm_handle_irq_exit(struct realm *realm_ptr,
+		unsigned int rec_num)
 {
-	struct rmi_rec_run *run = (struct rmi_rec_run *)realm_ptr->run;
+	struct rmi_rec_run *run = (struct rmi_rec_run *)realm_ptr->run[rec_num];
 
 	/* Check PMU overflow status */
 	if (run->exit.pmu_ovf_status == RMI_PMU_OVERFLOW_ACTIVE) {
@@ -184,7 +190,7 @@
 		INFO("Re-entering Realm with vIRQ %lu pending\n", PMU_VIRQ);
 
 		retrmm = host_realm_rec_enter(realm_ptr, &exit_reason,
-						&host_call_result);
+						&host_call_result, rec_num);
 		if ((retrmm == REALM_SUCCESS) &&
 		    (exit_reason == RMI_EXIT_HOST_CALL) &&
 		    (host_call_result == TEST_RESULT_SUCCESS)) {
@@ -209,6 +215,7 @@
 {
 	struct realm *realm_ptr;
 	u_register_t feature_flag;
+	u_register_t rec_flag[1] = {RMI_RUNNABLE};
 	bool ret1, ret2;
 
 	SKIP_TEST_IF_RME_NOT_SUPPORTED_OR_RMM_IS_TRP();
@@ -223,7 +230,7 @@
 			(u_register_t)(PAGE_POOL_MAX_SIZE +
 			NS_REALM_SHARED_MEM_SIZE),
 			(u_register_t)PAGE_POOL_MAX_SIZE,
-			feature_flag)) {
+			feature_flag, rec_flag, 1U)) {
 		return TEST_RESULT_FAIL;
 	}
 	if (!host_create_shared_mem(NS_REALM_SHARED_MEM_BASE,
@@ -231,12 +238,12 @@
 		return TEST_RESULT_FAIL;
 	}
 
-	ret1 = host_enter_realm_execute(cmd, &realm_ptr, RMI_EXIT_IRQ);
+	ret1 = host_enter_realm_execute(cmd, &realm_ptr, RMI_EXIT_IRQ, 0U);
 	if (!ret1 || (cmd != REALM_PMU_INTERRUPT)) {
 		goto test_exit;
 	}
 
-	ret1 = host_realm_handle_irq_exit(realm_ptr);
+	ret1 = host_realm_handle_irq_exit(realm_ptr, 0U);
 
 test_exit:
 	ret2 = host_destroy_realm();
diff --git a/tftf/tests/runtime_services/realm_payload/host_realm_spm.c b/tftf/tests/runtime_services/realm_payload/host_realm_spm.c
index 895a6dd..04c7f7c 100644
--- a/tftf/tests/runtime_services/realm_payload/host_realm_spm.c
+++ b/tftf/tests/runtime_services/realm_payload/host_realm_spm.c
@@ -56,6 +56,7 @@
 static test_result_t init_realm(void)
 {
 	u_register_t retrmm;
+	u_register_t rec_flag[1] = {RMI_RUNNABLE};
 
 	if (get_armv9_2_feat_rme_support() == 0U) {
 		return TEST_RESULT_SKIPPED;
@@ -77,7 +78,7 @@
 			(u_register_t)PAGE_POOL_BASE,
 			(u_register_t)(PAGE_POOL_MAX_SIZE +
 			NS_REALM_SHARED_MEM_SIZE),
-			(u_register_t)PAGE_POOL_MAX_SIZE, 0UL)) {
+			(u_register_t)PAGE_POOL_MAX_SIZE, 0UL, rec_flag, 1U)) {
 		return TEST_RESULT_FAIL;
 	}
 
@@ -92,9 +93,10 @@
 	return TEST_RESULT_SUCCESS;
 }
 
-static bool host_realm_handle_fiq_exit(struct realm *realm_ptr)
+static bool host_realm_handle_fiq_exit(struct realm *realm_ptr,
+		unsigned int rec_num)
 {
-	struct rmi_rec_run *run = (struct rmi_rec_run *)realm_ptr->run;
+	struct rmi_rec_run *run = (struct rmi_rec_run *)realm_ptr->run[rec_num];
 	if (run->exit.exit_reason == RMI_EXIT_FIQ) {
 		return true;
 	}
@@ -137,7 +139,7 @@
 /* Send request to Realm to fill FPU/SIMD regs with realm template values */
 static bool fpu_fill_rl(void)
 {
-	if (!host_enter_realm_execute(REALM_REQ_FPU_FILL_CMD, NULL, RMI_EXIT_HOST_CALL)) {
+	if (!host_enter_realm_execute(REALM_REQ_FPU_FILL_CMD, NULL, RMI_EXIT_HOST_CALL, 0U)) {
 		ERROR("%s failed %d\n", __func__, __LINE__);
 		return false;
 	}
@@ -147,7 +149,7 @@
 /* Send request to Realm to compare FPU/SIMD regs with previous realm template values */
 static bool fpu_cmp_rl(void)
 {
-	if (!host_enter_realm_execute(REALM_REQ_FPU_CMP_CMD, NULL, RMI_EXIT_HOST_CALL)) {
+	if (!host_enter_realm_execute(REALM_REQ_FPU_CMP_CMD, NULL, RMI_EXIT_HOST_CALL, 0U)) {
 		ERROR("%s failed %d\n", __func__, __LINE__);
 		return false;
 	}
@@ -230,13 +232,13 @@
 	 * Spin Realm payload for REALM_TIME_SLEEP ms, This ensures secure wdog
 	 * timer triggers during this time.
 	 */
-	realm_shared_data_set_host_val(HOST_SLEEP_INDEX, REALM_TIME_SLEEP);
-	host_enter_realm_execute(REALM_SLEEP_CMD, &realm_ptr, RMI_EXIT_FIQ);
+	host_shared_data_set_host_val(0U, HOST_SLEEP_INDEX, REALM_TIME_SLEEP);
+	host_enter_realm_execute(REALM_SLEEP_CMD, &realm_ptr, RMI_EXIT_FIQ, 0U);
 
 	/*
 	 * Check if Realm exit reason is FIQ.
 	 */
-	if (!host_realm_handle_fiq_exit(realm_ptr)) {
+	if (!host_realm_handle_fiq_exit(realm_ptr, 0U)) {
 		ERROR("Trusted watchdog timer interrupt not fired\n");
 		host_destroy_realm();
 		return TEST_RESULT_FAIL;