]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFspPkg/Library/BaseCacheLib/CacheLib.c
DynamicTablesPkg: GTDT updates for ACPI 6.3
[mirror_edk2.git] / IntelFspPkg / Library / BaseCacheLib / CacheLib.c
index aaaeb8b97b4f5439b0f35b575c3b10658e835e21..927cee13d31628fe84d55cdeedc93cb00da0ab4e 100644 (file)
@@ -1,13 +1,7 @@
 /** @file\r
 \r
-  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include <Library/CacheAsRamLib.h>\r
 #include "CacheLibInternal.h"\r
 \r
-/**\r
-  Calculate the maximum value which is a power of 2, but less the Input.\r
-\r
-  @param[in]  Input        The number to pass in.\r
-  @return The maximum value which is align to power of 2 and less the Input\r
-**/\r
-UINT32\r
-SetPower2 (\r
-  IN  UINT32                    Input\r
-  );\r
-\r
 /**\r
   Search the memory cache type for specific memory from MTRR.\r
 \r
@@ -56,7 +39,7 @@ SearchForExactMtrr (
   @param[in] MemoryCacheType  input cache type to be checked.\r
 \r
   @retval TRUE MemoryCacheType is default MTRR setting.\r
-  @retval TRUE MemoryCacheType is NOT default MTRR setting.\r
+  @retval FALSE MemoryCacheType is NOT default MTRR setting.\r
 **/\r
 BOOLEAN\r
 IsDefaultType (\r
@@ -159,7 +142,7 @@ EfiRecoverCacheMtrr (
   //\r
   if (EnableMtrr) {\r
     TempQword = AsmReadMsr64(EFI_MSR_CACHE_IA32_MTRR_DEF_TYPE);\r
-    TempQword |= (B_EFI_MSR_GLOBAL_MTRR_ENABLE | B_EFI_MSR_FIXED_MTRR_ENABLE);\r
+    TempQword |= (UINT64)(B_EFI_MSR_GLOBAL_MTRR_ENABLE | B_EFI_MSR_FIXED_MTRR_ENABLE);\r
   } else {\r
     TempQword = OldMtrr;\r
   }\r
@@ -236,11 +219,7 @@ Power2MaxMemory (
   //\r
   // Compute inital power of 2 size to return\r
   //\r
-  if (RShiftU64(MemoryLength, 32)) {\r
-    Result = LShiftU64((UINT64)SetPower2((UINT32) RShiftU64(MemoryLength, 32)), 32);\r
-  } else {\r
-    Result = (UINT64)SetPower2((UINT32)MemoryLength);\r
-  }\r
+  Result = GetPowerOfTwo64(MemoryLength);\r
 \r
   //\r
   // Special case base of 0 as all ranges are valid\r
@@ -295,37 +274,6 @@ CheckMtrrAlignment (
   return ShiftedBase % ShiftedSize;\r
 }\r
 \r
-/**\r
-  Calculate the maximum value which is a power of 2, but less the Input.\r
-\r
-  @param[in]  Input        The number to pass in.\r
-\r
-  @return The maximum value which is align to power of 2 and less the Input.\r
-**/\r
-UINT32\r
-SetPower2 (\r
-  IN UINT32 Input\r
-  )\r
-{\r
-  UINT32 Result;\r
-\r
-  Result = 0;\r
-#if defined(__GCC__)\r
-  asm("bsr %1, \\r
-      %%eax; \\r
-     bts %%eax, \\r
-      %0;" :"=r"(Result) :\r
-    "r"(Input)\r
-  );\r
-#elif defined(_MSC_VER)\r
-  _asm {\r
-    bsr eax, Input\r
-    bts Result, eax\r
-  }\r
-#endif\r
-  return Result;\r
-}\r
-\r
 /**\r
   Programs fixed MTRRs registers.\r
 \r
@@ -381,7 +329,7 @@ ProgramFixedMtrr (
     *Len -= mFixedMtrrTable[MsrNum].Length;\r
     *Base += mFixedMtrrTable[MsrNum].Length;\r
   }\r
-  TempQword = AsmReadMsr64 (mFixedMtrrTable[MsrNum].Msr) & (~ClearMask | OrMask);\r
+  TempQword = (AsmReadMsr64 (mFixedMtrrTable[MsrNum].Msr) & (~ClearMask)) | OrMask;\r
   AsmWriteMsr64 (mFixedMtrrTable[MsrNum].Msr, TempQword);\r
 \r
   return EFI_SUCCESS;\r