1 #ifndef _UAPI__LINUX_FUNCTIONFS_H__ 2 #define _UAPI__LINUX_FUNCTIONFS_H__ 3 4 5 #include <linux/types.h> 6 #include <linux/ioctl.h> 7 8 #include <linux/usb/ch9.h> 9 10 11 enum { 12 FUNCTIONFS_DESCRIPTORS_MAGIC = 1, 13 FUNCTIONFS_STRINGS_MAGIC = 2 14 }; 15 16 #define FUNCTIONFS_SS_DESC_MAGIC 0x0055DE5C 17 18 #ifndef __KERNEL__ 19 20 /* Descriptor of an non-audio endpoint */ 21 struct usb_endpoint_descriptor_no_audio { 22 __u8 bLength; 23 __u8 bDescriptorType; 24 25 __u8 bEndpointAddress; 26 __u8 bmAttributes; 27 __le16 wMaxPacketSize; 28 __u8 bInterval; 29 } __attribute__((packed)); 30 31 32 /* 33 * All numbers must be in little endian order. 34 */ 35 36 struct usb_functionfs_descs_head { 37 __le32 magic; 38 __le32 length; 39 __le32 fs_count; 40 __le32 hs_count; 41 } __attribute__((packed)); 42 43 /* 44 * Descriptors format: 45 * 46 * | off | name | type | description | 47 * |-----+-----------+--------------+--------------------------------------| 48 * | 0 | magic | LE32 | FUNCTIONFS_{FS,HS}_DESCRIPTORS_MAGIC | 49 * | 4 | length | LE32 | length of the whole data chunk | 50 * | 8 | fs_count | LE32 | number of full-speed descriptors | 51 * | 12 | hs_count | LE32 | number of high-speed descriptors | 52 * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors | 53 * | | hs_descrs | Descriptor[] | list of high-speed descriptors | 54 * | | ss_magic | LE32 | FUNCTIONFS_SS_DESC_MAGIC | 55 * | | ss_count | LE32 | number of super-speed descriptors | 56 * | | ss_descrs | Descriptor[] | list of super-speed descriptors | 57 * 58 * ss_magic: if present then it implies that SS_DESCs are also present 59 * descs are just valid USB descriptors and have the following format: 60 * 61 * | off | name | type | description | 62 * |-----+-----------------+------+--------------------------| 63 * | 0 | bLength | U8 | length of the descriptor | 64 * | 1 | bDescriptorType | U8 | descriptor type | 65 * | 2 | payload | | descriptor's payload | 66 */ 67 68 struct usb_functionfs_strings_head { 69 __le32 magic; 70 __le32 length; 71 __le32 str_count; 72 __le32 lang_count; 73 } __attribute__((packed)); 74 75 /* 76 * Strings format: 77 * 78 * | off | name | type | description | 79 * |-----+------------+-----------------------+----------------------------| 80 * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC | 81 * | 4 | length | LE32 | length of the data chunk | 82 * | 8 | str_count | LE32 | number of strings | 83 * | 12 | lang_count | LE32 | number of languages | 84 * | 16 | stringtab | StringTab[lang_count] | table of strings per lang | 85 * 86 * For each language there is one stringtab entry (ie. there are lang_count 87 * stringtab entires). Each StringTab has following format: 88 * 89 * | off | name | type | description | 90 * |-----+---------+-------------------+------------------------------------| 91 * | 0 | lang | LE16 | language code | 92 * | 2 | strings | String[str_count] | array of strings in given language | 93 * 94 * For each string there is one strings entry (ie. there are str_count 95 * string entries). Each String is a NUL terminated string encoded in 96 * UTF-8. 97 */ 98 99 #endif 100 101 102 /* 103 * Events are delivered on the ep0 file descriptor, when the user mode driver 104 * reads from this file descriptor after writing the descriptors. Don't 105 * stop polling this descriptor. 106 */ 107 108 enum usb_functionfs_event_type { 109 FUNCTIONFS_BIND, 110 FUNCTIONFS_UNBIND, 111 112 FUNCTIONFS_ENABLE, 113 FUNCTIONFS_DISABLE, 114 115 FUNCTIONFS_SETUP, 116 117 FUNCTIONFS_SUSPEND, 118 FUNCTIONFS_RESUME 119 }; 120 121 /* NOTE: this structure must stay the same size and layout on 122 * both 32-bit and 64-bit kernels. 123 */ 124 struct usb_functionfs_event { 125 union { 126 /* SETUP: packet; DATA phase i/o precedes next event 127 *(setup.bmRequestType & USB_DIR_IN) flags direction */ 128 struct usb_ctrlrequest setup; 129 } __attribute__((packed)) u; 130 131 /* enum usb_functionfs_event_type */ 132 __u8 type; 133 __u8 _pad[3]; 134 } __attribute__((packed)); 135 136 137 /* Endpoint ioctls */ 138 /* The same as in gadgetfs */ 139 140 /* IN transfers may be reported to the gadget driver as complete 141 * when the fifo is loaded, before the host reads the data; 142 * OUT transfers may be reported to the host's "client" driver as 143 * complete when they're sitting in the FIFO unread. 144 * THIS returns how many bytes are "unclaimed" in the endpoint fifo 145 * (needed for precise fault handling, when the hardware allows it) 146 */ 147 #define FUNCTIONFS_FIFO_STATUS _IO('g', 1) 148 149 /* discards any unclaimed data in the fifo. */ 150 #define FUNCTIONFS_FIFO_FLUSH _IO('g', 2) 151 152 /* resets endpoint halt+toggle; used to implement set_interface. 153 * some hardware (like pxa2xx) can't support this. 154 */ 155 #define FUNCTIONFS_CLEAR_HALT _IO('g', 3) 156 157 /* Specific for functionfs */ 158 159 /* 160 * Returns reverse mapping of an interface. Called on EP0. If there 161 * is no such interface returns -EDOM. If function is not active 162 * returns -ENODEV. 163 */ 164 #define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128) 165 166 /* 167 * Returns real bEndpointAddress of an endpoint. If function is not 168 * active returns -ENODEV. 169 */ 170 #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129) 171 172 173 174 #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */ 175