Skip to contentSkip to conversation

irqchip/riscv-intc: Introduce Andes IRQ chip

PATCH Superseded Yu Chien Peter Lin 2 participants 3 messages Oct 19, 2023 – Oct 30, 2023

Subsystems (3)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 3/10 irqchip/riscv-intc: Introduce Andes IRQ chip

This commit adds support for the Andes IRQ chip, which provides IRQ mask/unmask functions to access the custom CSR (SLIE) where the non-standard S-mode local interrupt enable bits are located.

The Andes INTC requires the "andestech,cpu-intc" compatible string to be present in interrupt-controller of each cpu node. e.g.,

  cpu0: cpu@0 {
      compatible = "andestech,ax45mp", "riscv";
      ...
      cpu0-intc: interrupt-controller {
          #interrupt-cells = <0x01>;
          compatible = "andestech,cpu-intc";
          interrupt-controller;
      };
  };

---
Changes v1 -> v2:
- New patch

---
 drivers/irqchip/irq-riscv-intc.c       | 49 ++++++++++++++++++++++++--
 include/linux/irqchip/irq-riscv-intc.h | 12 +++++++
 2 files changed, 59 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/irqchip/irq-riscv-intc.h
drivers/irqchip/irq-riscv-intc.c +47 -2
index 79d049105384..fcd06b58bdac 100644
@@ -13,6 +13,7 @@
 #include <linux/irq.h>
 #include <linux/irqchip.h>
 #include <linux/irqdomain.h>
+#include <linux/irqchip/irq-riscv-intc.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/of.h>
@@ -45,6 +46,26 @@ static void riscv_intc_irq_unmask(struct irq_data *d)
 	csr_set(CSR_IE, BIT(d->hwirq));
 }
 
