/* Read specified bytes from Lba from the device. */
EFI_STATUS AhciRead(IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData, OUT VOID *Buffer, IN EFI_LBA StartLba, IN UINTN BufferSize)
/* Read specified bytes from Lba from the device. */
EFI_STATUS AhciRead(IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData, OUT VOID *Buffer, IN EFI_LBA StartLba, IN UINTN BufferSize)
{
  EFI_STATUS  Status;
  UINTN       BlockSize;
  UINTN       NumberOfBlocks;
  if (Buffer == NULL) {
    return EFI_INVALID_PARAMETER;
  }
  if (BufferSize == 0) {
    return EFI_SUCCESS;
  }
  BlockSize = DeviceData->Media.BlockSize;
  if ((BufferSize % BlockSize) != 0) {
    return EFI_BAD_BUFFER_SIZE;
  }
  if (StartLba > DeviceData->Media.LastBlock) {
    return EFI_INVALID_PARAMETER;
  }
  NumberOfBlocks = BufferSize / BlockSize;
  if (NumberOfBlocks - 1 > DeviceData->Media.LastBlock - StartLba) {
    return EFI_INVALID_PARAMETER;
  }
  Status = AccessAtaDevice (DeviceData, Buffer, StartLba, NumberOfBlocks);
  return Status;
}