5 * AMD Family_10 after warm reset sequence
7 * Performs the "CPU Core Minimum P-State Transition Sequence After Warm Reset"
8 * as described in the BKDG.
10 * @xrefitem bom "File Content Label" "Release Content"
12 * @e sub-project: CPU/Family/0x10
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 *----------------------------------------------------------------------------------------
53 #include "cpuF10PowerMgmt.h"
54 #include "cpuRegisters.h"
55 #include "cpuApicUtilities.h"
56 #include "cpuFamilyTranslation.h"
57 #include "cpuF10Utilities.h"
58 #include "cpuF10EarlyInit.h"
59 #include "GeneralServices.h"
60 #include "cpuServices.h"
61 #include "OptionMultiSocket.h"
66 #define FILECODE PROC_CPU_FAMILY_0X10_CPUF10EARLYINIT_FILECODE
68 /*----------------------------------------------------------------------------------------
69 * D E F I N I T I O N S A N D M A C R O S
70 *----------------------------------------------------------------------------------------
73 /*----------------------------------------------------------------------------------------
74 * T Y P E D E F S A N D S T R U C T U R E S
75 *----------------------------------------------------------------------------------------
77 /// Enum for handling code branching while transitioning to the
78 /// minimum P-state after a warm reset
80 EXIT_SEQUENCE, ///< Exit the sequence
81 STEP7, ///< Go to step 7
82 STEP17, ///< Go to step 17
83 STEP20 ///< Go to step 20
86 /*----------------------------------------------------------------------------------------
87 * 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
88 *----------------------------------------------------------------------------------------
92 F10PmVoltageAlignmentAfterResetCore (
93 IN AMD_CONFIG_PARAMS *StdHeader
99 IN AMD_CONFIG_PARAMS *StdHeader
104 WaitForCpuFidAndDidToMatch (
105 IN UINT32 PstateNumber,
106 IN AMD_CONFIG_PARAMS *StdHeader
109 /*----------------------------------------------------------------------------------------
110 * E X P O R T E D F U N C T I O N S
111 *----------------------------------------------------------------------------------------
113 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
114 /*---------------------------------------------------------------------------------------*/
116 * Family 10h core 0 entry point for performing the necessary steps after
117 * a warm reset has occurred.
119 * The steps are as follows:
120 * 1. Modify F3xDC[PstateMaxVal] to reflect the lowest performance P-state
121 * supported, as indicated in MSRC001_00[68:64][PstateEn]
122 * 2. If MSRC001_0071[CurNbDid] = 0, set MSRC001_001F[GfxNbPstateDis]
123 * 3. If MSRC001_0071[CurPstate] != F3xDC[PstateMaxVal], go to step 20
124 * 4. If F3xDC[PstateMaxVal] = 0 or F3xDC[PstateMaxVal] != 4, go to step 7
125 * 5. If MSRC001_0061[CurPstateLimit] <= F3xDC[PstateMaxVal]-1, go to step 17
126 * 6. Exit the sequence
127 * 7. Copy the P-state register pointed to by F3xDC[PstateMaxVal] to the P-state
128 * register pointed to by F3xDC[PstateMaxVal]+1
129 * 8. Write F3xDC[PstateMaxVal]+1 to F3xDC[PstateMaxVal]
130 * 9. Write (the new) F3xDC[PstateMaxVal] to MSRC001_0062[PstateCmd]
131 * 10. Wait for MSRC001_0071[CurCpuFid/CurCpuDid] = CpuFid/CpuDid from the P-state
132 * register pointed to by (the new) F3xDC[PstateMaxVal]
133 * 11. Copy (the new) F3xDC[PstateMaxVal]-1 to MSRC001_0062[PstateCmd]
134 * 12. Wait for MSRC001_0071[CurCpuFid/CurCpuDid] = CpuFid/CpuDid from the P-state
135 * register pointed to by (the new) F3xDC[PstateMaxVal]-1
136 * 13. If MSRC001_0071[CurNbDid] = 1, set MSRC001_001F[GfxNbPstateDis]
137 * 14. If required, transition the NB COF and VID to the NbDid and NbVid from the
138 * P-state register pointed to by MSRC001_0061[CurPstateLimit] using the NB COF
139 * and VID transition sequence after a warm reset
140 * 15. Write MSRC001_00[68:64][PstateEn]=0 for the P-state pointed to by F3xDC[PstateMaxVal]
141 * 16. Write (the new) F3xDC[PstateMaxVal]-1 to F3xDC[PstateMaxVal] and exit the sequence
142 * 17. Copy MSRC001_0061[PstateMaxVal] - 1 to MSRC001_0062[PstateCmd]
143 * 18. Wait for MSRC001_0071[CurCpuFid/CurCpuDid] = CpuFid/CpuDid from the P-state
144 * register pointed to by F3xDC[PstateMaxVal]-1
145 * 19. If MSRC001_0071[CurNbDid] = 0, set MSRC001_001F[GfxNbPstateDis]
146 * 20. Copy MSRC001_0061[PstateMaxVal] to MSRC001_0062[PstateCmd]
147 * 21. Wait for MSRC001_0071[CurCpuFid/CurCpuDid] = CpuFid/CpuDid from the P-state
148 * register pointed to by F3xDC[PstateMaxVal]
149 * 22. If MSRC001_0071[CurNbDid] = 1, set MSRC001_001F[GfxNbPstateDis]
150 * 23. Issue an LDTSTOP assertion in the IO hub and exit sequence
151 * 24. If required, transition the NB COF and VID to the NbDid and NbVid from the
152 * P-state register pointed to by F3xDC[PstateMaxVal] using the NB COF and VID
153 * transition sequence after a warm reset
155 * @param[in] FamilySpecificServices The current Family Specific Services.
156 * @param[in] CpuEarlyParamsPtr Service parameters
157 * @param[in] StdHeader Config handle for library and services.
162 IN CPU_SPECIFIC_SERVICES *FamilySpecificServices,
163 IN AMD_CPU_EARLY_PARAMS *CpuEarlyParamsPtr,
164 IN AMD_CONFIG_PARAMS *StdHeader
173 UINT64 LocalMsrRegister;
174 UINT64 CurrentStatus;
179 GetCurrentCore (&Core, StdHeader);
182 // Core P-State Voltage Alignment After Warm Reset
183 CpbNum = F10GetNumberOfBoostedPstatesOnCore (StdHeader);
185 // Step 1 Write MSRC001_0063[ CurPstate] to MSRC001_0062[ PstateCmd] on every core in the processor.
186 TaskPtr.FuncAddress.PfApTask = F10PmVoltageAlignmentAfterResetCore;
187 TaskPtr.DataTransfer.DataSizeInDwords = 0;
188 TaskPtr.ExeFlags = WAIT_FOR_CORE;
189 ApUtilRunCodeOnAllLocalCoresAtEarly (&TaskPtr, StdHeader, CpuEarlyParamsPtr);
191 // Step 2 Wait for MSRC001_0071[ CurCpuVid] >= [CpuVid] from MSRC001_00[ 68:64] indexed by 4x15C[ NumBoost States]
192 // Get target P-state indexed by F4x15C[NumBoostStates]
193 LibAmdMsrRead ((MSR_PSTATE_0 + CpbNum), &TargetPsMsr, StdHeader);
195 LibAmdMsrRead (MSR_COFVID_STS, &CurrentStatus, StdHeader);
196 } while (((COFVID_STS_MSR *) &CurrentStatus)->CurCpuVid < ((PSTATE_MSR *) &TargetPsMsr)->CpuVid);
199 // Core Minimum P-State Transition Sequence After Warm Reset
200 // Step 1 Modify F3xDC[PstateMaxVal] to reflect the lowest performance
201 // P-state supported, as indicated in MSRC001_00[68:64][PstateEn]
202 for (MsrAddr = PS_MAX_REG; MsrAddr > PS_REG_BASE; --MsrAddr) {
203 LibAmdMsrRead (MsrAddr, &LocalMsrRegister, StdHeader);
204 if (((PSTATE_MSR *) &LocalMsrRegister)->PsEnable == 1) {
208 PsMaxVal = MsrAddr - PS_REG_BASE;
209 PciAddress.Address.Function = FUNC_3;
210 PciAddress.Address.Register = CPTC2_REG;
211 AndMask = 0xFFFFFFFF;
213 ((CLK_PWR_TIMING_CTRL2_REGISTER *) &AndMask)->PstateMaxVal = 0;
214 ((CLK_PWR_TIMING_CTRL2_REGISTER *) &OrMask)->PstateMaxVal = PsMaxVal;
215 OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader);
217 // Launch each local core to perform the remaining steps.
218 TaskPtr.FuncAddress.PfApTask = F10PmAfterResetCore;
219 TaskPtr.DataTransfer.DataSizeInDwords = 0;
220 TaskPtr.ExeFlags = WAIT_FOR_CORE;
221 ApUtilRunCodeOnAllLocalCoresAtEarly (&TaskPtr, StdHeader, CpuEarlyParamsPtr);
225 /*---------------------------------------------------------------------------------------
226 * L O C A L F U N C T I O N S
227 *---------------------------------------------------------------------------------------
230 /*---------------------------------------------------------------------------------------*/
232 * Support routine for F10PmAfterReset to perform MSR initialization on all
233 * cores of a family 10h socket.
235 * This function implements steps 2 - 24 on each core.
237 * @param[in] StdHeader Config handle for library and services.
242 F10PmAfterResetCore (
243 IN AMD_CONFIG_PARAMS *StdHeader
248 UINT32 LocalPciRegister;
249 UINT64 LocalMsrRegister;
251 UINT64 CurrentLimitMsr;
254 CPU_LOGICAL_ID LogicalId;
255 CPU_SPECIFIC_SERVICES *FamilySpecificServices;
257 // Step 2 If MSR C001_0071[CurNbDid] = 0, set MSR C001_001F[GfxNbPstateDis]
258 GetLogicalIdOfCurrentCore (&LogicalId, StdHeader);
259 GetCpuServicesFromLogicalId (&LogicalId, (const CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader);
260 if ((LogicalId.Revision & (AMD_F10_C3 | AMD_F10_DA_C2)) != 0) {
261 LibAmdMsrRead (MSR_COFVID_STS, &LocalMsrRegister, StdHeader);
262 if (((COFVID_STS_MSR *) &LocalMsrRegister)->CurNbDid == 0) {
263 LibAmdMsrRead (NB_CFG, &LocalMsrRegister, StdHeader);
264 LocalMsrRegister |= BIT62;
265 LibAmdMsrWrite (NB_CFG, &LocalMsrRegister, StdHeader);
269 GoToStep = EXIT_SEQUENCE;
271 OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader);
272 PciAddress.Address.Function = FUNC_3;
273 PciAddress.Address.Register = CPTC2_REG;
274 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
275 PsMaxVal = ((CLK_PWR_TIMING_CTRL2_REGISTER *) &LocalPciRegister)->PstateMaxVal;
277 LibAmdMsrRead (MSR_PSTATE_CURRENT_LIMIT, &CurrentLimitMsr, StdHeader);
278 SwPsMaxVal = (UINT32) (((PSTATE_CURLIM_MSR *) &CurrentLimitMsr)->PstateMaxVal);
280 // Step 3 If MSRC001_0071[CurPstate] != F3xDC[PstateMaxVal], go to step 20
281 LibAmdMsrRead (MSR_COFVID_STS, &LocalMsrRegister, StdHeader);
282 if (((COFVID_STS_MSR *) &LocalMsrRegister)->CurPstate != PsMaxVal) {
285 // Step 4 If F3xDC[PstateMaxVal] = 0 || F3xDC[PstateMaxVal] != 4, go to step 7
286 if ((PsMaxVal == 0) || (PsMaxVal != 4)) {
289 // Step 5 If MSRC001_0061[CurPstateLimit] <= F3xDC[PstateMaxVal]-1, go to step 17
290 if (((PSTATE_CURLIM_MSR *) &CurrentLimitMsr)->CurPstateLimit <= (PsMaxVal - 1)) {
298 // Step 6 Exit the sequence
301 // Workaround for S3 ----Save the value of [The PState[4:0] Registers] MSRC001_00[68:64]
302 // pointed to by F3xDC[PstateMaxVal] + 1
303 LibAmdMsrRead ((MSR_PSTATE_0 + (PsMaxVal + 1)), &SavedMsr, StdHeader);
305 // Step 7 Copy the P-state register pointed to by F3xDC[PstateMaxVal] to the P-state
306 // register pointed to by F3xDC[PstateMaxVal]+1
307 LibAmdMsrRead ((MSR_PSTATE_0 + PsMaxVal), &LocalMsrRegister, StdHeader);
308 LibAmdMsrWrite ((MSR_PSTATE_0 + (PsMaxVal + 1)), &LocalMsrRegister, StdHeader);
310 // Step 8 Write F3xDC[PstateMaxVal]+1 to F3xDC[PstateMaxVal]
311 PciAddress.Address.Function = FUNC_3;
312 PciAddress.Address.Register = CPTC2_REG;
313 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
314 ((CLK_PWR_TIMING_CTRL2_REGISTER *) &LocalPciRegister)->PstateMaxVal = PsMaxVal + 1;
315 LibAmdPciWrite (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
317 // Step 9 Write (the new) F3xDC[PstateMaxVal] to MSRC001_0062[PstateCmd]
318 FamilySpecificServices->TransitionPstate (FamilySpecificServices, (UINT8) (PsMaxVal + 1), (BOOLEAN) FALSE, StdHeader);
320 // Step 10 Wait for MSRC001_0071[CurCpuFid/CurCpuDid] = CpuFid/CpuDid from the P-state
321 // register pointed to by (the new) F3xDC[PstateMaxVal]
322 WaitForCpuFidAndDidToMatch ((UINT32) (PsMaxVal + 1), StdHeader);
324 // Step 11 Copy (the new) F3xDC[PstateMaxVal]-1 to MSRC001_0062[PstateCmd]
325 FamilySpecificServices->TransitionPstate (FamilySpecificServices, (UINT8) PsMaxVal, (BOOLEAN) FALSE, StdHeader);
327 // Step 12 Wait for MSRC001_0071[CurCpuFid/CurCpuDid] = CpuFid/CpuDid from the P-state
328 // register pointed to by (the new) F3xDC[PstateMaxVal]-1
329 WaitForCpuFidAndDidToMatch (PsMaxVal, StdHeader);
331 // Step 13 If MSRC001_0071[CurNbDid] = 1, set MSRC001_001F[GfxNbPstateDis]
332 if ((LogicalId.Revision & (AMD_F10_C3 | AMD_F10_DA_C2)) != 0) {
333 LibAmdMsrRead (MSR_COFVID_STS, &LocalMsrRegister, StdHeader);
334 if (((COFVID_STS_MSR *) &LocalMsrRegister)->CurNbDid == 1) {
335 LibAmdMsrRead (NB_CFG, &LocalMsrRegister, StdHeader);
336 LocalMsrRegister |= BIT62;
337 LibAmdMsrWrite (NB_CFG, &LocalMsrRegister, StdHeader);
341 // Step 14 If required, transition the NB COF and VID to the NbDid and NbVid from the
342 // P-state register pointed to by MSRC001_0061[CurPstateLimit] using the NB COF
343 // and VID transition sequence after a warm reset
345 // Step 15 Write 0 to PstateEn of the P-state register pointed to by (the new) F3xDC[PstateMaxVal]
346 // Workaround for S3----Restore the value of [The PState[4:0] Registers] MSRC001_00[68:64]
347 // pointed to by F3xDC[PstateMaxVal] + 1
348 ((PSTATE_MSR *) &SavedMsr)->PsEnable = 0;
349 LibAmdMsrWrite ((MSR_PSTATE_0 + (PsMaxVal + 1)), &SavedMsr, StdHeader);
351 // Step 16 Write (the new) F3xDC[PstateMaxVal]-1 to F3xDC[PstateMaxVal]
352 LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
353 ((CLK_PWR_TIMING_CTRL2_REGISTER *) &LocalPciRegister)->PstateMaxVal = PsMaxVal;
354 LibAmdPciWrite (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
357 // Step 17 Copy MSRC001_0061[PstateMaxVal]-1 to MSRC001_0062[PstateCmd]
358 FamilySpecificServices->TransitionPstate (FamilySpecificServices, (UINT8) (SwPsMaxVal - 1), (BOOLEAN) FALSE, StdHeader);
360 // Step 18 Wait for MSRC001_0071[CurCpuFid/CurCpuDid] = CpuFid/CpuDid from the P-state
361 // register pointed to by F3xDC[PstateMaxVal]-1
362 WaitForCpuFidAndDidToMatch ((UINT32) (PsMaxVal - 1), StdHeader);
364 // Step 19 If MSR C001_0071[CurNbDid] = 0, set MSR C001_001F[GfxNbPstateDis]
365 if ((LogicalId.Revision & (AMD_F10_C3 | AMD_F10_DA_C2)) != 0) {
366 LibAmdMsrRead (MSR_COFVID_STS, &LocalMsrRegister, StdHeader);
367 if (((COFVID_STS_MSR *) &LocalMsrRegister)->CurNbDid == 0) {
368 LibAmdMsrRead (NB_CFG, &LocalMsrRegister, StdHeader);
369 LocalMsrRegister |= BIT62;
370 LibAmdMsrWrite (NB_CFG, &LocalMsrRegister, StdHeader);
374 // Fall through from step 19 to step 20
376 // Step 20 Copy MSRC001_0061[PstateMaxVal] to MSRC001_0062[PstateCmd]
377 FamilySpecificServices->TransitionPstate (FamilySpecificServices, (UINT8) SwPsMaxVal, (BOOLEAN) FALSE, StdHeader);
379 // Step 21 Wait for MSRC001_0071[CurCpuFid/CurCpuDid] = CpuFid/CpuDid from the P-state
380 // register pointed to by F3xDC[PstateMaxVal]
381 WaitForCpuFidAndDidToMatch (PsMaxVal, StdHeader);
383 // Step 22 If MSR C001_0071[CurNbDid] = 1, set MSR C001_001F[GfxNbPstateDis] and exit
385 if ((LogicalId.Revision & (AMD_F10_C3 | AMD_F10_DA_C2)) != 0) {
386 LibAmdMsrRead (MSR_COFVID_STS, &LocalMsrRegister, StdHeader);
387 if (((COFVID_STS_MSR *) &LocalMsrRegister)->CurNbDid == 1) {
388 LibAmdMsrRead (NB_CFG, &LocalMsrRegister, StdHeader);
389 LocalMsrRegister |= BIT62;
390 LibAmdMsrWrite (NB_CFG, &LocalMsrRegister, StdHeader);
395 // Step 23 Issue an LDTSTOP and exit the sequence
397 // Step 24 If required, transition the NB COF and VID to the NbDid and NbVid from the
398 // P-state register pointed to by F3xDC[PstateMaxVal] using the NB COF and VID
399 // transition sequence after a warm reset
404 /*---------------------------------------------------------------------------------------*/
406 * Support routine for F10PmAfterResetCore to wait for Cpu FID and DID to
407 * match a specific P-state.
409 * This function implements steps 11, 13, 18, and 20 on each core as needed.
411 * @param[in] PstateNumber P-state settings to match
412 * @param[in] StdHeader Config handle for library and services.
417 WaitForCpuFidAndDidToMatch (
418 IN UINT32 PstateNumber,
419 IN AMD_CONFIG_PARAMS *StdHeader
423 UINT64 CurrentStatus;
425 // Get target P-state settings
426 LibAmdMsrRead ((MSR_PSTATE_0 + PstateNumber), &TargetPsMsr, StdHeader);
428 // Wait for current CPU FID/DID to match target FID/DID
430 LibAmdMsrRead (MSR_COFVID_STS, &CurrentStatus, StdHeader);
431 } while ((((COFVID_STS_MSR *) &CurrentStatus)->CurCpuFid != ((PSTATE_MSR *) &TargetPsMsr)->CpuFid) ||
432 (((COFVID_STS_MSR *) &CurrentStatus)->CurCpuDid != ((PSTATE_MSR *) &TargetPsMsr)->CpuDid));
435 /*---------------------------------------------------------------------------------------*/
437 * Support routine for F10PmAfterReset to Core P-State Voltage Alignment for CPB on all
438 * cores of a family 10h socket.
440 * @param[in] StdHeader Config handle for library and services.
445 F10PmVoltageAlignmentAfterResetCore (
446 IN AMD_CONFIG_PARAMS *StdHeader
449 UINT64 CurrentStatus;
451 LibAmdMsrRead (MSR_PSTATE_STS, &CurrentStatus, StdHeader);
452 LibAmdMsrWrite (MSR_PSTATE_CTL, &CurrentStatus, StdHeader);