lib: sbi_ecall: Remove mcause, scratch and hartid parameters

We remove mcause, scratch and hartid parameters from various
functions for ecall handling because we can always get current
HART id and current scratch pointer using just one CSR access.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
Anup Patel
2020-03-19 21:55:12 +05:30
committed by Anup Patel
parent fe37d7da29
commit 7487116b41
9 changed files with 33 additions and 39 deletions

View File

@@ -19,16 +19,13 @@
struct sbi_trap_regs;
struct sbi_trap_info;
struct sbi_scratch;
struct sbi_ecall_extension {
struct sbi_dlist head;
unsigned long extid_start;
unsigned long extid_end;
int (* probe)(struct sbi_scratch *scratch,
unsigned long extid, unsigned long *out_val);
int (* handle)(struct sbi_scratch *scratch,
unsigned long extid, unsigned long funcid,
int (* probe)(unsigned long extid, unsigned long *out_val);
int (* handle)(unsigned long extid, unsigned long funcid,
unsigned long *args, unsigned long *out_val,
struct sbi_trap_info *out_trap);
};
@@ -51,8 +48,7 @@ int sbi_ecall_register_extension(struct sbi_ecall_extension *ext);
void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext);
int sbi_ecall_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs,
struct sbi_scratch *scratch);
int sbi_ecall_handler(struct sbi_trap_regs *regs);
int sbi_ecall_init(void);

View File

@@ -19,6 +19,8 @@
#define SBI_HART_STARTED 3
#define SBI_HART_UNKNOWN 4
struct sbi_scratch;
int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot);
void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch);

View File

