AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Family / 0x10 / cpuF10EarlyInit.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD Family_10 after warm reset sequence
6  *
7  * Performs the "CPU Core Minimum P-State Transition Sequence After Warm Reset"
8  * as described in the BKDG.
9  *
10  * @xrefitem bom "File Content Label" "Release Content"
11  * @e project:      AGESA
12  * @e sub-project:  CPU/Family/0x10
13  * @e \$Revision: 56279 $   @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
14  *
15  */
16 /*
17  ******************************************************************************
18  *
19  * Copyright (C) 2012 Advanced Micro Devices, Inc.
20  * All rights reserved.
21  *
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.
32  *
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.
43  *
44  ******************************************************************************
45  */
46
47 /*----------------------------------------------------------------------------------------
48  *                             M O D U L E S    U S E D
49  *----------------------------------------------------------------------------------------
50  */
51 #include "AGESA.h"
52 #include "amdlib.h"
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"
62 #include "Filecode.h"
63 CODE_GROUP (G1_PEICC)
64 RDATA_GROUP (G2_PEI)
65
66 #define FILECODE PROC_CPU_FAMILY_0X10_CPUF10EARLYINIT_FILECODE
67
68 /*----------------------------------------------------------------------------------------
69  *                   D E F I N I T I O N S    A N D    M A C R O S
70  *----------------------------------------------------------------------------------------
71  */
72
73 /*----------------------------------------------------------------------------------------
74  *                  T Y P E D E F S     A N D     S T R U C T U R E S
75  *----------------------------------------------------------------------------------------
76  */
77 /// Enum for handling code branching while transitioning to the
78 /// minimum P-state after a warm reset
79 typedef enum {
80   EXIT_SEQUENCE,        ///< Exit the sequence
81   STEP7,                ///< Go to step 7
82   STEP17,               ///< Go to step 17
83   STEP20                ///< Go to step 20
84 } GO_TO_STEP;
85
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  *----------------------------------------------------------------------------------------
89  */
90 VOID
91 STATIC
92 F10PmVoltageAlignmentAfterResetCore (
93   IN       AMD_CONFIG_PARAMS *StdHeader
94   );
95
96 VOID
97 STATIC
98 F10PmAfterResetCore (
99   IN       AMD_CONFIG_PARAMS *StdHeader
100   );
101
102 VOID
103 STATIC
104 WaitForCpuFidAndDidToMatch (
105   IN       UINT32             PstateNumber,
106   IN       AMD_CONFIG_PARAMS  *StdHeader
107   );
108
109 /*----------------------------------------------------------------------------------------
110  *                          E X P O R T E D    F U N C T I O N S
111  *----------------------------------------------------------------------------------------
112  */
113 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
114 /*---------------------------------------------------------------------------------------*/
115 /**
116  * Family 10h core 0 entry point for performing the necessary steps after
117  * a warm reset has occurred.
118  *
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
154  *
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.
158  *
159  */
160 VOID
161 F10PmAfterReset (
162   IN       CPU_SPECIFIC_SERVICES *FamilySpecificServices,
163   IN       AMD_CPU_EARLY_PARAMS  *CpuEarlyParamsPtr,
164   IN       AMD_CONFIG_PARAMS     *StdHeader
165   )
166 {
167   UINT32    PsMaxVal;
168   UINT32    MsrAddr;
169   UINT32    Core;
170   UINT32    AndMask;
171   UINT32    OrMask;
172   UINT32    CpbNum;
173   UINT64    LocalMsrRegister;
174   UINT64    CurrentStatus;
175   UINT64    TargetPsMsr;
176   PCI_ADDR  PciAddress;
177   AP_TASK   TaskPtr;
178
179   GetCurrentCore (&Core, StdHeader);
180   ASSERT (Core == 0);
181
182   // Core P-State Voltage Alignment After Warm Reset
183   CpbNum = F10GetNumberOfBoostedPstatesOnCore (StdHeader);
184   if (CpbNum == 1) {
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);
190
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);
194     do {
195       LibAmdMsrRead (MSR_COFVID_STS, &CurrentStatus, StdHeader);
196     } while (((COFVID_STS_MSR *) &CurrentStatus)->CurCpuVid < ((PSTATE_MSR *) &TargetPsMsr)->CpuVid);
197   }
198
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) {
205       break;
206     }
207   }
208   PsMaxVal = MsrAddr - PS_REG_BASE;
209   PciAddress.Address.Function = FUNC_3;
210   PciAddress.Address.Register = CPTC2_REG;
211   AndMask = 0xFFFFFFFF;
212   OrMask = 0x00000000;
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);
216
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);
222 }
223
224
225 /*---------------------------------------------------------------------------------------
226  *                          L O C A L    F U N C T I O N S
227  *---------------------------------------------------------------------------------------
228  */
229
230 /*---------------------------------------------------------------------------------------*/
231 /**
232  * Support routine for F10PmAfterReset to perform MSR initialization on all
233  * cores of a family 10h socket.
234  *
235  * This function implements steps 2 - 24 on each core.
236  *
237  * @param[in]  StdHeader          Config handle for library and services.
238  *
239  */
240 VOID
241 STATIC
242 F10PmAfterResetCore (
243   IN       AMD_CONFIG_PARAMS *StdHeader
244   )
245 {
246   UINT32 PsMaxVal;
247   UINT32 SwPsMaxVal;
248   UINT32 LocalPciRegister;
249   UINT64 LocalMsrRegister;
250   UINT64 SavedMsr;
251   UINT64 CurrentLimitMsr;
252   PCI_ADDR PciAddress;
253   GO_TO_STEP GoToStep;
254   CPU_LOGICAL_ID LogicalId;
255   CPU_SPECIFIC_SERVICES *FamilySpecificServices;
256
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);
266     }
267   }
268
269   GoToStep = EXIT_SEQUENCE;
270
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;
276
277   LibAmdMsrRead (MSR_PSTATE_CURRENT_LIMIT, &CurrentLimitMsr, StdHeader);
278   SwPsMaxVal = (UINT32) (((PSTATE_CURLIM_MSR *) &CurrentLimitMsr)->PstateMaxVal);
279
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) {
283     GoToStep = STEP20;
284   } else {
285     // Step 4 If F3xDC[PstateMaxVal] = 0 || F3xDC[PstateMaxVal] != 4, go to step 7
286     if ((PsMaxVal == 0) || (PsMaxVal != 4)) {
287       GoToStep = STEP7;
288     } else {
289       // Step 5 If MSRC001_0061[CurPstateLimit] <= F3xDC[PstateMaxVal]-1, go to step 17
290       if (((PSTATE_CURLIM_MSR *) &CurrentLimitMsr)->CurPstateLimit <= (PsMaxVal - 1)) {
291         GoToStep = STEP17;
292       }
293     }
294   }
295   switch (GoToStep) {
296   default:
297   case EXIT_SEQUENCE:
298     // Step 6 Exit the sequence
299     break;
300   case STEP7:
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);
304
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);
309
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);
316
317     // Step 9 Write (the new) F3xDC[PstateMaxVal] to MSRC001_0062[PstateCmd]
318     FamilySpecificServices->TransitionPstate (FamilySpecificServices, (UINT8) (PsMaxVal + 1), (BOOLEAN) FALSE, StdHeader);
319
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);
323
324     // Step 11 Copy (the new) F3xDC[PstateMaxVal]-1 to MSRC001_0062[PstateCmd]
325     FamilySpecificServices->TransitionPstate (FamilySpecificServices, (UINT8) PsMaxVal, (BOOLEAN) FALSE, StdHeader);
326
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);
330
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);
338       }
339     }
340
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
344
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);
350
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);
355     break;
356   case STEP17:
357     // Step 17 Copy MSRC001_0061[PstateMaxVal]-1 to MSRC001_0062[PstateCmd]
358     FamilySpecificServices->TransitionPstate (FamilySpecificServices, (UINT8) (SwPsMaxVal - 1), (BOOLEAN) FALSE, StdHeader);
359
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);
363
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);
371       }
372     }
373
374     // Fall through from step 19 to step 20
375   case STEP20:
376     // Step 20 Copy MSRC001_0061[PstateMaxVal] to MSRC001_0062[PstateCmd]
377     FamilySpecificServices->TransitionPstate (FamilySpecificServices, (UINT8) SwPsMaxVal, (BOOLEAN) FALSE, StdHeader);
378
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);
382
383     // Step 22 If MSR C001_0071[CurNbDid] = 1, set MSR C001_001F[GfxNbPstateDis] and exit
384     //         the sequence
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);
391         break;
392       }
393     }
394
395     // Step 23 Issue an LDTSTOP and exit the sequence
396
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
400     break;
401   }
402 }
403
404 /*---------------------------------------------------------------------------------------*/
405 /**
406  * Support routine for F10PmAfterResetCore to wait for Cpu FID and DID to
407  * match a specific P-state.
408  *
409  * This function implements steps 11, 13, 18, and 20 on each core as needed.
410  *
411  * @param[in]  PstateNumber       P-state settings to match
412  * @param[in]  StdHeader          Config handle for library and services.
413  *
414  */
415 VOID
416 STATIC
417 WaitForCpuFidAndDidToMatch (
418   IN       UINT32             PstateNumber,
419   IN       AMD_CONFIG_PARAMS  *StdHeader
420   )
421 {
422   UINT64  TargetPsMsr;
423   UINT64  CurrentStatus;
424
425   // Get target P-state settings
426   LibAmdMsrRead ((MSR_PSTATE_0 + PstateNumber), &TargetPsMsr, StdHeader);
427
428   // Wait for current CPU FID/DID to match target FID/DID
429   do {
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));
433 }
434
435 /*---------------------------------------------------------------------------------------*/
436 /**
437  * Support routine for F10PmAfterReset to Core P-State Voltage Alignment for CPB on all
438  * cores of a family 10h socket.
439  *
440  * @param[in]  StdHeader          Config handle for library and services.
441  *
442  */
443 VOID
444 STATIC
445 F10PmVoltageAlignmentAfterResetCore (
446   IN       AMD_CONFIG_PARAMS *StdHeader
447   )
448 {
449   UINT64 CurrentStatus;
450
451   LibAmdMsrRead (MSR_PSTATE_STS, &CurrentStatus, StdHeader);
452   LibAmdMsrWrite (MSR_PSTATE_CTL, &CurrentStatus, StdHeader);
453 }
454