+static void andes_intc_irq_mask(struct irq_data *d)
+{
+	unsigned int mask = BIT(d->hwirq % BITS_PER_LONG);
+
+	if (d->hwirq < ANDES_SLI_CAUSE_BASE)
+		csr_clear(CSR_IE, mask);
+	else
+		csr_clear(ANDES_CSR_SLIE, mask);
+}
+
+static void andes_intc_irq_unmask(struct irq_data *d)
+{
+	unsigned int mask = BIT(d->hwirq % BITS_PER_LONG);
+
+	if (d->hwirq < ANDES_SLI_CAUSE_BASE)
+		csr_set(CSR_IE, mask);
+	else
+		csr_set(ANDES_CSR_SLIE, mask);
+}
+
 static void riscv_intc_irq_eoi(struct irq_data *d)
 {
 	/*
@@ -68,12 +89,35 @@ static struct irq_chip riscv_intc_chip = {
 	.irq_eoi = riscv_intc_irq_eoi,
 };
 
+static struct irq_chip andes_intc_chip = {
+	.name = "RISC-V INTC",
+	.irq_mask = andes_intc_irq_mask,
+	.irq_unmask = andes_intc_irq_unmask,
+	.irq_eoi = riscv_intc_irq_eoi,
+};
+
 static int riscv_intc_domain_map(struct irq_domain *d, unsigned int irq,
 				 irq_hw_number_t hwirq)
 {
+	struct fwnode_handle *fn = riscv_get_intc_hwnode();
+	struct irq_chip *chip;
+	const char *cp;
+	int rc;
+
 	irq_set_percpu_devid(irq);
-	irq_domain_set_info(d, irq, hwirq, &riscv_intc_chip, d->host_data,
-			    handle_percpu_devid_irq, NULL, NULL);
+
+	rc = fwnode_property_read_string(fn, "compatible", &cp);
+	if (rc)
+		return rc;
+
+	if (strcmp(cp, "riscv,cpu-intc") == 0)
+		chip = &riscv_intc_chip;
+	else if (strcmp(cp, "andestech,cpu-intc") == 0)
+		chip = &andes_intc_chip;
+
+	irq_domain_set_info(d, irq, hwirq, chip,
+			    d->host_data, handle_percpu_devid_irq, NULL,
+			    NULL);
 
 	return 0;
 }
@@ -166,6 +210,7 @@ static int __init riscv_intc_init(struct device_node *node,
 }
 
 IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init);
+IRQCHIP_DECLARE(andes, "andestech,cpu-intc", riscv_intc_init);
 
 #ifdef CONFIG_ACPI
 
include/linux/irqchip/irq-riscv-intc.h new file +12 -0
new file mode 100644
index 000000000000..87c105b5b545
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2023 Andes Technology Corporation
+ */
+#ifndef __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H
+#define __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H
+
+#define ANDES_SLI_CAUSE_BASE	256
+#define ANDES_CSR_SLIE		0x9c4
+#define ANDES_CSR_SLIP		0x9c5
+
+#endif /* __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H */
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw
Quoted 1 line · Yu Chien Peter Lin

This commit adds support for the Andes IRQ chip, which provides

"This commit" is not any different from "This patch" and equaly pointless. See Documentation/process/submitting-patches.rst

Also please write out interrupt instead of IRQ. Changelogs are text and not subject to twitter limitations.

Quoted 1 line

IRQ mask/unmask functions to access the custom CSR (SLIE)

What is a CSR? These acronyms are really annoying for people who are not familiar with the chip specific details.

drivers/irqchip/irq-riscv-intc.c static void riscv_intc_irq_unmask(struct irq_data *d) · line 53

Quoted 5 lines
drivers/irqchip/irq-riscv-intc.c +5 -0
+static void andes_intc_irq_mask(struct irq_data *d)
+{
+	unsigned int mask = BIT(d->hwirq % BITS_PER_LONG);
+
+	if (d->hwirq < ANDES_SLI_CAUSE_BASE)

This lacks a comment which explains why these hardware interrupts are special.

Quoted 19 lines
drivers/irqchip/irq-riscv-intc.c +15 -0
+		csr_clear(CSR_IE, mask);
+	else
+		csr_clear(ANDES_CSR_SLIE, mask);
+}
+
+static void andes_intc_irq_unmask(struct irq_data *d)
+{
+	unsigned int mask = BIT(d->hwirq % BITS_PER_LONG);
+
+	if (d->hwirq < ANDES_SLI_CAUSE_BASE)
+		csr_set(CSR_IE, mask);
+	else
+		csr_set(ANDES_CSR_SLIE, mask);
+}
+
 static void riscv_intc_irq_eoi(struct irq_data *d)
 {
 	/*

drivers/irqchip/irq-riscv-intc.c static struct irq_chip riscv_intc_chip = { · line 96

Quoted 8 lines
drivers/irqchip/irq-riscv-intc.c +5 -0
@@ -68,12 +89,35 @@ static struct irq_chip riscv_intc_chip = {
 	.irq_eoi = riscv_intc_irq_eoi,
 };
 
+static struct irq_chip andes_intc_chip = {
+	.name = "RISC-V INTC",
+	.irq_mask = andes_intc_irq_mask,
+	.irq_unmask = andes_intc_irq_unmask,
+	.irq_eoi = riscv_intc_irq_eoi,

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#struct-declarations-and-initializers

drivers/irqchip/irq-riscv-intc.c static struct irq_chip riscv_intc_chip = { · line 107

Quoted 11 lines
drivers/irqchip/irq-riscv-intc.c +7 -0
+};
+
 static int riscv_intc_domain_map(struct irq_domain *d, unsigned int irq,
 				 irq_hw_number_t hwirq)
 {
+	struct fwnode_handle *fn = riscv_get_intc_hwnode();
+	struct irq_chip *chip;
+	const char *cp;
+	int rc;
+
 	irq_set_percpu_devid(irq);

Why is this not moved after the failure condition too?

drivers/irqchip/irq-riscv-intc.c static struct irq_chip riscv_intc_chip = { · line 116

Quoted 11 lines
drivers/irqchip/irq-riscv-intc.c +9 -2
-	irq_domain_set_info(d, irq, hwirq, &riscv_intc_chip, d->host_data,
-			    handle_percpu_devid_irq, NULL, NULL);
+
+	rc = fwnode_property_read_string(fn, "compatible", &cp);
+	if (rc)
+		return rc;
+
+	if (strcmp(cp, "riscv,cpu-intc") == 0)
+		chip = &riscv_intc_chip;
+	else if (strcmp(cp, "andestech,cpu-intc") == 0)
+		chip = &andes_intc_chip;

How is this supposed to work with ACPI?

The obvious solution for this is to have two different init functions

riscv_intc_init()

{
        riscv_intc_init_common(..., &risc_intc_chip);
}

riscv_andes_init()

{
        riscv_intc_init_common(..., &andes_intc_chip);
}

riscv_intc_init_common(...., *chip)

{
        // Set the interrupt chip pointer as domain host data
        irqdomain_create_linear(...., chip);
}

and then you can use that in the map function:

    chip = domain->host_data;

See?

Quoted 8 lines
include/linux/irqchip/irq-riscv-intc.h new file +2 -0
new file mode 100644
index 000000000000..87c105b5b545
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*

include/linux/irqchip/irq-riscv-intc.h line 12

Quoted 10 lines
include/linux/irqchip/irq-riscv-intc.h new file +10 -0
+ * Copyright (C) 2023 Andes Technology Corporation
+ */
+#ifndef __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H
+#define __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H
+
+#define ANDES_SLI_CAUSE_BASE	256
+#define ANDES_CSR_SLIE		0x9c4
+#define ANDES_CSR_SLIP		0x9c5
+
+#endif /* __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H */

What's the purpose of this header file? The defines are only used in the interrupt chip driver code, so they can just be in the C file. No?

Thanks,

tglx

#2 lore raw

Hi Thomas,

Quoted 5 lines · Thomas Gleixner
Quoted 1 line · Yu Chien Peter Lin

This commit adds support for the Andes IRQ chip, which provides

"This commit" is not any different from "This patch" and equaly pointless. See Documentation/process/submitting-patches.rst

Sure, will rewrite the commit message.
Thanks for the pointer.

Quoted 2 lines

Also please write out interrupt instead of IRQ. Changelogs are text and not subject to twitter limitations.

OK!

Quoted 4 lines
Quoted 1 line

IRQ mask/unmask functions to access the custom CSR (SLIE)

What is a CSR? These acronyms are really annoying for people who are not familiar with the chip specific details.

OK!

Quoted 8 lines

drivers/irqchip/irq-riscv-intc.c static void riscv_intc_irq_unmask(struct irq_data *d) · line 53

Quoted 5 lines
drivers/irqchip/irq-riscv-intc.c +5 -0
+static void andes_intc_irq_mask(struct irq_data *d)
+{
+	unsigned int mask = BIT(d->hwirq % BITS_PER_LONG);
+
+	if (d->hwirq < ANDES_SLI_CAUSE_BASE)

This lacks a comment which explains why these hardware interrupts are special.

Sure, will add a comment here.

Quoted 22 lines
Quoted 22 lines
drivers/irqchip/irq-riscv-intc.c +15 -0
+		csr_clear(CSR_IE, mask);
+	else
+		csr_clear(ANDES_CSR_SLIE, mask);
+}
+
+static void andes_intc_irq_unmask(struct irq_data *d)
+{
+	unsigned int mask = BIT(d->hwirq % BITS_PER_LONG);
+
+	if (d->hwirq < ANDES_SLI_CAUSE_BASE)
+		csr_set(CSR_IE, mask);
+	else
+		csr_set(ANDES_CSR_SLIE, mask);
+}
+
 static void riscv_intc_irq_eoi(struct irq_data *d)
 {
 	/*
@@ -68,12 +89,35 @@ static struct irq_chip riscv_intc_chip = {
 	.irq_eoi = riscv_intc_irq_eoi,
 };
 
Quoted 7 lines

drivers/irqchip/irq-riscv-intc.c static struct irq_chip riscv_intc_chip = { · line 96

Quoted 5 lines
drivers/irqchip/irq-riscv-intc.c +5 -0
+static struct irq_chip andes_intc_chip = {
+	.name = "RISC-V INTC",
+	.irq_mask = andes_intc_irq_mask,
+	.irq_unmask = andes_intc_irq_unmask,
+	.irq_eoi = riscv_intc_irq_eoi,

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#struct-declarations-and-initializers

OK, will fix.

Quoted 46 lines

drivers/irqchip/irq-riscv-intc.c static struct irq_chip riscv_intc_chip = { · line 107

Quoted 11 lines
drivers/irqchip/irq-riscv-intc.c +7 -0
+};
+
 static int riscv_intc_domain_map(struct irq_domain *d, unsigned int irq,
 				 irq_hw_number_t hwirq)
 {
+	struct fwnode_handle *fn = riscv_get_intc_hwnode();
+	struct irq_chip *chip;
+	const char *cp;
+	int rc;
+
 	irq_set_percpu_devid(irq);

Why is this not moved after the failure condition too?

drivers/irqchip/irq-riscv-intc.c static struct irq_chip riscv_intc_chip = { · line 116

Quoted 11 lines
drivers/irqchip/irq-riscv-intc.c +9 -2
-	irq_domain_set_info(d, irq, hwirq, &riscv_intc_chip, d->host_data,
-			    handle_percpu_devid_irq, NULL, NULL);
+
+	rc = fwnode_property_read_string(fn, "compatible", &cp);
+	if (rc)
+		return rc;
+
+	if (strcmp(cp, "riscv,cpu-intc") == 0)
+		chip = &riscv_intc_chip;
+	else if (strcmp(cp, "andestech,cpu-intc") == 0)
+		chip = &andes_intc_chip;

How is this supposed to work with ACPI?

The obvious solution for this is to have two different init functions

riscv_intc_init()

{
        riscv_intc_init_common(..., &risc_intc_chip);
}

riscv_andes_init()

{
        riscv_intc_init_common(..., &andes_intc_chip);
}

riscv_intc_init_common(...., *chip)

{
        // Set the interrupt chip pointer as domain host data
        irqdomain_create_linear(...., chip);
}
Quoted 5 lines

and then you can use that in the map function:

    chip = domain->host_data;

See?

Got it! Will reimplement according to this method.

Quoted 22 lines
Quoted 8 lines
include/linux/irqchip/irq-riscv-intc.h new file +2 -0
new file mode 100644
index 000000000000..87c105b5b545
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*

include/linux/irqchip/irq-riscv-intc.h line 12

Quoted 10 lines
include/linux/irqchip/irq-riscv-intc.h new file +10 -0
+ * Copyright (C) 2023 Andes Technology Corporation
+ */
+#ifndef __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H
+#define __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H
+
+#define ANDES_SLI_CAUSE_BASE	256
+#define ANDES_CSR_SLIE		0x9c4
+#define ANDES_CSR_SLIP		0x9c5
+
+#endif /* __INCLUDE_LINUX_IRQCHIP_IRQ_RISCV_INTC_H */

What's the purpose of this header file? The defines are only used in the interrupt chip driver code, so they can just be in the C file. No?

Quoted 1 line

Thanks,

These definitions are shared with drivers/perf/riscv_pmu_sbi.c, however, I should not add vendor specific things here, they will be move to include/linux/soc/andes/irq.h.

Thanks for the review!

Best regards,
Peter Lin

Quoted 2 lines

tglx