Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libcpu/risc-v/common/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,12 @@ static rt_bool_t handler_irq(int hwirq, void *data)
#if INTC_TYPE != INTC_TYPE_CLIC
static rt_bool_t handler_plic_irq(int hwirq, void *data)
{
rt_bool_t res = handler_irq(hwirq, data);

/* Complete after handling to avoid re-pending level interrupts. */
plic_irq_ack_or_eoi(rt_hw_cpu_id(), hwirq);

return handler_irq(hwirq, data);
return res;
}

void plic_init(void)
Expand Down
32 changes: 31 additions & 1 deletion libcpu/risc-v/common/pic/pic-sifive-plic.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,41 @@ static void plic_irq_mask_raw(int cpu, int hwirq)
static void plic_irq_ack_or_eoi(int cpu, int hwirq)
{
struct plic_percpu *percpu = &plic_percpu[cpu];
rt_uint32_t *enable_reg, enable_mask;

if (percpu->valid)
if (!percpu->valid)
{
return;
}

enable_reg = percpu->enable_base + (hwirq / 32) * sizeof(rt_uint32_t);
enable_mask = 1U << (hwirq % 32);

/*
* The PLIC ignores completion for a disabled source.
* Temporarily enable it if the handler masked the interrupt.
*/
if (HWREG32(enable_reg) & enable_mask)
{
HWREG32(percpu->hart_base + CONTEXT_CLAIM) = hwirq;
}
else
{
rt_ubase_t level = rt_spin_lock_irqsave(&percpu->enable_lock);

if (HWREG32(enable_reg) & enable_mask)
{
HWREG32(percpu->hart_base + CONTEXT_CLAIM) = hwirq;
}
else
{
HWREG32(enable_reg) |= enable_mask;
HWREG32(percpu->hart_base + CONTEXT_CLAIM) = hwirq;
HWREG32(enable_reg) &= ~enable_mask;
}

rt_spin_unlock_irqrestore(&percpu->enable_lock, level);
}
}

static rt_bool_t plic_handler_isr_raw(struct plic *plic,
Expand Down
Loading