Skip to content

Commit

Permalink
iio: core: Add new DMABUF interface infrastructure
Browse files Browse the repository at this point in the history
Add the necessary infrastructure to the IIO core to support a new
optional DMABUF based interface.

With this new interface, DMABUF objects (externally created) can be
attached to a IIO buffer, and subsequently used for data transfer.

A userspace application can then use this interface to share DMABUF
objects between several interfaces, allowing it to transfer data in a
zero-copy fashion, for instance between IIO and the USB stack.

The userspace application can also memory-map the DMABUF objects, and
access the sample data directly. The advantage of doing this vs. the
read() interface is that it avoids an extra copy of the data between the
kernel and userspace. This is particularly userful for high-speed
devices which produce several megabytes or even gigabytes of data per
second.

As part of the interface, 3 new IOCTLs have been added:

IIO_BUFFER_DMABUF_ATTACH_IOCTL(int fd):
 Attach the DMABUF object identified by the given file descriptor to the
 buffer.

IIO_BUFFER_DMABUF_DETACH_IOCTL(int fd):
 Detach the DMABUF object identified by the given file descriptor from
 the buffer. Note that closing the IIO buffer's file descriptor will
 automatically detach all previously attached DMABUF objects.

IIO_BUFFER_DMABUF_ENQUEUE_IOCTL(struct iio_dmabuf *):
 Request a data transfer to/from the given DMABUF object. Its file
 descriptor, as well as the transfer size and flags are provided in the
 "iio_dmabuf" structure.

These three IOCTLs have to be performed on the IIO buffer's file
descriptor, obtained using the IIO_BUFFER_GET_FD_IOCTL() ioctl.

Signed-off-by: Paul Cercueil <[email protected]>
Co-developed-by: Nuno Sa <[email protected]>
Signed-off-by: Nuno Sa <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
pcercuei authored and jic23 committed Jun 30, 2024
1 parent da5a6fa commit 3e26d9f
Show file tree
Hide file tree
Showing 4 changed files with 515 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/iio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if IIO

config IIO_BUFFER
bool "Enable buffer support within IIO"
select DMA_SHARED_BUFFER
help
Provide core support for various buffer based data
acquisition methods.
Expand Down
Loading

0 comments on commit 3e26d9f

Please sign in to comment.