Skip to content

Commit a6c0c1b

Browse files
fix(riscv/irqc): align IMSIC handler to AIA specifications
"The RISC-V Advanced Interrupt Architecture" specifications explain in Chapter 3 (pages 26-27) how interrupts should be handled with IMSIC, in particular, interrupt claiming has to be done right after reading the STOPEI register or in the same read instruction with the csrrw instruction. This commit aligns the IMSIC interrupt handler to that specs. Without this change, if an interrupt with higher priority becomes pending while handling a lower one, writing to STOPEI after `interrupts_handle()` executes will claim the higher IRQ, freezing the execution. Signed-off-by: Filippo Fontana <[email protected]>
1 parent 5b11dc3 commit a6c0c1b

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/arch/riscv/irqc/aia/imsic.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,11 @@ void imsic_send_msi(cpuid_t target_cpu, irqid_t ipi_id)
8787

8888
void imsic_handle(void)
8989
{
90-
uint32_t intp_identity = (uint32_t)(csrs_stopei_read() >> STOPEI_EEID);
90+
/* Read STOPEI and write to it to claim the interrupt */
91+
uint32_t intp_identity = (uint32_t)(csrs_stopei_swap(0) >> STOPEI_EEID);
9192

9293
if (intp_identity != 0) {
93-
enum irq_res res = interrupts_handle(intp_identity);
94-
if (res == HANDLED_BY_HYP) {
95-
/* Write to STOPEI to clear the interrupt */
96-
csrs_stopei_write(0);
97-
}
94+
interrupts_handle(intp_identity);
9895
};
9996
}
10097

0 commit comments

Comments
 (0)