include: sbi_timer: Remove scratch parameter from most funcitons

This patch removes scratch parameter from most sbi_timer functions.

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-27 12:08:34 +05:30 committed by Anup Patel
parent ec0d80f5b4
commit 0a28ea54dc
6 changed files with 52 additions and 45 deletions

View file

@ -14,22 +14,31 @@
struct sbi_scratch;
u64 sbi_timer_value(struct sbi_scratch *scratch);
/** Get timer value for current HART */
u64 sbi_timer_value(void);
u64 sbi_timer_virt_value(struct sbi_scratch *scratch);
/** Get virtualized timer value for current HART */
u64 sbi_timer_virt_value(void);
u64 sbi_timer_get_delta(struct sbi_scratch *scratch);
/** Get timer delta value for current HART */
u64 sbi_timer_get_delta(void);
void sbi_timer_set_delta(struct sbi_scratch *scratch, ulong delta);
/** Set timer delta value for current HART */
void sbi_timer_set_delta(ulong delta);
void sbi_timer_set_delta_upper(struct sbi_scratch *scratch, ulong delta_upper);
/** Set upper 32-bits of timer delta value for current HART */
void sbi_timer_set_delta_upper(ulong delta_upper);
void sbi_timer_event_start(struct sbi_scratch *scratch, u64 next_event);
/** Start timer event for current HART */
void sbi_timer_event_start(u64 next_event);
void sbi_timer_process(struct sbi_scratch *scratch);
/** Process timer event for current HART */
void sbi_timer_process(void);
/* Initialize timer */
int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot);
/* Exit timer */
void sbi_timer_exit(struct sbi_scratch *scratch);
#endif

View file

