blob: b7e5486b7cbf243163bf221f161517b0cae6b131 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Marc Jones1587dc82017-05-15 18:55:11 -06003
4#include <cbfs.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +01005#include <console/console.h>
Marc Jones33eef132017-10-26 16:50:42 -06006#include <cpu/x86/lapic.h>
7#include <cpu/x86/mp.h>
8#include <timer.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -07009#include <amdblocks/BiosCallOuts.h>
10#include <amdblocks/agesawrapper.h>
11#include <amdblocks/agesawrapper_call.h>
Nico Huber73c11192018-10-06 18:20:47 +020012#include <amdblocks/reset.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060013#include <soc/southbridge.h>
Marc Jones1587dc82017-05-15 18:55:11 -060014
Martin Rothc450fbe2017-10-02 13:46:50 -060015#if ENV_BOOTBLOCK
16const BIOS_CALLOUT_STRUCT BiosCallouts[] = {
17 { AGESA_DO_RESET, agesa_Reset },
18 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initreset },
Richard Spiegela9f49362018-03-05 08:11:50 -070019 { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
Marshall Dawsonc150a572018-04-30 17:59:27 -060020 { AGESA_HEAP_REBASE, agesa_HeapRebase },
Martin Rothc450fbe2017-10-02 13:46:50 -060021 { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl }
22};
23#else
24const BIOS_CALLOUT_STRUCT BiosCallouts[] = {
25 /* Required callouts */
Richard Spiegel09a16e62018-04-04 12:40:20 -070026#if ENV_ROMSTAGE
27 { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
28#endif
Martin Rothc450fbe2017-10-02 13:46:50 -060029 { AGESA_ALLOCATE_BUFFER, agesa_AllocateBuffer },
30 { AGESA_DEALLOCATE_BUFFER, agesa_DeallocateBuffer },
31 { AGESA_DO_RESET, agesa_Reset },
32 { AGESA_LOCATE_BUFFER, agesa_LocateBuffer },
33 { AGESA_READ_SPD, agesa_ReadSpd },
Marc Jones33eef132017-10-26 16:50:42 -060034 { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl },
Marshall Dawson10b52e02018-05-07 08:51:04 -060035 { AGESA_GET_TEMP_HEAP_BASE, agesa_GetTempHeapBase },
Marshall Dawsonc150a572018-04-30 17:59:27 -060036 { AGESA_HEAP_REBASE, agesa_HeapRebase },
Marc Jones33eef132017-10-26 16:50:42 -060037#if ENV_RAMSTAGE
Martin Rothc450fbe2017-10-02 13:46:50 -060038 { AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
39 { AGESA_RUNFUNC_ON_ALL_APS, agesa_RunFcnOnAllAps },
Martin Rothc450fbe2017-10-02 13:46:50 -060040 { AGESA_WAIT_FOR_ALL_APS, agesa_WaitForAllApsFinished },
41 { AGESA_IDLE_AN_AP, agesa_IdleAnAp },
Marc Jones33eef132017-10-26 16:50:42 -060042#endif /* ENV_RAMSTAGE */
Martin Rothc450fbe2017-10-02 13:46:50 -060043
44 /* Optional callouts */
45 { AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData },
46 //AgesaHeapRebase - Hook ID?
47 { AGESA_HOOKBEFORE_DRAM_INIT, agesa_NoopUnsupported },
48 { AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopUnsupported },
49 { AGESA_EXTERNAL_2D_TRAIN_VREF_CHANGE, agesa_NoopUnsupported },
50 { AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopUnsupported },
51 { AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage },
52 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initenv },
53 { AGESA_EXTERNAL_VOLTAGE_ADJUST, agesa_NoopUnsupported },
54 { AGESA_GNB_PCIE_CLK_REQ, agesa_NoopUnsupported },
55
56 /* Deprecated */
57 { AGESA_HOOKBEFORE_DRAM_INIT_RECOVERY, agesa_NoopUnsupported},
58 { AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported },
59
60};
61#endif
62
63const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts);
64
Richard Spiegel271b8a52018-11-06 16:32:28 -070065AGESA_STATUS GetBiosCallout(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060066{
Richard Spiegel271b8a52018-11-06 16:32:28 -070067 uintptr_t i;
Marc Jones1587dc82017-05-15 18:55:11 -060068
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060069 for (i = 0 ; i < BiosCalloutsLen ; i++) {
Marc Jones1587dc82017-05-15 18:55:11 -060070 if (BiosCallouts[i].CalloutName == Func)
71 break;
72 }
Marc Jones7e710e02017-10-12 15:19:51 -060073
74 if (i >= BiosCalloutsLen) {
Marshall Dawson492e4db2018-05-01 11:12:51 -060075 printk(BIOS_ERR, "ERROR: AGESA Callout Not Supported: 0x%x\n",
Marc Jones7e710e02017-10-12 15:19:51 -060076 (u32)Func);
Marc Jones1587dc82017-05-15 18:55:11 -060077 return AGESA_UNSUPPORTED;
Marc Jones7e710e02017-10-12 15:19:51 -060078 }
Marc Jones1587dc82017-05-15 18:55:11 -060079
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060080 return BiosCallouts[i].CalloutPtr(Func, Data, ConfigPtr);
Marc Jones1587dc82017-05-15 18:55:11 -060081}
82
Richard Spiegel271b8a52018-11-06 16:32:28 -070083AGESA_STATUS agesa_NoopUnsupported(uint32_t Func, uintptr_t Data,
84 void *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060085{
86 return AGESA_UNSUPPORTED;
87}
88
Richard Spiegel271b8a52018-11-06 16:32:28 -070089AGESA_STATUS agesa_NoopSuccess(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060090{
91 return AGESA_SUCCESS;
92}
93
Richard Spiegel271b8a52018-11-06 16:32:28 -070094AGESA_STATUS agesa_EmptyIdsInitData(uint32_t Func, uintptr_t Data,
95 void *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060096{
97 IDS_NV_ITEM *IdsPtr = ((IDS_CALLOUT_STRUCT *) ConfigPtr)->IdsNvPtr;
98 if (Data == IDS_CALLOUT_INIT)
99 IdsPtr[0].IdsNvValue = IdsPtr[0].IdsNvId = 0xffff;
100 return AGESA_SUCCESS;
101}
102
Richard Spiegel271b8a52018-11-06 16:32:28 -0700103AGESA_STATUS agesa_Reset(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600104{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600105 AGESA_STATUS Status;
Richard Spiegel271b8a52018-11-06 16:32:28 -0700106 uintptr_t ResetType;
Marc Jones1587dc82017-05-15 18:55:11 -0600107
108 ResetType = Data;
Marc Jones1587dc82017-05-15 18:55:11 -0600109
Marc Jones4f886cc2017-10-11 20:20:49 -0600110 /*
111 * This should perform the RESET based upon the ResetType, but coreboot
112 * doesn't have a reset manager to handle a WHENEVER case. Do all
113 * resets immediately.
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600114 */
Marc Jones1587dc82017-05-15 18:55:11 -0600115 switch (ResetType) {
116 case WARM_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600117 case WARM_RESET_IMMEDIATELY:
Nico Huber73c11192018-10-06 18:20:47 +0200118 warm_reset();
Martin Roth4f92b152017-11-12 10:56:43 -0700119 break;
120
121 case COLD_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600122 case COLD_RESET_IMMEDIATELY:
Nico Huber73c11192018-10-06 18:20:47 +0200123 cold_reset();
Marc Jones1587dc82017-05-15 18:55:11 -0600124 break;
125
126 default:
127 break;
128 }
129
130 Status = 0;
131 return Status;
132}
133
Richard Spiegel271b8a52018-11-06 16:32:28 -0700134AGESA_STATUS agesa_GfxGetVbiosImage(uint32_t Func, uintptr_t FchData,
135 void *ConfigPrt)
Marc Jones1587dc82017-05-15 18:55:11 -0600136{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600137 GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo;
138
139 pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt;
Marc Jones1587dc82017-05-15 18:55:11 -0600140 pVbiosImageInfo->ImagePtr = cbfs_boot_map_with_leak(
141 "pci"CONFIG_VGA_BIOS_ID".rom",
142 CBFS_TYPE_OPTIONROM, NULL);
Richard Spiegelde332f32018-10-23 14:34:12 -0700143 printk(BIOS_DEBUG, "%s: IMGptr=%p\n", __func__,
144 pVbiosImageInfo->ImagePtr);
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600145 return pVbiosImageInfo->ImagePtr ? AGESA_SUCCESS : AGESA_WARNING;
Marc Jones1587dc82017-05-15 18:55:11 -0600146}
147
Richard Spiegel271b8a52018-11-06 16:32:28 -0700148AGESA_STATUS __weak platform_PcieSlotResetControl(uint32_t Func,
149 uintptr_t Data, void *ConfigPtr)
Marc Jones6e70d672017-10-26 16:42:03 -0600150{
151 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
152 __func__);
153 return AGESA_UNSUPPORTED;
154}
155
Richard Spiegel271b8a52018-11-06 16:32:28 -0700156AGESA_STATUS agesa_PcieSlotResetControl(uint32_t Func, uintptr_t Data,
157 void *ConfigPtr)
Martin Rothf80a4312017-09-26 14:45:16 -0600158{
Marc Jones6e70d672017-10-26 16:42:03 -0600159 return platform_PcieSlotResetControl(Func, Data, ConfigPtr);
Martin Rothf80a4312017-09-26 14:45:16 -0600160}
161
Marc Jones33eef132017-10-26 16:50:42 -0600162/*
163 * Application Processor callouts:
164 * agesa_RunFuncOnAp() and agesa_RunFcnOnAllAps() are called after main memory
165 * has been initialized and coreboot has taken control of AP task dispatching.
166 * These functions execute callout_ap_entry() on each AP, which calls the
167 * AmdLateRunApTask() entry point if it is a targeted AP.
168 */
169
170/*
171 * Global data for APs.
172 * Passed from the AGESA_Callout for the agesawrapper_amdlaterunaptask.
173 */
174static struct agesa_data {
Richard Spiegel271b8a52018-11-06 16:32:28 -0700175 uint32_t Func;
176 uintptr_t Data;
Kyösti Mälkki423d03c2018-06-28 21:18:12 +0300177 AP_EXE_PARAMS *ConfigPtr;
Marc Jones33eef132017-10-26 16:50:42 -0600178} agesadata;
179
180/*
181 * BSP deploys APs to callout_ap_entry(), which calls
182 * agesawrapper_amdlaterunaptask with the agesadata.
183 */
Subrata Banik33374972018-04-24 13:45:30 +0530184static void callout_ap_entry(void *unused)
Marc Jones33eef132017-10-26 16:50:42 -0600185{
186 AGESA_STATUS Status = AGESA_UNSUPPORTED;
187
Julius Werner540a9802019-12-09 13:03:29 -0800188 printk(BIOS_DEBUG, "%s Func: 0x%x, Data: 0x%lx, Ptr: %p\n",
Marc Jones33eef132017-10-26 16:50:42 -0600189 __func__, agesadata.Func, agesadata.Data, agesadata.ConfigPtr);
190
191 /* Check if this AP should run the function */
192 if (!((agesadata.Func == AGESA_RUNFUNC_ONAP) &&
193 (agesadata.Data == lapicid())))
194 return;
195
Kyösti Mälkki423d03c2018-06-28 21:18:12 +0300196 Status = amd_late_run_ap_task(agesadata.ConfigPtr);
Marc Jones33eef132017-10-26 16:50:42 -0600197
198 if (Status)
199 printk(BIOS_DEBUG, "There was a problem with %lx returned %s\n",
200 lapicid(), decodeAGESA_STATUS(Status));
201}
202
Richard Spiegel271b8a52018-11-06 16:32:28 -0700203AGESA_STATUS agesa_RunFuncOnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Marc Jones33eef132017-10-26 16:50:42 -0600204{
205 printk(BIOS_DEBUG, "%s\n", __func__);
206
207 agesadata.Func = Func;
208 agesadata.Data = Data;
209 agesadata.ConfigPtr = ConfigPtr;
Patrick Rudolphbe207b12019-07-26 14:22:09 +0200210 if (mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS, 100 * USECS_PER_MSEC))
211 return AGESA_ERROR;
Marc Jones33eef132017-10-26 16:50:42 -0600212
213 return AGESA_SUCCESS;
214}
215
Richard Spiegel271b8a52018-11-06 16:32:28 -0700216AGESA_STATUS agesa_RunFcnOnAllAps(uint32_t Func, uintptr_t Data,
217 void *ConfigPtr)
Marc Jones33eef132017-10-26 16:50:42 -0600218{
219 printk(BIOS_DEBUG, "%s\n", __func__);
220
221 agesadata.Func = Func;
222 agesadata.Data = Data;
223 agesadata.ConfigPtr = ConfigPtr;
Patrick Rudolphbe207b12019-07-26 14:22:09 +0200224 if (mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS, 100 * USECS_PER_MSEC))
225 return AGESA_ERROR;
Marc Jones33eef132017-10-26 16:50:42 -0600226
227 return AGESA_SUCCESS;
228}
229
Richard Spiegel271b8a52018-11-06 16:32:28 -0700230AGESA_STATUS agesa_WaitForAllApsFinished(uint32_t Func, uintptr_t Data,
231 void *ConfigPtr)
Martin Rothf80a4312017-09-26 14:45:16 -0600232{
Marc Jones33eef132017-10-26 16:50:42 -0600233 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
234 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600235 AGESA_STATUS Status = AGESA_UNSUPPORTED;
236
237 return Status;
238}
239
Richard Spiegel271b8a52018-11-06 16:32:28 -0700240AGESA_STATUS agesa_IdleAnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Martin Rothf80a4312017-09-26 14:45:16 -0600241{
Marc Jones33eef132017-10-26 16:50:42 -0600242 printk(BIOS_WARNING, "Warning - AGESA callout: %s no supported\n",
243 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600244 AGESA_STATUS Status = AGESA_UNSUPPORTED;
245
246 return Status;
247}