mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: barebox@lists.infradead.org
Subject: [PATCH v2 1/6] base: Introduce deferred probing
Date: Wed, 15 Apr 2015 00:53:15 +0200	[thread overview]
Message-ID: <1429052000-20647-2-git-send-email-sebastian.hesselbarth@gmail.com> (raw)
In-Reply-To: <1429052000-20647-1-git-send-email-sebastian.hesselbarth@gmail.com>

As expected, we would need deferred probing sooner or later. This is
a first approach to allow devices to return -EPROBE_DEFER and get
sorted into a list of deferred devices that will be re-probed later.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Changelog:
v1->v2:
- Rework deferred probing to loop until no previously deferred device
  probing succeeds. (Suggested by Sascha Hauer)
- Print an error message for devices stuck in deferred list.
- Add a comment how deferred probing and re-assignment to deferred
  list works.

Cc: barebox@lists.infradead.org
---
 drivers/base/driver.c       | 56 ++++++++++++++++++++++++++++++++++++++++++---
 include/asm-generic/errno.h |  1 +
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 590c97c96424..6112b4953ba6 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -29,6 +29,7 @@
 #include <console.h>
 #include <linux/ctype.h>
 #include <errno.h>
+#include <init.h>
 #include <fs.h>
 #include <of.h>
 #include <linux/list.h>
@@ -43,6 +44,7 @@ LIST_HEAD(driver_list);
 EXPORT_SYMBOL(driver_list);
 
 static LIST_HEAD(active);
+static LIST_HEAD(deferred);
 
 struct device_d *get_device_by_name(const char *name)
 {
@@ -88,13 +90,20 @@ int device_probe(struct device_d *dev)
 	list_add(&dev->active, &active);
 
 	ret = dev->bus->probe(dev);
-	if (ret) {
+	if (ret == 0)
+		return 0;
+
+	if (ret == -EPROBE_DEFER) {
 		list_del(&dev->active);
-		dev_err(dev, "probe failed: %s\n", strerror(-ret));
+		list_add(&dev->active, &deferred);
+		dev_dbg(dev, "probe deferred\n");
 		return ret;
 	}
 
-	return 0;
+	list_del(&dev->active);
+	dev_err(dev, "probe failed: %s\n", strerror(-ret));
+
+	return ret;
 }
 
 int device_detect(struct device_d *dev)
@@ -213,6 +222,47 @@ int unregister_device(struct device_d *old_dev)
 }
 EXPORT_SYMBOL(unregister_device);
 
+/*
+ * Loop over list of deferred devices as long as at least one
+ * device is successfully probed. Devices that again request
+ * deferral are re-added to deferred list in device_probe().
+ * For devices finally left in deferred list -EPROBE_DEFER
+ * becomes a fatal error.
+ */
+static int device_probe_deferred(void)
+{
+	struct device_d *dev, *tmp;
+	struct driver_d *drv;
+	bool success;
+
+	do {
+		success = false;
+
+		if (list_empty(&deferred))
+			break;
+
+		list_for_each_entry_safe(dev, tmp, &deferred, active) {
+			list_del(&dev->active);
+			dev_dbg(dev, "re-probe device\n");
+			bus_for_each_driver(dev->bus, drv) {
+				if (match(drv, dev))
+					continue;
+				success = true;
+				break;
+			}
+		}
+	} while (success);
+
+	if (list_empty(&deferred))
+		return 0;
+
+	list_for_each_entry(dev, &deferred, active)
+		dev_err(dev, "probe permanently deferred\n");
+
+	return 0;
+}
+late_initcall(device_probe_deferred);
+
 struct driver_d *get_driver_by_name(const char *name)
 {
 	struct driver_d *drv;
diff --git a/include/asm-generic/errno.h b/include/asm-generic/errno.h
index bbf493c373ae..6072f7b605bb 100644
--- a/include/asm-generic/errno.h
+++ b/include/asm-generic/errno.h
@@ -132,6 +132,7 @@
 #define ERESTARTNOINTR	513
 #define ERESTARTNOHAND	514	/* restart if no handler.. */
 #define ENOIOCTLCMD	515	/* No ioctl command */
+#define EPROBE_DEFER	517	/* Driver requests probe retry */
 
 #define ENOTSUPP	524	/* Operation is not supported */
 
-- 
2.1.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2015-04-14 22:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-14 22:53 [PATCH v2 0/6] " Sebastian Hesselbarth
2015-04-14 22:53 ` Sebastian Hesselbarth [this message]
2015-04-14 22:53 ` [PATCH v2 2/6] gpio: Return -EPROBE_DEFER on gpio_get_num() Sebastian Hesselbarth
2015-04-14 22:53 ` [PATCH v2 3/6] OF: gpio: Silence error message on -EPROBE_DEFER Sebastian Hesselbarth
2015-04-14 22:53 ` [PATCH v2 4/6] led: gpio: Properly deal with deferred probing Sebastian Hesselbarth
2015-04-14 22:53 ` [PATCH v2 5/6] led: gpio: Free GPIOs on unregister() Sebastian Hesselbarth
2015-04-14 22:53 ` [PATCH v2 6/6] gpio: orion: Convert to platform_driver Sebastian Hesselbarth
2015-04-17  5:24 ` [PATCH v2 0/6] Introduce deferred probing Sascha Hauer

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=1429052000-20647-2-git-send-email-sebastian.hesselbarth@gmail.com \
    --to=sebastian.hesselbarth@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox