Update AMD F14 Agesa to support Rev C0 cpus
[coreboot.git] / src / vendorcode / amd / agesa / f14 / Proc / Common / AmdInitPost.c
blob958d1e55989b1b879c06488927df667f214d8216
1 /* $NoKeywords:$ */
2 /**
3 * @file
5 * AMD AGESA Basic Level Public APIs
7 * Contains basic Level Initialization routines.
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: Interface
12 * @e \$Revision: 37437 $ @e \$Date: 2010-09-04 01:15:21 +0800 (Sat, 04 Sep 2010) $
16 *****************************************************************************
18 * Copyright (c) 2011, 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 /*----------------------------------------------------------------------------------------
49 * M O D U L E S U S E D
50 *----------------------------------------------------------------------------------------
52 #include "AGESA.h"
53 #include "amdlib.h"
54 #include "mm.h"
55 #include "Ids.h"
56 #include "cpuRegisters.h"
57 #include "cpuServices.h"
58 #include "cpuPostInit.h"
59 #include "AdvancedApi.h"
60 #include "CreateStruct.h"
61 #include "heapManager.h"
62 #include "CommonInits.h"
63 #include "cpuServices.h"
64 #include "GnbInterface.h"
65 #include "Filecode.h"
66 CODE_GROUP (G1_PEICC)
67 RDATA_GROUP (G1_PEICC)
69 #define FILECODE PROC_COMMON_AMDINITPOST_FILECODE
70 /*----------------------------------------------------------------------------------------
71 * D E F I N I T I O N S A N D M A C R O S
72 *----------------------------------------------------------------------------------------
76 /*----------------------------------------------------------------------------------------
77 * T Y P E D E F S A N D S T R U C T U R E S
78 *----------------------------------------------------------------------------------------
82 /*----------------------------------------------------------------------------------------
83 * P R O T O T Y P E S O F L O C A L F U N C T I O N S
84 *----------------------------------------------------------------------------------------
87 AGESA_STATUS
88 AmdPostPlatformConfigInit (
89 IN OUT PLATFORM_CONFIGURATION *PlatformConfig,
90 IN OUT AMD_CONFIG_PARAMS *StdHeader
93 /*----------------------------------------------------------------------------------------
94 * E X P O R T E D F U N C T I O N S
95 *----------------------------------------------------------------------------------------
98 extern BUILD_OPT_CFG UserOptions;
100 /*------------------------------------------------------------------------------------*/
102 * Initialize AmdInitPost stage platform profile and user option input.
104 * @param[in,out] PlatformConfig Platform profile/build option config structure
105 * @param[in,out] StdHeader AMD standard header config param
107 * @retval AGESA_SUCCESS Always Succeeds.
110 AGESA_STATUS
111 AmdPostPlatformConfigInit (
112 IN OUT PLATFORM_CONFIGURATION *PlatformConfig,
113 IN OUT AMD_CONFIG_PARAMS *StdHeader
116 CommonPlatformConfigInit (PlatformConfig, StdHeader);
118 return AGESA_SUCCESS;
122 *---------------------------------------------------------------------------------------
124 * AmdInitPostInitializer
126 * Initializer routine that will be invoked by the wrapper
127 * to initialize the input structure for the AmdInitPost
129 * @param[in, out] IN OUT AMD_POST_PARAMS *PostParamsPtr
131 * @retval AGESA_STATUS
133 *---------------------------------------------------------------------------------------
135 AGESA_STATUS
136 AmdInitPostInitializer (
137 IN AMD_CONFIG_PARAMS *StdHeader,
138 IN OUT AMD_POST_PARAMS *PostParamsPtr
141 AGESA_STATUS AgesaStatus;
142 ALLOCATE_HEAP_PARAMS AllocHeapParams;
144 ASSERT (StdHeader != NULL);
145 ASSERT (PostParamsPtr != NULL);
147 PostParamsPtr->StdHeader = *StdHeader;
149 AllocHeapParams.RequestedBufferSize = sizeof (MEM_DATA_STRUCT);
150 AllocHeapParams.BufferHandle = AMD_MEM_DATA_HANDLE;
151 AllocHeapParams.Persist = HEAP_LOCAL_CACHE;
152 AgesaStatus = HeapAllocateBuffer (&AllocHeapParams, &PostParamsPtr->StdHeader);
154 if (AgesaStatus == AGESA_SUCCESS) {
155 PostParamsPtr->MemConfig.MemData = (MEM_DATA_STRUCT *) AllocHeapParams.BufferPtr;
156 PostParamsPtr->MemConfig.MemData->ParameterListPtr = &(PostParamsPtr->MemConfig);
157 PostParamsPtr->MemConfig.MemData->StdHeader = PostParamsPtr->StdHeader;
158 AmdPostPlatformConfigInit (&PostParamsPtr->PlatformConfig, &PostParamsPtr->StdHeader);
159 AmdMemInitDataStructDef (PostParamsPtr->MemConfig.MemData, &PostParamsPtr->PlatformConfig);
161 return AgesaStatus;
165 *---------------------------------------------------------------------------------------
167 * AmdInitPostDestructor
169 * Destruct routine that provide a chance if something need to be done
170 * before the end of AmdInitPost.
172 * @param[in] StdHeader The standard header.
173 * @param[in] PostParamsPtr AMD init post param.
175 * @retval AGESA_STATUS
177 *---------------------------------------------------------------------------------------
179 AGESA_STATUS
180 AmdInitPostDestructor (
181 IN AMD_CONFIG_PARAMS *StdHeader,
182 IN AMD_POST_PARAMS *PostParamsPtr
186 ASSERT (PostParamsPtr != NULL);
188 PostParamsPtr->StdHeader = *StdHeader;
189 PostParamsPtr->MemConfig.MemData->StdHeader = *StdHeader;
192 // AmdMemAuto completed. Here, release heap space which is used for memory init.
194 MemAmdFinalize (PostParamsPtr->MemConfig.MemData);
195 HeapDeallocateBuffer (AMD_MEM_DATA_HANDLE, StdHeader);
198 // AmdCpuPost completed.
200 if (PostParamsPtr->MemConfig.SysLimit != 0) {
201 // WBINVD can only be executed when memory is available
202 FinalizeAtPost (StdHeader);
205 return AGESA_SUCCESS;
208 /*---------------------------------------------------------------------------------------*/
210 * Main entry point for the AMD_INIT_POST function.
212 * This entry point is responsible for initializing all system memory,
213 * gathering important data out of the pre-memory cache storage into a
214 * temporary holding buffer in main memory. After that APs will be
215 * shutdown in preparation for the host environment to take control.
216 * Note: pre-memory stack will be disabled also.
218 * @param[in,out] PostParams Required input parameters for the AMD_INIT_POST
219 * entry point.
221 * @return Aggregated status across all internal AMD POST calls invoked.
224 AGESA_STATUS
225 AmdInitPost (
226 IN OUT AMD_POST_PARAMS *PostParams
229 AGESA_STATUS AgesaStatus;
230 AGESA_STATUS AmdInitPostStatus;
231 WARM_RESET_REQUEST Request;
232 UINT8 PrevRequestBit;
233 UINT8 PrevStateBits;
235 AGESA_TESTPOINT (TpIfAmdInitPostEntry, &PostParams->StdHeader);
236 IDS_HDT_CONSOLE (MAIN_FLOW, "AmdInitPost: Start\n\n");
237 IDS_PERF_TIME_MEASURE (&PostParams->StdHeader);
239 ASSERT (PostParams != NULL);
240 AmdInitPostStatus = AGESA_SUCCESS;
241 PrevRequestBit = FALSE;
242 PrevStateBits = WR_STATE_COLD;
244 IDS_OPTION_HOOK (IDS_INIT_POST_BEFORE, PostParams, &PostParams->StdHeader);
246 IDS_OPTION_HOOK (IDS_BEFORE_MEM_INIT, PostParams, &PostParams->StdHeader);
248 // If a previously requested warm reset cannot be triggered in the
249 // current stage, store the previous state of request and reset the
250 // request struct to the current post stage
251 GetWarmResetFlag (&PostParams->StdHeader, &Request);
252 if (Request.RequestBit == TRUE) {
253 if (Request.StateBits >= Request.PostStage) {
254 PrevRequestBit = Request.RequestBit;
255 PrevStateBits = Request.StateBits;
256 Request.RequestBit = FALSE;
257 Request.StateBits = Request.PostStage - 1;
258 SetWarmResetFlag (&PostParams->StdHeader, &Request);
262 AgesaStatus = GnbInitAtPost (PostParams);
263 if (AgesaStatus > AmdInitPostStatus) {
264 AmdInitPostStatus = AgesaStatus;
267 IDS_HDT_CONSOLE (MAIN_FLOW, "AmdMemAuto: Start\n");
268 AgesaStatus = AmdMemAuto (PostParams->MemConfig.MemData);
269 IDS_HDT_CONSOLE (MAIN_FLOW, "AmdMemAuto: End\n");
270 if (AgesaStatus > AmdInitPostStatus) {
271 AmdInitPostStatus = AgesaStatus;
274 if (AgesaStatus != AGESA_FATAL) {
276 IDS_OPTION_HOOK (IDS_INIT_POST_MID, PostParams, &PostParams->StdHeader);
278 // Check BIST status
279 AgesaStatus = CheckBistStatus (&PostParams->StdHeader);
280 if (AgesaStatus > AmdInitPostStatus) {
281 AmdInitPostStatus = AgesaStatus;
285 // P-State data gathered, then, Relinquish APs
287 IDS_HDT_CONSOLE (MAIN_FLOW, "AmdCpuPost: Start\n");
288 AgesaStatus = AmdCpuPost (&PostParams->StdHeader, &PostParams->PlatformConfig);
289 IDS_HDT_CONSOLE (MAIN_FLOW, "AmdCpuPost: End\n");
290 if (AgesaStatus > AmdInitPostStatus) {
291 AmdInitPostStatus = AgesaStatus;
294 // Warm Reset
295 GetWarmResetFlag (&PostParams->StdHeader, &Request);
296 // If a warm reset is requested in the current post stage, trigger the
297 // warm reset and ignore the previous request
298 if (Request.RequestBit == TRUE) {
299 if (Request.StateBits < Request.PostStage) {
300 AgesaDoReset (WARM_RESET_WHENEVER, &PostParams->StdHeader);
302 } else {
303 // Otherwise, if there's a previous request, restore it
304 // so that the subsequent post stage can trigger the warm reset
305 if (PrevRequestBit == TRUE) {
306 Request.RequestBit = PrevRequestBit;
307 Request.StateBits = PrevStateBits;
308 SetWarmResetFlag (&PostParams->StdHeader, &Request);
312 AgesaStatus = GnbInitAtPostAfterDram (PostParams);
313 if (AgesaStatus > AmdInitPostStatus) {
314 AmdInitPostStatus = AgesaStatus;
317 IDS_OPTION_HOOK (IDS_INIT_POST_AFTER, PostParams, &PostParams->StdHeader);
319 IDS_PERF_TIME_MEASURE (&PostParams->StdHeader);
320 AGESA_TESTPOINT (TpIfAmdInitPostExit, &PostParams->StdHeader);
321 IDS_HDT_CONSOLE (MAIN_FLOW, "\nAmdInitPost: End\n\n");
322 IDS_HDT_CONSOLE (MAIN_FLOW, "Heap transfer Start ...\n\n");
324 //For Heap will be relocate to new address in next stage, flush out debug print buffer if needed
325 IDS_HDT_CONSOLE_FLUSH_BUFFER (&PostParams->StdHeader);
327 // Copies BSP heap content to RAM, and it should be at the end of AmdInitPost
328 AgesaStatus = CopyHeapToTempRamAtPost (&(PostParams->StdHeader));
329 if (AgesaStatus > AmdInitPostStatus) {
330 AmdInitPostStatus = AgesaStatus;
332 PostParams->StdHeader.HeapStatus = HEAP_TEMP_MEM;
334 // Check for Cache As Ram Corruption
335 IDS_CAR_CORRUPTION_CHECK (&PostParams->StdHeader);
337 // At the end of AmdInitPost, set StateBits to POST to allow any warm reset that occurs outside
338 // of AGESA to be recognized by IsWarmReset()
339 GetWarmResetFlag (&PostParams->StdHeader, &Request);
340 Request.StateBits = Request.PostStage;
341 SetWarmResetFlag (&PostParams->StdHeader, &Request);
343 return AmdInitPostStatus;