From: Logan Gunthorpe <logang@deltatee.com>
To: dmaengine@vger.kernel.org, Vinod Koul <vkoul@kernel.org>
Cc: "Frank Li" <Frank.li@nxp.com>,
"Christoph Hellwig" <hch@infradead.org>,
"Christophe Jaillet" <christophe.jaillet@wanadoo.fr>,
"Dave Jiang" <dave.jiang@intel.com>,
"Thomas Weißschuh" <linux@weissschuh.net>,
"Kelvin Cao" <kelvin.cao@microchip.com>,
"Logan Gunthorpe" <logang@deltatee.com>
Subject: [PATCH v1 1/5] dmaengine: add support for custom per-channel sysfs attributes
Date: Tue, 7 Jul 2026 10:20:41 -0600 [thread overview]
Message-ID: <20260707162045.23910-2-logang@deltatee.com> (raw)
In-Reply-To: <20260707162045.23910-1-logang@deltatee.com>
Add specific support for adding sysfs attributes to channels.
This will be used to replace similar functionality in ioat so it can
be used in other drivers.
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
---
drivers/dma/dmaengine.c | 62 +++++++++++++++++++++++++++++++++++++++
drivers/dma/dmaengine.h | 11 +++++++
include/linux/dmaengine.h | 3 ++
3 files changed, 76 insertions(+)
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 9049171df857..7ea2a8709c07 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -125,6 +125,63 @@ static int dmaengine_summary_show(struct seq_file *s, void *data)
}
DEFINE_SHOW_ATTRIBUTE(dmaengine_summary);
+static ssize_t
+dma_chan_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
+{
+ const struct dma_chan_sysfs_entry *entry;
+ struct dma_chan *dma_chan;
+
+ entry = container_of_const(attr, struct dma_chan_sysfs_entry, attr);
+ dma_chan = container_of(kobj, struct dma_chan, kobj);
+
+ if (!entry->show)
+ return -EIO;
+
+ return entry->show(dma_chan, page);
+}
+
+static ssize_t
+dma_chan_attr_store(struct kobject *kobj, struct attribute *attr,
+ const char *page, size_t count)
+{
+ const struct dma_chan_sysfs_entry *entry;
+ struct dma_chan *dma_chan;
+
+ entry = container_of_const(attr, struct dma_chan_sysfs_entry, attr);
+ dma_chan = container_of(kobj, struct dma_chan, kobj);
+
+ if (!entry->store)
+ return -EIO;
+
+ return entry->store(dma_chan, page, count);
+}
+
+const struct sysfs_ops dma_chan_sysfs_ops = {
+ .show = dma_chan_attr_show,
+ .store = dma_chan_attr_store,
+};
+EXPORT_SYMBOL_GPL(dma_chan_sysfs_ops);
+
+void dma_chan_kobject_add(struct dma_device *dev, const struct kobj_type *type,
+ const char *name)
+{
+ struct dma_chan *chan;
+ int err;
+
+ list_for_each_entry(chan, &dev->channels, device_node) {
+ chan->kobj_used = true;
+ err = kobject_init_and_add(&chan->kobj, type,
+ &chan->dev->device.kobj, name);
+ if (err) {
+ dev_warn(dev->dev,
+ "sysis init error(%d), continuinng...\n", err);
+ kobject_put(&chan->kobj);
+ chan->kobj_used = false;
+ }
+ }
+}
+EXPORT_SYMBOL_GPL(dma_chan_kobject_add);
+
static void __init dmaengine_debugfs_init(void)
{
rootdir = debugfs_create_dir("dmaengine", NULL);
@@ -1143,6 +1200,11 @@ static void __dma_async_device_channel_unregister(struct dma_device *device,
if (chan->local == NULL)
return;
+ if (chan->kobj_used) {
+ kobject_del(&chan->kobj);
+ kobject_put(&chan->kobj);
+ }
+
WARN_ONCE(!device->device_release && chan->client_count,
"%s called while %d clients hold a reference\n",
__func__, chan->client_count);
diff --git a/drivers/dma/dmaengine.h b/drivers/dma/dmaengine.h
index 53f16d3f0029..496cac056350 100644
--- a/drivers/dma/dmaengine.h
+++ b/drivers/dma/dmaengine.h
@@ -182,6 +182,17 @@ dmaengine_desc_callback_valid(struct dmaengine_desc_callback *cb)
struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
+struct dma_chan_sysfs_entry {
+ struct attribute attr;
+ ssize_t (*show)(struct dma_chan *chan, char *page);
+ ssize_t (*store)(struct dma_chan *chan, const char *page, size_t count);
+};
+
+extern const struct sysfs_ops dma_chan_sysfs_ops;
+
+void dma_chan_kobject_add(struct dma_device *dev, const struct kobj_type *type,
+ const char *name);
+
#ifdef CONFIG_DEBUG_FS
#include <linux/debugfs.h>
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index b3d251c9734e..852943ef46b8 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -358,6 +358,9 @@ struct dma_chan {
struct dma_router *router;
void *route_data;
+ bool kobj_used;
+ struct kobject kobj;
+
void *private;
};
--
2.47.3
next prev parent reply other threads:[~2026-07-07 16:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 16:20 [PATCH v1 0/5] Add sysfs interface to switchtec-dma Logan Gunthorpe
2026-07-07 16:20 ` Logan Gunthorpe [this message]
2026-07-07 16:54 ` [PATCH v1 1/5] dmaengine: add support for custom per-channel sysfs attributes sashiko-bot
2026-07-07 16:20 ` [PATCH v1 2/5] dmaengine: ioatdma: use common channel sysfs attribute creation Logan Gunthorpe
2026-07-07 16:48 ` Dave Jiang
2026-07-07 16:59 ` sashiko-bot
2026-07-07 16:20 ` [PATCH v1 3/5] dmaengine: switchtec-dma: Add config sysfs attributes Logan Gunthorpe
2026-07-07 16:55 ` sashiko-bot
2026-07-07 16:20 ` [PATCH v1 4/5] dmaengine: switchtec-dma: Add pmon " Logan Gunthorpe
2026-07-07 16:58 ` sashiko-bot
2026-07-07 16:20 ` [PATCH v1 5/5] dmaengine: switchtec-dma: Add PCI1008 device ID Logan Gunthorpe
2026-07-07 16:53 ` sashiko-bot
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=20260707162045.23910-2-logang@deltatee.com \
--to=logang@deltatee.com \
--cc=Frank.li@nxp.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dave.jiang@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=hch@infradead.org \
--cc=kelvin.cao@microchip.com \
--cc=linux@weissschuh.net \
--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