Skip to contentSkip to conversation

dmaengine: atcdmac300: Add Andes ATCDMAC300 DMA driver

PATCH In review CL Wang 4 participants 8 messages Oct 1

Subsystems (2)
lore
Share & tools
lore

CL Wang

author
#0 lore raw

v8 cover dmaengine: atcdmac300: Add Andes ATCDMAC300 DMA driver

This patch series adds support for the Andes ATCDMAC300 DMA controller, a memory-to-memory and peripheral DMA controller that provides scatter-gather, cyclic, and slave transfer capabilities.

The ATCDMAC300 IP is embedded in AndesCore-based platforms or SoCs such as AE350 and Qilai.

v7 drew eight findings from sashiko-bot, and Frank Li asked for each to be fixed or explained. Five are fixed here. The other three are answered in the reply to v7 rather than changed:

- Terminal count and error arriving together:
The data sheet defines the terminal count status as being set only when a transfer finishes without an error or abort event, and only one transfer is in flight on a channel at a time, so the two cannot both describe the same transfer.

- Descriptors a client prepares and never submits:
The desc_free half does not apply, as the driver does not set descriptor_reuse and so that callback is unreachable; for the rest the API offers no unprepare a driver could hook. No in-tree client of this driver prepares a transfer it does not submit.

- Endianness conversions:
The driver depends on ARCH_ANDES and Linux has no big-endian RISC-V, so the conversions would be no-ops everywhere this can be built, and struct atcdmac_regs is both the linked list node the controller reads and the staging copy fed to regmap_write(), so the fields would be converted on the way in and converted straight back on the way out.

v7: https://lore.kernel.org/r/[email protected]

Changes in v8:
- Fold in fourteen further correctness fixes; no interface or binding change. Five of them answer the v7 findings above; the remaining nine come from a review of the whole driver.
- Descriptor lifetime:
- Track cyclic mode on the descriptor rather than on the channel; a cyclic and a non-cyclic transfer on one channel could leave the flag set for the wrong descriptor and dereference a NULL callback
- Drop the num_sg field, which was written but never read
- Suspend and resume:
- Restore stop_mask when suspend times out, instead of leaving every channel stopped for good
- Start transfers that were queued while suspended
- Driver model:
- Do not offer the controller for unbinding; a client holding a channel across an unbind would run against devres memory that remove() has already released
- Register encoding:
- Reject a DMA request line the request-select field cannot hold, rather than truncating it silently
- Keep the burst field out of its reserved range, which the controller reports as an error exception
- Refuse a transfer width the width field cannot encode
- Slave configuration:
- Clear the stored configuration when a channel is allocated, so a client cannot inherit the previous one's device address
- Accept a configuration that describes only the direction it uses
- Reject a length that is not a whole number of device-width units, which either transfers fewer bytes than asked for or programs a zero transfer size
- Probe:
- Use struct_size() for the channel array, which is already declared with __counted_by()
- Check the configuration register read, and refuse a channel count of zero rather than registering a controller with no channels
- Cleanups:
- Return a bool from the channel-enabled helper rather than a value that is negative on a failed register read; pass a register value rather than a bool to regmap_update_bits(); use dma_cookie_status() directly

Changes in v7:
- Rebase onto the current dmaengine/next
- Fold in twelve correctness fixes found by review and confirmed on an FPGA; no interface or binding change
- Interrupt path:
- Acknowledge only the status bits that were actually read
- Key the acknowledge on channel ownership instead of on in-flight state the handler itself clears, which could leave a completion unacknowledged until the core disabled the line
- Use raw spinlocks for the state shared with the hard IRQ handler
- Termination and descriptor lifetime:
- Do not run the callback twice, or recycle a descriptor, when a transfer is terminated while its completion is in flight
- Initialise desc_node when a descriptor is allocated
- Wait for the channel to stop without holding the channel lock; the poll could spin 100 ms with interrupts disabled
- Suspend and resume:
- Move the PM callbacks to the late phase so clients terminate their transfers first, and name the channels that fail to idle
- Drain in-flight completions across suspend and resume
- Do not restart an idle cyclic channel on resume
- Probe:
- Register the DMA device only after the interrupt and cache coherency setup, closing a window in which a client could obtain a channel through dma_request_channel() on an unready controller
- Do not read-modify-write write-only registers
- Name the device in the probe-time reset error

Changes in v6:
- Rebase onto dmaengine/next; no functional changes from v5
- Fold the MAINTAINERS entry into the driver patch instead of carrying it as a separate patch (series is now 2 patches)

Changes in v5:
- Update copyright year to 2026
- Remove redundant headers (init.h, iopoll.h, mod_devicetable.h)
- Move atcdmac_init_iocp() before of_dma_controller_register() in probe
- Change builtin_platform_driver() to module_platform_driver()
- Implement .remove callback to support safe module unloading
- Update Kconfig entry from bool to tristate
- Add MODULE_AUTHOR, MODULE_DESCRIPTION, MODULE_LICENSE macros

Changes in v4:
- Use items list format with descriptions for reg property in DT binding as suggested by Conor Dooley
- Re-add Acked-by from Conor Dooley for DT binding patch

Changes in v3:
- Rename DT binding file from andestech,qilai-dma.yaml to andestech,ae350-dma.yaml
- Deprecate IP-core-based compatible usage and align with SoC/platform-based strings
- Dropped Acked-by from Conor Dooley due to the above binding change
- Remove "andestech,atcdmac300" from of_device_id table
- Replace deprecated tasklet with threaded IRQ using devm_request_threaded_irq() and IRQF_ONESHOT
- Update locking from spin_lock_bh() to spin_lock_irqsave()
- Use builtin_platform_driver() instead of module_platform_driver()
- Remove "select DMATEST" from Kconfig
- Add separate MAINTAINERS patch (patch 3/3)

Please kindly review.

CL Wang (2):
dt-bindings: dmaengine: Add support for ATCDMAC300 DMA engine
dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

 .../bindings/dma/andestech,ae350-dma.yaml     |   67 +
 MAINTAINERS                                   |    6 +
 drivers/dma/Kconfig                           |   11 +
 drivers/dma/Makefile                          |    1 +
 drivers/dma/atcdmac300.c                      | 1759 +++++++++++++++++
 drivers/dma/atcdmac300.h                      |  298 +++
 6 files changed, 2142 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
 create mode 100644 drivers/dma/atcdmac300.c
 create mode 100644 drivers/dma/atcdmac300.h

base-commit: 0a8dda0a15d3926422d286567f945a05328a4ac6

Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v8 1/2 dt-bindings: dmaengine: Add support for ATCDMAC300 DMA engine

Document devicetree bindings for Andes ATCDMAC300 DMA engine

ATCDMAC300 is the IP name, which is embedded in AndesCore-based platforms or SoCs such as AE350 and Qilai.

---
Changes for v7:
- Rebase onto the current dmaengine/next; no changes from v6

Changes for v6:
- Rebase onto dmaengine/next; no changes from v5

Changes for v5:
- No changes from v4

Changes for v4:
- Use items list format with descriptions for reg property as suggested by Conor Dooley

Changes for v3:
- Rename DT binding file from andestech,qilai-dma.yaml to andestech,ae350-dma.yaml.
- Deprecate IP-core-based compatible usage and align with SoC/platform-based strings.
- Dropped Acked-by tag from Conor Dooley due to the above change.

---
 .../bindings/dma/andestech,ae350-dma.yaml     | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +67 -0
new file mode 100644
index 000000000000..f040a2bf7d4b
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/andestech,ae350-dma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Andes ATCDMAC300 DMA Controller
+
+maintainers:
+  - CL Wang <[email protected]>
+
+allOf:
+  - $ref: dma-controller.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - andestech,qilai-dma
+          - const: andestech,ae350-dma
+      - const: andestech,ae350-dma
+
+  reg:
+    minItems: 1
+    items:
+      - description: DMA controller register range
+      - description: cache control in IOCP controller
+
+  reg-names:
+    minItems: 1
+    items:
+      - const: dma
+      - const: iocp
+
+  interrupts:
+    maxItems: 1
+
+  "#dma-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - "#dma-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        dma-controller@f0c00000 {
+            compatible = "andestech,ae350-dma";
+            reg = <0x0 0xf0c00000 0x0 0x1000>,
+                  <0x0 0xe8000000 0x0 0x10>;
+            reg-names = "dma", "iocp";
+            interrupts = <10 IRQ_TYPE_LEVEL_HIGH>;
+            #dma-cells = <1>;
+        };
+    };
+...
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v8 1/2] dt-bindings: dmaengine: Add support for ATCDMAC300 DMA engine

Quoted 77 lines · CL Wang

Document devicetree bindings for Andes ATCDMAC300 DMA engine

ATCDMAC300 is the IP name, which is embedded in AndesCore-based platforms or SoCs such as AE350 and Qilai.

---
Changes for v7:
- Rebase onto the current dmaengine/next; no changes from v6

Changes for v6:
- Rebase onto dmaengine/next; no changes from v5

Changes for v5:
- No changes from v4

Changes for v4:
- Use items list format with descriptions for reg property as suggested by Conor Dooley

Changes for v3:
- Rename DT binding file from andestech,qilai-dma.yaml to andestech,ae350-dma.yaml.
- Deprecate IP-core-based compatible usage and align with SoC/platform-based strings.
- Dropped Acked-by tag from Conor Dooley due to the above change.

---
 .../bindings/dma/andestech,ae350-dma.yaml     | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +38 -0
new file mode 100644
index 000000000000..f040a2bf7d4b
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/andestech,ae350-dma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Andes ATCDMAC300 DMA Controller
+
+maintainers:
+  - CL Wang <[email protected]>
+
+allOf:
+  - $ref: dma-controller.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - andestech,qilai-dma
+          - const: andestech,ae350-dma
+      - const: andestech,ae350-dma
+
+  reg:
+    minItems: 1
+    items:
+      - description: DMA controller register range
+      - description: cache control in IOCP controller
+
+  reg-names:
+    minItems: 1
+    items:
+      - const: dma
+      - const: iocp
+
+  interrupts:
+    maxItems: 1
+

Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml line 48

Quoted 10 lines
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +10 -0
+  "#dma-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - "#dma-cells"
+
+additionalProperties: false

According to Documentation/devicetree/bindings/writing-bindings.rst ref to other yaml(ref: dma-controller.yaml)

should use
unevaluatedProperties: false

Frank

Quoted 22 lines
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +19 -1
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        dma-controller@f0c00000 {
+            compatible = "andestech,ae350-dma";
+            reg = <0x0 0xf0c00000 0x0 0x1000>,
+                  <0x0 0xe8000000 0x0 0x10>;
+            reg-names = "dma", "iocp";
+            interrupts = <10 IRQ_TYPE_LEVEL_HIGH>;
+            #dma-cells = <1>;
+        };
+    };
+...
--

2.34.1

#3 lore raw

Re: [PATCH v8 1/2] dt-bindings: dmaengine: Add support for ATCDMAC300 DMA engine

Quoted 92 lines · Frank Li
Quoted 77 lines · CL Wang

Document devicetree bindings for Andes ATCDMAC300 DMA engine

ATCDMAC300 is the IP name, which is embedded in AndesCore-based platforms or SoCs such as AE350 and Qilai.

---
Changes for v7:
- Rebase onto the current dmaengine/next; no changes from v6

Changes for v6:
- Rebase onto dmaengine/next; no changes from v5

Changes for v5:
- No changes from v4

Changes for v4:
- Use items list format with descriptions for reg property as suggested by Conor Dooley

Changes for v3:
- Rename DT binding file from andestech,qilai-dma.yaml to andestech,ae350-dma.yaml.
- Deprecate IP-core-based compatible usage and align with SoC/platform-based strings.
- Dropped Acked-by tag from Conor Dooley due to the above change.

---
 .../bindings/dma/andestech,ae350-dma.yaml     | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +38 -0
new file mode 100644
index 000000000000..f040a2bf7d4b
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/andestech,ae350-dma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Andes ATCDMAC300 DMA Controller
+
+maintainers:
+  - CL Wang <[email protected]>
+
+allOf:
+  - $ref: dma-controller.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - andestech,qilai-dma
+          - const: andestech,ae350-dma
+      - const: andestech,ae350-dma
+
+  reg:
+    minItems: 1
+    items:
+      - description: DMA controller register range
+      - description: cache control in IOCP controller
+
+  reg-names:
+    minItems: 1
+    items:
+      - const: dma
+      - const: iocp
+
+  interrupts:
+    maxItems: 1
+

Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml line 48

Quoted 10 lines
Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml new file +10 -0
+  "#dma-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - "#dma-cells"
+
+additionalProperties: false

According to Documentation/devicetree/bindings/writing-bindings.rst ref to other yaml(ref: dma-controller.yaml)

Quoted 2 lines

should use
unevaluatedProperties: false

It's fine to use additionalProperties: false though, and is correct to do IMO when the other properties being imported do not apply.

Thanks,
Conor.

author
#4 lore raw

PATCH v8 2/2 dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

In reply to CL Wang

This patch adds support for the Andes ATCDMAC300 DMA controller.

The ATCDMAC300 is a memory-to-memory and peripheral DMA controller that provides scatter-gather, cyclic, and slave transfer capabilities.

---
Changes for v8:
- Fold in fourteen further correctness fixes; no interface or binding change. Five of them answer findings reported on v7; the other three findings from that posting are explained in the reply to it rather than changed. The remaining nine come from a review of the whole driver.

