30 ASSERT (TrsRing !=
NULL);
37 ASSERT (TrsTrb !=
NULL);
39 for (Index = 0; Index < TrsRing->TrbNumber; Index++) {
40 if (TrsTrb->CycleBit != (TrsRing->RingPCS & BIT0)) {
45 if ((UINT8)TrsTrb->Type == TRB_TYPE_LINK) {
46 ASSERT (((
LINK_TRB *)TrsTrb)->TC != 0);
50 ((
LINK_TRB *)TrsTrb)->CycleBit = TrsRing->RingPCS & BIT0;
54 TrsRing->RingPCS = (TrsRing->RingPCS & BIT0) ? 0 : 1;
59 ASSERT (Index != TrsRing->TrbNumber);
68 CycleBit = TrsTrb->CycleBit;
70 TrsTrb->CycleBit = CycleBit;
94 ASSERT (EvtRing !=
NULL);
102 for (Index = 0; Index < EvtRing->TrbNumber; Index++) {
103 if (EvtTrb1->CycleBit != EvtRing->EventRingCCS) {
111 EvtRing->EventRingCCS = (EvtRing->EventRingCCS) ? 0 : 1;
115 if (Index < EvtRing->TrbNumber) {
145 ASSERT (EvtRing !=
NULL);
149 if (EvtRing->EventRingDequeue == EvtRing->EventRingEnqueue) {
150 return EFI_NOT_READY;
159 if ((
UINTN)EvtRing->EventRingDequeue >= ((
UINTN)EvtRing->EventRingSeg0 + sizeof (
TRB_TEMPLATE) * EvtRing->TrbNumber)) {
160 EvtRing->EventRingDequeue = EvtRing->EventRingSeg0;
187 ASSERT (Ring->TrbNumber == TR_RING_TRB_NUMBER);
189 for (Index = 0; Index < Ring->TrbNumber; Index++) {
190 if (Trb == CheckedTrb) {
223 ASSERT ((Handle !=
NULL) && (Urb !=
NULL));
236 for (Index = 0; Index < Handle->EventRing.TrbNumber; Index++) {
238 if (Status == EFI_NOT_READY) {
245 if ((EvtTrb->Type != TRB_TYPE_COMMAND_COMPLT_EVENT) && (EvtTrb->Type != TRB_TYPE_TRANS_EVENT)) {
258 Handle->DataCount = (UINT8)(Handle->UrbIn.DataLen - EvtTrb->Length);
259 CopyMem ((VOID *)(
UINTN)Handle->Data, (VOID *)(
UINTN)Handle->UrbIn.Data, Handle->DataCount);
263 TRBPtr->CycleBit = (TRBPtr->CycleBit & BIT0) ? 0 : 1;
269 if ((EvtTrb->Completecode == TRB_COMPLETION_SHORT_PACKET) ||
270 (EvtTrb->Completecode == TRB_COMPLETION_SUCCESS))
277 CheckedUrb->Result |= EFI_USB_ERR_TIMEOUT;
283 CheckedUrb->Finished =
TRUE;
295 XhcDequeue = (UINT64)(
LShiftU64 ((UINT64)High, 32) | Low);
297 if ((XhcDequeue & (~0x0F)) != ((UINT64)(
UINTN)Handle->EventRing.EventRingDequeue & (~0x0F))) {
302 XhcWriteDebugReg (Handle, XHC_DC_DCERDP, XHC_LOW_32BIT (Handle->EventRing.EventRingDequeue));
303 XhcWriteDebugReg (Handle, XHC_DC_DCERDP + 4, XHC_HIGH_32BIT (Handle->EventRing.EventRingDequeue));
328 Dcdb = (Urb->Direction == EfiUsbDataIn) ? 0x100 : 0x0;
359 Loop = Timeout / XHC_DEBUG_PORT_1_MILLISECOND;
368 for (Index = 0; Index < Loop; Index++) {
381 Urb->Result |= EFI_USB_ERR_TIMEOUT;
389 if ((Urb->Result != EFI_USB_NOERROR) && (Urb->Direction == EfiUsbDataIn)) {
393 Ring->RingEnqueue = Urb->Trb;
398 Trb->CycleBit = ((~Ring->RingPCS) & BIT0);
425 if (Urb->Direction == EfiUsbDataIn) {
426 EPRing = &Handle->TransferRingIn;
428 EPRing = &Handle->TransferRingOut;
434 Urb->Trb = EPRing->RingEnqueue;
435 Trb = (
TRB *)(
UINTN)EPRing->RingEnqueue;
436 Trb->TrbNormal.TRBPtrLo = XHC_LOW_32BIT (Urb->Data);
437 Trb->TrbNormal.TRBPtrHi = XHC_HIGH_32BIT (Urb->Data);
438 Trb->TrbNormal.Length = Urb->DataLen;
439 Trb->TrbNormal.TDSize = 0;
440 Trb->TrbNormal.IntTarget = 0;
441 Trb->TrbNormal.ISP = 1;
442 Trb->TrbNormal.IOC = 1;
443 Trb->TrbNormal.Type = TRB_TYPE_NORMAL;
448 Trb->TrbNormal.CycleBit = EPRing->RingPCS & BIT0;
476 if (Direction == EfiUsbDataIn) {
477 Urb = &Handle->UrbIn;
479 Urb = &Handle->UrbOut;
485 Urb->Direction = Direction;
494 if (Direction == EfiUsbDataIn) {
498 Urb->DataLen = (UINT32)DataLen;
505 Urb->DataLen = (UINT32)DataLen;
548 if ((DataLength ==
NULL) || (*DataLength == 0) || (Data ==
NULL)) {
549 return EFI_INVALID_PARAMETER;
556 Urb =
XhcCreateUrb (Handle, Direction, Data, *DataLength);
557 ASSERT (Urb !=
NULL);
564 if (Urb->Completed > *DataLength) {
565 return EFI_DEVICE_ERROR;
568 *DataLength = Urb->Completed;
570 Status = EFI_TIMEOUT;
571 if (Urb->Result == EFI_USB_NOERROR) {
575 if (Direction == EfiUsbDataIn) {
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
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)
UINT32 XhcReadDebugReg(IN USB3_DEBUG_PORT_HANDLE *Handle, IN UINT32 Offset)
VOID XhcWriteDebugReg(IN USB3_DEBUG_PORT_HANDLE *Handle, IN UINT32 Offset, IN UINT32 Data)
URB * XhcCreateUrb(IN USB3_DEBUG_PORT_HANDLE *Handle, IN EFI_USB_DATA_DIRECTION Direction, IN VOID *Data, IN UINTN DataLen)
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)
EFI_STATUS XhcCreateTransferTrb(IN USB3_DEBUG_PORT_HANDLE *Handle, IN URB *Urb)
EFI_STATUS EFIAPI XhcRingDoorBell(IN USB3_DEBUG_PORT_HANDLE *Handle, IN URB *Urb)
BOOLEAN IsTrbInTrsRing(IN TRANSFER_RING *Ring, IN TRB_TEMPLATE *Trb)
VOID XhcCheckUrbResult(IN USB3_DEBUG_PORT_HANDLE *Handle, IN URB *Urb)
VOID XhcExecTransfer(IN USB3_DEBUG_PORT_HANDLE *Handle, IN URB *Urb, IN UINTN Timeout)
EFI_STATUS EFIAPI XhcCheckNewEvent(IN USB3_DEBUG_PORT_HANDLE *Handle, IN EVENT_RING *EvtRing, OUT TRB_TEMPLATE **NewEvtTrb)
EFI_STATUS EFIAPI XhcSyncTrsRing(IN USB3_DEBUG_PORT_HANDLE *Handle, IN TRANSFER_RING *TrsRing)
EFI_STATUS EFIAPI XhcSyncEventRing(IN USB3_DEBUG_PORT_HANDLE *Handle, IN EVENT_RING *EvtRing)
#define ASSERT_EFI_ERROR(StatusParameter)
UINT64 EFI_PHYSICAL_ADDRESS