Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 - 2012 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <string.h> |
| 22 | #include <cpu/x86/mtrr.h> |
| 23 | #include <northbridge/amd/agesa/agesawrapper.h> |
| 24 | #include <northbridge/amd/agesa/BiosCallOuts.h> |
| 25 | #include "cpuRegisters.h" |
| 26 | #include "cpuCacheInit.h" |
| 27 | #include "cpuApicUtilities.h" |
| 28 | #include "cpuEarlyInit.h" |
| 29 | #include "cpuLateInit.h" |
| 30 | #include "Dispatcher.h" |
| 31 | #include "cpuCacheInit.h" |
| 32 | #include "amdlib.h" |
| 33 | #include "Filecode.h" |
| 34 | #include "heapManager.h" |
| 35 | #include <cpuFamilyTranslation.h> /* CPU_SPECIFIC_SERVICES */ |
| 36 | |
| 37 | #define FILECODE UNASSIGNED_FILE_FILECODE |
| 38 | |
| 39 | /* ACPI table pointers returned by AmdInitLate */ |
| 40 | VOID *DmiTable = NULL; |
| 41 | VOID *AcpiPstate = NULL; |
| 42 | VOID *AcpiSrat = NULL; |
| 43 | VOID *AcpiSlit = NULL; |
| 44 | |
| 45 | VOID *AcpiWheaMce = NULL; |
| 46 | VOID *AcpiWheaCmc = NULL; |
| 47 | VOID *AcpiAlib = NULL; |
| 48 | |
| 49 | /* TODO: Function body should be in mainboard directory. */ |
Kyösti Mälkki | 34ad72c | 2014-10-21 13:43:46 +0300 | [diff] [blame] | 50 | void OemCustomizeInitEarly(AMD_EARLY_PARAMS *InitEarly) |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 51 | { |
| 52 | } |
| 53 | |
Kyösti Mälkki | 34ad72c | 2014-10-21 13:43:46 +0300 | [diff] [blame] | 54 | void OemCustomizeInitPost(AMD_POST_PARAMS *InitPost) |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 55 | { |
| 56 | #if IS_ENABLED(CONFIG_BOARD_AMD_DINAR) |
| 57 | InitPost->MemConfig.UmaMode = UMA_AUTO; |
| 58 | InitPost->MemConfig.BottomIo = 0xE0; |
| 59 | InitPost->MemConfig.UmaSize = 0xE0-0xC0; |
| 60 | #endif |
| 61 | } |
| 62 | |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 63 | AGESA_STATUS agesawrapper_amdinitreset(void) |
| 64 | { |
| 65 | AGESA_STATUS status = AGESA_SUCCESS; |
| 66 | AMD_INTERFACE_PARAMS AmdParamStruct; |
| 67 | AMD_RESET_PARAMS AmdResetParams; |
| 68 | |
Kyösti Mälkki | 7cfc70b | 2014-12-14 18:41:10 +0200 | [diff] [blame^] | 69 | memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); |
| 70 | memset(&AmdResetParams, 0, sizeof(AMD_RESET_PARAMS)); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 71 | |
| 72 | AmdParamStruct.AgesaFunctionName = AMD_INIT_RESET; |
| 73 | AmdParamStruct.AllocationMethod = ByHost; |
| 74 | AmdParamStruct.NewStructSize = sizeof(AMD_RESET_PARAMS); |
| 75 | AmdParamStruct.NewStructPtr = &AmdResetParams; |
| 76 | AmdParamStruct.StdHeader.AltImageBasePtr = 0; |
| 77 | AmdParamStruct.StdHeader.CalloutPtr = NULL; |
| 78 | AmdParamStruct.StdHeader.Func = 0; |
| 79 | AmdParamStruct.StdHeader.ImageBasePtr = 0; |
| 80 | status = AmdCreateStruct(&AmdParamStruct); |
| 81 | if (status != AGESA_SUCCESS) { |
| 82 | return status; |
| 83 | } |
| 84 | AmdResetParams.HtConfig.Depth = 0; |
| 85 | |
| 86 | //MARG34PI disabled AGESA_ENTRY_INIT_RESET by default |
| 87 | //but we need to call AmdCreateStruct to call HeapManagerInit, or the event log not work |
| 88 | #if (defined AGESA_ENTRY_INIT_RESET) && (AGESA_ENTRY_INIT_RESET == TRUE) |
| 89 | status = AmdInitReset((AMD_RESET_PARAMS *) AmdParamStruct.NewStructPtr); |
| 90 | #endif |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 91 | AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 92 | AmdReleaseStruct(&AmdParamStruct); |
| 93 | |
| 94 | return status; |
| 95 | } |
| 96 | |
| 97 | AGESA_STATUS agesawrapper_amdinitearly(void) |
| 98 | { |
| 99 | AGESA_STATUS status; |
| 100 | AMD_INTERFACE_PARAMS AmdParamStruct; |
| 101 | AMD_EARLY_PARAMS *AmdEarlyParamsPtr; |
| 102 | UINT32 TscRateInMhz; |
| 103 | CPU_SPECIFIC_SERVICES *FamilySpecificServices; |
| 104 | |
Kyösti Mälkki | 7cfc70b | 2014-12-14 18:41:10 +0200 | [diff] [blame^] | 105 | memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 106 | |
| 107 | AmdParamStruct.AgesaFunctionName = AMD_INIT_EARLY; |
| 108 | AmdParamStruct.AllocationMethod = PreMemHeap; |
| 109 | AmdParamStruct.StdHeader.AltImageBasePtr = 0; |
| 110 | AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout; |
| 111 | AmdParamStruct.StdHeader.Func = 0; |
| 112 | AmdParamStruct.StdHeader.ImageBasePtr = 0; |
| 113 | status = AmdCreateStruct(&AmdParamStruct); |
| 114 | if (status != AGESA_SUCCESS) { |
| 115 | return status; |
| 116 | } |
| 117 | |
| 118 | AmdEarlyParamsPtr = (AMD_EARLY_PARAMS *) AmdParamStruct.NewStructPtr; |
| 119 | |
| 120 | /* OEM Should Customize the defaults through this hook */ |
| 121 | OemCustomizeInitEarly(AmdEarlyParamsPtr); |
| 122 | |
| 123 | status = AmdInitEarly(AmdEarlyParamsPtr); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 124 | AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 125 | |
| 126 | GetCpuServicesOfCurrentCore((CONST CPU_SPECIFIC_SERVICES **) & FamilySpecificServices, |
| 127 | &AmdParamStruct.StdHeader); |
| 128 | FamilySpecificServices->GetTscRate(FamilySpecificServices, &TscRateInMhz, &AmdParamStruct.StdHeader); |
| 129 | printk(BIOS_DEBUG, "BSP Frequency: %uMHz\n", (unsigned int)TscRateInMhz); |
| 130 | |
| 131 | AmdReleaseStruct(&AmdParamStruct); |
| 132 | return status; |
| 133 | } |
| 134 | |
| 135 | AGESA_STATUS agesawrapper_amdinitpost(void) |
| 136 | { |
| 137 | AGESA_STATUS status; |
| 138 | AMD_INTERFACE_PARAMS AmdParamStruct; |
| 139 | AMD_POST_PARAMS *PostParams; |
| 140 | UINT32 TscRateInMhz; |
| 141 | CPU_SPECIFIC_SERVICES *FamilySpecificServices; |
| 142 | |
Kyösti Mälkki | 7cfc70b | 2014-12-14 18:41:10 +0200 | [diff] [blame^] | 143 | memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 144 | |
| 145 | AmdParamStruct.AgesaFunctionName = AMD_INIT_POST; |
| 146 | AmdParamStruct.AllocationMethod = PreMemHeap; |
| 147 | AmdParamStruct.StdHeader.AltImageBasePtr = 0; |
| 148 | AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout; |
| 149 | AmdParamStruct.StdHeader.Func = 0; |
| 150 | AmdParamStruct.StdHeader.ImageBasePtr = 0; |
| 151 | |
| 152 | status = AmdCreateStruct(&AmdParamStruct); |
| 153 | if (status != AGESA_SUCCESS) { |
| 154 | return status; |
| 155 | } |
| 156 | PostParams = (AMD_POST_PARAMS *) AmdParamStruct.NewStructPtr; |
| 157 | |
| 158 | /* OEM Should Customize the defaults through this hook */ |
| 159 | OemCustomizeInitPost(PostParams); |
| 160 | |
| 161 | status = AmdInitPost(PostParams); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 162 | AGESA_EVENTLOG(status, &PostParams->StdHeader); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 163 | |
| 164 | AmdReleaseStruct(&AmdParamStruct); |
| 165 | |
| 166 | /* Initialize heap space */ |
| 167 | EmptyHeap(); |
| 168 | |
| 169 | GetCpuServicesOfCurrentCore((CONST CPU_SPECIFIC_SERVICES **) & FamilySpecificServices, |
| 170 | &AmdParamStruct.StdHeader); |
| 171 | FamilySpecificServices->GetTscRate(FamilySpecificServices, &TscRateInMhz, &AmdParamStruct.StdHeader); |
| 172 | printk(BIOS_DEBUG, "BSP Frequency: %uMHz\n", (unsigned int)TscRateInMhz); |
| 173 | |
| 174 | return status; |
| 175 | } |
| 176 | |
| 177 | AGESA_STATUS agesawrapper_amdinitenv(void) |
| 178 | { |
| 179 | AGESA_STATUS status; |
| 180 | AMD_INTERFACE_PARAMS AmdParamStruct; |
| 181 | AMD_ENV_PARAMS *EnvParams; |
| 182 | |
Kyösti Mälkki | 7cfc70b | 2014-12-14 18:41:10 +0200 | [diff] [blame^] | 183 | memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 184 | |
| 185 | AmdParamStruct.AgesaFunctionName = AMD_INIT_ENV; |
| 186 | AmdParamStruct.AllocationMethod = PostMemDram; |
| 187 | AmdParamStruct.StdHeader.AltImageBasePtr = 0; |
| 188 | AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout; |
| 189 | AmdParamStruct.StdHeader.Func = 0; |
| 190 | AmdParamStruct.StdHeader.ImageBasePtr = 0; |
| 191 | |
| 192 | status = AmdCreateStruct(&AmdParamStruct); |
| 193 | if (status != AGESA_SUCCESS) { |
| 194 | return status; |
| 195 | } |
| 196 | EnvParams = (AMD_ENV_PARAMS *) AmdParamStruct.NewStructPtr; |
| 197 | status = AmdInitEnv(EnvParams); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 198 | AGESA_EVENTLOG(status, &EnvParams->StdHeader); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 199 | |
| 200 | AmdReleaseStruct(&AmdParamStruct); |
| 201 | return status; |
| 202 | } |
| 203 | |
| 204 | VOID *agesawrapper_getlateinitptr(int pick) |
| 205 | { |
| 206 | switch (pick) { |
| 207 | case PICK_DMI: |
| 208 | return DmiTable; |
| 209 | |
| 210 | case PICK_PSTATE: |
| 211 | return AcpiPstate; |
| 212 | |
| 213 | case PICK_SRAT: |
| 214 | return AcpiSrat; |
| 215 | |
| 216 | case PICK_SLIT: |
| 217 | return AcpiSlit; |
| 218 | case PICK_WHEA_MCE: |
| 219 | return AcpiWheaMce; |
| 220 | case PICK_WHEA_CMC: |
| 221 | return AcpiWheaCmc; |
| 222 | case PICK_ALIB: |
| 223 | return AcpiAlib; |
| 224 | default: |
| 225 | return NULL; |
| 226 | } |
| 227 | |
| 228 | return NULL; |
| 229 | } |
| 230 | |
| 231 | AGESA_STATUS agesawrapper_amdinitmid(void) |
| 232 | { |
| 233 | AGESA_STATUS status; |
| 234 | AMD_INTERFACE_PARAMS AmdParamStruct; |
| 235 | |
Kyösti Mälkki | 7cfc70b | 2014-12-14 18:41:10 +0200 | [diff] [blame^] | 236 | memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 237 | |
| 238 | AmdParamStruct.AgesaFunctionName = AMD_INIT_MID; |
| 239 | AmdParamStruct.AllocationMethod = PostMemDram; |
| 240 | AmdParamStruct.StdHeader.AltImageBasePtr = 0; |
| 241 | AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout; |
| 242 | AmdParamStruct.StdHeader.Func = 0; |
| 243 | AmdParamStruct.StdHeader.ImageBasePtr = 0; |
| 244 | |
| 245 | status = AmdCreateStruct(&AmdParamStruct); |
| 246 | if (status != AGESA_SUCCESS) { |
| 247 | return status; |
| 248 | } |
| 249 | status = AmdInitMid((AMD_MID_PARAMS *) AmdParamStruct.NewStructPtr); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 250 | AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 251 | AmdReleaseStruct(&AmdParamStruct); |
| 252 | |
| 253 | return status; |
| 254 | } |
| 255 | |
| 256 | AGESA_STATUS agesawrapper_amdinitlate(void) |
| 257 | { |
| 258 | AGESA_STATUS status; |
| 259 | AMD_INTERFACE_PARAMS AmdParamStruct; |
| 260 | AMD_LATE_PARAMS *AmdLateParamsPtr; |
| 261 | |
Kyösti Mälkki | 7cfc70b | 2014-12-14 18:41:10 +0200 | [diff] [blame^] | 262 | memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 263 | |
| 264 | AmdParamStruct.AgesaFunctionName = AMD_INIT_LATE; |
| 265 | AmdParamStruct.AllocationMethod = PostMemDram; |
| 266 | AmdParamStruct.StdHeader.AltImageBasePtr = 0; |
| 267 | AmdParamStruct.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout; |
| 268 | AmdParamStruct.StdHeader.Func = 0; |
| 269 | AmdParamStruct.StdHeader.ImageBasePtr = 0; |
| 270 | |
| 271 | AmdCreateStruct(&AmdParamStruct); |
| 272 | AmdLateParamsPtr = (AMD_LATE_PARAMS *) AmdParamStruct.NewStructPtr; |
| 273 | |
| 274 | printk(BIOS_DEBUG, "agesawrapper_amdinitlate: AmdLateParamsPtr = %X\n", (u32) AmdLateParamsPtr); |
| 275 | |
| 276 | status = AmdInitLate(AmdLateParamsPtr); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 277 | AGESA_EVENTLOG(status, &AmdLateParamsPtr->StdHeader); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 278 | ASSERT(status == AGESA_SUCCESS); |
| 279 | |
| 280 | DmiTable = AmdLateParamsPtr->DmiTable; |
| 281 | AcpiPstate = AmdLateParamsPtr->AcpiPState; |
| 282 | AcpiSrat = AmdLateParamsPtr->AcpiSrat; |
| 283 | AcpiSlit = AmdLateParamsPtr->AcpiSlit; |
| 284 | AcpiWheaMce = AmdLateParamsPtr->AcpiWheaMce; |
| 285 | AcpiWheaCmc = AmdLateParamsPtr->AcpiWheaCmc; |
| 286 | AcpiAlib = AmdLateParamsPtr->AcpiAlib; |
| 287 | |
| 288 | printk(BIOS_DEBUG, "In %s, AGESA generated ACPI tables:\n" |
| 289 | " DmiTable:%p\n AcpiPstate: %p\n AcpiSrat:%p\n AcpiSlit:%p\n" |
| 290 | " Mce:%p\n Cmc:%p\n Alib:%p\n", |
| 291 | __func__, DmiTable, AcpiPstate, AcpiSrat, AcpiSlit, AcpiWheaMce, AcpiWheaCmc, AcpiAlib); |
| 292 | |
| 293 | /* Don't release the structure until coreboot has copied the ACPI tables. |
| 294 | * AmdReleaseStruct (&AmdLateParams); |
| 295 | */ |
| 296 | |
| 297 | return status; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * @param[in] UINTN ApicIdOfCore, |
| 302 | * @param[in] AP_EXE_PARAMS *LaunchApParams |
| 303 | */ |
| 304 | AGESA_STATUS agesawrapper_amdlaterunaptask(UINT32 Func, UINT32 Data, VOID * ConfigPtr) |
| 305 | { |
| 306 | AGESA_STATUS status; |
| 307 | AMD_LATE_PARAMS AmdLateParams; |
| 308 | |
Kyösti Mälkki | 7cfc70b | 2014-12-14 18:41:10 +0200 | [diff] [blame^] | 309 | memset(&AmdLateParams, 0, sizeof(AMD_LATE_PARAMS)); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 310 | |
| 311 | AmdLateParams.StdHeader.AltImageBasePtr = 0; |
| 312 | AmdLateParams.StdHeader.CalloutPtr = (CALLOUT_ENTRY) & GetBiosCallout; |
| 313 | AmdLateParams.StdHeader.Func = 0; |
| 314 | AmdLateParams.StdHeader.ImageBasePtr = 0; |
| 315 | AmdLateParams.StdHeader.HeapStatus = HEAP_TEMP_MEM; |
| 316 | |
| 317 | printk(BIOS_DEBUG, "AmdLateRunApTask on Core: %x\n", (uint32_t) Data); |
| 318 | status = AmdLateRunApTask((AP_EXE_PARAMS *) ConfigPtr); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 319 | AGESA_EVENTLOG(status, &AmdLateParams.StdHeader); |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 320 | ASSERT((status == AGESA_SUCCESS) || (status == AGESA_UNSUPPORTED)); |
| 321 | |
| 322 | return status; |
| 323 | } |