Descriptor lifetime:
- Track cyclic mode on the descriptor rather than on the channel. A cyclic and a non-cyclic transfer on one channel could leave the flag set for the wrong descriptor and dereference a NULL callback.
- Drop the num_sg field, which was written but never read.
Suspend and resume:
- Restore stop_mask when suspend times out, instead of leaving every channel stopped for good.
- Start transfers that were queued while suspended.
Driver model:
- Do not offer the controller for unbinding. A client holding a channel across an unbind would run against devres memory that remove() has already released.
Register encoding:
- Reject a DMA request line the request-select field cannot hold, rather than truncating it silently.
- Keep the burst field out of its reserved range, which the controller reports as an error exception.
- Refuse a transfer width the width field cannot encode.
Slave configuration:
- Clear the stored configuration when a channel is allocated, so a client cannot inherit the previous one's device address.
- Accept a configuration that describes only the direction it uses. Requiring all four of the width and burst fields to be powers of two rejected any client that fills in one direction, and the transfer then divided by a zero device width.
- Reject a length that is not a whole number of device-width units, which either transfers fewer bytes than asked for or programs a zero transfer size.
Probe:
- Use struct_size() for the channel array, which is already declared with __counted_by().
- Check the configuration register read, and refuse a channel count of zero rather than registering a controller with no channels.
Cleanups:
- Return a bool from the channel-enabled helper rather than a value that is negative on a failed register read; pass a register value rather than a bool to regmap_update_bits(); use dma_cookie_status() directly.

Changes for v7:
- Fold in twelve correctness fixes found by review and confirmed on an FPGA; no interface or binding change. Interrupt path:
- Acknowledge only the status bits that were actually read, and key the acknowledge on channel ownership rather than on in-flight state the handler itself clears. The old mask could drop a completion that arrived while it was being cleared, leaving the source asserted until the core disabled the line ("nobody cared").
- Use raw spinlocks for the state shared with the hard IRQ handler.
Termination and descriptor lifetime:
- Do not run the callback twice, or recycle a descriptor, when a transfer is terminated while its completion is in flight.
- Initialise desc_node when a descriptor is allocated.
- Wait for the channel to stop without holding the channel lock; the poll could spin 100 ms with interrupts disabled.
Suspend and resume:
- Move the PM callbacks to the late phase so clients terminate their transfers first, and name the channels that fail to idle.
- Drain in-flight completions across suspend and resume.
- Do not restart an idle cyclic channel on resume.
Probe:
- Register the DMA device only after the interrupt and cache coherency setup, closing a window in which a client could obtain a channel through dma_request_channel() on an unready controller.
- Do not read-modify-write write-only registers.
- Name the device in the probe-time reset error.

Changes for v6:
- Rebase onto dmaengine/next; no functional changes from v5
- Fold the MAINTAINERS entry into this patch instead of carrying it as a separate patch

Changes for v5:
- Update copyright year to 2026
- Remove redundant headers (init.h, iopoll.h, mod_devicetable.h)
- Move atcdmac_init_iocp() before of_dma_controller_register() in probe
- Change builtin_platform_driver() to module_platform_driver()
- Implement .remove callback to support safe module unloading
- Update Kconfig entry from bool to tristate
- Add MODULE_AUTHOR, MODULE_DESCRIPTION, MODULE_LICENSE macros

Changes for v4:
- No changes from v3

Changes for v3:
- Remove "andestech,atcdmac300" from of_device_id
- Replace deprecated tasklet with threaded IRQ using devm_request_threaded_irq() and IRQF_ONESHOT to handle bottom-half processing.
- Update locking mechanism from spin_lock_bh() to spin_lock_irqsave()
- Minor cleanups and correctness fixes
- Initialize descriptor pointers (first = NULL) explicitly
- Add missing headers (err.h, iopoll.h, log2.h, sprintf.h)
- Remove unused code paths related to tasklets
- Use builtin_platform_driver() instead of module_platform_driver()
- Remove "select DMATEST" from Kconfig

---
 MAINTAINERS              |    6 +
 drivers/dma/Kconfig      |   11 +
 drivers/dma/Makefile     |    1 +
 drivers/dma/atcdmac300.c | 1759 ++++++++++++++++++++++++++++++++++++++
 drivers/dma/atcdmac300.h |  298 +++++++
 5 files changed, 2075 insertions(+)
 create mode 100644 drivers/dma/atcdmac300.c
 create mode 100644 drivers/dma/atcdmac300.h
