Skip to contentSkip to conversation

irqchip: Prevent drivers abusing irq_chip::name

PATCH Applied Marc Zyngier 6 participants 39 messages Feb 9, 2022 – Feb 19, 2022

Subsystems (11)
lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

cover irqchip: Prevent drivers abusing irq_chip::name

Another common abuse in irqchip drivers (and derivatives) is to place a string representing the underlying device in the irq_chip::name field that gets displayed in /proc/interrupts while this should only be an indication of the "type" of interrupt controller.

Not only this is pretty pointless (with hierarchical domains, you only see the top chip), but it also gets in the way of making the irq_chip structure const. For debug, we have a whole infrastructure that does everything you can imagine (and stuff you don't want to).

We can't remove this name as it is visible from userspace and there is a whole collection of CI scripts that parse /proc/interrupts for good (and mostly bad) reasons. The solution is to use the irq_print_chip() callback and to let it output whatever string is necessary.

Having done that, we can cleanup a few irqchip drivers and make their irq_chip structure const (which requires touching a handful of core functions). Whilst we're at it, we do the same for a couple of gpio drivers.

This series relies on the one posted at [1].

Thanks,

	M.

[1] https://lore.kernel.org/r/[email protected]

Marc Zyngier (10):
irqdomain: Let irq_domain_set_{info,hwirq_and_chip} take a const
irq_chip
genirq: Allow irq_chip registration functions to take a const irq_chip irqchip/gic: Switch to dynamic chip name output irqchip/lpc32xx: Switch to dynamic chip name output irqchip/mvebu-pic: Switch to dynamic chip name output irqchip/ts4800: Switch to dynamic chip name output irqchip/versatile-fpga: Switch to dynamic chip name output
gpio: mt7621: Switch to dynamic chip name output
gpio: omap: Switch to dynamic chip name output
pinctrl: starfive: Switch to dynamic chip name output

 drivers/gpio/gpio-mt7621.c             |  12 ++-
 drivers/gpio/gpio-omap.c               |  28 ++++---
 drivers/irqchip/irq-ftintc010.c        |   1 -
 drivers/irqchip/irq-gic.c              | 102 +++++++++++++------------
 drivers/irqchip/irq-lpc32xx.c          |  34 ++++++---
 drivers/irqchip/irq-mvebu-pic.c        |  28 ++++---
 drivers/irqchip/irq-ts4800.c           |  25 ++++--
 drivers/irqchip/irq-versatile-fpga.c   |  46 ++++++-----
 drivers/pinctrl/pinctrl-starfive.c     |  11 ++-
 include/linux/irq.h                    |   7 +-
 include/linux/irqchip/versatile-fpga.h |  14 ----
 include/linux/irqdomain.h              |   5 +-
 kernel/irq/chip.c                      |   9 +--
 kernel/irq/irqdomain.c                 |   7 +-
 14 files changed, 189 insertions(+), 140 deletions(-)
 delete mode 100644 include/linux/irqchip/versatile-fpga.h
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 1/10 irqdomain: Let irq_domain_set_{info,hwirq_and_chip} take a const irq_chip

In order to let a const irqchip be fed to the irqchip layer, adjust the various prototypes. An extra cast in irq_domain_set_hwirq_and_chip() is required to avoid a warning.

---
 include/linux/irqdomain.h | 5 +++--
 kernel/irq/irqdomain.c    | 7 ++++---
 2 files changed, 7 insertions(+), 5 deletions(-)
include/linux/irqdomain.h +3 -2
index be25a33293e5..00d577f90883 100644
@@ -479,7 +479,8 @@ int irq_destroy_ipi(unsigned int irq, const struct cpumask *dest);
 extern struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
 						unsigned int virq);
 extern void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
-				irq_hw_number_t hwirq, struct irq_chip *chip,
+				irq_hw_number_t hwirq,
+				const struct irq_chip *chip,
 				void *chip_data, irq_flow_handler_t handler,
 				void *handler_data, const char *handler_name);
 extern void irq_domain_reset_irq_data(struct irq_data *irq_data);
@@ -522,7 +523,7 @@ extern int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,
 extern int irq_domain_set_hwirq_and_chip(struct irq_domain *domain,
 					 unsigned int virq,
 					 irq_hw_number_t hwirq,
-					 struct irq_chip *chip,
+					 const struct irq_chip *chip,
 					 void *chip_data);
 extern void irq_domain_free_irqs_common(struct irq_domain *domain,
 					unsigned int virq,
kernel/irq/irqdomain.c +4 -3
index bf38c546aa25..14cf52708890 100644
@@ -1319,7 +1319,8 @@ EXPORT_SYMBOL_GPL(irq_domain_get_irq_data);
  * @chip_data:	The associated chip data
  */
 int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq,
-				  irq_hw_number_t hwirq, struct irq_chip *chip,
+				  irq_hw_number_t hwirq,
+				  const struct irq_chip *chip,
 				  void *chip_data)
 {
 	struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq);
@@ -1328,7 +1329,7 @@ int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq,
 		return -ENOENT;
 
 	irq_data->hwirq = hwirq;
-	irq_data->chip = chip ? chip : &no_irq_chip;
+	irq_data->chip = (struct irq_chip *)(chip ? chip : &no_irq_chip);
 	irq_data->chip_data = chip_data;
 
 	return 0;
@@ -1347,7 +1348,7 @@ EXPORT_SYMBOL_GPL(irq_domain_set_hwirq_and_chip);
  * @handler_name:	The interrupt handler name
  */
 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
-			 irq_hw_number_t hwirq, struct irq_chip *chip,
+			 irq_hw_number_t hwirq, const struct irq_chip *chip,
 			 void *chip_data, irq_flow_handler_t handler,
 			 void *handler_data, const char *handler_name)
 {
Signature · 1 line
2.30.2
#2 lore raw

[irqchip: irq/irqchip-next] irqdomain: Let irq_domain_set_{info,hwirq_and_chip} take a const irq_chip

The following commit has been merged into the irq/irqchip-next branch of irqchip:

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     45ec846c1cd11835a29c85645065115dd791aa45
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/45ec846c1cd11835a29c85645065115dd791aa45
Author:        Marc Zyngier <[email protected]>
AuthorDate:    Wed, 09 Feb 2022 16:25:58 
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Tue, 15 Feb 2022 11:10:21 

irqdomain: Let irq_domain_set_{info,hwirq_and_chip} take a const irq_chip

In order to let a const irqchip be fed to the irqchip layer, adjust the various prototypes. An extra cast in irq_domain_set_hwirq_and_chip() is required to avoid a warning.

---
 include/linux/irqdomain.h |  5 +++--
 kernel/irq/irqdomain.c    |  9 +++++----
 2 files changed, 8 insertions(+), 6 deletions(-)
include/linux/irqdomain.h +3 -2
index be25a33..00d577f 100644
@@ -479,7 +479,8 @@ int irq_destroy_ipi(unsigned int irq, const struct cpumask *dest);
 extern struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
 						unsigned int virq);
 extern void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
-				irq_hw_number_t hwirq, struct irq_chip *chip,
+				irq_hw_number_t hwirq,
+				const struct irq_chip *chip,
 				void *chip_data, irq_flow_handler_t handler,
 				void *handler_data, const char *handler_name);
 extern void irq_domain_reset_irq_data(struct irq_data *irq_data);
@@ -522,7 +523,7 @@ extern int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,
 extern int irq_domain_set_hwirq_and_chip(struct irq_domain *domain,
 					 unsigned int virq,
 					 irq_hw_number_t hwirq,
-					 struct irq_chip *chip,
+					 const struct irq_chip *chip,
 					 void *chip_data);
 extern void irq_domain_free_irqs_common(struct irq_domain *domain,
 					unsigned int virq,
kernel/irq/irqdomain.c +5 -4
index bf38c54..d5ce965 100644
@@ -1319,7 +1319,8 @@ EXPORT_SYMBOL_GPL(irq_domain_get_irq_data);
  * @chip_data:	The associated chip data
  */
 int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq,
-				  irq_hw_number_t hwirq, struct irq_chip *chip,
+				  irq_hw_number_t hwirq,
+				  const struct irq_chip *chip,
 				  void *chip_data)
 {
 	struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq);
@@ -1328,7 +1329,7 @@ int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq,
 		return -ENOENT;
 
 	irq_data->hwirq = hwirq;
-	irq_data->chip = chip ? chip : &no_irq_chip;
+	irq_data->chip = (struct irq_chip *)(chip ? chip : &no_irq_chip);
 	irq_data->chip_data = chip_data;
 
 	return 0;
@@ -1347,7 +1348,7 @@ EXPORT_SYMBOL_GPL(irq_domain_set_hwirq_and_chip);
  * @handler_name:	The interrupt handler name
  */
 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
