linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/10] of/irq: Defer interrupt reference resolution
@ 2013-09-18 13:24 Thierry Reding
  2013-09-18 13:24 ` [PATCH v2 01/10] of/irq: Rework of_irq_count() Thierry Reding
                   ` (9 more replies)
  0 siblings, 10 replies; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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(-)

-- 
1.8.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v2 01/10] of/irq: Rework of_irq_count()
  2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
@ 2013-09-18 13:24 ` Thierry Reding
  2013-09-22 21:19   ` Rob Herring
  2013-09-18 13:24 ` [PATCH v2 02/10] of/irq: Use irq_of_parse_and_map() Thierry Reding
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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().

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/of/irq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 1752988..5f44388 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -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


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 02/10] of/irq: Use irq_of_parse_and_map()
  2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
  2013-09-18 13:24 ` [PATCH v2 01/10] of/irq: Rework of_irq_count() Thierry Reding
@ 2013-09-18 13:24 ` Thierry Reding
  2013-09-22 21:17   ` Rob Herring
  2013-09-18 13:24 ` [PATCH v2 03/10] irqdomain: Introduce __irq_create_mapping() Thierry Reding
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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().

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 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(-)

diff --git a/arch/arm/mach-u300/timer.c b/arch/arm/mach-u300/timer.c
index b5db207..9a5f9fb 100644
--- a/arch/arm/mach-u300/timer.c
+++ b/arch/arm/mach-u300/timer.c
@@ -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);
diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
index 14be2bd..856ad64 100644
--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
@@ -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");
diff --git a/arch/powerpc/platforms/cell/spider-pic.c b/arch/powerpc/platforms/cell/spider-pic.c
index 8e29944..1f72f4a 100644
--- a/arch/powerpc/platforms/cell/spider-pic.c
+++ b/arch/powerpc/platforms/cell/spider-pic.c
@@ -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);
diff --git a/arch/powerpc/sysdev/fsl_gtm.c b/arch/powerpc/sysdev/fsl_gtm.c
index 0eb871c..dd0d5be 100644
--- a/arch/powerpc/sysdev/fsl_gtm.c
+++ b/arch/powerpc/sysdev/fsl_gtm.c
@@ -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;
 		}
 
diff --git a/arch/powerpc/sysdev/mpic_msgr.c b/arch/powerpc/sysdev/mpic_msgr.c
index c753258..2c9b52a 100644
--- a/arch/powerpc/sysdev/mpic_msgr.c
+++ b/arch/powerpc/sysdev/mpic_msgr.c
@@ -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;
diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 26438cd..c8224da 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -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,
diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 105ba4d..517a16d 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -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 */
diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index 8bdde57..e28104b 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -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;
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index b2b8aa9..3e5ea2c 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -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;
 
diff --git a/drivers/input/serio/xilinx_ps2.c b/drivers/input/serio/xilinx_ps2.c
index 4b7662a..36f7b95 100644
--- a/drivers/input/serio/xilinx_ps2.c
+++ b/drivers/input/serio/xilinx_ps2.c
@@ -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;
 
diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c
index 9e16014..d087852 100644
--- a/drivers/net/ethernet/arc/emac_main.c
+++ b/drivers/net/ethernet/arc/emac_main.c
@@ -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 */
diff --git a/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c b/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c
index 7583a95..10f781d 100644
--- a/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c
+++ b/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c
@@ -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;
 
diff --git a/drivers/net/ethernet/freescale/fs_enet/mac-fec.c b/drivers/net/ethernet/freescale/fs_enet/mac-fec.c
index 9ae6cdb..53a0c23 100644
--- a/drivers/net/ethernet/freescale/fs_enet/mac-fec.c
+++ b/drivers/net/ethernet/freescale/fs_enet/mac-fec.c
@@ -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;
 
diff --git a/drivers/net/ethernet/freescale/fs_enet/mac-scc.c b/drivers/net/ethernet/freescale/fs_enet/mac-scc.c
index 22a02a7..631f098 100644
--- a/drivers/net/ethernet/freescale/fs_enet/mac-scc.c
+++ b/drivers/net/ethernet/freescale/fs_enet/mac-scc.c
@@ -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;
 
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index b8f1103..3197d55 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -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;
diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
index 1a535f7..6957f445 100644
--- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
@@ -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


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 03/10] irqdomain: Introduce __irq_create_mapping()
  2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
  2013-09-18 13:24 ` [PATCH v2 01/10] of/irq: Rework of_irq_count() Thierry Reding
  2013-09-18 13:24 ` [PATCH v2 02/10] of/irq: Use irq_of_parse_and_map() Thierry Reding
@ 2013-09-18 13:24 ` Thierry Reding
  2013-09-18 13:24 ` [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping() Thierry Reding
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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().

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 kernel/irq/irqdomain.c | 59 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 20 deletions(-)

diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 706724e..d2a3b01 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -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);
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping()
  2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
                   ` (2 preceding siblings ...)
  2013-09-18 13:24 ` [PATCH v2 03/10] irqdomain: Introduce __irq_create_mapping() Thierry Reding
@ 2013-09-18 13:24 ` Thierry Reding
  2013-09-18 14:23   ` Ralf Baechle
  2013-09-22 21:14   ` Rob Herring
  2013-09-18 13:24 ` [PATCH v2 05/10] of/irq: Introduce __irq_of_parse_and_map() Thierry Reding
                   ` (5 subsequent siblings)
  9 siblings, 2 replies; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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).

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
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(-)

diff --git a/arch/arm/mach-integrator/pci_v3.c b/arch/arm/mach-integrator/pci_v3.c
index bef1005..aa0f867 100644
--- a/arch/arm/mach-integrator/pci_v3.c
+++ b/arch/arm/mach-integrator/pci_v3.c
@@ -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,
diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c
index 1b93bf0..80b6e0f 100644
--- a/arch/microblaze/pci/pci-common.c
+++ b/arch/microblaze/pci/pci-common.c
@@ -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");
diff --git a/arch/mips/pci/fixup-lantiq.c b/arch/mips/pci/fixup-lantiq.c
index 6c829df..dfe7bf1 100644
--- a/arch/mips/pci/fixup-lantiq.c
+++ b/arch/mips/pci/fixup-lantiq.c
@@ -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;
 }
diff --git a/arch/mips/pci/pci-rt3883.c b/arch/mips/pci/pci-rt3883.c
index 95c9d41..79b49b5 100644
--- a/arch/mips/pci/pci-rt3883.c
+++ b/arch/mips/pci/pci-rt3883.c
@@ -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
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index 905a24b..ae71b14 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -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");
diff --git a/arch/powerpc/platforms/cell/celleb_scc_sio.c b/arch/powerpc/platforms/cell/celleb_scc_sio.c
index 9c339ec..94b771e 100644
--- a/arch/powerpc/platforms/cell/celleb_scc_sio.c
+++ b/arch/powerpc/platforms/cell/celleb_scc_sio.c
@@ -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;
diff --git a/arch/powerpc/platforms/cell/spu_manage.c b/arch/powerpc/platforms/cell/spu_manage.c
index 2bb6977..b78c7a4 100644
--- a/arch/powerpc/platforms/cell/spu_manage.c
+++ b/arch/powerpc/platforms/cell/spu_manage.c
@@ -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;
 		}
diff --git a/arch/powerpc/platforms/fsl_uli1575.c b/arch/powerpc/platforms/fsl_uli1575.c
index 92ac9b5..575b215 100644
--- a/arch/powerpc/platforms/fsl_uli1575.c
+++ b/arch/powerpc/platforms/fsl_uli1575.c
@@ -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);
diff --git a/arch/powerpc/platforms/pseries/event_sources.c b/arch/powerpc/platforms/pseries/event_sources.c
index 2605c31..4367fdd 100644
--- a/arch/powerpc/platforms/pseries/event_sources.c
+++ b/arch/powerpc/platforms/pseries/event_sources.c
@@ -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);
diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
index 376dc78..7adede6 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -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;
 }
 
diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c
index 77f8a7c..7773a17 100644
--- a/drivers/pci/host/pci-mvebu.c
+++ b/drivers/pci/host/pci-mvebu.c
@@ -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)
diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
index 535cecf..138266d 100644
--- a/include/linux/of_irq.h
+++ b/include/linux/of_irq.h
@@ -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);
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index d2a3b01..5f8401c 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -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);
 
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 05/10] of/irq: Introduce __irq_of_parse_and_map()
  2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
                   ` (3 preceding siblings ...)
  2013-09-18 13:24 ` [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping() Thierry Reding
@ 2013-09-18 13:24 ` Thierry Reding
  2013-09-18 13:24 ` [PATCH v2 06/10] of/irq: Return errors from of_irq_to_resource() Thierry Reding
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
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(-)

diff --git a/arch/sparc/kernel/of_device_common.c b/arch/sparc/kernel/of_device_common.c
index de199bf..a69559f 100644
--- a/arch/sparc/kernel/of_device_common.c
+++ b/arch/sparc/kernel/of_device_common.c
@@ -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)
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 5f44388..6ad46fd 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -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
diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
index 138266d..11da949 100644
--- a/include/linux/of_irq.h
+++ b/include/linux/of_irq.h
@@ -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 */
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 06/10] of/irq: Return errors from of_irq_to_resource()
  2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
                   ` (4 preceding siblings ...)
  2013-09-18 13:24 ` [PATCH v2 05/10] of/irq: Introduce __irq_of_parse_and_map() Thierry Reding
@ 2013-09-18 13:24 ` Thierry Reding
  2013-09-18 13:24 ` [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table() Thierry Reding
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
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(-)

diff --git a/arch/powerpc/platforms/83xx/mpc832x_rdb.c b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
index eff5baa..b198e73 100644
--- a/arch/powerpc/platforms/83xx/mpc832x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
@@ -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);
diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index 7fb5677..bd713bd 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -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)) {
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 6ad46fd..e4f38c0 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -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);
 
diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
index 11da949..6d62b73 100644
--- a/include/linux/of_irq.h
+++ b/include/linux/of_irq.h
@@ -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,
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table()
  2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
                   ` (5 preceding siblings ...)
  2013-09-18 13:24 ` [PATCH v2 06/10] of/irq: Return errors from of_irq_to_resource() Thierry Reding
