Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 5, 2025

BCM2711 has three distinct DMA engine types with different register maps and control blocks. This PR implements type-safe support for all three variants while avoiding virtual function overhead.

Implementation

Architecture

  • CRTP base class (DmaBase<Derived, DmaTag>) provides shared functionality with compile-time dispatch
  • Type traits (DmaTraits<DmaTag>) associate register maps and control blocks with each DMA type
  • Zero overhead: No virtual functions, all polymorphism resolved at compile time

DMA Types

// Standard DMA (channels 0-6, 8-10): 32-bit addressing
auto dma = Dma::GetInstance(Dma::Channel::kChannel0);
auto* cb = dma_memory.AllocateObject<DmaControlBlock>();
Dma::ConfigureMemoryToMemory(cb, src_phys, dst_phys, size);

// DMA Lite (channel 7): Simplified for basic operations
auto dma_lite = DmaLite::GetInstance(DmaLite::Channel::kChannel7);
auto* cb = dma_memory.AllocateObject<DmaLiteControlBlock>();

// DMA4 (channels 11-14): 40-bit addressing for >1GB RAM
auto dma4 = Dma4::GetInstance(Dma4::Channel::kChannel11);
auto* cb = dma_memory.AllocateObject<Dma4ControlBlock>();
Dma4::ConfigureMemoryToMemory(cb, src_phys_64, dst_phys_64, size);  // 40-bit addresses

Key Files

  • dma_base.hpp: CRTP base with common methods (Enable, Reset, Start, WaitForCompletion, etc.)
  • dma_standard.hpp/cpp: Standard DMA (channels 0-6, 8-10)
  • dma_lite.hpp/cpp: DMA Lite (channel 7)
  • dma4.hpp/cpp: DMA4 with 40-bit addressing (channels 11-14)
  • registers_dma.hpp: Added Dma4RegisterMap and Dma4ControlBlock with split address fields

Register Mapping

  • Channels 11-14 mapped only to Dma4RegisterMap (not DmaRegisterMap)
  • REG_DMA11-14 set to nullptr to prevent misuse
  • Channel 15 not available on BCM2711

Example

dma_types_example.cpp demonstrates all three types with performance comparison and verification.

Backward Compatibility

include/rpl4/peripheral/dma.hpp now includes all three types. Existing code using Dma class unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>DMA, DMALite, DMA4対応</issue_title>
<issue_description>- raspberry pi 4のDMAは3種類ありらそれぞれレジスタマップとControl Blockが異なる。

  • なるべくメモリアクセスが少なくなるように、コンパイル時に多くが確定するように、これらのDMAを共通に扱えるようにする
  • 共通機能は同じ実装が使えるので、ベースクラスに機能を追加する形で各DMAクラスを実装すれば良さそうです。
  • 仮想関数はなるべく避けたいです
  • 最初の一回の初期化時に処理が増えるのは許容します
  • DMAの仕様はBCM2711のデータシートを参照してください
  • それぞれのDMAの違いを把握するのにちょうど良いexampleを追加で実装してください</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits November 5, 2025 00:32
…o TI

Co-authored-by: yutatech <61183418+yutatech@users.noreply.github.com>
Co-authored-by: yutatech <61183418+yutatech@users.noreply.github.com>
Co-authored-by: yutatech <61183418+yutatech@users.noreply.github.com>
Co-authored-by: yutatech <61183418+yutatech@users.noreply.github.com>
Co-authored-by: yutatech <61183418+yutatech@users.noreply.github.com>
Copilot AI changed the title [WIP] Add DMA, DMALite, and DMA4 support for Raspberry Pi 4 Add DMA, DMA Lite, and DMA4 support for BCM2711 Nov 5, 2025
Copilot AI requested a review from yutatech November 5, 2025 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DMA, DMALite, DMA4対応

2 participants