요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
====================
DMA Engine API Guide
====================
Vinod Koul <vinod dot koul at intel.com>
.. note:: For DMA Engine usage in async_tx please see:
``Documentation/crypto/async-tx-api.rst``
Below is a guide to device driver writers on how to use the Slave-DMA API of the
DMA Engine. This is applicable only for slave DMA usage only.
DMA usage
=========
The slave DMA usage consists of following steps:
- Allocate a DMA slave channel
- Set slave and controller specific parameters
- Get a descriptor for transaction
- Submit the transaction
- Issue pending requests and wait for callback notification
The details of these operations are:
1. Allocate a DMA slave channel
Channel allocation is slightly different in the slave DMA context,
client drivers typically need a channel from a particular DMA
controller only and even in some cases a specific channel is desired.
To request a channel dma_request_chan() API is used.
Interface:
.. code-block:: c
struct dma_chan *dma_request_chan(struct device *dev, const char *name);
Which will find and return the ``name`` DMA channel associated with the 'dev'
device. The association is done via DT, ACPI or board file based
dma_slave_map matching table.
A channel allocated via this interface is exclusive to the caller,
until dma_release_channel() is called.
2. Set slave and controller specific parameters
Next step is always to pass some specific information to the DMA
driver. Most of the generic information which a slave DMA can use
is in struct dma_slave_config. This allows the clients to specify
DMA direction, DMA addresses, bus widths, DMA burst lengths etc
for the peripheral.
If some DMA controllers have more parameters to be sent then they
should try to embed struct dma_slave_config in their controller
specific structure. That gives flexibility to client to pass more
parameters, if required.
Interface:
.. code-block:: c
int dmaengine_slave_config(struct dma_chan *chan,
struct dma_slave_config *config)
Please see the dma_slave_config structure definition in dmaengine.h
for a detailed explanation of the struct members. Please note
that the 'direction' member will be going away as it duplicates the
direction given in the prepare call.
3. Get a descriptor for transaction
For slave usage the various modes of slave transfers supported by the
DMA-engine are:
- slave_sg: DMA a list of scatter gather buffers from/to a peripheral
- peripheral_dma_vec: DMA an array of scatter gather buffers from/to a
peripheral. Similar to slave_sg, but uses an array of dma_vec
structures instead of a scatterlist.
- dma_cyclic: Perform a cyclic DMA operation from/to a peripheral till the
operation is explicitly stopped.
- interleaved_dma: This is common to Slave as well as M2M clients. For slave
address of devices' fifo could be already known to the driver.
Various types of operations could be expressed by setting
appropriate values to the 'dma_interleaved_template' members. Cyclic
interleaved DMA transfers are also possible if supported by the channel by
setting the DMA_PREP_REPEAT transfer flag.
A non-NULL return of this transfer API represents a "descriptor" for
the given transaction.
Interface:
.. code-block:: c
struct dma_async_tx_descriptor *dmaengine_prep_slave_sg(
struct dma_chan *chan, struct scatterlist *sgl,
unsigned int sg_len, enum dma_data_direction direction,
unsigned long flags);
struct dma_async_tx_descriptor *dmaengine_prep_peripheral_dma_vec(
struct dma_chan *chan, const struct dma_vec *vecs,
size_t nents, enum dma_data_direction direction,
unsigned long flags);
struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic(
struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
size_t period_len, enum dma_data_direction direction);
struct dma_async_tx_descriptor *dmaengine_prep_interleaved_dma(
struct dma_chan *chan, struct dma_interleaved_template *xt,
unsigned long flags);
The peripheral driver is expected to have mapped the scatterlist for
the DMA operation prior to calling dmaengine_prep_slave_sg(), and must
keep the scatterlist mapped until the DMA operation has completed.
The scatterlist must be mapped using the DMA struct device.
If a mapping needs to be synchronized later, dma_sync_*_for_*() must be
called using the DMA struct device, too.
So, normal setup should look like this:
.. code-block:: c
struct device *dma_dev = dmaengine_get_dma_device(chan);
nr_sg = dma_map_sg(dma_dev, sgl, sg_len);
if (nr_sg == 0)
/* error */
desc = dmaengine_prep_slave_sg(chan, sgl, nr_sg, direction, flags);
Once a descriptor has been obtained, the callback information can be
added and the descriptor must then be submitted. Some DMA engine
drivers may hold a spinlock between a successful preparation and
submission so it is important that these two operations are closely
paired.
.. note::
Although the async_tx API specifies that completion callback
routines cannot submit any new operations, this is not the
case for slave/cyclic DMA.
For slave DMA, the subsequent transaction may not be available
for submission prior to callback function being invoked, so
slave DMA callbacks are permitted to prepare and submit a new
transaction.
For cyclic DMA, a callback function may wish to terminate the
DMA via dmaengine_terminate_async().
Therefore, it is important that DMA engine drivers drop any
locks before calling the callback function which may cause a
deadlock.
Note that callbacks will always be invoked from the DMA
engines tasklet, never from interrupt context.
**Optional: per descriptor metadata**
DMAengine provides two ways for metadata support.
DESC_METADATA_CLIENT
The metadata buffer is allocated/provided by the client driver and it is
attached to the descriptor.
.. code-block:: c
int dmaengine_desc_attach_metadata(struct dma_async_tx_descriptor *desc,
void *data, size_t len);
DESC_METADATA_ENGINE
The metadata buffer is allocated/managed by the DMA driver. The client
driver can ask for the pointer, maximum size and the currently used size of
the metadata and can directly update or read it.
Because the DMA driver manages the memory area containing the metadata,
clients must make sure that they do not try to access or get the pointer
after their transfer completion callback has run for the descriptor.
If no completion callback has been defined for the transfer, then the
metadata must not be accessed after issue_pending.
In other words: if the aim is to read back metadata after the transfer is
completed, then the client must use completion callback.
.. code-block:: c
void *dmaengine_desc_get_metadata_ptr(struct dma_async_tx_descriptor *desc,
size_t *payload_len, size_t *max_len);
int dmaengine_desc_set_metadata_len(struct dma_async_tx_descriptor *desc,
size_t payload_len);
Client drivers can query if a given mode is supported with:
.. code-block:: c
bool dmaengine_is_metadata_mode_supported(struct dma_chan *chan,
enum dma_desc_metadata_mode mode);
Depending on the used mode client drivers must follow different flow.
DESC_METADATA_CLIENT
- DMA_MEM_TO_DEV / DEV_MEM_TO_MEM:
1. prepare the descriptor (dmaengine_prep_*)
construct the metadata in the client's buffer
2. use dmaengine_desc_attach_metadata() to attach the buffer to the
descriptor
3. submit the transfer
- DMA_DEV_TO_MEM:
1. prepare the descriptor (dmaengine_prep_*)
2. use dmaengine_desc_attach_metadata() to attach the buffer to the
descriptor
3. submit the transfer
4. when the transfer is completed, the metadata should be available in the
attached buffer
DESC_METADATA_ENGINE
- DMA_MEM_TO_DEV / DEV_MEM_TO_MEM:
1. prepare the descriptor (dmaengine_prep_*)
2. use dmaengine_desc_get_metadata_ptr() to get the pointer to the
engine's metadata area
3. update the metadata at the pointer
4. use dmaengine_desc_set_metadata_len() to tell the DMA engine the
amount of data the client has placed into the metadata buffer
5. submit the transfer
- DMA_DEV_TO_MEM:
1. prepare the descriptor (dmaengine_prep_*)
2. submit the transfer
3. on transfer completion, use dmaengine_desc_get_metadata_ptr() to get
the pointer to the engine's metadata area
4. read out the metadata from the pointer
.. note::
When DESC_METADATA_ENGINE mode is used the metadata area for the descriptor
is no longer valid after the transfer has been completed (valid up to the
point when the completion callback returns if used).
Mixed use of DESC_METADATA_CLIENT / DESC_METADATA_ENGINE is not allowed,
client drivers must use either of the modes per descriptor.
4. Submit the transaction
Once the descriptor has been prepared and the callback information
added, it must be placed on the DMA engine drivers pending queue.
Interface:
.. code-block:: c
dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc)
This returns a cookie can be used to check the progress of DMA engine
activity via other DMA engine calls not covered in this document.
dmaengine_submit() will not start the DMA operation, it merely adds
it to the pending queue. For this, see step 5, dma_async_issue_pending.
.. note::
After calling ``dmaengine_submit()`` the submitted transfer descriptor
(``struct dma_async_tx_descriptor``) belongs to the DMA engine.
Consequently, the client must consider invalid the pointer to that
descriptor.
5. Issue pending DMA requests and wait for callback notification
The transactions in the pending queue can be activated by calling the
issue_pending API. If channel is idle then the first transaction in
queue is started and subsequent ones queued up.
On completion of each DMA operation, the next in queue is started and
a tasklet triggered. The tasklet will then call the client driver
completion callback routine for notification, if set.
Interface:
.. code-block:: c
void dma_async_issue_pending(struct dma_chan *chan);
Further APIs
------------
1. Terminate APIs
.. code-block:: c
int dmaengine_terminate_sync(struct dma_chan *chan)
int dmaengine_terminate_async(struct dma_chan *chan)
int dmaengine_terminate_all(struct dma_chan *chan) /* DEPRECATED */
This causes all activity for the DMA channel to be stopped, and may
discard data in the DMA FIFO which hasn't been fully transferred.
No callback functions will be called for any incomplete transfers.
Two variants of this function are available.
dmaengine_terminate_async() might not wait until the DMA has been fully
stopped or until any running complete callbacks have finished. But it is
possible to call dmaengine_terminate_async() from atomic context or from
within a complete callback. dmaengine_synchronize() must be called before it
is safe to free the memory accessed by the DMA transfer or free resources
accessed from within the complete callback.
dmaengine_terminate_sync() will wait for the transfer and any running
complete callbacks to finish before it returns. But the function must not be
called from atomic context or from within a complete callback.
dmaengine_terminate_all() is deprecated and should not be used in new code.
2. Pause API
.. code-block:: c
int dmaengine_pause(struct dma_chan *chan)
This pauses activity on the DMA channel without data loss.
3. Resume API
.. code-block:: c
int dmaengine_resume(struct dma_chan *chan)
Resume a previously paused DMA channel. It is invalid to resume a
channel which is not currently paused.
4. Check Txn complete
.. code-block:: c
enum dma_status dma_async_is_tx_complete(struct dma_chan *chan,
dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used)
This can be used to check the status of the channel. Please see
the documentation in include/linux/dmaengine.h for a more complete
description of this API.
This can be used in conjunction with dma_async_is_complete() and
the cookie returned from dmaengine_submit() to check for
completion of a specific DMA transaction.
.. note::
Not all DMA engine drivers can return reliable information for
a running DMA channel. It is recommended that DMA engine users
pause or stop (via dmaengine_terminate_all()) the channel before
using this API.
5. Synchronize termination API
.. code-block:: c
void dmaengine_synchronize(struct dma_chan *chan)
Synchronize the termination of the DMA channel to the current context.
This function should be used after dmaengine_terminate_async() to synchronize
the termination of the DMA channel to the current context. The function will
wait for the transfer and any running complete callbacks to finish before it
returns.
If dmaengine_terminate_async() is used to stop the DMA channel this function
must be called before it is safe to free memory accessed by previously
submitted descriptors or to free any resources accessed within the complete
callback of previously submitted descriptors.
The behavior of this function is undefined if dma_async_issue_pending() has
been called between dmaengine_terminate_async() and this function.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
DMA Engine Slave-DMA API 안내
1-13이 문서는 Vinod Koul이 작성한 DMA Engine API 안내서입니다.
`async_tx`에서 DMA Engine을 사용하는 방법은 `Documentation/crypto/async-tx-api.rst`를 참조합니다.
아래 내용은 device driver 작성자가 DMA Engine의 Slave-DMA API를 사용하는 방법을 설명하며, slave DMA 용도에만 적용됩니다.
Slave DMA 사용 절차
14-30slave DMA 사용은 다음 단계로 구성됩니다.
- DMA slave channel을 할당합니다.
- slave와 controller별 parameter를 설정합니다.
- transaction descriptor를 얻습니다.
- transaction을 submit합니다.
- pending request를 issue하고 callback notification을 기다립니다.
channel 확보부터 completion callback까지의 실행 순서를 정리했습니다.
각 동작의 세부 내용은 다음과 같습니다.
1. DMA slave channel 할당
31-50slave DMA 문맥에서 channel 할당은 조금 다릅니다. client driver는 보통 특정 DMA controller의 channel이 필요하고, 경우에 따라서는 특정 channel 자체가 필요합니다. channel 요청에는 `dma_request_chan()` API를 사용합니다.
Interface:
.. code-block:: c
struct dma_chan *dma_request_chan(struct device *dev, const char *name);
이 함수는 `dev` device와 연결된 이름 `name`의 DMA channel을 찾아 반환합니다. 연결 관계는 DT, ACPI 또는 board file 기반 `dma_slave_map` matching table로 정의됩니다.
이 interface로 할당한 channel은 `dma_release_channel()`을 호출할 때까지 호출자가 독점합니다.
2. Slave와 controller parameter 설정
51-75다음 단계에서는 항상 DMA driver에 구체적인 정보를 전달합니다. slave DMA가 사용할 수 있는 대부분의 generic 정보는 `struct dma_slave_config`에 들어 있습니다. client는 이 구조체로 peripheral의 DMA direction, DMA address, bus width, DMA burst length 등을 지정할 수 있습니다.
DMA controller에 추가 parameter가 필요하다면 controller별 구조체 안에 `struct dma_slave_config`를 포함하는 방식을 권장합니다. 그러면 필요할 때 client가 더 많은 parameter를 전달할 수 있습니다.
Interface:
.. code-block:: c
int dmaengine_slave_config(struct dma_chan *chan,
struct dma_slave_config *config)
각 member의 자세한 설명은 `dmaengine.h`의 `dma_slave_config` 구조체 정의를 참조합니다. `direction` member는 prepare 호출에 이미 전달되는 direction과 중복되므로 향후 제거될 예정입니다.
3. Transaction descriptor 준비
76-165slave 용도로 DMA-engine이 지원하는 slave transfer mode는 다음과 같습니다.
- `slave_sg`: scatter-gather buffer 목록을 peripheral에서 또는 peripheral로 DMA합니다.
- `peripheral_dma_vec`: scatter-gather buffer 배열을 peripheral에서 또는 peripheral로 DMA합니다. `slave_sg`와 비슷하지만 scatterlist 대신 `dma_vec` 구조체 배열을 사용합니다.
- `dma_cyclic`: 명시적으로 중지할 때까지 peripheral에서 또는 peripheral로 cyclic DMA operation을 수행합니다.
- `interleaved_dma`: Slave client와 M2M client가 함께 사용하는 mode입니다. slave에서는 device FIFO address를 driver가 이미 알고 있을 수 있습니다. `dma_interleaved_template` member에 적절한 값을 넣어 여러 operation을 표현합니다. channel이 지원한다면 `DMA_PREP_REPEAT` transfer flag를 설정해 cyclic interleaved DMA transfer도 수행할 수 있습니다.
buffer 표현과 반복 동작에 따라 descriptor 준비 API를 대응시켰습니다.
이 transfer API가 NULL이 아닌 값을 반환하면 해당 transaction의 descriptor를 뜻합니다.
Interface:
.. code-block:: c
struct dma_async_tx_descriptor *dmaengine_prep_slave_sg(
struct dma_chan *chan, struct scatterlist *sgl,
unsigned int sg_len, enum dma_data_direction direction,
unsigned long flags);
struct dma_async_tx_descriptor *dmaengine_prep_peripheral_dma_vec(
struct dma_chan *chan, const struct dma_vec *vecs,
size_t nents, enum dma_data_direction direction,
unsigned long flags);
struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic(
struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
size_t period_len, enum dma_data_direction direction);
struct dma_async_tx_descriptor *dmaengine_prep_interleaved_dma(
struct dma_chan *chan, struct dma_interleaved_template *xt,
unsigned long flags);
peripheral driver는 `dmaengine_prep_slave_sg()`를 호출하기 전에 DMA operation용 scatterlist를 mapping해야 하며, DMA operation이 완료될 때까지 mapping을 유지해야 합니다. scatterlist는 DMA struct device를 사용해 mapping해야 합니다. 나중에 mapping을 synchronize해야 한다면 `dma_sync_*_for_*()`도 같은 DMA struct device로 호출해야 합니다. 일반적인 설정은 다음과 같습니다.
.. code-block:: c
struct device *dma_dev = dmaengine_get_dma_device(chan);
nr_sg = dma_map_sg(dma_dev, sgl, sg_len);
if (nr_sg == 0)
/* error */
desc = dmaengine_prep_slave_sg(chan, sgl, nr_sg, direction, flags);
descriptor를 얻은 뒤 callback 정보를 추가하고 descriptor를 submit해야 합니다. 일부 DMA engine driver는 prepare 성공부터 submit 사이에 spinlock을 유지할 수 있으므로 두 operation을 가깝게 연속해서 수행하는 것이 중요합니다.
`async_tx` API에서는 completion callback이 새 operation을 submit할 수 없다고 규정하지만 slave/cyclic DMA에는 이 제한이 적용되지 않습니다.
- slave DMA에서는 callback이 호출되기 전까지 다음 transaction을 submit할 수 없는 경우가 있으므로 callback에서 새 transaction을 prepare하고 submit할 수 있습니다.
- cyclic DMA callback에서는 `dmaengine_terminate_async()`로 DMA를 종료할 수 있습니다.
- callback이 다시 DMA API를 호출해 deadlock을 만들 수 있으므로 DMA engine driver는 callback을 부르기 전에 모든 lock을 해제해야 합니다.
- callback은 항상 DMA engine의 tasklet에서 실행되며 interrupt context에서는 절대 실행되지 않습니다.
선택 사항: descriptor별 metadata
166-259DMAengine은 metadata를 두 방식으로 지원합니다.
`DESC_METADATA_CLIENT`에서는 client driver가 metadata buffer를 할당하거나 제공하고 descriptor에 연결합니다.
.. code-block:: c
int dmaengine_desc_attach_metadata(struct dma_async_tx_descriptor *desc,
void *data, size_t len);
`DESC_METADATA_ENGINE`에서는 DMA driver가 metadata buffer를 할당하고 관리합니다. client driver는 metadata pointer, 최대 크기, 현재 사용 크기를 요청하고 해당 영역을 직접 갱신하거나 읽을 수 있습니다.
DMA driver가 metadata memory area를 관리하므로 client는 해당 descriptor의 transfer completion callback이 실행된 뒤에는 영역에 접근하거나 pointer를 얻어서는 안 됩니다. completion callback이 정의되지 않았다면 `issue_pending` 뒤에 metadata에 접근하면 안 됩니다. 즉 transfer 완료 뒤 metadata를 되읽으려면 client가 반드시 completion callback을 사용해야 합니다.
.. code-block:: c
void *dmaengine_desc_get_metadata_ptr(struct dma_async_tx_descriptor *desc,
size_t *payload_len, size_t *max_len);
int dmaengine_desc_set_metadata_len(struct dma_async_tx_descriptor *desc,
size_t payload_len);
Client drivers can query if a given mode is supported with:
.. code-block:: c
bool dmaengine_is_metadata_mode_supported(struct dma_chan *chan,
enum dma_desc_metadata_mode mode);
client driver는 `dmaengine_is_metadata_mode_supported()`로 mode 지원 여부를 조회할 수 있습니다.
사용하는 mode에 따라 client driver가 따라야 할 흐름이 다릅니다.
- `DESC_METADATA_CLIENT`, `DMA_MEM_TO_DEV` / `DEV_MEM_TO_MEM`: descriptor를 prepare하고 client buffer에 metadata를 만든 다음 `dmaengine_desc_attach_metadata()`로 buffer를 연결하고 transfer를 submit합니다.
- `DESC_METADATA_CLIENT`, `DMA_DEV_TO_MEM`: descriptor를 prepare하고 buffer를 연결한 뒤 submit합니다. transfer가 완료되면 연결한 buffer에서 metadata를 사용할 수 있습니다.
- `DESC_METADATA_ENGINE`, `DMA_MEM_TO_DEV` / `DEV_MEM_TO_MEM`: descriptor를 prepare하고 `dmaengine_desc_get_metadata_ptr()`로 engine metadata area pointer를 얻어 내용을 갱신합니다. `dmaengine_desc_set_metadata_len()`으로 client가 넣은 양을 알린 뒤 transfer를 submit합니다.
- `DESC_METADATA_ENGINE`, `DMA_DEV_TO_MEM`: descriptor를 prepare하고 submit합니다. transfer completion 시 `dmaengine_desc_get_metadata_ptr()`로 engine metadata area pointer를 얻어 metadata를 읽습니다.
metadata 소유자, transfer 방향, attach 또는 pointer API의 사용 시점을 구분했습니다.
`DESC_METADATA_ENGINE` mode에서 descriptor metadata area는 transfer 완료 뒤 더 이상 유효하지 않습니다. completion callback을 사용했다면 callback이 반환할 때까지만 유효합니다.
한 descriptor에서 `DESC_METADATA_CLIENT`와 `DESC_METADATA_ENGINE`을 섞어 사용할 수 없습니다. client driver는 descriptor마다 둘 중 하나의 mode만 사용해야 합니다.
4. Transaction submit
260-283descriptor를 prepare하고 callback 정보를 추가했으면 DMA engine driver의 pending queue에 넣어야 합니다.
Interface:
.. code-block:: c
dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc)
반환되는 `dma_cookie_t` cookie는 이 문서에서 다루지 않는 다른 DMA engine 호출로 DMA engine activity의 진행 상태를 확인할 때 사용할 수 있습니다.
`dmaengine_submit()`은 DMA operation을 시작하지 않고 pending queue에 추가하기만 합니다. 시작은 5단계의 `dma_async_issue_pending`을 참조합니다.
`dmaengine_submit()` 호출 뒤 submit한 `struct dma_async_tx_descriptor`는 DMA engine 소유가 됩니다. 따라서 client는 해당 descriptor pointer를 무효한 것으로 간주해야 합니다.
5. Pending request 실행과 callback 대기
284-299pending queue의 transaction은 issue_pending API를 호출해 활성화합니다. channel이 idle이면 queue의 첫 transaction이 시작되고 이후 transaction은 대기열에 남습니다.
각 DMA operation이 완료되면 queue의 다음 operation이 시작되고 tasklet이 trigger됩니다. completion callback을 설정했다면 tasklet이 client driver의 callback routine을 호출해 완료를 알립니다.
Interface:
.. code-block:: c
void dma_async_issue_pending(struct dma_chan *chan);
추가 API 1. Terminate
300-329Terminate interface는 다음과 같습니다.
.. code-block:: c
int dmaengine_terminate_sync(struct dma_chan *chan)
int dmaengine_terminate_async(struct dma_chan *chan)
int dmaengine_terminate_all(struct dma_chan *chan) /* DEPRECATED */
이 API는 DMA channel의 모든 activity를 중지하며, 아직 완전히 전송되지 않은 DMA FIFO data를 버릴 수 있습니다. 완료되지 않은 transfer의 callback은 호출되지 않습니다.
이 기능에는 두 variant가 있습니다.
- `dmaengine_terminate_async()`는 DMA가 완전히 멈추거나 실행 중인 completion callback이 끝날 때까지 기다리지 않을 수 있습니다. 대신 atomic context 또는 completion callback 안에서 호출할 수 있습니다. DMA transfer가 접근한 memory나 completion callback이 접근한 resource를 해제하기 전에 반드시 `dmaengine_synchronize()`를 호출해야 합니다.
- `dmaengine_terminate_sync()`는 transfer와 실행 중인 completion callback이 끝날 때까지 기다린 뒤 반환합니다. atomic context나 completion callback 안에서는 호출하면 안 됩니다.
- `dmaengine_terminate_all()`은 deprecated되었으므로 새 code에서 사용하면 안 됩니다.
추가 API 2-3. Pause와 resume
330-346Pause interface:
.. code-block:: c
int dmaengine_pause(struct dma_chan *chan)
`dmaengine_pause()`는 data 손실 없이 DMA channel activity를 일시 중지합니다.
Resume interface:
.. code-block:: c
int dmaengine_resume(struct dma_chan *chan)
`dmaengine_resume()`은 이전에 일시 중지한 DMA channel을 재개합니다. 현재 pause 상태가 아닌 channel을 resume하는 것은 잘못된 사용입니다.
추가 API 4. Transaction 완료 확인
347-368Interface:
.. code-block:: c
enum dma_status dma_async_is_tx_complete(struct dma_chan *chan,
dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used)
`dma_async_is_tx_complete()`는 channel 상태를 확인하는 데 사용할 수 있습니다. 더 자세한 설명은 `include/linux/dmaengine.h` 문서를 참조합니다.
이 API를 `dma_async_is_complete()` 및 `dmaengine_submit()`이 반환한 cookie와 함께 사용하면 특정 DMA transaction의 완료 여부를 확인할 수 있습니다.
모든 DMA engine driver가 실행 중인 DMA channel에 대해 신뢰할 수 있는 정보를 반환하는 것은 아닙니다. 이 API를 쓰기 전에 DMA engine 사용자가 channel을 pause하거나 `dmaengine_terminate_all()`로 중지하는 것을 권장합니다.
추가 API 5. Termination synchronize
369-388Interface:
.. code-block:: c
void dmaengine_synchronize(struct dma_chan *chan)
`dmaengine_synchronize()`는 DMA channel termination을 현재 context와 synchronize합니다.
`dmaengine_terminate_async()` 뒤에 이 함수를 사용해야 합니다. 함수는 transfer와 실행 중인 completion callback이 끝날 때까지 기다린 뒤 반환합니다.
`dmaengine_terminate_async()`로 DMA channel을 중지했다면 이전에 submit한 descriptor가 접근한 memory 또는 이전 completion callback이 접근한 resource를 안전하게 해제하기 전에 이 함수를 반드시 호출해야 합니다.
`dmaengine_terminate_async()`와 이 함수 사이에 `dma_async_issue_pending()`을 호출하면 동작은 정의되지 않습니다.
종료, 일시 중지, 상태 확인, 동기화 API의 대기와 호출 문맥을 비교했습니다.
요약과 해설
client.rst:1-388Slave-DMA client는 channel을 독점 할당하고 `dma_slave_config`를 적용한 뒤 transfer mode에 맞는 descriptor를 prepare, submit, issue합니다. scatterlist는 DMA struct device로 mapping해 완료까지 유지해야 하며 prepare와 submit은 가깝게 수행합니다. slave/cyclic callback은 다음 transaction을 prepare하거나 비동기 종료할 수 있으므로 engine driver가 callback 전에 lock을 풀어야 합니다. metadata mode별 buffer 소유권과 유효 기간, submit 뒤 descriptor 소유권 이전, async terminate 뒤 `dmaengine_synchronize()` 의무를 지키는 것이 핵심입니다.