@ 2013-09-18 13:24 ` Thierry Reding
  2013-09-18 14:23   ` Ralf Baechle
  2013-09-22 21:08   ` Rob Herring
  2013-09-18 13:24 ` [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time Thierry Reding
                   ` (2 subsequent siblings)
  9 siblings, 2 replies; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
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(-)

diff --git a/arch/mips/lantiq/irq.c b/arch/mips/lantiq/irq.c
index eb3e186..5bb7ee6 100644
--- a/arch/mips/lantiq/irq.c
+++ b/arch/mips/lantiq/irq.c
@@ -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),
diff --git a/arch/mips/lantiq/xway/gptu.c b/arch/mips/lantiq/xway/gptu.c
index 850821d..0c4b134 100644
--- a/arch/mips/lantiq/xway/gptu.c
+++ b/arch/mips/lantiq/xway/gptu.c
@@ -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);
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index e4f38c0..6d7f824 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -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);
 
diff --git a/drivers/tty/serial/lantiq.c b/drivers/tty/serial/lantiq.c
index 88d01e0..e59efdc 100644
--- a/drivers/tty/serial/lantiq.c
+++ b/drivers/tty/serial/lantiq.c
@@ -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;
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time
  2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
                   ` (6 preceding siblings ...)
  2013-09-18 13:24 ` [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table() Thierry Reding
@ 2013-09-18 13:24 ` Thierry Reding
  2013-10-15 23:24   ` Grant Likely
  2013-09-18 13:24 ` [PATCH v2 09/10] of/i2c: " Thierry Reding
  2013-09-18 13:24 ` [PATCH v2 10/10] gpio: tegra: Use module_platform_driver() Thierry Reding
  9 siblings, 1 reply; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
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(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 4f8bef3..8dcf835 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -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);
 
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 9b439ac..df6d56e 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -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 */
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 05cb4a9..92fc4f6 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -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 */
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 09/10] of/i2c: Resolve interrupt references at probe time
  2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
                   ` (7 preceding siblings ...)
  2013-09-18 13:24 ` [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time Thierry Reding
@ 2013-09-18 13:24 ` Thierry Reding
  2013-09-18 13:24 ` [PATCH v2 10/10] gpio: tegra: Use module_platform_driver() Thierry Reding
  9 siblings, 0 replies; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
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(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 29d3f04..5b4f289 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -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;
 		}
 	}
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 10/10] gpio: tegra: Use module_platform_driver()
  2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
                   ` (8 preceding siblings ...)
  2013-09-18 13:24 ` [PATCH v2 09/10] of/i2c: " Thierry Reding
@ 2013-09-18 13:24 ` Thierry Reding
  9 siblings, 0 replies; 26+ messages in thread
From: Thierry Reding @ 2013-09-18 13:24 UTC (permalink / raw)
  To: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
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(-)

diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 9a62672..766e6ef 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -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
 
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping()
  2013-09-18 13:24 ` [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping() Thierry Reding
@ 2013-09-18 14:23   ` Ralf Baechle
  2013-09-22 21:14   ` Rob Herring
  1 sibling, 0 replies; 26+ messages in thread
From: Ralf Baechle @ 2013-09-18 14:23 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner,
	Benjamin Herrenschmidt, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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

For the MIPS bits:

Acked-by: Ralf Baechle <ralf@linux-mips.org>

  Ralf

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table()
  2013-09-18 13:24 ` [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table() Thierry Reding
@ 2013-09-18 14:23   ` Ralf Baechle
  2013-09-22 21:08   ` Rob Herring
  1 sibling, 0 replies; 26+ messages in thread
From: Ralf Baechle @ 2013-09-18 14:23 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner,
	Benjamin Herrenschmidt, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

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

For the MIPS bits:

Acked-by: Ralf Baechle <ralf@linux-mips.org>

  Ralf

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table()
  2013-09-18 13:24 ` [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table() Thierry Reding
  2013-09-18 14:23   ` Ralf Baechle
@ 2013-09-22 21:08   ` Rob Herring
  2013-09-23  8:36     ` Thierry Reding
  1 sibling, 1 reply; 26+ messages in thread
From: Rob Herring @ 2013-09-22 21:08 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner,
	Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

On Wed, Sep 18, 2013 at 8:24 AM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> Now that all helpers return precise error codes, this function can
> propagate these errors to the caller properly.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
> Changes in v2:
> - return 0 on success or a negative error code on failure
> - convert callers to new calling convention

[snip]

> diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> index e4f38c0..6d7f824 100644
> --- a/drivers/of/irq.c
> +++ b/drivers/of/irq.c
> @@ -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.

>   *
> - * 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.

> -                       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);
>

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping()
  2013-09-18 13:24 ` [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping() Thierry Reding
  2013-09-18 14:23   ` Ralf Baechle
@ 2013-09-22 21:14   ` Rob Herring
  2013-09-23  8:13     ` Thierry Reding
  1 sibling, 1 reply; 26+ messages in thread
From: Rob Herring @ 2013-09-22 21:14 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner,
	linux-mips, Russell King, devicetree, Benjamin Herrenschmidt,
	linux-kernel, Ralf Baechle, sparclinux, linuxppc-dev,
	linux-arm-kernel

On Wed, Sep 18, 2013 at 8:24 AM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> 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).
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

One comment below, otherwise:

Acked-by: Rob Herring <rob.herring@calxeda.com>

> diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
> index 905a24b..ae71b14 100644
> --- a/arch/powerpc/kernel/pci-common.c
> +++ b/arch/powerpc/kernel/pci-common.c
> @@ -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");

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

Rob

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 02/10] of/irq: Use irq_of_parse_and_map()
  2013-09-18 13:24 ` [PATCH v2 02/10] of/irq: Use irq_of_parse_and_map() Thierry Reding
@ 2013-09-22 21:17   ` Rob Herring
  0 siblings, 0 replies; 26+ messages in thread
From: Rob Herring @ 2013-09-22 21:17 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner,
	Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

On Wed, Sep 18, 2013 at 8:24 AM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> 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().
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Acked-by: Rob Herring <rob.herring@calxeda.com>

