User:ScotXW/DMA BUF

A dma-buf is a kernel DMA buffer
 * http://lwn.net/Articles/569701/
 * https://lwn.net/Articles/474819/

DMA-BUF
The DMA-BUF framework provides a generic method for sharing buffers between multiple devices. Device drivers that support DMABUF can export a DMA buffer to userspace as a file descriptor (known as the exporter role), import a DMA buffer from userspace using a file descriptor previously exported for a different or the same device (known as the importer role), or both.

DMA-BUF cross-device synchronization and DMA-BUF fencing was merged into Linux kernel 3.17.

A fence can be attached to a buffer which is being filled or consumed by hardware, to allow userspace to pass the buffer without waiting to another device. For example, userspace can call page_flip ioctl to display the next frame of graphics after kicking the GPU but while the GPU is still rendering. The display device sharing the buffer with the GPU would attach a callback to get notified when the GPU's rendering-complete IRQ fires, to update the scan-out address of the display, without having to wake up userspace."


 * 1) dma-buf operations for device dma only; The dma_buf buffer sharing API usage contains the following steps
 * 2) Exporter announces that it wishes to export a buffer
 * 3) Userspace gets the file descriptor associated with the exported buffer, and passes it around to potential buffer-users based on use case
 * 4) Each buffer-user 'connects' itself to the buffer
 * 5) When needed, buffer-user requests access to the buffer from exporter
 * 6) When finished with its use, the buffer-user notifies end-of-DMA to exporter
 * 7) when buffer-user is done using this buffer completely, it 'disconnects' itself from the buffer.
 * 8) Kernel cpu access to a dma-buf buffer object; Access to a dma_buf from the kernel context involves three steps:
 * 9) Prepare access, which invalidate any necessary caches and make the object available for cpu access.
 * 10) Access the object page-by-page with the dma_buf map apis
 * 11) Finish access, which will flush any necessary cpu caches and free reserved resources.
 * 12) Direct Userspace Access/mmap Support


 * Direct Rendering Infrastructure version 3 replaced GEM handles with DMA-BUFs
 * Video4Linux has experimental use of DMA-BUFs