/* Wait for the env to be ready for execute specified TRB. */
EFI_STATUS SdMmcWaitTrbEnv(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
/* Wait for the env to be ready for execute specified TRB. */
EFI_STATUS SdMmcWaitTrbEnv(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
{
  EFI_STATUS                           Status;
  EFI_SD_MMC_PASS_THRU_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 = SdMmcCheckTrbEnv (Private, Trb);
    if (Status != EFI_NOT_READY) {
      return Status;
    }
    gBS->Stall (1);
    Timeout--;
  }
  return EFI_TIMEOUT;
}