File Index
Files and directories
Sign in
FILE

functionfs.h

File preview with syntax highlighting.

linux-6.19.14/include/uapi/linux/usb/functionfs.h C
  1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2#ifndef _UAPI__LINUX_FUNCTIONFS_H__
  3#define _UAPI__LINUX_FUNCTIONFS_H__
  4
  5
  6#include <linux/const.h>
  7#include <linux/types.h>
  8#include <linux/ioctl.h>
  9
 10#include <linux/usb/ch9.h>
 11
 12
 13enum {
 14	FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
 15	FUNCTIONFS_STRINGS_MAGIC = 2,
 16	FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
 17};
 18
 19enum functionfs_flags {
 20	FUNCTIONFS_HAS_FS_DESC = 1,
 21	FUNCTIONFS_HAS_HS_DESC = 2,
 22	FUNCTIONFS_HAS_SS_DESC = 4,
 23	FUNCTIONFS_HAS_MS_OS_DESC = 8,
 24	FUNCTIONFS_VIRTUAL_ADDR = 16,
 25	FUNCTIONFS_EVENTFD = 32,
 26	FUNCTIONFS_ALL_CTRL_RECIP = 64,
 27	FUNCTIONFS_CONFIG0_SETUP = 128,
 28};
 29
 30/* Descriptor of an non-audio endpoint */
 31struct usb_endpoint_descriptor_no_audio {
 32	__u8  bLength;
 33	__u8  bDescriptorType;
 34
 35	__u8  bEndpointAddress;
 36	__u8  bmAttributes;
 37	__le16 wMaxPacketSize;
 38	__u8  bInterval;
 39} __attribute__((packed));
 40
 41/**
 42 * struct usb_dfu_functional_descriptor - DFU Functional descriptor
 43 * @bLength:		Size of the descriptor (bytes)
 44 * @bDescriptorType:	USB_DT_DFU_FUNCTIONAL
 45 * @bmAttributes:	DFU attributes
 46 * @wDetachTimeOut:	Maximum time to wait after DFU_DETACH (ms, le16)
 47 * @wTransferSize:	Maximum number of bytes per control-write (le16)
 48 * @bcdDFUVersion:	DFU Spec version (BCD, le16)
 49 */
 50struct usb_dfu_functional_descriptor {
 51	__u8  bLength;
 52	__u8  bDescriptorType;
 53	__u8  bmAttributes;
 54	__le16 wDetachTimeOut;
 55	__le16 wTransferSize;
 56	__le16 bcdDFUVersion;
 57} __attribute__ ((packed));
 58
 59/* from DFU functional descriptor bmAttributes */
 60#define DFU_FUNC_ATT_CAN_DOWNLOAD	_BITUL(0)
 61#define DFU_FUNC_ATT_CAN_UPLOAD		_BITUL(1)
 62#define DFU_FUNC_ATT_MANIFEST_TOLERANT	_BITUL(2)
 63#define DFU_FUNC_ATT_WILL_DETACH	_BITUL(3)
 64
 65
 66struct usb_functionfs_descs_head_v2 {
 67	__le32 magic;
 68	__le32 length;
 69	__le32 flags;
 70	/*
 71	 * __le32 fs_count, hs_count, fs_count; must be included manually in
 72	 * the structure taking flags into consideration.
 73	 */
 74} __attribute__((packed));
 75
 76/* Legacy format, deprecated as of 3.14. */
 77struct usb_functionfs_descs_head {
 78	__le32 magic;
 79	__le32 length;
 80	__le32 fs_count;
 81	__le32 hs_count;
 82} __attribute__((packed, deprecated));
 83
 84/* MS OS Descriptor header */
 85struct usb_os_desc_header {
 86	__u8	interface;
 87	__le32	dwLength;
 88	__le16	bcdVersion;
 89	__le16	wIndex;
 90	union {
 91		struct {
 92			__u8	bCount;
 93			__u8	Reserved;
 94		};
 95		__le16	wCount;
 96	};
 97} __attribute__((packed));
 98
 99struct usb_ext_compat_desc {
100	__u8	bFirstInterfaceNumber;
101	__u8	Reserved1;
102	__struct_group(/* no tag */, IDs, /* no attrs */,
103		__u8	CompatibleID[8];
104		__u8	SubCompatibleID[8];
105	);
106	__u8	Reserved2[6];
107};
108
109struct usb_ext_prop_desc {
110	__le32	dwSize;
111	__le32	dwPropertyDataType;
112	__le16	wPropertyNameLength;
113} __attribute__((packed));
114
115/* Flags for usb_ffs_dmabuf_transfer_req->flags (none for now) */
116#define USB_FFS_DMABUF_TRANSFER_MASK	0x0
117
118/**
119 * struct usb_ffs_dmabuf_transfer_req - Transfer request for a DMABUF object
120 * @fd:		file descriptor of the DMABUF object
121 * @flags:	one or more USB_FFS_DMABUF_TRANSFER_* flags
122 * @length:	number of bytes used in this DMABUF for the data transfer.
123 *		Should generally be set to the DMABUF's size.
124 */
125struct usb_ffs_dmabuf_transfer_req {
126	int fd;
127	__u32 flags;
128	__u64 length;
129} __attribute__((packed));
130
131#ifndef __KERNEL__
132
133/**
134 * DOC: descriptors
135 *
136 * Descriptors format:
137 *
138 * +-----+-----------+--------------+--------------------------------------+
139 * | off | name      | type         | description                          |
140 * +-----+-----------+--------------+--------------------------------------+
141 * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC_V2      |
142 * +-----+-----------+--------------+--------------------------------------+
143 * |   4 | length    | LE32         | length of the whole data chunk       |
144 * +-----+-----------+--------------+--------------------------------------+
145 * |   8 | flags     | LE32         | combination of functionfs_flags      |
146 * +-----+-----------+--------------+--------------------------------------+
147 * |     | eventfd   | LE32         | eventfd file descriptor              |
148 * +-----+-----------+--------------+--------------------------------------+
149 * |     | fs_count  | LE32         | number of full-speed descriptors     |
150 * +-----+-----------+--------------+--------------------------------------+
151 * |     | hs_count  | LE32         | number of high-speed descriptors     |
152 * +-----+-----------+--------------+--------------------------------------+
153 * |     | ss_count  | LE32         | number of super-speed descriptors    |
154 * +-----+-----------+--------------+--------------------------------------+
155 * |     | os_count  | LE32         | number of MS OS descriptors          |
156 * +-----+-----------+--------------+--------------------------------------+
157 * |     | fs_descrs | Descriptor[] | list of full-speed descriptors       |
158 * +-----+-----------+--------------+--------------------------------------+
159 * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
160 * +-----+-----------+--------------+--------------------------------------+
161 * |     | ss_descrs | Descriptor[] | list of super-speed descriptors      |
162 * +-----+-----------+--------------+--------------------------------------+
163 * |     | os_descrs | OSDesc[]     | list of MS OS descriptors            |
164 * +-----+-----------+--------------+--------------------------------------+
165 *
166 * Depending on which flags are set, various fields may be missing in the
167 * structure.  Any flags that are not recognised cause the whole block to be
168 * rejected with -ENOSYS.
169 *
170 * Legacy descriptors format (deprecated as of 3.14):
171 *
172 * +-----+-----------+--------------+--------------------------------------+
173 * | off | name      | type         | description                          |
174 * +-----+-----------+--------------+--------------------------------------+
175 * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC         |
176 * +-----+-----------+--------------+--------------------------------------+
177 * |   4 | length    | LE32         | length of the whole data chunk       |
178 * +-----+-----------+--------------+--------------------------------------+
179 * |   8 | fs_count  | LE32         | number of full-speed descriptors     |
180 * +-----+-----------+--------------+--------------------------------------+
181 * |  12 | hs_count  | LE32         | number of high-speed descriptors     |
182 * +-----+-----------+--------------+--------------------------------------+
183 * |  16 | fs_descrs | Descriptor[] | list of full-speed descriptors       |
184 * +-----+-----------+--------------+--------------------------------------+
185 * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
186 * +-----+-----------+--------------+--------------------------------------+
187 *
188 * All numbers must be in little endian order.
189 *
190 * Descriptor[] is an array of valid USB descriptors which have the following
191 * format:
192 *
193 * +-----+-----------------+------+--------------------------+
194 * | off | name            | type | description              |
195 * +-----+-----------------+------+--------------------------+
196 * |   0 | bLength         | U8   | length of the descriptor |
197 * +-----+-----------------+------+--------------------------+
198 * |   1 | bDescriptorType | U8   | descriptor type          |
199 * +-----+-----------------+------+--------------------------+
200 * |   2 | payload         |      | descriptor's payload     |
201 * +-----+-----------------+------+--------------------------+
202 *
203 * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
204 * the following formats:
205 *
206 * +-----+-----------------+------+--------------------------+
207 * | off | name            | type | description              |
208 * +-----+-----------------+------+--------------------------+
209 * |   0 | interface       | U8   | related interface number |
210 * +-----+-----------------+------+--------------------------+
211 * |   1 | dwLength        | U32  | length of the descriptor |
212 * +-----+-----------------+------+--------------------------+
213 * |   5 | bcdVersion      | U16  | currently supported: 1   |
214 * +-----+-----------------+------+--------------------------+
215 * |   7 | wIndex          | U16  | currently supported: 4   |
216 * +-----+-----------------+------+--------------------------+
217 * |   9 | bCount          | U8   | number of ext. compat.   |
218 * +-----+-----------------+------+--------------------------+
219 * |  10 | Reserved        | U8   | 0                        |
220 * +-----+-----------------+------+--------------------------+
221 * |  11 | ExtCompat[]     |      | list of ext. compat. d.  |
222 * +-----+-----------------+------+--------------------------+
223 *
224 * +-----+-----------------+------+--------------------------+
225 * | off | name            | type | description              |
226 * +-----+-----------------+------+--------------------------+
227 * |   0 | interface       | U8   | related interface number |
228 * +-----+-----------------+------+--------------------------+
229 * |   1 | dwLength        | U32  | length of the descriptor |
230 * +-----+-----------------+------+--------------------------+
231 * |   5 | bcdVersion      | U16  | currently supported: 1   |
232 * +-----+-----------------+------+--------------------------+
233 * |   7 | wIndex          | U16  | currently supported: 5   |
234 * +-----+-----------------+------+--------------------------+
235 * |   9 | wCount          | U16  | number of ext. compat.   |
236 * +-----+-----------------+------+--------------------------+
237 * |  11 | ExtProp[]       |      | list of ext. prop. d.    |
238 * +-----+-----------------+------+--------------------------+
239 *
240 * ExtCompat[] is an array of valid Extended Compatibility descriptors
241 * which have the following format:
242 *
243 * +-----+-----------------------+------+-------------------------------------+
244 * | off | name                  | type | description                         |
245 * +-----+-----------------------+------+-------------------------------------+
246 * |   0 | bFirstInterfaceNumber | U8   | index of the interface or of the 1st|
247 * +-----+-----------------------+------+-------------------------------------+
248 * |     |                       |      | interface in an IAD group           |
249 * +-----+-----------------------+------+-------------------------------------+
250 * |   1 | Reserved              | U8   | 1                                   |
251 * +-----+-----------------------+------+-------------------------------------+
252 * |   2 | CompatibleID          | U8[8]| compatible ID string                |
253 * +-----+-----------------------+------+-------------------------------------+
254 * |  10 | SubCompatibleID       | U8[8]| subcompatible ID string             |
255 * +-----+-----------------------+------+-------------------------------------+
256 * |  18 | Reserved              | U8[6]| 0                                   |
257 * +-----+-----------------------+------+-------------------------------------+
258 *
259 * ExtProp[] is an array of valid Extended Properties descriptors
260 * which have the following format:
261 *
262 * +-----+-----------------------+------+-------------------------------------+
263 * | off | name                  | type | description                         |
264 * +-----+-----------------------+------+-------------------------------------+
265 * |   0 | dwSize                | U32  | length of the descriptor            |
266 * +-----+-----------------------+------+-------------------------------------+
267 * |   4 | dwPropertyDataType    | U32  | 1..7                                |
268 * +-----+-----------------------+------+-------------------------------------+
269 * |   8 | wPropertyNameLength   | U16  | bPropertyName length (NL)           |
270 * +-----+-----------------------+------+-------------------------------------+
271 * |  10 | bPropertyName         |U8[NL]| name of this property               |
272 * +-----+-----------------------+------+-------------------------------------+
273 * |10+NL| dwPropertyDataLength  | U32  | bPropertyData length (DL)           |
274 * +-----+-----------------------+------+-------------------------------------+
275 * |14+NL| bProperty             |U8[DL]| payload of this property            |
276 * +-----+-----------------------+------+-------------------------------------+
277 */
278
279struct usb_functionfs_strings_head {
280	__le32 magic;
281	__le32 length;
282	__le32 str_count;
283	__le32 lang_count;
284} __attribute__((packed));
285
286/*
287 * Strings format:
288 *
289 * | off | name       | type                  | description                |
290 * |-----+------------+-----------------------+----------------------------|
291 * |   0 | magic      | LE32                  | FUNCTIONFS_STRINGS_MAGIC   |
292 * |   4 | length     | LE32                  | length of the data chunk   |
293 * |   8 | str_count  | LE32                  | number of strings          |
294 * |  12 | lang_count | LE32                  | number of languages        |
295 * |  16 | stringtab  | StringTab[lang_count] | table of strings per lang  |
296 *
297 * For each language there is one stringtab entry (ie. there are lang_count
298 * stringtab entries).  Each StringTab has following format:
299 *
300 * | off | name    | type              | description                        |
301 * |-----+---------+-------------------+------------------------------------|
302 * |   0 | lang    | LE16              | language code                      |
303 * |   2 | strings | String[str_count] | array of strings in given language |
304 *
305 * For each string there is one strings entry (ie. there are str_count
306 * string entries).  Each String is a NUL terminated string encoded in
307 * UTF-8.
308 */
309
310#endif
311
312
313/*
314 * Events are delivered on the ep0 file descriptor, when the user mode driver
315 * reads from this file descriptor after writing the descriptors.  Don't
316 * stop polling this descriptor.
317 */
318
319enum usb_functionfs_event_type {
320	FUNCTIONFS_BIND,
321	FUNCTIONFS_UNBIND,
322
323	FUNCTIONFS_ENABLE,
324	FUNCTIONFS_DISABLE,
325
326	FUNCTIONFS_SETUP,
327
328	FUNCTIONFS_SUSPEND,
329	FUNCTIONFS_RESUME
330};
331
332/* NOTE:  this structure must stay the same size and layout on
333 * both 32-bit and 64-bit kernels.
334 */
335struct usb_functionfs_event {
336	union {
337		/* SETUP: packet; DATA phase i/o precedes next event
338		 *(setup.bmRequestType & USB_DIR_IN) flags direction */
339		struct usb_ctrlrequest	setup;
340	} __attribute__((packed)) u;
341
342	/* enum usb_functionfs_event_type */
343	__u8				type;
344	__u8				_pad[3];
345} __attribute__((packed));
346
347
348/* Endpoint ioctls */
349/* The same as in gadgetfs */
350
351/* IN transfers may be reported to the gadget driver as complete
352 *	when the fifo is loaded, before the host reads the data;
353 * OUT transfers may be reported to the host's "client" driver as
354 *	complete when they're sitting in the FIFO unread.
355 * THIS returns how many bytes are "unclaimed" in the endpoint fifo
356 * (needed for precise fault handling, when the hardware allows it)
357 */
358#define	FUNCTIONFS_FIFO_STATUS	_IO('g', 1)
359
360/* discards any unclaimed data in the fifo. */
361#define	FUNCTIONFS_FIFO_FLUSH	_IO('g', 2)
362
363/* resets endpoint halt+toggle; used to implement set_interface.
364 * some hardware (like pxa2xx) can't support this.
365 */
366#define	FUNCTIONFS_CLEAR_HALT	_IO('g', 3)
367
368/* Specific for functionfs */
369
370/*
371 * Returns reverse mapping of an interface.  Called on EP0.  If there
372 * is no such interface returns -EDOM.  If function is not active
373 * returns -ENODEV.
374 */
375#define	FUNCTIONFS_INTERFACE_REVMAP	_IO('g', 128)
376
377/*
378 * Returns real bEndpointAddress of an endpoint. If endpoint shuts down
379 * during the call, returns -ESHUTDOWN.
380 */
381#define	FUNCTIONFS_ENDPOINT_REVMAP	_IO('g', 129)
382
383/*
384 * Returns endpoint descriptor. If endpoint shuts down during the call,
385 * returns -ESHUTDOWN.
386 */
387#define	FUNCTIONFS_ENDPOINT_DESC	_IOR('g', 130, \
388					     struct usb_endpoint_descriptor)
389
390/*
391 * Attach the DMABUF object, identified by its file descriptor, to the
392 * data endpoint. Returns zero on success, and a negative errno value
393 * on error.
394 */
395#define FUNCTIONFS_DMABUF_ATTACH	_IOW('g', 131, int)
396
397
398/*
399 * Detach the given DMABUF object, identified by its file descriptor,
400 * from the data endpoint. Returns zero on success, and a negative
401 * errno value on error. Note that closing the endpoint's file
402 * descriptor will automatically detach all attached DMABUFs.
403 */
404#define FUNCTIONFS_DMABUF_DETACH	_IOW('g', 132, int)
405
406/*
407 * Enqueue the previously attached DMABUF to the transfer queue.
408 * The argument is a structure that packs the DMABUF's file descriptor,
409 * the size in bytes to transfer (which should generally correspond to
410 * the size of the DMABUF), and a 'flags' field which is unused
411 * for now. Returns zero on success, and a negative errno value on
412 * error.
413 */
414#define FUNCTIONFS_DMABUF_TRANSFER	_IOW('g', 133, \
415					     struct usb_ffs_dmabuf_transfer_req)
416
417#endif /* _UAPI__LINUX_FUNCTIONFS_H__ */
~/ Read-only file preview.