5 * AMD CPU Power Management Multisocket Functions.
7 * Contains code for doing power management for multisocket CPUs
9 * @xrefitem bom "File Content Label" "Release Content"
12 * @e \$Revision: 35136 $ @e \$Date: 2010-07-16 11:29:48 +0800 (Fri, 16 Jul 2010) $
16 *****************************************************************************
18 * Copyright (c) 2011, Advanced Micro Devices, Inc.
19 * All rights reserved.
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.
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.
43 * ***************************************************************************
47 /*----------------------------------------------------------------------------------------
48 * M O D U L E S U S E D
49 *----------------------------------------------------------------------------------------
55 #include "cpuRegisters.h"
56 #include "GeneralServices.h"
57 #include "cpuServices.h"
58 #include "cpuApicUtilities.h"
59 #include "cpuFamilyTranslation.h"
60 #include "cpuPowerMgmtSystemTables.h"
61 #include "cpuPowerMgmtMultiSocket.h"
62 #include "GeneralServices.h"
65 RDATA_GROUP (G1_PEICC)
67 #define FILECODE PROC_CPU_CPUPOWERMGMTMULTISOCKET_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 *----------------------------------------------------------------------------------------
78 /*----------------------------------------------------------------------------------------
79 * 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
80 *----------------------------------------------------------------------------------------
85 IN OUT VOID *EventLogEntryPtr,
86 IN AMD_CONFIG_PARAMS *StdHeader
90 GetEarlyPmErrorsMulti (
91 IN AMD_CONFIG_PARAMS *StdHeader
94 /*----------------------------------------------------------------------------------------
95 * E X P O R T E D F U N C T I O N S
96 *----------------------------------------------------------------------------------------
99 /*---------------------------------------------------------------------------------------*/
101 * Multisocket BSC call to start all system core 0s to perform a standard AP_TASK.
103 * This function loops through all possible socket locations, starting core 0 of
104 * each populated socket to perform the passed in AP_TASK. After starting all
105 * other core 0s, the BSC will perform the AP_TASK as well. This must be run by
106 * the system BSC only.
108 * @param[in] TaskPtr Function descriptor
109 * @param[in] StdHeader Config handle for library and services
110 * @param[in] ConfigParams AMD entry point's CPU parameter structure
114 RunCodeOnAllSystemCore0sMulti (
116 IN AMD_CONFIG_PARAMS *StdHeader,
117 IN VOID *ConfigParams
124 UINT32 NumberOfSockets;
125 AGESA_STATUS DummyStatus;
127 ASSERT (IsBsp (StdHeader, &DummyStatus));
129 NumberOfSockets = GetPlatformNumberOfSockets ();
131 IdentifyCore (StdHeader, &BscSocket, &BscModule, &BscCoreNum, &DummyStatus);
133 for (Socket = 0; Socket < NumberOfSockets; Socket++) {
134 if (Socket != BscSocket) {
135 if (IsProcessorPresent (Socket, StdHeader)) {
136 ApUtilRunCodeOnSocketCore (Socket, 0, TaskPtr, StdHeader);
140 ApUtilTaskOnExecutingCore (TaskPtr, StdHeader, ConfigParams);
144 /*---------------------------------------------------------------------------------------*/
146 * Multisocket BSC call to determine the maximum number of steps that any single
147 * processor needs to execute.
149 * This function loops through all possible socket locations, gathering the number
150 * of power management steps each populated socket requires, and returns the
153 * @param[out] NumSystemSteps Maximum number of system steps required
154 * @param[in] StdHeader Config handle for library and services
158 GetNumberOfSystemPmStepsPtrMulti (
159 OUT UINT8 *NumSystemSteps,
160 IN AMD_CONFIG_PARAMS *StdHeader
164 UINT32 NumberOfSockets;
166 SYS_PM_TBL_STEP *Ignored;
167 CPU_SPECIFIC_SERVICES *FamilySpecificServices;
169 NumberOfSockets = GetPlatformNumberOfSockets ();
172 for (Socket = 0; Socket < NumberOfSockets; Socket++) {
173 if (IsProcessorPresent (Socket, StdHeader)) {
174 GetCpuServicesOfSocket (Socket, (const CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader);
175 FamilySpecificServices->GetSysPmTableStruct (FamilySpecificServices, (const VOID **)&Ignored, &NumberOfSteps, StdHeader);
176 if (NumberOfSteps > *NumSystemSteps) {
177 *NumSystemSteps = NumberOfSteps;
184 /*---------------------------------------------------------------------------------------*/
186 * Multisocket call to determine the frequency that the northbridges must run.
188 * This function loops through all possible socket locations, comparing the
189 * maximum NB frequencies to determine the slowest. This function also
190 * determines if all coherent NB frequencies are equivalent.
192 * @param[in] NbPstate NB P-state number to check (0 = fastest)
193 * @param[in] PlatformConfig Platform profile/build option config structure.
194 * @param[out] SystemNbCofNumerator NB frequency numerator for the system in MHz
195 * @param[out] SystemNbCofDenominator NB frequency denominator for the system
196 * @param[out] SystemNbCofsMatch Whether or not all NB frequencies are equivalent
197 * @param[out] NbPstateIsEnabledOnAllCPUs Whether or not NbPstate is valid on all CPUs
198 * @param[in] StdHeader Config handle for library and services
200 * @retval TRUE At least one processor has NbPstate enabled.
201 * @retval FALSE NbPstate is disabled on all CPUs
205 GetSystemNbCofMulti (
207 IN PLATFORM_CONFIGURATION *PlatformConfig,
208 OUT UINT32 *SystemNbCofNumerator,
209 OUT UINT32 *SystemNbCofDenominator,
210 OUT BOOLEAN *SystemNbCofsMatch,
211 OUT BOOLEAN *NbPstateIsEnabledOnAllCPUs,
212 IN AMD_CONFIG_PARAMS *StdHeader
218 UINT32 CurrentDivisor;
222 BOOLEAN FirstCofNotFound;
223 BOOLEAN NbPstateDisabled;
224 BOOLEAN IsNbPstateEnabledOnAny;
226 AGESA_STATUS Ignored;
227 CPU_SPECIFIC_SERVICES *FamilySpecificServices;
229 // Find the slowest NB COF in the system & whether or not all are equivalent
230 LowFrequency = 0xFFFFFFFF;
231 *SystemNbCofsMatch = TRUE;
232 *NbPstateIsEnabledOnAllCPUs = FALSE;
233 IsNbPstateEnabledOnAny = FALSE;
234 FirstCofNotFound = TRUE;
235 NbPstateDisabled = FALSE;
236 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
237 if (IsProcessorPresent (Socket, StdHeader)) {
238 GetCpuServicesOfSocket (Socket, (const CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader);
239 for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) {
240 if (GetPciAddress (StdHeader, Socket, Module, &PciAddress, &Ignored)) {
244 if (FamilySpecificServices->GetNbPstateInfo (FamilySpecificServices,
252 ASSERT (CurrentDivisor != 0);
253 CurrentFreq = (CurrentNbCof / CurrentDivisor);
254 if (FirstCofNotFound) {
255 *SystemNbCofNumerator = CurrentNbCof;
256 *SystemNbCofDenominator = CurrentDivisor;
257 LowFrequency = CurrentFreq;
258 IsNbPstateEnabledOnAny = TRUE;
259 if (!NbPstateDisabled) {
260 *NbPstateIsEnabledOnAllCPUs = TRUE;
262 FirstCofNotFound = FALSE;
264 if (CurrentFreq != LowFrequency) {
265 *SystemNbCofsMatch = FALSE;
266 if (CurrentFreq < LowFrequency) {
267 LowFrequency = CurrentFreq;
268 *SystemNbCofNumerator = CurrentNbCof;
269 *SystemNbCofDenominator = CurrentDivisor;
274 NbPstateDisabled = TRUE;
275 *NbPstateIsEnabledOnAllCPUs = FALSE;
279 return IsNbPstateEnabledOnAny;
283 /*---------------------------------------------------------------------------------------*/
285 * Multisocket call to determine if the BIOS is responsible for updating the
286 * northbridge operating frequency and voltage.
288 * This function loops through all possible socket locations, checking whether
289 * any populated sockets require NB COF VID programming.
291 * @param[in] StdHeader Config handle for library and services
293 * @retval TRUE BIOS needs to set up NB frequency and voltage
294 * @retval FALSE BIOS does not need to set up NB frequency and voltage
298 GetSystemNbCofVidUpdateMulti (
299 IN AMD_CONFIG_PARAMS *StdHeader
304 UINT32 NumberOfSockets;
306 BOOLEAN AtLeast1RequiresUpdate;
308 AGESA_STATUS Ignored;
309 CPU_SPECIFIC_SERVICES *FamilySpecificServices;
311 NumberOfSockets = GetPlatformNumberOfSockets ();
313 AtLeast1RequiresUpdate = FALSE;
314 for (Socket = 0; Socket < NumberOfSockets; Socket++) {
315 if (IsProcessorPresent (Socket, StdHeader)) {
316 GetCpuServicesOfSocket (Socket, (const CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader);
317 for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) {
318 if (GetPciAddress (StdHeader, (UINT8) Socket, Module, &PciAddress, &Ignored)) {
322 if (FamilySpecificServices->IsNbCofInitNeeded (FamilySpecificServices, &PciAddress, &IgnoredBool, StdHeader)) {
323 AtLeast1RequiresUpdate = TRUE;
328 return AtLeast1RequiresUpdate;
332 /*---------------------------------------------------------------------------------------*/
334 * Multisocket call to determine the most severe AGESA_STATUS return value after
335 * processing the power management initialization tables.
337 * This function loops through all possible socket locations, collecting any
338 * power management initialization errors that may have occurred. These errors
339 * are transferred from the core 0s of the socket in which the errors occurred
340 * to the BSC's heap. The BSC's heap is then searched for the most severe error
341 * that occurred, and returns it. This function must be called by the BSC only.
343 * @param[in] StdHeader Config handle for library and services
345 * @return The most severe error code from power management init
349 GetEarlyPmErrorsMulti (
350 IN AMD_CONFIG_PARAMS *StdHeader
358 UINT32 NumberOfSockets;
360 AGESA_EVENT EventLogEntry;
361 AGESA_STATUS ReturnCode;
362 AGESA_STATUS DummyStatus;
364 ASSERT (IsBsp (StdHeader, &ReturnCode));
366 ReturnCode = AGESA_SUCCESS;
367 EventLogEntry.EventClass = AGESA_SUCCESS;
368 EventLogEntry.EventInfo = 0;
369 EventLogEntry.DataParam1 = 0;
370 EventLogEntry.DataParam2 = 0;
371 EventLogEntry.DataParam3 = 0;
372 EventLogEntry.DataParam4 = 0;
374 NumberOfSockets = GetPlatformNumberOfSockets ();
375 IdentifyCore (StdHeader, &BscSocket, &BscModule, &BscCoreNum, &DummyStatus);
377 TaskPtr.FuncAddress.PfApTaskI = GetNextEvent;
378 TaskPtr.DataTransfer.DataSizeInDwords = SIZE_IN_DWORDS (AGESA_EVENT);
379 TaskPtr.DataTransfer.DataPtr = &EventLogEntry;
380 TaskPtr.DataTransfer.DataTransferFlags = 0;
381 TaskPtr.ExeFlags = WAIT_FOR_CORE | RETURN_PARAMS;
382 for (Socket = 0; Socket < NumberOfSockets; Socket++) {
383 if (Socket != BscSocket) {
384 if (IsProcessorPresent (Socket, StdHeader)) {
386 ApUtilRunCodeOnSocketCore ((UINT8)Socket, (UINT8) 0, &TaskPtr, StdHeader);
387 if ((EventLogEntry.EventInfo & CPU_EVENT_PM_EVENT_MASK) == CPU_EVENT_PM_EVENT_CLASS) {
389 EventLogEntry.EventClass,
390 EventLogEntry.EventInfo,
391 EventLogEntry.DataParam1,
392 EventLogEntry.DataParam2,
393 EventLogEntry.DataParam3,
394 EventLogEntry.DataParam4,
398 } while (EventLogEntry.EventInfo != 0);
403 for (i = 0; PeekEventLog (&EventLogEntry, i, StdHeader); i++) {
404 if ((EventLogEntry.EventInfo & CPU_EVENT_PM_EVENT_MASK) == CPU_EVENT_PM_EVENT_CLASS) {
405 if (EventLogEntry.EventClass > ReturnCode) {
406 ReturnCode = EventLogEntry.EventClass;
413 /*---------------------------------------------------------------------------------------
414 * L O C A L F U N C T I O N S
415 *---------------------------------------------------------------------------------------
418 /*---------------------------------------------------------------------------------------*/
420 * AP task to return the next event log entry to the BSC.
422 * This function calls to the event log manager to retrieve the next error out
425 * @param[out] EventLogEntryPtr The AP's next event log entry
426 * @param[in] StdHeader Config handle for library and services
432 IN OUT VOID *EventLogEntryPtr,
433 IN AMD_CONFIG_PARAMS *StdHeader
436 GetEventLog ((AGESA_EVENT *) EventLogEntryPtr, StdHeader);