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