10#ifndef _RECOVERY_UHC_H_
11#define _RECOVERY_UHC_H_
28#define USB_SLOW_SPEED_DEVICE 0x01
29#define USB_FULL_SPEED_DEVICE 0x02
34#define NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES 16
38#define USBCMD_HCRESET BIT1
39#define USBCMD_GRESET BIT2
40#define USBCMD_EGSM BIT3
41#define USBCMD_FGR BIT4
42#define USBCMD_SWDBG BIT5
44#define USBCMD_MAXP BIT7
48#define USBSTS_USBINT BIT0
49#define USBSTS_ERROR BIT1
51#define USBSTS_HSE BIT3
52#define USBSTS_HCPE BIT4
53#define USBSTS_HCH BIT5
57#define USBINTR_TIMEOUT BIT0
58#define USBINTR_RESUME BIT1
59#define USBINTR_IOC BIT2
60#define USBINTR_SP BIT3
72#define USBPORTSC1 0x10
73#define USBPORTSC2 0x12
75#define USBPORTSC_CCS BIT0
76#define USBPORTSC_CSC BIT1
77#define USBPORTSC_PED BIT2
78#define USBPORTSC_PEDC BIT3
79#define USBPORTSC_LSL BIT4
80#define USBPORTSC_LSH BIT5
81#define USBPORTSC_RD BIT6
82#define USBPORTSC_LSDA BIT8
83#define USBPORTSC_PR BIT9
84#define USBPORTSC_SUSP BIT12
86#define SETUP_PACKET_ID 0x2D
87#define INPUT_PACKET_ID 0x69
88#define OUTPUT_PACKET_ID 0xE1
89#define ERROR_PACKET_ID 0x55
91#define STALL_1_MICRO_SECOND 1
92#define STALL_1_MILLI_SECOND 1000
97 UINT32 FrameListPtrTerminate : 1;
98 UINT32 FrameListPtrQSelect : 1;
99 UINT32 FrameListRsvd : 2;
100 UINT32 FrameListPtr : 28;
104 UINT32 QHHorizontalTerminate : 1;
105 UINT32 QHHorizontalQSelect : 1;
106 UINT32 QHHorizontalRsvd : 2;
107 UINT32 QHHorizontalPtr : 28;
108 UINT32 QHVerticalTerminate : 1;
109 UINT32 QHVerticalQSelect : 1;
110 UINT32 QHVerticalRsvd : 2;
111 UINT32 QHVerticalPtr : 28;
125 UINT32 TDLinkPtrTerminate : 1;
126 UINT32 TDLinkPtrQSelect : 1;
127 UINT32 TDLinkPtrDepthSelect : 1;
128 UINT32 TDLinkPtrRsvd : 1;
129 UINT32 TDLinkPtr : 28;
130 UINT32 TDStatusActualLength : 11;
131 UINT32 TDStatusRsvd : 5;
133 UINT32 TDStatusIOC : 1;
134 UINT32 TDStatusIOS : 1;
135 UINT32 TDStatusLS : 1;
136 UINT32 TDStatusErr : 2;
137 UINT32 TDStatusSPD : 1;
138 UINT32 TDStatusRsvd2 : 2;
139 UINT32 TDTokenPID : 8;
140 UINT32 TDTokenDevAddr : 7;
141 UINT32 TDTokenEndPt : 4;
142 UINT32 TDTokenDataToggle : 1;
143 UINT32 TDTokenRsvd : 1;
144 UINT32 TDTokenMaxLen : 11;
153 UINT16 TDBufferLength;
163 UINTN BitArraySizeInBytes;
164 UINT8 *MemoryBlockPtr;
165 UINTN MemoryBlockSizeInBytes;
169#define USB_UHC_DEV_SIGNATURE SIGNATURE_32 ('p', 'u', 'h', 'c')
181 UINT32 UsbHostControllerBaseAddress;
191#define PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS(a) CR (a, USB_UHC_DEV, UsbHostControllerPpi, USB_UHC_DEV_SIGNATURE)
192#define PEI_RECOVERY_USB_UHC_DEV_FROM_THIS_NOTIFY(a) CR (a, USB_UHC_DEV, EndOfPeiNotifyList, USB_UHC_DEV_SIGNATURE)
222 IN UINT8 DeviceAddress,
223 IN UINT8 DeviceSpeed,
224 IN UINT8 MaximumPacketLength,
227 IN OUT VOID *Data OPTIONAL,
230 OUT UINT32 *TransferResult
265 IN UINT8 DeviceAddress,
266 IN UINT8 EndPointAddress,
267 IN UINT8 MaximumPacketLength,
270 IN OUT UINT8 *DataToggle,
272 OUT UINT32 *TransferResult
292 OUT UINT8 *PortNumber
462 IN UINT32 StatusRegAddr
476 IN UINT32 FrameListRegAddr,
629 IN UINT8 DeviceSpeed,
630 IN UINT8 *DevRequest,
631 IN UINT8 *RequestPhy,
664 IN UINT8 DeviceSpeed,
688 IN UINT8 DeviceSpeed,
793 IN BOOLEAN IsLowSpeedDevice
806 IN BOOLEAN IsIsochronous
1099 OUT UINT32 *TransferResult
1122 IN UINT8 *DataToggle,
1124 OUT UINT32 *TransferResult
1174 IN UINTN MemoryBlockSizeInPages
1270 IN OUT VOID *Request,
1271 OUT UINT8 **MappedAddr,
1297 OUT UINT8 **MappedAddr,
1325 IN VOID *HostAddress,
1367 OUT VOID **HostAddress,
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)
VOID SetTDDataBuffer(IN TD_STRUCT *PtrTDStruct)
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)
VOID IoMmuUnmap(IN EDKII_IOMMU_PPI *IoMmu, IN VOID *Mapping)
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)
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 IoMmuMap(IN EDKII_IOMMU_PPI *IoMmu, IN EDKII_IOMMU_OPERATION Operation, IN VOID *HostAddress, IN OUT UINTN *NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
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)
VOID IoMmuInit(OUT EDKII_IOMMU_PPI **IoMmu)
EFI_STATUS IoMmuAllocateBuffer(IN EDKII_IOMMU_PPI *IoMmu, IN UINTN Pages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
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)
BOOLEAN IsTDStatusActive(IN TD_STRUCT *PtrTDStruct)
VOID InsertMemoryHeaderToList(IN MEMORY_MANAGE_HEADER *MemoryHeader, IN MEMORY_MANAGE_HEADER *NewMemoryHeader)
BOOLEAN IsTDStatusBabbleError(IN TD_STRUCT *PtrTDStruct)