Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 2 | |
| 3 | #include <cbfs.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 4 | #include <console/console.h> |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 5 | #include <cpu/x86/lapic.h> |
| 6 | #include <cpu/x86/mp.h> |
| 7 | #include <timer.h> |
Richard Spiegel | 0ad74ac | 2017-12-08 16:53:29 -0700 | [diff] [blame] | 8 | #include <amdblocks/BiosCallOuts.h> |
| 9 | #include <amdblocks/agesawrapper.h> |
| 10 | #include <amdblocks/agesawrapper_call.h> |
Nico Huber | 73c1119 | 2018-10-06 18:20:47 +0200 | [diff] [blame] | 11 | #include <amdblocks/reset.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 12 | #include <soc/southbridge.h> |
Felix Held | 82faefb | 2021-10-20 20:50:58 +0200 | [diff] [blame] | 13 | #include <types.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 14 | |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 15 | #if ENV_BOOTBLOCK |
| 16 | const BIOS_CALLOUT_STRUCT BiosCallouts[] = { |
| 17 | { AGESA_DO_RESET, agesa_Reset }, |
| 18 | { AGESA_FCH_OEM_CALLOUT, agesa_fch_initreset }, |
Richard Spiegel | a9f4936 | 2018-03-05 08:11:50 -0700 | [diff] [blame] | 19 | { AGESA_HALT_THIS_AP, agesa_HaltThisAp }, |
Marshall Dawson | c150a57 | 2018-04-30 17:59:27 -0600 | [diff] [blame] | 20 | { AGESA_HEAP_REBASE, agesa_HeapRebase }, |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 21 | { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl } |
| 22 | }; |
| 23 | #else |
| 24 | const BIOS_CALLOUT_STRUCT BiosCallouts[] = { |
| 25 | /* Required callouts */ |
Richard Spiegel | 09a16e6 | 2018-04-04 12:40:20 -0700 | [diff] [blame] | 26 | #if ENV_ROMSTAGE |
| 27 | { AGESA_HALT_THIS_AP, agesa_HaltThisAp }, |
| 28 | #endif |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 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 }, |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 34 | { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl }, |
Marshall Dawson | 10b52e0 | 2018-05-07 08:51:04 -0600 | [diff] [blame] | 35 | { AGESA_GET_TEMP_HEAP_BASE, agesa_GetTempHeapBase }, |
Marshall Dawson | c150a57 | 2018-04-30 17:59:27 -0600 | [diff] [blame] | 36 | { AGESA_HEAP_REBASE, agesa_HeapRebase }, |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 37 | #if ENV_RAMSTAGE |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 38 | { AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp }, |
| 39 | { AGESA_RUNFUNC_ON_ALL_APS, agesa_RunFcnOnAllAps }, |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 40 | { AGESA_WAIT_FOR_ALL_APS, agesa_WaitForAllApsFinished }, |
| 41 | { AGESA_IDLE_AN_AP, agesa_IdleAnAp }, |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 42 | #endif /* ENV_RAMSTAGE */ |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 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 | |
| 63 | const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts); |
| 64 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 65 | AGESA_STATUS GetBiosCallout(uint32_t Func, uintptr_t Data, void *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 66 | { |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 67 | uintptr_t i; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 68 | |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 69 | for (i = 0 ; i < BiosCalloutsLen ; i++) { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 70 | if (BiosCallouts[i].CalloutName == Func) |
| 71 | break; |
| 72 | } |
Marc Jones | 7e710e0 | 2017-10-12 15:19:51 -0600 | [diff] [blame] | 73 | |
| 74 | if (i >= BiosCalloutsLen) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame^] | 75 | printk(BIOS_ERR, "AGESA Callout Not Supported: 0x%x\n", |
Marc Jones | 7e710e0 | 2017-10-12 15:19:51 -0600 | [diff] [blame] | 76 | (u32)Func); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 77 | return AGESA_UNSUPPORTED; |
Marc Jones | 7e710e0 | 2017-10-12 15:19:51 -0600 | [diff] [blame] | 78 | } |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 79 | |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 80 | return BiosCallouts[i].CalloutPtr(Func, Data, ConfigPtr); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 81 | } |
| 82 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 83 | AGESA_STATUS agesa_NoopUnsupported(uint32_t Func, uintptr_t Data, |
| 84 | void *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 85 | { |
| 86 | return AGESA_UNSUPPORTED; |
| 87 | } |
| 88 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 89 | AGESA_STATUS agesa_NoopSuccess(uint32_t Func, uintptr_t Data, void *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 90 | { |
| 91 | return AGESA_SUCCESS; |
| 92 | } |
| 93 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 94 | AGESA_STATUS agesa_EmptyIdsInitData(uint32_t Func, uintptr_t Data, |
| 95 | void *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 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 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 103 | AGESA_STATUS agesa_Reset(uint32_t Func, uintptr_t Data, void *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 104 | { |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 105 | AGESA_STATUS Status; |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 106 | uintptr_t ResetType; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 107 | |
| 108 | ResetType = Data; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 109 | |
Marc Jones | 4f886cc | 2017-10-11 20:20:49 -0600 | [diff] [blame] | 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. |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 114 | */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 115 | switch (ResetType) { |
| 116 | case WARM_RESET_WHENEVER: |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 117 | case WARM_RESET_IMMEDIATELY: |
Nico Huber | 73c1119 | 2018-10-06 18:20:47 +0200 | [diff] [blame] | 118 | warm_reset(); |
Martin Roth | 4f92b15 | 2017-11-12 10:56:43 -0700 | [diff] [blame] | 119 | break; |
| 120 | |
| 121 | case COLD_RESET_WHENEVER: |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 122 | case COLD_RESET_IMMEDIATELY: |
Nico Huber | 73c1119 | 2018-10-06 18:20:47 +0200 | [diff] [blame] | 123 | cold_reset(); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 124 | break; |
| 125 | |
| 126 | default: |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | Status = 0; |
| 131 | return Status; |
| 132 | } |
| 133 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 134 | AGESA_STATUS agesa_GfxGetVbiosImage(uint32_t Func, uintptr_t FchData, |
| 135 | void *ConfigPrt) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 136 | { |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 137 | GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo; |
| 138 | |
| 139 | pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt; |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 140 | pVbiosImageInfo->ImagePtr = cbfs_map( |
| 141 | "pci"CONFIG_VGA_BIOS_ID".rom", NULL); |
Richard Spiegel | de332f3 | 2018-10-23 14:34:12 -0700 | [diff] [blame] | 142 | printk(BIOS_DEBUG, "%s: IMGptr=%p\n", __func__, |
| 143 | pVbiosImageInfo->ImagePtr); |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 144 | return pVbiosImageInfo->ImagePtr ? AGESA_SUCCESS : AGESA_WARNING; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 145 | } |
| 146 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 147 | AGESA_STATUS __weak platform_PcieSlotResetControl(uint32_t Func, |
| 148 | uintptr_t Data, void *ConfigPtr) |
Marc Jones | 6e70d67 | 2017-10-26 16:42:03 -0600 | [diff] [blame] | 149 | { |
| 150 | printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n", |
| 151 | __func__); |
| 152 | return AGESA_UNSUPPORTED; |
| 153 | } |
| 154 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 155 | AGESA_STATUS agesa_PcieSlotResetControl(uint32_t Func, uintptr_t Data, |
| 156 | void *ConfigPtr) |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 157 | { |
Marc Jones | 6e70d67 | 2017-10-26 16:42:03 -0600 | [diff] [blame] | 158 | return platform_PcieSlotResetControl(Func, Data, ConfigPtr); |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 159 | } |
| 160 | |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 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 { |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 174 | uint32_t Func; |
| 175 | uintptr_t Data; |
Kyösti Mälkki | 423d03c | 2018-06-28 21:18:12 +0300 | [diff] [blame] | 176 | AP_EXE_PARAMS *ConfigPtr; |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 177 | } agesadata; |
| 178 | |
| 179 | /* |
| 180 | * BSP deploys APs to callout_ap_entry(), which calls |
| 181 | * agesawrapper_amdlaterunaptask with the agesadata. |
| 182 | */ |
Subrata Banik | 3337497 | 2018-04-24 13:45:30 +0530 | [diff] [blame] | 183 | static void callout_ap_entry(void *unused) |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 184 | { |
| 185 | AGESA_STATUS Status = AGESA_UNSUPPORTED; |
| 186 | |
Julius Werner | 540a980 | 2019-12-09 13:03:29 -0800 | [diff] [blame] | 187 | printk(BIOS_DEBUG, "%s Func: 0x%x, Data: 0x%lx, Ptr: %p\n", |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 188 | __func__, agesadata.Func, agesadata.Data, agesadata.ConfigPtr); |
| 189 | |
| 190 | /* Check if this AP should run the function */ |
| 191 | if (!((agesadata.Func == AGESA_RUNFUNC_ONAP) && |
| 192 | (agesadata.Data == lapicid()))) |
| 193 | return; |
| 194 | |
Kyösti Mälkki | 423d03c | 2018-06-28 21:18:12 +0300 | [diff] [blame] | 195 | Status = amd_late_run_ap_task(agesadata.ConfigPtr); |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 196 | |
| 197 | if (Status) |
Patrick Rudolph | fc57d6c | 2019-11-12 16:30:14 +0100 | [diff] [blame] | 198 | printk(BIOS_DEBUG, "There was a problem with %x returned %s\n", |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 199 | lapicid(), decodeAGESA_STATUS(Status)); |
| 200 | } |
| 201 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 202 | AGESA_STATUS agesa_RunFuncOnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr) |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 203 | { |
| 204 | printk(BIOS_DEBUG, "%s\n", __func__); |
| 205 | |
| 206 | agesadata.Func = Func; |
| 207 | agesadata.Data = Data; |
| 208 | agesadata.ConfigPtr = ConfigPtr; |
Felix Held | 82faefb | 2021-10-20 20:50:58 +0200 | [diff] [blame] | 209 | if (mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS, 100 * USECS_PER_MSEC) != |
| 210 | CB_SUCCESS) |
Patrick Rudolph | be207b1 | 2019-07-26 14:22:09 +0200 | [diff] [blame] | 211 | return AGESA_ERROR; |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 212 | |
| 213 | return AGESA_SUCCESS; |
| 214 | } |
| 215 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 216 | AGESA_STATUS agesa_RunFcnOnAllAps(uint32_t Func, uintptr_t Data, |
| 217 | void *ConfigPtr) |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 218 | { |
| 219 | printk(BIOS_DEBUG, "%s\n", __func__); |
| 220 | |
| 221 | agesadata.Func = Func; |
| 222 | agesadata.Data = Data; |
| 223 | agesadata.ConfigPtr = ConfigPtr; |
Felix Held | 82faefb | 2021-10-20 20:50:58 +0200 | [diff] [blame] | 224 | if (mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS, 100 * USECS_PER_MSEC) != |
| 225 | CB_SUCCESS) |
Patrick Rudolph | be207b1 | 2019-07-26 14:22:09 +0200 | [diff] [blame] | 226 | return AGESA_ERROR; |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 227 | |
| 228 | return AGESA_SUCCESS; |
| 229 | } |
| 230 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 231 | AGESA_STATUS agesa_WaitForAllApsFinished(uint32_t Func, uintptr_t Data, |
| 232 | void *ConfigPtr) |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 233 | { |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 234 | printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n", |
| 235 | __func__); |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 236 | AGESA_STATUS Status = AGESA_UNSUPPORTED; |
| 237 | |
| 238 | return Status; |
| 239 | } |
| 240 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 241 | AGESA_STATUS agesa_IdleAnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr) |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 242 | { |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 243 | printk(BIOS_WARNING, "Warning - AGESA callout: %s no supported\n", |
| 244 | __func__); |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 245 | AGESA_STATUS Status = AGESA_UNSUPPORTED; |
| 246 | |
| 247 | return Status; |
| 248 | } |