Skip to content

dmaengine: Add Peripheral DMA support for SpacemiT K3 SoC #321

Open
EncrowThorne19 wants to merge 15 commits into
RVCK-Project:rvck-6.6from
EncrowThorne19:dev-dma-k3
Open

dmaengine: Add Peripheral DMA support for SpacemiT K3 SoC #321
EncrowThorne19 wants to merge 15 commits into
RVCK-Project:rvck-6.6from
EncrowThorne19:dev-dma-k3

Conversation

@EncrowThorne19

@EncrowThorne19 EncrowThorne19 commented Jul 2, 2026

Copy link
Copy Markdown

fixed: #320

The K3 PDMA IP is largely based on the design found in the previous
SpacemiT K1 SoC, but introduces a few key architectural differences:

  1. It features a variable extended DRCMR base address for DMA request
    numbers (>= 64) depending on the hardware implementation.
  2. Unlike the K1 SoC, where some DMA masters had memory addressing
    limitations (requiring a dedicated dma-bus), the K3 DMA masters
    have full memory addressing capabilities.

Remove the legacy Spacemit K1 DMA implementation and unify the DMA
driver support for both K1 and K3 SoCs using mmp_pdma.c.

Keep spacemit-k1-dma.h to retain DMA macros for peripherals (SPI/I2C/UART)
and avoid magic numbers in k1.dtsi.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/28582174284

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/321/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware ['qemu']
LAVA Testcase path lava-testcases/common-test/ltp/ltp.yaml
need run job kunit-test,kernel-build,check-patch,lava-trigger

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[10:13:01] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 10

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_28582174284_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_28582174284_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_321__common-test_qemu

result: Lava check done!

@unicornx

unicornx commented Jul 3, 2026

Copy link
Copy Markdown

1st review:

同样存在和我在 #319 提到的一样的问题 #319 (comment),你从上游 copy commit messaage 过来时漏了部分信息,我怀疑你没有参考 上游主线中的 commit 而是拿的 mailist 中的 patch email 的签名,导致遗漏了实际上游主线中的信息(maintainer 会在上游 merge 时追加自己的签名和 mail link 信息)。

既然我们要求参考的 commit 必须是 已经合入上游主线 的 ,所以我们的要求是 copy 最终主线中的 patch 信息。

请检查改正。

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/28634325511

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/321/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware ['qemu']
LAVA Testcase path lava-testcases/common-test/ltp/ltp.yaml
need run job kunit-test,kernel-build,check-patch,lava-trigger

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[02:29:30] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 9

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_28634325511_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_28634325511_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_321__common-test_qemu

result: Lava check done!

@unicornx
unicornx self-requested a review July 6, 2026 05:40
Comment thread Documentation/devicetree/bindings/dma/spacemit,k1-pdma.yaml
Comment thread drivers/dma/mmp_pdma.c
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown

开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/29797092848

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/321/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware ['qemu']
LAVA Testcase path lava-testcases/common-test/ltp/ltp.yaml
need run job kunit-test,kernel-build,check-patch,lava-trigger

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[02:59:28] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 24

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_29797092848_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_29797092848_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_321__common-test_qemu

result: Lava check done!

@unicornx unicornx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3rd review:
还存在一些问题。

其中发现比较大的一个问题是 k1 dma 补丁的冲突问题,请和 zhangmeng 一起研究一下。

Comment thread drivers/dma/mmp_pdma.c
ret = reset_control_deassert(rst);
if (ret)
return ret;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的缩进格式有问题。

Comment thread drivers/dma/mmp_pdma.c

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看你和原补丁的做法有区别,没有引入另外两个文件的修改。
但是我觉得这个担心是没有必要的,这个补丁的逻辑和修改原因非常直接,如果他们其他两个会有问题,我觉得 drivers/dma/mmp_pdma.c 的修改也早就有问题了,所以我觉得直接 pick 原先完整的补丁是安全的,你觉得呢?

