dma-buf: Introduce dma buffer sharing mechanism
authorSumit Semwal <sumit.semwal@ti.com>
Mon, 26 Dec 2011 09:23:15 +0000 (14:23 +0530)
committerRohan Somvanshi <rsomvanshi@nvidia.com>
Fri, 3 Feb 2012 13:20:29 +0000 (05:20 -0800)
commit9ba7a60e8c71e46580da32f4d0e8eed3fb11a47a
treea28eeb20648edb1076a65fed8eeb2364ce1d052d
parentc8bee9dfd45d9bc9e35cc735567f25a210e87a5c
dma-buf: Introduce dma buffer sharing mechanism

This is the first step in defining a dma buffer sharing mechanism.

A new buffer object dma_buf is added, with operations and API to allow easy
sharing of this buffer object across devices.

The framework allows:
- creation of a buffer object, its association with a file pointer, and
   associated allocator-defined operations on that buffer. This operation is
   called the 'export' operation.
- different devices to 'attach' themselves to this exported buffer object, to
  facilitate backing storage negotiation, using dma_buf_attach() API.
- the exported buffer object to be shared with the other entity by asking for
   its 'file-descriptor (fd)', and sharing the fd across.
- a received fd to get the buffer object back, where it can be accessed using
   the associated exporter-defined operations.
- the exporter and user to share the scatterlist associated with this buffer
   object using map_dma_buf and unmap_dma_buf operations.

Atleast one 'attach()' call is required to be made prior to calling the
map_dma_buf() operation.

Couple of building blocks in map_dma_buf() are added to ease introduction
of sync'ing across exporter and users, and late allocation by the exporter.

For this first version, this framework will work with certain conditions:
- *ONLY* exporter will be allowed to mmap to userspace (outside of this
   framework - mmap is not a buffer object operation),
- currently, *ONLY* users that do not need CPU access to the buffer are
   allowed.

More details are there in the documentation patch.

This is based on design suggestions from many people at the mini-summits[1],
most notably from Arnd Bergmann <arnd@arndb.de>, Rob Clark <rob@ti.com> and
Daniel Vetter <daniel@ffwll.ch>.

The implementation is inspired from proof-of-concept patch-set from
Tomasz Stanislawski <t.stanislaws@samsung.com>, who demonstrated buffer sharing
between two v4l2 devices. [2]

[1]: https://wiki.linaro.org/OfficeofCTO/MemoryManagement
[2]: http://lwn.net/Articles/454389

Change-Id: I8ebd858ad86242ee7b02d5f42bb25c3edbd64fca
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Signed-off-by: Sumit Semwal <sumit.semwal@ti.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-and-Tested-by: Rob Clark <rob.clark@linaro.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Hiroshi DOYU <hdoyu@nvidia.com>
[Hiroshi DOYU: Backported from v3.3-rc1]
Reviewed-on: http://git-master/r/78384
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Varun Wadekar <vwadekar@nvidia.com>
Reviewed-by: Ken Adams <kadams@nvidia.com>
drivers/base/Kconfig
drivers/base/Makefile
drivers/base/dma-buf.c [new file with mode: 0644]
include/linux/dma-buf.h [new file with mode: 0644]