2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
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.
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.
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
20 /*-----------------------------------------------------------------------------
21 * M O D U L E S U S E D
22 *-----------------------------------------------------------------------------
27 #include "agesawrapper.h"
28 #include "BiosCallOuts.h"
29 #include "cpuRegisters.h"
30 #include "cpuCacheInit.h"
31 #include "cpuApicUtilities.h"
32 #include "cpuEarlyInit.h"
33 #include "cpuLateInit.h"
34 #include "Dispatcher.h"
35 #include "cpuCacheInit.h"
37 #include "PlatformGnbPcieComplex.h"
40 #define FILECODE UNASSIGNED_FILE_FILECODE
42 /*------------------------------------------------------------------------------
43 * D E F I N I T I O N S A N D M A C R O S
44 *------------------------------------------------------------------------------
48 /* ACPI table pointers returned by AmdInitLate */
49 VOID *DmiTable = NULL;
50 VOID *AcpiPstate = NULL;
51 VOID *AcpiSrat = NULL;
52 VOID *AcpiSlit = NULL;
54 VOID *AcpiWheaMce = NULL;
55 VOID *AcpiWheaCmc = NULL;
56 VOID *AcpiAlib = NULL;
58 /*------------------------------------------------------------------------------
59 * T Y P E D E F S A N D S T R U C T U R E S
60 *------------------------------------------------------------------------------
63 /*------------------------------------------------------------------------------
64 * 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
65 *------------------------------------------------------------------------------
68 /*------------------------------------------------------------------------------
69 * E X P O R T E D F U N C T I O N S
70 *------------------------------------------------------------------------------
73 /*------------------------------------------------------------------------------
74 * L O C A L F U N C T I O N S
75 *------------------------------------------------------------------------------
78 agesawrapper_amdinitcpuio (
86 AMD_CONFIG_PARAMS StdHeader;
88 /* Enable legacy video routing: D18F1xF4 VGA Enable */
89 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0xF4);
91 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
93 /* The platform BIOS needs to ensure the memory ranges of SB800 legacy
94 * devices (TPM, HPET, BIOS RAM, Watchdog Timer, I/O APIC and ACPI) are
95 * set to non-posted regions.
97 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0x84);
98 PciData = 0x00FEDF00; // last address before processor local APIC at FEE00000
99 PciData |= 1 << 7; // set NP (non-posted) bit
100 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
101 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0x80);
102 PciData = (0xFED00000 >> 8) | 3; // lowest NP address is HPET at FED00000
103 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
105 /* Map the remaining PCI hole as posted MMIO */
106 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0x8C);
107 PciData = 0x00FECF00; // last address before non-posted range
108 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
109 LibAmdMsrRead (0xC001001A, &MsrReg, &StdHeader);
110 MsrReg = (MsrReg >> 8) | 3;
111 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0x88);
112 PciData = (UINT32)MsrReg;
113 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
115 /* Send all IO (0000-FFFF) to southbridge. */
116 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0xC4);
117 PciData = 0x0000F000;
118 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
119 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0xC0);
120 PciData = 0x00000003;
121 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
122 Status = AGESA_SUCCESS;
123 return (UINT32)Status;
127 agesawrapper_amdinitmmio (
135 AMD_CONFIG_PARAMS StdHeader;
138 Set the MMIO Configuration Base Address and Bus Range onto MMIO configuration base
139 Address MSR register.
142 MsrReg = CONFIG_MMCONF_BASE_ADDRESS | (LibAmdBitScanReverse (CONFIG_MMCONF_BUS_NUMBER) << 2) | 1;
143 LibAmdMsrWrite (0xC0010058, &MsrReg, &StdHeader);
146 Set the NB_CFG MSR register. Enable CF8 extended configuration cycles.
148 LibAmdMsrRead (0xC001001F, &MsrReg, &StdHeader);
149 MsrReg = MsrReg | 0x0000400000000000;
150 LibAmdMsrWrite (0xC001001F, &MsrReg, &StdHeader);
152 /* Set Ontario Link Data */
153 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0, 0, 0xE0);
154 PciData = 0x01308002;
155 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
156 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0, 0, 0xE4);
157 PciData = (AMD_APU_SSID<<0x10)|AMD_APU_SVID;
158 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
160 Status = AGESA_SUCCESS;
161 return (UINT32)Status;
165 agesawrapper_amdinitreset (
170 AMD_INTERFACE_PARAMS AmdParamStruct;
171 AMD_RESET_PARAMS AmdResetParams;
173 LibAmdMemFill (&AmdParamStruct,
175 sizeof (AMD_INTERFACE_PARAMS),
176 &(AmdParamStruct.StdHeader));
178 LibAmdMemFill (&AmdResetParams,
180 sizeof (AMD_RESET_PARAMS),
181 &(AmdResetParams.StdHeader));
183 AmdParamStruct.AgesaFunctionName = AMD_INIT_RESET;
184 AmdParamStruct.AllocationMethod = ByHost;
185 AmdParamStruct.NewStructSize = sizeof(AMD_RESET_PARAMS);
186 AmdParamStruct.NewStructPtr = &AmdResetParams;
187 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
188 AmdParamStruct.StdHeader.CalloutPtr = NULL;
189 AmdParamStruct.StdHeader.Func = 0;
190 AmdParamStruct.StdHeader.ImageBasePtr = 0;
191 AmdCreateStruct (&AmdParamStruct);
192 AmdResetParams.HtConfig.Depth = 0;
194 status = AmdInitReset ((AMD_RESET_PARAMS *)AmdParamStruct.NewStructPtr);
195 if (status != AGESA_SUCCESS) agesawrapper_amdreadeventlog();
196 AmdReleaseStruct (&AmdParamStruct);
197 return (UINT32)status;
201 agesawrapper_amdinitearly (
206 AMD_INTERFACE_PARAMS AmdParamStruct;
207 AMD_EARLY_PARAMS *AmdEarlyParamsPtr;
209 LibAmdMemFill (&AmdParamStruct,
211 sizeof (AMD_INTERFACE_PARAMS),
212 &(AmdParamStruct.StdHeader));
214 AmdParamStruct.AgesaFunctionName = AMD_INIT_EARLY;
215 AmdParamStruct.AllocationMethod = PreMemHeap;
216 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
217 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) &GetBiosCallout;
218 AmdParamStruct.StdHeader.Func = 0;
219 AmdParamStruct.StdHeader.ImageBasePtr = 0;
220 AmdCreateStruct (&AmdParamStruct);
222 AmdEarlyParamsPtr = (AMD_EARLY_PARAMS *)AmdParamStruct.NewStructPtr;
223 OemCustomizeInitEarly (AmdEarlyParamsPtr);
225 status = AmdInitEarly ((AMD_EARLY_PARAMS *)AmdParamStruct.NewStructPtr);
226 if (status != AGESA_SUCCESS) agesawrapper_amdreadeventlog();
227 AmdReleaseStruct (&AmdParamStruct);
229 return (UINT32)status;
233 agesawrapper_amdinitpost (
240 AMD_INTERFACE_PARAMS AmdParamStruct;
241 BIOS_HEAP_MANAGER *BiosManagerPtr;
243 LibAmdMemFill (&AmdParamStruct,
245 sizeof (AMD_INTERFACE_PARAMS),
246 &(AmdParamStruct.StdHeader));
248 AmdParamStruct.AgesaFunctionName = AMD_INIT_POST;
249 AmdParamStruct.AllocationMethod = PreMemHeap;
250 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
251 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) &GetBiosCallout;
252 AmdParamStruct.StdHeader.Func = 0;
253 AmdParamStruct.StdHeader.ImageBasePtr = 0;
255 AmdCreateStruct (&AmdParamStruct);
256 status = AmdInitPost ((AMD_POST_PARAMS *)AmdParamStruct.NewStructPtr);
257 if (status != AGESA_SUCCESS) agesawrapper_amdreadeventlog();
258 AmdReleaseStruct (&AmdParamStruct);
260 /* Initialize heap space */
261 BiosManagerPtr = (BIOS_HEAP_MANAGER *)BIOS_HEAP_START_ADDRESS;
263 HeadPtr = (UINT32 *) ((UINT8 *) BiosManagerPtr + sizeof (BIOS_HEAP_MANAGER));
264 for (i = 0; i < ((BIOS_HEAP_SIZE/4) - (sizeof (BIOS_HEAP_MANAGER)/4)); i++)
266 *HeadPtr = 0x00000000;
269 BiosManagerPtr->StartOfAllocatedNodes = 0;
270 BiosManagerPtr->StartOfFreedNodes = 0;
272 return (UINT32)status;
276 agesawrapper_amdinitenv (
281 AMD_INTERFACE_PARAMS AmdParamStruct;
285 LibAmdMemFill (&AmdParamStruct,
287 sizeof (AMD_INTERFACE_PARAMS),
288 &(AmdParamStruct.StdHeader));
290 AmdParamStruct.AgesaFunctionName = AMD_INIT_ENV;
291 AmdParamStruct.AllocationMethod = PostMemDram;
292 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
293 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) &GetBiosCallout;
294 AmdParamStruct.StdHeader.Func = 0;
295 AmdParamStruct.StdHeader.ImageBasePtr = 0;
296 AmdCreateStruct (&AmdParamStruct);
297 status = AmdInitEnv ((AMD_ENV_PARAMS *)AmdParamStruct.NewStructPtr);
298 if (status != AGESA_SUCCESS) agesawrapper_amdreadeventlog();
299 /* Initialize Subordinate Bus Number and Secondary Bus Number
300 * In platform BIOS this address is allocated by PCI enumeration code
303 PciAddress.Address.Bus = 0;
304 PciAddress.Address.Device = 1;
305 PciAddress.Address.Function = 0;
306 PciAddress.Address.Register = 0x18;
307 /* Write to D1F0x18 */
308 LibAmdPciRead (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
309 PciValue |= 0x00010100;
310 LibAmdPciWrite (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
312 /* Initialize GMM Base Address for Legacy Bridge Mode
315 PciAddress.Address.Bus = 1;
316 PciAddress.Address.Device = 5;
317 PciAddress.Address.Function = 0;
318 PciAddress.Address.Register = 0x18;
320 LibAmdPciRead (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
321 PciValue |= 0x96000000;
322 LibAmdPciWrite (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
324 /* Initialize FB Base Address for Legacy Bridge Mode
327 PciAddress.Address.Register = 0x10;
328 LibAmdPciRead (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
329 PciValue |= 0x80000000;
330 LibAmdPciWrite (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
332 /* Initialize GMM Base Address for Pcie Mode
335 PciAddress.Address.Bus = 0;
336 PciAddress.Address.Device = 1;
337 PciAddress.Address.Function = 0;
338 PciAddress.Address.Register = 0x18;
340 LibAmdPciRead (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
341 PciValue |= 0x96000000;
342 LibAmdPciWrite (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
344 /* Initialize FB Base Address for Pcie Mode
347 PciAddress.Address.Register = 0x10;
348 LibAmdPciRead (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
349 PciValue |= 0x80000000;
350 LibAmdPciWrite (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
352 /* Initialize MMIO Base and Limit Address
355 PciAddress.Address.Bus = 0;
356 PciAddress.Address.Device = 1;
357 PciAddress.Address.Function = 0;
358 PciAddress.Address.Register = 0x20;
360 LibAmdPciRead (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
361 PciValue |= 0x96009600;
362 LibAmdPciWrite (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
364 /* Initialize MMIO Prefetchable Memory Limit and Base
367 PciAddress.Address.Register = 0x24;
368 LibAmdPciRead (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
369 PciValue |= 0x8FF18001;
370 LibAmdPciWrite (AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
371 AmdReleaseStruct (&AmdParamStruct);
373 return (UINT32)status;
377 agesawrapper_getlateinitptr (
402 agesawrapper_amdinitmid (
407 AMD_INTERFACE_PARAMS AmdParamStruct;
409 /* Enable MMIO on AMD CPU Address Map Controller */
410 agesawrapper_amdinitcpuio ();
412 LibAmdMemFill (&AmdParamStruct,
414 sizeof (AMD_INTERFACE_PARAMS),
415 &(AmdParamStruct.StdHeader));
417 AmdParamStruct.AgesaFunctionName = AMD_INIT_MID;
418 AmdParamStruct.AllocationMethod = PostMemDram;
419 AmdParamStruct.StdHeader.AltImageBasePtr = 0;
420 AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) &GetBiosCallout;
421 AmdParamStruct.StdHeader.Func = 0;
422 AmdParamStruct.StdHeader.ImageBasePtr = 0;
424 AmdCreateStruct (&AmdParamStruct);
426 status = AmdInitMid ((AMD_MID_PARAMS *)AmdParamStruct.NewStructPtr);
427 if (status != AGESA_SUCCESS) agesawrapper_amdreadeventlog();
428 AmdReleaseStruct (&AmdParamStruct);
430 return (UINT32)status;
434 agesawrapper_amdinitlate (
439 AMD_LATE_PARAMS AmdLateParams;
441 LibAmdMemFill (&AmdLateParams,
443 sizeof (AMD_LATE_PARAMS),
444 &(AmdLateParams.StdHeader));
446 AmdLateParams.StdHeader.AltImageBasePtr = 0;
447 AmdLateParams.StdHeader.CalloutPtr = (CALLOUT_ENTRY) &GetBiosCallout;
448 AmdLateParams.StdHeader.Func = 0;
449 AmdLateParams.StdHeader.ImageBasePtr = 0;
451 Status = AmdInitLate (&AmdLateParams);
452 if (Status != AGESA_SUCCESS) {
453 agesawrapper_amdreadeventlog();
454 ASSERT(Status == AGESA_SUCCESS);
457 DmiTable = AmdLateParams.DmiTable;
458 AcpiPstate = AmdLateParams.AcpiPState;
459 AcpiSrat = AmdLateParams.AcpiSrat;
460 AcpiSlit = AmdLateParams.AcpiSlit;
462 AcpiWheaMce = AmdLateParams.AcpiWheaMce;
463 AcpiWheaCmc = AmdLateParams.AcpiWheaCmc;
464 AcpiAlib = AmdLateParams.AcpiAlib;
466 return (UINT32)Status;
470 agesawrapper_amdlaterunaptask (
477 AP_EXE_PARAMS ApExeParams;
479 LibAmdMemFill (&ApExeParams,
481 sizeof (AP_EXE_PARAMS),
482 &(ApExeParams.StdHeader));
484 ApExeParams.StdHeader.AltImageBasePtr = 0;
485 ApExeParams.StdHeader.CalloutPtr = (CALLOUT_ENTRY) &GetBiosCallout;
486 ApExeParams.StdHeader.Func = 0;
487 ApExeParams.StdHeader.ImageBasePtr = 0;
488 ApExeParams.StdHeader.ImageBasePtr = 0;
489 ApExeParams.FunctionNumber = Func;
490 ApExeParams.RelatedDataBlock = ConfigPtr;
492 Status = AmdLateRunApTask (&ApExeParams);
493 if (Status != AGESA_SUCCESS) {
494 agesawrapper_amdreadeventlog();
495 ASSERT(Status == AGESA_SUCCESS);
498 return (UINT32)Status;
502 agesawrapper_amdreadeventlog (
507 EVENT_PARAMS AmdEventParams;
509 LibAmdMemFill (&AmdEventParams,
511 sizeof (EVENT_PARAMS),
512 &(AmdEventParams.StdHeader));
514 AmdEventParams.StdHeader.AltImageBasePtr = 0;
515 AmdEventParams.StdHeader.CalloutPtr = NULL;
516 AmdEventParams.StdHeader.Func = 0;
517 AmdEventParams.StdHeader.ImageBasePtr = 0;
518 Status = AmdReadEventLog (&AmdEventParams);
519 while (AmdEventParams.EventClass != 0) {
520 printk(BIOS_DEBUG,"\nEventLog: EventClass = %x, EventInfo = %x.\n",AmdEventParams.EventClass,AmdEventParams.EventInfo);
521 printk(BIOS_DEBUG," Param1 = %x, Param2 = %x.\n",AmdEventParams.DataParam1,AmdEventParams.DataParam2);
522 printk(BIOS_DEBUG," Param3 = %x, Param4 = %x.\n",AmdEventParams.DataParam3,AmdEventParams.DataParam4);
523 Status = AmdReadEventLog (&AmdEventParams);
526 return (UINT32)Status;