blob: 9fc8ab9b5a3dd2cd623944e7a74b90d6d40e0c81 [file] [log] [blame]
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +03001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 - 2012 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <stdint.h>
21#include <string.h>
22#include <cpu/x86/mtrr.h>
23#include <northbridge/amd/agesa/agesawrapper.h>
24#include <northbridge/amd/agesa/BiosCallOuts.h>
25#include "cpuRegisters.h"
26#include "cpuCacheInit.h"
27#include "cpuApicUtilities.h"
28#include "cpuEarlyInit.h"
29#include "cpuLateInit.h"
30#include "Dispatcher.h"
31#include "cpuCacheInit.h"
32#include "amdlib.h"
33#include "Filecode.h"
34#include "heapManager.h"
35#include <cpuFamilyTranslation.h> /* CPU_SPECIFIC_SERVICES */
36
37#define FILECODE UNASSIGNED_FILE_FILECODE
38
39/* ACPI table pointers returned by AmdInitLate */
40VOID *DmiTable = NULL;
41VOID *AcpiPstate = NULL;
42VOID *AcpiSrat = NULL;
43VOID *AcpiSlit = NULL;
44
45VOID *AcpiWheaMce = NULL;
46VOID *AcpiWheaCmc = NULL;
47VOID *AcpiAlib = NULL;
48
49/* TODO: Function body should be in mainboard directory. */
Kyösti Mälkki34ad72c2014-10-21 13:43:46 +030050void OemCustomizeInitEarly(AMD_EARLY_PARAMS *InitEarly)
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +030051{
52}
53
Kyösti Mälkki34ad72c2014-10-21 13:43:46 +030054void OemCustomizeInitPost(AMD_POST_PARAMS *InitPost)
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +030055{
56#if IS_ENABLED(CONFIG_BOARD_AMD_DINAR)
57 InitPost->MemConfig.UmaMode = UMA_AUTO;
58 InitPost->MemConfig.BottomIo = 0xE0;
59 InitPost->MemConfig.UmaSize = 0xE0-0xC0;
60#endif
61}
62
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +030063AGESA_STATUS agesawrapper_amdinitreset(void)
64{
65 AGESA_STATUS status = AGESA_SUCCESS;
66 AMD_INTERFACE_PARAMS AmdParamStruct;
67 AMD_RESET_PARAMS AmdResetParams;
68
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +020069 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
70 memset(&AmdResetParams, 0, sizeof(AMD_RESET_PARAMS));
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +030071
72 AmdParamStruct.AgesaFunctionName = AMD_INIT_RESET;
73 AmdParamStruct.AllocationMethod = ByHost;
74 AmdParamStruct.NewStructSize = sizeof(AMD_RESET_PARAMS);
75 AmdParamStruct.NewStructPtr = &AmdResetParams;
76 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
77 AmdParamStruct.StdHeader.CalloutPtr = NULL;
78 AmdParamStruct.StdHeader.Func = 0;
79 AmdParamStruct.StdHeader.ImageBasePtr = 0;
80 status = AmdCreateStruct(&AmdParamStruct);
81 if (status != AGESA_SUCCESS) {
82 return status;
83 }
84 AmdResetParams.HtConfig.Depth = 0;
85
86 //MARG34PI disabled AGESA_ENTRY_INIT_RESET by default
87 //but we need to call AmdCreateStruct to call HeapManagerInit, or the event log not work
88#if (defined AGESA_ENTRY_INIT_RESET) && (AGESA_ENTRY_INIT_RESET == TRUE)
89 status = AmdInitReset((AMD_RESET_PARAMS *) AmdParamStruct.NewStructPtr);
90#endif
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030091 AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader);
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +030092 AmdReleaseStruct(&AmdParamStruct);
93
94 return status;
95}
96
97AGESA_STATUS agesawrapper_amdinitearly(void)
98{
99 AGESA_STATUS status;
100 AMD_INTERFACE_PARAMS AmdParamStruct;
101 AMD_EARLY_PARAMS *AmdEarlyParamsPtr;
102 UINT32 TscRateInMhz;
103 CPU_SPECIFIC_SERVICES *FamilySpecificServices;
104
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200105 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300106
107 AmdParamStruct.AgesaFunctionName = AMD_INIT_EARLY;
108 AmdParamStruct.AllocationMethod = PreMemHeap;
109 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
110 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
111 AmdParamStruct.StdHeader.Func = 0;
112 AmdParamStruct.StdHeader.ImageBasePtr = 0;
113 status = AmdCreateStruct(&AmdParamStruct);
114 if (status != AGESA_SUCCESS) {
115 return status;
116 }
117
118 AmdEarlyParamsPtr = (AMD_EARLY_PARAMS *) AmdParamStruct.NewStructPtr;
119
120 /* OEM Should Customize the defaults through this hook */
121 OemCustomizeInitEarly(AmdEarlyParamsPtr);
122
123 status = AmdInitEarly(AmdEarlyParamsPtr);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300124 AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader);
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300125
126 GetCpuServicesOfCurrentCore((CONST CPU_SPECIFIC_SERVICES **) & FamilySpecificServices,
127 &AmdParamStruct.StdHeader);
128 FamilySpecificServices->GetTscRate(FamilySpecificServices, &TscRateInMhz, &AmdParamStruct.StdHeader);
129 printk(BIOS_DEBUG, "BSP Frequency: %uMHz\n", (unsigned int)TscRateInMhz);
130
131 AmdReleaseStruct(&AmdParamStruct);
132 return status;
133}
134
135AGESA_STATUS agesawrapper_amdinitpost(void)
136{
137 AGESA_STATUS status;
138 AMD_INTERFACE_PARAMS AmdParamStruct;
139 AMD_POST_PARAMS *PostParams;
140 UINT32 TscRateInMhz;
141 CPU_SPECIFIC_SERVICES *FamilySpecificServices;
142
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200143 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300144
145 AmdParamStruct.AgesaFunctionName = AMD_INIT_POST;
146 AmdParamStruct.AllocationMethod = PreMemHeap;
147 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
148 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
149 AmdParamStruct.StdHeader.Func = 0;
150 AmdParamStruct.StdHeader.ImageBasePtr = 0;
151
152 status = AmdCreateStruct(&AmdParamStruct);
153 if (status != AGESA_SUCCESS) {
154 return status;
155 }
156 PostParams = (AMD_POST_PARAMS *) AmdParamStruct.NewStructPtr;
157
158 /* OEM Should Customize the defaults through this hook */
159 OemCustomizeInitPost(PostParams);
160
161 status = AmdInitPost(PostParams);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300162 AGESA_EVENTLOG(status, &PostParams->StdHeader);
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300163
164 AmdReleaseStruct(&AmdParamStruct);
165
166 /* Initialize heap space */
167 EmptyHeap();
168
169 GetCpuServicesOfCurrentCore((CONST CPU_SPECIFIC_SERVICES **) & FamilySpecificServices,
170 &AmdParamStruct.StdHeader);
171 FamilySpecificServices->GetTscRate(FamilySpecificServices, &TscRateInMhz, &AmdParamStruct.StdHeader);
172 printk(BIOS_DEBUG, "BSP Frequency: %uMHz\n", (unsigned int)TscRateInMhz);
173
174 return status;
175}
176
177AGESA_STATUS agesawrapper_amdinitenv(void)
178{
179 AGESA_STATUS status;
180 AMD_INTERFACE_PARAMS AmdParamStruct;
181 AMD_ENV_PARAMS *EnvParams;
182
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200183 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300184
185 AmdParamStruct.AgesaFunctionName = AMD_INIT_ENV;
186 AmdParamStruct.AllocationMethod = PostMemDram;
187 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
188 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
189 AmdParamStruct.StdHeader.Func = 0;
190 AmdParamStruct.StdHeader.ImageBasePtr = 0;
191
192 status = AmdCreateStruct(&AmdParamStruct);
193 if (status != AGESA_SUCCESS) {
194 return status;
195 }
196 EnvParams = (AMD_ENV_PARAMS *) AmdParamStruct.NewStructPtr;
197 status = AmdInitEnv(EnvParams);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300198 AGESA_EVENTLOG(status, &EnvParams->StdHeader);
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300199
200 AmdReleaseStruct(&AmdParamStruct);
201 return status;
202}
203
204VOID *agesawrapper_getlateinitptr(int pick)
205{
206 switch (pick) {
207 case PICK_DMI:
208 return DmiTable;
209
210 case PICK_PSTATE:
211 return AcpiPstate;
212
213 case PICK_SRAT:
214 return AcpiSrat;
215
216 case PICK_SLIT:
217 return AcpiSlit;
218 case PICK_WHEA_MCE:
219 return AcpiWheaMce;
220 case PICK_WHEA_CMC:
221 return AcpiWheaCmc;
222 case PICK_ALIB:
223 return AcpiAlib;
224 default:
225 return NULL;
226 }
227
228 return NULL;
229}
230
231AGESA_STATUS agesawrapper_amdinitmid(void)
232{
233 AGESA_STATUS status;
234 AMD_INTERFACE_PARAMS AmdParamStruct;
235
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200236 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300237
238 AmdParamStruct.AgesaFunctionName = AMD_INIT_MID;
239 AmdParamStruct.AllocationMethod = PostMemDram;
240 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
241 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
242 AmdParamStruct.StdHeader.Func = 0;
243 AmdParamStruct.StdHeader.ImageBasePtr = 0;
244
245 status = AmdCreateStruct(&AmdParamStruct);
246 if (status != AGESA_SUCCESS) {
247 return status;
248 }
249 status = AmdInitMid((AMD_MID_PARAMS *) AmdParamStruct.NewStructPtr);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300250 AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader);
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300251 AmdReleaseStruct(&AmdParamStruct);
252
253 return status;
254}
255
256AGESA_STATUS agesawrapper_amdinitlate(void)
257{
258 AGESA_STATUS status;
259 AMD_INTERFACE_PARAMS AmdParamStruct;
260 AMD_LATE_PARAMS *AmdLateParamsPtr;
261
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200262 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300263
264 AmdParamStruct.AgesaFunctionName = AMD_INIT_LATE;
265 AmdParamStruct.AllocationMethod = PostMemDram;
266 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
267 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
268 AmdParamStruct.StdHeader.Func = 0;
269 AmdParamStruct.StdHeader.ImageBasePtr = 0;
270
271 AmdCreateStruct(&AmdParamStruct);
272 AmdLateParamsPtr = (AMD_LATE_PARAMS *) AmdParamStruct.NewStructPtr;
273
274 printk(BIOS_DEBUG, "agesawrapper_amdinitlate: AmdLateParamsPtr = %X\n", (u32) AmdLateParamsPtr);
275
276 status = AmdInitLate(AmdLateParamsPtr);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300277 AGESA_EVENTLOG(status, &AmdLateParamsPtr->StdHeader);
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300278 ASSERT(status == AGESA_SUCCESS);
279
280 DmiTable = AmdLateParamsPtr->DmiTable;
281 AcpiPstate = AmdLateParamsPtr->AcpiPState;
282 AcpiSrat = AmdLateParamsPtr->AcpiSrat;
283 AcpiSlit = AmdLateParamsPtr->AcpiSlit;
284 AcpiWheaMce = AmdLateParamsPtr->AcpiWheaMce;
285 AcpiWheaCmc = AmdLateParamsPtr->AcpiWheaCmc;
286 AcpiAlib = AmdLateParamsPtr->AcpiAlib;
287
288 printk(BIOS_DEBUG, "In %s, AGESA generated ACPI tables:\n"
289 " DmiTable:%p\n AcpiPstate: %p\n AcpiSrat:%p\n AcpiSlit:%p\n"
290 " Mce:%p\n Cmc:%p\n Alib:%p\n",
291 __func__, DmiTable, AcpiPstate, AcpiSrat, AcpiSlit, AcpiWheaMce, AcpiWheaCmc, AcpiAlib);
292
293 /* Don't release the structure until coreboot has copied the ACPI tables.
294 * AmdReleaseStruct (&AmdLateParams);
295 */
296
297 return status;
298}
299
300/**
301 * @param[in] UINTN ApicIdOfCore,
302 * @param[in] AP_EXE_PARAMS *LaunchApParams
303 */
304AGESA_STATUS agesawrapper_amdlaterunaptask(UINT32 Func, UINT32 Data, VOID * ConfigPtr)
305{
306 AGESA_STATUS status;
307 AMD_LATE_PARAMS AmdLateParams;
308
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200309 memset(&AmdLateParams, 0, sizeof(AMD_LATE_PARAMS));
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300310
311 AmdLateParams.StdHeader.AltImageBasePtr = 0;
312 AmdLateParams.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
313 AmdLateParams.StdHeader.Func = 0;
314 AmdLateParams.StdHeader.ImageBasePtr = 0;
315 AmdLateParams.StdHeader.HeapStatus = HEAP_TEMP_MEM;
316
317 printk(BIOS_DEBUG, "AmdLateRunApTask on Core: %x\n", (uint32_t) Data);
318 status = AmdLateRunApTask((AP_EXE_PARAMS *) ConfigPtr);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300319 AGESA_EVENTLOG(status, &AmdLateParams.StdHeader);
Kyösti Mälkkie68f4ff2014-10-22 15:53:34 +0300320 ASSERT((status == AGESA_SUCCESS) || (status == AGESA_UNSUPPORTED));
321
322 return status;
323}