7 * Common Northbridge functions for DR
9 * @xrefitem bom "File Content Label" "Release Content"
11 * @e sub-project: (Mem/NB/DR)
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 * ***************************************************************************
46 *----------------------------------------------------------------------------
49 *----------------------------------------------------------------------------
55 #include "AdvancedApi.h"
58 #include "OptionMemory.h"
65 #include "cpuRegisters.h"
66 #include "cpuFamRegisters.h"
67 #include "cpuFamilyTranslation.h"
68 #include "heapManager.h"
69 #include "GeneralServices.h"
74 #define FILECODE PROC_MEM_NB_DR_MNDR_FILECODE
77 /*----------------------------------------------------------------------------
78 * DEFINITIONS AND MACROS
80 *----------------------------------------------------------------------------
83 #define SPLIT_CHANNEL (UINT32) 0x20000000
84 #define CHANNEL_SELECT (UINT32) 0x10000000
86 /*----------------------------------------------------------------------------
87 * TYPEDEFS AND STRUCTURES
89 *----------------------------------------------------------------------------
92 /*----------------------------------------------------------------------------
93 * PROTOTYPES OF LOCAL FUNCTIONS
95 *----------------------------------------------------------------------------
98 /*----------------------------------------------------------------------------
101 *----------------------------------------------------------------------------
104 extern BUILD_OPT_CFG UserOptions;
105 extern PSO_ENTRY DefaultPlatformMemoryConfiguration[];
107 /* -----------------------------------------------------------------------------*/
111 * This function initializes the northbridge block
113 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
114 * @param[in,out] *MemPtr - Pointer to the MEM_DATA_STRUCT
115 * @param[in] *FeatPtr - Pointer to the MEM_FEAT_BLOCK_NB
116 * @param[in] *SharedPtr - Pointer to the MEM_SHARED_DATA
117 * @param[in] NodeID - UINT8 indicating node ID of the NB object.
119 * @return Boolean indicating that this is the correct memory
120 * controller type for the node number that was passed in.
124 MemConstructNBBlockDR (
125 IN OUT MEM_NB_BLOCK *NBPtr,
126 IN OUT MEM_DATA_STRUCT *MemPtr,
127 IN MEM_FEAT_BLOCK_NB *FeatPtr,
128 IN MEM_SHARED_DATA *SharedPtr,
134 UINT8 SpdSocketIndex;
135 UINT8 SpdChannelIndex;
137 ALLOCATE_HEAP_PARAMS AllocHeapParams;
140 // Determine if this is the expected NB Type
142 GetLogicalIdOfSocket (MemPtr->DiesPerSystem[NodeID].SocketId, &(MemPtr->DiesPerSystem[NodeID].LogicalCpuid), &(MemPtr->StdHeader));
143 if (!MemNIsIdSupportedDr (NBPtr, &(MemPtr->DiesPerSystem[NodeID].LogicalCpuid))) {
147 NBPtr->MemPtr = MemPtr;
148 NBPtr->RefPtr = MemPtr->ParameterListPtr;
149 NBPtr->SharedPtr = SharedPtr;
151 MCTPtr = &(MemPtr->DiesPerSystem[NodeID]);
152 NBPtr->MCTPtr = MCTPtr;
153 NBPtr->MCTPtr->NodeId = NodeID;
154 NBPtr->PciAddr.AddressValue = MCTPtr->PciAddr.AddressValue;
155 NBPtr->VarMtrrHiMsk = GetVarMtrrHiMsk (&(MemPtr->DiesPerSystem[NodeID].LogicalCpuid), &(MemPtr->StdHeader));
158 // Allocate buffer for DCT_STRUCTs and CH_DEF_STRUCTs
160 AllocHeapParams.RequestedBufferSize = MAX_DCTS_PER_NODE_DR * (
161 sizeof (DCT_STRUCT) + (
162 MAX_CHANNELS_PER_DCT_DR * (sizeof (CH_DEF_STRUCT) + sizeof (MEM_PS_BLOCK))
165 AllocHeapParams.BufferHandle = GENERATE_MEM_HANDLE (ALLOC_DCT_STRUCT_HANDLE, NodeID, 0, 0);
166 AllocHeapParams.Persist = HEAP_LOCAL_CACHE;
167 if (HeapAllocateBuffer (&AllocHeapParams, &MemPtr->StdHeader) != AGESA_SUCCESS) {
168 PutEventLog (AGESA_FATAL, MEM_ERROR_HEAP_ALLOCATE_FOR_DCT_STRUCT_AND_CH_DEF_STRUCTs, NBPtr->Node, 0, 0, 0, &MemPtr->StdHeader);
169 SetMemError (AGESA_FATAL, MCTPtr);
170 ASSERT(FALSE); // Could not allocate buffer for DCT_STRUCTs and CH_DEF_STRUCTs
174 MCTPtr->DctCount = MAX_DCTS_PER_NODE_DR;
175 MCTPtr->DctData = (DCT_STRUCT *) AllocHeapParams.BufferPtr;
176 AllocHeapParams.BufferPtr += MAX_DCTS_PER_NODE_DR * sizeof (DCT_STRUCT);
177 for (Dct = 0; Dct < MAX_DCTS_PER_NODE_DR; Dct++) {
178 MCTPtr->DctData[Dct].Dct = Dct;
179 MCTPtr->DctData[Dct].ChannelCount = MAX_CHANNELS_PER_DCT_DR;
180 MCTPtr->DctData[Dct].ChData = (CH_DEF_STRUCT *) AllocHeapParams.BufferPtr;
181 MCTPtr->DctData[Dct].ChData[0].Dct = Dct;
182 AllocHeapParams.BufferPtr += MAX_CHANNELS_PER_DCT_DR * sizeof (CH_DEF_STRUCT);
184 NBPtr->PSBlock = (MEM_PS_BLOCK *) AllocHeapParams.BufferPtr;
187 // Initialize Socket List
189 for (Dct = 0; Dct < MAX_DCTS_PER_NODE_DR; Dct++) {
190 MemPtr->SocketList[MCTPtr->SocketId].ChannelPtr[Dct] = &(MCTPtr->DctData[Dct].ChData[0]);
191 MemPtr->SocketList[MCTPtr->SocketId].TimingsPtr[Dct] = &(MCTPtr->DctData[Dct].Timings);
192 MCTPtr->DctData[Dct].ChData[0].ChannelID = (MCTPtr->DieId * 2) + Dct;
195 MemNInitNBDataDr (NBPtr);
197 FeatPtr->InitCPG (NBPtr);
198 NBPtr->FeatPtr = FeatPtr;
199 FeatPtr->InitHwRxEn (NBPtr);
201 // Calculate SPD Offsets per channel and assign pointers to the data. At this point, we calculate the Node-Dct-Channel
202 // centric offsets and store the pointers to the first DIMM of each channel in the Channel Definition struct for that
203 // channel. This pointer is then used later to calculate the offsets to be used for each logical dimm once the
204 // dimm types(QR or not) are known. This is done in the Technology block constructor.
206 // Calculate the SpdSocketIndex separately from the SpdChannelIndex.
207 // This will facilitate modifications due to some processors that might
208 // map the DCT-CHANNEL differently.
210 SpdSocketIndex = GetSpdSocketIndex (NBPtr->RefPtr->PlatformMemoryConfiguration, NBPtr->MCTPtr->SocketId, &MemPtr->StdHeader);
212 // Traverse the Dct/Channel structures
214 for (Dct = 0; Dct < MAX_DCTS_PER_NODE_DR; Dct++) {
215 for (Channel = 0; Channel < MAX_CHANNELS_PER_DCT_DR; Channel++) {
217 // Calculate the number of Dimms on this channel using the
218 // die/dct/channel to Socket/channel conversion.
220 SpdChannelIndex = GetSpdChannelIndex (NBPtr->RefPtr->PlatformMemoryConfiguration,
221 NBPtr->MCTPtr->SocketId,
222 MemNGetSocketRelativeChannelNb (NBPtr, Dct, Channel),
224 NBPtr->MCTPtr->DctData[Dct].ChData[Channel].SpdPtr = &(MemPtr->SpdDataStructure[SpdSocketIndex + SpdChannelIndex]);
228 MemNSwitchDCTNb (NBPtr, 0);
232 /* -----------------------------------------------------------------------------*/
235 * This function initializes member functions and variables of NB block.
237 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
243 IN OUT MEM_NB_BLOCK *NBPtr
246 NBPtr->DctCachePtr = NBPtr->DctCache;
247 NBPtr->PsPtr = NBPtr->PSBlock;
249 InitNBRegTableDr (NBPtr, NBPtr->NBRegTable);
250 NBPtr->Node = ((UINT8) NBPtr->PciAddr.Address.Device) - 24;
253 NBPtr->DctCount = MAX_DCTS_PER_NODE_DR;
254 NBPtr->ChannelCount = MAX_CHANNELS_PER_DCT_DR;
255 NBPtr->Ganged = FALSE;
256 NBPtr->PosTrnPattern = POS_PATTERN_72B;
257 NBPtr->MemCleared = FALSE;
258 NBPtr->StartupSpeed = DDR800_FREQUENCY;
259 NBPtr->RcvrEnDlyLimit = 0xFF;
260 NBPtr->NodeCount = MAX_NODES_SUPPORTED_DR;
261 NBPtr->DefDctSelIntLvAddr = 3;
262 NBPtr->CsRegMsk = 0x1FF83FE0;
264 LibAmdMemFill (NBPtr->DctCache, 0, sizeof (NBPtr->DctCache), &NBPtr->MemPtr->StdHeader);
266 NBPtr->SetMaxLatency = MemNSetMaxLatencyNb;
267 NBPtr->getMaxLatParams = MemNGetMaxLatParamsNb;
268 NBPtr->InitializeMCT = MemNInitializeMctDr;
269 NBPtr->FinalizeMCT = MemNFinalizeMctDr;
270 NBPtr->SendMrsCmd = MemNSendMrsCmdDr;
271 NBPtr->sendZQCmd = MemNSendZQCmdNb;
272 NBPtr->WritePattern = MemNWritePatternDr;
273 NBPtr->ReadPattern = MemNReadPatternDr;
274 NBPtr->GenHwRcvEnReads = (VOID (*) (MEM_NB_BLOCK *, UINT32)) memDefRet;
275 NBPtr->CompareTestPattern = MemNCompareTestPatternNb;
276 NBPtr->InsDlyCompareTestPattern = MemNInsDlyCompareTestPatternNb;
277 NBPtr->StitchMemory = MemNStitchMemoryNb;
278 NBPtr->AutoConfig = memNAutoConfigDr;
279 NBPtr->PlatformSpec = MemNPlatformSpecNb;
280 NBPtr->InitMCT = MemNInitMCTNb;
281 NBPtr->DisableDCT = MemNDisableDCTNb;
282 NBPtr->StartupDCT = MemNStartupDCTNb;
283 NBPtr->SyncTargetSpeed = MemNSyncTargetSpeedNb;
284 NBPtr->ChangeFrequency = MemNChangeFrequencyNb;
285 NBPtr->RampUpFrequency = MemNRampUpFrequencyNb;
286 NBPtr->ChangeNbFrequency = (BOOLEAN (*) (MEM_NB_BLOCK *)) memDefFalse;
287 NBPtr->ProgramCycTimings = MemNProgramCycTimingsDr;
288 NBPtr->SyncDctsReady = MemNSyncDctsReadyNb;
289 NBPtr->HtMemMapInit = MemNHtMemMapInitNb;
290 NBPtr->SyncAddrMapToAllNodes = MemNSyncAddrMapToAllNodesNb;
291 NBPtr->CpuMemTyping = MemNCPUMemTypingNb;
292 NBPtr->BeforeDqsTraining = MemNBeforeDQSTrainingNb;
293 NBPtr->AfterDqsTraining = (VOID (*) (MEM_NB_BLOCK *)) memDefRet;
294 NBPtr->OtherTiming = (BOOLEAN (*) (MEM_NB_BLOCK *)) MemMDefRet; //@attention - due to build issue with MemNOtherTimingDr
295 NBPtr->UMAMemTyping = MemNUMAMemTypingNb;
296 NBPtr->TechBlockSwitch = MemNTechBlockSwitchNb;
297 NBPtr->SetEccSymbolSize = (VOID (*) (MEM_NB_BLOCK *)) memDefRet;
298 NBPtr->TrainingFlow = MemNTrainingFlowNb;
299 NBPtr->MinDataEyeWidth = MemNMinDataEyeWidthNb;
300 MemNInitNBDataNb (NBPtr);
301 NBPtr->PollBitField = MemNPollBitFieldNb;
302 NBPtr->BrdcstCheck = MemNBrdcstCheckNb;
303 NBPtr->BrdcstSet = MemNBrdcstSetNb;
304 NBPtr->GetTrainDly = MemNGetTrainDlyNb;
305 NBPtr->SetTrainDly = MemNSetTrainDlyNb;
306 NBPtr->PhyFenceTraining = MemNPhyFenceTrainingNb;
307 NBPtr->GetSysAddr = MemNGetMCTSysAddrNb;
308 NBPtr->RankEnabled = MemNRankEnabledNb;
309 NBPtr->GetSocketRelativeChannel = MemNGetSocketRelativeChannelNb;
310 NBPtr->MemNPlatformSpecificFormFactorInitNb = MemNPlatformSpecificFormFactorInitDr;
311 NBPtr->MemNBeforePlatformSpecNb = MemNBeforePlatformSpecDr;
312 NBPtr->MemNcmnGetSetTrainDly = MemNcmnGetSetTrainDlyNb;
313 NBPtr->MemPPhyFenceTrainingNb = MemPPhyFenceTrainingDr;
314 NBPtr->MemPNodeMemBoundaryNb = MemPNodeMemBoundaryDr;
315 NBPtr->MemNInitPhyComp = MemNInitPhyCompNb;
316 NBPtr->MemNCmnGetSetFieldNb = MemNCmnGetSetFieldDr;
317 NBPtr->MemNBeforeDramInitNb = MemNBeforeDramInitDr;
318 NBPtr->MemNPFenceAdjustNb = MemNPFenceAdjustDr;
319 NBPtr->GetTrainDlyParms = MemNGetTrainDlyParmsNb;
320 NBPtr->TrainingPatternInit = MemNTrainingPatternInitNb;
321 NBPtr->TrainingPatternFinalize = MemNTrainingPatternFinalizeNb;
322 NBPtr->GetApproximateWriteDatDelay = MemNGetApproximateWriteDatDelayNb;
323 NBPtr->CSPerChannel = MemNCSPerChannelNb;
324 NBPtr->CSPerDelay = MemNCSPerDelayNb;
325 NBPtr->FlushPattern = MemNFlushPatternNb;
326 NBPtr->MemNCapSpeedBatteryLife = (VOID (*) (MEM_NB_BLOCK *)) memDefRet;
327 NBPtr->GetUmaSize = MemNGetUmaSizeNb;
328 NBPtr->GetMemClkFreqId = MemNGetMemClkFreqIdNb;
329 NBPtr->EnableSwapIntlvRgn = (VOID (*) (MEM_NB_BLOCK *, UINT32, UINT32)) memDefRet;
330 NBPtr->WaitXMemClks = MemNWaitXMemClksNb;
331 NBPtr->MemNGetDramTerm = MemNGetDramTermNb;
332 NBPtr->MemNGetDynDramTerm = MemNGetDynDramTermNb;
333 NBPtr->MemNGetMR0CL = MemNGetMR0CLNb;
334 NBPtr->MemNGetMR0WR = MemNGetMR0WRNb;
335 NBPtr->MemNSaveMR0 = (VOID (*) (MEM_NB_BLOCK *, UINT32)) memDefRet;
336 NBPtr->MemNGetMR2CWL = MemNGetMR2CWLNb;
337 NBPtr->AllocateC6Storage = (VOID (*) (MEM_NB_BLOCK *)) memDefRet;
339 NBPtr->IsSupported[SetSpareEn] = TRUE;
340 NBPtr->IsSupported[CheckSpareEn] = TRUE;
341 NBPtr->IsSupported[DimmBasedOnSpeed] = TRUE;
342 NBPtr->IsSupported[CheckMaxDramRate] = TRUE;
343 NBPtr->IsSupported[Check1GAlign] = TRUE;
344 NBPtr->IsSupported[CheckMaxRdDqsDlyPtr] = TRUE;
345 NBPtr->IsSupported[CheckGetMCTSysAddr] = TRUE;
346 NBPtr->IsSupported[CheckFindPSOverideWithSocket] = TRUE;
347 NBPtr->IsSupported[CheckSlewWithMarginImprv] = TRUE;
348 NBPtr->IsSupported[ForceEnMemHoleRemapping] = TRUE;
351 /* -----------------------------------------------------------------------------*/
355 * This function initializes the default values in the MEM_DATA_STRUCT
357 * @param[in,out] *MemPtr - Pointer to the MEM_DATA_STRUCT
362 IN OUT MEM_DATA_STRUCT *MemPtr
367 MEM_PARAMETER_STRUCT *RefPtr;
368 ASSERT (MemPtr != NULL);
369 RefPtr = MemPtr->ParameterListPtr;
372 // Mask Bottom IO with 0xF8 to force hole size to have granularity of 128MB
373 RefPtr->BottomIo = 0xE0;
374 RefPtr->UmaMode = UserOptions.CfgUmaMode;
375 RefPtr->UmaSize = UserOptions.CfgUmaSize;
376 RefPtr->MemHoleRemapping = TRUE;
377 RefPtr->LimitMemoryToBelow1Tb = UserOptions.CfgLimitMemoryToBelow1Tb;
382 RefPtr->UserTimingMode = UserOptions.CfgTimingModeSelect;
383 RefPtr->MemClockValue = UserOptions.CfgMemoryClockSelect;
384 for (Socket = 0; Socket < MAX_SOCKETS_SUPPORTED; Socket++) {
385 for (Channel = 0; Channel < MAX_CHANNELS_PER_SOCKET; Channel++) {
386 MemPtr->SocketList[Socket].ChannelPtr[Channel] = NULL;
387 MemPtr->SocketList[Socket].TimingsPtr[Channel] = NULL;
392 RefPtr->EnableMemClr = TRUE;
394 // TableBasedAlterations
395 RefPtr->TableBasedAlterations = NULL;
397 // Platform config table
398 RefPtr->PlatformMemoryConfiguration = DefaultPlatformMemoryConfiguration;
401 RefPtr->MemRestoreCtl = FALSE;
402 RefPtr->SaveMemContextCtl = FALSE;
403 AmdS3ParamsInitializer (&RefPtr->MemContext);
405 // Dram Configuration
406 RefPtr->EnableBankIntlv = UserOptions.CfgMemoryEnableBankInterleaving;
407 RefPtr->EnableNodeIntlv = UserOptions.CfgMemoryEnableNodeInterleaving;
408 RefPtr->EnableChannelIntlv = UserOptions.CfgMemoryChannelInterleaving;
409 RefPtr->EnableBankSwizzle = UserOptions.CfgBankSwizzle;
410 RefPtr->EnableParity = UserOptions.CfgMemoryParityEnable;
411 RefPtr->EnableOnLineSpareCtl = UserOptions.CfgOnlineSpare;
414 RefPtr->EnablePowerDown = UserOptions.CfgMemoryPowerDown;
417 RefPtr->EnableEccFeature = UserOptions.CfgEnableEccFeature;
420 RefPtr->ExternalVrefCtl = UserOptions.CfgExternalVrefCtlFeature;
423 RefPtr->ForceTrainMode = UserOptions.CfgForceTrainMode;
426 /*-----------------------------------------------------------------------------*/
429 * This function writes training pattern
430 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
431 * @param[in] Pattern[] - Pattern to write
432 * @param[in] Address - System Address [47:16]
433 * @param[in] ClCount - Number of cache lines
439 IN OUT MEM_NB_BLOCK *NBPtr,
445 Address = MemUSetUpperFSbase (Address, NBPtr->MemPtr);
446 MemUWriteCachelines (Address, Pattern, ClCount);
449 /*-----------------------------------------------------------------------------*/
452 * This function reads training pattern
453 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
454 * @param[in] Buffer[] - Buffer to fill
455 * @param[in] Address - System Address [47:16]
456 * @param[in] ClCount - Number of cache lines
462 IN OUT MEM_NB_BLOCK *NBPtr,
468 Address = MemUSetUpperFSbase (Address, NBPtr->MemPtr);
469 MemUReadCachelines (Buffer, Address, ClCount);
471 /* -----------------------------------------------------------------------------*/
474 * This function initiates DQS training for Server NB
476 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
481 memNEnableTrainSequenceDr (
482 IN OUT MEM_NB_BLOCK *NBPtr
487 if (!MemNIsIdSupportedDr (NBPtr, &(NBPtr->MemPtr->DiesPerSystem[NBPtr->MCTPtr->NodeId].LogicalCpuid))) {