blob: 54b1ede72ac35645fbe44c4da0d576045ca56ac3 [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>
Aaron Durbin64031672018-04-21 14:45:32 -060018#include <compiler.h>
Marc Jones33eef132017-10-26 16:50:42 -060019#include <cpu/x86/lapic.h>
20#include <cpu/x86/mp.h>
21#include <timer.h>
Marc Jones1587dc82017-05-15 18:55:11 -060022#include <amdlib.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070023#include <amdblocks/BiosCallOuts.h>
24#include <amdblocks/agesawrapper.h>
25#include <amdblocks/agesawrapper_call.h>
Martin Roth4f92b152017-11-12 10:56:43 -070026#include <reset.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060027#include <soc/southbridge.h>
Marc Jones1587dc82017-05-15 18:55:11 -060028
Martin Rothc450fbe2017-10-02 13:46:50 -060029#if ENV_BOOTBLOCK
30const BIOS_CALLOUT_STRUCT BiosCallouts[] = {
31 { AGESA_DO_RESET, agesa_Reset },
32 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initreset },
Richard Spiegela9f49362018-03-05 08:11:50 -070033 { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
Marshall Dawsonc150a572018-04-30 17:59:27 -060034 { AGESA_HEAP_REBASE, agesa_HeapRebase },
Martin Rothc450fbe2017-10-02 13:46:50 -060035 { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl }
36};
37#else
38const BIOS_CALLOUT_STRUCT BiosCallouts[] = {
39 /* Required callouts */
Richard Spiegel09a16e62018-04-04 12:40:20 -070040#if ENV_ROMSTAGE
41 { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
42#endif
Martin Rothc450fbe2017-10-02 13:46:50 -060043 { AGESA_ALLOCATE_BUFFER, agesa_AllocateBuffer },
44 { AGESA_DEALLOCATE_BUFFER, agesa_DeallocateBuffer },
45 { AGESA_DO_RESET, agesa_Reset },
46 { AGESA_LOCATE_BUFFER, agesa_LocateBuffer },
47 { AGESA_READ_SPD, agesa_ReadSpd },
Marc Jones33eef132017-10-26 16:50:42 -060048 { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl },
Marshall Dawson10b52e02018-05-07 08:51:04 -060049 { AGESA_GET_TEMP_HEAP_BASE, agesa_GetTempHeapBase },
Marshall Dawsonc150a572018-04-30 17:59:27 -060050 { AGESA_HEAP_REBASE, agesa_HeapRebase },
Marc Jones33eef132017-10-26 16:50:42 -060051#if ENV_RAMSTAGE
Martin Rothc450fbe2017-10-02 13:46:50 -060052 { AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
53 { AGESA_RUNFUNC_ON_ALL_APS, agesa_RunFcnOnAllAps },
Martin Rothc450fbe2017-10-02 13:46:50 -060054 { AGESA_WAIT_FOR_ALL_APS, agesa_WaitForAllApsFinished },
55 { AGESA_IDLE_AN_AP, agesa_IdleAnAp },
Marc Jones33eef132017-10-26 16:50:42 -060056#endif /* ENV_RAMSTAGE */
Martin Rothc450fbe2017-10-02 13:46:50 -060057
58 /* Optional callouts */
59 { AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData },
60 //AgesaHeapRebase - Hook ID?
61 { AGESA_HOOKBEFORE_DRAM_INIT, agesa_NoopUnsupported },
62 { AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopUnsupported },
63 { AGESA_EXTERNAL_2D_TRAIN_VREF_CHANGE, agesa_NoopUnsupported },
64 { AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopUnsupported },
65 { AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage },
66 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initenv },
67 { AGESA_EXTERNAL_VOLTAGE_ADJUST, agesa_NoopUnsupported },
68 { AGESA_GNB_PCIE_CLK_REQ, agesa_NoopUnsupported },
69
70 /* Deprecated */
71 { AGESA_HOOKBEFORE_DRAM_INIT_RECOVERY, agesa_NoopUnsupported},
72 { AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported },
73
74};
75#endif
76
77const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts);
78
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060079AGESA_STATUS GetBiosCallout(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060080{
81 UINTN i;
82
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060083 for (i = 0 ; i < BiosCalloutsLen ; i++) {
Marc Jones1587dc82017-05-15 18:55:11 -060084 if (BiosCallouts[i].CalloutName == Func)
85 break;
86 }
Marc Jones7e710e02017-10-12 15:19:51 -060087
88 if (i >= BiosCalloutsLen) {
Marshall Dawson492e4db2018-05-01 11:12:51 -060089 printk(BIOS_ERR, "ERROR: AGESA Callout Not Supported: 0x%x\n",
Marc Jones7e710e02017-10-12 15:19:51 -060090 (u32)Func);
Marc Jones1587dc82017-05-15 18:55:11 -060091 return AGESA_UNSUPPORTED;
Marc Jones7e710e02017-10-12 15:19:51 -060092 }
Marc Jones1587dc82017-05-15 18:55:11 -060093
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060094 return BiosCallouts[i].CalloutPtr(Func, Data, ConfigPtr);
Marc Jones1587dc82017-05-15 18:55:11 -060095}
96
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060097AGESA_STATUS agesa_NoopUnsupported(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060098{
99 return AGESA_UNSUPPORTED;
100}
101
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600102AGESA_STATUS agesa_NoopSuccess(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600103{
104 return AGESA_SUCCESS;
105}
106
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600107AGESA_STATUS agesa_EmptyIdsInitData(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600108{
109 IDS_NV_ITEM *IdsPtr = ((IDS_CALLOUT_STRUCT *) ConfigPtr)->IdsNvPtr;
110 if (Data == IDS_CALLOUT_INIT)
111 IdsPtr[0].IdsNvValue = IdsPtr[0].IdsNvId = 0xffff;
112 return AGESA_SUCCESS;
113}
114
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600115AGESA_STATUS agesa_Reset(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600116{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600117 AGESA_STATUS Status;
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600118 UINTN ResetType;
119 AMD_CONFIG_PARAMS *StdHeader;
Marc Jones1587dc82017-05-15 18:55:11 -0600120
121 ResetType = Data;
122 StdHeader = ConfigPtr;
123
Marc Jones4f886cc2017-10-11 20:20:49 -0600124 /*
125 * This should perform the RESET based upon the ResetType, but coreboot
126 * doesn't have a reset manager to handle a WHENEVER case. Do all
127 * resets immediately.
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600128 */
Marc Jones1587dc82017-05-15 18:55:11 -0600129 switch (ResetType) {
130 case WARM_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600131 case WARM_RESET_IMMEDIATELY:
Martin Roth4f92b152017-11-12 10:56:43 -0700132 do_soft_reset();
133 break;
134
135 case COLD_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600136 case COLD_RESET_IMMEDIATELY:
Martin Roth4f92b152017-11-12 10:56:43 -0700137 do_hard_reset();
Marc Jones1587dc82017-05-15 18:55:11 -0600138 break;
139
140 default:
141 break;
142 }
143
144 Status = 0;
145 return Status;
146}
147
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600148AGESA_STATUS agesa_GfxGetVbiosImage(UINT32 Func, UINTN FchData,
149 VOID *ConfigPrt)
Marc Jones1587dc82017-05-15 18:55:11 -0600150{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600151 GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo;
152
153 pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt;
Marc Jones1587dc82017-05-15 18:55:11 -0600154 pVbiosImageInfo->ImagePtr = cbfs_boot_map_with_leak(
155 "pci"CONFIG_VGA_BIOS_ID".rom",
156 CBFS_TYPE_OPTIONROM, NULL);
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600157 printk(BIOS_DEBUG, "agesa_GfxGetVbiosImage: IMGptr=%p\n",
158 pVbiosImageInfo->ImagePtr);
159 return pVbiosImageInfo->ImagePtr ? AGESA_SUCCESS : AGESA_WARNING;
Marc Jones1587dc82017-05-15 18:55:11 -0600160}
161
Aaron Durbin64031672018-04-21 14:45:32 -0600162AGESA_STATUS __weak platform_PcieSlotResetControl(UINT32 Func,
Marc Jones6e70d672017-10-26 16:42:03 -0600163 UINTN Data, VOID *ConfigPtr)
164{
165 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
166 __func__);
167 return AGESA_UNSUPPORTED;
168}
169
Martin Rothf80a4312017-09-26 14:45:16 -0600170AGESA_STATUS agesa_PcieSlotResetControl(UINT32 Func, UINTN Data,
171 VOID *ConfigPtr)
172{
Marc Jones6e70d672017-10-26 16:42:03 -0600173 return platform_PcieSlotResetControl(Func, Data, ConfigPtr);
Martin Rothf80a4312017-09-26 14:45:16 -0600174}
175
Marc Jones33eef132017-10-26 16:50:42 -0600176/*
177 * Application Processor callouts:
178 * agesa_RunFuncOnAp() and agesa_RunFcnOnAllAps() are called after main memory
179 * has been initialized and coreboot has taken control of AP task dispatching.
180 * These functions execute callout_ap_entry() on each AP, which calls the
181 * AmdLateRunApTask() entry point if it is a targeted AP.
182 */
183
184/*
185 * Global data for APs.
186 * Passed from the AGESA_Callout for the agesawrapper_amdlaterunaptask.
187 */
188static struct agesa_data {
189 UINT32 Func;
190 UINTN Data;
191 VOID *ConfigPtr;
192} agesadata;
193
194/*
195 * BSP deploys APs to callout_ap_entry(), which calls
196 * agesawrapper_amdlaterunaptask with the agesadata.
197 */
Subrata Banik33374972018-04-24 13:45:30 +0530198static void callout_ap_entry(void *unused)
Marc Jones33eef132017-10-26 16:50:42 -0600199{
200 AGESA_STATUS Status = AGESA_UNSUPPORTED;
201
202 printk(BIOS_DEBUG, "%s Func: 0x%x, Data: 0x%lx, Ptr: 0x%p \n",
203 __func__, agesadata.Func, agesadata.Data, agesadata.ConfigPtr);
204
205 /* Check if this AP should run the function */
206 if (!((agesadata.Func == AGESA_RUNFUNC_ONAP) &&
207 (agesadata.Data == lapicid())))
208 return;
209
210 Status = agesawrapper_amdlaterunaptask(agesadata.Func, agesadata.Data,
211 agesadata.ConfigPtr);
212
213 if (Status)
214 printk(BIOS_DEBUG, "There was a problem with %lx returned %s\n",
215 lapicid(), decodeAGESA_STATUS(Status));
216}
217
218AGESA_STATUS agesa_RunFuncOnAp(UINT32 Func, UINTN Data, VOID *ConfigPtr)
219{
220 printk(BIOS_DEBUG, "%s\n", __func__);
221
222 agesadata.Func = Func;
223 agesadata.Data = Data;
224 agesadata.ConfigPtr = ConfigPtr;
Subrata Banik8a25cae2018-05-03 18:48:41 +0530225 mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS,
226 100 * USECS_PER_MSEC);
Marc Jones33eef132017-10-26 16:50:42 -0600227
228 return AGESA_SUCCESS;
229}
230
231AGESA_STATUS agesa_RunFcnOnAllAps(UINT32 Func, UINTN Data, VOID *ConfigPtr)
232{
233 printk(BIOS_DEBUG, "%s\n", __func__);
234
235 agesadata.Func = Func;
236 agesadata.Data = Data;
237 agesadata.ConfigPtr = ConfigPtr;
Subrata Banik8a25cae2018-05-03 18:48:41 +0530238 mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS,
239 100 * USECS_PER_MSEC);
Marc Jones33eef132017-10-26 16:50:42 -0600240
241 return AGESA_SUCCESS;
242}
243
Martin Rothf80a4312017-09-26 14:45:16 -0600244AGESA_STATUS agesa_WaitForAllApsFinished(UINT32 Func, UINTN Data,
245 VOID *ConfigPtr)
246{
Marc Jones33eef132017-10-26 16:50:42 -0600247 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
248 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600249 AGESA_STATUS Status = AGESA_UNSUPPORTED;
250
251 return Status;
252}
253
254AGESA_STATUS agesa_IdleAnAp(UINT32 Func, UINTN Data, VOID *ConfigPtr)
255{
Marc Jones33eef132017-10-26 16:50:42 -0600256 printk(BIOS_WARNING, "Warning - AGESA callout: %s no supported\n",
257 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600258 AGESA_STATUS Status = AGESA_UNSUPPORTED;
259
260 return Status;
261}