]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuDxe/CpuDxe.c
UefiCpuPkg: Apply uncrustify changes
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuDxe.c
index efa0bc33084e62ff6cf082b93b75d828e3726e81..00f3cb09572cfcb2308d0fef50ab269b74fe90cb 100644 (file)
 //\r
 // Global Variables\r
 //\r
-BOOLEAN                   InterruptState = FALSE;\r
-EFI_HANDLE                mCpuHandle = NULL;\r
-BOOLEAN                   mIsFlushingGCD;\r
-BOOLEAN                   mIsAllocatingPageTable = FALSE;\r
-UINT64                    mValidMtrrAddressMask;\r
-UINT64                    mValidMtrrBitsMask;\r
-UINT64                    mTimerPeriod = 0;\r
-\r
-FIXED_MTRR    mFixedMtrrTable[] = {\r
+BOOLEAN     InterruptState = FALSE;\r
+EFI_HANDLE  mCpuHandle     = NULL;\r
+BOOLEAN     mIsFlushingGCD;\r
+BOOLEAN     mIsAllocatingPageTable = FALSE;\r
+UINT64      mValidMtrrAddressMask;\r
+UINT64      mValidMtrrBitsMask;\r
+UINT64      mTimerPeriod = 0;\r
+\r
+FIXED_MTRR  mFixedMtrrTable[] = {\r
   {\r
     MSR_IA32_MTRR_FIX64K_00000,\r
     0,\r
@@ -79,7 +79,6 @@ FIXED_MTRR    mFixedMtrrTable[] = {
   },\r
 };\r
 \r
-\r
 EFI_CPU_ARCH_PROTOCOL  gCpu = {\r
   CpuFlushCpuDataCache,\r
   CpuEnableInterrupt,\r
@@ -115,10 +114,10 @@ EFI_CPU_ARCH_PROTOCOL  gCpu = {
 EFI_STATUS\r
 EFIAPI\r
 CpuFlushCpuDataCache (\r
-  IN EFI_CPU_ARCH_PROTOCOL     *This,\r
-  IN EFI_PHYSICAL_ADDRESS      Start,\r
-  IN UINT64                    Length,\r
-  IN EFI_CPU_FLUSH_TYPE        FlushType\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   Start,\r
+  IN UINT64                 Length,\r
+  IN EFI_CPU_FLUSH_TYPE     FlushType\r
   )\r
 {\r
   if (FlushType == EfiCpuFlushTypeWriteBackInvalidate) {\r
@@ -132,7 +131,6 @@ CpuFlushCpuDataCache (
   }\r
 }\r
 \r
-\r
 /**\r
   Enables CPU interrupts.\r
 \r
@@ -145,7 +143,7 @@ CpuFlushCpuDataCache (
 EFI_STATUS\r
 EFIAPI\r
 CpuEnableInterrupt (\r
-  IN EFI_CPU_ARCH_PROTOCOL          *This\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
   )\r
 {\r
   EnableInterrupts ();\r
@@ -154,7 +152,6 @@ CpuEnableInterrupt (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Disables CPU interrupts.\r
 \r
@@ -167,7 +164,7 @@ CpuEnableInterrupt (
 EFI_STATUS\r
 EFIAPI\r
 CpuDisableInterrupt (\r
-  IN EFI_CPU_ARCH_PROTOCOL     *This\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
   )\r
 {\r
   DisableInterrupts ();\r
@@ -176,7 +173,6 @@ CpuDisableInterrupt (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Return the state of interrupts.\r
 \r
@@ -190,8 +186,8 @@ CpuDisableInterrupt (
 EFI_STATUS\r
 EFIAPI\r
 CpuGetInterruptState (\r
-  IN  EFI_CPU_ARCH_PROTOCOL     *This,\r
-  OUT BOOLEAN                   *State\r
+  IN  EFI_CPU_ARCH_PROTOCOL  *This,\r
+  OUT BOOLEAN                *State\r
   )\r
 {\r
   if (State == NULL) {\r
@@ -202,7 +198,6 @@ CpuGetInterruptState (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Generates an INIT to the CPU.\r
 \r
@@ -218,14 +213,13 @@ CpuGetInterruptState (
 EFI_STATUS\r
 EFIAPI\r
 CpuInit (\r
-  IN EFI_CPU_ARCH_PROTOCOL      *This,\r
-  IN EFI_CPU_INIT_TYPE          InitType\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_CPU_INIT_TYPE      InitType\r
   )\r
 {\r
   return EFI_UNSUPPORTED;\r
 }\r
 \r
-\r
 /**\r
   Registers a function to be called from the CPU interrupt handler.\r
 \r
@@ -249,15 +243,14 @@ CpuInit (
 EFI_STATUS\r
 EFIAPI\r
 CpuRegisterInterruptHandler (\r
-  IN EFI_CPU_ARCH_PROTOCOL         *This,\r
-  IN EFI_EXCEPTION_TYPE            InterruptType,\r
-  IN EFI_CPU_INTERRUPT_HANDLER     InterruptHandler\r
+  IN EFI_CPU_ARCH_PROTOCOL      *This,\r
+  IN EFI_EXCEPTION_TYPE         InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler\r
   )\r
 {\r
   return RegisterCpuInterruptHandler (InterruptType, InterruptHandler);\r
 }\r
 \r
-\r
 /**\r
   Returns a timer value from one of the CPU's internal timers. There is no\r
   inherent time interval between ticks but is a function of the CPU frequency.\r
@@ -284,14 +277,14 @@ CpuRegisterInterruptHandler (
 EFI_STATUS\r
 EFIAPI\r
 CpuGetTimerValue (\r
-  IN  EFI_CPU_ARCH_PROTOCOL     *This,\r
-  IN  UINT32                    TimerIndex,\r
-  OUT UINT64                    *TimerValue,\r
-  OUT UINT64                    *TimerPeriod OPTIONAL\r
+  IN  EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN  UINT32                 TimerIndex,\r
+  OUT UINT64                 *TimerValue,\r
+  OUT UINT64                 *TimerPeriod OPTIONAL\r
   )\r
 {\r
-  UINT64          BeginValue;\r
-  UINT64          EndValue;\r
+  UINT64  BeginValue;\r
+  UINT64  EndValue;\r
 \r
   if (TimerValue == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -310,7 +303,7 @@ CpuGetTimerValue (
       //\r
       BeginValue = AsmReadTsc ();\r
       MicroSecondDelay (100);\r
-      EndValue   = AsmReadTsc ();\r
+      EndValue = AsmReadTsc ();\r
       //\r
       // Calculate the actual frequency\r
       //\r
@@ -323,6 +316,7 @@ CpuGetTimerValue (
                        NULL\r
                        );\r
     }\r
+\r
     *TimerPeriod = mTimerPeriod;\r
   }\r
 \r
@@ -339,7 +333,7 @@ CpuGetTimerValue (
 VOID\r
 EFIAPI\r
 SetMtrrsFromBuffer (\r
-  IN VOID *Buffer\r
+  IN VOID  *Buffer\r
   )\r
 {\r
   MtrrSetAllMtrrs (Buffer);\r
@@ -373,10 +367,10 @@ SetMtrrsFromBuffer (
 EFI_STATUS\r
 EFIAPI\r
 CpuSetMemoryAttributes (\r
-  IN EFI_CPU_ARCH_PROTOCOL     *This,\r
-  IN EFI_PHYSICAL_ADDRESS      BaseAddress,\r
-  IN UINT64                    Length,\r
-  IN UINT64                    Attributes\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
+  IN UINT64                 Length,\r
+  IN UINT64                 Attributes\r
   )\r
 {\r
   RETURN_STATUS             Status;\r
@@ -395,7 +389,7 @@ CpuSetMemoryAttributes (
   // to avoid unnecessary computing.\r
   //\r
   if (mIsFlushingGCD) {\r
-    DEBUG((DEBUG_VERBOSE, "  Flushing GCD\n"));\r
+    DEBUG ((DEBUG_VERBOSE, "  Flushing GCD\n"));\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -410,11 +404,11 @@ CpuSetMemoryAttributes (
   // by page table memory allocation.\r
   //\r
   if (mIsAllocatingPageTable) {\r
-    DEBUG((DEBUG_VERBOSE, "  Allocating page table memory\n"));\r
+    DEBUG ((DEBUG_VERBOSE, "  Allocating page table memory\n"));\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  CacheAttributes = Attributes & EFI_CACHE_ATTRIBUTE_MASK;\r
+  CacheAttributes  = Attributes & EFI_CACHE_ATTRIBUTE_MASK;\r
   MemoryAttributes = Attributes & EFI_MEMORY_ATTRIBUTE_MASK;\r
 \r
   if (Attributes != (CacheAttributes | MemoryAttributes)) {\r
@@ -427,30 +421,31 @@ CpuSetMemoryAttributes (
     }\r
 \r
     switch (CacheAttributes) {\r
-    case EFI_MEMORY_UC:\r
-      CacheType = CacheUncacheable;\r
-      break;\r
+      case EFI_MEMORY_UC:\r
+        CacheType = CacheUncacheable;\r
+        break;\r
 \r
-    case EFI_MEMORY_WC:\r
-      CacheType = CacheWriteCombining;\r
-      break;\r
+      case EFI_MEMORY_WC:\r
+        CacheType = CacheWriteCombining;\r
+        break;\r
 \r
-    case EFI_MEMORY_WT:\r
-      CacheType = CacheWriteThrough;\r
-      break;\r
+      case EFI_MEMORY_WT:\r
+        CacheType = CacheWriteThrough;\r
+        break;\r
 \r
-    case EFI_MEMORY_WP:\r
-      CacheType = CacheWriteProtected;\r
-      break;\r
+      case EFI_MEMORY_WP:\r
+        CacheType = CacheWriteProtected;\r
+        break;\r
 \r
-    case EFI_MEMORY_WB:\r
-      CacheType = CacheWriteBack;\r
-      break;\r
+      case EFI_MEMORY_WB:\r
+        CacheType = CacheWriteBack;\r
+        break;\r
 \r
-    default:\r
-      return EFI_INVALID_PARAMETER;\r
+      default:\r
+        return EFI_INVALID_PARAMETER;\r
     }\r
-    CurrentCacheType = MtrrGetMemoryAttribute(BaseAddress);\r
+\r
+    CurrentCacheType = MtrrGetMemoryAttribute (BaseAddress);\r
     if (CurrentCacheType != CacheType) {\r
       //\r
       // call MTRR library function\r
@@ -484,7 +479,8 @@ CpuSetMemoryAttributes (
           ASSERT (MpStatus == EFI_SUCCESS || MpStatus == EFI_NOT_STARTED);\r
         }\r
       }\r
-      if (EFI_ERROR(Status)) {\r
+\r
+      if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
     }\r
@@ -507,15 +503,15 @@ InitializeMtrrMask (
   VOID\r
   )\r
 {\r
-  UINT32                              RegEax;\r
-  UINT8                               PhysicalAddressBits;\r
+  UINT32  RegEax;\r
+  UINT8   PhysicalAddressBits;\r
 \r
   AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
 \r
   if (RegEax >= 0x80000008) {\r
     AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);\r
 \r
-    PhysicalAddressBits = (UINT8) RegEax;\r
+    PhysicalAddressBits = (UINT8)RegEax;\r
   } else {\r
     PhysicalAddressBits = 36;\r
   }\r
@@ -536,22 +532,22 @@ InitializeMtrrMask (
 **/\r
 UINT64\r
 GetMemorySpaceAttributeFromMtrrType (\r
-  IN UINT8                MtrrAttributes\r
+  IN UINT8  MtrrAttributes\r
   )\r
 {\r
   switch (MtrrAttributes) {\r
-  case MTRR_CACHE_UNCACHEABLE:\r
-    return EFI_MEMORY_UC;\r
-  case MTRR_CACHE_WRITE_COMBINING:\r
-    return EFI_MEMORY_WC;\r
-  case MTRR_CACHE_WRITE_THROUGH:\r
-    return EFI_MEMORY_WT;\r
-  case MTRR_CACHE_WRITE_PROTECTED:\r
-    return EFI_MEMORY_WP;\r
-  case MTRR_CACHE_WRITE_BACK:\r
-    return EFI_MEMORY_WB;\r
-  default:\r
-    return 0;\r
+    case MTRR_CACHE_UNCACHEABLE:\r
+      return EFI_MEMORY_UC;\r
+    case MTRR_CACHE_WRITE_COMBINING:\r
+      return EFI_MEMORY_WC;\r
+    case MTRR_CACHE_WRITE_THROUGH:\r
+      return EFI_MEMORY_WT;\r
+    case MTRR_CACHE_WRITE_PROTECTED:\r
+      return EFI_MEMORY_WP;\r
+    case MTRR_CACHE_WRITE_BACK:\r
+      return EFI_MEMORY_WB;\r
+    default:\r
+      return 0;\r
   }\r
 }\r
 \r
@@ -575,29 +571,33 @@ GetMemorySpaceAttributeFromMtrrType (
 **/\r
 EFI_STATUS\r
 SearchGcdMemorySpaces (\r
-  IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR     *MemorySpaceMap,\r
-  IN UINTN                               NumberOfDescriptors,\r
-  IN EFI_PHYSICAL_ADDRESS                BaseAddress,\r
-  IN UINT64                              Length,\r
-  OUT UINTN                              *StartIndex,\r
-  OUT UINTN                              *EndIndex\r
+  IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap,\r
+  IN UINTN                            NumberOfDescriptors,\r
+  IN EFI_PHYSICAL_ADDRESS             BaseAddress,\r
+  IN UINT64                           Length,\r
+  OUT UINTN                           *StartIndex,\r
+  OUT UINTN                           *EndIndex\r
   )\r
 {\r
-  UINTN           Index;\r
+  UINTN  Index;\r
 \r
   *StartIndex = 0;\r
   *EndIndex   = 0;\r
   for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
-    if (BaseAddress >= MemorySpaceMap[Index].BaseAddress &&\r
-        BaseAddress < MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) {\r
+    if ((BaseAddress >= MemorySpaceMap[Index].BaseAddress) &&\r
+        (BaseAddress < MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length))\r
+    {\r
       *StartIndex = Index;\r
     }\r
-    if (BaseAddress + Length - 1 >= MemorySpaceMap[Index].BaseAddress &&\r
-        BaseAddress + Length - 1 < MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) {\r
+\r
+    if ((BaseAddress + Length - 1 >= MemorySpaceMap[Index].BaseAddress) &&\r
+        (BaseAddress + Length - 1 < MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length))\r
+    {\r
       *EndIndex = Index;\r
       return EFI_SUCCESS;\r
     }\r
   }\r
+\r
   return EFI_NOT_FOUND;\r
 }\r
 \r
@@ -619,11 +619,11 @@ SearchGcdMemorySpaces (
 **/\r
 EFI_STATUS\r
 SetGcdMemorySpaceAttributes (\r
-  IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR     *MemorySpaceMap,\r
-  IN UINTN                               NumberOfDescriptors,\r
-  IN EFI_PHYSICAL_ADDRESS                BaseAddress,\r
-  IN UINT64                              Length,\r
-  IN UINT64                              Attributes\r
+  IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap,\r
+  IN UINTN                            NumberOfDescriptors,\r
+  IN EFI_PHYSICAL_ADDRESS             BaseAddress,\r
+  IN UINT64                           Length,\r
+  IN UINT64                           Attributes\r
   )\r
 {\r
   EFI_STATUS            Status;\r
@@ -655,6 +655,7 @@ SetGcdMemorySpaceAttributes (
     if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeNonExistent) {\r
       continue;\r
     }\r
+\r
     //\r
     // Calculate the start and end address of the overlapping range\r
     //\r
@@ -663,11 +664,13 @@ SetGcdMemorySpaceAttributes (
     } else {\r
       RegionStart = MemorySpaceMap[Index].BaseAddress;\r
     }\r
+\r
     if (BaseAddress + Length - 1 < MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) {\r
       RegionLength = BaseAddress + Length - RegionStart;\r
     } else {\r
       RegionLength = MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - RegionStart;\r
     }\r
+\r
     //\r
     // Set memory attributes according to MTRR attribute and the original attribute of descriptor\r
     //\r
@@ -681,7 +684,6 @@ SetGcdMemorySpaceAttributes (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Refreshes the GCD Memory Space attributes according to MTRRs.\r
 \r
@@ -693,22 +695,22 @@ RefreshMemoryAttributesFromMtrr (
   VOID\r
   )\r
 {\r
-  EFI_STATUS                          Status;\r
-  UINTN                               Index;\r
-  UINTN                               SubIndex;\r
-  UINT64                              RegValue;\r
-  EFI_PHYSICAL_ADDRESS                BaseAddress;\r
-  UINT64                              Length;\r
-  UINT64                              Attributes;\r
-  UINT64                              CurrentAttributes;\r
-  UINT8                               MtrrType;\r
-  UINTN                               NumberOfDescriptors;\r
-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR     *MemorySpaceMap;\r
-  UINT64                              DefaultAttributes;\r
-  VARIABLE_MTRR                       VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
-  MTRR_FIXED_SETTINGS                 MtrrFixedSettings;\r
-  UINT32                              FirmwareVariableMtrrCount;\r
-  UINT8                               DefaultMemoryType;\r
+  EFI_STATUS                       Status;\r
+  UINTN                            Index;\r
+  UINTN                            SubIndex;\r
+  UINT64                           RegValue;\r
+  EFI_PHYSICAL_ADDRESS             BaseAddress;\r
+  UINT64                           Length;\r
+  UINT64                           Attributes;\r
+  UINT64                           CurrentAttributes;\r
+  UINT8                            MtrrType;\r
+  UINTN                            NumberOfDescriptors;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap;\r
+  UINT64                           DefaultAttributes;\r
+  VARIABLE_MTRR                    VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
+  MTRR_FIXED_SETTINGS              MtrrFixedSettings;\r
+  UINT32                           FirmwareVariableMtrrCount;\r
+  UINT8                            DefaultMemoryType;\r
 \r
   FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();\r
   ASSERT (FirmwareVariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);\r
@@ -738,7 +740,7 @@ RefreshMemoryAttributesFromMtrr (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  DefaultMemoryType = (UINT8) MtrrGetDefaultMemoryType ();\r
+  DefaultMemoryType = (UINT8)MtrrGetDefaultMemoryType ();\r
   DefaultAttributes = GetMemorySpaceAttributeFromMtrrType (DefaultMemoryType);\r
 \r
   //\r
@@ -748,6 +750,7 @@ RefreshMemoryAttributesFromMtrr (
     if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeNonExistent) {\r
       continue;\r
     }\r
+\r
     gDS->SetMemorySpaceAttributes (\r
            MemorySpaceMap[Index].BaseAddress,\r
            MemorySpaceMap[Index].Length,\r
@@ -761,7 +764,8 @@ RefreshMemoryAttributesFromMtrr (
   //\r
   for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
     if (VariableMtrr[Index].Valid &&\r
-        VariableMtrr[Index].Type == MTRR_CACHE_WRITE_BACK) {\r
+        (VariableMtrr[Index].Type == MTRR_CACHE_WRITE_BACK))\r
+    {\r
       SetGcdMemorySpaceAttributes (\r
         MemorySpaceMap,\r
         NumberOfDescriptors,\r
@@ -777,9 +781,10 @@ RefreshMemoryAttributesFromMtrr (
   //\r
   for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
     if (VariableMtrr[Index].Valid &&\r
-        VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK &&\r
-        VariableMtrr[Index].Type != MTRR_CACHE_UNCACHEABLE) {\r
-      Attributes = GetMemorySpaceAttributeFromMtrrType ((UINT8) VariableMtrr[Index].Type);\r
+        (VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK) &&\r
+        (VariableMtrr[Index].Type != MTRR_CACHE_UNCACHEABLE))\r
+    {\r
+      Attributes = GetMemorySpaceAttributeFromMtrrType ((UINT8)VariableMtrr[Index].Type);\r
       SetGcdMemorySpaceAttributes (\r
         MemorySpaceMap,\r
         NumberOfDescriptors,\r
@@ -795,7 +800,8 @@ RefreshMemoryAttributesFromMtrr (
   //\r
   for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
     if (VariableMtrr[Index].Valid &&\r
-        VariableMtrr[Index].Type == MTRR_CACHE_UNCACHEABLE) {\r
+        (VariableMtrr[Index].Type == MTRR_CACHE_UNCACHEABLE))\r
+    {\r
       SetGcdMemorySpaceAttributes (\r
         MemorySpaceMap,\r
         NumberOfDescriptors,\r
@@ -819,7 +825,7 @@ RefreshMemoryAttributesFromMtrr (
     // Check for continuous fixed MTRR sections\r
     //\r
     for (SubIndex = 0; SubIndex < 8; SubIndex++) {\r
-      MtrrType = (UINT8) RShiftU64 (RegValue, SubIndex * 8);\r
+      MtrrType          = (UINT8)RShiftU64 (RegValue, SubIndex * 8);\r
       CurrentAttributes = GetMemorySpaceAttributeFromMtrrType (MtrrType);\r
       if (Length == 0) {\r
         //\r
@@ -839,13 +845,15 @@ RefreshMemoryAttributesFromMtrr (
             Attributes\r
             );\r
           BaseAddress = mFixedMtrrTable[Index].BaseAddress + mFixedMtrrTable[Index].Length * SubIndex;\r
-          Length = 0;\r
-          Attributes = CurrentAttributes;\r
+          Length      = 0;\r
+          Attributes  = CurrentAttributes;\r
         }\r
       }\r
+\r
       Length += mFixedMtrrTable[Index].Length;\r
     }\r
   }\r
+\r
   //\r
   // Handle the last fixed MTRR region\r
   //\r
@@ -916,20 +924,20 @@ InitInterruptDescriptorTable (
   VOID\r
   )\r
 {\r
-  EFI_STATUS                     Status;\r
-  EFI_VECTOR_HANDOFF_INFO        *VectorInfoList;\r
-  EFI_VECTOR_HANDOFF_INFO        *VectorInfo;\r
+  EFI_STATUS               Status;\r
+  EFI_VECTOR_HANDOFF_INFO  *VectorInfoList;\r
+  EFI_VECTOR_HANDOFF_INFO  *VectorInfo;\r
 \r
   VectorInfo = NULL;\r
-  Status = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID **) &VectorInfoList);\r
-  if (Status == EFI_SUCCESS && VectorInfoList != NULL) {\r
+  Status     = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID **)&VectorInfoList);\r
+  if ((Status == EFI_SUCCESS) && (VectorInfoList != NULL)) {\r
     VectorInfo = VectorInfoList;\r
   }\r
+\r
   Status = InitializeCpuInterruptHandlers (VectorInfo);\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
-\r
 /**\r
   Callback function for idle events.\r
 \r
@@ -941,8 +949,8 @@ InitInterruptDescriptorTable (
 VOID\r
 EFIAPI\r
 IdleLoopEventCallback (\r
-  IN EFI_EVENT                Event,\r
-  IN VOID                     *Context\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
   )\r
 {\r
   CpuSleep ();\r
@@ -989,24 +997,27 @@ IdleLoopEventCallback (
 **/\r
 EFI_STATUS\r
 IntersectMemoryDescriptor (\r
-  IN  UINT64                                Base,\r
-  IN  UINT64                                Length,\r
-  IN  UINT64                                Capabilities,\r
-  IN  CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor\r
+  IN  UINT64                                 Base,\r
+  IN  UINT64                                 Length,\r
+  IN  UINT64                                 Capabilities,\r
+  IN  CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *Descriptor\r
   )\r
 {\r
-  UINT64                                    IntersectionBase;\r
-  UINT64                                    IntersectionEnd;\r
-  EFI_STATUS                                Status;\r
+  UINT64      IntersectionBase;\r
+  UINT64      IntersectionEnd;\r
+  EFI_STATUS  Status;\r
 \r
-  if (Descriptor->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo &&\r
-      (Descriptor->Capabilities & Capabilities) == Capabilities) {\r
+  if ((Descriptor->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&\r
+      ((Descriptor->Capabilities & Capabilities) == Capabilities))\r
+  {\r
     return EFI_SUCCESS;\r
   }\r
 \r
   IntersectionBase = MAX (Base, Descriptor->BaseAddress);\r
-  IntersectionEnd = MIN (Base + Length,\r
-                      Descriptor->BaseAddress + Descriptor->Length);\r
+  IntersectionEnd  = MIN (\r
+                       Base + Length,\r
+                       Descriptor->BaseAddress + Descriptor->Length\r
+                       );\r
   if (IntersectionBase >= IntersectionEnd) {\r
     //\r
     // The descriptor and the aperture don't overlap.\r
@@ -1015,21 +1026,39 @@ IntersectMemoryDescriptor (
   }\r
 \r
   if (Descriptor->GcdMemoryType == EfiGcdMemoryTypeNonExistent) {\r
-    Status = gDS->AddMemorySpace (EfiGcdMemoryTypeMemoryMappedIo,\r
-                    IntersectionBase, IntersectionEnd - IntersectionBase,\r
-                    Capabilities);\r
-\r
-    DEBUG ((EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE,\r
-      "%a: %a: add [%Lx, %Lx): %r\n", gEfiCallerBaseName, __FUNCTION__,\r
-      IntersectionBase, IntersectionEnd, Status));\r
+    Status = gDS->AddMemorySpace (\r
+                    EfiGcdMemoryTypeMemoryMappedIo,\r
+                    IntersectionBase,\r
+                    IntersectionEnd - IntersectionBase,\r
+                    Capabilities\r
+                    );\r
+\r
+    DEBUG ((\r
+      EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE,\r
+      "%a: %a: add [%Lx, %Lx): %r\n",\r
+      gEfiCallerBaseName,\r
+      __FUNCTION__,\r
+      IntersectionBase,\r
+      IntersectionEnd,\r
+      Status\r
+      ));\r
     return Status;\r
   }\r
 \r
-  DEBUG ((DEBUG_ERROR, "%a: %a: desc [%Lx, %Lx) type %u cap %Lx conflicts "\r
-    "with aperture [%Lx, %Lx) cap %Lx\n", gEfiCallerBaseName, __FUNCTION__,\r
-    Descriptor->BaseAddress, Descriptor->BaseAddress + Descriptor->Length,\r
-    (UINT32)Descriptor->GcdMemoryType, Descriptor->Capabilities,\r
-    Base, Base + Length, Capabilities));\r
+  DEBUG ((\r
+    DEBUG_ERROR,\r
+    "%a: %a: desc [%Lx, %Lx) type %u cap %Lx conflicts "\r
+    "with aperture [%Lx, %Lx) cap %Lx\n",\r
+    gEfiCallerBaseName,\r
+    __FUNCTION__,\r
+    Descriptor->BaseAddress,\r
+    Descriptor->BaseAddress + Descriptor->Length,\r
+    (UINT32)Descriptor->GcdMemoryType,\r
+    Descriptor->Capabilities,\r
+    Base,\r
+    Base + Length,\r
+    Capabilities\r
+    ));\r
   return EFI_INVALID_PARAMETER;\r
 }\r
 \r
@@ -1046,49 +1075,60 @@ IntersectMemoryDescriptor (
 **/\r
 EFI_STATUS\r
 AddMemoryMappedIoSpace (\r
-  IN  UINT64                            Base,\r
-  IN  UINT64                            Length,\r
-  IN  UINT64                            Capabilities\r
+  IN  UINT64  Base,\r
+  IN  UINT64  Length,\r
+  IN  UINT64  Capabilities\r
   )\r
 {\r
-  EFI_STATUS                            Status;\r
-  UINTN                                 Index;\r
-  UINTN                                 NumberOfDescriptors;\r
-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR       *MemorySpaceMap;\r
+  EFI_STATUS                       Status;\r
+  UINTN                            Index;\r
+  UINTN                            NumberOfDescriptors;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap;\r
 \r
   Status = gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((DEBUG_ERROR, "%a: %a: GetMemorySpaceMap(): %r\n",\r
-      gEfiCallerBaseName, __FUNCTION__, Status));\r
+    DEBUG ((\r
+      DEBUG_ERROR,\r
+      "%a: %a: GetMemorySpaceMap(): %r\n",\r
+      gEfiCallerBaseName,\r
+      __FUNCTION__,\r
+      Status\r
+      ));\r
     return Status;\r
   }\r
 \r
   for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
-    Status = IntersectMemoryDescriptor (Base, Length, Capabilities,\r
-               &MemorySpaceMap[Index]);\r
+    Status = IntersectMemoryDescriptor (\r
+               Base,\r
+               Length,\r
+               Capabilities,\r
+               &MemorySpaceMap[Index]\r
+               );\r
     if (EFI_ERROR (Status)) {\r
       goto FreeMemorySpaceMap;\r
     }\r
   }\r
 \r
   DEBUG_CODE_BEGIN ();\r
-    //\r
-    // Make sure there are adjacent descriptors covering [Base, Base + Length).\r
-    // It is possible that they have not been merged; merging can be prevented\r
-    // by allocation and different capabilities.\r
-    //\r
-    UINT64                          CheckBase;\r
-    EFI_STATUS                      CheckStatus;\r
-    EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r
-\r
-    for (CheckBase = Base;\r
-         CheckBase < Base + Length;\r
-         CheckBase = Descriptor.BaseAddress + Descriptor.Length) {\r
-      CheckStatus = gDS->GetMemorySpaceDescriptor (CheckBase, &Descriptor);\r
-      ASSERT_EFI_ERROR (CheckStatus);\r
-      ASSERT (Descriptor.GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo);\r
-      ASSERT ((Descriptor.Capabilities & Capabilities) == Capabilities);\r
-    }\r
+  //\r
+  // Make sure there are adjacent descriptors covering [Base, Base + Length).\r
+  // It is possible that they have not been merged; merging can be prevented\r
+  // by allocation and different capabilities.\r
+  //\r
+  UINT64                           CheckBase;\r
+  EFI_STATUS                       CheckStatus;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR  Descriptor;\r
+\r
+  for (CheckBase = Base;\r
+       CheckBase < Base + Length;\r
+       CheckBase = Descriptor.BaseAddress + Descriptor.Length)\r
+  {\r
+    CheckStatus = gDS->GetMemorySpaceDescriptor (CheckBase, &Descriptor);\r
+    ASSERT_EFI_ERROR (CheckStatus);\r
+    ASSERT (Descriptor.GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo);\r
+    ASSERT ((Descriptor.Capabilities & Capabilities) == Capabilities);\r
+  }\r
+\r
   DEBUG_CODE_END ();\r
 \r
 FreeMemorySpaceMap:\r
@@ -1105,14 +1145,14 @@ FreeMemorySpaceMap:
 **/\r
 VOID\r
 AddLocalApicMemorySpace (\r
-  IN EFI_HANDLE               ImageHandle\r
+  IN EFI_HANDLE  ImageHandle\r
   )\r
 {\r
-  EFI_STATUS              Status;\r
-  EFI_PHYSICAL_ADDRESS    BaseAddress;\r
+  EFI_STATUS            Status;\r
+  EFI_PHYSICAL_ADDRESS  BaseAddress;\r
 \r
-  BaseAddress = (EFI_PHYSICAL_ADDRESS) GetLocalApicBaseAddress();\r
-  Status = AddMemoryMappedIoSpace (BaseAddress, SIZE_4KB, EFI_MEMORY_UC);\r
+  BaseAddress = (EFI_PHYSICAL_ADDRESS)GetLocalApicBaseAddress ();\r
+  Status      = AddMemoryMappedIoSpace (BaseAddress, SIZE_4KB, EFI_MEMORY_UC);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
@@ -1130,8 +1170,13 @@ AddLocalApicMemorySpace (
                   NULL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((DEBUG_INFO, "%a: %a: AllocateMemorySpace() Status - %r\n",\r
-                         gEfiCallerBaseName, __FUNCTION__, Status));\r
+    DEBUG ((\r
+      DEBUG_INFO,\r
+      "%a: %a: AllocateMemorySpace() Status - %r\n",\r
+      gEfiCallerBaseName,\r
+      __FUNCTION__,\r
+      Status\r
+      ));\r
   }\r
 }\r
 \r
@@ -1149,14 +1194,14 @@ AddLocalApicMemorySpace (
 EFI_STATUS\r
 EFIAPI\r
 InitializeCpu (\r
-  IN EFI_HANDLE                            ImageHandle,\r
-  IN EFI_SYSTEM_TABLE                      *SystemTable\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
   EFI_STATUS  Status;\r
   EFI_EVENT   IdleLoopEvent;\r
 \r
-  InitializePageTableLib();\r
+  InitializePageTableLib ();\r
 \r
   InitializeFloatingPointUnits ();\r
 \r
@@ -1180,7 +1225,8 @@ InitializeCpu (
   //\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &mCpuHandle,\r
-                  &gEfiCpuArchProtocolGuid, &gCpu,\r
+                  &gEfiCpuArchProtocolGuid,\r
+                  &gCpu,\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r