]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmMmuLib: drop pointless LookupAddresstoRootTable() routine
authorArd Biesheuvel <ard.biesheuvel@arm.com>
Tue, 31 Mar 2020 17:25:02 +0000 (19:25 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 2 Apr 2020 12:35:52 +0000 (12:35 +0000)
LookupAddresstoRootTable() uses a loop to go over its MaxAddress
argument, essentially to do a log2() and determine how many bits are
needed to represent it. Since the argument is the result of a shift-left
expression, there is some room for improvement here, and we can simply
use the bit count directly to calculate the value of T0SZ. At the same
time, we can omit calling GetRootTranslationTableInfo() to determine the
number of root table entries, and add a new helper that applies the
trivial calculation directly.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
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