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/inc/hf/api.h b/inc/hf/api.h
index f34d61c..b6234c9 100644
--- a/inc/hf/api.h
+++ b/inc/hf/api.h
@@ -49,7 +49,8 @@
 				    uint32_t intid,
 				    struct vcpu_locked current_locked,
 				    struct vcpu **next);
-void api_sri_send_if_delayed(struct vcpu *current);
+uint64_t api_hf_interrupt_send_ipi(uint32_t target_vcpu_id,
+				   struct vcpu *current);
 
 struct ffa_value api_ffa_msg_send(ffa_id_t sender_vm_id,
 				  ffa_id_t receiver_vm_id, uint32_t size,
diff --git a/inc/hf/cpu.h b/inc/hf/cpu.h
index ac1f7d5..3d7a35c 100644
--- a/inc/hf/cpu.h
+++ b/inc/hf/cpu.h
@@ -31,6 +31,9 @@
 
 	/* In case there is a pending SRI for the NWd. */
 	bool is_sri_delayed;
+
+	/* Track pending IPIs. */
+	struct vcpu *ipi_target_vcpu;
 };
 
 void cpu_module_init(const cpu_id_t *cpu_ids, size_t count);
diff --git a/inc/hf/hf_ipi.h b/inc/hf/hf_ipi.h
new file mode 100644
index 0000000..dd40b84
--- /dev/null
+++ b/inc/hf/hf_ipi.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2024 The Hafnium Authors.
+ *
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file or at
+ * https://opensource.org/licenses/BSD-3-Clause.
+ */
+
+#pragma once
+
+#include "hf/types.h"
+#include "hf/vcpu.h"
+#include "hf/vm.h"
+
+void hf_ipi_init_interrupt(void);
+struct vcpu *hf_ipi_get_pending_target_vcpu(struct cpu *current);
+void hf_ipi_send_interrupt(struct vm *vm, ffa_vcpu_index_t target_vcpu_index);
+bool hf_ipi_handle(struct vcpu_locked target_vcpu_locked);
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index 64df9f4..5bcb30c 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -395,6 +395,15 @@
 	return vm->id == HF_PRIMARY_VM_ID;
 }
 
+/**
+ * Convert a CPU ID for a secondary VM to the corresponding vCPU index.
+ */
+static inline ffa_vcpu_index_t vcpu_id_to_index(cpu_id_t vcpu_id)
+{
+	/* For now we use indices as IDs. */
+	return vcpu_id;
+}
+
 struct interrupt_descriptor *vm_interrupt_set_target_mpidr(
 	struct vm_locked vm_locked, uint32_t id, uint32_t target_mpidr);
 struct interrupt_descriptor *vm_interrupt_set_sec_state(