From patchwork Wed Aug 23 14:42:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 9917523 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DBAEB60327 for ; Wed, 23 Aug 2017 14:43:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDE5928991 for ; Wed, 23 Aug 2017 14:43:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C27F4289AF; Wed, 23 Aug 2017 14:43:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AF9E28991 for ; Wed, 23 Aug 2017 14:43:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932114AbdHWOm0 (ORCPT ); Wed, 23 Aug 2017 10:42:26 -0400 Received: from mail-lf0-f44.google.com ([209.85.215.44]:34821 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754106AbdHWOmW (ORCPT ); Wed, 23 Aug 2017 10:42:22 -0400 Received: by mail-lf0-f44.google.com with SMTP id k186so1475381lfe.2 for ; Wed, 23 Aug 2017 07:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4/W6OZ+A4Rz4hctfwlJI6a5jCkwwM43qZi+T3IcWlFs=; b=ZP9/pZzS1cSGSh0OxQT/y//rYdQFqMhJnodSRjERdabwOYiHF+l5+pIlecIH1rvGZ0 acN36gN9gjDpKNj9iz+AuGX3sYaDSRFCcePu2y6v0rWTMSrN3KMRKoJUiJxRU5532Iav Wbeqe4RLX+C94NB3ecq3D5/g7IxPN6PnbbHqs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4/W6OZ+A4Rz4hctfwlJI6a5jCkwwM43qZi+T3IcWlFs=; b=fF9EQCptRmjBJQ8+Z+FKXAKbYiM+jvnBDuvWtY88Sj6Y9ooVB7ZZD0JK9hqBD4Lx0K gChpnIDSf27gbFW7vccMDnacyzyaAzDFl3HRsW8tOEcWGIJa1WJ+NOQpwXZSfIEal9e7 WdyuqicxG+IbZ3kExRfkScCN3MBcz3CI+w6ZxVsGn9I+x7EWvGeJBlAXr1QtZPU2Xd+7 F+DSvOIvheWzuJ5+apSZ8WmhT2sls2XTdY3SxfO8uZ230lmhtOmQbsBOXZR6jvTWZ8/o jYw5lTMFI0ReHF6PoIUF4baVphWqTYha7rdbk1TGsmN7ruybp/lT/FFBrAeNRBK0Q+aS Yolw== X-Gm-Message-State: AHYfb5jscXkx4TGqHETXP6xjatvK45p+FiiVXgHmSJdSXI1jUElphoKl YWEOburn4Iw1mOxB X-Received: by 10.46.9.65 with SMTP id 62mr1166862ljj.177.1503499340683; Wed, 23 Aug 2017 07:42:20 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-67.NA.cust.bahnhof.se. [158.174.22.67]) by smtp.gmail.com with ESMTPSA id c89sm287593lfb.78.2017.08.23.07.42.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Aug 2017 07:42:20 -0700 (PDT) From: Ulf Hansson To: Wolfram Sang , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org Cc: Kevin Hilman , Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Jisheng Zhang , John Stultz , Guodong Xu , Sumit Semwal , Haojian Zhuang , linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, Ulf Hansson Subject: [PATCH v2 3/9] PM / ACPI: Split code validating need for runtime resume in ->prepare() Date: Wed, 23 Aug 2017 16:42:03 +0200 Message-Id: <1503499329-28834-4-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503499329-28834-1-git-send-email-ulf.hansson@linaro.org> References: <1503499329-28834-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the code dealing with validation of whether runtime resuming the device is needed during system suspend. In this way it becomes more clear for what circumstances ACPI is prevented from trying the direct_complete path. Signed-off-by: Ulf Hansson --- Changes in v2: - Updated return expression for acpi_dev_needs_resume(). --- drivers/acpi/device_pm.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index 632f214..5181057 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -989,6 +989,27 @@ int acpi_dev_resume_early(struct device *dev) } EXPORT_SYMBOL_GPL(acpi_dev_resume_early); +static bool acpi_dev_needs_resume(struct device *dev, struct acpi_device *adev) +{ + u32 sys_target = acpi_target_system_state(); + int ret, state; + + if (device_may_wakeup(dev) != !!adev->wakeup.prepare_count) + return true; + + if (sys_target == ACPI_STATE_S0) + return false; + + if (adev->power.flags.dsw_present) + return true; + + ret = acpi_dev_pm_get_state(dev, adev, sys_target, NULL, &state); + if (ret) + return true; + + return state != adev->power.state; +} + /** * acpi_subsys_prepare - Prepare device for system transition to a sleep state. * @dev: Device to prepare. @@ -996,26 +1017,16 @@ EXPORT_SYMBOL_GPL(acpi_dev_resume_early); int acpi_subsys_prepare(struct device *dev) { struct acpi_device *adev = ACPI_COMPANION(dev); - u32 sys_target; - int ret, state; + int ret; ret = pm_generic_prepare(dev); if (ret < 0) return ret; - if (!adev || !pm_runtime_suspended(dev) - || device_may_wakeup(dev) != !!adev->wakeup.prepare_count) - return 0; - - sys_target = acpi_target_system_state(); - if (sys_target == ACPI_STATE_S0) - return 1; - - if (adev->power.flags.dsw_present) + if (!adev || !pm_runtime_suspended(dev)) return 0; - ret = acpi_dev_pm_get_state(dev, adev, sys_target, NULL, &state); - return !ret && state == adev->power.state; + return !acpi_dev_needs_resume(dev, adev); } EXPORT_SYMBOL_GPL(acpi_subsys_prepare);