Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 1 | /* |
| 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 Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 18 | #include <cpu/x86/lapic.h> |
| 19 | #include <cpu/x86/mp.h> |
| 20 | #include <timer.h> |
Richard Spiegel | 0ad74ac | 2017-12-08 16:53:29 -0700 | [diff] [blame] | 21 | #include <amdblocks/BiosCallOuts.h> |
| 22 | #include <amdblocks/agesawrapper.h> |
| 23 | #include <amdblocks/agesawrapper_call.h> |
Nico Huber | 73c1119 | 2018-10-06 18:20:47 +0200 | [diff] [blame] | 24 | #include <amdblocks/reset.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 25 | #include <soc/southbridge.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 26 | |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 27 | #if ENV_BOOTBLOCK |
| 28 | const BIOS_CALLOUT_STRUCT BiosCallouts[] = { |
| 29 | { AGESA_DO_RESET, agesa_Reset }, |
| 30 | { AGESA_FCH_OEM_CALLOUT, agesa_fch_initreset }, |
Richard Spiegel | a9f4936 | 2018-03-05 08:11:50 -0700 | [diff] [blame] | 31 | { AGESA_HALT_THIS_AP, agesa_HaltThisAp }, |
Marshall Dawson | c150a57 | 2018-04-30 17:59:27 -0600 | [diff] [blame] | 32 | { AGESA_HEAP_REBASE, agesa_HeapRebase }, |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 33 | { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl } |
| 34 | }; |
| 35 | #else |
| 36 | const BIOS_CALLOUT_STRUCT BiosCallouts[] = { |
| 37 | /* Required callouts */ |
Richard Spiegel | 09a16e6 | 2018-04-04 12:40:20 -0700 | [diff] [blame] | 38 | #if ENV_ROMSTAGE |
| 39 | { AGESA_HALT_THIS_AP, agesa_HaltThisAp }, |
| 40 | #endif |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 41 | { 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 Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 46 | { AGESA_GNB_PCIE_SLOT_RESET, agesa_PcieSlotResetControl }, |
Marshall Dawson | 10b52e0 | 2018-05-07 08:51:04 -0600 | [diff] [blame] | 47 | { AGESA_GET_TEMP_HEAP_BASE, agesa_GetTempHeapBase }, |
Marshall Dawson | c150a57 | 2018-04-30 17:59:27 -0600 | [diff] [blame] | 48 | { AGESA_HEAP_REBASE, agesa_HeapRebase }, |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 49 | #if ENV_RAMSTAGE |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 50 | { AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp }, |
| 51 | { AGESA_RUNFUNC_ON_ALL_APS, agesa_RunFcnOnAllAps }, |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 52 | { AGESA_WAIT_FOR_ALL_APS, agesa_WaitForAllApsFinished }, |
| 53 | { AGESA_IDLE_AN_AP, agesa_IdleAnAp }, |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 54 | #endif /* ENV_RAMSTAGE */ |
Martin Roth | c450fbe | 2017-10-02 13:46:50 -0600 | [diff] [blame] | 55 | |
| 56 | /* Optional callouts */ |
| 57 | { AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData }, |
| 58 | //AgesaHeapRebase - Hook ID? |
| 59 | { AGESA_HOOKBEFORE_DRAM_INIT, agesa_NoopUnsupported }, |
| 60 | { AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopUnsupported }, |
| 61 | { AGESA_EXTERNAL_2D_TRAIN_VREF_CHANGE, agesa_NoopUnsupported }, |
| 62 | { AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopUnsupported }, |
| 63 | { AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage }, |
| 64 | { AGESA_FCH_OEM_CALLOUT, agesa_fch_initenv }, |
| 65 | { AGESA_EXTERNAL_VOLTAGE_ADJUST, agesa_NoopUnsupported }, |
| 66 | { AGESA_GNB_PCIE_CLK_REQ, agesa_NoopUnsupported }, |
| 67 | |
| 68 | /* Deprecated */ |
| 69 | { AGESA_HOOKBEFORE_DRAM_INIT_RECOVERY, agesa_NoopUnsupported}, |
| 70 | { AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported }, |
| 71 | |
| 72 | }; |
| 73 | #endif |
| 74 | |
| 75 | const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts); |
| 76 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 77 | AGESA_STATUS GetBiosCallout(uint32_t Func, uintptr_t Data, void *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 78 | { |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 79 | uintptr_t i; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 80 | |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 81 | for (i = 0 ; i < BiosCalloutsLen ; i++) { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 82 | if (BiosCallouts[i].CalloutName == Func) |
| 83 | break; |
| 84 | } |
Marc Jones | 7e710e0 | 2017-10-12 15:19:51 -0600 | [diff] [blame] | 85 | |
| 86 | if (i >= BiosCalloutsLen) { |
Marshall Dawson | 492e4db | 2018-05-01 11:12:51 -0600 | [diff] [blame] | 87 | printk(BIOS_ERR, "ERROR: AGESA Callout Not Supported: 0x%x\n", |
Marc Jones | 7e710e0 | 2017-10-12 15:19:51 -0600 | [diff] [blame] | 88 | (u32)Func); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 89 | return AGESA_UNSUPPORTED; |
Marc Jones | 7e710e0 | 2017-10-12 15:19:51 -0600 | [diff] [blame] | 90 | } |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 91 | |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 92 | return BiosCallouts[i].CalloutPtr(Func, Data, ConfigPtr); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 93 | } |
| 94 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 95 | AGESA_STATUS agesa_NoopUnsupported(uint32_t Func, uintptr_t Data, |
| 96 | void *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 97 | { |
| 98 | return AGESA_UNSUPPORTED; |
| 99 | } |
| 100 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 101 | AGESA_STATUS agesa_NoopSuccess(uint32_t Func, uintptr_t Data, void *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 102 | { |
| 103 | return AGESA_SUCCESS; |
| 104 | } |
| 105 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 106 | AGESA_STATUS agesa_EmptyIdsInitData(uint32_t Func, uintptr_t Data, |
| 107 | void *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 108 | { |
| 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 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 115 | AGESA_STATUS agesa_Reset(uint32_t Func, uintptr_t Data, void *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 116 | { |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 117 | AGESA_STATUS Status; |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 118 | uintptr_t ResetType; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 119 | |
| 120 | ResetType = Data; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 121 | |
Marc Jones | 4f886cc | 2017-10-11 20:20:49 -0600 | [diff] [blame] | 122 | /* |
| 123 | * This should perform the RESET based upon the ResetType, but coreboot |
| 124 | * doesn't have a reset manager to handle a WHENEVER case. Do all |
| 125 | * resets immediately. |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 126 | */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 127 | switch (ResetType) { |
| 128 | case WARM_RESET_WHENEVER: |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 129 | case WARM_RESET_IMMEDIATELY: |
Nico Huber | 73c1119 | 2018-10-06 18:20:47 +0200 | [diff] [blame] | 130 | warm_reset(); |
Martin Roth | 4f92b15 | 2017-11-12 10:56:43 -0700 | [diff] [blame] | 131 | break; |
| 132 | |
| 133 | case COLD_RESET_WHENEVER: |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 134 | case COLD_RESET_IMMEDIATELY: |
Nico Huber | 73c1119 | 2018-10-06 18:20:47 +0200 | [diff] [blame] | 135 | cold_reset(); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 136 | break; |
| 137 | |
| 138 | default: |
| 139 | break; |
| 140 | } |
| 141 | |
| 142 | Status = 0; |
| 143 | return Status; |
| 144 | } |
| 145 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 146 | AGESA_STATUS agesa_GfxGetVbiosImage(uint32_t Func, uintptr_t FchData, |
| 147 | void *ConfigPrt) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 148 | { |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 149 | GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo; |
| 150 | |
| 151 | pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 152 | pVbiosImageInfo->ImagePtr = cbfs_boot_map_with_leak( |
| 153 | "pci"CONFIG_VGA_BIOS_ID".rom", |
| 154 | CBFS_TYPE_OPTIONROM, NULL); |
Richard Spiegel | de332f3 | 2018-10-23 14:34:12 -0700 | [diff] [blame] | 155 | printk(BIOS_DEBUG, "%s: IMGptr=%p\n", __func__, |
| 156 | pVbiosImageInfo->ImagePtr); |
Marshall Dawson | f3dc71e | 2017-06-14 16:22:07 -0600 | [diff] [blame] | 157 | return pVbiosImageInfo->ImagePtr ? AGESA_SUCCESS : AGESA_WARNING; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 158 | } |
| 159 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 160 | AGESA_STATUS __weak platform_PcieSlotResetControl(uint32_t Func, |
| 161 | uintptr_t Data, void *ConfigPtr) |
Marc Jones | 6e70d67 | 2017-10-26 16:42:03 -0600 | [diff] [blame] | 162 | { |
| 163 | printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n", |
| 164 | __func__); |
| 165 | return AGESA_UNSUPPORTED; |
| 166 | } |
| 167 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 168 | AGESA_STATUS agesa_PcieSlotResetControl(uint32_t Func, uintptr_t Data, |
| 169 | void *ConfigPtr) |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 170 | { |
Marc Jones | 6e70d67 | 2017-10-26 16:42:03 -0600 | [diff] [blame] | 171 | return platform_PcieSlotResetControl(Func, Data, ConfigPtr); |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 172 | } |
| 173 | |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 174 | /* |
| 175 | * Application Processor callouts: |
| 176 | * agesa_RunFuncOnAp() and agesa_RunFcnOnAllAps() are called after main memory |
| 177 | * has been initialized and coreboot has taken control of AP task dispatching. |
| 178 | * These functions execute callout_ap_entry() on each AP, which calls the |
| 179 | * AmdLateRunApTask() entry point if it is a targeted AP. |
| 180 | */ |
| 181 | |
| 182 | /* |
| 183 | * Global data for APs. |
| 184 | * Passed from the AGESA_Callout for the agesawrapper_amdlaterunaptask. |
| 185 | */ |
| 186 | static struct agesa_data { |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 187 | uint32_t Func; |
| 188 | uintptr_t Data; |
Kyösti Mälkki | 423d03c | 2018-06-28 21:18:12 +0300 | [diff] [blame^] | 189 | AP_EXE_PARAMS *ConfigPtr; |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 190 | } agesadata; |
| 191 | |
| 192 | /* |
| 193 | * BSP deploys APs to callout_ap_entry(), which calls |
| 194 | * agesawrapper_amdlaterunaptask with the agesadata. |
| 195 | */ |
Subrata Banik | 3337497 | 2018-04-24 13:45:30 +0530 | [diff] [blame] | 196 | static void callout_ap_entry(void *unused) |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 197 | { |
| 198 | AGESA_STATUS Status = AGESA_UNSUPPORTED; |
| 199 | |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 200 | printk(BIOS_DEBUG, "%s Func: 0x%x, Data: 0x%lx, Ptr: 0x%p\n", |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 201 | __func__, agesadata.Func, agesadata.Data, agesadata.ConfigPtr); |
| 202 | |
| 203 | /* Check if this AP should run the function */ |
| 204 | if (!((agesadata.Func == AGESA_RUNFUNC_ONAP) && |
| 205 | (agesadata.Data == lapicid()))) |
| 206 | return; |
| 207 | |
Kyösti Mälkki | 423d03c | 2018-06-28 21:18:12 +0300 | [diff] [blame^] | 208 | Status = amd_late_run_ap_task(agesadata.ConfigPtr); |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 209 | |
| 210 | if (Status) |
| 211 | printk(BIOS_DEBUG, "There was a problem with %lx returned %s\n", |
| 212 | lapicid(), decodeAGESA_STATUS(Status)); |
| 213 | } |
| 214 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 215 | AGESA_STATUS agesa_RunFuncOnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr) |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 216 | { |
| 217 | printk(BIOS_DEBUG, "%s\n", __func__); |
| 218 | |
| 219 | agesadata.Func = Func; |
| 220 | agesadata.Data = Data; |
| 221 | agesadata.ConfigPtr = ConfigPtr; |
Subrata Banik | 8a25cae | 2018-05-03 18:48:41 +0530 | [diff] [blame] | 222 | mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS, |
| 223 | 100 * USECS_PER_MSEC); |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 224 | |
| 225 | return AGESA_SUCCESS; |
| 226 | } |
| 227 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 228 | AGESA_STATUS agesa_RunFcnOnAllAps(uint32_t Func, uintptr_t Data, |
| 229 | void *ConfigPtr) |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 230 | { |
| 231 | printk(BIOS_DEBUG, "%s\n", __func__); |
| 232 | |
| 233 | agesadata.Func = Func; |
| 234 | agesadata.Data = Data; |
| 235 | agesadata.ConfigPtr = ConfigPtr; |
Subrata Banik | 8a25cae | 2018-05-03 18:48:41 +0530 | [diff] [blame] | 236 | mp_run_on_aps(callout_ap_entry, NULL, MP_RUN_ON_ALL_CPUS, |
| 237 | 100 * USECS_PER_MSEC); |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 238 | |
| 239 | return AGESA_SUCCESS; |
| 240 | } |
| 241 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 242 | AGESA_STATUS agesa_WaitForAllApsFinished(uint32_t Func, uintptr_t Data, |
| 243 | void *ConfigPtr) |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 244 | { |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 245 | printk(BIOS_WARNING, "Warning - AGESA callout: %s not supported\n", |
| 246 | __func__); |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 247 | AGESA_STATUS Status = AGESA_UNSUPPORTED; |
| 248 | |
| 249 | return Status; |
| 250 | } |
| 251 | |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 252 | AGESA_STATUS agesa_IdleAnAp(uint32_t Func, uintptr_t Data, void *ConfigPtr) |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 253 | { |
Marc Jones | 33eef13 | 2017-10-26 16:50:42 -0600 | [diff] [blame] | 254 | printk(BIOS_WARNING, "Warning - AGESA callout: %s no supported\n", |
| 255 | __func__); |
Martin Roth | f80a431 | 2017-09-26 14:45:16 -0600 | [diff] [blame] | 256 | AGESA_STATUS Status = AGESA_UNSUPPORTED; |
| 257 | |
| 258 | return Status; |
| 259 | } |