From 7487116b41e6c06d3903b600a2231d2a68d0c4a4 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Thu, 19 Mar 2020 21:55:12 +0530 Subject: [PATCH] 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 Reviewed-by: Atish Patra --- include/sbi/sbi_ecall.h | 10 +++------- include/sbi/sbi_hsm.h | 2 ++ lib/sbi/sbi_ecall.c | 5 ++--- lib/sbi/sbi_ecall_base.c | 11 ++++------- lib/sbi/sbi_ecall_hsm.c | 8 ++++---- lib/sbi/sbi_ecall_legacy.c | 5 +++-- lib/sbi/sbi_ecall_replace.c | 19 ++++++++++--------- lib/sbi/sbi_ecall_vendor.c | 10 ++++------ lib/sbi/sbi_trap.c | 2 +- 9 files changed, 33 insertions(+), 39 deletions(-) diff --git a/include/sbi/sbi_ecall.h b/include/sbi/sbi_ecall.h index 1b564969..0b92e678 100644 --- a/include/sbi/sbi_ecall.h +++ b/include/sbi/sbi_ecall.h @@ -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); diff --git a/include/sbi/sbi_hsm.h b/include/sbi/sbi_hsm.h index f2f39baa..57d41ff0 100644 --- a/include/sbi/sbi_hsm.h +++ b/include/sbi/sbi_hsm.h @@ -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); diff --git a/lib/sbi/sbi_ecall.c b/lib/sbi/sbi_ecall.c index 230dfa36..6c425539 100644 --- a/lib/sbi/sbi_ecall.c +++ b/lib/sbi/sbi_ecall.c @@ -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) diff --git a/lib/sbi/sbi_ecall_base.c b/lib/sbi/sbi_ecall_base.c index 6475745e..1049c806 100644 --- a/lib/sbi/sbi_ecall_base.c +++ b/lib/sbi/sbi_ecall_base.c @@ -14,9 +14,7 @@ #include #include -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; diff --git a/lib/sbi/sbi_ecall_hsm.c b/lib/sbi/sbi_ecall_hsm.c index 5b77726a..028bf68e 100644 --- a/lib/sbi/sbi_ecall_hsm.c +++ b/lib/sbi/sbi_ecall_hsm.c @@ -12,15 +12,15 @@ #include #include #include +#include #include -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: diff --git a/lib/sbi/sbi_ecall_legacy.c b/lib/sbi/sbi_ecall_legacy.c index 70981e47..95f612aa 100644 --- a/lib/sbi/sbi_ecall_legacy.c +++ b/lib/sbi/sbi_ecall_legacy.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -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) { diff --git a/lib/sbi/sbi_ecall_replace.c b/lib/sbi/sbi_ecall_replace.c index 21f3809b..36a5c5c2 100644 --- a/lib/sbi/sbi_ecall_replace.c +++ b/lib/sbi/sbi_ecall_replace.c @@ -14,11 +14,11 @@ #include #include #include +#include #include #include -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; diff --git a/lib/sbi/sbi_ecall_vendor.c b/lib/sbi/sbi_ecall_vendor.c index 70d04469..34c0be68 100644 --- a/lib/sbi/sbi_ecall_vendor.c +++ b/lib/sbi/sbi_ecall_vendor.c @@ -13,21 +13,19 @@ #include #include -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); } diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index b06b33fb..7f8f30f7 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -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: