irqchip/riscv-intc: Add support for RISC-V AIA
authorAnup Patel <apatel@ventanamicro.com>
Thu, 22 Feb 2024 09:39:56 +0000 (15:09 +0530)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 23 Feb 2024 09:18:44 +0000 (10:18 +0100)
The RISC-V advanced interrupt architecture (AIA) extends the per-HART
local interrupts in following ways:
1. Minimum 64 local interrupts for both RV32 and RV64
2. Ability to process multiple pending local interrupts in same
   interrupt handler
3. Priority configuration for each local interrupts
4. Special CSRs to configure/access the per-HART MSI controller

Add support for #1 and #2 described above in the RISC-V intc driver.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240222094006.1030709-9-apatel@ventanamicro.com
drivers/irqchip/irq-riscv-intc.c

index 0cd6b48a5dbf95a865961ca2d8e3b503b89cdfbf..cccb653399821cea6da6a54a4a3a472725324479 100644 (file)
@@ -19,6 +19,8 @@
 #include <linux/smp.h>
 #include <linux/soc/andes/irq.h>
 
+#include <asm/hwcap.h>
+
 static struct irq_domain *intc_domain;
 static unsigned int riscv_intc_nr_irqs __ro_after_init = BITS_PER_LONG;
 static unsigned int riscv_intc_custom_base __ro_after_init = BITS_PER_LONG;
@@ -32,6 +34,14 @@ static asmlinkage void riscv_intc_irq(struct pt_regs *regs)
                pr_warn_ratelimited("Failed to handle interrupt (cause: %ld)\n", cause);
 }
 
+static asmlinkage void riscv_intc_aia_irq(struct pt_regs *regs)
+{
+       unsigned long topi;
+
+       while ((topi = csr_read(CSR_TOPI)))
+               generic_handle_domain_irq(intc_domain, topi >> TOPI_IID_SHIFT);
+}
+
 /*
  * On RISC-V systems local interrupts are masked or unmasked by writing
  * the SIE (Supervisor Interrupt Enable) CSR.  As CSRs can only be written
@@ -41,12 +51,18 @@ static asmlinkage void riscv_intc_irq(struct pt_regs *regs)
 
 static void riscv_intc_irq_mask(struct irq_data *d)
 {
-       csr_clear(CSR_IE, BIT(d->hwirq));
+       if (IS_ENABLED(CONFIG_32BIT) && d->hwirq >= BITS_PER_LONG)
+               csr_clear(CSR_IEH, BIT(d->hwirq - BITS_PER_LONG));
+       else
+               csr_clear(CSR_IE, BIT(d->hwirq));
 }
 
 static void riscv_intc_irq_unmask(struct irq_data *d)
 {
-       csr_set(CSR_IE, BIT(d->hwirq));
+       if (IS_ENABLED(CONFIG_32BIT) && d->hwirq >= BITS_PER_LONG)
+               csr_set(CSR_IEH, BIT(d->hwirq - BITS_PER_LONG));
+       else
+               csr_set(CSR_IE, BIT(d->hwirq));
 }
 
 static void andes_intc_irq_mask(struct irq_data *d)
@@ -157,8 +173,7 @@ static struct fwnode_handle *riscv_intc_hwnode(void)
        return intc_domain->fwnode;
 }
 
-static int __init riscv_intc_init_common(struct fwnode_handle *fn,
-                                        struct irq_chip *chip)
+static int __init riscv_intc_init_common(struct fwnode_handle *fn, struct irq_chip *chip)
 {
        int rc;
 
@@ -176,11 +191,10 @@ static int __init riscv_intc_init_common(struct fwnode_handle *fn,
 
        riscv_set_intc_hwnode_fn(riscv_intc_hwnode);
 
-       pr_info("%d local interrupts mapped\n", riscv_intc_nr_irqs);
-       if (riscv_intc_custom_nr_irqs) {
-               pr_info("%d custom local interrupts mapped\n",
-                       riscv_intc_custom_nr_irqs);
-       }
+       pr_info("%d local interrupts mapped\n",
+               riscv_isa_extension_available(NULL, SxAIA) ? 64 : riscv_intc_nr_irqs);
+       if (riscv_intc_custom_nr_irqs)
+               pr_info("%d custom local interrupts mapped\n", riscv_intc_custom_nr_irqs);
 
        return 0;
 }