blob: 27d4b0b5527fe9ffe566c5580b49308dfe4813f9 [file] [log] [blame]
Marc Jones1587dc82017-05-15 18:55:11 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
5 * Copyright (C) 2013 Sage Electronic Engineering, LLC
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <cbfs.h>
Marc Jones33eef132017-10-26 16:50:42 -060018#include <cpu/x86/lapic.h>
19#include <cpu/x86/mp.h>
20#include <timer.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070021#include <amdblocks/BiosCallOuts.h>
22#include <amdblocks/agesawrapper.h>
23#include <amdblocks/agesawrapper_call.h>
Nico Huber73c11192018-10-06 18:20:47 +020024#include <amdblocks/reset.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060025#include <soc/southbridge.h>
Marc Jones1587dc82017-05-15 18:55:11 -060026
Martin Rothc450fbe2017-10-02 13:46:50 -060027#if ENV_BOOTBLOCK
28const BIOS_CALLOUT_STRUCT BiosCallouts[] = {
29 { AGESA_DO_RESET, agesa_Reset },
30 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initreset },
Richard Spiegela9f49362018-03-05 08:11:50 -070031 { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
Marshall Dawsonc150a572018-04-30 17:59:27 -060032 { AGESA_HEAP_REBASE, agesa_HeapRebase },
Martin Rothc450fbe2017-10-02 13:46:50 -060033 { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl }
34};
35#else
36const BIOS_CALLOUT_STRUCT BiosCallouts[] = {
37 /* Required callouts */
Richard Spiegel09a16e62018-04-04 12:40:20 -070038#if ENV_ROMSTAGE
39 { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
40#endif
Martin Rothc450fbe2017-10-02 13:46:50 -060041 { AGESA_ALLOCATE_BUFFER, agesa_AllocateBuffer },
42 { AGESA_DEALLOCATE_BUFFER, agesa_DeallocateBuffer },
43 { AGESA_DO_RESET, agesa_Reset },
44 { AGESA_LOCATE_BUFFER, agesa_LocateBuffer },
45 { AGESA_READ_SPD, agesa_ReadSpd },
Marc Jones33eef132017-10-26 16:50:42 -060046 { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl },
Marshall Dawson10b52e02018-05-07 08:51:04 -060047 { AGESA_GET_TEMP_HEAP_BASE, agesa_GetTempHeapBase },
Marshall Dawsonc150a572018-04-30 17:59:27 -060048 { AGESA_HEAP_REBASE, agesa_HeapRebase },
Marc Jones33eef132017-10-26 16:50:42 -060049#if ENV_RAMSTAGE
Martin Rothc450fbe2017-10-02 13:46:50 -060050 { AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
51 { AGESA_RUNFUNC_ON_ALL_APS, agesa_RunFcnOnAllAps },
Martin Rothc450fbe2017-10-02 13:46:50 -060052 { AGESA_WAIT_FOR_ALL_APS, agesa_WaitForAllApsFinished },
53 { AGESA_IDLE_AN_AP, agesa_IdleAnAp },
Marc Jones33eef132017-10-26 16:50:42 -060054#endif /* ENV_RAMSTAGE */
Martin Rothc450fbe2017-10-02 13:46:50 -060055
56 /* Optional callouts */
57 { AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData },
58 //AgesaHeapRebase - Hook ID?
59 { AGESA_HOOKBEFORE_DRAM_INIT, agesa_NoopUnsupported },
60 { AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopUnsupported },
61 { AGESA_EXTERNAL_2D_TRAIN_VREF_CHANGE, agesa_NoopUnsupported },
62 { AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopUnsupported },
63 { AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage },
64 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initenv },
65 { AGESA_EXTERNAL_VOLTAGE_ADJUST, agesa_NoopUnsupported },
66 { AGESA_GNB_PCIE_CLK_REQ, agesa_NoopUnsupported },
67
68 /* Deprecated */
69 { AGESA_HOOKBEFORE_DRAM_INIT_RECOVERY, agesa_NoopUnsupported},
70 { AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported },
71
72};
73#endif
74
75const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts);
76
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060077AGESA_STATUS GetBiosCallout(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060078{
79 UINTN i;
80
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060081 for (i = 0 ; i < BiosCalloutsLen ; i++) {
Marc Jones1587dc82017-05-15 18:55:11 -060082 if (BiosCallouts[i].CalloutName == Func)
83 break;
84 }
Marc Jones7e710e02017-10-12 15:19:51 -060085
86 if (i >= BiosCalloutsLen) {
Marshall Dawson492e4db2018-05-01 11:12:51 -060087 printk(BIOS_ERR, "ERROR: AGESA Callout Not Supported: 0x%x\n",
Marc Jones7e710e02017-10-12 15:19:51 -060088 (u32)Func);
Marc Jones1587dc82017-05-15 18:55:11 -060089 return AGESA_UNSUPPORTED;
Marc Jones7e710e02017-10-12 15:19:51 -060090 }
Marc Jones1587dc82017-05-15 18:55:11 -060091
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060092 return BiosCallouts[i].CalloutPtr(Func, Data, ConfigPtr);
Marc Jones1587dc82017-05-15 18:55:11 -060093}
94
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060095AGESA_STATUS agesa_NoopUnsupported(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060096{
97 return AGESA_UNSUPPORTED;
98}
99
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600100AGESA_STATUS agesa_NoopSuccess(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600101{
102 return AGESA_SUCCESS;
103}
104
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600105AGESA_STATUS agesa_EmptyIdsInitData(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600106{
107 IDS_NV_ITEM *IdsPtr = ((IDS_CALLOUT_STRUCT *) ConfigPtr)->IdsNvPtr;
108 if (Data == IDS_CALLOUT_INIT)
109 IdsPtr[0].IdsNvValue = IdsPtr[0].IdsNvId = 0xffff;
110 return AGESA_SUCCESS;
111}
112
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600113AGESA_STATUS agesa_Reset(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600114{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600115 AGESA_STATUS Status;
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600116 UINTN ResetType;
117 AMD_CONFIG_PARAMS *StdHeader;
Marc Jones1587dc82017-05-15 18:55:11 -0600118
119 ResetType = Data;
120 StdHeader = ConfigPtr;
121
Marc Jones4f886cc2017-10-11 20:20:49 -0600122 /*
123 * This should perform the RESET based upon the ResetType, but coreboot
124 * doesn't have a reset manager to handle a WHENEVER case. Do all
125 * resets immediately.
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600126 */
Marc Jones1587dc82017-05-15 18:55:11 -0600127 switch (ResetType) {
128 case WARM_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600129 case WARM_RESET_IMMEDIATELY:
Nico Huber73c11192018-10-06 18:20:47 +0200130 warm_reset();
Martin Roth4f92b152017-11-12 10:56:43 -0700131 break;
132
133 case COLD_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600134 case COLD_RESET_IMMEDIATELY:
Nico Huber73c11192018-10-06 18:20:47 +0200135 cold_reset();
Marc Jones1587dc82017-05-15 18:55:11 -0600136 break;
137
138 default:
139 break;
140 }
141
142 Status = 0;
143 return Status;
144}
145
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600146AGESA_STATUS agesa_GfxGetVbiosImage(UINT32 Func, UINTN FchData,
147 VOID *ConfigPrt)
Marc Jones1587dc82017-05-15 18:55:11 -0600148{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600149 GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo;
150
151 pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt;
Marc Jones1587dc82017-05-15 18:55:11 -0600152 pVbiosImageInfo->ImagePtr = cbfs_boot_map_with_leak(
153 "pci"CONFIG_VGA_BIOS_ID".rom",
154 CBFS_TYPE_OPTIONROM, NULL);
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600155 printk(BIOS_DEBUG, "agesa_GfxGetVbiosImage: IMGptr=%p\n",
156 pVbiosImageInfo->ImagePtr);
157 return pVbiosImageInfo->ImagePtr ? AGESA_SUCCESS : AGESA_WARNING;
Marc Jones1587dc82017-05-15 18:55:11 -0600158}
159
Aaron Durbin64031672018-04-21 14:45:32 -0600160AGESA_STATUS __weak platform_PcieSlotResetControl(UINT32 Func,
Marc Jones6e70d672017-10-26 16:42:03 -0600161 UINTN Data, VOID *ConfigPtr)
162{
163 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
164 __func__);
165 return AGESA_UNSUPPORTED;
166}
167
Martin Rothf80a4312017-09-26 14:45:16 -0600168AGESA_STATUS agesa_PcieSlotResetControl(UINT32 Func, UINTN Data,
169 VOID *ConfigPtr)
170{
Marc Jones6e70d672017-10-26 16:42:03 -0600171 return platform_PcieSlotResetControl(Func, Data, ConfigPtr);
Martin Rothf80a4312017-09-26 14:45:16 -0600172}
173
Marc Jones33eef132017-10-26 16:50:42 -0600174/*
175 * Application Processor callouts:
176 * agesa_RunFuncOnAp() and agesa_RunFcnOnAllAps() are called after main memory
177 * has been initialized and coreboot has taken control of AP task dispatching.
178 * These functions execute callout_ap_entry() on each AP, which calls the
179 * AmdLateRunApTask() entry point if it is a targeted AP.
180 */
181
182/*
183 * Global data for APs.
184 * Passed from the AGESA_Callout for the agesawrapper_amdlaterunaptask.
185 */
186static struct agesa_data {
187 UINT32 Func;
188 UINTN Data;
189 VOID *ConfigPtr;
190} agesadata;
191
192/*
193 * BSP deploys APs to callout_ap_entry(), which calls
194 * agesawrapper_amdlaterunaptask with the agesadata.
195 */
Subrata Banik33374972018-04-24 13:45:30 +0530196static void callout_ap_entry(void *unused)
Marc Jones33eef132017-10-26 16:50:42 -0600197{
198 AGESA_STATUS Status = AGESA_UNSUPPORTED;
199
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200200 printk(BIOS_DEBUG, "%s Func: 0x%x, Data: 0x%lx, Ptr: 0x%p\n",
Marc Jones33eef132017-10-26 16:50:42 -0600201 __func__, agesadata.Func, agesadata.Data, agesadata.ConfigPtr);
202
203 /* Check if this AP should run the function */
204 if (!((agesadata.Func == AGESA_RUNFUNC_ONAP) &&
205 (agesadata.Data == lapicid())))
206 return;
207
208 Status = agesawrapper_amdlaterunaptask(agesadata.Func, agesadata.Data,
209 agesadata.ConfigPtr);
210
211 if (Status)
212 printk(BIOS_DEBUG, "There was a problem with %lx returned %s\n",
213 lapicid(), decodeAGESA_STATUS(Status));
214}
215
216AGESA_STATUS agesa_RunFuncOnAp(UINT32 Func, UINTN Data, VOID *ConfigPtr)
217{
218 printk(BIOS_DEBUG, "%s\n", __func__);
219
220 agesadata.Func = Func;
221 agesadata.Data = Data;
222 agesadata.ConfigPtr = ConfigPtr;
Subrata Banik8a25cae2018-05-03 18:48:41 +0530223 mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS,
224 100 * USECS_PER_MSEC);
Marc Jones33eef132017-10-26 16:50:42 -0600225
226 return AGESA_SUCCESS;
227}
228
229AGESA_STATUS agesa_RunFcnOnAllAps(UINT32 Func, UINTN Data, VOID *ConfigPtr)
230{
231 printk(BIOS_DEBUG, "%s\n", __func__);
232
233 agesadata.Func = Func;
234 agesadata.Data = Data;
235 agesadata.ConfigPtr = ConfigPtr;
Subrata Banik8a25cae2018-05-03 18:48:41 +0530236 mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS,
237 100 * USECS_PER_MSEC);
Marc Jones33eef132017-10-26 16:50:42 -0600238
239 return AGESA_SUCCESS;
240}
241
Martin Rothf80a4312017-09-26 14:45:16 -0600242AGESA_STATUS agesa_WaitForAllApsFinished(UINT32 Func, UINTN Data,
243 VOID *ConfigPtr)
244{
Marc Jones33eef132017-10-26 16:50:42 -0600245 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
246 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600247 AGESA_STATUS Status = AGESA_UNSUPPORTED;
248
249 return Status;
250}
251
252AGESA_STATUS agesa_IdleAnAp(UINT32 Func, UINTN Data, VOID *ConfigPtr)
253{
Marc Jones33eef132017-10-26 16:50:42 -0600254 printk(BIOS_WARNING, "Warning - AGESA callout: %s no supported\n",
255 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600256 AGESA_STATUS Status = AGESA_UNSUPPORTED;
257
258 return Status;
259}