123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- /** @file
- This file is PeiCpuPolicy library.
- Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
- **/
- #include "PeiCpuPolicyLibrary.h"
- #include <SaAccess.h>
- #include <IndustryStandard/Pci22.h>
- #include <Library/MmPciLib.h>
- #include <Library/SaPlatformLib.h>
- #include <Library/ConfigBlockLib.h>
- #include <Library/PostCodeLib.h>
- /**
- Load Config block default
- @param[in] ConfigBlockPointer Pointer to config block
- **/
- VOID
- LoadCpuConfigDefault (
- IN VOID *ConfigBlockPointer
- )
- {
- CPU_CONFIG *CpuConfig;
- CpuConfig = ConfigBlockPointer;
- DEBUG ((DEBUG_INFO, "CpuConfig->Header.GuidHob.Name = %g\n", &CpuConfig->Header.GuidHob.Name));
- DEBUG ((DEBUG_INFO, "CpuConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuConfig->Header.GuidHob.Header.HobLength));
- /********************************
- CPU configuration
- ********************************/
- CpuConfig->AesEnable = CPU_FEATURE_ENABLE;
- CpuConfig->EnableRsr = CPU_FEATURE_ENABLE;
- CpuConfig->SmmbaseSwSmiNumber = (UINTN) PcdGet8 (PcdSmmbaseSwSmi);
- //
- // This function is shared by both non-FSP and FSP scenarios and always executed unconditionally.
- // Since FSP/silicon code should not unconditionally access any hardcoding flash regions (that region might not be accessible
- // in unknown platforms), the microcode location searching code should be moved to outside silicon code scope.
- //
- CpuConfig->MicrocodePatchAddress = 0;
- }
- /**
- Load Config block default
- @param[in] ConfigBlockPointer Pointer to config block
- **/
- VOID
- LoadCpuPowerMgmtBasicConfigDefault (
- IN VOID *ConfigBlockPointer
- )
- {
- CPU_POWER_MGMT_BASIC_CONFIG *CpuPowerMgmtBasicConfig;
- CPU_SKU CpuSku;
- MSR_REGISTER TempMsr;
- CpuPowerMgmtBasicConfig = ConfigBlockPointer;
- CpuSku = GetCpuSku();
- DEBUG ((DEBUG_INFO, "CpuPowerMgmtBasicConfig->Header.GuidHob.Name = %g\n", &CpuPowerMgmtBasicConfig->Header.GuidHob.Name));
- DEBUG ((DEBUG_INFO, "CpuPowerMgmtBasicConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuPowerMgmtBasicConfig->Header.GuidHob.Header.HobLength));
- /********************************
- CPU Power Management Basic configuration
- ********************************/
- CpuPowerMgmtBasicConfig->Hwp = TRUE;
- CpuPowerMgmtBasicConfig->HdcControl = TRUE;
- CpuPowerMgmtBasicConfig->PowerLimit2 = TRUE;
- CpuPowerMgmtBasicConfig->PowerLimit3Lock = TRUE;
- ///
- /// Initialize RATL (Runtime Average Temperature Limit) Config for SKL Y series.
- ///
- if (CpuSku == EnumCpuUlx) {
- CpuPowerMgmtBasicConfig->TccActivationOffset = 10;
- CpuPowerMgmtBasicConfig->TccOffsetTimeWindowForRatl = 5000; // 5 sec
- CpuPowerMgmtBasicConfig->TccOffsetClamp = CPU_FEATURE_ENABLE;
- }
- CpuPowerMgmtBasicConfig->TurboMode = TRUE;
- TempMsr.Qword = AsmReadMsr64 (MSR_TURBO_RATIO_LIMIT);
- CpuPowerMgmtBasicConfig->OneCoreRatioLimit = TempMsr.Bytes.FirstByte;
- CpuPowerMgmtBasicConfig->TwoCoreRatioLimit = TempMsr.Bytes.SecondByte;
- CpuPowerMgmtBasicConfig->ThreeCoreRatioLimit = TempMsr.Bytes.ThirdByte;
- CpuPowerMgmtBasicConfig->FourCoreRatioLimit = TempMsr.Bytes.FouthByte;
- CpuPowerMgmtBasicConfig->FiveCoreRatioLimit = TempMsr.Bytes.FifthByte;
- CpuPowerMgmtBasicConfig->SixCoreRatioLimit = TempMsr.Bytes.SixthByte;
- CpuPowerMgmtBasicConfig->SevenCoreRatioLimit = TempMsr.Bytes.SeventhByte;
- CpuPowerMgmtBasicConfig->EightCoreRatioLimit = TempMsr.Bytes.EighthByte;
- }
- /**
- Load Config block default
- @param[in] ConfigBlockPointer Pointer to config block
- **/
- VOID
- LoadCpuPowerMgmtCustomConfigDefault (
- IN VOID *ConfigBlockPointer
- )
- {
- CPU_POWER_MGMT_CUSTOM_CONFIG *CpuPowerMgmtCustomConfig;
- CpuPowerMgmtCustomConfig = ConfigBlockPointer;
- DEBUG ((DEBUG_INFO, "CpuPowerMgmtCustomConfig->Header.GuidHob.Name = %g\n", &CpuPowerMgmtCustomConfig->Header.GuidHob.Name));
- DEBUG ((DEBUG_INFO, "CpuPowerMgmtCustomConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuPowerMgmtCustomConfig->Header.GuidHob.Header.HobLength));
- /********************************
- CPU Power Management Custom configuration
- ********************************/
- CpuPowerMgmtCustomConfig->CustomRatioTable.Cpuid = (UINT16) ((GetCpuFamily() | GetCpuStepping()) & (0x0FFF));
- }
- /**
- Load Config block default
- @param[in] ConfigBlockPointer Pointer to config block
- **/
- VOID
- LoadCpuTestConfigDefault (
- IN VOID *ConfigBlockPointer
- )
- {
- CPU_TEST_CONFIG *CpuTestConfig;
- CPU_SKU CpuSku;
- CpuTestConfig = ConfigBlockPointer;
- DEBUG ((DEBUG_INFO, "CpuTestConfig->Header.GuidHob.Name = %g\n", &CpuTestConfig->Header.GuidHob.Name));
- DEBUG ((DEBUG_INFO, "CpuTestConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuTestConfig->Header.GuidHob.Header.HobLength));
- CpuSku = GetCpuSku();
- /********************************
- CPU Test configuration
- ********************************/
- CpuTestConfig->MlcStreamerPrefetcher = CPU_FEATURE_ENABLE;
- CpuTestConfig->MlcSpatialPrefetcher = CPU_FEATURE_ENABLE;
- CpuTestConfig->MonitorMwaitEnable = CPU_FEATURE_ENABLE;
- CpuTestConfig->MachineCheckEnable = CPU_FEATURE_ENABLE;
- CpuTestConfig->DebugInterfaceLockEnable = CPU_FEATURE_ENABLE;
- CpuTestConfig->ApIdleManner = 2; // AP Idle Manner default as Mwait Loop
- CpuTestConfig->ApHandoffManner = 2; // AP Handoff to OS default as Mwait Loop
- ///
- /// Processor Trace
- ///
- CpuTestConfig->ProcTraceMemSize = EnumProcTraceMemDisable;
- /**
- This policy should be used to enable or disable Voltage Optimization feature.
- Recommended defaults:
- Enable - For Mobile SKUs(U/Y)
- Disable - Rest of all SKUs other than Mobile.
- **/
- if ((CpuSku == EnumCpuUlx) || (CpuSku == EnumCpuUlt)){
- CpuTestConfig->VoltageOptimization = CPU_FEATURE_ENABLE;
- } else {
- CpuTestConfig->VoltageOptimization = CPU_FEATURE_DISABLE;
- }
- }
- /**
- Load Config block default
- @param[in] ConfigBlockPointer Pointer to config block
- **/
- VOID
- LoadCpuPidTestConfigDefault (
- IN VOID *ConfigBlockPointer
- )
- {
- CPU_PID_TEST_CONFIG *CpuPidTestConfig;
- CpuPidTestConfig = ConfigBlockPointer;
- DEBUG ((DEBUG_INFO, "CpuPidTestConfig->Header.GuidHob.Name = %g\n", &CpuPidTestConfig->Header.GuidHob.Name));
- DEBUG ((DEBUG_INFO, "CpuPidTestConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuPidTestConfig->Header.GuidHob.Header.HobLength));
- /********************************
- CPU PID Test configuration
- ********************************/
- }
- /**
- Load Config block default
- @param[in] ConfigBlockPointer Pointer to config block
- **/
- VOID
- LoadCpuPowerMgmtTestConfigDefault (
- IN VOID *ConfigBlockPointer
- )
- {
- CPU_POWER_MGMT_TEST_CONFIG *CpuPowerMgmtTestConfig;
- CPU_FAMILY CpuFamily;
- CpuPowerMgmtTestConfig = ConfigBlockPointer;
- DEBUG ((DEBUG_INFO, "CpuPowerMgmtTestConfig->Header.GuidHob.Name = %g\n", &CpuPowerMgmtTestConfig->Header.GuidHob.Name));
- DEBUG ((DEBUG_INFO, "CpuPowerMgmtTestConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuPowerMgmtTestConfig->Header.GuidHob.Header.HobLength));
- /********************************
- CPU Power Management Test configuration
- ********************************/
- CpuPowerMgmtTestConfig->Eist = TRUE;
- CpuPowerMgmtTestConfig->EnergyEfficientPState = TRUE;
- CpuPowerMgmtTestConfig->EnergyEfficientTurbo = TRUE;
- CpuPowerMgmtTestConfig->BiProcHot = TRUE;
- CpuPowerMgmtTestConfig->DisableProcHotOut = TRUE;
- CpuPowerMgmtTestConfig->AutoThermalReporting = TRUE;
- CpuPowerMgmtTestConfig->ThermalMonitor = TRUE;
- CpuPowerMgmtTestConfig->Cx = TRUE;
- CpuPowerMgmtTestConfig->PmgCstCfgCtrlLock = TRUE;
- CpuPowerMgmtTestConfig->C1e = TRUE;
- CpuPowerMgmtTestConfig->C1AutoDemotion = TRUE;
- CpuPowerMgmtTestConfig->C1UnDemotion = TRUE;
- CpuPowerMgmtTestConfig->C3AutoDemotion = TRUE;
- CpuPowerMgmtTestConfig->C3UnDemotion = TRUE;
- CpuPowerMgmtTestConfig->PkgCStateDemotion = TRUE;
- CpuPowerMgmtTestConfig->PkgCStateUnDemotion = TRUE;
- CpuPowerMgmtTestConfig->CStatePreWake = TRUE;
- CpuPowerMgmtTestConfig->RaceToHalt = TRUE;
- CpuPowerMgmtTestConfig->CstateLatencyControl0Irtl = C3_LATENCY;
- CpuPowerMgmtTestConfig->CstateLatencyControl1Irtl = C6_C7_SHORT_LATENCY;
- CpuPowerMgmtTestConfig->CstateLatencyControl2Irtl = C6_C7_LONG_LATENCY;
- CpuPowerMgmtTestConfig->CstateLatencyControl3Irtl = C8_LATENCY;
- CpuPowerMgmtTestConfig->CstateLatencyControl4Irtl = C9_LATENCY;
- //
- // If PS4 is disabled, program 2750us to MSR_C_STATE_LATENCY_CONTROL_5
- //
- CpuPowerMgmtTestConfig->CstateLatencyControl5Irtl = C10_LATENCY;
- CpuPowerMgmtTestConfig->PkgCStateLimit = PkgAuto;
- CpuPowerMgmtTestConfig->CstateLatencyControl0TimeUnit = TimeUnit1024ns;
- CpuPowerMgmtTestConfig->CstateLatencyControl1TimeUnit = TimeUnit1024ns;
- CpuPowerMgmtTestConfig->CstateLatencyControl2TimeUnit = TimeUnit1024ns;
- CpuPowerMgmtTestConfig->CstateLatencyControl3TimeUnit = TimeUnit1024ns;
- CpuPowerMgmtTestConfig->CstateLatencyControl4TimeUnit = TimeUnit1024ns;
- CpuPowerMgmtTestConfig->CstateLatencyControl5TimeUnit = TimeUnit1024ns;
- CpuPowerMgmtTestConfig->CustomPowerUnit = PowerUnit125MilliWatts;
- CpuPowerMgmtTestConfig->PpmIrmSetting = PpmIrmPairFixedPriority;
- //
- // Pkg C-state Demotion/Un Demotion
- //
- CpuFamily = GetCpuFamily();
- if((CpuFamily == EnumCpuSklUltUlx) || (CpuFamily == EnumCpuSklDtHalo)){
- CpuPowerMgmtTestConfig->PkgCStateDemotion = TRUE;
- } else if((CpuFamily == EnumCpuKblUltUlx) || (CpuFamily == EnumCpuKblDtHalo)) {
- CpuPowerMgmtTestConfig->PkgCStateDemotion = FALSE;
- }
- if((CpuFamily == EnumCpuSklUltUlx) || (CpuFamily == EnumCpuSklDtHalo)){
- CpuPowerMgmtTestConfig->PkgCStateDemotion = TRUE;
- } else if((CpuFamily == EnumCpuKblUltUlx) || (CpuFamily == EnumCpuKblDtHalo)) {
- CpuPowerMgmtTestConfig->PkgCStateDemotion = FALSE;
- }
- }
- static COMPONENT_BLOCK_ENTRY mCpuIpBlocks [] = {
- {&gCpuConfigGuid, sizeof (CPU_CONFIG), CPU_CONFIG_REVISION, LoadCpuConfigDefault},
- {&gCpuPowerMgmtBasicConfigGuid, sizeof (CPU_POWER_MGMT_BASIC_CONFIG), CPU_POWER_MGMT_BASIC_CONFIG_REVISION, LoadCpuPowerMgmtBasicConfigDefault},
- {&gCpuPowerMgmtCustomConfigGuid, sizeof (CPU_POWER_MGMT_CUSTOM_CONFIG), CPU_POWER_MGMT_CUSTOM_CONFIG_REVISION, LoadCpuPowerMgmtCustomConfigDefault},
- {&gCpuTestConfigGuid, sizeof (CPU_TEST_CONFIG), CPU_TEST_CONFIG_REVISION, LoadCpuTestConfigDefault},
- {&gCpuPidTestConfigGuid, sizeof (CPU_PID_TEST_CONFIG), CPU_PID_TEST_CONFIG_REVISION, LoadCpuPidTestConfigDefault},
- {&gCpuPowerMgmtTestConfigGuid, sizeof (CPU_POWER_MGMT_TEST_CONFIG), CPU_POWER_MGMT_TEST_CONFIG_REVISION, LoadCpuPowerMgmtTestConfigDefault},
- };
- /**
- Get CPU config block table total size.
- @retval Size of CPU config block table
- **/
- UINT16
- EFIAPI
- CpuGetConfigBlockTotalSize (
- VOID
- )
- {
- return GetComponentConfigBlockTotalSize (&mCpuIpBlocks[0], sizeof (mCpuIpBlocks) / sizeof (COMPONENT_BLOCK_ENTRY));
- }
- /**
- CpuAddConfigBlocks add all Cpu config blocks.
- @param[in] ConfigBlockTableAddress The pointer to add CPU config blocks
- @retval EFI_SUCCESS The policy default is initialized.
- @retval EFI_OUT_OF_RESOURCES Insufficient resources to create buffer
- **/
- EFI_STATUS
- EFIAPI
- CpuAddConfigBlocks (
- IN VOID *ConfigBlockTableAddress
- )
- {
- EFI_STATUS Status;
- DEBUG((DEBUG_INFO, "CPU Post-Mem Entry \n"));
- PostCode (0xC00);
- Status = AddComponentConfigBlocks (ConfigBlockTableAddress, &mCpuIpBlocks[0], sizeof (mCpuIpBlocks) / sizeof (COMPONENT_BLOCK_ENTRY));
- DEBUG ((DEBUG_INFO, "CpuAddConfigBlocks Done \n"));
- PostCode (0xC09);
- return Status;
- }
|