Skip to contentSkip to conversation

of/irq: Defer interrupt reference resolution

PATCH Applied Thierry Reding 4 participants 26 messages Sep 18, 2013 – Oct 25, 2013

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

v2 cover of/irq: Defer interrupt reference resolution

Hi,

This small series allows interrupt references from the device tree to be resolved at driver probe time, rather than at device creation time. The current implementation resolves such references while devices are added during the call to of_platform_populate(), which happens very early in the boot process. This causes probe ordering issues, because all devices that are an interrupt parent for other devices need to have been probed by that time. This is worked around for primary interrupt controllers by initializing them using a device tree specific way (of_irq_init()), but it doesn't work for something like a GPIO controller that is itself a platform device and an interrupt parent for other devices at the same time.

Currently such drivers use explicit initcall ordering to force these chips to be probed earlier than other devices, but that only fixes a subset of the problematic cases. It doesn't work if the interrupt user is itself a platform device on the same bus. There are possibly other cases where it doesn't work either.

This patch series attempts to fix this by not resolving the interrupt references at device creation time. Instead, some functionality is added to the driver core to resolve them for each device immediately before it is probed. Often this is a lot later than the point at which the device was created, which gives interrupt parents more time and therefore a better chance of being probed. More importantly, however, it allows the driver core to detect when an interrupt parent isn't there yet and cause the device to be queued for deferred probing. After all, resolving probe ordering issues is one of the primary reason for the introduction of deferred probing.

Unfortunately the interrupt core code isn't prepared to handle this very well, so some preparatory work is required.

Patches 1 and 2 are cleanup. Patch 1 modifies of_irq_count() to not use the heavyweight of_irq_to_resource(), which will actually try to create a mapping. While not usually harmful, it causes a warning during boot if the interrupt parent hasn't registered an IRQ domain yet. Furthermore it is much more than the stated intention of the function, which is to return the number of interrupts that a device node uses. Various uses of the of_irq_to_resource() function are replaced by more simpler versions using irq_of_parse_and_map() in patch 2.

Patches 3 introduces the __irq_create_mapping() function, equivalent to its non-__ counterpart except that it returns a negative error code on failure and therefore allows propagation of a precise error code instead of 0 for all errors. This is an important prerequisite for subsequent patches. I would've preferred not to introduce an underscore-prefixed variant but there are about 114 callers and updating them all would've been rather messy.

Patch 4 updates irq_create_of_mapping() to return a negative error code on failure instead of 0. The number of the mapped interrupt is returned in an output parameter. All callers of this function are updated.

Patch 5 adds an __-prefixed variant of irq_of_parse_and_map() which returns a negative error code on failure instead of 0. The number of the mapped interrupt is returned in an output parameter.

Patch 6 modifies of_irq_to_resource() to return a negative error code on failure (so that error can be propagated) and updates all callers.

Patch 7 propagates errors from of_irq_to_resource() to users of the of_irq_to_resource_table() function.

Patch 8 adds functionality to the platform driver code to resolve interrupt references at probe time. It uses the negative error code of the of_irq_to_resource_table() function to trigger deferred probing.

Patch 9 implements similar functionality for I2C devices.

Patch 10 serves as an example of the kind of cleanup that can be done after this series. Obviously this will require quite a bit of retesting of working setups, but I think that in the long run we're better off without the kind of explicit probe ordering employed by the gpio-tegra driver and many others.

Note that I've only implemented this for platform and I2C devices, but the same can be done for SPI and possibly other subsystems as well.

There is another use-case that I'm aware of for which a similar solution could be implemented. IOMMUs on SoCs generally need to hook themselves up to new platform devices. This causes a similar issues as interrupt resolution and should be fixable by extending the of_platform_probe() function introduced in patch 7 of this series.

Changes in v2:
- use more consistent naming and calling conventions
- use less wrappers, update more callers
- make of_platform_probe() idempotent

The initial version of this patch series can be found here:

	https://lkml.org/lkml/2013/9/16/111

Thierry

Thierry Reding (10):
of/irq: Rework of_irq_count()
of/irq: Use irq_of_parse_and_map()
irqdomain: Introduce __irq_create_mapping()
irqdomain: Return errors from irq_create_of_mapping() of/irq: Introduce __irq_of_parse_and_map() of/irq: Return errors from of_irq_to_resource() of/irq: Propagate errors in of_irq_to_resource_table() of/platform: Resolve interrupt references at probe time of/i2c: Resolve interrupt references at probe time
gpio: tegra: Use module_platform_driver()

 arch/arm/mach-integrator/pci_v3.c                |   8 +-
 arch/arm/mach-u300/timer.c                       |   9 +-
 arch/microblaze/pci/pci-common.c                 |   6 +-
 arch/mips/lantiq/irq.c                           |   2 +-
 arch/mips/lantiq/xway/gptu.c                     |   6 +-
 arch/mips/pci/fixup-lantiq.c                     |  12 ++-
 arch/mips/pci/pci-rt3883.c                       |   9 +-
 arch/powerpc/kernel/pci-common.c                 |   7 +-
 arch/powerpc/platforms/83xx/mpc832x_rdb.c        |   2 +-
 arch/powerpc/platforms/cell/celleb_scc_pciex.c   |   8 +-
 arch/powerpc/platforms/cell/celleb_scc_sio.c     |   8 +-
 arch/powerpc/platforms/cell/spider-pic.c         |   7 +-
 arch/powerpc/platforms/cell/spu_manage.c         |   6 +-
 arch/powerpc/platforms/fsl_uli1575.c             |   7 +-
 arch/powerpc/platforms/pseries/event_sources.c   |  12 +--
 arch/powerpc/sysdev/fsl_gtm.c                    |   9 +-
 arch/powerpc/sysdev/mpic_msgr.c                  |   6 +-
 arch/sparc/kernel/of_device_common.c             |  12 ++-
 arch/x86/kernel/devicetree.c                     |  11 ++-
 drivers/base/platform.c                          |   4 +
 drivers/crypto/caam/ctrl.c                       |   2 +-
 drivers/crypto/caam/jr.c                         |   2 +-
 drivers/crypto/omap-sham.c                       |   2 +-
 drivers/gpio/gpio-tegra.c                        |   7 +-
 drivers/i2c/busses/i2c-cpm.c                     |   2 +-
 drivers/i2c/i2c-core.c                           |  24 ++++-
 drivers/input/serio/xilinx_ps2.c                 |   7 +-
 drivers/net/ethernet/arc/emac_main.c             |  10 +--
 drivers/net/ethernet/freescale/fs_enet/mac-fcc.c |   2 +-
 drivers/net/ethernet/freescale/fs_enet/mac-fec.c |   2 +-
 drivers/net/ethernet/freescale/fs_enet/mac-scc.c |   2 +-
 drivers/net/ethernet/marvell/mv643xx_eth.c       |   5 +-
 drivers/of/irq.c                                 |  49 +++++++----
 drivers/of/platform.c                            | 107 +++++++++++++++++++++--
 drivers/pci/host/pci-mvebu.c                     |   9 +-
 drivers/spi/spi-fsl-espi.c                       |   6 +-
 drivers/tty/serial/cpm_uart/cpm_uart_core.c      |   2 +-
 drivers/tty/serial/lantiq.c                      |   2 +-
 include/linux/of_irq.h                           |  27 ++++--
 include/linux/of_platform.h                      |   7 ++
 kernel/irq/irqdomain.c                           |  87 +++++++++++-------
 41 files changed, 353 insertions(+), 161 deletions(-)
Signature · 1 line
1.8.4
#1 lore raw

PATCH v2 1/10 of/irq: Rework of_irq_count()

The of_irq_to_resource() helper that is used to implement of_irq_count() tries to resolve interrupts and in fact creates a mapping for resolved interrupts. That's pretty heavy lifting for something that claims to just return the number of interrupts requested by a given device node.

Instead, use the more lightweight of_irq_map_one(), which, despite the name, doesn't create an actual mapping. Perhaps a better name would be of_irq_translate_one().

---
 drivers/of/irq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/irq.c +2 -1
