简体   繁体   English

关于dma_sync_single_for_cpu()的问题

[英]Questions about dma_sync_single_for_cpu() / dma_sync_single_for_device()

My code uses stream DMA APIs to map an allocated buffer to DMA region like below: 我的代码使用流DMA API将分配的缓冲区映射到DMA区域,如下所示:

void perform_dma(void *buffer)
{
    dma_map_single(buffer...  DMA_BIDIRECTIONAL);  <- map buffer to physical address

    ring_doorbell()  -> notify device to read DMA content

    // wait until DMA is done or wake up by interrupts 
    .....

    dma_unmap_single(... , DMA_BIDIRECTIONAL)   <- unmap buffer
}

The DMA direction is BIDIRECTIONAL and buffer is allocated, filled by caller before perform_dma() is called and freed after it is done. DMA方向为BIDIRECTIONAL, buffer已分配,在调用perform_dma()之前由调用方填充,并在完成后释放。

Should I use 我应该使用

  • dma_sync_single_for_device() after dma_map_single() is called (but before notifying device to perform DMA) dma_sync_single_for_device()之后(但在通知设备执行DMA之前dma_sync_single_for_device() dma_map_single()

and

  • dma_sync_single_for_cpu() right before dma_unmap_single() (as the buffer would be read by caller after perform_dma() ) ? dma_sync_single_for_cpu()右前dma_unmap_single()作为缓冲会被呼叫者之后读取perform_dma()

Yes. 是。 You can lookup in here in this KernelTLV presentation (slide 13). 您可以在此KernelTLV演示文稿 (幻灯片13)中查找。 There's an explanation there regarding buffer responsibility. 那里有关于缓冲区责任的解释。

In the example in the presentation it is said you (the driver) can alter the buffer content after dma_sync_single_for_cpu() and return ownership to the device by calling dma_sync_single_for_device() . 在演示的示例中,据说您(驱动程序)可以在dma_sync_single_for_cpu()之后更改缓冲区内容,并通过调用dma_sync_single_for_device()将所有权返回给设备。

It's a question of ownership. 这是所有权问题。 dma_sync_single_for_device() grants ownership to the DMA controller where dma_sync_single_for_cpu() gains ownership back. dma_sync_single_for_device()将所有权授予DMA控制器,其中dma_sync_single_for_cpu()获得所有权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM