feat(ipi): introduce IPI paravirtualised interface
Interprocessor Interrupts (IPIs) allow an SP to send an interrupt to
itself on another CPU. This patch starts the implementation of this
feature and enables it for the case where the SP is in the RUNNING
state on the target_vcpu.
Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>
Change-Id: Idd0e1a5863730ae0f169bd0f56ac3abcd2916870
diff --git a/src/arch/aarch64/hypervisor/handler.c b/src/arch/aarch64/hypervisor/handler.c
index 0244eae..107cdab 100644
--- a/src/arch/aarch64/hypervisor/handler.c
+++ b/src/arch/aarch64/hypervisor/handler.c
@@ -23,6 +23,7 @@
#include "hf/dlog.h"
#include "hf/ffa.h"
#include "hf/ffa_internal.h"
+#include "hf/hf_ipi.h"
#include "hf/panic.h"
#include "hf/plat/interrupts.h"
#include "hf/vm.h"
@@ -1086,6 +1087,10 @@
vcpu->regs.r[0] = plat_ffa_interrupt_reconfigure(
args.arg1, args.arg2, args.arg3, vcpu);
break;
+
+ case HF_INTERRUPT_SEND_IPI:
+ vcpu->regs.r[0] = api_hf_interrupt_send_ipi(args.arg1, vcpu);
+ break;
#endif
case HF_INTERRUPT_ENABLE:
vcpu->regs.r[0] = api_interrupt_enable(args.arg1, args.arg2,
diff --git a/src/arch/aarch64/hypervisor/psci_handler.c b/src/arch/aarch64/hypervisor/psci_handler.c
index 5c0ce87..4702301 100644
--- a/src/arch/aarch64/hypervisor/psci_handler.c
+++ b/src/arch/aarch64/hypervisor/psci_handler.c
@@ -215,16 +215,6 @@
}
/**
- * Convert a PSCI CPU / affinity ID for a secondary VM to the corresponding vCPU
- * index.
- */
-ffa_vcpu_index_t vcpu_id_to_index(cpu_id_t vcpu_id)
-{
- /* For now we use indices as IDs for the purposes of PSCI. */
- return vcpu_id;
-}
-
-/**
* Handles PSCI requests received via HVC or SMC instructions from a secondary
* VM.
*
diff --git a/src/arch/aarch64/plat/ffa/spmc.c b/src/arch/aarch64/plat/ffa/spmc.c
index 807d5a5..6eeb82b 100644
--- a/src/arch/aarch64/plat/ffa/spmc.c
+++ b/src/arch/aarch64/plat/ffa/spmc.c
@@ -20,6 +20,7 @@
#include "hf/ffa.h"
#include "hf/ffa_internal.h"
#include "hf/ffa_memory.h"
+#include "hf/hf_ipi.h"
#include "hf/interrupt_desc.h"
#include "hf/plat/interrupts.h"
#include "hf/std.h"
@@ -1448,38 +1449,49 @@
}
}
-static struct vcpu *plat_ffa_find_target_vcpu(struct vcpu *current,
- uint32_t interrupt_id)
+static struct vcpu *plat_ffa_find_target_vcpu_secure_interrupt(
+ struct vcpu *current, uint32_t interrupt_id)
{
- bool target_vm_found = false;
- struct vm *vm;
- struct vcpu *target_vcpu;
- struct interrupt_descriptor int_desc;
-
/*
- * Find which VM/SP owns this interrupt. We then find the corresponding
- * vCPU context for this CPU.
+ * Find which VM/SP owns this interrupt. We then find the
+ * corresponding vCPU context for this CPU.
*/
for (ffa_vm_count_t index = 0; index < vm_get_count(); ++index) {
- vm = vm_find_index(index);
+ struct vm *vm = vm_find_index(index);
for (uint32_t j = 0; j < HF_NUM_INTIDS; j++) {
- int_desc = vm->interrupt_desc[j];
+ struct interrupt_descriptor int_desc =
+ vm->interrupt_desc[j];
- /* Interrupt descriptors are populated contiguously. */
+ /*
+ * Interrupt descriptors are populated
+ * contiguously.
+ */
if (!int_desc.valid) {
break;
}
if (int_desc.interrupt_id == interrupt_id) {
- target_vm_found = true;
- goto out;
+ return api_ffa_get_vm_vcpu(vm, current);
}
}
}
-out:
- CHECK(target_vm_found);
- target_vcpu = api_ffa_get_vm_vcpu(vm, current);
+ return NULL;
+}
+
+static struct vcpu *plat_ffa_find_target_vcpu(struct vcpu *current,
+ uint32_t interrupt_id)
+{
+ struct vcpu *target_vcpu;
+
+ switch (interrupt_id) {
+ case HF_IPI_INTID:
+ target_vcpu = hf_ipi_get_pending_target_vcpu(current->cpu);
+ break;
+ default:
+ target_vcpu = plat_ffa_find_target_vcpu_secure_interrupt(
+ current, interrupt_id);
+ }
/* The target vCPU for a secure interrupt cannot be NULL. */
CHECK(target_vcpu != NULL);
@@ -1866,26 +1878,38 @@
/* Resume current vCPU. */
*next = NULL;
} else {
- /*
- * Do not currently support nested interrupts as such, masking
- * interrupts.
- */
- plat_ffa_mask_interrupts(target_vcpu_locked);
-
/* Set the interrupt pending in the target vCPU. */
vcpu_interrupt_inject(target_vcpu_locked, intid);
- /*
- * Either invoke the handler related to partitions from S-EL0 or
- * from S-EL1.
- */
- *next = target_vcpu_locked.vcpu->vm->el0_partition
- ? plat_ffa_signal_secure_interrupt_sel0(
- current_locked, target_vcpu_locked,
- intid)
- : plat_ffa_signal_secure_interrupt_sel1(
- current_locked, target_vcpu_locked,
- intid);
+ switch (intid) {
+ case HF_IPI_INTID:
+ if (hf_ipi_handle(target_vcpu_locked)) {
+ *next = NULL;
+ break;
+ }
+ /*
+ * Fall through in the case handling has not been fully
+ * completed.
+ */
+ default:
+ /*
+ * Do not currently support nested interrupts as such,
+ * masking interrupts.
+ */
+ plat_ffa_mask_interrupts(target_vcpu_locked);
+
+ /*
+ * Either invoke the handler related to partitions from
+ * S-EL0 or from S-EL1.
+ */
+ *next = target_vcpu_locked.vcpu->vm->el0_partition
+ ? plat_ffa_signal_secure_interrupt_sel0(
+ current_locked,
+ target_vcpu_locked, intid)
+ : plat_ffa_signal_secure_interrupt_sel1(
+ current_locked,
+ target_vcpu_locked, intid);
+ }
}
if (target_vcpu_locked.vcpu != NULL) {
diff --git a/src/arch/aarch64/plat/psci/spmc.c b/src/arch/aarch64/plat/psci/spmc.c
index 7f9fb01..18f910b 100644
--- a/src/arch/aarch64/plat/psci/spmc.c
+++ b/src/arch/aarch64/plat/psci/spmc.c
@@ -13,6 +13,7 @@
#include "hf/check.h"
#include "hf/cpu.h"
#include "hf/dlog.h"
+#include "hf/hf_ipi.h"
#include "hf/vm.h"
#include "vmapi/hf/types.h"
@@ -74,6 +75,8 @@
arch_cpu_init(c);
+ /* Initialize IPI for running core. */
+ hf_ipi_init_interrupt();
/* Initialize SRI for running core. */
plat_ffa_sri_init(c);