7 * Northbridge DA DCT supporting functions
9 * @xrefitem bom "File Content Label" "Release Content"
11 * @e sub-project: (Mem/NB/DA)
12 * @e \$Revision: 56279 $ @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
15 /*****************************************************************************
17 * Copyright (C) 2012 Advanced Micro Devices, Inc.
18 * All rights reserved.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are met:
22 * * Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * * Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
27 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
28 * its contributors may be used to endorse or promote products derived
29 * from this software without specific prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
35 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 * ***************************************************************************
48 *----------------------------------------------------------------------------
51 *----------------------------------------------------------------------------
62 #include "OptionMemory.h" // need def for MEM_FEAT_BLOCK_NB
65 #include "cpuRegisters.h"
67 #include "GeneralServices.h"
68 #include "cpuFamilyTranslation.h"
69 #include "cpuRegisters.h"
71 #include "F10PackageType.h"
75 #define FILECODE PROC_MEM_NB_DA_MNDCTDA_FILECODE
76 /*----------------------------------------------------------------------------
77 * DEFINITIONS AND MACROS
79 *----------------------------------------------------------------------------
83 /*----------------------------------------------------------------------------
84 * TYPEDEFS AND STRUCTURES
86 *----------------------------------------------------------------------------
89 /*----------------------------------------------------------------------------
90 * PROTOTYPES OF LOCAL FUNCTIONS
92 *----------------------------------------------------------------------------
97 /*----------------------------------------------------------------------------
100 *----------------------------------------------------------------------------
103 extern BUILD_OPT_CFG UserOptions;
105 /* -----------------------------------------------------------------------------*/
109 * This is a general purpose function that executes before DRAM init
111 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
116 MemNBeforeDramInitDA (
117 IN OUT MEM_NB_BLOCK *NBPtr
122 //Setting the reset value of Phy DLL standby and shutdown registers.
123 for (Dct = 0; Dct < MAX_DCTS_PER_NODE_DA; Dct++) {
124 MemNSwitchDCTNb (NBPtr, Dct);
125 if (NBPtr->DCTPtr->Timings.DctMemSize != 0) {
126 //Set PllLockTime and DllLockTime to default.
127 MemNSetBitFieldNb (NBPtr, BFPhyPLLLockTime, 0x000007D0);
128 MemNSetBitFieldNb (NBPtr, BFPhyDLLLockTime, 0x00000190);
129 MemNSetBitFieldNb (NBPtr, BFDisDllShutdownSR, 1);
131 //Clear PHY PLL Control Register before doing fence training and reset DLL
132 MemNSetBitFieldNb (NBPtr, BFPhy0x0D080F0C, 0x00002000);
133 MemNSetBitFieldNb (NBPtr, BFPhyDLLControl, 0);
134 MemNSetBitFieldNb (NBPtr, BFPhy0x0D080F0C, 0);
139 /* -----------------------------------------------------------------------------*/
143 * This function programs the memory controller with configuration parameters
146 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
148 * @return TRUE - An Error value lower than AGESA_FATAL may have occurred
149 * @return FALSE - An Error value greater than or equal to AGESA_FATAL may have occurred
150 * @return NBPtr->MCTPtr->ErrCode - Contains detailed AGESA_STATUS value
155 IN OUT MEM_NB_BLOCK *NBPtr
160 MEM_PARAMETER_STRUCT *RefPtr;
162 RefPtr = NBPtr->RefPtr;
163 MCTPtr = NBPtr->MCTPtr;
164 DCTPtr = NBPtr->DCTPtr;
165 //======================================================================
166 // Build Dram Control Register Value (F2x78)
167 //======================================================================
170 MemNSetBitFieldNb (NBPtr, BFEarlyArbEn, 1);
172 //======================================================================
173 // Build Dram Config Lo Register Value
174 //======================================================================
177 if (MCTPtr->Status[SbParDimms]) {
179 // SbParDimms should be set for all DDR3 RDIMMS
180 // Cannot turn off ParEn for DDR3
182 //@attention - add debug option for parity control
183 MemNSetBitFieldNb (NBPtr, BFParEn, 1);
187 if (MCTPtr->GangedMode) {
188 MemNSetBitFieldNb (NBPtr, BFWidth128, 1);
191 MemNSetBitFieldNb (NBPtr, BFX4Dimm, DCTPtr->Timings.Dimmx4Present & 0xF);
193 if (!MCTPtr->Status[SbRegistered]) {
194 MemNSetBitFieldNb (NBPtr, BFUnBuffDimm, 1);
197 if (MCTPtr->Status[SbEccDimms]) {
198 MemNSetBitFieldNb (NBPtr, BFDimmEccEn, 1);
201 //======================================================================
202 // Build Dram Config Hi Register Value
203 //======================================================================
206 MemNSetBitFieldNb (NBPtr, BFMemClkFreq, MemNGetMemClkFreqIdNb (NBPtr, DCTPtr->Timings.Speed));
208 if (MCTPtr->Status[SbRegistered]) {
209 if (DCTPtr->Timings.Dimmx4Present && DCTPtr->Timings.Dimmx8Present) {
210 MemNSetBitFieldNb (NBPtr, BFRDqsEn, 1);
214 if (RefPtr->EnableBankSwizzle) {
215 MemNSetBitFieldNb (NBPtr, BFBankSwizzleMode, 1);
218 if (DCTPtr->Timings.DimmQrPresent) {
219 if (UserOptions.CfgMemoryQuadrankType == QUADRANK_UNBUFFERED) {
220 MemNSetBitFieldNb (NBPtr, BFFourRankSoDimm, 1);
221 } else if (UserOptions.CfgMemoryQuadrankType == QUADRANK_REGISTERED) {
222 MemNSetBitFieldNb (NBPtr, BFFourRankRDimm, 1);
226 MemNSetBitFieldNb (NBPtr, BFDcqBypassMax, 0xF);
228 MemNSetBitFieldNb (NBPtr, BFDcqArbBypassEn, 1);
230 //======================================================================
231 // Build Dram Config Misc Register Value
232 //======================================================================
234 MemNSetBitFieldNb (NBPtr, BFOdtSwizzle, 1);
235 // For DDR3 Registered Dimms
236 if (MCTPtr->Status[SbRegistered]) {
237 if (MemNGetBitFieldNb (NBPtr, BFDdr3Mode)!= 0) {
238 MemNSetBitFieldNb (NBPtr, BFSubMemclkRegDly, 1);
241 return (BOOLEAN) (MCTPtr->ErrCode < AGESA_FATAL);
244 /* -----------------------------------------------------------------------------*/
248 * This function sends an MRS command
250 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
256 IN OUT MEM_NB_BLOCK *NBPtr
259 MemNSwapBitsNb (NBPtr);
261 IDS_HDT_CONSOLE (MEM_FLOW, "\t\t\tCS%d MR%d %04x\n",
262 (MemNGetBitFieldNb (NBPtr, BFDramInitRegReg) >> 20) & 0xF,
263 (MemNGetBitFieldNb (NBPtr, BFDramInitRegReg) >> 16) & 0xF,
264 (MemNGetBitFieldNb (NBPtr, BFDramInitRegReg) & 0xFFFF));
266 // 1.Set SendMrsCmd=1
267 MemNSetBitFieldNb (NBPtr, BFSendMrsCmd, 1);
269 // 2.Wait for SendMrsCmd=0
270 MemNPollBitFieldNb (NBPtr, BFSendMrsCmd, 0, PCI_ACCESS_TIMEOUT, FALSE);
273 /* -----------------------------------------------------------------------------*/
277 * Workaround for erratum 322 and 263
279 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
283 MemNBeforePlatformSpecDA (
284 IN OUT MEM_NB_BLOCK *NBPtr
288 if ((NBPtr->DCTPtr->Timings.Speed == DDR533_FREQUENCY) || (NBPtr->DCTPtr->Timings.Speed == DDR667_FREQUENCY)) {
289 MemNSetBitFieldNb (NBPtr, BFErr263, 0x0800);
291 MemNSetBitFieldNb (NBPtr, BFErr263, 0);
295 // 1.Write 00000000h to F2x[1,0]9C_xD08E000
296 MemNSetBitFieldNb (NBPtr, BFErr322I, 0);
297 // 2.If DRAM Configuration Register[MemClkFreq] (F2x[1,0]94[2:0]) is
298 // greater than or equal to 011b (DDR-800 and higher),
299 // then write 00000080h to F2x[1,0]9C_xD02E001,
300 // else write 00000090h to F2x[1,0]9C_xD02E001.
301 MemNSetBitFieldNb (NBPtr, BFErr322II, (NBPtr->DCTPtr->Timings.Speed >= DDR800_FREQUENCY) ? 0x80 : 0x90);
304 /* -----------------------------------------------------------------------------*/
308 * Change Average Value of 3
310 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
314 MemNChangeAvgValue3DA (
315 IN OUT MEM_NB_BLOCK *NBPtr
318 if ((NBPtr->MCTPtr->LogicalCpuid.Revision & AMD_F10_C0) != 0) {
328 * Change Average Value of 8
330 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
334 MemNChangeAvgValue8DA (
335 IN OUT MEM_NB_BLOCK *NBPtr
338 if ((NBPtr->MCTPtr->LogicalCpuid.Revision & AMD_F10_C1) != 0) {
344 /* -----------------------------------------------------------------------------*/
348 * Enable DLL Shut down
350 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
354 MemNEnDLLShutDownDA (
355 IN OUT MEM_NB_BLOCK *NBPtr
359 BOOLEAN DllShutDownEn;
361 DllShutDownEn = TRUE;
362 IDS_OPTION_HOOK (IDS_DLL_SHUT_DOWN, &DllShutDownEn, &(NBPtr->MemPtr->StdHeader));
364 if (DllShutDownEn && NBPtr->IsSupported[SetDllShutDown]) {
365 for (Dct = 0; Dct < NBPtr->DctCount; Dct++) {
366 MemNSwitchDCTNb (NBPtr, Dct);
367 if (NBPtr->DCTPtr->Timings.DctMemSize != 0) {
368 MemNSetBitFieldNb (NBPtr, BFPhyPLLLockTime, 0x0000001C);
369 MemNSetBitFieldNb (NBPtr, BFPhyDLLLockTime, 0x0000013D);
370 MemNSetBitFieldNb (NBPtr, BFDisDllShutdownSR, 0);
376 /* -----------------------------------------------------------------------------*/
380 * This function caps speed based on batter life check.
382 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
385 MemNCapSpeedBatteryLifeDA (
386 IN OUT MEM_NB_BLOCK *NBPtr
389 CONST UINT16 SupportedFreq[] = {
401 CPU_SPECIFIC_SERVICES *FamilySpecificServices;
402 UINT32 ProcessorPackageType;
404 FamilySpecificServices = NULL;
405 DdrFreq = DDR800_FREQUENCY; // Set Default to be 400Mhz
406 ProcessorPackageType = LibAmdGetPackageType (&(NBPtr->MemPtr->StdHeader));
407 GetCpuServicesOfSocket (NBPtr->MCTPtr->SocketId, (const CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, &(NBPtr->MemPtr->StdHeader));
408 if (FamilySpecificServices->IsNbPstateEnabled (FamilySpecificServices, NBPtr->MemPtr->PlatFormConfig, &(NBPtr->MemPtr->StdHeader))) {
409 NBFreq = (MemNGetBitFieldNb (NBPtr, BFNbFid) + 4) * 100; // Calculate the Nb P1 frequency (NbFreq / 2)
410 for (j = 0; j < GET_SIZE_OF (SupportedFreq); j++) {
411 if (NBFreq >= ((UINT32) 2 * SupportedFreq[j])) {
412 // Pick Max MEMCLK that is less than or equal to (NCLK_P1 / 2)
413 DdrFreq = SupportedFreq[j];
417 if (NBPtr->MemPtr->PlatFormConfig->PlatformProfile.PlatformPowerPolicy == BatteryLife) {
418 if (NBPtr->DCTPtr->Timings.TargetSpeed > DdrFreq) {
419 NBPtr->DCTPtr->Timings.TargetSpeed = DdrFreq;
422 PutEventLog (AGESA_WARNING, MEM_WARNING_PERFORMANCE_ENABLED_BATTERY_LIFE_PREFERRED, NBPtr->Node, NBPtr->Dct, NBPtr->Channel, 0, &NBPtr->MemPtr->StdHeader);
423 DdrFreq = DDR800_FREQUENCY; // Set Default to be 400Mhz
424 NBFreq = (MemNGetBitFieldNb (NBPtr, BFNbFid) + 4) * 200; // Calculate the Nb P0 frequency
425 for (j = 0; j < GET_SIZE_OF (SupportedFreq); j++) {
426 if (NBFreq >= ((UINT32) 2 * SupportedFreq[j])) {
427 // Pick Max MEMCLK that is less than or equal to (NCLK_P0 / 2)
428 DdrFreq = SupportedFreq[j];
432 if (NBPtr->DCTPtr->Timings.TargetSpeed > DdrFreq) {
433 NBPtr->DCTPtr->Timings.TargetSpeed = DdrFreq;
436 if (((NBPtr->MCTPtr->LogicalCpuid.Revision & AMD_F10_C3) != 0) && (ProcessorPackageType == PACKAGE_TYPE_S1G3_S1G4 || ProcessorPackageType == PACKAGE_TYPE_ASB2)) {
437 MemNSetBitFieldNb (NBPtr, BFRdPtrInit, 4);
438 MemNSetBitFieldNb (NBPtr, BFDataTxFifoWrDly, 1);
440 MemNSetBitFieldNb (NBPtr, BFRdPtrInit, 6);
441 MemNSetBitFieldNb (NBPtr, BFDataTxFifoWrDly, 0);
444 NBFreq = (MemNGetBitFieldNb (NBPtr, BFNbFid) + 4) * 200; // Calculate the Nb P0 frequency
445 for (j = 0; j < GET_SIZE_OF (SupportedFreq); j++) {
446 if (NBFreq >= ((UINT32) 2 * SupportedFreq[j])) {
447 // Pick Max MEMCLK that is less than or equal to (NCLK_P0 / 2)
448 DdrFreq = SupportedFreq[j];
452 if (NBPtr->DCTPtr->Timings.TargetSpeed > DdrFreq) {
453 NBPtr->DCTPtr->Timings.TargetSpeed = DdrFreq;
455 MemNSetBitFieldNb (NBPtr, BFRdPtrInit, 6);
456 MemNSetBitFieldNb (NBPtr, BFDataTxFifoWrDly, 0);
460 /* -----------------------------------------------------------------------------*/
464 /*----------------------------------------------------------------------------
467 *----------------------------------------------------------------------------