-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[DM/DMA] Update DMA #10987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DM/DMA] Update DMA #10987
Conversation
1. Append WT attribute. 2. Change the API with pool size only. Signed-off-by: GuEe-GUI <2991707448@qq.com>
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-12-02 11:03 CST)
📝 Review Instructions
|
There was a problem hiding this 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); |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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);| LOG_D("%s offset = %p, pages = %d", "Free", offset, size); | |
| LOG_D("%s offset = %#lx, pages = %d", "Free", (unsigned long)offset, size); |
| } | ||
|
|
||
| region = ®->memreg; | ||
| if (rt_strcmp(region->name, "dma-pool") || !reg->memreg.name) |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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" 则跳过
}| if (rt_strcmp(region->name, "dma-pool") || !reg->memreg.name) | |
| if (!region->name || rt_strcmp(region->name, "dma-pool") != 0) |
| * 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 |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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" 或类似格式。请验证并更正位字段图。
| * 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 |
| #define RT_DMA_ADDR_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL << (n)) - 1)) | ||
| rt_uint64_t addr_mask; |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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 宏定义在结构体声明内部,这很不寻常且降低了可读性。此宏应移到结构体外部,理想情况下应放在文件顶部与其他宏定义一起,或在结构体定义之前。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GuEe-GUI 这个宏有用吗?
There was a problem hiding this comment.
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: | ||
| ; |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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 行)是不必要的。虽然语法正确,但降低了代码清晰度。考虑删除它或添加注释说明其目的。
| ; |
There was a problem hiding this comment.
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; |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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 以提高清晰度。
| { | ||
| continue; | ||
| } | ||
|
|
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
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 描述中记录,解释为什么不再需要此验证。
| /* Check for RT_DMA_F_LINEAR compatibility */ | |
| if ((flags & RT_DMA_F_LINEAR) && !(pool->flags & RT_DMA_F_LINEAR)) | |
| { | |
| continue; | |
| } |
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>
|
@Rbb666 除部分 AI 不合理修改外均已修改 |
* 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
拉取/合并请求描述:(PR description)
[
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up