-			 irq_hw_number_t hwirq, struct irq_chip *chip,
+			 irq_hw_number_t hwirq, const struct irq_chip *chip,
 			 void *chip_data, irq_flow_handler_t handler,
 			 void *handler_data, const char *handler_name)
 {
@@ -1853,7 +1854,7 @@ EXPORT_SYMBOL_GPL(irq_domain_get_irq_data);
  * @handler_name:	The interrupt handler name
  */
 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
-			 irq_hw_number_t hwirq, struct irq_chip *chip,
+			 irq_hw_number_t hwirq, const struct irq_chip *chip,
 			 void *chip_data, irq_flow_handler_t handler,
 			 void *handler_data, const char *handler_name)
 {
author maintainer
#3 lore raw

PATCH 2/10 genirq: Allow irq_chip registration functions to take a const irq_chip

In reply to Marc Zyngier

In order to let a const irqchip be fed to the irqchip layer, adjust the various prototypes. An extra cast in irq_set_chip()() is required to avoid a warning.

---
 include/linux/irq.h | 7 ++++---
 kernel/irq/chip.c   | 9 +++------
 2 files changed, 7 insertions(+), 9 deletions(-)
include/linux/irq.h +4 -3
index 2cb2e2ac2703..f92788ccdba2 100644
@@ -710,10 +710,11 @@ extern struct irq_chip no_irq_chip;
 extern struct irq_chip dummy_irq_chip;
 
 extern void
-irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
+irq_set_chip_and_handler_name(unsigned int irq, const struct irq_chip *chip,
 			      irq_flow_handler_t handle, const char *name);
 
-static inline void irq_set_chip_and_handler(unsigned int irq, struct irq_chip *chip,
+static inline void irq_set_chip_and_handler(unsigned int irq,
+					    const struct irq_chip *chip,
 					    irq_flow_handler_t handle)
 {
 	irq_set_chip_and_handler_name(irq, chip, handle, NULL);
@@ -803,7 +804,7 @@ static inline void irq_set_percpu_devid_flags(unsigned int irq)
 }
 
 /* Set/get chip/data for an IRQ: */
-extern int irq_set_chip(unsigned int irq, struct irq_chip *chip);
+extern int irq_set_chip(unsigned int irq, const struct irq_chip *chip);
 extern int irq_set_handler_data(unsigned int irq, void *data);
 extern int irq_set_chip_data(unsigned int irq, void *data);
 extern int irq_set_irq_type(unsigned int irq, unsigned int type);
kernel/irq/chip.c +3 -6
index 24b6f2b40e5e..54af0deb239b 100644
@@ -38,7 +38,7 @@ struct irqaction chained_action = {
  *	@irq:	irq number
  *	@chip:	pointer to irq chip description structure
  */
-int irq_set_chip(unsigned int irq, struct irq_chip *chip)
+int irq_set_chip(unsigned int irq, const struct irq_chip *chip)
 {
 	unsigned long flags;
 	struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
@@ -46,10 +46,7 @@ int irq_set_chip(unsigned int irq, struct irq_chip *chip)
 	if (!desc)
 		return -EINVAL;
 
-	if (!chip)
-		chip = &no_irq_chip;
-
-	desc->irq_data.chip = chip;
+	desc->irq_data.chip = (struct irq_chip *)(chip ?: &no_irq_chip);
 	irq_put_desc_unlock(desc, flags);
 	/*
 	 * For !CONFIG_SPARSE_IRQ make the irq show up in
@@ -1073,7 +1070,7 @@ irq_set_chained_handler_and_data(unsigned int irq, irq_flow_handler_t handle,
 EXPORT_SYMBOL_GPL(irq_set_chained_handler_and_data);
 
 void
-irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
+irq_set_chip_and_handler_name(unsigned int irq, const struct irq_chip *chip,
 			      irq_flow_handler_t handle, const char *name)
 {
 	irq_set_chip(irq, chip);
Signature · 1 line
2.30.2
#4 lore raw

[irqchip: irq/irqchip-next] genirq: Allow irq_chip registration functions to take a const irq_chip

The following commit has been merged into the irq/irqchip-next branch of irqchip:

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     393e1280f765661cf39785e967676a4e57324126
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/393e1280f765661cf39785e967676a4e57324126
Author:        Marc Zyngier <[email protected]>
AuthorDate:    Wed, 09 Feb 2022 16:25:59 
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Tue, 15 Feb 2022 11:10:21 

genirq: Allow irq_chip registration functions to take a const irq_chip

In order to let a const irqchip be fed to the irqchip layer, adjust the various prototypes. An extra cast in irq_set_chip()() is required to avoid a warning.

---
 include/linux/irq.h |  7 ++++---
 kernel/irq/chip.c   |  9 +++------
 2 files changed, 7 insertions(+), 9 deletions(-)
include/linux/irq.h +4 -3
index 2cb2e2a..f92788c 100644
@@ -710,10 +710,11 @@ extern struct irq_chip no_irq_chip;
 extern struct irq_chip dummy_irq_chip;
 
 extern void
-irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
+irq_set_chip_and_handler_name(unsigned int irq, const struct irq_chip *chip,
 			      irq_flow_handler_t handle, const char *name);
 
-static inline void irq_set_chip_and_handler(unsigned int irq, struct irq_chip *chip,
+static inline void irq_set_chip_and_handler(unsigned int irq,
+					    const struct irq_chip *chip,
 					    irq_flow_handler_t handle)
 {
 	irq_set_chip_and_handler_name(irq, chip, handle, NULL);
@@ -803,7 +804,7 @@ static inline void irq_set_percpu_devid_flags(unsigned int irq)
 }
 
 /* Set/get chip/data for an IRQ: */
-extern int irq_set_chip(unsigned int irq, struct irq_chip *chip);
+extern int irq_set_chip(unsigned int irq, const struct irq_chip *chip);
 extern int irq_set_handler_data(unsigned int irq, void *data);
 extern int irq_set_chip_data(unsigned int irq, void *data);
 extern int irq_set_irq_type(unsigned int irq, unsigned int type);
kernel/irq/chip.c +3 -6
index 24b6f2b..54af0de 100644
@@ -38,7 +38,7 @@ struct irqaction chained_action = {
  *	@irq:	irq number
  *	@chip:	pointer to irq chip description structure
  */
-int irq_set_chip(unsigned int irq, struct irq_chip *chip)
+int irq_set_chip(unsigned int irq, const struct irq_chip *chip)
 {
 	unsigned long flags;
 	struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
@@ -46,10 +46,7 @@ int irq_set_chip(unsigned int irq, struct irq_chip *chip)
 	if (!desc)
 		return -EINVAL;
 
-	if (!chip)
-		chip = &no_irq_chip;
-
-	desc->irq_data.chip = chip;
+	desc->irq_data.chip = (struct irq_chip *)(chip ?: &no_irq_chip);
 	irq_put_desc_unlock(desc, flags);
 	/*
 	 * For !CONFIG_SPARSE_IRQ make the irq show up in
@@ -1073,7 +1070,7 @@ irq_set_chained_handler_and_data(unsigned int irq, irq_flow_handler_t handle,
 EXPORT_SYMBOL_GPL(irq_set_chained_handler_and_data);
 
 void
-irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
+irq_set_chip_and_handler_name(unsigned int irq, const struct irq_chip *chip,
 			      irq_flow_handler_t handle, const char *name)
 {
 	irq_set_chip(irq, chip);
author maintainer
#5 lore raw

PATCH 3/10 irqchip/gic: Switch to dynamic chip name output

In reply to Marc Zyngier

The last dynamic aspect of the GIC's irq_chip structure is the name that is associated to it.

Move the output of that name to the relevant callback, which allows us to do a bit of cleanup and mark the structures const.

---
 drivers/irqchip/irq-gic.c | 102 ++++++++++++++++++++------------------
 1 file changed, 54 insertions(+), 48 deletions(-)
drivers/irqchip/irq-gic.c +54 -48
index fb741b42ca2d..58ba835bee1f 100644
@@ -34,6 +34,7 @@
 #include <linux/irqdomain.h>
 #include <linux/interrupt.h>
 #include <linux/percpu.h>
+#include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/irqchip.h>
 #include <linux/irqchip/chained_irq.h>
@@ -66,7 +67,6 @@ union gic_base {
 };
 
 struct gic_chip_data {
-	struct irq_chip chip;
 	union gic_base dist_base;
 	union gic_base cpu_base;
 	void __iomem *raw_dist_base;
@@ -397,18 +397,15 @@ static void gic_handle_cascade_irq(struct irq_desc *desc)
 	chained_irq_exit(chip, desc);
 }
 
-static const struct irq_chip gic_chip = {
-	.irq_mask		= gic_mask_irq,
-	.irq_unmask		= gic_unmask_irq,
-	.irq_eoi		= gic_eoi_irq,
-	.irq_set_type		= gic_set_type,
-	.irq_retrigger          = gic_retrigger,
-	.irq_get_irqchip_state	= gic_irq_get_irqchip_state,
-	.irq_set_irqchip_state	= gic_irq_set_irqchip_state,
-	.flags			= IRQCHIP_SET_TYPE_MASKED |
-				  IRQCHIP_SKIP_SET_WAKE |
-				  IRQCHIP_MASK_ON_SUSPEND,
-};
+static void gic_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct gic_chip_data *gic = irq_data_get_irq_chip_data(d);
+
+	if (gic->domain->dev)
+		seq_printf(p, gic->domain->dev->of_node->name);
+	else
+		seq_printf(p, "GIC-%d", (int)(gic - &gic_data[0]));
+}
 
 void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq)
 {
@@ -799,8 +796,12 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
 			    bool force)
 {
 	void __iomem *reg = gic_dist_base(d) + GIC_DIST_TARGET + gic_irq(d);
+	struct gic_chip_data *gic = irq_data_get_irq_chip_data(d);
 	unsigned int cpu;
 
+	if (unlikely(gic != &gic_data[0]))
+		return -EINVAL;
+
 	if (!force)
 		cpu = cpumask_any_and(mask_val, cpu_online_mask);
 	else
@@ -880,6 +881,39 @@ static __init void gic_smp_init(void)
 #define gic_ipi_send_mask	NULL
 #endif
 
+static const struct irq_chip gic_chip = {
+	.irq_mask		= gic_mask_irq,
+	.irq_unmask		= gic_unmask_irq,
+	.irq_eoi		= gic_eoi_irq,
+	.irq_set_type		= gic_set_type,
+	.irq_retrigger          = gic_retrigger,
+	.irq_set_affinity	= gic_set_affinity,
+	.ipi_send_mask		= gic_ipi_send_mask,
+	.irq_get_irqchip_state	= gic_irq_get_irqchip_state,
+	.irq_set_irqchip_state	= gic_irq_set_irqchip_state,
+	.irq_print_chip		= gic_irq_print_chip,
+	.flags			= IRQCHIP_SET_TYPE_MASKED |
+				  IRQCHIP_SKIP_SET_WAKE |
+				  IRQCHIP_MASK_ON_SUSPEND,
+};
+
+static const struct irq_chip gic_chip_mode1 = {
+	.name			= "GICv2",
+	.irq_mask		= gic_eoimode1_mask_irq,
+	.irq_unmask		= gic_unmask_irq,
+	.irq_eoi		= gic_eoimode1_eoi_irq,
+	.irq_set_type		= gic_set_type,
+	.irq_retrigger          = gic_retrigger,
+	.irq_set_affinity	= gic_set_affinity,
+	.ipi_send_mask		= gic_ipi_send_mask,
+	.irq_get_irqchip_state	= gic_irq_get_irqchip_state,
+	.irq_set_irqchip_state	= gic_irq_set_irqchip_state,
+	.irq_set_vcpu_affinity	= gic_irq_set_vcpu_affinity,
+	.flags			= IRQCHIP_SET_TYPE_MASKED |
+				  IRQCHIP_SKIP_SET_WAKE |
+				  IRQCHIP_MASK_ON_SUSPEND,
+};
+
 #ifdef CONFIG_BL_SWITCHER
 /*
  * gic_send_sgi - send a SGI directly to given CPU interface number
@@ -1024,15 +1058,19 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq,
 {
 	struct gic_chip_data *gic = d->host_data;
 	struct irq_data *irqd = irq_desc_get_irq_data(irq_to_desc(irq));
+	const struct irq_chip *chip;
+
+	chip = (static_branch_likely(&supports_deactivate_key) &&
+		gic == &gic_data[0]) ? &gic_chip_mode1 : &gic_chip;
 
 	switch (hw) {
 	case 0 ... 31:
 		irq_set_percpu_devid(irq);
-		irq_domain_set_info(d, irq, hw, &gic->chip, d->host_data,
+		irq_domain_set_info(d, irq, hw, chip, d->host_data,
 				    handle_percpu_devid_irq, NULL, NULL);
 		break;
 	default:
-		irq_domain_set_info(d, irq, hw, &gic->chip, d->host_data,
+		irq_domain_set_info(d, irq, hw, chip, d->host_data,
 				    handle_fasteoi_irq, NULL, NULL);
 		irq_set_probe(irq);
 		irqd_set_single_target(irqd);
@@ -1127,25 +1165,6 @@ static const struct irq_domain_ops gic_irq_domain_ops = {
 	.unmap = gic_irq_domain_unmap,
 };
 
-static void gic_init_chip(struct gic_chip_data *gic, const char *name,
-			  bool use_eoimode1)
-{
-	/* Initialize irq_chip */
-	gic->chip = gic_chip;
-	gic->chip.name = name;
-
-	if (use_eoimode1) {
-		gic->chip.irq_mask = gic_eoimode1_mask_irq;
-		gic->chip.irq_eoi = gic_eoimode1_eoi_irq;
-		gic->chip.irq_set_vcpu_affinity = gic_irq_set_vcpu_affinity;
-	}
-
-	if (gic == &gic_data[0]) {
-		gic->chip.irq_set_affinity = gic_set_affinity;
-		gic->chip.ipi_send_mask = gic_ipi_send_mask;
-	}
-}
-
 static int gic_init_bases(struct gic_chip_data *gic,
 			  struct fwnode_handle *handle)
 {
@@ -1245,7 +1264,6 @@ static int gic_init_bases(struct gic_chip_data *gic,
 static int __init __gic_init_bases(struct gic_chip_data *gic,
 				   struct fwnode_handle *handle)
 {
-	char *name;
 	int i, ret;
 
 	if (WARN_ON(!gic || gic->domain))
@@ -1265,18 +1283,8 @@ static int __init __gic_init_bases(struct gic_chip_data *gic,
 			pr_info("GIC: Using split EOI/Deactivate mode\n");
 	}
 
-	if (static_branch_likely(&supports_deactivate_key) && gic == &gic_data[0]) {
-		name = kasprintf(GFP_KERNEL, "GICv2");
-		gic_init_chip(gic, name, true);
-	} else {
-		name = kasprintf(GFP_KERNEL, "GIC-%d", (int)(gic-&gic_data[0]));
-		gic_init_chip(gic, name, false);
-	}
-
 	ret = gic_init_bases(gic, handle);
-	if (ret)
-		kfree(name);
-	else if (gic == &gic_data[0])
+	if (gic == &gic_data[0])
 		gic_smp_init();
 
 	return ret;
@@ -1459,8 +1467,6 @@ int gic_of_init_child(struct device *dev, struct gic_chip_data **gic, int irq)
 	if (!*gic)
 		return -ENOMEM;
 
-	gic_init_chip(*gic, dev->of_node->name, false);
-
 	ret = gic_of_setup(*gic, dev->of_node);
 	if (ret)
 		return ret;
Signature · 1 line
2.30.2
Reviewed-by on v1 3/10
#6 lore raw

Re: [PATCH 03/10] irqchip/gic: Switch to dynamic chip name output

Quoted 7 lines · Marc Zyngier

The last dynamic aspect of the GIC's irq_chip structure is the name that is associated to it.

Move the output of that name to the relevant callback, which allows us to do a bit of cleanup and mark the structures const.

This naming was once introduced for the ARM PB11MPCore that had two cascaded GICs (commit 58b8964990dc6) so it became a pain to see which one
was being used in /proc/interrupts arch/arm/boot/dts/arm-realview-pb11mp.dts

I see it is not appreciated to use /proc/interrupts for this type of diagnostics. Ugh. I suppose people do it for the same reason they keep using the GPIO sysfs, they like it and they know it.

Yours,
Linus Walleij

author maintainer
#7 lore raw

Re: [PATCH 03/10] irqchip/gic: Switch to dynamic chip name output

Quoted 19 lines · Linus Walleij
Quoted 7 lines · Marc Zyngier

The last dynamic aspect of the GIC's irq_chip structure is the name that is associated to it.

Move the output of that name to the relevant callback, which allows us to do a bit of cleanup and mark the structures const.

This naming was once introduced for the ARM PB11MPCore that had two cascaded GICs (commit 58b8964990dc6) so it became a pain to see which one
was being used in /proc/interrupts arch/arm/boot/dts/arm-realview-pb11mp.dts

Quoted 4 lines

I see it is not appreciated to use /proc/interrupts for this type of diagnostics. Ugh. I suppose people do it for the same reason they keep using the GPIO sysfs, they like it and they know it.

It was sort of fair game to use /proc/interrupts to track these things when we only had that. These days, we have a whole interrupt debugging infrastructure that is able to track hierarchies, domains and other state. And it isn't like we're taking away the /proc/interrupts facility at all, we only indirecting the name output it when possible.

There are also a number of advantages in keeping these data structures read-only when possible, in addition to the memory saving associated with only having a reference to the irq_chip structure.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#8 lore raw

[irqchip: irq/irqchip-next] irqchip/gic: Switch to dynamic chip name output

In reply to Marc Zyngier
The following commit has been merged into the irq/irqchip-next branch of irqchip:

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     745f1fb91fe51b4a36bc1c3dbccdbbbb978f93d2
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/745f1fb91fe51b4a36bc1c3dbccdbbbb978f93d2
Author:        Marc Zyngier <[email protected]>
AuthorDate:    Wed, 09 Feb 2022 16:26:00 
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Tue, 15 Feb 2022 11:25:46 

irqchip/gic: Switch to dynamic chip name output

The last dynamic aspect of the GIC's irq_chip structure is the name that is associated to it.

Move the output of that name to the relevant callback, which allows us to do a bit of cleanup and mark the structures const.

---
 drivers/irqchip/irq-gic.c | 102 +++++++++++++++++++------------------
 1 file changed, 54 insertions(+), 48 deletions(-)
drivers/irqchip/irq-gic.c +54 -48
index fb741b4..58ba835 100644
@@ -34,6 +34,7 @@
 #include <linux/irqdomain.h>
 #include <linux/interrupt.h>
 #include <linux/percpu.h>
+#include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/irqchip.h>
 #include <linux/irqchip/chained_irq.h>
@@ -66,7 +67,6 @@ union gic_base {
 };
 
 struct gic_chip_data {
-	struct irq_chip chip;
 	union gic_base dist_base;
 	union gic_base cpu_base;
 	void __iomem *raw_dist_base;
@@ -397,18 +397,15 @@ static void gic_handle_cascade_irq(struct irq_desc *desc)
 	chained_irq_exit(chip, desc);
 }
 
-static const struct irq_chip gic_chip = {
-	.irq_mask		= gic_mask_irq,
-	.irq_unmask		= gic_unmask_irq,
-	.irq_eoi		= gic_eoi_irq,
-	.irq_set_type		= gic_set_type,
-	.irq_retrigger          = gic_retrigger,
-	.irq_get_irqchip_state	= gic_irq_get_irqchip_state,
-	.irq_set_irqchip_state	= gic_irq_set_irqchip_state,
-	.flags			= IRQCHIP_SET_TYPE_MASKED |
-				  IRQCHIP_SKIP_SET_WAKE |
-				  IRQCHIP_MASK_ON_SUSPEND,
-};
+static void gic_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct gic_chip_data *gic = irq_data_get_irq_chip_data(d);
+
+	if (gic->domain->dev)
+		seq_printf(p, gic->domain->dev->of_node->name);
+	else
+		seq_printf(p, "GIC-%d", (int)(gic - &gic_data[0]));
+}
 
 void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq)
 {
@@ -799,8 +796,12 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
 			    bool force)
 {
 	void __iomem *reg = gic_dist_base(d) + GIC_DIST_TARGET + gic_irq(d);
+	struct gic_chip_data *gic = irq_data_get_irq_chip_data(d);
 	unsigned int cpu;
 
+	if (unlikely(gic != &gic_data[0]))
+		return -EINVAL;
+
 	if (!force)
 		cpu = cpumask_any_and(mask_val, cpu_online_mask);
 	else
@@ -880,6 +881,39 @@ static __init void gic_smp_init(void)
 #define gic_ipi_send_mask	NULL
 #endif
 
+static const struct irq_chip gic_chip = {
+	.irq_mask		= gic_mask_irq,
+	.irq_unmask		= gic_unmask_irq,
+	.irq_eoi		= gic_eoi_irq,
+	.irq_set_type		= gic_set_type,
+	.irq_retrigger          = gic_retrigger,
+	.irq_set_affinity	= gic_set_affinity,
+	.ipi_send_mask		= gic_ipi_send_mask,
+	.irq_get_irqchip_state	= gic_irq_get_irqchip_state,
+	.irq_set_irqchip_state	= gic_irq_set_irqchip_state,
+	.irq_print_chip		= gic_irq_print_chip,
+	.flags			= IRQCHIP_SET_TYPE_MASKED |
+				  IRQCHIP_SKIP_SET_WAKE |
+				  IRQCHIP_MASK_ON_SUSPEND,
+};
+
+static const struct irq_chip gic_chip_mode1 = {
+	.name			= "GICv2",
+	.irq_mask		= gic_eoimode1_mask_irq,
+	.irq_unmask		= gic_unmask_irq,
+	.irq_eoi		= gic_eoimode1_eoi_irq,
+	.irq_set_type		= gic_set_type,
+	.irq_retrigger          = gic_retrigger,
+	.irq_set_affinity	= gic_set_affinity,
+	.ipi_send_mask		= gic_ipi_send_mask,
+	.irq_get_irqchip_state	= gic_irq_get_irqchip_state,
+	.irq_set_irqchip_state	= gic_irq_set_irqchip_state,
+	.irq_set_vcpu_affinity	= gic_irq_set_vcpu_affinity,
+	.flags			= IRQCHIP_SET_TYPE_MASKED |
+				  IRQCHIP_SKIP_SET_WAKE |
+				  IRQCHIP_MASK_ON_SUSPEND,
+};
+
 #ifdef CONFIG_BL_SWITCHER
 /*
  * gic_send_sgi - send a SGI directly to given CPU interface number
@@ -1024,15 +1058,19 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq,
 {
 	struct gic_chip_data *gic = d->host_data;
 	struct irq_data *irqd = irq_desc_get_irq_data(irq_to_desc(irq));
+	const struct irq_chip *chip;
+
+	chip = (static_branch_likely(&supports_deactivate_key) &&
+		gic == &gic_data[0]) ? &gic_chip_mode1 : &gic_chip;
 
 	switch (hw) {
 	case 0 ... 31:
 		irq_set_percpu_devid(irq);
-		irq_domain_set_info(d, irq, hw, &gic->chip, d->host_data,
+		irq_domain_set_info(d, irq, hw, chip, d->host_data,
 				    handle_percpu_devid_irq, NULL, NULL);
 		break;
 	default:
-		irq_domain_set_info(d, irq, hw, &gic->chip, d->host_data,
+		irq_domain_set_info(d, irq, hw, chip, d->host_data,
 				    handle_fasteoi_irq, NULL, NULL);
 		irq_set_probe(irq);
 		irqd_set_single_target(irqd);
@@ -1127,25 +1165,6 @@ static const struct irq_domain_ops gic_irq_domain_ops = {
 	.unmap = gic_irq_domain_unmap,
 };
 
-static void gic_init_chip(struct gic_chip_data *gic, const char *name,
-			  bool use_eoimode1)
-{
-	/* Initialize irq_chip */
-	gic->chip = gic_chip;
-	gic->chip.name = name;
-
-	if (use_eoimode1) {
-		gic->chip.irq_mask = gic_eoimode1_mask_irq;
-		gic->chip.irq_eoi = gic_eoimode1_eoi_irq;
-		gic->chip.irq_set_vcpu_affinity = gic_irq_set_vcpu_affinity;
-	}
-
-	if (gic == &gic_data[0]) {
-		gic->chip.irq_set_affinity = gic_set_affinity;
-		gic->chip.ipi_send_mask = gic_ipi_send_mask;
-	}
-}
-
 static int gic_init_bases(struct gic_chip_data *gic,
 			  struct fwnode_handle *handle)
 {
@@ -1245,7 +1264,6 @@ error:
 static int __init __gic_init_bases(struct gic_chip_data *gic,
 				   struct fwnode_handle *handle)
 {
-	char *name;
 	int i, ret;
 
 	if (WARN_ON(!gic || gic->domain))
@@ -1265,18 +1283,8 @@ static int __init __gic_init_bases(struct gic_chip_data *gic,
 			pr_info("GIC: Using split EOI/Deactivate mode\n");
 	}
 
-	if (static_branch_likely(&supports_deactivate_key) && gic == &gic_data[0]) {
-		name = kasprintf(GFP_KERNEL, "GICv2");
-		gic_init_chip(gic, name, true);
-	} else {
-		name = kasprintf(GFP_KERNEL, "GIC-%d", (int)(gic-&gic_data[0]));
-		gic_init_chip(gic, name, false);
-	}
-
 	ret = gic_init_bases(gic, handle);
-	if (ret)
-		kfree(name);
-	else if (gic == &gic_data[0])
+	if (gic == &gic_data[0])
 		gic_smp_init();
 
 	return ret;
@@ -1459,8 +1467,6 @@ int gic_of_init_child(struct device *dev, struct gic_chip_data **gic, int irq)
 	if (!*gic)
 		return -ENOMEM;
 
-	gic_init_chip(*gic, dev->of_node->name, false);
-
 	ret = gic_of_setup(*gic, dev->of_node);
 	if (ret)
 		return ret;
author maintainer
#9 lore raw

PATCH 4/10 irqchip/lpc32xx: Switch to dynamic chip name output

In reply to Marc Zyngier

Instead of overriding the name field with the device name, use the relevant callback. This allows us to make the irq_chip structure const.

---
 drivers/irqchip/irq-lpc32xx.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/irqchip/irq-lpc32xx.c +22 -12
index a29357f39450..4d70a857133f 100644
@@ -11,6 +11,7 @@
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
+#include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <asm/exception.h>
 
@@ -25,8 +26,8 @@
 
 struct lpc32xx_irq_chip {
 	void __iomem *base;
+	phys_addr_t addr;
 	struct irq_domain *domain;
-	struct irq_chip chip;
 };
 
 static struct lpc32xx_irq_chip *lpc32xx_mic_irqc;
@@ -118,6 +119,24 @@ static int lpc32xx_irq_set_type(struct irq_data *d, unsigned int type)
 	return 0;
 }
 
+static void lpc32xx_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct lpc32xx_irq_chip *ic = irq_data_get_irq_chip_data(d);
+
+	if (ic == lpc32xx_mic_irqc)
+		seq_printf(p, "%08x.mic", ic->addr);
+	else
+		seq_printf(p, "%08x.sic", ic->addr);
+}
+
+static const struct irq_chip lpc32xx_chip = {
+	.irq_ack	= lpc32xx_irq_ack,
+	.irq_mask	= lpc32xx_irq_mask,
+	.irq_unmask	= lpc32xx_irq_unmask,
+	.irq_set_type	= lpc32xx_irq_set_type,
+	.irq_print_chip	= lpc32xx_irq_print_chip,
+};
+
 static void __exception_irq_entry lpc32xx_handle_irq(struct pt_regs *regs)
 {
 	struct lpc32xx_irq_chip *ic = lpc32xx_mic_irqc;
@@ -153,7 +172,7 @@ static int lpc32xx_irq_domain_map(struct irq_domain *id, unsigned int virq,
 	struct lpc32xx_irq_chip *ic = id->host_data;
 
 	irq_set_chip_data(virq, ic);
-	irq_set_chip_and_handler(virq, &ic->chip, handle_level_irq);
+	irq_set_chip_and_handler(virq, &lpc32xx_chip, handle_level_irq);
 	irq_set_status_flags(virq, IRQ_LEVEL);
 	irq_set_noprobe(virq);
 
@@ -183,6 +202,7 @@ static int __init lpc32xx_of_ic_init(struct device_node *node,
 	if (!irqc)
 		return -ENOMEM;
 
+	irqc->addr = addr;
 	irqc->base = of_iomap(node, 0);
 	if (!irqc->base) {
 		pr_err("%pOF: unable to map registers\n", node);
@@ -190,21 +210,11 @@ static int __init lpc32xx_of_ic_init(struct device_node *node,
 		return -EINVAL;
 	}
 
-	irqc->chip.irq_ack = lpc32xx_irq_ack;
-	irqc->chip.irq_mask = lpc32xx_irq_mask;
-	irqc->chip.irq_unmask = lpc32xx_irq_unmask;
-	irqc->chip.irq_set_type = lpc32xx_irq_set_type;
-	if (is_mic)
-		irqc->chip.name = kasprintf(GFP_KERNEL, "%08x.mic", addr);
-	else
-		irqc->chip.name = kasprintf(GFP_KERNEL, "%08x.sic", addr);
-
 	irqc->domain = irq_domain_add_linear(node, NR_LPC32XX_IC_IRQS,
 					     &lpc32xx_irq_domain_ops, irqc);
 	if (!irqc->domain) {
 		pr_err("unable to add irq domain\n");
 		iounmap(irqc->base);
-		kfree(irqc->chip.name);
 		kfree(irqc);
 		return -ENODEV;
 	}
Signature · 1 line
2.30.2
#10 lore raw

[irqchip: irq/irqchip-next] irqchip/lpc32xx: Switch to dynamic chip name output

The following commit has been merged into the irq/irqchip-next branch of irqchip:

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     365550239f87342e3d29802fce0f5e9a044e8070
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/365550239f87342e3d29802fce0f5e9a044e8070
Author:        Marc Zyngier <[email protected]>
AuthorDate:    Wed, 09 Feb 2022 16:26:01 
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Tue, 15 Feb 2022 11:25:46 

irqchip/lpc32xx: Switch to dynamic chip name output

Instead of overriding the name field with the device name, use the relevant callback. This allows us to make the irq_chip structure const.

---
 drivers/irqchip/irq-lpc32xx.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/irqchip/irq-lpc32xx.c +22 -12
index a29357f..4d70a85 100644
@@ -11,6 +11,7 @@
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
+#include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <asm/exception.h>
 
@@ -25,8 +26,8 @@
 
 struct lpc32xx_irq_chip {
 	void __iomem *base;
+	phys_addr_t addr;
 	struct irq_domain *domain;
-	struct irq_chip chip;
 };
 
 static struct lpc32xx_irq_chip *lpc32xx_mic_irqc;
@@ -118,6 +119,24 @@ static int lpc32xx_irq_set_type(struct irq_data *d, unsigned int type)
 	return 0;
 }
 
+static void lpc32xx_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct lpc32xx_irq_chip *ic = irq_data_get_irq_chip_data(d);
+
+	if (ic == lpc32xx_mic_irqc)
+		seq_printf(p, "%08x.mic", ic->addr);
+	else
+		seq_printf(p, "%08x.sic", ic->addr);
+}
+
+static const struct irq_chip lpc32xx_chip = {
+	.irq_ack	= lpc32xx_irq_ack,
+	.irq_mask	= lpc32xx_irq_mask,
+	.irq_unmask	= lpc32xx_irq_unmask,
+	.irq_set_type	= lpc32xx_irq_set_type,
+	.irq_print_chip	= lpc32xx_irq_print_chip,
+};
+
 static void __exception_irq_entry lpc32xx_handle_irq(struct pt_regs *regs)
 {
 	struct lpc32xx_irq_chip *ic = lpc32xx_mic_irqc;
@@ -153,7 +172,7 @@ static int lpc32xx_irq_domain_map(struct irq_domain *id, unsigned int virq,
 	struct lpc32xx_irq_chip *ic = id->host_data;
 
 	irq_set_chip_data(virq, ic);
-	irq_set_chip_and_handler(virq, &ic->chip, handle_level_irq);
+	irq_set_chip_and_handler(virq, &lpc32xx_chip, handle_level_irq);
 	irq_set_status_flags(virq, IRQ_LEVEL);
 	irq_set_noprobe(virq);
 
@@ -183,6 +202,7 @@ static int __init lpc32xx_of_ic_init(struct device_node *node,
 	if (!irqc)
 		return -ENOMEM;
 
+	irqc->addr = addr;
 	irqc->base = of_iomap(node, 0);
 	if (!irqc->base) {
 		pr_err("%pOF: unable to map registers\n", node);
@@ -190,21 +210,11 @@ static int __init lpc32xx_of_ic_init(struct device_node *node,
 		return -EINVAL;
 	}
 
-	irqc->chip.irq_ack = lpc32xx_irq_ack;
-	irqc->chip.irq_mask = lpc32xx_irq_mask;
-	irqc->chip.irq_unmask = lpc32xx_irq_unmask;
-	irqc->chip.irq_set_type = lpc32xx_irq_set_type;
-	if (is_mic)
-		irqc->chip.name = kasprintf(GFP_KERNEL, "%08x.mic", addr);
-	else
-		irqc->chip.name = kasprintf(GFP_KERNEL, "%08x.sic", addr);
-
 	irqc->domain = irq_domain_add_linear(node, NR_LPC32XX_IC_IRQS,
 					     &lpc32xx_irq_domain_ops, irqc);
 	if (!irqc->domain) {
 		pr_err("unable to add irq domain\n");
 		iounmap(irqc->base);
-		kfree(irqc->chip.name);
 		kfree(irqc);
 		return -ENODEV;
 	}
author maintainer
#11 lore raw

PATCH 5/10 irqchip/mvebu-pic: Switch to dynamic chip name output

In reply to Marc Zyngier

Instead of overriding the name field, track the corresponding device and use the relevant callback to output its name.

This allows us to make the irq_chip structure const.

---
 drivers/irqchip/irq-mvebu-pic.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/irqchip/irq-mvebu-pic.c +18 -10
index 870f9866b8da..ef3d3646ccc2 100644
@@ -18,6 +18,7 @@
 #include <linux/module.h>
 #include <linux/of_irq.h>
 #include <linux/platform_device.h>
+#include <linux/seq_file.h>
 
 #define PIC_CAUSE	       0x0
 #define PIC_MASK	       0x4
@@ -29,7 +30,7 @@ struct mvebu_pic {
 	void __iomem *base;
 	u32 parent_irq;
 	struct irq_domain *domain;
-	struct irq_chip irq_chip;
+	struct platform_device *pdev;
 };
 
 static void mvebu_pic_reset(struct mvebu_pic *pic)
@@ -66,6 +67,20 @@ static void mvebu_pic_unmask_irq(struct irq_data *d)
 	writel(reg, pic->base + PIC_MASK);
 }
 
+static void mvebu_pic_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct mvebu_pic *pic = irq_data_get_irq_chip_data(d);
+
+	seq_printf(p, dev_name(&pic->pdev->dev));
+}
+
+static const struct irq_chip mvebu_pic_chip = {
+	.irq_mask	= mvebu_pic_mask_irq,
+	.irq_unmask	= mvebu_pic_unmask_irq,
+	.irq_eoi	= mvebu_pic_eoi_irq,
+	.irq_print_chip	= mvebu_pic_print_chip,
+};
+
 static int mvebu_pic_irq_map(struct irq_domain *domain, unsigned int virq,
 			     irq_hw_number_t hwirq)
 {
@@ -73,8 +88,7 @@ static int mvebu_pic_irq_map(struct irq_domain *domain, unsigned int virq,
 
 	irq_set_percpu_devid(virq);
 	irq_set_chip_data(virq, pic);
-	irq_set_chip_and_handler(virq, &pic->irq_chip,
-				 handle_percpu_devid_irq);
+	irq_set_chip_and_handler(virq, &mvebu_pic_chip, handle_percpu_devid_irq);
 	irq_set_status_flags(virq, IRQ_LEVEL);
 	irq_set_probe(virq);
 
@@ -120,22 +134,16 @@ static int mvebu_pic_probe(struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
 	struct mvebu_pic *pic;
-	struct irq_chip *irq_chip;
 
 	pic = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_pic), GFP_KERNEL);
 	if (!pic)
 		return -ENOMEM;
 
+	pic->pdev = pdev;
 	pic->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(pic->base))
 		return PTR_ERR(pic->base);
 
-	irq_chip = &pic->irq_chip;
-	irq_chip->name = dev_name(&pdev->dev);
-	irq_chip->irq_mask = mvebu_pic_mask_irq;
-	irq_chip->irq_unmask = mvebu_pic_unmask_irq;
-	irq_chip->irq_eoi = mvebu_pic_eoi_irq;
-
 	pic->parent_irq = irq_of_parse_and_map(node, 0);
 	if (pic->parent_irq <= 0) {
 		dev_err(&pdev->dev, "Failed to parse parent interrupt\n");
Signature · 1 line
2.30.2
maintainer Reviewed-by on v1 5/10
#12 lore raw

Re: [PATCH 05/10] irqchip/mvebu-pic: Switch to dynamic chip name output

Hello Marc;

Quoted 6 lines

Instead of overriding the name field, track the corresponding device and use the relevant callback to output its name.

This allows us to make the irq_chip structure const.

Thanks,

Gregory

Quoted 83 lines
---
 drivers/irqchip/irq-mvebu-pic.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/irqchip/irq-mvebu-pic.c +18 -10
index 870f9866b8da..ef3d3646ccc2 100644
@@ -18,6 +18,7 @@
 #include <linux/module.h>
 #include <linux/of_irq.h>
 #include <linux/platform_device.h>
+#include <linux/seq_file.h>
 
 #define PIC_CAUSE	       0x0
 #define PIC_MASK	       0x4
@@ -29,7 +30,7 @@ struct mvebu_pic {
 	void __iomem *base;
 	u32 parent_irq;
 	struct irq_domain *domain;
-	struct irq_chip irq_chip;
+	struct platform_device *pdev;
 };
 
 static void mvebu_pic_reset(struct mvebu_pic *pic)
@@ -66,6 +67,20 @@ static void mvebu_pic_unmask_irq(struct irq_data *d)
 	writel(reg, pic->base + PIC_MASK);
 }
 
+static void mvebu_pic_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct mvebu_pic *pic = irq_data_get_irq_chip_data(d);
+
+	seq_printf(p, dev_name(&pic->pdev->dev));
+}
+
+static const struct irq_chip mvebu_pic_chip = {
+	.irq_mask	= mvebu_pic_mask_irq,
+	.irq_unmask	= mvebu_pic_unmask_irq,
+	.irq_eoi	= mvebu_pic_eoi_irq,
+	.irq_print_chip	= mvebu_pic_print_chip,
+};
+
 static int mvebu_pic_irq_map(struct irq_domain *domain, unsigned int virq,
 			     irq_hw_number_t hwirq)
 {
@@ -73,8 +88,7 @@ static int mvebu_pic_irq_map(struct irq_domain *domain, unsigned int virq,
 
 	irq_set_percpu_devid(virq);
 	irq_set_chip_data(virq, pic);
-	irq_set_chip_and_handler(virq, &pic->irq_chip,
-				 handle_percpu_devid_irq);
+	irq_set_chip_and_handler(virq, &mvebu_pic_chip, handle_percpu_devid_irq);
 	irq_set_status_flags(virq, IRQ_LEVEL);
 	irq_set_probe(virq);
 
@@ -120,22 +134,16 @@ static int mvebu_pic_probe(struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
 	struct mvebu_pic *pic;
-	struct irq_chip *irq_chip;
 
 	pic = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_pic), GFP_KERNEL);
 	if (!pic)
 		return -ENOMEM;
 
+	pic->pdev = pdev;
 	pic->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(pic->base))
 		return PTR_ERR(pic->base);
 
-	irq_chip = &pic->irq_chip;
-	irq_chip->name = dev_name(&pdev->dev);
-	irq_chip->irq_mask = mvebu_pic_mask_irq;
-	irq_chip->irq_unmask = mvebu_pic_unmask_irq;
-	irq_chip->irq_eoi = mvebu_pic_eoi_irq;
-
 	pic->parent_irq = irq_of_parse_and_map(node, 0);
 	if (pic->parent_irq <= 0) {
 		dev_err(&pdev->dev, "Failed to parse parent interrupt\n");
Signature · 1 line
2.30.2
Signature · 3 lines
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com
#13 lore raw

[irqchip: irq/irqchip-next] irqchip/mvebu-pic: Switch to dynamic chip name output

In reply to Marc Zyngier
The following commit has been merged into the irq/irqchip-next branch of irqchip:

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     421f16238a9da88ce1f2e3a103866de095cc15f6
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/421f16238a9da88ce1f2e3a103866de095cc15f6
Author:        Marc Zyngier <[email protected]>
AuthorDate:    Wed, 09 Feb 2022 16:26:02 
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Tue, 15 Feb 2022 11:25:46 

irqchip/mvebu-pic: Switch to dynamic chip name output

Instead of overriding the name field, track the corresponding device and use the relevant callback to output its name.

This allows us to make the irq_chip structure const.

---
 drivers/irqchip/irq-mvebu-pic.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/irqchip/irq-mvebu-pic.c +18 -10
index 870f986..ef3d364 100644
@@ -18,6 +18,7 @@
 #include <linux/module.h>
 #include <linux/of_irq.h>
 #include <linux/platform_device.h>
+#include <linux/seq_file.h>
 
 #define PIC_CAUSE	       0x0
 #define PIC_MASK	       0x4
@@ -29,7 +30,7 @@ struct mvebu_pic {
 	void __iomem *base;
 	u32 parent_irq;
 	struct irq_domain *domain;
-	struct irq_chip irq_chip;
+	struct platform_device *pdev;
 };
 
 static void mvebu_pic_reset(struct mvebu_pic *pic)
@@ -66,6 +67,20 @@ static void mvebu_pic_unmask_irq(struct irq_data *d)
 	writel(reg, pic->base + PIC_MASK);
 }
 
+static void mvebu_pic_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct mvebu_pic *pic = irq_data_get_irq_chip_data(d);
+
+	seq_printf(p, dev_name(&pic->pdev->dev));
+}
+
+static const struct irq_chip mvebu_pic_chip = {
+	.irq_mask	= mvebu_pic_mask_irq,
+	.irq_unmask	= mvebu_pic_unmask_irq,
+	.irq_eoi	= mvebu_pic_eoi_irq,
+	.irq_print_chip	= mvebu_pic_print_chip,
+};
+
 static int mvebu_pic_irq_map(struct irq_domain *domain, unsigned int virq,
 			     irq_hw_number_t hwirq)
 {
@@ -73,8 +88,7 @@ static int mvebu_pic_irq_map(struct irq_domain *domain, unsigned int virq,
 
 	irq_set_percpu_devid(virq);
 	irq_set_chip_data(virq, pic);
-	irq_set_chip_and_handler(virq, &pic->irq_chip,
-				 handle_percpu_devid_irq);
+	irq_set_chip_and_handler(virq, &mvebu_pic_chip, handle_percpu_devid_irq);
 	irq_set_status_flags(virq, IRQ_LEVEL);
 	irq_set_probe(virq);
 
@@ -120,22 +134,16 @@ static int mvebu_pic_probe(struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
 	struct mvebu_pic *pic;
-	struct irq_chip *irq_chip;
 
 	pic = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_pic), GFP_KERNEL);
 	if (!pic)
 		return -ENOMEM;
 
+	pic->pdev = pdev;
 	pic->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(pic->base))
 		return PTR_ERR(pic->base);
 
-	irq_chip = &pic->irq_chip;
-	irq_chip->name = dev_name(&pdev->dev);
-	irq_chip->irq_mask = mvebu_pic_mask_irq;
-	irq_chip->irq_unmask = mvebu_pic_unmask_irq;
-	irq_chip->irq_eoi = mvebu_pic_eoi_irq;
-
 	pic->parent_irq = irq_of_parse_and_map(node, 0);
 	if (pic->parent_irq <= 0) {
 		dev_err(&pdev->dev, "Failed to parse parent interrupt\n");
author maintainer
#14 lore raw

PATCH 6/10 irqchip/ts4800: Switch to dynamic chip name output

In reply to Marc Zyngier
---
 drivers/irqchip/irq-ts4800.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/irqchip/irq-ts4800.c +17 -8
index f032db23b30f..b2d61d4f6fe6 100644
@@ -19,14 +19,15 @@
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/platform_device.h>
+#include <linux/seq_file.h>
 
 #define IRQ_MASK        0x4
 #define IRQ_STATUS      0x8
 
 struct ts4800_irq_data {
 	void __iomem            *base;
+	struct platform_device	*pdev;
 	struct irq_domain       *domain;
-	struct irq_chip         irq_chip;
 };
 
 static void ts4800_irq_mask(struct irq_data *d)
@@ -47,12 +48,25 @@ static void ts4800_irq_unmask(struct irq_data *d)
 	writew(reg & ~mask, data->base + IRQ_MASK);
 }
 
+static void ts4800_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct ts4800_irq_data *data = irq_data_get_irq_chip_data(d);
+
+	seq_printf(p, "%s", dev_name(&data->pdev->dev));
+}
+
+static const struct irq_chip ts4800_chip = {
+	.irq_mask	= ts4800_irq_mask,
+	.irq_unmask	= ts4800_irq_unmask,
+	.irq_print_chip	= ts4800_irq_print_chip,
+};
+
 static int ts4800_irqdomain_map(struct irq_domain *d, unsigned int irq,
 				irq_hw_number_t hwirq)
 {
 	struct ts4800_irq_data *data = d->host_data;
 
-	irq_set_chip_and_handler(irq, &data->irq_chip, handle_simple_irq);
+	irq_set_chip_and_handler(irq, &ts4800_chip, handle_simple_irq);
 	irq_set_chip_data(irq, data);
 	irq_set_noprobe(irq);
 
@@ -92,13 +106,13 @@ static int ts4800_ic_probe(struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
 	struct ts4800_irq_data *data;
-	struct irq_chip *irq_chip;
 	int parent_irq;
 
 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
+	data->pdev = pdev;
 	data->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(data->base))
 		return PTR_ERR(data->base);
@@ -111,11 +125,6 @@ static int ts4800_ic_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	irq_chip = &data->irq_chip;
-	irq_chip->name = dev_name(&pdev->dev);
-	irq_chip->irq_mask = ts4800_irq_mask;
-	irq_chip->irq_unmask = ts4800_irq_unmask;
-
 	data->domain = irq_domain_add_linear(node, 8, &ts4800_ic_ops, data);
 	if (!data->domain) {
 		dev_err(&pdev->dev, "cannot add IRQ domain\n");
Signature · 1 line
2.30.2
#15 lore raw

[irqchip: irq/irqchip-next] irqchip/ts4800: Switch to dynamic chip name output

The following commit has been merged into the irq/irqchip-next branch of irqchip:

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     3344265a2692414831c15964dd27a5b4adc4ed83
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/3344265a2692414831c15964dd27a5b4adc4ed83
Author:        Marc Zyngier <[email protected]>
AuthorDate:    Wed, 09 Feb 2022 16:26:03 
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Tue, 15 Feb 2022 11:25:46 

irqchip/ts4800: Switch to dynamic chip name output

---
 drivers/irqchip/irq-ts4800.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/irqchip/irq-ts4800.c +17 -8
index f032db2..b2d61d4 100644
@@ -19,14 +19,15 @@
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/platform_device.h>
+#include <linux/seq_file.h>
 
 #define IRQ_MASK        0x4
 #define IRQ_STATUS      0x8
 
 struct ts4800_irq_data {
 	void __iomem            *base;
+	struct platform_device	*pdev;
 	struct irq_domain       *domain;
-	struct irq_chip         irq_chip;
 };
 
 static void ts4800_irq_mask(struct irq_data *d)
@@ -47,12 +48,25 @@ static void ts4800_irq_unmask(struct irq_data *d)
 	writew(reg & ~mask, data->base + IRQ_MASK);
 }
 
+static void ts4800_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct ts4800_irq_data *data = irq_data_get_irq_chip_data(d);
+
+	seq_printf(p, "%s", dev_name(&data->pdev->dev));
+}
+
+static const struct irq_chip ts4800_chip = {
+	.irq_mask	= ts4800_irq_mask,
+	.irq_unmask	= ts4800_irq_unmask,
+	.irq_print_chip	= ts4800_irq_print_chip,
+};
+
 static int ts4800_irqdomain_map(struct irq_domain *d, unsigned int irq,
 				irq_hw_number_t hwirq)
 {
 	struct ts4800_irq_data *data = d->host_data;
 
-	irq_set_chip_and_handler(irq, &data->irq_chip, handle_simple_irq);
+	irq_set_chip_and_handler(irq, &ts4800_chip, handle_simple_irq);
 	irq_set_chip_data(irq, data);
 	irq_set_noprobe(irq);
 
@@ -92,13 +106,13 @@ static int ts4800_ic_probe(struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
 	struct ts4800_irq_data *data;
-	struct irq_chip *irq_chip;
 	int parent_irq;
 
 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
+	data->pdev = pdev;
 	data->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(data->base))
 		return PTR_ERR(data->base);
@@ -111,11 +125,6 @@ static int ts4800_ic_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	irq_chip = &data->irq_chip;
-	irq_chip->name = dev_name(&pdev->dev);
-	irq_chip->irq_mask = ts4800_irq_mask;
-	irq_chip->irq_unmask = ts4800_irq_unmask;
-
 	data->domain = irq_domain_add_linear(node, 8, &ts4800_ic_ops, data);
 	if (!data->domain) {
 		dev_err(&pdev->dev, "cannot add IRQ domain\n");
author maintainer
#16 lore raw

PATCH 7/10 irqchip/versatile-fpga: Switch to dynamic chip name output

In reply to Marc Zyngier

Move the name output to the relevant callback, which allows us some nice cleanups (mostly owing to the fact that the driver is now DT only.

We also drop a random include directive from the ftintc010 driver.

---
 drivers/irqchip/irq-ftintc010.c        |  1 -
 drivers/irqchip/irq-versatile-fpga.c   | 46 +++++++++++++++-----------
 include/linux/irqchip/versatile-fpga.h | 14 --------
 3 files changed, 26 insertions(+), 35 deletions(-)
 delete mode 100644 include/linux/irqchip/versatile-fpga.h
drivers/irqchip/irq-ftintc010.c +0 -1
index 5cc268880f8e..46a3aa60e50e 100644
@@ -11,7 +11,6 @@
 #include <linux/irq.h>
 #include <linux/io.h>
 #include <linux/irqchip.h>
-#include <linux/irqchip/versatile-fpga.h>
 #include <linux/irqdomain.h>
 #include <linux/module.h>
 #include <linux/of.h>
drivers/irqchip/irq-versatile-fpga.c +26 -20

126 lines not on this page · raw message

include/linux/irqchip/versatile-fpga.h deleted +0 -14
deleted file mode 100644
index a978fc8c7996..000000000000
@@ -1,14 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef PLAT_FPGA_IRQ_H
-#define PLAT_FPGA_IRQ_H
-
-struct device_node;
-struct pt_regs;
-
-void fpga_handle_irq(struct pt_regs *regs);
-void fpga_irq_init(void __iomem *, const char *, int, int, u32,
-		struct device_node *node);
-int fpga_irq_of_init(struct device_node *node,
-		     struct device_node *parent);
-
-#endif
Signature · 1 line
2.30.2
Reviewed-by on v1 7/10
#17 lore raw

Re: [PATCH 07/10] irqchip/versatile-fpga: Switch to dynamic chip name output

Quoted 7 lines · Marc Zyngier

Move the name output to the relevant callback, which allows us some nice cleanups (mostly owing to the fact that the driver is now DT only.

We also drop a random include directive from the ftintc010 driver.

BTW nice cleanup.

Yours,
Linus Walleij

#18 lore raw

[irqchip: irq/irqchip-next] irqchip/versatile-fpga: Switch to dynamic chip name output

In reply to Marc Zyngier
The following commit has been merged into the irq/irqchip-next branch of irqchip:

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     3fb212a042fbd8eccbb2af1852e03ed7757b9600
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/3fb212a042fbd8eccbb2af1852e03ed7757b9600
Author:        Marc Zyngier <[email protected]>
AuthorDate:    Wed, 09 Feb 2022 16:26:04 
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Tue, 15 Feb 2022 11:25:46 

irqchip/versatile-fpga: Switch to dynamic chip name output

Move the name output to the relevant callback, which allows us some nice cleanups (mostly owing to the fact that the driver is now DT only.

We also drop a random include directive from the ftintc010 driver.

---
 drivers/irqchip/irq-ftintc010.c        |  1 +-
 drivers/irqchip/irq-versatile-fpga.c   | 46 ++++++++++++++-----------
 include/linux/irqchip/versatile-fpga.h | 14 +--------
 3 files changed, 26 insertions(+), 35 deletions(-)
 delete mode 100644 include/linux/irqchip/versatile-fpga.h
drivers/irqchip/irq-ftintc010.c +0 -1
index 5cc2688..46a3aa6 100644
@@ -11,7 +11,6 @@
 #include <linux/irq.h>
 #include <linux/io.h>
 #include <linux/irqchip.h>
-#include <linux/irqchip/versatile-fpga.h>
 #include <linux/irqdomain.h>
 #include <linux/module.h>
 #include <linux/of.h>
drivers/irqchip/irq-versatile-fpga.c +26 -20

126 lines not on this page · raw message

include/linux/irqchip/versatile-fpga.h deleted +0 -14
deleted file mode 100644
index a978fc8..0000000
@@ -1,14 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef PLAT_FPGA_IRQ_H
-#define PLAT_FPGA_IRQ_H
-
-struct device_node;
-struct pt_regs;
-
-void fpga_handle_irq(struct pt_regs *regs);
-void fpga_irq_init(void __iomem *, const char *, int, int, u32,
-		struct device_node *node);
-int fpga_irq_of_init(struct device_node *node,
-		     struct device_node *parent);
-
-#endif
author maintainer
#19 lore raw

PATCH 8/10 gpio: mt7621: Switch to dynamic chip name output

In reply to Marc Zyngier

Instead of overloading the name field, use the relevant callback to output the device name.

---
 drivers/gpio/gpio-mt7621.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/gpio/gpio-mt7621.c +11 -1
index d8a26e503ca5..14ba4bc141c9 100644
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/of_irq.h>
 #include <linux/platform_device.h>
+#include <linux/seq_file.h>
 #include <linux/spinlock.h>
 
 #define MTK_BANK_CNT	3
@@ -188,6 +189,15 @@ mediatek_gpio_irq_type(struct irq_data *d, unsigned int type)
 	return 0;
 }
 
+static void mediatek_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+	struct mtk_gc *rg = to_mediatek_gpio(gc);
+	struct mtk *mtk = container_of(rg - rg->bank, struct mtk, gc_map[0]);
+
+	seq_printf(p, dev_name(mtk->dev));
+}
+
 static int
 mediatek_gpio_xlate(struct gpio_chip *chip,
 		    const struct of_phandle_args *spec, u32 *flags)
@@ -238,11 +248,11 @@ mediatek_gpio_bank_probe(struct device *dev, int bank)
 		return -ENOMEM;
 
 	rg->chip.offset = bank * MTK_BANK_WIDTH;
-	rg->irq_chip.name = dev_name(dev);
 	rg->irq_chip.irq_unmask = mediatek_gpio_irq_unmask;
 	rg->irq_chip.irq_mask = mediatek_gpio_irq_mask;
 	rg->irq_chip.irq_mask_ack = mediatek_gpio_irq_mask;
 	rg->irq_chip.irq_set_type = mediatek_gpio_irq_type;
+	rg->irq_chip.irq_print_chip = mediatek_gpio_irq_print_chip;
 
 	if (mtk->gpio_irq) {
 		struct gpio_irq_chip *girq;
Signature · 1 line
2.30.2
author maintainer
#20 lore raw

PATCH 9/10 gpio: omap: Switch to dynamic chip name output

In reply to Marc Zyngier

Instead of overloading the name field, use the relevant callback to output the device name. Take this opportunity to fix the trailing commas that really should be semi-colons.

---
 drivers/gpio/gpio-omap.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/gpio/gpio-omap.c +18 -10
index 80ddc43fd875..f2f874f0bf95 100644
@@ -22,6 +22,7 @@
 #include <linux/pm.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/seq_file.h>
 #include <linux/gpio/driver.h>
 #include <linux/bitops.h>
 #include <linux/platform_data/gpio-omap.h>
@@ -708,6 +709,13 @@ static void omap_gpio_unmask_irq(struct irq_data *d)
 	raw_spin_unlock_irqrestore(&bank->lock, flags);
 }
 
+static void omap_gpio_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct gpio_bank *bank = omap_irq_data_get_bank(d);
+
+	seq_printf(p, dev_name(bank->chip.parent));
+}
+
 /*---------------------------------------------------------------------*/
 
 static int omap_mpuio_suspend_noirq(struct device *dev)
@@ -1393,16 +1401,16 @@ static int omap_gpio_probe(struct platform_device *pdev)
 	if (!irqc)
 		return -ENOMEM;
 
-	irqc->irq_startup = omap_gpio_irq_startup,
-	irqc->irq_shutdown = omap_gpio_irq_shutdown,
-	irqc->irq_ack = dummy_irq_chip.irq_ack,
-	irqc->irq_mask = omap_gpio_mask_irq,
-	irqc->irq_unmask = omap_gpio_unmask_irq,
-	irqc->irq_set_type = omap_gpio_irq_type,
-	irqc->irq_set_wake = omap_gpio_wake_enable,
-	irqc->irq_bus_lock = omap_gpio_irq_bus_lock,
-	irqc->irq_bus_sync_unlock = gpio_irq_bus_sync_unlock,
-	irqc->name = dev_name(&pdev->dev);
+	irqc->irq_startup = omap_gpio_irq_startup;
+	irqc->irq_shutdown = omap_gpio_irq_shutdown;
+	irqc->irq_ack = dummy_irq_chip.irq_ack;
+	irqc->irq_mask = omap_gpio_mask_irq;
+	irqc->irq_unmask = omap_gpio_unmask_irq;
+	irqc->irq_set_type = omap_gpio_irq_type;
+	irqc->irq_set_wake = omap_gpio_wake_enable;
+	irqc->irq_bus_lock = omap_gpio_irq_bus_lock;
+	irqc->irq_bus_sync_unlock = gpio_irq_bus_sync_unlock;
+	irqc->irq_print_chip = omap_gpio_irq_print_chip;
 	irqc->flags = IRQCHIP_MASK_ON_SUSPEND;
 
 	bank->irq = platform_get_irq(pdev, 0);
Signature · 1 line
2.30.2
author maintainer
#21 lore raw

PATCH 10/10 pinctrl: starfive: Switch to dynamic chip name output

In reply to Marc Zyngier

Instead of overloading the name field, use the relevant callback to output the device name.

---
 drivers/pinctrl/pinctrl-starfive.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-starfive.c +9 -2
index 5be9866c2b3c..f29d9ccf858b 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/seq_file.h>
 #include <linux/spinlock.h>
 
 #include <linux/pinctrl/pinctrl.h>
@@ -1163,12 +1164,20 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
 	return 0;
 }
 
+static void starfive_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+	struct starfive_pinctrl *sfp = starfive_from_irq_data(d);
+
+	seq_printf(p, sfp->gc.label);
+}
+
 static struct irq_chip starfive_irq_chip = {
 	.irq_ack = starfive_irq_ack,
 	.irq_mask = starfive_irq_mask,
 	.irq_mask_ack = starfive_irq_mask_ack,
 	.irq_unmask = starfive_irq_unmask,
 	.irq_set_type = starfive_irq_set_type,
+	.irq_print_chip = starfive_irq_print_chip,
 	.flags = IRQCHIP_SET_TYPE_MASKED,
 };
 
@@ -1307,8 +1316,6 @@ static int starfive_probe(struct platform_device *pdev)
 	sfp->gc.base = -1;
 	sfp->gc.ngpio = NR_GPIOS;
 
-	starfive_irq_chip.name = sfp->gc.label;
-
 	sfp->gc.irq.chip = &starfive_irq_chip;
 	sfp->gc.irq.parent_handler = starfive_gpio_irq_handler;
 	sfp->gc.irq.num_parents = 1;
Signature · 1 line
2.30.2
#22 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

Quoted 31 lines · Marc Zyngier

Instead of overloading the name field, use the relevant callback to output the device name.

---
 drivers/pinctrl/pinctrl-starfive.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-starfive.c +7 -0
index 5be9866c2b3c..f29d9ccf858b 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/seq_file.h>
 #include <linux/spinlock.h>
 
 #include <linux/pinctrl/pinctrl.h>
@@ -1163,12 +1164,20 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
        return 0;
 }
 
+static void starfive_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+       struct starfive_pinctrl *sfp = starfive_from_irq_data(d);
+
+       seq_printf(p, sfp->gc.label);
+}

drivers/pinctrl/pinctrl-starfive.c static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger) · line 1182

Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c +2 -0
+
 static struct irq_chip starfive_irq_chip = {
        .irq_ack = starfive_irq_ack,
        .irq_mask = starfive_irq_mask,
        .irq_mask_ack = starfive_irq_mask_ack,
        .irq_unmask = starfive_irq_unmask,
        .irq_set_type = starfive_irq_set_type,
+       .irq_print_chip = starfive_irq_print_chip,
        .flags = IRQCHIP_SET_TYPE_MASKED,
 };

The parent interrupt doesn't show up in /proc/interrupts anyway, so if setting the name is considered abuse we can just drop the addition above and just delete the two lines below.

The gpio framework seems to fill in default handlers in the struct above, so unfortunately it can't yet be made const. Is this something you intend to fix in the future?

Quoted 12 lines
drivers/pinctrl/pinctrl-starfive.c +0 -3
@@ -1307,8 +1316,6 @@ static int starfive_probe(struct platform_device *pdev)
        sfp->gc.base = -1;
        sfp->gc.ngpio = NR_GPIOS;
 
-       starfive_irq_chip.name = sfp->gc.label;
-
        sfp->gc.irq.chip = &starfive_irq_chip;
        sfp->gc.irq.parent_handler = starfive_gpio_irq_handler;
        sfp->gc.irq.num_parents = 1;
--

2.30.2

author maintainer
#23 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

Quoted 39 lines · Emil Renner Berthing
Quoted 37 lines · Marc Zyngier

Instead of overloading the name field, use the relevant callback to output the device name.

---
 drivers/pinctrl/pinctrl-starfive.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-starfive.c +8 -0
index 5be9866c2b3c..f29d9ccf858b 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/seq_file.h>
 #include <linux/spinlock.h>
 
 #include <linux/pinctrl/pinctrl.h>
@@ -1163,12 +1164,20 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
        return 0;
 }
 
+static void starfive_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+       struct starfive_pinctrl *sfp = starfive_from_irq_data(d);
+
+       seq_printf(p, sfp->gc.label);
+}
+
 static struct irq_chip starfive_irq_chip = {
        .irq_ack = starfive_irq_ack,
        .irq_mask = starfive_irq_mask,
        .irq_mask_ack = starfive_irq_mask_ack,
        .irq_unmask = starfive_irq_unmask,
Quoted 8 lines

drivers/pinctrl/pinctrl-starfive.c static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger) · line 1182

Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c +1 -0
        .irq_set_type = starfive_irq_set_type,
+       .irq_print_chip = starfive_irq_print_chip,
        .flags = IRQCHIP_SET_TYPE_MASKED,
 };

The parent interrupt doesn't show up in /proc/interrupts anyway, so if setting the name is considered abuse we can just drop the addition above and just delete the two lines below.

Are you sure this never appears? Is there a another irqchip stacked on top of this one? Could you please dump /sys/kernel/debug/irq/irqs/XX, where XX is an interrupt number using one of these GPIO pins? Please run it without this patch, as I just noticed that debugfs blindly uses the name.

Quoted 3 lines

The gpio framework seems to fill in default handlers in the struct above, so unfortunately it can't yet be made const. Is this something you intend to fix in the future?

This is next on my list of things to address. The whole 'let's copy a whole irqchip structure and hijack random pointers' should not have happened, and it certainly is going to be an interesting ride.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#24 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

Quoted 50 lines · Marc Zyngier
Quoted 39 lines · Emil Renner Berthing
Quoted 37 lines · Marc Zyngier

Instead of overloading the name field, use the relevant callback to output the device name.

---
 drivers/pinctrl/pinctrl-starfive.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-starfive.c +8 -0
index 5be9866c2b3c..f29d9ccf858b 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/seq_file.h>
 #include <linux/spinlock.h>
 
 #include <linux/pinctrl/pinctrl.h>
@@ -1163,12 +1164,20 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
        return 0;
 }
 
+static void starfive_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+       struct starfive_pinctrl *sfp = starfive_from_irq_data(d);
+
+       seq_printf(p, sfp->gc.label);
+}
+
 static struct irq_chip starfive_irq_chip = {
        .irq_ack = starfive_irq_ack,
        .irq_mask = starfive_irq_mask,
        .irq_mask_ack = starfive_irq_mask_ack,
        .irq_unmask = starfive_irq_unmask,
Quoted 8 lines

drivers/pinctrl/pinctrl-starfive.c static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger) · line 1182

Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c +1 -0
        .irq_set_type = starfive_irq_set_type,
+       .irq_print_chip = starfive_irq_print_chip,
        .flags = IRQCHIP_SET_TYPE_MASKED,
 };

The parent interrupt doesn't show up in /proc/interrupts anyway, so if setting the name is considered abuse we can just drop the addition above and just delete the two lines below.

Quoted 5 lines

Are you sure this never appears? Is there a another irqchip stacked on top of this one? Could you please dump /sys/kernel/debug/irq/irqs/XX, where XX is an interrupt number using one of these GPIO pins? Please run it without this patch, as I just noticed that debugfs blindly uses the name.

Yes, the old gpio driver this derives from used to set

    sfp->gc.irq.parent_handler = NULL

and then register its own irq handler, then the parent would show up in /proc/interrupts. But after switching to letting the gpio framework register the handler it stopped showing up.

