AMD Agesa macro expansion fix
[coreboot.git] / src / vendorcode / amd / agesa / f12 / Proc / CPU / cpuPowerMgmtSingleSocket.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD CPU Power Management Single Socket Functions.
6  *
7  * Contains code for doing power management for single socket CPU
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU
12  * @e \$Revision: 48937 $   @e \$Date: 2011-03-15 03:37:15 +0800 (Tue, 15 Mar 2011) $
13  *
14  */
15 /*
16  ******************************************************************************
17  *
18  * Copyright (c) 2011, Advanced Micro Devices, Inc.
19  * All rights reserved.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions are met:
23  *     * Redistributions of source code must retain the above copyright
24  *       notice, this list of conditions and the following disclaimer.
25  *     * Redistributions in binary form must reproduce the above copyright
26  *       notice, this list of conditions and the following disclaimer in the
27  *       documentation and/or other materials provided with the distribution.
28  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
29  *       its contributors may be used to endorse or promote products derived
30  *       from this software without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
36  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  ******************************************************************************
43  */
44
45 /*----------------------------------------------------------------------------------------
46  *                             M O D U L E S    U S E D
47  *----------------------------------------------------------------------------------------
48  */
49
50 #include "AGESA.h"
51 #include "amdlib.h"
52 #include "GeneralServices.h"
53 #include "cpuRegisters.h"
54 #include "cpuApicUtilities.h"
55 #include "cpuFamilyTranslation.h"
56 #include "cpuPowerMgmtSystemTables.h"
57 #include "cpuPowerMgmtSingleSocket.h"
58 #include "Filecode.h"
59 CODE_GROUP (G1_PEICC)
60 RDATA_GROUP (G1_PEICC)
61
62 #define FILECODE PROC_CPU_CPUPOWERMGMTSINGLESOCKET_FILECODE
63 /*----------------------------------------------------------------------------------------
64  *                   D E F I N I T I O N S    A N D    M A C R O S
65  *----------------------------------------------------------------------------------------
66  */
67
68 /*----------------------------------------------------------------------------------------
69  *                  T Y P E D E F S     A N D     S T R U C T U R E S
70  *----------------------------------------------------------------------------------------
71  */
72
73 /*----------------------------------------------------------------------------------------
74  *           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
75  *----------------------------------------------------------------------------------------
76  */
77
78 /*----------------------------------------------------------------------------------------
79  *                          E X P O R T E D    F U N C T I O N S
80  *----------------------------------------------------------------------------------------
81  */
82
83 /*---------------------------------------------------------------------------------------*/
84 /**
85  * Single socket BSC call to start all system core 0s to perform a standard AP_TASK.
86  *
87  * This function will simply invoke the task on the executing core.  This must be
88  * run by the system BSC only.
89  *
90  * @param[in]  TaskPtr           Function descriptor
91  * @param[in]  StdHeader         Config handle for library and services
92  * @param[in]  ConfigParams      AMD entry point's CPU parameter structure
93  *
94  */
95 VOID
96 RunCodeOnAllSystemCore0sSingle (
97   IN       AP_TASK *TaskPtr,
98   IN       AMD_CONFIG_PARAMS *StdHeader,
99   IN       VOID *ConfigParams
100   )
101 {
102   ApUtilTaskOnExecutingCore (TaskPtr, StdHeader, ConfigParams);
103 }
104
105
106 /*---------------------------------------------------------------------------------------*/
107 /**
108  * Single socket BSC call to determine the maximum number of steps that any single
109  * processor needs to execute.
110  *
111  * This function simply returns the number of steps that the BSC needs.
112  *
113  * @param[out] NumSystemSteps    Maximum number of system steps required
114  * @param[in]  StdHeader         Config handle for library and services
115  *
116  */
117 VOID
118 GetNumberOfSystemPmStepsPtrSingle (
119      OUT   UINT8 *NumSystemSteps,
120   IN       AMD_CONFIG_PARAMS   *StdHeader
121   )
122 {
123   SYS_PM_TBL_STEP *Ignored;
124   CPU_SPECIFIC_SERVICES *FamilySpecificServices;
125
126   GetCpuServicesOfCurrentCore ((const CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader);
127   FamilySpecificServices->GetSysPmTableStruct (FamilySpecificServices, (const VOID **)&Ignored, NumSystemSteps, StdHeader);
128 }
129
130
131 /*---------------------------------------------------------------------------------------*/
132 /**
133  * Single socket call to determine the frequency that the northbridges must run.
134  *
135  * This function simply returns the executing core's NB frequency, and that all
136  * NB frequencies are equivalent.
137  *
138  * @param[in]  NbPstate                    NB P-state number to check (0 = fastest)
139  * @param[in]  PlatformConfig              Platform profile/build option config structure.
140  * @param[out] SystemNbCofNumerator        NB frequency numerator for the system in MHz
141  * @param[out] SystemNbCofDenominator      NB frequency denominator for the system
142  * @param[out] SystemNbCofsMatch           Whether or not all NB frequencies are equivalent
143  * @param[out] NbPstateIsEnabledOnAllCPUs  Whether or not NbPstate is valid on all CPUs
144  * @param[in]  StdHeader                   Config handle for library and services
145  *
146  * @retval     TRUE                        At least one processor has NbPstate enabled.
147  * @retval     FALSE                       NbPstate is disabled on all CPUs
148  *
149  */
150 BOOLEAN
151 GetSystemNbCofSingle (
152   IN       UINT32 NbPstate,
153   IN       PLATFORM_CONFIGURATION *PlatformConfig,
154      OUT   UINT32 *SystemNbCofNumerator,
155      OUT   UINT32 *SystemNbCofDenominator,
156      OUT   BOOLEAN *SystemNbCofsMatch,
157      OUT   BOOLEAN *NbPstateIsEnabledOnAllCPUs,
158   IN       AMD_CONFIG_PARAMS *StdHeader
159   )
160 {
161   UINT32 Ignored;
162   PCI_ADDR PciAddress;
163   CPU_SPECIFIC_SERVICES *FamilySpecificServices;
164
165   PciAddress.AddressValue = MAKE_SBDFO (0, 0, 24, 0, 0);
166   *SystemNbCofsMatch = TRUE;
167   GetCpuServicesOfCurrentCore ((const CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader);
168   *NbPstateIsEnabledOnAllCPUs = FamilySpecificServices->GetNbPstateInfo (FamilySpecificServices,
169                                                                          PlatformConfig,
170                                                                          &PciAddress,
171                                                                          NbPstate,
172                                                                          SystemNbCofNumerator,
173                                                                          SystemNbCofDenominator,
174                                                                          &Ignored,
175                                                                          StdHeader);
176   return *NbPstateIsEnabledOnAllCPUs;
177 }
178
179
180 /*---------------------------------------------------------------------------------------*/
181 /**
182  * Single socket call to determine if the BIOS is responsible for updating the
183  * northbridge operating frequency and voltage.
184  *
185  * This function simply returns whether or not the executing core needs NB COF
186  * VID programming.
187  *
188  * @param[in]  StdHeader              Config handle for library and services
189  *
190  * @retval     TRUE    BIOS needs to set up NB frequency and voltage
191  * @retval     FALSE   BIOS does not need to set up NB frequency and voltage
192  *
193  */
194 BOOLEAN
195 GetSystemNbCofVidUpdateSingle (
196   IN       AMD_CONFIG_PARAMS *StdHeader
197   )
198 {
199   BOOLEAN   Ignored;
200   PCI_ADDR PciAddress;
201   CPU_SPECIFIC_SERVICES *FamilySpecificServices;
202
203   PciAddress.AddressValue = MAKE_SBDFO (0, 0, 24, 0, 0);
204   GetCpuServicesOfCurrentCore ((const CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader);
205   return (FamilySpecificServices->IsNbCofInitNeeded (FamilySpecificServices, &PciAddress, &Ignored, StdHeader));
206 }
207
208
209 /*---------------------------------------------------------------------------------------*/
210 /**
211  * Single socket call to determine the most severe AGESA_STATUS return value after
212  * processing the power management initialization tables.
213  *
214  * This function searches the event log for the most severe error and returns
215  * the status code.  This function must be called by the BSC only.
216  *
217  * @param[in]  StdHeader         Config handle for library and services
218  *
219  * @return     The most severe error code from power management init
220  *
221  */
222 AGESA_STATUS
223 GetEarlyPmErrorsSingle (
224   IN       AMD_CONFIG_PARAMS *StdHeader
225   )
226 {
227   UINT16       i;
228   AGESA_EVENT  EventLogEntry;
229   AGESA_STATUS ReturnCode;
230
231   ASSERT (IsBsp (StdHeader, &ReturnCode));
232
233   ReturnCode = AGESA_SUCCESS;
234   for (i = 0; PeekEventLog (&EventLogEntry, i, StdHeader); i++) {
235     if ((EventLogEntry.EventInfo & CPU_EVENT_PM_EVENT_MASK) == CPU_EVENT_PM_EVENT_CLASS) {
236       if (EventLogEntry.EventClass > ReturnCode) {
237         ReturnCode = EventLogEntry.EventClass;
238       }
239     }
240   }
241
242   return (ReturnCode);
243 }
244
245 /**
246  * Single socket call to loop through all Nb Pstates, comparing the NB frequencies
247  * to determine the slowest in the system. This routine also returns the NB P0 frequency.
248  *
249  * @param[in]  PlatformConfig      Platform profile/build option config structure.
250  * @param[out] MinSysNbFreq        NB frequency numerator for the system in MHz
251  * @param[out] MinP0NbFreq         NB frequency numerator for P0 in MHz
252  * @param[in]  StdHeader           Config handle for library and services
253  */
254 VOID
255 GetMinNbCofSingle (
256   IN       PLATFORM_CONFIGURATION *PlatformConfig,
257      OUT   UINT32                 *MinSysNbFreq,
258      OUT   UINT32                 *MinP0NbFreq,
259   IN       AMD_CONFIG_PARAMS      *StdHeader
260   )
261 {
262   PCI_ADDR              PciAddress;
263   CPU_SPECIFIC_SERVICES *FamilySpecificServices;
264
265   PciAddress.AddressValue = MAKE_SBDFO (0, 0, 24, 0, 0);
266   GetCpuServicesOfCurrentCore ((const CPU_SPECIFIC_SERVICES **) &FamilySpecificServices, StdHeader);
267   FamilySpecificServices->GetMinMaxNbFrequency (FamilySpecificServices,
268                                              PlatformConfig,
269                                              &PciAddress,
270                                              MinSysNbFreq,
271                                              MinP0NbFreq,
272                                              StdHeader);
273 }