34 Status = Xhc->PciIo->Mem.Read (
43 if (EFI_ERROR (Status)) {
44 DEBUG ((DEBUG_ERROR,
"XhcReadCapReg: Pci Io read error - %r at %d\n", Status, Offset));
70 Status = Xhc->PciIo->Mem.Read (
79 if (EFI_ERROR (Status)) {
80 DEBUG ((DEBUG_ERROR,
"XhcReadCapReg: Pci Io read error - %r at %d\n", Status, Offset));
106 ASSERT (Xhc->CapLength != 0);
108 Status = Xhc->PciIo->Mem.Read (
112 Xhc->CapLength + Offset,
117 if (EFI_ERROR (Status)) {
118 DEBUG ((DEBUG_ERROR,
"XhcReadOpReg: Pci Io Read error - %r at %d\n", Status, Offset));
142 ASSERT (Xhc->CapLength != 0);
144 Status = Xhc->PciIo->Mem.Write (
148 Xhc->CapLength + Offset,
153 if (EFI_ERROR (Status)) {
154 DEBUG ((DEBUG_ERROR,
"XhcWriteOpReg: Pci Io Write error: %r at %d\n", Status, Offset));
175 ASSERT (Xhc->DBOff != 0);
177 Status = Xhc->PciIo->Mem.Write (
186 if (EFI_ERROR (Status)) {
187 DEBUG ((DEBUG_ERROR,
"XhcWriteOpReg: Pci Io Write error: %r at %d\n", Status, Offset));
209 ASSERT (Xhc->RTSOff != 0);
211 Status = Xhc->PciIo->Mem.Read (
215 Xhc->RTSOff + Offset,
220 if (EFI_ERROR (Status)) {
221 DEBUG ((DEBUG_ERROR,
"XhcReadRuntimeReg: Pci Io Read error - %r at %d\n", Status, Offset));
245 ASSERT (Xhc->RTSOff != 0);
247 Status = Xhc->PciIo->Mem.Write (
251 Xhc->RTSOff + Offset,
256 if (EFI_ERROR (Status)) {
257 DEBUG ((DEBUG_ERROR,
"XhcWriteRuntimeReg: Pci Io Write error: %r at %d\n", Status, Offset));
279 ASSERT (Xhc->ExtCapRegBase != 0);
281 Status = Xhc->PciIo->Mem.Read (
285 Xhc->ExtCapRegBase + Offset,
290 if (EFI_ERROR (Status)) {
291 DEBUG ((DEBUG_ERROR,
"XhcReadExtCapReg: Pci Io Read error - %r at %d\n", Status, Offset));
315 ASSERT (Xhc->ExtCapRegBase != 0);
317 Status = Xhc->PciIo->Mem.Write (
321 Xhc->ExtCapRegBase + Offset,
326 if (EFI_ERROR (Status)) {
327 DEBUG ((DEBUG_ERROR,
"XhcWriteExtCapReg: Pci Io Write error: %r at %d\n", Status, Offset));
438 IN BOOLEAN WaitToSet,
455 if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) == WaitToSet) {
459 gBS->Stall (XHC_1_MICROSECOND);
462 if (TicksDelta == 0) {
466 ElapsedTicks += TicksDelta;
467 }
while (ElapsedTicks < TimeoutTicks);
485 if (Xhc->UsbLegSupOffset == 0xFFFFFFFF) {
489 DEBUG ((DEBUG_INFO,
"XhcSetBiosOwnership: called to set BIOS ownership\n"));
492 Buffer = ((Buffer & (~USBLEGSP_OS_SEMAPHORE)) | USBLEGSP_BIOS_SEMAPHORE);
509 if (Xhc->UsbLegSupOffset == 0xFFFFFFFF) {
513 DEBUG ((DEBUG_INFO,
"XhcClearBiosOwnership: called to clear BIOS ownership\n"));
516 Buffer = ((Buffer & (~USBLEGSP_BIOS_SEMAPHORE)) | USBLEGSP_OS_SEMAPHORE);
546 if ((Data & 0xFF) == CapId) {
553 NextExtCapReg = (UINT8)((Data >> 8) & 0xFF);
554 ExtCapOffset += (NextExtCapReg << 2);
555 }
while (NextExtCapReg != 0);
572 IN UINT8 MajorVersion
592 UsbSupportDw0.Dword = Data;
593 if ((Data & 0xFF) == XHC_CAP_USB_SUPPORTED_PROTOCOL) {
594 if (UsbSupportDw0.Data.RevMajor == MajorVersion) {
595 NameString =
XhcReadExtCapReg (Xhc, ExtCapOffset + XHC_SUPPORTED_PROTOCOL_NAME_STRING_OFFSET);
596 if (NameString == XHC_SUPPORTED_PROTOCOL_NAME_STRING_VALUE) {
608 NextExtCapReg = (UINT8)((Data >> 8) & 0xFF);
609 ExtCapOffset += (NextExtCapReg << 2);
610 }
while (NextExtCapReg != 0);
629 IN UINT32 ExtCapOffset,
640 if ((Xhc ==
NULL) || (ExtCapOffset == 0xFFFFFFFF)) {
650 PortId.Dword =
XhcReadExtCapReg (Xhc, ExtCapOffset + XHC_SUPPORTED_PROTOCOL_DW2_OFFSET);
658 if ((PortId.Data.CompPortOffset == 0) || (PortId.Data.CompPortCount == 0)) {
662 MinPortIndex = PortId.Data.CompPortOffset - 1;
663 MaxPortIndex = MinPortIndex + PortId.Data.CompPortCount - 1;
665 if ((PortNumber < MinPortIndex) || (PortNumber > MaxPortIndex)) {
669 for (Count = 0; Count < PortId.Data.Psic; Count++) {
670 Reg.Dword =
XhcReadExtCapReg (Xhc, ExtCapOffset + XHC_SUPPORTED_PROTOCOL_PSI_OFFSET + (Count << 2));
671 if (Reg.Data.Psiv == PortSpeed) {
697 UINT16 UsbSpeedIdMap;
710 if (Xhc->Usb3SupOffset != 0xFFFFFFFF) {
711 SpField.Dword =
XhciPsivGetPsid (Xhc, Xhc->Usb3SupOffset, PortSpeed, PortNumber);
712 if (SpField.Dword != 0) {
716 UsbSpeedIdMap = USB_PORT_STAT_SUPER_SPEED;
724 if ((UsbSpeedIdMap == 0) && (Xhc->Usb2SupOffset != 0xFFFFFFFF)) {
725 SpField.Dword =
XhciPsivGetPsid (Xhc, Xhc->Usb2SupOffset, PortSpeed, PortNumber);
726 if (SpField.Dword != 0) {
730 if (SpField.Data.Psie == 2) {
736 if (SpField.Data.Psim == XHC_SUPPORTED_PROTOCOL_USB2_HIGH_SPEED_PSIM) {
740 UsbSpeedIdMap = USB_PORT_STAT_HIGH_SPEED;
742 }
else if (SpField.Data.Psie == 1) {
748 if (SpField.Data.Psim == XHC_SUPPORTED_PROTOCOL_USB2_LOW_SPEED_PSIM) {
752 UsbSpeedIdMap = USB_PORT_STAT_LOW_SPEED;
758 return UsbSpeedIdMap;
775 return XHC_REG_BIT_IS_SET (Xhc, XHC_USBSTS_OFFSET, XHC_USBSTS_HALT);
792 return XHC_REG_BIT_IS_SET (Xhc, XHC_USBSTS_OFFSET, XHC_USBSTS_HSE);
814 Status = PciIo->Pci.
Read (
818 sizeof (XhciCmd) /
sizeof (UINT16),
821 if (!EFI_ERROR (Status)) {
848 DEBUG ((DEBUG_INFO,
"XhcResetHC!\n"));
852 if (!XHC_REG_BIT_IS_SET (Xhc, XHC_USBSTS_OFFSET, XHC_USBSTS_HALT)) {
855 if (EFI_ERROR (Status)) {
860 if ((Xhc->DebugCapSupOffset == 0xFFFFFFFF) || ((
XhcReadExtCapReg (Xhc, Xhc->DebugCapSupOffset) & 0xFF) != XHC_CAP_USB_DEBUG) ||
861 ((
XhcReadExtCapReg (Xhc, Xhc->DebugCapSupOffset + XHC_DC_DCCTRL) & BIT0) == 0))
872 if (!EFI_ERROR (Status)) {
UINT64 EFIAPI GetPerformanceCounter(VOID)
#define DEBUG(Expression)
#define PcdGet16(TokenName)
#define EFI_PCI_COMMAND_SERR
0x0100
UINT64 XhcGetElapsedTicks(IN OUT UINT64 *PreviousTick)
UINT64 XhcConvertTimeToTicks(IN UINT64 Time)
VOID XhcSetRuntimeRegBit(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset, IN UINT32 Bit)
EFI_STATUS XhcResetHC(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Timeout)
BOOLEAN XhcIsSysError(IN USB_XHCI_INSTANCE *Xhc)
UINT32 XhcReadRuntimeReg(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset)
EFI_STATUS XhcRunHC(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Timeout)
UINT32 XhcGetCapabilityAddr(IN USB_XHCI_INSTANCE *Xhc, IN UINT8 CapId)
VOID XhcClearBiosOwnership(IN USB_XHCI_INSTANCE *Xhc)
EFI_STATUS XhcHaltHC(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Timeout)
VOID XhcClearRuntimeRegBit(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset, IN UINT32 Bit)
UINT16 XhcCheckUsbPortSpeedUsedPsic(IN USB_XHCI_INSTANCE *Xhc, IN UINT8 PortSpeed, IN UINT8 PortNumber)
VOID XhcSetHsee(IN USB_XHCI_INSTANCE *Xhc)
VOID XhcWriteRuntimeReg(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset, IN UINT32 Data)
VOID XhcClearOpRegBit(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset, IN UINT32 Bit)
UINT32 XhcReadExtCapReg(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset)
VOID XhcWriteOpReg(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset, IN UINT32 Data)
VOID XhcSetBiosOwnership(IN USB_XHCI_INSTANCE *Xhc)
UINT32 XhcGetSupportedProtocolCapabilityAddr(IN USB_XHCI_INSTANCE *Xhc, IN UINT8 MajorVersion)
UINT32 XhciPsivGetPsid(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 ExtCapOffset, IN UINT8 PortSpeed, IN UINT8 PortNumber)
UINT32 XhcReadCapReg(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset)
VOID XhcSetOpRegBit(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset, IN UINT32 Bit)
VOID XhcWriteDoorBellReg(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset, IN UINT32 Data)
UINT32 XhcReadOpReg(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset)
BOOLEAN XhcIsHalt(IN USB_XHCI_INSTANCE *Xhc)
UINT8 XhcReadCapReg8(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset)
VOID XhcWriteExtCapReg(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset, IN UINT32 Data)
EFI_STATUS XhcWaitOpRegBit(IN USB_XHCI_INSTANCE *Xhc, IN UINT32 Offset, IN UINT32 Bit, IN BOOLEAN WaitToSet, IN UINT32 Timeout)
EFI_PCI_IO_PROTOCOL_CONFIG Read