> ---
>  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(-)
>
> diff --git a/arch/arm/mach-u300/timer.c b/arch/arm/mach-u300/timer.c
> index b5db207..9a5f9fb 100644
> --- a/arch/arm/mach-u300/timer.c
> +++ b/arch/arm/mach-u300/timer.c
> @@ -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);
> diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
> index 14be2bd..856ad64 100644
> --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
> +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
> @@ -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");
> diff --git a/arch/powerpc/platforms/cell/spider-pic.c b/arch/powerpc/platforms/cell/spider-pic.c
> index 8e29944..1f72f4a 100644
> --- a/arch/powerpc/platforms/cell/spider-pic.c
> +++ b/arch/powerpc/platforms/cell/spider-pic.c
> @@ -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);
> diff --git a/arch/powerpc/sysdev/fsl_gtm.c b/arch/powerpc/sysdev/fsl_gtm.c
> index 0eb871c..dd0d5be 100644
> --- a/arch/powerpc/sysdev/fsl_gtm.c
> +++ b/arch/powerpc/sysdev/fsl_gtm.c
> @@ -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;
>                 }
>
> diff --git a/arch/powerpc/sysdev/mpic_msgr.c b/arch/powerpc/sysdev/mpic_msgr.c
> index c753258..2c9b52a 100644
> --- a/arch/powerpc/sysdev/mpic_msgr.c
> +++ b/arch/powerpc/sysdev/mpic_msgr.c
> @@ -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;
> diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
> index 26438cd..c8224da 100644
> --- a/drivers/crypto/caam/ctrl.c
> +++ b/drivers/crypto/caam/ctrl.c
> @@ -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,
> diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
> index 105ba4d..517a16d 100644
> --- a/drivers/crypto/caam/jr.c
> +++ b/drivers/crypto/caam/jr.c
> @@ -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 */
> diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
> index 8bdde57..e28104b 100644
> --- a/drivers/crypto/omap-sham.c
> +++ b/drivers/crypto/omap-sham.c
> @@ -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;
> diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
> index b2b8aa9..3e5ea2c 100644
> --- a/drivers/i2c/busses/i2c-cpm.c
> +++ b/drivers/i2c/busses/i2c-cpm.c
> @@ -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;
>
> diff --git a/drivers/input/serio/xilinx_ps2.c b/drivers/input/serio/xilinx_ps2.c
> index 4b7662a..36f7b95 100644
> --- a/drivers/input/serio/xilinx_ps2.c
> +++ b/drivers/input/serio/xilinx_ps2.c
> @@ -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;
>
> diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c
> index 9e16014..d087852 100644
> --- a/drivers/net/ethernet/arc/emac_main.c
> +++ b/drivers/net/ethernet/arc/emac_main.c
> @@ -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 */
> diff --git a/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c b/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c
> index 7583a95..10f781d 100644
> --- a/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c
> +++ b/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c
> @@ -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;
>
> diff --git a/drivers/net/ethernet/freescale/fs_enet/mac-fec.c b/drivers/net/ethernet/freescale/fs_enet/mac-fec.c
> index 9ae6cdb..53a0c23 100644
> --- a/drivers/net/ethernet/freescale/fs_enet/mac-fec.c
> +++ b/drivers/net/ethernet/freescale/fs_enet/mac-fec.c
> @@ -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;
>
> diff --git a/drivers/net/ethernet/freescale/fs_enet/mac-scc.c b/drivers/net/ethernet/freescale/fs_enet/mac-scc.c
> index 22a02a7..631f098 100644
> --- a/drivers/net/ethernet/freescale/fs_enet/mac-scc.c
> +++ b/drivers/net/ethernet/freescale/fs_enet/mac-scc.c
> @@ -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;
>
> diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
> index b8f1103..3197d55 100644
> --- a/drivers/spi/spi-fsl-espi.c
> +++ b/drivers/spi/spi-fsl-espi.c
> @@ -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;
> diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
> index 1a535f7..6957f445 100644
> --- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
> +++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
> @@ -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@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 01/10] of/irq: Rework of_irq_count()
  2013-09-18 13:24 ` [PATCH v2 01/10] of/irq: Rework of_irq_count() Thierry Reding
@ 2013-09-22 21:19   ` Rob Herring
  2013-10-15 22:42     ` Grant Likely
  2013-10-15 22:55     ` Grant Likely
  0 siblings, 2 replies; 26+ messages in thread
