/* Get the specified port number from a port bitmap. */
EFI_STATUS AhciGetPortFromMap(IN UINT32 PortBitMap, IN UINT8 PortIndex, OUT UINT8 *Port)
/* Get the specified port number from a port bitmap. */
EFI_STATUS AhciGetPortFromMap(IN UINT32 PortBitMap, IN UINT8 PortIndex, OUT UINT8 *Port)
{
  if (PortIndex == 0) {
    return EFI_NOT_FOUND;
  }
  *Port = 0;
  while (PortBitMap != 0) {
    if ((PortBitMap & ((UINT32)BIT0)) != 0) {
      PortIndex--;
      if (PortIndex == 0) {
        return EFI_SUCCESS;
      }
    }
    PortBitMap = PortBitMap >> 1;
    *Port      = *Port + 1;
  }
  return EFI_NOT_FOUND;
}