]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmMmuLib: permit initial configuration with MMU enabled
authorArd Biesheuvel <ardb@kernel.org>
Sat, 2 Jul 2022 13:14:28 +0000 (15:14 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 19 Oct 2022 09:07:13 +0000 (09:07 +0000)
Permit the use of this library with the MMU and caches already enabled.
This removes the need for any cache maintenance for coherency, and is
generally better for robustness and performance, especially when running
under virtualization.

Note that this means we have to defer assignment of TTBR0 until the
page tables are ready to be used, and so UpdateRegionMapping() can no
longer read back TTBR0 directly to discover the root table address.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Leif Lindholm <quic_llindhol@quicinc.com>
ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

index 4d75788ed2b2356180058d7e3b0a8d0d2e7c5503..ae59e9a7d04e34ba2e328b8afb246e668aea5493 100644 (file)
@@ -357,6 +357,7 @@ UpdateRegionMapping (
   IN  UINT64   RegionLength,\r
   IN  UINT64   AttributeSetMask,\r
   IN  UINT64   AttributeClearMask,\r
+  IN  UINT64   *RootTable,\r
   IN  BOOLEAN  TableIsLive\r
   )\r
 {\r
@@ -373,7 +374,7 @@ UpdateRegionMapping (
            RegionStart + RegionLength,\r
            AttributeSetMask,\r
            AttributeClearMask,\r
-           ArmGetTTBR0BaseAddress (),\r
+           RootTable,\r
            GetRootTableLevel (T0SZ),\r
            TableIsLive\r
            );\r
@@ -391,6 +392,7 @@ FillTranslationTable (
            MemoryRegion->Length,\r
            ArmMemoryAttributeToPageAttribute (MemoryRegion->Attributes) | TT_AF,\r
            0,\r
+           RootTable,\r
            FALSE\r
            );\r
 }\r
@@ -466,6 +468,7 @@ ArmSetMemoryAttributes (
            Length,\r
            PageAttributes,\r
            PageAttributeMask,\r
+           ArmGetTTBR0BaseAddress (),\r
            TRUE\r
            );\r
 }\r
@@ -484,6 +487,7 @@ SetMemoryRegionAttribute (
            Length,\r
            Attributes,\r
            BlockEntryMask,\r
+           ArmGetTTBR0BaseAddress (),\r
            TRUE\r
            );\r
 }\r
@@ -675,14 +679,6 @@ ArmConfigureMmu (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  //\r
-  // We set TTBR0 just after allocating the table to retrieve its location from\r
-  // the subsequent functions without needing to pass this value across the\r
-  // functions. The MMU is only enabled after the translation tables are\r
-  // populated.\r
-  //\r
-  ArmSetTTBR0 (TranslationTable);\r
-\r
   if (TranslationTableBase != NULL) {\r
     *TranslationTableBase = TranslationTable;\r
   }\r
@@ -691,14 +687,17 @@ ArmConfigureMmu (
     *TranslationTableSize = RootTableEntryCount * sizeof (UINT64);\r
   }\r
 \r
-  //\r
-  // Make sure we are not inadvertently hitting in the caches\r
-  // when populating the page tables.\r
-  //\r
-  InvalidateDataCacheRange (\r
-    TranslationTable,\r
-    RootTableEntryCount * sizeof (UINT64)\r
-    );\r
+  if (!ArmMmuEnabled ()) {\r
+    //\r
+    // Make sure we are not inadvertently hitting in the caches\r
+    // when populating the page tables.\r
+    //\r
+    InvalidateDataCacheRange (\r
+      TranslationTable,\r
+      RootTableEntryCount * sizeof (UINT64)\r
+      );\r
+  }\r
+\r
   ZeroMem (TranslationTable, RootTableEntryCount * sizeof (UINT64));\r
 \r
   while (MemoryTable->Length != 0) {\r
@@ -723,12 +722,17 @@ ArmConfigureMmu (
     MAIR_ATTR (TT_ATTR_INDX_MEMORY_WRITE_BACK, MAIR_ATTR_NORMAL_MEMORY_WRITE_BACK)\r
     );\r
 \r
-  ArmDisableAlignmentCheck ();\r
-  ArmEnableStackAlignmentCheck ();\r
-  ArmEnableInstructionCache ();\r
-  ArmEnableDataCache ();\r
+  ArmSetTTBR0 (TranslationTable);\r
+\r
+  if (!ArmMmuEnabled ()) {\r
+    ArmDisableAlignmentCheck ();\r
+    ArmEnableStackAlignmentCheck ();\r
+    ArmEnableInstructionCache ();\r
+    ArmEnableDataCache ();\r
+\r
+    ArmEnableMmu ();\r
+  }\r
 \r
-  ArmEnableMmu ();\r
   return EFI_SUCCESS;\r
 \r
 FreeTranslationTable:\r