blob: a66917b697a65d89c447d2f1cd6ad2b99fb7cb33 [file] [log] [blame]
Bruce Griffith79f47cf2014-08-15 12:38:21 -06001/*
2 * This file is part of the coreboot project.
3 *
Dave Frodin84c72de2015-03-12 13:41:44 -06004 * Copyright (C) 2012 - 2014 Advanced Micro Devices, Inc.
Bruce Griffith79f47cf2014-08-15 12:38:21 -06005 *
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.
Bruce Griffith79f47cf2014-08-15 12:38:21 -060014 */
15
Dave Frodin84c72de2015-03-12 13:41:44 -060016#include <AGESA.h>
Marc Jonesa6a566b2015-05-05 09:55:57 -060017#include <cbfs.h>
Kyösti Mälkkie87564f2017-04-15 20:07:53 +030018#include <cbmem.h>
Aaron Durbin64031672018-04-21 14:45:32 -060019#include <compiler.h>
Ricardo Ribalda Delgadob2bb6ad2016-12-20 10:08:45 +010020#include <delay.h>
Bruce Griffith79f47cf2014-08-15 12:38:21 -060021#include <cpu/x86/mtrr.h>
Dave Frodin84c72de2015-03-12 13:41:44 -060022#include <FchPlatform.h>
23#include <heapManager.h>
Kyösti Mälkkied8d2772017-07-15 17:12:44 +030024#include <northbridge/amd/agesa/agesa_helper.h>
Kyösti Mälkki0a7cab82017-07-29 08:11:52 +030025#include <northbridge/amd/agesa/state_machine.h>
Kyösti Mälkki023ed1f2014-10-22 08:05:36 +030026#include <northbridge/amd/pi/agesawrapper.h>
Kyösti Mälkki9de82612017-04-13 16:56:07 +030027#include <northbridge/amd/agesa/BiosCallOuts.h>
Bruce Griffith79f47cf2014-08-15 12:38:21 -060028
Aaron Durbin64031672018-04-21 14:45:32 -060029void __weak OemPostParams(AMD_POST_PARAMS *PostParams) {}
Kyösti Mälkki3ff36b02015-10-30 16:45:21 +020030
Bruce Griffith79f47cf2014-08-15 12:38:21 -060031#define FILECODE UNASSIGNED_FILE_FILECODE
32
Bruce Griffith79f47cf2014-08-15 12:38:21 -060033AGESA_STATUS agesawrapper_amdinitreset(void)
34{
35 AGESA_STATUS status;
36 AMD_INTERFACE_PARAMS AmdParamStruct;
37 AMD_RESET_PARAMS AmdResetParams;
38
39 LibAmdMemFill (&AmdParamStruct,
40 0,
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +020041 sizeof(AMD_INTERFACE_PARAMS),
Bruce Griffith79f47cf2014-08-15 12:38:21 -060042 &(AmdParamStruct.StdHeader));
43
44 LibAmdMemFill (&AmdResetParams,
45 0,
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +020046 sizeof(AMD_RESET_PARAMS),
Bruce Griffith79f47cf2014-08-15 12:38:21 -060047 &(AmdResetParams.StdHeader));
48
49 AmdParamStruct.AgesaFunctionName = AMD_INIT_RESET;
50 AmdParamStruct.AllocationMethod = ByHost;
51 AmdParamStruct.NewStructSize = sizeof(AMD_RESET_PARAMS);
52 AmdParamStruct.NewStructPtr = &AmdResetParams;
53 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
Kyösti Mälkkia58c0b02015-10-30 23:38:40 +020054 AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout;
Bruce Griffith79f47cf2014-08-15 12:38:21 -060055 AmdParamStruct.StdHeader.Func = 0;
56 AmdParamStruct.StdHeader.ImageBasePtr = 0;
57 AmdCreateStruct (&AmdParamStruct);
58
59 AmdResetParams.FchInterface.Xhci0Enable = IS_ENABLED(CONFIG_HUDSON_XHCI_ENABLE);
Dave Frodin84c72de2015-03-12 13:41:44 -060060 if (IS_ENABLED(CONFIG_SOUTHBRIDGE_AMD_PI_BOLTON))
61 AmdResetParams.FchInterface.Xhci1Enable = TRUE;
Bruce Griffith79f47cf2014-08-15 12:38:21 -060062
Dave Frodin84c72de2015-03-12 13:41:44 -060063 AmdResetParams.FchInterface.SataEnable = !((CONFIG_HUDSON_SATA_MODE == 0) || (CONFIG_HUDSON_SATA_MODE == 3));
64 AmdResetParams.FchInterface.IdeEnable = (CONFIG_HUDSON_SATA_MODE == 0) || (CONFIG_HUDSON_SATA_MODE == 3);
65
66 status = AmdInitReset(&AmdResetParams);
Bruce Griffith79f47cf2014-08-15 12:38:21 -060067 if (status != AGESA_SUCCESS) agesawrapper_amdreadeventlog(AmdParamStruct.StdHeader.HeapStatus);
68 AmdReleaseStruct (&AmdParamStruct);
69 return status;
70}
71
72AGESA_STATUS agesawrapper_amdinitearly(void)
73{
74 AGESA_STATUS status;
75 AMD_INTERFACE_PARAMS AmdParamStruct;
76 AMD_EARLY_PARAMS *AmdEarlyParamsPtr;
77
78 LibAmdMemFill (&AmdParamStruct,
79 0,
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +020080 sizeof(AMD_INTERFACE_PARAMS),
Bruce Griffith79f47cf2014-08-15 12:38:21 -060081 &(AmdParamStruct.StdHeader));
82
83 AmdParamStruct.AgesaFunctionName = AMD_INIT_EARLY;
84 AmdParamStruct.AllocationMethod = PreMemHeap;
85 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
Kyösti Mälkkia58c0b02015-10-30 23:38:40 +020086 AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout;
Bruce Griffith79f47cf2014-08-15 12:38:21 -060087 AmdParamStruct.StdHeader.Func = 0;
88 AmdParamStruct.StdHeader.ImageBasePtr = 0;
89 AmdCreateStruct (&AmdParamStruct);
90
91 AmdEarlyParamsPtr = (AMD_EARLY_PARAMS *)AmdParamStruct.NewStructPtr;
92 OemCustomizeInitEarly (AmdEarlyParamsPtr);
93
WANG Siyuan6762a8b2015-06-08 10:13:13 +080094 AmdEarlyParamsPtr->GnbConfig.PsppPolicy = PsppDisabled;
Bruce Griffith79f47cf2014-08-15 12:38:21 -060095 status = AmdInitEarly ((AMD_EARLY_PARAMS *)AmdParamStruct.NewStructPtr);
Ricardo Ribalda Delgadob2bb6ad2016-12-20 10:08:45 +010096 /*
97 * init_timer() needs to be called on CZ PI, because AGESA resets the LAPIC reload value
98 * on the AMD_INIT_EARLY call
99 */
100 if (IS_ENABLED(CONFIG_CPU_AMD_PI_00660F01))
101 init_timer();
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600102 if (status != AGESA_SUCCESS) agesawrapper_amdreadeventlog(AmdParamStruct.StdHeader.HeapStatus);
103 AmdReleaseStruct (&AmdParamStruct);
104
105 return status;
106}
107
108AGESA_STATUS agesawrapper_amdinitpost(void)
109{
110 AGESA_STATUS status;
111 AMD_INTERFACE_PARAMS AmdParamStruct;
112 AMD_POST_PARAMS *PostParams;
113
114 LibAmdMemFill (&AmdParamStruct,
115 0,
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200116 sizeof(AMD_INTERFACE_PARAMS),
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600117 &(AmdParamStruct.StdHeader));
118
119 AmdParamStruct.AgesaFunctionName = AMD_INIT_POST;
120 AmdParamStruct.AllocationMethod = PreMemHeap;
Dave Frodin84c72de2015-03-12 13:41:44 -0600121 AmdParamStruct.StdHeader.AltImageBasePtr = NULL;
Kyösti Mälkkia58c0b02015-10-30 23:38:40 +0200122 AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout;
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600123 AmdParamStruct.StdHeader.Func = 0;
124 AmdParamStruct.StdHeader.ImageBasePtr = 0;
125
126 AmdCreateStruct (&AmdParamStruct);
127 PostParams = (AMD_POST_PARAMS *)AmdParamStruct.NewStructPtr;
128
129 // Do not use IS_ENABLED here. CONFIG_GFXUMA should always have a value. Allow
130 // the compiler to flag the error if CONFIG_GFXUMA is not set.
131 PostParams->MemConfig.UmaMode = CONFIG_GFXUMA ? UMA_AUTO : UMA_NONE;
132 PostParams->MemConfig.UmaSize = 0;
Ricardo Ribalda Delgadoa1328922016-12-28 15:16:22 +0100133 PostParams->MemConfig.BottomIo = (UINT16)
134 (CONFIG_BOTTOMIO_POSITION >> 24);
Kyösti Mälkkie87564f2017-04-15 20:07:53 +0300135
136 OemPostParams(PostParams);
137
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600138 status = AmdInitPost (PostParams);
Kyösti Mälkkie87564f2017-04-15 20:07:53 +0300139
140 /* If UMA is enabled we currently have it below TOP_MEM as well.
141 * UMA may or may not be cacheable, so Sub4GCacheTop could be
142 * higher than UmaBase. With UMA_NONE we see UmaBase==0. */
143 if (PostParams->MemConfig.UmaBase)
Kyösti Mälkki70d92b92017-04-19 19:57:01 +0300144 backup_top_of_low_cacheable(PostParams->MemConfig.UmaBase << 16);
Kyösti Mälkkie87564f2017-04-15 20:07:53 +0300145 else
Kyösti Mälkki70d92b92017-04-19 19:57:01 +0300146 backup_top_of_low_cacheable(PostParams->MemConfig.Sub4GCacheTop);
Kyösti Mälkkie87564f2017-04-15 20:07:53 +0300147
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600148 printk(
149 BIOS_SPEW,
Dave Frodin84c72de2015-03-12 13:41:44 -0600150 "setup_uma_memory: umamode %s\n",
151 (PostParams->MemConfig.UmaMode == UMA_AUTO) ? "UMA_AUTO" :
152 (PostParams->MemConfig.UmaMode == UMA_SPECIFIED) ? "UMA_SPECIFIED" :
153 (PostParams->MemConfig.UmaMode == UMA_NONE) ? "UMA_NONE" :
154 "unknown"
155 );
156 printk(
157 BIOS_SPEW,
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600158 "setup_uma_memory: syslimit 0x%08llX, bottomio 0x%08lx\n",
159 (unsigned long long)(PostParams->MemConfig.SysLimit) << 16,
160 (unsigned long)(PostParams->MemConfig.BottomIo) << 16
161 );
162 printk(
163 BIOS_SPEW,
164 "setup_uma_memory: uma size %luMB, uma start 0x%08lx\n",
165 (unsigned long)(PostParams->MemConfig.UmaSize) >> (20 - 16),
166 (unsigned long)(PostParams->MemConfig.UmaBase) << 16
167 );
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600168 if (status != AGESA_SUCCESS) agesawrapper_amdreadeventlog(PostParams->StdHeader.HeapStatus);
169 AmdReleaseStruct (&AmdParamStruct);
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600170
171 return status;
172}
173
174AGESA_STATUS agesawrapper_amdinitenv(void)
175{
176 AGESA_STATUS status;
177 AMD_INTERFACE_PARAMS AmdParamStruct;
178 AMD_ENV_PARAMS *EnvParam;
179
Kyösti Mälkki4c1e41c2017-03-25 22:45:18 +0200180 /* Initialize heap space */
181 EmptyHeap();
182
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600183 LibAmdMemFill (&AmdParamStruct,
184 0,
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200185 sizeof(AMD_INTERFACE_PARAMS),
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600186 &(AmdParamStruct.StdHeader));
187
188 AmdParamStruct.AgesaFunctionName = AMD_INIT_ENV;
189 AmdParamStruct.AllocationMethod = PostMemDram;
190 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
Kyösti Mälkkia58c0b02015-10-30 23:38:40 +0200191 AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout;
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600192 AmdParamStruct.StdHeader.Func = 0;
193 AmdParamStruct.StdHeader.ImageBasePtr = 0;
194 status = AmdCreateStruct (&AmdParamStruct);
195 EnvParam = (AMD_ENV_PARAMS *)AmdParamStruct.NewStructPtr;
196
Dave Frodin84c72de2015-03-12 13:41:44 -0600197 EnvParam->FchInterface.AzaliaController = AzEnable;
198 EnvParam->FchInterface.SataClass = CONFIG_HUDSON_SATA_MODE;
199 EnvParam->FchInterface.SataEnable = !((CONFIG_HUDSON_SATA_MODE == 0) || (CONFIG_HUDSON_SATA_MODE == 3));
200 EnvParam->FchInterface.IdeEnable = (CONFIG_HUDSON_SATA_MODE == 0) || (CONFIG_HUDSON_SATA_MODE == 3);
201 EnvParam->FchInterface.SataIdeMode = (CONFIG_HUDSON_SATA_MODE == 3);
Bruce Griffith875434252014-12-08 01:43:23 -0700202 EnvParam->GnbEnvConfiguration.IommuSupport = FALSE;
203
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600204 status = AmdInitEnv (EnvParam);
205 if (status != AGESA_SUCCESS) agesawrapper_amdreadeventlog(EnvParam->StdHeader.HeapStatus);
206 /* Initialize Subordinate Bus Number and Secondary Bus Number
207 * In platform BIOS this address is allocated by PCI enumeration code
208 Modify D1F0x18
209 */
210
211 return status;
212}
213
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600214AGESA_STATUS agesawrapper_amdinitmid(void)
215{
216 AGESA_STATUS status;
217 AMD_INTERFACE_PARAMS AmdParamStruct;
Dave Frodin84c72de2015-03-12 13:41:44 -0600218 AMD_MID_PARAMS *MidParam;
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600219
220 /* Enable MMIO on AMD CPU Address Map Controller */
Dave Frodin4b45dd32015-03-13 09:29:20 -0600221 amd_initcpuio ();
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600222
223 LibAmdMemFill (&AmdParamStruct,
224 0,
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200225 sizeof(AMD_INTERFACE_PARAMS),
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600226 &(AmdParamStruct.StdHeader));
227
228 AmdParamStruct.AgesaFunctionName = AMD_INIT_MID;
229 AmdParamStruct.AllocationMethod = PostMemDram;
230 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
Kyösti Mälkkia58c0b02015-10-30 23:38:40 +0200231 AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout;
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600232 AmdParamStruct.StdHeader.Func = 0;
233 AmdParamStruct.StdHeader.ImageBasePtr = 0;
234
235 AmdCreateStruct (&AmdParamStruct);
Dave Frodin84c72de2015-03-12 13:41:44 -0600236 MidParam = (AMD_MID_PARAMS *)AmdParamStruct.NewStructPtr;
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600237
Dave Frodin84c72de2015-03-12 13:41:44 -0600238 MidParam->GnbMidConfiguration.iGpuVgaMode = 0;/* 0 iGpuVgaAdapter, 1 iGpuVgaNonAdapter; */
239 MidParam->GnbMidConfiguration.GnbIoapicAddress = 0xFEC20000;
240
241 MidParam->FchInterface.AzaliaController = AzEnable;
242 MidParam->FchInterface.SataClass = CONFIG_HUDSON_SATA_MODE;
243 MidParam->FchInterface.SataEnable = !((CONFIG_HUDSON_SATA_MODE == 0) || (CONFIG_HUDSON_SATA_MODE == 3));
244 MidParam->FchInterface.IdeEnable = (CONFIG_HUDSON_SATA_MODE == 0) || (CONFIG_HUDSON_SATA_MODE == 3);
245 MidParam->FchInterface.SataIdeMode = (CONFIG_HUDSON_SATA_MODE == 3);
246
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600247 status = AmdInitMid ((AMD_MID_PARAMS *)AmdParamStruct.NewStructPtr);
248 if (status != AGESA_SUCCESS) agesawrapper_amdreadeventlog(AmdParamStruct.StdHeader.HeapStatus);
249 AmdReleaseStruct (&AmdParamStruct);
250
251 return status;
252}
253
Kyösti Mälkkia4c370a2014-10-22 06:42:57 +0300254#ifndef __PRE_RAM__
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600255AGESA_STATUS agesawrapper_amdinitlate(void)
256{
257 AGESA_STATUS Status;
258 AMD_INTERFACE_PARAMS AmdParamStruct;
259 AMD_LATE_PARAMS *AmdLateParams;
260
261 LibAmdMemFill (&AmdParamStruct,
262 0,
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200263 sizeof(AMD_INTERFACE_PARAMS),
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600264 &(AmdParamStruct.StdHeader));
265
266 AmdParamStruct.AgesaFunctionName = AMD_INIT_LATE;
267 AmdParamStruct.AllocationMethod = PostMemDram;
268 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
Kyösti Mälkkia58c0b02015-10-30 23:38:40 +0200269 AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout;
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600270 AmdParamStruct.StdHeader.HeapStatus = HEAP_SYSTEM_MEM;
271 AmdParamStruct.StdHeader.Func = 0;
272 AmdParamStruct.StdHeader.ImageBasePtr = 0;
273
274 /* NOTE: if not call amdcreatestruct, the initializer(AmdInitLateInitializer) would not be called */
275 AmdCreateStruct(&AmdParamStruct);
276 AmdLateParams = (AMD_LATE_PARAMS *)AmdParamStruct.NewStructPtr;
277 Status = AmdInitLate(AmdLateParams);
278 if (Status != AGESA_SUCCESS) {
279 agesawrapper_amdreadeventlog(AmdLateParams->StdHeader.HeapStatus);
280 ASSERT(Status == AGESA_SUCCESS);
281 }
282
Kyösti Mälkki0e01c482017-07-27 06:15:02 +0300283 agesawrapper_setlateinitptr(AmdLateParams);
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600284
Kyösti Mälkki0e01c482017-07-27 06:15:02 +0300285 /* No AmdReleaseStruct(&AmdParamStruct), we need AmdLateParams later. */
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600286 return Status;
287}
Dave Frodin84c72de2015-03-12 13:41:44 -0600288#endif /* #ifndef __PRE_RAM__ */
Bruce Griffith79f47cf2014-08-15 12:38:21 -0600289
Marc Jonesa6a566b2015-05-05 09:55:57 -0600290const void *agesawrapper_locate_module (const CHAR8 name[8])
291{
Marc Jonesa6a566b2015-05-05 09:55:57 -0600292 const void* agesa;
293 const AMD_IMAGE_HEADER* image;
294 const AMD_MODULE_HEADER* module;
295 size_t file_size;
296
Marshall Dawsonca3815b2017-01-25 15:23:47 -0700297 if (IS_ENABLED(CONFIG_VBOOT)) {
298 /* Use phys. location in flash and prevent vboot from searching cbmem */
299 agesa = (void *)CONFIG_AGESA_BINARY_PI_LOCATION;
300 file_size = 0x100000;
301 } else {
Kyösti Mälkki7104fe22017-05-27 20:53:29 +0300302 agesa = cbfs_boot_map_with_leak((const char *)CONFIG_AGESA_CBFS_NAME,
Aaron Durbin899d13d2015-05-15 23:39:23 -0500303 CBFS_TYPE_RAW, &file_size);
Marshall Dawsonca3815b2017-01-25 15:23:47 -0700304 }
305
Marc Jonesa6a566b2015-05-05 09:55:57 -0600306 if (!agesa)
307 return NULL;
308 image = LibAmdLocateImage(agesa, agesa + file_size - 1, 4096, name);
309 module = (AMD_MODULE_HEADER*)image->ModuleInfoOffset;
310
311 return module;
312}