11UINT16 mString0Desc[] = {
13 (USB_DESC_TYPE_STRING << 8) + STRING0_DESC_LEN,
17UINT16 mManufacturerStrDesc[] = {
19 (USB_DESC_TYPE_STRING << 8) + MANU_DESC_LEN,
20 'I',
'n',
't',
'e',
'l'
23UINT16 mProductStrDesc[] = {
25 (USB_DESC_TYPE_STRING << 8) + PRODUCT_DESC_LEN,
26 'U',
'S',
'B',
' ',
'3',
'.',
'0',
' ',
'D',
'e',
'b',
'u',
'g',
' ',
'C',
'a',
'b',
'l',
'e'
29UINT16 mSerialNumberStrDesc[] = {
31 (USB_DESC_TYPE_STRING << 8) + SERIAL_DESC_LEN,
50 RegisterValue |= (UINT32)(BitMask);
69 RegisterValue &= ~BitMask;
90 DebugCapabilityBase = Handle->DebugCapabilityBase;
114 DebugCapabilityBase = Handle->DebugCapabilityBase;
181 High =
PciRead32 (
PcdGet32 (PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + 4);
183 XhciMmioBase &= XHCI_BASE_ADDRESS_64_BIT_MASK;
185 if ((XhciMmioBase == 0) || (XhciMmioBase == XHCI_BASE_ADDRESS_64_BIT_MASK)) {
186 XhciMmioBase =
PcdGet64 (PcdUsbXhciMemorySpaceBase);
187 PciWrite32 (
PcdGet32 (PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, XhciMmioBase & 0xFFFFFFFF);
213 if (Handle ==
NULL) {
220 Handle->XhciMmioBase = XhciMmioBase;
221 Handle->DebugCapabilityBase = XhciMmioBase + Handle->DebugCapabilityOffset;
222 Handle->XhciOpRegister = XhciMmioBase +
MmioRead8 ((
UINTN)XhciMmioBase);
250 if (Handle->Initialized != USB3DBG_UNINITIALIZED) {
251 if (Handle->Initialized == USB3DBG_NO_DBG_CAB) {
261 if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) {
265 ProgInterface =
PciRead8 (
PcdGet32 (PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET);
266 SubClassCode =
PciRead8 (
PcdGet32 (PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET + 1);
267 BaseCode =
PciRead8 (
PcdGet32 (PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET + 2);
269 if ((ProgInterface != PCI_IF_XHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) {
278 CapabilityPointer = Handle->XhciMmioBase + (
MmioRead32 ((
UINTN)(Handle->XhciMmioBase + XHC_HCCPARAMS_OFFSET)) >> 16) * 4;
286 if ((Capability & XHC_CAPABILITY_ID_MASK) == PCI_CAPABILITY_ID_DEBUG_PORT) {
291 if ((((Capability & XHC_NEXT_CAPABILITY_MASK) >> 8) & XHC_CAPABILITY_ID_MASK) == 0) {
298 CapabilityPointer += ((Capability & XHC_NEXT_CAPABILITY_MASK) >> 8) * 4;
309 Handle->DebugCapabilityBase = CapabilityPointer;
310 Handle->DebugCapabilityOffset = CapabilityPointer - Handle->XhciMmioBase;
311 Handle->XhciOpRegister = Handle->XhciMmioBase + CapLength;
312 Handle->DebugSupport =
TRUE;
313 Handle->Initialized = USB3DBG_DBG_CAB;
317 Handle->Initialized = USB3DBG_NO_DBG_CAB;
341 volatile UINT32 Dcctrl;
349 if ((Dcctrl & BIT0) == 0) {
351 }
else if (!Handle->Ready) {
352 Handle->Ready =
TRUE;
353 Handle->Initialized = USB3DBG_ENABLED;
375 ASSERT (EventRing !=
NULL);
381 ASSERT (Buf !=
NULL);
382 ASSERT (((
UINTN)Buf & 0x3F) == 0);
386 EventRing->TrbNumber = EVENT_RING_TRB_NUMBER;
394 EventRing->EventRingCCS = 1;
400 ASSERT (Buf !=
NULL);
401 ASSERT (((
UINTN)Buf & 0x3F) == 0);
410 ERSTBase->PtrLo = XHC_LOW_32BIT (EventRing->EventRingSeg0);
411 ERSTBase->PtrHi = XHC_HIGH_32BIT (EventRing->EventRingSeg0);
412 ERSTBase->RingTrbSize = EVENT_RING_TRB_NUMBER;
420 XHC_LOW_32BIT ((UINT64)(
UINTN)EventRing->EventRingDequeue)
426 XHC_HIGH_32BIT ((UINT64)(
UINTN)EventRing->EventRingDequeue)
435 XHC_LOW_32BIT ((UINT64)(
UINTN)ERSTBase)
441 XHC_HIGH_32BIT ((UINT64)(
UINTN)ERSTBase)
474 ASSERT (Buf !=
NULL);
475 ASSERT (((
UINTN)Buf & 0xF) == 0);
479 TransferRing->TrbNumber = TrbNum;
480 TransferRing->RingEnqueue = TransferRing->RingSeg0;
481 TransferRing->RingDequeue = TransferRing->RingSeg0;
482 TransferRing->RingPCS = 1;
489 EndTrb->Type = TRB_TYPE_LINK;
490 EndTrb->PtrLo = XHC_LOW_32BIT (Buf);
491 EndTrb->PtrHi = XHC_HIGH_32BIT (Buf);
499 EndTrb->CycleBit = 0;
519 UINT8 *ManufacturerStrDesc;
520 UINT8 *ProductStrDesc;
521 UINT8 *SerialNumberStrDesc;
527 ASSERT (Buf !=
NULL);
528 ASSERT (((
UINTN)Buf & 0xF) == 0);
537 DebugCapabilityContext->DbcInfoContext.String0Length = STRING0_DESC_LEN;
538 DebugCapabilityContext->DbcInfoContext.ManufacturerStrLength = MANU_DESC_LEN;
539 DebugCapabilityContext->DbcInfoContext.ProductStrLength = PRODUCT_DESC_LEN;
540 DebugCapabilityContext->DbcInfoContext.SerialNumberStrLength = SERIAL_DESC_LEN;
545 DebugCapabilityContext->EpOutContext.CErr = 0x3;
546 DebugCapabilityContext->EpOutContext.EPType = ED_BULK_OUT;
547 DebugCapabilityContext->EpOutContext.MaxPacketSize = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
548 DebugCapabilityContext->EpOutContext.AverageTRBLength = 0x1000;
553 DebugCapabilityContext->EpInContext.CErr = 0x3;
554 DebugCapabilityContext->EpInContext.EPType = ED_BULK_IN;
555 DebugCapabilityContext->EpInContext.MaxPacketSize = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
556 DebugCapabilityContext->EpInContext.AverageTRBLength = 0x1000;
561 String0Desc = (UINT8 *)
AllocateAlignBuffer (STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN);
562 ASSERT (String0Desc !=
NULL);
563 ZeroMem (String0Desc, STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN);
564 CopyMem (String0Desc, mString0Desc, STRING0_DESC_LEN);
565 DebugCapabilityContext->DbcInfoContext.String0DescAddress = (UINT64)(
UINTN)String0Desc;
567 ManufacturerStrDesc = String0Desc + STRING0_DESC_LEN;
568 CopyMem (ManufacturerStrDesc, mManufacturerStrDesc, MANU_DESC_LEN);
569 DebugCapabilityContext->DbcInfoContext.ManufacturerStrDescAddress = (UINT64)(
UINTN)ManufacturerStrDesc;
571 ProductStrDesc = ManufacturerStrDesc + MANU_DESC_LEN;
572 CopyMem (ProductStrDesc, mProductStrDesc, PRODUCT_DESC_LEN);
573 DebugCapabilityContext->DbcInfoContext.ProductStrDescAddress = (UINT64)(
UINTN)ProductStrDesc;
575 SerialNumberStrDesc = ProductStrDesc + PRODUCT_DESC_LEN;
576 CopyMem (SerialNumberStrDesc, mSerialNumberStrDesc, SERIAL_DESC_LEN);
577 DebugCapabilityContext->DbcInfoContext.SerialNumberStrDescAddress = (UINT64)(
UINTN)SerialNumberStrDesc;
584 DebugCapabilityContext->EpInContext.PtrLo = XHC_LOW_32BIT (Handle->TransferRingIn.RingSeg0) | BIT0;
585 DebugCapabilityContext->EpInContext.PtrHi = XHC_HIGH_32BIT (Handle->TransferRingIn.RingSeg0);
592 DebugCapabilityContext->EpOutContext.PtrLo = XHC_LOW_32BIT (Handle->TransferRingOut.RingSeg0) | BIT0;
593 DebugCapabilityContext->EpOutContext.PtrHi = XHC_HIGH_32BIT (Handle->TransferRingOut.RingSeg0);
601 XHC_LOW_32BIT ((UINT64)(
UINTN)DebugCapabilityContext)
606 XHC_HIGH_32BIT ((UINT64)(
UINTN)DebugCapabilityContext)
623 volatile UINT32 Dcctrl;
626 if (Handle->Initialized == USB3DBG_DBG_CAB) {
632 TimeOut =
DivU64x32 (
PcdGet64 (PcdUsbXhciDebugDetectTimeout), XHC_POLL_DELAY) + 1;
640 if ((Dcctrl & BIT0) != 0) {
644 Handle->Ready =
TRUE;
650 }
while (TimeOut != 0);
668 RETURN_STATUS Status;
675 XhciOpRegister = Handle->XhciOpRegister;
676 TotalUsb3Port =
MmioRead32 (((
UINTN)Handle->XhciMmioBase + XHC_HCSPARAMS1_OFFSET)) >> 24;
678 if (Handle->Initialized == USB3DBG_NOT_ENABLED) {
680 if (Dcddi1 != (UINT32)((XHCI_DEBUG_DEVICE_VENDOR_ID << 16) | XHCI_DEBUG_DEVICE_PROTOCOL)) {
684 return EFI_DEVICE_ERROR;
699 Buffer =
AllocateAlignBuffer (XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2 + USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE);
700 if (Buffer ==
NULL) {
710 for (Index = 0; Index < TotalUsb3Port; Index++) {
718 if ((
XhcReadDebugReg (Handle, XHC_DC_DCCTRL) & (BIT1|BIT31)) == (BIT1|BIT31)) {
727 Handle->UrbOut.Data = Handle->UrbIn.Data + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2;
748 (UINT32)((XHCI_DEBUG_DEVICE_VENDOR_ID << 16) | XHCI_DEBUG_DEVICE_PROTOCOL)
754 (UINT32)((XHCI_DEBUG_DEVICE_REVISION << 16) | XHCI_DEBUG_DEVICE_PRODUCT_ID)
758 if ((Handle->Initialized == USB3DBG_NOT_ENABLED) && (!Handle->ChangePortPower)) {
763 for (Index = 0; Index < TotalUsb3Port; Index++) {
768 Handle->ChangePortPower =
TRUE;
780 if (!Handle->Ready) {
781 Handle->Initialized = USB3DBG_NOT_ENABLED;
784 Handle->Initialized = USB3DBG_ENABLED;
808 Handle->XhciMmioBase = XhciMmioBase;
833 ASSERT (AddrPtr !=
NULL);
850 ASSERT (AddrPtr !=
NULL);
877 IN DEBUG_PORT_HANDLE Handle,
887 if ((NumberOfBytes != 1) || (Buffer ==
NULL) || (Timeout != 0)) {
895 if (Handle !=
NULL) {
902 if (UsbDebugPortHandle ==
NULL) {
906 if (UsbDebugPortHandle->InNotify) {
912 if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
916 Data = (UINT8 *)(
UINTN)UsbDebugPortHandle->Data;
921 if (UsbDebugPortHandle->DataCount < 1) {
926 for (Index = 0; Index < UsbDebugPortHandle->DataCount - 1; Index++) {
927 if ((Index + 1) >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
931 Data[Index] = Data[Index + 1];
934 UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1);
959 IN DEBUG_PORT_HANDLE Handle,
968 if ((NumberOfBytes == 0) || (Buffer ==
NULL)) {
979 if (Handle !=
NULL) {
986 if (UsbDebugPortHandle ==
NULL) {
990 if (UsbDebugPortHandle->InNotify) {
996 if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
1006 while ((Total < NumberOfBytes)) {
1007 if (NumberOfBytes - Total > USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE) {
1008 Sent = USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE;
1010 Sent = (UINT8)(NumberOfBytes - Total);
1013 XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataOut, Buffer + Total, &Sent, DATA_TRANSFER_WRITE_TIMEOUT);
1036 IN DEBUG_PORT_HANDLE Handle
1046 if (Handle !=
NULL) {
1053 if (UsbDebugPortHandle ==
NULL) {
1057 if (UsbDebugPortHandle->InNotify) {
1063 if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
1071 if (UsbDebugPortHandle->DataCount != 0) {
1078 Length = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
1079 XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, (VOID *)(
UINTN)UsbDebugPortHandle->Data, &Length, DATA_TRANSFER_POLL_TIMEOUT);
1081 if (Length > XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
1092 UsbDebugPortHandle->DataCount = (UINT8)Length;
1134 if ((Function ==
NULL) && (Context !=
NULL)) {
1136 return (DEBUG_PORT_HANDLE)Context;
1140 if (UsbDebugPortHandle ==
NULL) {
1146 if (Function !=
NULL) {
1147 Function (Context, (DEBUG_PORT_HANDLE)UsbDebugPortHandle);
1150 return (DEBUG_PORT_HANDLE)UsbDebugPortHandle;
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID(EFIAPI * DEBUG_PORT_CONTINUE)(IN VOID *Context, IN DEBUG_PORT_HANDLE DebugPortHandle)
VOID CreateTransferRing(IN USB3_DEBUG_PORT_HANDLE *Handle, IN UINT32 TrbNum, OUT TRANSFER_RING *TransferRing)
RETURN_STATUS EFIAPI CalculateUsbDebugPortMmioBase(USB3_DEBUG_PORT_HANDLE *Handle)
VOID XhcSetDebugRegBit(IN USB3_DEBUG_PORT_HANDLE *Handle, IN UINT32 Offset, IN UINT32 Bit)
VOID XhcDetectDebugCapabilityReady(IN USB3_DEBUG_PORT_HANDLE *Handle)
VOID XhcClearR32Bit(IN OUT UINTN Register, IN UINT32 BitMask)
USB3_DEBUG_PORT_HANDLE * GetUsb3DebugPortInstance(VOID)
DEBUG_PORT_HANDLE EFIAPI DebugPortInitialize(IN VOID *Context, IN DEBUG_PORT_CONTINUE Function)
UINTN EFIAPI DebugPortReadBuffer(IN DEBUG_PORT_HANDLE Handle, IN UINT8 *Buffer, IN UINTN NumberOfBytes, IN UINTN Timeout)
EFI_STATUS CreateDebugCapabilityContext(IN USB3_DEBUG_PORT_HANDLE *Handle)
VOID SetUsb3DebugPortInstance(IN USB3_DEBUG_PORT_HANDLE *Instance)
VOID XhcSetR32Bit(IN OUT UINTN Register, IN UINT32 BitMask)
UINT32 XhcReadDebugReg(IN USB3_DEBUG_PORT_HANDLE *Handle, IN UINT32 Offset)
EFI_PHYSICAL_ADDRESS ProgramXhciBaseAddress(VOID)
BOOLEAN EFIAPI DebugPortPollBuffer(IN DEBUG_PORT_HANDLE Handle)
EFI_STATUS CreateEventRing(IN USB3_DEBUG_PORT_HANDLE *Handle, OUT EVENT_RING *EventRing)
VOID UpdateXhcResource(IN OUT USB3_DEBUG_PORT_HANDLE *Handle, IN EFI_PHYSICAL_ADDRESS XhciMmioBase)
VOID XhcClearDebugRegBit(IN USB3_DEBUG_PORT_HANDLE *Handle, IN UINT32 Offset, IN UINT32 Bit)
VOID XhcWriteDebugReg(IN USB3_DEBUG_PORT_HANDLE *Handle, IN UINT32 Offset, IN UINT32 Data)
RETURN_STATUS EFIAPI InitializeUsbDebugHardware(IN USB3_DEBUG_PORT_HANDLE *Handle)
VOID DiscoverInitializeUsbDebugPort(IN USB3_DEBUG_PORT_HANDLE *Handle)
UINTN EFIAPI DebugPortWriteBuffer(IN DEBUG_PORT_HANDLE Handle, IN UINT8 *Buffer, IN UINTN NumberOfBytes)
BOOLEAN EFIAPI NeedReinitializeHardware(IN USB3_DEBUG_PORT_HANDLE *Handle)
VOID * AllocateAlignBuffer(IN UINTN BufferSize)
EFI_PHYSICAL_ADDRESS * GetUsb3DebugPortInstanceAddrPtr(VOID)
EFI_STATUS EFIAPI XhcDataTransfer(IN USB3_DEBUG_PORT_HANDLE *Handle, IN EFI_USB_DATA_DIRECTION Direction, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN UINTN Timeout)
UINT8 EFIAPI MmioRead8(IN UINTN Address)
UINT32 EFIAPI MmioRead32(IN UINTN Address)
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
#define RETURN_ERROR(StatusCode)
#define RETURN_UNSUPPORTED
#define ASSERT_EFI_ERROR(StatusParameter)
UINT32 EFIAPI PciRead32(IN UINTN Address)
UINT8 EFIAPI PciRead8(IN UINTN Address)
UINT32 EFIAPI PciWrite32(IN UINTN Address, IN UINT32 Value)
UINT16 EFIAPI PciWrite16(IN UINTN Address, IN UINT16 Value)
UINT16 EFIAPI PciRead16(IN UINTN Address)
#define PcdGet16(TokenName)
#define PcdGet64(TokenName)
#define PcdGet32(TokenName)
#define EFI_PCI_COMMAND_MEMORY_SPACE
0x0002
#define EFI_PCI_COMMAND_BUS_MASTER
0x0004
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
UINT64 EFI_PHYSICAL_ADDRESS