From: Marco Felsch <m.felsch@pengutronix.de>
To: Vinod Koul <vkoul@kernel.org>, Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Jiada Wang <jiada_wang@mentor.com>, Frank Li <Frank.Li@nxp.com>
Cc: dmaengine@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Marco Felsch <m.felsch@pengutronix.de>
Subject: [PATCH 1/2] dmaengine: add device_link support
Date: Fri, 12 Sep 2025 00:00:41 +0200 [thread overview]
Message-ID: <20250912-v6-16-topic-dma-devlink-v1-1-4debc2fbf901@pengutronix.de> (raw)
In-Reply-To: <20250912-v6-16-topic-dma-devlink-v1-0-4debc2fbf901@pengutronix.de>
Shift the device dependency handling to the driver core by adding
support for devlinks.
The link between the consumer device and the dmaengine device is
established by the consumer via the dma_request_chan() automatically if
the dmaengine driver supports it (create_devlink flag set).
By adding the devlink support it is ensured that the supplier can't be
removed while the consumer still uses the dmaengine. Furthermore it
ensures that the supplier driver is present and actual bound before the
consumer is uses the supplier.
Additional PM and runtime-PM dependency handling can be added easily too
by setting the required flags (not implemented by this commit).
The new create_devlink flag controlls the devlink creation to not cause
any regressions with existing dmaengine drivers. This flag can be
removed once all drivers are successfully tested to support devlinks.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
drivers/dma/dmaengine.c | 15 +++++++++++++++
include/linux/dmaengine.h | 3 +++
2 files changed, 18 insertions(+)
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 758fcd0546d8bde8e8dddc6039848feeb1e24475..e81985ab806ae87ff3aa4739fe6f6328b2587f2e 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -858,6 +858,21 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name)
/* No functional issue if it fails, users are supposed to test before use */
#endif
+ /*
+ * Devlinks between the dmaengine device and the consumer device
+ * are optional till all dmaengine drivers are converted/tested.
+ */
+ if (chan->device->create_devlink) {
+ struct device_link *dl;
+
+ dl = device_link_add(dev, chan->device->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
+ if (!dl) {
+ dev_err(dev, "failed to create device link to %s\n",
+ dev_name(chan->device->dev));
+ return ERR_PTR(-EINVAL);
+ }
+ }
+
chan->name = kasprintf(GFP_KERNEL, "dma:%s", name);
if (!chan->name)
return chan;
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index bb146c5ac3e4ccd7bc0afbf3b28e5b3d659ad62f..c67737a358df659f2bf050a9ccb8d23b17ceb357 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -817,6 +817,8 @@ struct dma_filter {
* DMA tansaction with no software intervention for reinitialization.
* Zero value means unlimited number of entries.
* @descriptor_reuse: a submitted transfer can be resubmitted after completion
+ * @create_devlink: create a devlink between a dma_chan_dev supplier and
+ * dma-channel consumer device
* @residue_granularity: granularity of the transfer residue reported
* by tx_status
* @device_alloc_chan_resources: allocate resources and return the
@@ -894,6 +896,7 @@ struct dma_device {
u32 max_burst;
u32 max_sg_burst;
bool descriptor_reuse;
+ bool create_devlink;
enum dma_residue_granularity residue_granularity;
int (*device_alloc_chan_resources)(struct dma_chan *chan);
--
2.47.3
next prev parent reply other threads:[~2025-09-11 22:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-11 22:00 [PATCH 0/2] Add DMA devlink support Marco Felsch
2025-09-11 22:00 ` Marco Felsch [this message]
2025-09-25 16:31 ` [PATCH 1/2] dmaengine: add device_link support Frank Li
2025-10-27 1:11 ` Laurent Pinchart
2025-10-27 18:59 ` Frank Li
2025-09-11 22:00 ` [PATCH 2/2] dmaengine: imx-sdma: fix supplier/consumer dependency handling Marco Felsch
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=20250912-v6-16-topic-dma-devlink-v1-1-4debc2fbf901@pengutronix.de \
--to=m.felsch@pengutronix.de \
--cc=Frank.Li@nxp.com \
--cc=dmaengine@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=jiada_wang@mentor.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=vkoul@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