/* Synchronize the specified event ring to update the enqueue and dequeue pointer. */
EFI_STATUS XhcPeiSyncEventRing(IN PEI_XHC_DEV *Xhc, IN EVENT_RING *EvtRing)
/* Synchronize the specified event ring to update the enqueue and dequeue pointer. */
EFI_STATUS XhcPeiSyncEventRing(IN PEI_XHC_DEV *Xhc, IN EVENT_RING *EvtRing)
{
  UINTN         Index;
  TRB_TEMPLATE  *EvtTrb;
  ASSERT (EvtRing != NULL);
  EvtTrb = EvtRing->EventRingDequeue;
  for (Index = 0; Index < EvtRing->TrbNumber; Index++) {
    if (EvtTrb->CycleBit != EvtRing->EventRingCCS) {
      break;
    }
    EvtTrb++;
    if ((UINTN)EvtTrb >= ((UINTN)EvtRing->EventRingSeg0 + sizeof (TRB_TEMPLATE) * EvtRing->TrbNumber)) {
      EvtTrb                = EvtRing->EventRingSeg0;
      EvtRing->EventRingCCS = (EvtRing->EventRingCCS) ? 0 : 1;
    }
  }
  if (Index < EvtRing->TrbNumber) {
    EvtRing->EventRingEnqueue = EvtTrb;
  } else {
    ASSERT (FALSE);
  }
  return EFI_SUCCESS;
}