blob: a596a5e9ceb52075f096cab00dc1258ce1200ca6 [file] [log] [blame]
zbao7d94cf92012-07-02 14:19:14 +08001/* $NoKeywords:$ */
2/**
3 * @file
4 *
5 * mmNodeInterleave.c
6 *
7 * Main Memory Feature implementation file for Node Interleaving
8 *
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: (Mem/Main)
12 * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $
13 *
14 **/
15/*****************************************************************************
16*
Siyuan Wang641f00c2013-06-08 11:50:55 +080017 * Copyright (c) 2008 - 2012, Advanced Micro Devices, Inc.
18 * All rights reserved.
19 *
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.
30 *
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.
zbao7d94cf92012-07-02 14:19:14 +080041* ***************************************************************************
42*
43*/
44
45/*
46 *----------------------------------------------------------------------------
47 * MODULES USED
48 *
49 *----------------------------------------------------------------------------
50 */
51
52
53#include "Porting.h"
54#include "AGESA.h"
55#include "amdlib.h"
56#include "Ids.h"
57#include "cpuRegisters.h"
58#include "cpuServices.h"
59#include "cpuApicUtilities.h"
60#include "GeneralServices.h"
61#include "OptionMemory.h"
62#include "mm.h"
63#include "mn.h"
64#include "mt.h"
65#include "ma.h"
66#include "mu.h"
67#include "mfParallelTraining.h"
68#include "GeneralServices.h"
69#include "heapManager.h"
70#include "merrhdl.h"
71#include "Filecode.h"
72CODE_GROUP (G2_PEI)
73RDATA_GROUP (G2_PEI)
74
75#define FILECODE PROC_MEM_MAIN_MMPARALLELTRAINING_FILECODE
76
77extern MEM_FEAT_BLOCK_MAIN MemFeatMain;
78/*----------------------------------------------------------------------------
79 * PROTOTYPES OF LOCAL FUNCTIONS
80 *
81 *----------------------------------------------------------------------------
82 */
83
84BOOLEAN
85MemMParallelTraining (
86 IN OUT MEM_MAIN_DATA_BLOCK *mmPtr
87 );
88
89/*-----------------------------------------------------------------------------
90* EXPORTED FUNCTIONS
91*
92*-----------------------------------------------------------------------------
93*/
94/* -----------------------------------------------------------------------------*/
95/**
96 *
97 *
98 *
99 *
100 * @param[in,out] *mmPtr - Pointer to the MEM_MAIN_DATA_BLOCK
101 *
102 * @return TRUE - No fatal error occurs.
103 * @return FALSE - Fatal error occurs.
104 */
105BOOLEAN
106MemMParallelTraining (
107 IN OUT MEM_MAIN_DATA_BLOCK *mmPtr
108 )
109{
110 AMD_CONFIG_PARAMS *StdHeader;
111 MEM_DATA_STRUCT *MemPtr;
112 MEM_NB_BLOCK *NBPtr;
113 DIE_INFO TrainInfo[MAX_NODES_SUPPORTED];
114 AP_DATA_TRANSFER ReturnData;
115 AGESA_STATUS Status;
116 UINT8 ApSts;
117 UINT8 Die;
118 UINT8 Socket;
119 UINT32 Module;
120 UINT32 LowCore;
121 UINT32 HighCore;
122 UINT32 Time;
123 UINT32 TimeOut;
124 UINT32 TargetApicId;
125 BOOLEAN StillTraining;
126 ALLOCATE_HEAP_PARAMS AllocHeapParams;
127 UINT8 *BufferPtr;
128 BOOLEAN TimeoutEn;
129
130 NBPtr = mmPtr->NBPtr;
131 MemPtr = mmPtr->MemPtr;
132 StdHeader = &(mmPtr->MemPtr->StdHeader);
133 Time = 0;
134 TimeOut = PARALLEL_TRAINING_TIMEOUT;
135 TimeoutEn = TRUE;
136 IDS_TIMEOUT_CTL (&TimeoutEn);
137
138 IDS_HDT_CONSOLE (MEM_STATUS, "\nStart parallel training\n");
139 AGESA_TESTPOINT (TpProcMemBeforeAnyTraining, StdHeader);
140 //
141 // Initialize Training Info Array
142 //
143 for (Die = 0; Die < mmPtr->DieCount; Die ++) {
144 Socket = TrainInfo[Die].Socket = NBPtr[Die].MCTPtr->SocketId;
145 Module = NBPtr[Die].MCTPtr->DieId;
146 GetGivenModuleCoreRange (Socket, Module, &LowCore, &HighCore, StdHeader);
147 TrainInfo[Die].Core = (UINT8) (LowCore & 0x000000FF);
148 IDS_HDT_CONSOLE (MEM_FLOW, "\tLaunch core %d of socket %d\n", LowCore, Socket);
149 TrainInfo[Die].Training = FALSE;
150 }
151 //
152 // Start Training on Each remote die.
153 //
154 for (Die = 0; Die < mmPtr->DieCount; Die ++ ) {
155 if (Die != BSP_DIE) {
156 NBPtr[Die].BeforeDqsTraining (&(mmPtr->NBPtr[Die]));
157 if (NBPtr[Die].MCTPtr->NodeMemSize != 0) {
158 if (!NBPtr[Die].FeatPtr->Training (&(mmPtr->NBPtr[Die]))) {
159 // Fail to launch code on AP
160 PutEventLog (AGESA_ERROR, MEM_ERROR_PARALLEL_TRAINING_LAUNCH_FAIL, NBPtr->Node, NBPtr->Dct, NBPtr->Channel, 0, &NBPtr->MemPtr->StdHeader);
161 SetMemError (AGESA_ERROR, NBPtr[Die].MCTPtr);
162 if (!MemPtr->ErrorHandling (NBPtr[Die].MCTPtr, EXCLUDE_ALL_DCT, EXCLUDE_ALL_CHIPSEL, &MemPtr->StdHeader)) {
163 ASSERT (FALSE);
164 }
165 } else {
166 TrainInfo[Die].Training = TRUE;
167 }
168 }
169 }
170 }
171 //
172 // Call training on BSP
173 //
174 IDS_HDT_CONSOLE (MEM_STATUS, "Node %d\n", NBPtr[BSP_DIE].Node);
175 NBPtr[BSP_DIE].BeforeDqsTraining (&(mmPtr->NBPtr[BSP_DIE]));
176 NBPtr[BSP_DIE].TrainingFlow (&(mmPtr->NBPtr[BSP_DIE]));
177 NBPtr[BSP_DIE].AfterDqsTraining (&(mmPtr->NBPtr[BSP_DIE]));
178
179 //
180 // Get Results from remote processors training
181 //
182 do {
183 StillTraining = FALSE;
184 for (Die = 0; Die < mmPtr->DieCount; Die ++ ) {
185 //
186 // For each Die that is training, read the status
187 //
188 if (TrainInfo[Die].Training == TRUE) {
189 GetLocalApicIdForCore (TrainInfo[Die].Socket, TrainInfo[Die].Core, &TargetApicId, StdHeader);
190 ApSts = ApUtilReadRemoteControlByte (TargetApicId, StdHeader);
191 if ((ApSts & 0x80) == 0) {
192 //
193 // Allocate buffer for received data
194 //
195 AllocHeapParams.RequestedBufferSize = (
196 sizeof (DIE_STRUCT) +
197 NBPtr[Die].DctCount * (
198 sizeof (DCT_STRUCT) + (
199 NBPtr[Die].ChannelCount * (
200 sizeof (CH_DEF_STRUCT) + sizeof (MEM_PS_BLOCK) + (
201 (NBPtr[Die].MCTPtr->DctData[0].ChData[0].RowCount *
202 NBPtr[Die].MCTPtr->DctData[0].ChData[0].ColumnCount *
203 NUMBER_OF_DELAY_TABLES) +
204 (MAX_BYTELANES_PER_CHANNEL * MAX_CS_PER_CHANNEL * NUMBER_OF_FAILURE_MASK_TABLES) +
205 (MAX_DIMMS_PER_CHANNEL * MAX_NUMBER_LANES)
206 )
207 )
208 )
209 )
210 ) + 3;
211 AllocHeapParams.BufferHandle = GENERATE_MEM_HANDLE (ALLOC_PAR_TRN_HANDLE, Die, 0, 0);
212 AllocHeapParams.Persist = HEAP_LOCAL_CACHE;
213 if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) == AGESA_SUCCESS) {
214 //
215 // Receive Training Results
216 //
217
218 ReturnData.DataPtr = AllocHeapParams.BufferPtr;
219 ReturnData.DataSizeInDwords = (UINT16) AllocHeapParams.RequestedBufferSize / 4;
220 ReturnData.DataTransferFlags = 0;
221 Status = ApUtilReceiveBuffer (TrainInfo[Die].Socket, TrainInfo[Die].Core, &ReturnData, StdHeader);
222 if (Status != AGESA_SUCCESS) {
223 SetMemError (Status, NBPtr[Die].MCTPtr);
224 }
225
226 BufferPtr = AllocHeapParams.BufferPtr;
227 LibAmdMemCopy (NBPtr[Die].MCTPtr, BufferPtr, sizeof (DIE_STRUCT), StdHeader);
228 BufferPtr += sizeof (DIE_STRUCT);
229 LibAmdMemCopy ( NBPtr[Die].MCTPtr->DctData,
230 BufferPtr,
231 NBPtr[Die].DctCount * (sizeof (DCT_STRUCT) + NBPtr[Die].ChannelCount * sizeof (CH_DEF_STRUCT)),
232 StdHeader);
233 BufferPtr += NBPtr[Die].DctCount * (sizeof (DCT_STRUCT) + NBPtr[Die].ChannelCount * sizeof (CH_DEF_STRUCT));
234 LibAmdMemCopy ( NBPtr[Die].PSBlock,
235 BufferPtr,
236 NBPtr[Die].DctCount * NBPtr[Die].ChannelCount * sizeof (MEM_PS_BLOCK),
237 StdHeader);
238 BufferPtr += NBPtr[Die].DctCount * NBPtr[Die].ChannelCount * sizeof (MEM_PS_BLOCK);
239 LibAmdMemCopy ( NBPtr[Die].MCTPtr->DctData[0].ChData[0].RcvEnDlys,
240 BufferPtr,
241 (NBPtr[Die].DctCount * NBPtr[Die].ChannelCount) *
242 ((NBPtr[Die].MCTPtr->DctData[0].ChData[0].RowCount *
243 NBPtr[Die].MCTPtr->DctData[0].ChData[0].ColumnCount *
244 NUMBER_OF_DELAY_TABLES) +
245 (MAX_BYTELANES_PER_CHANNEL * MAX_CS_PER_CHANNEL * NUMBER_OF_FAILURE_MASK_TABLES) +
246 (MAX_DIMMS_PER_CHANNEL * MAX_NUMBER_LANES)
247 ),
248 StdHeader);
249
250 HeapDeallocateBuffer (AllocHeapParams.BufferHandle, StdHeader);
251
252 NBPtr[Die].AfterDqsTraining (&(mmPtr->NBPtr[Die]));
253 TrainInfo[Die].Training = FALSE;
254 } else {
255 PutEventLog (AGESA_FATAL, MEM_ERROR_HEAP_ALLOCATE_FOR_RECEIVED_DATA, NBPtr[Die].Node, 0, 0, 0, StdHeader);
256 SetMemError (AGESA_FATAL, NBPtr[Die].MCTPtr);
257 ASSERT(FALSE); // Insufficient Heap Space allocation for parallel training buffer
258 }
259 } else if (ApSts == CORE_IDLE) {
260 // AP does not have buffer to transmit to BSP
261 // AP fails to locate a buffer for data transfer
262 TrainInfo[Die].Training = FALSE;
263 } else {
264 // Signal to loop through again
265 StillTraining = TRUE;
266 }
267 }
268 }
269 // Wait for 1 us
270 MemUWait10ns (100, NBPtr->MemPtr);
271 Time ++;
272 } while ((StillTraining) && ((Time < TimeOut) || !TimeoutEn)); // Continue until all Dies are finished
273 // if cannot finish in 1 s, do fatal exit
274
275 if (StillTraining && TimeoutEn) {
276 // Parallel training time out, do fatal exit, as there is at least one AP hangs.
277 PutEventLog (AGESA_FATAL, MEM_ERROR_PARALLEL_TRAINING_TIME_OUT, 0, 0, 0, 0, &NBPtr->MemPtr->StdHeader);
278 SetMemError (AGESA_FATAL, NBPtr[BSP_DIE].MCTPtr);
279 ASSERT(FALSE); // Timeout occurred while still training
280 }
281
282 for (Die = 0; Die < mmPtr->DieCount; Die ++ ) {
283 if (NBPtr[Die].MCTPtr->ErrCode == AGESA_FATAL) {
284 return FALSE;
285 }
286 }
287 return TRUE;
288}