Skip to contentSkip to conversation

dma: DMA slave device bringup tool

RFC PATCH In review Alexander Gordeev 3 participants 8 messages Feb 21 – Feb 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover dma: DMA slave device bringup tool

Hi All,

This is a custom tool that can be used to bring up DMA slave devices. It consists of a user-level utility and a companion device driver that communicate via IOCTL.

The tool is likely need some polishing, but I would like first get some feedback to ensure there is interest.

I also tested it only on x86 and have little idea on how channel names on other architectures look like. That could especially impact the way dma_request_channel() treats user-provided target DMA channel names, as exposed via /sys/class/dma.

Thanks!

Alexander Gordeev (2):
dmaengine/dma-slave: DMA slave device xfer passthrough driver tools/dma-slave: DMA slave device transfer utility

 drivers/dma/Kconfig            |   7 +
 drivers/dma/Makefile           |   1 +
 drivers/dma/dma-slave.c        | 246 +++++++++++++++++++++++++
 include/uapi/linux/dma-slave.h |  30 +++
 tools/Makefile                 |  11 +-
 tools/dma/Makefile             |  20 ++
 tools/dma/dma-slave.c          | 321 +++++++++++++++++++++++++++++++++
 7 files changed, 631 insertions(+), 5 deletions(-)
 create mode 100644 drivers/dma/dma-slave.c
 create mode 100644 include/uapi/linux/dma-slave.h
 create mode 100644 tools/dma/Makefile
 create mode 100644 tools/dma/dma-slave.c
Signature · 1 line
2.51.0
#1 lore raw

RFC PATCH 1/2 dmaengine/dma-slave: DMA slave device xfer passthrough driver

This is a driver to help bringing up or debug DMA slave devices. A target device should expose itself as DMA_SLAVE to be able get found by dma_request_channel() service. It is located by the name as exposed in /sys/class/dma.

The ioctl() caller is expected to map a file in user space and provide the mapping address along with DMA transfer parameters. The driver sets up and triggers a single the DMA transfer using zero-copy approach.

The DMA transfer parameters are not sanitized in any way and the ioctl() caller is expected to be the device-aware.

In other words, considering the DMA transfer parameters and the data itself this introduces a DMA passthrough driver.

---
 drivers/dma/Kconfig            |   7 +
 drivers/dma/Makefile           |   1 +
 drivers/dma/dma-slave.c        | 246 +++++++++++++++++++++++++++++++++
 include/uapi/linux/dma-slave.h |  30 ++++
 4 files changed, 284 insertions(+)
 create mode 100644 drivers/dma/dma-slave.c
 create mode 100644 include/uapi/linux/dma-slave.h
drivers/dma/Kconfig +7 -0
index 4d0946f92edf..03808df52f4b 100644
@@ -801,6 +801,13 @@ config DMATEST
 	  Simple DMA test client. Say N unless you're debugging a
 	  DMA Device driver.
 
+config DMA_SLAVE
+	tristate "DMA Slave Test client"
+	depends on DMA_ENGINE
+	help
+	  Simple DMA Passthrough Slave test client. Say N unless you're
+	  debugging a DMA Device driver.
+
 config DMA_ENGINE_RAID
 	bool
 
drivers/dma/Makefile +1 -0
index a6535b2310bb..f52a2d525e8b 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_DMA_OF) += of-dma.o
 
 #dmatest
 obj-$(CONFIG_DMATEST) += dmatest.o
+obj-$(CONFIG_DMA_SLAVE) += dma-slave.o
 
 #devices
 obj-$(CONFIG_ALTERA_MSGDMA) += altera-msgdma.o
drivers/dma/dma-slave.c new file +246 -0

246 lines not on this page · raw message

include/uapi/linux/dma-slave.h new file +30 -0
new file mode 100644
index 000000000000..e3da14d4224e
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2026 Alexander Gordeev <[email protected]>
+ */
+#ifndef _UAPI_LINUX_DMA_SLAVE_H__
+#define _UAPI_LINUX_DMA_SLAVE_H__
+
+#define DMA_SLAVE_DEVICE		"dma-slave"
+
+struct dma_slave_config_uapi {
+	struct iovec data;
+	struct iovec peripheral_config;
+	__u64 src_addr;
+	__u64 dst_addr;
+	__u32 src_addr_width;
+	__u32 dst_addr_width;
+	__u32 src_maxburst;
+	__u32 dst_maxburst;
+	__u32 src_port_window_size;
+	__u32 dst_port_window_size;
+	bool device_fc;
+	char channel_name[32];
+};
+
+#define DMA_SLAVE_SIG 'S'
+
+#define IOCTL_DMA_SLAVE_READ		_IOR(DMA_SLAVE_SIG, 0, struct dma_slave_config_uapi)
+#define IOCTL_DMA_SLAVE_WRITE		_IOW(DMA_SLAVE_SIG, 1, struct dma_slave_config_uapi)
+
+#endif
Signature · 1 line
2.51.0
#2 lore raw

RFC PATCH 2/2 tools/dma-slave: DMA slave device transfer utility

In reply to Alexander Gordeev

A utility to pass user data through a DMA slave device. It is intended for bringing up and debugging DMA devices.

The tool writes the contents of a binary file to, or reads from, the companion dma-slave device driver, which must be loaded.

The contents of an input file to be transferred can be prepared to trigger specific target device behavior on writes.

For read operations, the output file contents can be examined using user-level tools to detect transfer integrity issues.

The DMA transfer parameters are provided via command-line arguments and are not sanitized in any way. These parameters are used as-is to initialize a dma_slave_config instance passed to dmaengine_slave_config().

An additional file may be provided as peripheral configuration data for the DMA transfer. In this case, dma_slave_config::peripheral_config and dma_slave_config::peripheral_size members are populated from the file contents and its size.

---
 tools/Makefile        |  11 +-
 tools/dma/Makefile    |  20 +++
 tools/dma/dma-slave.c | 321 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 347 insertions(+), 5 deletions(-)
 create mode 100644 tools/dma/Makefile
 create mode 100644 tools/dma/dma-slave.c
tools/Makefile +6 -5
index c31cbbd12c45..2c52bf7bc899 100644
@@ -14,6 +14,7 @@ help:
 	@echo '  counter                - counter tools'
 	@echo '  cpupower               - a tool for all things x86 CPU power'
 	@echo '  debugging              - tools for debugging'
+	@echo '  dma                    - DMA tools'
 	@echo '  firewire               - the userspace part of nosy, an IEEE-1394 traffic sniffer'
 	@echo '  firmware               - Firmware tools'
 	@echo '  freefall               - laptop accelerometer program for disk protection'
@@ -69,7 +70,7 @@ acpi: FORCE
 cpupower: FORCE
 	$(call descend,power/$@)
 
-counter firewire hv guest bootconfig spi usb virtio mm bpf iio gpio objtool leds wmi firmware debugging tracing: FORCE
+counter firewire hv guest bootconfig spi usb virtio mm bpf iio gpio objtool leds wmi firmware debugging tracing dma: FORCE
 	$(call descend,$@)
 
 bpf/%: FORCE
@@ -122,7 +123,7 @@ kvm_stat: FORCE
 ynl: FORCE
 	$(call descend,net/ynl)
 
-all: acpi counter cpupower gpio hv firewire \
+all: acpi counter cpupower dma gpio hv firewire \
 		perf selftests bootconfig spi turbostat usb \
 		virtio mm bpf x86_energy_perf_policy \
 		tmon freefall iio objtool kvm_stat wmi \
@@ -134,7 +135,7 @@ acpi_install:
 cpupower_install:
 	$(call descend,power/$(@:_install=),install)
 
-counter_install firewire_install gpio_install hv_install iio_install perf_install bootconfig_install spi_install usb_install virtio_install mm_install bpf_install objtool_install wmi_install debugging_install tracing_install:
+counter_install firewire_install gpio_install hv_install iio_install perf_install bootconfig_install spi_install usb_install virtio_install mm_install bpf_install objtool_install wmi_install debugging_install tracing_install dma_install:
 	$(call descend,$(@:_install=),install)
 
 selftests_install:
@@ -165,7 +166,7 @@ ynl_install:
 	$(call descend,net/$(@:_install=),install)
 
 install: acpi_install counter_install cpupower_install gpio_install \
-		hv_install firewire_install iio_install \
+		hv_install firewire_install iio_install dma_install \
 		perf_install selftests_install turbostat_install usb_install \
 		virtio_install mm_install bpf_install x86_energy_perf_policy_install \
 		tmon_install freefall_install objtool_install kvm_stat_install \
@@ -178,7 +179,7 @@ acpi_clean:
 cpupower_clean:
 	$(call descend,power/cpupower,clean)
 
-counter_clean hv_clean firewire_clean bootconfig_clean spi_clean usb_clean virtio_clean mm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean firmware_clean debugging_clean tracing_clean:
+counter_clean hv_clean firewire_clean bootconfig_clean spi_clean usb_clean virtio_clean mm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean firmware_clean debugging_clean tracing_clean dma_clean:
 	$(call descend,$(@:_clean=),clean)
 
 libapi_clean:
tools/dma/Makefile new file +20 -0
new file mode 100644
index 000000000000..c92a260ccf36
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0
+PREFIX ?= /usr
+SBINDIR ?= sbin
+INSTALL ?= install
+CFLAGS += -Wall -Wextra -I../../include/uapi -D__EXPORTED_HEADERS__
+
+TARGET = dma-slave
+
+all: $(TARGET)
+
+%: %.c
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
+
+clean:
+	$(RM) $(TARGET)
+
+install: $(TARGET)
+	$(INSTALL) -D -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/$(SBINDIR)/$(TARGET)
+
+.PHONY: all clean install
tools/dma/dma-slave.c new file +321 -0

321 lines not on this page · raw message

Signature · 1 line
2.51.0
#3 lore raw
In reply to Alexander Gordeev
Quoted 6 lines · Alexander Gordeev

Hi All,

This is a custom tool that can be used to bring up DMA slave devices. It consists of a user-level utility and a companion device driver that communicate via IOCTL.

Quoted 7 lines

The tool is likely need some polishing, but I would like first get some feedback to ensure there is interest.

I also tested it only on x86 and have little idea on how channel names on other architectures look like. That could especially impact the way dma_request_channel() treats user-provided target DMA channel names, as exposed via /sys/class/dma.

I am not sure if it can work for general dma engine because it slave setting is tight coupling with FIFO settings and timing, some periphal require start dma firstly, then enable DMA. some perphial require enable DMA first then queue dma transfer.

burst len is also related with FIFO 's watermark settings.

Frank

Quoted 23 lines

Thanks!

Alexander Gordeev (2):
dmaengine/dma-slave: DMA slave device xfer passthrough driver tools/dma-slave: DMA slave device transfer utility

 drivers/dma/Kconfig            |   7 +
 drivers/dma/Makefile           |   1 +
 drivers/dma/dma-slave.c        | 246 +++++++++++++++++++++++++
 include/uapi/linux/dma-slave.h |  30 +++
 tools/Makefile                 |  11 +-
 tools/dma/Makefile             |  20 ++
 tools/dma/dma-slave.c          | 321 +++++++++++++++++++++++++++++++++
 7 files changed, 631 insertions(+), 5 deletions(-)
 create mode 100644 drivers/dma/dma-slave.c
 create mode 100644 include/uapi/linux/dma-slave.h
 create mode 100644 tools/dma/Makefile
 create mode 100644 tools/dma/dma-slave.c

--
2.51.0

maintainer
#4 lore raw
Quoted 15 lines · Frank Li
Quoted 6 lines · Alexander Gordeev

Hi All,

This is a custom tool that can be used to bring up DMA slave devices. It consists of a user-level utility and a companion device driver that communicate via IOCTL.

Quoted 7 lines

The tool is likely need some polishing, but I would like first get some feedback to ensure there is interest.

I also tested it only on x86 and have little idea on how channel names on other architectures look like. That could especially impact the way dma_request_channel() treats user-provided target DMA channel names, as exposed via /sys/class/dma.

Quoted 6 lines

I am not sure if it can work for general dma engine because it slave setting is tight coupling with FIFO settings and timing, some periphal require start dma firstly, then enable DMA. some perphial require enable DMA first then queue dma transfer.

burst len is also related with FIFO 's watermark settings.

Correct!

I like the idea but it is not practical. Every dmaengine is tied to the peripheral for setting up the transfer. It is not a memcpy! How did you test it, which controller was used ..?

Signature · 1 line
~Vinod
#5 lore raw

On Wed, Feb 25, 2026 at 03:07:06PM +0530, Vinod Koul wrote:

Hi Vinod, Frank,

Quoted 5 lines
Quoted 5 lines

I am not sure if it can work for general dma engine because it slave setting is tight coupling with FIFO settings and timing, some periphal require start dma firstly, then enable DMA. some perphial require enable DMA first then queue dma transfer.

Quoted 7 lines
Quoted 1 line

burst len is also related with FIFO 's watermark settings.

Correct!

I like the idea but it is not practical. Every dmaengine is tied to the peripheral for setting up the transfer. It is not a memcpy! How did you test it, which controller was used ..?

I likely missing something, but how this differs from dmatest, which also lacks any controller-specific setup?

I tested it on Avalon-MM Interface on Arria 10 FPGA and found it super- useful - thus an attempt to share.

Quoted 1 line

~Vinod

Thanks!

maintainer
#6 lore raw
Quoted 11 lines · Alexander Gordeev

On Wed, Feb 25, 2026 at 03:07:06PM +0530, Vinod Koul wrote:

Hi Vinod, Frank,

Quoted 7 lines
Quoted 6 lines

I am not sure if it can work for general dma engine because it slave setting is tight coupling with FIFO settings and timing, some periphal require start dma firstly, then enable DMA. some perphial require enable DMA first then queue dma transfer.

burst len is also related with FIFO 's watermark settings.

Quoted 8 lines
Quoted 5 lines

Correct!

I like the idea but it is not practical. Every dmaengine is tied to the peripheral for setting up the transfer. It is not a memcpy! How did you test it, which controller was used ..?

I likely missing something, but how this differs from dmatest, which also lacks any controller-specific setup?

slave dma needs a peripheral to test. For example a spi/i2c etc dmaengine in slave mode will not work untill unless there is some signalling for dmaengine from peripheral to push/pull data.

Quoted 2 lines

I tested it on Avalon-MM Interface on Arria 10 FPGA and found it super- useful - thus an attempt to share.

Which driver is that? Seems more like a memcpy masked as slave to me

Signature · 1 line
~Vinod
#7 lore raw
Quoted 6 lines · Vinod Koul
Quoted 2 lines

I likely missing something, but how this differs from dmatest, which also lacks any controller-specific setup?

slave dma needs a peripheral to test. For example a spi/i2c etc dmaengine in slave mode will not work untill unless there is some signalling for dmaengine from peripheral to push/pull data.

Well, the idea is to trigger xfers using custom out-of-band tooling.

Quoted 4 lines
Quoted 2 lines

I tested it on Avalon-MM Interface on Arria 10 FPGA and found it super- useful - thus an attempt to share.

Which driver is that? Seems more like a memcpy masked as slave to me

Yes, one could say so. It transfers off-CPU memory in one of FPGA implementations, which does not need any xfer setup.

When attached to a camera however the xfer is triggered using a private tool that uses i2c - exactly as you guys noticed.

The dmaengine driver for Avalon-MM Interface is not upstreamed yet.

Quoted 1 line

~Vinod

Thanks!