Skip to content

Commit 779d4af

Browse files
g2gpsxiaoxiang781216
authored andcommitted
arch/risc-v/src/litex: Claim all pending PLIC interrupts.
Attempt to service all interrupts pending in the PLIC's claim register. Ideally, this is more efficient than switching context for each interrupt received.
1 parent 29ee9aa commit 779d4af

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

arch/risc-v/src/litex/litex_irq_dispatch.c

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,48 +47,38 @@
4747
* riscv_dispatch_irq
4848
****************************************************************************/
4949

50+
#ifdef CONFIG_LITEX_CORE_VEXRISCV_SMP
5051
void *riscv_dispatch_irq(uintptr_t vector, uintreg_t *regs)
5152
{
52-
#ifdef CONFIG_LITEX_CORE_VEXRISCV_SMP
5353
int irq = (vector & 0x3f);
54+
DEBUGASSERT(irq <= RISCV_IRQ_EXT);
5455

5556
if ((vector & RISCV_IRQ_BIT) != 0)
5657
{
5758
irq += RISCV_IRQ_ASYNC;
5859
}
5960

60-
/* Firstly, check if the irq is machine external interrupt */
61-
62-
if (irq == RISCV_IRQ_EXT)
61+
if (irq < RISCV_IRQ_EXT)
6362
{
64-
uint32_t ext = getreg32(LITEX_PLIC_CLAIM);
65-
66-
/* Add the value to nuttx irq which is offset to the ext */
67-
68-
irq = RISCV_IRQ_EXT + ext;
69-
}
70-
71-
/* Acknowledge the interrupt */
72-
73-
riscv_ack_irq(irq);
74-
75-
/* EXT means no interrupt */
76-
77-
if (irq != RISCV_IRQ_EXT)
78-
{
79-
/* Deliver the IRQ */
80-
8163
regs = riscv_doirq(irq, regs);
8264
}
83-
84-
if (irq > RISCV_IRQ_EXT)
65+
else
8566
{
86-
/* Then write PLIC_CLAIM to clear pending in PLIC */
87-
88-
putreg32(irq - RISCV_IRQ_EXT, LITEX_PLIC_CLAIM);
67+
uint32_t ext = getreg32(LITEX_PLIC_CLAIM);
68+
do
69+
{
70+
regs = riscv_doirq(RISCV_IRQ_EXT + ext, regs);
71+
putreg32(ext, LITEX_PLIC_CLAIM);
72+
ext = getreg32(LITEX_PLIC_CLAIM);
73+
}
74+
while (ext);
8975
}
9076

91-
#else
77+
return regs;
78+
}
79+
#else
80+
void *riscv_dispatch_irq(uintptr_t vector, uintreg_t *regs)
81+
{
9282
int i;
9383
int irq = (vector >> RV_IRQ_MASK) | (vector & 0xf);
9484

@@ -127,6 +117,6 @@ void *riscv_dispatch_irq(uintptr_t vector, uintreg_t *regs)
127117

128118
regs = riscv_doirq(irq, regs);
129119

130-
#endif /* CONFIG_LITEX_CORE_VEXRISCV_SMP */
131120
return regs;
132121
}
122+
#endif

0 commit comments

Comments
 (0)