coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
def_callouts.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <cbfs.h>
4 #include <console/console.h>
5 #include <cpu/x86/lapic.h>
6 #include <cpu/x86/mp.h>
7 #include <timer.h>
11 #include <amdblocks/reset.h>
12 #include <soc/southbridge.h>
13 #include <types.h>
14 
15 #if ENV_BOOTBLOCK
17  { AGESA_DO_RESET, agesa_Reset },
18  { AGESA_FCH_OEM_CALLOUT, agesa_fch_initreset },
19  { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
20  { AGESA_HEAP_REBASE, agesa_HeapRebase },
21  { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl }
22 };
23 #else
25  /* Required callouts */
26 #if ENV_ROMSTAGE
27  { AGESA_HALT_THIS_AP, agesa_HaltThisAp },
28 #endif
29  { 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 },
34  { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl },
35  { AGESA_GET_TEMP_HEAP_BASE, agesa_GetTempHeapBase },
36  { AGESA_HEAP_REBASE, agesa_HeapRebase },
37 #if ENV_RAMSTAGE
38  { AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
39  { AGESA_RUNFUNC_ON_ALL_APS, agesa_RunFcnOnAllAps },
40  { AGESA_WAIT_FOR_ALL_APS, agesa_WaitForAllApsFinished },
41  { AGESA_IDLE_AN_AP, agesa_IdleAnAp },
42 #endif /* ENV_RAMSTAGE */
43 
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 
64 
65 AGESA_STATUS GetBiosCallout(uint32_t Func, uintptr_t Data, void *ConfigPtr)
66 {
67  uintptr_t i;
68 
69  for (i = 0 ; i < BiosCalloutsLen ; i++) {
70  if (BiosCallouts[i].CalloutName == Func)
71  break;
72  }
73 
74  if (i >= BiosCalloutsLen) {
75  printk(BIOS_ERR, "AGESA Callout Not Supported: 0x%x\n",
76  (u32)Func);
77  return AGESA_UNSUPPORTED;
78  }
79 
80  return BiosCallouts[i].CalloutPtr(Func, Data, ConfigPtr);
81 }
82 
84  void *ConfigPtr)
85 {
86  return AGESA_UNSUPPORTED;
87 }
88 
89 AGESA_STATUS agesa_NoopSuccess(uint32_t Func, uintptr_t Data, void *ConfigPtr)
90 {
91  return AGESA_SUCCESS;
92 }
93 
95  void *ConfigPtr)
96 {
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 
103 AGESA_STATUS agesa_Reset(uint32_t Func, uintptr_t Data, void *ConfigPtr)
104 {
105  AGESA_STATUS Status;
106  uintptr_t ResetType;
107 
108  ResetType = Data;
109 
110  /*
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.
114  */
115  switch (ResetType) {
116  case WARM_RESET_WHENEVER:
117  case WARM_RESET_IMMEDIATELY:
118  warm_reset();
119  break;
120 
121  case COLD_RESET_WHENEVER:
122  case COLD_RESET_IMMEDIATELY:
123  cold_reset();
124  break;
125 
126  default:
127  break;
128  }
129 
130  Status = 0;
131  return Status;
132 }
133 
135  void *ConfigPrt)
136 {
137  GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo;
138 
139  pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt;
140  pVbiosImageInfo->ImagePtr = cbfs_map(
141  "pci"CONFIG_VGA_BIOS_ID".rom", NULL);
142  printk(BIOS_DEBUG, "%s: IMGptr=%p\n", __func__,
143  pVbiosImageInfo->ImagePtr);
144  return pVbiosImageInfo->ImagePtr ? AGESA_SUCCESS : AGESA_WARNING;
145 }
146 
148  uintptr_t Data, void *ConfigPtr)
149 {
150  printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
151  __func__);
152  return AGESA_UNSUPPORTED;
153 }
154 
156  void *ConfigPtr)
157 {
158  return platform_PcieSlotResetControl(Func, Data, ConfigPtr);
159 }
160 
161 /*
162  * Application Processor callouts:
163  * agesa_RunFuncOnAp() and agesa_RunFcnOnAllAps() are called after main memory
164  * has been initialized and coreboot has taken control of AP task dispatching.
165  * These functions execute callout_ap_entry() on each AP, which calls the
166  * AmdLateRunApTask() entry point if it is a targeted AP.
167  */
168 
169 /*
170  * Global data for APs.
171  * Passed from the AGESA_Callout for the agesawrapper_amdlaterunaptask.
172  */
173 static struct agesa_data {
176  AP_EXE_PARAMS *ConfigPtr;
178 
179 /*
180  * BSP deploys APs to callout_ap_entry(), which calls
181  * agesawrapper_amdlaterunaptask with the agesadata.
182  */
183 static void callout_ap_entry(void *unused)
184 {
186 
187  printk(BIOS_DEBUG, "%s Func: 0x%x, Data: 0x%lx, Ptr: %p\n",
189 
190  /* Check if this AP should run the function */
191  if (!((agesadata.Func == AGESA_RUNFUNC_ONAP) &&
192  (agesadata.Data == lapicid())))
193  return;
194 
196 
197  if (Status)
198  printk(BIOS_DEBUG, "There was a problem with %x returned %s\n",
199  lapicid(), decodeAGESA_STATUS(Status));
200 }
201 
202 AGESA_STATUS agesa_RunFuncOnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr)
203 {
204  printk(BIOS_DEBUG, "%s\n", __func__);
205 
206  agesadata.Func = Func;
207  agesadata.Data = Data;
208  agesadata.ConfigPtr = ConfigPtr;
210  CB_SUCCESS)
211  return AGESA_ERROR;
212 
213  return AGESA_SUCCESS;
214 }
215 
217  void *ConfigPtr)
218 {
219  printk(BIOS_DEBUG, "%s\n", __func__);
220 
221  agesadata.Func = Func;
222  agesadata.Data = Data;
223  agesadata.ConfigPtr = ConfigPtr;
225  CB_SUCCESS)
226  return AGESA_ERROR;
227 
228  return AGESA_SUCCESS;
229 }
230 
232  void *ConfigPtr)
233 {
234  printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n",
235  __func__);
237 
238  return Status;
239 }
240 
241 AGESA_STATUS agesa_IdleAnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr)
242 {
243  printk(BIOS_WARNING, "Warning - AGESA callout: %s no supported\n",
244  __func__);
246 
247  return Status;
248 }
#define AGESA_SUCCESS
Definition: Amd.h:38
#define AGESA_WARNING
Definition: Amd.h:40
unsigned int AGESA_STATUS
Definition: Amd.h:36
#define AGESA_ERROR
Definition: Amd.h:42
#define AGESA_UNSUPPORTED
Definition: Amd.h:41
AGESA_STATUS amd_late_run_ap_task(AP_EXE_PARAMS *ApExeParams)
Definition: agesawrapper.c:48
#define ARRAY_SIZE(a)
Definition: helpers.h:12
@ CB_SUCCESS
Call completed successfully.
Definition: cb_err.h:16
static void * cbfs_map(const char *name, size_t *size_out)
Definition: cbfs.h:246
#define printk(level,...)
Definition: stdlib.h:16
enum cb_err mp_run_on_aps(void(*func)(void *), void *arg, int logical_cpu_num, long expire_us)
Definition: mp_init.c:971
AGESA_STATUS agesa_RunFuncOnAp(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Definition: def_callouts.c:102
AGESA_STATUS agesa_EmptyIdsInitData(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Definition: def_callouts.c:58
AGESA_STATUS agesa_ReadSpd(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Definition: def_callouts.c:130
AGESA_STATUS GetBiosCallout(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Definition: def_callouts.c:19
AGESA_STATUS agesa_NoopUnsupported(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Definition: def_callouts.c:48
AGESA_STATUS agesa_NoopSuccess(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Definition: def_callouts.c:53
AGESA_STATUS agesa_Reset(UINT32 Func, UINTN Data, VOID *ConfigPtr)
Definition: def_callouts.c:66
static AGESA_STATUS agesa_DeallocateBuffer(BIOS_HEAP_MANAGER *BiosHeapBasePtr, AGESA_BUFFER_PARAMS *AllocParams)
Definition: heapmanager.c:207
static AGESA_STATUS agesa_AllocateBuffer(BIOS_HEAP_MANAGER *BiosHeapBasePtr, AGESA_BUFFER_PARAMS *AllocParams)
Definition: heapmanager.c:81
static AGESA_STATUS agesa_LocateBuffer(BIOS_HEAP_MANAGER *BiosHeapBasePtr, AGESA_BUFFER_PARAMS *AllocParams)
Definition: heapmanager.c:324
static const char * decodeAGESA_STATUS(AGESA_STATUS sret)
Definition: eventlog.c:141
#define USECS_PER_MSEC
Definition: timer.h:10
static __always_inline unsigned int lapicid(void)
Definition: lapic.h:136
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
@ MP_RUN_ON_ALL_CPUS
Definition: mp.h:94
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
AGESA_STATUS agesa_HaltThisAp(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Definition: BiosCallOuts.c:126
AGESA_STATUS agesa_HeapRebase(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Definition: heapmanager.c:58
AGESA_STATUS agesa_GetTempHeapBase(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Definition: heapmanager.c:34
AGESA_STATUS agesa_fch_initenv(uint32_t Func, uintptr_t FchData, void *ConfigPtr)
Definition: BiosCallOuts.c:36
AGESA_STATUS agesa_fch_initreset(uint32_t Func, uintptr_t FchData, void *ConfigPtr)
Definition: BiosCallOuts.c:17
static __noreturn void warm_reset(void)
Definition: reset.h:15
static __noreturn void cold_reset(void)
Definition: reset.h:23
AGESA_STATUS agesa_GfxGetVbiosImage(uint32_t Func, uintptr_t FchData, void *ConfigPrt)
Definition: def_callouts.c:134
AGESA_STATUS agesa_WaitForAllApsFinished(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Definition: def_callouts.c:231
AGESA_STATUS agesa_RunFcnOnAllAps(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Definition: def_callouts.c:216
const int BiosCalloutsLen
Definition: def_callouts.c:63
AGESA_STATUS agesa_IdleAnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Definition: def_callouts.c:241
static void callout_ap_entry(void *unused)
Definition: def_callouts.c:183
AGESA_STATUS agesa_PcieSlotResetControl(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Definition: def_callouts.c:155
static struct agesa_data agesadata
const BIOS_CALLOUT_STRUCT BiosCallouts[]
Definition: def_callouts.c:24
AGESA_STATUS __weak platform_PcieSlotResetControl(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Definition: def_callouts.c:147
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
unsigned long uintptr_t
Definition: stdint.h:21
CALLOUT_ENTRY CalloutPtr
Definition: BiosCallOuts.h:24
AP_EXE_PARAMS * ConfigPtr
Definition: def_callouts.c:176
uintptr_t Data
Definition: def_callouts.c:175
uint32_t Func
Definition: def_callouts.c:174