MAINTAINERS +6 -0
index c31b81eb42d7..2c48bb3053b3 100644
@@ -1974,6 +1974,12 @@ S:	Supported
 F:	drivers/clk/analogbits/*
 F:	include/linux/clk/analogbits*
 
+ANDES ATCDMAC300 DMA DRIVER
+M:	CL Wang <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
+F:	drivers/dma/atcdmac300*
+
 ANDES ATCSPI200 SPI DRIVER
 M:	CL Wang <[email protected]>
 S:	Supported
drivers/dma/Kconfig +11 -0
index ae6a682c9f76..dabd2c8cc94f 100644
@@ -100,6 +100,17 @@ config ARM_DMA350
 	help
 	  Enable support for the Arm DMA-350 controller.
 
+config ATCDMAC300
+	tristate "Andes ATCDMAC300 DMA support"
+	depends on ARCH_ANDES
+	depends on OF
+	select DMA_ENGINE
+	help
+	  Enable support for the Andes ATCDMAC300 DMA controller.
+	  Select Y or M if your platform includes an ATCDMAC300 device that
+	  requires DMA engine support. This driver supports DMA_SLAVE,
+	  DMA_MEMCPY, and DMA_CYCLIC transfer modes.
+
 config AT_HDMAC
 	tristate "Atmel AHB DMA support"
 	depends on ARCH_AT91 || COMPILE_TEST
drivers/dma/Makefile +1 -0
index 14aa086629d5..c8fffb31efc4 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_AMBA_PL08X) += amba-pl08x.o
 obj-$(CONFIG_AMCC_PPC440SPE_ADMA) += ppc4xx/
 obj-$(CONFIG_APPLE_ADMAC) += apple-admac.o
 obj-$(CONFIG_ARM_DMA350) += arm-dma350.o
+obj-$(CONFIG_ATCDMAC300) += atcdmac300.o
 obj-$(CONFIG_AT_HDMAC) += at_hdmac.o
 obj-$(CONFIG_AT_XDMAC) += at_xdmac.o
 obj-$(CONFIG_AXI_DMAC) += dma-axi-dmac.o
drivers/dma/atcdmac300.c new file +1759 -0

1,759 lines not on this page · raw message

drivers/dma/atcdmac300.h new file +298 -0

298 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v8 2/2] dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider: - [High] dmaengine: atcdmac300: missing interrupt enable flags in channel control - [High] dmaengine…

Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
- [High] dmaengine: atcdmac300: missing interrupt enable flags in channel control
- [High] dmaengine: atcdmac300: start unissued pending transfers in atcdmac_resume()
- [High] dmaengine: atcdmac300: integer overflow of cyclic period variable
- [High] dmaengine: atcdmac300: missing status clearing in atcdmac_terminate_all()
- [High] dmaengine: atcdmac300: fail to reset chan_used flag during suspend
- [High] dmaengine: atcdmac300: unhandled pending interrupt causes IRQ storm
- [Medium] dmaengine: atcdmac300: ignore client transfer flags in atcdmac_prep_dma_memcpy()
- [Medium] dmaengine: atcdmac300: memory leak of unsubmitted descriptors
- [Medium] dmaengine: atcdmac300: integer truncation of len in atcdmac_prep_dma_memcpy()
- [Medium] dmaengine: atcdmac300: integer truncation of sizes in atcdmac_prep_dma_cyclic()
- [Medium] dmaengine: atcdmac300: missing args_count check in atcdmac_dma_xlate_handler() --

commit 0b5c5b75d701997e0656ae1d35e0499a595165ad
Author: CL Wang <[email protected]>

dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

This patch adds support for the Andes ATCDMAC300 DMA controller. The ATCDMAC300 is a memory-to-memory and peripheral DMA controller that provides scatter-gather, cyclic, and slave transfer capabilities.

Quoted 3 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -0,0 +1,1759 @@

[ ... ]

drivers/dma/atcdmac300.c line 274

Quoted 12 lines
drivers/dma/atcdmac300.c new file +12 -0
+static void atcdmac_start_transfer(struct atcdmac_chan *dmac_chan,
+				   struct atcdmac_desc *first_desc)
+{
+	struct atcdmac_dmac *dmac = dmac_chan->dma_dev;
+	struct regmap *reg = dmac_chan->regmap;
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&dmac->lock, flags);
+	dmac->owned_chan |= BIT(dmac_chan->chan_id);
+	raw_spin_unlock_irqrestore(&dmac->lock, flags);
+
+	regmap_write(reg, REG_CH_CTL_OFF, first_desc->regs.ctrl);

[Severity: High]
Since INT_TC_MASK, INT_ERR_MASK, and INT_ABT_MASK are missing from the ctrl bitmask written here (and constructed in functions like atcdmac_build_slave_desc()), won't the hardware fail to assert interrupts upon completion, error, or abort? This appears to cause silent transfer timeouts.

[ ... ]

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+static void atcdmac_advance_work(struct atcdmac_chan *dmac_chan)
+{

[ ... ]

Quoted 3 lines
drivers/dma/atcdmac300.c new file +3 -0
+	if (dma_desc->cyclic) {
+		if (!stop)
+			atcdmac_start_next_trans(dmac_chan);

[ ... ]

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+	} else {
+		if (list_is_singular(&dmac_chan->active_list)) {

[ ... ]

drivers/dma/atcdmac300.c

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+		if (!stop)
+			atcdmac_start_next_trans(dmac_chan);

[Severity: High]
If stop_mask is active during atcdmac_suspend(), this code skips calling atcdmac_start_next_trans(), which bypasses the internal reset of chan_used back to 0. Does this leave chan_used permanently stuck at 1?

[ ... ]

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+static int atcdmac_terminate_all(struct dma_chan *chan)
+{

[ ... ]

drivers/dma/atcdmac300.c line 1069

Quoted 7 lines
drivers/dma/atcdmac300.c new file +7 -0
+	spin_lock_irqsave(&dmac_chan->lock, flags);
+	atcdmac_abort_chan(dmac_chan);
+	atcdmac_enable_chan(dmac_chan, 0);
+	list_splice_init(&dmac_chan->queue_list,  &list);
+	list_splice_init(&dmac_chan->active_list, &list);
+	dmac_chan->chan_used = 0;
+	spin_unlock_irqrestore(&dmac_chan->lock, flags);

[Severity: High]
Does this code fail to clear the software state dmac_chan->status before dropping the lock? If an asynchronous abort interrupt fires as the channel is terminated, the threaded handler may process a stale ATCDMAC_STA_TC bit. If a client immediately queues and issues a new transfer, could atcdmac_advance_work() prematurely complete it?

[ ... ]

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+static void atcdmac_free_chan_resources(struct dma_chan *chan)
+{

[ ... ]

drivers/dma/atcdmac300.c line 1222

Quoted 12 lines
drivers/dma/atcdmac300.c new file +12 -0
+	atcdmac_terminate_all(chan);
+
+	/*
+	 * Give up ownership only after the abort raised by the termination
+	 * above has been serviced.  Dropping the bit first would mask that
+	 * status out of the acknowledge and leave the interrupt asserted.
+	 */
+	atcdmac_synchronize(chan);
+
+	raw_spin_lock_irq(&dmac->lock);
+	dmac->owned_chan &= ~BIT(dmac_chan->chan_id);
+	raw_spin_unlock_irq(&dmac->lock);

[Severity: High]
Since atcdmac_synchronize() only flushes executing handlers and not pending hardware interrupts, does clearing owned_chan immediately afterward mask out a pending ABORT interrupt in the top-half handler? It seems this would leave the level-triggered interrupt line permanently asserted, causing an IRQ storm.

drivers/dma/atcdmac300.c line 1231

Quoted 9 lines
drivers/dma/atcdmac300.c new file +9 -0
+
+	spin_lock_irqsave(&dmac_chan->lock, flags);
+	list_for_each_entry_safe(desc,
+				 desc_next,
+				 &dmac_chan->free_list,
+				 desc_node) {
+		list_del(&desc->desc_node);
+		dma_pool_free(dmac->dma_desc_pool, desc, desc->txd.phys);
+	}

[Severity: Medium]
In the cleanup loop above, unsubmitted descriptors that were allocated but never submitted via dmaengine_submit() are unlinked from tracking lists. Will these unsubmitted descriptors leak since this loop only reclaims from free_list?

[ ... ]

