]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h
MdeModulePkg/Usb: Boost the r/w performance by reducing stall time on polling cmd...
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusPei / UsbPeim.h
CommitLineData
4b1bf81c 1/** @file\r
2Usb Peim definition.\r
3\r
ca243131 4Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved. <BR>\r
4b1bf81c 5 \r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions\r
8of the BSD License which accompanies this distribution. The\r
9full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#ifndef _PEI_USB_PEIM_H_\r
18#define _PEI_USB_PEIM_H_\r
19\r
20\r
21#include <PiPei.h>\r
22\r
23#include <Ppi/UsbHostController.h>\r
24#include <Ppi/Usb2HostController.h>\r
25#include <Ppi/UsbIo.h>\r
26\r
27#include <Library/DebugLib.h>\r
28#include <Library/PeimEntryPoint.h>\r
29#include <Library/PeiServicesLib.h>\r
30#include <Library/BaseMemoryLib.h>\r
31#include <Library/TimerLib.h>\r
32#include <Library/PcdLib.h>\r
33\r
34#include <IndustryStandard/Usb.h>\r
35\r
36#define MAX_ROOT_PORT 2\r
37#define MAX_ENDPOINT 16\r
38\r
39#define USB_SLOW_SPEED_DEVICE 0x01\r
40#define USB_FULL_SPEED_DEVICE 0x02\r
41\r
42#define PEI_USB_DEVICE_SIGNATURE SIGNATURE_32 ('U', 's', 'b', 'D')\r
43typedef struct {\r
44 UINTN Signature;\r
45 PEI_USB_IO_PPI UsbIoPpi;\r
46 EFI_PEI_PPI_DESCRIPTOR UsbIoPpiList;\r
47 UINT8 DeviceAddress;\r
48 UINT8 MaxPacketSize0;\r
49 UINT8 DeviceSpeed;\r
50 UINT8 DataToggle;\r
51 UINT8 IsHub;\r
52 UINT8 DownStreamPortNo;\r
53 UINT8 Reserved[2]; // Padding for IPF\r
54 UINTN AllocateAddress;\r
55 PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi;\r
56 PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi;\r
57 UINT8 ConfigurationData[1024];\r
58 EFI_USB_CONFIG_DESCRIPTOR *ConfigDesc;\r
59 EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDesc;\r
60 EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDesc[MAX_ENDPOINT];\r
61 EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator; \r
62} PEI_USB_DEVICE;\r
63\r
64#define PEI_USB_DEVICE_FROM_THIS(a) CR (a, PEI_USB_DEVICE, UsbIoPpi, PEI_USB_DEVICE_SIGNATURE)\r
65\r
66\r
67/**\r
68 Submits control transfer to a target USB device.\r
69 \r
70 @param PeiServices The pointer of EFI_PEI_SERVICES.\r
71 @param This The pointer of PEI_USB_IO_PPI.\r
72 @param Request USB device request to send.\r
73 @param Direction Specifies the data direction for the data stage.\r
ca243131
FT
74 @param Timeout Indicates the maximum timeout, in millisecond. If Timeout\r
75 is 0, then the caller must wait for the function to be\r
76 completed until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.\r
4b1bf81c 77 @param Data Data buffer to be transmitted or received from USB device.\r
78 @param DataLength The size (in bytes) of the data buffer.\r
79\r
80 @retval EFI_SUCCESS Transfer was completed successfully.\r
81 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources.\r
82 @retval EFI_INVALID_PARAMETER Some parameters are invalid.\r
83 @retval EFI_TIMEOUT Transfer failed due to timeout.\r
84 @retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error.\r
85\r
86**/\r
87EFI_STATUS\r
88EFIAPI\r
89PeiUsbControlTransfer (\r
90 IN EFI_PEI_SERVICES **PeiServices,\r
91 IN PEI_USB_IO_PPI *This,\r
92 IN EFI_USB_DEVICE_REQUEST *Request,\r
93 IN EFI_USB_DATA_DIRECTION Direction,\r
94 IN UINT32 Timeout,\r
95 IN OUT VOID *Data, OPTIONAL\r
96 IN UINTN DataLength OPTIONAL\r
97 );\r
98\r
99/**\r
100 Submits bulk transfer to a bulk endpoint of a USB device.\r
101 \r
102 @param PeiServices The pointer of EFI_PEI_SERVICES.\r
103 @param This The pointer of PEI_USB_IO_PPI.\r
104 @param DeviceEndpoint Endpoint number and its direction in bit 7.\r
105 @param Data A pointer to the buffer of data to transmit \r
106 from or receive into.\r
107 @param DataLength The lenght of the data buffer.\r
108 @param Timeout Indicates the maximum time, in millisecond, which the\r
ca243131
FT
109 transfer is allowed to complete. If Timeout is 0, then\r
110 the caller must wait for the function to be completed\r
111 until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.\r
4b1bf81c 112\r
113 @retval EFI_SUCCESS The transfer was completed successfully.\r
114 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.\r
115 @retval EFI_INVALID_PARAMETER Parameters are invalid.\r
116 @retval EFI_TIMEOUT The transfer failed due to timeout.\r
117 @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.\r
118\r
119**/\r
120EFI_STATUS\r
121EFIAPI\r
122PeiUsbBulkTransfer (\r
123 IN EFI_PEI_SERVICES **PeiServices,\r
124 IN PEI_USB_IO_PPI *This,\r
125 IN UINT8 DeviceEndpoint,\r
126 IN OUT VOID *Data,\r
127 IN OUT UINTN *DataLength,\r
128 IN UINTN Timeout\r
129 );\r
130\r
131/**\r
132 Get the usb interface descriptor.\r
133\r
134 @param PeiServices General-purpose services that are available to every PEIM.\r
135 @param This Indicates the PEI_USB_IO_PPI instance.\r
136 @param InterfaceDescriptor Request interface descriptor.\r
137\r
138\r
139 @retval EFI_SUCCESS Usb interface descriptor is obtained successfully.\r
140\r
141**/\r
142EFI_STATUS\r
143EFIAPI\r
144PeiUsbGetInterfaceDescriptor (\r
145 IN EFI_PEI_SERVICES **PeiServices,\r
146 IN PEI_USB_IO_PPI *This,\r
147 OUT EFI_USB_INTERFACE_DESCRIPTOR **InterfaceDescriptor\r
148 );\r
149\r
150/**\r
151 Get the usb endpoint descriptor.\r
152\r
153 @param PeiServices General-purpose services that are available to every PEIM.\r
154 @param This Indicates the PEI_USB_IO_PPI instance.\r
155 @param EndpointIndex The valid index of the specified endpoint.\r
156 @param EndpointDescriptor Request endpoint descriptor.\r
157\r
158 @retval EFI_SUCCESS Usb endpoint descriptor is obtained successfully.\r
159 @retval EFI_NOT_FOUND Usb endpoint descriptor is NOT found.\r
160\r
161**/\r
162EFI_STATUS\r
163EFIAPI\r
164PeiUsbGetEndpointDescriptor (\r
165 IN EFI_PEI_SERVICES **PeiServices,\r
166 IN PEI_USB_IO_PPI *This,\r
167 IN UINT8 EndpointIndex,\r
168 OUT EFI_USB_ENDPOINT_DESCRIPTOR **EndpointDescriptor\r
169 );\r
170\r
171/**\r
172 Reset the port and re-configure the usb device.\r
173\r
174 @param PeiServices General-purpose services that are available to every PEIM.\r
175 @param This Indicates the PEI_USB_IO_PPI instance.\r
176\r
177 @retval EFI_SUCCESS Usb device is reset and configured successfully.\r
178 @retval Others Other failure occurs.\r
179\r
180**/\r
181EFI_STATUS\r
182EFIAPI\r
183PeiUsbPortReset (\r
184 IN EFI_PEI_SERVICES **PeiServices,\r
185 IN PEI_USB_IO_PPI *This\r
186 );\r
187\r
188/**\r
189 Send reset signal over the given root hub port.\r
190 \r
191 @param PeiServices Describes the list of possible PEI Services.\r
192 @param UsbHcPpi The pointer of PEI_USB_HOST_CONTROLLER_PPI instance.\r
193 @param Usb2HcPpi The pointer of PEI_USB2_HOST_CONTROLLER_PPI instance.\r
194 @param PortNum The port to be reset.\r
195 @param RetryIndex The retry times.\r
196\r
197**/\r
198VOID\r
199ResetRootPort (\r
200 IN EFI_PEI_SERVICES **PeiServices,\r
201 IN PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi,\r
202 IN PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi,\r
203 IN UINT8 PortNum,\r
204 IN UINT8 RetryIndex\r
205 );\r
206\r
207#endif\r