iio_dmabuf_api.rst 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===================================
  3. High-speed DMABUF interface for IIO
  4. ===================================
  5. 1. Overview
  6. ===========
  7. The Industrial I/O subsystem supports access to buffers through a
  8. file-based interface, with read() and write() access calls through the
  9. IIO device's dev node.
  10. It additionally supports a DMABUF based interface, where the userspace
  11. can attach DMABUF objects (externally created) to an IIO buffer, and
  12. subsequently use them for data transfers.
  13. A userspace application can then use this interface to share DMABUF
  14. objects between several interfaces, allowing it to transfer data in a
  15. zero-copy fashion, for instance between IIO and the USB stack.
  16. The userspace application can also memory-map the DMABUF objects, and
  17. access the sample data directly. The advantage of doing this vs. the
  18. read() interface is that it avoids an extra copy of the data between the
  19. kernel and userspace. This is particularly useful for high-speed devices
  20. which produce several megabytes or even gigabytes of data per second.
  21. It does however increase the userspace-kernelspace synchronization
  22. overhead, as the DMA_BUF_SYNC_START and DMA_BUF_SYNC_END IOCTLs have to
  23. be used for data integrity.
  24. 2. User API
  25. ===========
  26. As part of this interface, three new IOCTLs have been added. These three
  27. IOCTLs have to be performed on the IIO buffer's file descriptor, which
  28. can be obtained using the IIO_BUFFER_GET_FD_IOCTL() ioctl.
  29. ``IIO_BUFFER_DMABUF_ATTACH_IOCTL(int fd)``
  30. Attach the DMABUF object, identified by its file descriptor, to the
  31. IIO buffer. Returns zero on success, and a negative errno value on
  32. error.
  33. ``IIO_BUFFER_DMABUF_DETACH_IOCTL(int fd)``
  34. Detach the given DMABUF object, identified by its file descriptor,
  35. from the IIO buffer. Returns zero on success, and a negative errno
  36. value on error.
  37. Note that closing the IIO buffer's file descriptor will
  38. automatically detach all previously attached DMABUF objects.
  39. ``IIO_BUFFER_DMABUF_ENQUEUE_IOCTL(struct iio_dmabuf *iio_dmabuf)``
  40. Enqueue a previously attached DMABUF object to the buffer queue.
  41. Enqueued DMABUFs will be read from (if output buffer) or written to
  42. (if input buffer) as long as the buffer is enabled.