Skip to content

Conversation

@GuEe-GUI
Copy link
Contributor

@GuEe-GUI GuEe-GUI commented Dec 1, 2025

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

[

  1. Append WT attribute.
  2. Change the API with pool size only.
  3. Add address mask for DMA
  4. Change DMA lock to mutex
  5. Add pause callback for DMA engine driver
  6. Add DMA Engine test
  7. Add ARM PL330 DMA Engine driver

]

当前拉取/合并请求的状态 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
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

1. Append WT attribute.
2. Change the API with pool size only.

Signed-off-by: GuEe-GUI <2991707448@qq.com>
@GuEe-GUI GuEe-GUI requested a review from Rbb666 as a code owner December 1, 2025 07:24
@github-actions
Copy link

github-actions bot commented Dec 1, 2025

👋 感谢您对 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

  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  • 将目标分支设置为 \ Set the target branch to:dma
  • 设置PR number为 \ Set the PR number to:10987
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将自动推送至你的分支。
    The formatted code will be automatically pushed to your branch.

完成后,提交将自动更新至 dma 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the 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

github-actions bot commented Dec 1, 2025

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: Maihuanyi

Changed Files (Click to expand)
  • components/drivers/dma/Kconfig
  • components/drivers/dma/SConscript
  • components/drivers/dma/dma-pl330.c
  • components/drivers/dma/dma.c
  • components/drivers/dma/dma_pool.c
  • components/drivers/include/drivers/dma.h

📊 Current Review Status (Last Updated: 2025-12-02 11:03 CST)

  • Maihuanyi Pending Review

📝 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
Contributor Author

GuEe-GUI commented Dec 1, 2025

@Rbb666 @Maihuanyi

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the DMA (Direct Memory Access) subsystem with several enhancements including a new ARM PL330 DMA engine driver, pause callback support, write-through (WT) cache attribute, address mask validation, mutex-based locking, and a DMA test utility. The changes span core DMA infrastructure, memory pool management, and a new hardware driver implementation.

Key Changes:

  • Adds ARM PL330 DMA controller driver with full microcode generation support
  • Introduces DMA channel pause functionality and address mask validation for hardware limitations
  • Refactors DMA pool extraction API to use memblock internally instead of external region lists

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
examples/test/dma_test.c New DMA memcpy test utility demonstrating DMA usage with memory allocation and transfer verification
components/drivers/include/drivers/dma.h Adds pause callback, address mask support, WT cache flag; breaks API by changing rt_dma_pool_extract signature
components/drivers/dma/dma_pool.c Updates pool extraction to use memblock, adds debug logging, fixes WT mapping support
components/drivers/dma/dma.c Replaces direct mutex calls with conditional locking helpers, implements pause functionality, adds address mask validation
components/drivers/dma/dma-pl330.c Complete ARM PL330 DMA engine driver with microcode generation, interrupt handling, and multi-direction support
components/drivers/dma/SConscript Adds conditional compilation for PL330 driver
components/drivers/dma/Kconfig Adds configuration option for PL330 driver with CLK and RESET dependencies

rt_bitmap_clear_bit(pool->map, bit);
}

LOG_D("%s offset = %p, pages = %d", "Free", offset, size);
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

🟡 Error Message / 错误信息

English: Same issue as above - using %p format specifier for rt_ubase_t type. Should use %#lx with proper casting:

LOG_D("%s offset = %#lx, pages = %d", "Free", (unsigned long)offset, size);

中文: 与上述相同的问题 - 对 rt_ubase_t 类型使用 %p 格式说明符。应使用 %#lx 并进行适当的类型转换:

LOG_D("%s offset = %#lx, pages = %d", "Free", (unsigned long)offset, size);
Suggested change
LOG_D("%s offset = %p, pages = %d", "Free", offset, size);
LOG_D("%s offset = %#lx, pages = %d", "Free", (unsigned long)offset, size);

Copilot uses AI. Check for mistakes.
}

region = &reg->memreg;
if (rt_strcmp(region->name, "dma-pool") || !reg->memreg.name)
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

🟠 Bug / 错误

English: Incorrect string comparison logic. The condition rt_strcmp(region->name, "dma-pool") returns 0 when strings match, but the code continues (skips) when the result is non-zero OR when name is NULL. This means it will skip regions named "dma-pool" (the ones we want) and process everything else. The logic should be:

if (rt_strcmp(region->name, "dma-pool") != 0 || !reg->memreg.name)

Or better yet, to find "dma-pool":

if (!region->name || rt_strcmp(region->name, "dma-pool") != 0)
{
    continue;  // Skip if not "dma-pool"
}

中文: 字符串比较逻辑错误。条件 rt_strcmp(region->name, "dma-pool") 在字符串匹配时返回 0,但代码在结果非零或名称为 NULL 时继续(跳过)。这意味着它会跳过名为 "dma-pool" 的区域(我们想要的),而处理其他所有区域。逻辑应该是:

if (rt_strcmp(region->name, "dma-pool") != 0 || !reg->memreg.name)

或者更好的是,查找 "dma-pool":

if (!region->name || rt_strcmp(region->name, "dma-pool") != 0)
{
    continue;  // 如果不是 "dma-pool" 则跳过
}
Suggested change
if (rt_strcmp(region->name, "dma-pool") || !reg->memreg.name)
if (!region->name || rt_strcmp(region->name, "dma-pool") != 0)

Copilot uses AI. Check for mistakes.
Comment on lines +256 to +262
* 15 4 3 2 1 10 ... 8 7 6 5 4 3 2 1 0
* 0 0 0 0 0 |rd[2:0]|1 0 1 1 1 1 0 0
*
* 47 ... 16
* imm[32:0]
*
* rd: b000 for SAR, b001 CCR, b010 DAR
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

🟡 Documentation / 文档

English: The bit field encoding comment is incorrect. It shows "15 4 3 2 1 10 ... 8" which doesn't make sense (bit 10 between 1 and 8). Based on the DMAMOV instruction format, this should likely be "15 ... 8 7 6 5 4 3 2 1 0" or similar. Please verify and correct the bit field diagram.

中文: 位字段编码注释不正确。它显示 "15 4 3 2 1 10 ... 8",这没有意义(位 10 在 1 和 8 之间)。根据 DMAMOV 指令格式,这应该是 "15 ... 8 7 6 5 4 3 2 1 0" 或类似格式。请验证并更正位字段图。

Suggested change
* 15 4 3 2 1 10 ... 8 7 6 5 4 3 2 1 0
* 0 0 0 0 0 |rd[2:0]|1 0 1 1 1 1 0 0
*
* 47 ... 16
* imm[32:0]
*
* rd: b000 for SAR, b001 CCR, b010 DAR
* 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
* | opcode | rd | reserved | 0xbc |
*
* 47 ... 16
* imm[31:0]
*
* rd: b000 for SAR, b001 for CCR, b010 for DAR

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +85
#define RT_DMA_ADDR_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL << (n)) - 1))
rt_uint64_t addr_mask;
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

[nitpick] 🟡 Best Practices / 最佳实践

English: The RT_DMA_ADDR_MASK macro is defined inside the struct declaration which is unusual and reduces readability. This macro should be moved outside the struct, ideally near the top of the file with other macro definitions, or before the struct definition.

中文: RT_DMA_ADDR_MASK 宏定义在结构体声明内部,这很不寻常且降低了可读性。此宏应移到结构体外部,理想情况下应放在文件顶部与其他宏定义一起,或在结构体定义之前。

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

@GuEe-GUI 这个宏有用吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DMA驱动私用

return pool->start + bit * ARCH_PAGE_SIZE;
}
_next:
;
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

[nitpick] 🟡 Best Practices / 最佳实践

English: The empty statement after the label _next: at line 301 is unnecessary. While syntactically correct, it reduces code clarity. Consider removing it or adding a comment to explain its purpose.

中文: 标签 _next: 后的空语句(第 301 行)是不必要的。虽然语法正确,但降低了代码清晰度。考虑删除它或添加注释说明其目的。

Suggested change
;

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

你懂个毛


HWREG32(pl330->regs + PL330_REG_INTCLR) = RT_BIT(i);

csr = HWREG32(pl330->regs + PL330_REG_CSR(i)) & 0xf;
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

[nitpick] 🟠 Maintainability / 可维护性

English: Magic number without explanation. The value 0xf is used to mask the CSR register value, but there's no comment explaining why this specific mask is needed or what bits it represents. Add a comment or define a constant like PL330_CSR_STATUS_MASK for clarity.

中文: 没有解释的魔术数字。值 0xf 用于掩码 CSR 寄存器值,但没有注释解释为什么需要这个特定掩码或它代表哪些位。添加注释或定义常量如 PL330_CSR_STATUS_MASK 以提高清晰度。

Copilot uses AI. Check for mistakes.
{
continue;
}

Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

[nitpick] 🟡 Maintainability / 可维护性

English: Code removal without clear explanation. Lines were removed that checked for RT_DMA_F_LINEAR flag compatibility between requested flags and pool flags. The removal of this check may allow allocation from incompatible pools. If this check is intentionally removed as part of the update, it should be documented in the commit message or PR description explaining why this validation is no longer needed.

中文: 代码删除没有明确的解释。删除了检查请求的标志和池标志之间 RT_DMA_F_LINEAR 标志兼容性的代码行。删除此检查可能允许从不兼容的池中分配。如果此检查作为更新的一部分被有意删除,应在提交消息或 PR 描述中记录,解释为什么不再需要此验证。

Suggested change
/* Check for RT_DMA_F_LINEAR compatibility */
if ((flags & RT_DMA_F_LINEAR) && !(pool->flags & RT_DMA_F_LINEAR))
{
continue;
}

Copilot uses AI. Check for mistakes.
1. Add address mask for DMA
2. Change DMA lock to mutex
3. Add pause callback for DMA engine driver

Signed-off-by: GuEe-GUI <2991707448@qq.com>
Signed-off-by: GuEe-GUI <2991707448@qq.com>
Signed-off-by: GuEe-GUI <2991707448@qq.com>
@GuEe-GUI
Copy link
Contributor Author

GuEe-GUI commented Dec 2, 2025

@Rbb666 除部分 AI 不合理修改外均已修改

@Rbb666 Rbb666 merged commit e5e0ad2 into RT-Thread:master Dec 3, 2025
58 checks passed
Dailingxiang1 pushed a commit to Dailingxiang1/rt-thread that referenced this pull request Dec 11, 2025
* Append WT attribute.
* Change the API with pool size only.
* Add address mask for DMA
* Change DMA lock to mutex
* Add pause callback for DMA engine driver
* Add DMA Engine test
* Add ARM PL330 DMA Engine driver
@GuEe-GUI GuEe-GUI deleted the dma branch December 12, 2025 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

2 participants