29 UINT16 CommandContent;
33 CommandContent =
USBReadPortW (Uhc, Uhc->UsbHostControllerBaseAddress + USBCMD);
34 CommandContent &= USBCMD_RS;
35 USBWritePortW (Uhc, Uhc->UsbHostControllerBaseAddress + USBCMD, CommandContent);
41 for (Index = 0; Index < (Timeout / 50) + 1; Index++) {
42 UsbSts =
USBReadPortW (Uhc, Uhc->UsbHostControllerBaseAddress + USBSTS);
44 if ((UsbSts & USBSTS_HCH) == USBSTS_HCH) {
75 Uhc = PEI_RECOVERY_USB_UHC_DEV_FROM_THIS_NOTIFY (NotifyDescriptor);
105 UINTN ControllerType;
119 &gPeiUsbControllerPpiGuid,
122 (VOID **)&ChipSetUsbControllerPpi
131 Status = ChipSetUsbControllerPpi->GetUsbController (
133 ChipSetUsbControllerPpi,
141 if (EFI_ERROR (Status)) {
153 MemPages =
sizeof (
USB_UHC_DEV) / EFI_PAGE_SIZE + 1;
160 if (EFI_ERROR (Status)) {
161 return EFI_OUT_OF_RESOURCES;
165 UhcDev->Signature = USB_UHC_DEV_SIGNATURE;
167 UhcDev->UsbHostControllerBaseAddress = (UINT32)BaseAddress;
173 if (EFI_ERROR (Status)) {
181 if (EFI_ERROR (Status)) {
192 UhcDev->PpiDescriptor.
Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
193 UhcDev->PpiDescriptor.
Guid = &gPeiUsbHostControllerPpiGuid;
194 UhcDev->PpiDescriptor.
Ppi = &UhcDev->UsbHostControllerPpi;
197 if (EFI_ERROR (Status)) {
202 UhcDev->EndOfPeiNotifyList.
Flags = (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
203 UhcDev->EndOfPeiNotifyList.
Guid = &gEfiEndOfPeiSignalPpiGuid;
244 IN UINT8 DeviceAddress,
245 IN UINT8 DeviceSpeed,
246 IN UINT8 MaximumPacketLength,
249 IN OUT VOID *Data OPTIONAL,
252 OUT UINT32 *TransferResult
271 UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
273 StatusReg = UhcDev->UsbHostControllerBaseAddress + USBSTS;
275 PktID = INPUT_PACKET_ID;
279 if ((Request ==
NULL) || (TransferResult ==
NULL)) {
280 return EFI_INVALID_PARAMETER;
290 *TransferResult = EFI_USB_ERR_SYSTEM;
291 return EFI_DEVICE_ERROR;
301 if (EFI_ERROR (Status)) {
305 Status =
UhciMapUserData (UhcDev, TransferDirection, Data, DataLength, &PktID, &DataPhy, &DataMap);
307 if (EFI_ERROR (Status)) {
308 if (RequestMap !=
NULL) {
319 PtrQH = UhcDev->ConfigQH;
337 PtrPreTD = PtrSetupTD;
343 if (TransferDirection == EfiUsbNoData) {
346 DataLen = (UINT32)*DataLength;
352 while (DataLen > 0) {
361 PacketSize = (UINT8)DataLen;
362 if (DataLen > MaximumPacketLength) {
363 PacketSize = MaximumPacketLength;
386 Data = (VOID *)((UINT8 *)Data + PacketSize);
387 DataPhy += PacketSize;
388 DataLen -= PacketSize;
399 if (PktID == OUTPUT_PACKET_ID) {
400 PktID = INPUT_PACKET_ID;
402 PktID = OUTPUT_PACKET_ID;
441 *TransferResult |= EFI_USB_ERR_SYSTEM;
442 Status = EFI_DEVICE_ERROR;
447 if (DataMap !=
NULL) {
451 if (RequestMap !=
NULL) {
492 IN UINT8 DeviceAddress,
493 IN UINT8 EndPointAddress,
494 IN UINT8 MaximumPacketLength,
497 IN OUT UINT8 *DataToggle,
499 OUT UINT32 *TransferResult
520 BOOLEAN ShortPacketEnable;
522 UINT16 CommandContent;
527 UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
534 CommandContent =
USBReadPortW (UhcDev, UhcDev->UsbHostControllerBaseAddress + USBCMD);
535 if ((CommandContent & USBCMD_MAXP) != USBCMD_MAXP) {
536 CommandContent |= USBCMD_MAXP;
537 USBWritePortW (UhcDev, UhcDev->UsbHostControllerBaseAddress + USBCMD, CommandContent);
540 StatusReg = UhcDev->UsbHostControllerBaseAddress + USBSTS;
545 PktID = INPUT_PACKET_ID;
551 ShortPacketEnable =
FALSE;
553 if ((DataLength == 0) || (Data ==
NULL) || (TransferResult ==
NULL)) {
554 return EFI_INVALID_PARAMETER;
557 if ((*DataToggle != 1) && (*DataToggle != 0)) {
558 return EFI_INVALID_PARAMETER;
561 if ( (MaximumPacketLength != 8) && (MaximumPacketLength != 16)
562 && (MaximumPacketLength != 32) && (MaximumPacketLength != 64))
564 return EFI_INVALID_PARAMETER;
572 *TransferResult = EFI_USB_ERR_SYSTEM;
573 return EFI_DEVICE_ERROR;
582 if ((EndPointAddress & 0x80) != 0) {
583 TransferDirection = EfiUsbDataIn;
585 TransferDirection = EfiUsbDataOut;
588 Status =
UhciMapUserData (UhcDev, TransferDirection, Data, DataLength, &PktID, &DataPhy, &DataMap);
590 if (EFI_ERROR (Status)) {
594 DataLen = (UINT32)*DataLength;
596 PtrQH = UhcDev->BulkQH;
599 while (DataLen > 0) {
605 PacketSize = (UINT8)DataLen;
606 if (DataLen > MaximumPacketLength) {
607 PacketSize = MaximumPacketLength;
619 USB_FULL_SPEED_DEVICE,
627 if (ShortPacketEnable) {
633 PtrFirstTD->PtrNextTD =
NULL;
645 Data = (VOID *)((UINT8 *)Data + PacketSize);
646 DataPhy += PacketSize;
647 DataLen -= PacketSize;
681 *TransferResult |= EFI_USB_ERR_SYSTEM;
682 Status = EFI_DEVICE_ERROR;
687 if (DataMap !=
NULL) {
711 OUT UINT8 *PortNumber
716 UINT16 RHPortControl;
719 UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
721 if (PortNumber ==
NULL) {
722 return EFI_INVALID_PARAMETER;
727 for (Index = 0; Index < 2; Index++) {
728 PSAddr = UhcDev->UsbHostControllerBaseAddress + USBPORTSC1 + Index * 2;
733 if (RHPortControl != 0xff) {
766 UINT8 TotalPortNumber;
768 if (PortStatus ==
NULL) {
769 return EFI_INVALID_PARAMETER;
773 if (PortNumber > TotalPortNumber) {
774 return EFI_INVALID_PARAMETER;
777 UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
778 PSAddr = UhcDev->UsbHostControllerBaseAddress + USBPORTSC1 + PortNumber * 2;
780 PortStatus->PortStatus = 0;
781 PortStatus->PortChangeStatus = 0;
788 if ((RHPortStatus & USBPORTSC_CCS) != 0) {
795 if ((RHPortStatus & USBPORTSC_PED) != 0) {
796 PortStatus->PortStatus |= USB_PORT_STAT_ENABLE;
802 if ((RHPortStatus & USBPORTSC_SUSP) != 0) {
803 PortStatus->PortStatus |= USB_PORT_STAT_SUSPEND;
809 if ((RHPortStatus & USBPORTSC_PR) != 0) {
810 PortStatus->PortStatus |= USB_PORT_STAT_RESET;
816 if ((RHPortStatus & USBPORTSC_LSDA) != 0) {
817 PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
826 if ((RHPortStatus & USBPORTSC_CSC) != 0) {
833 if ((RHPortStatus & USBPORTSC_PEDC) != 0) {
834 PortStatus->PortChangeStatus |= USB_PORT_STAT_C_ENABLE;
864 UINT32 CommandRegAddr;
865 UINT16 RHPortControl;
866 UINT8 TotalPortNumber;
869 if (PortNumber > TotalPortNumber) {
870 return EFI_INVALID_PARAMETER;
873 UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
874 PSAddr = UhcDev->UsbHostControllerBaseAddress + USBPORTSC1 + PortNumber * 2;
875 CommandRegAddr = UhcDev->UsbHostControllerBaseAddress + USBCMD;
879 switch (PortFeature) {
880 case EfiUsbPortSuspend:
881 if ((
USBReadPortW (UhcDev, CommandRegAddr) & USBCMD_EGSM) == 0) {
885 RHPortControl &= 0xfff5;
886 RHPortControl |= USBPORTSC_SUSP;
891 case EfiUsbPortReset:
892 RHPortControl &= 0xfff5;
893 RHPortControl |= USBPORTSC_PR;
899 case EfiUsbPortPower:
902 case EfiUsbPortEnable:
903 RHPortControl &= 0xfff5;
904 RHPortControl |= USBPORTSC_PED;
908 return EFI_INVALID_PARAMETER;
942 UINT16 RHPortControl;
943 UINT8 TotalPortNumber;
947 if (PortNumber > TotalPortNumber) {
948 return EFI_INVALID_PARAMETER;
951 UhcDev = PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS (This);
952 PSAddr = UhcDev->UsbHostControllerBaseAddress + USBPORTSC1 + PortNumber * 2;
956 switch (PortFeature) {
960 case EfiUsbPortEnable:
961 RHPortControl &= 0xfff5;
962 RHPortControl &= ~USBPORTSC_PED;
969 case EfiUsbPortSuspend:
970 RHPortControl &= 0xfff5;
971 RHPortControl &= ~USBPORTSC_SUSP;
977 case EfiUsbPortPower:
983 case EfiUsbPortReset:
984 RHPortControl &= 0xfff5;
985 RHPortControl &= ~USBPORTSC_PR;
991 case EfiUsbPortConnectChange:
992 RHPortControl &= 0xfff5;
993 RHPortControl |= USBPORTSC_CSC;
999 case EfiUsbPortEnableChange:
1000 RHPortControl &= 0xfff5;
1001 RHPortControl |= USBPORTSC_PEDC;
1007 case EfiUsbPortSuspendChange:
1013 case EfiUsbPortOverCurrentChange:
1019 case EfiUsbPortResetChange:
1023 return EFI_INVALID_PARAMETER;
1046 UINT32 FrameListBaseAddrReg;
1054 if (EFI_ERROR (Status)) {
1058 FrameListBaseAddrReg = UhcDev->UsbHostControllerBaseAddress + USBFLBASEADD;
1059 CommandReg = UhcDev->UsbHostControllerBaseAddress + USBCMD;
1067 Command |= USBCMD_GRESET;
1072 Command &= ~USBCMD_GRESET;
1085 Command |= USBCMD_RS | USBCMD_MAXP;
1121 return EFI_OUT_OF_RESOURCES;
1127 Status =
CreateQH (UhcDev, &UhcDev->ConfigQH);
1129 return EFI_OUT_OF_RESOURCES;
1132 ASSERT (UhcDev->ConfigQH !=
NULL);
1134 Status =
CreateQH (UhcDev, &UhcDev->BulkQH);
1136 return EFI_OUT_OF_RESOURCES;
1139 ASSERT (UhcDev->BulkQH !=
NULL);
1150 FrameListPtr = UhcDev->FrameListEntry;
1152 for (Index = 0; Index < 1024; Index++) {
1153 FrameListPtr->FrameListPtrTerminate = 0;
1154 FrameListPtr->FrameListPtr = (UINT32)(
UINTN)UhcDev->ConfigQH >> 4;
1155 FrameListPtr->FrameListPtrQSelect = 1;
1156 FrameListPtr->FrameListRsvd = 0;
1227 IN UINT32 StatusAddr
1249 IN UINT32 StatusRegAddr
1256 if ((StatusValue & (USBSTS_HCPE | USBSTS_HSE | USBSTS_HCH)) != 0) {
1274 IN UINT32 FrameListRegAddr,
1281 USBWritePortDW (UhcDev, FrameListRegAddr, (UINT32)(Addr & 0xFFFFF000));
1306 if (EFI_ERROR (Status)) {
1307 return EFI_OUT_OF_RESOURCES;
1337 PtrQH->QueueHead.QHHorizontalPtr = (UINT32)(
UINTN)PtrNext >> 4;
1357 PtrQH->QueueHead.QHHorizontalQSelect = IsQH ? 1 : 0;
1377 PtrQH->QueueHead.QHHorizontalTerminate = IsValid ? 0 : 1;
1398 PtrQH->QueueHead.QHVerticalPtr = (UINT32)(
UINTN)PtrNext >> 4;
1418 PtrQH->QueueHead.QHVerticalQSelect = IsQH ? 1 : 0;
1438 PtrQH->QueueHead.QHVerticalTerminate = IsValid ? 0 : 1;
1456 OUT VOID **PtrStruct
1466 (UINT8 **)PtrStruct,
1469 if (EFI_ERROR (Status)) {
1500 if (EFI_ERROR (Status)) {
1533 IN UINT8 DeviceSpeed,
1534 IN UINT8 *DevRequest,
1535 IN UINT8 *RequestPhy,
1536 IN UINT8 RequestLen,
1543 Status =
CreateTD (UhcDev, &TdStruct);
1544 if (EFI_ERROR (Status)) {
1575 switch (DeviceSpeed) {
1576 case USB_SLOW_SPEED_DEVICE:
1580 case USB_FULL_SPEED_DEVICE:
1611 TdStruct->PtrTDBuffer = (UINT8 *)DevRequest;
1612 TdStruct->TDBufferLength = RequestLen;
1617 TdStruct->TDData.TDBufferPtr = (UINT32)(
UINTN)RequestPhy;
1652 IN UINT8 DeviceSpeed,
1659 Status =
CreateTD (UhcDev, &TdStruct);
1660 if (EFI_ERROR (Status)) {
1695 switch (DeviceSpeed) {
1696 case USB_SLOW_SPEED_DEVICE:
1700 case USB_FULL_SPEED_DEVICE:
1735 TdStruct->PtrTDBuffer = (UINT8 *)PtrData;
1736 TdStruct->TDBufferLength = Len;
1741 TdStruct->TDData.TDBufferPtr = (UINT32)(
UINTN)DataPhy;
1768 IN UINT8 DeviceSpeed,
1775 Status =
CreateTD (UhcDev, &PtrTDStruct);
1776 if (EFI_ERROR (Status)) {
1807 switch (DeviceSpeed) {
1808 case USB_SLOW_SPEED_DEVICE:
1812 case USB_FULL_SPEED_DEVICE:
1843 PtrTDStruct->PtrTDBuffer =
NULL;
1844 PtrTDStruct->TDBufferLength = 0;
1849 PtrTDStruct->TDData.TDBufferPtr = 0;
1851 *PtrTD = PtrTDStruct;
1873 PtrTDStruct->TDData.TDLinkPtrTerminate = (IsValid ? 0 : 1);
1892 PtrTDStruct->TDData.TDLinkPtrQSelect = (IsQH ? 1 : 0);
1912 PtrTDStruct->TDData.TDLinkPtrDepthSelect = (IsDepth ? 1 : 0);
1932 PtrTDStruct->TDData.TDLinkPtr = (UINT32)(
UINTN)PtrNext >> 4;
1952 return (VOID *)(
UINTN)((PtrTDStruct->TDData.TDLinkPtr) << 4);
1971 PtrTDStruct->TDData.TDStatusSPD = (IsEnable ? 1 : 0);
1990 if (MaxErrors > 3) {
1994 PtrTDStruct->TDData.TDStatusErr = MaxErrors;
2007 IN BOOLEAN IsLowSpeedDevice
2013 PtrTDStruct->TDData.TDStatusLS = (IsLowSpeedDevice ? 1 : 0);
2026 IN BOOLEAN IsIsochronous
2032 PtrTDStruct->TDData.TDStatusIOS = (IsIsochronous ? 1 : 0);
2053 PtrTDStruct->TDData.TDStatusIOC = IsSet ? 1 : 0;
2074 PtrTDStruct->TDData.TDStatus |= 0x80;
2076 PtrTDStruct->TDData.TDStatus &= 0x7F;
2098 if (MaxLen > 0x500) {
2102 PtrTDStruct->TDData.TDTokenMaxLen = MaxLen - 1;
2121 PtrTDStruct->TDData.TDTokenDataToggle = 1;
2138 PtrTDStruct->TDData.TDTokenDataToggle = 0;
2157 PtrTDStruct->TDData.TDTokenEndPt = (UINT8)EndPoint;
2176 PtrTDStruct->TDData.TDTokenDevAddr = (UINT8)DevAddr;
2195 PtrTDStruct->TDData.TDTokenPID = PacketID;
2216 TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
2217 return (BOOLEAN)(TDStatus & 0x80);
2238 TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
2239 return (BOOLEAN)(TDStatus & 0x40);
2260 TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
2261 return (BOOLEAN)(TDStatus & 0x20);
2282 TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
2283 return (BOOLEAN)(TDStatus & 0x10);
2304 TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
2305 return (BOOLEAN)(TDStatus & 0x08);
2326 TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
2327 return (BOOLEAN)(TDStatus & 0x04);
2348 TDStatus = (UINT8)(PtrTDStruct->TDData.TDStatus);
2349 return (BOOLEAN)(TDStatus & 0x02);
2369 return (UINT16)((PtrTDStruct->TDData.TDStatusActualLength) + 1);
2389 if ((PtrTDStruct->TDData.TDLinkPtrTerminate & BIT0) != 0) {
2438 if ((PtrQH ==
NULL) || (PtrTD ==
NULL)) {
2454 PtrQH->PtrDown = (VOID *)PtrTD;
2470 if ((PtrPreTD ==
NULL) || (PtrTD ==
NULL)) {
2491 PtrPreTD->PtrNextTD = (VOID *)PtrTD;
2493 PtrTD->PtrNextTD =
NULL;
2516 OUT UINT32 *TransferResult
2521 BOOLEAN InfiniteLoop;
2524 *TransferResult = EFI_USB_NOERROR;
2526 InfiniteLoop =
FALSE;
2528 Delay = TimeOut * STALL_1_MILLI_SECOND;
2534 InfiniteLoop =
TRUE;
2543 if ((*TransferResult & EFI_USB_ERR_NOTEXECUTE) != EFI_USB_ERR_NOTEXECUTE) {
2549 }
while (InfiniteLoop || (Delay != 0));
2551 if (*TransferResult != EFI_USB_NOERROR) {
2552 return EFI_DEVICE_ERROR;
2578 IN UINT8 *DataToggle,
2580 OUT UINT32 *TransferResult
2586 BOOLEAN InfiniteLoop;
2589 *TransferResult = EFI_USB_NOERROR;
2591 InfiniteLoop =
FALSE;
2593 Delay = TimeOut * STALL_1_MILLI_SECOND;
2599 InfiniteLoop =
TRUE;
2607 if ((*TransferResult & EFI_USB_ERR_NOTEXECUTE) != EFI_USB_ERR_NOTEXECUTE) {
2613 }
while (InfiniteLoop || (Delay != 0));
2618 if (*TransferResult != EFI_USB_NOERROR) {
2623 if ((ScrollNum % 2) != 0) {
2631 return EFI_DEVICE_ERROR;
2658 while (Tptr1 !=
NULL) {
2697 *Result = EFI_USB_NOERROR;
2703 *ActualTransferSize = 0;
2705 while (PtrTD !=
NULL) {
2707 *Result |= EFI_USB_ERR_NOTEXECUTE;
2711 *Result |= EFI_USB_ERR_STALL;
2715 *Result |= EFI_USB_ERR_BUFFER;
2719 *Result |= EFI_USB_ERR_BABBLE;
2723 *Result |= EFI_USB_ERR_NAK;
2727 *Result |= EFI_USB_ERR_TIMEOUT;
2731 *Result |= EFI_USB_ERR_BITSTUFF;
2738 *ActualTransferSize += Len;
2743 if ((*Result) != 0) {
2747 PtrTD = (
TD_STRUCT *)(PtrTD->PtrNextTD);
2773 IN UINTN MemoryBlockSizeInPages
2787 MemPages = MemoryBlockSizeInPages + 1;
2795 if (EFI_ERROR (Status) || (TempPtr ==
NULL)) {
2796 return EFI_OUT_OF_RESOURCES;
2801 ZeroMem (Ptr, MemPages * EFI_PAGE_SIZE);
2811 (*MemoryHeader)->BitArrayPtr = Ptr;
2813 (*MemoryHeader)->Next =
NULL;
2819 Ptr += EFI_PAGE_SIZE;
2820 (*MemoryHeader)->MemoryBlockPtr = Ptr;
2824 (*MemoryHeader)->MemoryBlockSizeInBytes = MemoryBlockSizeInPages * EFI_PAGE_SIZE;
2828 (*MemoryHeader)->BitArraySizeInBytes = ((*MemoryHeader)->MemoryBlockSizeInBytes / 32) / 8;
2851 MemPages = NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES;
2853 if (EFI_ERROR (Status)) {
2857 UhcDev->Header1 = MemoryHeader;
2883 UINTN RealAllocSize;
2884 UINTN MemoryBlockSizeInPages;
2889 MemoryHeader = UhcDev->Header1;
2894 if ((AllocSize & 0x1F) != 0) {
2895 RealAllocSize = (AllocSize / 32 + 1) * 32;
2897 RealAllocSize = AllocSize;
2900 Status = EFI_NOT_FOUND;
2901 for (TempHeaderPtr = MemoryHeader; TempHeaderPtr !=
NULL; TempHeaderPtr = TempHeaderPtr->Next) {
2907 if (!EFI_ERROR (Status)) {
2920 if (RealAllocSize > (NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES * EFI_PAGE_SIZE)) {
2921 MemoryBlockSizeInPages = RealAllocSize / EFI_PAGE_SIZE + 1;
2923 MemoryBlockSizeInPages = NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES;
2927 if (EFI_ERROR (Status)) {
2968 UINTN NumberOfZeros;
2974 ByteValue = MemoryHeader->BitArrayPtr[0];
2977 for (TempBytePos = 0; TempBytePos < MemoryHeader->BitArraySizeInBytes;) {
2981 BitValue = (UINT8)(ByteValue & 0x1);
2983 if (BitValue == 0) {
2991 if (NumberOfZeros >= NumberOfMemoryUnit) {
2998 if (NumberOfZeros >= NumberOfMemoryUnit) {
3013 FoundBytePos = TempBytePos;
3014 FoundBitPos = Index;
3033 ByteValue = MemoryHeader->BitArrayPtr[TempBytePos];
3038 if (NumberOfZeros < NumberOfMemoryUnit) {
3039 return EFI_NOT_FOUND;
3053 if ((MemoryHeader->BitArrayPtr[0] & BIT0) != 0) {
3060 if (FoundBitPos > 7) {
3068 for (TempBytePos = FoundBytePos, Index = FoundBitPos, Count = 0; Count < NumberOfMemoryUnit; Count++) {
3069 MemoryHeader->BitArrayPtr[TempBytePos] = (UINT8)(MemoryHeader->BitArrayPtr[TempBytePos] | (1 << Index));
3077 *Pool = MemoryHeader->MemoryBlockPtr + (FoundBytePos * 8 + FoundBitPos) * 32;
3104 UINTN RealAllocSize;
3106 MemoryHeader = UhcDev->Header1;
3111 if ((AllocSize & 0x1F) != 0) {
3112 RealAllocSize = (AllocSize / 32 + 1) * 32;
3114 RealAllocSize = AllocSize;
3117 for (TempHeaderPtr = MemoryHeader; TempHeaderPtr !=
NULL;
3118 TempHeaderPtr = TempHeaderPtr->Next)
3120 if ((Pool >= TempHeaderPtr->MemoryBlockPtr) &&
3121 ((Pool + RealAllocSize) <= (TempHeaderPtr->MemoryBlockPtr +
3122 TempHeaderPtr->MemoryBlockSizeInBytes)))
3128 StartBytePos = ((Pool - TempHeaderPtr->MemoryBlockPtr) / 32) / 8;
3129 StartBitPos = (UINT8)(((Pool - TempHeaderPtr->MemoryBlockPtr) / 32) % 8);
3134 for (Index = StartBytePos, Index2 = StartBitPos, Count = 0; Count < (RealAllocSize / 32); Count++) {
3135 TempHeaderPtr->BitArrayPtr[Index] = (UINT8)(TempHeaderPtr->BitArrayPtr[Index] ^ (1 << Index2));
3166 for (TempHeaderPtr = MemoryHeader; TempHeaderPtr !=
NULL; TempHeaderPtr = TempHeaderPtr->Next) {
3167 if (TempHeaderPtr->Next ==
NULL) {
3168 TempHeaderPtr->Next = NewMemoryHeader;
3189 IN OUT VOID *Request,
3190 OUT UINT8 **MappedAddr,
3208 if (!EFI_ERROR (Status)) {
3209 *MappedAddr = (UINT8 *)(
UINTN)PhyAddr;
3237 OUT UINT8 **MappedAddr,
3246 switch (Direction) {
3251 *PktId = INPUT_PACKET_ID;
3261 if (EFI_ERROR (Status)) {
3265 *MappedAddr = (UINT8 *)(
UINTN)PhyAddr;
3269 *PktId = OUTPUT_PACKET_ID;
3279 if (EFI_ERROR (Status)) {
3283 *MappedAddr = (UINT8 *)(
UINTN)PhyAddr;
3287 if ((Len !=
NULL) && (*Len != 0)) {
3288 Status = EFI_INVALID_PARAMETER;
3292 *PktId = OUTPUT_PACKET_ID;
3298 Status = EFI_INVALID_PARAMETER;
EFI_STATUS IoMmuUnmap(IN VOID *Mapping)
EFI_STATUS IoMmuAllocateBuffer(IN UINTN Pages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
EFI_STATUS IoMmuMap(IN EDKII_IOMMU_OPERATION Operation, IN VOID *HostAddress, IN OUT UINTN *NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
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 PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
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)
UINT16 EFIAPI IoRead16(IN UINTN Port)
UINT32 EFIAPI IoWrite32(IN UINTN Port, IN UINT32 Value)
UINT16 EFIAPI IoWrite16(IN UINTN Port, IN UINT16 Value)
#define ASSERT_EFI_ERROR(StatusParameter)
#define USB_PORT_STAT_C_CONNECTION
#define USB_PORT_STAT_CONNECTION
VOID IoMmuInit(OUT EDKII_IOMMU_PPI **IoMmu)
VOID * EFI_PEI_FILE_HANDLE
@ EdkiiIoMmuOperationBusMasterWrite
@ EdkiiIoMmuOperationBusMasterRead
UINT64 EFI_PHYSICAL_ADDRESS
VOID SetQHVerticalQHorTDSelect(IN QH_STRUCT *PtrQH, IN BOOLEAN IsQH)
VOID SetFrameListBaseAddress(IN USB_UHC_DEV *UhcDev, IN UINT32 FrameListRegAddr, IN UINT32 Addr)
VOID SetTDTokenDeviceAddress(IN TD_STRUCT *PtrTDStruct, IN UINTN DevAddr)
VOID SetTDTokenEndPoint(IN TD_STRUCT *PtrTDStruct, IN UINTN EndPoint)
EFI_STATUS EFIAPI UhcControlTransfer(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_HOST_CONTROLLER_PPI *This, IN UINT8 DeviceAddress, IN UINT8 DeviceSpeed, IN UINT8 MaximumPacketLength, IN EFI_USB_DEVICE_REQUEST *Request, IN EFI_USB_DATA_DIRECTION TransferDirection, IN OUT VOID *Data OPTIONAL, IN OUT UINTN *DataLength OPTIONAL, IN UINTN TimeOut, OUT UINT32 *TransferResult)
VOID SetTDTokenDataToggle1(IN TD_STRUCT *PtrTDStruct)
EFI_STATUS EFIAPI UhcBulkTransfer(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_HOST_CONTROLLER_PPI *This, IN UINT8 DeviceAddress, IN UINT8 EndPointAddress, IN UINT8 MaximumPacketLength, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN OUT UINT8 *DataToggle, IN UINTN TimeOut, OUT UINT32 *TransferResult)
BOOLEAN GetTDLinkPtrValidorInvalid(IN TD_STRUCT *PtrTDStruct)
BOOLEAN CheckTDsResults(IN TD_STRUCT *PtrTD, OUT UINT32 *Result, OUT UINTN *ErrTDPos, OUT UINTN *ActualTransferSize)
VOID LinkTDToQH(IN QH_STRUCT *PtrQH, IN TD_STRUCT *PtrTD)
VOID SetTDLinkPtrValidorInvalid(IN TD_STRUCT *PtrTDStruct, IN BOOLEAN IsValid)
EFI_STATUS CreateQH(IN USB_UHC_DEV *UhcDev, OUT QH_STRUCT **PtrQH)
VOID ClearStatusReg(IN USB_UHC_DEV *UhcDev, IN UINT32 StatusAddr)
EFI_STATUS CreateMemoryBlock(IN USB_UHC_DEV *UhcDev, OUT MEMORY_MANAGE_HEADER **MemoryHeader, IN UINTN MemoryBlockSizeInPages)
EFI_STATUS UhciMapUserRequest(IN USB_UHC_DEV *Uhc, IN OUT VOID *Request, OUT UINT8 **MappedAddr, OUT VOID **Map)
EFI_STATUS InitializeMemoryManagement(IN USB_UHC_DEV *UhcDev)
VOID SetQHHorizontalQHorTDSelect(IN QH_STRUCT *PtrQH, IN BOOLEAN IsQH)
EFI_STATUS EFIAPI UhcGetRootHubPortNumber(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_HOST_CONTROLLER_PPI *This, OUT UINT8 *PortNumber)
UINTN CountTDsNumber(IN TD_STRUCT *PtrFirstTD)
VOID USBWritePortDW(IN USB_UHC_DEV *UhcDev, IN UINT32 Port, IN UINT32 Data)
EFI_STATUS CreateFrameList(USB_UHC_DEV *UhcDev)
EFI_STATUS CreateStatusTD(IN USB_UHC_DEV *UhcDev, IN UINT8 DevAddr, IN UINT8 Endpoint, IN UINT8 PktID, IN UINT8 DeviceSpeed, OUT TD_STRUCT **PtrTD)
VOID SetQHHorizontalLinkPtr(IN QH_STRUCT *PtrQH, IN VOID *PtrNext)
EFI_STATUS AllocMemInMemoryBlock(IN MEMORY_MANAGE_HEADER *MemoryHeader, OUT VOID **Pool, IN UINTN NumberOfMemoryUnit)
EFI_STATUS UhcAllocatePool(IN USB_UHC_DEV *UhcDev, OUT UINT8 **Pool, IN UINTN AllocSize)
VOID USBWritePortW(IN USB_UHC_DEV *UhcDev, IN UINT32 Port, IN UINT16 Data)
VOID SetorClearTDControlIOC(IN TD_STRUCT *PtrTDStruct, IN BOOLEAN IsSet)
BOOLEAN IsStatusOK(IN USB_UHC_DEV *UhcDev, IN UINT32 StatusRegAddr)
VOID SetTDLinkPtrQHorTDSelect(IN TD_STRUCT *PtrTDStruct, IN BOOLEAN IsQH)
VOID SetQHHorizontalValidorInvalid(IN QH_STRUCT *PtrQH, IN BOOLEAN IsValid)
VOID SetTDControlErrorCounter(IN TD_STRUCT *PtrTDStruct, IN UINT8 MaxErrors)
VOID UhcFreePool(IN USB_UHC_DEV *UhcDev, IN UINT8 *Pool, IN UINTN AllocSize)
EFI_STATUS InitializeUsbHC(IN USB_UHC_DEV *UhcDev)
BOOLEAN IsTDStatusBufferError(IN TD_STRUCT *PtrTDStruct)
VOID SetTDStatusActiveorInactive(IN TD_STRUCT *PtrTDStruct, IN BOOLEAN IsActive)
VOID DeleteQueuedTDs(IN USB_UHC_DEV *UhcDev, IN TD_STRUCT *PtrFirstTD)
EFI_STATUS EFIAPI UhcGetRootHubPortStatus(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_HOST_CONTROLLER_PPI *This, IN UINT8 PortNumber, OUT EFI_USB_PORT_STATUS *PortStatus)
BOOLEAN IsTDStatusCRCTimeOutError(IN TD_STRUCT *PtrTDStruct)
EFI_STATUS AllocateTDorQHStruct(IN USB_UHC_DEV *UhcDev, IN UINT32 Size, OUT VOID **PtrStruct)
BOOLEAN IsTDStatusStalled(IN TD_STRUCT *PtrTDStruct)
VOID SetTDLinkPtr(IN TD_STRUCT *PtrTDStruct, IN VOID *PtrNext)
EFI_STATUS GenDataTD(IN USB_UHC_DEV *UhcDev, IN UINT8 DevAddr, IN UINT8 Endpoint, IN UINT8 *PtrData, IN UINT8 *DataPhy, IN UINT8 Len, IN UINT8 PktID, IN UINT8 Toggle, IN UINT8 DeviceSpeed, OUT TD_STRUCT **PtrTD)
UINT16 GetTDStatusActualLength(IN TD_STRUCT *PtrTDStruct)
EFI_STATUS GenSetupStageTD(IN USB_UHC_DEV *UhcDev, IN UINT8 DevAddr, IN UINT8 Endpoint, IN UINT8 DeviceSpeed, IN UINT8 *DevRequest, IN UINT8 *RequestPhy, IN UINT8 RequestLen, OUT TD_STRUCT **PtrTD)
EFI_STATUS EFIAPI UhcSetRootHubPortFeature(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_HOST_CONTROLLER_PPI *This, IN UINT8 PortNumber, IN EFI_USB_PORT_FEATURE PortFeature)
UINT16 SetTDTokenMaxLength(IN TD_STRUCT *PtrTDStruct, IN UINT16 MaxLen)
VOID SetTDLinkPtrDepthorBreadth(IN TD_STRUCT *PtrTDStruct, IN BOOLEAN IsDepth)
VOID EnableorDisableTDShortPacket(IN TD_STRUCT *PtrTDStruct, IN BOOLEAN IsEnable)
EFI_STATUS EFIAPI UhcPeimEntry(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
VOID SetTDLoworFullSpeedDevice(IN TD_STRUCT *PtrTDStruct, IN BOOLEAN IsLowSpeedDevice)
VOID SetQHVerticalLinkPtr(IN QH_STRUCT *PtrQH, IN VOID *PtrNext)
BOOLEAN IsTDStatusNAKReceived(IN TD_STRUCT *PtrTDStruct)
EFI_STATUS ExecuteControlTransfer(IN USB_UHC_DEV *UhcDev, IN TD_STRUCT *PtrTD, OUT UINTN *ActualLen, IN UINTN TimeOut, OUT UINT32 *TransferResult)
EFI_STATUS UhciMapUserData(IN USB_UHC_DEV *Uhc, IN EFI_USB_DATA_DIRECTION Direction, IN VOID *Data, IN OUT UINTN *Len, OUT UINT8 *PktId, OUT UINT8 **MappedAddr, OUT VOID **Map)
VOID * GetTDLinkPtr(IN TD_STRUCT *PtrTDStruct)
EFI_STATUS ExecBulkTransfer(IN USB_UHC_DEV *UhcDev, IN TD_STRUCT *PtrTD, IN OUT UINTN *ActualLen, IN UINT8 *DataToggle, IN UINTN TimeOut, OUT UINT32 *TransferResult)
VOID SetQHVerticalValidorInvalid(IN QH_STRUCT *PtrQH, IN BOOLEAN IsValid)
BOOLEAN IsTDStatusBitStuffError(IN TD_STRUCT *PtrTDStruct)
UINT16 USBReadPortW(IN USB_UHC_DEV *UhcDev, IN UINT32 Port)
VOID SetTDTokenPacketID(IN TD_STRUCT *PtrTDStruct, IN UINT8 PacketID)
VOID SetTDControlIsochronousorNot(IN TD_STRUCT *PtrTDStruct, IN BOOLEAN IsIsochronous)
VOID SetTDTokenDataToggle0(IN TD_STRUCT *PtrTDStruct)
VOID LinkTDToTD(IN TD_STRUCT *PtrPreTD, IN TD_STRUCT *PtrTD)
EFI_STATUS EFIAPI UhcClearRootHubPortFeature(IN EFI_PEI_SERVICES **PeiServices, IN PEI_USB_HOST_CONTROLLER_PPI *This, IN UINT8 PortNumber, IN EFI_USB_PORT_FEATURE PortFeature)
EFI_STATUS CreateTD(IN USB_UHC_DEV *UhcDev, OUT TD_STRUCT **PtrTD)
EFI_STATUS UhciStopHc(IN USB_UHC_DEV *Uhc, IN UINTN Timeout)
BOOLEAN IsTDStatusActive(IN TD_STRUCT *PtrTDStruct)
VOID InsertMemoryHeaderToList(IN MEMORY_MANAGE_HEADER *MemoryHeader, IN MEMORY_MANAGE_HEADER *NewMemoryHeader)
EFI_STATUS EFIAPI UhcEndOfPei(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
BOOLEAN IsTDStatusBabbleError(IN TD_STRUCT *PtrTDStruct)
#define PEI_UHCI_CONTROLLER
EFI_PEIM_NOTIFY_ENTRY_POINT Notify