From patchwork Thu May 8 22:41:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 4139171 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EE48C9F387 for ; Thu, 8 May 2014 22:27:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 30D3A202E5 for ; Thu, 8 May 2014 22:27:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FD36202EB for ; Thu, 8 May 2014 22:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756151AbaEHW0h (ORCPT ); Thu, 8 May 2014 18:26:37 -0400 Received: from v094114.home.net.pl ([79.96.170.134]:49572 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1756137AbaEHW0g (ORCPT ); Thu, 8 May 2014 18:26:36 -0400 Received: from afdb188.neoplus.adsl.tpnet.pl [95.49.79.188] (HELO vostro.rjw.lan) by serwer1319399.home.pl [79.96.170.134] with SMTP (IdeaSmtpServer v0.80) id 6b87a764e1392c98; Fri, 9 May 2014 00:26:34 +0200 From: "Rafael J. Wysocki" To: Alan Stern Cc: Linux PM list , Mika Westerberg , Aaron Lu , ACPI Devel Maling List , LKML , Ulf Hansson Subject: [RFC][PATCH 2/3] PM / runtime: Routine for checking device status during system suspend Date: Fri, 09 May 2014 00:41:59 +0200 Message-ID: <3848796.OqSGUVFgr8@vostro.rjw.lan> User-Agent: KMail/4.11.5 (Linux/3.14.0-rc7+; KDE/4.11.5; x86_64; ; ) In-Reply-To: <4232134.uNVe9bptuo@vostro.rjw.lan> References: <2356017.WpDFDYKWcr@vostro.rjw.lan> <4232134.uNVe9bptuo@vostro.rjw.lan> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafael J. Wysocki Add a new helper routine, pm_runtime_enabled_and_suspended(), to allow subsystems (or PM domains) to check the runtime PM status of devices during system suspend (possibly to avoid resuming those devices upfront at that time). Signed-off-by: Rafael J. Wysocki --- drivers/base/power/runtime.c | 27 +++++++++++++++++++++++++++ include/linux/pm_runtime.h | 2 ++ 2 files changed, 29 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-pm/include/linux/pm_runtime.h =================================================================== --- linux-pm.orig/include/linux/pm_runtime.h +++ linux-pm/include/linux/pm_runtime.h @@ -57,6 +57,7 @@ extern unsigned long pm_runtime_autosusp extern void pm_runtime_update_max_time_suspended(struct device *dev, s64 delta_ns); extern void pm_runtime_set_memalloc_noio(struct device *dev, bool enable); +extern bool pm_runtime_enabled_and_suspended(struct device *dev); extern void pm_set_direct_resume(struct device *dev, bool val); static inline bool pm_children_suspended(struct device *dev) @@ -175,6 +176,7 @@ static inline unsigned long pm_runtime_a struct device *dev) { return 0; } static inline void pm_runtime_set_memalloc_noio(struct device *dev, bool enable){} +static inline bool pm_runtime_enabled_and_suspended(struct device *dev) { return false; } static inline void __set_direct_resume(struct device *dev, bool val) {} static inline void pm_set_direct_resume(struct device *dev, bool val) {} static inline bool pm_direct_resume_is_set(struct device *dev) { return false; } Index: linux-pm/drivers/base/power/runtime.c =================================================================== --- linux-pm.orig/drivers/base/power/runtime.c +++ linux-pm/drivers/base/power/runtime.c @@ -1196,6 +1196,33 @@ void pm_runtime_enable(struct device *de EXPORT_SYMBOL_GPL(pm_runtime_enable); /** + * pm_runtime_enabled_and_suspended - Check runtime PM status of a device. + * @dev: Device to handle. + * + * This routine is to be executed during system suspend only, after + * device_prepare() has been executed for @dev. + * + * Return false if runtime PM is disabled for the device. Otherwise, wait + * for pending transitions to complete and check the runtime PM status of the + * device after that. Return true if it is RPM_SUSPENDED. + */ +bool pm_runtime_enabled_and_suspended(struct device *dev) +{ + unsigned long flags; + bool ret; + + spin_lock_irqsave(&dev->power.lock, flags); + if (dev->power.disable_depth) { + ret = false; + } else { + __pm_runtime_barrier(dev); + ret = pm_runtime_status_suspended(dev); + } + spin_unlock_irqrestore(&dev->power.lock, flags); + return ret; +} + +/** * pm_runtime_forbid - Block runtime PM of a device. * @dev: Device to handle. *