lib: sbi_trap: Simplify sbi_trap_handler() API
authorAnup Patel <anup.patel@wdc.com>
Fri, 20 Mar 2020 03:23:35 +0000 (08:53 +0530)
committerAnup Patel <anup@brainfault.org>
Sat, 28 Mar 2020 08:02:23 +0000 (13:32 +0530)
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 <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
firmware/fw_base.S
include/sbi/sbi_trap.h
lib/sbi/sbi_trap.c

index d2aca98..cc6381d 100644 (file)
@@ -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 */
index 54ccea7..5d0962f 100644 (file)
@@ -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
 
index 7f8f30f..32fa699 100644 (file)
 #include <sbi/sbi_illegal_insn.h>
 #include <sbi/sbi_ipi.h>
 #include <sbi/sbi_misaligned_ldst.h>
+#include <sbi/sbi_scratch.h>
 #include <sbi/sbi_timer.h>
 #include <sbi/sbi_trap.h>
 
-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);
 }