]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmMmuLib AARCH64: use helpers to determine table entry types
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Sat, 7 Mar 2020 11:44:16 +0000 (12:44 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 26 Mar 2020 10:34:14 +0000 (10:34 +0000)
Given how the meaning of the attribute bits for page table entry types
is slightly awkward, and changes between levels, add some helpers to
abstract from this.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
Reviewed-by: Ashish Singhal <ashishsingha@nvidia.com>
Tested-by: Ashish Singhal <ashishsingha@nvidia.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

index d78918cf7ba80f0c0837aaddfee50b78fa2b36e6..0680ba36d9079f47024b519101c6ce6acf2b2289 100644 (file)
@@ -162,6 +162,36 @@ FreePageTablesRecursive (
   FreePages (TranslationTable, 1);\r
 }\r
 \r
+STATIC\r
+BOOLEAN\r
+IsBlockEntry (\r
+  IN  UINT64  Entry,\r
+  IN  UINTN   Level\r
+  )\r
+{\r
+  if (Level == 3) {\r
+    return (Entry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY_LEVEL3;\r
+  }\r
+  return (Entry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY;\r
+}\r
+\r
+STATIC\r
+BOOLEAN\r
+IsTableEntry (\r
+  IN  UINT64  Entry,\r
+  IN  UINTN   Level\r
+  )\r
+{\r
+  if (Level == 3) {\r
+    //\r
+    // TT_TYPE_TABLE_ENTRY aliases TT_TYPE_BLOCK_ENTRY_LEVEL3\r
+    // so we need to take the level into account as well.\r
+    //\r
+    return FALSE;\r
+  }\r
+  return (Entry & TT_TYPE_MASK) == TT_TYPE_TABLE_ENTRY;\r
+}\r
+\r
 STATIC\r
 EFI_STATUS\r
 UpdateRegionMappingRecursive (\r
@@ -203,7 +233,7 @@ UpdateRegionMappingRecursive (
     if (Level == 0 || ((RegionStart | BlockEnd) & BlockMask) != 0) {\r
       ASSERT (Level < 3);\r
 \r
-      if ((*Entry & TT_TYPE_MASK) != TT_TYPE_TABLE_ENTRY) {\r
+      if (!IsTableEntry (*Entry, Level)) {\r
         //\r
         // No table entry exists yet, so we need to allocate a page table\r
         // for the next level.\r
@@ -221,7 +251,7 @@ UpdateRegionMappingRecursive (
           InvalidateDataCacheRange (TranslationTable, EFI_PAGE_SIZE);\r
         }\r
 \r
-        if ((*Entry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY) {\r
+        if (IsBlockEntry (*Entry, Level)) {\r
           //\r
           // We are splitting an existing block entry, so we have to populate\r
           // the new table with the attributes of the block entry it replaces.\r
@@ -252,7 +282,7 @@ UpdateRegionMappingRecursive (
                  AttributeSetMask, AttributeClearMask, TranslationTable,\r
                  Level + 1);\r
       if (EFI_ERROR (Status)) {\r
-        if ((*Entry & TT_TYPE_MASK) != TT_TYPE_TABLE_ENTRY) {\r
+        if (!IsTableEntry (*Entry, Level)) {\r
           //\r
           // We are creating a new table entry, so on failure, we can free all\r
           // allocations we made recursively, given that the whole subhierarchy\r
@@ -265,10 +295,10 @@ UpdateRegionMappingRecursive (
         return Status;\r
       }\r
 \r
-      if ((*Entry & TT_TYPE_MASK) != TT_TYPE_TABLE_ENTRY) {\r
+      if (!IsTableEntry (*Entry, Level)) {\r
         EntryValue = (UINTN)TranslationTable | TT_TYPE_TABLE_ENTRY;\r
         ReplaceTableEntry (Entry, EntryValue, RegionStart,\r
-                           (*Entry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY);\r
+          IsBlockEntry (*Entry, Level));\r
       }\r
     } else {\r
       EntryValue = (*Entry & AttributeClearMask) | AttributeSetMask;\r