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