X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=UefiCpuPkg%2FLibrary%2FMtrrLib%2FMtrrLib.c;h=b1c12aa32e01026a4a2765b9f08a4bd13d51c39f;hp=1584ae23d9ce49d57fdfa034c04a6d1644b6dd44;hb=31b3597ee22c431904476bacd1970fb1cb3f8fc5;hpb=76b4cae357dff0f8f1f5cc3ce20675ba20ed2847 diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c index 1584ae23d9..b1c12aa32e 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -103,6 +103,24 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mMtrrMemoryCacheTypeShortName[] = { "R*" // Invalid }; +/** + Worker function returns the variable MTRR count for the CPU. + + @return Variable MTRR count + +**/ +UINT32 +GetVariableMtrrCountWorker ( + VOID + ) +{ + UINT32 VariableMtrrCount; + + VariableMtrrCount = (UINT32)(AsmReadMsr64 (MTRR_LIB_IA32_MTRR_CAP) & MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK); + ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR); + return VariableMtrrCount; +} + /** Returns the variable MTRR count for the CPU. @@ -115,34 +133,27 @@ GetVariableMtrrCount ( VOID ) { - UINT32 VariableMtrrCount; - if (!IsMtrrSupported ()) { return 0; } - - VariableMtrrCount = (UINT32)(AsmReadMsr64 (MTRR_LIB_IA32_MTRR_CAP) & MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK); - ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR); - - return VariableMtrrCount; + return GetVariableMtrrCountWorker (); } /** - Returns the firmware usable variable MTRR count for the CPU. + Worker function returns the firmware usable variable MTRR count for the CPU. @return Firmware usable variable MTRR count **/ UINT32 -EFIAPI -GetFirmwareVariableMtrrCount ( +GetFirmwareVariableMtrrCountWorker ( VOID ) { UINT32 VariableMtrrCount; UINT32 ReservedMtrrNumber; - VariableMtrrCount = GetVariableMtrrCount (); + VariableMtrrCount = GetVariableMtrrCountWorker (); ReservedMtrrNumber = PcdGet32 (PcdCpuNumberOfReservedVariableMtrrs); if (VariableMtrrCount < ReservedMtrrNumber) { return 0; @@ -151,6 +162,39 @@ GetFirmwareVariableMtrrCount ( return VariableMtrrCount - ReservedMtrrNumber; } +/** + Returns the firmware usable variable MTRR count for the CPU. + + @return Firmware usable variable MTRR count + +**/ +UINT32 +EFIAPI +GetFirmwareVariableMtrrCount ( + VOID + ) +{ + if (!IsMtrrSupported ()) { + return 0; + } + return GetFirmwareVariableMtrrCountWorker (); +} + +/** + Worker function returns the default MTRR cache type for the system. + + @return The default MTRR cache type. + +**/ +MTRR_MEMORY_CACHE_TYPE +MtrrGetDefaultMemoryTypeWorker ( + VOID + ) +{ + return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7); +} + + /** Returns the default MTRR cache type for the system. @@ -166,8 +210,7 @@ MtrrGetDefaultMemoryType ( if (!IsMtrrSupported ()) { return CacheUncacheable; } - - return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7); + return MtrrGetDefaultMemoryTypeWorker (); } /** @@ -1290,26 +1333,21 @@ MtrrGetMemoryAttribute ( /** - This function will get the raw value in variable MTRRs + Worker function will get the raw value in variable MTRRs - @param[out] FixedSettings A buffer to hold fixed MTRRs content. + @param[out] VariableSettings A buffer to hold variable MTRRs content. @return The VariableSettings input pointer **/ MTRR_VARIABLE_SETTINGS* -EFIAPI -MtrrGetVariableMtrr ( - OUT MTRR_VARIABLE_SETTINGS *VariableSettings +MtrrGetVariableMtrrWorker ( + OUT MTRR_VARIABLE_SETTINGS *VariableSettings ) { UINT32 Index; UINT32 VariableMtrrCount; - if (!IsMtrrSupported ()) { - return VariableSettings; - } - VariableMtrrCount = GetVariableMtrrCount (); ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR); @@ -1323,6 +1361,29 @@ MtrrGetVariableMtrr ( return VariableSettings; } +/** + This function will get the raw value in variable MTRRs + + @param[out] VariableSettings A buffer to hold variable MTRRs content. + + @return The VariableSettings input pointer + +**/ +MTRR_VARIABLE_SETTINGS* +EFIAPI +MtrrGetVariableMtrr ( + OUT MTRR_VARIABLE_SETTINGS *VariableSettings + ) +{ + if (!IsMtrrSupported ()) { + return VariableSettings; + } + + return MtrrGetVariableMtrrWorker ( + VariableSettings + ); +} + /** Worker function setting variable MTRRs @@ -1380,11 +1441,34 @@ MtrrSetVariableMtrr ( return VariableSettings; } +/** + Worker function gets the content in fixed MTRRs + + @param[out] FixedSettings A buffer to hold fixed MTRRs content. + + @retval The pointer of FixedSettings + +**/ +MTRR_FIXED_SETTINGS* +MtrrGetFixedMtrrWorker ( + OUT MTRR_FIXED_SETTINGS *FixedSettings + ) +{ + UINT32 Index; + + for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) { + FixedSettings->Mtrr[Index] = + AsmReadMsr64 (mMtrrLibFixedMtrrTable[Index].Msr); + } + + return FixedSettings; +} + /** This function gets the content in fixed MTRRs - @param[out] FixedSettings A buffer to hold fixed Mtrrs content. + @param[out] FixedSettings A buffer to hold fixed MTRRs content. @retval The pointer of FixedSettings @@ -1395,18 +1479,11 @@ MtrrGetFixedMtrr ( OUT MTRR_FIXED_SETTINGS *FixedSettings ) { - UINT32 Index; - if (!IsMtrrSupported ()) { return FixedSettings; } - for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) { - FixedSettings->Mtrr[Index] = - AsmReadMsr64 (mMtrrLibFixedMtrrTable[Index].Msr); - }; - - return FixedSettings; + return MtrrGetFixedMtrrWorker (FixedSettings); } /**