TianoCore EDK2 master
Loading...
Searching...
No Matches
PeiUsbLib.c
Go to the documentation of this file.
1
10#include "UsbPeim.h"
11#include "PeiUsbLib.h"
12
31 IN EFI_PEI_SERVICES **PeiServices,
32 IN PEI_USB_IO_PPI *UsbIoPpi,
33 IN UINT16 Value,
34 IN UINT16 Index,
35 IN UINT16 DescriptorLength,
36 OUT VOID *Descriptor
37 )
38{
40
41 ASSERT (UsbIoPpi != NULL);
42
43 DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;
44 DevReq.Request = USB_DEV_GET_DESCRIPTOR;
45 DevReq.Value = Value;
46 DevReq.Index = Index;
47 DevReq.Length = DescriptorLength;
48
49 return UsbIoPpi->UsbControlTransfer (
50 PeiServices,
51 UsbIoPpi,
52 &DevReq,
53 EfiUsbDataIn,
54 PcdGet32 (PcdUsbTransferTimeoutValue),
55 Descriptor,
56 DescriptorLength
57 );
58}
59
74 IN EFI_PEI_SERVICES **PeiServices,
75 IN PEI_USB_IO_PPI *UsbIoPpi,
76 IN UINT16 AddressValue
77 )
78{
80
81 ASSERT (UsbIoPpi != NULL);
82
83 DevReq.RequestType = USB_DEV_SET_ADDRESS_REQ_TYPE;
84 DevReq.Request = USB_DEV_SET_ADDRESS;
85 DevReq.Value = AddressValue;
86 DevReq.Index = 0;
87 DevReq.Length = 0;
88
89 return UsbIoPpi->UsbControlTransfer (
90 PeiServices,
91 UsbIoPpi,
92 &DevReq,
93 EfiUsbNoData,
94 PcdGet32 (PcdUsbTransferTimeoutValue),
95 NULL,
96 0
97 );
98}
99
113 IN EFI_PEI_SERVICES **PeiServices,
114 IN PEI_USB_IO_PPI *UsbIoPpi
115 )
116{
118
119 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
120
121 DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;
122 DevReq.Request = USB_DEV_SET_CONFIGURATION;
123 DevReq.Value = 1;
124
125 return UsbIoPpi->UsbControlTransfer (
126 PeiServices,
127 UsbIoPpi,
128 &DevReq,
129 EfiUsbNoData,
130 PcdGet32 (PcdUsbTransferTimeoutValue),
131 NULL,
132 0
133 );
134}
135
145BOOLEAN
147 IN UINT16 PortStatus
148 )
149{
150 //
151 // return the bit 0 value of PortStatus
152 //
153 if ((PortStatus & USB_PORT_STAT_CONNECTION) != 0) {
154 return TRUE;
155 } else {
156 return FALSE;
157 }
158}
159
168UINTN
170 IN UINT16 PortStatus
171 )
172{
173 if ((PortStatus & USB_PORT_STAT_LOW_SPEED) != 0) {
174 return EFI_USB_SPEED_LOW;
175 } else if ((PortStatus & USB_PORT_STAT_HIGH_SPEED) != 0) {
176 return EFI_USB_SPEED_HIGH;
177 } else if ((PortStatus & USB_PORT_STAT_SUPER_SPEED) != 0) {
178 return EFI_USB_SPEED_SUPER;
179 } else {
180 return EFI_USB_SPEED_FULL;
181 }
182}
UINT64 UINTN
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define EFI_USB_SPEED_SUPER
4.8 Gb/s, USB 3.0 XHCI HC.
#define USB_PORT_STAT_CONNECTION
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_STATUS PeiUsbSetDeviceAddress(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *UsbIoPpi, IN UINT16 AddressValue)
Definition: PeiUsbLib.c:73
EFI_STATUS PeiUsbGetDescriptor(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *UsbIoPpi, IN UINT16 Value, IN UINT16 Index, IN UINT16 DescriptorLength, OUT VOID *Descriptor)
Definition: PeiUsbLib.c:30
UINTN PeiUsbGetDeviceSpeed(IN UINT16 PortStatus)
Definition: PeiUsbLib.c:169
EFI_STATUS PeiUsbSetConfiguration(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *UsbIoPpi)
Definition: PeiUsbLib.c:112
BOOLEAN IsPortConnect(IN UINT16 PortStatus)
Definition: PeiUsbLib.c:146