From: Anup Patel Date: Fri, 20 Mar 2020 03:23:35 +0000 (+0530) Subject: lib: sbi_trap: Simplify sbi_trap_handler() API X-Git-Tag: v1.3~782 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=40b221baffd6bb348b63367784d4f6fcff53c24a;p=platform%2Fkernel%2Fopensbi-spacemit.git lib: sbi_trap: Simplify sbi_trap_handler() API This patch simplify sbi_trap_handler() API as follows: 1. Remove current hartid local variable because sbi_trap_handler() itself does not need it. 2. Remove scratch parameter because none of the functions directly called by sbi_trap_handler() require it. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- diff --git a/firmware/fw_base.S b/firmware/fw_base.S index d2aca98..cc6381d 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -556,7 +556,6 @@ _skip_mstatush_save: /* Call C routine */ add a0, sp, zero - csrr a1, CSR_MSCRATCH call sbi_trap_handler /* Restore all general regisers except SP and T0 */ diff --git a/include/sbi/sbi_trap.h b/include/sbi/sbi_trap.h index 54ccea7..5d0962f 100644 --- a/include/sbi/sbi_trap.h +++ b/include/sbi/sbi_trap.h @@ -202,13 +202,10 @@ struct sbi_trap_info { unsigned long tinst; }; -struct sbi_scratch; - int sbi_trap_redirect(struct sbi_trap_regs *regs, struct sbi_trap_info *trap); -void sbi_trap_handler(struct sbi_trap_regs *regs, - struct sbi_scratch *scratch); +void sbi_trap_handler(struct sbi_trap_regs *regs); #endif diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 7f8f30f..32fa699 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -16,13 +16,16 @@ #include #include #include +#include #include #include -static void __noreturn sbi_trap_error(const char *msg, int rc, u32 hartid, +static void __noreturn sbi_trap_error(const char *msg, int rc, ulong mcause, ulong mtval, ulong mtval2, ulong mtinst, struct sbi_trap_regs *regs) { + u32 hartid = current_hartid(); + sbi_printf("%s: hart%d: %s (error %d)\n", __func__, hartid, msg, rc); sbi_printf("%s: hart%d: mcause=0x%" PRILX " mtval=0x%" PRILX "\n", __func__, hartid, mcause, mtval); @@ -208,14 +211,11 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, * 7. Interrupts are disabled in MSTATUS CSR * * @param regs pointer to register state - * @param scratch pointer to sbi_scratch of current HART */ -void sbi_trap_handler(struct sbi_trap_regs *regs, - struct sbi_scratch *scratch) +void sbi_trap_handler(struct sbi_trap_regs *regs) { int rc = SBI_ENOTSUPP; const char *msg = "trap handler failed"; - u32 hartid = current_hartid(); ulong mcause = csr_read(CSR_MCAUSE); ulong mtval = csr_read(CSR_MTVAL), mtval2 = 0, mtinst = 0; struct sbi_trap_info trap; @@ -229,10 +229,10 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, mcause &= ~(1UL << (__riscv_xlen - 1)); switch (mcause) { case IRQ_M_TIMER: - sbi_timer_process(scratch); + sbi_timer_process(sbi_scratch_thishart_ptr()); break; case IRQ_M_SOFT: - sbi_ipi_process(scratch); + sbi_ipi_process(sbi_scratch_thishart_ptr()); break; default: msg = "unhandled external interrupt"; @@ -271,8 +271,6 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, }; trap_error: - if (rc) { - sbi_trap_error(msg, rc, hartid, mcause, mtval, - mtval2, mtinst, regs); - } + if (rc) + sbi_trap_error(msg, rc, mcause, mtval, mtval2, mtinst, regs); }