History

usb: gadget: functionfs: Add DMABUF import interface

This patch introduces three new ioctls. They all should be called on a data endpoint (ie. not ep0). They are: - FUNCTIONFS_DMABUF_ATTACH, which takes the file descriptor of a DMABUF object to attach to the endpoint. - FUNCTIONFS_DMABUF_DETACH, which takes the file descriptor of the DMABUF to detach from the endpoint. Note that closing the endpoint's file descriptor will automatically detach all attached DMABUFs. - FUNCTIONFS_DMABUF_TRANSFER, which requests a data transfer from / to the given DMABUF. Its argument is a structure that packs the DMABUF's file descriptor, the size in bytes to transfer (which should generally be set to the size of the DMABUF), and a 'flags' field which is unused for now. Before this ioctl can be used, the related DMABUF must be attached with FUNCTIONFS_DMABUF_ATTACH. These three ioctls enable the FunctionFS code to transfer data between the USB stack and a DMABUF object, which can be provided by a driver from a completely different subsystem, in a zero-copy fashion.

Paul Cercueil committed 2 years ago

Commit 7b07a2a1 parent 799970a3 files · +509 −0Browse files

Showing the changes to include/uapi (1 of 3 files). Show all

Unified · Split

include/uapi/linux/usb/functionfs.h+41−0
@@ -86,6 +86,22 @@ struct usb_ext_prop_desc { · 85 unmodified lines
8686 __le16 wPropertyNameLength;
8787 } __attribute__((packed));
8888
89+/* Flags for usb_ffs_dmabuf_transfer_req->flags (none for now) */
90+#define USB_FFS_DMABUF_TRANSFER_MASK 0x0
91+
92+/**
93+ * struct usb_ffs_dmabuf_transfer_req - Transfer request for a DMABUF object
94+ * @fd: file descriptor of the DMABUF object
95+ * @flags: one or more USB_FFS_DMABUF_TRANSFER_* flags
96+ * @length: number of bytes used in this DMABUF for the data transfer.
97+ * Should generally be set to the DMABUF's size.
98+ */
99+struct usb_ffs_dmabuf_transfer_req {
100+ int fd;
101+ __u32 flags;
102+ __u64 length;
103+} __attribute__((packed));
104+
89105 #ifndef __KERNEL__
90106
91107 /*
@@ -290,6 +306,31 @@ struct usb_functionfs_event { · 198 unmodified lines
290306 #define FUNCTIONFS_ENDPOINT_DESC _IOR('g', 130, \
291307 struct usb_endpoint_descriptor)
292308
309+/*
310+ * Attach the DMABUF object, identified by its file descriptor, to the
311+ * data endpoint. Returns zero on success, and a negative errno value
312+ * on error.
313+ */
314+#define FUNCTIONFS_DMABUF_ATTACH _IOW('g', 131, int)
315+
293316
317+/*
318+ * Detach the given DMABUF object, identified by its file descriptor,
319+ * from the data endpoint. Returns zero on success, and a negative
320+ * errno value on error. Note that closing the endpoint's file
321+ * descriptor will automatically detach all attached DMABUFs.
322+ */
323+#define FUNCTIONFS_DMABUF_DETACH _IOW('g', 132, int)
324+
325+/*
326+ * Enqueue the previously attached DMABUF to the transfer queue.
327+ * The argument is a structure that packs the DMABUF's file descriptor,
328+ * the size in bytes to transfer (which should generally correspond to
329+ * the size of the DMABUF), and a 'flags' field which is unused
330+ * for now. Returns zero on success, and a negative errno value on
331+ * error.
332+ */
333+#define FUNCTIONFS_DMABUF_TRANSFER _IOW('g', 133, \
334+ struct usb_ffs_dmabuf_transfer_req)
294335
295336 #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t