Skip to content

Commit

Permalink
arch/risc-v/src/mpfs/mpfs_irq.c: Fix up_irqinitialize for warm reboot
Browse files Browse the repository at this point in the history
It is possible that a PLIC IRQ is claimed but not completed at warm
reset. This occurs at least if there is a fault in the middle of irq
handler execution.

To recover from such situation, we can complete all IRQ:s in PLIC;
this completes any already claimed IRQ, but has no effect on IRQs
which are not claimed or not enabled.

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Jan 16, 2024
1 parent 15391f4 commit 723dad7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions arch/risc-v/src/mpfs/mpfs_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ void up_irqinitialize(void)

up_irq_save();

/* Complete possibly claimed IRQs in PLIC (for current hart) in case
* of warm reboot, e.g. after a crash in the middle of IRQ handler.
* This has no effect on non-claimed or disabled interrupts.
*/

uintptr_t claim_address = mpfs_plic_get_claimbase();

int irq;
for (irq = MPFS_IRQ_EXT_START; irq < NR_IRQS; irq++)
{
putreg32(irq - MPFS_IRQ_EXT_START, claim_address);
}

/* Disable all global interrupts for current hart */

uintptr_t iebase = mpfs_plic_get_iebase();
Expand All @@ -61,12 +74,6 @@ void up_irqinitialize(void)
putreg32(0x0, iebase + 16);
putreg32(0x0, iebase + 20);

/* Clear pendings in PLIC (for current hart) */

uintptr_t claim_address = mpfs_plic_get_claimbase();
uint32_t val = getreg32(claim_address);
putreg32(val, claim_address);

/* Colorize the interrupt stack for debug purposes */

#if defined(CONFIG_STACK_COLORATION) && CONFIG_ARCH_INTERRUPTSTACK > 15
Expand All @@ -77,7 +84,6 @@ void up_irqinitialize(void)
/* Set priority for all global interrupts to 1 (lowest) */

int id;

for (id = 1; id <= NR_IRQS; id++)
{
putreg32(1, (uintptr_t)(MPFS_PLIC_PRIORITY + (4 * id)));
Expand Down

0 comments on commit 723dad7

Please sign in to comment.