From patchwork Thu Nov 28 16:03:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 11266351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D753112B for ; Thu, 28 Nov 2019 16:03:27 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0567421771 for ; Thu, 28 Nov 2019 16:03:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0567421771 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 554476E853; Thu, 28 Nov 2019 16:03:25 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB0046E850 for ; Thu, 28 Nov 2019 16:03:20 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id w15so807120wru.4 for ; Thu, 28 Nov 2019 08:03:20 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=lOL2WwXKMkqlZX6wUQQ6MwqMeR5NI46AhAiQFt0R8fk=; b=l737nuF8Nymh5wPeB4DiahNhNlDxAcJQXH8ZuzE8aDFu+67N9yokIr5JYqsftIDfBx VZsnqFNN51DvMvhmXtYELwVvLJoAB1cy4eE5uQOkk4KNPpB16r45pXtLQCLw9pPruRFl IblnagMT3qeUblhJLHrPxKUTpYLz8tIWOyOynCOTGLvsn/HHywY+hhQBe8tC+luOZpyO 0eT1F3rToGBfNj0dFszSpKvV7J2tOq9N4BUzu3mjiUDMzcJ+rrzVQW5ooWztmTEUbs9g woXIIrICNZqf2dHQWyrIAcw44lyRXAhmyMekJWwoqcEa9GDAuJZWoVBn5pU2OV0+Kc43 osZw== X-Gm-Message-State: APjAAAUz9RHTRc21znC7Omb7P9sZ7p3cugrlTsHNHrr9DtUQKonzOLx4 xJ/2AyshyKXG51II92jPrdw= X-Google-Smtp-Source: APXvYqwURFbvadsjM8yhtZLmDVxnsZK14DaAfPq8tFyanA5Uc6CobSzma1LQagRMoEn6yPCP6+rw1g== X-Received: by 2002:a5d:4602:: with SMTP id t2mr3193411wrq.37.1574956999474; Thu, 28 Nov 2019 08:03:19 -0800 (PST) Received: from localhost (pD9E518ED.dip0.t-ipconnect.de. [217.229.24.237]) by smtp.gmail.com with ESMTPSA id g21sm25945451wrb.48.2019.11.28.08.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 08:03:18 -0800 (PST) From: Thierry Reding To: "Rafael J . Wysocki" , Thierry Reding Subject: [PATCH 1/2] PM / runtime: Allow drivers to override runtime PM behaviour on sleep Date: Thu, 28 Nov 2019 17:03:13 +0100 Message-Id: <20191128160314.2381249-2-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191128160314.2381249-1-thierry.reding@gmail.com> References: <20191128160314.2381249-1-thierry.reding@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lOL2WwXKMkqlZX6wUQQ6MwqMeR5NI46AhAiQFt0R8fk=; b=c+nu4vtO+mJqL0W7fDFWd80nKNeQXZLNC4avT3H6DFtFBCKsCNI+/Xcx5u4Moz0mef tJX7I0vKqGfiiOwHmcsLPZiq+Bp+miZivn9I373iV+5nYjNdXGBooV5dAgZA42sDhBwp RAa9lySbVenpLPBcb+PDI02gGZ8/5AXVgh4FOusBKTYSCpujI4W41Bvs9lx/xnxui1cL p9VF9R1U4n64Q8PpMdtKtB1hlxB7KJ2lO3ognuM2fPLDFePLcSNYbsYl+lvmlh1Mnwak Fuj8IkSGxCWqrWo/PSCUqxm49SSEoja5dmdGHp8oWKmzKkDyy4u/5Pfirmocc+uPzN0V o9iw== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Len Brown , linux-pm@vger.kernel.org, Greg Kroah-Hartman , dri-devel@lists.freedesktop.org, Pavel Machek , linux-tegra@vger.kernel.org, Dmitry Osipenko Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Thierry Reding Currently the driver PM core will automatically acquire a runtime PM reference for devices before system sleep is entered. This is needed to avoid potential issues related to devices' parents getting put to runtime suspend at the wrong time and causing problems with their children. In some cases drivers are carefully written to avoid such issues and the default behaviour can be changed to allow runtime PM to operate regularly during system sleep. Add helpers to flag devices as being safe to be runtime suspended at system sleep time. Signed-off-by: Thierry Reding --- drivers/base/power/main.c | 6 ++++-- drivers/base/power/runtime.c | 16 ++++++++++++++++ include/linux/pm.h | 1 + include/linux/pm_runtime.h | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 134a8af51511..f8dbf00c703b 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -1113,7 +1113,8 @@ static void device_complete(struct device *dev, pm_message_t state) device_unlock(dev); - pm_runtime_put(dev); + if (!dev->power.always_runtime) + pm_runtime_put(dev); } /** @@ -1896,7 +1897,8 @@ static int device_prepare(struct device *dev, pm_message_t state) * block runtime suspend here, during the prepare phase, and allow * it again during the complete phase. */ - pm_runtime_get_noresume(dev); + if (!dev->power.always_runtime) + pm_runtime_get_noresume(dev); device_lock(dev); diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 48616f358854..699803984426 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1440,6 +1440,22 @@ void pm_runtime_allow(struct device *dev) } EXPORT_SYMBOL_GPL(pm_runtime_allow); +void pm_runtime_always_allow(struct device *dev) +{ + spin_lock_irq(&dev->power.lock); + dev->power.always_runtime = 1; + spin_unlock_irq(&dev->power.lock); +} +EXPORT_SYMBOL_GPL(pm_runtime_always_allow); + +void pm_runtime_always_forbid(struct device *dev) +{ + spin_lock_irq(&dev->power.lock); + dev->power.always_runtime = 0; + spin_unlock_irq(&dev->power.lock); +} +EXPORT_SYMBOL_GPL(pm_runtime_always_forbid); + /** * pm_runtime_no_callbacks - Ignore runtime PM callbacks for a device. * @dev: Device to handle. diff --git a/include/linux/pm.h b/include/linux/pm.h index e057d1fa2469..6133cf496878 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -615,6 +615,7 @@ struct dev_pm_info { unsigned int use_autosuspend:1; unsigned int timer_autosuspends:1; unsigned int memalloc_noio:1; + unsigned int always_runtime:1; unsigned int links_count; enum rpm_request request; enum rpm_status runtime_status; diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index 22af69d237a6..28204baf01cb 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -46,6 +46,8 @@ extern void pm_runtime_enable(struct device *dev); extern void __pm_runtime_disable(struct device *dev, bool check_resume); extern void pm_runtime_allow(struct device *dev); extern void pm_runtime_forbid(struct device *dev); +extern void pm_runtime_always_allow(struct device *dev); +extern void pm_runtime_always_forbid(struct device *dev); extern void pm_runtime_no_callbacks(struct device *dev); extern void pm_runtime_irq_safe(struct device *dev); extern void __pm_runtime_use_autosuspend(struct device *dev, bool use); From patchwork Thu Nov 28 16:03:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 11266353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F75A112B for ; Thu, 28 Nov 2019 16:03:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1728C21771 for ; Thu, 28 Nov 2019 16:03:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1728C21771 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E1D76E852; Thu, 28 Nov 2019 16:03:25 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id 134D06E84B for ; Thu, 28 Nov 2019 16:03:23 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id b11so11434364wmj.4 for ; Thu, 28 Nov 2019 08:03:22 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=jiPFkJr8K+r185dz3meGF9Rkk5ahdrm7UQfYURLxxJE=; b=Mrxm09+GtM3szft4t/ybCIgFFrBDZRvZDZppqkd8KHIIvrTkY0++mERheVX+6LlGiC UBOBggQ1sxmC9JwqlSTijasjvRO5ggJ3LL4fZVO3Ev3cRC7yFtADpORV7iSGAwmIKe3D uiJQdrgDN5wb6qAcfwjl2eMfimc7REuhtx0x9BxLL3P+9LNj2i0ta+VzyYMVmIruZjAW LJQSQ27xWb//aQX0vYkW7pnC27RmjnqazH1AVHbhjm7fOGxxMcSFoKyjwIlMktFWQIgG u+kyfl4I6YKcCkEzOxYR6OuO403TuSXN53himxNfatyCcN6TwREtmibysruVmYkgBIUh wDyg== X-Gm-Message-State: APjAAAXijzKnCcY5FNDO+0hw12yH81ALxot+2MU5/qnFPia0nXxfdBO9 a69uvEwY+7Zv6nvi2Dm7r24= X-Google-Smtp-Source: APXvYqx+k4JQZLKsE8o2E6bpXGMJN487dEZBP+g2+g5JjAWAcxUXYJTrNdAN+zermTFhePpO/HD/dg== X-Received: by 2002:a1c:f317:: with SMTP id q23mr9783029wmq.97.1574957001542; Thu, 28 Nov 2019 08:03:21 -0800 (PST) Received: from localhost (pD9E518ED.dip0.t-ipconnect.de. [217.229.24.237]) by smtp.gmail.com with ESMTPSA id h15sm24670157wrb.44.2019.11.28.08.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 08:03:20 -0800 (PST) From: Thierry Reding To: "Rafael J . Wysocki" , Thierry Reding Subject: [PATCH 2/2] drm/tegra: Allow runtime suspend on system sleep Date: Thu, 28 Nov 2019 17:03:14 +0100 Message-Id: <20191128160314.2381249-3-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191128160314.2381249-1-thierry.reding@gmail.com> References: <20191128160314.2381249-1-thierry.reding@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jiPFkJr8K+r185dz3meGF9Rkk5ahdrm7UQfYURLxxJE=; b=PB5LHoZshTGHaxfaPdX6fSYl+Me/Ge/gdvpmr49K3UIpK4gfRq/KpgCsQ1oq5HKSFw 1zfeG/fGqvCfpmDSrXL73JkAnw2f0+umB9V8TBXB4OoTk9jER+lOm/GAysrxR8W2v46M uIfg11Ne+LX4ZRz/S1ACz4sOdbLfUxmYDPlu0fzS8sEU+uD7FvMKdm7VCAB852vUW7Qn VqPvGE+p7tCDAuFm4aR4F2alNFpDHpclNOEN5XrUmoOARu4MVcT9peAXQyntutLcMyNn BMjfUGJ4bDHlQQYe3PMTVoql96B6dNLYj1EgQgdz1068X63FWvet0T6ECffMCgZF0xtu PLQg== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Len Brown , linux-pm@vger.kernel.org, Greg Kroah-Hartman , dri-devel@lists.freedesktop.org, Pavel Machek , linux-tegra@vger.kernel.org, Dmitry Osipenko Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Thierry Reding By default the PM core prevents devices from being runtime suspended during system sleep. This is needed to avoid some common cases where devices cannot be properly resumed because their parents are runtime suspended at an unfortunate point in time. However, there are cases where suspend/resume works in a way that it becomes possible for devices to be runtime suspended at system sleep time. In fact, for some devices runtime suspension can be equivalent to their state in system sleep. Typically this would be solved by making the runtime suspend/resume callbacks the same as the system suspend/resume callbacks. For some subsystems it isn't quite that simple, unfortunately. For example, the DRM subsystem has subsystem-level suspend/resume helpers that control how display pipelines are shut down on suspend and brought up again on resume. This procedure is the same as their operation under normal circumstances (when the user switches on/off a subset of the displays in their configuration). These helpers are carefully ordering the operations to make sure the right sequences between connectors, encoders and display controllers are respected. In order for suspend/resume to not get in the way of the sequencing that's already happening at the subsystem level, allow the devices involved in the display pipelines to runtime suspend during system sleep. Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/dc.c | 1 + drivers/gpu/drm/tegra/dsi.c | 1 + drivers/gpu/drm/tegra/hdmi.c | 1 + drivers/gpu/drm/tegra/hub.c | 1 + drivers/gpu/drm/tegra/sor.c | 1 + 5 files changed, 5 insertions(+) diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c index 2b9a25c977c0..386819b4662b 100644 --- a/drivers/gpu/drm/tegra/dc.c +++ b/drivers/gpu/drm/tegra/dc.c @@ -2506,6 +2506,7 @@ static int tegra_dc_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, dc); + pm_runtime_always_allow(&pdev->dev); pm_runtime_enable(&pdev->dev); INIT_LIST_HEAD(&dc->client.list); diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c index a5d47e301c5f..683a27f9ba52 100644 --- a/drivers/gpu/drm/tegra/dsi.c +++ b/drivers/gpu/drm/tegra/dsi.c @@ -1552,6 +1552,7 @@ static int tegra_dsi_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, dsi); + pm_runtime_always_allow(&pdev->dev); pm_runtime_enable(&pdev->dev); INIT_LIST_HEAD(&dsi->client.list); diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c index 50269ffbcb6b..2562bf607be1 100644 --- a/drivers/gpu/drm/tegra/hdmi.c +++ b/drivers/gpu/drm/tegra/hdmi.c @@ -1664,6 +1664,7 @@ static int tegra_hdmi_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, hdmi); + pm_runtime_always_allow(&pdev->dev); pm_runtime_enable(&pdev->dev); INIT_LIST_HEAD(&hdmi->client.list); diff --git a/drivers/gpu/drm/tegra/hub.c b/drivers/gpu/drm/tegra/hub.c index e56c0f7d3a13..aced537ac990 100644 --- a/drivers/gpu/drm/tegra/hub.c +++ b/drivers/gpu/drm/tegra/hub.c @@ -844,6 +844,7 @@ static int tegra_display_hub_probe(struct platform_device *pdev) return err; platform_set_drvdata(pdev, hub); + pm_runtime_always_allow(&pdev->dev); pm_runtime_enable(&pdev->dev); INIT_LIST_HEAD(&hub->client.list); diff --git a/drivers/gpu/drm/tegra/sor.c b/drivers/gpu/drm/tegra/sor.c index a68d3b36b972..20058f11bf81 100644 --- a/drivers/gpu/drm/tegra/sor.c +++ b/drivers/gpu/drm/tegra/sor.c @@ -3833,6 +3833,7 @@ static int tegra_sor_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, sor); + pm_runtime_always_allow(&pdev->dev); pm_runtime_enable(&pdev->dev); /*