From patchwork Tue Oct 3 07:11:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 9981845 X-Patchwork-Delegate: rjw@sisk.pl 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 6A3B76038E for ; Tue, 3 Oct 2017 07:11:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DCA02870C for ; Tue, 3 Oct 2017 07:11:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52D062887E; Tue, 3 Oct 2017 07:11:28 +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 028B72872A for ; Tue, 3 Oct 2017 07:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751164AbdJCHL0 (ORCPT ); Tue, 3 Oct 2017 03:11:26 -0400 Received: from mail-lf0-f44.google.com ([209.85.215.44]:43139 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751072AbdJCHLY (ORCPT ); Tue, 3 Oct 2017 03:11:24 -0400 Received: by mail-lf0-f44.google.com with SMTP id o125so3964954lfe.0 for ; Tue, 03 Oct 2017 00:11:23 -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=b/5PXwmf1jNxWtUEybtkUD/Hn5S35dwcZ4666wjykUU=; b=AbwxFldDb+IfNuZ+NjEvbN/DrM0z9ZBO5bklgTotH5o19TAt/rhp+9Rh9Z7Pr44mPP bPaRnJedWarSYoeF9O0Rf82dt7Oz2aJtErmc4Vk5vqxhzzhj5RAILZBHXS1idgVFz9mo YtTcLQf0ML3WqZghvNC34jpAh2XERMYJefDxc= 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=b/5PXwmf1jNxWtUEybtkUD/Hn5S35dwcZ4666wjykUU=; b=CZ5WOa3VxSWyN/IB6dkmLW82JEABgiNonRtirLJTmw+0RXPwf+/K6P9WgUZcHsPgdL aYzGHT367UfrE0C/PQ8maAn0c1r/XQREkxEhc+yN3Qtr0y855IBDE/MOaaaUWvr4W61T 98idyb4h0sXym2My528l11FyDOXw4MqFOxk21E2tY8smEFNEbJy/I0uV6nzbB6hDRNJX 0lgDPz/aiBNeyQ30jGqBV0dKlxkVAbYYMtyHJCmTePzGEmbKneT4I4I3jWpKdSmQnu2P MHE9USPgxDMDQvmi78BbR1IQl7PNQZPUFwkwz320qH6kaZ0W3FT8l2+NdqnZwF5Dl19F dEvA== X-Gm-Message-State: AMCzsaWkzZHwiOy19puv2IN1/YSC48uwBO1b0sfb9P4lTbddhxTJPtm4 V58zivdPVmZG9qoTBQm6Bpe6uA== X-Google-Smtp-Source: AOwi7QCVP5tChGw2NpXCsB/cR3h2sB4tUoiw6Db/opEn0ur73lb63MK0skn76JzyxUhb0UjKF7wocw== X-Received: by 10.25.27.71 with SMTP id b68mr5677462lfb.125.1507014683080; Tue, 03 Oct 2017 00:11:23 -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 x13sm2764497ljb.23.2017.10.03.00.11.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Oct 2017 00:11:22 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org Cc: Len Brown , Pavel Machek , Kevin Hilman , Ulf Hansson Subject: [PATCH 3/4] PM / ACPI: Split code validating need for runtime resume in ->prepare() Date: Tue, 3 Oct 2017 09:11:08 +0200 Message-Id: <1507014669-1502-4-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507014669-1502-1-git-send-email-ulf.hansson@linaro.org> References: <1507014669-1502-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 --- 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);