/* Wait for the env to be ready for execute specified TRB. */
EFI_STATUS EmmcPeimWaitTrbEnv(IN UINTN Bar, IN EMMC_TRB *Trb)
/* Wait for the env to be ready for execute specified TRB. */
EFI_STATUS EmmcPeimWaitTrbEnv(IN UINTN Bar, IN EMMC_TRB *Trb)
{
  EFI_STATUS           Status;
  EMMC_COMMAND_PACKET  *Packet;
  UINT64               Timeout;
  BOOLEAN              InfiniteWait;
  Packet  = Trb->Packet;
  Timeout = Packet->Timeout;
  if (Timeout == 0) {
    InfiniteWait = TRUE;
  } else {
    InfiniteWait = FALSE;
  }
  while (InfiniteWait || (Timeout > 0)) {
    Status = EmmcPeimCheckTrbEnv (Bar, Trb);
    if (Status != EFI_NOT_READY) {
      return Status;
    }
    MicroSecondDelay (1);
    Timeout--;
  }
  return EFI_TIMEOUT;
}