zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * AMD CPU Feature Leveling Function. |
| 6 | * |
| 7 | * Contains code to Level the Feature in a multi-socket system |
| 8 | * |
| 9 | * @xrefitem bom "File Content Label" "Release Content" |
| 10 | * @e project: AGESA |
| 11 | * @e sub-project: CPU |
| 12 | * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 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 | |
| 47 | /* |
| 48 | *---------------------------------------------------------------------------- |
| 49 | * MODULES USED |
| 50 | * |
| 51 | *---------------------------------------------------------------------------- |
| 52 | */ |
| 53 | #include "AGESA.h" |
| 54 | #include "amdlib.h" |
| 55 | #include "cpuRegisters.h" |
| 56 | #include "GeneralServices.h" |
| 57 | #include "cpuServices.h" |
| 58 | #include "cpuPostInit.h" |
| 59 | #include "cpuApicUtilities.h" |
| 60 | #include "cpuFamilyTranslation.h" |
| 61 | #include "Filecode.h" |
| 62 | CODE_GROUP (G1_PEICC) |
| 63 | RDATA_GROUP (G1_PEICC) |
| 64 | |
| 65 | #define FILECODE PROC_CPU_FEATURE_CPUFEATURELEVELING_FILECODE |
| 66 | /*---------------------------------------------------------------------------- |
| 67 | * DEFINITIONS AND MACROS |
| 68 | * |
| 69 | *---------------------------------------------------------------------------- |
| 70 | */ |
| 71 | |
| 72 | |
| 73 | /*---------------------------------------------------------------------------- |
| 74 | * TYPEDEFS AND STRUCTURES |
| 75 | * |
| 76 | *---------------------------------------------------------------------------- |
| 77 | */ |
| 78 | |
| 79 | /*---------------------------------------------------------------------------------------- |
| 80 | * E X P O R T E D F U N C T I O N S |
| 81 | *---------------------------------------------------------------------------------------- |
| 82 | */ |
| 83 | |
| 84 | /*---------------------------------------------------------------------------- |
| 85 | * PROTOTYPES OF LOCAL FUNCTIONS |
| 86 | * |
| 87 | *---------------------------------------------------------------------------- |
| 88 | */ |
| 89 | VOID |
| 90 | STATIC |
| 91 | SaveFeatures ( |
| 92 | IN OUT VOID *cpuFeatureListPtr, |
| 93 | IN OUT AMD_CONFIG_PARAMS *StdHeader |
| 94 | ); |
| 95 | |
| 96 | VOID |
| 97 | STATIC |
| 98 | WriteFeatures ( |
| 99 | IN OUT VOID *cpuFeatureListPtr, |
| 100 | IN OUT AMD_CONFIG_PARAMS *StdHeader |
| 101 | ); |
| 102 | |
| 103 | VOID |
| 104 | STATIC |
| 105 | GetGlobalCpuFeatureListAddress ( |
| 106 | OUT UINT64 **Address, |
| 107 | IN AMD_CONFIG_PARAMS *StdHeader |
| 108 | ); |
| 109 | |
| 110 | /*---------------------------------------------------------------------------------------- |
| 111 | * P U B L I C F U N C T I O N S |
| 112 | *---------------------------------------------------------------------------------------- |
| 113 | */ |
| 114 | |
| 115 | /* -----------------------------------------------------------------------------*/ |
| 116 | /** |
| 117 | * |
| 118 | * FeatureLeveling |
| 119 | * |
| 120 | * CPU feature leveling. Set least common features set of all CPUs |
| 121 | * |
| 122 | * @param[in,out] StdHeader - Pointer to AMD_CONFIG_PARAMS struct. |
| 123 | * |
| 124 | */ |
| 125 | VOID |
| 126 | FeatureLeveling ( |
| 127 | IN OUT AMD_CONFIG_PARAMS *StdHeader |
| 128 | ) |
| 129 | { |
| 130 | UINT32 BscSocket; |
| 131 | UINT32 Ignored; |
| 132 | UINT32 BscCoreNum; |
| 133 | UINT32 Socket; |
| 134 | UINT32 Core; |
| 135 | UINT32 NumberOfSockets; |
| 136 | UINT32 NumberOfCores; |
| 137 | BOOLEAN *FirstTime; |
| 138 | BOOLEAN *NeedLeveling; |
| 139 | AGESA_STATUS IgnoredSts; |
| 140 | CPU_FEATURES_LIST *globalCpuFeatureList; |
| 141 | AP_TASK TaskPtr; |
| 142 | |
| 143 | ASSERT (IsBsp (StdHeader, &IgnoredSts)); |
| 144 | |
| 145 | GetGlobalCpuFeatureListAddress ((UINT64 **) &globalCpuFeatureList, StdHeader); |
| 146 | FirstTime = (BOOLEAN *) ((UINT8 *) globalCpuFeatureList + sizeof (CPU_FEATURES_LIST)); |
| 147 | NeedLeveling = (BOOLEAN *) ((UINT8 *) globalCpuFeatureList + sizeof (CPU_FEATURES_LIST) + sizeof (BOOLEAN)); |
| 148 | |
| 149 | *FirstTime = TRUE; |
| 150 | *NeedLeveling = FALSE; |
| 151 | |
| 152 | LibAmdMemFill (globalCpuFeatureList, 0xFF, sizeof (CPU_FEATURES_LIST), StdHeader); |
| 153 | IdentifyCore (StdHeader, &BscSocket, &Ignored, &BscCoreNum, &IgnoredSts); |
| 154 | NumberOfSockets = GetPlatformNumberOfSockets (); |
| 155 | |
| 156 | TaskPtr.FuncAddress.PfApTaskI = SaveFeatures; |
| 157 | TaskPtr.DataTransfer.DataSizeInDwords = SIZE_IN_DWORDS (CPU_FEATURES_LIST); |
| 158 | TaskPtr.ExeFlags = WAIT_FOR_CORE; |
| 159 | TaskPtr.DataTransfer.DataPtr = globalCpuFeatureList; |
| 160 | TaskPtr.DataTransfer.DataTransferFlags = DATA_IN_MEMORY; |
| 161 | |
| 162 | for (Socket = 0; Socket < NumberOfSockets; Socket++) { |
| 163 | if (IsProcessorPresent (Socket, StdHeader)) { |
| 164 | if (Socket != BscSocket) { |
| 165 | ApUtilRunCodeOnSocketCore ((UINT8)Socket, 0, &TaskPtr, StdHeader); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | ApUtilTaskOnExecutingCore (&TaskPtr, StdHeader, NULL); |
| 170 | |
| 171 | if (*NeedLeveling) { |
| 172 | TaskPtr.FuncAddress.PfApTaskI = WriteFeatures; |
| 173 | for (Socket = 0; Socket < NumberOfSockets; Socket++) { |
| 174 | if (GetActiveCoresInGivenSocket (Socket, &NumberOfCores, StdHeader)) { |
| 175 | for (Core = 0; Core < NumberOfCores; Core++) { |
| 176 | if ((Socket != BscSocket) || (Core != BscCoreNum)) { |
| 177 | ApUtilRunCodeOnSocketCore ((UINT8)Socket, (UINT8)Core, &TaskPtr, StdHeader); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | ApUtilTaskOnExecutingCore (&TaskPtr, StdHeader, NULL); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | /*---------------------------------------------------------------------------------------- |
| 187 | * L O C A L F U N C T I O N S |
| 188 | *---------------------------------------------------------------------------------------- |
| 189 | */ |
| 190 | |
| 191 | /* -----------------------------------------------------------------------------*/ |
| 192 | /** |
| 193 | * |
| 194 | * SaveFeatures |
| 195 | * |
| 196 | * save least common features set of all CPUs |
| 197 | * |
| 198 | * @param[in,out] cpuFeatureListPtr - Pointer to CPU Feature List. |
| 199 | * @param[in,out] StdHeader - Pointer to AMD_CONFIG_PARAMS struct. |
| 200 | * |
| 201 | */ |
| 202 | VOID |
| 203 | STATIC |
| 204 | SaveFeatures ( |
| 205 | IN OUT VOID *cpuFeatureListPtr, |
| 206 | IN OUT AMD_CONFIG_PARAMS *StdHeader |
| 207 | ) |
| 208 | { |
| 209 | CPU_SPECIFIC_SERVICES *FamilySpecificServices; |
| 210 | FamilySpecificServices = NULL; |
| 211 | |
| 212 | GetCpuServicesOfCurrentCore ((CONST CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader); |
| 213 | FamilySpecificServices->SaveFeatures (FamilySpecificServices, cpuFeatureListPtr, StdHeader); |
| 214 | } |
| 215 | |
| 216 | /* -----------------------------------------------------------------------------*/ |
| 217 | /** |
| 218 | * |
| 219 | * WriteFeatures |
| 220 | * |
| 221 | * Write out least common features set of all CPUs |
| 222 | * |
| 223 | * @param[in,out] cpuFeatureListPtr - Pointer to CPU Feature List. |
| 224 | * @param[in,out] StdHeader - Pointer to AMD_CONFIG_PARAMS struct. |
| 225 | * |
| 226 | */ |
| 227 | VOID |
| 228 | STATIC |
| 229 | WriteFeatures ( |
| 230 | IN OUT VOID *cpuFeatureListPtr, |
| 231 | IN OUT AMD_CONFIG_PARAMS *StdHeader |
| 232 | ) |
| 233 | { |
| 234 | CPU_SPECIFIC_SERVICES *FamilySpecificServices; |
| 235 | FamilySpecificServices = NULL; |
| 236 | |
| 237 | GetCpuServicesOfCurrentCore ((CONST CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader); |
| 238 | FamilySpecificServices->WriteFeatures (FamilySpecificServices, cpuFeatureListPtr, StdHeader); |
| 239 | } |
| 240 | |
| 241 | /*---------------------------------------------------------------------------------------*/ |
| 242 | /** |
| 243 | * |
| 244 | * GetGlobalCpuFeatureListAddress |
| 245 | * |
| 246 | * Determines the address in system DRAM that should be used for CPU feature leveling. |
| 247 | * |
| 248 | * @param[out] Address Address to utilize |
| 249 | * @param[in] StdHeader Config handle for library and services |
| 250 | * |
| 251 | * |
| 252 | */ |
| 253 | VOID |
| 254 | STATIC |
| 255 | GetGlobalCpuFeatureListAddress ( |
| 256 | OUT UINT64 **Address, |
| 257 | IN AMD_CONFIG_PARAMS *StdHeader |
| 258 | ) |
| 259 | { |
| 260 | UINT64 AddressValue; |
| 261 | |
| 262 | AddressValue = GLOBAL_CPU_FEATURE_LIST_TEMP_ADDR; |
| 263 | |
Martin Roth | 73e86a8 | 2013-01-17 16:28:30 -0700 | [diff] [blame] | 264 | *Address = (UINT64 *)(intptr_t)(AddressValue); |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 265 | } |