@ -15,7 +15,6 @@
#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>
@ -47,16 +46,14 @@ static int sbi_ecall_legacy_handler(unsigned long extid, unsigned long funcid,
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) {
case SBI_EXT_0_1_SET_TIMER:
#if __riscv_xlen == 32
sbi_timer_event_start(scratch,
(((u64)args[1] << 32) | (u64)args[0]));
sbi_timer_event_start((((u64)args[1] << 32) | (u64)args[0]));
#else
sbi_timer_event_start(scratch, (u64)args[0]);
sbi_timer_event_start((u64)args[0]);
#endif
break;
case SBI_EXT_0_1_CONSOLE_PUTCHAR:

View file

@ -14,7 +14,6 @@
#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>
@ -26,11 +25,9 @@ static int sbi_ecall_time_handler(unsigned long extid, unsigned long funcid,
if (funcid == SBI_EXT_TIME_SET_TIMER) {
#if __riscv_xlen == 32
sbi_timer_event_start(sbi_scratch_thishart_ptr(),
(((u64)args[1] << 32) | (u64)args[0]));
sbi_timer_event_start((((u64)args[1] << 32) | (u64)args[0]));
#else
sbi_timer_event_start(sbi_scratch_thishart_ptr(),
(u64)args[0]);
sbi_timer_event_start((u64)args[0]);
#endif
} else
ret = SBI_ENOTSUPP;

View file

@ -22,7 +22,6 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
{
int ret = 0;
ulong cen = -1UL;
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
#if __riscv_xlen == 32
bool virt = (regs->mstatusH & MSTATUSH_MPV) ? TRUE : FALSE;
@ -36,7 +35,7 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
switch (csr_num) {
case CSR_HTIMEDELTA:
if (prev_mode == PRV_S && !virt)
*csr_val = sbi_timer_get_delta(scratch);
*csr_val = sbi_timer_get_delta();
else
ret = SBI_ENOTSUPP;
break;
@ -48,8 +47,8 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
case CSR_TIME:
if (!((cen >> (CSR_TIME - CSR_CYCLE)) & 1))
return -1;
*csr_val = (virt) ? sbi_timer_virt_value(scratch):
sbi_timer_value(scratch);
*csr_val = (virt) ? sbi_timer_virt_value():
sbi_timer_value();
break;
case CSR_INSTRET:
if (!((cen >> (CSR_INSTRET - CSR_CYCLE)) & 1))
@ -69,7 +68,7 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
#if __riscv_xlen == 32
case CSR_HTIMEDELTAH:
if (prev_mode == PRV_S && !virt)
*csr_val = sbi_timer_get_delta(scratch) >> 32;
*csr_val = sbi_timer_get_delta() >> 32;
else
ret = SBI_ENOTSUPP;
break;
@ -81,8 +80,8 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
case CSR_TIMEH:
if (!((cen >> (CSR_TIME - CSR_CYCLE)) & 1))
return -1;
*csr_val = (virt) ? sbi_timer_virt_value(scratch) >> 32:
sbi_timer_value(scratch) >> 32;
*csr_val = (virt) ? sbi_timer_virt_value() >> 32:
sbi_timer_value() >> 32;
break;
case CSR_INSTRETH:
if (!((cen >> (CSR_INSTRET - CSR_CYCLE)) & 1))
@ -112,7 +111,8 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
};
if (ret)
sbi_dprintf(scratch, "%s: hartid%d: invalid csr_num=0x%x\n",
sbi_dprintf(sbi_scratch_thishart_ptr(),
"%s: hartid%d: invalid csr_num=0x%x\n",
__func__, current_hartid(), csr_num);
return ret;
@ -122,7 +122,6 @@ int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs,
ulong csr_val)
{
int ret = 0;
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
#if __riscv_xlen == 32
bool virt = (regs->mstatusH & MSTATUSH_MPV) ? TRUE : FALSE;
@ -133,7 +132,7 @@ int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs,
switch (csr_num) {
case CSR_HTIMEDELTA:
if (prev_mode == PRV_S && !virt)
sbi_timer_set_delta(scratch, csr_val);
sbi_timer_set_delta(csr_val);
else
ret = SBI_ENOTSUPP;
break;
@ -152,7 +151,7 @@ int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs,
#if __riscv_xlen == 32
case CSR_HTIMEDELTAH:
if (prev_mode == PRV_S && !virt)
sbi_timer_set_delta_upper(scratch, csr_val);
sbi_timer_set_delta_upper(csr_val);
else
ret = SBI_ENOTSUPP;
break;
@ -181,7 +180,8 @@ int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs,
};
if (ret)
sbi_dprintf(scratch, "%s: hartid%d: invalid csr_num=0x%x\n",
sbi_dprintf(sbi_scratch_thishart_ptr(),
"%s: hartid%d: invalid csr_num=0x%x\n",
__func__, current_hartid(), csr_num);
return ret;

View file

@ -11,6 +11,7 @@
#include <sbi/riscv_encoding.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_platform.h>
#include <sbi/sbi_scratch.h>
#include <sbi/sbi_timer.h>
static unsigned long time_delta_off;
@ -37,9 +38,9 @@ u64 get_ticks(void)
}
#endif
u64 sbi_timer_value(struct sbi_scratch *scratch)
u64 sbi_timer_value(void)
{
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
const struct sbi_platform *plat = sbi_platform_thishart_ptr();
if (sbi_platform_has_timer_value(plat))
return sbi_platform_timer_value(plat);
@ -47,43 +48,47 @@ u64 sbi_timer_value(struct sbi_scratch *scratch)
return get_ticks();
}
u64 sbi_timer_virt_value(struct sbi_scratch *scratch)
u64 sbi_timer_virt_value(void)
{
u64 *time_delta = sbi_scratch_offset_ptr(scratch, time_delta_off);
u64 *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(),
time_delta_off);
return sbi_timer_value(scratch) + *time_delta;
return sbi_timer_value() + *time_delta;
}
u64 sbi_timer_get_delta(struct sbi_scratch *scratch)
u64 sbi_timer_get_delta(void)
{
u64 *time_delta = sbi_scratch_offset_ptr(scratch, time_delta_off);
u64 *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(),
time_delta_off);
return *time_delta;
}
void sbi_timer_set_delta(struct sbi_scratch *scratch, ulong delta)
void sbi_timer_set_delta(ulong delta)
{
u64 *time_delta = sbi_scratch_offset_ptr(scratch, time_delta_off);
u64 *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(),
time_delta_off);
*time_delta = (u64)delta;
}
void sbi_timer_set_delta_upper(struct sbi_scratch *scratch, ulong delta_upper)
void sbi_timer_set_delta_upper(ulong delta_upper)
{
u64 *time_delta = sbi_scratch_offset_ptr(scratch, time_delta_off);
u64 *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(),
time_delta_off);
*time_delta &= 0xffffffffULL;
*time_delta |= ((u64)delta_upper << 32);
}
void sbi_timer_event_start(struct sbi_scratch *scratch, u64 next_event)
void sbi_timer_event_start(u64 next_event)
{
sbi_platform_timer_event_start(sbi_platform_ptr(scratch), next_event);
sbi_platform_timer_event_start(sbi_platform_thishart_ptr(), next_event);
csr_clear(CSR_MIP, MIP_STIP);
csr_set(CSR_MIE, MIP_MTIP);
}
void sbi_timer_process(struct sbi_scratch *scratch)
void sbi_timer_process(void)
{
csr_clear(CSR_MIE, MIP_MTIP);
csr_set(CSR_MIP, MIP_STIP);

View file

@ -16,7 +16,6 @@
#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>
@ -229,7 +228,7 @@ void sbi_trap_handler(struct sbi_trap_regs *regs)
mcause &= ~(1UL << (__riscv_xlen - 1));
switch (mcause) {
case IRQ_M_TIMER:
sbi_timer_process(sbi_scratch_thishart_ptr());
sbi_timer_process();
break;
case IRQ_M_SOFT:
sbi_ipi_process();