@@ -79,8 +79,7 @@ void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)
sbi_list_del_init(&ext->head);
}
int sbi_ecall_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs,
struct sbi_scratch *scratch)
int sbi_ecall_handler(struct sbi_trap_regs *regs)
{
int ret = 0;
struct sbi_ecall_extension *ext;
@@ -100,7 +99,7 @@ int sbi_ecall_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs,
ext = sbi_ecall_find_extension(extension_id);
if (ext && ext->handle) {
ret = ext->handle(scratch, extension_id, func_id,
ret = ext->handle(extension_id, func_id,
args, &out_val, &trap);
if (extension_id >= SBI_EXT_0_1_SET_TIMER &&
extension_id <= SBI_EXT_0_1_SHUTDOWN)

View File

@@ -14,9 +14,7 @@
#include <sbi/sbi_version.h>
#include <sbi/riscv_asm.h>
static int sbi_ecall_base_probe(struct sbi_scratch *scratch,
unsigned long extid,
unsigned long *out_val)
static int sbi_ecall_base_probe(unsigned long extid, unsigned long *out_val)
{
struct sbi_ecall_extension *ext;
@@ -27,14 +25,13 @@ static int sbi_ecall_base_probe(struct sbi_scratch *scratch,
}
if (ext->probe)
return ext->probe(scratch, extid, out_val);
return ext->probe(extid, out_val);
*out_val = 1;
return 0;
}
static int sbi_ecall_base_handler(struct sbi_scratch *scratch,
unsigned long extid, unsigned long funcid,
static int sbi_ecall_base_handler(unsigned long extid, unsigned long funcid,
unsigned long *args, unsigned long *out_val,
struct sbi_trap_info *out_trap)
{
@@ -64,7 +61,7 @@ static int sbi_ecall_base_handler(struct sbi_scratch *scratch,
*out_val = csr_read(CSR_MIMPID);
break;
case SBI_EXT_BASE_PROBE_EXT:
ret = sbi_ecall_base_probe(scratch, args[0], out_val);
ret = sbi_ecall_base_probe(args[0], out_val);
break;
default:
ret = SBI_ENOTSUPP;

View File

@@ -12,15 +12,15 @@
#include <sbi/sbi_error.h>
#include <sbi/sbi_version.h>
#include <sbi/sbi_hsm.h>
#include <sbi/sbi_scratch.h>
#include <sbi/riscv_asm.h>
static int sbi_ecall_hsm_handler(struct sbi_scratch *scratch,
unsigned long extid, unsigned long funcid,
static int sbi_ecall_hsm_handler(unsigned long extid, unsigned long funcid,
unsigned long *args, unsigned long *out_val,
struct sbi_trap_info *out_trap)
{
int ret = 0;
int hstate;
int ret = 0, hstate;
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
switch (funcid) {
case SBI_EXT_HSM_HART_START:

View File

@@ -15,6 +15,7 @@
#include <sbi/sbi_error.h>
#include <sbi/sbi_hsm.h>
#include <sbi/sbi_ipi.h>
#include <sbi/sbi_scratch.h>
#include <sbi/sbi_system.h>
#include <sbi/sbi_timer.h>
#include <sbi/sbi_tlb.h>
@@ -39,14 +40,14 @@ static int sbi_load_hart_mask_unpriv(ulong *pmask, ulong *hmask,
return 0;
}
static int sbi_ecall_legacy_handler(struct sbi_scratch *scratch,
unsigned long extid, unsigned long funcid,
static int sbi_ecall_legacy_handler(unsigned long extid, unsigned long funcid,
unsigned long *args, unsigned long *out_val,
struct sbi_trap_info *out_trap)
{
int ret = 0;
struct sbi_tlb_info tlb_info;
u32 source_hart = current_hartid();
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
ulong hmask = 0;
switch (extid) {

View File

@@ -14,11 +14,11 @@
#include <sbi/sbi_error.h>
#include <sbi/sbi_hart.h>
#include <sbi/sbi_ipi.h>
#include <sbi/sbi_scratch.h>
#include <sbi/sbi_timer.h>
#include <sbi/sbi_tlb.h>
static int sbi_ecall_time_handler(struct sbi_scratch *scratch,
unsigned long extid, unsigned long funcid,
static int sbi_ecall_time_handler(unsigned long extid, unsigned long funcid,
unsigned long *args, unsigned long *out_val,
struct sbi_trap_info *out_trap)
{
@@ -26,10 +26,11 @@ static int sbi_ecall_time_handler(struct sbi_scratch *scratch,
if (funcid == SBI_EXT_TIME_SET_TIMER) {
#if __riscv_xlen == 32
sbi_timer_event_start(scratch,
sbi_timer_event_start(sbi_scratch_thishart_ptr(),
(((u64)args[1] << 32) | (u64)args[0]));
#else
sbi_timer_event_start(scratch, (u64)args[0]);
sbi_timer_event_start(sbi_scratch_thishart_ptr(),
(u64)args[0]);
#endif
} else
ret = SBI_ENOTSUPP;
@@ -43,14 +44,14 @@ struct sbi_ecall_extension ecall_time = {
.handle = sbi_ecall_time_handler,
};
static int sbi_ecall_rfence_handler(struct sbi_scratch *scratch,
unsigned long extid, unsigned long funcid,
static int sbi_ecall_rfence_handler(unsigned long extid, unsigned long funcid,
unsigned long *args, unsigned long *out_val,
struct sbi_trap_info *out_trap)
{
int ret = 0;
struct sbi_tlb_info tlb_info;
u32 source_hart = current_hartid();
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
if (funcid >= SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA &&
funcid <= SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID)
@@ -106,15 +107,15 @@ struct sbi_ecall_extension ecall_rfence = {
.handle = sbi_ecall_rfence_handler,
};
static int sbi_ecall_ipi_handler(struct sbi_scratch *scratch,
unsigned long extid, unsigned long funcid,
static int sbi_ecall_ipi_handler(unsigned long extid, unsigned long funcid,
unsigned long *args, unsigned long *out_val,
struct sbi_trap_info *out_trap)
{
int ret = 0;
if (funcid == SBI_EXT_IPI_SEND_IPI)
ret = sbi_ipi_send_smode(scratch, args[0], args[1]);
ret = sbi_ipi_send_smode(sbi_scratch_thishart_ptr(),
args[0], args[1]);
else
ret = SBI_ENOTSUPP;

View File

@@ -13,21 +13,19 @@
#include <sbi/sbi_error.h>
#include <sbi/sbi_platform.h>
static int sbi_ecall_vendor_probe(struct sbi_scratch *scratch,
unsigned long extid,
static int sbi_ecall_vendor_probe(unsigned long extid,
unsigned long *out_val)
{
*out_val = sbi_platform_vendor_ext_check(sbi_platform_ptr(scratch),
*out_val = sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr(),
extid);
return 0;
}
static int sbi_ecall_vendor_handler(struct sbi_scratch *scratch,
unsigned long extid, unsigned long funcid,
static int sbi_ecall_vendor_handler(unsigned long extid, unsigned long funcid,
unsigned long *args, unsigned long *out_val,
struct sbi_trap_info *out_trap)
{
return sbi_platform_vendor_ext_provider(sbi_platform_ptr(scratch),
return sbi_platform_vendor_ext_provider(sbi_platform_thishart_ptr(),
extid, funcid, args,
out_val, out_trap);
}

View File

@@ -256,7 +256,7 @@ void sbi_trap_handler(struct sbi_trap_regs *regs,
break;
case CAUSE_SUPERVISOR_ECALL:
case CAUSE_HYPERVISOR_ECALL:
rc = sbi_ecall_handler(hartid, mcause, regs, scratch);
rc = sbi_ecall_handler(regs);
msg = "ecall handler failed";
break;
default: