From patchwork Fri Aug 17 04:05:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 1336961 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 7CCE43FC71 for ; Fri, 17 Aug 2012 04:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750958Ab2HQEFy (ORCPT ); Fri, 17 Aug 2012 00:05:54 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:60927 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750886Ab2HQEFx (ORCPT ); Fri, 17 Aug 2012 00:05:53 -0400 Received: by pbbrr13 with SMTP id rr13so2659575pbb.19 for ; Thu, 16 Aug 2012 21:05:53 -0700 (PDT) Received: by 10.68.231.10 with SMTP id tc10mr8178718pbc.107.1345176353150; Thu, 16 Aug 2012 21:05:53 -0700 (PDT) Received: from localhost ([183.37.194.232]) by mx.google.com with ESMTPS id ty1sm939980pbc.76.2012.08.16.21.05.49 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 16 Aug 2012 21:05:51 -0700 (PDT) From: Ming Lei To: Linus Torvalds , Greg Kroah-Hartman Cc: "Rafael J. Wysocki" , Borislav Petkov , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ming Lei Subject: [PATCH 2/3] PM / Sleep: introduce dpm_for_each_dev Date: Fri, 17 Aug 2012 12:05:41 +0800 Message-Id: <1345176342-23513-1-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org dpm_list and its pm lock provide a good way to iterate all devices in system. Except this way, there is no other easy way to iterate devices in system. firmware loader need to cache firmware images for devices before system sleep, so introduce the function to meet its demand. Reported-by: Fengguang Wu Signed-off-by: Ming Lei --- v1: - add 'static inline' if !PM_SLEEP - check 'fn' in dpm_for_each_dev drivers/base/power/main.c | 22 ++++++++++++++++++++++ include/linux/pm.h | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 57f5814..23b417f 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -1349,3 +1349,25 @@ int device_pm_wait_for_dev(struct device *subordinate, struct device *dev) return async_error; } EXPORT_SYMBOL_GPL(device_pm_wait_for_dev); + +/** + * dpm_for_each_dev - device iterator. + * @data: data for the callback. + * @fn: function to be called for each device. + * + * Iterate over devices in dpm_list, and call @fn for each device, + * passing it @data. + */ +void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *)) +{ + struct device *dev; + + if (!fn) + return; + + device_pm_lock(); + list_for_each_entry(dev, &dpm_list, power.entry) + fn(dev, data); + device_pm_unlock(); +} +EXPORT_SYMBOL_GPL(dpm_for_each_dev); diff --git a/include/linux/pm.h b/include/linux/pm.h index 44d1f23..007e687 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -640,6 +640,7 @@ extern void __suspend_report_result(const char *function, void *fn, int ret); } while (0) extern int device_pm_wait_for_dev(struct device *sub, struct device *dev); +extern void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *)); extern int pm_generic_prepare(struct device *dev); extern int pm_generic_suspend_late(struct device *dev); @@ -679,6 +680,10 @@ static inline int device_pm_wait_for_dev(struct device *a, struct device *b) return 0; } +static inline void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *)) +{ +} + #define pm_generic_prepare NULL #define pm_generic_suspend NULL #define pm_generic_resume NULL