-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for passing sample data as DMABUF objects between IIO devices, and the USB stack. This mechanism has the benefit that the CPU will never access the data to copy it from one hardware buffer to another, and therefore results in a much higher throughput at a much lower CPU usage. For this new mechanism to work, the DMABUF-based IIO kernel API must be available and used by the local backend, and the FunctionFS stack must also support importing DMABUFs. If those conditions are not met, the standard way of transferring the data will be used. Signed-off-by: Paul Cercueil <paul@crapouillou.net>
- Loading branch information
Showing
5 changed files
with
129 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
/* | ||
* libiio - Library for interfacing industrial I/O (IIO) devices | ||
* | ||
* Copyright (C) 2023 Analog Devices, Inc. | ||
* Author: Paul Cercueil <paul.cercueil@analog.com> | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <sys/ioctl.h> | ||
|
||
#define IIO_FFS_DMABUF_ATTACH _IOW('g', 131, int) | ||
#define IIO_FFS_DMABUF_DETACH _IOW('g', 132, int) | ||
#define IIO_FFS_DMABUF_TRANSFER _IOW('g', 133, struct iio_ffs_dmabuf_transfer) | ||
|
||
struct iio_ffs_dmabuf_transfer { | ||
int fd; | ||
uint32_t flags; | ||
uint64_t length; | ||
}; | ||
|
||
int usb_attach_dmabuf(int ep_fd, int fd) | ||
{ | ||
int ret; | ||
|
||
ret = ioctl(ep_fd, IIO_FFS_DMABUF_ATTACH, &fd); | ||
if (ret == -1) | ||
return -errno; | ||
|
||
return 0; | ||
} | ||
|
||
int usb_detach_dmabuf(int ep_fd, int fd) | ||
{ | ||
int ret; | ||
|
||
ret = ioctl(ep_fd, IIO_FFS_DMABUF_DETACH, &fd); | ||
if (ret == -1) | ||
return -errno; | ||
|
||
return 0; | ||
} | ||
|
||
int usb_transfer_dmabuf(int ep_fd, int fd, uint64_t size) | ||
{ | ||
struct iio_ffs_dmabuf_transfer req; | ||
int ret; | ||
|
||
req.fd = fd; | ||
req.length = size; | ||
req.flags = 0; | ||
|
||
ret = ioctl(ep_fd, IIO_FFS_DMABUF_TRANSFER, &req); | ||
if (ret == -1) | ||
return -errno; | ||
|
||
return 0; | ||
} |