root@visionfive~# cat /proc/interrupts
           CPU0       CPU1
  5:       5035       4907  RISC-V INTC   5 Edge      riscv-timer
  6:        960          0  SiFive PLIC   4 Edge      dw-mci
  7:       4384          0  SiFive PLIC   5 Edge      dw-mci
  8:        562          0  SiFive PLIC   6 Edge      eth0
 10:          1          0  SiFive PLIC   7 Edge      eth0
 11:          0          0  SiFive PLIC   2 Edge      dw_axi_dmac_platform
 15:       2690          0  SiFive PLIC  44 Edge      xhci-hcd:usb1
 17:          0          0  SiFive PLIC  43 Edge      104c0000.usb
 18:          0          0  SiFive PLIC   1 Edge      dw_axi_dmac_platform
 20:        234          0  SiFive PLIC  96 Edge      118b0000.i2c
 21:          0          0  SiFive PLIC  97 Edge      118c0000.i2c
 22:          7          0  SiFive PLIC  98 Edge      118d0000.trng
 28:          0          0  SiFive PLIC 101 Edge      sf_lcdc
 29:          0          0  SiFive PLIC 103 Edge      sf_vpp1
 30:          0          0  SiFive PLIC  70 Edge      12410000.spi
 31:        205          0  SiFive PLIC  73 Edge      ttyS0
 32:          0          0  SiFive PLIC  74 Edge      12450000.i2c
 33:          0          0  SiFive PLIC  80 Edge      12480000.watchdog
 34:         28          0  SiFive PLIC 122 Edge      124a0000.tmon
 37:          0          0  11910000.pinctrl  35 Edge      gpiomon
