/* Wait specified time interval to poll for BSY bit clear in the Status Register. */
EFI_STATUS WaitForBSYClear(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
/* Wait specified time interval to poll for BSY bit clear in the Status Register. */
EFI_STATUS WaitForBSYClear(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
{
  UINTN   Delay;
  UINT16  StatusRegister;
  UINT8   StatusValue;
  StatusValue = 0;
  StatusRegister = IdeIoRegisters->Reg.Status;
  Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1;
  do {
    StatusValue = IoRead8 (StatusRegister);
    if ((StatusValue & ATA_STSREG_BSY) == 0x00) {
      break;
    }
    MicroSecondDelay (250);
    Delay--;
  } while (Delay != 0);
  if (Delay == 0) {
    return EFI_TIMEOUT;
  }
  return EFI_SUCCESS;
}