18c2ecf20Sopenharmony_ci==================== 28c2ecf20Sopenharmony_ciDMA Engine API Guide 38c2ecf20Sopenharmony_ci==================== 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciVinod Koul <vinod dot koul at intel.com> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci.. note:: For DMA Engine usage in async_tx please see: 88c2ecf20Sopenharmony_ci ``Documentation/crypto/async-tx-api.rst`` 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciBelow is a guide to device driver writers on how to use the Slave-DMA API of the 128c2ecf20Sopenharmony_ciDMA Engine. This is applicable only for slave DMA usage only. 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciDMA usage 158c2ecf20Sopenharmony_ci========= 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ciThe slave DMA usage consists of following steps: 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci- Allocate a DMA slave channel 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci- Set slave and controller specific parameters 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci- Get a descriptor for transaction 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci- Submit the transaction 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci- Issue pending requests and wait for callback notification 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ciThe details of these operations are: 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci1. Allocate a DMA slave channel 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci Channel allocation is slightly different in the slave DMA context, 348c2ecf20Sopenharmony_ci client drivers typically need a channel from a particular DMA 358c2ecf20Sopenharmony_ci controller only and even in some cases a specific channel is desired. 368c2ecf20Sopenharmony_ci To request a channel dma_request_chan() API is used. 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci Interface: 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci .. code-block:: c 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci struct dma_chan *dma_request_chan(struct device *dev, const char *name); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci Which will find and return the ``name`` DMA channel associated with the 'dev' 458c2ecf20Sopenharmony_ci device. The association is done via DT, ACPI or board file based 468c2ecf20Sopenharmony_ci dma_slave_map matching table. 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci A channel allocated via this interface is exclusive to the caller, 498c2ecf20Sopenharmony_ci until dma_release_channel() is called. 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci2. Set slave and controller specific parameters 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci Next step is always to pass some specific information to the DMA 548c2ecf20Sopenharmony_ci driver. Most of the generic information which a slave DMA can use 558c2ecf20Sopenharmony_ci is in struct dma_slave_config. This allows the clients to specify 568c2ecf20Sopenharmony_ci DMA direction, DMA addresses, bus widths, DMA burst lengths etc 578c2ecf20Sopenharmony_ci for the peripheral. 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci If some DMA controllers have more parameters to be sent then they 608c2ecf20Sopenharmony_ci should try to embed struct dma_slave_config in their controller 618c2ecf20Sopenharmony_ci specific structure. That gives flexibility to client to pass more 628c2ecf20Sopenharmony_ci parameters, if required. 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci Interface: 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci .. code-block:: c 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci int dmaengine_slave_config(struct dma_chan *chan, 698c2ecf20Sopenharmony_ci struct dma_slave_config *config) 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci Please see the dma_slave_config structure definition in dmaengine.h 728c2ecf20Sopenharmony_ci for a detailed explanation of the struct members. Please note 738c2ecf20Sopenharmony_ci that the 'direction' member will be going away as it duplicates the 748c2ecf20Sopenharmony_ci direction given in the prepare call. 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci3. Get a descriptor for transaction 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci For slave usage the various modes of slave transfers supported by the 798c2ecf20Sopenharmony_ci DMA-engine are: 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci - slave_sg: DMA a list of scatter gather buffers from/to a peripheral 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci - dma_cyclic: Perform a cyclic DMA operation from/to a peripheral till the 848c2ecf20Sopenharmony_ci operation is explicitly stopped. 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci - interleaved_dma: This is common to Slave as well as M2M clients. For slave 878c2ecf20Sopenharmony_ci address of devices' fifo could be already known to the driver. 888c2ecf20Sopenharmony_ci Various types of operations could be expressed by setting 898c2ecf20Sopenharmony_ci appropriate values to the 'dma_interleaved_template' members. Cyclic 908c2ecf20Sopenharmony_ci interleaved DMA transfers are also possible if supported by the channel by 918c2ecf20Sopenharmony_ci setting the DMA_PREP_REPEAT transfer flag. 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci A non-NULL return of this transfer API represents a "descriptor" for 948c2ecf20Sopenharmony_ci the given transaction. 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci Interface: 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci .. code-block:: c 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci struct dma_async_tx_descriptor *dmaengine_prep_slave_sg( 1018c2ecf20Sopenharmony_ci struct dma_chan *chan, struct scatterlist *sgl, 1028c2ecf20Sopenharmony_ci unsigned int sg_len, enum dma_data_direction direction, 1038c2ecf20Sopenharmony_ci unsigned long flags); 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic( 1068c2ecf20Sopenharmony_ci struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, 1078c2ecf20Sopenharmony_ci size_t period_len, enum dma_data_direction direction); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci struct dma_async_tx_descriptor *dmaengine_prep_interleaved_dma( 1108c2ecf20Sopenharmony_ci struct dma_chan *chan, struct dma_interleaved_template *xt, 1118c2ecf20Sopenharmony_ci unsigned long flags); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci The peripheral driver is expected to have mapped the scatterlist for 1148c2ecf20Sopenharmony_ci the DMA operation prior to calling dmaengine_prep_slave_sg(), and must 1158c2ecf20Sopenharmony_ci keep the scatterlist mapped until the DMA operation has completed. 1168c2ecf20Sopenharmony_ci The scatterlist must be mapped using the DMA struct device. 1178c2ecf20Sopenharmony_ci If a mapping needs to be synchronized later, dma_sync_*_for_*() must be 1188c2ecf20Sopenharmony_ci called using the DMA struct device, too. 1198c2ecf20Sopenharmony_ci So, normal setup should look like this: 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci .. code-block:: c 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci nr_sg = dma_map_sg(chan->device->dev, sgl, sg_len); 1248c2ecf20Sopenharmony_ci if (nr_sg == 0) 1258c2ecf20Sopenharmony_ci /* error */ 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci desc = dmaengine_prep_slave_sg(chan, sgl, nr_sg, direction, flags); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci Once a descriptor has been obtained, the callback information can be 1308c2ecf20Sopenharmony_ci added and the descriptor must then be submitted. Some DMA engine 1318c2ecf20Sopenharmony_ci drivers may hold a spinlock between a successful preparation and 1328c2ecf20Sopenharmony_ci submission so it is important that these two operations are closely 1338c2ecf20Sopenharmony_ci paired. 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci .. note:: 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci Although the async_tx API specifies that completion callback 1388c2ecf20Sopenharmony_ci routines cannot submit any new operations, this is not the 1398c2ecf20Sopenharmony_ci case for slave/cyclic DMA. 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci For slave DMA, the subsequent transaction may not be available 1428c2ecf20Sopenharmony_ci for submission prior to callback function being invoked, so 1438c2ecf20Sopenharmony_ci slave DMA callbacks are permitted to prepare and submit a new 1448c2ecf20Sopenharmony_ci transaction. 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci For cyclic DMA, a callback function may wish to terminate the 1478c2ecf20Sopenharmony_ci DMA via dmaengine_terminate_async(). 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci Therefore, it is important that DMA engine drivers drop any 1508c2ecf20Sopenharmony_ci locks before calling the callback function which may cause a 1518c2ecf20Sopenharmony_ci deadlock. 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci Note that callbacks will always be invoked from the DMA 1548c2ecf20Sopenharmony_ci engines tasklet, never from interrupt context. 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci **Optional: per descriptor metadata** 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci DMAengine provides two ways for metadata support. 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci DESC_METADATA_CLIENT 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci The metadata buffer is allocated/provided by the client driver and it is 1638c2ecf20Sopenharmony_ci attached to the descriptor. 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci .. code-block:: c 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci int dmaengine_desc_attach_metadata(struct dma_async_tx_descriptor *desc, 1688c2ecf20Sopenharmony_ci void *data, size_t len); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci DESC_METADATA_ENGINE 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci The metadata buffer is allocated/managed by the DMA driver. The client 1738c2ecf20Sopenharmony_ci driver can ask for the pointer, maximum size and the currently used size of 1748c2ecf20Sopenharmony_ci the metadata and can directly update or read it. 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci Becasue the DMA driver manages the memory area containing the metadata, 1778c2ecf20Sopenharmony_ci clients must make sure that they do not try to access or get the pointer 1788c2ecf20Sopenharmony_ci after their transfer completion callback has run for the descriptor. 1798c2ecf20Sopenharmony_ci If no completion callback has been defined for the transfer, then the 1808c2ecf20Sopenharmony_ci metadata must not be accessed after issue_pending. 1818c2ecf20Sopenharmony_ci In other words: if the aim is to read back metadata after the transfer is 1828c2ecf20Sopenharmony_ci completed, then the client must use completion callback. 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci .. code-block:: c 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci void *dmaengine_desc_get_metadata_ptr(struct dma_async_tx_descriptor *desc, 1878c2ecf20Sopenharmony_ci size_t *payload_len, size_t *max_len); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci int dmaengine_desc_set_metadata_len(struct dma_async_tx_descriptor *desc, 1908c2ecf20Sopenharmony_ci size_t payload_len); 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci Client drivers can query if a given mode is supported with: 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci .. code-block:: c 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci bool dmaengine_is_metadata_mode_supported(struct dma_chan *chan, 1978c2ecf20Sopenharmony_ci enum dma_desc_metadata_mode mode); 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci Depending on the used mode client drivers must follow different flow. 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci DESC_METADATA_CLIENT 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci - DMA_MEM_TO_DEV / DEV_MEM_TO_MEM: 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci 1. prepare the descriptor (dmaengine_prep_*) 2068c2ecf20Sopenharmony_ci construct the metadata in the client's buffer 2078c2ecf20Sopenharmony_ci 2. use dmaengine_desc_attach_metadata() to attach the buffer to the 2088c2ecf20Sopenharmony_ci descriptor 2098c2ecf20Sopenharmony_ci 3. submit the transfer 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci - DMA_DEV_TO_MEM: 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci 1. prepare the descriptor (dmaengine_prep_*) 2148c2ecf20Sopenharmony_ci 2. use dmaengine_desc_attach_metadata() to attach the buffer to the 2158c2ecf20Sopenharmony_ci descriptor 2168c2ecf20Sopenharmony_ci 3. submit the transfer 2178c2ecf20Sopenharmony_ci 4. when the transfer is completed, the metadata should be available in the 2188c2ecf20Sopenharmony_ci attached buffer 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci DESC_METADATA_ENGINE 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci - DMA_MEM_TO_DEV / DEV_MEM_TO_MEM: 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci 1. prepare the descriptor (dmaengine_prep_*) 2258c2ecf20Sopenharmony_ci 2. use dmaengine_desc_get_metadata_ptr() to get the pointer to the 2268c2ecf20Sopenharmony_ci engine's metadata area 2278c2ecf20Sopenharmony_ci 3. update the metadata at the pointer 2288c2ecf20Sopenharmony_ci 4. use dmaengine_desc_set_metadata_len() to tell the DMA engine the 2298c2ecf20Sopenharmony_ci amount of data the client has placed into the metadata buffer 2308c2ecf20Sopenharmony_ci 5. submit the transfer 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci - DMA_DEV_TO_MEM: 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci 1. prepare the descriptor (dmaengine_prep_*) 2358c2ecf20Sopenharmony_ci 2. submit the transfer 2368c2ecf20Sopenharmony_ci 3. on transfer completion, use dmaengine_desc_get_metadata_ptr() to get 2378c2ecf20Sopenharmony_ci the pointer to the engine's metadata area 2388c2ecf20Sopenharmony_ci 4. read out the metadata from the pointer 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci .. note:: 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci When DESC_METADATA_ENGINE mode is used the metadata area for the descriptor 2438c2ecf20Sopenharmony_ci is no longer valid after the transfer has been completed (valid up to the 2448c2ecf20Sopenharmony_ci point when the completion callback returns if used). 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci Mixed use of DESC_METADATA_CLIENT / DESC_METADATA_ENGINE is not allowed, 2478c2ecf20Sopenharmony_ci client drivers must use either of the modes per descriptor. 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci4. Submit the transaction 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci Once the descriptor has been prepared and the callback information 2528c2ecf20Sopenharmony_ci added, it must be placed on the DMA engine drivers pending queue. 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci Interface: 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci .. code-block:: c 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc) 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci This returns a cookie can be used to check the progress of DMA engine 2618c2ecf20Sopenharmony_ci activity via other DMA engine calls not covered in this document. 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci dmaengine_submit() will not start the DMA operation, it merely adds 2648c2ecf20Sopenharmony_ci it to the pending queue. For this, see step 5, dma_async_issue_pending. 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci .. note:: 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci After calling ``dmaengine_submit()`` the submitted transfer descriptor 2698c2ecf20Sopenharmony_ci (``struct dma_async_tx_descriptor``) belongs to the DMA engine. 2708c2ecf20Sopenharmony_ci Consequently, the client must consider invalid the pointer to that 2718c2ecf20Sopenharmony_ci descriptor. 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci5. Issue pending DMA requests and wait for callback notification 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci The transactions in the pending queue can be activated by calling the 2768c2ecf20Sopenharmony_ci issue_pending API. If channel is idle then the first transaction in 2778c2ecf20Sopenharmony_ci queue is started and subsequent ones queued up. 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci On completion of each DMA operation, the next in queue is started and 2808c2ecf20Sopenharmony_ci a tasklet triggered. The tasklet will then call the client driver 2818c2ecf20Sopenharmony_ci completion callback routine for notification, if set. 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci Interface: 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci .. code-block:: c 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci void dma_async_issue_pending(struct dma_chan *chan); 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ciFurther APIs 2908c2ecf20Sopenharmony_ci------------ 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci1. Terminate APIs 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci .. code-block:: c 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci int dmaengine_terminate_sync(struct dma_chan *chan) 2978c2ecf20Sopenharmony_ci int dmaengine_terminate_async(struct dma_chan *chan) 2988c2ecf20Sopenharmony_ci int dmaengine_terminate_all(struct dma_chan *chan) /* DEPRECATED */ 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci This causes all activity for the DMA channel to be stopped, and may 3018c2ecf20Sopenharmony_ci discard data in the DMA FIFO which hasn't been fully transferred. 3028c2ecf20Sopenharmony_ci No callback functions will be called for any incomplete transfers. 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci Two variants of this function are available. 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci dmaengine_terminate_async() might not wait until the DMA has been fully 3078c2ecf20Sopenharmony_ci stopped or until any running complete callbacks have finished. But it is 3088c2ecf20Sopenharmony_ci possible to call dmaengine_terminate_async() from atomic context or from 3098c2ecf20Sopenharmony_ci within a complete callback. dmaengine_synchronize() must be called before it 3108c2ecf20Sopenharmony_ci is safe to free the memory accessed by the DMA transfer or free resources 3118c2ecf20Sopenharmony_ci accessed from within the complete callback. 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci dmaengine_terminate_sync() will wait for the transfer and any running 3148c2ecf20Sopenharmony_ci complete callbacks to finish before it returns. But the function must not be 3158c2ecf20Sopenharmony_ci called from atomic context or from within a complete callback. 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci dmaengine_terminate_all() is deprecated and should not be used in new code. 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci2. Pause API 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci .. code-block:: c 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci int dmaengine_pause(struct dma_chan *chan) 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci This pauses activity on the DMA channel without data loss. 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci3. Resume API 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci .. code-block:: c 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci int dmaengine_resume(struct dma_chan *chan) 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci Resume a previously paused DMA channel. It is invalid to resume a 3348c2ecf20Sopenharmony_ci channel which is not currently paused. 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci4. Check Txn complete 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci .. code-block:: c 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci enum dma_status dma_async_is_tx_complete(struct dma_chan *chan, 3418c2ecf20Sopenharmony_ci dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used) 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci This can be used to check the status of the channel. Please see 3448c2ecf20Sopenharmony_ci the documentation in include/linux/dmaengine.h for a more complete 3458c2ecf20Sopenharmony_ci description of this API. 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci This can be used in conjunction with dma_async_is_complete() and 3488c2ecf20Sopenharmony_ci the cookie returned from dmaengine_submit() to check for 3498c2ecf20Sopenharmony_ci completion of a specific DMA transaction. 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci .. note:: 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci Not all DMA engine drivers can return reliable information for 3548c2ecf20Sopenharmony_ci a running DMA channel. It is recommended that DMA engine users 3558c2ecf20Sopenharmony_ci pause or stop (via dmaengine_terminate_all()) the channel before 3568c2ecf20Sopenharmony_ci using this API. 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci5. Synchronize termination API 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci .. code-block:: c 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci void dmaengine_synchronize(struct dma_chan *chan) 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci Synchronize the termination of the DMA channel to the current context. 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci This function should be used after dmaengine_terminate_async() to synchronize 3678c2ecf20Sopenharmony_ci the termination of the DMA channel to the current context. The function will 3688c2ecf20Sopenharmony_ci wait for the transfer and any running complete callbacks to finish before it 3698c2ecf20Sopenharmony_ci returns. 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci If dmaengine_terminate_async() is used to stop the DMA channel this function 3728c2ecf20Sopenharmony_ci must be called before it is safe to free memory accessed by previously 3738c2ecf20Sopenharmony_ci submitted descriptors or to free any resources accessed within the complete 3748c2ecf20Sopenharmony_ci callback of previously submitted descriptors. 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci The behavior of this function is undefined if dma_async_issue_pending() has 3778c2ecf20Sopenharmony_ci been called between dmaengine_terminate_async() and this function. 378