-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
riscv: irq: Correct interrupt handling in clic non-vectored mode
According to the clic specification (https://github.com/riscv/riscv-fast-interrupt), the mnxti register has be written, in order to clear the pending bit for non-vectored interrupts. For vectored interrupts, this is automatically done. From the spec: "If the pending interrupt is edge-triggered, hardware will automatically clear the corresponding pending bit when the CSR instruction that accesses xnxti includes a write." I added a kconfig `RISCV_SOC_HAS_CUSTOM_IRQ_HANDLING` to allow custom irq handling. If enabled, `__soc_handle_all_irqs` has to be implemented. For clic, non-vectored mode, I added a `__soc_handle_all_irqs`, that handles the pending interrupts according to the pseudo code in the spec. (cherry picked from commit 08a2ca5) Original-Signed-off-by: Greter Raffael <[email protected]> GitOrigin-RevId: 08a2ca5 Change-Id: Ibaf8494660c6f2655cae88b2d68302eaa504c52c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5211285 Tested-by: Keith Short <[email protected]> Commit-Queue: Keith Short <[email protected]> Tested-by: ChromeOS Prod (Robot) <[email protected]> Reviewed-by: Keith Short <[email protected]>
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2024 Baumer Electric AG | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* @brief Assembler-hooks specific to Nuclei's Extended Core Interrupt Controller | ||
*/ | ||
|
||
#include <zephyr/arch/cpu.h> | ||
|
||
|
||
GTEXT(__soc_handle_irq) | ||
/* | ||
* In an ECLIC, pending interrupts don't have to be cleared by hand. | ||
* In vectored mode, interrupts are cleared automatically. | ||
* In non-vectored mode, interrupts are cleared when writing the mnxti register (done in | ||
* __soc_handle_all_irqs). | ||
* Thus this function can directly return. | ||
*/ | ||
SECTION_FUNC(exception.other, __soc_handle_irq) | ||
ret | ||
|
||
#if !defined(CONFIG_RISCV_VECTORED_MODE) | ||
|
||
GTEXT(__soc_handle_all_irqs) | ||
|
||
#ifdef CONFIG_TRACING | ||
/* imports */ | ||
GTEXT(sys_trace_isr_enter) | ||
GTEXT(sys_trace_isr_exit) | ||
#endif | ||
|
||
/* | ||
* This function services and clears all pending interrupts for an ECLIC in non-vectored mode. | ||
*/ | ||
SECTION_FUNC(exception.other, __soc_handle_all_irqs) | ||
mv t2, ra | ||
|
||
/* Read and clear mnxti to get highest current interrupt and enable interrupts. Will return | ||
* original interrupt if no others appear. */ | ||
csrrci a0, 0x345, MSTATUS_IEN | ||
beqz a0, irq_done /* Check if original interrupt vanished. */ | ||
|
||
irq_loop: | ||
|
||
#ifdef CONFIG_TRACING_ISR | ||
call sys_trace_isr_enter | ||
#endif | ||
|
||
/* Call corresponding registered function in _sw_isr_table. a0 is offset in words, table is | ||
* 2-word wide -> shift by one */ | ||
la t0, _sw_isr_table | ||
slli a0, a0, (1) | ||
add t0, t0, a0 | ||
|
||
/* Load argument in a0 register */ | ||
lw a0, 0(t0) | ||
|
||
/* Load ISR function address in register t1 */ | ||
lw t1, RV_REGSIZE(t0) | ||
|
||
/* Call ISR function */ | ||
jalr ra, t1, 0 | ||
|
||
/* Read and clear mnxti to get highest current interrupt and enable interrupts. */ | ||
csrrci a0, 0x345, MSTATUS_IEN | ||
|
||
#ifdef CONFIG_TRACING_ISR | ||
call sys_trace_isr_exit | ||
#endif | ||
|
||
bnez a0, irq_loop | ||
|
||
irq_done: | ||
mv ra, t2 | ||
ret | ||
#endif |