Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * AMD AGESA CPU C6 feature support code. |
| 6 | * |
| 7 | * Contains code that declares the AGESA CPU C6 related APIs |
| 8 | * |
| 9 | * @xrefitem bom "File Content Label" "Release Content" |
| 10 | * @e project: AGESA |
| 11 | * @e sub-project: CPU/Feature |
| 12 | * @e \$Revision: 36186 $ @e \$Date: 2010-08-13 01:10:33 +0800 (Fri, 13 Aug 2010) $ |
| 13 | * |
| 14 | */ |
| 15 | /* |
| 16 | ***************************************************************************** |
| 17 | * |
| 18 | * Copyright (c) 2011, Advanced Micro Devices, Inc. |
| 19 | * All rights reserved. |
Edward O'Callaghan | 1542a6f | 2014-07-06 19:24:06 +1000 | [diff] [blame] | 20 | * |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [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. |
Edward O'Callaghan | 1542a6f | 2014-07-06 19:24:06 +1000 | [diff] [blame] | 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 |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 30 | * from this software without specific prior written permission. |
Edward O'Callaghan | 1542a6f | 2014-07-06 19:24:06 +1000 | [diff] [blame] | 31 | * |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [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. |
Edward O'Callaghan | 1542a6f | 2014-07-06 19:24:06 +1000 | [diff] [blame] | 42 | * |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 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 "Ids.h" |
| 54 | #include "cpuRegisters.h" |
| 55 | #include "cpuEarlyInit.h" |
| 56 | #include "GeneralServices.h" |
| 57 | #include "cpuFamilyTranslation.h" |
| 58 | #include "OptionMultiSocket.h" |
| 59 | #include "cpuApicUtilities.h" |
| 60 | #include "cpuServices.h" |
| 61 | #include "cpuFeatures.h" |
| 62 | #include "cpuC6State.h" |
| 63 | #include "Filecode.h" |
| 64 | CODE_GROUP (G1_PEICC) |
| 65 | RDATA_GROUP (G1_PEICC) |
| 66 | |
| 67 | #define FILECODE PROC_CPU_FEATURE_CPUC6STATE_FILECODE |
| 68 | |
| 69 | /*---------------------------------------------------------------------------------------- |
| 70 | * D E F I N I T I O N S A N D M A C R O S |
| 71 | *---------------------------------------------------------------------------------------- |
| 72 | */ |
| 73 | |
| 74 | /*---------------------------------------------------------------------------------------- |
| 75 | * T Y P E D E F S A N D S T R U C T U R E S |
| 76 | *---------------------------------------------------------------------------------------- |
| 77 | */ |
| 78 | |
| 79 | /*---------------------------------------------------------------------------------------- |
| 80 | * 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 |
| 81 | *---------------------------------------------------------------------------------------- |
| 82 | */ |
| 83 | VOID |
| 84 | STATIC |
| 85 | EnableC6OnSocket ( |
| 86 | IN VOID *EntryPoint, |
| 87 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 88 | IN AMD_CPU_EARLY_PARAMS *CpuEarlyParams |
| 89 | ); |
| 90 | |
| 91 | /*---------------------------------------------------------------------------------------- |
| 92 | * E X P O R T E D F U N C T I O N S |
| 93 | *---------------------------------------------------------------------------------------- |
| 94 | */ |
| 95 | extern CPU_FAMILY_SUPPORT_TABLE C6FamilyServiceTable; |
| 96 | extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration; |
| 97 | |
| 98 | /*---------------------------------------------------------------------------------------*/ |
| 99 | /** |
| 100 | * Should C6 be enabled |
| 101 | * |
| 102 | * @param[in] PlatformConfig Contains the runtime modifiable feature input data. |
| 103 | * @param[in] StdHeader Config Handle for library, services. |
| 104 | * |
| 105 | * @retval TRUE C6 is supported. |
| 106 | * @retval FALSE C6 cannot be enabled. |
| 107 | * |
| 108 | */ |
| 109 | BOOLEAN |
| 110 | STATIC |
| 111 | IsC6FeatureEnabled ( |
| 112 | IN PLATFORM_CONFIGURATION *PlatformConfig, |
| 113 | IN AMD_CONFIG_PARAMS *StdHeader |
| 114 | ) |
| 115 | { |
| 116 | UINT32 Socket; |
| 117 | BOOLEAN IsEnabled; |
| 118 | C6_FAMILY_SERVICES *FamilyServices; |
| 119 | |
| 120 | IsEnabled = FALSE; |
| 121 | if (PlatformConfig->CStateMode == CStateModeC6) { |
| 122 | IsEnabled = TRUE; |
| 123 | for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) { |
| 124 | if (IsProcessorPresent (Socket, StdHeader)) { |
efdesign98 | 84cbce2 | 2011-08-04 12:09:17 -0600 | [diff] [blame] | 125 | GetFeatureServicesOfSocket (&C6FamilyServiceTable, Socket, (const VOID **)&FamilyServices, StdHeader); |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 126 | if ((FamilyServices == NULL) || !FamilyServices->IsC6Supported (FamilyServices, Socket, StdHeader)) { |
| 127 | IsEnabled = FALSE; |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | return IsEnabled; |
| 134 | } |
| 135 | |
| 136 | /*---------------------------------------------------------------------------------------*/ |
| 137 | /** |
| 138 | * Enable the C6 C-state |
| 139 | * |
| 140 | * @param[in] EntryPoint Timepoint designator. |
| 141 | * @param[in] PlatformConfig Contains the runtime modifiable feature input data. |
| 142 | * @param[in] StdHeader Config Handle for library, services. |
| 143 | * |
| 144 | * @retval AGESA_SUCCESS Always succeeds. |
| 145 | * |
| 146 | */ |
| 147 | AGESA_STATUS |
| 148 | STATIC |
| 149 | InitializeC6Feature ( |
| 150 | IN UINT64 EntryPoint, |
| 151 | IN PLATFORM_CONFIGURATION *PlatformConfig, |
| 152 | IN AMD_CONFIG_PARAMS *StdHeader |
| 153 | ) |
| 154 | { |
| 155 | UINT32 BscSocket; |
| 156 | UINT32 Ignored; |
efdesign98 | 84cbce2 | 2011-08-04 12:09:17 -0600 | [diff] [blame] | 157 | UINT32 BscCoreNum; |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 158 | UINT32 Core; |
| 159 | UINT32 Socket; |
| 160 | UINT32 NumberOfSockets; |
| 161 | UINT32 NumberOfCores; |
| 162 | AP_TASK TaskPtr; |
| 163 | AMD_CPU_EARLY_PARAMS CpuEarlyParams; |
| 164 | C6_FAMILY_SERVICES *C6FamilyServices; |
| 165 | AGESA_STATUS IgnoredSts; |
| 166 | |
| 167 | CpuEarlyParams.PlatformConfig = *PlatformConfig; |
| 168 | |
| 169 | TaskPtr.FuncAddress.PfApTaskIC = EnableC6OnSocket; |
| 170 | TaskPtr.DataTransfer.DataSizeInDwords = 2; |
| 171 | TaskPtr.DataTransfer.DataPtr = &EntryPoint; |
| 172 | TaskPtr.DataTransfer.DataTransferFlags = 0; |
| 173 | TaskPtr.ExeFlags = PASS_EARLY_PARAMS; |
| 174 | OptionMultiSocketConfiguration.BscRunCodeOnAllSystemCore0s (&TaskPtr, StdHeader, &CpuEarlyParams); |
| 175 | |
| 176 | if ((EntryPoint & (CPU_FEAT_AFTER_POST_MTRR_SYNC | CPU_FEAT_AFTER_RESUME_MTRR_SYNC)) != 0) { |
| 177 | // Load any required microcode patches on both normal boot and resume from S3. |
efdesign98 | 84cbce2 | 2011-08-04 12:09:17 -0600 | [diff] [blame] | 178 | IdentifyCore (StdHeader, &BscSocket, &Ignored, &BscCoreNum, &IgnoredSts); |
| 179 | GetFeatureServicesOfSocket (&C6FamilyServiceTable, BscSocket, (const VOID **)&C6FamilyServices, StdHeader); |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 180 | if (C6FamilyServices != NULL) { |
| 181 | C6FamilyServices->ReloadMicrocodePatchAfterMemInit (StdHeader); |
| 182 | } |
| 183 | |
| 184 | // run code on all APs |
| 185 | TaskPtr.DataTransfer.DataSizeInDwords = 0; |
| 186 | TaskPtr.ExeFlags = 0; |
| 187 | |
| 188 | NumberOfSockets = GetPlatformNumberOfSockets (); |
| 189 | |
| 190 | for (Socket = 0; Socket < NumberOfSockets; Socket++) { |
| 191 | if (IsProcessorPresent (Socket, StdHeader)) { |
efdesign98 | 84cbce2 | 2011-08-04 12:09:17 -0600 | [diff] [blame] | 192 | GetFeatureServicesOfSocket (&C6FamilyServiceTable, Socket, (const VOID **)&C6FamilyServices, StdHeader); |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 193 | if (C6FamilyServices != NULL) { |
| 194 | // run code on all APs |
| 195 | TaskPtr.FuncAddress.PfApTask = C6FamilyServices->ReloadMicrocodePatchAfterMemInit; |
| 196 | if (GetActiveCoresInGivenSocket (Socket, &NumberOfCores, StdHeader)) { |
| 197 | for (Core = 0; Core < NumberOfCores; Core++) { |
efdesign98 | 84cbce2 | 2011-08-04 12:09:17 -0600 | [diff] [blame] | 198 | if ((Socket != BscSocket) || (Core != BscCoreNum)) { |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 199 | ApUtilRunCodeOnSocketCore ((UINT8) Socket, (UINT8) Core, &TaskPtr, StdHeader); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | return AGESA_SUCCESS; |
| 208 | } |
| 209 | |
| 210 | |
| 211 | /*---------------------------------------------------------------------------------------*/ |
| 212 | /** |
| 213 | * 'Local' core 0 task to enable C6 on it's socket. |
| 214 | * |
| 215 | * @param[in] EntryPoint Timepoint designator. |
| 216 | * @param[in] StdHeader Config Handle for library, services. |
| 217 | * @param[in] CpuEarlyParams Service parameters. |
| 218 | * |
| 219 | */ |
| 220 | VOID |
| 221 | STATIC |
| 222 | EnableC6OnSocket ( |
| 223 | IN VOID *EntryPoint, |
| 224 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 225 | IN AMD_CPU_EARLY_PARAMS *CpuEarlyParams |
| 226 | ) |
| 227 | { |
| 228 | |
| 229 | C6_FAMILY_SERVICES *FamilyServices; |
| 230 | |
| 231 | IDS_HDT_CONSOLE (CPU_TRACE, " C6 is enabled\n"); |
| 232 | |
efdesign98 | 84cbce2 | 2011-08-04 12:09:17 -0600 | [diff] [blame] | 233 | GetFeatureServicesOfCurrentCore (&C6FamilyServiceTable, (const VOID **)&FamilyServices, StdHeader); |
Frank Vibrans | 2b4c831 | 2011-02-14 18:30:54 +0000 | [diff] [blame] | 234 | FamilyServices->InitializeC6 (FamilyServices, |
| 235 | *((UINT64 *) EntryPoint), |
| 236 | &CpuEarlyParams->PlatformConfig, |
| 237 | StdHeader); |
| 238 | } |
| 239 | |
| 240 | /*---------------------------------------------------------------------------------------*/ |
| 241 | /** |
| 242 | * Reload microcode patch after memory is initialized. |
| 243 | * |
| 244 | * @param[in] StdHeader Config Handle for library, services. |
| 245 | * |
| 246 | */ |
| 247 | VOID |
| 248 | ReloadMicrocodePatchAfterMemInit ( |
| 249 | IN AMD_CONFIG_PARAMS *StdHeader |
| 250 | ) |
| 251 | { |
| 252 | LoadMicrocodePatch (StdHeader); |
| 253 | } |
| 254 | |
| 255 | |
| 256 | CONST CPU_FEATURE_DESCRIPTOR ROMDATA CpuFeatureC6State = |
| 257 | { |
| 258 | C6Cstate, |
| 259 | (CPU_FEAT_AFTER_PM_INIT | CPU_FEAT_AFTER_POST_MTRR_SYNC | CPU_FEAT_AFTER_RESUME_MTRR_SYNC), |
| 260 | IsC6FeatureEnabled, |
| 261 | InitializeC6Feature |
| 262 | }; |