/** @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
@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
//\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
//\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
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
*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