]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuDxe/CpuDxe.c
1. Introduce the API MtrrGetDefaultMemoryType () in Mtrr Library.
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuDxe.c
index ad4599dab93c8674ecaa9303c54846fcd8cd0ee0..c1eee028aa4bb27e4d15d6ea85980ec50de4f415 100644 (file)
@@ -23,7 +23,6 @@ EFI_CPU_INTERRUPT_HANDLER ExternalVectorTable[0x100];
 BOOLEAN                   InterruptState = FALSE;\r
 EFI_HANDLE                mCpuHandle = NULL;\r
 BOOLEAN                   mIsFlushingGCD;\r
-UINT8                     mDefaultMemoryType    = MTRR_CACHE_WRITE_BACK;\r
 UINT64                    mValidMtrrAddressMask = MTRR_LIB_CACHE_VALID_ADDRESS;\r
 UINT64                    mValidMtrrBitsMask    = MTRR_LIB_MSR_VALID_MASK;\r
 \r
@@ -715,7 +714,7 @@ InitializeMtrrMask (
 **/\r
 UINT64\r
 GetMemorySpaceAttributeFromMtrrType (\r
-  IN UINT8                MtrrAttributes\r
+  IN MTRR_MEMORY_CACHE_TYPE  MtrrAttributes\r
   )\r
 {\r
   switch (MtrrAttributes) {\r
@@ -880,13 +879,14 @@ RefreshGcdMemoryAttributes (
   UINT64                              Length;\r
   UINT64                              Attributes;\r
   UINT64                              CurrentAttributes;\r
-  UINT8                               MtrrType;\r
+  MTRR_MEMORY_CACHE_TYPE              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
+  MTRR_MEMORY_CACHE_TYPE              DefaultMemoryType;\r
 \r
   if (!IsMtrrSupported ()) {\r
     return;\r
@@ -895,8 +895,7 @@ RefreshGcdMemoryAttributes (
   FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();\r
   ASSERT (FirmwareVariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);\r
 \r
-//  mIsFlushingGCD = TRUE;\r
-  mIsFlushingGCD = FALSE;\r
+  mIsFlushingGCD = TRUE;\r
   MemorySpaceMap = NULL;\r
 \r
   //\r
@@ -922,7 +921,8 @@ RefreshGcdMemoryAttributes (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  DefaultAttributes = GetMemorySpaceAttributeFromMtrrType (mDefaultMemoryType);\r
+  DefaultMemoryType = MtrrGetDefaultMemoryType ();\r
+  DefaultAttributes = GetMemorySpaceAttributeFromMtrrType (DefaultMemoryType);\r
 \r
   //\r
   // Set default attributes to all spaces.\r
@@ -954,13 +954,15 @@ RefreshGcdMemoryAttributes (
         );\r
     }\r
   }\r
+\r
   //\r
-  // Go for variable MTRRs with Non-WB attribute\r
+  // Go for variable MTRRs with the attribute except for WB and UC attributes\r
   //\r
   for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
-    if (VariableMtrr[Index].Valid &&\r
-        VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK) {\r
-      Attributes = GetMemorySpaceAttributeFromMtrrType ((UINT8) VariableMtrr[Index].Type);\r
+    if (VariableMtrr[Index].Valid &&                          \r
+        VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK &&\r
+        VariableMtrr[Index].Type != MTRR_CACHE_UNCACHEABLE) {\r
+      Attributes = GetMemorySpaceAttributeFromMtrrType ((MTRR_MEMORY_CACHE_TYPE) VariableMtrr[Index].Type);\r
       SetGcdMemorySpaceAttributes (\r
         MemorySpaceMap,\r
         NumberOfDescriptors,\r
@@ -971,6 +973,22 @@ RefreshGcdMemoryAttributes (
     }\r
   }\r
 \r
+  //\r
+  // Go for variable MTRRs with UC attribute\r
+  //\r
+  for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
+    if (VariableMtrr[Index].Valid &&\r
+        VariableMtrr[Index].Type == MTRR_CACHE_UNCACHEABLE) {\r
+      SetGcdMemorySpaceAttributes (\r
+        MemorySpaceMap,\r
+        NumberOfDescriptors,\r
+        VariableMtrr[Index].BaseAddress,\r
+        VariableMtrr[Index].Length,\r
+        EFI_MEMORY_UC\r
+        );\r
+    }\r
+  }\r
+\r
   //\r
   // Go for fixed MTRRs\r
   //\r
@@ -984,7 +1002,7 @@ RefreshGcdMemoryAttributes (
     // Check for continuous fixed MTRR sections\r
     //\r
     for (SubIndex = 0; SubIndex < 8; SubIndex++) {\r
-      MtrrType = (UINT8) RShiftU64 (RegValue, SubIndex * 8);\r
+      MtrrType = (MTRR_MEMORY_CACHE_TYPE) RShiftU64 (RegValue, SubIndex * 8);\r
       CurrentAttributes = GetMemorySpaceAttributeFromMtrrType (MtrrType);\r
       if (Length == 0) {\r
         //\r