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