mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Sven Peter" <sven@svenpeter.dev>
To: "Hector Martin" <marcan@marcan.st>,
	"Joerg Roedel" <joro@8bytes.org>, "Will Deacon" <will@kernel.org>,
	"Robin Murphy" <robin.murphy@arm.com>
Cc: "Alyssa Rosenzweig" <alyssa@rosenzweig.io>,
	asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iommu: dart: Add suspend/resume support
Date: Mon, 05 Dec 2022 15:09:56 +0100	[thread overview]
Message-ID: <b02fdcce-b2cf-466e-83df-688f35348b86@app.fastmail.com> (raw)
In-Reply-To: <20221205100907.10230-1-marcan@marcan.st>

Hi,

On Mon, Dec 5, 2022, at 11:09, Hector Martin wrote:
> We need to save/restore the TCR/TTBR registers, since they are lost
> on power gate.
>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> ---
>  drivers/iommu/apple-dart.c | 50 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
>
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> index 4f4a323be0d0..ed524765ad87 100644
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
> @@ -121,6 +121,9 @@ struct apple_dart {
> 
>  	struct iommu_group *sid2group[DART_MAX_STREAMS];
>  	struct iommu_device iommu;
> +
> +	u32 save_tcr[DART_MAX_STREAMS];
> +	u32 save_ttbr[DART_MAX_STREAMS][DART_MAX_TTBR];
>  };
> 
>  /*
> @@ -932,6 +935,50 @@ static const struct apple_dart_hw apple_dart_hw_t6000 = {
>  	.fmt = APPLE_DART2,
>  };
> 
> +#ifdef CONFIG_PM_SLEEP
> +static int apple_dart_suspend(struct device *dev)
> +{
> +	struct apple_dart *dart = dev_get_drvdata(dev);
> +	unsigned int sid, idx;
> +
> +	for (sid = 0; sid < DART_MAX_STREAMS; sid++) {
> +		dart->save_tcr[sid] = readl_relaxed(dart->regs + DART_TCR(sid));
> +		for (idx = 0; idx < DART_MAX_TTBR; idx++)
> +			dart->save_ttbr[sid][idx] =
> +				readl_relaxed(dart->regs + DART_TTBR(sid, idx));

The rest of the driver uses the non-relaxed variants and I'd use the
same here (and further below) to be consistent.


> +	}
> +
> +	return 0;
> +}
> +
> +static int apple_dart_resume(struct device *dev)
> +{
> +	struct apple_dart *dart = dev_get_drvdata(dev);
> +	unsigned int sid, idx;
> +	int ret;
> +
> +	ret = apple_dart_hw_reset(dart);
> +	if (ret) {
> +		dev_err(dev, "Failed to reset DART on resume\n");
> +		return ret;
> +	}
> +
> +	for (sid = 0; sid < DART_MAX_STREAMS; sid++) {
> +		for (idx = 0; idx < DART_MAX_TTBR; idx++)
> +			writel_relaxed(dart->save_ttbr[sid][idx],
> +				       dart->regs + DART_TTBR(sid, idx));
> +		writel_relaxed(dart->save_tcr[sid], dart->regs + DART_TCR(sid));
> +	}
> +
> +	return 0;
> +}
> +
> +static const struct dev_pm_ops apple_dart_pm_ops = {
> +	.suspend	= apple_dart_suspend,
> +	.resume		= apple_dart_resume,
> +};
> +#endif

You can use DEFINE_SIMPLE_DEV_PM_OPS here and then ...

> +
>  static const struct of_device_id apple_dart_of_match[] = {
>  	{ .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 },
>  	{ .compatible = "apple,t6000-dart", .data = &apple_dart_hw_t6000 },
> @@ -944,6 +991,9 @@ static struct platform_driver apple_dart_driver = {
>  		.name			= "apple-dart",
>  		.of_match_table		= apple_dart_of_match,
>  		.suppress_bind_attrs    = true,
> +#ifdef CONFIG_PM_SLEEP
> +		.pm			= &apple_dart_pm_ops,

... pm_sleep_ptr() here to get rid of these #ifdefs like e.g. in our nvme
driver.


With those things addressed:

Reviewed-by: Sven Peter <sven@svenpeter.dev>


Sven

      parent reply	other threads:[~2022-12-05 14:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05 10:09 Hector Martin
2022-12-05 14:04 ` Robin Murphy
2022-12-05 14:09 ` Sven Peter [this message]

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=b02fdcce-b2cf-466e-83df-688f35348b86@app.fastmail.com \
    --to=sven@svenpeter.dev \
    --cc=alyssa@rosenzweig.io \
    --cc=asahi@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcan@marcan.st \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /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®