logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

functionfs.h (16655B)


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