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: 114669 Delivered-To: patches@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1552840qgn; Tue, 3 Oct 2017 00:11:23 -0700 (PDT) X-Received: by 10.46.42.3 with SMTP id q3mr7686634ljq.191.1507014683417; Tue, 03 Oct 2017 00:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507014683; cv=none; d=google.com; s=arc-20160816; b=NDvDGcZT1nE4bTRpvEqGAg5I9Fn+BF6OeuOmj/nHS26cKU+dVPsaBGkHR09QvwQvCT ex0FY9NiQBWIrFHSEZ3QpovjkHKSdKfaZhrCy3IZ97Afyfzsch9drQBvS2T1Rdqjm0gy Cpx5ycnkjcXk+ysDegBCpIKOnD2+CLs58o6GS2RutXNyGmQQKqtVCwywW/Mvn8NnFnxV t4/HsD7s95S9Nh5qypE5FqyMLrU6FBzPXEB5Cb6nHQM6LAJPcmJI8dnuhAIUlwUWHXlH rJPMOkSE6/dmhBaeySeEDDalK9mauQd6sJx1NN6Cr80uS+XwQRDCyd0ehwImhHnTwWk8 YrXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=b/5PXwmf1jNxWtUEybtkUD/Hn5S35dwcZ4666wjykUU=; b=U1Zo6P/mNZrhmP9auZammEcy0n9CQ+httXM3kd3q0FFvh7mwJBwVFPX4b18yUgAH3Q 7Nqpo6IHuBHVNqgdhqt/Lh3pqiaBseOAY9PTrsVkTvgytwDo4vNQe3yAC6c0cwXkcfZ3 6aHO9S+PzGP00YaWTDvnLoJN8PA/NhbXPrRbVCpMJudT/q6Bm7JoOXKeuwmqmRdxfIax 4fikMbL4GW3C6DGoG58Igsdtz5cDRKYwXRGlkJVO1i7HIedeIlumNovbtBFWi2M3Y/LQ 32lPhtF8lxHX2p5/+XxT5ZbXfAZmb54JpTKiB7gIHX6H42+7gO9lZIchzVrLvBvyxb4K lKXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AbwxFldD; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id t17sor1809631lfi.74.2017.10.03.00.11.23 for (Google Transport Security); Tue, 03 Oct 2017 00:11:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AbwxFldD; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=m3DCNF8F0COskJZz0CXGzH7UCisiqyCvQ8Z6z/uGz7vGIPTs8QJd4NgbKozqqJQRIq wa3FTLGH/Pquhl7ycXhKCIQddALOGFfdzEuXsC8WQD9DVxpFkUsKv2qvWHgvVZMiaeTH wc2emcS986COAG58WyOqRvUJlAVdge7VMwRHdDu85JDGHCzrCB4thv/EMI87DFvSOtUn 8klU5ru3B683PJp3oVxlGaPLF/MN3IfB28yqiZpTjmyhg5fQhBb0TUk6vBzjkgEwa/w1 6xswq6W1B/Dal1vAcAvCGaw9L3tarsmQZ+29I8u9dgi7DocgiH94DW4wl3DkNK81C6X1 K89A== X-Gm-Message-State: AMCzsaVs0PdzzNm+h4HoFc505yWcQ8x0jFgqkKm+6HsJrQXxxkhkz8Gq 95DrSTKqEgsNcsAfY1lW2HzEnv+1 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) Return-Path: 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> 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(-) -- 2.7.4 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);