Skip to content

Commit 9fba163

Browse files
committed
[nrf fromlist] arch:riscv: Support for Direct ISRs for RISCV targets
Added support for Direct ISRs in the multithreaded enviroment Signed-off-by: Rafal Dyla <[email protected]>
1 parent 6cbc9d9 commit 9fba163

File tree

6 files changed

+44
-4
lines changed

6 files changed

+44
-4
lines changed

arch/riscv/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ zephyr_library_sources(
66
cpu_idle.c
77
fatal.c
88
irq_manage.c
9+
isr.S
910
prep_c.c
1011
reboot.c
1112
reset.S
@@ -26,7 +27,6 @@ endif()
2627
zephyr_library_sources_ifdef(CONFIG_FPU_SHARING fpu.c fpu.S)
2728
zephyr_library_sources_ifdef(CONFIG_DEBUG_COREDUMP coredump.c)
2829
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
29-
zephyr_library_sources_ifdef(CONFIG_GEN_SW_ISR_TABLE isr.S)
3030
zephyr_library_sources_ifdef(CONFIG_RISCV_PMP pmp.c pmp.S)
3131
zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE tls.c)
3232
zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S)

arch/riscv/core/irq_manage.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <zephyr/arch/riscv/csr.h>
1111
#include <zephyr/irq_multilevel.h>
1212
#include <zephyr/sw_isr_table.h>
13+
#include <zephyr/pm/pm.h>
1314

1415
#ifdef CONFIG_RISCV_HAS_PLIC
1516
#include <zephyr/drivers/interrupt_controller/riscv_plic.h>
@@ -75,3 +76,20 @@ int arch_irq_disconnect_dynamic(unsigned int irq, unsigned int priority,
7576
}
7677
#endif /* CONFIG_SHARED_INTERRUPTS */
7778
#endif /* CONFIG_DYNAMIC_INTERRUPTS */
79+
80+
#ifdef CONFIG_PM
81+
void _arch_isr_direct_pm(void)
82+
{
83+
unsigned int key;
84+
85+
/* irq_lock() does what we want for this CPU */
86+
key = irq_lock();
87+
88+
if (_kernel.idle) {
89+
_kernel.idle = 0;
90+
pm_system_resume();
91+
}
92+
93+
irq_unlock(key);
94+
}
95+
#endif

arch/riscv/core/isr.S

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ on_irq_stack:
640640
*/
641641
jal ra, __soc_handle_irq
642642

643+
#ifdef CONFIG_GEN_SW_ISR_TABLE
643644
/*
644645
* Call corresponding registered function in _sw_isr_table.
645646
* (table is 2-word wide, we should shift index accordingly)
@@ -656,7 +657,7 @@ on_irq_stack:
656657

657658
/* Call ISR function */
658659
jalr ra, t1, 0
659-
660+
#endif
660661
#ifdef CONFIG_TRACING_ISR
661662
call sys_trace_isr_exit
662663
#endif

drivers/timer/nrf_grtc_timer.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,26 @@ uint32_t sys_clock_elapsed(void)
461461
return (uint32_t)(counter_sub(counter(), last_count) / CYC_PER_TICK);
462462
}
463463

464+
#if !defined(CONFIG_GEN_SW_ISR_TABLE)
465+
ISR_DIRECT_DECLARE(nrfx_grtc_direct_irq_handler)
466+
{
467+
nrfx_grtc_irq_handler();
468+
ISR_DIRECT_PM();
469+
return 1;
470+
}
471+
#endif
472+
464473
static int sys_clock_driver_init(void)
465474
{
466475
nrfx_err_t err_code;
467476

477+
#if defined(CONFIG_GEN_SW_ISR_TABLE)
468478
IRQ_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_isr,
469479
nrfx_grtc_irq_handler, 0);
480+
#else
481+
IRQ_DIRECT_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_grtc_direct_irq_handler, 0);
482+
irq_enable(DT_IRQN(GRTC_NODE));
483+
#endif
470484

471485
#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && NRF_GRTC_HAS_CLKSEL
472486
#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC)

include/zephyr/arch/riscv/irq.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ extern void z_riscv_irq_vector_set(unsigned int irq);
8383
z_riscv_irq_vector_set(irq_p); \
8484
}
8585

86+
#ifdef CONFIG_PM
87+
extern void _arch_isr_direct_pm(void);
88+
#define ARCH_ISR_DIRECT_PM() _arch_isr_direct_pm()
89+
#else
90+
#define ARCH_ISR_DIRECT_PM() do { } while (false)
91+
#endif
92+
8693
#define ARCH_ISR_DIRECT_HEADER() arch_isr_direct_header()
8794
#define ARCH_ISR_DIRECT_FOOTER(swap) arch_isr_direct_footer(swap)
8895

soc/common/riscv-privileged/vector.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ GTEXT(__start)
1212

1313
/* imports */
1414
GTEXT(__initialize)
15-
#if defined(CONFIG_GEN_SW_ISR_TABLE)
15+
#if defined(CONFIG_GEN_SW_ISR_TABLE) || defined (CONFIG_GEN_IRQ_VECTOR_TABLE)
1616
GTEXT(_isr_wrapper)
1717
#endif
1818

@@ -37,7 +37,7 @@ SECTION_FUNC(vectors, __start)
3737
* mtvec.base must be aligned to 64 bytes (this is done using
3838
* CONFIG_RISCV_TRAP_HANDLER_ALIGNMENT)
3939
*/
40-
#if defined(CONFIG_GEN_SW_ISR_TABLE)
40+
#if defined(CONFIG_GEN_SW_ISR_TABLE) || defined (CONFIG_GEN_IRQ_VECTOR_TABLE)
4141
la t0, _isr_wrapper
4242
#else
4343
add t0, zero, zero

0 commit comments

Comments
 (0)