Skip to content

Commit

Permalink
plic: Clear hart interrupt before consuming IRQ bits
Browse files Browse the repository at this point in the history
  • Loading branch information
LekKit authored Mar 5, 2024
1 parent 84f7ce9 commit 5f4d891
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/devices/plic.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ static uint32_t plic_claim_irq(plic_ctx_t* plic, uint32_t ctx)
size_t nirqs = 0;
uint32_t claimed_irq = 0;
uint32_t max_prio = 0;
riscv_interrupt_clear(vector_at(plic->machine->harts, CTX_HARTID(ctx)), CTX_IRQ_PRIO(ctx));
for (size_t i=0; i<PLIC_SRC_REG_COUNT; ++i) {
uint32_t irqs = atomic_load_uint32(&plic->pending[i]);
// Only enabled interrupts will pass
Expand All @@ -147,8 +148,8 @@ static uint32_t plic_claim_irq(plic_ctx_t* plic, uint32_t ctx)
return 0;
}
}
if (nirqs <= 1 || max_prio <= atomic_load_uint32(&plic->threshold[ctx])) {
riscv_interrupt_clear(vector_at(plic->machine->harts, CTX_HARTID(ctx)), CTX_IRQ_PRIO(ctx));
if (nirqs > 1 && max_prio > atomic_load_uint32(&plic->threshold[ctx])) {
riscv_interrupt(vector_at(plic->machine->harts, CTX_HARTID(ctx)), CTX_IRQ_PRIO(ctx));
}
return claimed_irq;
}
Expand Down

0 comments on commit 5f4d891

Please sign in to comment.