feat: partition runtime models initial support

This patch adds initial support for specifying runtime model of
a partition. FF-A v1.1 EAC0 spec specifies four runtime models:

1. Runtime model for FFA_RUN
2. Runtime model for FFA_MSG_SEND_DIRECT_REQUEST
3. Runtime model for Secure Interrupt handling
4. Runtime model for SP Initialization

Change-Id: I9361e8217bb92c0f80338663b2edbce8e968a54e
Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
diff --git a/src/arch/aarch64/plat/ffa/spmc.c b/src/arch/aarch64/plat/ffa/spmc.c
index fea68f8..0078d52 100644
--- a/src/arch/aarch64/plat/ffa/spmc.c
+++ b/src/arch/aarch64/plat/ffa/spmc.c
@@ -1548,7 +1548,8 @@
 	return true;
 }
 
-static bool sp_boot_next(struct vcpu *current, struct vcpu **next)
+static bool sp_boot_next(struct vcpu *current, struct vcpu **next,
+			 bool *boot_order_complete)
 {
 	struct vm_locked current_vm_locked;
 	struct vm *vm_next = NULL;
@@ -1564,6 +1565,7 @@
 	if (current_vm_locked.vm->initialized == false) {
 		current_vm_locked.vm->initialized = true;
 		current->is_bootstrapped = true;
+		current->rt_model = RTM_NONE;
 		dlog_verbose("Initialized VM: %#x, boot_order: %u\n",
 			     current_vm_locked.vm->id,
 			     current_vm_locked.vm->boot_order);
@@ -1578,6 +1580,7 @@
 			(*next)->cpu = current->cpu;
 			(*next)->state = VCPU_STATE_RUNNING;
 			(*next)->regs_available = false;
+			(*next)->rt_model = RTM_SP_INIT;
 
 			vm_set_boot_info_gp_reg(vm_next, (*next));
 
@@ -1585,6 +1588,7 @@
 			goto out;
 		}
 
+		*boot_order_complete = true;
 		dlog_verbose("Finished initializing all VMs.\n");
 	}
 
@@ -1596,11 +1600,18 @@
 bool plat_ffa_msg_wait_prepare(struct vcpu *current, struct vcpu **next,
 			       struct ffa_value *ret_args)
 {
-	if (sp_boot_next(current, next)) {
+	bool boot_order_complete = false;
+
+	if (sp_boot_next(current, next, &boot_order_complete)) {
 		*ret_args = (struct ffa_value){.func = FFA_INTERRUPT_32};
 		return true;
 	}
 
+	/* All the SPs have been booted now. Return to NWd. */
+	if (boot_order_complete) {
+		return false;
+	}
+
 	/* Refer FF-A v1.1 Beta0 section 7.4 bullet 2. */
 	if (current->processing_secure_interrupt) {
 		/*
@@ -1622,5 +1633,13 @@
 		return true;
 	}
 
+	/*
+	 * The vCPU of an SP on secondary CPUs will invoke FFA_MSG_WAIT
+	 * to indicate successful initialization to SPMC.
+	 */
+	sl_lock(&current->lock);
+	current->rt_model = RTM_NONE;
+	sl_unlock(&current->lock);
+
 	return false;
 }
diff --git a/src/vcpu.c b/src/vcpu.c
index 87486f2..cb7bcca 100644
--- a/src/vcpu.c
+++ b/src/vcpu.c
@@ -199,6 +199,7 @@
 
 	/* Reset the registers to give a clean start for vCPU. */
 	arch_regs_reset(vcpu);
+	vcpu->rt_model = RTM_SP_INIT;
 }
 
 void vcpu_set_phys_core_idx(struct vcpu *vcpu)