From patchwork Wed Jul 1 09:41:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6702561 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1B86D9F2F0 for ; Wed, 1 Jul 2015 09:51:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1863620688 for ; Wed, 1 Jul 2015 09:51:12 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 9E76620670 for ; Wed, 1 Jul 2015 09:51:10 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id D52C92614EE; Wed, 1 Jul 2015 11:51:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id F345F261A40; Wed, 1 Jul 2015 11:46:16 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 61E032606D3; Wed, 1 Jul 2015 11:46:13 +0200 (CEST) Received: from mail-wg0-f52.google.com (mail-wg0-f52.google.com [74.125.82.52]) by alsa0.perex.cz (Postfix) with ESMTP id CAE4A2606D4 for ; Wed, 1 Jul 2015 11:43:07 +0200 (CEST) Received: by wgck11 with SMTP id k11so31776186wgc.0 for ; Wed, 01 Jul 2015 02:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=zX3MC7JdIkxpG/kdBnyhj1WNNCO2uwnEd3iNxJbXZU0=; b=qfIIX7zIrVMpToW9dgzlCgpFx6IwGwqAh5BR2ONIEAxshpCQGTsNRrxE7BbK05o6Qg 6zbyQGfGAF3rdS/OLXKonL547n7hzmGaYT0k01TW4xKj2imnlx8HyGQ6B/K40BlQB25P BeiWf9Rrw6mtQWGSya5rU7CbiKfjOBYGqTbyzr7+wq0Ub9rzUgmPP2gkxNBWEQxZ8tH2 eu8j2fCGlHKvi7+3pn0l0qnTTmm0UPIbF8WucSKoC97gl0a2NsCZUAZAdg6W4go05MIn 8qxTswiaZg/fZ4WTczCVT2dxA5glNP9JDKEIjNT/yKLXMgfrf16Xr5y7IXNUHQreT8dF R7GA== X-Received: by 10.180.82.162 with SMTP id j2mr4873093wiy.54.1435743787633; Wed, 01 Jul 2015 02:43:07 -0700 (PDT) Received: from cizrna.lan ([109.72.12.160]) by mx.google.com with ESMTPSA id x10sm1992663wjr.25.2015.07.01.02.43.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jul 2015 02:43:06 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Date: Wed, 1 Jul 2015 11:41:07 +0200 Message-Id: <1435743667-11987-13-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1435743667-11987-1-git-send-email-tomeu.vizoso@collabora.com> References: <1435743667-11987-1-git-send-email-tomeu.vizoso@collabora.com> Cc: devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, Tomeu Vizoso , linux-gpio@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , alsa-devel@alsa-project.org, dri-devel@lists.freedesktop.org, linux-acpi@vger.kernel.org, Mark Brown , linux-pwm@vger.kernel.org Subject: [alsa-devel] [PATCH v2 12/12] driver-core: probe dependencies before probing X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 and probing them. Non-platform devices will be probed when the closest ancestor that is a platform device is probed. 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 code that is already implementing the specification of the firmware bindings, via the callbacks registered with fwnode_add_dependency_parser(). Currently the dependencies list is discarded but it could be stored for later usage. Signed-off-by: Tomeu Vizoso tegra, kernel, usb --- Changes in v2: - Allocate the list of dependencies and pass it to the function that fills it. drivers/base/dd.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index a638bbb..c8a1aff 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #include "base.h" #include "power/power.h" @@ -54,6 +57,140 @@ 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 bool fwnode_is_platform(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *parent; + const char *compatible; + int count; + + count = fwnode_property_read_string_array(fwnode, "compatible", NULL, + 0); + + /* The node has to have a compatible string */ + if (!count) + return false; + + /* But it cannot be only simple-bus */ + if ((count == 1) && + !fwnode_property_read_string(fwnode, "compatible", &compatible) && + !strcmp(compatible, "simple-bus")) + return false; + + parent = fwnode_get_parent(fwnode); + + /* Node is immediately below root */ + if (!fwnode_get_parent(parent)) + return true; + + /* If its parent is a simple-bus */ + if (fwnode_is_compatible(parent, "simple-bus")) + return true; + + return 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)) { + + /* + * If we already have a platform device and an ancestor is + * already bound, the first is the one we want to probe. + */ + if (node && fwnode_is_bound(iter)) + break; + + if (fwnode_is_platform(iter)) + node = iter; + } + + 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(struct device *dev) +{ + struct fwnode_dependency *dep, *tmp; + LIST_HEAD(deps); + + 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; + } + + fwnode_get_dependencies(dev->fwnode, &deps); + + 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); + } +} + /* * deferred_probe_work_func() - Retry probing devices in the active list. */ @@ -287,6 +424,8 @@ static int really_probe(struct device *dev, struct device_driver *drv) dev->driver = drv; + check_dependencies(dev); + /* If using pinctrl, bind pins now before probing */ ret = pinctrl_bind_pins(dev); if (ret)