Quoted 7 lines
drivers/dma/atcdmac300.c new file +7 -0
+static struct dma_async_tx_descriptor *
+atcdmac_prep_dma_memcpy(struct dma_chan *chan,
+			dma_addr_t dst,
+			dma_addr_t src,
+			size_t len,
+			unsigned long flags)
+{

[ ... ]

drivers/dma/atcdmac300.c line 756

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+	desc = atcdmac_build_desc(dmac_chan, src, dst, ctrl,
+				  len >> src_width);

[Severity: Medium]
When len is a 64-bit size_t value exceeding 4GB, does shifting it by src_width and passing it as a 32-bit unsigned int to atcdmac_build_desc() cause silent integer truncation, resulting in a partial transfer?

drivers/dma/atcdmac300.c line 760

Quoted 4 lines
drivers/dma/atcdmac300.c new file +4 -0
+	if (!desc)
+		goto err_desc_get;
+
+	return &desc->txd;

[Severity: Medium]
Is there a missing assignment for the client transfer flags? The flags parameter is never assigned to desc->txd.flags, which ignores client intents like DMA_PREP_INTERRUPT or DMA_CTRL_REUSE.

[ ... ]

Quoted 8 lines
drivers/dma/atcdmac300.c new file +8 -0
+static struct dma_async_tx_descriptor *
+atcdmac_prep_dma_cyclic(struct dma_chan *chan,
+			dma_addr_t buf_addr,
+			size_t buf_len,
+			size_t period_len,
+			enum dma_transfer_direction direction,
+			unsigned long flags)
+{

[ ... ]

Quoted 1 line
drivers/dma/atcdmac300.c new file +1 -0
+	unsigned int period;

[ ... ]

drivers/dma/atcdmac300.c line 994

Quoted 5 lines
drivers/dma/atcdmac300.c new file +5 -0
+	for (period = 0; period < buf_len; period += period_len) {
+		struct atcdmac_desc *desc;
+		dma_addr_t mem = buf_addr + period;
+		unsigned int len = min_t(unsigned int, period_len,
+					 buf_len - period);

[Severity: High]
Since buf_len is a 64-bit size_t, does using a 32-bit unsigned int period cause an integer overflow for buffer lengths exceeding 4GB? This appears to create an infinite loop of descriptor allocations until the pool is exhausted.

[Severity: Medium]
Does the use of min_t(unsigned int, period_len, buf_len - period) silently truncate 64-bit size_t sizes over 4GB, programming a malformed transfer size?

[ ... ]

drivers/dma/atcdmac300.c line 1254

Quoted 9 lines
drivers/dma/atcdmac300.c new file +9 -0
+static struct dma_chan *atcdmac_dma_xlate_handler(struct of_phandle_args *dmac,
+						  struct of_dma *of_dma)
+{
+	struct platform_device *dmac_pdev;
+	struct atcdmac_chan *dmac_chan;
+	struct dma_chan *chan;
+	dma_cap_mask_t mask;
+
+	if (dmac->args[0] > FIELD_MAX(SRC_REQ_SEL_MASK)) {

[Severity: Medium]
Does this code access dmac->args[0] without first verifying dmac->args_count? If #dma-cells = <0>, this may read uninitialized or out-of-bounds memory.

[ ... ]

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+static int atcdmac_resume(struct device *dev)
+{

[ ... ]

drivers/dma/atcdmac300.c line 1642

Quoted 11 lines
drivers/dma/atcdmac300.c new file +11 -0
+	list_for_each_entry_safe(chan,
+				 chan_next,
+				 &dmac->dma_device.channels,
+				 device_node) {
+		dmac_chan = atcdmac_chan_to_dmac_chan(chan);
+		spin_lock_irqsave(&dmac_chan->lock, flags);
+		if (!list_empty(&dmac_chan->active_list) ||
+		    !list_empty(&dmac_chan->queue_list))
+			atcdmac_start_next_trans(dmac_chan);
+		spin_unlock_irqrestore(&dmac_chan->lock, flags);
+	}

[Severity: High]
If a client has queued descriptors but not yet called dma_async_issue_pending() (leaving chan_used == 0), does unconditionally starting the next transaction from queue_list violate the API contract by starting pending transfers prematurely?

[Severity: High]
Additionally, if both active_list and queue_list are empty, this bypasses atcdmac_start_next_trans(). Coupled with the issue in atcdmac_advance_work() above, does this solidify the leaked chan_used == 1 state from suspend, permanently locking out the channel?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH v8 2/2] dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

Quoted 5 lines · On Thu, Oct 01, 2026 at 02:27:02AM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
- [High] dmaengine: atcdmac300: missing interrupt enable flags in channel control
- [High] dmaengine: atcdmac300: start unissued pending transfers in atcdmac_resume()
- [High] dmaengine: atcdmac300: integer overflow of cyclic period variable
- [High] dmaengine: atcdmac300: missing status clearing in atcdmac_terminate_all()

Quoted 8 lines

- [High] dmaengine: atcdmac300: fail to reset chan_used flag during suspend
- [High] dmaengine: atcdmac300: unhandled pending interrupt causes IRQ storm
- [Medium] dmaengine: atcdmac300: ignore client transfer flags in atcdmac_prep_dma_memcpy()
- [Medium] dmaengine: atcdmac300: memory leak of unsubmitted descriptors
- [Medium] dmaengine: atcdmac300: integer truncation of len in atcdmac_prep_dma_memcpy()
- [Medium] dmaengine: atcdmac300: integer truncation of sizes in atcdmac_prep_dma_cyclic()
- [Medium] dmaengine: atcdmac300: missing args_count check in atcdmac_dma_xlate_handler() --

You should fix these issues for new drivers.

Frank

Quoted 214 lines

commit 0b5c5b75d701997e0656ae1d35e0499a595165ad
Author: CL Wang <[email protected]>

dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

This patch adds support for the Andes ATCDMAC300 DMA controller. The ATCDMAC300 is a memory-to-memory and peripheral DMA controller that provides scatter-gather, cyclic, and slave transfer capabilities.

Quoted 3 lines
drivers/dma/atcdmac300.c new file +0 -0
@@ -0,0 +1,1759 @@

[ ... ]

drivers/dma/atcdmac300.c line 274

Quoted 12 lines
drivers/dma/atcdmac300.c new file +12 -0
+static void atcdmac_start_transfer(struct atcdmac_chan *dmac_chan,
+				   struct atcdmac_desc *first_desc)
+{
+	struct atcdmac_dmac *dmac = dmac_chan->dma_dev;
+	struct regmap *reg = dmac_chan->regmap;
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&dmac->lock, flags);
+	dmac->owned_chan |= BIT(dmac_chan->chan_id);
+	raw_spin_unlock_irqrestore(&dmac->lock, flags);
+
+	regmap_write(reg, REG_CH_CTL_OFF, first_desc->regs.ctrl);

[Severity: High]
Since INT_TC_MASK, INT_ERR_MASK, and INT_ABT_MASK are missing from the ctrl bitmask written here (and constructed in functions like atcdmac_build_slave_desc()), won't the hardware fail to assert interrupts upon completion, error, or abort? This appears to cause silent transfer timeouts.

[ ... ]

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+static void atcdmac_advance_work(struct atcdmac_chan *dmac_chan)
+{

[ ... ]

Quoted 3 lines
drivers/dma/atcdmac300.c new file +3 -0
+	if (dma_desc->cyclic) {
+		if (!stop)
+			atcdmac_start_next_trans(dmac_chan);

[ ... ]

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+	} else {
+		if (list_is_singular(&dmac_chan->active_list)) {

[ ... ]

drivers/dma/atcdmac300.c

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+		if (!stop)
+			atcdmac_start_next_trans(dmac_chan);

[Severity: High]
If stop_mask is active during atcdmac_suspend(), this code skips calling atcdmac_start_next_trans(), which bypasses the internal reset of chan_used back to 0. Does this leave chan_used permanently stuck at 1?

[ ... ]

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+static int atcdmac_terminate_all(struct dma_chan *chan)
+{

[ ... ]

drivers/dma/atcdmac300.c line 1069

Quoted 7 lines
drivers/dma/atcdmac300.c new file +7 -0
+	spin_lock_irqsave(&dmac_chan->lock, flags);
+	atcdmac_abort_chan(dmac_chan);
+	atcdmac_enable_chan(dmac_chan, 0);
+	list_splice_init(&dmac_chan->queue_list,  &list);
+	list_splice_init(&dmac_chan->active_list, &list);
+	dmac_chan->chan_used = 0;
+	spin_unlock_irqrestore(&dmac_chan->lock, flags);

[Severity: High]
Does this code fail to clear the software state dmac_chan->status before dropping the lock? If an asynchronous abort interrupt fires as the channel is terminated, the threaded handler may process a stale ATCDMAC_STA_TC bit. If a client immediately queues and issues a new transfer, could atcdmac_advance_work() prematurely complete it?

[ ... ]

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+static void atcdmac_free_chan_resources(struct dma_chan *chan)
+{

[ ... ]

drivers/dma/atcdmac300.c line 1222

Quoted 12 lines
drivers/dma/atcdmac300.c new file +12 -0
+	atcdmac_terminate_all(chan);
+
+	/*
+	 * Give up ownership only after the abort raised by the termination
+	 * above has been serviced.  Dropping the bit first would mask that
+	 * status out of the acknowledge and leave the interrupt asserted.
+	 */
+	atcdmac_synchronize(chan);
+
+	raw_spin_lock_irq(&dmac->lock);
+	dmac->owned_chan &= ~BIT(dmac_chan->chan_id);
+	raw_spin_unlock_irq(&dmac->lock);

[Severity: High]
Since atcdmac_synchronize() only flushes executing handlers and not pending hardware interrupts, does clearing owned_chan immediately afterward mask out a pending ABORT interrupt in the top-half handler? It seems this would leave the level-triggered interrupt line permanently asserted, causing an IRQ storm.

drivers/dma/atcdmac300.c line 1231

Quoted 9 lines
drivers/dma/atcdmac300.c new file +9 -0
+
+	spin_lock_irqsave(&dmac_chan->lock, flags);
+	list_for_each_entry_safe(desc,
+				 desc_next,
+				 &dmac_chan->free_list,
+				 desc_node) {
+		list_del(&desc->desc_node);
+		dma_pool_free(dmac->dma_desc_pool, desc, desc->txd.phys);
+	}

[Severity: Medium]
In the cleanup loop above, unsubmitted descriptors that were allocated but never submitted via dmaengine_submit() are unlinked from tracking lists. Will these unsubmitted descriptors leak since this loop only reclaims from free_list?

[ ... ]

Quoted 7 lines
drivers/dma/atcdmac300.c new file +7 -0
+static struct dma_async_tx_descriptor *
+atcdmac_prep_dma_memcpy(struct dma_chan *chan,
+			dma_addr_t dst,
+			dma_addr_t src,
+			size_t len,
+			unsigned long flags)
+{

[ ... ]

drivers/dma/atcdmac300.c line 756

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+	desc = atcdmac_build_desc(dmac_chan, src, dst, ctrl,
+				  len >> src_width);

[Severity: Medium]
When len is a 64-bit size_t value exceeding 4GB, does shifting it by src_width and passing it as a 32-bit unsigned int to atcdmac_build_desc() cause silent integer truncation, resulting in a partial transfer?

drivers/dma/atcdmac300.c line 760

Quoted 4 lines
drivers/dma/atcdmac300.c new file +4 -0
+	if (!desc)
+		goto err_desc_get;
+
+	return &desc->txd;

[Severity: Medium]
Is there a missing assignment for the client transfer flags? The flags parameter is never assigned to desc->txd.flags, which ignores client intents like DMA_PREP_INTERRUPT or DMA_CTRL_REUSE.

[ ... ]

Quoted 8 lines
drivers/dma/atcdmac300.c new file +8 -0
+static struct dma_async_tx_descriptor *
+atcdmac_prep_dma_cyclic(struct dma_chan *chan,
+			dma_addr_t buf_addr,
+			size_t buf_len,
+			size_t period_len,
+			enum dma_transfer_direction direction,
+			unsigned long flags)
+{

[ ... ]

Quoted 1 line
drivers/dma/atcdmac300.c new file +1 -0
+	unsigned int period;

[ ... ]

drivers/dma/atcdmac300.c line 994

Quoted 5 lines
drivers/dma/atcdmac300.c new file +5 -0
+	for (period = 0; period < buf_len; period += period_len) {
+		struct atcdmac_desc *desc;
+		dma_addr_t mem = buf_addr + period;
+		unsigned int len = min_t(unsigned int, period_len,
+					 buf_len - period);

[Severity: High]
Since buf_len is a 64-bit size_t, does using a 32-bit unsigned int period cause an integer overflow for buffer lengths exceeding 4GB? This appears to create an infinite loop of descriptor allocations until the pool is exhausted.

[Severity: Medium]
Does the use of min_t(unsigned int, period_len, buf_len - period) silently truncate 64-bit size_t sizes over 4GB, programming a malformed transfer size?

[ ... ]

drivers/dma/atcdmac300.c line 1254

Quoted 9 lines
drivers/dma/atcdmac300.c new file +9 -0
+static struct dma_chan *atcdmac_dma_xlate_handler(struct of_phandle_args *dmac,
+						  struct of_dma *of_dma)
+{
+	struct platform_device *dmac_pdev;
+	struct atcdmac_chan *dmac_chan;
+	struct dma_chan *chan;
+	dma_cap_mask_t mask;
+
+	if (dmac->args[0] > FIELD_MAX(SRC_REQ_SEL_MASK)) {

[Severity: Medium]
Does this code access dmac->args[0] without first verifying dmac->args_count? If #dma-cells = <0>, this may read uninitialized or out-of-bounds memory.

[ ... ]

Quoted 2 lines
drivers/dma/atcdmac300.c new file +2 -0
+static int atcdmac_resume(struct device *dev)
+{

[ ... ]

drivers/dma/atcdmac300.c line 1642

Quoted 11 lines
drivers/dma/atcdmac300.c new file +11 -0
+	list_for_each_entry_safe(chan,
+				 chan_next,
+				 &dmac->dma_device.channels,
+				 device_node) {
+		dmac_chan = atcdmac_chan_to_dmac_chan(chan);
+		spin_lock_irqsave(&dmac_chan->lock, flags);
+		if (!list_empty(&dmac_chan->active_list) ||
+		    !list_empty(&dmac_chan->queue_list))
+			atcdmac_start_next_trans(dmac_chan);
+		spin_unlock_irqrestore(&dmac_chan->lock, flags);
+	}

[Severity: High]
If a client has queued descriptors but not yet called dma_async_issue_pending() (leaving chan_used == 0), does unconditionally starting the next transaction from queue_list violate the API contract by starting pending transfers prematurely?

[Severity: High]
Additionally, if both active_list and queue_list are empty, this bypasses atcdmac_start_next_trans(). Coupled with the issue in atcdmac_advance_work() above, does this solidify the leaked chan_used == 1 state from suspend, permanently locking out the channel?

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2

#7 lore raw

Re: [PATCH v8 2/2] dmaengine: atcdmac300: Add driver for Andes ATCDMAC300 DMA controller

In reply to CL Wang
Quoted 145 lines · CL Wang

This patch adds support for the Andes ATCDMAC300 DMA controller.

The ATCDMAC300 is a memory-to-memory and peripheral DMA controller that provides scatter-gather, cyclic, and slave transfer capabilities.

---
Changes for v8:
- Fold in fourteen further correctness fixes; no interface or binding change. Five of them answer findings reported on v7; the other three findings from that posting are explained in the reply to it rather than changed. The remaining nine come from a review of the whole driver.

Descriptor lifetime:
- Track cyclic mode on the descriptor rather than on the channel. A cyclic and a non-cyclic transfer on one channel could leave the flag set for the wrong descriptor and dereference a NULL callback.
- Drop the num_sg field, which was written but never read.
Suspend and resume:
- Restore stop_mask when suspend times out, instead of leaving every channel stopped for good.
- Start transfers that were queued while suspended.
Driver model:
- Do not offer the controller for unbinding. A client holding a channel across an unbind would run against devres memory that remove() has already released.
Register encoding:
- Reject a DMA request line the request-select field cannot hold, rather than truncating it silently.
- Keep the burst field out of its reserved range, which the controller reports as an error exception.
- Refuse a transfer width the width field cannot encode.
Slave configuration:
- Clear the stored configuration when a channel is allocated, so a client cannot inherit the previous one's device address.
- Accept a configuration that describes only the direction it uses. Requiring all four of the width and burst fields to be powers of two rejected any client that fills in one direction, and the transfer then divided by a zero device width.
- Reject a length that is not a whole number of device-width units, which either transfers fewer bytes than asked for or programs a zero transfer size.
Probe:
- Use struct_size() for the channel array, which is already declared with __counted_by().
- Check the configuration register read, and refuse a channel count of zero rather than registering a controller with no channels.
Cleanups:
- Return a bool from the channel-enabled helper rather than a value that is negative on a failed register read; pass a register value rather than a bool to regmap_update_bits(); use dma_cookie_status() directly.

Changes for v7:
- Fold in twelve correctness fixes found by review and confirmed on an FPGA; no interface or binding change. Interrupt path:
- Acknowledge only the status bits that were actually read, and key the acknowledge on channel ownership rather than on in-flight state the handler itself clears. The old mask could drop a completion that arrived while it was being cleared, leaving the source asserted until the core disabled the line ("nobody cared").
- Use raw spinlocks for the state shared with the hard IRQ handler.
Termination and descriptor lifetime:
- Do not run the callback twice, or recycle a descriptor, when a transfer is terminated while its completion is in flight.
- Initialise desc_node when a descriptor is allocated.
- Wait for the channel to stop without holding the channel lock; the poll could spin 100 ms with interrupts disabled.
Suspend and resume:
- Move the PM callbacks to the late phase so clients terminate their transfers first, and name the channels that fail to idle.
- Drain in-flight completions across suspend and resume.
- Do not restart an idle cyclic channel on resume.
Probe:
- Register the DMA device only after the interrupt and cache coherency setup, closing a window in which a client could obtain a channel through dma_request_channel() on an unready controller.
- Do not read-modify-write write-only registers.
- Name the device in the probe-time reset error.

Changes for v6:
- Rebase onto dmaengine/next; no functional changes from v5
- Fold the MAINTAINERS entry into this patch instead of carrying it as a separate patch

Changes for v5:
- Update copyright year to 2026
- Remove redundant headers (init.h, iopoll.h, mod_devicetable.h)
- Move atcdmac_init_iocp() before of_dma_controller_register() in probe
- Change builtin_platform_driver() to module_platform_driver()
- Implement .remove callback to support safe module unloading
- Update Kconfig entry from bool to tristate
- Add MODULE_AUTHOR, MODULE_DESCRIPTION, MODULE_LICENSE macros

Changes for v4:
- No changes from v3

Changes for v3:
- Remove "andestech,atcdmac300" from of_device_id
- Replace deprecated tasklet with threaded IRQ using devm_request_threaded_irq() and IRQF_ONESHOT to handle bottom-half processing.
- Update locking mechanism from spin_lock_bh() to spin_lock_irqsave()
- Minor cleanups and correctness fixes
- Initialize descriptor pointers (first = NULL) explicitly
- Add missing headers (err.h, iopoll.h, log2.h, sprintf.h)
- Remove unused code paths related to tasklets
- Use builtin_platform_driver() instead of module_platform_driver()
- Remove "select DMATEST" from Kconfig

---
 MAINTAINERS              |    6 +
 drivers/dma/Kconfig      |   11 +
 drivers/dma/Makefile     |    1 +
 drivers/dma/atcdmac300.c | 1759 ++++++++++++++++++++++++++++++++++++++
 drivers/dma/atcdmac300.h |  298 +++++++
 5 files changed, 2075 insertions(+)
 create mode 100644 drivers/dma/atcdmac300.c
 create mode 100644 drivers/dma/atcdmac300.h
MAINTAINERS +6 -0
index c31b81eb42d7..2c48bb3053b3 100644
@@ -1974,6 +1974,12 @@ S:	Supported
 F:	drivers/clk/analogbits/*
 F:	include/linux/clk/analogbits*
 
+ANDES ATCDMAC300 DMA DRIVER
+M:	CL Wang <[email protected]>
+S:	Supported
+F:	Documentation/devicetree/bindings/dma/andestech,ae350-dma.yaml
+F:	drivers/dma/atcdmac300*
+
 ANDES ATCSPI200 SPI DRIVER
 M:	CL Wang <[email protected]>
 S:	Supported
drivers/dma/Kconfig +0 -0
index ae6a682c9f76..dabd2c8cc94f 100644

drivers/dma/Kconfig config ARM_DMA350 · line 105

Quoted 6 lines
drivers/dma/Kconfig +3 -0
@@ -100,6 +100,17 @@ config ARM_DMA350
 	help
 	  Enable support for the Arm DMA-350 controller.
 
+config ATCDMAC300
+	tristate "Andes ATCDMAC300 DMA support"
+	depends on ARCH_ANDES

|| COMPILE_TEST

make sure it can build

Quoted 44 lines
drivers/dma/Kconfig +8 -0
+	depends on OF
+	select DMA_ENGINE
+	help
+	  Enable support for the Andes ATCDMAC300 DMA controller.
+	  Select Y or M if your platform includes an ATCDMAC300 device that
+	  requires DMA engine support. This driver supports DMA_SLAVE,
+	  DMA_MEMCPY, and DMA_CYCLIC transfer modes.
+
 config AT_HDMAC
 	tristate "Atmel AHB DMA support"
 	depends on ARCH_AT91 || COMPILE_TEST
drivers/dma/Makefile +1 -0
index 14aa086629d5..c8fffb31efc4 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_AMBA_PL08X) += amba-pl08x.o
 obj-$(CONFIG_AMCC_PPC440SPE_ADMA) += ppc4xx/
 obj-$(CONFIG_APPLE_ADMAC) += apple-admac.o
 obj-$(CONFIG_ARM_DMA350) += arm-dma350.o
+obj-$(CONFIG_ATCDMAC300) += atcdmac300.o
 obj-$(CONFIG_AT_HDMAC) += at_hdmac.o
 obj-$(CONFIG_AT_XDMAC) += at_xdmac.o
 obj-$(CONFIG_AXI_DMAC) += dma-axi-dmac.o
drivers/dma/atcdmac300.c new file +15 -0
new file mode 100644
index 000000000000..b67675647b36
@@ -0,0 +1,1759 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Andes ATCDMAC300 controller driver
+ *
+ * Copyright (C) 2026 Andes Technology Corporation
+ */
+#include <linux/align.h>
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/dmaengine.h>
+#include <linux/dmapool.h>
+#include <linux/dma-mapping.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>

drivers/dma/atcdmac300.c line 25

Quoted 10 lines
drivers/dma/atcdmac300.c new file +10 -0
+#include <linux/log2.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_dma.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/pm.h>
+#include <linux/slab.h>
+#include <linux/sprintf.h>
+#include <linux/regmap.h>

Add empty line here.

Quoted 11 lines
drivers/dma/atcdmac300.c new file +11 -0
+#include "dmaengine.h"
+#include "atcdmac300.h"
+
+static bool atcdmac_is_chan_enabled(struct atcdmac_chan *dmac_chan)
+{
+	struct atcdmac_dmac *dmac =
+		atcdmac_dev_to_dmac(dmac_chan->dma_chan.device);
+
+	/*
+	 * regmap_test_bits() reports a failed read as a negative errno,
+	 * which every caller here would otherwise read as "enabled".

drivers/dma/atcdmac300.c line 46

Quoted 10 lines
drivers/dma/atcdmac300.c new file +10 -0
+	 */
+	return regmap_test_bits(dmac->regmap,
+				REG_CH_EN,
+				BIT(dmac_chan->chan_id)) > 0;
+}
+
+static void atcdmac_enable_chan(struct atcdmac_chan *dmac_chan, bool enable)
+{
+	regmap_update_bits(dmac_chan->regmap, REG_CH_CTL_OFF, CHEN,
+			   enable ? CHEN : 0);

Use regmap_assign_bits() will be more simple

Quoted 65 lines
drivers/dma/atcdmac300.c new file +65 -0
+}
+
+static void atcdmac_abort_chan(struct atcdmac_chan *dmac_chan)
+{
+	/*
+	 * ChAbort is write-only: write 1 to the channel's bit to abort it.
+	 * Do not read-modify-write, the read value is undefined and writing
+	 * it back could abort a channel owned by someone else.
+	 */
+	regmap_write(dmac_chan->dma_dev->regmap,
+		     REG_CH_ABT,
+		     BIT(dmac_chan->chan_id));
+}
+
+static dma_cookie_t atcdmac_tx_submit(struct dma_async_tx_descriptor *tx)
+{
+	struct atcdmac_chan *dmac_chan = atcdmac_chan_to_dmac_chan(tx->chan);
+	struct atcdmac_desc *desc = atcdmac_txd_to_dma_desc(tx);
+	dma_cookie_t cookie;
+	unsigned long flags;
+
+	spin_lock_irqsave(&dmac_chan->lock, flags);
+	cookie = dma_cookie_assign(tx);
+	list_add_tail(&desc->desc_node, &dmac_chan->queue_list);
+	spin_unlock_irqrestore(&dmac_chan->lock, flags);
+
+	return cookie;
+}
+
+static struct atcdmac_desc *
+atcdmac_get_active_head(struct atcdmac_chan *dmac_chan)
+{
+	return list_first_entry(&dmac_chan->active_list,
+				struct atcdmac_desc,
+				desc_node);
+}
+
+static struct atcdmac_desc *atcdmac_alloc_desc(struct dma_chan *chan,
+					       gfp_t gfp_flags)
+{
+	struct atcdmac_dmac *dmac = atcdmac_dev_to_dmac(chan->device);
+	struct atcdmac_desc *desc;
+	dma_addr_t phys;
+
+	desc = dma_pool_zalloc(dmac->dma_desc_pool, gfp_flags, &phys);
+	if (desc) {
+		INIT_LIST_HEAD(&desc->desc_node);
+		INIT_LIST_HEAD(&desc->tx_list);
+		dma_async_tx_descriptor_init(&desc->txd, chan);
+		desc->txd.flags = DMA_CTRL_ACK;
+		desc->txd.tx_submit = atcdmac_tx_submit;
+		desc->txd.phys = phys;
+	}
+
+	return desc;
+}
+
+static struct atcdmac_desc *atcdmac_get_desc(struct atcdmac_chan *dmac_chan)
+{
+	struct atcdmac_desc *ret = NULL;
+	struct atcdmac_desc *desc_next;
+	struct atcdmac_desc *desc;
+	unsigned long flags;
+
+	spin_lock_irqsave(&dmac_chan->lock, flags);

drivers/dma/atcdmac300.c line 121

Quoted 10 lines
drivers/dma/atcdmac300.c new file +10 -0
+	list_for_each_entry_safe(desc, desc_next,
+				 &dmac_chan->free_list,
+				 desc_node) {
+		if (async_tx_test_ack(&desc->txd)) {
+			list_del_init(&desc->desc_node);
+			ret = desc;
+			break;
+		}
+	}
+	spin_unlock_irqrestore(&dmac_chan->lock, flags);

Not sure why need manually manage free_list. Most likely dma_pool_zalloc() is quick enough.

And why not use virt-dma?

Frank