Comment thread drivers/dma/mmp_pdma.c
.compatible = "marvell,pdma-1.0",
.data = &marvell_pdma_v1_ops
}, {
.compatible = "spacemit,k1-pdma",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有个问题,我发现 "spacemit,k1-pdma" 这个 compatible 在 drivers/dma/spacemit-k1-dma.c 中也存在(重复了),而上游的主线中我看了一下是没有 drivers/dma/spacemit-k1-dma.c 这个文件的。
看上去现在 k1 和 k3 都统一使用了 mmp_pdma.c, 那么看上去以前有些 k1 的 dma PR 需要先 Revert 掉?
我查了一下,对应的 issue是 #44,是 zhangmeng 提交的,请和他讨论一下怎么处理。@kevin-zhm

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/29915053871

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/321/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware ['qemu']
LAVA Testcase path lava-testcases/common-test/ltp/ltp.yaml
need run job kunit-test,kernel-build,check-patch,lava-trigger

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu failure
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[11:20:50] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 17

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_29915053871_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_29915053871_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_321__common-test_qemu

result: Lava check fail!

@unicornx

unicornx commented Jul 23, 2026

Copy link
Copy Markdown

4th review:

问题1:

补丁的提交顺序,应该是先 revert 再加新的功能或者修改,也就是说你本地 git log --oneline 时应该看到的顺序是:

riscv: dts: spacemit: Add PDMA controller node for K3 SoC
...
dt-bindings: dma: Add SpacemiT K1 PDMA controller
Revert "riscv: config: enable dma driver for spacemit k1"
Revert "driver: k1: add dma driver support for spacemit k1"
Revert "riscv: k1: dt-bindings: support dma binding for spacemit k1 soc"
rvck-6.6

问题 2:

在 revert 的 commit message 中应该同样按照其他 commit 的格式进行说明,以 "Revert "riscv: k1: dt-bindings: support dma binding for spacemit k1 soc" 为例

Revert "riscv: k1: dt-bindings: support dma binding for spacemit k1 soc"

category: feature
bugzilla: https://github.com/RVCK-Project/rvck/issues/320
// note: 这里还是要记录 issue#,这样以后我们从 git log 中可以通过 issue# 找到关联的 pr#,回溯历史信息。

正文
// note
// commit 的正文不要说 “This reverts commit 944dcdf50304b18c64b4904af7a4be5035c20fe0.”,
// 因为说 revert 这个动作从 commit 的标题已经显而易见了,再说一遍毫无意义。
// 正文应该说的是为什么要 revert,以及如果改动复杂还要加上详细的设计说明,测试等。
// 这里原因比较简单,就是因为本 PR 将按照上游的做法对 K1 和 K3 一样沿用 mmp_pdma 驱动而不再使用自己 vendor 的驱动了。

Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>

问题3

对于 "Revert "riscv: k1: dt-bindings: support dma binding for spacemit k1 soc" 这个 commit 有个疑问:你删除了 spacemit-k1-dma.h,但是 arch/riscv/boot/dts/spacemit/k1.dtsi 中还有 #include <dt-bindings/dma/spacemit-k1-dma.h>, 你编译 dtb 时没有看到告警,或者你本地没有运行 dtbcheck 吗?请单独提一笔 commit 清理这个,并在 commit message 中说明你为何要这么做。

注意在引用依赖的 commit 时不要用 commit hashcode。而要用 commit 的 title。因为 rvck 会 rebase,导致 commit hash 发生改变,但 title 不变,这一点和上游主线 master 不同。
所以你原先写的诸如 "This reverts commit 944dcdf." 这样的描述是不对的,正确的写法应该是 'This reverts commit "driver: k1: add dma driver support for spacemit k1"'

问题4:

对于 “dmaengine: Drop unnecessary of_match_device() calls” 和 “riscv: dts: spacemit: Add PDMA controller node for K3 SoC” 这两个,上游 commit hashcode 建议用 12 位和其他保持一致。

问题 5

我发现你没有为 defconfig 增加配置,建议普通驱动用 CONFIG_MMP_PDMA=m,尽量不扩大 Image 体积

@EncrowThorne19

Copy link
Copy Markdown
Author

4th review:

问题1:

补丁的提交顺序,应该是先 revert 再加新的功能或者修改,也就是说你本地 git log --oneline 时应该看到的顺序是:

riscv: dts: spacemit: Add PDMA controller node for K3 SoC
...
dt-bindings: dma: Add SpacemiT K1 PDMA controller
Revert "riscv: config: enable dma driver for spacemit k1"
Revert "driver: k1: add dma driver support for spacemit k1"
Revert "riscv: k1: dt-bindings: support dma binding for spacemit k1 soc"
rvck-6.6

问题 2:

在 revert 的 commit message 中应该同样按照其他 commit 的格式进行说明,以 "Revert "riscv: k1: dt-bindings: support dma binding for spacemit k1 soc" 为例

Revert "riscv: k1: dt-bindings: support dma binding for spacemit k1 soc"

category: feature
bugzilla: https://github.com/RVCK-Project/rvck/issues/320
// note: 这里还是要记录 issue#,这样以后我们从 git log 中可以通过 issue# 找到关联的 pr#,回溯历史信息。

正文
// note
// commit 的正文不要说 “This reverts commit 944dcdf50304b18c64b4904af7a4be5035c20fe0.”,
// 因为说 revert 这个动作从 commit 的标题已经显而易见了,再说一遍毫无意义。
// 正文应该说的是为什么要 revert,以及如果改动复杂还要加上详细的设计说明,测试等。
// 这里原因比较简单,就是因为本 PR 将按照上游的做法对 K1 和 K3 一样沿用 mmp_pdma 驱动而不再使用自己 vendor 的驱动了。

Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>

问题3

对于 "Revert "riscv: k1: dt-bindings: support dma binding for spacemit k1 soc" 这个 commit 有个疑问:你删除了 spacemit-k1-dma.h,但是 arch/riscv/boot/dts/spacemit/k1.dtsi 中还有 #include <dt-bindings/dma/spacemit-k1-dma.h>, 你编译 dtb 时没有看到告警,或者你本地没有运行 dtbcheck 吗?请单独提一笔 commit 清理这个,并在 commit message 中说明你为何要这么做。

注意在引用依赖的 commit 时不要用 commit hashcode。而要用 commit 的 title。因为 rvck 会 rebase,导致 commit hash 发生改变,但 title 不变,这一点和上游主线 master 不同。 所以你原先写的诸如 "This reverts commit 944dcdf." 这样的描述是不对的,正确的写法应该是 'This reverts commit "driver: k1: add dma driver support for spacemit k1"'

问题4:

对于 “dmaengine: Drop unnecessary of_match_device() calls” 和 “riscv: dts: spacemit: Add PDMA controller node for K3 SoC” 这两个,上游 commit hashcode 建议用 12 位和其他保持一致。

问题 5

我发现你没有为 defconfig 增加配置,建议普通驱动用 CONFIG_MMP_PDMA=m,尽量不扩大 Image 体积

问题已知晓,关于include/dt-bindings/dma/spacemit-k1-dma.h 头文件打算还是保留下来,因为k1 dma引入的比较早,已经有了上层外设(如 SPI、I2C、UART)都依赖此文件,(很抱歉昨天没有及时发现),如果revret的话,那么在k1.dtsi里的 “dmas = <&pdma0 通道号>”就要使用魔数了

encrow and others added 14 commits July 23, 2026 15:51
category: feature
bugzilla: RVCK-Project#320

--------------------------------

This reverts commit "riscv: config: enable dma driver for spacemit k1".

Following the upstream approach, both K1 and K3 will use the mmp_pdma driver,
so this configuration is not required.

Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
category: feature
bugzilla: RVCK-Project#320

--------------------------------

This reverts commit "driver: k1: add dma driver support for spacemit k1".

Following the upstream approach, both K1 and K3 will use the mmp_pdma driver,
no longer using the vendor driver.

Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit 39ce725
category: feature
bugzilla: RVCK-Project#320

--------------------------------

Add device tree binding documentation for the SpacemiT K1 PDMA
controller.

Signed-off-by: Guodong Xu <guodong@riscstar.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Link: https://lore.kernel.org/r/20250822-working_dma_0701_v2-v5-1-f5c0eda734cc@riscstar.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit 55620b1
category: feature
bugzilla: RVCK-Project#320

--------------------------------

Add the "spacemit,k3-pdma" compatible string for the SpacemiT K3 SoC.

While the K3 PDMA IP reuses most of the design found on the earlier
K1 SoC, a new compatible string is required because the DRCMR
(DMA Request/Command Register) base address for extended DMA request
numbers (>= 64) differs from the K1 implementation.

Signed-off-by: Guodong Xu <guodong@riscstar.com>
Acked-by: Conor Dooley <conor.dooley@microchip.com>
Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Link: https://patch.msgid.link/20260518-k3-pdma-v6-1-67fdf319a8f8@linux.spacemit.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit c0f0d93
category: feature
bugzilla: RVCK-Project#320

--------------------------------

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is ignored (apart
from emitting a warning) and this typically results in resource leaks.
To improve here there is a quest to make the remove callback return
void. In the first step of this quest all drivers are converted to
.remove_new() which already returns void. Eventually after all drivers
are converted, .remove_new() is renamed to .remove().

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20230919133207.1400430-26-u.kleine-koenig@pengutronix.de
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit c48de45
category: feature
bugzilla: RVCK-Project#320

--------------------------------

If probe is reached, we've already matched the device and in the case of
DT matching, the struct device_node pointer will be set. Therefore, there
is no need to call of_match_device() in probe.

Signed-off-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20231006213835.332848-1-robh@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit e73a9a1
category: feature
bugzilla: RVCK-Project#320

--------------------------------

Add support for retrieving and enabling an optional clock during
mmp_pdma_probe(). It is optional because in Marvell devices
such as "marvell,pdma-1.0" the clocks property is not a required
property. But in SpacemiT K1 PDMA, "spacemit,k1-pdma" as the dt
binding schema file stated, clocks is required.

Signed-off-by: Guodong Xu <guodong@riscstar.com>
Link: https://lore.kernel.org/r/20250822-working_dma_0701_v2-v5-2-f5c0eda734cc@riscstar.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit fc72462
category: feature
bugzilla: RVCK-Project#320

Replace devm_reset_control_get_optional_exclusive_deasserted() with explicit
devm_reset_control_get_optional_exclusive() and reset_control_deassert() calls
for compatibility with Linux 6.6 kernels.

--------------------------------

Add support to acquire and deassert an optional hardware reset controller
during mmp_pdma_probe(). It is optional because in Marvell devices
such as "marvell,pdma-1.0" the resets property is not a required
property. But in SpacemiT K1 PDMA, "spacemit,k1-pdma" as the dt
binding schema file stated, resets is required.

Signed-off-by: Guodong Xu <guodong@riscstar.com>
Link: https://lore.kernel.org/r/20250822-working_dma_0701_v2-v5-3-f5c0eda734cc@riscstar.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit 35e40bf
category: feature
bugzilla: RVCK-Project#320

--------------------------------

Introduce mmp_pdma_ops structure to abstract 32-bit addressing operations
and enable support for different controller variants. This prepares for
adding 64-bit addressing support.

The ops structure includes:
- Hardware register operations (read/write DDADR, DSADR, DTADR)
- Descriptor memory operations (manipulate descriptor structs)
- Controller configuration (run bits, DMA mask)

Convert existing 32-bit operations to use the new abstraction layer
while maintaining backward compatibility.

Cc: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Guodong Xu <guodong@riscstar.com>
Link: https://lore.kernel.org/r/20250822-working_dma_0701_v2-v5-4-f5c0eda734cc@riscstar.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit 5cfe585
category: feature
bugzilla: RVCK-Project#320

--------------------------------

Add support for SpacemiT K1 PDMA controller which features 64-bit
addressing capabilities.

The SpacemiT K1 PDMA extends the descriptor format with additional
32-bit words for high address bits, enabling access to memory beyond
4GB boundaries. The new spacemit_k1_pdma_ops provides necessary 64-bit
address handling functions and k1 specific controller configurations.

Key changes:
- Add ARCH_SPACEMIT dependency to Kconfig
- Define new high 32-bit address registers (DDADRH, DSADRH, DTADRH)
- Add DCSR_LPAEEN bit for Long Physical Address Extension Enable
- Implement 64-bit operations for SpacemiT K1 PDMA

Signed-off-by: Guodong Xu <guodong@riscstar.com>
Link: https://lore.kernel.org/r/20250822-working_dma_0701_v2-v5-5-f5c0eda734cc@riscstar.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit 49400b7
category: feature
bugzilla: RVCK-Project#320

--------------------------------

The driver's existing logic for setting the DMA mask for "marvell,pdma-1.0"
was flawed. It incorrectly relied on pdev->dev->coherent_dma_mask instead
of declaring the hardware's fixed addressing capability. A cleaner and
more correct approach is to define the mask directly based on the hardware
limitations.

The MMP/PXA PDMA controller is a 32-bit DMA engine. This is supported by
datasheets and various dtsi files for PXA25x, PXA27x, PXA3xx, and MMP2,
all of which are 32-bit systems.

This patch simplifies the driver's logic by replacing the 'u64 dma_mask'
field with a simpler 'u32 dma_width' to store the addressing capability
in bits. The complex if/else block in probe() is then replaced with a
single, clear call to dma_set_mask_and_coherent(). This sets a fixed
32-bit DMA mask for "marvell,pdma-1.0" and a 64-bit mask for
"spacemit,k1-pdma," matching each device's hardware capabilities.

Finally, this change also works around a specific build error encountered
with clang-20 on x86_64 allyesconfig. The shift-count-overflow error is
caused by a known clang compiler issue where the DMA_BIT_MASK(n) macro's
ternary operator is not correctly evaluated in static initializers. By
moving the macro's evaluation into the probe() function, the driver avoids
this compiler bug.

Fixes: 5cfe585 ("dmaengine: mmp_pdma: Add SpacemiT K1 PDMA support with 64-bit addressing")
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Closes: https://lore.kernel.org/lkml/CA+G9fYsPcMfW-e_0_TRqu4cnwqOqYF3aJOeKUYk6Z4qRStdFvg@mail.gmail.com
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Guodong Xu <guodong@riscstar.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Nathan Chancellor <nathan@kernel.org> # build
Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit f46b476
category: feature
bugzilla: RVCK-Project#320

--------------------------------

Refactor the DRCMR macro into a helper function mmp_pdma_get_drcmr()
to support variable extended DRCMR base addresses across different PDMA
implementations, such as SpacemiT K3.

Signed-off-by: Guodong Xu <guodong@riscstar.com>
Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Link: https://patch.msgid.link/20260518-k3-pdma-v6-2-67fdf319a8f8@linux.spacemit.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit 6587b86
category: feature
bugzilla: RVCK-Project#320

--------------------------------

SpacemiT K3 reuses most of the PDMA IP design found on K1, with one
difference being the extended DRCMR base address. Add "spacemit,k3-pdma"
compatible string and define a new mmp_pdma_ops for K3 PDMA.

Signed-off-by: Guodong Xu <guodong@riscstar.com>
Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Link: https://patch.msgid.link/20260518-k3-pdma-v6-3-67fdf319a8f8@linux.spacemit.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
mainline inclusion
from mainline-7.2-rc1
commit 3f47ca8
category: feature
bugzilla: RVCK-Project#320

Added `interrupt-parent = <&saplic>;` to the PDMA node in k3.dtsi,
because the `soc` node in our v6.6 tree does not inherit the
interrupt controller context globally.

--------------------------------

Add the Peripheral DMA (PDMA) controller node for the SpacemiT K3 SoC.
The PDMA controller provides general-purpose DMA capabilities for various
peripheral devices across the system to offload CPU data transfers.

Unlike the previous K1 SoC, where some DMA masters had memory addressing
limitations (e.g. restricted to the 0-4GB space) requiring a dedicated
dma-bus with dma-ranges to restrict memory allocations, the K3 DMA masters
have full memory addressing capabilities. Therefore, the PDMA node is now
instantiated directly under the main soc bus.

Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Link: https://patch.msgid.link/20260518-k3-pdma-v6-4-67fdf319a8f8@linux.spacemit.com
Signed-off-by: Yixun Lan <dlan@kernel.org>
Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/29992183719

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/321/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware ['qemu']
LAVA Testcase path lava-testcases/common-test/ltp/ltp.yaml
need run job kunit-test,kernel-build,check-patch,lava-trigger

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[08:49:57] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 21

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_29992183719_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_29992183719_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_321__common-test_qemu

result: Lava check done!

@unicornx

unicornx commented Jul 23, 2026

Copy link
Copy Markdown

5th review

“riscv: config: enable dma driver for spacemit k1 and k3”

rvck 只需要改 defconfig,因为 rvck 的设计思想是一份配置支持所有的产品,k1_defconfig 和 k3_defconfig 实际上是不支持的,已经有一个 PR #337 将会删除这两个文件。目前请只要改 defconfig。

category: feature
bugzilla: RVCK-Project#320

--------------------------------

Enable DMA support

Signed-off-by: Yongchao Jia <yongchao.jia@spacemit.com>
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/30017029127

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/321/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware ['qemu']
LAVA Testcase path lava-testcases/common-test/ltp/ltp.yaml
need run job kunit-test,kernel-build,check-patch,lava-trigger

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu cancelled
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[14:46:12] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 21

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_30017029127_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_30017029127_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_321__common-test_qemu

result: Lava check done!

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[14:46:12] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 21

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_30017029127_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/321_30017029127_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_321__common-test_qemu

result: Lava check done!

@unicornx unicornx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Reviewed-by: Chen Wang wangchen20@iscas.ac.cn
Tested-by: Chen Wang wangchen20@iscas.ac.cn only built pass with defconfig and boot successfully with QEMU and insmod passed.

我这里没有 K1/K3 的硬件,所以请 @EncrowThorne19 确保 dma 功能在 K1/K3 上工作正常。

另外,请更新一下 PR 的描述,将 PR 中涉及的修改简单总结补充一下,方便以后回溯,谢谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DMA: Support Peripheral DMA (PDMA) for SpacemiT K3 SoC

6 participants