lib: utils/irqchip: Check before initializing imsic
authorCheng Yang <yangcheng.work@foxmail.com>
Wed, 15 May 2024 06:15:14 +0000 (14:15 +0800)
committerAnup Patel <anup@brainfault.org>
Thu, 16 May 2024 04:51:16 +0000 (10:21 +0530)
The current mlevel imsic check is only for the platform, which
may cause hart without imsic in the platform to trigger an
illegal instruction exception when initializing imsic. For
example, the platform contains a management hart that only
supports wired interrupts.

This patch will check if each hart supports Smaia extension
before doing imsic initialization to avoid triggering illegal
instruction exceptions.

Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/utils/irqchip/imsic.c

index f2a35c6302b2bebfb2a0aa6511d75fd532e445d9..02e3a334912f033657925af7f09c3eb4b821dbd0 100644 (file)
@@ -12,6 +12,7 @@
 #include <sbi/riscv_io.h>
 #include <sbi/riscv_encoding.h>
 #include <sbi/sbi_console.h>
+#include <sbi/sbi_csr_detect.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_ipi.h>
 #include <sbi/sbi_irqchip.h>
@@ -222,6 +223,8 @@ static void imsic_local_eix_update(unsigned long base_id,
 
 void imsic_local_irqchip_init(void)
 {
+       struct sbi_trap_info trap = { 0 };
+
        /*
         * This function is expected to be called from:
         * 1) nascent_init() platform callback which is called
@@ -231,6 +234,11 @@ void imsic_local_irqchip_init(void)
         *    in boot-up path.
         */
 
+       /* If Smaia not available then do nothing */
+       csr_read_allowed(CSR_MTOPI, (ulong)&trap);
+       if (trap.cause)
+               return;
+
        /* Setup threshold to allow all enabled interrupts */
        imsic_csr_write(IMSIC_EITHRESHOLD, IMSIC_ENABLE_EITHRESHOLD);