AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Family / 0x10 / F10PmNbPstateInit.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD Family_10 NB Pstate Initialization
6  *
7  * Performs the action described in F3x1F0[NbPstate] as
8  * described in the BKDG.
9  *
10  * @xrefitem bom "File Content Label" "Release Content"
11  * @e project:      AGESA
12  * @e sub-project:  CPU/F10
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 "cpuRegisters.h"
54 #include "cpuF10PowerMgmt.h"
55 #include "cpuApicUtilities.h"
56 #include "GeneralServices.h"
57 #include "cpuFamilyTranslation.h"
58 #include "F10PmNbPstateInit.h"
59 #include "OptionMultiSocket.h"
60 #include "Filecode.h"
61 CODE_GROUP (G1_PEICC)
62 RDATA_GROUP (G2_PEI)
63
64 #define FILECODE PROC_CPU_FAMILY_0X10_F10PMNBPSTATEINIT_FILECODE
65
66 /*----------------------------------------------------------------------------------------
67  *                   D E F I N I T I O N S    A N D    M A C R O S
68  *----------------------------------------------------------------------------------------
69  */
70 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
71 /*----------------------------------------------------------------------------------------
72  *                  T Y P E D E F S     A N D     S T R U C T U R E S
73  *----------------------------------------------------------------------------------------
74  */
75 /// Structure used for modifying the P-state
76 /// MSRs on fuse enable CPUs.
77 typedef struct {
78   UINT8   NbVid1;             ///< Destination NB VID code
79   UINT8   NbPstate;           ///< Status of NbVidUpdateAll
80 } NB_PSTATE_INIT;
81
82 /*----------------------------------------------------------------------------------------
83  *           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
84  *----------------------------------------------------------------------------------------
85  */
86 VOID
87 STATIC
88 PmNbPstateInitCore (
89   IN       VOID *NbPstateParams,
90   IN       AMD_CONFIG_PARAMS *StdHeader
91   );
92
93 /*----------------------------------------------------------------------------------------
94  *                          E X P O R T E D    F U N C T I O N S
95  *----------------------------------------------------------------------------------------
96  */
97
98 /*---------------------------------------------------------------------------------------*/
99 /**
100  * Family 10h core 0 entry point for performing the actions described in the
101  * description of F3x1F0[NbPstate].
102  *
103  * If F3x1F0[NbPstate] is non zero, it specifies the highest performance
104  * P-state in which to enable NbDid.  Each core must loop through their
105  * P-state MSRs, enabling NbDid and changing NbVid to a lower voltage.
106  *
107  * @param[in]  FamilySpecificServices  The current Family Specific Services.
108  * @param[in]  CpuEarlyParamsPtr       Service related parameters (unused).
109  * @param[in]  StdHeader               Config handle for library and services.
110  *
111  */
112 VOID
113 F10PmNbPstateInit (
114   IN       CPU_SPECIFIC_SERVICES *FamilySpecificServices,
115   IN       AMD_CPU_EARLY_PARAMS  *CpuEarlyParamsPtr,
116   IN       AMD_CONFIG_PARAMS     *StdHeader
117   )
118 {
119   UINT32         Core;
120   UINT32         LocalPciRegister;
121   AP_TASK        TaskPtr;
122   PCI_ADDR       PciAddress;
123   NB_PSTATE_INIT ApParams;
124
125   if (FamilySpecificServices->IsNbPstateEnabled (FamilySpecificServices, &CpuEarlyParamsPtr->PlatformConfig, StdHeader)) {
126     if (CpuEarlyParamsPtr->PlatformConfig.PlatformProfile.PlatformPowerPolicy == BatteryLife) {
127       OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader);
128       GetCurrentCore (&Core, StdHeader);
129       ASSERT (Core == 0);
130
131       PciAddress.Address.Function = FUNC_3;
132       PciAddress.Address.Register = 0x1F0;
133       LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
134       if ((LocalPciRegister & 0x00070000) != 0) {
135         ApParams.NbPstate = (UINT8) ((LocalPciRegister & 0x00070000) >> 16);
136         ASSERT (ApParams.NbPstate < NM_PS_REG);
137
138         PciAddress.Address.Function = FUNC_4;
139         PciAddress.Address.Register = 0x1F4;
140         LibAmdPciRead (AccessWidth32, PciAddress, &LocalPciRegister, StdHeader);
141         ApParams.NbVid1 = (UINT8) ((LocalPciRegister & 0x00003F80) >> 7);
142
143         TaskPtr.FuncAddress.PfApTaskI = PmNbPstateInitCore;
144         TaskPtr.DataTransfer.DataSizeInDwords = SIZE_IN_DWORDS (NB_PSTATE_INIT);
145         TaskPtr.DataTransfer.DataPtr = &ApParams;
146         TaskPtr.DataTransfer.DataTransferFlags = 0;
147         TaskPtr.ExeFlags = WAIT_FOR_CORE;
148         ApUtilRunCodeOnAllLocalCoresAtEarly (&TaskPtr, StdHeader, CpuEarlyParamsPtr);
149
150       }
151     }
152   }
153 }
154
155
156 /*---------------------------------------------------------------------------------------*/
157 /**
158  * Support routine for F10PmNbPstateInit.
159  *
160  * This function modifies NbVid and NbDid on each core.
161  *
162  * @param[in]  NbPstateParams     Appropriate NbVid1 and NbPstate as determined by core 0.
163  * @param[in]  StdHeader          Config handle for library and services.
164  *
165  */
166 VOID
167 STATIC
168 PmNbPstateInitCore (
169   IN       VOID *NbPstateParams,
170   IN       AMD_CONFIG_PARAMS *StdHeader
171   )
172 {
173   UINT32 MsrAddress;
174   UINT64 LocalMsrRegister;
175
176   for (MsrAddress = (PS_REG_BASE + ((NB_PSTATE_INIT *) NbPstateParams)->NbPstate); MsrAddress <= PS_MAX_REG; MsrAddress++) {
177     LibAmdMsrRead (MsrAddress, &LocalMsrRegister, StdHeader);
178     if (((PSTATE_MSR *) &LocalMsrRegister)->PsEnable == 1) {
179       ((PSTATE_MSR *) &LocalMsrRegister)->NbDid = 1;
180       ((PSTATE_MSR *) &LocalMsrRegister)->NbVid = ((NB_PSTATE_INIT *) NbPstateParams)->NbVid1;
181       LibAmdMsrWrite (MsrAddress, &LocalMsrRegister, StdHeader);
182     }
183   }
184 }
185