Skip to content

[drivers][dma] Fix DMA boundaries and PL330/SDIO transfers - #11945

Open
GuEe-GUI wants to merge 1 commit into
RT-Thread:masterfrom
GuEe-GUI:fixup_dma
Open

GuEe-GUI wants to merge 1 commit into
RT-Thread:masterfrom
GuEe-GUI:fixup_dma

Conversation

@GuEe-GUI

Copy link
Copy Markdown
Contributor

拉取/合并请求描述:(PR description)

[

  • include the final fitting bitmap range when allocating from a DMA pool
  • match DMA pool ownership with exclusive region boundaries and allocation size
  • preserve mapping ownership when freeing cached and non-linear DMA memory
  • emit the correct PL330 DMALP loop-count byte
  • wait for DMAEND after DMAKILL before reusing a PL330 channel or releasing resources
  • honor the peripheral burst quirk when generating PL330 single-transfer programs
  • reject 32-bit DW SDIO IDMAC buffers and descriptor rings outside its DMA aperture
  • use one-shot timers for DW SDIO command and data timeouts

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用clang-format 源码格式化工具确保格式符合RT-Thread代码规范 This PR has been formatted with clang-format and complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

- include the final fitting bitmap range when allocating from a DMA pool
- match DMA pool ownership with exclusive region boundaries and allocation size
- preserve mapping ownership when freeing cached and non-linear DMA memory
- emit the correct PL330 DMALP loop-count byte
- wait for DMAEND after DMAKILL before reusing a PL330 channel or releasing resources
- honor the peripheral burst quirk when generating PL330 single-transfer programs
- reject 32-bit DW SDIO IDMAC buffers and descriptor rings outside its DMA aperture
- use one-shot timers for DW SDIO command and data timeouts

Signed-off-by: GuEe-GUI <2991707448@qq.com>
@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 fixup_dma
    Enter PR branch fixup_dma in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 fixup_dma 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the fixup_dma branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/drivers/dma/dma-pl330.c
  • components/drivers/dma/dma_pool.c
  • components/drivers/sdio/host/sdio-dw.c

📊 Current Review Status (Last Updated: 2026-10-29 16:24 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@GuEe-GUI

Copy link
Copy Markdown
Contributor Author

@Rbb666

@github-actions

Copy link
Copy Markdown

@Rbb666 Rbb666 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

发现两处 PL330 错误恢复问题,详见行内意见。已使用提取自本提交的 C 函数进行主机桩测试;尚未进行硬件或 QEMU 验证。


if ((err = pl330_wait_stopped(pl330, pc)))
{
return err;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] 准备失败后仍需允许停止旧传输

当旧传输仍处于 WFP、循环运行中或已经进入 FAULT 时,这里会返回超时或 I/O 错误。上层 rt_dma_prep_single() 会把该错误写入 chan->prep_err,而 rt_dma_chan_stop() 在发现 prep_err 非零时直接返回,不再调用控制器的 stop(),因此后续清理无法下发 DMAKILL。对于需要 DMAKILL 才能退出的状态,重试准备也无法恢复。

使用本提交中的函数进行主机桩测试,能够复现 prep 返回错误后,调用 rt_dma_chan_stop() 时控制器停止函数的调用次数为 0。建议同步调整框架的停止路径,确保准备失败不会阻止清理此前的活动传输;prep_memcpy 和 prep_cyclic 新增的检查也需要覆盖这一情况。

}
if (csr == PL330_CS_FAULT || csr == PL330_CS_FLTCMP)
{
return -RT_EIO;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] 等待 DMAKILL 完成时不应因旧故障状态立即退出

pl330_dma_stop() 写入 DBGCMD 后立即调用此函数,但调试指令可能需要若干时钟周期才开始执行。如果第一次读取 CSR 时仍是原来的 FAULT/FLTCMP,这里就返回 -RT_EIO,没有等到 DMAKILL 将通道推进到 STOP,导致停止操作误报失败,也没有完成本次修改预期的同步停止。

建议区分准备/启动前的状态检查与 DMAKILL 后的停止等待:后者应允许故障状态在指令执行前短暂存在,并有界等待 STOP。主机桩测试中,将 CSR 设置为 FAULT、计划下一次轮询转为 STOP,当前函数会在第一次读取后直接退出。

依据:ARM PL330 技术参考手册 第 2.5.1 节说明调试指令可能延迟若干周期执行,第 4.3.10 节说明 DMAKILL 最终使通道进入 Stopped。

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants