/* This function retrieves a memory region starting from a given base address. */
EFI_STATUS GetMemoryRegion(IN OUT UINTN *BaseAddress, OUT UINTN *RegionLength, OUT UINTN *RegionAttributes)
/* This function retrieves a memory region starting from a given base address. */
EFI_STATUS GetMemoryRegion(IN OUT UINTN *BaseAddress, OUT UINTN *RegionLength, OUT UINTN *RegionAttributes)
{
  EFI_STATUS  Status;
  UINT64      *TranslationTable;
  UINTN       TableLevel;
  UINTN       EntryCount;
  UINTN       T0SZ;
  if ((BaseAddress == NULL) || (RegionLength == NULL) || (RegionAttributes == NULL)) {
    ASSERT ((BaseAddress != NULL) && (RegionLength != NULL) && (RegionAttributes != NULL));
    return EFI_INVALID_PARAMETER;
  }
  TranslationTable = ArmGetTTBR0BaseAddress ();
  *RegionLength     = 0;
  *RegionAttributes = 0;
  T0SZ = ArmGetTCR () & TCR_T0SZ_MASK;
  GetRootTranslationTableInfo (T0SZ, &TableLevel, &EntryCount);
  Status = GetMemoryRegionRec (
             TranslationTable,
             TableLevel,
             (UINTN *)TT_LAST_BLOCK_ADDRESS (TranslationTable, EntryCount),
             BaseAddress,
             RegionLength,
             RegionAttributes
             );
  if ((Status == EFI_NOT_FOUND) && (*RegionLength > 0)) {
    return EFI_SUCCESS;
  }
  return Status;
}