From: Rob Herring @ 2013-09-22 21:19 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner,
	linux-mips, Russell King, devicetree, Benjamin Herrenschmidt,
	linux-kernel, Ralf Baechle, sparclinux, linuxppc-dev,
	linux-arm-kernel

On Wed, Sep 18, 2013 at 8:24 AM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> 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().
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Acked-by: Rob Herring <rob.herring@calxeda.com>

> ---
>  drivers/of/irq.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> index 1752988..5f44388 100644
> --- a/drivers/of/irq.c
> +++ b/drivers/of/irq.c
> @@ -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@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping()
  2013-09-22 21:14   ` Rob Herring
@ 2013-09-23  8:13     ` Thierry Reding
  2013-10-15 23:01       ` Grant Likely
  0 siblings, 1 reply; 26+ messages in thread
From: Thierry Reding @ 2013-09-23  8:13 UTC (permalink / raw)
  To: Rob Herring, Benjamin Herrenschmidt
  Cc: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner,
	linux-mips, Russell King, devicetree, linux-kernel, Ralf Baechle,
	sparclinux, linuxppc-dev, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 2486 bytes --]

On Sun, Sep 22, 2013 at 04:14:43PM -0500, Rob Herring wrote:
> On Wed, Sep 18, 2013 at 8:24 AM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
> > 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).
> >
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> 
> One comment below, otherwise:
> 
> Acked-by: Rob Herring <rob.herring@calxeda.com>
> 
> > diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
> > index 905a24b..ae71b14 100644
> > --- a/arch/powerpc/kernel/pci-common.c
> > +++ b/arch/powerpc/kernel/pci-common.c
> > @@ -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");
> 
> 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

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table()
  2013-09-22 21:08   ` Rob Herring
@ 2013-09-23  8:36     ` Thierry Reding
  0 siblings, 0 replies; 26+ messages in thread
From: Thierry Reding @ 2013-09-23  8:36 UTC (permalink / raw)
  To: Rob Herring
  Cc: Rob Herring, Grant Likely, Greg Kroah-Hartman, Thomas Gleixner,
	Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1602 bytes --]

On Sun, Sep 22, 2013 at 04:08:26PM -0500, Rob Herring wrote:
> On Wed, Sep 18, 2013 at 8:24 AM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
> > Now that all helpers return precise error codes, this function can
> > propagate these errors to the caller properly.
> >
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> > ---
> > Changes in v2:
> > - return 0 on success or a negative error code on failure
> > - convert callers to new calling convention
> 
> [snip]
> 
> > diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> > index e4f38c0..6d7f824 100644
> > --- a/drivers/of/irq.c
> > +++ b/drivers/of/irq.c
> > @@ -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.

> >   *
> > - * 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.

Yes, you're right.

Thanks,
Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 01/10] of/irq: Rework of_irq_count()
  2013-09-22 21:19   ` Rob Herring
@ 2013-10-15 22:42     ` Grant Likely
  2013-10-15 22:55     ` Grant Likely
  1 sibling, 0 replies; 26+ messages in thread
From: Grant Likely @ 2013-10-15 22:42 UTC (permalink / raw)
  To: Rob Herring, Thierry Reding
  Cc: Rob Herring, Greg Kroah-Hartman, Thomas Gleixner, linux-mips,
	Russell King, devicetree, Benjamin Herrenschmidt, linux-kernel,
	Ralf Baechle, sparclinux, linuxppc-dev, linux-arm-kernel

On Sun, 22 Sep 2013 16:19:27 -0500, Rob Herring <robherring2@gmail.com> wrote:
> On Wed, Sep 18, 2013 at 8:24 AM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
> > 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().
> >
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> 
> Acked-by: Rob Herring <rob.herring@calxeda.com>

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.

> 
> > ---
> >  drivers/of/irq.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> > index 1752988..5f44388 100644
> > --- a/drivers/of/irq.c
> > +++ b/drivers/of/irq.c
> > @@ -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@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 01/10] of/irq: Rework of_irq_count()
  2013-09-22 21:19   ` Rob Herring
  2013-10-15 22:42     ` Grant Likely
