/* Retrieve the AddrTranslationOffset from RootBridgeIo for the specified range. */
UINT64 GetMmioAddressTranslationOffset(EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *RootBridgeIo, UINT64 AddrRangeMin, UINT64 AddrLen)
/* Retrieve the AddrTranslationOffset from RootBridgeIo for the specified range. */
UINT64 GetMmioAddressTranslationOffset(EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *RootBridgeIo, UINT64 AddrRangeMin, UINT64 AddrLen)
{
  EFI_STATUS                         Status;
  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR  *Configuration;
  Status = RootBridgeIo->Configuration (
                           RootBridgeIo,
                           (VOID **)&Configuration
                           );
  if (EFI_ERROR (Status)) {
    return (UINT64)-1;
  }
  while (Configuration->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {
    if ((Configuration->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) &&
        (Configuration->AddrRangeMin + Configuration->AddrTranslationOffset <= AddrRangeMin) &&
        (Configuration->AddrRangeMin + Configuration->AddrLen + Configuration->AddrTranslationOffset >= AddrRangeMin + AddrLen)
        )
    {
      return Configuration->AddrTranslationOffset;
    }
    Configuration++;
  }
  ASSERT (FALSE);
  return (UINT64)-1;
}