]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmMmuLib: deobfuscate GetRootTranslationTableInfo ()
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 9 Sep 2016 09:52:25 +0000 (10:52 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 13 Sep 2016 12:42:57 +0000 (13:42 +0100)
The relations between T0SZ, the number of translation levels and the
size/alignment of the root table can be expressed in simple arithmetic
expressions, so get rid of the lookup table.

Note that this disregards the fact that the maximum value of T0SZ is
39 not 42 (as one would expect for the smallest VA size using 2 levels)
but since this corresponds to a VA size of 32 MB and 4 MB, respectively,
neither of which are sufficient to run UEFI, we can safely ignore the
distinction.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

index 6e05e6085011a4bbbc8dd45d03173bc69d001532..84a689af7c8aef4f969d1a27c0084f6dfc5e9631 100644 (file)
@@ -121,20 +121,8 @@ GcdAttributeToArmAttribute (
   }\r
 }\r
 \r
   }\r
 }\r
 \r
-// Describe the T0SZ values for each translation table level\r
-typedef struct {\r
-  UINTN     MinT0SZ;\r
-  UINTN     MaxT0SZ;\r
-  UINTN     LargestT0SZ; // Generally (MaxT0SZ == LargestT0SZ) but at the Level3 Table\r
-                         // the MaxT0SZ is not at the boundary of the table\r
-} T0SZ_DESCRIPTION_PER_LEVEL;\r
-\r
-// Map table for the corresponding Level of Table\r
-STATIC CONST T0SZ_DESCRIPTION_PER_LEVEL T0SZPerTableLevel[] = {\r
-    { 16, 24, 24 }, // Table Level 0\r
-    { 25, 33, 33 }, // Table Level 1\r
-    { 34, 39, 42 }  // Table Level 2\r
-};\r
+#define MIN_T0SZ        16\r
+#define BITS_PER_LEVEL  9\r
 \r
 VOID\r
 GetRootTranslationTableInfo (\r
 \r
 VOID\r
 GetRootTranslationTableInfo (\r
@@ -143,28 +131,13 @@ GetRootTranslationTableInfo (
   OUT UINTN   *TableEntryCount\r
   )\r
 {\r
   OUT UINTN   *TableEntryCount\r
   )\r
 {\r
-  UINTN Index;\r
-\r
-  // Identify the level of the root table from the given T0SZ\r
-  for (Index = 0; Index < sizeof (T0SZPerTableLevel) / sizeof (T0SZ_DESCRIPTION_PER_LEVEL); Index++) {\r
-    if (T0SZ <= T0SZPerTableLevel[Index].MaxT0SZ) {\r
-      break;\r
-    }\r
-  }\r
-\r
-  // If we have not found the corresponding maximum T0SZ then we use the last one\r
-  if (Index == sizeof (T0SZPerTableLevel) / sizeof (T0SZ_DESCRIPTION_PER_LEVEL)) {\r
-    Index--;\r
-  }\r
-\r
   // Get the level of the root table\r
   if (TableLevel) {\r
   // Get the level of the root table\r
   if (TableLevel) {\r
-    *TableLevel = Index;\r
+    *TableLevel = (T0SZ - MIN_T0SZ) / BITS_PER_LEVEL;\r
   }\r
 \r
   }\r
 \r
-  // The Size of the Table is 2^(T0SZ-LargestT0SZ)\r
   if (TableEntryCount) {\r
   if (TableEntryCount) {\r
-    *TableEntryCount = 1 << (T0SZPerTableLevel[Index].LargestT0SZ - T0SZ + 1);\r
+    *TableEntryCount = 1UL << (BITS_PER_LEVEL - (T0SZ - MIN_T0SZ) % BITS_PER_LEVEL);\r
   }\r
 }\r
 \r
   }\r
 }\r
 \r