/* Detect if an IDE controller exists in specified position. */
BOOLEAN DetectIDEController(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition)
/* Detect if an IDE controller exists in specified position. */
BOOLEAN DetectIDEController(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition)
{
  UINT8       Channel;
  EFI_STATUS  Status;
  UINT8       AtaCommand;
  Channel = (UINT8)(DevicePosition / 2);
  ASSERT (Channel < MAX_IDE_CHANNELS);
  Status = WaitForBSYClear (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), 31000);
  if (EFI_ERROR (Status)) {
    return FALSE;
  }
  AtaCommand = 0xE5;
  Status     = CheckPowerMode (AtapiBlkIoDev, DevicePosition, AtaCommand);
  if ((Status == EFI_ABORTED) || (Status == EFI_SUCCESS)) {
    return TRUE;
  }
  return FALSE;
}