fix: enable VM/SP virtual interrupts at load time

For all secondary VM vCPUs, enable the notification pending virtual
interrupt if requested in the manifest.
For all S-EL1 MP SP vCPUs, enable the NPI and managed exit virtual
interrupts if requested in the manifest.
For a S-EL0 UP SP, enable the virtual interrupts IDs matching the
secure physical interrupt IDs declared in device regions.

Change-Id: I9c2fc3fb9b503442f89e2c15c5b86fdb500ddb45
Reported-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
diff --git a/src/load.c b/src/load.c
index b815e1e..c34120d 100644
--- a/src/load.c
+++ b/src/load.c
@@ -678,6 +678,7 @@
 	const size_t mem_size = pa_difference(mem_begin, mem_end);
 	uint32_t map_mode;
 	bool is_el0_partition = manifest_vm->partition.run_time_el == S_EL0;
+	size_t n;
 
 	/*
 	 * Load the kernel if a filename is specified in the VM manifest.
@@ -809,9 +810,6 @@
 
 	vcpu_locked = vcpu_lock(vcpu);
 
-	/* Enable relevant virtual interrupts for Secure Partitions. */
-	plat_ffa_enable_virtual_interrupts(vcpu_locked, vm_locked);
-
 	if (has_fdt) {
 		vcpu_secondary_reset_and_start(vcpu_locked, secondary_entry,
 					       pa_addr(fdt_addr));
@@ -827,6 +825,22 @@
 
 	vcpu_unlock(&vcpu_locked);
 
+	/*
+	 * For all vCPUs,
+	 * in a VM: enable the notification pending virtual interrupt if
+	 *          requested in the manifest.
+	 * in a SP: enable the NPI and managed exit virtual interrupts if
+	 *          requested in the manifest. For a S-EL0 partition, enable
+	 *          the virtual interrupts IDs matching the secure physical
+	 *          interrupt IDs declared in device regions.
+	 */
+	for (n = 0; n < manifest_vm->secondary.vcpu_count; n++) {
+		vcpu = vm_get_vcpu(vm, n);
+		vcpu_locked = vcpu_lock(vcpu);
+		plat_ffa_enable_virtual_interrupts(vcpu_locked, vm_locked);
+		vcpu_unlock(&vcpu_locked);
+	}
+
 	ret = true;
 
 out: