blob: 2ee7f460563da157dd7367534325a72f203b9cae [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jones1587dc82017-05-15 18:55:11 -06002
3#include <cbfs.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +01004#include <console/console.h>
Marc Jones33eef132017-10-26 16:50:42 -06005#include <cpu/x86/lapic.h>
6#include <cpu/x86/mp.h>
7#include <timer.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -07008#include <amdblocks/BiosCallOuts.h>
9#include <amdblocks/agesawrapper.h>
10#include <amdblocks/agesawrapper_call.h>
Nico Huber73c11192018-10-06 18:20:47 +020011#include <amdblocks/reset.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060012#include <soc/southbridge.h>
Marc Jones1587dc82017-05-15 18:55:11 -060013
Martin Rothc450fbe2017-10-02 13:46:50 -060014#if ENV_BOOTBLOCK
15const BIOS_CALLOUT_STRUCT BiosCallouts[] = {
16 { AGESA_DO_RESET, agesa_Reset },
17 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initreset },
Richard Spiegela9f49362018-03-05 08:11:50 -070018 { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
Marshall Dawsonc150a572018-04-30 17:59:27 -060019 { AGESA_HEAP_REBASE, agesa_HeapRebase },
Martin Rothc450fbe2017-10-02 13:46:50 -060020 { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl }
21};
22#else
23const BIOS_CALLOUT_STRUCT BiosCallouts[] = {
24 /* Required callouts */
Richard Spiegel09a16e62018-04-04 12:40:20 -070025#if ENV_ROMSTAGE
26 { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
27#endif
Martin Rothc450fbe2017-10-02 13:46:50 -060028 { AGESA_ALLOCATE_BUFFER, agesa_AllocateBuffer },
29 { AGESA_DEALLOCATE_BUFFER, agesa_DeallocateBuffer },
30 { AGESA_DO_RESET, agesa_Reset },
31 { AGESA_LOCATE_BUFFER, agesa_LocateBuffer },
32 { AGESA_READ_SPD, agesa_ReadSpd },
Marc Jones33eef132017-10-26 16:50:42 -060033 { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl },
Marshall Dawson10b52e02018-05-07 08:51:04 -060034 { AGESA_GET_TEMP_HEAP_BASE, agesa_GetTempHeapBase },
Marshall Dawsonc150a572018-04-30 17:59:27 -060035 { AGESA_HEAP_REBASE, agesa_HeapRebase },
Marc Jones33eef132017-10-26 16:50:42 -060036#if ENV_RAMSTAGE
Martin Rothc450fbe2017-10-02 13:46:50 -060037 { AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
38 { AGESA_RUNFUNC_ON_ALL_APS, agesa_RunFcnOnAllAps },
Martin Rothc450fbe2017-10-02 13:46:50 -060039 { AGESA_WAIT_FOR_ALL_APS, agesa_WaitForAllApsFinished },
40 { AGESA_IDLE_AN_AP, agesa_IdleAnAp },
Marc Jones33eef132017-10-26 16:50:42 -060041#endif /* ENV_RAMSTAGE */
Martin Rothc450fbe2017-10-02 13:46:50 -060042
43 /* Optional callouts */
44 { AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData },
45 //AgesaHeapRebase - Hook ID?
46 { AGESA_HOOKBEFORE_DRAM_INIT, agesa_NoopUnsupported },
47 { AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopUnsupported },
48 { AGESA_EXTERNAL_2D_TRAIN_VREF_CHANGE, agesa_NoopUnsupported },
49 { AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopUnsupported },
50 { AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage },
51 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initenv },
52 { AGESA_EXTERNAL_VOLTAGE_ADJUST, agesa_NoopUnsupported },
53 { AGESA_GNB_PCIE_CLK_REQ, agesa_NoopUnsupported },
54
55 /* Deprecated */
56 { AGESA_HOOKBEFORE_DRAM_INIT_RECOVERY, agesa_NoopUnsupported},
57 { AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported },
58
59};
60#endif
61
62const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts);
63
Richard Spiegel271b8a52018-11-06 16:32:28 -070064AGESA_STATUS GetBiosCallout(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060065{
Richard Spiegel271b8a52018-11-06 16:32:28 -070066 uintptr_t i;
Marc Jones1587dc82017-05-15 18:55:11 -060067
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060068 for (i = 0 ; i < BiosCalloutsLen ; i++) {
Marc Jones1587dc82017-05-15 18:55:11 -060069 if (BiosCallouts[i].CalloutName == Func)
70 break;
71 }
Marc Jones7e710e02017-10-12 15:19:51 -060072
73 if (i >= BiosCalloutsLen) {
Marshall Dawson492e4db2018-05-01 11:12:51 -060074 printk(BIOS_ERR, "ERROR: AGESA Callout Not Supported: 0x%x\n",
Marc Jones7e710e02017-10-12 15:19:51 -060075 (u32)Func);
Marc Jones1587dc82017-05-15 18:55:11 -060076 return AGESA_UNSUPPORTED;
Marc Jones7e710e02017-10-12 15:19:51 -060077 }
Marc Jones1587dc82017-05-15 18:55:11 -060078
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060079 return BiosCallouts[i].CalloutPtr(Func, Data, ConfigPtr);
Marc Jones1587dc82017-05-15 18:55:11 -060080}
81
Richard Spiegel271b8a52018-11-06 16:32:28 -070082AGESA_STATUS agesa_NoopUnsupported(uint32_t Func, uintptr_t Data,
83 void *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060084{
85 return AGESA_UNSUPPORTED;
86}
87
Richard Spiegel271b8a52018-11-06 16:32:28 -070088AGESA_STATUS agesa_NoopSuccess(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060089{
90 return AGESA_SUCCESS;
91}
92
Richard Spiegel271b8a52018-11-06 16:32:28 -070093AGESA_STATUS agesa_EmptyIdsInitData(uint32_t Func, uintptr_t Data,
94 void *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060095{
96 IDS_NV_ITEM *IdsPtr = ((IDS_CALLOUT_STRUCT *) ConfigPtr)->IdsNvPtr;
97 if (Data == IDS_CALLOUT_INIT)
98 IdsPtr[0].IdsNvValue = IdsPtr[0].IdsNvId = 0xffff;
99 return AGESA_SUCCESS;
100}
101
Richard Spiegel271b8a52018-11-06 16:32:28 -0700102AGESA_STATUS agesa_Reset(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600103{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600104 AGESA_STATUS Status;
Richard Spiegel271b8a52018-11-06 16:32:28 -0700105 uintptr_t ResetType;
Marc Jones1587dc82017-05-15 18:55:11 -0600106
107 ResetType = Data;
Marc Jones1587dc82017-05-15 18:55:11 -0600108
Marc Jones4f886cc2017-10-11 20:20:49 -0600109 /*
110 * This should perform the RESET based upon the ResetType, but coreboot
111 * doesn't have a reset manager to handle a WHENEVER case. Do all
112 * resets immediately.
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600113 */
Marc Jones1587dc82017-05-15 18:55:11 -0600114 switch (ResetType) {
115 case WARM_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600116 case WARM_RESET_IMMEDIATELY:
Nico Huber73c11192018-10-06 18:20:47 +0200117 warm_reset();
Martin Roth4f92b152017-11-12 10:56:43 -0700118 break;
119
120 case COLD_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600121 case COLD_RESET_IMMEDIATELY:
Nico Huber73c11192018-10-06 18:20:47 +0200122 cold_reset();
Marc Jones1587dc82017-05-15 18:55:11 -0600123 break;
124
125 default:
126 break;
127 }
128
129 Status = 0;
130 return Status;
131}
132
Richard Spiegel271b8a52018-11-06 16:32:28 -0700133AGESA_STATUS agesa_GfxGetVbiosImage(uint32_t Func, uintptr_t FchData,
134 void *ConfigPrt)
Marc Jones1587dc82017-05-15 18:55:11 -0600135{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600136 GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo;
137
138 pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt;
Julius Werner834b3ec2020-03-04 16:52:08 -0800139 pVbiosImageInfo->ImagePtr = cbfs_map(
140 "pci"CONFIG_VGA_BIOS_ID".rom", NULL);
Richard Spiegelde332f32018-10-23 14:34:12 -0700141 printk(BIOS_DEBUG, "%s: IMGptr=%p\n", __func__,
142 pVbiosImageInfo->ImagePtr);
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600143 return pVbiosImageInfo->ImagePtr ? AGESA_SUCCESS : AGESA_WARNING;
Marc Jones1587dc82017-05-15 18:55:11 -0600144}
145
Richard Spiegel271b8a52018-11-06 16:32:28 -0700146AGESA_STATUS __weak platform_PcieSlotResetControl(uint32_t Func,
147 uintptr_t Data, void *ConfigPtr)
Marc Jones6e70d672017-10-26 16:42:03 -0600148{
149 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
150 __func__);
151 return AGESA_UNSUPPORTED;
152}
153
Richard Spiegel271b8a52018-11-06 16:32:28 -0700154AGESA_STATUS agesa_PcieSlotResetControl(uint32_t Func, uintptr_t Data,
155 void *ConfigPtr)
Martin Rothf80a4312017-09-26 14:45:16 -0600156{
Marc Jones6e70d672017-10-26 16:42:03 -0600157 return platform_PcieSlotResetControl(Func, Data, ConfigPtr);
Martin Rothf80a4312017-09-26 14:45:16 -0600158}
159
Marc Jones33eef132017-10-26 16:50:42 -0600160/*
161 * Application Processor callouts:
162 * agesa_RunFuncOnAp() and agesa_RunFcnOnAllAps() are called after main memory
163 * has been initialized and coreboot has taken control of AP task dispatching.
164 * These functions execute callout_ap_entry() on each AP, which calls the
165 * AmdLateRunApTask() entry point if it is a targeted AP.
166 */
167
168/*
169 * Global data for APs.
170 * Passed from the AGESA_Callout for the agesawrapper_amdlaterunaptask.
171 */
172static struct agesa_data {
Richard Spiegel271b8a52018-11-06 16:32:28 -0700173 uint32_t Func;
174 uintptr_t Data;
Kyösti Mälkki423d03c2018-06-28 21:18:12 +0300175 AP_EXE_PARAMS *ConfigPtr;
Marc Jones33eef132017-10-26 16:50:42 -0600176} agesadata;
177
178/*
179 * BSP deploys APs to callout_ap_entry(), which calls
180 * agesawrapper_amdlaterunaptask with the agesadata.
181 */
Subrata Banik33374972018-04-24 13:45:30 +0530182static void callout_ap_entry(void *unused)
Marc Jones33eef132017-10-26 16:50:42 -0600183{
184 AGESA_STATUS Status = AGESA_UNSUPPORTED;
185
Julius Werner540a9802019-12-09 13:03:29 -0800186 printk(BIOS_DEBUG, "%s Func: 0x%x, Data: 0x%lx, Ptr: %p\n",
Marc Jones33eef132017-10-26 16:50:42 -0600187 __func__, agesadata.Func, agesadata.Data, agesadata.ConfigPtr);
188
189 /* Check if this AP should run the function */
190 if (!((agesadata.Func == AGESA_RUNFUNC_ONAP) &&
191 (agesadata.Data == lapicid())))
192 return;
193
Kyösti Mälkki423d03c2018-06-28 21:18:12 +0300194 Status = amd_late_run_ap_task(agesadata.ConfigPtr);
Marc Jones33eef132017-10-26 16:50:42 -0600195
196 if (Status)
Patrick Rudolphfc57d6c2019-11-12 16:30:14 +0100197 printk(BIOS_DEBUG, "There was a problem with %x returned %s\n",
Marc Jones33eef132017-10-26 16:50:42 -0600198 lapicid(), decodeAGESA_STATUS(Status));
199}
200
Richard Spiegel271b8a52018-11-06 16:32:28 -0700201AGESA_STATUS agesa_RunFuncOnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Marc Jones33eef132017-10-26 16:50:42 -0600202{
203 printk(BIOS_DEBUG, "%s\n", __func__);
204
205 agesadata.Func = Func;
206 agesadata.Data = Data;
207 agesadata.ConfigPtr = ConfigPtr;
Patrick Rudolphbe207b12019-07-26 14:22:09 +0200208 if (mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS, 100 * USECS_PER_MSEC))
209 return AGESA_ERROR;
Marc Jones33eef132017-10-26 16:50:42 -0600210
211 return AGESA_SUCCESS;
212}
213
Richard Spiegel271b8a52018-11-06 16:32:28 -0700214AGESA_STATUS agesa_RunFcnOnAllAps(uint32_t Func, uintptr_t Data,
215 void *ConfigPtr)
Marc Jones33eef132017-10-26 16:50:42 -0600216{
217 printk(BIOS_DEBUG, "%s\n", __func__);
218
219 agesadata.Func = Func;
220 agesadata.Data = Data;
221 agesadata.ConfigPtr = ConfigPtr;
Patrick Rudolphbe207b12019-07-26 14:22:09 +0200222 if (mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS, 100 * USECS_PER_MSEC))
223 return AGESA_ERROR;
Marc Jones33eef132017-10-26 16:50:42 -0600224
225 return AGESA_SUCCESS;
226}
227
Richard Spiegel271b8a52018-11-06 16:32:28 -0700228AGESA_STATUS agesa_WaitForAllApsFinished(uint32_t Func, uintptr_t Data,
229 void *ConfigPtr)
Martin Rothf80a4312017-09-26 14:45:16 -0600230{
Marc Jones33eef132017-10-26 16:50:42 -0600231 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
232 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600233 AGESA_STATUS Status = AGESA_UNSUPPORTED;
234
235 return Status;
236}
237
Richard Spiegel271b8a52018-11-06 16:32:28 -0700238AGESA_STATUS agesa_IdleAnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Martin Rothf80a4312017-09-26 14:45:16 -0600239{
Marc Jones33eef132017-10-26 16:50:42 -0600240 printk(BIOS_WARNING, "Warning - AGESA callout: %s no supported\n",
241 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600242 AGESA_STATUS Status = AGESA_UNSUPPORTED;
243
244 return Status;
245}