]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Drivers/CpuDxe/AArch64/Mmu.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Drivers / CpuDxe / AArch64 / Mmu.c
index 838803aa9b4432b9e36cc851f077cbb65255dd49..8997b7f61f8bca11c2fc393f7dc99edb8fb8fa8d 100644 (file)
@@ -13,7 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/MemoryAllocationLib.h>\r
 #include "CpuDxe.h"\r
 \r
 #include <Library/MemoryAllocationLib.h>\r
 #include "CpuDxe.h"\r
 \r
-#define INVALID_ENTRY   ((UINT32)~0)\r
+#define INVALID_ENTRY  ((UINT32)~0)\r
 \r
 #define MIN_T0SZ        16\r
 #define BITS_PER_LEVEL  9\r
 \r
 #define MIN_T0SZ        16\r
 #define BITS_PER_LEVEL  9\r
@@ -21,49 +21,52 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 STATIC\r
 VOID\r
 GetRootTranslationTableInfo (\r
 STATIC\r
 VOID\r
 GetRootTranslationTableInfo (\r
-  IN  UINTN     T0SZ,\r
-  OUT UINTN     *RootTableLevel,\r
-  OUT UINTN     *RootTableEntryCount\r
+  IN  UINTN  T0SZ,\r
+  OUT UINTN  *RootTableLevel,\r
+  OUT UINTN  *RootTableEntryCount\r
   )\r
 {\r
   )\r
 {\r
-  *RootTableLevel       = (T0SZ - MIN_T0SZ) / BITS_PER_LEVEL;\r
-  *RootTableEntryCount  = TT_ENTRY_COUNT >> (T0SZ - MIN_T0SZ) % BITS_PER_LEVEL;\r
+  *RootTableLevel      = (T0SZ - MIN_T0SZ) / BITS_PER_LEVEL;\r
+  *RootTableEntryCount = TT_ENTRY_COUNT >> (T0SZ - MIN_T0SZ) % BITS_PER_LEVEL;\r
 }\r
 \r
 STATIC\r
 UINT64\r
 PageAttributeToGcdAttribute (\r
 }\r
 \r
 STATIC\r
 UINT64\r
 PageAttributeToGcdAttribute (\r
-  IN UINT64 PageAttributes\r
+  IN UINT64  PageAttributes\r
   )\r
 {\r
   UINT64  GcdAttributes;\r
 \r
   switch (PageAttributes & TT_ATTR_INDX_MASK) {\r
   )\r
 {\r
   UINT64  GcdAttributes;\r
 \r
   switch (PageAttributes & TT_ATTR_INDX_MASK) {\r
-  case TT_ATTR_INDX_DEVICE_MEMORY:\r
-    GcdAttributes = EFI_MEMORY_UC;\r
-    break;\r
-  case TT_ATTR_INDX_MEMORY_NON_CACHEABLE:\r
-    GcdAttributes = EFI_MEMORY_WC;\r
-    break;\r
-  case TT_ATTR_INDX_MEMORY_WRITE_THROUGH:\r
-    GcdAttributes = EFI_MEMORY_WT;\r
-    break;\r
-  case TT_ATTR_INDX_MEMORY_WRITE_BACK:\r
-    GcdAttributes = EFI_MEMORY_WB;\r
-    break;\r
-  default:\r
-    DEBUG ((DEBUG_ERROR,\r
-      "PageAttributeToGcdAttribute: PageAttributes:0x%lX not supported.\n",\r
-      PageAttributes));\r
-    ASSERT (0);\r
-    // The Global Coherency Domain (GCD) value is defined as a bit set.\r
-    // Returning 0 means no attribute has been set.\r
-    GcdAttributes = 0;\r
+    case TT_ATTR_INDX_DEVICE_MEMORY:\r
+      GcdAttributes = EFI_MEMORY_UC;\r
+      break;\r
+    case TT_ATTR_INDX_MEMORY_NON_CACHEABLE:\r
+      GcdAttributes = EFI_MEMORY_WC;\r
+      break;\r
+    case TT_ATTR_INDX_MEMORY_WRITE_THROUGH:\r
+      GcdAttributes = EFI_MEMORY_WT;\r
+      break;\r
+    case TT_ATTR_INDX_MEMORY_WRITE_BACK:\r
+      GcdAttributes = EFI_MEMORY_WB;\r
+      break;\r
+    default:\r
+      DEBUG ((\r
+        DEBUG_ERROR,\r
+        "PageAttributeToGcdAttribute: PageAttributes:0x%lX not supported.\n",\r
+        PageAttributes\r
+        ));\r
+      ASSERT (0);\r
+      // The Global Coherency Domain (GCD) value is defined as a bit set.\r
+      // Returning 0 means no attribute has been set.\r
+      GcdAttributes = 0;\r
   }\r
 \r
   // Determine protection attributes\r
   if (((PageAttributes & TT_AP_MASK) == TT_AP_NO_RO) ||\r
   }\r
 \r
   // Determine protection attributes\r
   if (((PageAttributes & TT_AP_MASK) == TT_AP_NO_RO) ||\r
-      ((PageAttributes & TT_AP_MASK) == TT_AP_RO_RO)) {\r
+      ((PageAttributes & TT_AP_MASK) == TT_AP_RO_RO))\r
+  {\r
     // Read only cases map to write-protect\r
     GcdAttributes |= EFI_MEMORY_RO;\r
   }\r
     // Read only cases map to write-protect\r
     GcdAttributes |= EFI_MEMORY_RO;\r
   }\r
@@ -80,19 +83,19 @@ STATIC
 UINT64\r
 GetFirstPageAttribute (\r
   IN UINT64  *FirstLevelTableAddress,\r
 UINT64\r
 GetFirstPageAttribute (\r
   IN UINT64  *FirstLevelTableAddress,\r
-  IN UINTN    TableLevel\r
+  IN UINTN   TableLevel\r
   )\r
 {\r
   )\r
 {\r
-  UINT64 FirstEntry;\r
+  UINT64  FirstEntry;\r
 \r
   // Get the first entry of the table\r
   FirstEntry = *FirstLevelTableAddress;\r
 \r
 \r
   // Get the first entry of the table\r
   FirstEntry = *FirstLevelTableAddress;\r
 \r
-  if ((TableLevel != 3) && (FirstEntry & TT_TYPE_MASK) == TT_TYPE_TABLE_ENTRY) {\r
+  if ((TableLevel != 3) && ((FirstEntry & TT_TYPE_MASK) == TT_TYPE_TABLE_ENTRY)) {\r
     // Only valid for Levels 0, 1 and 2\r
 \r
     // Get the attribute of the subsequent table\r
     // Only valid for Levels 0, 1 and 2\r
 \r
     // Get the attribute of the subsequent table\r
-    return GetFirstPageAttribute ((UINT64*)(FirstEntry & TT_ADDRESS_MASK_DESCRIPTION_TABLE), TableLevel + 1);\r
+    return GetFirstPageAttribute ((UINT64 *)(FirstEntry & TT_ADDRESS_MASK_DESCRIPTION_TABLE), TableLevel + 1);\r
   } else if (((FirstEntry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY) ||\r
              ((TableLevel == 3) && ((FirstEntry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY_LEVEL3)))\r
   {\r
   } else if (((FirstEntry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY) ||\r
              ((TableLevel == 3) && ((FirstEntry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY_LEVEL3)))\r
   {\r
@@ -105,25 +108,25 @@ GetFirstPageAttribute (
 STATIC\r
 UINT64\r
 GetNextEntryAttribute (\r
 STATIC\r
 UINT64\r
 GetNextEntryAttribute (\r
-  IN     UINT64 *TableAddress,\r
+  IN     UINT64  *TableAddress,\r
   IN     UINTN   EntryCount,\r
   IN     UINTN   TableLevel,\r
   IN     UINT64  BaseAddress,\r
   IN     UINTN   EntryCount,\r
   IN     UINTN   TableLevel,\r
   IN     UINT64  BaseAddress,\r
-  IN OUT UINT32 *PrevEntryAttribute,\r
-  IN OUT UINT64 *StartGcdRegion\r
+  IN OUT UINT32  *PrevEntryAttribute,\r
+  IN OUT UINT64  *StartGcdRegion\r
   )\r
 {\r
   )\r
 {\r
-  UINTN                             Index;\r
-  UINT64                            Entry;\r
-  UINT32                            EntryAttribute;\r
-  UINT32                            EntryType;\r
-  EFI_STATUS                        Status;\r
-  UINTN                             NumberOfDescriptors;\r
+  UINTN                            Index;\r
+  UINT64                           Entry;\r
+  UINT32                           EntryAttribute;\r
+  UINT32                           EntryType;\r
+  EFI_STATUS                       Status;\r
+  UINTN                            NumberOfDescriptors;\r
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap;\r
 \r
   // Get the memory space map from GCD\r
   MemorySpaceMap = NULL;\r
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap;\r
 \r
   // Get the memory space map from GCD\r
   MemorySpaceMap = NULL;\r
-  Status = gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
+  Status         = gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   // We cannot get more than 3-level page table\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   // We cannot get more than 3-level page table\r
@@ -132,24 +135,28 @@ GetNextEntryAttribute (
   // While the top level table might not contain TT_ENTRY_COUNT entries;\r
   // the subsequent ones should be filled up\r
   for (Index = 0; Index < EntryCount; Index++) {\r
   // While the top level table might not contain TT_ENTRY_COUNT entries;\r
   // the subsequent ones should be filled up\r
   for (Index = 0; Index < EntryCount; Index++) {\r
-    Entry = TableAddress[Index];\r
-    EntryType = Entry & TT_TYPE_MASK;\r
+    Entry          = TableAddress[Index];\r
+    EntryType      = Entry & TT_TYPE_MASK;\r
     EntryAttribute = Entry  & TT_ATTR_INDX_MASK;\r
 \r
     // If Entry is a Table Descriptor type entry then go through the sub-level table\r
     if ((EntryType == TT_TYPE_BLOCK_ENTRY) ||\r
     EntryAttribute = Entry  & TT_ATTR_INDX_MASK;\r
 \r
     // If Entry is a Table Descriptor type entry then go through the sub-level table\r
     if ((EntryType == TT_TYPE_BLOCK_ENTRY) ||\r
-        ((TableLevel == 3) && (EntryType == TT_TYPE_BLOCK_ENTRY_LEVEL3))) {\r
+        ((TableLevel == 3) && (EntryType == TT_TYPE_BLOCK_ENTRY_LEVEL3)))\r
+    {\r
       if ((*PrevEntryAttribute == INVALID_ENTRY) || (EntryAttribute != *PrevEntryAttribute)) {\r
         if (*PrevEntryAttribute != INVALID_ENTRY) {\r
           // Update GCD with the last region\r
       if ((*PrevEntryAttribute == INVALID_ENTRY) || (EntryAttribute != *PrevEntryAttribute)) {\r
         if (*PrevEntryAttribute != INVALID_ENTRY) {\r
           // Update GCD with the last region\r
-          SetGcdMemorySpaceAttributes (MemorySpaceMap, NumberOfDescriptors,\r
-              *StartGcdRegion,\r
-              (BaseAddress + (Index * TT_ADDRESS_AT_LEVEL(TableLevel))) - *StartGcdRegion,\r
-              PageAttributeToGcdAttribute (*PrevEntryAttribute));\r
+          SetGcdMemorySpaceAttributes (\r
+            MemorySpaceMap,\r
+            NumberOfDescriptors,\r
+            *StartGcdRegion,\r
+            (BaseAddress + (Index * TT_ADDRESS_AT_LEVEL (TableLevel))) - *StartGcdRegion,\r
+            PageAttributeToGcdAttribute (*PrevEntryAttribute)\r
+            );\r
         }\r
 \r
         // Start of the new region\r
         }\r
 \r
         // Start of the new region\r
-        *StartGcdRegion = BaseAddress + (Index * TT_ADDRESS_AT_LEVEL(TableLevel));\r
+        *StartGcdRegion     = BaseAddress + (Index * TT_ADDRESS_AT_LEVEL (TableLevel));\r
         *PrevEntryAttribute = EntryAttribute;\r
       } else {\r
         continue;\r
         *PrevEntryAttribute = EntryAttribute;\r
       } else {\r
         continue;\r
@@ -159,20 +166,27 @@ GetNextEntryAttribute (
       ASSERT (TableLevel < 3);\r
 \r
       // Increase the level number and scan the sub-level table\r
       ASSERT (TableLevel < 3);\r
 \r
       // Increase the level number and scan the sub-level table\r
-      GetNextEntryAttribute ((UINT64*)(Entry & TT_ADDRESS_MASK_DESCRIPTION_TABLE),\r
-                             TT_ENTRY_COUNT, TableLevel + 1,\r
-                             (BaseAddress + (Index * TT_ADDRESS_AT_LEVEL(TableLevel))),\r
-                             PrevEntryAttribute, StartGcdRegion);\r
+      GetNextEntryAttribute (\r
+        (UINT64 *)(Entry & TT_ADDRESS_MASK_DESCRIPTION_TABLE),\r
+        TT_ENTRY_COUNT,\r
+        TableLevel + 1,\r
+        (BaseAddress + (Index * TT_ADDRESS_AT_LEVEL (TableLevel))),\r
+        PrevEntryAttribute,\r
+        StartGcdRegion\r
+        );\r
     } else {\r
       if (*PrevEntryAttribute != INVALID_ENTRY) {\r
         // Update GCD with the last region\r
     } else {\r
       if (*PrevEntryAttribute != INVALID_ENTRY) {\r
         // Update GCD with the last region\r
-        SetGcdMemorySpaceAttributes (MemorySpaceMap, NumberOfDescriptors,\r
-            *StartGcdRegion,\r
-            (BaseAddress + (Index * TT_ADDRESS_AT_LEVEL(TableLevel))) - *StartGcdRegion,\r
-            PageAttributeToGcdAttribute (*PrevEntryAttribute));\r
+        SetGcdMemorySpaceAttributes (\r
+          MemorySpaceMap,\r
+          NumberOfDescriptors,\r
+          *StartGcdRegion,\r
+          (BaseAddress + (Index * TT_ADDRESS_AT_LEVEL (TableLevel))) - *StartGcdRegion,\r
+          PageAttributeToGcdAttribute (*PrevEntryAttribute)\r
+          );\r
 \r
         // Start of the new region\r
 \r
         // Start of the new region\r
-        *StartGcdRegion = BaseAddress + (Index * TT_ADDRESS_AT_LEVEL(TableLevel));\r
+        *StartGcdRegion     = BaseAddress + (Index * TT_ADDRESS_AT_LEVEL (TableLevel));\r
         *PrevEntryAttribute = INVALID_ENTRY;\r
       }\r
     }\r
         *PrevEntryAttribute = INVALID_ENTRY;\r
       }\r
     }\r
@@ -180,25 +194,25 @@ GetNextEntryAttribute (
 \r
   FreePool (MemorySpaceMap);\r
 \r
 \r
   FreePool (MemorySpaceMap);\r
 \r
-  return BaseAddress + (EntryCount * TT_ADDRESS_AT_LEVEL(TableLevel));\r
+  return BaseAddress + (EntryCount * TT_ADDRESS_AT_LEVEL (TableLevel));\r
 }\r
 \r
 EFI_STATUS\r
 SyncCacheConfig (\r
 }\r
 \r
 EFI_STATUS\r
 SyncCacheConfig (\r
-  IN  EFI_CPU_ARCH_PROTOCOL *CpuProtocol\r
+  IN  EFI_CPU_ARCH_PROTOCOL  *CpuProtocol\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS                          Status;\r
-  UINT32                              PageAttribute;\r
-  UINT64                             *FirstLevelTableAddress;\r
-  UINTN                               TableLevel;\r
-  UINTN                               TableCount;\r
-  UINTN                               NumberOfDescriptors;\r
-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR    *MemorySpaceMap;\r
-  UINTN                               Tcr;\r
-  UINTN                               T0SZ;\r
-  UINT64                              BaseAddressGcdRegion;\r
-  UINT64                              EndAddressGcdRegion;\r
+  EFI_STATUS                       Status;\r
+  UINT32                           PageAttribute;\r
+  UINT64                           *FirstLevelTableAddress;\r
+  UINTN                            TableLevel;\r
+  UINTN                            TableCount;\r
+  UINTN                            NumberOfDescriptors;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap;\r
+  UINTN                            Tcr;\r
+  UINTN                            T0SZ;\r
+  UINT64                           BaseAddressGcdRegion;\r
+  UINT64                           EndAddressGcdRegion;\r
 \r
   // This code assumes MMU is enabled and filed with section translations\r
   ASSERT (ArmMmuEnabled ());\r
 \r
   // This code assumes MMU is enabled and filed with section translations\r
   ASSERT (ArmMmuEnabled ());\r
@@ -207,7 +221,7 @@ SyncCacheConfig (
   // Get the memory space map from GCD\r
   //\r
   MemorySpaceMap = NULL;\r
   // Get the memory space map from GCD\r
   //\r
   MemorySpaceMap = NULL;\r
-  Status = gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
+  Status         = gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   // The GCD implementation maintains its own copy of the state of memory space attributes.  GCD needs\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   // The GCD implementation maintains its own copy of the state of memory space attributes.  GCD needs\r
@@ -217,7 +231,7 @@ SyncCacheConfig (
   // with a way for GCD to query the CPU Arch. driver of the existing memory space attributes instead.\r
 \r
   // Obtain page table base\r
   // with a way for GCD to query the CPU Arch. driver of the existing memory space attributes instead.\r
 \r
   // Obtain page table base\r
-  FirstLevelTableAddress = (UINT64*)(ArmGetTTBR0BaseAddress ());\r
+  FirstLevelTableAddress = (UINT64 *)(ArmGetTTBR0BaseAddress ());\r
 \r
   // Get Translation Control Register value\r
   Tcr = ArmGetTCR ();\r
 \r
   // Get Translation Control Register value\r
   Tcr = ArmGetTCR ();\r
@@ -232,17 +246,24 @@ SyncCacheConfig (
 \r
   // We scan from the start of the memory map (ie: at the address 0x0)\r
   BaseAddressGcdRegion = 0x0;\r
 \r
   // We scan from the start of the memory map (ie: at the address 0x0)\r
   BaseAddressGcdRegion = 0x0;\r
-  EndAddressGcdRegion = GetNextEntryAttribute (FirstLevelTableAddress,\r
-                                               TableCount, TableLevel,\r
-                                               BaseAddressGcdRegion,\r
-                                               &PageAttribute, &BaseAddressGcdRegion);\r
+  EndAddressGcdRegion  = GetNextEntryAttribute (\r
+                           FirstLevelTableAddress,\r
+                           TableCount,\r
+                           TableLevel,\r
+                           BaseAddressGcdRegion,\r
+                           &PageAttribute,\r
+                           &BaseAddressGcdRegion\r
+                           );\r
 \r
   // Update GCD with the last region if valid\r
   if (PageAttribute != INVALID_ENTRY) {\r
 \r
   // Update GCD with the last region if valid\r
   if (PageAttribute != INVALID_ENTRY) {\r
-    SetGcdMemorySpaceAttributes (MemorySpaceMap, NumberOfDescriptors,\r
-        BaseAddressGcdRegion,\r
-        EndAddressGcdRegion - BaseAddressGcdRegion,\r
-        PageAttributeToGcdAttribute (PageAttribute));\r
+    SetGcdMemorySpaceAttributes (\r
+      MemorySpaceMap,\r
+      NumberOfDescriptors,\r
+      BaseAddressGcdRegion,\r
+      EndAddressGcdRegion - BaseAddressGcdRegion,\r
+      PageAttributeToGcdAttribute (PageAttribute)\r
+      );\r
   }\r
 \r
   FreePool (MemorySpaceMap);\r
   }\r
 \r
   FreePool (MemorySpaceMap);\r
@@ -252,30 +273,31 @@ SyncCacheConfig (
 \r
 UINT64\r
 EfiAttributeToArmAttribute (\r
 \r
 UINT64\r
 EfiAttributeToArmAttribute (\r
-  IN UINT64                    EfiAttributes\r
+  IN UINT64  EfiAttributes\r
   )\r
 {\r
   )\r
 {\r
-  UINT64 ArmAttributes;\r
+  UINT64  ArmAttributes;\r
 \r
   switch (EfiAttributes & EFI_MEMORY_CACHETYPE_MASK) {\r
 \r
   switch (EfiAttributes & EFI_MEMORY_CACHETYPE_MASK) {\r
-  case EFI_MEMORY_UC:\r
-    if (ArmReadCurrentEL () == AARCH64_EL2) {\r
-      ArmAttributes = TT_ATTR_INDX_DEVICE_MEMORY | TT_XN_MASK;\r
-    } else {\r
-      ArmAttributes = TT_ATTR_INDX_DEVICE_MEMORY | TT_UXN_MASK | TT_PXN_MASK;\r
-    }\r
-    break;\r
-  case EFI_MEMORY_WC:\r
-    ArmAttributes = TT_ATTR_INDX_MEMORY_NON_CACHEABLE;\r
-    break;\r
-  case EFI_MEMORY_WT:\r
-    ArmAttributes = TT_ATTR_INDX_MEMORY_WRITE_THROUGH | TT_SH_INNER_SHAREABLE;\r
-    break;\r
-  case EFI_MEMORY_WB:\r
-    ArmAttributes = TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE;\r
-    break;\r
-  default:\r
-    ArmAttributes = TT_ATTR_INDX_MASK;\r
+    case EFI_MEMORY_UC:\r
+      if (ArmReadCurrentEL () == AARCH64_EL2) {\r
+        ArmAttributes = TT_ATTR_INDX_DEVICE_MEMORY | TT_XN_MASK;\r
+      } else {\r
+        ArmAttributes = TT_ATTR_INDX_DEVICE_MEMORY | TT_UXN_MASK | TT_PXN_MASK;\r
+      }\r
+\r
+      break;\r
+    case EFI_MEMORY_WC:\r
+      ArmAttributes = TT_ATTR_INDX_MEMORY_NON_CACHEABLE;\r
+      break;\r
+    case EFI_MEMORY_WT:\r
+      ArmAttributes = TT_ATTR_INDX_MEMORY_WRITE_THROUGH | TT_SH_INNER_SHAREABLE;\r
+      break;\r
+    case EFI_MEMORY_WB:\r
+      ArmAttributes = TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE;\r
+      break;\r
+    default:\r
+      ArmAttributes = TT_ATTR_INDX_MASK;\r
   }\r
 \r
   // Set the access flag to match the block attributes\r
   }\r
 \r
   // Set the access flag to match the block attributes\r
@@ -298,19 +320,19 @@ EfiAttributeToArmAttribute (
 // And then the function will identify the size of the region that has the same page table attribute.\r
 EFI_STATUS\r
 GetMemoryRegionRec (\r
 // And then the function will identify the size of the region that has the same page table attribute.\r
 EFI_STATUS\r
 GetMemoryRegionRec (\r
-  IN     UINT64                  *TranslationTable,\r
-  IN     UINTN                    TableLevel,\r
-  IN     UINT64                  *LastBlockEntry,\r
-  IN OUT UINTN                   *BaseAddress,\r
-  OUT    UINTN                   *RegionLength,\r
-  OUT    UINTN                   *RegionAttributes\r
+  IN     UINT64  *TranslationTable,\r
+  IN     UINTN   TableLevel,\r
+  IN     UINT64  *LastBlockEntry,\r
+  IN OUT UINTN   *BaseAddress,\r
+  OUT    UINTN   *RegionLength,\r
+  OUT    UINTN   *RegionAttributes\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS Status;\r
-  UINT64    *NextTranslationTable;\r
-  UINT64    *BlockEntry;\r
-  UINT64     BlockEntryType;\r
-  UINT64     EntryType;\r
+  EFI_STATUS  Status;\r
+  UINT64      *NextTranslationTable;\r
+  UINT64      *BlockEntry;\r
+  UINT64      BlockEntryType;\r
+  UINT64      EntryType;\r
 \r
   if (TableLevel != 3) {\r
     BlockEntryType = TT_TYPE_BLOCK_ENTRY;\r
 \r
   if (TableLevel != 3) {\r
     BlockEntryType = TT_TYPE_BLOCK_ENTRY;\r
@@ -319,22 +341,25 @@ GetMemoryRegionRec (
   }\r
 \r
   // Find the block entry linked to the Base Address\r
   }\r
 \r
   // Find the block entry linked to the Base Address\r
-  BlockEntry = (UINT64*)TT_GET_ENTRY_FOR_ADDRESS (TranslationTable, TableLevel, *BaseAddress);\r
-  EntryType = *BlockEntry & TT_TYPE_MASK;\r
+  BlockEntry = (UINT64 *)TT_GET_ENTRY_FOR_ADDRESS (TranslationTable, TableLevel, *BaseAddress);\r
+  EntryType  = *BlockEntry & TT_TYPE_MASK;\r
 \r
   if ((TableLevel < 3) && (EntryType == TT_TYPE_TABLE_ENTRY)) {\r
 \r
   if ((TableLevel < 3) && (EntryType == TT_TYPE_TABLE_ENTRY)) {\r
-    NextTranslationTable = (UINT64*)(*BlockEntry & TT_ADDRESS_MASK_DESCRIPTION_TABLE);\r
+    NextTranslationTable = (UINT64 *)(*BlockEntry & TT_ADDRESS_MASK_DESCRIPTION_TABLE);\r
 \r
     // The entry is a page table, so we go to the next level\r
     Status = GetMemoryRegionRec (\r
 \r
     // The entry is a page table, so we go to the next level\r
     Status = GetMemoryRegionRec (\r
-        NextTranslationTable, // Address of the next level page table\r
-        TableLevel + 1, // Next Page Table level\r
-        (UINTN*)TT_LAST_BLOCK_ADDRESS(NextTranslationTable, TT_ENTRY_COUNT),\r
-        BaseAddress, RegionLength, RegionAttributes);\r
+               NextTranslationTable, // Address of the next level page table\r
+               TableLevel + 1,       // Next Page Table level\r
+               (UINTN *)TT_LAST_BLOCK_ADDRESS (NextTranslationTable, TT_ENTRY_COUNT),\r
+               BaseAddress,\r
+               RegionLength,\r
+               RegionAttributes\r
+               );\r
 \r
     // In case of 'Success', it means the end of the block region has been found into the upper\r
     // level translation table\r
 \r
     // In case of 'Success', it means the end of the block region has been found into the upper\r
     // level translation table\r
-    if (!EFI_ERROR(Status)) {\r
+    if (!EFI_ERROR (Status)) {\r
       return EFI_SUCCESS;\r
     }\r
 \r
       return EFI_SUCCESS;\r
     }\r
 \r
@@ -343,7 +368,7 @@ GetMemoryRegionRec (
   } else if (EntryType == BlockEntryType) {\r
     // We have found the BlockEntry attached to the address. We save its start address (the start\r
     // address might be before the 'BaseAddress') and attributes\r
   } else if (EntryType == BlockEntryType) {\r
     // We have found the BlockEntry attached to the address. We save its start address (the start\r
     // address might be before the 'BaseAddress') and attributes\r
-    *BaseAddress      = *BaseAddress & ~(TT_ADDRESS_AT_LEVEL(TableLevel) - 1);\r
+    *BaseAddress      = *BaseAddress & ~(TT_ADDRESS_AT_LEVEL (TableLevel) - 1);\r
     *RegionLength     = 0;\r
     *RegionAttributes = *BlockEntry & TT_ATTRIBUTES_MASK;\r
   } else {\r
     *RegionLength     = 0;\r
     *RegionAttributes = *BlockEntry & TT_ATTRIBUTES_MASK;\r
   } else {\r
@@ -353,11 +378,12 @@ GetMemoryRegionRec (
 \r
   while (BlockEntry <= LastBlockEntry) {\r
     if ((*BlockEntry & TT_ATTRIBUTES_MASK) == *RegionAttributes) {\r
 \r
   while (BlockEntry <= LastBlockEntry) {\r
     if ((*BlockEntry & TT_ATTRIBUTES_MASK) == *RegionAttributes) {\r
-      *RegionLength = *RegionLength + TT_BLOCK_ENTRY_SIZE_AT_LEVEL(TableLevel);\r
+      *RegionLength = *RegionLength + TT_BLOCK_ENTRY_SIZE_AT_LEVEL (TableLevel);\r
     } else {\r
       // In case we have found the end of the region we return success\r
       return EFI_SUCCESS;\r
     }\r
     } else {\r
       // In case we have found the end of the region we return success\r
       return EFI_SUCCESS;\r
     }\r
+\r
     BlockEntry++;\r
   }\r
 \r
     BlockEntry++;\r
   }\r
 \r
@@ -369,13 +395,13 @@ GetMemoryRegionRec (
 \r
 EFI_STATUS\r
 GetMemoryRegion (\r
 \r
 EFI_STATUS\r
 GetMemoryRegion (\r
-  IN OUT UINTN                   *BaseAddress,\r
-  OUT    UINTN                   *RegionLength,\r
-  OUT    UINTN                   *RegionAttributes\r
+  IN OUT UINTN  *BaseAddress,\r
+  OUT    UINTN  *RegionLength,\r
+  OUT    UINTN  *RegionAttributes\r
   )\r
 {\r
   EFI_STATUS  Status;\r
   )\r
 {\r
   EFI_STATUS  Status;\r
-  UINT64     *TranslationTable;\r
+  UINT64      *TranslationTable;\r
   UINTN       TableLevel;\r
   UINTN       EntryCount;\r
   UINTN       T0SZ;\r
   UINTN       TableLevel;\r
   UINTN       EntryCount;\r
   UINTN       T0SZ;\r
@@ -388,9 +414,14 @@ GetMemoryRegion (
   // Get the Table info from T0SZ\r
   GetRootTranslationTableInfo (T0SZ, &TableLevel, &EntryCount);\r
 \r
   // Get the Table info from T0SZ\r
   GetRootTranslationTableInfo (T0SZ, &TableLevel, &EntryCount);\r
 \r
-  Status = GetMemoryRegionRec (TranslationTable, TableLevel,\r
-      (UINTN*)TT_LAST_BLOCK_ADDRESS(TranslationTable, EntryCount),\r
-      BaseAddress, RegionLength, RegionAttributes);\r
+  Status = GetMemoryRegionRec (\r
+             TranslationTable,\r
+             TableLevel,\r
+             (UINTN *)TT_LAST_BLOCK_ADDRESS (TranslationTable, EntryCount),\r
+             BaseAddress,\r
+             RegionLength,\r
+             RegionAttributes\r
+             );\r
 \r
   // If the region continues up to the end of the root table then GetMemoryRegionRec()\r
   // will return EFI_NOT_FOUND\r
 \r
   // If the region continues up to the end of the root table then GetMemoryRegionRec()\r
   // will return EFI_NOT_FOUND\r