@ 2013-10-15 22:55     ` Grant Likely
  1 sibling, 0 replies; 26+ messages in thread
From: Grant Likely @ 2013-10-15 22:55 UTC (permalink / raw)
  To: Rob Herring, Thierry Reding
  Cc: Rob Herring, Greg Kroah-Hartman, Thomas Gleixner, linux-mips,
	Russell King, devicetree, Benjamin Herrenschmidt, linux-kernel,
	Ralf Baechle, sparclinux, linuxppc-dev, linux-arm-kernel

On Sun, 22 Sep 2013 16:19:27 -0500, Rob Herring <robherring2@gmail.com> wrote:
> On Wed, Sep 18, 2013 at 8:24 AM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
> > 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().
> >
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> 
> Acked-by: Rob Herring <rob.herring@calxeda.com>

Applied, thanks.

g.

> 
> > ---
> >  drivers/of/irq.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> > index 1752988..5f44388 100644
> > --- a/drivers/of/irq.c
> > +++ b/drivers/of/irq.c
> > @@ -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@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping()
  2013-09-23  8:13     ` Thierry Reding
@ 2013-10-15 23:01       ` Grant Likely
  0 siblings, 0 replies; 26+ messages in thread
From: Grant Likely @ 2013-10-15 23:01 UTC (permalink / raw)
  To: Thierry Reding, Rob Herring, Benjamin Herrenschmidt
  Cc: Rob Herring, Greg Kroah-Hartman, Thomas Gleixner, linux-mips,
	Russell King, devicetree, linux-kernel, Ralf Baechle, sparclinux,
	linuxppc-dev, linux-arm-kernel

On Mon, 23 Sep 2013 10:13:38 +0200, Thierry Reding <thierry.reding@gmail.com> wrote:
> On Sun, Sep 22, 2013 at 04:14:43PM -0500, Rob Herring wrote:
> > On Wed, Sep 18, 2013 at 8:24 AM, Thierry Reding
> > <thierry.reding@gmail.com> wrote:
> > > 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).
> > >
> > > Signed-off-by: Thierry Reding <treding@nvidia.com>
> > 
> > One comment below, otherwise:
> > 
> > Acked-by: Rob Herring <rob.herring@calxeda.com>
> > 
> > > diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
> > > index 905a24b..ae71b14 100644
> > > --- a/arch/powerpc/kernel/pci-common.c
> > > +++ b/arch/powerpc/kernel/pci-common.c
> > > @@ -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");
> > 
> > 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 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.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time
  2013-09-18 13:24 ` [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time Thierry Reding
@ 2013-10-15 23:24   ` Grant Likely
  2013-10-16  8:20     ` Thierry Reding
  2013-10-24 16:37     ` Grant Likely
  0 siblings, 2 replies; 26+ messages in thread
From: Grant Likely @ 2013-10-15 23:24 UTC (permalink / raw)
  To: Thierry Reding, Rob Herring, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

On Wed, 18 Sep 2013 15:24:50 +0200, Thierry Reding <thierry.reding@gmail.com> wrote:
> 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.

> 
> 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.
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
> 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(-)
> 
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 4f8bef3..8dcf835 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -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);
>  
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index 9b439ac..df6d56e 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -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 */
> diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
> index 05cb4a9..92fc4f6 100644
> --- a/include/linux/of_platform.h
> +++ b/include/linux/of_platform.h
> @@ -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 */
> -- 
> 1.8.4
> 


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time
  2013-10-15 23:24   ` Grant Likely
@ 2013-10-16  8:20     ` Thierry Reding
  2013-10-24 16:37     ` Grant Likely
  1 sibling, 0 replies; 26+ messages in thread
From: Thierry Reding @ 2013-10-16  8:20 UTC (permalink / raw)
  To: Grant Likely
  Cc: Rob Herring, Greg Kroah-Hartman, Thomas Gleixner,
	Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 4329 bytes --]

