TianoCore EDK2 master
Loading...
Searching...
No Matches
UsbIoPeim.c
Go to the documentation of this file.
1
10#include "UsbPeim.h"
11#include "PeiUsbLib.h"
12
34EFIAPI
36 IN EFI_PEI_SERVICES **PeiServices,
37 IN PEI_USB_IO_PPI *This,
39 IN EFI_USB_DATA_DIRECTION Direction,
40 IN UINT32 Timeout,
41 IN OUT VOID *Data OPTIONAL,
42 IN UINTN DataLength OPTIONAL
43 )
44{
45 EFI_STATUS Status;
46 PEI_USB_DEVICE *PeiUsbDev;
47 UINT32 TransferResult;
48 EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescriptor;
49 UINT8 EndpointIndex;
50
51 PeiUsbDev = PEI_USB_DEVICE_FROM_THIS (This);
52
53 EndpointDescriptor = NULL;
54 EndpointIndex = 0;
55
56 if ((Request->Request == USB_REQ_CLEAR_FEATURE) &&
57 (Request->RequestType == USB_DEV_CLEAR_FEATURE_REQ_TYPE_E) &&
58 (Request->Value == USB_FEATURE_ENDPOINT_HALT))
59 {
60 //
61 // Request->Index is the Endpoint Address, use it to get the Endpoint Index.
62 //
63 while (EndpointIndex < MAX_ENDPOINT) {
64 Status = PeiUsbGetEndpointDescriptor (PeiServices, This, EndpointIndex, &EndpointDescriptor);
65 if (EFI_ERROR (Status)) {
66 return EFI_INVALID_PARAMETER;
67 }
68
69 if (EndpointDescriptor->EndpointAddress == Request->Index) {
70 break;
71 }
72
73 EndpointIndex++;
74 }
75
76 if (EndpointIndex == MAX_ENDPOINT) {
77 return EFI_INVALID_PARAMETER;
78 }
79 }
80
81 if (PeiUsbDev->Usb2HcPpi != NULL) {
82 Status = PeiUsbDev->Usb2HcPpi->ControlTransfer (
83 PeiServices,
84 PeiUsbDev->Usb2HcPpi,
85 PeiUsbDev->DeviceAddress,
86 PeiUsbDev->DeviceSpeed,
87 PeiUsbDev->MaxPacketSize0,
88 Request,
89 Direction,
90 Data,
91 &DataLength,
92 Timeout,
93 &(PeiUsbDev->Translator),
94 &TransferResult
95 );
96 } else {
97 Status = PeiUsbDev->UsbHcPpi->ControlTransfer (
98 PeiServices,
99 PeiUsbDev->UsbHcPpi,
100 PeiUsbDev->DeviceAddress,
101 PeiUsbDev->DeviceSpeed,
102 (UINT8)PeiUsbDev->MaxPacketSize0,
103 Request,
104 Direction,
105 Data,
106 &DataLength,
107 Timeout,
108 &TransferResult
109 );
110 }
111
112 //
113 // Reset the endpoint toggle when endpoint stall is cleared
114 //
115 if ((Request->Request == USB_REQ_CLEAR_FEATURE) &&
116 (Request->RequestType == USB_DEV_CLEAR_FEATURE_REQ_TYPE_E) &&
117 (Request->Value == USB_FEATURE_ENDPOINT_HALT))
118 {
119 if ((PeiUsbDev->DataToggle & (1 << EndpointIndex)) != 0) {
120 PeiUsbDev->DataToggle = (UINT16)(PeiUsbDev->DataToggle ^ (1 << EndpointIndex));
121 }
122 }
123
124 DEBUG ((DEBUG_INFO, "PeiUsbControlTransfer: %r\n", Status));
125 return Status;
126}
127
150EFIAPI
152 IN EFI_PEI_SERVICES **PeiServices,
153 IN PEI_USB_IO_PPI *This,
154 IN UINT8 DeviceEndpoint,
155 IN OUT VOID *Data,
156 IN OUT UINTN *DataLength,
157 IN UINTN Timeout
158 )
159{
160 EFI_STATUS Status;
161 PEI_USB_DEVICE *PeiUsbDev;
162 UINT32 TransferResult;
163 UINTN MaxPacketLength;
164 UINT8 DataToggle;
165 UINT8 OldToggle;
166 EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescriptor;
167 UINT8 EndpointIndex;
168 VOID *Data2[EFI_USB_MAX_BULK_BUFFER_NUM];
169
170 PeiUsbDev = PEI_USB_DEVICE_FROM_THIS (This);
171
172 EndpointDescriptor = NULL;
173 EndpointIndex = 0;
174 Data2[0] = Data;
175 Data2[1] = NULL;
176
177 while (EndpointIndex < MAX_ENDPOINT) {
178 Status = PeiUsbGetEndpointDescriptor (PeiServices, This, EndpointIndex, &EndpointDescriptor);
179 if (EFI_ERROR (Status)) {
180 return EFI_INVALID_PARAMETER;
181 }
182
183 if (EndpointDescriptor->EndpointAddress == DeviceEndpoint) {
184 break;
185 }
186
187 EndpointIndex++;
188 }
189
190 if (EndpointIndex == MAX_ENDPOINT) {
191 return EFI_INVALID_PARAMETER;
192 }
193
194 MaxPacketLength = PeiUsbDev->EndpointDesc[EndpointIndex]->MaxPacketSize;
195 if ((PeiUsbDev->DataToggle & (1 << EndpointIndex)) != 0) {
196 DataToggle = 1;
197 } else {
198 DataToggle = 0;
199 }
200
201 OldToggle = DataToggle;
202
203 if (PeiUsbDev->Usb2HcPpi != NULL) {
204 Status = PeiUsbDev->Usb2HcPpi->BulkTransfer (
205 PeiServices,
206 PeiUsbDev->Usb2HcPpi,
207 PeiUsbDev->DeviceAddress,
208 DeviceEndpoint,
209 PeiUsbDev->DeviceSpeed,
210 MaxPacketLength,
211 Data2,
212 DataLength,
213 &DataToggle,
214 Timeout,
215 &(PeiUsbDev->Translator),
216 &TransferResult
217 );
218 } else {
219 Status = PeiUsbDev->UsbHcPpi->BulkTransfer (
220 PeiServices,
221 PeiUsbDev->UsbHcPpi,
222 PeiUsbDev->DeviceAddress,
223 DeviceEndpoint,
224 (UINT8)MaxPacketLength,
225 Data,
226 DataLength,
227 &DataToggle,
228 Timeout,
229 &TransferResult
230 );
231 }
232
233 if (OldToggle != DataToggle) {
234 PeiUsbDev->DataToggle = (UINT16)(PeiUsbDev->DataToggle ^ (1 << EndpointIndex));
235 }
236
237 DEBUG ((DEBUG_INFO, "PeiUsbBulkTransfer: %r\n", Status));
238 return Status;
239}
240
253EFIAPI
255 IN EFI_PEI_SERVICES **PeiServices,
256 IN PEI_USB_IO_PPI *This,
257 OUT EFI_USB_INTERFACE_DESCRIPTOR **InterfaceDescriptor
258 )
259{
260 PEI_USB_DEVICE *PeiUsbDev;
261
262 PeiUsbDev = PEI_USB_DEVICE_FROM_THIS (This);
263 *InterfaceDescriptor = PeiUsbDev->InterfaceDesc;
264 return EFI_SUCCESS;
265}
266
280EFIAPI
282 IN EFI_PEI_SERVICES **PeiServices,
283 IN PEI_USB_IO_PPI *This,
284 IN UINT8 EndpointIndex,
285 OUT EFI_USB_ENDPOINT_DESCRIPTOR **EndpointDescriptor
286 )
287{
288 PEI_USB_DEVICE *PeiUsbDev;
289
290 PeiUsbDev = PEI_USB_DEVICE_FROM_THIS (This);
291
292 ASSERT (EndpointDescriptor != NULL);
293
294 //
295 // The valid range of EndpointIndex is 0..15
296 // If EndpointIndex is lesser than 15 but larger than the number of interfaces,
297 // a EFI_NOT_FOUND should be returned
298 //
299 ASSERT (EndpointIndex <= 15);
300
301 if (EndpointIndex >= PeiUsbDev->InterfaceDesc->NumEndpoints) {
302 return EFI_NOT_FOUND;
303 }
304
305 *EndpointDescriptor = PeiUsbDev->EndpointDesc[EndpointIndex];
306
307 return EFI_SUCCESS;
308}
309
321EFIAPI
323 IN EFI_PEI_SERVICES **PeiServices,
324 IN PEI_USB_IO_PPI *This
325 )
326{
327 PEI_USB_DEVICE *PeiUsbDev;
328 EFI_STATUS Status;
329 UINT8 Address;
330
331 PeiUsbDev = PEI_USB_DEVICE_FROM_THIS (This);
332
334 PeiServices,
335 PeiUsbDev->UsbHcPpi,
336 PeiUsbDev->Usb2HcPpi,
337 PeiUsbDev->DeviceAddress,
338 0
339 );
340
341 //
342 // Set address
343 //
344 Address = PeiUsbDev->DeviceAddress;
345 PeiUsbDev->DeviceAddress = 0;
346
347 Status = PeiUsbSetDeviceAddress (
348 PeiServices,
349 This,
350 Address
351 );
352
353 if (EFI_ERROR (Status)) {
354 return Status;
355 }
356
357 PeiUsbDev->DeviceAddress = Address;
358
359 //
360 // Set default configuration
361 //
362 Status = PeiUsbSetConfiguration (
363 PeiServices,
364 This
365 );
366
367 return Status;
368}
UINT64 UINTN
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_USB_DATA_DIRECTION
Definition: UsbIo.h:44
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS PeiUsbSetDeviceAddress(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *UsbIoPpi, IN UINT16 AddressValue)
Definition: PeiUsbLib.c:73
EFI_STATUS PeiUsbSetConfiguration(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *UsbIoPpi)
Definition: PeiUsbLib.c:112
EFI_STATUS EFIAPI PeiUsbBulkTransfer(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *This, IN UINT8 DeviceEndpoint, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN UINTN Timeout)
Definition: UsbIoPeim.c:151
EFI_STATUS EFIAPI PeiUsbGetInterfaceDescriptor(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *This, OUT EFI_USB_INTERFACE_DESCRIPTOR **InterfaceDescriptor)
Definition: UsbIoPeim.c:254
EFI_STATUS EFIAPI PeiUsbControlTransfer(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *This, IN EFI_USB_DEVICE_REQUEST *Request, IN EFI_USB_DATA_DIRECTION Direction, IN UINT32 Timeout, IN OUT VOID *Data OPTIONAL, IN UINTN DataLength OPTIONAL)
Definition: UsbIoPeim.c:35
EFI_STATUS EFIAPI PeiUsbGetEndpointDescriptor(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *This, IN UINT8 EndpointIndex, OUT EFI_USB_ENDPOINT_DESCRIPTOR **EndpointDescriptor)
Definition: UsbIoPeim.c:281
EFI_STATUS EFIAPI PeiUsbPortReset(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *This)
Definition: UsbIoPeim.c:322
VOID ResetRootPort(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi, IN PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi, IN UINT8 PortNum, IN UINT8 RetryIndex)
Definition: UsbPeim.c:1033