blob: fec1776da25e4638f4ca7546f8936a695aff4577 [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>
Marc Jones1587dc82017-05-15 18:55:11 -060021#include <amdlib.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070022#include <amdblocks/BiosCallOuts.h>
23#include <amdblocks/agesawrapper.h>
24#include <amdblocks/agesawrapper_call.h>
Martin Roth4f92b152017-11-12 10:56:43 -070025#include <reset.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060026#include <soc/southbridge.h>
Marc Jones1587dc82017-05-15 18:55:11 -060027
Martin Rothc450fbe2017-10-02 13:46:50 -060028#if ENV_BOOTBLOCK
29const BIOS_CALLOUT_STRUCT BiosCallouts[] = {
30 { AGESA_DO_RESET, agesa_Reset },
31 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initreset },
Richard Spiegela9f49362018-03-05 08:11:50 -070032 { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
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 },
47#if ENV_RAMSTAGE
Martin Rothc450fbe2017-10-02 13:46:50 -060048 { AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
49 { AGESA_RUNFUNC_ON_ALL_APS, agesa_RunFcnOnAllAps },
Martin Rothc450fbe2017-10-02 13:46:50 -060050 { AGESA_WAIT_FOR_ALL_APS, agesa_WaitForAllApsFinished },
51 { AGESA_IDLE_AN_AP, agesa_IdleAnAp },
Marc Jones33eef132017-10-26 16:50:42 -060052#endif /* ENV_RAMSTAGE */
Martin Rothc450fbe2017-10-02 13:46:50 -060053
54 /* Optional callouts */
55 { AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData },
56 //AgesaHeapRebase - Hook ID?
57 { AGESA_HOOKBEFORE_DRAM_INIT, agesa_NoopUnsupported },
58 { AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopUnsupported },
59 { AGESA_EXTERNAL_2D_TRAIN_VREF_CHANGE, agesa_NoopUnsupported },
60 { AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopUnsupported },
61 { AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage },
62 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initenv },
63 { AGESA_EXTERNAL_VOLTAGE_ADJUST, agesa_NoopUnsupported },
64 { AGESA_GNB_PCIE_CLK_REQ, agesa_NoopUnsupported },
65
66 /* Deprecated */
67 { AGESA_HOOKBEFORE_DRAM_INIT_RECOVERY, agesa_NoopUnsupported},
68 { AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported },
69
70};
71#endif
72
73const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts);
74
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060075AGESA_STATUS GetBiosCallout(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060076{
77 UINTN i;
78
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060079 for (i = 0 ; i < BiosCalloutsLen ; i++) {
Marc Jones1587dc82017-05-15 18:55:11 -060080 if (BiosCallouts[i].CalloutName == Func)
81 break;
82 }
Marc Jones7e710e02017-10-12 15:19:51 -060083
84 if (i >= BiosCalloutsLen) {
85 printk(BIOS_ERR, "ERROR: AGESA Callout Not Supported: 0x%x",
86 (u32)Func);
Marc Jones1587dc82017-05-15 18:55:11 -060087 return AGESA_UNSUPPORTED;
Marc Jones7e710e02017-10-12 15:19:51 -060088 }
Marc Jones1587dc82017-05-15 18:55:11 -060089
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060090 return BiosCallouts[i].CalloutPtr(Func, Data, ConfigPtr);
Marc Jones1587dc82017-05-15 18:55:11 -060091}
92
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060093AGESA_STATUS agesa_NoopUnsupported(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060094{
95 return AGESA_UNSUPPORTED;
96}
97
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060098AGESA_STATUS agesa_NoopSuccess(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060099{
100 return AGESA_SUCCESS;
101}
102
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600103AGESA_STATUS agesa_EmptyIdsInitData(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600104{
105 IDS_NV_ITEM *IdsPtr = ((IDS_CALLOUT_STRUCT *) ConfigPtr)->IdsNvPtr;
106 if (Data == IDS_CALLOUT_INIT)
107 IdsPtr[0].IdsNvValue = IdsPtr[0].IdsNvId = 0xffff;
108 return AGESA_SUCCESS;
109}
110
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600111AGESA_STATUS agesa_Reset(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600112{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600113 AGESA_STATUS Status;
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600114 UINTN ResetType;
115 AMD_CONFIG_PARAMS *StdHeader;
Marc Jones1587dc82017-05-15 18:55:11 -0600116
117 ResetType = Data;
118 StdHeader = ConfigPtr;
119
Marc Jones4f886cc2017-10-11 20:20:49 -0600120 /*
121 * This should perform the RESET based upon the ResetType, but coreboot
122 * doesn't have a reset manager to handle a WHENEVER case. Do all
123 * resets immediately.
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600124 */
Marc Jones1587dc82017-05-15 18:55:11 -0600125 switch (ResetType) {
126 case WARM_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600127 case WARM_RESET_IMMEDIATELY:
Martin Roth4f92b152017-11-12 10:56:43 -0700128 do_soft_reset();
129 break;
130
131 case COLD_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600132 case COLD_RESET_IMMEDIATELY:
Martin Roth4f92b152017-11-12 10:56:43 -0700133 do_hard_reset();
Marc Jones1587dc82017-05-15 18:55:11 -0600134 break;
135
136 default:
137 break;
138 }
139
140 Status = 0;
141 return Status;
142}
143
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600144AGESA_STATUS agesa_GfxGetVbiosImage(UINT32 Func, UINTN FchData,
145 VOID *ConfigPrt)
Marc Jones1587dc82017-05-15 18:55:11 -0600146{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600147 GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo;
148
149 pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt;
Marc Jones1587dc82017-05-15 18:55:11 -0600150 pVbiosImageInfo->ImagePtr = cbfs_boot_map_with_leak(
151 "pci"CONFIG_VGA_BIOS_ID".rom",
152 CBFS_TYPE_OPTIONROM, NULL);
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600153 printk(BIOS_DEBUG, "agesa_GfxGetVbiosImage: IMGptr=%p\n",
154 pVbiosImageInfo->ImagePtr);
155 return pVbiosImageInfo->ImagePtr ? AGESA_SUCCESS : AGESA_WARNING;
Marc Jones1587dc82017-05-15 18:55:11 -0600156}
157
Marc Jones6e70d672017-10-26 16:42:03 -0600158AGESA_STATUS __attribute__((weak)) platform_PcieSlotResetControl(UINT32 Func,
159 UINTN Data, VOID *ConfigPtr)
160{
161 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
162 __func__);
163 return AGESA_UNSUPPORTED;
164}
165
Martin Rothf80a4312017-09-26 14:45:16 -0600166AGESA_STATUS agesa_PcieSlotResetControl(UINT32 Func, UINTN Data,
167 VOID *ConfigPtr)
168{
Marc Jones6e70d672017-10-26 16:42:03 -0600169 return platform_PcieSlotResetControl(Func, Data, ConfigPtr);
Martin Rothf80a4312017-09-26 14:45:16 -0600170}
171
Marc Jones33eef132017-10-26 16:50:42 -0600172/*
173 * Application Processor callouts:
174 * agesa_RunFuncOnAp() and agesa_RunFcnOnAllAps() are called after main memory
175 * has been initialized and coreboot has taken control of AP task dispatching.
176 * These functions execute callout_ap_entry() on each AP, which calls the
177 * AmdLateRunApTask() entry point if it is a targeted AP.
178 */
179
180/*
181 * Global data for APs.
182 * Passed from the AGESA_Callout for the agesawrapper_amdlaterunaptask.
183 */
184static struct agesa_data {
185 UINT32 Func;
186 UINTN Data;
187 VOID *ConfigPtr;
188} agesadata;
189
190/*
191 * BSP deploys APs to callout_ap_entry(), which calls
192 * agesawrapper_amdlaterunaptask with the agesadata.
193 */
194static void callout_ap_entry(void)
195{
196 AGESA_STATUS Status = AGESA_UNSUPPORTED;
197
198 printk(BIOS_DEBUG, "%s Func: 0x%x, Data: 0x%lx, Ptr: 0x%p \n",
199 __func__, agesadata.Func, agesadata.Data, agesadata.ConfigPtr);
200
201 /* Check if this AP should run the function */
202 if (!((agesadata.Func == AGESA_RUNFUNC_ONAP) &&
203 (agesadata.Data == lapicid())))
204 return;
205
206 Status = agesawrapper_amdlaterunaptask(agesadata.Func, agesadata.Data,
207 agesadata.ConfigPtr);
208
209 if (Status)
210 printk(BIOS_DEBUG, "There was a problem with %lx returned %s\n",
211 lapicid(), decodeAGESA_STATUS(Status));
212}
213
214AGESA_STATUS agesa_RunFuncOnAp(UINT32 Func, UINTN Data, VOID *ConfigPtr)
215{
216 printk(BIOS_DEBUG, "%s\n", __func__);
217
218 agesadata.Func = Func;
219 agesadata.Data = Data;
220 agesadata.ConfigPtr = ConfigPtr;
221 mp_run_on_aps(callout_ap_entry, 100 * USECS_PER_MSEC);
222
223 return AGESA_SUCCESS;
224}
225
226AGESA_STATUS agesa_RunFcnOnAllAps(UINT32 Func, UINTN Data, VOID *ConfigPtr)
227{
228 printk(BIOS_DEBUG, "%s\n", __func__);
229
230 agesadata.Func = Func;
231 agesadata.Data = Data;
232 agesadata.ConfigPtr = ConfigPtr;
233 mp_run_on_aps(callout_ap_entry, 100 * USECS_PER_MSEC);
234
235 return AGESA_SUCCESS;
236}
237
Martin Rothf80a4312017-09-26 14:45:16 -0600238AGESA_STATUS agesa_WaitForAllApsFinished(UINT32 Func, UINTN Data,
239 VOID *ConfigPtr)
240{
Marc Jones33eef132017-10-26 16:50:42 -0600241 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
242 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600243 AGESA_STATUS Status = AGESA_UNSUPPORTED;
244
245 return Status;
246}
247
248AGESA_STATUS agesa_IdleAnAp(UINT32 Func, UINTN Data, VOID *ConfigPtr)
249{
Marc Jones33eef132017-10-26 16:50:42 -0600250 printk(BIOS_WARNING, "Warning - AGESA callout: %s no supported\n",
251 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600252 AGESA_STATUS Status = AGESA_UNSUPPORTED;
253
254 return Status;
255}