On Wed, Oct 16, 2013 at 12:24:36AM +0100, Grant Likely wrote:
> On Wed, 18 Sep 2013 15:24:50 +0200, Thierry Reding <thierry.reding@gmail.com> wrote:
> > 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.

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

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time
  2013-10-15 23:24   ` Grant Likely
  2013-10-16  8:20     ` Thierry Reding
@ 2013-10-24 16:37     ` Grant Likely
  2013-10-25  7:35       ` Thierry Reding
  1 sibling, 1 reply; 26+ messages in thread
From: Grant Likely @ 2013-10-24 16:37 UTC (permalink / raw)
  To: Thierry Reding, Rob Herring, Greg Kroah-Hartman, Thomas Gleixner
  Cc: Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

On Wed, 16 Oct 2013 00:24:36 +0100, Grant Likely <grant.likely@linaro.org> wrote:
> On Wed, 18 Sep 2013 15:24:50 +0200, Thierry Reding <thierry.reding@gmail.com> wrote:
> > 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.

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.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time
  2013-10-24 16:37     ` Grant Likely
@ 2013-10-25  7:35       ` Thierry Reding
  0 siblings, 0 replies; 26+ messages in thread
From: Thierry Reding @ 2013-10-25  7:35 UTC (permalink / raw)
  To: Grant Likely
  Cc: Rob Herring, Greg Kroah-Hartman, Thomas Gleixner,
	Benjamin Herrenschmidt, Ralf Baechle, Russell King, devicetree,
	linux-arm-kernel, linux-mips, linuxppc-dev, sparclinux,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 5592 bytes --]

On Thu, Oct 24, 2013 at 05:37:49PM +0100, Grant Likely wrote:
> On Wed, 16 Oct 2013 00:24:36 +0100, Grant Likely <grant.likely@linaro.org> wrote:
> > On Wed, 18 Sep 2013 15:24:50 +0200, Thierry Reding <thierry.reding@gmail.com> wrote:
> > > 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.
> 
> 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.

> 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.

> 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.

> 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.

> 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.

> 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

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2013-10-25  7:35 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-18 13:24 [PATCH v2 00/10] of/irq: Defer interrupt reference resolution Thierry Reding
2013-09-18 13:24 ` [PATCH v2 01/10] of/irq: Rework of_irq_count() Thierry Reding
2013-09-22 21:19   ` Rob Herring
2013-10-15 22:42     ` Grant Likely
2013-10-15 22:55     ` Grant Likely
2013-09-18 13:24 ` [PATCH v2 02/10] of/irq: Use irq_of_parse_and_map() Thierry Reding
2013-09-22 21:17   ` Rob Herring
2013-09-18 13:24 ` [PATCH v2 03/10] irqdomain: Introduce __irq_create_mapping() Thierry Reding
2013-09-18 13:24 ` [PATCH v2 04/10] irqdomain: Return errors from irq_create_of_mapping() Thierry Reding
2013-09-18 14:23   ` Ralf Baechle
2013-09-22 21:14   ` Rob Herring
2013-09-23  8:13     ` Thierry Reding
2013-10-15 23:01       ` Grant Likely
2013-09-18 13:24 ` [PATCH v2 05/10] of/irq: Introduce __irq_of_parse_and_map() Thierry Reding
2013-09-18 13:24 ` [PATCH v2 06/10] of/irq: Return errors from of_irq_to_resource() Thierry Reding
2013-09-18 13:24 ` [PATCH v2 07/10] of/irq: Propagate errors in of_irq_to_resource_table() Thierry Reding
2013-09-18 14:23   ` Ralf Baechle
2013-09-22 21:08   ` Rob Herring
2013-09-23  8:36     ` Thierry Reding
2013-09-18 13:24 ` [PATCH v2 08/10] of/platform: Resolve interrupt references at probe time Thierry Reding
2013-10-15 23:24   ` Grant Likely
2013-10-16  8:20     ` Thierry Reding
2013-10-24 16:37     ` Grant Likely
2013-10-25  7:35       ` Thierry Reding
2013-09-18 13:24 ` [PATCH v2 09/10] of/i2c: " Thierry Reding
2013-09-18 13:24 ` [PATCH v2 10/10] gpio: tegra: Use module_platform_driver() Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).