VisionFive2 OpenSBI

StarFive Tech OpenSBI for VisionFive (JH7110) boards (mirror)

1266 Commits   10 Branches   49 Tags
author: andy.hu <andy.hu@starfivetech.com> 2024-05-31 08:24:17 +0000 committer: andy.hu <andy.hu@starfivetech.com> 2024-05-31 08:24:17 +0000 commit: d5e88252154dc08ddb13f326a3d765a051215fab parent: c6a092cd80112529cb2e92e180767ff5341b22a3
Commit Summary:
Merge branch 'CR_10877_IPI_AMP_minda' into 'master'
Diffstat:
4 files changed, 36 insertions, 1 deletion
diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
index 4597358..029345a 100644
--- a/include/sbi/sbi_ecall_interface.h
+++ b/include/sbi/sbi_ecall_interface.h
@@ -46,6 +46,9 @@
 
 /* SBI function IDs for IPI extension*/
 #define SBI_EXT_IPI_SEND_IPI			0x0
+#define SBI_EXT_IPI_SEND_EXT_DOMAIN		0x100
+#define SBI_EXT_IPI_SET_AMP_DATA_ADDR		0x101
+#define SBI_EXT_IPI_CLEAR_IPI			0x102
 
 /* SBI function IDs for RFENCE extension*/
 #define SBI_EXT_RFENCE_REMOTE_FENCE_I		0x0
diff --git a/include/sbi/sbi_ipi.h b/include/sbi/sbi_ipi.h
index f384e74..0dc60f8 100644
--- a/include/sbi/sbi_ipi.h
+++ b/include/sbi/sbi_ipi.h
@@ -68,6 +68,9 @@ int sbi_ipi_event_create(const struct sbi_ipi_event_ops *ops);
 void sbi_ipi_event_destroy(u32 event);
 
 int sbi_ipi_send_smode(ulong hmask, ulong hbase);
+int sbi_ipi_send_ext(u32 linux_amp_type, u32 hartid, u32 msg_bits);
+void sbi_ipi_set_amp_data_addr(unsigned long addr);
+void sbi_ipi_clear_ext_ipi(unsigned long addr);
 
 void sbi_ipi_clear_smode(void);
 
diff --git a/lib/sbi/sbi_ecall_ipi.c b/lib/sbi/sbi_ecall_ipi.c
index f4797e1..06dc60e 100644
--- a/lib/sbi/sbi_ecall_ipi.c
+++ b/lib/sbi/sbi_ecall_ipi.c
@@ -13,6 +13,7 @@
 #include <sbi/sbi_ecall_interface.h>
 #include <sbi/sbi_trap.h>
 #include <sbi/sbi_ipi.h>
+#include <sbi/sbi_console.h>
 
 static int sbi_ecall_ipi_handler(unsigned long extid, unsigned long funcid,
 				 const struct sbi_trap_regs *regs,
@@ -23,6 +24,12 @@ static int sbi_ecall_ipi_handler(unsigned long extid, unsigned long funcid,
 
 	if (funcid == SBI_EXT_IPI_SEND_IPI)
 		ret = sbi_ipi_send_smode(regs->a0, regs->a1);
+	else if (funcid == SBI_EXT_IPI_SEND_EXT_DOMAIN)
+		ret = sbi_ipi_send_ext(regs->a0, regs->a1, regs->a2);
+	else if (funcid == SBI_EXT_IPI_SET_AMP_DATA_ADDR)
+		sbi_ipi_set_amp_data_addr(regs->a0);
+	else if (funcid == SBI_EXT_IPI_CLEAR_IPI)
+		sbi_ipi_clear_ext_ipi(regs->a0);
 	else
 		ret = SBI_ENOTSUPP;
 
diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c
index b9f6205..49a3ae5 100644
--- a/lib/sbi/sbi_ipi.c
+++ b/lib/sbi/sbi_ipi.c
@@ -11,6 +11,7 @@
 #include <sbi/riscv_asm.h>
 #include <sbi/riscv_atomic.h>
 #include <sbi/riscv_barrier.h>
+#include <sbi/sbi_console.h>
 #include <sbi/sbi_bitops.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
@@ -150,7 +151,7 @@ static struct sbi_ipi_event_ops ipi_smode_ops = {
 };
 
 static u32 ipi_smode_event = SBI_IPI_EVENT_MAX;
-
+static unsigned long* amp_data_addr;
 int sbi_ipi_send_smode(ulong hmask, ulong hbase)
 {
 	return sbi_ipi_send_many(hmask, hbase, ipi_smode_event, NULL);
@@ -161,6 +162,34 @@ void sbi_ipi_clear_smode(void)
 	csr_clear(CSR_MIP, MIP_SSIP);
 }
 
+int sbi_ipi_send_ext(u32 type, u32 hartid, u32 msg_bits)
+{
+	if (!amp_data_addr)
+		return SBI_EINVAL;
+
+	atomic_raw_set_bit(msg_bits, (void *)(amp_data_addr + hartid));
+
+	return sbi_ipi_send(sbi_scratch_thishart_ptr(), hartid, ipi_smode_event, NULL);
+}
+
+void sbi_ipi_set_amp_data_addr(unsigned long addr)
+{
+	amp_data_addr = (void *)addr;
+}
+
+void sbi_ipi_clear_ext_ipi(unsigned long addr)
+{
+	unsigned long msg_type;
+
+	if (!amp_data_addr)
+		return;
+
+	msg_type = atomic_raw_xchg_ulong(amp_data_addr + current_hartid(), 0);
+	*(unsigned long *)addr = msg_type;
+
+	sbi_ipi_clear_smode();
+}
+
 static void sbi_ipi_process_halt(struct sbi_scratch *scratch)
 {
 	sbi_hsm_hart_stop(scratch, true);