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

raw_gadget.h (8577B)


  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * USB Raw Gadget driver.
  4. *
  5. * See Documentation/usb/raw-gadget.rst for more details.
  6. */
  7. #ifndef __LINUX_USB_RAW_GADGET_H
  8. #define __LINUX_USB_RAW_GADGET_H
  9. #include <asm/ioctl.h>
  10. #include <linux/types.h>
  11. #include <linux/usb/ch9.h>
  12. /* Maximum length of driver_name/device_name in the usb_raw_init struct. */
  13. #define UDC_NAME_LENGTH_MAX 128
  14. /*
  15. * struct usb_raw_init - argument for USB_RAW_IOCTL_INIT ioctl.
  16. * @speed: The speed of the emulated USB device, takes the same values as
  17. * the usb_device_speed enum: USB_SPEED_FULL, USB_SPEED_HIGH, etc.
  18. * @driver_name: The name of the UDC driver.
  19. * @device_name: The name of a UDC instance.
  20. *
  21. * The last two fields identify a UDC the gadget driver should bind to.
  22. * For example, Dummy UDC has "dummy_udc" as its driver_name and "dummy_udc.N"
  23. * as its device_name, where N in the index of the Dummy UDC instance.
  24. * At the same time the dwc2 driver that is used on Raspberry Pi Zero, has
  25. * "20980000.usb" as both driver_name and device_name.
  26. */
  27. struct usb_raw_init {
  28. __u8 driver_name[UDC_NAME_LENGTH_MAX];
  29. __u8 device_name[UDC_NAME_LENGTH_MAX];
  30. __u8 speed;
  31. };
  32. /* The type of event fetched with the USB_RAW_IOCTL_EVENT_FETCH ioctl. */
  33. enum usb_raw_event_type {
  34. USB_RAW_EVENT_INVALID = 0,
  35. /* This event is queued when the driver has bound to a UDC. */
  36. USB_RAW_EVENT_CONNECT = 1,
  37. /* This event is queued when a new control request arrived to ep0. */
  38. USB_RAW_EVENT_CONTROL = 2,
  39. /*
  40. * These events are queued when the gadget driver is suspended,
  41. * resumed, reset, or disconnected. Note that some UDCs (e.g. dwc2)
  42. * report a disconnect event instead of a reset.
  43. */
  44. USB_RAW_EVENT_SUSPEND = 3,
  45. USB_RAW_EVENT_RESUME = 4,
  46. USB_RAW_EVENT_RESET = 5,
  47. USB_RAW_EVENT_DISCONNECT = 6,
  48. /* The list might grow in the future. */
  49. };
  50. /*
  51. * struct usb_raw_event - argument for USB_RAW_IOCTL_EVENT_FETCH ioctl.
  52. * @type: The type of the fetched event.
  53. * @length: Length of the data buffer. Updated by the driver and set to the
  54. * actual length of the fetched event data.
  55. * @data: A buffer to store the fetched event data.
  56. *
  57. * The fetched event data buffer contains struct usb_ctrlrequest for
  58. * USB_RAW_EVENT_CONTROL and is empty for other events.
  59. */
  60. struct usb_raw_event {
  61. __u32 type;
  62. __u32 length;
  63. __u8 data[];
  64. };
  65. #define USB_RAW_IO_FLAGS_ZERO 0x0001
  66. #define USB_RAW_IO_FLAGS_MASK 0x0001
  67. static __inline__ int usb_raw_io_flags_valid(__u16 flags)
  68. {
  69. return (flags & ~USB_RAW_IO_FLAGS_MASK) == 0;
  70. }
  71. static __inline__ int usb_raw_io_flags_zero(__u16 flags)
  72. {
  73. return (flags & USB_RAW_IO_FLAGS_ZERO);
  74. }
  75. /*
  76. * struct usb_raw_ep_io - argument for USB_RAW_IOCTL_EP0/EP_WRITE/READ ioctls.
  77. * @ep: Endpoint handle as returned by USB_RAW_IOCTL_EP_ENABLE for
  78. * USB_RAW_IOCTL_EP_WRITE/READ. Ignored for USB_RAW_IOCTL_EP0_WRITE/READ.
  79. * @flags: When USB_RAW_IO_FLAGS_ZERO is specified, the zero flag is set on
  80. * the submitted USB request, see include/linux/usb/gadget.h for details.
  81. * @length: Length of data.
  82. * @data: Data to send for USB_RAW_IOCTL_EP0/EP_WRITE. Buffer to store received
  83. * data for USB_RAW_IOCTL_EP0/EP_READ.
  84. */
  85. struct usb_raw_ep_io {
  86. __u16 ep;
  87. __u16 flags;
  88. __u32 length;
  89. __u8 data[];
  90. };
  91. /* Maximum number of non-control endpoints in struct usb_raw_eps_info. */
  92. #define USB_RAW_EPS_NUM_MAX 30
  93. /* Maximum length of UDC endpoint name in struct usb_raw_ep_info. */
  94. #define USB_RAW_EP_NAME_MAX 16
  95. /* Used as addr in struct usb_raw_ep_info if endpoint accepts any address. */
  96. #define USB_RAW_EP_ADDR_ANY 0xff
  97. /*
  98. * struct usb_raw_ep_caps - exposes endpoint capabilities from struct usb_ep
  99. * (technically from its member struct usb_ep_caps).
  100. */
  101. struct usb_raw_ep_caps {
  102. __u32 type_control : 1;
  103. __u32 type_iso : 1;
  104. __u32 type_bulk : 1;
  105. __u32 type_int : 1;
  106. __u32 dir_in : 1;
  107. __u32 dir_out : 1;
  108. };
  109. /*
  110. * struct usb_raw_ep_limits - exposes endpoint limits from struct usb_ep.
  111. * @maxpacket_limit: Maximum packet size value supported by this endpoint.
  112. * @max_streams: maximum number of streams supported by this endpoint
  113. * (actual number is 2^n).
  114. * @reserved: Empty, reserved for potential future extensions.
  115. */
  116. struct usb_raw_ep_limits {
  117. __u16 maxpacket_limit;
  118. __u16 max_streams;
  119. __u32 reserved;
  120. };
  121. /*
  122. * struct usb_raw_ep_info - stores information about a gadget endpoint.
  123. * @name: Name of the endpoint as it is defined in the UDC driver.
  124. * @addr: Address of the endpoint that must be specified in the endpoint
  125. * descriptor passed to USB_RAW_IOCTL_EP_ENABLE ioctl.
  126. * @caps: Endpoint capabilities.
  127. * @limits: Endpoint limits.
  128. */
  129. struct usb_raw_ep_info {
  130. __u8 name[USB_RAW_EP_NAME_MAX];
  131. __u32 addr;
  132. struct usb_raw_ep_caps caps;
  133. struct usb_raw_ep_limits limits;
  134. };
  135. /*
  136. * struct usb_raw_eps_info - argument for USB_RAW_IOCTL_EPS_INFO ioctl.
  137. * eps: Structures that store information about non-control endpoints.
  138. */
  139. struct usb_raw_eps_info {
  140. struct usb_raw_ep_info eps[USB_RAW_EPS_NUM_MAX];
  141. };
  142. /*
  143. * Initializes a Raw Gadget instance.
  144. * Accepts a pointer to the usb_raw_init struct as an argument.
  145. * Returns 0 on success or negative error code on failure.
  146. */
  147. #define USB_RAW_IOCTL_INIT _IOW('U', 0, struct usb_raw_init)
  148. /*
  149. * Instructs Raw Gadget to bind to a UDC and start emulating a USB device.
  150. * Returns 0 on success or negative error code on failure.
  151. */
  152. #define USB_RAW_IOCTL_RUN _IO('U', 1)
  153. /*
  154. * A blocking ioctl that waits for an event and returns fetched event data to
  155. * the user.
  156. * Accepts a pointer to the usb_raw_event struct.
  157. * Returns 0 on success or negative error code on failure.
  158. */
  159. #define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event)
  160. /*
  161. * Queues an IN (OUT for READ) request as a response to the last setup request
  162. * received on endpoint 0 (provided that was an IN (OUT for READ) request), and
  163. * waits until the request is completed. Copies received data to user for READ.
  164. * Accepts a pointer to the usb_raw_ep_io struct as an argument.
  165. * Returns length of transferred data on success or negative error code on
  166. * failure.
  167. */
  168. #define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io)
  169. #define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io)
  170. /*
  171. * Finds an endpoint that satisfies the parameters specified in the provided
  172. * descriptors (address, transfer type, etc.) and enables it.
  173. * Accepts a pointer to the usb_raw_ep_descs struct as an argument.
  174. * Returns enabled endpoint handle on success or negative error code on failure.
  175. */
  176. #define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor)
  177. /*
  178. * Disables specified endpoint.
  179. * Accepts endpoint handle as an argument.
  180. * Returns 0 on success or negative error code on failure.
  181. */
  182. #define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32)
  183. /*
  184. * Queues an IN (OUT for READ) request as a response to the last setup request
  185. * received on endpoint usb_raw_ep_io.ep (provided that was an IN (OUT for READ)
  186. * request), and waits until the request is completed. Copies received data to
  187. * user for READ.
  188. * Accepts a pointer to the usb_raw_ep_io struct as an argument.
  189. * Returns length of transferred data on success or negative error code on
  190. * failure.
  191. */
  192. #define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io)
  193. #define USB_RAW_IOCTL_EP_READ _IOWR('U', 8, struct usb_raw_ep_io)
  194. /*
  195. * Switches the gadget into the configured state.
  196. * Returns 0 on success or negative error code on failure.
  197. */
  198. #define USB_RAW_IOCTL_CONFIGURE _IO('U', 9)
  199. /*
  200. * Constrains UDC VBUS power usage.
  201. * Accepts current limit in 2 mA units as an argument.
  202. * Returns 0 on success or negative error code on failure.
  203. */
  204. #define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32)
  205. /*
  206. * Fills in the usb_raw_eps_info structure with information about non-control
  207. * endpoints available for the currently connected UDC.
  208. * Returns the number of available endpoints on success or negative error code
  209. * on failure.
  210. */
  211. #define USB_RAW_IOCTL_EPS_INFO _IOR('U', 11, struct usb_raw_eps_info)
  212. /*
  213. * Stalls a pending control request on endpoint 0.
  214. * Returns 0 on success or negative error code on failure.
  215. */
  216. #define USB_RAW_IOCTL_EP0_STALL _IO('U', 12)
  217. /*
  218. * Sets or clears halt or wedge status of the endpoint.
  219. * Accepts endpoint handle as an argument.
  220. * Returns 0 on success or negative error code on failure.
  221. */
  222. #define USB_RAW_IOCTL_EP_SET_HALT _IOW('U', 13, __u32)
  223. #define USB_RAW_IOCTL_EP_CLEAR_HALT _IOW('U', 14, __u32)
  224. #define USB_RAW_IOCTL_EP_SET_WEDGE _IOW('U', 15, __u32)
  225. #endif /* __LINUX_USB_RAW_GADGET_H */