5 * AMD CPU L3 Features Initialization functions.
7 * Contains code for initializing L3 features.
9 * @xrefitem bom "File Content Label" "Release Content"
12 * @e \$Revision: 60552 $ @e \$Date: 2011-10-17 18:50:55 -0600 (Mon, 17 Oct 2011) $
16 ******************************************************************************
18 * Copyright (C) 2012 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 ******************************************************************************
48 *----------------------------------------------------------------------------
51 *----------------------------------------------------------------------------
57 #include "cpuRegisters.h"
58 #include "cpuLateInit.h"
59 #include "cpuFamilyTranslation.h"
60 #include "cpuServices.h"
61 #include "GeneralServices.h"
62 #include "cpuFeatures.h"
63 #include "cpuL3Features.h"
68 #define FILECODE PROC_CPU_FEATURE_CPUL3FEATURES_FILECODE
69 /*----------------------------------------------------------------------------
70 * DEFINITIONS AND MACROS
72 *----------------------------------------------------------------------------
75 /*----------------------------------------------------------------------------
76 * TYPEDEFS AND STRUCTURES
78 *----------------------------------------------------------------------------
81 /*----------------------------------------------------------------------------
82 * PROTOTYPES OF LOCAL FUNCTIONS
84 *----------------------------------------------------------------------------
87 /*----------------------------------------------------------------------------
90 *----------------------------------------------------------------------------
92 extern CPU_FAMILY_SUPPORT_TABLE L3FeatureFamilyServiceTable;
94 /*---------------------------------------------------------------------------------------*/
96 * Should L3 features be enabled
98 * @param[in] PlatformConfig Contains the runtime modifiable feature input data.
99 * @param[in] StdHeader Config Handle for library, services.
101 * @retval TRUE L3 Features are supported
102 * @retval FALSE L3 Features are not supported
108 IN PLATFORM_CONFIGURATION *PlatformConfig,
109 IN AMD_CONFIG_PARAMS *StdHeader
114 L3_FEATURE_FAMILY_SERVICES *FamilyServices;
117 if (PlatformConfig->PlatformProfile.UseHtAssist ||
118 PlatformConfig->PlatformProfile.UseAtmMode) {
120 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
121 if (IsProcessorPresent (Socket, StdHeader)) {
122 GetFeatureServicesOfSocket (&L3FeatureFamilyServiceTable, Socket, (CONST VOID **)&FamilyServices, StdHeader);
123 if ((FamilyServices == NULL) || !FamilyServices->IsL3FeatureSupported (FamilyServices, Socket, StdHeader, PlatformConfig)) {
133 /*---------------------------------------------------------------------------------------*/
135 * Enable L3 dependent features.
137 * L3 features initialization requires the following series of steps.
138 * 1. Disable L3 and DRAM scrubbers on all nodes
139 * 2. Wait 40us for outstanding scrub results to complete
140 * 3. Disable all cache activity in the system
141 * 4. Issue WBINVD on all active cores
142 * 5. Initialize Probe Filter, if supported
143 * 6. Initialize ATM Mode, if supported
144 * 7. Enable all cache activity in the system
145 * 8. Restore L3 and DRAM scrubber register values
147 * @param[in] EntryPoint Timepoint designator.
148 * @param[in] PlatformConfig Contains the runtime modifiable feature input data.
149 * @param[in] StdHeader Config Handle for library, services.
151 * @retval AGESA_SUCCESS Always succeeds.
156 InitializeL3Feature (
157 IN UINT64 EntryPoint,
158 IN PLATFORM_CONFIGURATION *PlatformConfig,
159 IN AMD_CONFIG_PARAMS *StdHeader
164 BOOLEAN HtAssistEnabled;
165 BOOLEAN AtmModeEnabled;
166 AGESA_STATUS AgesaStatus;
167 AP_MAILBOXES ApMailboxes;
168 AP_EXE_PARAMS ApParams;
169 UINT32 Scrubbers[MAX_SOCKETS_SUPPORTED][L3_SCRUBBER_CONTEXT_ARRAY_SIZE];
170 L3_FEATURE_FAMILY_SERVICES *FamilyServices[MAX_SOCKETS_SUPPORTED];
172 AgesaStatus = AGESA_SUCCESS;
173 HtAssistEnabled = TRUE;
174 AtmModeEnabled = TRUE;
176 IDS_HDT_CONSOLE (CPU_TRACE, " Enabling L3 dependent features\n");
178 // There are many family service call outs. Initialize the family service array while
179 // cache is still enabled.
180 for (Socket = 0; Socket < MAX_SOCKETS_SUPPORTED; Socket++) {
181 if (IsProcessorPresent (Socket, StdHeader)) {
182 GetFeatureServicesOfSocket (&L3FeatureFamilyServiceTable, Socket, (CONST VOID **)&FamilyServices[Socket], StdHeader);
184 FamilyServices[Socket] = NULL;
188 if (EntryPoint == CPU_FEAT_AFTER_POST_MTRR_SYNC) {
189 // Check for optimal settings
190 GetApMailbox (&ApMailboxes.ApMailInfo.Info, StdHeader);
191 CpuCount = GetNumberOfProcessors (StdHeader);
192 if (((CpuCount == 1) && (ApMailboxes.ApMailInfo.Fields.ModuleType == 1)) ||
193 ((CpuCount == 2) && (ApMailboxes.ApMailInfo.Fields.ModuleType == 0))) {
194 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
195 // Only check for non-optimal HT Assist setting is if's supported.
196 if ((FamilyServices[Socket] != NULL) &&
197 (FamilyServices[Socket]->IsHtAssistSupported (FamilyServices[Socket], PlatformConfig, StdHeader))) {
198 if (FamilyServices[Socket]->IsNonOptimalConfig (FamilyServices[Socket], Socket, StdHeader)) {
199 // Non-optimal settings. Log an event.
200 AgesaStatus = AGESA_WARNING;
201 PutEventLog (AgesaStatus, CPU_WARNING_NONOPTIMAL_HT_ASSIST_CFG, 0, 0, 0, 0, StdHeader);
208 // Disable the scrubbers.
209 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
210 if (FamilyServices[Socket] != NULL) {
211 FamilyServices[Socket]->GetL3ScrubCtrl (FamilyServices[Socket], Socket, &Scrubbers[Socket][0], StdHeader);
213 // If any node in the system does not support Probe Filter, disable it on the system
214 if (!FamilyServices[Socket]->IsHtAssistSupported (FamilyServices[Socket], PlatformConfig, StdHeader)) {
215 HtAssistEnabled = FALSE;
217 // If any node in the system does not support ATM mode, disable it on the system
218 if (!FamilyServices[Socket]->IsAtmModeSupported (FamilyServices[Socket], PlatformConfig, StdHeader)) {
219 AtmModeEnabled = FALSE;
225 WaitMicroseconds ((UINT32) 40, StdHeader);
227 // Run DisableAllCaches on AP cores.
228 ApParams.StdHeader = *StdHeader;
229 ApParams.FunctionNumber = AP_LATE_TASK_DISABLE_CACHE;
230 ApParams.RelatedDataBlock = (VOID *) &HtAssistEnabled;
231 ApParams.RelatedBlockLength = sizeof (BOOLEAN);
232 RunLateApTaskOnAllAPs (&ApParams, StdHeader);
234 // Run DisableAllCaches on core 0.
235 DisableAllCaches (&ApParams);
237 // Family hook before initialization.
238 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
239 if (FamilyServices[Socket] != NULL) {
240 FamilyServices[Socket]->HookBeforeInit (FamilyServices[Socket], Socket, StdHeader);
244 // Activate Probe Filter & ATM mode.
245 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
246 if (FamilyServices[Socket] != NULL) {
247 if (HtAssistEnabled) {
248 FamilyServices[Socket]->HtAssistInit (FamilyServices[Socket], Socket, StdHeader);
250 if (AtmModeEnabled) {
251 FamilyServices[Socket]->AtmModeInit (FamilyServices[Socket], Socket, StdHeader);
256 // Family hook after initialization.
257 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
258 if (FamilyServices[Socket] != NULL) {
259 FamilyServices[Socket]->HookAfterInit (FamilyServices[Socket], Socket, StdHeader);
263 // Run EnableAllCaches on core 0.
264 EnableAllCaches (&ApParams);
266 // Run EnableAllCaches on every core.
267 ApParams.FunctionNumber = AP_LATE_TASK_ENABLE_CACHE;
268 RunLateApTaskOnAllAPs (&ApParams, StdHeader);
270 // Restore the scrubbers.
271 for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
272 if (FamilyServices[Socket] != NULL) {
273 FamilyServices[Socket]->SetL3ScrubCtrl (FamilyServices[Socket], Socket, &Scrubbers[Socket][0], StdHeader);
281 /*---------------------------------------------------------------------------------------*/
284 * Disable all the caches on current core.
286 * @param[in] ApExeParams Handle to config for library and services.
288 * @retval AGESA_SUCCESS Always succeeds.
293 IN AP_EXE_PARAMS *ApExeParams
297 L3_FEATURE_FAMILY_SERVICES *FamilyServices;
299 // Disable cache through CR0.
300 LibAmdReadCpuReg (0, &CR0Data);
301 CR0Data |= (0x60000000);
302 LibAmdWriteCpuReg (0, CR0Data);
305 LibAmdWriteBackInvalidateCache ();
307 GetFeatureServicesOfCurrentCore (&L3FeatureFamilyServiceTable, (CONST VOID **)&FamilyServices, &ApExeParams->StdHeader);
309 FamilyServices->HookDisableCache (FamilyServices, *(BOOLEAN *) ApExeParams->RelatedDataBlock, &ApExeParams->StdHeader);
311 return AGESA_SUCCESS;
314 /*---------------------------------------------------------------------------------------*/
317 * Enable all the caches on current core.
319 * @param[in] ApExeParams Handle to config for library and services.
321 * @retval AGESA_SUCCESS Always succeeds.
326 IN AP_EXE_PARAMS *ApExeParams
330 L3_FEATURE_FAMILY_SERVICES *FamilyServices;
332 // Enable cache through CR0.
333 LibAmdReadCpuReg (0, &CR0Data);
334 CR0Data &= ~(0x60000000);
335 LibAmdWriteCpuReg (0, CR0Data);
337 GetFeatureServicesOfCurrentCore (&L3FeatureFamilyServiceTable, (CONST VOID **)&FamilyServices, &ApExeParams->StdHeader);
339 FamilyServices->HookEnableCache (FamilyServices, &ApExeParams->StdHeader);
341 return AGESA_SUCCESS;
344 CONST CPU_FEATURE_DESCRIPTOR ROMDATA CpuL3Features =
347 (CPU_FEAT_AFTER_POST_MTRR_SYNC | CPU_FEAT_INIT_MID_END | CPU_FEAT_S3_LATE_RESTORE_END),