Skip to contentSkip to conversation

irqchip/ath79-misc: probe as a platform driver

PATCH New Rosen Penev 2 participants 9 messages Nov 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover irqchip/ath79-misc: probe as a platform driver

The MISC interrupt controller of the Atheros/Qualcomm ath79 SoCs is cascaded from a CPU interrupt, and all of its users are platform devices. It is still initialized from IRQCHIP_DECLARE, before the early initcalls, only because the MIPS perf code asks for the performance counter overflow interrupt, which goes through it, from an early_initcall.

Patch 1 makes the MIPS perf code look up that interrupt when the first event is created, which is when it is requested. Patch 2 makes the ath79 MISC driver create the mapping at that point. Patch 3 then converts the driver to IRQCHIP_PLATFORM_DRIVER with device-managed resources, which also fixes the leak of the register mapping on its error path. Patch 4 adds COMPILE_TEST coverage, which a platform driver makes possible.

Patch 3 depends on patch 1: without it, perf would ask for the interrupt before the controller has probed and would lose its overflow interrupt. Patch 1 touches only arch/mips, so the series could go through the MIPS tree with an ack for the irqchip patches, or through irqchip with an ack for patch 1.

The other users of get_c0_perfcount_int() (generic/GIC, Malta, Lantiq, Ralink) return an interrupt that is set up at boot, so calling it later does not change anything for them. The perf boot message no longer prints the interrupt, which is not known at that point.

Tested on a TP-Link Archer C7 v2 (QCA9558), with the device tree from the pending series that adds it: the MISC controller probes as a platform device, its users (UART, GPIO, watchdog) probe with nothing left deferred, and perf record gets its samples from the overflow interrupt on MISC 5. Each patch builds with W=1 (mips, clang), and with patch 4 the driver also builds with W=1 for arm64, x86_64 and a non-ath79 MIPS kernel (Lantiq). The v2 change has only been build
tested: no QCA956x or TP9343 board was available.

Changes in v2:
- Patch 3: keep the MIPS timer interrupt enabled in the MISC controller when probing. plat_time_init() enables it on QCA956x and TP9343, and the driver now probes after it, so clearing every enable bit left those SoCs without jiffies. Reported by the review of v1.
- Rebased on next-20261112.

v1: https://lore.kernel.org/all/[email protected]/

An AI coding assistant (Claude Code, Claude Opus 5.5) was used to write the patches, test them on the router over its serial console, and draft the commit messages and this cover letter.

Rosen Penev (4):
MIPS: perf: look up the PMU interrupt when it is requested irqchip/ath79-misc: map the performance counter interrupt on demand irqchip/ath79-misc: convert to a platform driver irqchip/ath79-misc: allow COMPILE_TEST builds

 arch/mips/kernel/perf_event_mipsxx.c |  30 ++++---
 drivers/irqchip/Kconfig              |  14 ++++
 drivers/irqchip/Makefile             |   2 +-
 drivers/irqchip/irq-ath79-misc.c     | 120 +++++++++++++++------------
 4 files changed, 98 insertions(+), 68 deletions(-)

base-commit: 6d582d78fad9d828e575ca0cdcff8ea47a77220b

Signature · 1 line
2.56.1
#1 lore raw

PATCH v2 1/4 MIPS: perf: look up the PMU interrupt when it is requested

init_hw_perf_events() is an early_initcall and asks the platform for the counter overflow interrupt through get_c0_perfcount_int(). On ath79, that interrupt goes through the MISC interrupt controller, so the controller has to be initialized from IRQCHIP_DECLARE before the early initcalls, even though nothing else needs it that early.

The interrupt is only requested when the first event is created. Look it up then, so that it can come from an interrupt controller probed as a platform driver. The boot message no longer prints the interrupt.

---
 arch/mips/kernel/perf_event_mipsxx.c | 30 +++++++++++++++++-----------
 1 file changed, 18 insertions(+), 12 deletions(-)
arch/mips/kernel/perf_event_mipsxx.c +18 -12
index 196a070349b0..4d660952e643 100644
@@ -589,10 +589,25 @@ static atomic_t active_events = ATOMIC_INIT(0);
 static DEFINE_MUTEX(pmu_reserve_mutex);
 static int (*save_perf_irq)(void);
 
