From: Sven Peter <sven@svenpeter.dev>
To: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@fb.com>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>
Cc: Sven Peter <sven@svenpeter.dev>, Hector Martin <marcan@marcan.st>,
Alyssa Rosenzweig <alyssa@rosenzweig.io>,
Rob Herring <robh+dt@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Marc Zyngier <maz@kernel.org>,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org
Subject: [PATCH 8/9] nvme-apple: Add support for multiple power domains
Date: Mon, 21 Mar 2022 17:50:48 +0100 [thread overview]
Message-ID: <20220321165049.35985-9-sven@svenpeter.dev> (raw)
In-Reply-To: <20220321165049.35985-1-sven@svenpeter.dev>
From: Hector Martin <marcan@marcan.st>
Turns out we really need this, as the APCIE_ST*_SYS domains really do
hard-depend on ANS2, at least on t6000.
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
drivers/nvme/host/apple.c | 67 +++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c
index a4193429564e..d89b4ab80169 100644
--- a/drivers/nvme/host/apple.c
+++ b/drivers/nvme/host/apple.c
@@ -29,6 +29,7 @@
#include <linux/of_platform.h>
#include <linux/once.h>
#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
#include <linux/soc/apple/rtkit.h>
#include <linux/soc/apple/sart.h>
#include <linux/reset.h>
@@ -178,6 +179,10 @@ struct apple_nvme {
void __iomem *mmio_coproc;
void __iomem *mmio_nvme;
+ struct device **pd_dev;
+ struct device_link **pd_link;
+ int pd_count;
+
struct apple_sart *sart;
struct apple_rtkit *rtk;
struct reset_control *reset;
@@ -1313,6 +1318,62 @@ static int apple_nvme_queue_alloc(struct apple_nvme *anv,
return 0;
}
+static void apple_nvme_detach_genpd(struct apple_nvme *anv)
+{
+ int i;
+
+ if (anv->pd_count <= 1)
+ return;
+
+ for (i = anv->pd_count - 1; i >= 0; i--) {
+ if (anv->pd_link[i])
+ device_link_del(anv->pd_link[i]);
+ if (!IS_ERR_OR_NULL(anv->pd_dev[i]))
+ dev_pm_domain_detach(anv->pd_dev[i], true);
+ }
+}
+
+static int apple_nvme_attach_genpd(struct apple_nvme *anv)
+{
+ struct device *dev = anv->dev;
+ int i;
+
+ anv->pd_count = of_count_phandle_with_args(dev->of_node,
+ "power-domains",
+ "#power-domain-cells");
+ if (anv->pd_count <= 1)
+ return 0;
+
+ anv->pd_dev = devm_kcalloc(dev, anv->pd_count, sizeof(*anv->pd_dev),
+ GFP_KERNEL);
+ if (!anv->pd_dev)
+ return -ENOMEM;
+
+ anv->pd_link = devm_kcalloc(dev, anv->pd_count, sizeof(*anv->pd_link),
+ GFP_KERNEL);
+ if (!anv->pd_link)
+ return -ENOMEM;
+
+ for (i = 0; i < anv->pd_count; i++) {
+ anv->pd_dev[i] = dev_pm_domain_attach_by_id(dev, i);
+ if (IS_ERR(anv->pd_dev[i])) {
+ apple_nvme_detach_genpd(anv);
+ return PTR_ERR(anv->pd_dev[i]);
+ }
+
+ anv->pd_link[i] = device_link_add(dev, anv->pd_dev[i],
+ DL_FLAG_STATELESS |
+ DL_FLAG_PM_RUNTIME |
+ DL_FLAG_RPM_ACTIVE);
+ if (!anv->pd_link[i]) {
+ apple_nvme_detach_genpd(anv);
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
static int apple_nvme_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -1327,6 +1388,10 @@ static int apple_nvme_probe(struct platform_device *pdev)
anv->adminq.is_adminq = true;
platform_set_drvdata(pdev, anv);
+ ret = apple_nvme_attach_genpd(anv);
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Failed to attach power domains");
+
if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)))
return -ENXIO;
@@ -1435,6 +1500,8 @@ static int apple_nvme_remove(struct platform_device *pdev)
if (apple_rtkit_is_running(anv->rtk))
apple_rtkit_shutdown(anv->rtk);
+ apple_nvme_detach_genpd(anv);
+
return 0;
}
--
2.25.1
next prev parent reply other threads:[~2022-03-21 16:52 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-21 16:50 [PATCH 0/9] Apple M1 (Pro/Max) NVMe driver Sven Peter
2022-03-21 16:50 ` [PATCH 1/9] dt-bindings: soc: apple: Add Apple SART Sven Peter
2022-03-31 21:23 ` Rob Herring
2022-04-02 12:58 ` Sven Peter
2022-03-21 16:50 ` [PATCH 2/9] dt-bindings: soc: apple: Add ANS NVMe Sven Peter
2022-03-23 11:14 ` Krzysztof Kozlowski
2022-04-02 13:05 ` Sven Peter
2022-04-02 16:06 ` Krzysztof Kozlowski
2022-03-21 16:50 ` [PATCH 3/9] soc: apple: Always include Makefile Sven Peter
2022-03-21 16:50 ` [PATCH 4/9] soc: apple: Add SART driver Sven Peter
2022-03-21 17:07 ` Arnd Bergmann
2022-04-02 12:38 ` Sven Peter
2022-04-02 19:07 ` Arnd Bergmann
2022-04-04 14:58 ` Rob Herring
2022-04-04 15:01 ` Hector Martin
2022-04-05 15:37 ` Sven Peter
2022-03-21 17:17 ` Alyssa Rosenzweig
2022-04-02 12:40 ` Sven Peter
2022-03-21 16:50 ` [PATCH 5/9] soc: apple: Add RTKit IPC library Sven Peter
2022-03-22 13:13 ` Arnd Bergmann
2022-03-22 17:41 ` Robin Murphy
2022-04-02 12:56 ` Sven Peter
2022-04-02 18:30 ` Arnd Bergmann
2022-04-03 10:45 ` Sven Peter
2022-03-22 17:23 ` Alyssa Rosenzweig
2022-04-02 12:50 ` Sven Peter
2022-03-23 11:19 ` Krzysztof Kozlowski
2022-04-02 13:51 ` Sven Peter
2022-04-02 16:08 ` Krzysztof Kozlowski
2022-04-04 15:02 ` Rob Herring
2022-04-04 15:47 ` Hector Martin
2022-03-21 16:50 ` [PATCH 6/9] nvme-apple: Add initial Apple SoC NVMe driver Sven Peter
2022-03-21 17:01 ` Keith Busch
2022-04-02 13:10 ` Sven Peter
2022-03-22 13:38 ` Arnd Bergmann
2022-04-02 13:34 ` Sven Peter
2022-04-02 13:58 ` Janne Grunau
2022-04-02 14:02 ` Sven Peter
2022-04-02 21:26 ` Arnd Bergmann
2022-03-24 6:16 ` Christoph Hellwig
2022-04-02 12:47 ` Sven Peter
2022-04-04 15:57 ` Hector Martin
2022-04-04 15:59 ` Christoph Hellwig
2022-04-04 16:03 ` Sven Peter
2022-04-04 16:05 ` hch
2022-04-04 16:05 ` Hector Martin
2022-04-04 18:29 ` Jens Axboe
2022-04-05 6:24 ` Christoph Hellwig
2022-03-21 16:50 ` [PATCH 7/9] nvme-apple: Serialize command issue Sven Peter
2022-03-24 6:16 ` Christoph Hellwig
2022-04-02 12:42 ` Sven Peter
2022-03-21 16:50 ` Sven Peter [this message]
2022-03-21 16:50 ` [PATCH 9/9] nvme-apple: Add support for suspend/resume Sven Peter
2022-03-24 6:17 ` Christoph Hellwig
2022-03-22 17:26 ` [PATCH 0/9] Apple M1 (Pro/Max) NVMe driver Alyssa Rosenzweig
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=20220321165049.35985-9-sven@svenpeter.dev \
--to=sven@svenpeter.dev \
--cc=alyssa@rosenzweig.io \
--cc=arnd@arndb.de \
--cc=axboe@fb.com \
--cc=devicetree@vger.kernel.org \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=marcan@marcan.st \
--cc=maz@kernel.org \
--cc=robh+dt@kernel.org \
--cc=sagi@grimberg.me \
/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;
as well as URLs for NNTP newsgroup(s).