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