zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * AMD AGESA CPU create low power P-state for PROCHOT_L throttling support code. |
| 6 | * |
| 7 | * Contains code that declares the AGESA CPU low power P-state related APIs |
| 8 | * |
| 9 | * @xrefitem bom "File Content Label" "Release Content" |
| 10 | * @e project: AGESA |
| 11 | * @e sub-project: CPU/Feature |
| 12 | * @e \$Revision: 63523 $ @e \$Date: 2011-12-25 20:31:15 -0600 (Sun, 25 Dec 2011) $ |
| 13 | * |
| 14 | */ |
| 15 | /* |
| 16 | ****************************************************************************** |
| 17 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 18 | * Copyright (c) 2008 - 2012, Advanced Micro Devices, Inc. |
| 19 | * All rights reserved. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 20 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 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. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 31 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 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. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 42 | ****************************************************************************** |
| 43 | */ |
| 44 | |
| 45 | /*---------------------------------------------------------------------------------------- |
| 46 | * M O D U L E S U S E D |
| 47 | *---------------------------------------------------------------------------------------- |
| 48 | */ |
| 49 | #include "AGESA.h" |
| 50 | #include "amdlib.h" |
| 51 | #include "GeneralServices.h" |
| 52 | #include "cpuFamilyTranslation.h" |
| 53 | #include "cpuApicUtilities.h" |
| 54 | #include "OptionMultiSocket.h" |
| 55 | #include "cpuRegisters.h" |
| 56 | #include "cpuApicUtilities.h" |
| 57 | #include "cpuFeatures.h" |
| 58 | #include "cpuLowPwrPstate.h" |
| 59 | #include "Filecode.h" |
| 60 | CODE_GROUP (G1_PEICC) |
| 61 | RDATA_GROUP (G1_PEICC) |
| 62 | |
| 63 | #define FILECODE PROC_CPU_FEATURE_CPULOWPWRPSTATE_FILECODE |
| 64 | |
| 65 | /*---------------------------------------------------------------------------------------- |
| 66 | * D E F I N I T I O N S A N D M A C R O S |
| 67 | *---------------------------------------------------------------------------------------- |
| 68 | */ |
| 69 | extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration; |
| 70 | |
| 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 | |
| 76 | /*---------------------------------------------------------------------------------------- |
| 77 | * 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 |
| 78 | *---------------------------------------------------------------------------------------- |
| 79 | */ |
| 80 | VOID |
| 81 | STATIC |
| 82 | EnableLowPwrPstateOnSocket ( |
| 83 | IN VOID *PlatformConfig, |
| 84 | IN AMD_CONFIG_PARAMS *StdHeader |
| 85 | ); |
| 86 | |
| 87 | VOID |
| 88 | STATIC |
| 89 | ProgramHtcPstateLimit ( |
| 90 | IN VOID *PlatformConfig, |
| 91 | IN AMD_CONFIG_PARAMS *StdHeader |
| 92 | ); |
| 93 | |
| 94 | /*---------------------------------------------------------------------------------------- |
| 95 | * E X P O R T E D F U N C T I O N S |
| 96 | *---------------------------------------------------------------------------------------- |
| 97 | */ |
| 98 | extern CPU_FAMILY_SUPPORT_TABLE LowPwrPstateFamilyServiceTable; |
| 99 | |
| 100 | /*---------------------------------------------------------------------------------------*/ |
| 101 | /** |
| 102 | * Should Low Power P-state be enabled |
| 103 | * If all processors support Low Power P-state, reture TRUE, otherwise reture FALSE |
| 104 | * |
| 105 | * @param[in] PlatformConfig Contains the runtime modifiable feature input data. |
| 106 | * @param[in] StdHeader Config Handle for library, services. |
| 107 | * |
| 108 | * @retval TRUE Low Power P-state is supported. |
| 109 | * @retval FALSE Low Power P-state cannot be enabled. |
| 110 | * |
| 111 | */ |
| 112 | BOOLEAN |
| 113 | STATIC |
| 114 | IsLowPwrPstateFeatureSupported ( |
| 115 | IN PLATFORM_CONFIGURATION *PlatformConfig, |
| 116 | IN AMD_CONFIG_PARAMS *StdHeader |
| 117 | ) |
| 118 | { |
| 119 | UINT32 Socket; |
| 120 | BOOLEAN IsSupported; |
| 121 | LOW_PWR_PSTATE_FAMILY_SERVICES *FamilyServices; |
| 122 | |
| 123 | IsSupported = FALSE; |
| 124 | if (PlatformConfig->LowPowerPstateForProcHot == LOW_POWER_PSTATE_FOR_PROCHOT_AUTO) { |
| 125 | for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) { |
| 126 | if (IsProcessorPresent (Socket, StdHeader)) { |
| 127 | GetFeatureServicesOfSocket (&LowPwrPstateFamilyServiceTable, Socket, (CONST VOID **)&FamilyServices, StdHeader); |
| 128 | if (FamilyServices != NULL) { |
| 129 | if (FamilyServices->IsLowPwrPstateSupported (FamilyServices, PlatformConfig, Socket, StdHeader)) { |
| 130 | IsSupported = TRUE; |
| 131 | } else { |
| 132 | IsSupported = FALSE; |
| 133 | break; |
| 134 | } |
| 135 | } else { |
| 136 | IsSupported = FALSE; |
| 137 | break; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | IDS_OPTION_HOOK (IDS_LOW_POWER_PSTATE, &IsSupported, StdHeader); |
| 143 | return IsSupported; |
| 144 | } |
| 145 | |
| 146 | /*---------------------------------------------------------------------------------------*/ |
| 147 | /** |
| 148 | * Enable low power P-state |
| 149 | * |
| 150 | * @param[in] EntryPoint Timepoint designator. |
| 151 | * @param[in] PlatformConfig Contains the runtime modifiable feature input data. |
| 152 | * @param[in] StdHeader Config Handle for library, services. |
| 153 | * |
| 154 | * @retval AGESA_SUCCESS Always succeeds. |
| 155 | * |
| 156 | */ |
| 157 | AGESA_STATUS |
| 158 | STATIC |
| 159 | InitializeLowPwrPstateFeature ( |
| 160 | IN UINT64 EntryPoint, |
| 161 | IN PLATFORM_CONFIGURATION *PlatformConfig, |
| 162 | IN AMD_CONFIG_PARAMS *StdHeader |
| 163 | ) |
| 164 | { |
| 165 | UINT32 BscSocket; |
| 166 | UINT32 Ignored; |
| 167 | UINT32 BscCoreNum; |
| 168 | UINT32 Core; |
| 169 | UINT32 Socket; |
| 170 | UINT32 NumberOfSockets; |
| 171 | UINT32 NumberOfCores; |
| 172 | AP_TASK TaskPtr; |
| 173 | AGESA_STATUS IgnoredSts; |
| 174 | |
| 175 | IdentifyCore (StdHeader, &BscSocket, &Ignored, &BscCoreNum, &IgnoredSts); |
| 176 | NumberOfSockets = GetPlatformNumberOfSockets (); |
| 177 | |
| 178 | if (!IsWarmReset (StdHeader)) { |
| 179 | IDS_HDT_CONSOLE (CPU_TRACE, " Low pwr P-state is enabled\n"); |
| 180 | |
| 181 | TaskPtr.FuncAddress.PfApTaskI = EnableLowPwrPstateOnSocket; |
| 182 | TaskPtr.DataTransfer.DataSizeInDwords = 2; |
| 183 | TaskPtr.DataTransfer.DataPtr = PlatformConfig; |
| 184 | TaskPtr.DataTransfer.DataTransferFlags = 0; |
| 185 | TaskPtr.ExeFlags = WAIT_FOR_CORE; |
| 186 | |
| 187 | for (Socket = 0; Socket < NumberOfSockets; Socket++) { |
| 188 | if (GetActiveCoresInGivenSocket (Socket, &NumberOfCores, StdHeader)) { |
| 189 | for (Core = 0; Core < NumberOfCores; Core++) { |
| 190 | if ((Socket != BscSocket) || (Core != BscCoreNum)) { |
| 191 | ApUtilRunCodeOnSocketCore ((UINT8) Socket, (UINT8) Core, &TaskPtr, StdHeader); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | EnableLowPwrPstateOnSocket (PlatformConfig, StdHeader); |
| 198 | } else { |
| 199 | TaskPtr.FuncAddress.PfApTaskI = ProgramHtcPstateLimit; |
| 200 | TaskPtr.DataTransfer.DataSizeInDwords = 2; |
| 201 | TaskPtr.DataTransfer.DataPtr = PlatformConfig; |
| 202 | TaskPtr.DataTransfer.DataTransferFlags = 0; |
| 203 | TaskPtr.ExeFlags = WAIT_FOR_CORE; |
| 204 | |
| 205 | for (Socket = 0; Socket < NumberOfSockets; Socket++) { |
| 206 | if (IsProcessorPresent (Socket, StdHeader)) { |
| 207 | if (Socket != BscSocket) { |
| 208 | ApUtilRunCodeOnSocketCore ((UINT8) Socket, 0, &TaskPtr, StdHeader); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | ProgramHtcPstateLimit (PlatformConfig, StdHeader); |
| 214 | } |
| 215 | return AGESA_SUCCESS; |
| 216 | } |
| 217 | |
| 218 | /*---------------------------------------------------------------------------------------*/ |
| 219 | /** |
| 220 | * All APs task to enable low power P-state |
| 221 | * |
| 222 | * @param[in] PlatformConfig Contains the runtime modifiable feature input data. |
| 223 | * @param[in] StdHeader Config Handle for library, services. |
| 224 | * |
| 225 | */ |
| 226 | VOID |
| 227 | STATIC |
| 228 | EnableLowPwrPstateOnSocket ( |
| 229 | IN VOID *PlatformConfig, |
| 230 | IN AMD_CONFIG_PARAMS *StdHeader |
| 231 | ) |
| 232 | { |
| 233 | LOW_PWR_PSTATE_FAMILY_SERVICES *FamilyServices; |
| 234 | |
| 235 | GetFeatureServicesOfCurrentCore (&LowPwrPstateFamilyServiceTable, (CONST VOID **)&FamilyServices, StdHeader); |
| 236 | FamilyServices->EnableLowPwrPstate (FamilyServices, |
| 237 | PlatformConfig, |
| 238 | StdHeader); |
| 239 | } |
| 240 | |
| 241 | /*---------------------------------------------------------------------------------------*/ |
| 242 | /** |
| 243 | * 'Local' core 0 task to enable low power P-state |
| 244 | * |
| 245 | * @param[in] PlatformConfig Contains the runtime modifiable feature input data. |
| 246 | * @param[in] StdHeader Config Handle for library, services. |
| 247 | * |
| 248 | */ |
| 249 | VOID |
| 250 | STATIC |
| 251 | ProgramHtcPstateLimit ( |
| 252 | IN VOID *PlatformConfig, |
| 253 | IN AMD_CONFIG_PARAMS *StdHeader |
| 254 | ) |
| 255 | { |
| 256 | UINT32 OrMask; |
| 257 | UINT32 HtcCtrl; |
| 258 | UINT32 CPTC2; |
| 259 | PCI_ADDR PciAddress; |
| 260 | |
| 261 | OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader); |
| 262 | PciAddress.Address.Function = FUNC_3; |
| 263 | |
| 264 | PciAddress.Address.Register = CLOCK_POWER_TIMING_CTRL2_REG; |
| 265 | LibAmdPciRead (AccessWidth32, PciAddress, &CPTC2, StdHeader); // F3xDC[10:8] HwPstateMaxVal |
| 266 | OrMask = CPTC2 & 0x700; |
| 267 | OrMask = OrMask << 20; |
| 268 | |
| 269 | PciAddress.Address.Register = HARDWARE_THERMAL_CTRL_REG; |
| 270 | LibAmdPciRead (AccessWidth32, PciAddress, &HtcCtrl, StdHeader); // F3x64[30:28] HtcPstateLimit |
| 271 | // F3x64[30:28] HtcPstateLimit = F3xDC[10:8] HwPstateMaxVal |
| 272 | HtcCtrl = (HtcCtrl & 0x8FFFFFFF) | OrMask; |
| 273 | LibAmdPciWrite (AccessWidth32, PciAddress, &HtcCtrl, StdHeader); |
| 274 | } |
| 275 | |
| 276 | CONST CPU_FEATURE_DESCRIPTOR ROMDATA CpuFeatureLowPwrPstate = |
| 277 | { |
| 278 | LowPwrPstate, |
| 279 | (CPU_FEAT_BEFORE_RELINQUISH_AP | CPU_FEAT_AFTER_RESUME_MTRR_SYNC), |
| 280 | IsLowPwrPstateFeatureSupported, |
| 281 | InitializeLowPwrPstateFeature |
| 282 | }; |