blob: 403233292aa6ed83e3dedcf483023d93f2aaec06 [file] [log] [blame]
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001/* $NoKeywords:$ */
2/**
3 * @file
4 *
5 * AMD AGESA Basic Level Public APIs
6 *
7 * Contains basic Level Initialization routines.
8 *
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: Interface
12 * @e \$Revision: 35136 $ @e \$Date: 2010-07-16 11:29:48 +0800 (Fri, 16 Jul 2010) $
13 *
14 */
15/*
16 *****************************************************************************
17 *
18 * Copyright (c) 2011, Advanced Micro Devices, Inc.
19 * All rights reserved.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100020 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000021 * 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.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100028 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
29 * its contributors may be used to endorse or promote products derived
Frank Vibrans2b4c8312011-02-14 18:30:54 +000030 * from this software without specific prior written permission.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100031 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000032 * 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.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100042 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000043 * ***************************************************************************
44 *
45 */
46
47
48/*----------------------------------------------------------------------------------------
49 * M O D U L E S U S E D
50 *----------------------------------------------------------------------------------------
51 */
52#include "AGESA.h"
53#include "amdlib.h"
54#include "Ids.h"
55#include "cpuCacheInit.h"
56#include "cpuRegisters.h"
57#include "cpuApicUtilities.h"
58#include "cpuEarlyInit.h"
59#include "AdvancedApi.h"
60#include "cpuServices.h"
61#include "CommonInits.h"
62#include "GnbInterface.h"
efdesign9884cbce22011-08-04 12:09:17 -060063//#include "GnbInitAtEarly.h"
Frank Vibrans2b4c8312011-02-14 18:30:54 +000064#include "Filecode.h"
65CODE_GROUP (G1_PEICC)
66RDATA_GROUP (G1_PEICC)
67
68#define FILECODE PROC_COMMON_AMDINITEARLY_FILECODE
69/*----------------------------------------------------------------------------------------
70 * D E F I N I T I O N S A N D M A C R O S
71 *----------------------------------------------------------------------------------------
72 */
73
74
75/*----------------------------------------------------------------------------------------
76 * T Y P E D E F S A N D S T R U C T U R E S
77 *----------------------------------------------------------------------------------------
78 */
Arthur Heymans704ccaf2022-05-16 14:55:46 +020079CONST EXECUTION_CACHE_REGION InitExeCacheMap[] =
Frank Vibrans2b4c8312011-02-14 18:30:54 +000080{
81 {0x00000000, 0x00000000},
82 {0x00000000, 0x00000000},
83 {0x00000000, 0x00000000}
84};
85
86/*----------------------------------------------------------------------------------------
87 * 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
88 *----------------------------------------------------------------------------------------
89 */
90
efdesign9884cbce22011-08-04 12:09:17 -060091AGESA_STATUS
92AmdEarlyPlatformConfigInit (
93 IN OUT PLATFORM_CONFIGURATION *PlatformConfig,
94 IN OUT AMD_CONFIG_PARAMS *StdHeader
95 );
96
97AGESA_STATUS
98AllocateExecutionCacheInitializer (
99 IN AMD_CONFIG_PARAMS *StdHeader,
100 IN EXECUTION_CACHE_REGION *AmdExeAddrMapPtr
101 );
102
103AGESA_STATUS
104AmdInitEarlyInitializer (
105 IN AMD_CONFIG_PARAMS *StdHeader,
106 IN OUT AMD_EARLY_PARAMS *EarlyParams
107 );
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000108
109/*----------------------------------------------------------------------------------------
110 * E X P O R T E D F U N C T I O N S
111 *----------------------------------------------------------------------------------------
112 */
113extern BUILD_OPT_CFG UserOptions;
114/*------------------------------------------------------------------------------------*/
115/**
116 * Initialize AmdInitEarly stage platform profile and user option input.
117 *
118 * @param[in,out] PlatformConfig Platform profile/build option config structure
119 * @param[in,out] StdHeader AMD standard header config param
120 *
121 * @retval AGESA_SUCCESS Always Succeeds.
122 *
123 */
124AGESA_STATUS
125AmdEarlyPlatformConfigInit (
126 IN OUT PLATFORM_CONFIGURATION *PlatformConfig,
127 IN OUT AMD_CONFIG_PARAMS *StdHeader
128 )
129{
130 CommonPlatformConfigInit (PlatformConfig, StdHeader);
131
132 return AGESA_SUCCESS;
133}
134/*------------------------------------------------------------------------------------*/
135/**
136 * Initializer routine that will be invoked by the wrapper to initialize the input
137 * structure for the AllocateExecutionCache.
138 *
139 * @param[in] StdHeader Opaque handle to standard config header
140 * @param[in] AmdExeAddrMapPtr Our Service interface struct
141 *
142 * @retval AGESA_SUCCESS Always Succeeds.
143 *
144 */
145AGESA_STATUS
146AllocateExecutionCacheInitializer (
147 IN AMD_CONFIG_PARAMS *StdHeader,
148 IN EXECUTION_CACHE_REGION *AmdExeAddrMapPtr
149 )
150{
151 UINT8 i;
152 ASSERT (AmdExeAddrMapPtr != NULL);
153
154 for (i = 0; i < MAX_CACHE_REGIONS; ++i) {
155 AmdExeAddrMapPtr[i].ExeCacheStartAddr = InitExeCacheMap[i].ExeCacheStartAddr;
156 AmdExeAddrMapPtr[i].ExeCacheSize = InitExeCacheMap[i].ExeCacheSize;
157 }
158
159 return AGESA_SUCCESS;
160}
161
162/*---------------------------------------------------------------------------------------*/
163/**
164 *
165 * Initializer routine that will be invoked by the wrapper to initialize the input
166 * structure for the AmdInitEarly.
167 *
168 * @param[in] StdHeader AMD standard header config param.
169 * @param[in,out] EarlyParams The service interface struct to initialize.
170 *
171 * @retval AGESA_SUCCESS Always succeeds.
172 */
173AGESA_STATUS
174AmdInitEarlyInitializer (
175 IN AMD_CONFIG_PARAMS *StdHeader,
176 IN OUT AMD_EARLY_PARAMS *EarlyParams
177 )
178{
179 ASSERT (StdHeader != NULL);
180 ASSERT (EarlyParams != NULL);
181
182 EarlyParams->StdHeader = *StdHeader;
183
184 // We don't check any AGESA_STATUS from the called constructors, since they MUST all SUCCEED.
185 //
186
187 AllocateExecutionCacheInitializer (&EarlyParams->StdHeader, &EarlyParams->CacheRegion[0]);
188
189 AmdHtInterfaceConstructor (&EarlyParams->StdHeader, &EarlyParams->HtConfig);
190
191 AmdEarlyPlatformConfigInit (&EarlyParams->PlatformConfig, &EarlyParams->StdHeader);
192
193 return AGESA_SUCCESS;
194}
195
196
197/*---------------------------------------------------------------------------------------*/
198/**
199 * Perform initialization services required at the Early Init POST time point.
200 *
201 * Execution Cache, HyperTransport, and AP Init advanced services are performed.
202 *
203 * @param[in] EarlyParams The interface struct for all early services
204 *
205 * @return The most severe AGESA_STATUS returned by any called service.
206 *
207 */
208AGESA_STATUS
209AmdInitEarly (
210 IN OUT AMD_EARLY_PARAMS *EarlyParams
211 )
212{
213 AGESA_STATUS CalledAgesaStatus;
214 AGESA_STATUS EarlyInitStatus;
215 WARM_RESET_REQUEST Request;
216 UINT8 PrevRequestBit;
217 UINT8 PrevStateBits;
218
219 AGESA_TESTPOINT (TpIfAmdInitEarlyEntry, &EarlyParams->StdHeader);
220 IDS_PERF_TIME_MEASURE (&EarlyParams->StdHeader);
221 ASSERT (EarlyParams != NULL);
222 EarlyInitStatus = AGESA_SUCCESS;
223 PrevRequestBit = FALSE;
224 PrevStateBits = WR_STATE_COLD;
225 IDS_HDT_CONSOLE (MAIN_FLOW, "AmdInitEarly: Start %x \n\n", PrevStateBits);
226 // If a previously requested warm reset cannot be triggered in the
227 // current stage, store the previous state of request and reset the
228 // request struct to the current post stage
229 GetWarmResetFlag (&EarlyParams->StdHeader, &Request);
230 if (Request.RequestBit == TRUE) {
231 if (Request.StateBits >= Request.PostStage) {
232 PrevRequestBit = Request.RequestBit;
233 PrevStateBits = Request.StateBits;
234 Request.RequestBit = FALSE;
235 Request.StateBits = Request.PostStage - 1;
236 SetWarmResetFlag (&EarlyParams->StdHeader, &Request);
237 }
238 }
239
240 IDS_OPTION_HOOK (IDS_INIT_EARLY_BEFORE, EarlyParams, &EarlyParams->StdHeader);
241
242 // Setup ROM execution cache
243 IDS_HDT_CONSOLE (MAIN_FLOW, "AllocateExecutionCache: Start\n");
244 CalledAgesaStatus = AllocateExecutionCache (&EarlyParams->StdHeader, &EarlyParams->CacheRegion[0]);
245 IDS_HDT_CONSOLE (MAIN_FLOW, "AllocateExecutionCache: End\n");
246 if (CalledAgesaStatus > EarlyInitStatus) {
247 EarlyInitStatus = CalledAgesaStatus;
248 }
249
250 // Full Hypertransport Initialization
251 // IMPORTANT: All AP cores call Ht Init. HT Init handles full init for the BSC, and map init for APs.
252 IDS_HDT_CONSOLE (MAIN_FLOW, "AmdHtInitialize: Start\n");
253 CalledAgesaStatus = AmdHtInitialize (&EarlyParams->StdHeader, &EarlyParams->PlatformConfig, &EarlyParams->HtConfig);
254 IDS_HDT_CONSOLE (MAIN_FLOW, "AmdHtInitialize: End\n");
255 if (CalledAgesaStatus > EarlyInitStatus) {
256 EarlyInitStatus = CalledAgesaStatus;
257 }
258
259 // AP launch
260 IDS_HDT_CONSOLE (MAIN_FLOW, "AmdCpuEarly: Start\n");
261 CalledAgesaStatus = AmdCpuEarly (&EarlyParams->StdHeader, &EarlyParams->PlatformConfig);
262 IDS_HDT_CONSOLE (MAIN_FLOW, "AmdCpuEarly: End\n");
263 if (CalledAgesaStatus > EarlyInitStatus) {
264 EarlyInitStatus = CalledAgesaStatus;
265 }
266
267 // Warm Reset, should be at the end of AmdInitEarly
268 GetWarmResetFlag (&EarlyParams->StdHeader, &Request);
269 // If a warm reset is requested in the current post stage, trigger the
270 // warm reset and ignore the previous request
271 if (Request.RequestBit == TRUE) {
272 if (Request.StateBits < Request.PostStage) {
273 AgesaDoReset (WARM_RESET_WHENEVER, &EarlyParams->StdHeader);
274 }
275 } else {
276 // Otherwise, if there's a previous request, restore it
277 // so that the subsequent post stage can trigger the warm reset
278 if (PrevRequestBit == TRUE) {
279 Request.RequestBit = PrevRequestBit;
280 Request.StateBits = PrevStateBits;
281 SetWarmResetFlag (&EarlyParams->StdHeader, &Request);
282 }
283 }
284
285 CalledAgesaStatus = GnbInitAtEarly (EarlyParams);
286
287 if (CalledAgesaStatus > EarlyInitStatus) {
288 EarlyInitStatus = CalledAgesaStatus;
289 }
290 // Check for Cache As Ram Corruption
291 IDS_CAR_CORRUPTION_CHECK (&EarlyParams->StdHeader);
292
293 IDS_OPTION_HOOK (IDS_BEFORE_WARM_RESET, EarlyParams, &EarlyParams->StdHeader);
294 IDS_OPTION_HOOK (IDS_INIT_EARLY_AFTER, EarlyParams, &EarlyParams->StdHeader);
295 IDS_PERF_TIME_MEASURE (&EarlyParams->StdHeader);
296 AGESA_TESTPOINT (TpIfAmdInitEarlyExit, &EarlyParams->StdHeader);
297 IDS_HDT_CONSOLE (MAIN_FLOW, "\nAmdInitEarly: End\n\n");
298 return EarlyInitStatus;
299}