From patchwork Fri Aug 17 14:06:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 1338601 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 2C16EDF280 for ; Fri, 17 Aug 2012 14:07:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756287Ab2HQOHt (ORCPT ); Fri, 17 Aug 2012 10:07:49 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:37179 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756116Ab2HQOHi (ORCPT ); Fri, 17 Aug 2012 10:07:38 -0400 Received: by pbbrr13 with SMTP id rr13so3383710pbb.19 for ; Fri, 17 Aug 2012 07:07:37 -0700 (PDT) Received: by 10.68.222.170 with SMTP id qn10mr11720876pbc.114.1345212457669; Fri, 17 Aug 2012 07:07:37 -0700 (PDT) Received: from localhost ([119.136.68.120]) by mx.google.com with ESMTPS id hr1sm4992226pbc.23.2012.08.17.07.07.33 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Aug 2012 07:07:36 -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 v1 2/3] PM / Sleep: introduce dpm_for_each_dev Date: Fri, 17 Aug 2012 22:06:59 +0800 Message-Id: <1345212420-1707-3-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1345212420-1707-1-git-send-email-ming.lei@canonical.com> References: <1345212420-1707-1-git-send-email-ming.lei@canonical.com> 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 --- 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