mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Cc: Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
	Jonathan Corbet <corbet@lwn.net>,
	Russell King <linux@arm.linux.org.uk>,
	Dan Williams <dan.j.williams@intel.com>,
	Vinod Koul <vinod.koul@intel.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	linux-pm@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	Lars-Peter Clausen <lars@metafoo.de>,
	Michal Simek <michal.simek@xilinx.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Subject: Re: [PATCH v8 3/5] amba: Don't unprepare the clocks if device driver wants IRQ safe runtime PM
Date: Sat, 01 Nov 2014 01:45:47 +0100	[thread overview]
Message-ID: <1479283.dvHduzBoyf@vostro.rjw.lan> (raw)
In-Reply-To: <1413795888-18559-4-git-send-email-k.kozlowski@samsung.com>

On Monday, October 20, 2014 11:04:46 AM Krzysztof Kozlowski wrote:
> The AMBA bus driver defines runtime Power Management functions which
> disable and unprepare AMBA bus clock. This is problematic for runtime PM
> because unpreparing a clock might sleep so it is not interrupt safe.
> 
> However some drivers may want to implement runtime PM functions in
> interrupt-safe way (see pm_runtime_irq_safe()). In such case the AMBA
> bus driver should only disable/enable the clock in runtime suspend and
> resume callbacks.
> 
> Detect the device driver behavior after calling its probe function and
> store it. During runtime suspend/resume deal with clocks according to
> stored value.
> 
> Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
>  drivers/amba/bus.c       | 29 +++++++++++++++++++++++++----
>  include/linux/amba/bus.h |  1 +
>  2 files changed, 26 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
> index 47bbdc1b5be3..474434e1b1b9 100644
> --- a/drivers/amba/bus.c
> +++ b/drivers/amba/bus.c
> @@ -95,8 +95,18 @@ static int amba_pm_runtime_suspend(struct device *dev)
>  	struct amba_device *pcdev = to_amba_device(dev);
>  	int ret = pm_generic_runtime_suspend(dev);
>  
> -	if (ret == 0 && dev->driver)
> -		clk_disable_unprepare(pcdev->pclk);
> +	if (ret == 0 && dev->driver) {
> +		/*
> +		 * Drivers should not change pm_runtime_irq_safe()
> +		 * after probe.
> +		 */
> +		WARN_ON(pcdev->irq_safe != pm_runtime_is_irq_safe(dev));
> +
> +		if (pcdev->irq_safe)
> +			clk_disable(pcdev->pclk);
> +		else
> +			clk_disable_unprepare(pcdev->pclk);
> +	}
>  
>  	return ret;
>  }
> @@ -107,7 +117,16 @@ static int amba_pm_runtime_resume(struct device *dev)
>  	int ret;
>  
>  	if (dev->driver) {
> -		ret = clk_prepare_enable(pcdev->pclk);
> +		/*
> +		 * Drivers should not change pm_runtime_irq_safe()
> +		 * after probe.
> +		 */
> +		WARN_ON(pcdev->irq_safe != pm_runtime_is_irq_safe(dev));
> +
> +		if (pcdev->irq_safe)
> +			ret = clk_enable(pcdev->pclk);
> +		else
> +			ret = clk_prepare_enable(pcdev->pclk);
>  		/* Failure is probably fatal to the system, but... */
>  		if (ret)
>  			return ret;
> @@ -198,8 +217,10 @@ static int amba_probe(struct device *dev)
>  		pm_runtime_enable(dev);
>  
>  		ret = pcdrv->probe(pcdev, id);
> -		if (ret == 0)
> +		if (ret == 0) {
> +			pcdev->irq_safe = pm_runtime_is_irq_safe(dev);

This looks racy.

Is it guaranteed that runtime PM callbacks won't be run for the device
after pcdrv->probe() has returned and before setting pcdev->irq_safe?
If not, inconsistent behavior may ensue.

>  			break;
> +		}
>  
>  		pm_runtime_disable(dev);
>  		pm_runtime_set_suspended(dev);
> diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
> index ac02f9bd63dc..c4bae79851fb 100644
> --- a/include/linux/amba/bus.h
> +++ b/include/linux/amba/bus.h
> @@ -32,6 +32,7 @@ struct amba_device {
>  	struct clk		*pclk;
>  	unsigned int		periphid;
>  	unsigned int		irq[AMBA_NR_IRQS];
> +	unsigned int		irq_safe:1;
>  };
>  
>  struct amba_driver {
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

  reply	other threads:[~2014-11-01  0:25 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-20  9:04 [PATCH v8 0/5] amba/dma: pl330: add Power Management support Krzysztof Kozlowski
2014-10-20  9:04 ` [PATCH v8 1/5] PM / Runtime: Add getter for querying the IRQ safe option Krzysztof Kozlowski
2014-10-31  9:14   ` Krzysztof Kozlowski
2014-10-31  9:29     ` Ulf Hansson
2014-10-31  9:33       ` Russell King - ARM Linux
2014-10-31  9:54         ` Ulf Hansson
2014-10-31  9:33       ` Krzysztof Kozlowski
2014-10-31 14:22     ` Pavel Machek
2014-10-31 14:40       ` Krzysztof Kozlowski
2014-11-01  0:29         ` Laurent Pinchart
2014-11-03  9:36           ` Krzysztof Kozlowski
2014-11-03 16:27           ` Vinod Koul
2014-11-03 16:59             ` Laurent Pinchart
2014-11-05 14:09               ` Vinod Koul
2014-11-03 17:04             ` Russell King - ARM Linux
2014-11-05 14:04               ` Vinod Koul
2014-11-05 14:54               ` Laurent Pinchart
2014-10-31 23:11   ` Rafael J. Wysocki
2014-10-31 23:04     ` Russell King - ARM Linux
2014-11-01  0:42       ` Rafael J. Wysocki
2014-11-03  8:51         ` Krzysztof Kozlowski
2014-10-20  9:04 ` [PATCH v8 2/5] amba: Add helpers for (un)preparing AMBA clock Krzysztof Kozlowski
2014-10-21  8:05   ` Ulf Hansson
2014-10-20  9:04 ` [PATCH v8 3/5] amba: Don't unprepare the clocks if device driver wants IRQ safe runtime PM Krzysztof Kozlowski
2014-11-01  0:45   ` Rafael J. Wysocki [this message]
2014-11-01  0:55     ` Russell King - ARM Linux
2014-11-01  1:01       ` Russell King - ARM Linux
2014-11-03  8:36         ` Krzysztof Kozlowski
2014-11-03 10:04           ` Russell King - ARM Linux
2014-11-03 15:41             ` Alan Stern
2014-11-03 15:44               ` Russell King - ARM Linux
2014-11-04  7:59                 ` Krzysztof Kozlowski
2014-11-04  1:57               ` Rafael J. Wysocki
2014-11-04  8:01                 ` Krzysztof Kozlowski
2014-11-04  9:11                 ` Ulf Hansson
2014-11-04 13:59                   ` Rafael J. Wysocki
2014-11-04 16:19                     ` Ulf Hansson
2014-11-03 17:17         ` Kevin Hilman
2014-10-20  9:04 ` [PATCH v8 4/5] dma: pl330: add Power Management support Krzysztof Kozlowski
2014-10-20  9:04 ` [PATCH v8 5/5] amba: Remove unused amba_pclk_enable/disable macros Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479283.dvHduzBoyf@vostro.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=b.zolnierkie@samsung.com \
    --cc=corbet@lwn.net \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=k.kozlowski@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=lars@metafoo.de \
    --cc=len.brown@intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=michal.simek@xilinx.com \
    --cc=pavel@ucw.cz \
    --cc=stern@rowland.harvard.edu \
    --cc=ulf.hansson@linaro.org \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®