]>
Commit | Line | Data |
---|---|---|
e237e7ae | 1 | /** @file\r |
2 | \r | |
8616fc4c | 3 | Manage Usb Descriptor List\r |
4 | \r | |
43629612 | 5 | Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e237e7ae | 7 | \r |
e237e7ae | 8 | **/\r |
9 | \r | |
10 | #ifndef _USB_DESCRIPTOR_H_\r | |
11 | #define _USB_DESCRIPTOR_H_\r | |
12 | \r | |
43629612 | 13 | #define USB_MAX_INTERFACE_SETTING 256\r |
e237e7ae | 14 | \r |
15 | //\r | |
16 | // The RequestType in EFI_USB_DEVICE_REQUEST is composed of\r | |
17 | // three fields: One bit direction, 2 bit type, and 5 bit\r | |
18 | // target.\r | |
19 | //\r | |
20 | #define USB_REQUEST_TYPE(Dir, Type, Target) \\r | |
21 | ((UINT8)((((Dir) == EfiUsbDataIn ? 0x01 : 0) << 7) | (Type) | (Target)))\r | |
22 | \r | |
23 | //\r | |
24 | // A common header for usb standard descriptor.\r | |
25 | // Each stand descriptor has a length and type.\r | |
26 | //\r | |
27 | #pragma pack(1)\r | |
28 | typedef struct {\r | |
1436aea4 MK |
29 | UINT8 Len;\r |
30 | UINT8 Type;\r | |
e237e7ae | 31 | } USB_DESC_HEAD;\r |
32 | #pragma pack()\r | |
33 | \r | |
e237e7ae | 34 | //\r |
35 | // Each USB device has a device descriptor. Each device may\r | |
36 | // have several configures. Each configure contains several\r | |
37 | // interfaces. Each interface may have several settings. Each\r | |
38 | // setting has several endpoints.\r | |
39 | //\r | |
40 | // EFI_USB_..._DESCRIPTOR must be the first member of the\r | |
41 | // structure.\r | |
42 | //\r | |
43 | typedef struct {\r | |
1436aea4 MK |
44 | EFI_USB_ENDPOINT_DESCRIPTOR Desc;\r |
45 | UINT8 Toggle;\r | |
e237e7ae | 46 | } USB_ENDPOINT_DESC;\r |
47 | \r | |
48 | typedef struct {\r | |
1436aea4 MK |
49 | EFI_USB_INTERFACE_DESCRIPTOR Desc;\r |
50 | USB_ENDPOINT_DESC **Endpoints;\r | |
e237e7ae | 51 | } USB_INTERFACE_SETTING;\r |
52 | \r | |
53 | //\r | |
54 | // An interface may have several settings. Use a\r | |
55 | // fixed max number of settings to simplify code.\r | |
56 | // It should sufice in most environments.\r | |
57 | //\r | |
58 | typedef struct {\r | |
1436aea4 MK |
59 | USB_INTERFACE_SETTING *Settings[USB_MAX_INTERFACE_SETTING];\r |
60 | UINTN NumOfSetting;\r | |
61 | UINTN ActiveIndex; // Index of active setting\r | |
e237e7ae | 62 | } USB_INTERFACE_DESC;\r |
63 | \r | |
64 | typedef struct {\r | |
1436aea4 MK |
65 | EFI_USB_CONFIG_DESCRIPTOR Desc;\r |
66 | USB_INTERFACE_DESC **Interfaces;\r | |
e237e7ae | 67 | } USB_CONFIG_DESC;\r |
68 | \r | |
69 | typedef struct {\r | |
1436aea4 MK |
70 | EFI_USB_DEVICE_DESCRIPTOR Desc;\r |
71 | USB_CONFIG_DESC **Configs;\r | |
e237e7ae | 72 | } USB_DEVICE_DESC;\r |
73 | \r | |
8616fc4c | 74 | /**\r |
75 | USB standard control transfer support routine. This\r | |
76 | function is used by USB device. It is possible that\r | |
77 | the device's interfaces are still waiting to be\r | |
78 | enumerated.\r | |
79 | \r | |
80 | @param UsbDev The usb device.\r | |
81 | @param Direction The direction of data transfer.\r | |
82 | @param Type Standard / class specific / vendor specific.\r | |
83 | @param Target The receiving target.\r | |
84 | @param Request Which request.\r | |
85 | @param Value The wValue parameter of the request.\r | |
86 | @param Index The wIndex parameter of the request.\r | |
87 | @param Buf The buffer to receive data into / transmit from.\r | |
88 | @param Length The length of the buffer.\r | |
89 | \r | |
90 | @retval EFI_SUCCESS The control request is executed.\r | |
91 | @retval EFI_DEVICE_ERROR Failed to execute the control transfer.\r | |
92 | \r | |
93 | **/\r | |
e237e7ae | 94 | EFI_STATUS\r |
95 | UsbCtrlRequest (\r | |
1436aea4 MK |
96 | IN USB_DEVICE *UsbDev,\r |
97 | IN EFI_USB_DATA_DIRECTION Direction,\r | |
98 | IN UINTN Type,\r | |
99 | IN UINTN Target,\r | |
100 | IN UINTN Request,\r | |
101 | IN UINT16 Value,\r | |
102 | IN UINT16 Index,\r | |
103 | IN OUT VOID *Buf,\r | |
104 | IN UINTN Length\r | |
e237e7ae | 105 | );\r |
106 | \r | |
8616fc4c | 107 | /**\r |
108 | Return the max packet size for endpoint zero. This function\r | |
109 | is the first function called to get descriptors during bus\r | |
110 | enumeration.\r | |
111 | \r | |
112 | @param UsbDev The usb device.\r | |
113 | \r | |
114 | @retval EFI_SUCCESS The max packet size of endpoint zero is retrieved.\r | |
115 | @retval EFI_DEVICE_ERROR Failed to retrieve it.\r | |
116 | \r | |
117 | **/\r | |
e237e7ae | 118 | EFI_STATUS\r |
119 | UsbGetMaxPacketSize0 (\r | |
1436aea4 | 120 | IN USB_DEVICE *UsbDev\r |
e237e7ae | 121 | );\r |
122 | \r | |
8616fc4c | 123 | /**\r |
124 | Free a device descriptor with its configurations.\r | |
125 | \r | |
126 | @param DevDesc The device descriptor.\r | |
127 | \r | |
128 | @return None.\r | |
129 | \r | |
130 | **/\r | |
e237e7ae | 131 | VOID\r |
132 | UsbFreeDevDesc (\r | |
1436aea4 | 133 | IN USB_DEVICE_DESC *DevDesc\r |
e237e7ae | 134 | );\r |
135 | \r | |
8616fc4c | 136 | /**\r |
137 | Retrieve the indexed string for the language. It requires two\r | |
138 | steps to get a string, first to get the string's length. Then\r | |
139 | the string itself.\r | |
140 | \r | |
141 | @param UsbDev The usb device.\r | |
142 | @param StringIndex The index of the string to retrieve.\r | |
143 | @param LangId Language ID.\r | |
144 | \r | |
145 | @return The created string descriptor or NULL.\r | |
146 | \r | |
147 | **/\r | |
1436aea4 | 148 | EFI_USB_STRING_DESCRIPTOR *\r |
e237e7ae | 149 | UsbGetOneString (\r |
1436aea4 MK |
150 | IN USB_DEVICE *UsbDev,\r |
151 | IN UINT8 StringIndex,\r | |
152 | IN UINT16 LangId\r | |
e237e7ae | 153 | );\r |
154 | \r | |
8616fc4c | 155 | /**\r |
156 | Build the whole array of descriptors. This function must\r | |
157 | be called after UsbGetMaxPacketSize0 returns the max packet\r | |
158 | size correctly for endpoint 0.\r | |
159 | \r | |
160 | @param UsbDev The Usb device.\r | |
161 | \r | |
162 | @retval EFI_SUCCESS The descriptor table is build.\r | |
163 | @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the descriptor.\r | |
164 | \r | |
165 | **/\r | |
e237e7ae | 166 | EFI_STATUS\r |
167 | UsbBuildDescTable (\r | |
1436aea4 | 168 | IN USB_DEVICE *UsbDev\r |
e237e7ae | 169 | );\r |
170 | \r | |
8616fc4c | 171 | /**\r |
172 | Set the device's address.\r | |
173 | \r | |
174 | @param UsbDev The device to set address to.\r | |
175 | @param Address The address to set.\r | |
176 | \r | |
177 | @retval EFI_SUCCESS The device is set to the address.\r | |
178 | @retval Others Failed to set the device address.\r | |
179 | \r | |
180 | **/\r | |
e237e7ae | 181 | EFI_STATUS\r |
182 | UsbSetAddress (\r | |
1436aea4 MK |
183 | IN USB_DEVICE *UsbDev,\r |
184 | IN UINT8 Address\r | |
e237e7ae | 185 | );\r |
186 | \r | |
8616fc4c | 187 | /**\r |
188 | Set the device's configuration. This function changes\r | |
189 | the device's internal state. UsbSelectConfig changes\r | |
190 | the Usb bus's internal state.\r | |
191 | \r | |
192 | @param UsbDev The USB device to set configure to.\r | |
193 | @param ConfigIndex The configure index to set.\r | |
194 | \r | |
195 | @retval EFI_SUCCESS The device is configured now.\r | |
196 | @retval Others Failed to set the device configure.\r | |
197 | \r | |
198 | **/\r | |
e237e7ae | 199 | EFI_STATUS\r |
200 | UsbSetConfig (\r | |
1436aea4 MK |
201 | IN USB_DEVICE *UsbDev,\r |
202 | IN UINT8 ConfigIndex\r | |
e237e7ae | 203 | );\r |
204 | \r | |
8616fc4c | 205 | /**\r |
206 | Usb UsbIo interface to clear the feature. This is should\r | |
207 | only be used by HUB which is considered a device driver\r | |
208 | on top of the UsbIo interface.\r | |
209 | \r | |
210 | @param UsbIo The UsbIo interface.\r | |
211 | @param Target The target of the transfer: endpoint/device.\r | |
212 | @param Feature The feature to clear.\r | |
213 | @param Index The wIndex parameter.\r | |
214 | \r | |
215 | @retval EFI_SUCCESS The device feature is cleared.\r | |
216 | @retval Others Failed to clear the feature.\r | |
217 | \r | |
218 | **/\r | |
e237e7ae | 219 | EFI_STATUS\r |
220 | UsbIoClearFeature (\r | |
1436aea4 MK |
221 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r |
222 | IN UINTN Target,\r | |
223 | IN UINT16 Feature,\r | |
224 | IN UINT16 Index\r | |
e237e7ae | 225 | );\r |
1436aea4 | 226 | \r |
e237e7ae | 227 | #endif\r |