blob: 82becf4737bd27702b1164161e05e40bccb5b711 [file] [log] [blame]
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +03001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 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 "FchPlatform.h"
36#include "Fch.h"
37#include <cpu/amd/agesa/s3_resume.h>
38#include <arch/io.h>
39#include <device/device.h>
40#include "hudson.h"
41
42#define FILECODE UNASSIGNED_FILE_FILECODE
43
44/* ACPI table pointers returned by AmdInitLate */
45VOID *DmiTable = NULL;
46VOID *AcpiPstate = NULL;
47VOID *AcpiSrat = NULL;
48VOID *AcpiSlit = NULL;
49
50VOID *AcpiWheaMce = NULL;
51VOID *AcpiWheaCmc = NULL;
52VOID *AcpiAlib = NULL;
53VOID *AcpiIvrs = NULL;
54
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +030055AGESA_STATUS agesawrapper_amdinitreset(void)
56{
57 AGESA_STATUS status;
58 AMD_INTERFACE_PARAMS AmdParamStruct;
59 AMD_RESET_PARAMS AmdResetParams;
60
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +020061 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
62 memset(&AmdResetParams, 0, sizeof(AMD_RESET_PARAMS));
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +030063
64 AmdParamStruct.AgesaFunctionName = AMD_INIT_RESET;
65 AmdParamStruct.AllocationMethod = ByHost;
66 AmdParamStruct.NewStructSize = sizeof(AMD_RESET_PARAMS);
67 AmdParamStruct.NewStructPtr = &AmdResetParams;
68 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
69 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
70 AmdParamStruct.StdHeader.Func = 0;
71 AmdParamStruct.StdHeader.ImageBasePtr = 0;
72 AmdCreateStruct(&AmdParamStruct);
73 AmdResetParams.HtConfig.Depth = 0;
74
75 status = AmdInitReset((AMD_RESET_PARAMS *) AmdParamStruct.NewStructPtr);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030076 AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader);
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +030077 AmdReleaseStruct(&AmdParamStruct);
78 return status;
79}
80
81AGESA_STATUS agesawrapper_amdinitearly(void)
82{
83 AGESA_STATUS status;
84 AMD_INTERFACE_PARAMS AmdParamStruct;
85 AMD_EARLY_PARAMS *AmdEarlyParamsPtr;
86
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +020087 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +030088
89 AmdParamStruct.AgesaFunctionName = AMD_INIT_EARLY;
90 AmdParamStruct.AllocationMethod = PreMemHeap;
91 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
92 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
93 AmdParamStruct.StdHeader.Func = 0;
94 AmdParamStruct.StdHeader.ImageBasePtr = 0;
95 AmdCreateStruct(&AmdParamStruct);
96
97 AmdEarlyParamsPtr = (AMD_EARLY_PARAMS *) AmdParamStruct.NewStructPtr;
98 OemCustomizeInitEarly(AmdEarlyParamsPtr);
99
100 status = AmdInitEarly((AMD_EARLY_PARAMS *) AmdParamStruct.NewStructPtr);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300101 AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader);
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +0300102 AmdReleaseStruct(&AmdParamStruct);
103
104 return status;
105}
106
107AGESA_STATUS agesawrapper_amdinitpost(void)
108{
109 AGESA_STATUS status;
110 AMD_INTERFACE_PARAMS AmdParamStruct;
111 AMD_POST_PARAMS *PostParams;
112
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200113 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +0300114
115 AmdParamStruct.AgesaFunctionName = AMD_INIT_POST;
116 AmdParamStruct.AllocationMethod = PreMemHeap;
117 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
118 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
119 AmdParamStruct.StdHeader.Func = 0;
120 AmdParamStruct.StdHeader.ImageBasePtr = 0;
121
122 AmdCreateStruct(&AmdParamStruct);
123 PostParams = (AMD_POST_PARAMS *) AmdParamStruct.NewStructPtr;
124 status = AmdInitPost(PostParams);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300125 AGESA_EVENTLOG(status, &PostParams->StdHeader);
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +0300126 AmdReleaseStruct(&AmdParamStruct);
127 /* Initialize heap space */
128 EmptyHeap();
129
130 return status;
131}
132
133AGESA_STATUS agesawrapper_amdinitenv(void)
134{
135 AGESA_STATUS status;
136 AMD_INTERFACE_PARAMS AmdParamStruct;
137 AMD_ENV_PARAMS *EnvParam;
138
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200139 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +0300140
141 AmdParamStruct.AgesaFunctionName = AMD_INIT_ENV;
142 AmdParamStruct.AllocationMethod = PostMemDram;
143 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
144 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
145 AmdParamStruct.StdHeader.Func = 0;
146 AmdParamStruct.StdHeader.ImageBasePtr = 0;
147 status = AmdCreateStruct(&AmdParamStruct);
148 EnvParam = (AMD_ENV_PARAMS *) AmdParamStruct.NewStructPtr;
149
150 status = AmdInitEnv(EnvParam);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300151 AGESA_EVENTLOG(status, &EnvParam->StdHeader);
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +0300152
153 return status;
154}
155
156VOID *agesawrapper_getlateinitptr(int pick)
157{
158 switch (pick) {
159 case PICK_DMI:
160 return DmiTable;
161 case PICK_PSTATE:
162 return AcpiPstate;
163 case PICK_SRAT:
164 return AcpiSrat;
165 case PICK_SLIT:
166 return AcpiSlit;
167 case PICK_WHEA_MCE:
168 return AcpiWheaMce;
169 case PICK_WHEA_CMC:
170 return AcpiWheaCmc;
171 case PICK_ALIB:
172 return AcpiAlib;
173 case PICK_IVRS:
174 return AcpiIvrs;
175 default:
176 return NULL;
177 }
178}
179
180AGESA_STATUS agesawrapper_amdinitmid(void)
181{
182 AGESA_STATUS status;
183 AMD_INTERFACE_PARAMS AmdParamStruct;
184
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200185 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +0300186
187 AmdParamStruct.AgesaFunctionName = AMD_INIT_MID;
188 AmdParamStruct.AllocationMethod = PostMemDram;
189 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
190 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
191 AmdParamStruct.StdHeader.Func = 0;
192 AmdParamStruct.StdHeader.ImageBasePtr = 0;
193
194 AmdCreateStruct(&AmdParamStruct);
195
196 ((AMD_MID_PARAMS *) AmdParamStruct.NewStructPtr)->GnbMidConfiguration.iGpuVgaMode = 0; /* 0 iGpuVgaAdapter, 1 iGpuVgaNonAdapter; */
197 status = AmdInitMid((AMD_MID_PARAMS *) AmdParamStruct.NewStructPtr);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300198 AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader);
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +0300199 AmdReleaseStruct(&AmdParamStruct);
200
201 return status;
202}
203
204AGESA_STATUS agesawrapper_amdinitlate(void)
205{
206 AGESA_STATUS status;
207 AMD_INTERFACE_PARAMS AmdParamStruct;
208 AMD_LATE_PARAMS *AmdLateParams;
209
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200210 memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +0300211
212 AmdParamStruct.AgesaFunctionName = AMD_INIT_LATE;
213 AmdParamStruct.AllocationMethod = PostMemDram;
214 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
215 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
216 AmdParamStruct.StdHeader.HeapStatus = HEAP_SYSTEM_MEM;
217 AmdParamStruct.StdHeader.Func = 0;
218 AmdParamStruct.StdHeader.ImageBasePtr = 0;
219
220 /* NOTE: if not call amdcreatestruct, the initializer(AmdInitLateInitializer) would not be called */
221 AmdCreateStruct(&AmdParamStruct);
222 AmdLateParams = (AMD_LATE_PARAMS *) AmdParamStruct.NewStructPtr;
223 status = AmdInitLate(AmdLateParams);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300224 AGESA_EVENTLOG(status, &AmdLateParams->StdHeader);
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +0300225 ASSERT(status == AGESA_SUCCESS);
226
227 DmiTable = AmdLateParams->DmiTable;
228 AcpiPstate = AmdLateParams->AcpiPState;
229 AcpiSrat = AmdLateParams->AcpiSrat;
230 AcpiSlit = AmdLateParams->AcpiSlit;
231
232 AcpiWheaMce = AmdLateParams->AcpiWheaMce;
233 AcpiWheaCmc = AmdLateParams->AcpiWheaCmc;
234 AcpiAlib = AmdLateParams->AcpiAlib;
235 AcpiIvrs = AmdLateParams->AcpiIvrs;
236
237 printk(BIOS_DEBUG, "DmiTable:%x, AcpiPstatein: %x, AcpiSrat:%x,"
238 "AcpiSlit:%x, Mce:%x, Cmc:%x,"
239 "Alib:%x, AcpiIvrs:%x in %s\n",
240 (unsigned int)DmiTable, (unsigned int)AcpiPstate, (unsigned int)AcpiSrat,
241 (unsigned int)AcpiSlit, (unsigned int)AcpiWheaMce, (unsigned int)AcpiWheaCmc,
242 (unsigned int)AcpiAlib, (unsigned int)AcpiIvrs, __func__);
243
244 /* AmdReleaseStruct (&AmdParamStruct); */
245 return status;
246}
247
248AGESA_STATUS agesawrapper_amdlaterunaptask(UINT32 Func, UINT32 Data, VOID * ConfigPtr)
249{
250 AGESA_STATUS status;
251 AP_EXE_PARAMS ApExeParams;
252
Kyösti Mälkki7cfc70b2014-12-14 18:41:10 +0200253 memset(&ApExeParams, 0, sizeof(AP_EXE_PARAMS));
Kyösti Mälkki4b5a7112014-10-20 08:49:16 +0300254
255 ApExeParams.StdHeader.AltImageBasePtr = 0;
256 ApExeParams.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout;
257 ApExeParams.StdHeader.Func = 0;
258 ApExeParams.StdHeader.ImageBasePtr = 0;
259 ApExeParams.FunctionNumber = Func;
260 ApExeParams.RelatedDataBlock = ConfigPtr;
261
262 status = AmdLateRunApTask(&ApExeParams);
263 ASSERT(status == AGESA_SUCCESS);
264
265 return status;
266}