index 1752988..5f44388 100644
@@ -368,9 +368,10 @@ EXPORT_SYMBOL_GPL(of_irq_to_resource);
  */
 int of_irq_count(struct device_node *dev)
 {
+	struct of_irq irq;
 	int nr = 0;
 
-	while (of_irq_to_resource(dev, nr, NULL))
+	while (of_irq_map_one(dev, nr, &irq) == 0)
 		nr++;
 
 	return nr;
Signature · 1 line
1.8.4
Acked-by on v2 1/10
#2 lore raw

Re: [PATCH v2 01/10] of/irq: Rework of_irq_count()

Quoted 10 lines · Thierry Reding

The of_irq_to_resource() helper that is used to implement of_irq_count() tries to resolve interrupts and in fact creates a mapping for resolved interrupts. That's pretty heavy lifting for something that claims to just return the number of interrupts requested by a given device node.

Instead, use the more lightweight of_irq_map_one(), which, despite the name, doesn't create an actual mapping. Perhaps a better name would be of_irq_translate_one().

Quoted 28 lines
---
 drivers/of/irq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/irq.c +2 -2
index 1752988..5f44388 100644
@@ -368,9 +368,10 @@ EXPORT_SYMBOL_GPL(of_irq_to_resource);
  */
 int of_irq_count(struct device_node *dev)
 {
+       struct of_irq irq;
        int nr = 0;
 
-       while (of_irq_to_resource(dev, nr, NULL))
+       while (of_irq_map_one(dev, nr, &irq) == 0)
                nr++;
 
        return nr;
--

1.8.4

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw

Re: [PATCH v2 01/10] of/irq: Rework of_irq_count()

Quoted 7 lines · Rob Herring
Quoted 5 lines · Thierry Reding

The of_irq_to_resource() helper that is used to implement of_irq_count() tries to resolve interrupts and in fact creates a mapping for resolved interrupts. That's pretty heavy lifting for something that claims to just return the number of interrupts requested by a given device node.

Quoted 7 lines
Quoted 5 lines

Instead, use the more lightweight of_irq_map_one(), which, despite the name, doesn't create an actual mapping. Perhaps a better name would be of_irq_translate_one().

Applied (and fixed to match the of_irq_map_one --> of_irq_parse_one rename that I'm going to merge in v3.13).

g.

Quoted 29 lines
Quoted 29 lines
---
 drivers/of/irq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/irq.c +2 -2
index 1752988..5f44388 100644
@@ -368,9 +368,10 @@ EXPORT_SYMBOL_GPL(of_irq_to_resource);
  */
 int of_irq_count(struct device_node *dev)
 {
+       struct of_irq irq;
        int nr = 0;
 
-       while (of_irq_to_resource(dev, nr, NULL))
+       while (of_irq_map_one(dev, nr, &irq) == 0)
                nr++;
 
        return nr;
--

1.8.4

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Applied
#4 lore raw

Re: [PATCH v2 01/10] of/irq: Rework of_irq_count()

In reply to Rob Herring
Quoted 7 lines · Rob Herring
Quoted 5 lines · Thierry Reding

The of_irq_to_resource() helper that is used to implement of_irq_count() tries to resolve interrupts and in fact creates a mapping for resolved interrupts. That's pretty heavy lifting for something that claims to just return the number of interrupts requested by a given device node.

Quoted 7 lines
Quoted 5 lines

Instead, use the more lightweight of_irq_map_one(), which, despite the name, doesn't create an actual mapping. Perhaps a better name would be of_irq_translate_one().

Applied, thanks.

g.

Quoted 29 lines
Quoted 29 lines
---
 drivers/of/irq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/irq.c +2 -2
index 1752988..5f44388 100644
@@ -368,9 +368,10 @@ EXPORT_SYMBOL_GPL(of_irq_to_resource);
  */
 int of_irq_count(struct device_node *dev)
 {
+       struct of_irq irq;
        int nr = 0;
 
-       while (of_irq_to_resource(dev, nr, NULL))
+       while (of_irq_map_one(dev, nr, &irq) == 0)
                nr++;
 
        return nr;
--

1.8.4

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#5 lore raw

PATCH v2 2/10 of/irq: Use irq_of_parse_and_map()

In reply to Thierry Reding

Replace some instances of of_irq_map_one()/irq_create_of_mapping() and of_irq_to_resource() by the simpler equivalent irq_of_parse_and_map().

---
 arch/arm/mach-u300/timer.c                       |  9 ++++-----
 arch/powerpc/platforms/cell/celleb_scc_pciex.c   |  8 +++-----
 arch/powerpc/platforms/cell/spider-pic.c         |  7 ++-----
 arch/powerpc/sysdev/fsl_gtm.c                    |  9 ++++-----
 arch/powerpc/sysdev/mpic_msgr.c                  |  6 ++----
 drivers/crypto/caam/ctrl.c                       |  2 +-
 drivers/crypto/caam/jr.c                         |  2 +-
 drivers/crypto/omap-sham.c                       |  2 +-
 drivers/i2c/busses/i2c-cpm.c                     |  2 +-
 drivers/input/serio/xilinx_ps2.c                 |  7 ++++---
 drivers/net/ethernet/arc/emac_main.c             | 10 +++++-----
 drivers/net/ethernet/freescale/fs_enet/mac-fcc.c |  2 +-
 drivers/net/ethernet/freescale/fs_enet/mac-fec.c |  2 +-
 drivers/net/ethernet/freescale/fs_enet/mac-scc.c |  2 +-
 drivers/spi/spi-fsl-espi.c                       |  6 +++---
 drivers/tty/serial/cpm_uart/cpm_uart_core.c      |  2 +-
 16 files changed, 35 insertions(+), 43 deletions(-)
arch/arm/mach-u300/timer.c +4 -5
index b5db207..9a5f9fb 100644
@@ -358,8 +358,7 @@ static struct delay_timer u300_delay_timer;
  */
 static void __init u300_timer_init_of(struct device_node *np)
 {
-	struct resource irq_res;
-	int irq;
+	unsigned int irq;
 	struct clk *clk;
 	unsigned long rate;
 
@@ -368,11 +367,11 @@ static void __init u300_timer_init_of(struct device_node *np)
 		panic("could not ioremap system timer\n");
 
 	/* Get the IRQ for the GP1 timer */
-	irq = of_irq_to_resource(np, 2, &irq_res);
-	if (irq <= 0)
+	irq = irq_of_parse_and_map(np, 2);
+	if (!irq)
 		panic("no IRQ for system timer\n");
 
-	pr_info("U300 GP1 timer @ base: %p, IRQ: %d\n", u300_timer_base, irq);
+	pr_info("U300 GP1 timer @ base: %p, IRQ: %u\n", u300_timer_base, irq);
 
 	/* Clock the interrupt controller */
 	clk = of_clk_get(np, 0);
arch/powerpc/platforms/cell/celleb_scc_pciex.c +3 -5
index 14be2bd..856ad64 100644
@@ -486,8 +486,7 @@ static __init int celleb_setup_pciex(struct device_node *node,
 				     struct pci_controller *phb)
 {
 	struct resource	r;
-	struct of_irq oirq;
-	int virq;
+	unsigned int virq;
 
 	/* SMMIO registers; used inside this file */
 	if (of_address_to_resource(node, 0, &r)) {
@@ -507,12 +506,11 @@ static __init int celleb_setup_pciex(struct device_node *node,
 	phb->ops = &scc_pciex_pci_ops;
 
 	/* internal interrupt handler */
-	if (of_irq_map_one(node, 1, &oirq)) {
+	virq = irq_of_parse_and_map(node, 1);
+	if (!virq) {
 		pr_err("PCIEXC:Failed to map irq\n");
 		goto error;
 	}
-	virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-				     oirq.size);
 	if (request_irq(virq, pciex_handle_internal_irq,
 			0, "pciex", (void *)phb)) {
 		pr_err("PCIEXC:Failed to request irq\n");
arch/powerpc/platforms/cell/spider-pic.c +2 -5
index 8e29944..1f72f4a 100644
@@ -235,12 +235,9 @@ static unsigned int __init spider_find_cascade_and_node(struct spider_pic *pic)
 	/* First, we check whether we have a real "interrupts" in the device
 	 * tree in case the device-tree is ever fixed
 	 */
-	struct of_irq oirq;
-	if (of_irq_map_one(pic->host->of_node, 0, &oirq) == 0) {
-		virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-					     oirq.size);
+	virq = irq_of_parse_and_map(pic->host->of_node, 0);
+	if (virq)
 		return virq;
-	}
 
 	/* Now do the horrible hacks */
 	tmp = of_get_property(pic->host->of_node, "#interrupt-cells", NULL);
arch/powerpc/sysdev/fsl_gtm.c +4 -5
index 0eb871c..dd0d5be 100644
@@ -401,16 +401,15 @@ static int __init fsl_gtm_init(void)
 		gtm->clock = *clock;
 
 		for (i = 0; i < ARRAY_SIZE(gtm->timers); i++) {
-			int ret;
-			struct resource irq;
+			unsigned int irq;
 
-			ret = of_irq_to_resource(np, i, &irq);
-			if (ret == NO_IRQ) {
+			irq = irq_of_parse_and_map(np, i);
+			if (irq == NO_IRQ) {
 				pr_err("%s: not enough interrupts specified\n",
 				       np->full_name);
 				goto err;
 			}
-			gtm->timers[i].irq = irq.start;
+			gtm->timers[i].irq = irq;
 			gtm->timers[i].gtm = gtm;
 		}
 
arch/powerpc/sysdev/mpic_msgr.c +2 -4
index c753258..2c9b52a 100644
@@ -237,15 +237,13 @@ static int mpic_msgr_probe(struct platform_device *dev)
 		raw_spin_lock_init(&msgr->lock);
 
 		if (receive_mask & (1 << i)) {
-			struct resource irq;
-
-			if (of_irq_to_resource(np, irq_index, &irq) == NO_IRQ) {
+			msgr->irq = irq_of_parse_and_map(np, irq_index);
+			if (msgr->irq == NO_IRQ) {
 				dev_err(&dev->dev,
 						"Missing interrupt specifier");
 				kfree(msgr);
 				return -EFAULT;
 			}
-			msgr->irq = irq.start;
 			irq_index += 1;
 		} else {
 			msgr->irq = NO_IRQ;
drivers/crypto/caam/ctrl.c +1 -1
index 26438cd..c8224da 100644
@@ -419,7 +419,7 @@ static int caam_probe(struct platform_device *pdev)
 	topregs = (struct caam_full __iomem *)ctrl;
 
 	/* Get the IRQ of the controller (for security violations only) */
-	ctrlpriv->secvio_irq = of_irq_to_resource(nprop, 0, NULL);
+	ctrlpriv->secvio_irq = irq_of_parse_and_map(nprop, 0);
 
 	/*
 	 * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
drivers/crypto/caam/jr.c +1 -1
index 105ba4d..517a16d 100644
@@ -403,7 +403,7 @@ int caam_jr_probe(struct platform_device *pdev, struct device_node *np,
 		dma_set_mask(jrdev, DMA_BIT_MASK(32));
 
 	/* Identify the interrupt */
-	jrpriv->irq = of_irq_to_resource(np, 0, NULL);
+	jrpriv->irq = irq_of_parse_and_map(np, 0);
 
 	/* Now do the platform independent part */
 	error = caam_jr_init(jrdev); /* now turn on hardware */
drivers/crypto/omap-sham.c +1 -1
index 8bdde57..e28104b 100644
@@ -1818,7 +1818,7 @@ static int omap_sham_get_res_of(struct omap_sham_dev *dd,
 		goto err;
 	}
 
-	dd->irq = of_irq_to_resource(node, 0, NULL);
+	dd->irq = irq_of_parse_and_map(node, 0);
 	if (!dd->irq) {
 		dev_err(dev, "can't translate OF irq value\n");
 		err = -EINVAL;
drivers/i2c/busses/i2c-cpm.c +1 -1
index b2b8aa9..3e5ea2c 100644
@@ -447,7 +447,7 @@ static int cpm_i2c_setup(struct cpm_i2c *cpm)
 
 	init_waitqueue_head(&cpm->i2c_wait);
 
-	cpm->irq = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
+	cpm->irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
 	if (!cpm->irq)
 		return -EINVAL;
 
drivers/input/serio/xilinx_ps2.c +4 -3
index 4b7662a..36f7b95 100644
@@ -235,12 +235,12 @@ static void sxps2_close(struct serio *pserio)
  */
 static int xps2_of_probe(struct platform_device *ofdev)
 {
-	struct resource r_irq; /* Interrupt resources */
 	struct resource r_mem; /* IO mem resources */
 	struct xps2data *drvdata;
 	struct serio *serio;
 	struct device *dev = &ofdev->dev;
 	resource_size_t remap_size, phys_addr;
+	unsigned int irq;
 	int error;
 
 	dev_info(dev, "Device Tree Probing \'%s\'\n",
@@ -254,7 +254,8 @@ static int xps2_of_probe(struct platform_device *ofdev)
 	}
 
 	/* Get IRQ for the device */
-	if (!of_irq_to_resource(ofdev->dev.of_node, 0, &r_irq)) {
+	irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
+	if (!irq) {
 		dev_err(dev, "no IRQ found\n");
 		return -ENODEV;
 	}
@@ -267,7 +268,7 @@ static int xps2_of_probe(struct platform_device *ofdev)
 	}
 
 	spin_lock_init(&drvdata->lock);
-	drvdata->irq = r_irq.start;
+	drvdata->irq = irq;
 	drvdata->serio = serio;
 	drvdata->dev = dev;
 
drivers/net/ethernet/arc/emac_main.c +5 -5
index 9e16014..d087852 100644
@@ -628,12 +628,12 @@ static const struct net_device_ops arc_emac_netdev_ops = {
 
 static int arc_emac_probe(struct platform_device *pdev)
 {
-	struct resource res_regs, res_irq;
+	struct resource res_regs;
 	struct device_node *phy_node;
 	struct arc_emac_priv *priv;
 	struct net_device *ndev;
 	const char *mac_addr;
-	unsigned int id, clock_frequency;
+	unsigned int id, clock_frequency, irq;
 	int err;
 
 	if (!pdev->dev.of_node)
@@ -661,8 +661,8 @@ static int arc_emac_probe(struct platform_device *pdev)
 	}
 
 	/* Get IRQ from device tree */
-	err = of_irq_to_resource(pdev->dev.of_node, 0, &res_irq);
-	if (!err) {
+	irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
+	if (!irq) {
 		dev_err(&pdev->dev, "failed to retrieve <irq> value from device tree\n");
 		return -ENODEV;
 	}
@@ -711,7 +711,7 @@ static int arc_emac_probe(struct platform_device *pdev)
 		goto out;
 	}
 
-	ndev->irq = res_irq.start;
+	ndev->irq = irq;
 	dev_info(&pdev->dev, "IRQ is %d\n", ndev->irq);
 
 	/* Register interrupt handler for device */
drivers/net/ethernet/freescale/fs_enet/mac-fcc.c +1 -1
index 7583a95..10f781d 100644
@@ -88,7 +88,7 @@ static int do_pd_setup(struct fs_enet_private *fep)
 	struct fs_platform_info *fpi = fep->fpi;
 	int ret = -EINVAL;
 
-	fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
+	fep->interrupt = irq_of_parse_and_map(ofdev->dev.of_node, 0);
 	if (fep->interrupt == NO_IRQ)
 		goto out;
 
drivers/net/ethernet/freescale/fs_enet/mac-fec.c +1 -1
index 9ae6cdb..53a0c23 100644
@@ -98,7 +98,7 @@ static int do_pd_setup(struct fs_enet_private *fep)
 {
 	struct platform_device *ofdev = to_platform_device(fep->dev);
 
-	fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
+	fep->interrupt = irq_of_parse_and_map(ofdev->dev.of_node, 0);
 	if (fep->interrupt == NO_IRQ)
 		return -EINVAL;
 
drivers/net/ethernet/freescale/fs_enet/mac-scc.c +1 -1
index 22a02a7..631f098 100644
@@ -98,7 +98,7 @@ static int do_pd_setup(struct fs_enet_private *fep)
 {
 	struct platform_device *ofdev = to_platform_device(fep->dev);
 
-	fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
+	fep->interrupt = irq_of_parse_and_map(ofdev->dev.of_node, 0);
 	if (fep->interrupt == NO_IRQ)
 		return -EINVAL;
 
drivers/spi/spi-fsl-espi.c +3 -3
index b8f1103..3197d55 100644
@@ -687,7 +687,7 @@ static int of_fsl_espi_probe(struct platform_device *ofdev)
 	struct device_node *np = ofdev->dev.of_node;
 	struct spi_master *master;
 	struct resource mem;
-	struct resource irq;
+	unsigned int irq;
 	int ret = -ENOMEM;
 
 	ret = of_mpc8xxx_spi_probe(ofdev);
@@ -702,13 +702,13 @@ static int of_fsl_espi_probe(struct platform_device *ofdev)
 	if (ret)
 		goto err;
 
-	ret = of_irq_to_resource(np, 0, &irq);
+	irq = irq_of_parse_and_map(np, 0);
 	if (!ret) {
 		ret = -EINVAL;
 		goto err;
 	}
 
-	master = fsl_espi_probe(dev, &mem, irq.start);
+	master = fsl_espi_probe(dev, &mem, irq);
 	if (IS_ERR(master)) {
 		ret = PTR_ERR(master);
 		goto err;
drivers/tty/serial/cpm_uart/cpm_uart_core.c +1 -1
index 1a535f7..6957f445 100644
@@ -1207,7 +1207,7 @@ static int cpm_uart_init_port(struct device_node *np,
 	pinfo->port.fifosize = pinfo->tx_nrfifos * pinfo->tx_fifosize;
 	spin_lock_init(&pinfo->port.lock);
 
-	pinfo->port.irq = of_irq_to_resource(np, 0, NULL);
+	pinfo->port.irq = irq_of_parse_and_map(np, 0);
 	if (pinfo->port.irq == NO_IRQ) {
 		ret = -EINVAL;
 		goto out_pram;
Signature · 1 line
1.8.4
Acked-by on v2 2/10
#6 lore raw

Re: [PATCH v2 02/10] of/irq: Use irq_of_parse_and_map()

Quoted 4 lines · Thierry Reding

Replace some instances of of_irq_map_one()/irq_create_of_mapping() and of_irq_to_resource() by the simpler equivalent irq_of_parse_and_map().

Quoted 359 lines
---
 arch/arm/mach-u300/timer.c                       |  9 ++++-----
 arch/powerpc/platforms/cell/celleb_scc_pciex.c   |  8 +++-----
 arch/powerpc/platforms/cell/spider-pic.c         |  7 ++-----
 arch/powerpc/sysdev/fsl_gtm.c                    |  9 ++++-----
 arch/powerpc/sysdev/mpic_msgr.c                  |  6 ++----
 drivers/crypto/caam/ctrl.c                       |  2 +-
 drivers/crypto/caam/jr.c                         |  2 +-
 drivers/crypto/omap-sham.c                       |  2 +-
 drivers/i2c/busses/i2c-cpm.c                     |  2 +-
 drivers/input/serio/xilinx_ps2.c                 |  7 ++++---
 drivers/net/ethernet/arc/emac_main.c             | 10 +++++-----
 drivers/net/ethernet/freescale/fs_enet/mac-fcc.c |  2 +-
 drivers/net/ethernet/freescale/fs_enet/mac-fec.c |  2 +-
 drivers/net/ethernet/freescale/fs_enet/mac-scc.c |  2 +-
 drivers/spi/spi-fsl-espi.c                       |  6 +++---
 drivers/tty/serial/cpm_uart/cpm_uart_core.c      |  2 +-
 16 files changed, 35 insertions(+), 43 deletions(-)
arch/arm/mach-u300/timer.c +4 -5
index b5db207..9a5f9fb 100644
@@ -358,8 +358,7 @@ static struct delay_timer u300_delay_timer;
  */
 static void __init u300_timer_init_of(struct device_node *np)
 {
-       struct resource irq_res;
-       int irq;
+       unsigned int irq;
        struct clk *clk;
        unsigned long rate;
 
@@ -368,11 +367,11 @@ static void __init u300_timer_init_of(struct device_node *np)
                panic("could not ioremap system timer\n");
 
        /* Get the IRQ for the GP1 timer */
-       irq = of_irq_to_resource(np, 2, &irq_res);
-       if (irq <= 0)
+       irq = irq_of_parse_and_map(np, 2);
+       if (!irq)
                panic("no IRQ for system timer\n");
 
-       pr_info("U300 GP1 timer @ base: %p, IRQ: %d\n", u300_timer_base, irq);
+       pr_info("U300 GP1 timer @ base: %p, IRQ: %u\n", u300_timer_base, irq);
 
        /* Clock the interrupt controller */
        clk = of_clk_get(np, 0);
arch/powerpc/platforms/cell/celleb_scc_pciex.c +3 -5
index 14be2bd..856ad64 100644
@@ -486,8 +486,7 @@ static __init int celleb_setup_pciex(struct device_node *node,
                                     struct pci_controller *phb)
 {
        struct resource r;
-       struct of_irq oirq;
-       int virq;
+       unsigned int virq;
 
        /* SMMIO registers; used inside this file */
        if (of_address_to_resource(node, 0, &r)) {
@@ -507,12 +506,11 @@ static __init int celleb_setup_pciex(struct device_node *node,
        phb->ops = &scc_pciex_pci_ops;
 
        /* internal interrupt handler */
-       if (of_irq_map_one(node, 1, &oirq)) {
+       virq = irq_of_parse_and_map(node, 1);
+       if (!virq) {
                pr_err("PCIEXC:Failed to map irq\n");
                goto error;
        }
-       virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-                                    oirq.size);
        if (request_irq(virq, pciex_handle_internal_irq,
                        0, "pciex", (void *)phb)) {
                pr_err("PCIEXC:Failed to request irq\n");
arch/powerpc/platforms/cell/spider-pic.c +2 -5
index 8e29944..1f72f4a 100644
@@ -235,12 +235,9 @@ static unsigned int __init spider_find_cascade_and_node(struct spider_pic *pic)
        /* First, we check whether we have a real "interrupts" in the device
         * tree in case the device-tree is ever fixed
         */
-       struct of_irq oirq;
-       if (of_irq_map_one(pic->host->of_node, 0, &oirq) == 0) {
-               virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-                                            oirq.size);
+       virq = irq_of_parse_and_map(pic->host->of_node, 0);
+       if (virq)
                return virq;
-       }
 
        /* Now do the horrible hacks */
        tmp = of_get_property(pic->host->of_node, "#interrupt-cells", NULL);
arch/powerpc/sysdev/fsl_gtm.c +4 -5
index 0eb871c..dd0d5be 100644
@@ -401,16 +401,15 @@ static int __init fsl_gtm_init(void)
                gtm->clock = *clock;
 
                for (i = 0; i < ARRAY_SIZE(gtm->timers); i++) {
-                       int ret;
-                       struct resource irq;
+                       unsigned int irq;
 
-                       ret = of_irq_to_resource(np, i, &irq);
-                       if (ret == NO_IRQ) {
+                       irq = irq_of_parse_and_map(np, i);
+                       if (irq == NO_IRQ) {
                                pr_err("%s: not enough interrupts specified\n",
                                       np->full_name);
                                goto err;
                        }
-                       gtm->timers[i].irq = irq.start;
+                       gtm->timers[i].irq = irq;
                        gtm->timers[i].gtm = gtm;
                }
 
arch/powerpc/sysdev/mpic_msgr.c +2 -4
index c753258..2c9b52a 100644
@@ -237,15 +237,13 @@ static int mpic_msgr_probe(struct platform_device *dev)
                raw_spin_lock_init(&msgr->lock);
 
                if (receive_mask & (1 << i)) {
-                       struct resource irq;
-
-                       if (of_irq_to_resource(np, irq_index, &irq) == NO_IRQ) {
+                       msgr->irq = irq_of_parse_and_map(np, irq_index);
+                       if (msgr->irq == NO_IRQ) {
                                dev_err(&dev->dev,
                                                "Missing interrupt specifier");
                                kfree(msgr);
                                return -EFAULT;
                        }
-                       msgr->irq = irq.start;
                        irq_index += 1;
                } else {
                        msgr->irq = NO_IRQ;
drivers/crypto/caam/ctrl.c +1 -1
index 26438cd..c8224da 100644
@@ -419,7 +419,7 @@ static int caam_probe(struct platform_device *pdev)
        topregs = (struct caam_full __iomem *)ctrl;
 
        /* Get the IRQ of the controller (for security violations only) */
-       ctrlpriv->secvio_irq = of_irq_to_resource(nprop, 0, NULL);
+       ctrlpriv->secvio_irq = irq_of_parse_and_map(nprop, 0);
 
        /*
         * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
drivers/crypto/caam/jr.c +1 -1
index 105ba4d..517a16d 100644
@@ -403,7 +403,7 @@ int caam_jr_probe(struct platform_device *pdev, struct device_node *np,
                dma_set_mask(jrdev, DMA_BIT_MASK(32));
 
        /* Identify the interrupt */
-       jrpriv->irq = of_irq_to_resource(np, 0, NULL);
+       jrpriv->irq = irq_of_parse_and_map(np, 0);
 
        /* Now do the platform independent part */
        error = caam_jr_init(jrdev); /* now turn on hardware */
drivers/crypto/omap-sham.c +1 -1
index 8bdde57..e28104b 100644
@@ -1818,7 +1818,7 @@ static int omap_sham_get_res_of(struct omap_sham_dev *dd,
                goto err;
        }
 
-       dd->irq = of_irq_to_resource(node, 0, NULL);
+       dd->irq = irq_of_parse_and_map(node, 0);
        if (!dd->irq) {
                dev_err(dev, "can't translate OF irq value\n");
                err = -EINVAL;
drivers/i2c/busses/i2c-cpm.c +1 -1
index b2b8aa9..3e5ea2c 100644
@@ -447,7 +447,7 @@ static int cpm_i2c_setup(struct cpm_i2c *cpm)
 
        init_waitqueue_head(&cpm->i2c_wait);
 
-       cpm->irq = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
+       cpm->irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
        if (!cpm->irq)
                return -EINVAL;
 
drivers/input/serio/xilinx_ps2.c +4 -3
index 4b7662a..36f7b95 100644
@@ -235,12 +235,12 @@ static void sxps2_close(struct serio *pserio)
  */
 static int xps2_of_probe(struct platform_device *ofdev)
 {
-       struct resource r_irq; /* Interrupt resources */
        struct resource r_mem; /* IO mem resources */
        struct xps2data *drvdata;
        struct serio *serio;
        struct device *dev = &ofdev->dev;
        resource_size_t remap_size, phys_addr;
+       unsigned int irq;
        int error;
 
        dev_info(dev, "Device Tree Probing \'%s\'\n",
@@ -254,7 +254,8 @@ static int xps2_of_probe(struct platform_device *ofdev)
        }
 
        /* Get IRQ for the device */
-       if (!of_irq_to_resource(ofdev->dev.of_node, 0, &r_irq)) {
+       irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
+       if (!irq) {
                dev_err(dev, "no IRQ found\n");
                return -ENODEV;
        }
@@ -267,7 +268,7 @@ static int xps2_of_probe(struct platform_device *ofdev)
        }
 
        spin_lock_init(&drvdata->lock);
-       drvdata->irq = r_irq.start;
+       drvdata->irq = irq;
        drvdata->serio = serio;
        drvdata->dev = dev;
 
drivers/net/ethernet/arc/emac_main.c +5 -5
index 9e16014..d087852 100644
@@ -628,12 +628,12 @@ static const struct net_device_ops arc_emac_netdev_ops = {
 
 static int arc_emac_probe(struct platform_device *pdev)
 {
-       struct resource res_regs, res_irq;
+       struct resource res_regs;
        struct device_node *phy_node;
        struct arc_emac_priv *priv;
        struct net_device *ndev;
        const char *mac_addr;
-       unsigned int id, clock_frequency;
+       unsigned int id, clock_frequency, irq;
        int err;
 
        if (!pdev->dev.of_node)
@@ -661,8 +661,8 @@ static int arc_emac_probe(struct platform_device *pdev)
        }
 
        /* Get IRQ from device tree */
-       err = of_irq_to_resource(pdev->dev.of_node, 0, &res_irq);
-       if (!err) {
+       irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
+       if (!irq) {
                dev_err(&pdev->dev, "failed to retrieve <irq> value from device tree\n");
                return -ENODEV;
        }
@@ -711,7 +711,7 @@ static int arc_emac_probe(struct platform_device *pdev)
                goto out;
        }
 
-       ndev->irq = res_irq.start;
+       ndev->irq = irq;
        dev_info(&pdev->dev, "IRQ is %d\n", ndev->irq);
 
        /* Register interrupt handler for device */
drivers/net/ethernet/freescale/fs_enet/mac-fcc.c +1 -1
index 7583a95..10f781d 100644
@@ -88,7 +88,7 @@ static int do_pd_setup(struct fs_enet_private *fep)
        struct fs_platform_info *fpi = fep->fpi;
        int ret = -EINVAL;
 
-       fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
+       fep->interrupt = irq_of_parse_and_map(ofdev->dev.of_node, 0);
        if (fep->interrupt == NO_IRQ)
                goto out;
 
drivers/net/ethernet/freescale/fs_enet/mac-fec.c +1 -1
index 9ae6cdb..53a0c23 100644
@@ -98,7 +98,7 @@ static int do_pd_setup(struct fs_enet_private *fep)
 {
        struct platform_device *ofdev = to_platform_device(fep->dev);
 
-       fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
+       fep->interrupt = irq_of_parse_and_map(ofdev->dev.of_node, 0);
        if (fep->interrupt == NO_IRQ)
                return -EINVAL;
 
drivers/net/ethernet/freescale/fs_enet/mac-scc.c +1 -1
index 22a02a7..631f098 100644
@@ -98,7 +98,7 @@ static int do_pd_setup(struct fs_enet_private *fep)
 {
        struct platform_device *ofdev = to_platform_device(fep->dev);
 
-       fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
+       fep->interrupt = irq_of_parse_and_map(ofdev->dev.of_node, 0);
        if (fep->interrupt == NO_IRQ)
                return -EINVAL;
 
drivers/spi/spi-fsl-espi.c +3 -3
index b8f1103..3197d55 100644
@@ -687,7 +687,7 @@ static int of_fsl_espi_probe(struct platform_device *ofdev)
        struct device_node *np = ofdev->dev.of_node;
        struct spi_master *master;
        struct resource mem;
-       struct resource irq;
+       unsigned int irq;
        int ret = -ENOMEM;
 
        ret = of_mpc8xxx_spi_probe(ofdev);
@@ -702,13 +702,13 @@ static int of_fsl_espi_probe(struct platform_device *ofdev)
        if (ret)
                goto err;
 
-       ret = of_irq_to_resource(np, 0, &irq);
+       irq = irq_of_parse_and_map(np, 0);
        if (!ret) {
                ret = -EINVAL;
                goto err;
        }
 
-       master = fsl_espi_probe(dev, &mem, irq.start);
+       master = fsl_espi_probe(dev, &mem, irq);
        if (IS_ERR(master)) {
                ret = PTR_ERR(master);
                goto err;
drivers/tty/serial/cpm_uart/cpm_uart_core.c +1 -2
index 1a535f7..6957f445 100644
@@ -1207,7 +1207,7 @@ static int cpm_uart_init_port(struct device_node *np,
        pinfo->port.fifosize = pinfo->tx_nrfifos * pinfo->tx_fifosize;
        spin_lock_init(&pinfo->port.lock);
 
-       pinfo->port.irq = of_irq_to_resource(np, 0, NULL);
+       pinfo->port.irq = irq_of_parse_and_map(np, 0);
        if (pinfo->port.irq == NO_IRQ) {
                ret = -EINVAL;
                goto out_pram;
--

1.8.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

PATCH v2 3/10 irqdomain: Introduce __irq_create_mapping()

In reply to Thierry Reding

This is a version of irq_create_mapping() that propagates the precise error code instead of returning 0 for all errors. It will be used in subsequent patches to allow further propagation of error codes.

To avoid code duplication, implement irq_create_mapping() as a wrapper around the new __irq_create_mapping().

---
 kernel/irq/irqdomain.c | 59 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 20 deletions(-)
kernel/irq/irqdomain.c +39 -20
index 706724e..d2a3b01 100644
@@ -374,30 +374,21 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain)
 }
 EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
 
-/**
- * irq_create_mapping() - Map a hardware interrupt into linux irq space
- * @domain: domain owning this hardware interrupt or NULL for default domain
- * @hwirq: hardware irq number in that domain space
- *
- * Only one mapping per hardware interrupt is permitted. Returns a linux
- * irq number.
- * If the sense/trigger is to be specified, set_irq_type() should be called
- * on the number returned from that call.
- */
-unsigned int irq_create_mapping(struct irq_domain *domain,
-				irq_hw_number_t hwirq)
+static int __irq_create_mapping(struct irq_domain *domain,
+				irq_hw_number_t hwirq, unsigned int *virqp)
 {
-	unsigned int hint;
-	int virq;
+	unsigned int hint, virq;
+	int ret;
 
-	pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
+	pr_debug("__irq_create_mapping(0x%p, 0x%lx, %p)\n", domain, hwirq,
+		 virqp);
 
 	/* Look for default domain if nececssary */
 	if (domain == NULL)
 		domain = irq_default_domain;
 	if (domain == NULL) {
 		WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq);
-		return 0;
+		return -ENODEV;
 	}
 	pr_debug("-> using domain @%p\n", domain);
 
@@ -405,7 +396,11 @@ unsigned int irq_create_mapping(struct irq_domain *domain,
 	virq = irq_find_mapping(domain, hwirq);
 	if (virq) {
 		pr_debug("-> existing mapping on virq %d\n", virq);
-		return virq;
+
+		if (virqp)
+			*virqp = virq;
+
+		return 0;
 	}
 
 	/* Allocate a virtual interrupt number */
@@ -417,17 +412,41 @@ unsigned int irq_create_mapping(struct irq_domain *domain,
 		virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
 	if (virq <= 0) {
 		pr_debug("-> virq allocation failed\n");
-		return 0;
+		return virq ? : -ENOSPC;
 	}
 
-	if (irq_domain_associate(domain, virq, hwirq)) {
+	ret = irq_domain_associate(domain, virq, hwirq);
+	if (ret) {
 		irq_free_desc(virq);
-		return 0;
+		return ret;
 	}
 
 	pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
 		hwirq, of_node_full_name(domain->of_node), virq);
 
+	if (virqp)
+		*virqp = virq;
+
+	return 0;
+}
+/**
+ * irq_create_mapping() - Map a hardware interrupt into linux irq space
+ * @domain: domain owning this hardware interrupt or NULL for default domain
+ * @hwirq: hardware irq number in that domain space
+ *
+ * Only one mapping per hardware interrupt is permitted. Returns a linux
+ * irq number.
+ * If the sense/trigger is to be specified, set_irq_type() should be called
+ * on the number returned from that call.
+ */
+unsigned int irq_create_mapping(struct irq_domain *domain,
+				irq_hw_number_t hwirq)
+{
+	unsigned int virq;
+
+	if (__irq_create_mapping(domain, hwirq, &virq))
+		return 0;
+
 	return virq;
 }
 EXPORT_SYMBOL_GPL(irq_create_mapping);
Signature · 1 line
1.8.4
#8 lore raw

PATCH v2 4/10 irqdomain: Return errors from irq_create_of_mapping()

In reply to Thierry Reding

Instead of returning 0 for all errors, allow the precise error code to be propagated. This will be used in subsequent patches to allow further propagation of error codes.

The interrupt number corresponding to the new mapping is returned in an output parameter so that the return value is reserved to signal success (== 0) or failure (< 0).

---
Changes in v2:
- convert existing callers instead of using compatible wrapper

 arch/arm/mach-integrator/pci_v3.c              |  8 ++++++--
 arch/microblaze/pci/pci-common.c               |  6 ++++--
 arch/mips/pci/fixup-lantiq.c                   | 12 +++++++----
 arch/mips/pci/pci-rt3883.c                     |  9 +++++----
 arch/powerpc/kernel/pci-common.c               |  7 +++++--
 arch/powerpc/platforms/cell/celleb_scc_sio.c   |  8 +++++---
 arch/powerpc/platforms/cell/spu_manage.c       |  6 +++---
 arch/powerpc/platforms/fsl_uli1575.c           |  7 +++----
 arch/powerpc/platforms/pseries/event_sources.c | 12 ++++++-----
 arch/x86/kernel/devicetree.c                   | 11 +++++-----
 drivers/pci/host/pci-mvebu.c                   |  9 +++++++--
 include/linux/of_irq.h                         |  6 +++---
 kernel/irq/irqdomain.c                         | 28 ++++++++++++++++----------
 13 files changed, 78 insertions(+), 51 deletions(-)
arch/arm/mach-integrator/pci_v3.c +6 -2
index bef1005..aa0f867 100644
@@ -847,8 +847,12 @@ static int __init pci_v3_map_irq_dt(const struct pci_dev *dev, u8 slot, u8 pin)
 		return 0;
 	}
 
-	return irq_create_of_mapping(oirq.controller, oirq.specifier,
-				     oirq.size);
+	ret = irq_create_of_mapping(oirq.controller, oirq.specifier,
+				    oirq.size, &virq);
+	if (ret)
+		return 0;
+
+	return virq;
 }
 
 static int __init pci_v3_dtprobe(struct platform_device *pdev,
arch/microblaze/pci/pci-common.c +4 -2
index 1b93bf0..80b6e0f 100644
@@ -246,8 +246,10 @@ int pci_read_irq_line(struct pci_dev *pci_dev)
 			 oirq.size, oirq.specifier[0], oirq.specifier[1],
 			 of_node_full_name(oirq.controller));
 
-		virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-					     oirq.size);
+		ret = irq_create_of_mapping(oirq.controller, oirq.specifier,
+					    oirq.size, &virq);
+		if (ret)
+			virq = 0;
 	}
 	if (!virq) {
 		pr_debug(" Failed to map !\n");
arch/mips/pci/fixup-lantiq.c +8 -4
index 6c829df..dfe7bf1 100644
@@ -26,15 +26,19 @@ int pcibios_plat_dev_init(struct pci_dev *dev)
 int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
 {
 	struct of_irq dev_irq;
-	int irq;
+	unsigned int irq;
+	int err;
 
 	if (of_irq_map_pci(dev, &dev_irq)) {
 		dev_err(&dev->dev, "trying to map irq for unknown slot:%d pin:%d\n",
 			slot, pin);
 		return 0;
 	}
-	irq = irq_create_of_mapping(dev_irq.controller, dev_irq.specifier,
-					dev_irq.size);
-	dev_info(&dev->dev, "SLOT:%d PIN:%d IRQ:%d\n", slot, pin, irq);
+	err = irq_create_of_mapping(dev_irq.controller, dev_irq.specifier,
+				    dev_irq.size, &irq);
+	if (err)
+		return 0;
+
+	dev_info(&dev->dev, "SLOT:%d PIN:%d IRQ:%u\n", slot, pin, irq);
 	return irq;
 }
arch/mips/pci/pci-rt3883.c +5 -4
index 95c9d41..79b49b5 100644
@@ -584,8 +584,8 @@ err_put_intc_node:
 int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
 {
 	struct of_irq dev_irq;
+	unsigned int irq = 0;
 	int err;
-	int irq;
 
 	err = of_irq_map_pci(dev, &dev_irq);
 	if (err) {
@@ -594,11 +594,12 @@ int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
 		return 0;
 	}
 
-	irq = irq_create_of_mapping(dev_irq.controller,
+	err = irq_create_of_mapping(dev_irq.controller,
 				    dev_irq.specifier,
-				    dev_irq.size);
+				    dev_irq.size,
+				    &irq);
 
-	if (irq == 0)
+	if (err)
 		pr_crit("pci %s: no irq found for pin %u\n",
 			pci_name((struct pci_dev *) dev), pin);
 	else
arch/powerpc/kernel/pci-common.c +5 -2
index 905a24b..ae71b14 100644
@@ -230,6 +230,7 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
 {
 	struct of_irq oirq;
 	unsigned int virq;
+	int ret;
 
 	pr_debug("PCI: Try to map irq for %s...\n", pci_name(pci_dev));
 
@@ -266,8 +267,10 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
 			 oirq.size, oirq.specifier[0], oirq.specifier[1],
 			 of_node_full_name(oirq.controller));
 
-		virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-					     oirq.size);
+		ret = irq_create_of_mapping(oirq.controller, oirq.specifier,
+					    oirq.size, &virq);
+		if (ret)
+			virq = NO_IRQ;
 	}
 	if(virq == NO_IRQ) {
 		pr_debug(" Failed to map !\n");
arch/powerpc/platforms/cell/celleb_scc_sio.c +5 -3
index 9c339ec..94b771e 100644
@@ -43,7 +43,7 @@ static int __init txx9_serial_init(void)
 {
 	extern int early_serial_txx9_setup(struct uart_port *port);
 	struct device_node *node;
-	int i;
+	int i, err;
 	struct uart_port req;
 	struct of_irq irq;
 	struct resource res;
@@ -66,8 +66,10 @@ static int __init txx9_serial_init(void)
 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
 			req.membase = ioremap(req.mapbase, 0x24);
 #endif
-			req.irq = irq_create_of_mapping(irq.controller,
-				irq.specifier, irq.size);
+			err = irq_create_of_mapping(irq.controller,
+				irq.specifier, irq.size, &req.irq);
+			if (err)
+				req.irq = 0;
 			req.flags |= UPF_IOREMAP | UPF_BUGGY_UART
 				/*HAVE_CTS_LINE*/;
 			req.uartclk = 83300000;
arch/powerpc/platforms/cell/spu_manage.c +3 -3
index 2bb6977..b78c7a4 100644
@@ -190,9 +190,9 @@ static int __init spu_map_interrupts(struct spu *spu, struct device_node *np)
 		ret = -EINVAL;
 		pr_debug("  irq %d no 0x%x on %s\n", i, oirq.specifier[0],
 			 oirq.controller->full_name);
-		spu->irqs[i] = irq_create_of_mapping(oirq.controller,
-					oirq.specifier, oirq.size);
-		if (spu->irqs[i] == NO_IRQ) {
+		ret = irq_create_of_mapping(oirq.controller, oirq.specifier,
+					    oirq.size, &spu->irqs[i]);
+		if (ret) {
 			pr_debug("spu_new: failed to map it !\n");
 			goto err;
 		}
arch/powerpc/platforms/fsl_uli1575.c +3 -4
index 92ac9b5..575b215 100644
@@ -322,7 +322,7 @@ static void hpcd_final_uli5288(struct pci_dev *dev)
 	struct pci_controller *hose = pci_bus_to_host(dev->bus);
 	struct device_node *hosenode = hose ? hose->dn : NULL;
 	struct of_irq oirq;
-	int virq, pin = 2;
+	int pin = 2;
 	u32 laddr[3];
 
 	if (!machine_is(mpc86xx_hpcd))
@@ -334,9 +334,8 @@ static void hpcd_final_uli5288(struct pci_dev *dev)
 	laddr[0] = (hose->first_busno << 16) | (PCI_DEVFN(31, 0) << 8);
 	laddr[1] = laddr[2] = 0;
 	of_irq_map_raw(hosenode, &pin, 1, laddr, &oirq);
-	virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-				     oirq.size);
-	dev->irq = virq;
+	irq_create_of_mapping(oirq.controller, oirq.specifier, oirq.size,
+			      &dev->irq);
 }
 
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, hpcd_quirk_uli1575);
arch/powerpc/platforms/pseries/event_sources.c +7 -5
index 2605c31..4367fdd 100644
@@ -24,7 +24,7 @@ void request_event_sources_irqs(struct device_node *np,
 				irq_handler_t handler,
 				const char *name)
 {
-	int i, index, count = 0;
+	int i, index, err, count = 0;
 	struct of_irq oirq;
 	const u32 *opicprop;
 	unsigned int opicplen;
@@ -59,10 +59,12 @@ void request_event_sources_irqs(struct device_node *np,
 		     index++) {
 			if (count > 15)
 				break;
-			virqs[count] = irq_create_of_mapping(oirq.controller,
-							    oirq.specifier,
-							    oirq.size);
-			if (virqs[count] == NO_IRQ) {
+
+			err = irq_create_of_mapping(oirq.controller,
+						    oirq.specifier,
+						    oirq.size,
+						    &virqs[count]);
+			if (err) {
 				pr_err("event-sources: Unable to allocate "
 				       "interrupt number for %s\n",
 				       np->full_name);
arch/x86/kernel/devicetree.c +5 -6
index 376dc78..7adede6 100644
@@ -106,7 +106,6 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus)
 static int x86_of_pci_irq_enable(struct pci_dev *dev)
 {
 	struct of_irq oirq;
-	u32 virq;
 	int ret;
 	u8 pin;
 
@@ -120,11 +119,11 @@ static int x86_of_pci_irq_enable(struct pci_dev *dev)
 	if (ret)
 		return ret;
 
-	virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-			oirq.size);
-	if (virq == 0)
-		return -EINVAL;
-	dev->irq = virq;
+	ret = irq_create_of_mapping(oirq.controller, oirq.specifier, oirq.size,
+				    &dev->irq);
+	if (ret)
+		return ret;
+
 	return 0;
 }
 
drivers/pci/host/pci-mvebu.c +7 -2
index 77f8a7c..7773a17 100644
@@ -656,14 +656,19 @@ static int mvebu_pcie_setup(int nr, struct pci_sys_data *sys)
 static int mvebu_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
 {
 	struct of_irq oirq;
+	unsigned int virq;
 	int ret;
 
 	ret = of_irq_map_pci(dev, &oirq);
 	if (ret)
 		return ret;
 
-	return irq_create_of_mapping(oirq.controller, oirq.specifier,
-				     oirq.size);
+	ret = irq_create_of_mapping(oirq.controller, oirq.specifier, oirq.size,
+				    &virq);
+	if (ret)
+		return 0;
+
+	return virq;
 }
 
 static struct pci_bus *mvebu_pcie_scan_bus(int nr, struct pci_sys_data *sys)
include/linux/of_irq.h +3 -3
index 535cecf..138266d 100644
@@ -63,9 +63,9 @@ extern int of_irq_map_raw(struct device_node *parent, const __be32 *intspec,
 			  struct of_irq *out_irq);
 extern int of_irq_map_one(struct device_node *device, int index,
 			  struct of_irq *out_irq);
-extern unsigned int irq_create_of_mapping(struct device_node *controller,
-					  const u32 *intspec,
-					  unsigned int intsize);
+extern int irq_create_of_mapping(struct device_node *controller,
+				 const u32 *intspec, unsigned int intsize,
+				 unsigned int *virqp);
 extern int of_irq_to_resource(struct device_node *dev, int index,
 			      struct resource *r);
 extern int of_irq_count(struct device_node *dev);
kernel/irq/irqdomain.c +17 -11
index d2a3b01..5f8401c 100644
@@ -484,40 +484,46 @@ int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
 }
 EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
 
-unsigned int irq_create_of_mapping(struct device_node *controller,
-				   const u32 *intspec, unsigned int intsize)
+int irq_create_of_mapping(struct device_node *controller, const u32 *intspec,
+			  unsigned int intsize, unsigned int *virqp)
 {
+	unsigned int type = IRQ_TYPE_NONE;
 	struct irq_domain *domain;
 	irq_hw_number_t hwirq;
-	unsigned int type = IRQ_TYPE_NONE;
 	unsigned int virq;
+	int ret;
 
 	domain = controller ? irq_find_host(controller) : irq_default_domain;
 	if (!domain) {
 		pr_warn("no irq domain found for %s !\n",
 			of_node_full_name(controller));
-		return 0;
+		return -EPROBE_DEFER;
 	}
 
 	/* If domain has no translation, then we assume interrupt line */
 	if (domain->ops->xlate == NULL)
 		hwirq = intspec[0];
 	else {
-		if (domain->ops->xlate(domain, controller, intspec, intsize,
-				     &hwirq, &type))
-			return 0;
+		ret = domain->ops->xlate(domain, controller, intspec, intsize,
+					 &hwirq, &type);
+		if (ret)
+			return ret;
 	}
 
 	/* Create mapping */
-	virq = irq_create_mapping(domain, hwirq);
-	if (!virq)
-		return virq;
+	ret = __irq_create_mapping(domain, hwirq, &virq);
+	if (ret)
+		return ret;
 
 	/* Set type if specified and different than the current one */
 	if (type != IRQ_TYPE_NONE &&
 	    type != irq_get_trigger_type(virq))
 		irq_set_irq_type(virq, type);
-	return virq;
+
+	if (virqp)
+		*virqp = virq;
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(irq_create_of_mapping);
 
Signature · 1 line
1.8.4
Acked-by on v2 4/10
#9 lore raw

Re: [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping()

On Wed, Sep 18, 2013 at 03:24:46PM +0200, Thierry Reding wrote:

For the MIPS bits:

Ralf

Acked-by on v2 4/10
#10 lore raw

Re: [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping()

In reply to Thierry Reding
Quoted 9 lines · Thierry Reding

Instead of returning 0 for all errors, allow the precise error code to be propagated. This will be used in subsequent patches to allow further propagation of error codes.

The interrupt number corresponding to the new mapping is returned in an output parameter so that the return value is reserved to signal success (== 0) or failure (< 0).

One comment below, otherwise:

Quoted 15 lines
arch/powerpc/kernel/pci-common.c +1 -0
index 905a24b..ae71b14 100644
@@ -230,6 +230,7 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
 {
        struct of_irq oirq;
        unsigned int virq;
+       int ret;
 
        pr_debug("PCI: Try to map irq for %s...\n", pci_name(pci_dev));
 
@@ -266,8 +267,10 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
                         oirq.size, oirq.specifier[0], oirq.specifier[1],
                         of_node_full_name(oirq.controller));

arch/powerpc/kernel/pci-common.c static int pci_read_irq_line(struct pci_dev *pci_dev) · line 276

Quoted 10 lines
arch/powerpc/kernel/pci-common.c +4 -2
 
-               virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-                                            oirq.size);
+               ret = irq_create_of_mapping(oirq.controller, oirq.specifier,
+                                           oirq.size, &virq);
+               if (ret)
+                       virq = NO_IRQ;
        }
        if(virq == NO_IRQ) {
                pr_debug(" Failed to map !\n");

Can you get rid of NO_IRQ usage here instead of adding to it.

Rob

#11 lore raw

Re: [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping()

Quoted 32 lines · Rob Herring
Quoted 9 lines · Thierry Reding

Instead of returning 0 for all errors, allow the precise error code to be propagated. This will be used in subsequent patches to allow further propagation of error codes.

The interrupt number corresponding to the new mapping is returned in an output parameter so that the return value is reserved to signal success (== 0) or failure (< 0).

One comment below, otherwise:

Quoted 16 lines
arch/powerpc/kernel/pci-common.c +1 -0
index 905a24b..ae71b14 100644
@@ -230,6 +230,7 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
 {
        struct of_irq oirq;
        unsigned int virq;
+       int ret;
 
        pr_debug("PCI: Try to map irq for %s...\n", pci_name(pci_dev));
 
@@ -266,8 +267,10 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
                         oirq.size, oirq.specifier[0], oirq.specifier[1],
                         of_node_full_name(oirq.controller));
 
Quoted 11 lines

arch/powerpc/kernel/pci-common.c static int pci_read_irq_line(struct pci_dev *pci_dev) · line 276

Quoted 9 lines
arch/powerpc/kernel/pci-common.c +4 -2
-               virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-                                            oirq.size);
+               ret = irq_create_of_mapping(oirq.controller, oirq.specifier,
+                                           oirq.size, &virq);
+               if (ret)
+                       virq = NO_IRQ;
        }
        if(virq == NO_IRQ) {
                pr_debug(" Failed to map !\n");

Can you get rid of NO_IRQ usage here instead of adding to it.

I was trying to stay consistent with the remainder of the code. PowerPC is a pretty heavy user of NO_IRQ. Of all 348 references, more than half
(182) are in arch/powerpc, so I'd rather like to get a go-ahead from Benjamin on this.

That said, perhaps we should just go all the way and get rid of NO_IRQ for good. Things could get somewhat messy, though. There are a couple of these spread through the code:

	#ifndef NO_IRQ
	#define NO_IRQ (-1)
	#endif

And this isn't very encouraging either:

	$ git grep 'irq.*=.*-1' | wc -l
	638

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130923/c73738f4/attachment-0001.sig>

#12 lore raw

Re: [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping()

Quoted 50 lines · Thierry Reding
Quoted 32 lines · Rob Herring
Quoted 9 lines · Thierry Reding

Instead of returning 0 for all errors, allow the precise error code to be propagated. This will be used in subsequent patches to allow further propagation of error codes.

The interrupt number corresponding to the new mapping is returned in an output parameter so that the return value is reserved to signal success (== 0) or failure (< 0).

One comment below, otherwise:

Quoted 16 lines
arch/powerpc/kernel/pci-common.c +1 -0
index 905a24b..ae71b14 100644
@@ -230,6 +230,7 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
 {
        struct of_irq oirq;
        unsigned int virq;
+       int ret;
 
        pr_debug("PCI: Try to map irq for %s...\n", pci_name(pci_dev));
 
@@ -266,8 +267,10 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
                         oirq.size, oirq.specifier[0], oirq.specifier[1],
                         of_node_full_name(oirq.controller));
 
Quoted 11 lines

arch/powerpc/kernel/pci-common.c static int pci_read_irq_line(struct pci_dev *pci_dev) · line 276

Quoted 9 lines
arch/powerpc/kernel/pci-common.c +4 -2
-               virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
-                                            oirq.size);
+               ret = irq_create_of_mapping(oirq.controller, oirq.specifier,
+                                           oirq.size, &virq);
+               if (ret)
+                       virq = NO_IRQ;
        }
        if(virq == NO_IRQ) {
                pr_debug(" Failed to map !\n");

Can you get rid of NO_IRQ usage here instead of adding to it.

I was trying to stay consistent with the remainder of the code. PowerPC is a pretty heavy user of NO_IRQ. Of all 348 references, more than half
(182) are in arch/powerpc, so I'd rather like to get a go-ahead from Benjamin on this.

Quoted 7 lines

That said, perhaps we should just go all the way and get rid of NO_IRQ for good. Things could get somewhat messy, though. There are a couple of these spread through the code:

	#ifndef NO_IRQ
	#define NO_IRQ (-1)
	#endif

And all of them are wrong and need to be removed. :-) We're /slowly/ getting rid of the -1 and the usage of NO_IRQ. A global search and replace of s/NO_IRQ/0/g can be very safely done on arch/powerpc since powerpc has had NO_IRQ set correctly to '0' for a very long time now.

So, yes, if you're keen to do it I'd love to see a series getting rid of more NO_IRQ users.

g.

#13 lore raw

PATCH v2 5/10 of/irq: Introduce __irq_of_parse_and_map()

In reply to Thierry Reding

This is a version of irq_of_parse_and_map() that propagates the precise error code instead of returning 0 for all errors. It will be used in subsequent patches to allow further propagation of error codes.

To avoid code duplication, implement irq_of_parse_and_map() as a static inline wrapper around the new __irq_of_parse_and_map(). Note that this is somewhat complicated by the fact that SPARC implement its own version of irq_of_parse_and_map(). Make SPARC implement __irq_of_parse_and_map() so that the static inline wrapper can be used on all platforms.

---
Changes in v2:
- rename of_irq_get() to __irq_of_parse_and_map()

 arch/sparc/kernel/of_device_common.c | 12 ++++++++----
 drivers/of/irq.c                     | 18 ++++++++++++------
 include/linux/of_irq.h               | 19 ++++++++++++++-----
 3 files changed, 34 insertions(+), 15 deletions(-)
arch/sparc/kernel/of_device_common.c +8 -4
index de199bf..a69559f 100644
@@ -11,16 +11,20 @@
 
 #include "of_device_common.h"
 
-unsigned int irq_of_parse_and_map(struct device_node *node, int index)
+int __irq_of_parse_and_map(struct device_node *node, unsigned int index,
+			   unsigned int *virqp)
 {
 	struct platform_device *op = of_find_device_by_node(node);
 
 	if (!op || index >= op->archdata.num_irqs)
-		return 0;
+		return !op ? -ENODEV : -EINVAL;
 
-	return op->archdata.irqs[index];
+	if (virqp)
+		*virqp = op->archdata.irqs[index];
+
+	return 0;
 }
-EXPORT_SYMBOL(irq_of_parse_and_map);
+EXPORT_SYMBOL(__irq_of_parse_and_map);
 
 int of_address_to_resource(struct device_node *node, int index,
 			   struct resource *r)
drivers/of/irq.c +12 -6
index 5f44388..6ad46fd 100644
@@ -27,24 +27,30 @@
 #include <linux/slab.h>
 
 /**
- * irq_of_parse_and_map - Parse and map an interrupt into linux virq space
+ * __irq_of_parse_and_map - Parse and map an interrupt into linux virq space
  * @dev: Device node of the device whose interrupt is to be mapped
  * @index: Index of the interrupt to map
+ * @virqp: Linux interrupt number filled by this function
  *
  * This function is a wrapper that chains of_irq_map_one() and
  * irq_create_of_mapping() to make things easier to callers
+ *
+ * Returns 0 on success or a negative error code on failure.
  */
-unsigned int irq_of_parse_and_map(struct device_node *dev, int index)
+int __irq_of_parse_and_map(struct device_node *dev, unsigned int index,
+			   unsigned int *virqp)
 {
 	struct of_irq oirq;
+	int ret;
 
-	if (of_irq_map_one(dev, index, &oirq))
-		return 0;
+	ret = of_irq_map_one(dev, index, &oirq);
+	if (ret)
+		return ret;
 
 	return irq_create_of_mapping(oirq.controller, oirq.specifier,
-				     oirq.size);
+				     oirq.size, virqp);
 }
-EXPORT_SYMBOL_GPL(irq_of_parse_and_map);
+EXPORT_SYMBOL_GPL(__irq_of_parse_and_map);
 
 /**
  * of_irq_find_parent - Given a device node, find its interrupt parent node
include/linux/of_irq.h +14 -5
index 138266d..11da949 100644
@@ -11,11 +11,12 @@ struct of_irq;
 #include <linux/of.h>
 
 /*
- * irq_of_parse_and_map() is used by all OF enabled platforms; but SPARC
+ * __irq_of_parse_and_map() is used by all OF enabled platforms; but SPARC
  * implements it differently.  However, the prototype is the same for all,
  * so declare it here regardless of the CONFIG_OF_IRQ setting.
  */
-extern unsigned int irq_of_parse_and_map(struct device_node *node, int index);
+extern int __irq_of_parse_and_map(struct device_node *node, unsigned int index,
+				  unsigned int *virqp);
 
 #if defined(CONFIG_OF_IRQ)
 /**
@@ -78,10 +79,11 @@ extern void of_irq_init(const struct of_device_id *matches);
 #endif /* CONFIG_OF_IRQ */
 
 #else /* !CONFIG_OF */
-static inline unsigned int irq_of_parse_and_map(struct device_node *dev,
-						int index)
+static inline int __irq_of_parse_and_map(struct device_node *dev,
+					 unsigned int index,
+					 unsigned int *virqp)
 {
-	return 0;
+	return -ENOSYS;
 }
 
 static inline void *of_irq_find_parent(struct device_node *child)
@@ -90,4 +92,11 @@ static inline void *of_irq_find_parent(struct device_node *child)
 }
 #endif /* !CONFIG_OF */
 
+static inline unsigned int irq_of_parse_and_map(struct device_node *node,
+						unsigned int index)
+{
+	unsigned int irq;
+	return (__irq_of_parse_and_map(node, index, &irq) < 0) ? 0 : irq;
+}
+
 #endif /* __OF_IRQ_H */
Signature · 1 line
1.8.4
#14 lore raw

PATCH v2 6/10 of/irq: Return errors from of_irq_to_resource()

In reply to Thierry Reding

Update of_irq_to_resource() to return 0 on success and a negative error code on failure. This allows the precise nature of the failure to be determined in the caller and errors to be propagated appropriately.

While at it, make the index parameter unsigned. Accessing negative indices is invalid, so we might as well enforce that by using the right data type.

---
Changes in v2:
- convert existing callers instead of using compatible wrapper

 arch/powerpc/platforms/83xx/mpc832x_rdb.c  |  2 +-
 drivers/net/ethernet/marvell/mv643xx_eth.c |  5 +++--
 drivers/of/irq.c                           | 14 +++++++++++---
 include/linux/of_irq.h                     |  2 +-
 4 files changed, 16 insertions(+), 7 deletions(-)
arch/powerpc/platforms/83xx/mpc832x_rdb.c +1 -1
index eff5baa..b198e73 100644
@@ -89,7 +89,7 @@ static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
 			goto err;
 
 		ret = of_irq_to_resource(np, 0, &res[1]);
-		if (ret == NO_IRQ)
+		if (ret)
 			goto err;
 
 		pdev = platform_device_alloc("mpc83xx_spi", i);
drivers/net/ethernet/marvell/mv643xx_eth.c +3 -2
index 7fb5677..bd713bd 100644
@@ -2489,9 +2489,10 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
 	ppd.shared = pdev;
 
 	memset(&res, 0, sizeof(res));
-	if (!of_irq_to_resource(pnp, 0, &res)) {
+	ret = of_irq_to_resource(pnp, 0, &res);
+	if (ret) {
 		dev_err(&pdev->dev, "missing interrupt on %s\n", pnp->name);
-		return -EINVAL;
+		return ret;
 	}
 
 	if (of_property_read_u32(pnp, "reg", &ppd.port_number)) {
drivers/of/irq.c +11 -3
index 6ad46fd..e4f38c0 100644
@@ -341,10 +341,18 @@ EXPORT_SYMBOL_GPL(of_irq_map_one);
  * @dev: pointer to device tree node
  * @index: zero-based index of the irq
  * @r: pointer to resource structure to return result into.
+ *
+ * Returns zero on success or a negative error code on failure.
  */
-int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
+int of_irq_to_resource(struct device_node *dev, unsigned int index,
+		       struct resource *r)
 {
-	int irq = irq_of_parse_and_map(dev, index);
+	unsigned int irq;
+	int ret;
+
+	ret = __irq_of_parse_and_map(dev, index, &irq);
+	if (ret)
+		return ret;
 
 	/* Only dereference the resource if both the
 	 * resource and the irq are valid. */
@@ -364,7 +372,7 @@ int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
 		r->name = name ? name : dev->full_name;
 	}
 
-	return irq;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(of_irq_to_resource);
 
include/linux/of_irq.h +1 -1
index 11da949..6d62b73 100644
@@ -67,7 +67,7 @@ extern int of_irq_map_one(struct device_node *device, int index,
 extern int irq_create_of_mapping(struct device_node *controller,
 				 const u32 *intspec, unsigned int intsize,
 				 unsigned int *virqp);
-extern int of_irq_to_resource(struct device_node *dev, int index,
+extern int of_irq_to_resource(struct device_node *dev, unsigned int index,
 			      struct resource *r);
 extern int of_irq_count(struct device_node *dev);
 extern int of_irq_to_resource_table(struct device_node *dev,
Signature · 1 line
1.8.4
#15 lore raw

PATCH v2 7/10 of/irq: Propagate errors in of_irq_to_resource_table()

In reply to Thierry Reding

Now that all helpers return precise error codes, this function can propagate these errors to the caller properly.

---
Changes in v2:
- return 0 on success or a negative error code on failure
- convert callers to new calling convention

 arch/mips/lantiq/irq.c       |  2 +-
 arch/mips/lantiq/xway/gptu.c |  6 ++++--
 drivers/of/irq.c             | 14 ++++++++------
 drivers/tty/serial/lantiq.c  |  2 +-
 4 files changed, 14 insertions(+), 10 deletions(-)
arch/mips/lantiq/irq.c +1 -1
index eb3e186..5bb7ee6 100644
@@ -389,7 +389,7 @@ int __init icu_of_init(struct device_node *node, struct device_node *parent)
 
 		ret = of_irq_to_resource_table(eiu_node,
 						ltq_eiu_irq, exin_avail);
-		if (ret != exin_avail)
+		if (ret < 0)
 			panic("failed to load external irq resources\n");
 
 		if (request_mem_region(res.start, resource_size(&res),
arch/mips/lantiq/xway/gptu.c +4 -2
index 850821d..0c4b134 100644
@@ -137,10 +137,12 @@ static int gptu_probe(struct platform_device *pdev)
 {
 	struct clk *clk;
 	struct resource *res;
+	int ret;
 
-	if (of_irq_to_resource_table(pdev->dev.of_node, irqres, 6) != 6) {
+	ret = of_irq_to_resource_table(pdev->dev.of_node, irqres, 6);
+	if (ret < 0) {
 		dev_err(&pdev->dev, "Failed to get IRQ list\n");
-		return -EINVAL;
+		return ret;
 	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/of/irq.c +8 -6
index e4f38c0..6d7f824 100644
@@ -397,18 +397,20 @@ int of_irq_count(struct device_node *dev)
  * @res: array of resources to fill in
  * @nr_irqs: the number of IRQs (and upper bound for num of @res elements)
  *
- * Returns the size of the filled in table (up to @nr_irqs).
+ * Returns 0 on success or a negative error code on failure.
  */
 int of_irq_to_resource_table(struct device_node *dev, struct resource *res,
 		int nr_irqs)
 {
-	int i;
+	int i, ret;
 
-	for (i = 0; i < nr_irqs; i++, res++)
-		if (!of_irq_to_resource(dev, i, res))
-			break;
+	for (i = 0; i < nr_irqs; i++, res++) {
+		ret = of_irq_to_resource(dev, i, res);
+		if (ret < 0)
+			return ret;
+	}
 
-	return i;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(of_irq_to_resource_table);
 
drivers/tty/serial/lantiq.c +1 -1
index 88d01e0..e59efdc 100644
@@ -686,7 +686,7 @@ lqasc_probe(struct platform_device *pdev)
 
 	mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	ret = of_irq_to_resource_table(node, irqres, 3);
-	if (!mmres || (ret != 3)) {
+	if (!mmres || (ret < 0)) {
 		dev_err(&pdev->dev,
 			"failed to get memory/irq for serial port\n");
 		return -ENODEV;
Signature · 1 line
1.8.4
#17 lore raw

Re: [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table()

In reply to Thierry Reding
Quoted 8 lines · Thierry Reding

Now that all helpers return precise error codes, this function can propagate these errors to the caller properly.

---
Changes in v2:
- return 0 on success or a negative error code on failure
- convert callers to new calling convention

[snip]

drivers/of/irq.c int of_irq_count(struct device_node *dev) · line 398

Quoted 7 lines
drivers/of/irq.c +0 -0
index e4f38c0..6d7f824 100644
@@ -397,18 +397,20 @@ int of_irq_count(struct device_node *dev)
  * @res: array of resources to fill in
  * @nr_irqs: the number of IRQs (and upper bound for num of @res elements)

You are effectively changing this to require an exact match rather than an upper bound. That seems to be okay since that is what all the callers want, but the documentation should be updated.

drivers/of/irq.c int of_irq_count(struct device_node *dev) · line 408

Quoted 12 lines
drivers/of/irq.c +2 -4
  *
- * Returns the size of the filled in table (up to @nr_irqs).
+ * Returns 0 on success or a negative error code on failure.
  */
 int of_irq_to_resource_table(struct device_node *dev, struct resource *res,
                int nr_irqs)
 {
-       int i;
+       int i, ret;
 
-       for (i = 0; i < nr_irqs; i++, res++)
-               if (!of_irq_to_resource(dev, i, res))

The error handling here needs to be updated in the previous patch.

Quoted 12 lines
drivers/of/irq.c +6 -2
-                       break;
+       for (i = 0; i < nr_irqs; i++, res++) {
+               ret = of_irq_to_resource(dev, i, res);
+               if (ret < 0)
+                       return ret;
+       }
 
-       return i;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(of_irq_to_resource_table);
 
#18 lore raw

Re: [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table()

Quoted 13 lines · Rob Herring
Quoted 8 lines · Thierry Reding

Now that all helpers return precise error codes, this function can propagate these errors to the caller properly.

---
Changes in v2:
- return 0 on success or a negative error code on failure
- convert callers to new calling convention

[snip]

Quoted 11 lines

drivers/of/irq.c int of_irq_count(struct device_node *dev) · line 398

Quoted 7 lines
drivers/of/irq.c +0 -0
index e4f38c0..6d7f824 100644
@@ -397,18 +397,20 @@ int of_irq_count(struct device_node *dev)
  * @res: array of resources to fill in
  * @nr_irqs: the number of IRQs (and upper bound for num of @res elements)

You are effectively changing this to require an exact match rather than an upper bound. That seems to be okay since that is what all the callers want, but the documentation should be updated.

Done.

Quoted 10 lines
Quoted 10 lines
drivers/of/irq.c +2 -2
  *
- * Returns the size of the filled in table (up to @nr_irqs).
+ * Returns 0 on success or a negative error code on failure.
  */
 int of_irq_to_resource_table(struct device_node *dev, struct resource *res,
                int nr_irqs)
 {
-       int i;
+       int i, ret;
 
Quoted 4 lines

drivers/of/irq.c int of_irq_count(struct device_node *dev) · line 408

Quoted 2 lines
drivers/of/irq.c +0 -2
-       for (i = 0; i < nr_irqs; i++, res++)
-               if (!of_irq_to_resource(dev, i, res))

The error handling here needs to be updated in the previous patch.

Yes, you're right.

Thanks,
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130923/73e402a2/attachment.sig>

#19 lore raw

PATCH v2 8/10 of/platform: Resolve interrupt references at probe time

In reply to Thierry Reding

Interrupt references are currently resolved very early (when a device is created). This has the disadvantage that it will fail in cases where the interrupt parent hasn't been probed and no IRQ domain for it has been registered yet. To work around that various drivers use explicit initcall ordering to force interrupt parents to be probed before devices that need them are created. That's error prone and doesn't always work. If a platform device uses an interrupt line connected to a different platform device (such as a GPIO controller), both will be created in the same batch, and the GPIO controller won't have been probed by its driver when the depending platform device is created. Interrupt resolution will fail in that case.

Another common workaround is for drivers to explicitly resolve interrupt references at probe time. This is suboptimal, however, because it will require every driver to duplicate the code.

This patch adds support for late interrupt resolution to the platform driver core, by resolving the references right before a device driver's .probe() function will be called. This not only delays the resolution until a much later time (giving interrupt parents a better chance of being probed in the meantime), but it also allows the platform driver core to queue the device for deferred probing if the interrupt parent hasn't registered its IRQ domain yet.

---
Changes in v2:
- split off IRQ parsing into separate function to make code flow simpler
- add comments to point out some aspects of the implementation
- make code idempotent (as pointed out by Grygorii Strashko

 drivers/base/platform.c     |   4 ++
 drivers/of/platform.c       | 107 +++++++++++++++++++++++++++++++++++++++++---
 include/linux/of_platform.h |   7 +++
 3 files changed, 112 insertions(+), 6 deletions(-)
drivers/base/platform.c +4 -0
index 4f8bef3..8dcf835 100644
@@ -481,6 +481,10 @@ static int platform_drv_probe(struct device *_dev)
 	struct platform_device *dev = to_platform_device(_dev);
 	int ret;
 
+	ret = of_platform_probe(dev);
+	if (ret)
+		return ret;
+
 	if (ACPI_HANDLE(_dev))
 		acpi_dev_pm_attach(_dev, true);
 
drivers/of/platform.c +101 -6

135 lines not on this page · raw message

include/linux/of_platform.h +7 -0
index 05cb4a9..92fc4f6 100644
@@ -72,6 +72,8 @@ extern int of_platform_populate(struct device_node *root,
 				const struct of_device_id *matches,
 				const struct of_dev_auxdata *lookup,
 				struct device *parent);
+
+extern int of_platform_probe(struct platform_device *pdev);
 #else
 static inline int of_platform_populate(struct device_node *root,
 					const struct of_device_id *matches,
@@ -80,6 +82,11 @@ static inline int of_platform_populate(struct device_node *root,
 {
 	return -ENODEV;
 }
+
+static inline int of_platform_probe(struct platform_device *pdev)
+{
+	return 0;
+}
 #endif
 
 #endif	/* _LINUX_OF_PLATFORM_H */
Signature · 1 line
1.8.4
#20 lore raw

Re: [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time

Quoted 11 lines · Thierry Reding

Interrupt references are currently resolved very early (when a device is created). This has the disadvantage that it will fail in cases where the interrupt parent hasn't been probed and no IRQ domain for it has been registered yet. To work around that various drivers use explicit initcall ordering to force interrupt parents to be probed before devices that need them are created. That's error prone and doesn't always work. If a platform device uses an interrupt line connected to a different platform device (such as a GPIO controller), both will be created in the same batch, and the GPIO controller won't have been probed by its driver when the depending platform device is created. Interrupt resolution will fail in that case.

What is the reason for all the rework on the irq parsing return values? A return value of '0' is always an error on irq parsing, regardless of architecture even if NO_IRQ is defined as -1. I may have missed it, but I don't see any checking for specific error values in the return paths of the functions.

If the specific return value isn't required (and I don't think it is), then you can simplify the whole series by getting rid of the rework patches.

g.

Quoted 210 lines

Another common workaround is for drivers to explicitly resolve interrupt references at probe time. This is suboptimal, however, because it will require every driver to duplicate the code.

This patch adds support for late interrupt resolution to the platform driver core, by resolving the references right before a device driver's .probe() function will be called. This not only delays the resolution until a much later time (giving interrupt parents a better chance of being probed in the meantime), but it also allows the platform driver core to queue the device for deferred probing if the interrupt parent hasn't registered its IRQ domain yet.

---
Changes in v2:
- split off IRQ parsing into separate function to make code flow simpler
- add comments to point out some aspects of the implementation
- make code idempotent (as pointed out by Grygorii Strashko

 drivers/base/platform.c     |   4 ++
 drivers/of/platform.c       | 107 +++++++++++++++++++++++++++++++++++++++++---
 include/linux/of_platform.h |   7 +++
 3 files changed, 112 insertions(+), 6 deletions(-)
drivers/base/platform.c +4 -0
index 4f8bef3..8dcf835 100644
@@ -481,6 +481,10 @@ static int platform_drv_probe(struct device *_dev)
 	struct platform_device *dev = to_platform_device(_dev);
 	int ret;
 
+	ret = of_platform_probe(dev);
+	if (ret)
+		return ret;
+
 	if (ACPI_HANDLE(_dev))
 		acpi_dev_pm_attach(_dev, true);
 
drivers/of/platform.c +101 -6
index 9b439ac..df6d56e 100644
@@ -142,7 +142,7 @@ struct platform_device *of_device_alloc(struct device_node *np,
 				  struct device *parent)
 {
 	struct platform_device *dev;
-	int rc, i, num_reg = 0, num_irq;
+	int rc, i, num_reg = 0;
 	struct resource *res, temp_res;
 
 	dev = platform_device_alloc("", -1);
@@ -153,23 +153,21 @@ struct platform_device *of_device_alloc(struct device_node *np,
 	if (of_can_translate_address(np))
 		while (of_address_to_resource(np, num_reg, &temp_res) == 0)
 			num_reg++;
-	num_irq = of_irq_count(np);
 
 	/* Populate the resource table */
-	if (num_irq || num_reg) {
-		res = kzalloc(sizeof(*res) * (num_irq + num_reg), GFP_KERNEL);
+	if (num_reg) {
+		res = kzalloc(sizeof(*res) * num_reg, GFP_KERNEL);
 		if (!res) {
 			platform_device_put(dev);
 			return NULL;
 		}
 
-		dev->num_resources = num_reg + num_irq;
+		dev->num_resources = num_reg;
 		dev->resource = res;
 		for (i = 0; i < num_reg; i++, res++) {
 			rc = of_address_to_resource(np, i, res);
 			WARN_ON(rc);
 		}
-		WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq);
 	}
 
 	dev->dev.of_node = of_node_get(np);
@@ -490,4 +488,101 @@ int of_platform_populate(struct device_node *root,
 	return rc;
 }
 EXPORT_SYMBOL_GPL(of_platform_populate);
+
+/**
+ * of_platform_parse_irq() - parse interrupt resource from device node
+ * @pdev: pointer to platform device
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+static int of_platform_parse_irq(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	unsigned int num_res = pdev->num_resources;
+	struct resource *res = pdev->resource;
+	unsigned int num_irq, num, c;
+	int ret = 0;
+
+	num_irq = of_irq_count(pdev->dev.of_node);
+	if (!num_irq)
+		return 0;
+
+	/*
+	 * Deferred probing may cause this function to be called multiple
+	 * times, so check if all interrupts have been parsed already and
+	 * return early.
+	 */
+	for (c = 0; c < num_irq; c++)
+		if (platform_get_irq(pdev, c) < 0)
+			break;
+
+	if (c == num_irq)
+		return 0;
+
+	num = num_res + num_irq;
+
+	/*
+	 * Note that in case we're called twice on the same device (due to
+	 * deferred probing for example) this will simply be a nop because
+	 * krealloc() returns the input pointer if the size of the memory
+	 * block that it points to is larger than or equal to the new size
+	 * being requested.
+	 */
+	res = krealloc(res, num * sizeof(*res), GFP_KERNEL);
+	if (!res)
+		return -ENOMEM;
+
+	pdev->resource = res;
+	res += num_res;
+
+	/*
+	 * It is possible for this to fail. If so, not that the number of
+	 * resources is not updated, so that the next call to this function
+	 * will parse all interrupts again. Otherwise we can't keep track of
+	 * how many we've parsed so far.
+	 */
+	ret = of_irq_to_resource_table(np, res, num_irq);
+	if (ret < 0)
+		return ret;
+
+	/*
+	 * All interrupts are guaranteed to have been parsed and stored in
+	 * the resource table, so the number of resources can now safely be
+	 * updated.
+	 */
+	pdev->num_resources += num_irq;
+
+	return 0;
+}
+
+/**
+ * of_platform_probe() - OF specific initialization at probe time
+ * @pdev: pointer to a platform device
+ *
+ * This function is called by the driver core to perform devicetree-specific
+ * setup for a given platform device at probe time. If a device's resources
+ * as specified in the device tree are not available yet, this function can
+ * return -EPROBE_DEFER and cause the device to be probed again later, when
+ * other drivers that potentially provide the missing resources have been
+ * probed in turn.
+ *
+ * Note that because of the above, all code executed by this function must
+ * be prepared to be run multiple times on the same device (i.e. it must be
+ * idempotent).
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int of_platform_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	if (!pdev->dev.of_node)
+		return 0;
+
+	ret = of_platform_parse_irq(pdev);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
 #endif /* CONFIG_OF_ADDRESS */
include/linux/of_platform.h +7 -0
index 05cb4a9..92fc4f6 100644
@@ -72,6 +72,8 @@ extern int of_platform_populate(struct device_node *root,
 				const struct of_device_id *matches,
 				const struct of_dev_auxdata *lookup,
 				struct device *parent);
+
+extern int of_platform_probe(struct platform_device *pdev);
 #else
 static inline int of_platform_populate(struct device_node *root,
 					const struct of_device_id *matches,
@@ -80,6 +82,11 @@ static inline int of_platform_populate(struct device_node *root,
 {
 	return -ENODEV;
 }
+
+static inline int of_platform_probe(struct platform_device *pdev)
+{
+	return 0;
+}
 #endif
 
 #endif	/* _LINUX_OF_PLATFORM_H */
Signature · 1 line
1.8.4
#21 lore raw

Re: [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time

Quoted 19 lines · Grant Likely
Quoted 11 lines · Thierry Reding

Interrupt references are currently resolved very early (when a device is created). This has the disadvantage that it will fail in cases where the interrupt parent hasn't been probed and no IRQ domain for it has been registered yet. To work around that various drivers use explicit initcall ordering to force interrupt parents to be probed before devices that need them are created. That's error prone and doesn't always work. If a platform device uses an interrupt line connected to a different platform device (such as a GPIO controller), both will be created in the same batch, and the GPIO controller won't have been probed by its driver when the depending platform device is created. Interrupt resolution will fail in that case.

What is the reason for all the rework on the irq parsing return values? A return value of '0' is always an error on irq parsing, regardless of architecture even if NO_IRQ is defined as -1. I may have missed it, but I don't see any checking for specific error values in the return paths of the functions.

Quoted 3 lines

If the specific return value isn't required (and I don't think it is), then you can simplify the whole series by getting rid of the rework patches.

The whole reason for this patch set is to propagate the precise error code so that when one of the top-level OF IRQ functions is called (such as irq_of_parse_and_map()) the caller can actually make an reasonable choice on how to handle the error.

More precisely, the goal of this series was to propagate failure to create a mapping, due to an IRQ domain not having been registered yet for the device node passed into irq_create_of_mapping(), back to the caller, irq_of_parse_and_map(), which can then propagate it further. Ultimately this will allow driver probing to fail with EPROBE_DEFER when IRQ mapping fails and allow deferred probing to be triggered.

This cannot be done if all you have as error status is 0. Mapping of IRQs can fail for a number of reasons, such as when an IRQ descriptor cannot be allocated or when an IRQ domain's .xlate() fails. You don't want to be deferring probe on all errors because some of them are genuinely fatal and cannot be recovered from by deferring probe.

With the current implementation in the kernel, interrupt references are resolved very early, usually when a device is instantiated from the device tree. So unless all interrupt parents of all devices have been probed by that time (which usually can only be done using explicit initcall ordering, and even in that case doesn't always work) then many devices will end up with an invalid interrupt number.

The typical case where this can happen is if you have a GPIO expander on an I2C bus that provides interrupt services to other devices. With the current implementation, the GPIO expander will be probed fairly late, at which point many of its users will already have been instantiated and assigned an invalid interrupt. Many drivers try to work around that by explicitly calling irq_of_parse_and_map() within their .probe() function because that's usually called sometime after the device's instantiation. However even that isn't guaranteed to work. If the GPIO expander depends itself on other resources that cause it to require deferred probing, or if its driver is built as a module and therefore making the registration of the corresponding IRQ domain is completely non-deterministic, then this can fail just as easily.

With this patch series all of these issues should go away. All of the dependencies should be resolvable by using deferred probing. Furthermore the mechanism introduced to have the core resolve the IRQ references can be used to request other standard resources as well. A particular one that I'm aware of is how IOMMUs are associated with devices. Currently a variety of quirks have been proposed to work around these issues, such as reordering nodes in the device tree, which only work because the DTC implementation that everybody uses happens to keep them ordered in the same way in the DTB as they were in the DTS.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131016/211ce935/attachment-0001.sig>

#22 lore raw

Re: [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time

In reply to Grant Likely
Quoted 19 lines · Grant Likely
Quoted 11 lines · Thierry Reding

Interrupt references are currently resolved very early (when a device is created). This has the disadvantage that it will fail in cases where the interrupt parent hasn't been probed and no IRQ domain for it has been registered yet. To work around that various drivers use explicit initcall ordering to force interrupt parents to be probed before devices that need them are created. That's error prone and doesn't always work. If a platform device uses an interrupt line connected to a different platform device (such as a GPIO controller), both will be created in the same batch, and the GPIO controller won't have been probed by its driver when the depending platform device is created. Interrupt resolution will fail in that case.

What is the reason for all the rework on the irq parsing return values? A return value of '0' is always an error on irq parsing, regardless of architecture even if NO_IRQ is defined as -1. I may have missed it, but I don't see any checking for specific error values in the return paths of the functions.

Quoted 3 lines

If the specific return value isn't required (and I don't think it is), then you can simplify the whole series by getting rid of the rework patches.

I've not heard back about the above, but I've just had a conversation with Rob about what to do here. The problem that I have is that it makes a specific return code need to traverse several levels of function calls and have a meaning come out the other end. It becomes difficult to figure out where that code actually comes from when reading the code. That's more of a gut-feel reaction rather than pointing out specifics though.

The other thing that makes me nervous how invasive the series is.

However, even with saying all of the above, I'm not saying outright no. I want to get this feature in. It is obviously needed and I'll even merge the patches piecemeal as the look ready (I've already merged 2). Regardless, the current series needs to be reworked. It conflicts with the other IRQ rework that I've already put into my tree. The best thing to do would probably be respin it against my current tree and repost. I'll take a fresh look then.... In the mean time, anything you can do to /sanely/ reduce the impact will probably help. :-)

g.

#23 lore raw

Re: [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time

Quoted 20 lines · Grant Likely
Quoted 19 lines · Grant Likely
Quoted 11 lines · Thierry Reding

Interrupt references are currently resolved very early (when a device is created). This has the disadvantage that it will fail in cases where the interrupt parent hasn't been probed and no IRQ domain for it has been registered yet. To work around that various drivers use explicit initcall ordering to force interrupt parents to be probed before devices that need them are created. That's error prone and doesn't always work. If a platform device uses an interrupt line connected to a different platform device (such as a GPIO controller), both will be created in the same batch, and the GPIO controller won't have been probed by its driver when the depending platform device is created. Interrupt resolution will fail in that case.

What is the reason for all the rework on the irq parsing return values? A return value of '0' is always an error on irq parsing, regardless of architecture even if NO_IRQ is defined as -1. I may have missed it, but I don't see any checking for specific error values in the return paths of the functions.

Quoted 6 lines
Quoted 3 lines

If the specific return value isn't required (and I don't think it is), then you can simplify the whole series by getting rid of the rework patches.

I've not heard back about the above, but I've just had a conversation with Rob about what to do here.

I thought I had sent a reply regarding this about a week ago. Perhaps it got lost. I'll resend.

Quoted 5 lines

The problem that I have is that it makes a specific return code need to traverse several levels of function calls and have a meaning come out the other end. It becomes difficult to figure out where that code actually comes from when reading the code. That's more of a gut-feel reaction rather than pointing out specifics though.

To be honest, I'm not all that happy with that aspect myself, but at the same time I didn't feel like duplicating a lot of code to get this done more easily. I imagine that would've caused significant pushback as well. It's somewhat unfortunate that we have to propagate back through several level, but that's just the way the code is currently written and I don't think we can really get the information (EPROBE_DEFER) from any other place but from the lowest level.

Quoted 1 line

The other thing that makes me nervous how invasive the series is.

Well, I guess that comes with the territory, doesn't it? Interrupts are used in a large number of places and they have been used in a very static manner so far. The end result of this patch series is that for most devices instantiated from the device tree interrupts end up in the same category as any other resources such as GPIOs, regulators or clocks. They become mostly dynamic.

That in itself is a big change, so I don't think it's all that surprising that the required changes are invasive.

And I think if we really want to solve it properly we need to make even more invasive changes. For example, Grygorii pointed out that we could have a setup in the future where the following happens:

1) driver providing interrupts is probed
2) driver using interrupts is probed, interrupt references are resolved at probe time
3) both drivers are unloaded
4) both drivers are reloaded

In that case with the current set of patches the added core code assumes that the interrupts have already been resolved and are still valid.

Possibly the easiest way to fix that would be to just zero out the interrupt resources on remove so that they can be re-resolved on next probe.

But that's somewhat cumbersome and it seems to me like a better fix might be to go and change struct platform_device to not use a single array of resources, but rather a list, or perhaps an array per type of resource. The current platform_device structure is simple and easy, but it doesn't work well with all the new dynamicity that we want/need/have today.

Obviously modifying the innards of struct platform_device will likely turn out to be a mammoth task of its own, but if that's what it takes I'm prepared to do that as well. Or at least even try.

Quoted 2 lines

However, even with saying all of the above, I'm not saying outright no. I want to get this feature in.

That's good to hear. Last time we talked about it we seemed to have an agreement that this needs to be done, but you not replying had me worried that perhaps you had changed your mind. It seems you've been busy trying to address other issues that maybe are even more pressing so I can hardly complain. =)

I'm good as long as we can keep moving in the right direction.

Quoted 5 lines

It is obviously needed and I'll even merge the patches piecemeal as the look ready (I've already merged 2). Regardless, the current series needs to be reworked. It conflicts with the other IRQ rework that I've already put into my tree. The best thing to do would probably be respin it against my current tree and repost.

Sure, that won't be a problem. I might not get to it immediately, but I'll get back to it.

Quoted 2 lines

I'll take a fresh look then.... In the mean time, anything you can do to /sanely/ reduce the impact will probably help. :-)

I might be able to do that. But I'll mention that in another thread in the right context.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131025/e9e9304b/attachment.sig>

#24 lore raw

PATCH v2 9/10 of/i2c: Resolve interrupt references at probe time

In reply to Thierry Reding

Instead of resolving interrupt references at device creation time, delay resolution until probe time. At device creation time, there is nothing that can be done if an interrupt parent isn't ready yet, and the device will end up with an invalid interrupt number (0).

If the interrupt reference is resolved at probe time, the device's probe can be deferred, so that it's interrupt resolution can be retried after more devices (possibly including its interrupt parent) have been probed.

However, individual drivers shouldn't be required to do that themselves, over and over again, so this commit implements this functionality within the I2C core.

---
Changes in v2:
- use __irq_of_parse_and_map() instead of of_irq_get()

 drivers/i2c/i2c-core.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core.c +22 -2
index 29d3f04..5b4f289 100644
@@ -236,6 +236,22 @@ int i2c_recover_bus(struct i2c_adapter *adap)
 	return adap->bus_recovery_info->recover_bus(adap);
 }
 
+static int of_i2c_probe(struct i2c_client *client)
+{
+	struct device_node *np = client->dev.of_node;
+	int ret;
+
+	/* skip if the device node specifies no interrupts */
+	if (of_get_property(np, "interrupts", NULL)) {
+		ret = __irq_of_parse_and_map(client->dev.of_node, 0,
+					     &client->irq);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int i2c_device_probe(struct device *dev)
 {
 	struct i2c_client	*client = i2c_verify_client(dev);
@@ -254,6 +270,12 @@ static int i2c_device_probe(struct device *dev)
 					client->flags & I2C_CLIENT_WAKE);
 	dev_dbg(dev, "probe\n");
 
+	if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+		status = of_i2c_probe(client);
+		if (status)
+			return status;
+	}
+
 	status = driver->probe(client, i2c_match_id(driver->id_table, client));
 	if (status) {
 		client->driver = NULL;
@@ -1002,7 +1024,6 @@ static void of_i2c_register_devices(struct i2c_adapter *adap)
 			continue;
 		}
 
-		info.irq = irq_of_parse_and_map(node, 0);
 		info.of_node = of_node_get(node);
 		info.archdata = &dev_ad;
 
@@ -1016,7 +1037,6 @@ static void of_i2c_register_devices(struct i2c_adapter *adap)
 			dev_err(&adap->dev, "of_i2c: Failure registering %s\n",
 				node->full_name);
 			of_node_put(node);
-			irq_dispose_mapping(info.irq);
 			continue;
 		}
 	}
Signature · 1 line
1.8.4
#25 lore raw

PATCH v2 10/10 gpio: tegra: Use module_platform_driver()

In reply to Thierry Reding

With the driver core now resolving interrupt references at probe time, it is no longer necessary to force explicit probe ordering using initcalls.

---
Note that there are potentially many more drivers that can be switched to the generic module_*_driver() interfaces now that interrupts can be resolved later and deferred probe should be able to handle all the ordering issues.

 drivers/gpio/gpio-tegra.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpio/gpio-tegra.c +1 -6
index 9a62672..766e6ef 100644
@@ -513,12 +513,7 @@ static struct platform_driver tegra_gpio_driver = {
 	},
 	.probe		= tegra_gpio_probe,
 };
-
-static int __init tegra_gpio_init(void)
-{
-	return platform_driver_register(&tegra_gpio_driver);
-}
-postcore_initcall(tegra_gpio_init);
+module_platform_driver(tegra_gpio_driver);
 
 #ifdef	CONFIG_DEBUG_FS
 
Signature · 1 line
1.8.4