/* Traverse the attached ATA devices list to find out the device with given index. */
PEI_AHCI_ATA_DEVICE_DATA* SearchDeviceByIndex(IN PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private, IN UINTN DeviceIndex)
/* Traverse the attached ATA devices list to find out the device with given index. */
PEI_AHCI_ATA_DEVICE_DATA* SearchDeviceByIndex(IN PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private, IN UINTN DeviceIndex)
{
  PEI_AHCI_ATA_DEVICE_DATA  *DeviceData;
  LIST_ENTRY                *Node;
  if ((DeviceIndex == 0) || (DeviceIndex > Private->ActiveDevices)) {
    return NULL;
  }
  Node = GetFirstNode (&Private->DeviceList);
  while (!IsNull (&Private->DeviceList, Node)) {
    DeviceData = AHCI_PEI_ATA_DEVICE_INFO_FROM_THIS (Node);
    if (DeviceData->DeviceIndex == DeviceIndex) {
      return DeviceData;
    }
    Node = GetNextNode (&Private->DeviceList, Node);
  }
  return NULL;
}