+/*
+ * The interrupt is looked up when the first event is created, not when the
+ * PMU is registered: on some platforms, the interrupt controller that the
+ * counter overflow is wired to is only probed after the early initcalls.
+ */
+static int mipspmu_find_irq(void)
+{
+	if (get_c0_perfcount_int)
+		return get_c0_perfcount_int();
+	if (cp0_perfcount_irq >= 0)
+		return MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
+	return -1;
+}
+
 static int mipspmu_get_irq(void)
 {
 	int err;
 
+	mipspmu.irq = mipspmu_find_irq();
 	if (mipspmu.irq >= 0) {
 		/* Request my own irq handler. */
 		err = request_irq(mipspmu.irq, mipsxx_pmu_handle_irq,
@@ -1889,7 +1904,7 @@ static const struct mips_perf_event *octeon_pmu_map_raw_event(u64 config)
 static int __init
 init_hw_perf_events(void)
 {
-	int counters, irq, pmu_type;
+	int counters, pmu_type;
 
 	pr_info("Performance counters: ");
 
@@ -1904,13 +1919,6 @@ init_hw_perf_events(void)
 		counters = counters_total_to_per_cpu(counters);
 #endif
 
-	if (get_c0_perfcount_int)
-		irq = get_c0_perfcount_int();
-	else if (cp0_perfcount_irq >= 0)
-		irq = MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
-	else
-		irq = -1;
-
 	mipspmu.map_raw_event = mipsxx_pmu_map_raw_event;
 
 	switch (current_cpu_type()) {
@@ -2017,7 +2025,6 @@ init_hw_perf_events(void)
 	}
 
 	mipspmu.num_counters = counters;
-	mipspmu.irq = irq;
 
 	if (read_c0_perfctrl0() & MIPS_PERFCTRL_W) {
 		if (get_loongson3_pmu_type() == LOONGSON_PMU_TYPE2) {
@@ -2044,9 +2051,8 @@ init_hw_perf_events(void)
 
 	on_each_cpu(reset_counters, (void *)(long)counters, 1);
 
-	pr_cont("%s PMU enabled, %d %d-bit counters available to each "
-		"CPU, irq %d%s\n", mipspmu.name, counters, counter_bits, irq,
-		irq < 0 ? " (share with timer interrupt)" : "");
+	pr_cont("%s PMU enabled, %d %d-bit counters available to each CPU\n",
+		mipspmu.name, counters, counter_bits);
 
 	perf_pmu_register(&pmu, "cpu", PERF_TYPE_RAW);
 
Signature · 1 line
2.56.1
#2 lore raw

Re: [PATCH v2 1/4] MIPS: perf: look up the PMU interrupt when it is requested

Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

init_hw_perf_events() is an early_initcall and asks the platform for the counter overflow interrupt through get_c0_perfcount_int(). On ath79, that interrupt goes through the MISC interrupt controller, so the controller has to be initialized from IRQCHIP_DECLARE before the early initcalls, even though nothing else needs it that early.

The interrupt is only requested when the first event is created. Look it up then, so that it can come from an interrupt controller probed as a platform driver. The boot message no longer prints the interrupt.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH v2 2/4 irqchip/ath79-misc: map the performance counter interrupt on demand

In reply to Rosen Penev

The MIPS perf code now asks for the counter overflow interrupt when the first event is created, instead of from an early_initcall. Create the mapping in get_c0_perfcount_int() then, instead of when the controller is initialized, so that the controller no longer has to be ready before the early initcalls.

---
 drivers/irqchip/irq-ath79-misc.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/irqchip/irq-ath79-misc.c +11 -4
index 258b8e9a2d57..5cedea5234e0 100644
@@ -23,11 +23,19 @@
 #define ATH79_MISC_IRQ_COUNT			32
 #define ATH79_MISC_PERF_IRQ			5
 
-static int ath79_perfcount_irq;
+static struct irq_domain *ath79_misc_domain;
 
+/* Called by the MIPS perf code when the first event is created. */
 int get_c0_perfcount_int(void)
 {
-	return ath79_perfcount_irq;
+	unsigned int irq;
+
+	if (!ath79_misc_domain)
+		return -1;
+
+	irq = irq_create_mapping(ath79_misc_domain, ATH79_MISC_PERF_IRQ);
+
+	return irq ? irq : -1;
 }
 EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
 
@@ -121,8 +129,6 @@ static void __init ath79_misc_intc_domain_init(
 {
 	void __iomem *base = domain->host_data;
 
-	ath79_perfcount_irq = irq_create_mapping(domain, ATH79_MISC_PERF_IRQ);
-
 	/* Disable and clear all interrupts */
 	__raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
 	__raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
@@ -157,6 +163,7 @@ static int __init ath79_misc_intc_of_init(
 	}
 
 	ath79_misc_intc_domain_init(domain, irq);
+	ath79_misc_domain = domain;
 	return 0;
 }
 
Signature · 1 line
2.56.1
#4 lore raw

Re: [PATCH v2 2/4] irqchip/ath79-misc: map the performance counter interrupt on demand

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

The MIPS perf code now asks for the counter overflow interrupt when the first event is created, instead of from an early_initcall. Create the mapping in get_c0_perfcount_int() then, instead of when the controller is initialized, so that the controller no longer has to be ready before the early initcalls.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH v2 3/4 irqchip/ath79-misc: convert to a platform driver

In reply to Rosen Penev

The MISC interrupt controller is cascaded from a CPU interrupt, and its users are all platform devices, which defer their probe until it is available. The performance counter interrupt, the only one needed before the early initcalls, is now mapped on demand.

Probe the controller as a platform driver, and use device-managed resources, which also fixes the leak of the register mapping when the irq domain cannot be created.

The driver now probes after plat_time_init(), which on QCA956x and TP9343 enables the MIPS timer interrupt in the MISC controller, without which there are no jiffies. Keep that enable bit when disabling the other interrupts, which leaves the register as it was with the old init order.

---
 drivers/irqchip/irq-ath79-misc.c | 90 ++++++++++++++++----------------
 1 file changed, 44 insertions(+), 46 deletions(-)
drivers/irqchip/irq-ath79-misc.c +44 -46
index 5cedea5234e0..e69d4eca929f 100644
@@ -12,8 +12,9 @@
 
 #include <linux/irqchip.h>
 #include <linux/irqchip/chained_irq.h>
-#include <linux/of_address.h>
-#include <linux/of_irq.h>
+#include <linux/irqdomain.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
 
 #include <asm/time.h>
 
@@ -22,6 +23,7 @@
 
 #define ATH79_MISC_IRQ_COUNT			32
 #define ATH79_MISC_PERF_IRQ			5
+#define ATH79_MISC_SI_TIMERINT			BIT(28)
 
 static struct irq_domain *ath79_misc_domain;
 
@@ -124,65 +126,61 @@ static const struct irq_domain_ops misc_irq_domain_ops = {
 	.map = misc_map,
 };
 
-static void __init ath79_misc_intc_domain_init(
-	struct irq_domain *domain, int irq)
-{
-	void __iomem *base = domain->host_data;
-
-	/* Disable and clear all interrupts */
-	__raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
-	__raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
-
-	irq_set_chained_handler_and_data(irq, ath79_misc_irq_handler, domain);
-}
-
-static int __init ath79_misc_intc_of_init(
-	struct device_node *node, struct device_node *parent)
+static int ath79_misc_intc_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct irq_domain *domain;
 	void __iomem *base;
+	u32 enable;
 	int irq;
 
-	irq = irq_of_parse_and_map(node, 0);
-	if (!irq) {
-		pr_err("Failed to get MISC IRQ\n");
-		return -EINVAL;
-	}
-
-	base = of_iomap(node, 0);
-	if (!base) {
-		pr_err("Failed to get MISC IRQ registers\n");
-		return -ENOMEM;
-	}
-
-	domain = irq_domain_create_linear(of_fwnode_handle(node), ATH79_MISC_IRQ_COUNT,
-				&misc_irq_domain_ops, base);
-	if (!domain) {
-		pr_err("Failed to add MISC irqdomain\n");
-		return -EINVAL;
-	}
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	domain = devm_irq_domain_create_linear(dev, dev_fwnode(dev),
+					       ATH79_MISC_IRQ_COUNT,
+					       &misc_irq_domain_ops, base);
+	if (!domain)
+		return dev_err_probe(dev, -ENOMEM, "failed to add the irq domain\n");
+
+	/*
+	 * Disable and clear all interrupts, except the MIPS timer interrupt:
+	 * plat_time_init() enables it on QCA956x and TP9343, which have no
+	 * jiffies without it, and that runs before this driver probes.
+	 */
+	enable = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
+	__raw_writel(enable & ATH79_MISC_SI_TIMERINT,
+		     base + AR71XX_RESET_REG_MISC_INT_ENABLE);
+	__raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
 
-	ath79_misc_intc_domain_init(domain, irq);
+	irq_set_chained_handler_and_data(irq, ath79_misc_irq_handler, domain);
 	ath79_misc_domain = domain;
+
 	return 0;
 }
 
-static int __init ar7100_misc_intc_of_init(
-	struct device_node *node, struct device_node *parent)
+static int ar7100_misc_intc_probe(struct platform_device *pdev,
+				  struct device_node *parent)
 {
 	ath79_misc_irq_chip.irq_mask_ack = ar71xx_misc_irq_mask;
-	return ath79_misc_intc_of_init(node, parent);
+	return ath79_misc_intc_probe(pdev);
 }
 
-IRQCHIP_DECLARE(ar7100_misc_intc, "qca,ar7100-misc-intc",
-		ar7100_misc_intc_of_init);
-
-static int __init ar7240_misc_intc_of_init(
-	struct device_node *node, struct device_node *parent)
+static int ar7240_misc_intc_probe(struct platform_device *pdev,
+				  struct device_node *parent)
 {
 	ath79_misc_irq_chip.irq_ack = ar724x_misc_irq_ack;
-	return ath79_misc_intc_of_init(node, parent);
+	return ath79_misc_intc_probe(pdev);
 }
 
-IRQCHIP_DECLARE(ar7240_misc_intc, "qca,ar7240-misc-intc",
-		ar7240_misc_intc_of_init);
+IRQCHIP_PLATFORM_DRIVER_BEGIN(ath79_misc_intc)
+IRQCHIP_MATCH("qca,ar7100-misc-intc", ar7100_misc_intc_probe)
+IRQCHIP_MATCH("qca,ar7240-misc-intc", ar7240_misc_intc_probe)
+IRQCHIP_PLATFORM_DRIVER_END(ath79_misc_intc)
+MODULE_DESCRIPTION("Atheros AR71xx/AR724x/AR913x MISC interrupt controller");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.56.1
#6 lore raw

Re: [PATCH v2 3/4] irqchip/ath79-misc: convert to a platform driver

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

The MISC interrupt controller is cascaded from a CPU interrupt, and its users are all platform devices, which defer their probe until it is available. The performance counter interrupt, the only one needed before the early initcalls, is now mapped on demand.

Probe the controller as a platform driver, and use device-managed resources, which also fixes the leak of the register mapping when the irq domain cannot be created.

Quoted 7 lines

The driver now probes after plat_time_init(), which on QCA956x and TP9343 enables the MIPS timer interrupt in the MISC controller, without which there are no jiffies. Keep that enable bit when disabling the other interrupts, which leaves the register as it was with the old init order.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

PATCH v2 4/4 irqchip/ath79-misc: allow COMPILE_TEST builds

In reply to Rosen Penev

The driver is only built with ATH79, so only ath79 kernels build it. As a platform driver, its only MIPS-specific parts are the performance counter hook and the call to spurious_interrupt().

Add a Kconfig symbol that defaults to ATH79 and can be enabled with COMPILE_TEST. Build the performance counter hook only with ATH79, as other MIPS platforms provide their own. Drop the call to spurious_interrupt(), which only exists on MIPS: a cascaded interrupt with nothing pending only bumped the error count in /proc/interrupts, and the handler now just returns.

---
 drivers/irqchip/Kconfig          | 14 ++++++++++++++
 drivers/irqchip/Makefile         |  2 +-
 drivers/irqchip/irq-ath79-misc.c | 19 ++++++++++++-------
 3 files changed, 27 insertions(+), 8 deletions(-)
drivers/irqchip/Kconfig +14 -0
index 8aee8f731848..f83fe64f066b 100644
@@ -127,6 +127,20 @@ config ASPEED_AST2700_INTC_TEST
 
 	  If unsure, say N.
 
+config ATH79_MISC_IRQ
+	bool "Atheros/Qualcomm ath79 MISC interrupt controller" if COMPILE_TEST
+	depends on ATH79 || COMPILE_TEST
+	depends on OF
+	depends on HAS_IOMEM
+	default ATH79
+	select IRQ_DOMAIN
+	help
+	  Support the MISC interrupt controller of the Atheros/Qualcomm
+	  ath79 SoCs. It is cascaded from a CPU interrupt and collects the
+	  interrupts of the UART, GPIO, timers, watchdog and performance
+	  counters, among others. It is enabled by default on ath79, and
+	  only needs to be selected by hand for compile testing.
+
 config ATMEL_AIC_IRQ
 	bool
 	select GENERIC_IRQ_CHIP
drivers/irqchip/Makefile +1 -1
index eb539d41251e..c51e79d3621c 100644
@@ -4,7 +4,7 @@ obj-$(CONFIG_IRQCHIP)			+= irqchip.o
 obj-$(CONFIG_AL_FIC)			+= irq-al-fic.o
 obj-$(CONFIG_ALPINE_MSI)		+= irq-alpine-msi.o
 obj-$(CONFIG_ATH79)			+= irq-ath79-cpu.o
-obj-$(CONFIG_ATH79)			+= irq-ath79-misc.o
+obj-$(CONFIG_ATH79_MISC_IRQ)		+= irq-ath79-misc.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2835.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2836.o
 obj-$(CONFIG_ARCH_ACTIONS)		+= irq-owl-sirq.o
drivers/irqchip/irq-ath79-misc.c +12 -7
index e69d4eca929f..c25676a1c1cd 100644
@@ -16,7 +16,9 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 
+#ifdef CONFIG_ATH79
 #include <asm/time.h>
+#endif
 
 #define AR71XX_RESET_REG_MISC_INT_STATUS	0
 #define AR71XX_RESET_REG_MISC_INT_ENABLE	4
@@ -25,8 +27,14 @@
 #define ATH79_MISC_PERF_IRQ			5
 #define ATH79_MISC_SI_TIMERINT			BIT(28)
 
+#ifdef CONFIG_ATH79
 static struct irq_domain *ath79_misc_domain;
 
+static void ath79_misc_set_perf_domain(struct irq_domain *domain)
+{
+	ath79_misc_domain = domain;
+}
+
 /* Called by the MIPS perf code when the first event is created. */
 int get_c0_perfcount_int(void)
 {
@@ -40,6 +48,9 @@ int get_c0_perfcount_int(void)
 	return irq ? irq : -1;
 }
 EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
+#else
+static void ath79_misc_set_perf_domain(struct irq_domain *domain) { }
+#endif
 
 static void ath79_misc_irq_handler(struct irq_desc *desc)
 {
@@ -53,12 +64,6 @@ static void ath79_misc_irq_handler(struct irq_desc *desc)
 	pending = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS) &
 		  __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
 
-	if (!pending) {
-		spurious_interrupt();
-		chained_irq_exit(chip, desc);
-		return;
-	}
-
 	while (pending) {
 		int bit = __ffs(pending);
 
@@ -159,7 +164,7 @@ static int ath79_misc_intc_probe(struct platform_device *pdev)
 	__raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
 
 	irq_set_chained_handler_and_data(irq, ath79_misc_irq_handler, domain);
-	ath79_misc_domain = domain;
+	ath79_misc_set_perf_domain(domain);
 
 	return 0;
 }
Signature · 1 line
2.56.1
#8 lore raw

Re: [PATCH v2 4/4] irqchip/ath79-misc: allow COMPILE_TEST builds

Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

The driver is only built with ATH79, so only ath79 kernels build it. As a platform driver, its only MIPS-specific parts are the performance counter hook and the call to spurious_interrupt().

Quoted 8 lines

Add a Kconfig symbol that defaults to ATH79 and can be enabled with COMPILE_TEST. Build the performance counter hook only with ATH79, as other MIPS platforms provide their own. Drop the call to spurious_interrupt(), which only exists on MIPS: a cascaded interrupt with nothing pending only bumped the error count in /proc/interrupts, and the handler now just returns.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4