26 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
68 IN OUT UINT8 *DeviceAddress
147 &gPeiUsbHostControllerPpiGuid,
152 if (EFI_ERROR (Status)) {
169 &gPeiUsb2HostControllerPpiGuid,
174 if (EFI_ERROR (Status)) {
187 return EFI_UNSUPPORTED;
210 IN UINT8 *CurrentAddress
220 UINTN InterfaceIndex;
223 UsbIoPpi = &PeiUsbDevice->UsbIoPpi;
225 DEBUG ((DEBUG_INFO,
"PeiHubEnumeration: DownStreamPortNo: %x\n", PeiUsbDevice->DownStreamPortNo));
227 for (Index = 0; Index < PeiUsbDevice->DownStreamPortNo; Index++) {
232 (UINT32 *)&PortStatus
235 if (EFI_ERROR (Status)) {
239 DEBUG ((DEBUG_INFO,
"USB Status --- Port: %x ConnectChange[%04x] Status[%04x]\n", Index, PortStatus.PortChangeStatus, PortStatus.PortStatus));
243 if ((PortStatus.PortChangeStatus & (
USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | USB_PORT_STAT_C_OVERCURRENT | USB_PORT_STAT_C_RESET)) == 0) {
256 if (EFI_ERROR (Status)) {
257 return EFI_OUT_OF_RESOURCES;
263 NewPeiUsbDevice->Signature = PEI_USB_DEVICE_SIGNATURE;
264 NewPeiUsbDevice->DeviceAddress = 0;
265 NewPeiUsbDevice->MaxPacketSize0 = 8;
266 NewPeiUsbDevice->DataToggle = 0;
268 &(NewPeiUsbDevice->UsbIoPpi),
273 &(NewPeiUsbDevice->UsbIoPpiList),
277 NewPeiUsbDevice->UsbIoPpiList.
Ppi = &NewPeiUsbDevice->UsbIoPpi;
279 NewPeiUsbDevice->UsbHcPpi = PeiUsbDevice->UsbHcPpi;
280 NewPeiUsbDevice->Usb2HcPpi = PeiUsbDevice->Usb2HcPpi;
281 NewPeiUsbDevice->Tier = (UINT8)(PeiUsbDevice->Tier + 1);
282 NewPeiUsbDevice->IsHub = 0x0;
283 NewPeiUsbDevice->DownStreamPortNo = 0x0;
285 if (((PortStatus.PortChangeStatus & USB_PORT_STAT_C_RESET) == 0) ||
297 (UINT32 *)&PortStatus
304 EfiUsbPortResetChange
309 DEBUG ((DEBUG_INFO,
"Device Speed =%d\n", PeiUsbDevice->DeviceSpeed));
311 if (USB_BIT_IS_SET (PortStatus.PortStatus, USB_PORT_STAT_SUPER_SPEED)) {
312 NewPeiUsbDevice->MaxPacketSize0 = 512;
313 }
else if (USB_BIT_IS_SET (PortStatus.PortStatus, USB_PORT_STAT_HIGH_SPEED)) {
314 NewPeiUsbDevice->MaxPacketSize0 = 64;
315 }
else if (USB_BIT_IS_SET (PortStatus.PortStatus, USB_PORT_STAT_LOW_SPEED)) {
316 NewPeiUsbDevice->MaxPacketSize0 = 8;
318 NewPeiUsbDevice->MaxPacketSize0 = 8;
321 if (NewPeiUsbDevice->DeviceSpeed != EFI_USB_SPEED_HIGH) {
322 if (PeiUsbDevice->DeviceSpeed == EFI_USB_SPEED_HIGH) {
340 if (EFI_ERROR (Status)) {
344 DEBUG ((DEBUG_INFO,
"PeiHubEnumeration: PeiConfigureUsbDevice Success\n"));
348 if (NewPeiUsbDevice->InterfaceDesc->InterfaceClass == 0x09) {
349 NewPeiUsbDevice->IsHub = 0x1;
352 if (EFI_ERROR (Status)) {
359 for (InterfaceIndex = 1; InterfaceIndex < NewPeiUsbDevice->ConfigDesc->NumInterfaces; InterfaceIndex++) {
369 if (EFI_ERROR (Status)) {
370 return EFI_OUT_OF_RESOURCES;
376 NewPeiUsbDevice->UsbIoPpiList.
Ppi = &NewPeiUsbDevice->UsbIoPpi;
377 NewPeiUsbDevice->InterfaceDesc = NewPeiUsbDevice->InterfaceDescList[InterfaceIndex];
378 for (EndpointIndex = 0; EndpointIndex < NewPeiUsbDevice->InterfaceDesc->NumEndpoints; EndpointIndex++) {
379 NewPeiUsbDevice->EndpointDesc[EndpointIndex] = NewPeiUsbDevice->EndpointDescList[InterfaceIndex][EndpointIndex];
384 if (NewPeiUsbDevice->InterfaceDesc->InterfaceClass == 0x09) {
385 NewPeiUsbDevice->IsHub = 0x1;
388 if (EFI_ERROR (Status)) {
428 UINT8 CurrentAddress;
429 UINTN InterfaceIndex;
433 if (Usb2HcPpi !=
NULL) {
434 Usb2HcPpi->GetRootHubPortNumber (
437 (UINT8 *)&NumOfRootPort
439 }
else if (UsbHcPpi !=
NULL) {
440 UsbHcPpi->GetRootHubPortNumber (
443 (UINT8 *)&NumOfRootPort
447 return EFI_INVALID_PARAMETER;
450 DEBUG ((DEBUG_INFO,
"PeiUsbEnumeration: NumOfRootPort: %x\n", NumOfRootPort));
452 for (Index = 0; Index < NumOfRootPort; Index++) {
456 if (Usb2HcPpi !=
NULL) {
457 Usb2HcPpi->GetRootHubPortStatus (
464 UsbHcPpi->GetRootHubPortStatus (
486 if (EFI_ERROR (Status)) {
487 return EFI_OUT_OF_RESOURCES;
493 PeiUsbDevice->Signature = PEI_USB_DEVICE_SIGNATURE;
494 PeiUsbDevice->DeviceAddress = 0;
495 PeiUsbDevice->MaxPacketSize0 = 8;
496 PeiUsbDevice->DataToggle = 0;
498 &(PeiUsbDevice->UsbIoPpi),
503 &(PeiUsbDevice->UsbIoPpiList),
507 PeiUsbDevice->UsbIoPpiList.
Ppi = &PeiUsbDevice->UsbIoPpi;
509 PeiUsbDevice->UsbHcPpi = UsbHcPpi;
510 PeiUsbDevice->Usb2HcPpi = Usb2HcPpi;
511 PeiUsbDevice->IsHub = 0x0;
512 PeiUsbDevice->DownStreamPortNo = 0x0;
522 PeiUsbDevice->UsbHcPpi,
523 PeiUsbDevice->Usb2HcPpi,
528 if (Usb2HcPpi !=
NULL) {
529 Usb2HcPpi->GetRootHubPortStatus (
536 UsbHcPpi->GetRootHubPortStatus (
544 if (Usb2HcPpi !=
NULL) {
545 Usb2HcPpi->ClearRootHubPortFeature (
549 EfiUsbPortResetChange
552 UsbHcPpi->ClearRootHubPortFeature (
556 EfiUsbPortResetChange
562 DEBUG ((DEBUG_INFO,
"Device Speed =%d\n", PeiUsbDevice->DeviceSpeed));
564 if (USB_BIT_IS_SET (PortStatus.
PortStatus, USB_PORT_STAT_SUPER_SPEED)) {
565 PeiUsbDevice->MaxPacketSize0 = 512;
566 }
else if (USB_BIT_IS_SET (PortStatus.
PortStatus, USB_PORT_STAT_HIGH_SPEED)) {
567 PeiUsbDevice->MaxPacketSize0 = 64;
568 }
else if (USB_BIT_IS_SET (PortStatus.
PortStatus, USB_PORT_STAT_LOW_SPEED)) {
569 PeiUsbDevice->MaxPacketSize0 = 8;
571 PeiUsbDevice->MaxPacketSize0 = 8;
584 if (EFI_ERROR (Status)) {
588 DEBUG ((DEBUG_INFO,
"PeiUsbEnumeration: PeiConfigureUsbDevice Success\n"));
592 if (PeiUsbDevice->InterfaceDesc->InterfaceClass == 0x09) {
593 PeiUsbDevice->IsHub = 0x1;
596 if (EFI_ERROR (Status)) {
603 for (InterfaceIndex = 1; InterfaceIndex < PeiUsbDevice->ConfigDesc->NumInterfaces; InterfaceIndex++) {
613 if (EFI_ERROR (Status)) {
614 return EFI_OUT_OF_RESOURCES;
620 PeiUsbDevice->UsbIoPpiList.
Ppi = &PeiUsbDevice->UsbIoPpi;
621 PeiUsbDevice->InterfaceDesc = PeiUsbDevice->InterfaceDescList[InterfaceIndex];
622 for (EndpointIndex = 0; EndpointIndex < PeiUsbDevice->InterfaceDesc->NumEndpoints; EndpointIndex++) {
623 PeiUsbDevice->EndpointDesc[EndpointIndex] = PeiUsbDevice->EndpointDescList[InterfaceIndex][EndpointIndex];
628 if (PeiUsbDevice->InterfaceDesc->InterfaceClass == 0x09) {
629 PeiUsbDevice->IsHub = 0x1;
632 if (EFI_ERROR (Status)) {
668 IN OUT UINT8 *DeviceAddress
676 UsbIoPpi = &PeiUsbDevice->UsbIoPpi;
683 for (Retry = 0; Retry < 3; Retry++) {
687 (USB_DT_DEVICE << 8),
693 if (!EFI_ERROR (Status)) {
694 DEBUG ((DEBUG_INFO,
"PeiUsbGet Device Descriptor the %d time Success\n", Retry));
700 DEBUG ((DEBUG_ERROR,
"PeiUsbGet Device Descriptor fail: %x %r\n", Retry, Status));
704 if ((DeviceDescriptor.BcdUSB >= 0x0300) && (DeviceDescriptor.MaxPacketSize0 == 9)) {
705 PeiUsbDevice->MaxPacketSize0 = 1 << 9;
707 PeiUsbDevice->MaxPacketSize0 = DeviceDescriptor.MaxPacketSize0;
718 if (EFI_ERROR (Status)) {
719 DEBUG ((DEBUG_ERROR,
"PeiUsbSetDeviceAddress Failed: %r\n", Status));
725 PeiUsbDevice->DeviceAddress = *DeviceAddress;
733 (USB_DT_DEVICE << 8),
739 if (EFI_ERROR (Status)) {
740 DEBUG ((DEBUG_ERROR,
"PeiUsbGetDescriptor First Failed\n"));
751 if (EFI_ERROR (Status)) {
762 if (EFI_ERROR (Status)) {
789 UINT16 ConfigDescLength;
793 UINTN InterfaceIndex;
797 UsbIoPpi = &PeiUsbDevice->UsbIoPpi;
805 (USB_DT_CONFIG << 8),
808 PeiUsbDevice->ConfigurationData
811 if (EFI_ERROR (Status)) {
812 DEBUG ((DEBUG_ERROR,
"PeiUsbGet Config Descriptor First Failed\n"));
819 ConfigDescLength = ConfigDesc->TotalLength;
825 return EFI_DEVICE_ERROR;
831 if (ConfigDescLength >
sizeof (PeiUsbDevice->ConfigurationData)) {
832 return EFI_DEVICE_ERROR;
841 (USB_DT_CONFIG << 8),
844 PeiUsbDevice->ConfigurationData
847 if (EFI_ERROR (Status)) {
848 DEBUG ((DEBUG_ERROR,
"PeiUsbGet Config Descriptor all Failed\n"));
857 PeiUsbDevice->ConfigurationData,
864 if (EFI_ERROR (Status)) {
868 Ptr = PeiUsbDevice->ConfigurationData + SkipBytes;
874 for (InterfaceIndex = 0; InterfaceIndex < PeiUsbDevice->ConfigDesc->NumInterfaces; InterfaceIndex++) {
886 if (EFI_ERROR (Status)) {
891 if (InterfaceIndex == 0) {
898 LengthLeft -= SkipBytes;
904 NumOfEndpoint = PeiUsbDevice->InterfaceDescList[InterfaceIndex]->NumEndpoints;
905 ASSERT (NumOfEndpoint <= MAX_ENDPOINT);
907 for (Index = 0; Index < NumOfEndpoint; Index++) {
919 if (EFI_ERROR (Status)) {
924 if (InterfaceIndex == 0) {
931 LengthLeft -= SkipBytes;
968 DEBUG ((DEBUG_ERROR,
"GetExpectedDescriptor: met mal-format descriptor, total length = %d!\n", Length));
969 return EFI_DEVICE_ERROR;
984 if (Head->Len == 0) {
985 DEBUG ((DEBUG_ERROR,
"GetExpectedDescriptor: met mal-format descriptor, Head->Len = 0!\n"));
986 return EFI_DEVICE_ERROR;
992 if (Head->Len > MAX_UINTN - Offset) {
993 DEBUG ((DEBUG_ERROR,
"GetExpectedDescriptor: met mal-format descriptor, Head->Len = %d!\n", Head->Len));
994 return EFI_DEVICE_ERROR;
997 if (Head->Type == DescType) {
1001 Offset += Head->Len;
1008 if (Length < Offset) {
1009 DEBUG ((DEBUG_ERROR,
"GetExpectedDescriptor: met mal-format descriptor, Offset/Len = %d/%d!\n", Offset, Length));
1010 return EFI_DEVICE_ERROR;
1013 if ((Head->Type != DescType) || (Head->Len < DescLength)) {
1014 DEBUG ((DEBUG_ERROR,
"GetExpectedDescriptor: descriptor cannot be found, Header(T/L) = %d/%d!\n", Head->Type, Head->Len));
1015 return EFI_DEVICE_ERROR;
1018 *ParsedBytes = Offset;
1045 if (Usb2HcPpi !=
NULL) {
1051 Status = Usb2HcPpi->SetRootHubPortFeature (
1058 if (EFI_ERROR (Status)) {
1059 DEBUG ((DEBUG_ERROR,
"SetRootHubPortFeature EfiUsbPortReset Failed\n"));
1072 Status = Usb2HcPpi->ClearRootHubPortFeature (
1079 if (EFI_ERROR (Status)) {
1080 DEBUG ((DEBUG_ERROR,
"ClearRootHubPortFeature EfiUsbPortReset Failed\n"));
1092 for (Index = 0; Index < USB_WAIT_PORT_STS_CHANGE_LOOP; Index++) {
1093 Status = Usb2HcPpi->GetRootHubPortStatus (
1099 if (EFI_ERROR (Status)) {
1103 if (!USB_BIT_IS_SET (PortStatus.
PortStatus, USB_PORT_STAT_RESET)) {
1110 if (Index == USB_WAIT_PORT_STS_CHANGE_LOOP) {
1111 DEBUG ((DEBUG_ERROR,
"ResetRootPort: reset not finished in time on port %d\n", PortNum));
1115 Usb2HcPpi->ClearRootHubPortFeature (
1119 EfiUsbPortResetChange
1122 Usb2HcPpi->ClearRootHubPortFeature (
1126 EfiUsbPortConnectChange
1132 Usb2HcPpi->SetRootHubPortFeature (
1139 Usb2HcPpi->ClearRootHubPortFeature (
1143 EfiUsbPortEnableChange
1153 Status = UsbHcPpi->SetRootHubPortFeature (
1160 if (EFI_ERROR (Status)) {
1161 DEBUG ((DEBUG_ERROR,
"SetRootHubPortFeature EfiUsbPortReset Failed\n"));
1174 Status = UsbHcPpi->ClearRootHubPortFeature (
1181 if (EFI_ERROR (Status)) {
1182 DEBUG ((DEBUG_ERROR,
"ClearRootHubPortFeature EfiUsbPortReset Failed\n"));
1194 for (Index = 0; Index < USB_WAIT_PORT_STS_CHANGE_LOOP; Index++) {
1195 Status = UsbHcPpi->GetRootHubPortStatus (
1201 if (EFI_ERROR (Status)) {
1205 if (!USB_BIT_IS_SET (PortStatus.
PortStatus, USB_PORT_STAT_RESET)) {
1212 if (Index == USB_WAIT_PORT_STS_CHANGE_LOOP) {
1213 DEBUG ((DEBUG_ERROR,
"ResetRootPort: reset not finished in time on port %d\n", PortNum));
1217 UsbHcPpi->ClearRootHubPortFeature (
1221 EfiUsbPortResetChange
1224 UsbHcPpi->ClearRootHubPortFeature (
1228 EfiUsbPortConnectChange
1234 UsbHcPpi->SetRootHubPortFeature (
1241 UsbHcPpi->ClearRootHubPortFeature (
1245 EfiUsbPortEnableChange
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesAllocatePages(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages, OUT EFI_PHYSICAL_ADDRESS *Memory)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
EFI_STATUS EFIAPI PeiServicesRegisterForShadow(IN EFI_PEI_FILE_HANDLE FileHandle)
EFI_STATUS PeiHubClearPortFeature(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *UsbIoPpi, IN UINT8 Port, IN UINT8 Value)
EFI_STATUS PeiDoHubConfig(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_DEVICE *PeiUsbDevice)
VOID PeiResetHubPort(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *UsbIoPpi, IN UINT8 PortNum)
EFI_STATUS PeiHubGetPortStatus(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *UsbIoPpi, IN UINT8 Port, OUT UINT32 *PortStatus)
#define OFFSET_OF(TYPE, Field)
#define DEBUG(Expression)
#define USB_PORT_STAT_C_CONNECTION
#define USB_PORT_STAT_CONNECTION
VOID * EFI_PEI_FILE_HANDLE
UINT64 EFI_PHYSICAL_ADDRESS
EFI_STATUS PeiUsbSetDeviceAddress(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *UsbIoPpi, IN UINT16 AddressValue)
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)
UINTN PeiUsbGetDeviceSpeed(IN UINT16 PortStatus)
EFI_STATUS PeiUsbSetConfiguration(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *UsbIoPpi)
BOOLEAN IsPortConnect(IN UINT16 PortStatus)
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)
EFI_STATUS EFIAPI PeiUsbGetInterfaceDescriptor(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *This, OUT EFI_USB_INTERFACE_DESCRIPTOR **InterfaceDescriptor)
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)
EFI_STATUS EFIAPI PeiUsbGetEndpointDescriptor(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *This, IN UINT8 EndpointIndex, OUT EFI_USB_ENDPOINT_DESCRIPTOR **EndpointDescriptor)
EFI_STATUS EFIAPI PeiUsbPortReset(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_IO_PPI *This)
EFI_STATUS PeiConfigureUsbDevice(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_DEVICE *PeiUsbDevice, IN UINT8 Port, IN OUT UINT8 *DeviceAddress)
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)
EFI_STATUS PeiHubEnumeration(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_DEVICE *PeiUsbDevice, IN UINT8 *CurrentAddress)
EFI_STATUS EFIAPI PeimInitializeUsb(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS GetExpectedDescriptor(IN UINT8 *Buffer, IN UINTN Length, IN UINT8 DescType, IN UINT8 DescLength, OUT UINTN *ParsedBytes)
EFI_STATUS PeiUsbEnumeration(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi, IN PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi)
EFI_STATUS PeiUsbGetAllConfiguration(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_DEVICE *PeiUsbDevice)
UINT8 TranslatorHubAddress
device address
UINT8 TranslatorPortNumber
the port number of the hub that device is connected to.
UINT16 PortChangeStatus
Contains current port status change bitmap.
UINT16 PortStatus
Contains current port status bitmap.