refactor: set vcpu in preempted state

The function `vcpu_set_processing_interrupt` is refactored
to set the preempted vcpu state as `VCPU_STATE_PREEMPTED`.

This refactor opens the possibility to drop other instances
in which the `VCPU_STATE_PREEMPTED` is used.
This is completed in the subsequent patches.

Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I02f5d92e15aa850b73ededea37fd7fbe5ba41a52
diff --git a/src/arch/aarch64/plat/ffa/spmc.c b/src/arch/aarch64/plat/ffa/spmc.c
index 66828ff..0f96354 100644
--- a/src/arch/aarch64/plat/ffa/spmc.c
+++ b/src/arch/aarch64/plat/ffa/spmc.c
@@ -1480,7 +1480,7 @@
 						    .arg2 = intid});
 
 		vcpu_set_processing_interrupt(target_vcpu_locked, intid,
-					      current_locked.vcpu);
+					      current_locked);
 
 		/* Switch to target vCPU responsible for this interrupt. */
 		next = target_vcpu;
@@ -1502,7 +1502,9 @@
 		plat_interrupts_end_of_interrupt(intid);
 		target_vcpu->secure_interrupt_deactivated = true;
 
-		vcpu_set_processing_interrupt(target_vcpu_locked, intid, NULL);
+		vcpu_set_processing_interrupt(
+			target_vcpu_locked, intid,
+			(struct vcpu_locked){.vcpu = NULL});
 		break;
 	case VCPU_STATE_RUNNING:
 		/*
@@ -1510,8 +1512,9 @@
 		 * target vCPU that is in RUNNING state on another physical CPU.
 		 */
 		if (current_locked.vcpu == target_vcpu_locked.vcpu) {
-			vcpu_set_processing_interrupt(target_vcpu_locked, intid,
-						      NULL);
+			vcpu_set_processing_interrupt(
+				target_vcpu_locked, intid,
+				(struct vcpu_locked){.vcpu = NULL});
 			next = NULL;
 			break;
 		}
@@ -1558,7 +1561,7 @@
 			current->state = VCPU_STATE_PREEMPTED;
 		}
 		vcpu_set_processing_interrupt(target_vcpu_locked, intid,
-					      current);
+					      current_locked);
 		next = target_vcpu;
 		break;
 	case VCPU_STATE_BLOCKED:
@@ -1605,7 +1608,7 @@
 					 });
 
 			vcpu_set_processing_interrupt(target_vcpu_locked, intid,
-						      current);
+						      current_locked);
 
 			next = target_vcpu;
 			break;
@@ -1646,7 +1649,9 @@
 		 */
 		target_vcpu->implicit_completion_signal = true;
 
-		vcpu_set_processing_interrupt(target_vcpu_locked, intid, NULL);
+		vcpu_set_processing_interrupt(
+			target_vcpu_locked, intid,
+			(struct vcpu_locked){.vcpu = NULL});
 		break;
 	case VCPU_STATE_RUNNING:
 		if (current == target_vcpu) {
@@ -1666,8 +1671,9 @@
 			 * If the target vCPU is the running vCPU, no other
 			 * context needs to be resumed on interrupt completion.
 			 */
-			vcpu_set_processing_interrupt(target_vcpu_locked, intid,
-						      NULL);
+			vcpu_set_processing_interrupt(
+				target_vcpu_locked, intid,
+				(struct vcpu_locked){.vcpu = NULL});
 			break;
 		}
 	case VCPU_STATE_BLOCKED_INTERRUPT:
diff --git a/src/vcpu.c b/src/vcpu.c
index 68be2e9..ca0728f 100644
--- a/src/vcpu.c
+++ b/src/vcpu.c
@@ -317,11 +317,16 @@
 }
 
 void vcpu_set_processing_interrupt(struct vcpu_locked vcpu_locked,
-				   uint32_t intid, struct vcpu *preempted)
+				   uint32_t intid,
+				   struct vcpu_locked preempted_locked)
 {
 	struct vcpu *target_vcpu = vcpu_locked.vcpu;
 
-	target_vcpu->preempted_vcpu = preempted;
+	if (preempted_locked.vcpu != NULL) {
+		target_vcpu->preempted_vcpu = preempted_locked.vcpu;
+		preempted_locked.vcpu->state = VCPU_STATE_PREEMPTED;
+	}
+
 	target_vcpu->processing_secure_interrupt = true;
 	target_vcpu->current_sec_interrupt_id = intid;
 }