blob: c05d4de8cc58c75465b9adc2fb4b38bdd5a80622 [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 },
32 { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl }
33};
34#else
35const BIOS_CALLOUT_STRUCT BiosCallouts[] = {
36 /* Required callouts */
37 { AGESA_ALLOCATE_BUFFER, agesa_AllocateBuffer },
38 { AGESA_DEALLOCATE_BUFFER, agesa_DeallocateBuffer },
39 { AGESA_DO_RESET, agesa_Reset },
40 { AGESA_LOCATE_BUFFER, agesa_LocateBuffer },
41 { AGESA_READ_SPD, agesa_ReadSpd },
Marc Jones33eef132017-10-26 16:50:42 -060042 { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl },
43#if ENV_RAMSTAGE
Martin Rothc450fbe2017-10-02 13:46:50 -060044 { AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
45 { AGESA_RUNFUNC_ON_ALL_APS, agesa_RunFcnOnAllAps },
Martin Rothc450fbe2017-10-02 13:46:50 -060046 { AGESA_WAIT_FOR_ALL_APS, agesa_WaitForAllApsFinished },
47 { AGESA_IDLE_AN_AP, agesa_IdleAnAp },
Marc Jones33eef132017-10-26 16:50:42 -060048#endif /* ENV_RAMSTAGE */
Martin Rothc450fbe2017-10-02 13:46:50 -060049
50 /* Optional callouts */
51 { AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData },
52 //AgesaHeapRebase - Hook ID?
53 { AGESA_HOOKBEFORE_DRAM_INIT, agesa_NoopUnsupported },
54 { AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopUnsupported },
55 { AGESA_EXTERNAL_2D_TRAIN_VREF_CHANGE, agesa_NoopUnsupported },
56 { AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopUnsupported },
57 { AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage },
58 { AGESA_FCH_OEM_CALLOUT, agesa_fch_initenv },
59 { AGESA_EXTERNAL_VOLTAGE_ADJUST, agesa_NoopUnsupported },
60 { AGESA_GNB_PCIE_CLK_REQ, agesa_NoopUnsupported },
61
62 /* Deprecated */
63 { AGESA_HOOKBEFORE_DRAM_INIT_RECOVERY, agesa_NoopUnsupported},
64 { AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported },
65
66};
67#endif
68
69const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts);
70
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060071AGESA_STATUS GetBiosCallout(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060072{
73 UINTN i;
74
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060075 for (i = 0 ; i < BiosCalloutsLen ; i++) {
Marc Jones1587dc82017-05-15 18:55:11 -060076 if (BiosCallouts[i].CalloutName == Func)
77 break;
78 }
Marc Jones7e710e02017-10-12 15:19:51 -060079
80 if (i >= BiosCalloutsLen) {
81 printk(BIOS_ERR, "ERROR: AGESA Callout Not Supported: 0x%x",
82 (u32)Func);
Marc Jones1587dc82017-05-15 18:55:11 -060083 return AGESA_UNSUPPORTED;
Marc Jones7e710e02017-10-12 15:19:51 -060084 }
Marc Jones1587dc82017-05-15 18:55:11 -060085
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060086 return BiosCallouts[i].CalloutPtr(Func, Data, ConfigPtr);
Marc Jones1587dc82017-05-15 18:55:11 -060087}
88
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060089AGESA_STATUS agesa_NoopUnsupported(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060090{
91 return AGESA_UNSUPPORTED;
92}
93
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060094AGESA_STATUS agesa_NoopSuccess(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -060095{
96 return AGESA_SUCCESS;
97}
98
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -060099AGESA_STATUS agesa_EmptyIdsInitData(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600100{
101 IDS_NV_ITEM *IdsPtr = ((IDS_CALLOUT_STRUCT *) ConfigPtr)->IdsNvPtr;
102 if (Data == IDS_CALLOUT_INIT)
103 IdsPtr[0].IdsNvValue = IdsPtr[0].IdsNvId = 0xffff;
104 return AGESA_SUCCESS;
105}
106
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600107AGESA_STATUS agesa_Reset(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Marc Jones1587dc82017-05-15 18:55:11 -0600108{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600109 AGESA_STATUS Status;
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600110 UINTN ResetType;
111 AMD_CONFIG_PARAMS *StdHeader;
Marc Jones1587dc82017-05-15 18:55:11 -0600112
113 ResetType = Data;
114 StdHeader = ConfigPtr;
115
Marc Jones4f886cc2017-10-11 20:20:49 -0600116 /*
117 * This should perform the RESET based upon the ResetType, but coreboot
118 * doesn't have a reset manager to handle a WHENEVER case. Do all
119 * resets immediately.
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600120 */
Marc Jones1587dc82017-05-15 18:55:11 -0600121 switch (ResetType) {
122 case WARM_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600123 case WARM_RESET_IMMEDIATELY:
Martin Roth4f92b152017-11-12 10:56:43 -0700124 do_soft_reset();
125 break;
126
127 case COLD_RESET_WHENEVER:
Marc Jones1587dc82017-05-15 18:55:11 -0600128 case COLD_RESET_IMMEDIATELY:
Martin Roth4f92b152017-11-12 10:56:43 -0700129 do_hard_reset();
Marc Jones1587dc82017-05-15 18:55:11 -0600130 break;
131
132 default:
133 break;
134 }
135
136 Status = 0;
137 return Status;
138}
139
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600140AGESA_STATUS agesa_GfxGetVbiosImage(UINT32 Func, UINTN FchData,
141 VOID *ConfigPrt)
Marc Jones1587dc82017-05-15 18:55:11 -0600142{
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600143 GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo;
144
145 pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt;
Marc Jones1587dc82017-05-15 18:55:11 -0600146 pVbiosImageInfo->ImagePtr = cbfs_boot_map_with_leak(
147 "pci"CONFIG_VGA_BIOS_ID".rom",
148 CBFS_TYPE_OPTIONROM, NULL);
Marshall Dawsonf3dc71e2017-06-14 16:22:07 -0600149 printk(BIOS_DEBUG, "agesa_GfxGetVbiosImage: IMGptr=%p\n",
150 pVbiosImageInfo->ImagePtr);
151 return pVbiosImageInfo->ImagePtr ? AGESA_SUCCESS : AGESA_WARNING;
Marc Jones1587dc82017-05-15 18:55:11 -0600152}
153
Marc Jones6e70d672017-10-26 16:42:03 -0600154AGESA_STATUS __attribute__((weak)) platform_PcieSlotResetControl(UINT32 Func,
155 UINTN Data, VOID *ConfigPtr)
156{
157 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
158 __func__);
159 return AGESA_UNSUPPORTED;
160}
161
Martin Rothf80a4312017-09-26 14:45:16 -0600162AGESA_STATUS agesa_PcieSlotResetControl(UINT32 Func, UINTN Data,
163 VOID *ConfigPtr)
164{
Marc Jones6e70d672017-10-26 16:42:03 -0600165 return platform_PcieSlotResetControl(Func, Data, ConfigPtr);
Martin Rothf80a4312017-09-26 14:45:16 -0600166}
167
Marc Jones33eef132017-10-26 16:50:42 -0600168/*
169 * Application Processor callouts:
170 * agesa_RunFuncOnAp() and agesa_RunFcnOnAllAps() are called after main memory
171 * has been initialized and coreboot has taken control of AP task dispatching.
172 * These functions execute callout_ap_entry() on each AP, which calls the
173 * AmdLateRunApTask() entry point if it is a targeted AP.
174 */
175
176/*
177 * Global data for APs.
178 * Passed from the AGESA_Callout for the agesawrapper_amdlaterunaptask.
179 */
180static struct agesa_data {
181 UINT32 Func;
182 UINTN Data;
183 VOID *ConfigPtr;
184} agesadata;
185
186/*
187 * BSP deploys APs to callout_ap_entry(), which calls
188 * agesawrapper_amdlaterunaptask with the agesadata.
189 */
190static void callout_ap_entry(void)
191{
192 AGESA_STATUS Status = AGESA_UNSUPPORTED;
193
194 printk(BIOS_DEBUG, "%s Func: 0x%x, Data: 0x%lx, Ptr: 0x%p \n",
195 __func__, agesadata.Func, agesadata.Data, agesadata.ConfigPtr);
196
197 /* Check if this AP should run the function */
198 if (!((agesadata.Func == AGESA_RUNFUNC_ONAP) &&
199 (agesadata.Data == lapicid())))
200 return;
201
202 Status = agesawrapper_amdlaterunaptask(agesadata.Func, agesadata.Data,
203 agesadata.ConfigPtr);
204
205 if (Status)
206 printk(BIOS_DEBUG, "There was a problem with %lx returned %s\n",
207 lapicid(), decodeAGESA_STATUS(Status));
208}
209
210AGESA_STATUS agesa_RunFuncOnAp(UINT32 Func, UINTN Data, VOID *ConfigPtr)
211{
212 printk(BIOS_DEBUG, "%s\n", __func__);
213
214 agesadata.Func = Func;
215 agesadata.Data = Data;
216 agesadata.ConfigPtr = ConfigPtr;
217 mp_run_on_aps(callout_ap_entry, 100 * USECS_PER_MSEC);
218
219 return AGESA_SUCCESS;
220}
221
222AGESA_STATUS agesa_RunFcnOnAllAps(UINT32 Func, UINTN Data, VOID *ConfigPtr)
223{
224 printk(BIOS_DEBUG, "%s\n", __func__);
225
226 agesadata.Func = Func;
227 agesadata.Data = Data;
228 agesadata.ConfigPtr = ConfigPtr;
229 mp_run_on_aps(callout_ap_entry, 100 * USECS_PER_MSEC);
230
231 return AGESA_SUCCESS;
232}
233
Martin Rothf80a4312017-09-26 14:45:16 -0600234AGESA_STATUS agesa_WaitForAllApsFinished(UINT32 Func, UINTN Data,
235 VOID *ConfigPtr)
236{
Marc Jones33eef132017-10-26 16:50:42 -0600237 printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
238 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600239 AGESA_STATUS Status = AGESA_UNSUPPORTED;
240
241 return Status;
242}
243
244AGESA_STATUS agesa_IdleAnAp(UINT32 Func, UINTN Data, VOID *ConfigPtr)
245{
Marc Jones33eef132017-10-26 16:50:42 -0600246 printk(BIOS_WARNING, "Warning - AGESA callout: %s no supported\n",
247 __func__);
Martin Rothf80a4312017-09-26 14:45:16 -0600248 AGESA_STATUS Status = AGESA_UNSUPPORTED;
249
250 return Status;
251}