Skip to content

Commit 9004d79

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 9b71094 commit 9004d79

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
@@ -646,6 +646,7 @@ on_irq_stack:
646646
*/
647647
jal ra, __soc_handle_irq
648648

649+
#ifdef CONFIG_GEN_SW_ISR_TABLE
649650
/*
650651
* Call corresponding registered function in _sw_isr_table.
651652
* (table is 2-word wide, we should shift index accordingly)
@@ -662,7 +663,7 @@ on_irq_stack:
662663

663664
/* Call ISR function */
664665
jalr ra, t1, 0
665-
666+
#endif
666667
#ifdef CONFIG_TRACING_ISR
667668
call sys_trace_isr_exit
668669
#endif

drivers/timer/nrf_grtc_timer.c

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

452+
#if !defined(CONFIG_GEN_SW_ISR_TABLE)
453+
ISR_DIRECT_DECLARE(nrfx_grtc_direct_irq_handler)
454+
{
455+
nrfx_grtc_irq_handler();
456+
ISR_DIRECT_PM();
457+
return 1;
458+
}
459+
#endif
460+
452461
static int sys_clock_driver_init(void)
453462
{
454463
nrfx_err_t err_code;
455464

465+
#if defined(CONFIG_GEN_SW_ISR_TABLE)
456466
IRQ_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_isr,
457467
nrfx_grtc_irq_handler, 0);
468+
#else
469+
IRQ_DIRECT_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_grtc_direct_irq_handler, 0);
470+
irq_enable(DT_IRQN(GRTC_NODE));
471+
#endif
458472

459473
#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && NRF_GRTC_HAS_CLKSEL
460474
#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

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

0 commit comments

Comments
 (0)