PeiCpuPolicyLib.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /** @file
  2. This file is PeiCpuPolicy library.
  3. Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "PeiCpuPolicyLibrary.h"
  7. #include <SaAccess.h>
  8. #include <IndustryStandard/Pci22.h>
  9. #include <Library/MmPciLib.h>
  10. #include <Library/SaPlatformLib.h>
  11. #include <Library/ConfigBlockLib.h>
  12. #include <Library/PostCodeLib.h>
  13. /**
  14. Load Config block default
  15. @param[in] ConfigBlockPointer Pointer to config block
  16. **/
  17. VOID
  18. LoadCpuConfigDefault (
  19. IN VOID *ConfigBlockPointer
  20. )
  21. {
  22. CPU_CONFIG *CpuConfig;
  23. CpuConfig = ConfigBlockPointer;
  24. DEBUG ((DEBUG_INFO, "CpuConfig->Header.GuidHob.Name = %g\n", &CpuConfig->Header.GuidHob.Name));
  25. DEBUG ((DEBUG_INFO, "CpuConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuConfig->Header.GuidHob.Header.HobLength));
  26. /********************************
  27. CPU configuration
  28. ********************************/
  29. CpuConfig->AesEnable = CPU_FEATURE_ENABLE;
  30. CpuConfig->EnableRsr = CPU_FEATURE_ENABLE;
  31. CpuConfig->SmmbaseSwSmiNumber = (UINTN) PcdGet8 (PcdSmmbaseSwSmi);
  32. //
  33. // This function is shared by both non-FSP and FSP scenarios and always executed unconditionally.
  34. // Since FSP/silicon code should not unconditionally access any hardcoding flash regions (that region might not be accessible
  35. // in unknown platforms), the microcode location searching code should be moved to outside silicon code scope.
  36. //
  37. CpuConfig->MicrocodePatchAddress = 0;
  38. }
  39. /**
  40. Load Config block default
  41. @param[in] ConfigBlockPointer Pointer to config block
  42. **/
  43. VOID
  44. LoadCpuPowerMgmtBasicConfigDefault (
  45. IN VOID *ConfigBlockPointer
  46. )
  47. {
  48. CPU_POWER_MGMT_BASIC_CONFIG *CpuPowerMgmtBasicConfig;
  49. CPU_SKU CpuSku;
  50. MSR_REGISTER TempMsr;
  51. CpuPowerMgmtBasicConfig = ConfigBlockPointer;
  52. CpuSku = GetCpuSku();
  53. DEBUG ((DEBUG_INFO, "CpuPowerMgmtBasicConfig->Header.GuidHob.Name = %g\n", &CpuPowerMgmtBasicConfig->Header.GuidHob.Name));
  54. DEBUG ((DEBUG_INFO, "CpuPowerMgmtBasicConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuPowerMgmtBasicConfig->Header.GuidHob.Header.HobLength));
  55. /********************************
  56. CPU Power Management Basic configuration
  57. ********************************/
  58. CpuPowerMgmtBasicConfig->Hwp = TRUE;
  59. CpuPowerMgmtBasicConfig->HdcControl = TRUE;
  60. CpuPowerMgmtBasicConfig->PowerLimit2 = TRUE;
  61. CpuPowerMgmtBasicConfig->PowerLimit3Lock = TRUE;
  62. ///
  63. /// Initialize RATL (Runtime Average Temperature Limit) Config for SKL Y series.
  64. ///
  65. if (CpuSku == EnumCpuUlx) {
  66. CpuPowerMgmtBasicConfig->TccActivationOffset = 10;
  67. CpuPowerMgmtBasicConfig->TccOffsetTimeWindowForRatl = 5000; // 5 sec
  68. CpuPowerMgmtBasicConfig->TccOffsetClamp = CPU_FEATURE_ENABLE;
  69. }
  70. CpuPowerMgmtBasicConfig->TurboMode = TRUE;
  71. TempMsr.Qword = AsmReadMsr64 (MSR_TURBO_RATIO_LIMIT);
  72. CpuPowerMgmtBasicConfig->OneCoreRatioLimit = TempMsr.Bytes.FirstByte;
  73. CpuPowerMgmtBasicConfig->TwoCoreRatioLimit = TempMsr.Bytes.SecondByte;
  74. CpuPowerMgmtBasicConfig->ThreeCoreRatioLimit = TempMsr.Bytes.ThirdByte;
  75. CpuPowerMgmtBasicConfig->FourCoreRatioLimit = TempMsr.Bytes.FouthByte;
  76. CpuPowerMgmtBasicConfig->FiveCoreRatioLimit = TempMsr.Bytes.FifthByte;
  77. CpuPowerMgmtBasicConfig->SixCoreRatioLimit = TempMsr.Bytes.SixthByte;
  78. CpuPowerMgmtBasicConfig->SevenCoreRatioLimit = TempMsr.Bytes.SeventhByte;
  79. CpuPowerMgmtBasicConfig->EightCoreRatioLimit = TempMsr.Bytes.EighthByte;
  80. }
  81. /**
  82. Load Config block default
  83. @param[in] ConfigBlockPointer Pointer to config block
  84. **/
  85. VOID
  86. LoadCpuPowerMgmtCustomConfigDefault (
  87. IN VOID *ConfigBlockPointer
  88. )
  89. {
  90. CPU_POWER_MGMT_CUSTOM_CONFIG *CpuPowerMgmtCustomConfig;
  91. CpuPowerMgmtCustomConfig = ConfigBlockPointer;
  92. DEBUG ((DEBUG_INFO, "CpuPowerMgmtCustomConfig->Header.GuidHob.Name = %g\n", &CpuPowerMgmtCustomConfig->Header.GuidHob.Name));
  93. DEBUG ((DEBUG_INFO, "CpuPowerMgmtCustomConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuPowerMgmtCustomConfig->Header.GuidHob.Header.HobLength));
  94. /********************************
  95. CPU Power Management Custom configuration
  96. ********************************/
  97. CpuPowerMgmtCustomConfig->CustomRatioTable.Cpuid = (UINT16) ((GetCpuFamily() | GetCpuStepping()) & (0x0FFF));
  98. }
  99. /**
  100. Load Config block default
  101. @param[in] ConfigBlockPointer Pointer to config block
  102. **/
  103. VOID
  104. LoadCpuTestConfigDefault (
  105. IN VOID *ConfigBlockPointer
  106. )
  107. {
  108. CPU_TEST_CONFIG *CpuTestConfig;
  109. CPU_SKU CpuSku;
  110. CpuTestConfig = ConfigBlockPointer;
  111. DEBUG ((DEBUG_INFO, "CpuTestConfig->Header.GuidHob.Name = %g\n", &CpuTestConfig->Header.GuidHob.Name));
  112. DEBUG ((DEBUG_INFO, "CpuTestConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuTestConfig->Header.GuidHob.Header.HobLength));
  113. CpuSku = GetCpuSku();
  114. /********************************
  115. CPU Test configuration
  116. ********************************/
  117. CpuTestConfig->MlcStreamerPrefetcher = CPU_FEATURE_ENABLE;
  118. CpuTestConfig->MlcSpatialPrefetcher = CPU_FEATURE_ENABLE;
  119. CpuTestConfig->MonitorMwaitEnable = CPU_FEATURE_ENABLE;
  120. CpuTestConfig->MachineCheckEnable = CPU_FEATURE_ENABLE;
  121. CpuTestConfig->DebugInterfaceLockEnable = CPU_FEATURE_ENABLE;
  122. CpuTestConfig->ApIdleManner = 2; // AP Idle Manner default as Mwait Loop
  123. CpuTestConfig->ApHandoffManner = 2; // AP Handoff to OS default as Mwait Loop
  124. ///
  125. /// Processor Trace
  126. ///
  127. CpuTestConfig->ProcTraceMemSize = EnumProcTraceMemDisable;
  128. /**
  129. This policy should be used to enable or disable Voltage Optimization feature.
  130. Recommended defaults:
  131. Enable - For Mobile SKUs(U/Y)
  132. Disable - Rest of all SKUs other than Mobile.
  133. **/
  134. if ((CpuSku == EnumCpuUlx) || (CpuSku == EnumCpuUlt)){
  135. CpuTestConfig->VoltageOptimization = CPU_FEATURE_ENABLE;
  136. } else {
  137. CpuTestConfig->VoltageOptimization = CPU_FEATURE_DISABLE;
  138. }
  139. }
  140. /**
  141. Load Config block default
  142. @param[in] ConfigBlockPointer Pointer to config block
  143. **/
  144. VOID
  145. LoadCpuPidTestConfigDefault (
  146. IN VOID *ConfigBlockPointer
  147. )
  148. {
  149. CPU_PID_TEST_CONFIG *CpuPidTestConfig;
  150. CpuPidTestConfig = ConfigBlockPointer;
  151. DEBUG ((DEBUG_INFO, "CpuPidTestConfig->Header.GuidHob.Name = %g\n", &CpuPidTestConfig->Header.GuidHob.Name));
  152. DEBUG ((DEBUG_INFO, "CpuPidTestConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuPidTestConfig->Header.GuidHob.Header.HobLength));
  153. /********************************
  154. CPU PID Test configuration
  155. ********************************/
  156. }
  157. /**
  158. Load Config block default
  159. @param[in] ConfigBlockPointer Pointer to config block
  160. **/
  161. VOID
  162. LoadCpuPowerMgmtTestConfigDefault (
  163. IN VOID *ConfigBlockPointer
  164. )
  165. {
  166. CPU_POWER_MGMT_TEST_CONFIG *CpuPowerMgmtTestConfig;
  167. CPU_FAMILY CpuFamily;
  168. CpuPowerMgmtTestConfig = ConfigBlockPointer;
  169. DEBUG ((DEBUG_INFO, "CpuPowerMgmtTestConfig->Header.GuidHob.Name = %g\n", &CpuPowerMgmtTestConfig->Header.GuidHob.Name));
  170. DEBUG ((DEBUG_INFO, "CpuPowerMgmtTestConfig->Header.GuidHob.Header.HobLength = 0x%x\n", CpuPowerMgmtTestConfig->Header.GuidHob.Header.HobLength));
  171. /********************************
  172. CPU Power Management Test configuration
  173. ********************************/
  174. CpuPowerMgmtTestConfig->Eist = TRUE;
  175. CpuPowerMgmtTestConfig->EnergyEfficientPState = TRUE;
  176. CpuPowerMgmtTestConfig->EnergyEfficientTurbo = TRUE;
  177. CpuPowerMgmtTestConfig->BiProcHot = TRUE;
  178. CpuPowerMgmtTestConfig->DisableProcHotOut = TRUE;
  179. CpuPowerMgmtTestConfig->AutoThermalReporting = TRUE;
  180. CpuPowerMgmtTestConfig->ThermalMonitor = TRUE;
  181. CpuPowerMgmtTestConfig->Cx = TRUE;
  182. CpuPowerMgmtTestConfig->PmgCstCfgCtrlLock = TRUE;
  183. CpuPowerMgmtTestConfig->C1e = TRUE;
  184. CpuPowerMgmtTestConfig->C1AutoDemotion = TRUE;
  185. CpuPowerMgmtTestConfig->C1UnDemotion = TRUE;
  186. CpuPowerMgmtTestConfig->C3AutoDemotion = TRUE;
  187. CpuPowerMgmtTestConfig->C3UnDemotion = TRUE;
  188. CpuPowerMgmtTestConfig->PkgCStateDemotion = TRUE;
  189. CpuPowerMgmtTestConfig->PkgCStateUnDemotion = TRUE;
  190. CpuPowerMgmtTestConfig->CStatePreWake = TRUE;
  191. CpuPowerMgmtTestConfig->RaceToHalt = TRUE;
  192. CpuPowerMgmtTestConfig->CstateLatencyControl0Irtl = C3_LATENCY;
  193. CpuPowerMgmtTestConfig->CstateLatencyControl1Irtl = C6_C7_SHORT_LATENCY;
  194. CpuPowerMgmtTestConfig->CstateLatencyControl2Irtl = C6_C7_LONG_LATENCY;
  195. CpuPowerMgmtTestConfig->CstateLatencyControl3Irtl = C8_LATENCY;
  196. CpuPowerMgmtTestConfig->CstateLatencyControl4Irtl = C9_LATENCY;
  197. //
  198. // If PS4 is disabled, program 2750us to MSR_C_STATE_LATENCY_CONTROL_5
  199. //
  200. CpuPowerMgmtTestConfig->CstateLatencyControl5Irtl = C10_LATENCY;
  201. CpuPowerMgmtTestConfig->PkgCStateLimit = PkgAuto;
  202. CpuPowerMgmtTestConfig->CstateLatencyControl0TimeUnit = TimeUnit1024ns;
  203. CpuPowerMgmtTestConfig->CstateLatencyControl1TimeUnit = TimeUnit1024ns;
  204. CpuPowerMgmtTestConfig->CstateLatencyControl2TimeUnit = TimeUnit1024ns;
  205. CpuPowerMgmtTestConfig->CstateLatencyControl3TimeUnit = TimeUnit1024ns;
  206. CpuPowerMgmtTestConfig->CstateLatencyControl4TimeUnit = TimeUnit1024ns;
  207. CpuPowerMgmtTestConfig->CstateLatencyControl5TimeUnit = TimeUnit1024ns;
  208. CpuPowerMgmtTestConfig->CustomPowerUnit = PowerUnit125MilliWatts;
  209. CpuPowerMgmtTestConfig->PpmIrmSetting = PpmIrmPairFixedPriority;
  210. //
  211. // Pkg C-state Demotion/Un Demotion
  212. //
  213. CpuFamily = GetCpuFamily();
  214. if((CpuFamily == EnumCpuSklUltUlx) || (CpuFamily == EnumCpuSklDtHalo)){
  215. CpuPowerMgmtTestConfig->PkgCStateDemotion = TRUE;
  216. } else if((CpuFamily == EnumCpuKblUltUlx) || (CpuFamily == EnumCpuKblDtHalo)) {
  217. CpuPowerMgmtTestConfig->PkgCStateDemotion = FALSE;
  218. }
  219. if((CpuFamily == EnumCpuSklUltUlx) || (CpuFamily == EnumCpuSklDtHalo)){
  220. CpuPowerMgmtTestConfig->PkgCStateDemotion = TRUE;
  221. } else if((CpuFamily == EnumCpuKblUltUlx) || (CpuFamily == EnumCpuKblDtHalo)) {
  222. CpuPowerMgmtTestConfig->PkgCStateDemotion = FALSE;
  223. }
  224. }
  225. static COMPONENT_BLOCK_ENTRY mCpuIpBlocks [] = {
  226. {&gCpuConfigGuid, sizeof (CPU_CONFIG), CPU_CONFIG_REVISION, LoadCpuConfigDefault},
  227. {&gCpuPowerMgmtBasicConfigGuid, sizeof (CPU_POWER_MGMT_BASIC_CONFIG), CPU_POWER_MGMT_BASIC_CONFIG_REVISION, LoadCpuPowerMgmtBasicConfigDefault},
  228. {&gCpuPowerMgmtCustomConfigGuid, sizeof (CPU_POWER_MGMT_CUSTOM_CONFIG), CPU_POWER_MGMT_CUSTOM_CONFIG_REVISION, LoadCpuPowerMgmtCustomConfigDefault},
  229. {&gCpuTestConfigGuid, sizeof (CPU_TEST_CONFIG), CPU_TEST_CONFIG_REVISION, LoadCpuTestConfigDefault},
  230. {&gCpuPidTestConfigGuid, sizeof (CPU_PID_TEST_CONFIG), CPU_PID_TEST_CONFIG_REVISION, LoadCpuPidTestConfigDefault},
  231. {&gCpuPowerMgmtTestConfigGuid, sizeof (CPU_POWER_MGMT_TEST_CONFIG), CPU_POWER_MGMT_TEST_CONFIG_REVISION, LoadCpuPowerMgmtTestConfigDefault},
  232. };
  233. /**
  234. Get CPU config block table total size.
  235. @retval Size of CPU config block table
  236. **/
  237. UINT16
  238. EFIAPI
  239. CpuGetConfigBlockTotalSize (
  240. VOID
  241. )
  242. {
  243. return GetComponentConfigBlockTotalSize (&mCpuIpBlocks[0], sizeof (mCpuIpBlocks) / sizeof (COMPONENT_BLOCK_ENTRY));
  244. }
  245. /**
  246. CpuAddConfigBlocks add all Cpu config blocks.
  247. @param[in] ConfigBlockTableAddress The pointer to add CPU config blocks
  248. @retval EFI_SUCCESS The policy default is initialized.
  249. @retval EFI_OUT_OF_RESOURCES Insufficient resources to create buffer
  250. **/
  251. EFI_STATUS
  252. EFIAPI
  253. CpuAddConfigBlocks (
  254. IN VOID *ConfigBlockTableAddress
  255. )
  256. {
  257. EFI_STATUS Status;
  258. DEBUG((DEBUG_INFO, "CPU Post-Mem Entry \n"));
  259. PostCode (0xC00);
  260. Status = AddComponentConfigBlocks (ConfigBlockTableAddress, &mCpuIpBlocks[0], sizeof (mCpuIpBlocks) / sizeof (COMPONENT_BLOCK_ENTRY));
  261. DEBUG ((DEBUG_INFO, "CpuAddConfigBlocks Done \n"));
  262. PostCode (0xC09);
  263. return Status;
  264. }