IPI0:        52        133  Rescheduling interrupts
IPI1:      2591       6924  Function call interrupts
IPI2:         0          0  CPU stop interrupts
IPI3:         0          0  IRQ work interrupts
IPI4:         0          0  Timer broadcast interrupts
root@visionfive~# cat /sys/kernel/debug/irq/irqs/26
handler:  starfive_gpio_irq_handler
device:   (null)
status:   0x00010c00
            _IRQ_NOPROBE
            _IRQ_NOREQUEST
            _IRQ_NOTHREAD
istate:   0x00000000
ddepth:   0
wdepth:   0
dstate:   0x02401200
            IRQD_ACTIVATED
            IRQD_IRQ_STARTED
            IRQD_AFFINITY_SET
            IRQD_DEFAULT_TRIGGER_SET
node:     0
affinity: 0-1
domain:  :soc:interrupt-controller@c000000
 hwirq:   0x20
 chip:    SiFive PLIC
  flags:   0x0
root@visionfive~# cat /sys/kernel/debug/irq/irqs/37
handler:  handle_edge_irq
device:   (null)
status:   0x00000403
            _IRQ_NOPROBE
istate:   0x00000020
            IRQS_ONESHOT
ddepth:   0
wdepth:   0
dstate:   0x00400203
            IRQ_TYPE_EDGE_RISING
            IRQ_TYPE_EDGE_FALLING
            IRQD_ACTIVATED
            IRQD_IRQ_STARTED
