feat: adapt vcpu operational mode to interpret newly added states

With a set of newly introduced states for a vCPU to allow fine grain
tracking of lifecycle of a partition, we have to slightly extend the
notion of a vCPU being ON and OFF.

This patch adds necessary support and refactors helpers to interpret
if a vCPU is in ON or OFF from a operational mode perspective. For
example, VCPU_STATE_STARTING is also considered as OFF since partition
manager has not yet scheduled the vCPU on a physical CPU.

Change-Id: I03aeca4ecb83c28e6cb7897ad0e2a51b315e16b0
Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
diff --git a/src/vcpu.c b/src/vcpu.c
index 522973d..ba52d3b 100644
--- a/src/vcpu.c
+++ b/src/vcpu.c
@@ -79,12 +79,12 @@
 
 /**
  * Initialise the registers for the given vCPU and set the state to
- * VCPU_STATE_WAITING. The caller must hold the vCPU lock while calling this.
+ * VCPU_STATE_CREATED. The caller must hold the vCPU lock while calling this.
  */
-void vcpu_on(struct vcpu_locked vcpu, ipaddr_t entry, uintreg_t arg)
+void vcpu_prepare(struct vcpu_locked vcpu, ipaddr_t entry, uintreg_t arg)
 {
 	arch_regs_set_pc_arg(&vcpu.vcpu->regs, entry, arg);
-	vcpu.vcpu->state = VCPU_STATE_WAITING;
+	vcpu.vcpu->state = VCPU_STATE_CREATED;
 }
 
 ffa_vcpu_index_t vcpu_index(const struct vcpu *vcpu)
@@ -101,10 +101,14 @@
  * purposes of PSCI, because according to the PSCI specification (section
  * 5.7.1) a core is only considered to be off if it has been turned off
  * with a CPU_OFF call or hasn't yet been turned on with a CPU_ON call.
+ * Note that vCPU is considered to be off until it makes the transition
+ * to STARTING state.
  */
 bool vcpu_is_off(struct vcpu_locked vcpu)
 {
-	return (vcpu.vcpu->state == VCPU_STATE_OFF);
+	return (vcpu.vcpu->state == VCPU_STATE_OFF ||
+		vcpu.vcpu->state == VCPU_STATE_CREATED ||
+		vcpu.vcpu->state == VCPU_STATE_NULL);
 }
 
 /**
@@ -130,7 +134,7 @@
 		 * pCPU it is running on.
 		 */
 		arch_regs_reset(vcpu_locked.vcpu);
-		vcpu_on(vcpu_locked, entry, arg);
+		vcpu_prepare(vcpu_locked, entry, arg);
 	}
 
 	return vcpu_was_off;