5 * AMD Family_10 Power Plane Initialization
7 * Performs the "BIOS Requirements for Power Plane Initialization" as described
10 * @xrefitem bom "File Content Label" "Release Content"
12 * @e sub-project: CPU/F10
13 * @e \$Revision: 56279 $ @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
17 ******************************************************************************
19 * Copyright (C) 2012 Advanced Micro Devices, Inc.
20 * All rights reserved.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions are met:
24 * * Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * * Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
30 * its contributors may be used to endorse or promote products derived
31 * from this software without specific prior written permission.
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
35 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
37 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 ******************************************************************************
47 /*----------------------------------------------------------------------------------------
48 * M O D U L E S U S E D
49 *----------------------------------------------------------------------------------------
54 #include "cpuRegisters.h"
55 #include "cpuF10PowerMgmt.h"
56 #include "cpuApicUtilities.h"
57 #include "cpuServices.h"
58 #include "GeneralServices.h"
59 #include "cpuFamilyTranslation.h"
60 #include "cpuF10Utilities.h"
61 #include "cpuF10PowerPlane.h"
63 #include "F10PackageType.h"
64 #include "OptionMultiSocket.h"
69 #define FILECODE PROC_CPU_FAMILY_0X10_CPUF10POWERPLANE_FILECODE
71 /*----------------------------------------------------------------------------------------
72 * D E F I N I T I O N S A N D M A C R O S
73 *----------------------------------------------------------------------------------------
76 // Register encodings for F3xD4[PowerStepUp/PowerStepDown]
77 CONST UINT16 ROMDATA PowerStepEncodings[16] =
97 // Register encodings for F3xDC[AltvidVSSlamTime]
98 CONST UINT32 ROMDATA AltvidSlamTime[8] =
110 /*----------------------------------------------------------------------------------------
111 * T Y P E D E F S A N D S T R U C T U R E S
112 *----------------------------------------------------------------------------------------
115 /*----------------------------------------------------------------------------------------
116 * P R O T O T Y P E S O F L O C A L F U N C T I O N S
117 *----------------------------------------------------------------------------------------
121 F10PmPwrPlaneInitPviCore (
122 IN AMD_CONFIG_PARAMS *StdHeader
127 F10CalculateAltvidVSSlamTimeOnCore (
128 IN BOOLEAN PviModeFlag,
129 IN PCI_ADDR *PciAddress,
130 IN AMD_CPU_EARLY_PARAMS *CpuEarlyParams,
131 IN AMD_CONFIG_PARAMS *StdHeader
136 F10PmVrmLowPowerModeEnable (
137 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
138 IN AMD_CPU_EARLY_PARAMS *CpuEarlyParams,
139 IN PCI_ADDR PciAddress,
140 IN AMD_CONFIG_PARAMS *StdHeader
144 /*----------------------------------------------------------------------------------------
145 * E X P O R T E D F U N C T I O N S
146 *----------------------------------------------------------------------------------------
148 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
149 /*---------------------------------------------------------------------------------------*/
151 * Family 10h core 0 entry point for performing power plane initialization.
153 * The steps are as follows:
154 * 1. If single plane, program lower VID code of CpuVid & NbVid for all
156 * 2. Configure F3xA0[SlamMode] & F3xD8[VsRampTime & VsSlamTime] based on
157 * platform requirements.
158 * 3. Configure F3xD4[PowerStepUp & PowerStepDown]
159 * 4. Optionally configure F3xA0[PsiVidEn & PsiVid]
161 * @param[in] FamilySpecificServices The current Family Specific Services.
162 * @param[in] CpuEarlyParams Service parameters
163 * @param[in] StdHeader Config handle for library and services.
167 F10CpuAmdPmPwrPlaneInit (
168 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
169 IN AMD_CPU_EARLY_PARAMS *CpuEarlyParams,
170 IN AMD_CONFIG_PARAMS *StdHeader
175 UINT16 PowerStepTime;
176 UINT32 PowerStepEncoded;
177 UINT32 LocalPciRegister;
186 UINT32 ProcessorPackageType;
187 UINT64 LocalMsrRegister;
189 AGESA_STATUS IgnoredSts;
190 PLATFORM_FEATS Features;
191 CPU_LOGICAL_ID LogicalId;
193 // Initialize the union
194 Features.PlatformValue = 0;
195 GetPlatformFeatures (&Features, &CpuEarlyParams->PlatformConfig, StdHeader);
197 IdentifyCore (StdHeader, &Socket, &Module, &Core, &IgnoredSts);
198 GetPciAddress (StdHeader, Socket, Module, &PciAddress, &IgnoredSts);
202 GetLogicalIdOfCurrentCore (&LogicalId, StdHeader);
205 PciAddress.Address.Function = FUNC_3;
206 PciAddress.Address.Register = PW_CTL_MISC_REG;
207 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
208 AndMask = 0xFFFFFFFF;
210 if (((POWER_CTRL_MISC_REGISTER *) &LocalPciRegister)->PviMode == 1) {
212 ((POWER_CTRL_MISC_REGISTER *) &AndMask)->SlamVidMode = 0;
214 // Have all single plane cores adjust their NB and CPU VID fields
215 TaskPtr.FuncAddress.PfApTask = F10PmPwrPlaneInitPviCore;
216 TaskPtr.DataTransfer.DataSizeInDwords = 0;
217 TaskPtr.ExeFlags = WAIT_FOR_CORE;
218 ApUtilRunCodeOnAllLocalCoresAtEarly (&TaskPtr, StdHeader, CpuEarlyParams);
222 ((POWER_CTRL_MISC_REGISTER *) &OrMask)->SlamVidMode = 1;
224 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader);
226 F10ProgramVSSlamTimeOnSocket (&PciAddress, CpuEarlyParams, StdHeader);
228 // Configure PowerStepUp/PowerStepDown
229 PciAddress.Address.Register = CPTC0_REG;
230 if ((Features.PlatformFeatures.PlatformSingleLink == 1) ||
231 (Features.PlatformFeatures.PlatformUma == 1) ||
232 (Features.PlatformFeatures.PlatformUmaIfcm == 1) ||
233 (Features.PlatformFeatures.PlatformIfcm == 1) ||
234 (Features.PlatformFeatures.PlatformIommu == 1)) {
235 PowerStepEncoded = 0x8;
237 GetGivenModuleCoreRange ((UINT32) Socket,
242 NumOfCores = ((NumOfCores - LowCore) + 1);
243 PowerStepTime = (UINT16) (400 / NumOfCores);
244 for (PowerStepEncoded = 0xF; PowerStepEncoded > 0; PowerStepEncoded--) {
245 if (PowerStepTime <= PowerStepEncodings[PowerStepEncoded]) {
250 AndMask = 0xFFFFFFFF;
251 ((CLK_PWR_TIMING_CTRL_REGISTER *) &AndMask)->PowerStepUp = 0;
252 ((CLK_PWR_TIMING_CTRL_REGISTER *) &AndMask)->PowerStepDown = 0;
254 ((CLK_PWR_TIMING_CTRL_REGISTER *) &OrMask)->PowerStepUp = PowerStepEncoded;
255 ((CLK_PWR_TIMING_CTRL_REGISTER *) &OrMask)->PowerStepDown = PowerStepEncoded;
256 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader);
258 if ((LogicalId.Revision & AMD_F10_C3) != 0) {
259 // Set up Pop up P-state register
260 PciAddress.Address.Register = CPTC2_REG;
261 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
262 AndMask = 0xFFFFFFFF;
263 ((POPUP_PSTATE_REGISTER *) &AndMask)->PopupPstate = 0;
264 ((POPUP_PSTATE_REGISTER *) &AndMask)->PopupCpuVid = 0;
265 ((POPUP_PSTATE_REGISTER *) &AndMask)->PopupCpuFid = 0;
266 ((POPUP_PSTATE_REGISTER *) &AndMask)->PopupCpuDid = 0;
268 ((POPUP_PSTATE_REGISTER *) &OrMask)->PopupEn = 0;
269 ((POPUP_PSTATE_REGISTER *) &OrMask)->PopupPstate = ((CLK_PWR_TIMING_CTRL2_REGISTER *) &LocalPciRegister)->PstateMaxVal;
270 LibAmdMsrRead ((((CLK_PWR_TIMING_CTRL2_REGISTER *) &LocalPciRegister)->PstateMaxVal + PS_REG_BASE), &LocalMsrRegister, StdHeader);
271 ((POPUP_PSTATE_REGISTER *) &OrMask)->PopupCpuVid = (UINT32) ((PSTATE_MSR *) &LocalMsrRegister)->CpuVid;
272 ((POPUP_PSTATE_REGISTER *) &OrMask)->PopupCpuFid = (UINT32) ((PSTATE_MSR *) &LocalMsrRegister)->CpuFid;
273 ((POPUP_PSTATE_REGISTER *) &OrMask)->PopupCpuDid = (UINT32) ((PSTATE_MSR *) &LocalMsrRegister)->CpuDid;
274 PciAddress.Address.Register = POPUP_PSTATE_REG;
275 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader);
278 PciAddress.Address.Register = CPTC1_REG;
279 AndMask = 0xFFFFFFFF;
280 ((CLK_PWR_TIMING_CTRL1_REGISTER *) &AndMask)->AltVidStart = 0;
282 ((CLK_PWR_TIMING_CTRL1_REGISTER *) &OrMask)->AltVidStart = (UINT32) ((PSTATE_MSR *) &LocalMsrRegister)->CpuVid;
283 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader);
285 // Set up Altvid slam time
286 ProcessorPackageType = LibAmdGetPackageType (StdHeader);
287 PciAddress.Address.Register = CPTC2_REG;
288 VsSlamTime = F10CalculateAltvidVSSlamTimeOnCore (PviModeFlag, &PciAddress, CpuEarlyParams, StdHeader);
289 AndMask = 0xFFFFFFFF;
290 ((CLK_PWR_TIMING_CTRL2_REGISTER *) &AndMask)->AltvidVSSlamTime = 0;
291 ((CLK_PWR_TIMING_CTRL2_REGISTER *) &AndMask)->SlamTimeMode = 0;
293 ((CLK_PWR_TIMING_CTRL2_REGISTER *) &OrMask)->AltvidVSSlamTime = VsSlamTime;
294 if (ProcessorPackageType == PACKAGE_TYPE_S1G3_S1G4 || ProcessorPackageType == PACKAGE_TYPE_ASB2) {
295 // If CPUID Fn8000_0001_EBX[PkgType]=0010b or 0100b, BIOS should program this to 10b;
296 // else BIOS should leave this field at 00b.
297 ((CLK_PWR_TIMING_CTRL2_REGISTER *) &OrMask)->SlamTimeMode = 2;
299 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader);
302 if (IsWarmReset (StdHeader) && !PviModeFlag) {
304 F10PmVrmLowPowerModeEnable (FamilySpecificServices, CpuEarlyParams, PciAddress, StdHeader);
309 /*---------------------------------------------------------------------------------------*/
311 * Support routine for F10CpuAmdPmPwrPlaneInit.
313 * This function implements step 1 on each core.
315 * @param[in] StdHeader Config handle for library and services.
320 F10PmPwrPlaneInitPviCore (
321 IN AMD_CONFIG_PARAMS *StdHeader
327 UINT64 LocalMsrRegister;
329 for (MsrAddr = PS_REG_BASE; MsrAddr <= PS_MAX_REG; MsrAddr++) {
330 LibAmdMsrRead (MsrAddr, &LocalMsrRegister, StdHeader);
331 if (((PSTATE_MSR *) &LocalMsrRegister)->PsEnable == (UINT64) 1) {
332 NbVid = (UINT32) (((PSTATE_MSR *) &LocalMsrRegister)->NbVid);
333 CpuVid = (UINT32) (((PSTATE_MSR *) &LocalMsrRegister)->CpuVid);
334 if (NbVid != CpuVid) {
335 if (NbVid > CpuVid) {
338 ((PSTATE_MSR *) &LocalMsrRegister)->NbVid = NbVid;
339 ((PSTATE_MSR *) &LocalMsrRegister)->CpuVid = NbVid;
340 LibAmdMsrWrite (MsrAddr, &LocalMsrRegister, StdHeader);
347 /*---------------------------------------------------------------------------------------*/
349 * Returns the encoded altvid voltage stabilization slam time for the executing
352 * This function calculates how much time it will take for the voltage to
353 * stabilize when transitioning from altvid to Pmin, and returns the necessary
354 * encoded value for the amount of time discovered.
356 * @param[in] PviModeFlag Whether or not the platform uses VRMs that
357 * employ the parallel VID interface.
358 * @param[in] PciAddress Full PCI address of the executing core's config space.
359 * @param[in] CpuEarlyParams Service parameters
360 * @param[in] StdHeader Config handle for library and services.
362 * @retval Encoded register value.
367 F10CalculateAltvidVSSlamTimeOnCore (
368 IN BOOLEAN PviModeFlag,
369 IN PCI_ADDR *PciAddress,
370 IN AMD_CPU_EARLY_PARAMS *CpuEarlyParams,
371 IN AMD_CONFIG_PARAMS *StdHeader
378 UINT32 LocalPciRegister;
379 UINT64 LocalMsrRegister;
380 PCI_ADDR LocalPciAddress;
382 // Calculate Slam Time
383 // VSSlamTime = 0.4us/mV (or 0.2us/mV) * Vpmin - Altvid
384 // In our case, we will scale the values by 100 to avoid
388 LibAmdMsrRead (MSR_PSTATE_CURRENT_LIMIT, &LocalMsrRegister, StdHeader);
389 MsrAddr = (UINT32) ((((PSTATE_CURLIM_MSR *) &LocalMsrRegister)->PstateMaxVal) + PS_REG_BASE);
392 LibAmdMsrRead (MsrAddr, &LocalMsrRegister, StdHeader);
393 PminVidCode = (UINT8) (((PSTATE_MSR *) &LocalMsrRegister)->CpuVid);
395 // If SVI, we only care about CPU VID.
396 // If PVI, determine the higher voltage b/t NB and CPU
398 NbVid = (UINT8) (((PSTATE_MSR *) &LocalMsrRegister)->NbVid);
399 if (PminVidCode > NbVid) {
405 LocalPciAddress.AddressValue = PciAddress->AddressValue;
406 LocalPciAddress.Address.Function = FUNC_3;
407 LocalPciAddress.Address.Register = CPTC2_REG;
408 LibAmdPciRead (AccessWidth32, LocalPciAddress, &LocalPciRegister, StdHeader);
409 AltVidCode = (UINT8) (((CLK_PWR_TIMING_CTRL2_REGISTER *) &LocalPciRegister)->AltVid);
411 return (F10GetSlamTimeEncoding (PminVidCode, AltVidCode, CpuEarlyParams, AltvidSlamTime, StdHeader));
415 /*---------------------------------------------------------------------------------------*/
417 * Sets up PSI_L operation.
419 * This function implements the LowPowerThreshold parameter.
421 * @param[in] FamilySpecificServices The current Family Specific Services.
422 * @param[in] CpuEarlyParams Contains VrmLowPowerThreshold parameter.
423 * @param[in] PciAddress PCI address of the executing core's config space.
424 * @param[in] StdHeader Config handle for library and services.
429 F10PmVrmLowPowerModeEnable (
430 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
431 IN AMD_CPU_EARLY_PARAMS *CpuEarlyParams,
432 IN PCI_ADDR PciAddress,
433 IN AMD_CONFIG_PARAMS *StdHeader
437 UINT32 PstateCurrent;
438 UINT32 NextPstateCurrent;
447 if (CpuEarlyParams->PlatformConfig.VrmProperties[CoreVrm].LowPowerThreshold != 0) {
449 PreviousVID = 0x7F; // Initialize to invalid zero volt VID code
451 PciAddress.Address.Function = FUNC_3;
452 PciAddress.Address.Register = CPTC2_REG;
453 LibAmdPciRead (AccessWidth32, PciAddress, &HwPsMaxVal, StdHeader);
455 for (Pstate = 0; Pstate <= (UINT32) ((CLK_PWR_TIMING_CTRL2_REGISTER *) &HwPsMaxVal)->PstateMaxVal; Pstate++) {
456 if (FamilySpecificServices->GetProcIddMax (FamilySpecificServices, (UINT8) Pstate, &PstateCurrent, StdHeader)) {
457 LibAmdMsrRead ((UINT32) (Pstate + PS_REG_BASE), &PstateMsr, StdHeader);
458 PstateVID = (UINT32) (((PSTATE_MSR *) &PstateMsr)->CpuVid);
459 if ((Pstate + 1) > (UINT32) ((CLK_PWR_TIMING_CTRL2_REGISTER *) &HwPsMaxVal)->PstateMaxVal) {
460 NextPstateCurrent = 0;
461 } else if (FamilySpecificServices->GetProcIddMax (FamilySpecificServices, (UINT8) (Pstate + 1), &NextPstateCurrent, StdHeader)) {
462 NextPstateCurrent = CpuEarlyParams->PlatformConfig.VrmProperties[CoreVrm].InrushCurrentLimit + NextPstateCurrent;
464 if ((PstateCurrent <= CpuEarlyParams->PlatformConfig.VrmProperties[CoreVrm].LowPowerThreshold) && (NextPstateCurrent <= CpuEarlyParams->PlatformConfig.VrmProperties[CoreVrm].LowPowerThreshold) && (PstateVID != PreviousVID)) {
468 PreviousVID = PstateVID;
472 PciAddress.Address.Function = FUNC_3;
473 PciAddress.Address.Register = PW_CTL_MISC_REG;
474 AndMask = 0xFFFFFFFF;
476 ((POWER_CTRL_MISC_REGISTER *) &AndMask)->PsiVid = 0;
478 ((POWER_CTRL_MISC_REGISTER *) &OrMask)->PsiVid = PstateVID;
479 ((POWER_CTRL_MISC_REGISTER *) &OrMask)->PsiVidEn = 1;
481 ((POWER_CTRL_MISC_REGISTER *) &AndMask)->PsiVidEn = 0;
483 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader);