]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
ArmPkg/ArmMmuLib: drop pointless LookupAddresstoRootTable() routine
[mirror_edk2.git] / ArmPkg / Library / ArmMmuLib / AArch64 / ArmMmuLibCore.c
index d16e847218b7495c871675e289a561485ac02241..b6f3ef54aa26aa72bb98e7c7843ca9389e3bbf66 100644 (file)
@@ -59,6 +59,16 @@ ArmMemoryAttributeToPageAttribute (
 \r
 #define MIN_T0SZ        16\r
 #define BITS_PER_LEVEL  9\r
+#define MAX_VA_BITS     48\r
+\r
+STATIC\r
+UINTN\r
+GetRootTableEntryCount (\r
+  IN  UINTN T0SZ\r
+  )\r
+{\r
+  return TT_ENTRY_COUNT >> (T0SZ - MIN_T0SZ) % BITS_PER_LEVEL;\r
+}\r
 \r
 VOID\r
 GetRootTranslationTableInfo (\r
@@ -284,36 +294,6 @@ UpdateRegionMappingRecursive (
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
-VOID\r
-LookupAddresstoRootTable (\r
-  IN  UINT64  MaxAddress,\r
-  OUT UINTN  *T0SZ,\r
-  OUT UINTN  *TableEntryCount\r
-  )\r
-{\r
-  UINTN TopBit;\r
-\r
-  // Check the parameters are not NULL\r
-  ASSERT ((T0SZ != NULL) && (TableEntryCount != NULL));\r
-\r
-  // Look for the highest bit set in MaxAddress\r
-  for (TopBit = 63; TopBit != 0; TopBit--) {\r
-    if ((1ULL << TopBit) & MaxAddress) {\r
-      // MaxAddress top bit is found\r
-      TopBit = TopBit + 1;\r
-      break;\r
-    }\r
-  }\r
-  ASSERT (TopBit != 0);\r
-\r
-  // Calculate T0SZ from the top bit of the MaxAddress\r
-  *T0SZ = 64 - TopBit;\r
-\r
-  // Get the Table info from T0SZ\r
-  GetRootTranslationTableInfo (*T0SZ, NULL, TableEntryCount);\r
-}\r
-\r
 STATIC\r
 EFI_STATUS\r
 UpdateRegionMapping (\r
@@ -508,6 +488,7 @@ ArmConfigureMmu (
   )\r
 {\r
   VOID*                         TranslationTable;\r
+  UINTN                         MaxAddressBits;\r
   UINT64                        MaxAddress;\r
   UINTN                         T0SZ;\r
   UINTN                         RootTableEntryCount;\r
@@ -526,11 +507,11 @@ ArmConfigureMmu (
   // into account the architectural limitations that result from UEFI's\r
   // use of 4 KB pages.\r
   //\r
-  MaxAddress = MIN (LShiftU64 (1ULL, ArmGetPhysicalAddressBits ()) - 1,\r
-                    MAX_ALLOC_ADDRESS);\r
+  MaxAddressBits = MIN (ArmGetPhysicalAddressBits (), MAX_VA_BITS);\r
+  MaxAddress = LShiftU64 (1ULL, MaxAddressBits) - 1;\r
 \r
-  // Lookup the Table Level to get the information\r
-  LookupAddresstoRootTable (MaxAddress, &T0SZ, &RootTableEntryCount);\r
+  T0SZ = 64 - MaxAddressBits;\r
+  RootTableEntryCount = GetRootTableEntryCount (T0SZ);\r
 \r
   //\r
   // Set TCR that allows us to retrieve T0SZ in the subsequent functions\r