mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-12-22 12:17:45 +01:00
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 <paul@crapouillou.net> Co-developed-by: Nuno Sa <nuno.sa@analog.com> Signed-off-by: Nuno Sa <nuno.sa@analog.com> Link: https://patch.msgid.link/20240620122726.41232-4-paul@crapouillou.net Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
33 lines
1000 B
C
33 lines
1000 B
C
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
|
/* industrial I/O buffer definitions needed both in and out of kernel
|
|
*/
|
|
|
|
#ifndef _UAPI_IIO_BUFFER_H_
|
|
#define _UAPI_IIO_BUFFER_H_
|
|
|
|
#include <linux/types.h>
|
|
|
|
/* Flags for iio_dmabuf.flags */
|
|
#define IIO_BUFFER_DMABUF_CYCLIC (1 << 0)
|
|
#define IIO_BUFFER_DMABUF_SUPPORTED_FLAGS 0x00000001
|
|
|
|
/**
|
|
* struct iio_dmabuf - Descriptor for a single IIO DMABUF object
|
|
* @fd: file descriptor of the DMABUF object
|
|
* @flags: one or more IIO_BUFFER_DMABUF_* flags
|
|
* @bytes_used: number of bytes used in this DMABUF for the data transfer.
|
|
* Should generally be set to the DMABUF's size.
|
|
*/
|
|
struct iio_dmabuf {
|
|
__u32 fd;
|
|
__u32 flags;
|
|
__u64 bytes_used;
|
|
};
|
|
|
|
#define IIO_BUFFER_GET_FD_IOCTL _IOWR('i', 0x91, int)
|
|
#define IIO_BUFFER_DMABUF_ATTACH_IOCTL _IOW('i', 0x92, int)
|
|
#define IIO_BUFFER_DMABUF_DETACH_IOCTL _IOW('i', 0x93, int)
|
|
#define IIO_BUFFER_DMABUF_ENQUEUE_IOCTL _IOW('i', 0x94, struct iio_dmabuf)
|
|
|
|
#endif /* _UAPI_IIO_BUFFER_H_ */
|