Skip to content

[dm][dma] Update DMA - #11678

Open
GuEe-GUI wants to merge 4 commits into
RT-Thread:masterfrom
GuEe-GUI:dma
Open

[dm][dma] Update DMA#11678
GuEe-GUI wants to merge 4 commits into
RT-Thread:masterfrom
GuEe-GUI:dma

Conversation

@GuEe-GUI

@GuEe-GUI GuEe-GUI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

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

[

  1. Extend DMA mapping to honor OFW dma-ranges even when no reserved memory pool is present, and add PCI host-bridge DMA-region translation for PCI devices. Prefer 32-bit-addressable allocations for translated devices, improve pool allocation fallbacks and synchronization, and establish a linear mapping for installed DMA pools when possible.
  2. Fix PL330 channel allocation so device-tree cells select peripheral request lines rather than execution channels. Generate proper peripheral DMA microcode using DMAWFP, DMALDP, DMASTP, and DMAFLUSHP, encode burst lengths correctly, honor transfer direction and non-secure attributes, and allocate microcode from DMA-coherent memory.

]

当前拉取/合并请求的状态 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自查

Extend DMA mapping to honor OFW dma-ranges even
when no reserved memory pool is present,
and add PCI host-bridge DMA-region translation for PCI devices.
Prefer 32-bit-addressable allocations for translated devices,
improve pool allocation fallbacks and synchronization,
and establish a linear mapping for installed DMA pools when possible.

Signed-off-by: GuEe-GUI <2991707448@qq.com>
Fix PL330 channel allocation so device-tree cells
select peripheral request lines rather than execution channels.
Generate proper peripheral DMA microcode using DMAWFP, DMALDP, DMASTP, and DMAFLUSHP,
encode burst lengths correctly,
honor transfer direction and non-secure attributes,
and allocate microcode from DMA-coherent memory.

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

github-actions Bot commented Aug 1, 2026

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

📊 Current Review Status (Last Updated: 2026-08-07 09:38 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.

@github-actions

github-actions Bot commented Aug 1, 2026

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

  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  • 将目标分支设置为 \ Set the target branch to:dma
  • 设置PR number为 \ Set the PR number to:11678
  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

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gd32105r-start

  • CODE: .text -104 B (-0.1%, 69,260 B / 262,144 B, total: 26% used)

hc32f334

  • FLASH: .text -104 B (-0.1%, 99,460 B / 131,072 B, total: 76% used)

infineon-psoc6

  • flash: .text -104 B (-0.1%, 116,104 B / 262,144 B, total: 44% used)

k230

  • SRAM: .eh_frame -48 B, .text -32 B (-0.0%, 1,122,651 B / 268,300,288 B, total: 0% used)

loongson-ls1cdev

  • Code: .text -136 B (-0.0%, 362,632 B)

nuvoton-m487

  • CODE: .text -116 B (-0.0%, 355,696 B / 524,288 B, total: 68% used)

qemu-virt64-aarch64

  • Code: .eh_frame +472 B, .text +3,408 B (+0.4%, 1,060,364 B)
  • Data: .data +8 B (+0.0%, 517,384 B)

raspberry-pico-rp2040

  • FLASH: .rodata -24 B, .text -112 B (-0.1%, 114,064 B / 2,097,152 B, total: 5% used)

simulator

  • Code: .eh_frame +32 B, .eh_frame_hdr +8 B, .rela.dyn -96 B, .text +171 B (+0.0%, 2,634,218 B)
  • Data: .data -128 B (-0.0%, 1,583,108 B)

stm32f407-rt-spark

  • CODE: .text -104 B (-0.1%, 85,728 B / 1,048,576 B, total: 8% used)

stm32l475-atk-pandora-llvm

  • ROM: .text -124 B (-0.1%, 83,384 B / 524,288 B, total: 16% used)

x86

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

English: This PR updates RT-Thread’s DMA infrastructure, improving early DMA pool placement/extraction on AArch64, extending OFW/PCI DMA address translation behavior, and refining PL330 channel/microcode handling.
中文:本 PR 更新了 RT-Thread 的 DMA 基础设施,改进了 AArch64 早期 DMA 内存池的放置/提取逻辑,扩展了 OFW/PCI 的 DMA 地址转换行为,并完善了 PL330 通道分配与微码生成/执行流程。

Changes:

  • Improve AArch64 early DMA pool placement (sub-4G preference, single-bank tail placement) / 改进 AArch64 早期 DMA pool 放置策略(优先 4G 以下、单内存段尾部放置)
  • Extend DMA mapping to honor OFW dma-ranges and add PCI host-bridge DMA translation ops / 扩展 DMA 映射以支持 OFW dma-ranges,并为 PCI 增加 host-bridge DMA 区域转换
  • Update PL330 to allocate channels independently of DT request line IDs and generate peripheral-aware microcode / 更新 PL330:DT 参数选择外设请求线,控制器分配执行通道,并生成面向外设的微码

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
libcpu/aarch64/common/setup.c Adjust early DMA pool reservation strategy (sub-4G preference, tail placement).
components/drivers/dma/dma-pl330.c PL330 channel allocation + CCR/microcode generation updates; coherent microcode allocation.
components/drivers/dma/dma_pool.c OFW/PCI DMA translation ops; pool linear mapping support; allocation behavior changes.
bsp/qemu-virt64-aarch64/README.md Update AMP demo memory requirement from 258MB to 300MB.
bsp/qemu-virt64-aarch64/README_zh.md 同步更新 AMP 示例内存需求为 300MB。
bsp/qemu-virt64-aarch64/amp.dtsi Update run-command comment to match new AMP memory requirement.
Suppressed comments (2)

components/drivers/dma/dma_pool.c:216

  • [bug/问题] ofw_dma_map_alloc() forces RT_DMA_F_32BITS unconditionally, which can cause allocations to fail on platforms where no suitable <4GB pool exists (even if the device could accept higher addresses).

English: Prefer 32-bit allocations, but fall back to the original flags when the 32-bit attempt fails (unless the caller explicitly requested RT_DMA_F_32BITS).
中文:当前无条件强制 RT_DMA_F_32BITS,可能导致低 4G 内存不足时分配失败。建议优先尝试 32-bit,但在失败时回退到原 flags(除非调用者显式要求 RT_DMA_F_32BITS)。

This issue also appears on line 485 of the same file.

static void *ofw_dma_map_alloc(struct rt_device *dev, rt_size_t size,
                               rt_ubase_t *dma_handle, rt_ubase_t flags)
{
    void *cpu_addr;

    flags    |= RT_DMA_F_32BITS;
    cpu_addr  = dma_alloc(dev, size, dma_handle, flags);

    if (cpu_addr && dma_handle)
    {
        *dma_handle = ofw_addr_cpu2dma(dev, *dma_handle);
    }

components/drivers/dma/dma_pool.c:498

  • [bug/问题] pci_dma_map_alloc() forces RT_DMA_F_32BITS unconditionally, which may fail on systems without enough sub-4GB memory even when the PCI DMA translation could work with higher CPU physical addresses.

English: Prefer 32-bit allocations, but retry without RT_DMA_F_32BITS if the first attempt fails (unless the caller explicitly requested RT_DMA_F_32BITS).
中文:当前无条件强制 RT_DMA_F_32BITS,可能在低 4G 内存不足时导致分配失败。建议优先尝试 32-bit,失败后回退到原 flags(除非调用者显式要求 RT_DMA_F_32BITS)。

static void *pci_dma_map_alloc(struct rt_device *dev, rt_size_t size,
                               rt_ubase_t *dma_handle, rt_ubase_t flags)
{
    void *cpu_addr;

    flags    |= RT_DMA_F_32BITS;
    cpu_addr  = dma_alloc(dev, size, dma_handle, flags);

    if (cpu_addr && dma_handle)
    {
        *dma_handle = pci_addr_cpu2dma(dev, *dma_handle);
    }

    return cpu_addr;

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +368 to +376
if (!conf->src_maxburst || conf->src_maxburst > 16 ||
!conf->dst_maxburst || conf->dst_maxburst > 16)
{
return -RT_EINVAL;
}

*ccr = (conf->src_maxburst - 1) << PL330_SRC_BURST_LEN_SHIFT;
*ccr |= (conf->dst_maxburst - 1) << PL330_DST_BURST_LEN_SHIFT;


if (zone_end < platform_mem_region.end + pool_total)
{
LOG_E("No room for sub-4G DMA pool (%u bytes)", pool_total);
if (rt_aspace_map_phy(&rt_kernel_space, &hint, MMU_MAP_K_RWCB,
start >> MM_PAGE_SHIFT, &va))
{
LOG_E("map %s [%p, %p] failed", region->name, start, end);
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