alder_lake_bios/Intel/AlderLake/ClientOneSiliconPkg/Cpu/Library/PeiCpuPolicyLib/PeiCpuPolicyLib.c

319 lines
12 KiB
C

/** @file
This file is PeiCpuPolicy library.
@copyright
INTEL CONFIDENTIAL
Copyright 2014 - 2021 Intel Corporation.
The source code contained or described herein and all documents related to the
source code ("Material") are owned by Intel Corporation or its suppliers or
licensors. Title to the Material remains with Intel Corporation or its suppliers
and licensors. The Material may contain trade secrets and proprietary and
confidential information of Intel Corporation and its suppliers and licensors,
and is protected by worldwide copyright and trade secret laws and treaty
provisions. No part of the Material may be used, copied, reproduced, modified,
published, uploaded, posted, transmitted, distributed, or disclosed in any way
without Intel's prior express written permission.
No license under any patent, copyright, trade secret or other intellectual
property right is granted to or conferred upon you by disclosure or delivery
of the Materials, either expressly, by implication, inducement, estoppel or
otherwise. Any license under such intellectual property rights must be
express and approved by Intel in writing.
Unless otherwise agreed by Intel in writing, you may not remove or alter
this notice or any other notice embedded in Materials by Intel or
Intel's suppliers or licensors in any way.
This file contains an 'Intel Peripheral Driver' and is uniquely identified as
"Intel Reference Module" and is licensed for Intel CPUs and chipsets under
the terms of your license agreement with Intel or your vendor. This file may
be modified by the user, subject to additional terms of the license agreement.
@par Specification
**/
#include "PeiCpuPolicyLibrary.h"
#include <IndustryStandard/Pci22.h>
#include <Library/PciSegmentLib.h>
#include <Library/SaPlatformLib.h>
#include <Library/ConfigBlockLib.h>
#include <Library/PostCodeLib.h>
#include <Library/PcdLib.h>
#include <Library/CpuInfoFruLib.h>
#include <Library/PeiCpuInitFruLib.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->MicrocodePatchAddress = 0;
}
/**
Load Config block default
@param[in] ConfigBlockPointer Pointer to config block
**/
VOID
LoadBiosGuardConfigDefault (
IN VOID *ConfigBlockPointer
)
{
BIOS_GUARD_CONFIG *BiosGuardConfig;
BiosGuardConfig = ConfigBlockPointer;
DEBUG ((DEBUG_INFO, "BiosGuardConfig->Header.GuidHob.Name = %g\n", &BiosGuardConfig->Header.GuidHob.Name));
DEBUG ((DEBUG_INFO, "BiosGuardConfig->Header.GuidHob.Header.HobLength = 0x%x\n", BiosGuardConfig->Header.GuidHob.Header.HobLength));
/********************************
CPU BIOS Guard configuration
********************************/
BiosGuardConfig->EcCmdProvisionEav = 0xFF;
BiosGuardConfig->EcCmdLock = 0xFF;
BiosGuardConfig->BiosGuardModulePtr = 0xFFFFFFFFFFFFFFFF;
BiosGuardConfig->BiosGuardAttr = 0xFFFFFFFF;
BiosGuardConfig->SendEcCmd = 0xFFFFFFFF;
}
/**
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;
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 = FALSE;
CpuPowerMgmtBasicConfig->TccOffsetLock = TRUE;
CpuPowerMgmtBasicConfig->EnableItbm = TRUE;
CpuPowerMgmtBasicConfig->ApplyConfigTdp = TRUE;
CpuPowerMgmtBasicConfig->HwpLock = TRUE;
CpuPowerMgmtBasicConfig->HwpInterruptControl = TRUE;
///
/// Hwp misc functions
///
CpuPowerMgmtBasicConfig->EnablePerCorePState = TRUE;
CpuPowerMgmtBasicConfig->EnableHwpAutoPerCorePstate = TRUE;
CpuPowerMgmtBasicConfig->EnableHwpAutoEppGrouping = TRUE;
CpuPowerMgmtBasicConfig->EnableFastMsrHwpReq = FALSE;
CpuPowerMgmtBasicConfig->EnableEpbPeciOverride = FALSE;
///
/// Initialize RATL (Runtime Average Temperature Limit) Config
///
if (CpuSku == EnumCpuUlx) {
CpuPowerMgmtBasicConfig->TccActivationOffset = 10;
CpuPowerMgmtBasicConfig->TccOffsetTimeWindowForRatl = 5000; // 5 sec
CpuPowerMgmtBasicConfig->TccOffsetClamp = CPU_FEATURE_ENABLE;
}
if (GetPackageTdp() == CPU_TDP_150_WATTS) {
CpuPowerMgmtBasicConfig->TccActivationOffset = 10;
}
CpuPowerMgmtBasicConfig->TurboMode = TRUE;
PeiCpuLoadPowerMgmtBasicConfigDefault (CpuPowerMgmtBasicConfig);
}
/**
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
LoadCpuPowerMgmtPsysConfigDefault (
IN VOID *ConfigBlockPointer
)
{
CPU_POWER_MGMT_PSYS_CONFIG *CpuPowerMgmtPsysConfig;
CpuPowerMgmtPsysConfig = ConfigBlockPointer;
DEBUG ((DEBUG_INFO, "CpuPowerMgmtPsysConfig->Header.GuidHob.Name = %g\n", &CpuPowerMgmtPsysConfig->Header.GuidHob.Name));
DEBUG ((DEBUG_INFO, "CpuPowerMgmtPsysConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuPowerMgmtPsysConfig->Header.GuidHob.Header.HobLength));
/********************************
CPU Power Management Psys configuration
********************************/
}
/**
Load Config block default
@param[in] ConfigBlockPointer Pointer to config block
**/
VOID
LoadCpuTestConfigDefault (
IN VOID *ConfigBlockPointer
)
{
CPU_TEST_CONFIG *CpuTestConfig;
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));
/********************************
CPU Test configuration
********************************/
CpuTestConfig->MlcStreamerPrefetcher = CPU_FEATURE_ENABLE;
CpuTestConfig->MlcSpatialPrefetcher = CPU_FEATURE_ENABLE;
CpuTestConfig->MonitorMwaitEnable = CPU_FEATURE_ENABLE;
CpuTestConfig->MachineCheckEnable = CPU_FEATURE_ENABLE;
}
/**
Load Config block default
@param[in] ConfigBlockPointer Pointer to config block
**/
VOID
LoadCpuPowerMgmtTestConfigDefault (
IN VOID *ConfigBlockPointer
)
{
CPU_POWER_MGMT_TEST_CONFIG *CpuPowerMgmtTestConfig;
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->BiProcHot = TRUE;
CpuPowerMgmtTestConfig->DisableProcHotOut = TRUE;
CpuPowerMgmtTestConfig->ProcHotResponse = TRUE;
CpuPowerMgmtTestConfig->ProcHotLock = TRUE;
CpuPowerMgmtTestConfig->EnableAllThermalFunctions = TRUE;
CpuPowerMgmtTestConfig->ThermalMonitor = TRUE;
CpuPowerMgmtTestConfig->Cx = TRUE;
CpuPowerMgmtTestConfig->PmgCstCfgCtrlLock = TRUE;
CpuPowerMgmtTestConfig->C1e = TRUE;
CpuPowerMgmtTestConfig->C1AutoDemotion = TRUE;
CpuPowerMgmtTestConfig->C1UnDemotion = TRUE;
CpuPowerMgmtTestConfig->PkgCStateDemotion = TRUE;
CpuPowerMgmtTestConfig->PkgCStateUnDemotion = TRUE;
CpuPowerMgmtTestConfig->CStatePreWake = TRUE;
CpuPowerMgmtTestConfig->RaceToHalt = TRUE;
//
// If PS4 is disabled, program 2750us to MSR_C_STATE_LATENCY_CONTROL_5
//
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 = PpmIrmFixedPriority;
}
static COMPONENT_BLOCK_ENTRY mCpuIpBlocks [] = {
{&gCpuConfigGuid, sizeof (CPU_CONFIG), CPU_CONFIG_REVISION, LoadCpuConfigDefault},
{&gBiosGuardConfigGuid, sizeof (BIOS_GUARD_CONFIG), BIOS_GUARD_CONFIG_REVISION, LoadBiosGuardConfigDefault},
{&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},
{&gCpuPowerMgmtPsysConfigGuid, sizeof (CPU_POWER_MGMT_PSYS_CONFIG), CPU_POWER_MGMT_PSYS_CONFIG_REVISION, LoadCpuPowerMgmtPsysConfigDefault},
{&gCpuTestConfigGuid, sizeof (CPU_TEST_CONFIG), CPU_TEST_CONFIG_REVISION, LoadCpuTestConfigDefault},
{&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;
}