2018-12-11 21:54:06 +08:00
|
|
|
/*
|
2019-01-24 14:11:10 +08:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
2018-12-11 21:54:06 +08:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anup Patel <anup.patel@wdc.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sbi/sbi_console.h>
|
|
|
|
#include <sbi/sbi_ecall.h>
|
2018-12-26 12:12:26 +08:00
|
|
|
#include <sbi/sbi_ecall_interface.h>
|
2018-12-11 21:54:06 +08:00
|
|
|
#include <sbi/sbi_error.h>
|
|
|
|
#include <sbi/sbi_ipi.h>
|
|
|
|
#include <sbi/sbi_system.h>
|
|
|
|
#include <sbi/sbi_timer.h>
|
|
|
|
#include <sbi/sbi_trap.h>
|
|
|
|
|
2019-04-11 08:41:52 +08:00
|
|
|
#define SBI_ECALL_VERSION_MAJOR 0
|
|
|
|
#define SBI_ECALL_VERSION_MINOR 1
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
u16 sbi_ecall_version_major(void)
|
|
|
|
{
|
|
|
|
return SBI_ECALL_VERSION_MAJOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 sbi_ecall_version_minor(void)
|
|
|
|
{
|
|
|
|
return SBI_ECALL_VERSION_MINOR;
|
|
|
|
}
|
|
|
|
|
2019-04-11 08:41:52 +08:00
|
|
|
int sbi_ecall_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs,
|
2018-12-11 21:54:06 +08:00
|
|
|
struct sbi_scratch *scratch)
|
|
|
|
{
|
|
|
|
int ret = SBI_ENOTSUPP;
|
2019-03-10 04:57:20 +08:00
|
|
|
struct sbi_tlb_info tlb_info;
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
switch (regs->a7) {
|
|
|
|
case SBI_ECALL_SET_TIMER:
|
|
|
|
#if __riscv_xlen == 32
|
2019-01-22 17:17:03 +08:00
|
|
|
sbi_timer_event_start(scratch,
|
2019-04-11 08:41:52 +08:00
|
|
|
(((u64)regs->a1 << 32) | (u64)regs->a0));
|
2018-12-11 21:54:06 +08:00
|
|
|
#else
|
2019-01-22 17:17:03 +08:00
|
|
|
sbi_timer_event_start(scratch, (u64)regs->a0);
|
2018-12-11 21:54:06 +08:00
|
|
|
#endif
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case SBI_ECALL_CONSOLE_PUTCHAR:
|
|
|
|
sbi_putc(regs->a0);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case SBI_ECALL_CONSOLE_GETCHAR:
|
|
|
|
regs->a0 = sbi_getc();
|
2019-04-11 08:41:52 +08:00
|
|
|
ret = 0;
|
2018-12-11 21:54:06 +08:00
|
|
|
break;
|
|
|
|
case SBI_ECALL_CLEAR_IPI:
|
2019-01-22 16:50:59 +08:00
|
|
|
sbi_ipi_clear_smode(scratch);
|
2018-12-11 21:54:06 +08:00
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case SBI_ECALL_SEND_IPI:
|
2019-01-22 16:50:59 +08:00
|
|
|
ret = sbi_ipi_send_many(scratch, (ulong *)regs->a0,
|
2019-03-10 04:57:20 +08:00
|
|
|
SBI_IPI_EVENT_SOFT, NULL);
|
2018-12-11 21:54:06 +08:00
|
|
|
break;
|
|
|
|
case SBI_ECALL_REMOTE_FENCE_I:
|
2019-01-22 16:50:59 +08:00
|
|
|
ret = sbi_ipi_send_many(scratch, (ulong *)regs->a0,
|
2019-03-10 04:57:20 +08:00
|
|
|
SBI_IPI_EVENT_FENCE_I, NULL);
|
2018-12-11 21:54:06 +08:00
|
|
|
break;
|
|
|
|
case SBI_ECALL_REMOTE_SFENCE_VMA:
|
2019-03-10 04:57:20 +08:00
|
|
|
tlb_info.start = (unsigned long)regs->a1;
|
2019-04-11 08:41:52 +08:00
|
|
|
tlb_info.size = (unsigned long)regs->a2;
|
|
|
|
tlb_info.type = SBI_TLB_FLUSH_VMA;
|
2019-03-10 04:57:20 +08:00
|
|
|
|
|
|
|
ret = sbi_ipi_send_many(scratch, (ulong *)regs->a0,
|
|
|
|
SBI_IPI_EVENT_SFENCE_VMA, &tlb_info);
|
|
|
|
break;
|
2018-12-11 21:54:06 +08:00
|
|
|
case SBI_ECALL_REMOTE_SFENCE_VMA_ASID:
|
2019-03-10 04:57:20 +08:00
|
|
|
tlb_info.start = (unsigned long)regs->a1;
|
2019-04-11 08:41:52 +08:00
|
|
|
tlb_info.size = (unsigned long)regs->a2;
|
|
|
|
tlb_info.asid = (unsigned long)regs->a3;
|
|
|
|
tlb_info.type = SBI_TLB_FLUSH_VMA_ASID;
|
2019-03-10 04:57:20 +08:00
|
|
|
|
2019-01-22 16:50:59 +08:00
|
|
|
ret = sbi_ipi_send_many(scratch, (ulong *)regs->a0,
|
2019-04-11 08:41:52 +08:00
|
|
|
SBI_IPI_EVENT_SFENCE_VMA_ASID,
|
|
|
|
&tlb_info);
|
2018-12-11 21:54:06 +08:00
|
|
|
break;
|
|
|
|
case SBI_ECALL_SHUTDOWN:
|
|
|
|
sbi_system_shutdown(scratch, 0);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2019-03-14 02:08:31 +08:00
|
|
|
regs->a0 = SBI_ENOTSUPP;
|
2019-04-11 08:41:52 +08:00
|
|
|
ret = 0;
|
2018-12-11 21:54:06 +08:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
regs->mepc += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|