Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riscv: remove up_set_current_regs/up_current_regs #14962

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 25 additions & 36 deletions arch/risc-v/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,17 +671,9 @@ extern "C"
#define EXTERN extern
#endif

/* g_current_regs[] holds a references to the current interrupt level
* register storage structure. If is non-NULL only during interrupt
* processing. Access to g_current_regs[] must be through the
* [get/set]_current_regs for portability.
*/

/* For the case of architectures with multiple CPUs, then there must be one
* such value for each processor that can receive an interrupt.
*/
/* g_interrupt_context store irq status */

EXTERN volatile uintreg_t *g_current_regs[CONFIG_SMP_NCPUS];
EXTERN volatile bool g_interrupt_context[CONFIG_SMP_NCPUS];

/****************************************************************************
* Public Function Prototypes
Expand Down Expand Up @@ -724,24 +716,6 @@ int up_this_cpu(void);
* Inline Functions
****************************************************************************/

static inline_function uintreg_t *up_current_regs(void)
pussuw marked this conversation as resolved.
Show resolved Hide resolved
{
#ifdef CONFIG_SMP
return (uintreg_t *)g_current_regs[up_this_cpu()];
#else
return (uintreg_t *)g_current_regs[0];
#endif
}

static inline_function void up_set_current_regs(uintreg_t *regs)
{
#ifdef CONFIG_SMP
g_current_regs[up_this_cpu()] = regs;
#else
g_current_regs[0] = regs;
#endif
}

/****************************************************************************
* Name: up_irq_save
*
Expand Down Expand Up @@ -790,6 +764,24 @@ noinstrument_function static inline void up_irq_restore(irqstate_t flags)
);
}

/****************************************************************************
* Name: up_set_interrupt_context
*
* Description:
* Set the interrupt handler context.
*
****************************************************************************/

noinstrument_function
static inline_function void up_set_interrupt_context(bool flag)
{
#ifdef CONFIG_SMP
g_interrupt_context[up_this_cpu()] = flag;
#else
g_interrupt_context[0] = flag;
#endif
}

/****************************************************************************
* Name: up_interrupt_context
*
Expand All @@ -803,23 +795,20 @@ noinstrument_function static inline_function bool up_interrupt_context(void)
{
#ifdef CONFIG_SMP
irqstate_t flags = up_irq_save();
#endif

bool ret = up_current_regs() != NULL;

#ifdef CONFIG_SMP
bool ret = g_interrupt_context[up_this_cpu()];
up_irq_restore(flags);
#endif

return ret;
#else
return g_interrupt_context[0];
#endif
}

/****************************************************************************
* Name: up_getusrpc
****************************************************************************/

#define up_getusrpc(regs) \
(((uintptr_t *)((regs) ? (regs) : up_current_regs()))[REG_EPC])
(((uintptr_t *)((regs) ? (regs) : running_regs()))[REG_EPC])

#undef EXTERN
#if defined(__cplusplus)
Expand Down
4 changes: 2 additions & 2 deletions arch/risc-v/src/common/riscv_backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
{
ret += backtrace(rtcb->stack_base_ptr,
rtcb->stack_base_ptr + rtcb->adj_stack_size,
(void *)up_current_regs()[REG_FP],
(void *)up_current_regs()[REG_EPC],
running_regs()[REG_FP],
running_regs()[REG_EPC],
&buffer[ret], size - ret, &skip);
}
}
Expand Down
26 changes: 9 additions & 17 deletions arch/risc-v/src/common/riscv_doirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,20 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
(*running_task)->xcp.regs = regs;
}

/* Current regs non-zero indicates that we are processing an interrupt;
* current_regs is also used to manage interrupt level context switches.
*
* Nested interrupts are not supported
*/
/* Nested interrupts are not supported */

DEBUGASSERT(up_current_regs() == NULL);
up_set_current_regs(regs);
DEBUGASSERT(!up_interrupt_context());

/* Set irq flag */

up_set_interrupt_context(true);

/* Deliver the IRQ */

irq_dispatch(irq, regs);
tcb = this_task();

/* Check for a context switch. If a context switch occurred, then
* current_regs will have a different value than it did on entry. If an
* interrupt level context switch has occurred, then restore the floating
* point state and the establish the correct address environment before
* returning from the interrupt.
*/
/* Check for a context switch. */

if (*running_task != tcb)
{
Expand All @@ -124,11 +118,9 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
*running_task = tcb;
}

/* Set current_regs to NULL to indicate that we are no longer in an
* interrupt handler.
*/
/* Set irq flag */

up_set_current_regs(NULL);
up_set_interrupt_context(false);

#endif
board_autoled_off(LED_INIRQ);
Expand Down
12 changes: 6 additions & 6 deletions arch/risc-v/src/common/riscv_exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ int riscv_exception(int mcause, void *regs, void *args)

/* Return to _exit function in privileged mode with argument SIGSEGV */

up_current_regs()[REG_EPC] = (uintptr_t)_exit;
up_current_regs()[REG_A0] = SIGSEGV;
up_current_regs()[REG_INT_CTX] |= STATUS_PPP;
running_regs()[REG_EPC] = _exit;
running_regs()[REG_A0] = (void *)SIGSEGV;
((uintreg_t *)running_regs())[REG_INT_CTX] |= STATUS_PPP;

/* Continue with kernel stack in use. The frame(s) in kernel stack
* are no longer needed, so just set it to top
*/

up_current_regs()[REG_SP] = (uintptr_t)tcb->xcp.ktopstk;
running_regs()[REG_SP] = (void *)tcb->xcp.ktopstk;
}
else
#endif
{
_alert("PANIC!!! Exception = %" PRIxREG "\n", cause);
up_irq_save();
up_set_current_regs(regs);
up_set_interrupt_context(true);
PANIC_WITH_REGS("panic", regs);
}

Expand Down Expand Up @@ -197,7 +197,7 @@ int riscv_fillpage(int mcause, void *regs, void *args)
{
_alert("PANIC!!! virtual address not mappable: %" PRIxPTR "\n", vaddr);
up_irq_save();
up_set_current_regs(regs);
up_set_interrupt_context(true);
PANIC_WITH_REGS("panic", regs);
}

Expand Down
4 changes: 3 additions & 1 deletion arch/risc-v/src/common/riscv_initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
* Public Data
****************************************************************************/

volatile uintreg_t *g_current_regs[CONFIG_SMP_NCPUS];
/* g_interrupt_context store irq status */

volatile bool g_interrupt_context[CONFIG_SMP_NCPUS];

/****************************************************************************
* Private Functions
Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/common/riscv_registerdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ uintptr_t up_getusrsp(void *regs)

void up_dump_register(void *dumpregs)
{
volatile uintreg_t *regs = dumpregs ? dumpregs : up_current_regs();
volatile uintreg_t *regs = dumpregs ? dumpregs : running_regs();

/* Are user registers available from interrupt processing? */

Expand Down
8 changes: 5 additions & 3 deletions arch/risc-v/src/common/supervisor/riscv_perform_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ void *riscv_perform_syscall(uintreg_t *regs)
(*running_task)->xcp.regs = regs;
}

/* Set up the interrupt register set needed by swint() */
/* Set irq flag */

up_set_current_regs(regs);
up_set_interrupt_context(true);

/* Run the system call handler (swint) */

Expand Down Expand Up @@ -77,7 +77,9 @@ void *riscv_perform_syscall(uintreg_t *regs)
*running_task = tcb;
}

up_set_current_regs(NULL);
/* Set irq flag */

up_set_interrupt_context(false);

return tcb->xcp.regs;
}
Loading