]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
UefiCpuPkg: Apply uncrustify changes
[mirror_edk2.git] / UefiCpuPkg / Library / RegisterCpuFeaturesLib / CpuFeaturesInitialize.c
index 2f77ab3aeb559b1f6a3565dcf06470e7e19b395a..a8e4f920fc9e7e90159729a07d9365bd1961d76d 100644 (file)
@@ -8,7 +8,7 @@
 \r
 #include "RegisterCpuFeatures.h"\r
 \r
-CHAR16 *mDependTypeStr[]   = {L"None", L"Thread", L"Core", L"Package", L"Invalid" };\r
+CHAR16  *mDependTypeStr[] = { L"None", L"Thread", L"Core", L"Package", L"Invalid" };\r
 \r
 /**\r
   Worker function to save PcdCpuFeaturesCapability.\r
@@ -19,11 +19,11 @@ CHAR16 *mDependTypeStr[]   = {L"None", L"Thread", L"Core", L"Package", L"Invalid
 **/\r
 VOID\r
 SetCapabilityPcd (\r
-  IN UINT8               *SupportedFeatureMask,\r
-  IN UINTN               BitMaskSize\r
+  IN UINT8  *SupportedFeatureMask,\r
+  IN UINTN  BitMaskSize\r
   )\r
 {\r
-  EFI_STATUS             Status;\r
+  EFI_STATUS  Status;\r
 \r
   Status = PcdSetPtrS (PcdCpuFeaturesCapability, &BitMaskSize, SupportedFeatureMask);\r
   ASSERT_EFI_ERROR (Status);\r
@@ -37,11 +37,11 @@ SetCapabilityPcd (
 **/\r
 VOID\r
 SetSettingPcd (\r
-  IN UINT8               *SupportedFeatureMask,\r
-  IN UINTN               BitMaskSize\r
+  IN UINT8  *SupportedFeatureMask,\r
+  IN UINTN  BitMaskSize\r
   )\r
 {\r
-  EFI_STATUS             Status;\r
+  EFI_STATUS  Status;\r
 \r
   Status = PcdSetPtrS (PcdCpuFeaturesSetting, &BitMaskSize, SupportedFeatureMask);\r
   ASSERT_EFI_ERROR (Status);\r
@@ -54,14 +54,14 @@ SetSettingPcd (
 **/\r
 VOID\r
 FillProcessorInfo (\r
-  IN OUT REGISTER_CPU_FEATURE_INFORMATION        *CpuInfo\r
+  IN OUT REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo\r
   )\r
 {\r
-  CPUID_VERSION_INFO_EAX Eax;\r
-  CPUID_VERSION_INFO_ECX Ecx;\r
-  CPUID_VERSION_INFO_EDX Edx;\r
-  UINT32                 DisplayedFamily;\r
-  UINT32                 DisplayedModel;\r
+  CPUID_VERSION_INFO_EAX  Eax;\r
+  CPUID_VERSION_INFO_ECX  Ecx;\r
+  CPUID_VERSION_INFO_EDX  Edx;\r
+  UINT32                  DisplayedFamily;\r
+  UINT32                  DisplayedModel;\r
 \r
   AsmCpuid (CPUID_VERSION_INFO, &Eax.Uint32, NULL, &Ecx.Uint32, &Edx.Uint32);\r
 \r
@@ -71,14 +71,14 @@ FillProcessorInfo (
   }\r
 \r
   DisplayedModel = Eax.Bits.Model;\r
-  if (Eax.Bits.FamilyId == 0x06 || Eax.Bits.FamilyId == 0x0f) {\r
+  if ((Eax.Bits.FamilyId == 0x06) || (Eax.Bits.FamilyId == 0x0f)) {\r
     DisplayedModel |= (Eax.Bits.ExtendedModelId << 4);\r
   }\r
 \r
-  CpuInfo->DisplayFamily = DisplayedFamily;\r
-  CpuInfo->DisplayModel  = DisplayedModel;\r
-  CpuInfo->SteppingId    = Eax.Bits.SteppingId;\r
-  CpuInfo->ProcessorType = Eax.Bits.ProcessorType;\r
+  CpuInfo->DisplayFamily              = DisplayedFamily;\r
+  CpuInfo->DisplayModel               = DisplayedModel;\r
+  CpuInfo->SteppingId                 = Eax.Bits.SteppingId;\r
+  CpuInfo->ProcessorType              = Eax.Bits.ProcessorType;\r
   CpuInfo->CpuIdVersionInfoEcx.Uint32 = Ecx.Uint32;\r
   CpuInfo->CpuIdVersionInfoEdx.Uint32 = Edx.Uint32;\r
 }\r
@@ -92,29 +92,29 @@ CpuInitDataInitialize (
   VOID\r
   )\r
 {\r
-  EFI_STATUS                           Status;\r
-  UINTN                                ProcessorNumber;\r
-  EFI_PROCESSOR_INFORMATION            ProcessorInfoBuffer;\r
-  CPU_FEATURES_ENTRY                   *CpuFeature;\r
-  CPU_FEATURES_INIT_ORDER              *InitOrder;\r
-  CPU_FEATURES_DATA                    *CpuFeaturesData;\r
-  LIST_ENTRY                           *Entry;\r
-  UINT32                               Core;\r
-  UINT32                               Package;\r
-  UINT32                               Thread;\r
-  EFI_CPU_PHYSICAL_LOCATION            *Location;\r
-  UINT32                               PackageIndex;\r
-  UINT32                               CoreIndex;\r
-  UINTN                                Pages;\r
-  UINT32                               FirstPackage;\r
-  UINT32                               *FirstCore;\r
-  UINT32                               *FirstThread;\r
-  ACPI_CPU_DATA                        *AcpiCpuData;\r
-  CPU_STATUS_INFORMATION               *CpuStatus;\r
-  UINT32                               *ThreadCountPerPackage;\r
-  UINT8                                *ThreadCountPerCore;\r
-  UINTN                                NumberOfCpus;\r
-  UINTN                                NumberOfEnabledProcessors;\r
+  EFI_STATUS                 Status;\r
+  UINTN                      ProcessorNumber;\r
+  EFI_PROCESSOR_INFORMATION  ProcessorInfoBuffer;\r
+  CPU_FEATURES_ENTRY         *CpuFeature;\r
+  CPU_FEATURES_INIT_ORDER    *InitOrder;\r
+  CPU_FEATURES_DATA          *CpuFeaturesData;\r
+  LIST_ENTRY                 *Entry;\r
+  UINT32                     Core;\r
+  UINT32                     Package;\r
+  UINT32                     Thread;\r
+  EFI_CPU_PHYSICAL_LOCATION  *Location;\r
+  UINT32                     PackageIndex;\r
+  UINT32                     CoreIndex;\r
+  UINTN                      Pages;\r
+  UINT32                     FirstPackage;\r
+  UINT32                     *FirstCore;\r
+  UINT32                     *FirstThread;\r
+  ACPI_CPU_DATA              *AcpiCpuData;\r
+  CPU_STATUS_INFORMATION     *CpuStatus;\r
+  UINT32                     *ThreadCountPerPackage;\r
+  UINT8                      *ThreadCountPerCore;\r
+  UINTN                      NumberOfCpus;\r
+  UINTN                      NumberOfEnabledProcessors;\r
 \r
   Core    = 0;\r
   Package = 0;\r
@@ -143,23 +143,24 @@ CpuInitDataInitialize (
     if (CpuFeature->GetConfigDataFunc != NULL) {\r
       CpuFeature->ConfigData = CpuFeature->GetConfigDataFunc (NumberOfCpus);\r
     }\r
+\r
     Entry = Entry->ForwardLink;\r
   }\r
 \r
-  CpuFeaturesData->NumberOfCpus = (UINT32) NumberOfCpus;\r
+  CpuFeaturesData->NumberOfCpus = (UINT32)NumberOfCpus;\r
 \r
   AcpiCpuData = GetAcpiCpuData ();\r
   ASSERT (AcpiCpuData != NULL);\r
-  CpuFeaturesData->AcpiCpuData= AcpiCpuData;\r
+  CpuFeaturesData->AcpiCpuData = AcpiCpuData;\r
 \r
   CpuStatus = &AcpiCpuData->CpuFeatureInitData.CpuStatus;\r
-  Location = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus));\r
+  Location  = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus));\r
   ASSERT (Location != NULL);\r
   ZeroMem (Location, sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus);\r
   AcpiCpuData->CpuFeatureInitData.ApLocation = (EFI_PHYSICAL_ADDRESS)(UINTN)Location;\r
 \r
   for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {\r
-    InitOrder = &CpuFeaturesData->InitOrder[ProcessorNumber];\r
+    InitOrder                        = &CpuFeaturesData->InitOrder[ProcessorNumber];\r
     InitOrder->FeaturesSupportedMask = AllocateZeroPool (CpuFeaturesData->BitMaskSize);\r
     ASSERT (InitOrder->FeaturesSupportedMask != NULL);\r
     InitializeListHead (&InitOrder->OrderList);\r
@@ -182,12 +183,14 @@ CpuInitDataInitialize (
     if (Package < ProcessorInfoBuffer.Location.Package) {\r
       Package = ProcessorInfoBuffer.Location.Package;\r
     }\r
+\r
     //\r
     // Collect CPU max core count info.\r
     //\r
     if (Core < ProcessorInfoBuffer.Location.Core) {\r
       Core = ProcessorInfoBuffer.Location.Core;\r
     }\r
+\r
     //\r
     // Collect CPU max thread count info.\r
     //\r
@@ -195,13 +198,17 @@ CpuInitDataInitialize (
       Thread = ProcessorInfoBuffer.Location.Thread;\r
     }\r
   }\r
-  CpuStatus->PackageCount    = Package + 1;\r
-  CpuStatus->MaxCoreCount    = Core + 1;\r
-  CpuStatus->MaxThreadCount  = Thread + 1;\r
-  DEBUG ((DEBUG_INFO, "Processor Info: Package: %d, MaxCore : %d, MaxThread: %d\n",\r
-         CpuStatus->PackageCount,\r
-         CpuStatus->MaxCoreCount,\r
-         CpuStatus->MaxThreadCount));\r
+\r
+  CpuStatus->PackageCount   = Package + 1;\r
+  CpuStatus->MaxCoreCount   = Core + 1;\r
+  CpuStatus->MaxThreadCount = Thread + 1;\r
+  DEBUG ((\r
+    DEBUG_INFO,\r
+    "Processor Info: Package: %d, MaxCore : %d, MaxThread: %d\n",\r
+    CpuStatus->PackageCount,\r
+    CpuStatus->MaxCoreCount,\r
+    CpuStatus->MaxThreadCount\r
+    ));\r
 \r
   //\r
   // Collect valid core count in each package because not all cores are valid.\r
@@ -228,7 +235,10 @@ CpuInitDataInitialize (
       for (CoreIndex = 0; CoreIndex < CpuStatus->MaxCoreCount; CoreIndex++) {\r
         if (ThreadCountPerCore[PackageIndex * CpuStatus->MaxCoreCount + CoreIndex] != 0) {\r
           DEBUG ((\r
-            DEBUG_INFO, "  P%02d C%04d, Thread Count = %d\n", PackageIndex, CoreIndex,\r
+            DEBUG_INFO,\r
+            "  P%02d C%04d, Thread Count = %d\n",\r
+            PackageIndex,\r
+            CoreIndex,\r
             ThreadCountPerCore[PackageIndex * CpuStatus->MaxCoreCount + CoreIndex]\r
             ));\r
         }\r
@@ -248,13 +258,13 @@ CpuInitDataInitialize (
   Pages     = EFI_SIZE_TO_PAGES (CpuStatus->PackageCount * sizeof (UINT32) + CpuStatus->PackageCount * CpuStatus->MaxCoreCount * sizeof (UINT32));\r
   FirstCore = AllocatePages (Pages);\r
   ASSERT (FirstCore != NULL);\r
-  FirstThread  = FirstCore + CpuStatus->PackageCount;\r
+  FirstThread = FirstCore + CpuStatus->PackageCount;\r
 \r
   //\r
   // Set FirstPackage, FirstCore[], FirstThread[] to maximum package ID, core ID, thread ID.\r
   //\r
   FirstPackage = MAX_UINT32;\r
-  SetMem32 (FirstCore,   CpuStatus->PackageCount * sizeof (UINT32), MAX_UINT32);\r
+  SetMem32 (FirstCore, CpuStatus->PackageCount * sizeof (UINT32), MAX_UINT32);\r
   SetMem32 (FirstThread, CpuStatus->PackageCount * CpuStatus->MaxCoreCount * sizeof (UINT32), MAX_UINT32);\r
 \r
   for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {\r
@@ -263,7 +273,7 @@ CpuInitDataInitialize (
     //\r
     // Save the minimum package ID in the platform.\r
     //\r
-    FirstPackage                 = MIN (Location->Package, FirstPackage);\r
+    FirstPackage = MIN (Location->Package, FirstPackage);\r
 \r
     //\r
     // Save the minimum core ID per package.\r
@@ -274,9 +284,9 @@ CpuInitDataInitialize (
     // Save the minimum thread ID per core.\r
     //\r
     FirstThread[Location->Package * CpuStatus->MaxCoreCount + Location->Core] = MIN (\r
-      Location->Thread,\r
-      FirstThread[Location->Package * CpuStatus->MaxCoreCount + Location->Core]\r
-    );\r
+                                                                                  Location->Thread,\r
+                                                                                  FirstThread[Location->Package * CpuStatus->MaxCoreCount + Location->Core]\r
+                                                                                  );\r
   }\r
 \r
   //\r
@@ -293,13 +303,14 @@ CpuInitDataInitialize (
     // Set First.Die/Tile/Module for each thread assuming:\r
     //  single Die under each package, single Tile under each Die, single Module under each Tile\r
     //\r
-    CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Die = 1;\r
-    CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Tile = 1;\r
+    CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Die    = 1;\r
+    CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Tile   = 1;\r
     CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Module = 1;\r
 \r
     if (Location->Core == FirstCore[Location->Package]) {\r
       CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Core = 1;\r
     }\r
+\r
     if (Location->Thread == FirstThread[Location->Package * CpuStatus->MaxCoreCount + Location->Core]) {\r
       CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Thread = 1;\r
     }\r
@@ -318,14 +329,14 @@ CpuInitDataInitialize (
 **/\r
 VOID\r
 SupportedMaskOr (\r
-  IN UINT8               *SupportedFeatureMask,\r
-  IN UINT8               *OrFeatureBitMask,\r
-  IN UINT32              BitMaskSize\r
+  IN UINT8   *SupportedFeatureMask,\r
+  IN UINT8   *OrFeatureBitMask,\r
+  IN UINT32  BitMaskSize\r
   )\r
 {\r
-  UINTN                  Index;\r
-  UINT8                  *Data1;\r
-  UINT8                  *Data2;\r
+  UINTN  Index;\r
+  UINT8  *Data1;\r
+  UINT8  *Data2;\r
 \r
   Data1 = SupportedFeatureMask;\r
   Data2 = OrFeatureBitMask;\r
@@ -344,14 +355,14 @@ SupportedMaskOr (
 **/\r
 VOID\r
 SupportedMaskAnd (\r
-  IN       UINT8               *SupportedFeatureMask,\r
-  IN CONST UINT8               *AndFeatureBitMask,\r
-  IN       UINT32              BitMaskSize\r
+  IN       UINT8   *SupportedFeatureMask,\r
+  IN CONST UINT8   *AndFeatureBitMask,\r
+  IN       UINT32  BitMaskSize\r
   )\r
 {\r
-  UINTN                  Index;\r
-  UINT8                  *Data1;\r
-  CONST UINT8            *Data2;\r
+  UINTN        Index;\r
+  UINT8        *Data1;\r
+  CONST UINT8  *Data2;\r
 \r
   Data1 = SupportedFeatureMask;\r
   Data2 = AndFeatureBitMask;\r
@@ -369,14 +380,14 @@ SupportedMaskAnd (
 **/\r
 VOID\r
 SupportedMaskCleanBit (\r
-  IN UINT8               *SupportedFeatureMask,\r
-  IN UINT8               *AndFeatureBitMask,\r
-  IN UINT32              BitMaskSize\r
+  IN UINT8   *SupportedFeatureMask,\r
+  IN UINT8   *AndFeatureBitMask,\r
+  IN UINT32  BitMaskSize\r
   )\r
 {\r
-  UINTN                  Index;\r
-  UINT8                  *Data1;\r
-  UINT8                  *Data2;\r
+  UINTN  Index;\r
+  UINT8  *Data1;\r
+  UINT8  *Data2;\r
 \r
   Data1 = SupportedFeatureMask;\r
   Data2 = AndFeatureBitMask;\r
@@ -400,14 +411,14 @@ SupportedMaskCleanBit (
 **/\r
 BOOLEAN\r
 IsBitMaskMatch (\r
-  IN UINT8               *SupportedFeatureMask,\r
-  IN UINT8               *ComparedFeatureBitMask,\r
-  IN UINT32              BitMaskSize\r
+  IN UINT8   *SupportedFeatureMask,\r
+  IN UINT8   *ComparedFeatureBitMask,\r
+  IN UINT32  BitMaskSize\r
   )\r
 {\r
-  UINTN                  Index;\r
-  UINT8                  *Data1;\r
-  UINT8                  *Data2;\r
+  UINTN  Index;\r
+  UINT8  *Data1;\r
+  UINT8  *Data2;\r
 \r
   Data1 = SupportedFeatureMask;\r
   Data2 = ComparedFeatureBitMask;\r
@@ -416,6 +427,7 @@ IsBitMaskMatch (
       return TRUE;\r
     }\r
   }\r
+\r
   return FALSE;\r
 }\r
 \r
@@ -427,18 +439,18 @@ IsBitMaskMatch (
 VOID\r
 EFIAPI\r
 CollectProcessorData (\r
-  IN OUT VOID                          *Buffer\r
+  IN OUT VOID  *Buffer\r
   )\r
 {\r
-  UINTN                                ProcessorNumber;\r
-  CPU_FEATURES_ENTRY                   *CpuFeature;\r
-  REGISTER_CPU_FEATURE_INFORMATION     *CpuInfo;\r
-  LIST_ENTRY                           *Entry;\r
-  CPU_FEATURES_DATA                    *CpuFeaturesData;\r
+  UINTN                             ProcessorNumber;\r
+  CPU_FEATURES_ENTRY                *CpuFeature;\r
+  REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo;\r
+  LIST_ENTRY                        *Entry;\r
+  CPU_FEATURES_DATA                 *CpuFeaturesData;\r
 \r
   CpuFeaturesData = (CPU_FEATURES_DATA *)Buffer;\r
   ProcessorNumber = GetProcessorIndex (CpuFeaturesData);\r
-  CpuInfo = &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo;\r
+  CpuInfo         = &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo;\r
   //\r
   // collect processor information\r
   //\r
@@ -462,6 +474,7 @@ CollectProcessorData (
         CpuFeaturesData->BitMaskSize\r
         );\r
     }\r
+\r
     Entry = Entry->ForwardLink;\r
   }\r
 }\r
@@ -475,15 +488,15 @@ CollectProcessorData (
 **/\r
 VOID\r
 DumpRegisterTableOnProcessor (\r
-  IN UINTN                             ProcessorNumber\r
+  IN UINTN  ProcessorNumber\r
   )\r
 {\r
-  CPU_FEATURES_DATA                    *CpuFeaturesData;\r
-  UINTN                                FeatureIndex;\r
-  CPU_REGISTER_TABLE                   *RegisterTable;\r
-  CPU_REGISTER_TABLE_ENTRY             *RegisterTableEntry;\r
-  CPU_REGISTER_TABLE_ENTRY             *RegisterTableEntryHead;\r
-  UINT32                               DebugPrintErrorLevel;\r
+  CPU_FEATURES_DATA         *CpuFeaturesData;\r
+  UINTN                     FeatureIndex;\r
+  CPU_REGISTER_TABLE        *RegisterTable;\r
+  CPU_REGISTER_TABLE_ENTRY  *RegisterTableEntry;\r
+  CPU_REGISTER_TABLE_ENTRY  *RegisterTableEntryHead;\r
+  UINT32                    DebugPrintErrorLevel;\r
 \r
   DebugPrintErrorLevel = (ProcessorNumber == 0) ? DEBUG_INFO : DEBUG_VERBOSE;\r
   CpuFeaturesData      = GetCpuFeaturesData ();\r
@@ -493,71 +506,71 @@ DumpRegisterTableOnProcessor (
   RegisterTable = &CpuFeaturesData->RegisterTable[ProcessorNumber];\r
   DEBUG ((DebugPrintErrorLevel, "RegisterTable->TableLength = %d\n", RegisterTable->TableLength));\r
 \r
-  RegisterTableEntryHead = (CPU_REGISTER_TABLE_ENTRY *) (UINTN) RegisterTable->RegisterTableEntry;\r
+  RegisterTableEntryHead = (CPU_REGISTER_TABLE_ENTRY *)(UINTN)RegisterTable->RegisterTableEntry;\r
 \r
   for (FeatureIndex = 0; FeatureIndex < RegisterTable->TableLength; FeatureIndex++) {\r
     RegisterTableEntry = &RegisterTableEntryHead[FeatureIndex];\r
     switch (RegisterTableEntry->RegisterType) {\r
-    case Msr:\r
-      DEBUG ((\r
-        DebugPrintErrorLevel,\r
-        "Processor: %04d: Index %04d, MSR  : %08x, Bit Start: %02d, Bit Length: %02d, Value: %016lx\r\n",\r
-        (UINT32) ProcessorNumber,\r
-        (UINT32) FeatureIndex,\r
-        RegisterTableEntry->Index,\r
-        RegisterTableEntry->ValidBitStart,\r
-        RegisterTableEntry->ValidBitLength,\r
-        RegisterTableEntry->Value\r
-        ));\r
-      break;\r
-    case ControlRegister:\r
-      DEBUG ((\r
-        DebugPrintErrorLevel,\r
-        "Processor: %04d: Index %04d, CR   : %08x, Bit Start: %02d, Bit Length: %02d, Value: %016lx\r\n",\r
-        (UINT32) ProcessorNumber,\r
-        (UINT32) FeatureIndex,\r
-        RegisterTableEntry->Index,\r
-        RegisterTableEntry->ValidBitStart,\r
-        RegisterTableEntry->ValidBitLength,\r
-        RegisterTableEntry->Value\r
-        ));\r
-      break;\r
-    case MemoryMapped:\r
-      DEBUG ((\r
-        DebugPrintErrorLevel,\r
-        "Processor: %04d: Index %04d, MMIO : %016lx, Bit Start: %02d, Bit Length: %02d, Value: %016lx\r\n",\r
-        (UINT32) ProcessorNumber,\r
-        (UINT32) FeatureIndex,\r
-        RegisterTableEntry->Index | LShiftU64 (RegisterTableEntry->HighIndex, 32),\r
-        RegisterTableEntry->ValidBitStart,\r
-        RegisterTableEntry->ValidBitLength,\r
-        RegisterTableEntry->Value\r
-        ));\r
-      break;\r
-    case CacheControl:\r
-      DEBUG ((\r
-        DebugPrintErrorLevel,\r
-        "Processor: %04d: Index %04d, CACHE: %08x, Bit Start: %02d, Bit Length: %02d, Value: %016lx\r\n",\r
-        (UINT32) ProcessorNumber,\r
-        (UINT32) FeatureIndex,\r
-        RegisterTableEntry->Index,\r
-        RegisterTableEntry->ValidBitStart,\r
-        RegisterTableEntry->ValidBitLength,\r
-        RegisterTableEntry->Value\r
-        ));\r
-      break;\r
-    case Semaphore:\r
-      DEBUG ((\r
-        DebugPrintErrorLevel,\r
-        "Processor: %04d: Index %04d, SEMAP: %s\r\n",\r
-        (UINT32) ProcessorNumber,\r
-        (UINT32) FeatureIndex,\r
-        mDependTypeStr[MIN ((UINT32)RegisterTableEntry->Value, InvalidDepType)]\r
-        ));\r
-      break;\r
+      case Msr:\r
+        DEBUG ((\r
+          DebugPrintErrorLevel,\r
+          "Processor: %04d: Index %04d, MSR  : %08x, Bit Start: %02d, Bit Length: %02d, Value: %016lx\r\n",\r
+          (UINT32)ProcessorNumber,\r
+          (UINT32)FeatureIndex,\r
+          RegisterTableEntry->Index,\r
+          RegisterTableEntry->ValidBitStart,\r
+          RegisterTableEntry->ValidBitLength,\r
+          RegisterTableEntry->Value\r
+          ));\r
+        break;\r
+      case ControlRegister:\r
+        DEBUG ((\r
+          DebugPrintErrorLevel,\r
+          "Processor: %04d: Index %04d, CR   : %08x, Bit Start: %02d, Bit Length: %02d, Value: %016lx\r\n",\r
+          (UINT32)ProcessorNumber,\r
+          (UINT32)FeatureIndex,\r
+          RegisterTableEntry->Index,\r
+          RegisterTableEntry->ValidBitStart,\r
+          RegisterTableEntry->ValidBitLength,\r
+          RegisterTableEntry->Value\r
+          ));\r
+        break;\r
+      case MemoryMapped:\r
+        DEBUG ((\r
+          DebugPrintErrorLevel,\r
+          "Processor: %04d: Index %04d, MMIO : %016lx, Bit Start: %02d, Bit Length: %02d, Value: %016lx\r\n",\r
+          (UINT32)ProcessorNumber,\r
+          (UINT32)FeatureIndex,\r
+          RegisterTableEntry->Index | LShiftU64 (RegisterTableEntry->HighIndex, 32),\r
+          RegisterTableEntry->ValidBitStart,\r
+          RegisterTableEntry->ValidBitLength,\r
+          RegisterTableEntry->Value\r
+          ));\r
+        break;\r
+      case CacheControl:\r
+        DEBUG ((\r
+          DebugPrintErrorLevel,\r
+          "Processor: %04d: Index %04d, CACHE: %08x, Bit Start: %02d, Bit Length: %02d, Value: %016lx\r\n",\r
+          (UINT32)ProcessorNumber,\r
+          (UINT32)FeatureIndex,\r
+          RegisterTableEntry->Index,\r
+          RegisterTableEntry->ValidBitStart,\r
+          RegisterTableEntry->ValidBitLength,\r
+          RegisterTableEntry->Value\r
+          ));\r
+        break;\r
+      case Semaphore:\r
+        DEBUG ((\r
+          DebugPrintErrorLevel,\r
+          "Processor: %04d: Index %04d, SEMAP: %s\r\n",\r
+          (UINT32)ProcessorNumber,\r
+          (UINT32)FeatureIndex,\r
+          mDependTypeStr[MIN ((UINT32)RegisterTableEntry->Value, InvalidDepType)]\r
+          ));\r
+        break;\r
 \r
-    default:\r
-      break;\r
+      default:\r
+        break;\r
     }\r
   }\r
 }\r
@@ -581,11 +594,11 @@ BiggestDep (
   IN CPU_FEATURE_DEPENDENCE_TYPE  NoneNeibAfterDep\r
   )\r
 {\r
-  CPU_FEATURE_DEPENDENCE_TYPE Bigger;\r
+  CPU_FEATURE_DEPENDENCE_TYPE  Bigger;\r
 \r
   Bigger = MAX (BeforeDep, AfterDep);\r
   Bigger = MAX (Bigger, NoneNeibBeforeDep);\r
-  return MAX(Bigger, NoneNeibAfterDep);\r
+  return MAX (Bigger, NoneNeibAfterDep);\r
 }\r
 \r
 /**\r
@@ -596,26 +609,26 @@ BiggestDep (
 **/\r
 VOID\r
 AnalysisProcessorFeatures (\r
-  IN UINTN                             NumberOfCpus\r
+  IN UINTN  NumberOfCpus\r
   )\r
 {\r
-  EFI_STATUS                           Status;\r
-  UINTN                                ProcessorNumber;\r
-  CPU_FEATURES_ENTRY                   *CpuFeature;\r
-  CPU_FEATURES_ENTRY                   *CpuFeatureInOrder;\r
-  CPU_FEATURES_INIT_ORDER              *CpuInitOrder;\r
-  REGISTER_CPU_FEATURE_INFORMATION     *CpuInfo;\r
-  LIST_ENTRY                           *Entry;\r
-  CPU_FEATURES_DATA                    *CpuFeaturesData;\r
-  LIST_ENTRY                           *NextEntry;\r
-  CPU_FEATURES_ENTRY                   *NextCpuFeatureInOrder;\r
-  BOOLEAN                              Success;\r
-  CPU_FEATURE_DEPENDENCE_TYPE          BeforeDep;\r
-  CPU_FEATURE_DEPENDENCE_TYPE          AfterDep;\r
-  CPU_FEATURE_DEPENDENCE_TYPE          NoneNeibBeforeDep;\r
-  CPU_FEATURE_DEPENDENCE_TYPE          NoneNeibAfterDep;\r
-\r
-  CpuFeaturesData = GetCpuFeaturesData ();\r
+  EFI_STATUS                        Status;\r
+  UINTN                             ProcessorNumber;\r
+  CPU_FEATURES_ENTRY                *CpuFeature;\r
+  CPU_FEATURES_ENTRY                *CpuFeatureInOrder;\r
+  CPU_FEATURES_INIT_ORDER           *CpuInitOrder;\r
+  REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo;\r
+  LIST_ENTRY                        *Entry;\r
+  CPU_FEATURES_DATA                 *CpuFeaturesData;\r
+  LIST_ENTRY                        *NextEntry;\r
+  CPU_FEATURES_ENTRY                *NextCpuFeatureInOrder;\r
+  BOOLEAN                           Success;\r
+  CPU_FEATURE_DEPENDENCE_TYPE       BeforeDep;\r
+  CPU_FEATURE_DEPENDENCE_TYPE       AfterDep;\r
+  CPU_FEATURE_DEPENDENCE_TYPE       NoneNeibBeforeDep;\r
+  CPU_FEATURE_DEPENDENCE_TYPE       NoneNeibAfterDep;\r
+\r
+  CpuFeaturesData                = GetCpuFeaturesData ();\r
   CpuFeaturesData->CapabilityPcd = AllocatePool (CpuFeaturesData->BitMaskSize);\r
   ASSERT (CpuFeaturesData->CapabilityPcd != NULL);\r
   SetMem (CpuFeaturesData->CapabilityPcd, CpuFeaturesData->BitMaskSize, 0xFF);\r
@@ -626,6 +639,7 @@ AnalysisProcessorFeatures (
     //\r
     SupportedMaskAnd (CpuFeaturesData->CapabilityPcd, CpuInitOrder->FeaturesSupportedMask, CpuFeaturesData->BitMaskSize);\r
   }\r
+\r
   //\r
   // Calculate the last setting\r
   //\r
@@ -637,28 +651,30 @@ AnalysisProcessorFeatures (
   // Dump the last CPU feature list\r
   //\r
   DEBUG_CODE_BEGIN ();\r
-    DEBUG ((DEBUG_INFO, "Last CPU features list...\n"));\r
-    Entry = GetFirstNode (&CpuFeaturesData->FeatureList);\r
-    while (!IsNull (&CpuFeaturesData->FeatureList, Entry)) {\r
-      CpuFeature = CPU_FEATURE_ENTRY_FROM_LINK (Entry);\r
-      if (IsBitMaskMatch (CpuFeature->FeatureMask, CpuFeaturesData->CapabilityPcd, CpuFeaturesData->BitMaskSize)) {\r
-        if (IsBitMaskMatch (CpuFeature->FeatureMask, CpuFeaturesData->SettingPcd, CpuFeaturesData->BitMaskSize)) {\r
-          DEBUG ((DEBUG_INFO, "[Enable   ] "));\r
-        } else {\r
-          DEBUG ((DEBUG_INFO, "[Disable  ] "));\r
-        }\r
+  DEBUG ((DEBUG_INFO, "Last CPU features list...\n"));\r
+  Entry = GetFirstNode (&CpuFeaturesData->FeatureList);\r
+  while (!IsNull (&CpuFeaturesData->FeatureList, Entry)) {\r
+    CpuFeature = CPU_FEATURE_ENTRY_FROM_LINK (Entry);\r
+    if (IsBitMaskMatch (CpuFeature->FeatureMask, CpuFeaturesData->CapabilityPcd, CpuFeaturesData->BitMaskSize)) {\r
+      if (IsBitMaskMatch (CpuFeature->FeatureMask, CpuFeaturesData->SettingPcd, CpuFeaturesData->BitMaskSize)) {\r
+        DEBUG ((DEBUG_INFO, "[Enable   ] "));\r
       } else {\r
-        DEBUG ((DEBUG_INFO, "[Unsupport] "));\r
+        DEBUG ((DEBUG_INFO, "[Disable  ] "));\r
       }\r
-      DumpCpuFeature (CpuFeature, CpuFeaturesData->BitMaskSize);\r
-      Entry = Entry->ForwardLink;\r
+    } else {\r
+      DEBUG ((DEBUG_INFO, "[Unsupport] "));\r
     }\r
-    DEBUG ((DEBUG_INFO, "PcdCpuFeaturesCapability:\n"));\r
-    DumpCpuFeatureMask (CpuFeaturesData->CapabilityPcd, CpuFeaturesData->BitMaskSize);\r
-    DEBUG ((DEBUG_INFO, "Origin PcdCpuFeaturesSetting:\n"));\r
-    DumpCpuFeatureMask (PcdGetPtr (PcdCpuFeaturesSetting), CpuFeaturesData->BitMaskSize);\r
-    DEBUG ((DEBUG_INFO, "Final PcdCpuFeaturesSetting:\n"));\r
-    DumpCpuFeatureMask (CpuFeaturesData->SettingPcd, CpuFeaturesData->BitMaskSize);\r
+\r
+    DumpCpuFeature (CpuFeature, CpuFeaturesData->BitMaskSize);\r
+    Entry = Entry->ForwardLink;\r
+  }\r
+\r
+  DEBUG ((DEBUG_INFO, "PcdCpuFeaturesCapability:\n"));\r
+  DumpCpuFeatureMask (CpuFeaturesData->CapabilityPcd, CpuFeaturesData->BitMaskSize);\r
+  DEBUG ((DEBUG_INFO, "Origin PcdCpuFeaturesSetting:\n"));\r
+  DumpCpuFeatureMask (PcdGetPtr (PcdCpuFeaturesSetting), CpuFeaturesData->BitMaskSize);\r
+  DEBUG ((DEBUG_INFO, "Final PcdCpuFeaturesSetting:\n"));\r
+  DumpCpuFeatureMask (CpuFeaturesData->SettingPcd, CpuFeaturesData->BitMaskSize);\r
   DEBUG_CODE_END ();\r
 \r
   //\r
@@ -669,7 +685,7 @@ AnalysisProcessorFeatures (
 \r
   for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {\r
     CpuInitOrder = &CpuFeaturesData->InitOrder[ProcessorNumber];\r
-    Entry = GetFirstNode (&CpuFeaturesData->FeatureList);\r
+    Entry        = GetFirstNode (&CpuFeaturesData->FeatureList);\r
     while (!IsNull (&CpuFeaturesData->FeatureList, Entry)) {\r
       //\r
       // Insert each feature into processor's order list\r
@@ -680,13 +696,15 @@ AnalysisProcessorFeatures (
         ASSERT (CpuFeatureInOrder != NULL);\r
         InsertTailList (&CpuInitOrder->OrderList, &CpuFeatureInOrder->Link);\r
       }\r
+\r
       Entry = Entry->ForwardLink;\r
     }\r
+\r
     //\r
     // Go through ordered feature list to initialize CPU features\r
     //\r
     CpuInfo = &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo;\r
-    Entry = GetFirstNode (&CpuInitOrder->OrderList);\r
+    Entry   = GetFirstNode (&CpuInitOrder->OrderList);\r
     while (!IsNull (&CpuInitOrder->OrderList, Entry)) {\r
       CpuFeatureInOrder = CPU_FEATURE_ENTRY_FROM_LINK (Entry);\r
 \r
@@ -736,23 +754,24 @@ AnalysisProcessorFeatures (
           // Check whether next feature has After type dependence with not neighborhood CPU\r
           // Features in former CPU features.\r
           //\r
-          NoneNeibAfterDep = DetectNoneNeighborhoodFeatureScope(NextCpuFeatureInOrder, FALSE, &CpuInitOrder->OrderList);\r
+          NoneNeibAfterDep = DetectNoneNeighborhoodFeatureScope (NextCpuFeatureInOrder, FALSE, &CpuInitOrder->OrderList);\r
         } else {\r
           BeforeDep        = NoneDepType;\r
           AfterDep         = NoneDepType;\r
           NoneNeibAfterDep = NoneDepType;\r
         }\r
+\r
         //\r
         // Check whether current feature has Before type dependence with none neighborhood\r
         // CPU features in after Cpu features.\r
         //\r
-        NoneNeibBeforeDep = DetectNoneNeighborhoodFeatureScope(CpuFeatureInOrder, TRUE, &CpuInitOrder->OrderList);\r
+        NoneNeibBeforeDep = DetectNoneNeighborhoodFeatureScope (CpuFeatureInOrder, TRUE, &CpuInitOrder->OrderList);\r
 \r
         //\r
         // Get the biggest dependence and add semaphore for it.\r
         // PackageDepType > CoreDepType > ThreadDepType > NoneDepType.\r
         //\r
-        BeforeDep = BiggestDep(BeforeDep, AfterDep, NoneNeibBeforeDep, NoneNeibAfterDep);\r
+        BeforeDep = BiggestDep (BeforeDep, AfterDep, NoneNeibBeforeDep, NoneNeibAfterDep);\r
         if (BeforeDep > ThreadDepType) {\r
           CPU_REGISTER_TABLE_WRITE32 (ProcessorNumber, Semaphore, 0, BeforeDep);\r
         }\r
@@ -783,7 +802,7 @@ AnalysisProcessorFeatures (
 **/\r
 VOID\r
 LibReleaseSemaphore (\r
-  IN OUT  volatile UINT32           *Sem\r
+  IN OUT  volatile UINT32  *Sem\r
   )\r
 {\r
   InterlockedIncrement (Sem);\r
@@ -801,7 +820,7 @@ LibReleaseSemaphore (
 **/\r
 VOID\r
 LibWaitForSemaphore (\r
-  IN OUT  volatile UINT32           *Sem\r
+  IN OUT  volatile UINT32  *Sem\r
   )\r
 {\r
   UINT32  Value;\r
@@ -827,42 +846,46 @@ LibWaitForSemaphore (
 **/\r
 UINTN\r
 ReadWriteCr (\r
-  IN     UINT32       CrIndex,\r
-  IN     BOOLEAN      Read,\r
-  IN OUT UINTN        *CrValue\r
+  IN     UINT32   CrIndex,\r
+  IN     BOOLEAN  Read,\r
+  IN OUT UINTN    *CrValue\r
   )\r
 {\r
   switch (CrIndex) {\r
-  case 0:\r
-    if (Read) {\r
-      *CrValue = AsmReadCr0 ();\r
-    } else {\r
-      AsmWriteCr0 (*CrValue);\r
-    }\r
-    break;\r
-  case 2:\r
-    if (Read) {\r
-      *CrValue = AsmReadCr2 ();\r
-    } else {\r
-      AsmWriteCr2 (*CrValue);\r
-    }\r
-    break;\r
-  case 3:\r
-    if (Read) {\r
-      *CrValue = AsmReadCr3 ();\r
-    } else {\r
-      AsmWriteCr3 (*CrValue);\r
-    }\r
-    break;\r
-  case 4:\r
-    if (Read) {\r
-      *CrValue = AsmReadCr4 ();\r
-    } else {\r
-      AsmWriteCr4 (*CrValue);\r
-    }\r
-    break;\r
-  default:\r
-    return EFI_UNSUPPORTED;;\r
+    case 0:\r
+      if (Read) {\r
+        *CrValue = AsmReadCr0 ();\r
+      } else {\r
+        AsmWriteCr0 (*CrValue);\r
+      }\r
+\r
+      break;\r
+    case 2:\r
+      if (Read) {\r
+        *CrValue = AsmReadCr2 ();\r
+      } else {\r
+        AsmWriteCr2 (*CrValue);\r
+      }\r
+\r
+      break;\r
+    case 3:\r
+      if (Read) {\r
+        *CrValue = AsmReadCr3 ();\r
+      } else {\r
+        AsmWriteCr3 (*CrValue);\r
+      }\r
+\r
+      break;\r
+    case 4:\r
+      if (Read) {\r
+        *CrValue = AsmReadCr4 ();\r
+      } else {\r
+        AsmWriteCr4 (*CrValue);\r
+      }\r
+\r
+      break;\r
+    default:\r
+      return EFI_UNSUPPORTED;\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -880,10 +903,10 @@ ReadWriteCr (
 **/\r
 VOID\r
 ProgramProcessorRegister (\r
-  IN CPU_REGISTER_TABLE           *RegisterTable,\r
-  IN EFI_CPU_PHYSICAL_LOCATION    *ApLocation,\r
-  IN CPU_STATUS_INFORMATION       *CpuStatus,\r
-  IN PROGRAM_CPU_REGISTER_FLAGS   *CpuFlags\r
+  IN CPU_REGISTER_TABLE          *RegisterTable,\r
+  IN EFI_CPU_PHYSICAL_LOCATION   *ApLocation,\r
+  IN CPU_STATUS_INFORMATION      *CpuStatus,\r
+  IN PROGRAM_CPU_REGISTER_FLAGS  *CpuFlags\r
   )\r
 {\r
   CPU_REGISTER_TABLE_ENTRY  *RegisterTableEntry;\r
@@ -903,54 +926,25 @@ ProgramProcessorRegister (
   //\r
   // Traverse Register Table of this logical processor\r
   //\r
-  RegisterTableEntryHead = (CPU_REGISTER_TABLE_ENTRY *) (UINTN) RegisterTable->RegisterTableEntry;\r
+  RegisterTableEntryHead = (CPU_REGISTER_TABLE_ENTRY *)(UINTN)RegisterTable->RegisterTableEntry;\r
 \r
   for (Index = 0; Index < RegisterTable->TableLength; Index++) {\r
-\r
     RegisterTableEntry = &RegisterTableEntryHead[Index];\r
 \r
     //\r
     // Check the type of specified register\r
     //\r
     switch (RegisterTableEntry->RegisterType) {\r
-    //\r
-    // The specified register is Control Register\r
-    //\r
-    case ControlRegister:\r
-      Status = ReadWriteCr (RegisterTableEntry->Index, TRUE, &Value);\r
-      if (EFI_ERROR (Status)) {\r
-        break;\r
-      }\r
-      if (RegisterTableEntry->TestThenWrite) {\r
-        CurrentValue = BitFieldRead64 (\r
-                         Value,\r
-                         RegisterTableEntry->ValidBitStart,\r
-                         RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1\r
-                         );\r
-        if (CurrentValue == RegisterTableEntry->Value) {\r
+      //\r
+      // The specified register is Control Register\r
+      //\r
+      case ControlRegister:\r
+        Status = ReadWriteCr (RegisterTableEntry->Index, TRUE, &Value);\r
+        if (EFI_ERROR (Status)) {\r
           break;\r
         }\r
-      }\r
-      Value = (UINTN) BitFieldWrite64 (\r
-                        Value,\r
-                        RegisterTableEntry->ValidBitStart,\r
-                        RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1,\r
-                        RegisterTableEntry->Value\r
-                        );\r
-      ReadWriteCr (RegisterTableEntry->Index, FALSE, &Value);\r
-      break;\r
 \r
-    //\r
-    // The specified register is Model Specific Register\r
-    //\r
-    case Msr:\r
-      if (RegisterTableEntry->TestThenWrite) {\r
-        Value = (UINTN)AsmReadMsr64 (RegisterTableEntry->Index);\r
-        if (RegisterTableEntry->ValidBitLength >= 64) {\r
-          if (Value == RegisterTableEntry->Value) {\r
-            break;\r
-          }\r
-        } else {\r
+        if (RegisterTableEntry->TestThenWrite) {\r
           CurrentValue = BitFieldRead64 (\r
                            Value,\r
                            RegisterTableEntry->ValidBitStart,\r
@@ -960,153 +954,190 @@ ProgramProcessorRegister (
             break;\r
           }\r
         }\r
-      }\r
 \r
-      if (RegisterTableEntry->ValidBitLength >= 64) {\r
-        //\r
-        // If length is not less than 64 bits, then directly write without reading\r
-        //\r
-        AsmWriteMsr64 (\r
-          RegisterTableEntry->Index,\r
-          RegisterTableEntry->Value\r
-          );\r
-      } else {\r
-        //\r
-        // Set the bit section according to bit start and length\r
-        //\r
-        AsmMsrBitFieldWrite64 (\r
-          RegisterTableEntry->Index,\r
-          RegisterTableEntry->ValidBitStart,\r
-          RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1,\r
-          RegisterTableEntry->Value\r
-          );\r
-      }\r
-      break;\r
-    //\r
-    // MemoryMapped operations\r
-    //\r
-    case MemoryMapped:\r
-      AcquireSpinLock (&CpuFlags->MemoryMappedLock);\r
-      MmioBitFieldWrite32 (\r
-        (UINTN)(RegisterTableEntry->Index | LShiftU64 (RegisterTableEntry->HighIndex, 32)),\r
-        RegisterTableEntry->ValidBitStart,\r
-        RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1,\r
-        (UINT32)RegisterTableEntry->Value\r
-        );\r
-      ReleaseSpinLock (&CpuFlags->MemoryMappedLock);\r
-      break;\r
-    //\r
-    // Enable or disable cache\r
-    //\r
-    case CacheControl:\r
-      //\r
-      // If value of the entry is 0, then disable cache.  Otherwise, enable cache.\r
-      //\r
-      if (RegisterTableEntry->Value == 0) {\r
-        AsmDisableCache ();\r
-      } else {\r
-        AsmEnableCache ();\r
-      }\r
-      break;\r
+        Value = (UINTN)BitFieldWrite64 (\r
+                         Value,\r
+                         RegisterTableEntry->ValidBitStart,\r
+                         RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1,\r
+                         RegisterTableEntry->Value\r
+                         );\r
+        ReadWriteCr (RegisterTableEntry->Index, FALSE, &Value);\r
+        break;\r
 \r
-    case Semaphore:\r
-      // Semaphore works logic like below:\r
       //\r
-      //  V(x) = LibReleaseSemaphore (Semaphore[FirstThread + x]);\r
-      //  P(x) = LibWaitForSemaphore (Semaphore[FirstThread + x]);\r
+      // The specified register is Model Specific Register\r
       //\r
-      //  All threads (T0...Tn) waits in P() line and continues running\r
-      //  together.\r
+      case Msr:\r
+        if (RegisterTableEntry->TestThenWrite) {\r
+          Value = (UINTN)AsmReadMsr64 (RegisterTableEntry->Index);\r
+          if (RegisterTableEntry->ValidBitLength >= 64) {\r
+            if (Value == RegisterTableEntry->Value) {\r
+              break;\r
+            }\r
+          } else {\r
+            CurrentValue = BitFieldRead64 (\r
+                             Value,\r
+                             RegisterTableEntry->ValidBitStart,\r
+                             RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1\r
+                             );\r
+            if (CurrentValue == RegisterTableEntry->Value) {\r
+              break;\r
+            }\r
+          }\r
+        }\r
+\r
+        if (RegisterTableEntry->ValidBitLength >= 64) {\r
+          //\r
+          // If length is not less than 64 bits, then directly write without reading\r
+          //\r
+          AsmWriteMsr64 (\r
+            RegisterTableEntry->Index,\r
+            RegisterTableEntry->Value\r
+            );\r
+        } else {\r
+          //\r
+          // Set the bit section according to bit start and length\r
+          //\r
+          AsmMsrBitFieldWrite64 (\r
+            RegisterTableEntry->Index,\r
+            RegisterTableEntry->ValidBitStart,\r
+            RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1,\r
+            RegisterTableEntry->Value\r
+            );\r
+        }\r
+\r
+        break;\r
       //\r
+      // MemoryMapped operations\r
       //\r
-      //  T0             T1            ...           Tn\r
+      case MemoryMapped:\r
+        AcquireSpinLock (&CpuFlags->MemoryMappedLock);\r
+        MmioBitFieldWrite32 (\r
+          (UINTN)(RegisterTableEntry->Index | LShiftU64 (RegisterTableEntry->HighIndex, 32)),\r
+          RegisterTableEntry->ValidBitStart,\r
+          RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLength - 1,\r
+          (UINT32)RegisterTableEntry->Value\r
+          );\r
+        ReleaseSpinLock (&CpuFlags->MemoryMappedLock);\r
+        break;\r
       //\r
-      //  V(0...n)       V(0...n)      ...           V(0...n)\r
-      //  n * P(0)       n * P(1)      ...           n * P(n)\r
+      // Enable or disable cache\r
       //\r
-      switch (RegisterTableEntry->Value) {\r
-      case CoreDepType:\r
-        SemaphorePtr = CpuFlags->CoreSemaphoreCount;\r
-        ThreadCountPerCore = (UINT8 *)(UINTN)CpuStatus->ThreadCountPerCore;\r
-\r
-        CurrentCore = ApLocation->Package * CpuStatus->MaxCoreCount + ApLocation->Core;\r
+      case CacheControl:\r
         //\r
-        // Get Offset info for the first thread in the core which current thread belongs to.\r
+        // If value of the entry is 0, then disable cache.  Otherwise, enable cache.\r
         //\r
-        FirstThread   = CurrentCore * CpuStatus->MaxThreadCount;\r
-        CurrentThread = FirstThread + ApLocation->Thread;\r
-\r
-        //\r
-        // Different cores may have different valid threads in them. If driver maintail clearly\r
-        // thread index in different cores, the logic will be much complicated.\r
-        // Here driver just simply records the max thread number in all cores and use it as expect\r
-        // thread number for all cores.\r
-        // In below two steps logic, first current thread will Release semaphore for each thread\r
-        // in current core. Maybe some threads are not valid in this core, but driver don't\r
-        // care. Second, driver will let current thread wait semaphore for all valid threads in\r
-        // current core. Because only the valid threads will do release semaphore for this\r
-        // thread, driver here only need to wait the valid thread count.\r
-        //\r
-\r
-        //\r
-        // First Notify ALL THREADs in current Core that this thread is ready.\r
-        //\r
-        for (ProcessorIndex = 0; ProcessorIndex < CpuStatus->MaxThreadCount; ProcessorIndex ++) {\r
-          LibReleaseSemaphore (&SemaphorePtr[FirstThread + ProcessorIndex]);\r
-        }\r
-        //\r
-        // Second, check whether all VALID THREADs (not all threads) in current core are ready.\r
-        //\r
-        for (ProcessorIndex = 0; ProcessorIndex < ThreadCountPerCore[CurrentCore]; ProcessorIndex ++) {\r
-          LibWaitForSemaphore (&SemaphorePtr[CurrentThread]);\r
+        if (RegisterTableEntry->Value == 0) {\r
+          AsmDisableCache ();\r
+        } else {\r
+          AsmEnableCache ();\r
         }\r
+\r
         break;\r
 \r
-      case PackageDepType:\r
-        SemaphorePtr = CpuFlags->PackageSemaphoreCount;\r
-        ThreadCountPerPackage = (UINT32 *)(UINTN)CpuStatus->ThreadCountPerPackage;\r
+      case Semaphore:\r
+        // Semaphore works logic like below:\r
         //\r
-        // Get Offset info for the first thread in the package which current thread belongs to.\r
+        //  V(x) = LibReleaseSemaphore (Semaphore[FirstThread + x]);\r
+        //  P(x) = LibWaitForSemaphore (Semaphore[FirstThread + x]);\r
         //\r
-        FirstThread = ApLocation->Package * CpuStatus->MaxCoreCount * CpuStatus->MaxThreadCount;\r
+        //  All threads (T0...Tn) waits in P() line and continues running\r
+        //  together.\r
         //\r
-        // Get the possible threads count for current package.\r
         //\r
-        CurrentThread = FirstThread + CpuStatus->MaxThreadCount * ApLocation->Core + ApLocation->Thread;\r
-\r
+        //  T0             T1            ...           Tn\r
         //\r
-        // Different packages may have different valid threads in them. If driver maintail clearly\r
-        // thread index in different packages, the logic will be much complicated.\r
-        // Here driver just simply records the max thread number in all packages and use it as expect\r
-        // thread number for all packages.\r
-        // In below two steps logic, first current thread will Release semaphore for each thread\r
-        // in current package. Maybe some threads are not valid in this package, but driver don't\r
-        // care. Second, driver will let current thread wait semaphore for all valid threads in\r
-        // current package. Because only the valid threads will do release semaphore for this\r
-        // thread, driver here only need to wait the valid thread count.\r
+        //  V(0...n)       V(0...n)      ...           V(0...n)\r
+        //  n * P(0)       n * P(1)      ...           n * P(n)\r
         //\r
+        switch (RegisterTableEntry->Value) {\r
+          case CoreDepType:\r
+            SemaphorePtr       = CpuFlags->CoreSemaphoreCount;\r
+            ThreadCountPerCore = (UINT8 *)(UINTN)CpuStatus->ThreadCountPerCore;\r
+\r
+            CurrentCore = ApLocation->Package * CpuStatus->MaxCoreCount + ApLocation->Core;\r
+            //\r
+            // Get Offset info for the first thread in the core which current thread belongs to.\r
+            //\r
+            FirstThread   = CurrentCore * CpuStatus->MaxThreadCount;\r
+            CurrentThread = FirstThread + ApLocation->Thread;\r
+\r
+            //\r
+            // Different cores may have different valid threads in them. If driver maintail clearly\r
+            // thread index in different cores, the logic will be much complicated.\r
+            // Here driver just simply records the max thread number in all cores and use it as expect\r
+            // thread number for all cores.\r
+            // In below two steps logic, first current thread will Release semaphore for each thread\r
+            // in current core. Maybe some threads are not valid in this core, but driver don't\r
+            // care. Second, driver will let current thread wait semaphore for all valid threads in\r
+            // current core. Because only the valid threads will do release semaphore for this\r
+            // thread, driver here only need to wait the valid thread count.\r
+            //\r
+\r
+            //\r
+            // First Notify ALL THREADs in current Core that this thread is ready.\r
+            //\r
+            for (ProcessorIndex = 0; ProcessorIndex < CpuStatus->MaxThreadCount; ProcessorIndex++) {\r
+              LibReleaseSemaphore (&SemaphorePtr[FirstThread + ProcessorIndex]);\r
+            }\r
+\r
+            //\r
+            // Second, check whether all VALID THREADs (not all threads) in current core are ready.\r
+            //\r
+            for (ProcessorIndex = 0; ProcessorIndex < ThreadCountPerCore[CurrentCore]; ProcessorIndex++) {\r
+              LibWaitForSemaphore (&SemaphorePtr[CurrentThread]);\r
+            }\r
 \r
-        //\r
-        // First Notify ALL THREADS in current package that this thread is ready.\r
-        //\r
-        for (ProcessorIndex = 0; ProcessorIndex < CpuStatus->MaxThreadCount * CpuStatus->MaxCoreCount; ProcessorIndex ++) {\r
-          LibReleaseSemaphore (&SemaphorePtr[FirstThread + ProcessorIndex]);\r
-        }\r
-        //\r
-        // Second, check whether VALID THREADS (not all threads) in current package are ready.\r
-        //\r
-        for (ProcessorIndex = 0; ProcessorIndex < ThreadCountPerPackage[ApLocation->Package]; ProcessorIndex ++) {\r
-          LibWaitForSemaphore (&SemaphorePtr[CurrentThread]);\r
+            break;\r
+\r
+          case PackageDepType:\r
+            SemaphorePtr          = CpuFlags->PackageSemaphoreCount;\r
+            ThreadCountPerPackage = (UINT32 *)(UINTN)CpuStatus->ThreadCountPerPackage;\r
+            //\r
+            // Get Offset info for the first thread in the package which current thread belongs to.\r
+            //\r
+            FirstThread = ApLocation->Package * CpuStatus->MaxCoreCount * CpuStatus->MaxThreadCount;\r
+            //\r
+            // Get the possible threads count for current package.\r
+            //\r
+            CurrentThread = FirstThread + CpuStatus->MaxThreadCount * ApLocation->Core + ApLocation->Thread;\r
+\r
+            //\r
+            // Different packages may have different valid threads in them. If driver maintail clearly\r
+            // thread index in different packages, the logic will be much complicated.\r
+            // Here driver just simply records the max thread number in all packages and use it as expect\r
+            // thread number for all packages.\r
+            // In below two steps logic, first current thread will Release semaphore for each thread\r
+            // in current package. Maybe some threads are not valid in this package, but driver don't\r
+            // care. Second, driver will let current thread wait semaphore for all valid threads in\r
+            // current package. Because only the valid threads will do release semaphore for this\r
+            // thread, driver here only need to wait the valid thread count.\r
+            //\r
+\r
+            //\r
+            // First Notify ALL THREADS in current package that this thread is ready.\r
+            //\r
+            for (ProcessorIndex = 0; ProcessorIndex < CpuStatus->MaxThreadCount * CpuStatus->MaxCoreCount; ProcessorIndex++) {\r
+              LibReleaseSemaphore (&SemaphorePtr[FirstThread + ProcessorIndex]);\r
+            }\r
+\r
+            //\r
+            // Second, check whether VALID THREADS (not all threads) in current package are ready.\r
+            //\r
+            for (ProcessorIndex = 0; ProcessorIndex < ThreadCountPerPackage[ApLocation->Package]; ProcessorIndex++) {\r
+              LibWaitForSemaphore (&SemaphorePtr[CurrentThread]);\r
+            }\r
+\r
+            break;\r
+\r
+          default:\r
+            break;\r
         }\r
+\r
         break;\r
 \r
       default:\r
         break;\r
-      }\r
-      break;\r
-\r
-    default:\r
-      break;\r
     }\r
   }\r
 }\r
@@ -1120,32 +1151,33 @@ ProgramProcessorRegister (
 VOID\r
 EFIAPI\r
 SetProcessorRegister (\r
-  IN OUT VOID            *Buffer\r
+  IN OUT VOID  *Buffer\r
   )\r
 {\r
-  CPU_FEATURES_DATA         *CpuFeaturesData;\r
-  CPU_REGISTER_TABLE        *RegisterTable;\r
-  CPU_REGISTER_TABLE        *RegisterTables;\r
-  UINT32                    InitApicId;\r
-  UINTN                     ProcIndex;\r
-  UINTN                     Index;\r
-  ACPI_CPU_DATA             *AcpiCpuData;\r
+  CPU_FEATURES_DATA   *CpuFeaturesData;\r
+  CPU_REGISTER_TABLE  *RegisterTable;\r
+  CPU_REGISTER_TABLE  *RegisterTables;\r
+  UINT32              InitApicId;\r
+  UINTN               ProcIndex;\r
+  UINTN               Index;\r
+  ACPI_CPU_DATA       *AcpiCpuData;\r
 \r
-  CpuFeaturesData = (CPU_FEATURES_DATA *) Buffer;\r
-  AcpiCpuData = CpuFeaturesData->AcpiCpuData;\r
+  CpuFeaturesData = (CPU_FEATURES_DATA *)Buffer;\r
+  AcpiCpuData     = CpuFeaturesData->AcpiCpuData;\r
 \r
   RegisterTables = (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->CpuFeatureInitData.RegisterTable;\r
 \r
-  InitApicId = GetInitialApicId ();\r
+  InitApicId    = GetInitialApicId ();\r
   RegisterTable = NULL;\r
-  ProcIndex = (UINTN)-1;\r
+  ProcIndex     = (UINTN)-1;\r
   for (Index = 0; Index < AcpiCpuData->NumberOfCpus; Index++) {\r
     if (RegisterTables[Index].InitialApicId == InitApicId) {\r
       RegisterTable =  &RegisterTables[Index];\r
-      ProcIndex = Index;\r
+      ProcIndex     = Index;\r
       break;\r
     }\r
   }\r
+\r
   ASSERT (RegisterTable != NULL);\r
 \r
   ProgramProcessorRegister (\r
@@ -1170,9 +1202,9 @@ CpuFeaturesDetect (
   VOID\r
   )\r
 {\r
-  CPU_FEATURES_DATA      *CpuFeaturesData;\r
+  CPU_FEATURES_DATA  *CpuFeaturesData;\r
 \r
-  CpuFeaturesData = GetCpuFeaturesData();\r
+  CpuFeaturesData = GetCpuFeaturesData ();\r
 \r
   CpuInitDataInitialize ();\r
 \r