From: Tomeu Vizoso <tomeu.vizoso@collabora.com> To: linux-arm-kernel@lists.infradead.org Cc: "Tomeu Vizoso" <tomeu.vizoso@collabora.com>, "Alexander Holler" <holler@ahsoftware.de>, "Alexandre Courbot" <gnurou@gmail.com>, "Andrzej Hajda" <a.hajda@samsung.com>, "Arnd Bergmann" <arnd@arndb.de>, "Dmitry Torokhov" <dmitry.torokhov@gmail.com>, "Grant Likely" <grant.likely@linaro.org>, "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>, "Ian Campbell" <ijc+devicetree@hellion.org.uk>, "Javier Martinez Canillas" <javier.martinez@collabora.co.uk>, "Krzysztof Kozlowski" <k.kozlowski@samsung.com>, "Kumar Gala" <galak@codeaurora.org>, "Len Brown" <lenb@kernel.org>, "Linus Walleij" <linus.walleij@linaro.org>, linux-kernel@vger.kernel.org, "Lv Zheng" <lv.zheng@intel.com>, "Mark Brown" <broonie@kernel.org>, "Mark Rutland" <mark.rutland@arm.com>, "Pawel Moll" <pawel.moll@arm.com>, "Rafael J. Wysocki" <rjw@rjwysocki.net>, "Robert Moore" <robert.moore@intel.com>, "Rob Herring" <robh+dt@kernel.org>, "Russell King" <linux@arm.linux.org.uk>, "Stephen Warren" <swarren@wwwdotorg.org>, "Terje Bergström" <tbergstrom@nvidia.com>, "Thierry Reding" <thierry.reding@gmail.com> Subject: [PATCH 13/13] driver-core: probe dependencies before probing Date: Wed, 17 Jun 2015 15:42:23 +0200 [thread overview] Message-ID: <1434548543-22949-14-git-send-email-tomeu.vizoso@collabora.com> (raw) In-Reply-To: <1434548543-22949-1-git-send-email-tomeu.vizoso@collabora.com> Before actually probing a device, find out what dependencies it has and do our best to ensure that they are available at this point. This is accomplished by finding out what platform devices need to be probed so the dependencies are available. If any dependencies are still unavailable after that (most probably a missing driver or an error in the HW description from the firmware), we print a nice error message so that people don't have to add a zillion of printks to find out why a device asked for its probe to be deferred. Dependencies are discovered with the help of the subsystems that already implement the firmware bindings that specify the naming scheme of properties that point to other nodes, via class.get_deps(). Currently the dependencies list is discarded but it could be stored for later usage. Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> --- drivers/base/dd.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 18438aa..8a64a29 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -25,6 +25,9 @@ #include <linux/async.h> #include <linux/pm_runtime.h> #include <linux/pinctrl/devinfo.h> +#include <linux/property.h> +#include <linux/slab.h> +#include <linux/platform_device.h> #include "base.h" #include "power/power.h" @@ -54,6 +57,121 @@ static LIST_HEAD(deferred_probe_active_list); static struct workqueue_struct *deferred_wq; static atomic_t deferred_trigger_count = ATOMIC_INIT(0); +static bool device_is_bound(struct device *dev) +{ + return klist_node_attached(&dev->p->knode_driver); +} + +static int fwnode_match(struct device *dev, void *data) +{ + return dev->fwnode == data; +} + +static bool fwnode_is_bound(struct fwnode_handle *fwnode) +{ + struct device *dev; + + dev = bus_find_device(&platform_bus_type, NULL, fwnode, fwnode_match); + + /* Check whether device is bound or is being probed right now */ + return dev ? dev->driver : false; +} + +static struct fwnode_handle *get_enclosing_platform_dev( + struct fwnode_handle *fwnode) +{ + struct fwnode_handle *iter, *node = NULL; + + for (iter = fwnode; + iter && fwnode_get_parent(iter); + iter = fwnode_get_parent(iter)) { + struct fwnode_handle *parent = fwnode_get_parent(iter); + + /* Only nodes with the compatible property can be probed */ + if (fwnode_property_present(iter, "compatible")) + node = iter; + + /* Stop just below root or if the parent is bound already */ + if (!fwnode_get_parent(parent) || + fwnode_is_bound(parent)) + break; + } + + return node; +} + +static bool check_dependency(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *target; + struct device *dev; + + if (!fwnode) + return true; + + target = get_enclosing_platform_dev(fwnode); + if (!target) + return true; + + dev = bus_find_device(&platform_bus_type, NULL, target, fwnode_match); + if (!dev) { + pr_debug("Couldn't find device for %s\n", + fwnode_get_name(fwnode)); + return false; + } + + /* + * Device is bound or is being probed right now. If we have bad luck + * and the dependency isn't ready when it's needed, deferred probe + * will save us. + */ + if (dev->driver) + return true; + + bus_probe_device(dev); + + /* If the dependency hasn't finished probing, we'll want a warning */ + return device_is_bound(dev); +} + +static void check_dependencies_per_class(struct class *class, void *data) +{ + struct fwnode_handle *fwnode = data; + struct list_head *deps; + struct fwnode_dependency *dep, *tmp; + + if (!class->get_dependencies) + return; + + deps = class->get_dependencies(fwnode); + if (!deps) + return; + + list_for_each_entry_safe(dep, tmp, deps, dependency) { + if (!check_dependency(dep->fwnode)) + pr_debug("Dependency '%s' not available\n", + fwnode_get_name(dep->fwnode)); + + list_del(&dep->dependency); + kfree(dep); + } + + kfree(deps); +} + +static void check_dependencies(struct device *dev) +{ + if (dev->parent && !check_dependency(dev->parent->fwnode)) + pr_debug("Parent '%s' of device '%s' not available\n", + dev_name(dev->parent), dev_name(dev)); + + if (!dev->fwnode) { + pr_debug("Device '%s' doesn't have a fwnode\n", dev_name(dev)); + return; + } + + for_each_class(check_dependencies_per_class, dev->fwnode); +} + /* * deferred_probe_work_func() - Retry probing devices in the active list. */ @@ -413,6 +531,8 @@ int driver_probe_device(struct device_driver *drv, struct device *dev) return 0; } + check_dependencies(dev); + pr_debug("bus: '%s': %s: matched device %s with driver %s\n", drv->bus->name, __func__, dev_name(dev), drv->name); -- 2.4.1
WARNING: multiple messages have this Message-ID (diff)
From: tomeu.vizoso@collabora.com (Tomeu Vizoso) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 13/13] driver-core: probe dependencies before probing Date: Wed, 17 Jun 2015 15:42:23 +0200 [thread overview] Message-ID: <1434548543-22949-14-git-send-email-tomeu.vizoso@collabora.com> (raw) In-Reply-To: <1434548543-22949-1-git-send-email-tomeu.vizoso@collabora.com> Before actually probing a device, find out what dependencies it has and do our best to ensure that they are available at this point. This is accomplished by finding out what platform devices need to be probed so the dependencies are available. If any dependencies are still unavailable after that (most probably a missing driver or an error in the HW description from the firmware), we print a nice error message so that people don't have to add a zillion of printks to find out why a device asked for its probe to be deferred. Dependencies are discovered with the help of the subsystems that already implement the firmware bindings that specify the naming scheme of properties that point to other nodes, via class.get_deps(). Currently the dependencies list is discarded but it could be stored for later usage. Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> --- drivers/base/dd.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 18438aa..8a64a29 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -25,6 +25,9 @@ #include <linux/async.h> #include <linux/pm_runtime.h> #include <linux/pinctrl/devinfo.h> +#include <linux/property.h> +#include <linux/slab.h> +#include <linux/platform_device.h> #include "base.h" #include "power/power.h" @@ -54,6 +57,121 @@ static LIST_HEAD(deferred_probe_active_list); static struct workqueue_struct *deferred_wq; static atomic_t deferred_trigger_count = ATOMIC_INIT(0); +static bool device_is_bound(struct device *dev) +{ + return klist_node_attached(&dev->p->knode_driver); +} + +static int fwnode_match(struct device *dev, void *data) +{ + return dev->fwnode == data; +} + +static bool fwnode_is_bound(struct fwnode_handle *fwnode) +{ + struct device *dev; + + dev = bus_find_device(&platform_bus_type, NULL, fwnode, fwnode_match); + + /* Check whether device is bound or is being probed right now */ + return dev ? dev->driver : false; +} + +static struct fwnode_handle *get_enclosing_platform_dev( + struct fwnode_handle *fwnode) +{ + struct fwnode_handle *iter, *node = NULL; + + for (iter = fwnode; + iter && fwnode_get_parent(iter); + iter = fwnode_get_parent(iter)) { + struct fwnode_handle *parent = fwnode_get_parent(iter); + + /* Only nodes with the compatible property can be probed */ + if (fwnode_property_present(iter, "compatible")) + node = iter; + + /* Stop just below root or if the parent is bound already */ + if (!fwnode_get_parent(parent) || + fwnode_is_bound(parent)) + break; + } + + return node; +} + +static bool check_dependency(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *target; + struct device *dev; + + if (!fwnode) + return true; + + target = get_enclosing_platform_dev(fwnode); + if (!target) + return true; + + dev = bus_find_device(&platform_bus_type, NULL, target, fwnode_match); + if (!dev) { + pr_debug("Couldn't find device for %s\n", + fwnode_get_name(fwnode)); + return false; + } + + /* + * Device is bound or is being probed right now. If we have bad luck + * and the dependency isn't ready when it's needed, deferred probe + * will save us. + */ + if (dev->driver) + return true; + + bus_probe_device(dev); + + /* If the dependency hasn't finished probing, we'll want a warning */ + return device_is_bound(dev); +} + +static void check_dependencies_per_class(struct class *class, void *data) +{ + struct fwnode_handle *fwnode = data; + struct list_head *deps; + struct fwnode_dependency *dep, *tmp; + + if (!class->get_dependencies) + return; + + deps = class->get_dependencies(fwnode); + if (!deps) + return; + + list_for_each_entry_safe(dep, tmp, deps, dependency) { + if (!check_dependency(dep->fwnode)) + pr_debug("Dependency '%s' not available\n", + fwnode_get_name(dep->fwnode)); + + list_del(&dep->dependency); + kfree(dep); + } + + kfree(deps); +} + +static void check_dependencies(struct device *dev) +{ + if (dev->parent && !check_dependency(dev->parent->fwnode)) + pr_debug("Parent '%s' of device '%s' not available\n", + dev_name(dev->parent), dev_name(dev)); + + if (!dev->fwnode) { + pr_debug("Device '%s' doesn't have a fwnode\n", dev_name(dev)); + return; + } + + for_each_class(check_dependencies_per_class, dev->fwnode); +} + /* * deferred_probe_work_func() - Retry probing devices in the active list. */ @@ -413,6 +531,8 @@ int driver_probe_device(struct device_driver *drv, struct device *dev) return 0; } + check_dependencies(dev); + pr_debug("bus: '%s': %s: matched device %s with driver %s\n", drv->bus->name, __func__, dev_name(dev), drv->name); -- 2.4.1
next prev parent reply other threads:[~2015-06-17 13:44 UTC|newest] Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-06-17 13:42 [PATCH 00/13] Discover and probe dependencies Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-17 13:42 ` [PATCH 01/13] gpiolib: Fix docs for gpiochip_add_pingroup_range Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-07-13 12:16 ` Linus Walleij 2015-07-13 12:16 ` Linus Walleij 2015-06-17 13:42 ` [PATCH 02/13] driver-core: defer all probes until late_initcall Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-18 21:50 ` Rafael J. Wysocki 2015-06-18 21:50 ` Rafael J. Wysocki 2015-06-19 13:36 ` Tomeu Vizoso 2015-06-19 13:36 ` Tomeu Vizoso 2015-06-19 23:20 ` Rafael J. Wysocki 2015-06-19 23:20 ` Rafael J. Wysocki 2015-06-23 0:07 ` Rob Herring 2015-06-23 0:07 ` Rob Herring 2015-06-23 14:37 ` Rafael J. Wysocki 2015-06-23 14:37 ` Rafael J. Wysocki 2015-06-23 14:17 ` Tomeu Vizoso 2015-06-23 14:17 ` Tomeu Vizoso 2015-06-23 14:51 ` Rafael J. Wysocki 2015-06-23 14:51 ` Rafael J. Wysocki 2015-06-23 14:37 ` Tomeu Vizoso 2015-06-23 14:37 ` Tomeu Vizoso 2015-06-24 0:14 ` Rafael J. Wysocki 2015-06-24 0:14 ` Rafael J. Wysocki 2015-06-17 13:42 ` [PATCH 03/13] ARM: tegra: Add gpio-ranges property Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-17 17:25 ` Mark Brown 2015-06-17 17:25 ` Mark Brown 2015-06-18 8:06 ` Tomeu Vizoso 2015-06-18 8:06 ` Tomeu Vizoso 2015-06-17 13:42 ` [PATCH 04/13] pinctrl: tegra: Only set the gpio range if needed Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-07-13 20:14 ` Linus Walleij 2015-07-13 20:14 ` Linus Walleij 2015-07-14 8:34 ` Tomeu Vizoso 2015-07-14 8:34 ` Tomeu Vizoso 2015-07-15 3:17 ` Alexandre Courbot 2015-07-15 3:17 ` Alexandre Courbot 2015-07-15 8:13 ` Tomeu Vizoso 2015-07-15 8:13 ` Tomeu Vizoso 2015-07-17 8:04 ` Linus Walleij 2015-07-17 8:04 ` Linus Walleij 2015-07-17 8:19 ` Tomeu Vizoso 2015-07-17 8:19 ` Tomeu Vizoso 2015-07-17 9:36 ` Linus Walleij 2015-07-17 9:36 ` Linus Walleij 2015-06-17 13:42 ` [PATCH 05/13] driver core: fix docbook for device_private.device Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-17 13:42 ` [PATCH 06/13] of/platform: Set fwnode field for new devices Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-17 17:27 ` Mark Brown 2015-06-17 17:27 ` Mark Brown 2015-06-17 13:42 ` [PATCH 07/13] driver-core: Add class.get_dependencies() callback Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-17 13:42 ` [PATCH 08/13] gpio: sysfs: implement class.get_dependencies() Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-17 17:40 ` Mark Brown 2015-06-17 17:40 ` Mark Brown 2015-06-30 15:00 ` Tomeu Vizoso 2015-06-30 15:00 ` Tomeu Vizoso 2015-06-17 13:42 ` [PATCH 09/13] gpu: host1x: " Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-17 13:42 ` [PATCH 10/13] driver-core: add for_each_class() Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-17 13:42 ` [PATCH 11/13] device property: add fwnode_get_parent() Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-17 13:42 ` [PATCH 12/13] device property: add fwnode_get_name() Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso 2015-06-17 13:42 ` Tomeu Vizoso [this message] 2015-06-17 13:42 ` [PATCH 13/13] driver-core: probe dependencies before probing Tomeu Vizoso 2015-06-17 18:13 ` Mark Brown 2015-06-17 18:13 ` Mark Brown 2015-06-30 15:18 ` Tomeu Vizoso 2015-06-30 15:18 ` Tomeu Vizoso 2015-06-18 9:42 ` [PATCH 00/13] Discover and probe dependencies Andrzej Hajda 2015-06-18 9:42 ` Andrzej Hajda 2015-06-18 9:57 ` Russell King - ARM Linux 2015-06-18 9:57 ` Russell King - ARM Linux 2015-06-18 10:36 ` Mark Brown 2015-06-18 10:36 ` Mark Brown 2015-06-18 13:14 ` Andrzej Hajda 2015-06-18 13:14 ` Andrzej Hajda 2015-06-18 14:38 ` Tomeu Vizoso 2015-06-18 14:38 ` Tomeu Vizoso 2015-06-18 14:49 ` Russell King - ARM Linux 2015-06-18 14:49 ` Russell King - ARM Linux 2015-06-18 15:32 ` Alexander Holler 2015-06-18 15:32 ` Alexander Holler 2015-06-18 14:57 ` Tomeu Vizoso 2015-06-18 14:57 ` Tomeu Vizoso
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=1434548543-22949-14-git-send-email-tomeu.vizoso@collabora.com \ --to=tomeu.vizoso@collabora.com \ --cc=a.hajda@samsung.com \ --cc=arnd@arndb.de \ --cc=broonie@kernel.org \ --cc=dmitry.torokhov@gmail.com \ --cc=galak@codeaurora.org \ --cc=gnurou@gmail.com \ --cc=grant.likely@linaro.org \ --cc=gregkh@linuxfoundation.org \ --cc=holler@ahsoftware.de \ --cc=ijc+devicetree@hellion.org.uk \ --cc=javier.martinez@collabora.co.uk \ --cc=k.kozlowski@samsung.com \ --cc=lenb@kernel.org \ --cc=linus.walleij@linaro.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux@arm.linux.org.uk \ --cc=lv.zheng@intel.com \ --cc=mark.rutland@arm.com \ --cc=pawel.moll@arm.com \ --cc=rjw@rjwysocki.net \ --cc=robert.moore@intel.com \ --cc=robh+dt@kernel.org \ --cc=swarren@wwwdotorg.org \ --cc=tbergstrom@nvidia.com \ --cc=thierry.reding@gmail.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: linkBe 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.