Part 1
요약·해설
Single-owner channel, no heap allocation, Configured·Running·Suspended transition을 다룹니다.
single owner · spin lock
no heap · static descriptors
configured · running · suspended
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
22A9BDC5378FD97D9FB44705387A394B48864080CBF8B8921F1E8020A30033D8
.. _dma_api:
Direct Memory Access (DMA)
##########################
Overview
********
Direct Memory Access (Controller) is a commonly provided type of co-processor that can typically
offload transferring data to and from peripherals and memory.
The DMA API is not a portable API and really cannot be as each DMA has unique memory requirements,
peripheral interactions, and features. The API in effect provides a union of all useful DMA
functionality drivers have needed in the tree. It can still be a good abstraction, with care, for
peripheral devices for vendors where the DMA IP might be very similar but have slight variances.
Driver Implementation Expectations
**********************************
Synchronization and Ownership
+++++++++++++++++++++++++++++
From an API point of view, a DMA channel is a single-owner object, meaning the drivers should not
attempt to wrap a channel with kernel synchronization primitives such as mutexes or semaphores. If
DMA channels require mutating shared registers, those register updates should be wrapped in a spin
lock.
This enables the entire API to be low-cost and callable from any call context, including ISRs where
it may be very useful to start/stop/suspend/resume/reload a channel transfer.
Transfer Descriptor Memory Management
+++++++++++++++++++++++++++++++++++++
Drivers should not attempt to use heap allocations of any kind. If object pools are needed for
transfer descriptors then those should be setup in a way that does not break the promise of
ISR-allowable calls. Many drivers choose to create a simple static descriptor array per channel with
the size of the descriptor array adjustable using Kconfig.
Channel State Machine Expectations
++++++++++++++++++++++++++++++++++
DMA channels should be viewed as state machines that the DMA API provides transition events for in
the form of API calls. Every driver is expected to maintain its own channel state tracking. The busy
state of the channel should be inspectable at any time with :c:func:`dma_get_status()`.
A diagram showing those expectated possible state transitions and their API calls is provided here
for reference.
.. graphviz::
:caption: DMA state finite state machine
digraph {
node [style=rounded];
edge [fontname=Courier];
init [shape=point];
CONFIGURED [label=Configured,shape=box];
RUNNING [label=Running,shape=box];
SUSPENDED [label=Suspended,shape=box];
init -> CONFIGURED [label=dma_config];
CONFIGURED -> RUNNING [label=dma_start];
CONFIGURED -> CONFIGURED [label=dma_stop];
RUNNING -> CONFIGURED [label=dma_stop];
RUNNING -> RUNNING [label=dma_start];
RUNNING -> RUNNING [label=dma_resume, headport=w];
RUNNING -> SUSPENDED [label=dma_suspend];
SUSPENDED -> SUSPENDED [label=dma_suspend];
SUSPENDED -> RUNNING [label=dma_resume];
SUSPENDED -> CONFIGURED [label=dma_stop];
}
API Reference
*************
.. doxygengroup:: dma_interface
Part 3
한국어 전문 번역
개요
Direct Memory Access controller는 peripheral과 memory 사이의 data transfer를 보통 대신 수행하는 co-processor입니다.
DMA마다 memory requirement, peripheral interaction, feature가 고유하므로 DMA API는 portable API가 아니며 본질적으로 완전히 portable할 수 없습니다. 실제 API는 tree 안의 driver가 필요로 한 유용한 DMA 기능의 합집합입니다. 다만 같은 vendor의 DMA IP가 매우 비슷하고 조금씩만 다를 때는 주의해서 사용하면 peripheral device의 좋은 abstraction이 될 수 있습니다.
Driver 구현 기대 사항
동기화와 ownership
API 관점에서 DMA channel은 single-owner object입니다. 따라서 driver가 mutex나 semaphore 같은 kernel synchronization primitive로 channel을 감싸면 안 됩니다. 여러 channel이 shared register를 바꿔야 한다면 해당 register update만 spin lock으로 보호해야 합니다.
이 원칙 덕분에 API 비용이 낮고 ISR을 포함한 어느 call context에서도 channel transfer를 start, stop, suspend, resume, reload할 수 있습니다.
Transfer descriptor memory 관리
Driver는 어떤 종류의 heap allocation도 사용하면 안 됩니다. Transfer descriptor용 object pool이 필요하면 ISR에서도 호출 가능하다는 약속을 깨지 않는 방식으로 구성해야 합니다. 많은 driver는 channel마다 단순 static descriptor array를 만들고 Kconfig로 array 크기를 조정합니다.
Channel state machine 기대 사항
DMA channel은 DMA API call이 transition event를 제공하는 state machine으로 봐야 합니다. 각 driver는 자체 channel state를 추적해야 하며 dma_get_status()로 언제든 busy 상태를 확인할 수 있어야 합니다.
기대되는 state transition과 API call은 다음과 같습니다.
dma_config → Configured
dma_start → Runningdma_stop → Configured
dma_stop → Configureddma_start → Runningdma_resume → Runningdma_suspend → Suspended
dma_suspend → Suspendeddma_resume → Runningdma_stop → Configured
API reference
dma_interface Doxygen group이 DMA interface의 공식 API reference를 제공합니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.