]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg: move ARM version of SetMemoryAttributes to ArmMmuLib
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 1 Mar 2017 16:31:40 +0000 (16:31 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 7 Mar 2017 08:38:08 +0000 (09:38 +0100)
... where it belongs, since AARCH64 already keeps it there, and
non DXE users of ArmMmuLib (such as DxeIpl, for the non-executable
stack) may need its functionality as well.

While at it, rename SetMemoryAttributes to ArmSetMemoryAttributes,
and make any functions that are not exported STATIC. Also, replace
an explicit gBS->AllocatePages() call [which is DXE specific] with
MemoryAllocationLib::AllocatePages().

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/Drivers/CpuDxe/Arm/Mmu.c
ArmPkg/Drivers/CpuDxe/CpuDxe.h
ArmPkg/Drivers/CpuDxe/CpuMmuCommon.c
ArmPkg/Include/Chipset/ArmV7Mmu.h
ArmPkg/Include/Library/ArmMmuLib.h
ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c

index d3c307f4831788a0bb4a4ba944957d97f743ae2a..12ca5b26673e834932e5a522d5e8b1e48943df39 100644 (file)
@@ -19,19 +19,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/MemoryAllocationLib.h>\r
 #include "CpuDxe.h"\r
 \r
-#define CACHE_ATTRIBUTE_MASK   (EFI_MEMORY_UC | \\r
-                                EFI_MEMORY_WC | \\r
-                                EFI_MEMORY_WT | \\r
-                                EFI_MEMORY_WB | \\r
-                                EFI_MEMORY_UCE | \\r
-                                EFI_MEMORY_WP)\r
-\r
-// First Level Descriptors\r
-typedef UINT32    ARM_FIRST_LEVEL_DESCRIPTOR;\r
-\r
-// Second Level Descriptors\r
-typedef UINT32    ARM_PAGE_TABLE_ENTRY;\r
-\r
 EFI_STATUS\r
 SectionToGcdAttributes (\r
   IN  UINT32  SectionAttributes,\r
@@ -350,403 +337,6 @@ SyncCacheConfig (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
-\r
-EFI_STATUS\r
-UpdatePageEntries (\r
-  IN  EFI_PHYSICAL_ADDRESS      BaseAddress,\r
-  IN  UINT64                    Length,\r
-  IN  UINT64                    Attributes,\r
-  IN  EFI_PHYSICAL_ADDRESS      VirtualMask,\r
-  OUT BOOLEAN                   *FlushTlbs OPTIONAL\r
-  )\r
-{\r
-  EFI_STATUS    Status;\r
-  UINT32        EntryValue;\r
-  UINT32        EntryMask;\r
-  UINT32        FirstLevelIdx;\r
-  UINT32        Offset;\r
-  UINT32        NumPageEntries;\r
-  UINT32        Descriptor;\r
-  UINT32        p;\r
-  UINT32        PageTableIndex;\r
-  UINT32        PageTableEntry;\r
-  UINT32        CurrentPageTableEntry;\r
-  VOID          *Mva;\r
-\r
-  volatile ARM_FIRST_LEVEL_DESCRIPTOR   *FirstLevelTable;\r
-  volatile ARM_PAGE_TABLE_ENTRY         *PageTable;\r
-\r
-  Status = EFI_SUCCESS;\r
-\r
-  // EntryMask: bitmask of values to change (1 = change this value, 0 = leave alone)\r
-  // EntryValue: values at bit positions specified by EntryMask\r
-  EntryMask = TT_DESCRIPTOR_PAGE_TYPE_MASK | TT_DESCRIPTOR_PAGE_AP_MASK;\r
-  if ((Attributes & EFI_MEMORY_XP) != 0) {\r
-    EntryValue = TT_DESCRIPTOR_PAGE_TYPE_PAGE_XN;\r
-  } else {\r
-    EntryValue = TT_DESCRIPTOR_PAGE_TYPE_PAGE;\r
-  }\r
-\r
-  // Although the PI spec is unclear on this, the GCD guarantees that only\r
-  // one Attribute bit is set at a time, so the order of the conditionals below\r
-  // is irrelevant. If no memory attribute is specified, we preserve whatever\r
-  // memory type is set in the page tables, and update the permission attributes\r
-  // only.\r
-  if (Attributes & EFI_MEMORY_UC) {\r
-    // modify cacheability attributes\r
-    EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;\r
-    // map to strongly ordered\r
-    EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED; // TEX[2:0] = 0, C=0, B=0\r
-  } else if (Attributes & EFI_MEMORY_WC) {\r
-    // modify cacheability attributes\r
-    EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;\r
-    // map to normal non-cachable\r
-    EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE; // TEX [2:0]= 001 = 0x2, B=0, C=0\r
-  } else if (Attributes & EFI_MEMORY_WT) {\r
-    // modify cacheability attributes\r
-    EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;\r
-    // write through with no-allocate\r
-    EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC; // TEX [2:0] = 0, C=1, B=0\r
-  } else if (Attributes & EFI_MEMORY_WB) {\r
-    // modify cacheability attributes\r
-    EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;\r
-    // write back (with allocate)\r
-    EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC; // TEX [2:0] = 001, C=1, B=1\r
-  } else if (Attributes & CACHE_ATTRIBUTE_MASK) {\r
-    // catch unsupported memory type attributes\r
-    ASSERT (FALSE);\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  if ((Attributes & EFI_MEMORY_RO) != 0) {\r
-    EntryValue |= TT_DESCRIPTOR_PAGE_AP_RO_RO;\r
-  } else {\r
-    EntryValue |= TT_DESCRIPTOR_PAGE_AP_RW_RW;\r
-  }\r
-\r
-  // Obtain page table base\r
-  FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();\r
-\r
-  // Calculate number of 4KB page table entries to change\r
-  NumPageEntries = Length / TT_DESCRIPTOR_PAGE_SIZE;\r
-\r
-  // Iterate for the number of 4KB pages to change\r
-  Offset = 0;\r
-  for(p = 0; p < NumPageEntries; p++) {\r
-    // Calculate index into first level translation table for page table value\r
-\r
-    FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress + Offset) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;\r
-    ASSERT (FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);\r
-\r
-    // Read the descriptor from the first level page table\r
-    Descriptor = FirstLevelTable[FirstLevelIdx];\r
-\r
-    // Does this descriptor need to be converted from section entry to 4K pages?\r
-    if (!TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(Descriptor)) {\r
-      Status = ConvertSectionToPages (FirstLevelIdx << TT_DESCRIPTOR_SECTION_BASE_SHIFT);\r
-      if (EFI_ERROR(Status)) {\r
-        // Exit for loop\r
-        break;\r
-      }\r
-\r
-      // Re-read descriptor\r
-      Descriptor = FirstLevelTable[FirstLevelIdx];\r
-      if (FlushTlbs != NULL) {\r
-        *FlushTlbs = TRUE;\r
-      }\r
-    }\r
-\r
-    // Obtain page table base address\r
-    PageTable = (ARM_PAGE_TABLE_ENTRY *)TT_DESCRIPTOR_PAGE_BASE_ADDRESS(Descriptor);\r
-\r
-    // Calculate index into the page table\r
-    PageTableIndex = ((BaseAddress + Offset) & TT_DESCRIPTOR_PAGE_INDEX_MASK) >> TT_DESCRIPTOR_PAGE_BASE_SHIFT;\r
-    ASSERT (PageTableIndex < TRANSLATION_TABLE_PAGE_COUNT);\r
-\r
-    // Get the entry\r
-    CurrentPageTableEntry = PageTable[PageTableIndex];\r
-\r
-    // Mask off appropriate fields\r
-    PageTableEntry = CurrentPageTableEntry & ~EntryMask;\r
-\r
-    // Mask in new attributes and/or permissions\r
-    PageTableEntry |= EntryValue;\r
-\r
-    if (VirtualMask != 0) {\r
-      // Make this virtual address point at a physical page\r
-      PageTableEntry &= ~VirtualMask;\r
-    }\r
-\r
-    if (CurrentPageTableEntry  != PageTableEntry) {\r
-      Mva = (VOID *)(UINTN)((((UINTN)FirstLevelIdx) << TT_DESCRIPTOR_SECTION_BASE_SHIFT) + (PageTableIndex << TT_DESCRIPTOR_PAGE_BASE_SHIFT));\r
-\r
-      // Only need to update if we are changing the entry\r
-      PageTable[PageTableIndex] = PageTableEntry;\r
-      ArmUpdateTranslationTableEntry ((VOID *)&PageTable[PageTableIndex], Mva);\r
-\r
-      // Clean/invalidate the cache for this page, but only\r
-      // if we are modifying the memory type attributes\r
-      if (((CurrentPageTableEntry ^ PageTableEntry) & TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK) != 0) {\r
-        WriteBackInvalidateDataCacheRange (Mva, TT_DESCRIPTOR_PAGE_SIZE);\r
-      }\r
-    }\r
-\r
-    Status = EFI_SUCCESS;\r
-    Offset += TT_DESCRIPTOR_PAGE_SIZE;\r
-\r
-  } // End first level translation table loop\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-\r
-EFI_STATUS\r
-UpdateSectionEntries (\r
-  IN EFI_PHYSICAL_ADDRESS      BaseAddress,\r
-  IN UINT64                    Length,\r
-  IN UINT64                    Attributes,\r
-  IN EFI_PHYSICAL_ADDRESS      VirtualMask\r
-  )\r
-{\r
-  EFI_STATUS    Status = EFI_SUCCESS;\r
-  UINT32        EntryMask;\r
-  UINT32        EntryValue;\r
-  UINT32        FirstLevelIdx;\r
-  UINT32        NumSections;\r
-  UINT32        i;\r
-  UINT32        CurrentDescriptor;\r
-  UINT32        Descriptor;\r
-  VOID          *Mva;\r
-  volatile ARM_FIRST_LEVEL_DESCRIPTOR   *FirstLevelTable;\r
-\r
-  // EntryMask: bitmask of values to change (1 = change this value, 0 = leave alone)\r
-  // EntryValue: values at bit positions specified by EntryMask\r
-\r
-  // Make sure we handle a section range that is unmapped\r
-  EntryMask = TT_DESCRIPTOR_SECTION_TYPE_MASK | TT_DESCRIPTOR_SECTION_XN_MASK |\r
-              TT_DESCRIPTOR_SECTION_AP_MASK;\r
-  EntryValue = TT_DESCRIPTOR_SECTION_TYPE_SECTION;\r
-\r
-  // Although the PI spec is unclear on this, the GCD guarantees that only\r
-  // one Attribute bit is set at a time, so the order of the conditionals below\r
-  // is irrelevant. If no memory attribute is specified, we preserve whatever\r
-  // memory type is set in the page tables, and update the permission attributes\r
-  // only.\r
-  if (Attributes & EFI_MEMORY_UC) {\r
-    // modify cacheability attributes\r
-    EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;\r
-    // map to strongly ordered\r
-    EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED; // TEX[2:0] = 0, C=0, B=0\r
-  } else if (Attributes & EFI_MEMORY_WC) {\r
-    // modify cacheability attributes\r
-    EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;\r
-    // map to normal non-cachable\r
-    EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE; // TEX [2:0]= 001 = 0x2, B=0, C=0\r
-  } else if (Attributes & EFI_MEMORY_WT) {\r
-    // modify cacheability attributes\r
-    EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;\r
-    // write through with no-allocate\r
-    EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC; // TEX [2:0] = 0, C=1, B=0\r
-  } else if (Attributes & EFI_MEMORY_WB) {\r
-    // modify cacheability attributes\r
-    EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;\r
-    // write back (with allocate)\r
-    EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC; // TEX [2:0] = 001, C=1, B=1\r
-  } else if (Attributes & CACHE_ATTRIBUTE_MASK) {\r
-    // catch unsupported memory type attributes\r
-    ASSERT (FALSE);\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  if (Attributes & EFI_MEMORY_RO) {\r
-    EntryValue |= TT_DESCRIPTOR_SECTION_AP_RO_RO;\r
-  } else {\r
-    EntryValue |= TT_DESCRIPTOR_SECTION_AP_RW_RW;\r
-  }\r
-\r
-  if (Attributes & EFI_MEMORY_XP) {\r
-    EntryValue |= TT_DESCRIPTOR_SECTION_XN_MASK;\r
-  }\r
-\r
-  // obtain page table base\r
-  FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();\r
-\r
-  // calculate index into first level translation table for start of modification\r
-  FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;\r
-  ASSERT (FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);\r
-\r
-  // calculate number of 1MB first level entries this applies to\r
-  NumSections = Length / TT_DESCRIPTOR_SECTION_SIZE;\r
-\r
-  // iterate through each descriptor\r
-  for(i=0; i<NumSections; i++) {\r
-    CurrentDescriptor = FirstLevelTable[FirstLevelIdx + i];\r
-\r
-    // has this descriptor already been coverted to pages?\r
-    if (TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(CurrentDescriptor)) {\r
-      // forward this 1MB range to page table function instead\r
-      Status = UpdatePageEntries (\r
-                 (FirstLevelIdx + i) << TT_DESCRIPTOR_SECTION_BASE_SHIFT,\r
-                 TT_DESCRIPTOR_SECTION_SIZE,\r
-                 Attributes,\r
-                 VirtualMask,\r
-                 NULL);\r
-    } else {\r
-      // still a section entry\r
-\r
-      // mask off appropriate fields\r
-      Descriptor = CurrentDescriptor & ~EntryMask;\r
-\r
-      // mask in new attributes and/or permissions\r
-      Descriptor |= EntryValue;\r
-      if (VirtualMask != 0) {\r
-        Descriptor &= ~VirtualMask;\r
-      }\r
-\r
-      if (CurrentDescriptor  != Descriptor) {\r
-        Mva = (VOID *)(UINTN)(((UINTN)FirstLevelTable) << TT_DESCRIPTOR_SECTION_BASE_SHIFT);\r
-\r
-        // Only need to update if we are changing the descriptor\r
-        FirstLevelTable[FirstLevelIdx + i] = Descriptor;\r
-        ArmUpdateTranslationTableEntry ((VOID *)&FirstLevelTable[FirstLevelIdx + i], Mva);\r
-\r
-        // Clean/invalidate the cache for this section, but only\r
-        // if we are modifying the memory type attributes\r
-        if (((CurrentDescriptor ^ Descriptor) & TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK) != 0) {\r
-          WriteBackInvalidateDataCacheRange (Mva, SIZE_1MB);\r
-        }\r
-      }\r
-\r
-      Status = EFI_SUCCESS;\r
-    }\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-EFI_STATUS\r
-ConvertSectionToPages (\r
-  IN EFI_PHYSICAL_ADDRESS  BaseAddress\r
-  )\r
-{\r
-  EFI_STATUS              Status;\r
-  EFI_PHYSICAL_ADDRESS    PageTableAddr;\r
-  UINT32                  FirstLevelIdx;\r
-  UINT32                  SectionDescriptor;\r
-  UINT32                  PageTableDescriptor;\r
-  UINT32                  PageDescriptor;\r
-  UINT32                  Index;\r
-\r
-  volatile ARM_FIRST_LEVEL_DESCRIPTOR   *FirstLevelTable;\r
-  volatile ARM_PAGE_TABLE_ENTRY         *PageTable;\r
-\r
-  DEBUG ((EFI_D_PAGE, "Converting section at 0x%x to pages\n", (UINTN)BaseAddress));\r
-\r
-  // Obtain page table base\r
-  FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();\r
-\r
-  // Calculate index into first level translation table for start of modification\r
-  FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;\r
-  ASSERT (FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);\r
-\r
-  // Get section attributes and convert to page attributes\r
-  SectionDescriptor = FirstLevelTable[FirstLevelIdx];\r
-  PageDescriptor = TT_DESCRIPTOR_PAGE_TYPE_PAGE | ConvertSectionAttributesToPageAttributes (SectionDescriptor, FALSE);\r
-\r
-  // Allocate a page table for the 4KB entries (we use up a full page even though we only need 1KB)\r
-  Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, 1, &PageTableAddr);\r
-  if (EFI_ERROR(Status)) {\r
-    return Status;\r
-  }\r
-\r
-  PageTable = (volatile ARM_PAGE_TABLE_ENTRY *)(UINTN)PageTableAddr;\r
-\r
-  // Write the page table entries out\r
-  for (Index = 0; Index < TRANSLATION_TABLE_PAGE_COUNT; Index++) {\r
-    PageTable[Index] = TT_DESCRIPTOR_PAGE_BASE_ADDRESS(BaseAddress + (Index << 12)) | PageDescriptor;\r
-  }\r
-\r
-  // Flush d-cache so descriptors make it back to uncached memory for subsequent table walks\r
-  WriteBackInvalidateDataCacheRange ((VOID *)(UINTN)PageTableAddr, TT_DESCRIPTOR_PAGE_SIZE);\r
-\r
-  // Formulate page table entry, Domain=0, NS=0\r
-  PageTableDescriptor = (((UINTN)PageTableAddr) & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK) | TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE;\r
-\r
-  // Write the page table entry out, replacing section entry\r
-  FirstLevelTable[FirstLevelIdx] = PageTableDescriptor;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-\r
-EFI_STATUS\r
-SetMemoryAttributes (\r
-  IN EFI_PHYSICAL_ADDRESS      BaseAddress,\r
-  IN UINT64                    Length,\r
-  IN UINT64                    Attributes,\r
-  IN EFI_PHYSICAL_ADDRESS      VirtualMask\r
-  )\r
-{\r
-  EFI_STATUS    Status;\r
-  UINT64        ChunkLength;\r
-  BOOLEAN       FlushTlbs;\r
-\r
-  if (Length == 0) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  FlushTlbs = FALSE;\r
-  while (Length > 0) {\r
-    if ((BaseAddress % TT_DESCRIPTOR_SECTION_SIZE == 0) &&\r
-        Length >= TT_DESCRIPTOR_SECTION_SIZE) {\r
-\r
-      ChunkLength = Length - Length % TT_DESCRIPTOR_SECTION_SIZE;\r
-\r
-      DEBUG ((DEBUG_PAGE,\r
-        "SetMemoryAttributes(): MMU section 0x%lx length 0x%lx to %lx\n",\r
-        BaseAddress, ChunkLength, Attributes));\r
-\r
-      Status = UpdateSectionEntries (BaseAddress, ChunkLength, Attributes,\r
-                 VirtualMask);\r
-\r
-      FlushTlbs = TRUE;\r
-    } else {\r
-\r
-      //\r
-      // Process page by page until the next section boundary, but only if\r
-      // we have more than a section's worth of area to deal with after that.\r
-      //\r
-      ChunkLength = TT_DESCRIPTOR_SECTION_SIZE -\r
-                    (BaseAddress % TT_DESCRIPTOR_SECTION_SIZE);\r
-      if (ChunkLength + TT_DESCRIPTOR_SECTION_SIZE > Length) {\r
-        ChunkLength = Length;\r
-      }\r
-\r
-      DEBUG ((DEBUG_PAGE,\r
-        "SetMemoryAttributes(): MMU page 0x%lx length 0x%lx to %lx\n",\r
-        BaseAddress, ChunkLength, Attributes));\r
-\r
-      Status = UpdatePageEntries (BaseAddress, ChunkLength, Attributes,\r
-                 VirtualMask, &FlushTlbs);\r
-    }\r
-\r
-    if (EFI_ERROR (Status)) {\r
-      break;\r
-    }\r
-\r
-    BaseAddress += ChunkLength;\r
-    Length -= ChunkLength;\r
-  }\r
-\r
-  if (FlushTlbs) {\r
-    ArmInvalidateTlb ();\r
-  }\r
-  return Status;\r
-}\r
-\r
 UINT64\r
 EfiAttributeToArmAttribute (\r
   IN UINT64                    EfiAttributes\r
index a46db8d2575452c004f1c4d922ea9e10cf37764b..a0f71e69ec09ab3a6c34f839abcd1bb3eff9c525 100644 (file)
@@ -19,6 +19,7 @@
 #include <Uefi.h>\r
 \r
 #include <Library/ArmLib.h>\r
+#include <Library/ArmMmuLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/PcdLib.h>\r
@@ -112,11 +113,6 @@ SyncCacheConfig (
   IN  EFI_CPU_ARCH_PROTOCOL *CpuProtocol\r
   );\r
 \r
-EFI_STATUS\r
-ConvertSectionToPages (\r
-  IN EFI_PHYSICAL_ADDRESS  BaseAddress\r
-  );\r
-\r
 /**\r
  * Publish ARM Processor Data table in UEFI SYSTEM Table.\r
  * @param  HobStart               Pointer to the beginning of the HOB List from PEI.\r
@@ -132,14 +128,6 @@ PublishArmProcessorTable(
   VOID\r
   );\r
 \r
-EFI_STATUS\r
-SetMemoryAttributes (\r
-  IN EFI_PHYSICAL_ADDRESS      BaseAddress,\r
-  IN UINT64                    Length,\r
-  IN UINT64                    Attributes,\r
-  IN EFI_PHYSICAL_ADDRESS      VirtualMask\r
-  );\r
-\r
 // The ARM Attributes might be defined on 64-bit (case of the long format description table)\r
 UINT64\r
 EfiAttributeToArmAttribute (\r
index 0f36a058407afb1cdc0b82f434956a22e324d0f0..d0a3fedd3aa7a6a27e9f000c31dae1a8f1a7e178 100644 (file)
@@ -210,7 +210,7 @@ CpuSetMemoryAttributes (
   if (EFI_ERROR (Status) || (RegionArmAttributes != ArmAttributes) ||\r
       ((BaseAddress + Length) > (RegionBaseAddress + RegionLength)))\r
   {\r
-    return SetMemoryAttributes (BaseAddress, Length, EfiAttributes, 0);\r
+    return ArmSetMemoryAttributes (BaseAddress, Length, EfiAttributes, 0);\r
   } else {\r
     return EFI_SUCCESS;\r
   }\r
index 549a5cd7d45a07d3650d9149e2f565003d9075f3..4d913824b4edb6e90f98a56ddb241ad74dbe5913 100644 (file)
                                                         TT_DESCRIPTOR_PAGE_AP_RW_RW                                                       | \\r
                                                         TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE)\r
 \r
+// First Level Descriptors\r
+typedef UINT32    ARM_FIRST_LEVEL_DESCRIPTOR;\r
+\r
+// Second Level Descriptors\r
+typedef UINT32    ARM_PAGE_TABLE_ENTRY;\r
+\r
 UINT32\r
 ConvertSectionAttributesToPageAttributes (\r
   IN UINT32   SectionAttributes,\r
index c1d43872d54898e3162588ff072e6f00ce739ef5..d3a302fa8125550a13ce7d8364d3dcce5a403671 100644 (file)
@@ -62,4 +62,12 @@ ArmReplaceLiveTranslationEntry (
   IN  UINT64  Value\r
   );\r
 \r
+EFI_STATUS\r
+ArmSetMemoryAttributes (\r
+  IN EFI_PHYSICAL_ADDRESS      BaseAddress,\r
+  IN UINT64                    Length,\r
+  IN UINT64                    Attributes,\r
+  IN EFI_PHYSICAL_ADDRESS      VirtualMask\r
+  );\r
+\r
 #endif\r
index df170d20a2c259fd6f1b2cb0a54a7337b07a2785..77f108971f3efd15ec789084dcd9936967bf16f8 100644 (file)
@@ -447,7 +447,7 @@ GcdAttributeToPageAttribute (
 }\r
 \r
 EFI_STATUS\r
-SetMemoryAttributes (\r
+ArmSetMemoryAttributes (\r
   IN EFI_PHYSICAL_ADDRESS      BaseAddress,\r
   IN UINT64                    Length,\r
   IN UINT64                    Attributes,\r
index f981c5bbcab637133c3cc42e799a333c96354e5d..8a472a1eb64b6597fd31441f65f071b6ef1a9f33 100644 (file)
@@ -16,6 +16,7 @@
 #include <Uefi.h>\r
 #include <Chipset/ArmV7.h>\r
 #include <Library/BaseMemoryLib.h>\r
+#include <Library/CacheMaintenanceLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/ArmLib.h>\r
 #include <Library/BaseLib.h>\r
 #define ID_MMFR0_SHR_IMP_HW_COHERENT   1\r
 #define ID_MMFR0_SHR_IGNORED         0xf\r
 \r
+#define CACHE_ATTRIBUTE_MASK   (EFI_MEMORY_UC | \\r
+                                EFI_MEMORY_WC | \\r
+                                EFI_MEMORY_WT | \\r
+                                EFI_MEMORY_WB | \\r
+                                EFI_MEMORY_UCE | \\r
+                                EFI_MEMORY_WP)\r
+\r
 UINTN\r
 EFIAPI\r
 ArmReadIdMmfr0 (\r
@@ -406,6 +414,395 @@ ArmConfigureMmu (
   return RETURN_SUCCESS;\r
 }\r
 \r
+STATIC\r
+EFI_STATUS\r
+ConvertSectionToPages (\r
+  IN EFI_PHYSICAL_ADDRESS  BaseAddress\r
+  )\r
+{\r
+  UINT32                  FirstLevelIdx;\r
+  UINT32                  SectionDescriptor;\r
+  UINT32                  PageTableDescriptor;\r
+  UINT32                  PageDescriptor;\r
+  UINT32                  Index;\r
+\r
+  volatile ARM_FIRST_LEVEL_DESCRIPTOR   *FirstLevelTable;\r
+  volatile ARM_PAGE_TABLE_ENTRY         *PageTable;\r
+\r
+  DEBUG ((EFI_D_PAGE, "Converting section at 0x%x to pages\n", (UINTN)BaseAddress));\r
+\r
+  // Obtain page table base\r
+  FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();\r
+\r
+  // Calculate index into first level translation table for start of modification\r
+  FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;\r
+  ASSERT (FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);\r
+\r
+  // Get section attributes and convert to page attributes\r
+  SectionDescriptor = FirstLevelTable[FirstLevelIdx];\r
+  PageDescriptor = TT_DESCRIPTOR_PAGE_TYPE_PAGE | ConvertSectionAttributesToPageAttributes (SectionDescriptor, FALSE);\r
+\r
+  // Allocate a page table for the 4KB entries (we use up a full page even though we only need 1KB)\r
+  PageTable = (volatile ARM_PAGE_TABLE_ENTRY *)AllocatePages (1);\r
+  if (PageTable == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  // Write the page table entries out\r
+  for (Index = 0; Index < TRANSLATION_TABLE_PAGE_COUNT; Index++) {\r
+    PageTable[Index] = TT_DESCRIPTOR_PAGE_BASE_ADDRESS(BaseAddress + (Index << 12)) | PageDescriptor;\r
+  }\r
+\r
+  // Flush d-cache so descriptors make it back to uncached memory for subsequent table walks\r
+  WriteBackInvalidateDataCacheRange ((VOID *)PageTable, TT_DESCRIPTOR_PAGE_SIZE);\r
+\r
+  // Formulate page table entry, Domain=0, NS=0\r
+  PageTableDescriptor = (((UINTN)PageTable) & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK) | TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE;\r
+\r
+  // Write the page table entry out, replacing section entry\r
+  FirstLevelTable[FirstLevelIdx] = PageTableDescriptor;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UpdatePageEntries (\r
+  IN  EFI_PHYSICAL_ADDRESS      BaseAddress,\r
+  IN  UINT64                    Length,\r
+  IN  UINT64                    Attributes,\r
+  IN  EFI_PHYSICAL_ADDRESS      VirtualMask,\r
+  OUT BOOLEAN                   *FlushTlbs OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  UINT32        EntryValue;\r
+  UINT32        EntryMask;\r
+  UINT32        FirstLevelIdx;\r
+  UINT32        Offset;\r
+  UINT32        NumPageEntries;\r
+  UINT32        Descriptor;\r
+  UINT32        p;\r
+  UINT32        PageTableIndex;\r
+  UINT32        PageTableEntry;\r
+  UINT32        CurrentPageTableEntry;\r
+  VOID          *Mva;\r
+\r
+  volatile ARM_FIRST_LEVEL_DESCRIPTOR   *FirstLevelTable;\r
+  volatile ARM_PAGE_TABLE_ENTRY         *PageTable;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  // EntryMask: bitmask of values to change (1 = change this value, 0 = leave alone)\r
+  // EntryValue: values at bit positions specified by EntryMask\r
+  EntryMask = TT_DESCRIPTOR_PAGE_TYPE_MASK | TT_DESCRIPTOR_PAGE_AP_MASK;\r
+  if (Attributes & EFI_MEMORY_XP) {\r
+    EntryValue = TT_DESCRIPTOR_PAGE_TYPE_PAGE_XN;\r
+  } else {\r
+    EntryValue = TT_DESCRIPTOR_PAGE_TYPE_PAGE;\r
+  }\r
+\r
+  // Although the PI spec is unclear on this, the GCD guarantees that only\r
+  // one Attribute bit is set at a time, so the order of the conditionals below\r
+  // is irrelevant. If no memory attribute is specified, we preserve whatever\r
+  // memory type is set in the page tables, and update the permission attributes\r
+  // only.\r
+  if (Attributes & EFI_MEMORY_UC) {\r
+    // modify cacheability attributes\r
+    EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;\r
+    // map to strongly ordered\r
+    EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED; // TEX[2:0] = 0, C=0, B=0\r
+  } else if (Attributes & EFI_MEMORY_WC) {\r
+    // modify cacheability attributes\r
+    EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;\r
+    // map to normal non-cachable\r
+    EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE; // TEX [2:0]= 001 = 0x2, B=0, C=0\r
+  } else if (Attributes & EFI_MEMORY_WT) {\r
+    // modify cacheability attributes\r
+    EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;\r
+    // write through with no-allocate\r
+    EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC; // TEX [2:0] = 0, C=1, B=0\r
+  } else if (Attributes & EFI_MEMORY_WB) {\r
+    // modify cacheability attributes\r
+    EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;\r
+    // write back (with allocate)\r
+    EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC; // TEX [2:0] = 001, C=1, B=1\r
+  } else if (Attributes & CACHE_ATTRIBUTE_MASK) {\r
+    // catch unsupported memory type attributes\r
+    ASSERT (FALSE);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Attributes & EFI_MEMORY_RO) {\r
+    EntryValue |= TT_DESCRIPTOR_PAGE_AP_RO_RO;\r
+  } else {\r
+    EntryValue |= TT_DESCRIPTOR_PAGE_AP_RW_RW;\r
+  }\r
+\r
+  // Obtain page table base\r
+  FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();\r
+\r
+  // Calculate number of 4KB page table entries to change\r
+  NumPageEntries = Length / TT_DESCRIPTOR_PAGE_SIZE;\r
+\r
+  // Iterate for the number of 4KB pages to change\r
+  Offset = 0;\r
+  for(p = 0; p < NumPageEntries; p++) {\r
+    // Calculate index into first level translation table for page table value\r
+\r
+    FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress + Offset) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;\r
+    ASSERT (FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);\r
+\r
+    // Read the descriptor from the first level page table\r
+    Descriptor = FirstLevelTable[FirstLevelIdx];\r
+\r
+    // Does this descriptor need to be converted from section entry to 4K pages?\r
+    if (!TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(Descriptor)) {\r
+      Status = ConvertSectionToPages (FirstLevelIdx << TT_DESCRIPTOR_SECTION_BASE_SHIFT);\r
+      if (EFI_ERROR(Status)) {\r
+        // Exit for loop\r
+        break;\r
+      }\r
+\r
+      // Re-read descriptor\r
+      Descriptor = FirstLevelTable[FirstLevelIdx];\r
+      if (FlushTlbs != NULL) {\r
+        *FlushTlbs = TRUE;\r
+      }\r
+    }\r
+\r
+    // Obtain page table base address\r
+    PageTable = (ARM_PAGE_TABLE_ENTRY *)TT_DESCRIPTOR_PAGE_BASE_ADDRESS(Descriptor);\r
+\r
+    // Calculate index into the page table\r
+    PageTableIndex = ((BaseAddress + Offset) & TT_DESCRIPTOR_PAGE_INDEX_MASK) >> TT_DESCRIPTOR_PAGE_BASE_SHIFT;\r
+    ASSERT (PageTableIndex < TRANSLATION_TABLE_PAGE_COUNT);\r
+\r
+    // Get the entry\r
+    CurrentPageTableEntry = PageTable[PageTableIndex];\r
+\r
+    // Mask off appropriate fields\r
+    PageTableEntry = CurrentPageTableEntry & ~EntryMask;\r
+\r
+    // Mask in new attributes and/or permissions\r
+    PageTableEntry |= EntryValue;\r
+\r
+    if (VirtualMask != 0) {\r
+      // Make this virtual address point at a physical page\r
+      PageTableEntry &= ~VirtualMask;\r
+    }\r
+\r
+    if (CurrentPageTableEntry  != PageTableEntry) {\r
+      Mva = (VOID *)(UINTN)((((UINTN)FirstLevelIdx) << TT_DESCRIPTOR_SECTION_BASE_SHIFT) + (PageTableIndex << TT_DESCRIPTOR_PAGE_BASE_SHIFT));\r
+\r
+      // Clean/invalidate the cache for this page, but only\r
+      // if we are modifying the memory type attributes\r
+      if (((CurrentPageTableEntry ^ PageTableEntry) & TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK) != 0) {\r
+        WriteBackInvalidateDataCacheRange (Mva, TT_DESCRIPTOR_PAGE_SIZE);\r
+      }\r
+\r
+      // Only need to update if we are changing the entry\r
+      PageTable[PageTableIndex] = PageTableEntry;\r
+      ArmUpdateTranslationTableEntry ((VOID *)&PageTable[PageTableIndex], Mva);\r
+    }\r
+\r
+    Status = EFI_SUCCESS;\r
+    Offset += TT_DESCRIPTOR_PAGE_SIZE;\r
+\r
+  } // End first level translation table loop\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UpdateSectionEntries (\r
+  IN EFI_PHYSICAL_ADDRESS      BaseAddress,\r
+  IN UINT64                    Length,\r
+  IN UINT64                    Attributes,\r
+  IN EFI_PHYSICAL_ADDRESS      VirtualMask\r
+  )\r
+{\r
+  EFI_STATUS    Status = EFI_SUCCESS;\r
+  UINT32        EntryMask;\r
+  UINT32        EntryValue;\r
+  UINT32        FirstLevelIdx;\r
+  UINT32        NumSections;\r
+  UINT32        i;\r
+  UINT32        CurrentDescriptor;\r
+  UINT32        Descriptor;\r
+  VOID          *Mva;\r
+  volatile ARM_FIRST_LEVEL_DESCRIPTOR   *FirstLevelTable;\r
+\r
+  // EntryMask: bitmask of values to change (1 = change this value, 0 = leave alone)\r
+  // EntryValue: values at bit positions specified by EntryMask\r
+\r
+  // Make sure we handle a section range that is unmapped\r
+  EntryMask = TT_DESCRIPTOR_SECTION_TYPE_MASK | TT_DESCRIPTOR_SECTION_XN_MASK |\r
+              TT_DESCRIPTOR_SECTION_AP_MASK;\r
+  EntryValue = TT_DESCRIPTOR_SECTION_TYPE_SECTION;\r
+\r
+  // Although the PI spec is unclear on this, the GCD guarantees that only\r
+  // one Attribute bit is set at a time, so the order of the conditionals below\r
+  // is irrelevant. If no memory attribute is specified, we preserve whatever\r
+  // memory type is set in the page tables, and update the permission attributes\r
+  // only.\r
+  if (Attributes & EFI_MEMORY_UC) {\r
+    // modify cacheability attributes\r
+    EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;\r
+    // map to strongly ordered\r
+    EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED; // TEX[2:0] = 0, C=0, B=0\r
+  } else if (Attributes & EFI_MEMORY_WC) {\r
+    // modify cacheability attributes\r
+    EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;\r
+    // map to normal non-cachable\r
+    EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE; // TEX [2:0]= 001 = 0x2, B=0, C=0\r
+  } else if (Attributes & EFI_MEMORY_WT) {\r
+    // modify cacheability attributes\r
+    EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;\r
+    // write through with no-allocate\r
+    EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC; // TEX [2:0] = 0, C=1, B=0\r
+  } else if (Attributes & EFI_MEMORY_WB) {\r
+    // modify cacheability attributes\r
+    EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;\r
+    // write back (with allocate)\r
+    EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC; // TEX [2:0] = 001, C=1, B=1\r
+  } else if (Attributes & CACHE_ATTRIBUTE_MASK) {\r
+    // catch unsupported memory type attributes\r
+    ASSERT (FALSE);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Attributes & EFI_MEMORY_RO) {\r
+    EntryValue |= TT_DESCRIPTOR_SECTION_AP_RO_RO;\r
+  } else {\r
+    EntryValue |= TT_DESCRIPTOR_SECTION_AP_RW_RW;\r
+  }\r
+\r
+  if (Attributes & EFI_MEMORY_XP) {\r
+    EntryValue |= TT_DESCRIPTOR_SECTION_XN_MASK;\r
+  }\r
+\r
+  // obtain page table base\r
+  FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();\r
+\r
+  // calculate index into first level translation table for start of modification\r
+  FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;\r
+  ASSERT (FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);\r
+\r
+  // calculate number of 1MB first level entries this applies to\r
+  NumSections = Length / TT_DESCRIPTOR_SECTION_SIZE;\r
+\r
+  // iterate through each descriptor\r
+  for(i=0; i<NumSections; i++) {\r
+    CurrentDescriptor = FirstLevelTable[FirstLevelIdx + i];\r
+\r
+    // has this descriptor already been coverted to pages?\r
+    if (TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(CurrentDescriptor)) {\r
+      // forward this 1MB range to page table function instead\r
+      Status = UpdatePageEntries (\r
+                 (FirstLevelIdx + i) << TT_DESCRIPTOR_SECTION_BASE_SHIFT,\r
+                 TT_DESCRIPTOR_SECTION_SIZE,\r
+                 Attributes,\r
+                 VirtualMask,\r
+                 NULL);\r
+    } else {\r
+      // still a section entry\r
+\r
+      // mask off appropriate fields\r
+      Descriptor = CurrentDescriptor & ~EntryMask;\r
+\r
+      // mask in new attributes and/or permissions\r
+      Descriptor |= EntryValue;\r
+      if (VirtualMask != 0) {\r
+        Descriptor &= ~VirtualMask;\r
+      }\r
+\r
+      if (CurrentDescriptor  != Descriptor) {\r
+        Mva = (VOID *)(UINTN)(((UINTN)FirstLevelTable) << TT_DESCRIPTOR_SECTION_BASE_SHIFT);\r
+\r
+        // Clean/invalidate the cache for this section, but only\r
+        // if we are modifying the memory type attributes\r
+        if (((CurrentDescriptor ^ Descriptor) & TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK) != 0) {\r
+          WriteBackInvalidateDataCacheRange (Mva, SIZE_1MB);\r
+        }\r
+\r
+        // Only need to update if we are changing the descriptor\r
+        FirstLevelTable[FirstLevelIdx + i] = Descriptor;\r
+        ArmUpdateTranslationTableEntry ((VOID *)&FirstLevelTable[FirstLevelIdx + i], Mva);\r
+      }\r
+\r
+      Status = EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+ArmSetMemoryAttributes (\r
+  IN EFI_PHYSICAL_ADDRESS      BaseAddress,\r
+  IN UINT64                    Length,\r
+  IN UINT64                    Attributes,\r
+  IN EFI_PHYSICAL_ADDRESS      VirtualMask\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  UINT64        ChunkLength;\r
+  BOOLEAN       FlushTlbs;\r
+\r
+  if (Length == 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  FlushTlbs = FALSE;\r
+  while (Length > 0) {\r
+    if ((BaseAddress % TT_DESCRIPTOR_SECTION_SIZE == 0) &&\r
+        Length >= TT_DESCRIPTOR_SECTION_SIZE) {\r
+\r
+      ChunkLength = Length - Length % TT_DESCRIPTOR_SECTION_SIZE;\r
+\r
+      DEBUG ((DEBUG_PAGE,\r
+        "SetMemoryAttributes(): MMU section 0x%lx length 0x%lx to %lx\n",\r
+        BaseAddress, ChunkLength, Attributes));\r
+\r
+      Status = UpdateSectionEntries (BaseAddress, ChunkLength, Attributes,\r
+                 VirtualMask);\r
+\r
+      FlushTlbs = TRUE;\r
+    } else {\r
+\r
+      //\r
+      // Process page by page until the next section boundary, but only if\r
+      // we have more than a section's worth of area to deal with after that.\r
+      //\r
+      ChunkLength = TT_DESCRIPTOR_SECTION_SIZE -\r
+                    (BaseAddress % TT_DESCRIPTOR_SECTION_SIZE);\r
+      if (ChunkLength + TT_DESCRIPTOR_SECTION_SIZE > Length) {\r
+        ChunkLength = Length;\r
+      }\r
+\r
+      DEBUG ((DEBUG_PAGE,\r
+        "SetMemoryAttributes(): MMU page 0x%lx length 0x%lx to %lx\n",\r
+        BaseAddress, ChunkLength, Attributes));\r
+\r
+      Status = UpdatePageEntries (BaseAddress, ChunkLength, Attributes,\r
+                 VirtualMask, &FlushTlbs);\r
+    }\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+\r
+    BaseAddress += ChunkLength;\r
+    Length -= ChunkLength;\r
+  }\r
+\r
+  if (FlushTlbs) {\r
+    ArmInvalidateTlb ();\r
+  }\r
+  return Status;\r
+}\r
 \r
 EFI_STATUS\r
 ArmSetMemoryRegionNoExec (\r