]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbBotPei/PeiUsbLib.c
dfc4e4069885fa3318076529851167ab759ebe75
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBotPei / PeiUsbLib.c
1 /** @file
2 Common Library for PEI USB.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "UsbPeim.h"
11 #include "PeiUsbLib.h"
12
13 /**
14 Clear a given usb feature.
15
16 @param PeiServices General-purpose services that are available to every PEIM.
17 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
18 @param Recipient The recipient of ClearFeature Request, should be one of Device/Interface/Endpoint.
19 @param Value Request Value.
20 @param Target Request Index.
21
22 @retval EFI_SUCCESS Usb feature is cleared successfully.
23 @retval EFI_DEVICE_ERROR Cannot clear the usb feature due to a hardware error.
24 @retval Others Other failure occurs.
25
26 **/
27 EFI_STATUS
28 PeiUsbClearDeviceFeature (
29 IN EFI_PEI_SERVICES **PeiServices,
30 IN PEI_USB_IO_PPI *UsbIoPpi,
31 IN EFI_USB_RECIPIENT Recipient,
32 IN UINT16 Value,
33 IN UINT16 Target
34 )
35 {
36 EFI_USB_DEVICE_REQUEST DevReq;
37
38 ASSERT (UsbIoPpi != NULL);
39
40 switch (Recipient) {
41 case EfiUsbDevice:
42 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_D;
43 break;
44
45 case EfiUsbInterface:
46 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_I;
47 break;
48
49 case EfiUsbEndpoint:
50 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_E;
51 break;
52 }
53
54 DevReq.Request = USB_DEV_CLEAR_FEATURE;
55 DevReq.Value = Value;
56 DevReq.Index = Target;
57 DevReq.Length = 0;
58
59 return UsbIoPpi->UsbControlTransfer (
60 PeiServices,
61 UsbIoPpi,
62 &DevReq,
63 EfiUsbNoData,
64 PcdGet32 (PcdUsbTransferTimeoutValue),
65 NULL,
66 0
67 );
68 }
69
70 /**
71 Clear Endpoint Halt.
72
73 @param PeiServices General-purpose services that are available to every PEIM.
74 @param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
75 @param EndpointAddress The endpoint address.
76
77 @retval EFI_SUCCESS Endpoint halt is cleared successfully.
78 @retval EFI_DEVICE_ERROR Cannot clear the endpoint halt status due to a hardware error.
79 @retval Others Other failure occurs.
80
81 **/
82 EFI_STATUS
83 PeiUsbClearEndpointHalt (
84 IN EFI_PEI_SERVICES **PeiServices,
85 IN PEI_USB_IO_PPI *UsbIoPpi,
86 IN UINT8 EndpointAddress
87 )
88 {
89 EFI_STATUS Status;
90 EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDesc;
91 EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescriptor;
92 UINT8 EndpointIndex;
93
94 //
95 // Check its interface
96 //
97 Status = UsbIoPpi->UsbGetInterfaceDescriptor (
98 PeiServices,
99 UsbIoPpi,
100 &InterfaceDesc
101 );
102 if (EFI_ERROR (Status)) {
103 return Status;
104 }
105
106 for (EndpointIndex = 0; EndpointIndex < InterfaceDesc->NumEndpoints; EndpointIndex++) {
107 Status = UsbIoPpi->UsbGetEndpointDescriptor (PeiServices, UsbIoPpi, EndpointIndex, &EndpointDescriptor);
108 if (EFI_ERROR (Status)) {
109 return EFI_INVALID_PARAMETER;
110 }
111
112 if (EndpointDescriptor->EndpointAddress == EndpointAddress) {
113 break;
114 }
115 }
116
117 if (EndpointIndex == InterfaceDesc->NumEndpoints) {
118 return EFI_INVALID_PARAMETER;
119 }
120
121 Status = PeiUsbClearDeviceFeature (
122 PeiServices,
123 UsbIoPpi,
124 EfiUsbEndpoint,
125 EfiUsbEndpointHalt,
126 EndpointAddress
127 );
128
129 return Status;
130 }