7 * Technology Max Latency Training support
9 * @xrefitem bom "File Content Label" "Release Content"
11 * @e sub-project: (Mem/Tech)
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 * ***************************************************************************
47 *----------------------------------------------------------------------------
50 *----------------------------------------------------------------------------
61 #include "GeneralServices.h"
66 #define FILECODE PROC_MEM_TECH_MTTML_FILECODE
67 /*----------------------------------------------------------------------------
68 * DEFINITIONS AND MACROS
70 *----------------------------------------------------------------------------
73 /*----------------------------------------------------------------------------
74 * TYPEDEFS AND STRUCTURES
76 *----------------------------------------------------------------------------
79 /*----------------------------------------------------------------------------
80 * PROTOTYPES OF LOCAL FUNCTIONS
82 *----------------------------------------------------------------------------
85 /*----------------------------------------------------------------------------
88 *----------------------------------------------------------------------------
90 /* -----------------------------------------------------------------------------*/
93 * This function trains Max latency for all dies
95 * @param[in,out] *TechPtr - Pointer to the MEM_TECH_BLOCK
97 * @return TRUE - No fatal error occurs.
98 * @return FALSE - Fatal error occurs.
102 MemTTrainMaxLatency (
103 IN OUT MEM_TECH_BLOCK *TechPtr
109 UINT8 *PatternBufPtr;
110 UINT8 *TestBufferPtr;
111 UINT8 CurrentNbPstate;
112 UINT16 CalcMaxLatDly;
122 MEM_DATA_STRUCT *MemPtr;
126 NBPtr = TechPtr->NBPtr;
127 MCTPtr = NBPtr->MCTPtr;
128 MemPtr = NBPtr->MemPtr;
129 TechPtr->TrainingType = TRN_MAX_READ_LATENCY;
130 TimesRetrain = DEFAULT_TRAINING_TIMES;
131 IDS_OPTION_HOOK (IDS_MEM_RETRAIN_TIMES, &TimesRetrain, &MemPtr->StdHeader);
133 IDS_HDT_CONSOLE (MEM_STATUS, "\nStart MaxRdLat training\n");
134 // Set environment settings before training
135 AGESA_TESTPOINT (TpProcMemMaxRdLatencyTraining, &(MemPtr->StdHeader));
136 MemTBeginTraining (TechPtr);
138 // Initialize the Training Pattern
140 if (AGESA_SUCCESS != NBPtr->TrainingPatternInit (NBPtr)) {
141 return (BOOLEAN) (MCTPtr->ErrCode < AGESA_FATAL);
143 TechPtr->PatternLength = (MCTPtr->Status[Sb128bitmode]) ? 6 : 3;
145 // Setup hardware training engine (if applicable)
147 NBPtr->FamilySpecificHook[SetupHwTrainingEngine] (NBPtr, &TechPtr->TrainingType);
150 _CL_ = TechPtr->PatternLength;
151 PatternBufPtr = TechPtr->PatternBufPtr;
152 TestBufferPtr = TechPtr->TestBufPtr;
154 // Begin max latency training
156 for (Dct = 0; Dct < NBPtr->DctCount; Dct++) {
157 if (MCTPtr->Status[Sb128bitmode] && (Dct != 0)) {
161 IDS_HDT_CONSOLE (MEM_STATUS, "\tDct %d\n", Dct);
162 NBPtr->SwitchDCT (NBPtr, Dct);
164 if (NBPtr->DCTPtr->Timings.DctMemSize != 0) {
165 if (TechPtr->FindMaxDlyForMaxRdLat (TechPtr, &ChipSel)) {
166 TechPtr->ChipSel = ChipSel;
167 if (NBPtr->GetSysAddr (NBPtr, ChipSel, &TestAddrRJ16)) {
168 IDS_HDT_CONSOLE (MEM_STATUS, "\t\tCS %d\n", ChipSel);
169 IDS_HDT_CONSOLE (MEM_FLOW, "\t\t\tWrite to address: %04x0000\n", TestAddrRJ16);
171 // Write the test patterns
172 AGESA_TESTPOINT (TpProcMemMaxRdLatWritePattern, &(MemPtr->StdHeader));
173 NBPtr->WritePattern (NBPtr, TestAddrRJ16, PatternBufPtr, _CL_);
175 // Sweep max latency delays
176 NBPtr->getMaxLatParams (NBPtr, TechPtr->MaxDlyForMaxRdLat, &CalcMaxLatDly, &MaxLatLimit, &Margin);
177 AGESA_TESTPOINT (TpProcMemMaxRdLatStartSweep, &(MemPtr->StdHeader));
180 ERROR_HANDLE_RETRAIN_BEGIN (TimesFail, TimesRetrain)
182 MaxLatDly = CalcMaxLatDly;
183 for (i = 0; i < (MaxLatLimit - CalcMaxLatDly); i++) {
184 NBPtr->SetBitField (NBPtr, BFMaxLatency, MaxLatDly);
185 IDS_HDT_CONSOLE (MEM_FLOW, "\t\t\tDly %3x", MaxLatDly);
186 TechPtr->ResetDCTWrPtr (TechPtr, 6);
188 AGESA_TESTPOINT (TpProcMemMaxRdLatReadPattern, &(MemPtr->StdHeader));
189 NBPtr->ReadPattern (NBPtr, TestBufferPtr, TestAddrRJ16, _CL_);
190 AGESA_TESTPOINT (TpProcMemMaxRdLatTestPattern, &(MemPtr->StdHeader));
191 CurTest = NBPtr->CompareTestPattern (NBPtr, TestBufferPtr, PatternBufPtr, _CL_ * 64);
192 NBPtr->FlushPattern (NBPtr, TestAddrRJ16, _CL_);
194 if (NBPtr->IsSupported[ReverseMaxRdLatTrain]) {
195 // Reverse training decrements MaxLatDly whenever the test passes
196 // and uses the last passing MaxLatDly as left edge
197 if (CurTest == 0xFFFF) {
198 IDS_HDT_CONSOLE (MEM_FLOW, " P");
199 if (MaxLatDly == 0) {
206 // Traditional training increments MaxLatDly until the test passes
207 // and uses it as left edge
208 if (CurTest == 0xFFFF) {
209 IDS_HDT_CONSOLE (MEM_FLOW, " P");
215 IDS_HDT_CONSOLE (MEM_FLOW, "\n");
216 }// End of delay sweep
217 ERROR_HANDLE_RETRAIN_END ((MaxLatDly >= MaxLatLimit), TimesFail)
220 AGESA_TESTPOINT (TpProcMemMaxRdLatSetDelay, &(MemPtr->StdHeader));
222 if (MaxLatDly >= MaxLatLimit) {
223 PutEventLog (AGESA_ERROR, MEM_ERROR_MAX_LAT_NO_WINDOW, NBPtr->Node, NBPtr->Dct, NBPtr->Channel, 0, &NBPtr->MemPtr->StdHeader);
224 SetMemError (AGESA_ERROR, MCTPtr);
225 NBPtr->DCTPtr->Timings.CsTrainFail |= NBPtr->DCTPtr->Timings.CsPresent;
226 MCTPtr->ChannelTrainFail |= (UINT32)1 << Dct;
227 if (!NBPtr->MemPtr->ErrorHandling (MCTPtr, NBPtr->Dct, EXCLUDE_ALL_CHIPSEL, &NBPtr->MemPtr->StdHeader)) {
232 NBPtr->FamilySpecificHook[AddlMaxRdLatTrain] (NBPtr, &TestAddrRJ16);
234 MaxLatDly = MaxLatDly + Margin;
235 if (NBPtr->IsSupported[ReverseMaxRdLatTrain]) {
236 MaxLatDly++; // Add 1 to get back to the last passing value
239 CurrentNbPstate = (UINT8) MemNGetBitFieldNb (NBPtr, BFCurNbPstate);
240 ASSERT (CurrentNbPstate <= 3);
241 NBPtr->ChannelPtr->DctMaxRdLat [CurrentNbPstate] = MaxLatDly;
242 NBPtr->SetBitField (NBPtr, BFMaxLatency, MaxLatDly);
243 IDS_HDT_CONSOLE (MEM_FLOW, "\t\tFinal MaxRdLat: %03x\n", MaxLatDly);
251 // Restore environment settings after training
252 MemTEndTraining (TechPtr);
253 IDS_HDT_CONSOLE (MEM_FLOW, "End MaxRdLat training\n\n");
255 // Finalize the Pattern
257 NBPtr->TrainingPatternFinalize (NBPtr);
258 return (BOOLEAN) (MCTPtr->ErrCode < AGESA_FATAL);