node:     0
affinity: 0-1
domain:  :soc:pinctrl@11910000
 hwirq:   0x23
 chip:    11910000.pinctrl
  flags:   0x1
             IRQCHIP_SET_TYPE_MASKED
Quoted 7 lines
Quoted 3 lines

The gpio framework seems to fill in default handlers in the struct above, so unfortunately it can't yet be made const. Is this something you intend to fix in the future?

This is next on my list of things to address. The whole 'let's copy a whole irqchip structure and hijack random pointers' should not have happened, and it certainly is going to be an interesting ride.

Sounds great, thanks.

/Emil

author maintainer
#25 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

Quoted 58 lines · Emil Renner Berthing
Quoted 50 lines · Marc Zyngier
Quoted 39 lines · Emil Renner Berthing
Quoted 37 lines · Marc Zyngier

Instead of overloading the name field, use the relevant callback to output the device name.

---
 drivers/pinctrl/pinctrl-starfive.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-starfive.c +8 -0
index 5be9866c2b3c..f29d9ccf858b 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/seq_file.h>
 #include <linux/spinlock.h>
 
 #include <linux/pinctrl/pinctrl.h>
@@ -1163,12 +1164,20 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
        return 0;
 }
 
+static void starfive_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+       struct starfive_pinctrl *sfp = starfive_from_irq_data(d);
+
+       seq_printf(p, sfp->gc.label);
+}
+
 static struct irq_chip starfive_irq_chip = {
        .irq_ack = starfive_irq_ack,
        .irq_mask = starfive_irq_mask,
        .irq_mask_ack = starfive_irq_mask_ack,
        .irq_unmask = starfive_irq_unmask,
Quoted 8 lines

drivers/pinctrl/pinctrl-starfive.c static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger) · line 1182

Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c +1 -0
        .irq_set_type = starfive_irq_set_type,
+       .irq_print_chip = starfive_irq_print_chip,
        .flags = IRQCHIP_SET_TYPE_MASKED,
 };

The parent interrupt doesn't show up in /proc/interrupts anyway, so if setting the name is considered abuse we can just drop the addition above and just delete the two lines below.

Quoted 5 lines

Are you sure this never appears? Is there a another irqchip stacked on top of this one? Could you please dump /sys/kernel/debug/irq/irqs/XX, where XX is an interrupt number using one of these GPIO pins? Please run it without this patch, as I just noticed that debugfs blindly uses the name.

Quoted 5 lines

Yes, the old gpio driver this derives from used to set

    sfp->gc.irq.parent_handler = NULL

and then register its own irq handler, then the parent would show up in /proc/interrupts. But after switching to letting the gpio framework register the handler it stopped showing up.

But this patch does not deal with the parent interrupt. It deals with the irqchip that is used for the 'children interrupt'. Output interrupts for a chained handler are never shown, as they don't really make much sense on their own (you'd only see the sum of the input interrupts).

Quoted 15 lines
root@visionfive~# cat /proc/interrupts
           CPU0       CPU1
  5:       5035       4907  RISC-V INTC   5 Edge      riscv-timer
  6:        960          0  SiFive PLIC   4 Edge      dw-mci
  7:       4384          0  SiFive PLIC   5 Edge      dw-mci
  8:        562          0  SiFive PLIC   6 Edge      eth0
 10:          1          0  SiFive PLIC   7 Edge      eth0
 11:          0          0  SiFive PLIC   2 Edge      dw_axi_dmac_platform
 15:       2690          0  SiFive PLIC  44 Edge      xhci-hcd:usb1
 17:          0          0  SiFive PLIC  43 Edge      104c0000.usb
 18:          0          0  SiFive PLIC   1 Edge      dw_axi_dmac_platform
 20:        234          0  SiFive PLIC  96 Edge      118b0000.i2c
 21:          0          0  SiFive PLIC  97 Edge      118c0000.i2c
 22:          7          0  SiFive PLIC  98 Edge      118d0000.trng
Quoted 8 lines
 28:          0          0  SiFive PLIC 101 Edge      sf_lcdc
 29:          0          0  SiFive PLIC 103 Edge      sf_vpp1
 30:          0          0  SiFive PLIC  70 Edge      12410000.spi
 31:        205          0  SiFive PLIC  73 Edge      ttyS0
 32:          0          0  SiFive PLIC  74 Edge      12450000.i2c
 33:          0          0  SiFive PLIC  80 Edge      12480000.watchdog
 34:         28          0  SiFive PLIC 122 Edge      124a0000.tmon
 37:          0          0  11910000.pinctrl  35 Edge      gpiomon
                              ^^^^^^^^^^^^^^^^

This is what this patch deals with. Going with your suggestion of dropping this output (or to hardcode it to something else) would be a userspace visible change, and we can't do that.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Reviewed-by Tested-by
#26 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

Quoted 66 lines · Marc Zyngier
Quoted 58 lines · Emil Renner Berthing
Quoted 50 lines · Marc Zyngier
Quoted 39 lines · Emil Renner Berthing
Quoted 37 lines · Marc Zyngier

Instead of overloading the name field, use the relevant callback to output the device name.

---
 drivers/pinctrl/pinctrl-starfive.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-starfive.c +8 -0
index 5be9866c2b3c..f29d9ccf858b 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/seq_file.h>
 #include <linux/spinlock.h>
 
 #include <linux/pinctrl/pinctrl.h>
@@ -1163,12 +1164,20 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
        return 0;
 }
 
+static void starfive_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+       struct starfive_pinctrl *sfp = starfive_from_irq_data(d);
+
+       seq_printf(p, sfp->gc.label);
+}
+
 static struct irq_chip starfive_irq_chip = {
        .irq_ack = starfive_irq_ack,
        .irq_mask = starfive_irq_mask,
        .irq_mask_ack = starfive_irq_mask_ack,
        .irq_unmask = starfive_irq_unmask,
Quoted 8 lines

drivers/pinctrl/pinctrl-starfive.c static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger) · line 1182

Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c +1 -0
        .irq_set_type = starfive_irq_set_type,
+       .irq_print_chip = starfive_irq_print_chip,
        .flags = IRQCHIP_SET_TYPE_MASKED,
 };

The parent interrupt doesn't show up in /proc/interrupts anyway, so if setting the name is considered abuse we can just drop the addition above and just delete the two lines below.

Quoted 5 lines

Are you sure this never appears? Is there a another irqchip stacked on top of this one? Could you please dump /sys/kernel/debug/irq/irqs/XX, where XX is an interrupt number using one of these GPIO pins? Please run it without this patch, as I just noticed that debugfs blindly uses the name.

Quoted 5 lines

Yes, the old gpio driver this derives from used to set

    sfp->gc.irq.parent_handler = NULL

and then register its own irq handler, then the parent would show up in /proc/interrupts. But after switching to letting the gpio framework register the handler it stopped showing up.

Quoted 5 lines

But this patch does not deal with the parent interrupt. It deals with the irqchip that is used for the 'children interrupt'. Output interrupts for a chained handler are never shown, as they don't really make much sense on their own (you'd only see the sum of the input interrupts).

I see. Sorry for the confusion.

Quoted 23 lines
Quoted 15 lines
root@visionfive~# cat /proc/interrupts
           CPU0       CPU1
  5:       5035       4907  RISC-V INTC   5 Edge      riscv-timer
  6:        960          0  SiFive PLIC   4 Edge      dw-mci
  7:       4384          0  SiFive PLIC   5 Edge      dw-mci
  8:        562          0  SiFive PLIC   6 Edge      eth0
 10:          1          0  SiFive PLIC   7 Edge      eth0
 11:          0          0  SiFive PLIC   2 Edge      dw_axi_dmac_platform
 15:       2690          0  SiFive PLIC  44 Edge      xhci-hcd:usb1
 17:          0          0  SiFive PLIC  43 Edge      104c0000.usb
 18:          0          0  SiFive PLIC   1 Edge      dw_axi_dmac_platform
 20:        234          0  SiFive PLIC  96 Edge      118b0000.i2c
 21:          0          0  SiFive PLIC  97 Edge      118c0000.i2c
 22:          7          0  SiFive PLIC  98 Edge      118d0000.trng
Quoted 8 lines
 28:          0          0  SiFive PLIC 101 Edge      sf_lcdc
 29:          0          0  SiFive PLIC 103 Edge      sf_vpp1
 30:          0          0  SiFive PLIC  70 Edge      12410000.spi
 31:        205          0  SiFive PLIC  73 Edge      ttyS0
 32:          0          0  SiFive PLIC  74 Edge      12450000.i2c
 33:          0          0  SiFive PLIC  80 Edge      12480000.watchdog
 34:         28          0  SiFive PLIC 122 Edge      124a0000.tmon
 37:          0          0  11910000.pinctrl  35 Edge      gpiomon
Quoted 4 lines
                              ^^^^^^^^^^^^^^^^

This is what this patch deals with. Going with your suggestion of dropping this output (or to hardcode it to something else) would be a userspace visible change, and we can't do that.

Gotcha. The SoC has been out in very few numbers for less than a year and the driver only entered mainline in 5.17-rc1, so I doubt anyone has had time to write scripts that check for this, but I'll let it be up to you.

Thanks.
/Emil

author maintainer
#27 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

Quoted 104 lines · Emil Renner Berthing
Quoted 66 lines · Marc Zyngier
Quoted 58 lines · Emil Renner Berthing
Quoted 50 lines · Marc Zyngier
Quoted 39 lines · Emil Renner Berthing
Quoted 37 lines · Marc Zyngier

Instead of overloading the name field, use the relevant callback to output the device name.

---
 drivers/pinctrl/pinctrl-starfive.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-starfive.c +8 -0
index 5be9866c2b3c..f29d9ccf858b 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/seq_file.h>
 #include <linux/spinlock.h>
 
 #include <linux/pinctrl/pinctrl.h>
@@ -1163,12 +1164,20 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
        return 0;
 }
 
+static void starfive_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+       struct starfive_pinctrl *sfp = starfive_from_irq_data(d);
+
+       seq_printf(p, sfp->gc.label);
+}
+
 static struct irq_chip starfive_irq_chip = {
        .irq_ack = starfive_irq_ack,
        .irq_mask = starfive_irq_mask,
        .irq_mask_ack = starfive_irq_mask_ack,
        .irq_unmask = starfive_irq_unmask,
Quoted 8 lines

drivers/pinctrl/pinctrl-starfive.c static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger) · line 1182

Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c +1 -0
        .irq_set_type = starfive_irq_set_type,
+       .irq_print_chip = starfive_irq_print_chip,
        .flags = IRQCHIP_SET_TYPE_MASKED,
 };

The parent interrupt doesn't show up in /proc/interrupts anyway, so if setting the name is considered abuse we can just drop the addition above and just delete the two lines below.

Quoted 5 lines

Are you sure this never appears? Is there a another irqchip stacked on top of this one? Could you please dump /sys/kernel/debug/irq/irqs/XX, where XX is an interrupt number using one of these GPIO pins? Please run it without this patch, as I just noticed that debugfs blindly uses the name.

Quoted 5 lines

Yes, the old gpio driver this derives from used to set

    sfp->gc.irq.parent_handler = NULL

and then register its own irq handler, then the parent would show up in /proc/interrupts. But after switching to letting the gpio framework register the handler it stopped showing up.

Quoted 5 lines

But this patch does not deal with the parent interrupt. It deals with the irqchip that is used for the 'children interrupt'. Output interrupts for a chained handler are never shown, as they don't really make much sense on their own (you'd only see the sum of the input interrupts).

I see. Sorry for the confusion.

Quoted 23 lines
Quoted 15 lines
root@visionfive~# cat /proc/interrupts
           CPU0       CPU1
  5:       5035       4907  RISC-V INTC   5 Edge      riscv-timer
  6:        960          0  SiFive PLIC   4 Edge      dw-mci
  7:       4384          0  SiFive PLIC   5 Edge      dw-mci
  8:        562          0  SiFive PLIC   6 Edge      eth0
 10:          1          0  SiFive PLIC   7 Edge      eth0
 11:          0          0  SiFive PLIC   2 Edge      dw_axi_dmac_platform
 15:       2690          0  SiFive PLIC  44 Edge      xhci-hcd:usb1
 17:          0          0  SiFive PLIC  43 Edge      104c0000.usb
 18:          0          0  SiFive PLIC   1 Edge      dw_axi_dmac_platform
 20:        234          0  SiFive PLIC  96 Edge      118b0000.i2c
 21:          0          0  SiFive PLIC  97 Edge      118c0000.i2c
 22:          7          0  SiFive PLIC  98 Edge      118d0000.trng
Quoted 8 lines
 28:          0          0  SiFive PLIC 101 Edge      sf_lcdc
 29:          0          0  SiFive PLIC 103 Edge      sf_vpp1
 30:          0          0  SiFive PLIC  70 Edge      12410000.spi
 31:        205          0  SiFive PLIC  73 Edge      ttyS0
 32:          0          0  SiFive PLIC  74 Edge      12450000.i2c
 33:          0          0  SiFive PLIC  80 Edge      12480000.watchdog
 34:         28          0  SiFive PLIC 122 Edge      124a0000.tmon
 37:          0          0  11910000.pinctrl  35 Edge      gpiomon
Quoted 4 lines
                              ^^^^^^^^^^^^^^^^

This is what this patch deals with. Going with your suggestion of dropping this output (or to hardcode it to something else) would be a userspace visible change, and we can't do that.

Quoted 4 lines

Gotcha. The SoC has been out in very few numbers for less than a year and the driver only entered mainline in 5.17-rc1, so I doubt anyone has had time to write scripts that check for this, but I'll let it be up to you.

Ah, I should have checked that. In which case, would you be OK if I simply pushed the removal of this label as a fix for 5.17, and just have it to say "Star5 GPIO", for example, without any indication of the device (which appears in debugfs anyway as part of the irqdomain)?

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#28 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

Quoted 111 lines · Marc Zyngier
Quoted 104 lines · Emil Renner Berthing
Quoted 66 lines · Marc Zyngier
Quoted 58 lines · Emil Renner Berthing
Quoted 50 lines · Marc Zyngier
Quoted 39 lines · Emil Renner Berthing
Quoted 37 lines · Marc Zyngier

Instead of overloading the name field, use the relevant callback to output the device name.

---
 drivers/pinctrl/pinctrl-starfive.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-starfive.c +8 -0
index 5be9866c2b3c..f29d9ccf858b 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/seq_file.h>
 #include <linux/spinlock.h>
 
 #include <linux/pinctrl/pinctrl.h>
@@ -1163,12 +1164,20 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
        return 0;
 }
 
+static void starfive_irq_print_chip(struct irq_data *d, struct seq_file *p)
+{
+       struct starfive_pinctrl *sfp = starfive_from_irq_data(d);
+
+       seq_printf(p, sfp->gc.label);
+}
+
 static struct irq_chip starfive_irq_chip = {
        .irq_ack = starfive_irq_ack,
        .irq_mask = starfive_irq_mask,
        .irq_mask_ack = starfive_irq_mask_ack,
        .irq_unmask = starfive_irq_unmask,
Quoted 8 lines

drivers/pinctrl/pinctrl-starfive.c static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger) · line 1182

Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c +1 -0
        .irq_set_type = starfive_irq_set_type,
+       .irq_print_chip = starfive_irq_print_chip,
        .flags = IRQCHIP_SET_TYPE_MASKED,
 };

The parent interrupt doesn't show up in /proc/interrupts anyway, so if setting the name is considered abuse we can just drop the addition above and just delete the two lines below.

Quoted 5 lines

Are you sure this never appears? Is there a another irqchip stacked on top of this one? Could you please dump /sys/kernel/debug/irq/irqs/XX, where XX is an interrupt number using one of these GPIO pins? Please run it without this patch, as I just noticed that debugfs blindly uses the name.

Quoted 5 lines

Yes, the old gpio driver this derives from used to set

    sfp->gc.irq.parent_handler = NULL

and then register its own irq handler, then the parent would show up in /proc/interrupts. But after switching to letting the gpio framework register the handler it stopped showing up.

Quoted 5 lines

But this patch does not deal with the parent interrupt. It deals with the irqchip that is used for the 'children interrupt'. Output interrupts for a chained handler are never shown, as they don't really make much sense on their own (you'd only see the sum of the input interrupts).

I see. Sorry for the confusion.

Quoted 23 lines
Quoted 15 lines
root@visionfive~# cat /proc/interrupts
           CPU0       CPU1
  5:       5035       4907  RISC-V INTC   5 Edge      riscv-timer
  6:        960          0  SiFive PLIC   4 Edge      dw-mci
  7:       4384          0  SiFive PLIC   5 Edge      dw-mci
  8:        562          0  SiFive PLIC   6 Edge      eth0
 10:          1          0  SiFive PLIC   7 Edge      eth0
 11:          0          0  SiFive PLIC   2 Edge      dw_axi_dmac_platform
 15:       2690          0  SiFive PLIC  44 Edge      xhci-hcd:usb1
 17:          0          0  SiFive PLIC  43 Edge      104c0000.usb
 18:          0          0  SiFive PLIC   1 Edge      dw_axi_dmac_platform
 20:        234          0  SiFive PLIC  96 Edge      118b0000.i2c
 21:          0          0  SiFive PLIC  97 Edge      118c0000.i2c
 22:          7          0  SiFive PLIC  98 Edge      118d0000.trng
