From patchwork Thu May 9 05:18:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 2543061 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id 61D87DF24C for ; Thu, 9 May 2013 05:20:12 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UaJGa-0001OE-8j; Thu, 09 May 2013 05:19:44 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UaJGQ-0007Nf-AJ; Thu, 09 May 2013 05:19:34 +0000 Received: from wolverine02.qualcomm.com ([199.106.114.251]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UaJG8-0007LL-Gc for linux-arm-kernel@lists.infradead.org; Thu, 09 May 2013 05:19:17 +0000 X-IronPort-AV: E=Sophos;i="4.87,638,1363158000"; d="scan'208";a="45617294" Received: from pdmz-ns-snip_115.254.qualcomm.com (HELO mostmsg01.qualcomm.com) ([199.106.115.254]) by wolverine02.qualcomm.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 08 May 2013 22:18:52 -0700 Received: from skannan1-linux.qualcomm.com (pdmz-ns-snip_218_1.qualcomm.com [192.168.218.1]) by mostmsg01.qualcomm.com (Postfix) with ESMTPA id 1A95510004D6; Wed, 8 May 2013 22:18:52 -0700 (PDT) From: Saravana Kannan To: Greg Kroah-Hartman , Grant Likely , Mike Turquette , Liam Girdwood , Mark Brown Subject: [PATCH 1/3] driver core: Add API to wait for deferred probe to complete during init Date: Wed, 8 May 2013 22:18:44 -0700 Message-Id: <1368076726-11492-2-git-send-email-skannan@codeaurora.org> X-Mailer: git-send-email 1.7.8.3 In-Reply-To: <1368076726-11492-1-git-send-email-skannan@codeaurora.org> References: <1368076726-11492-1-git-send-email-skannan@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130509_011916_837094_03B808D4 X-CRM114-Status: GOOD ( 13.57 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [199.106.114.251 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-arm-msm@vger.kernel.org, Stephen Boyd , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Kernel framework (Eg: regulator, clock, etc) might want to do some clean up work (Eg: turn off unclaimed resources) after all devices are done probing during kernel init. Before deferred probing was introduced, this was typically done using a late_initcall(). That approach still makes the assumption that all drivers that are compiled in, register in one of the earlier initcall levels. With the introduction of deferred probing, even if the assumption that all compiled in drivers register in one of the earlier initcalls is ture, there is no longer a guarantee that all their matching devices would have completed probing by late_initcall(). This is because deferred probing loginc starts attempting the deferred probes only in a late_initcall() function. The most obvious fallback of using late_initcall_sync() also doesn't work since the deferred probing work initated during late_initcall() is done in a workqueue. So, frameworks that want to wait for all devices to finish probing during init will now have to wait for the deferred workqueue to finish it's work. This patch adds a wait_for_init_deferred_probe_done() API that can by called from late_initcall_sync() or a workqueue started from late_initcall_sync() Signed-off-by: Saravana Kannan --- drivers/base/dd.c | 8 ++++++++ include/linux/device.h | 1 + 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index bb5645e..bb2b9c6 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -52,6 +52,7 @@ static DEFINE_MUTEX(deferred_probe_mutex); static LIST_HEAD(deferred_probe_pending_list); static LIST_HEAD(deferred_probe_active_list); static struct workqueue_struct *deferred_wq; +DECLARE_COMPLETION(init_def_probe_done); /** * deferred_probe_work_func() - Retry probing devices in the active list. @@ -105,6 +106,7 @@ static void deferred_probe_work_func(struct work_struct *work) put_device(dev); } mutex_unlock(&deferred_probe_mutex); + complete_all(&init_def_probe_done); } static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func); @@ -179,6 +181,12 @@ static int deferred_probe_initcall(void) } late_initcall(deferred_probe_initcall); +void wait_for_init_deferred_probe_done(void) +{ + wait_for_completion(&init_def_probe_done); +} +EXPORT_SYMBOL_GPL(wait_for_init_deferred_probe_done); + static void driver_bound(struct device *dev) { if (klist_node_attached(&dev->p->knode_driver)) { diff --git a/include/linux/device.h b/include/linux/device.h index 9d6464e..5c557f7 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -247,6 +247,7 @@ extern struct device_driver *driver_find(const char *name, struct bus_type *bus); extern int driver_probe_done(void); extern void wait_for_device_probe(void); +extern void wait_for_init_deferred_probe_done(void); /* sysfs interface for exporting driver attributes */