All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: Grant Likely <grant.likely@linaro.org>,
	Rob Herring <rob.herring@calxeda.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH] of/platform: Fix no irq domain found errors when populating interrupts
Date: Fri, 22 Nov 2013 16:43:35 -0800	[thread overview]
Message-ID: <20131123004334.GJ10023@atomide.com> (raw)

Currently we get the following kind of errors if we try to use
interrupt phandles to irqchips that have not yet initialized:

irq: no irq domain found for /ocp/pinmux@48002030 !
WARNING: CPU: 0 PID: 1 at drivers/of/platform.c:171 of_device_alloc+0x144/0x184()
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.12.0-00038-g42a9708 #1012
(show_stack+0x14/0x1c)
(dump_stack+0x6c/0xa0)
(warn_slowpath_common+0x64/0x84)
(warn_slowpath_null+0x1c/0x24)
(of_device_alloc+0x144/0x184)
(of_platform_device_create_pdata+0x44/0x9c)
(of_platform_bus_create+0xd0/0x170)
(of_platform_bus_create+0x12c/0x170)
(of_platform_populate+0x60/0x98)
...

This is because we're wrongly trying to populate resources that are not
yet available. It's perfectly valid to create irqchips dynamically,
so let's fix up the issue by populating the interrupt resources based
on a notifier call instead.

Signed-off-by: Tony Lindgren <tony@atomide.com>

---

Rob & Grant, care to merge this for the -rc if this looks OK to you?

These happen for example when using interrupts-extended for omap
wake-up interrupts where the irq domain is created by pinctrl-single.c
at module_init time.

--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -130,6 +130,56 @@ void of_device_make_bus_id(struct device *dev)
 	dev_set_name(dev, "%s.%d", node->name, magic - 1);
 }
 
+/*
+ * The device interrupts are not necessarily available for all
+ * irqdomains initially so we need to populate them using a
+ * notifier.
+ */
+static int of_device_resource_notify(struct notifier_block *nb,
+				     unsigned long event, void *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct device_node *np = pdev->dev.of_node;
+	struct resource *res = pdev->resource;
+	struct resource *irqr = NULL;
+	int num_irq, i, found = 0;
+
+	if (event != BUS_NOTIFY_BIND_DRIVER)
+		return 0;
+
+	if (!np)
+		goto out;
+
+	num_irq = of_irq_count(np);
+	if (!num_irq)
+		goto out;
+
+	for (i = 0; i < pdev->num_resources; i++, res++) {
+		if (res->flags != IORESOURCE_IRQ ||
+		    res->start != -EPROBE_DEFER ||
+		    res->end != -EPROBE_DEFER)
+			continue;
+
+		if (!irqr)
+			irqr = res;
+		found++;
+	}
+
+	if (!found)
+		goto out;
+
+	if (found != num_irq) {
+		dev_WARN(dev, "error populating irq resources: %i != %i\n",
+			 found, num_irq);
+		goto out;
+	}
+
+	WARN_ON(of_irq_to_resource_table(np, irqr, num_irq) != num_irq);
+
+out:
+	return NOTIFY_DONE;
+}
+
 /**
  * of_device_alloc - Allocate and initialize an of_device
  * @np: device node to assign to device
@@ -168,7 +218,13 @@ struct platform_device *of_device_alloc(struct device_node *np,
 			rc = of_address_to_resource(np, i, res);
 			WARN_ON(rc);
 		}
-		WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq);
+
+		/* See of_device_resource_notify for populating interrupts */
+		for (i = 0; i < num_irq; i++, res++) {
+			res->flags = IORESOURCE_IRQ;
+			res->start = -EPROBE_DEFER;
+			res->end = -EPROBE_DEFER;
+		}
 	}
 
 	dev->dev.of_node = of_node_get(np);
@@ -447,6 +503,8 @@ int of_platform_bus_probe(struct device_node *root,
 }
 EXPORT_SYMBOL(of_platform_bus_probe);
 