Quoted 8 lines
 28:          0          0  SiFive PLIC 101 Edge      sf_lcdc
 29:          0          0  SiFive PLIC 103 Edge      sf_vpp1
 30:          0          0  SiFive PLIC  70 Edge      12410000.spi
 31:        205          0  SiFive PLIC  73 Edge      ttyS0
 32:          0          0  SiFive PLIC  74 Edge      12450000.i2c
 33:          0          0  SiFive PLIC  80 Edge      12480000.watchdog
 34:         28          0  SiFive PLIC 122 Edge      124a0000.tmon
 37:          0          0  11910000.pinctrl  35 Edge      gpiomon
Quoted 4 lines
                              ^^^^^^^^^^^^^^^^

This is what this patch deals with. Going with your suggestion of dropping this output (or to hardcode it to something else) would be a userspace visible change, and we can't do that.

Quoted 4 lines

Gotcha. The SoC has been out in very few numbers for less than a year and the driver only entered mainline in 5.17-rc1, so I doubt anyone has had time to write scripts that check for this, but I'll let it be up to you.

Quoted 4 lines

Ah, I should have checked that. In which case, would you be OK if I simply pushed the removal of this label as a fix for 5.17, and just have it to say "Star5 GPIO", for example, without any indication of the device (which appears in debugfs anyway as part of the irqdomain)?

I'm fine with it although I'd prefer "StarFive GPIO". I haven't seen star5 used anywhere.
But shouldn't changes like this normally go through Linus Walleij's tree?

/Emil

author maintainer
#29 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

Quoted 10 lines · Emil Renner Berthing
Quoted 8 lines · Marc Zyngier
Quoted 5 lines · Emil Renner Berthing

Gotcha. The SoC has been out in very few numbers for less than a year and the driver only entered mainline in 5.17-rc1, so I doubt anyone has had time to write scripts that check for this, but I'll let it be up to you.

Quoted 7 lines
Quoted 4 lines

Ah, I should have checked that. In which case, would you be OK if I simply pushed the removal of this label as a fix for 5.17, and just have it to say "Star5 GPIO", for example, without any indication of the device (which appears in debugfs anyway as part of the irqdomain)?

I'm fine with it although I'd prefer "StarFive GPIO". I haven't seen star5 used anywhere.

Fair enough.

Quoted 2 lines

But shouldn't changes like this normally go through Linus Walleij's tree?

Either way, I don't mind. For the record, see below what I'm suggesting we take in before 5.17-final.

Linus?

Thanks,

	M.

From a84b83c32048de2ba72e5d05645eabc95ffabe49 Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Thu, 10 Feb 2022 14:13:36 +0000
Subject: [PATCH] pinctrl: starfive: Use a static name for the GPIO irq_chip

Drop the device name used for the GPIO irq_chip and replace it with something static. The information is still available from debugfs and carried as part of the irqdomain.

---
 drivers/pinctrl/pinctrl-starfive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-starfive.c +1 -1
index 0b912152a405..266da41a6162 100644
@@ -1164,6 +1164,7 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
 }
 
 static struct irq_chip starfive_irq_chip = {
+	.name = "StarFive GPIO",
 	.irq_ack = starfive_irq_ack,
 	.irq_mask = starfive_irq_mask,
 	.irq_mask_ack = starfive_irq_mask_ack,
@@ -1308,7 +1309,6 @@ static int starfive_probe(struct platform_device *pdev)
 	sfp->gc.ngpio = NR_GPIOS;
 
 	starfive_irq_chip.parent_device = dev;
-	starfive_irq_chip.name = sfp->gc.label;
 
 	sfp->gc.irq.chip = &starfive_irq_chip;
 	sfp->gc.irq.parent_handler = starfive_gpio_irq_handler;
Signature · 5 lines
2.34.1


-- 
Without deviation from the norm, progress is not possible.
author maintainer
#30 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

In reply to Emil Renner Berthing

[resending, as I managed to royally screw up my initial email]

Quoted 10 lines · Emil Renner Berthing
Quoted 8 lines · Marc Zyngier
Quoted 5 lines · Emil Renner Berthing

Gotcha. The SoC has been out in very few numbers for less than a year and the driver only entered mainline in 5.17-rc1, so I doubt anyone has had time to write scripts that check for this, but I'll let it be up to you.

Quoted 7 lines
Quoted 4 lines

Ah, I should have checked that. In which case, would you be OK if I simply pushed the removal of this label as a fix for 5.17, and just have it to say "Star5 GPIO", for example, without any indication of the device (which appears in debugfs anyway as part of the irqdomain)?

I'm fine with it although I'd prefer "StarFive GPIO". I haven't seen star5 used anywhere.

Fair enough.

Quoted 2 lines

But shouldn't changes like this normally go through Linus Walleij's tree?

Either way, I don't mind. For the record, see below what I'm suggesting we take in before 5.17-final.

Linus?

Thanks,

	M.

From a84b83c32048de2ba72e5d05645eabc95ffabe49 Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Thu, 10 Feb 2022 14:13:36 +0000
Subject: [PATCH] pinctrl: starfive: Use a static name for the GPIO irq_chip

Drop the device name used for the GPIO irq_chip and replace it with something static. The information is still available from debugfs and carried as part of the irqdomain.

---
 drivers/pinctrl/pinctrl-starfive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-starfive.c +1 -1
index 0b912152a405..266da41a6162 100644
@@ -1164,6 +1164,7 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
 }
 
 static struct irq_chip starfive_irq_chip = {
+	.name = "StarFive GPIO",
 	.irq_ack = starfive_irq_ack,
 	.irq_mask = starfive_irq_mask,
 	.irq_mask_ack = starfive_irq_mask_ack,
@@ -1308,7 +1309,6 @@ static int starfive_probe(struct platform_device *pdev)
 	sfp->gc.ngpio = NR_GPIOS;
 
 	starfive_irq_chip.parent_device = dev;
-	starfive_irq_chip.name = sfp->gc.label;
 
 	sfp->gc.irq.chip = &starfive_irq_chip;
 	sfp->gc.irq.parent_handler = starfive_gpio_irq_handler;
Signature · 8 lines
2.34.1


-- 
Without deviation from the norm, progress is not possible.

-- 
Without deviation from the norm, progress is not possible.
#31 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

Quoted 23 lines · Marc Zyngier

[resending, as I managed to royally screw up my initial email]

Quoted 10 lines · Emil Renner Berthing
Quoted 8 lines · Marc Zyngier
Quoted 5 lines · Emil Renner Berthing

Gotcha. The SoC has been out in very few numbers for less than a year and the driver only entered mainline in 5.17-rc1, so I doubt anyone has had time to write scripts that check for this, but I'll let it be up to you.

Quoted 7 lines
Quoted 4 lines

Ah, I should have checked that. In which case, would you be OK if I simply pushed the removal of this label as a fix for 5.17, and just have it to say "Star5 GPIO", for example, without any indication of the device (which appears in debugfs anyway as part of the irqdomain)?

I'm fine with it although I'd prefer "StarFive GPIO". I haven't seen star5 used anywhere.

Quoted 7 lines

Fair enough.

Quoted 2 lines

But shouldn't changes like this normally go through Linus Walleij's tree?

Either way, I don't mind. For the record, see below what I'm suggesting we take in before 5.17-final.

Looks good to me. I don't mind which tree it goes through, just wanted to make sure everyone's happy.

Quoted 50 lines

Linus?

Thanks,

        M.

From a84b83c32048de2ba72e5d05645eabc95ffabe49 Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Thu, 10 Feb 2022 14:13:36 +0000
Subject: [PATCH] pinctrl: starfive: Use a static name for the GPIO irq_chip

Drop the device name used for the GPIO irq_chip and replace it with something static. The information is still available from debugfs and carried as part of the irqdomain.

---
 drivers/pinctrl/pinctrl-starfive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-starfive.c +1 -2
index 0b912152a405..266da41a6162 100644
@@ -1164,6 +1164,7 @@ static int starfive_irq_set_type(struct irq_data *d, unsigned int trigger)
 }
 
 static struct irq_chip starfive_irq_chip = {
+       .name = "StarFive GPIO",
        .irq_ack = starfive_irq_ack,
        .irq_mask = starfive_irq_mask,
        .irq_mask_ack = starfive_irq_mask_ack,
@@ -1308,7 +1309,6 @@ static int starfive_probe(struct platform_device *pdev)
        sfp->gc.ngpio = NR_GPIOS;
 
        starfive_irq_chip.parent_device = dev;
-       starfive_irq_chip.name = sfp->gc.label;
 
        sfp->gc.irq.chip = &starfive_irq_chip;
        sfp->gc.irq.parent_handler = starfive_gpio_irq_handler;
--

2.34.1

--
Without deviation from the norm, progress is not possible.

--
Without deviation from the norm, progress is not possible.

#32 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

In reply to Marc Zyngier
Quoted 4 lines · Marc Zyngier

Either way, I don't mind. For the record, see below what I'm suggesting we take in before 5.17-final.

Linus?

I'm game! :)

Can you send a separate patch because b4 doesn't let me pick a patch in the conversation
of a patch...

Yours,
Linus Walleij

#33 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

In reply to Marc Zyngier
Quoted 10 lines · Marc Zyngier
Quoted 3 lines · Emil Renner Berthing

The gpio framework seems to fill in default handlers in the struct above, so unfortunately it can't yet be made const. Is this something you intend to fix in the future?

This is next on my list of things to address. The whole 'let's copy a whole irqchip structure and hijack random pointers' should not have happened, and it certainly is going to be an interesting ride.

Sorry about that... Probably my bad idea. The only upside is that the things that are ugly are centralized to one spot.

Yours,
Linus Walleij

author maintainer
#34 lore raw

Re: [PATCH 10/10] pinctrl: starfive: Switch to dynamic chip name output

Quoted 9 lines · Linus Walleij
Quoted 7 lines · Marc Zyngier
Quoted 3 lines · Emil Renner Berthing

The gpio framework seems to fill in default handlers in the struct above, so unfortunately it can't yet be made const. Is this something you intend to fix in the future?

Quoted 6 lines
Quoted 3 lines

This is next on my list of things to address. The whole 'let's copy a whole irqchip structure and hijack random pointers' should not have happened, and it certainly is going to be an interesting ride.

Sorry about that... Probably my bad idea. The only upside is that the things that are ugly are centralized to one spot.

No worries. I should have kept an eye on that too and spotted it earlier. It is only when helping with the M1 GPIO driver that this was brought to my attention.

My current approach is to move each and every driver to using the existing helpers, and advertise to the core GPIO code that they don't need to be fiddled with a new irqchip flag. It is a rather simple change, but there are a lot of drivers (I have so far converted the Apple, Qualcomm and Tegra186 drivers, as this is the HW I have around), allowing their irq_chip structures to be made const and only used by reference.

Once all drivers are converted (one day), we can drop the flag and the pointer swapping code.

The alternative approach was to use a hierarchical irqchip provided by the GPIO code, but this proved difficult as it would need to know which methods to implement depending on the flow used. There are also only a handful of drivers using the hierarchical mode anyway, and we'd be stuck for all the other drivers.

Anyway, I'll post something shortly with the stuff I have changed, and we can happily repaint that bike shed.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Acked-by on the v1 series
#35 lore raw
In reply to Marc Zyngier
Quoted 4 lines · Marc Zyngier

Having done that, we can cleanup a few irqchip drivers and make their irq_chip structure const (which requires touching a handful of core functions). Whilst we're at it, we do the same for a couple of gpio drivers.

The series:

Since Bartosz is queueing GPIO patches and I am mostly playing with a baby during the daytime it's good if you also get an ACK from Bartosz on this one before applying the series.

Yours,
Linus Walleij

author maintainer
#36 lore raw
Quoted 10 lines · Linus Walleij
Quoted 4 lines · Marc Zyngier

Having done that, we can cleanup a few irqchip drivers and make their irq_chip structure const (which requires touching a handful of core functions). Whilst we're at it, we do the same for a couple of gpio drivers.

The series:

Thanks.

Quoted 4 lines

Since Bartosz is queueing GPIO patches and I am mostly playing with a baby during the daytime it's good if you also get an ACK from Bartosz on this one before applying the series.

To be on the safe side and until I hear from Bartosz, I have dropped the GPIO patches from the branch which I'm about to push into -next. If Bartosz is happy with them, I'll add them to the mix. Otherwise, they can be taken at a later time, as there is no shortage of drivers that will need reworking once we agree on the way to resolve the irqchip fiddling in gpiolib.

Have fun playing! :)

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#37 lore raw
In reply to Linus Walleij
Quoted 1 line · Linus Walleij

On Wed, Feb 9, 2022 at 5:26 PM Marc Zyngier <[email protected]> wrote:

...

Quoted 2 lines

Since ... I am mostly
playing with a baby during the daytime

A bit of a side topic, since I need to send a PR for fixes before my vacation starts tomorrow, should I Cc my PR to that Linus as well, so he can accept it?
It will contain two one-liner ID patches to pin control Intel drivers and won't conflict with anything (as far as I am aware and know).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#38 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 1 line · Linus Walleij

On Wed, Feb 9, 2022 at 5:26 PM Marc Zyngier <[email protected]> wrote:

...

Quoted 8 lines
Quoted 2 lines

Since ... I am mostly
playing with a baby during the daytime

A bit of a side topic, since I need to send a PR for fixes before my vacation starts tomorrow, should I Cc my PR to that Linus as well, so he can accept it?
It will contain two one-liner ID patches to pin control Intel drivers and won't conflict with anything (as far as I am aware and know).

I manage the pin control stuff but at a bit slow pace, so I'll pick it up!

Yours,
Linus Walleij