我的代码使用流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
}DMA方向是双向的,buffer被分配,在调用perform_dma()之前由调用方填充,并在调用完成后释放。
我该用吗
dma_sync_single_for_device()后的dma_map_single() (但在通知设备执行DMA之前)和
dma_sync_single_for_cpu()就在dma_unmap_single()之前(因为缓冲区将在perform_dma()之后被调用方读取)?发布于 2018-11-11 23:22:37
是。您可以在这里查找在本KernelTLV演示文稿中 (幻灯片13)。有一个关于缓冲责任的解释。
在演示文稿中的示例中,据说您(驱动程序)可以在dma_sync_single_for_cpu()之后更改缓冲区内容,并通过调用dma_sync_single_for_device()将所有权返回给设备。
这是所有权的问题。dma_sync_single_for_device()将所有权授予DMA控制器,其中dma_sync_single_for_cpu()获得所有权。
https://stackoverflow.com/questions/53246379
复制相似问题