+static struct notifier_block resource_nb;
+
 /**
  * of_platform_populate() - Populate platform_devices from device tree data
  * @root: parent of the first level to probe or NULL for the root of the tree
@@ -478,6 +536,11 @@ int of_platform_populate(struct device_node *root,
 	if (!root)
 		return -EINVAL;
 
+	if (!resource_nb.notifier_call) {
+		resource_nb.notifier_call = of_device_resource_notify,
+			bus_register_notifier(&platform_bus_type, &resource_nb);
+	}
+
 	for_each_child_of_node(root, child) {
 		rc = of_platform_bus_create(child, matches, lookup, parent, true);
 		if (rc)

WARNING: multiple messages have this Message-ID (diff)
From: Tony Lindgren <tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
To: Grant Likely
	<grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: [PATCH] of/platform: Fix no irq domain found errors when populating interrupts
Date: Fri, 22 Nov 2013 16:43:35 -0800	[thread overview]
Message-ID: <20131123004334.GJ10023@atomide.com> (raw)

Currently we get the following kind of errors if we try to use
interrupt phandles to irqchips that have not yet initialized:

irq: no irq domain found for /ocp/pinmux@48002030 !
WARNING: CPU: 0 PID: 1 at drivers/of/platform.c:171 of_device_alloc+0x144/0x184()
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.12.0-00038-g42a9708 #1012
(show_stack+0x14/0x1c)
(dump_stack+0x6c/0xa0)
(warn_slowpath_common+0x64/0x84)
(warn_slowpath_null+0x1c/0x24)
(of_device_alloc+0x144/0x184)
(of_platform_device_create_pdata+0x44/0x9c)
(of_platform_bus_create+0xd0/0x170)
(of_platform_bus_create+0x12c/0x170)
(of_platform_populate+0x60/0x98)
...

This is because we're wrongly trying to populate resources that are not
yet available. It's perfectly valid to create irqchips dynamically,
so let's fix up the issue by populating the interrupt resources based
on a notifier call instead.

Signed-off-by: Tony Lindgren <tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>

---

Rob & Grant, care to merge this for the -rc if this looks OK to you?

These happen for example when using interrupts-extended for omap
wake-up interrupts where the irq domain is created by pinctrl-single.c
at module_init time.

--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -130,6 +130,56 @@ void of_device_make_bus_id(struct device *dev)
 	dev_set_name(dev, "%s.%d", node->name, magic - 1);
 }
 
+/*
+ * The device interrupts are not necessarily available for all
+ * irqdomains initially so we need to populate them using a
+ * notifier.
+ */
+static int of_device_resource_notify(struct notifier_block *nb,
+				     unsigned long event, void *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct device_node *np = pdev->dev.of_node;
+	struct resource *res = pdev->resource;
+	struct resource *irqr = NULL;
+	int num_irq, i, found = 0;
+
+	if (event != BUS_NOTIFY_BIND_DRIVER)
+		return 0;
+
+	if (!np)
+		goto out;
+
+	num_irq = of_irq_count(np);
+	if (!num_irq)
+		goto out;
+
+	for (i = 0; i < pdev->num_resources; i++, res++) {
+		if (res->flags != IORESOURCE_IRQ ||
+		    res->start != -EPROBE_DEFER ||
+		    res->end != -EPROBE_DEFER)
+			continue;
+
+		if (!irqr)
+			irqr = res;
+		found++;
+	}
+
+	if (!found)
+		goto out;
+
+	if (found != num_irq) {
+		dev_WARN(dev, "error populating irq resources: %i != %i\n",
+			 found, num_irq);
+		goto out;
+	}
+
+	WARN_ON(of_irq_to_resource_table(np, irqr, num_irq) != num_irq);
+
+out:
+	return NOTIFY_DONE;
+}
+
 /**
  * of_device_alloc - Allocate and initialize an of_device
  * @np: device node to assign to device
@@ -168,7 +218,13 @@ struct platform_device *of_device_alloc(struct device_node *np,
 			rc = of_address_to_resource(np, i, res);
 			WARN_ON(rc);
 		}
-		WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq);
+
+		/* See of_device_resource_notify for populating interrupts */
+		for (i = 0; i < num_irq; i++, res++) {
+			res->flags = IORESOURCE_IRQ;
+			res->start = -EPROBE_DEFER;
+			res->end = -EPROBE_DEFER;
+		}
 	}
 
 	dev->dev.of_node = of_node_get(np);
@@ -447,6 +503,8 @@ int of_platform_bus_probe(struct device_node *root,
 }
 EXPORT_SYMBOL(of_platform_bus_probe);
 
+static struct notifier_block resource_nb;
+
 /**
  * of_platform_populate() - Populate platform_devices from device tree data
  * @root: parent of the first level to probe or NULL for the root of the tree
@@ -478,6 +536,11 @@ int of_platform_populate(struct device_node *root,
 	if (!root)
 		return -EINVAL;
 
+	if (!resource_nb.notifier_call) {
+		resource_nb.notifier_call = of_device_resource_notify,
+			bus_register_notifier(&platform_bus_type, &resource_nb);
+	}
+
 	for_each_child_of_node(root, child) {
 		rc = of_platform_bus_create(child, matches, lookup, parent, true);
 		if (rc)
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: tony@atomide.com (Tony Lindgren)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] of/platform: Fix no irq domain found errors when populating interrupts
Date: Fri, 22 Nov 2013 16:43:35 -0800	[thread overview]
Message-ID: <20131123004334.GJ10023@atomide.com> (raw)

Currently we get the following kind of errors if we try to use
interrupt phandles to irqchips that have not yet initialized:

irq: no irq domain found for /ocp/pinmux at 48002030 !
WARNING: CPU: 0 PID: 1 at drivers/of/platform.c:171 of_device_alloc+0x144/0x184()
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.12.0-00038-g42a9708 #1012
(show_stack+0x14/0x1c)
(dump_stack+0x6c/0xa0)
(warn_slowpath_common+0x64/0x84)
(warn_slowpath_null+0x1c/0x24)
(of_device_alloc+0x144/0x184)
(of_platform_device_create_pdata+0x44/0x9c)
(of_platform_bus_create+0xd0/0x170)
(of_platform_bus_create+0x12c/0x170)
(of_platform_populate+0x60/0x98)
...

This is because we're wrongly trying to populate resources that are not
yet available. It's perfectly valid to create irqchips dynamically,
so let's fix up the issue by populating the interrupt resources based
on a notifier call instead.

Signed-off-by: Tony Lindgren <tony@atomide.com>

---

Rob & Grant, care to merge this for the -rc if this looks OK to you?

These happen for example when using interrupts-extended for omap
wake-up interrupts where the irq domain is created by pinctrl-single.c
at module_init time.

--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -130,6 +130,56 @@ void of_device_make_bus_id(struct device *dev)
 	dev_set_name(dev, "%s.%d", node->name, magic - 1);
 }
 
+/*
+ * The device interrupts are not necessarily available for all
+ * irqdomains initially so we need to populate them using a
+ * notifier.
+ */
+static int of_device_resource_notify(struct notifier_block *nb,
+				     unsigned long event, void *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct device_node *np = pdev->dev.of_node;
+	struct resource *res = pdev->resource;
+	struct resource *irqr = NULL;
+	int num_irq, i, found = 0;
+
+	if (event != BUS_NOTIFY_BIND_DRIVER)
+		return 0;
+
+	if (!np)
+		goto out;
+
+	num_irq = of_irq_count(np);
+	if (!num_irq)
+		goto out;
+
+	for (i = 0; i < pdev->num_resources; i++, res++) {
+		if (res->flags != IORESOURCE_IRQ ||
+		    res->start != -EPROBE_DEFER ||
+		    res->end != -EPROBE_DEFER)
+			continue;
+
+		if (!irqr)
+			irqr = res;
+		found++;
+	}
+
+	if (!found)
+		goto out;
+
+	if (found != num_irq) {
+		dev_WARN(dev, "error populating irq resources: %i != %i\n",
+			 found, num_irq);
+		goto out;
+	}
+
+	WARN_ON(of_irq_to_resource_table(np, irqr, num_irq) != num_irq);
+
+out:
+	return NOTIFY_DONE;
+}
+
 /**
  * of_device_alloc - Allocate and initialize an of_device
  * @np: device node to assign to device
@@ -168,7 +218,13 @@ struct platform_device *of_device_alloc(struct device_node *np,
 			rc = of_address_to_resource(np, i, res);
 			WARN_ON(rc);
 		}
-		WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq);
+
+		/* See of_device_resource_notify for populating interrupts */
+		for (i = 0; i < num_irq; i++, res++) {
+			res->flags = IORESOURCE_IRQ;
+			res->start = -EPROBE_DEFER;
+			res->end = -EPROBE_DEFER;
+		}
 	}
 
 	dev->dev.of_node = of_node_get(np);
@@ -447,6 +503,8 @@ int of_platform_bus_probe(struct device_node *root,
 }
 EXPORT_SYMBOL(of_platform_bus_probe);
 
+static struct notifier_block resource_nb;
+
 /**
  * of_platform_populate() - Populate platform_devices from device tree data
  * @root: parent of the first level to probe or NULL for the root of the tree
@@ -478,6 +536,11 @@ int of_platform_populate(struct device_node *root,
 	if (!root)
 		return -EINVAL;
 
+	if (!resource_nb.notifier_call) {
+		resource_nb.notifier_call = of_device_resource_notify,
+			bus_register_notifier(&platform_bus_type, &resource_nb);
+	}
+
 	for_each_child_of_node(root, child) {
 		rc = of_platform_bus_create(child, matches, lookup, parent, true);
 		if (rc)

             reply	other threads:[~2013-11-23  0:43 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-23  0:43 Tony Lindgren [this message]
2013-11-23  0:43 ` [PATCH] of/platform: Fix no irq domain found errors when populating interrupts Tony Lindgren
2013-11-23  0:43 ` Tony Lindgren
2013-11-23  0:55 ` Russell King - ARM Linux
2013-11-23  0:55   ` Russell King - ARM Linux
2013-11-23  0:55   ` Russell King - ARM Linux
2013-11-23  1:08   ` Tony Lindgren
2013-11-23  1:08     ` Tony Lindgren
2013-11-23  1:15     ` Tony Lindgren
2013-11-23  1:15       ` Tony Lindgren
2013-11-23  1:50       ` Tony Lindgren
2013-11-23  1:50         ` Tony Lindgren
2013-11-23  1:50         ` Tony Lindgren
2013-11-23 15:42         ` Rob Herring
2013-11-23 15:42           ` Rob Herring
2013-11-23 15:42           ` Rob Herring
2013-11-23 16:32           ` Tony Lindgren
2013-11-23 16:32             ` Tony Lindgren
2013-11-23 16:32             ` Tony Lindgren
2013-11-25  9:34             ` Thierry Reding
2013-11-25  9:34               ` Thierry Reding
2013-11-25  9:34               ` Thierry Reding
2013-11-25 19:46               ` Tony Lindgren
2013-11-25 19:46                 ` Tony Lindgren
2013-11-25 19:46                 ` Tony Lindgren
2013-11-24 21:27         ` Grant Likely
2013-11-24 21:27           ` Grant Likely
2013-12-10  3:39           ` Paul Walmsley
2013-12-10  3:39             ` Paul Walmsley
2013-12-30 22:10             ` Paul Walmsley
2013-12-30 22:10               ` Paul Walmsley
2013-12-30 22:10               ` Paul Walmsley
2013-12-31 16:33               ` Rob Herring
2013-12-31 16:33                 ` Rob Herring
2013-12-31 16:33                 ` Rob Herring
2014-01-06 23:41                 ` Paul Walmsley
2014-01-06 23:41                   ` Paul Walmsley
2014-01-06 23:41                   ` Paul Walmsley
2014-01-08  1:19                   ` Tony Lindgren
2014-01-08  1:19                     ` Tony Lindgren
2014-01-08  1:19                     ` Tony Lindgren
2014-01-08 12:51                     ` [PATCH] driver-core: platform: Resolve DT interrupt references late Thierry Reding
2014-01-08 12:51                       ` Thierry Reding
2014-01-08 13:41                       ` Arnd Bergmann
2014-01-08 13:41                         ` Arnd Bergmann
2014-01-08 13:41                         ` Arnd Bergmann
2014-01-08 14:55                         ` Thierry Reding
2014-01-08 14:55                           ` Thierry Reding
2014-01-08 15:11                           ` Arnd Bergmann
2014-01-08 15:11                             ` Arnd Bergmann
2014-01-08 15:58                             ` Thierry Reding
2014-01-08 15:58                               ` Thierry Reding
2014-01-08 16:25                               ` Arnd Bergmann
2014-01-08 16:25                                 ` Arnd Bergmann
2014-01-08 16:25                                 ` Arnd Bergmann
2014-01-08 19:59                                 ` Thierry Reding
2014-01-08 19:59                                   ` Thierry Reding
2014-01-08 20:09                                   ` Arnd Bergmann
2014-01-08 20:09                                     ` Arnd Bergmann
2014-01-08 20:09                                     ` Arnd Bergmann
2014-01-08 20:24                                     ` Thierry Reding
2014-01-08 20:24                                       ` Thierry Reding
2014-01-08 21:01                                       ` Arnd Bergmann
2014-01-08 21:01                                         ` Arnd Bergmann
2014-01-08 16:40                       ` Tony Lindgren
2014-01-08 16:40                         ` Tony Lindgren
2014-01-08 16:40                         ` Tony Lindgren
2014-01-08 19:28                         ` Thierry Reding
2014-01-08 19:28                           ` Thierry Reding
2014-01-08 19:28                           ` Thierry Reding
2014-01-08 21:43                           ` Tony Lindgren
2014-01-08 21:43                             ` Tony Lindgren
2013-11-23  1:07 ` [PATCH] of/platform: Fix no irq domain found errors when populating interrupts Tony Lindgren
2013-11-23  1:07   ` Tony Lindgren
2013-11-23  1:07   ` Tony Lindgren
2013-11-24 21:36 ` Grant Likely
2013-11-24 21:36   ` Grant Likely
2013-11-24 21:36   ` Grant Likely
2013-11-25  9:25   ` Thierry Reding
2013-11-25  9:25     ` Thierry Reding
2013-11-25  9:25     ` Thierry Reding
     [not found]     ` < 20131125094954.GF22043@ulmo.nvidia.com>
2013-11-25  9:49     ` Thierry Reding
2013-11-25  9:49       ` Thierry Reding
2013-11-25  9:49       ` Thierry Reding
2013-11-25 19:50       ` Tony Lindgren
2013-11-25 19:50         ` Tony Lindgren
2013-11-27 15:56       ` Grant Likely
2013-11-27 15:56         ` Grant Likely
2013-11-28 15:46         ` Thierry Reding
2013-11-28 15:46           ` Thierry Reding
2013-11-28 15:46           ` Thierry Reding
2013-12-11 13:45           ` Grant Likely
2013-12-11 13:45             ` Grant Likely
2013-12-11 15:12             ` Thierry Reding
2013-12-11 15:12               ` Thierry Reding
2013-12-11 15:12               ` Thierry Reding
2013-12-11 16:43               ` Tony Lindgren
2013-12-11 16:43                 ` Tony Lindgren
2013-11-27 15:54     ` Grant Likely
2013-11-27 15:54       ` Grant Likely
2013-11-27 15:54       ` Grant Likely
2013-11-27 21:53   ` Tony Lindgren
2013-11-27 21:53     ` Tony Lindgren
2013-11-27 21:53     ` Tony Lindgren
2014-04-10 21:38 Tony Lindgren
2014-04-11  0:29 ` Rob Herring
2014-04-11 18:43   ` Thierry Reding
2014-04-18 20:55     ` Tony Lindgren
2014-04-11  9:20 ` Russell King - ARM Linux
2014-04-11 18:36   ` Thierry Reding
2014-04-18 21:37     ` Tony Lindgren
2014-04-18 23:18       ` Russell King - ARM Linux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131123004334.GJ10023@atomide.com \
    --to=tony@atomide.com \
    --cc=devicetree@vger.kernel.org \
    --cc=grant.likely@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob.herring@calxeda.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.