Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Richard Spiegel | 67c2a7b | 2017-11-09 16:04:35 -0700 | [diff] [blame] | 4 | * Copyright (C) 2012 - 2017 Advanced Micro Devices, Inc. |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 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 | |
Aaron Durbin | a78319b | 2017-12-08 15:38:59 -0700 | [diff] [blame] | 16 | #include <arch/early_variables.h> |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 17 | #include <arch/acpi.h> |
| 18 | #include <cpu/x86/mtrr.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 19 | #include <cbfs.h> |
| 20 | #include <cbmem.h> |
| 21 | #include <delay.h> |
Justin TerAvest | 9226195 | 2017-12-22 15:15:02 -0700 | [diff] [blame] | 22 | #include <rules.h> |
Aaron Durbin | 931ed7f | 2017-12-22 17:13:17 -0700 | [diff] [blame] | 23 | #include <rmodule.h> |
Aaron Durbin | e3f7d44 | 2017-11-03 11:44:10 -0600 | [diff] [blame] | 24 | #include <string.h> |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 25 | #include <timestamp.h> |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 26 | #include <amdblocks/agesawrapper.h> |
| 27 | #include <amdblocks/BiosCallOuts.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 28 | |
Richard Spiegel | 67c2a7b | 2017-11-09 16:04:35 -0700 | [diff] [blame] | 29 | void __attribute__((weak)) SetMemParams(AMD_POST_PARAMS *PostParams) {} |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 30 | void __attribute__((weak)) OemPostParams(AMD_POST_PARAMS *PostParams) {} |
| 31 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 32 | /* ACPI table pointers returned by AmdInitLate */ |
Aaron Durbin | 8dd4006 | 2017-11-03 11:50:14 -0600 | [diff] [blame] | 33 | static void *DmiTable; |
| 34 | static void *AcpiPstate; |
| 35 | static void *AcpiSrat; |
| 36 | static void *AcpiSlit; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 37 | |
Aaron Durbin | 8dd4006 | 2017-11-03 11:50:14 -0600 | [diff] [blame] | 38 | static void *AcpiWheaMce; |
| 39 | static void *AcpiWheaCmc; |
| 40 | static void *AcpiAlib; |
| 41 | static void *AcpiIvrs; |
| 42 | static void *AcpiCrat; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 43 | |
Marshall Dawson | 8f6cd22 | 2017-12-15 12:01:41 -0700 | [diff] [blame] | 44 | static AGESA_STATUS agesawrapper_readeventlog(UINT8 HeapStatus) |
| 45 | { |
| 46 | AGESA_STATUS Status; |
| 47 | EVENT_PARAMS AmdEventParams = { |
| 48 | .StdHeader.CalloutPtr = &GetBiosCallout, |
| 49 | .StdHeader.HeapStatus = HeapStatus, |
| 50 | }; |
| 51 | |
| 52 | Status = AmdReadEventLog(&AmdEventParams); |
| 53 | if (AmdEventParams.EventClass) |
| 54 | printk(BIOS_DEBUG, "AGESA Event Log:\n"); |
| 55 | |
| 56 | while (AmdEventParams.EventClass != 0) { |
| 57 | printk(BIOS_DEBUG, " Class = %x, Info = %x," |
| 58 | " Param1 = 0x%x, Param2 = 0x%x" |
| 59 | " Param3 = 0x%x, Param4 = 0x%x\n", |
| 60 | (u32)AmdEventParams.EventClass, |
| 61 | (u32)AmdEventParams.EventInfo, |
| 62 | (u32)AmdEventParams.DataParam1, |
| 63 | (u32)AmdEventParams.DataParam2, |
| 64 | (u32)AmdEventParams.DataParam3, |
| 65 | (u32)AmdEventParams.DataParam4); |
| 66 | Status = AmdReadEventLog(&AmdEventParams); |
| 67 | } |
| 68 | |
| 69 | return Status; |
| 70 | } |
| 71 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 72 | AGESA_STATUS agesawrapper_amdinitreset(void) |
| 73 | { |
| 74 | AGESA_STATUS status; |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 75 | AMD_RESET_PARAMS ResetParams; |
| 76 | AMD_INTERFACE_PARAMS AmdParamStruct = { |
| 77 | .AgesaFunctionName = AMD_INIT_RESET, |
| 78 | .AllocationMethod = ByHost, |
| 79 | .NewStructSize = sizeof(AMD_RESET_PARAMS), |
| 80 | .NewStructPtr = &ResetParams, |
| 81 | .StdHeader.CalloutPtr = &GetBiosCallout |
| 82 | }; |
| 83 | AmdCreateStruct(&AmdParamStruct); |
| 84 | SetFchResetParams(&ResetParams.FchInterface); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 85 | |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 86 | timestamp_add_now(TS_AGESA_INIT_RESET_START); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 87 | status = AmdInitReset(&ResetParams); |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 88 | timestamp_add_now(TS_AGESA_INIT_RESET_DONE); |
| 89 | |
Marshall Dawson | 3aed84a | 2017-12-13 20:59:23 -0700 | [diff] [blame] | 90 | if (status != AGESA_SUCCESS) |
| 91 | agesawrapper_readeventlog(AmdParamStruct.StdHeader.HeapStatus); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 92 | AmdReleaseStruct(&AmdParamStruct); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 93 | return status; |
| 94 | } |
| 95 | |
| 96 | AGESA_STATUS agesawrapper_amdinitearly(void) |
| 97 | { |
| 98 | AGESA_STATUS status; |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 99 | AMD_EARLY_PARAMS *EarlyParams; |
| 100 | AMD_INTERFACE_PARAMS AmdParamStruct = { |
| 101 | .AgesaFunctionName = AMD_INIT_EARLY, |
| 102 | .AllocationMethod = PreMemHeap, |
| 103 | .StdHeader.CalloutPtr = &GetBiosCallout, |
| 104 | }; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 105 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 106 | AmdCreateStruct(&AmdParamStruct); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 107 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 108 | EarlyParams = (AMD_EARLY_PARAMS *)AmdParamStruct.NewStructPtr; |
| 109 | OemCustomizeInitEarly(EarlyParams); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 110 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 111 | EarlyParams->GnbConfig.PsppPolicy = PsppDisabled; |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 112 | |
| 113 | timestamp_add_now(TS_AGESA_INIT_EARLY_START); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 114 | status = AmdInitEarly(EarlyParams); |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 115 | timestamp_add_now(TS_AGESA_INIT_EARLY_DONE); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 116 | |
Marshall Dawson | 3aed84a | 2017-12-13 20:59:23 -0700 | [diff] [blame] | 117 | if (status != AGESA_SUCCESS) |
| 118 | agesawrapper_readeventlog(AmdParamStruct.StdHeader.HeapStatus); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 119 | AmdReleaseStruct(&AmdParamStruct); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 120 | |
| 121 | return status; |
| 122 | } |
| 123 | |
Marshall Dawson | 972f826 | 2017-12-14 09:08:02 -0700 | [diff] [blame] | 124 | static void print_init_post_settings(AMD_POST_PARAMS *parms) |
| 125 | { |
| 126 | u64 syslimit, bottomio, uma_size, uma_start; |
| 127 | const char *mode; |
| 128 | |
| 129 | switch (parms->MemConfig.UmaMode) { |
| 130 | case UMA_AUTO: |
| 131 | mode = "UMA_AUTO"; |
| 132 | break; |
| 133 | case UMA_SPECIFIED: |
| 134 | mode = "UMA_SPECIFIED"; |
| 135 | break; |
| 136 | case UMA_NONE: |
| 137 | mode = "UMA_NONE"; |
| 138 | break; |
| 139 | default: |
| 140 | mode = "unknown!"; |
| 141 | break; |
| 142 | } |
| 143 | |
| 144 | syslimit = (u64)parms->MemConfig.SysLimit * 64 * KiB; |
| 145 | bottomio = (u64)parms->MemConfig.BottomIo * 64 * KiB; |
| 146 | |
| 147 | uma_size = (u64)parms->MemConfig.UmaSize * 64 * KiB; |
| 148 | uma_start = (u64)parms->MemConfig.UmaBase * 64 * KiB; |
| 149 | |
| 150 | printk(BIOS_SPEW, "AGESA set: umamode %s\n", mode); |
| 151 | printk(BIOS_SPEW, " : syslimit 0x%llx, bottomio 0x%08llx\n", |
| 152 | syslimit, bottomio); |
| 153 | printk(BIOS_SPEW, " : uma size %lluMB, uma start 0x%08llx\n", |
| 154 | uma_size / MiB, uma_start); |
| 155 | } |
| 156 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 157 | AGESA_STATUS agesawrapper_amdinitpost(void) |
| 158 | { |
| 159 | AGESA_STATUS status; |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 160 | AMD_INTERFACE_PARAMS AmdParamStruct = { |
| 161 | .AgesaFunctionName = AMD_INIT_POST, |
| 162 | .AllocationMethod = PreMemHeap, |
| 163 | .StdHeader.CalloutPtr = &GetBiosCallout, |
| 164 | }; |
| 165 | AMD_POST_PARAMS *PostParams; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 166 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 167 | AmdCreateStruct(&AmdParamStruct); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 168 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 169 | PostParams = (AMD_POST_PARAMS *)AmdParamStruct.NewStructPtr; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 170 | PostParams->MemConfig.UmaMode = CONFIG_GFXUMA ? UMA_AUTO : UMA_NONE; |
| 171 | PostParams->MemConfig.UmaSize = 0; |
| 172 | PostParams->MemConfig.BottomIo = (UINT16) |
| 173 | (CONFIG_BOTTOMIO_POSITION >> 24); |
| 174 | |
Richard Spiegel | 67c2a7b | 2017-11-09 16:04:35 -0700 | [diff] [blame] | 175 | SetMemParams(PostParams); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 176 | OemPostParams(PostParams); |
Richard Spiegel | 67c2a7b | 2017-11-09 16:04:35 -0700 | [diff] [blame] | 177 | printk(BIOS_SPEW, "DRAM clear on reset: %s\n", |
| 178 | (PostParams->MemConfig.EnableMemClr == FALSE) ? "Keep" : |
| 179 | (PostParams->MemConfig.EnableMemClr == TRUE) ? "Clear" : |
| 180 | "unknown" |
| 181 | ); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 182 | |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 183 | timestamp_add_now(TS_AGESA_INIT_POST_START); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 184 | status = AmdInitPost(PostParams); |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 185 | timestamp_add_now(TS_AGESA_INIT_POST_DONE); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 186 | |
Marshall Dawson | 972f826 | 2017-12-14 09:08:02 -0700 | [diff] [blame] | 187 | /* |
| 188 | * If UMA is enabled we currently have it below TOP_MEM as well. |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 189 | * UMA may or may not be cacheable, so Sub4GCacheTop could be |
Marshall Dawson | 972f826 | 2017-12-14 09:08:02 -0700 | [diff] [blame] | 190 | * higher than UmaBase. With UMA_NONE we see UmaBase==0. |
| 191 | */ |
| 192 | uintptr_t top; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 193 | if (PostParams->MemConfig.UmaBase) |
Marshall Dawson | 972f826 | 2017-12-14 09:08:02 -0700 | [diff] [blame] | 194 | top = PostParams->MemConfig.UmaBase << 16; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 195 | else |
Marshall Dawson | 972f826 | 2017-12-14 09:08:02 -0700 | [diff] [blame] | 196 | top = PostParams->MemConfig.Sub4GCacheTop; |
| 197 | backup_top_of_low_cacheable(top); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 198 | |
Marshall Dawson | 972f826 | 2017-12-14 09:08:02 -0700 | [diff] [blame] | 199 | print_init_post_settings(PostParams); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 200 | |
Marshall Dawson | 3aed84a | 2017-12-13 20:59:23 -0700 | [diff] [blame] | 201 | if (status != AGESA_SUCCESS) |
| 202 | agesawrapper_readeventlog(PostParams->StdHeader.HeapStatus); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 203 | AmdReleaseStruct(&AmdParamStruct); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 204 | |
| 205 | return status; |
| 206 | } |
| 207 | |
| 208 | AGESA_STATUS agesawrapper_amdinitenv(void) |
| 209 | { |
| 210 | AGESA_STATUS status; |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 211 | AMD_INTERFACE_PARAMS AmdParamStruct = { |
| 212 | .AgesaFunctionName = AMD_INIT_ENV, |
| 213 | .AllocationMethod = PostMemDram, |
| 214 | .StdHeader.CalloutPtr = &GetBiosCallout, |
| 215 | }; |
| 216 | AMD_ENV_PARAMS *EnvParams; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 217 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 218 | status = AmdCreateStruct(&AmdParamStruct); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 219 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 220 | EnvParams = (AMD_ENV_PARAMS *)AmdParamStruct.NewStructPtr; |
| 221 | SetFchEnvParams(&EnvParams->FchInterface); |
| 222 | SetNbEnvParams(&EnvParams->GnbEnvConfiguration); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 223 | |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 224 | timestamp_add_now(TS_AGESA_INIT_ENV_START); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 225 | status = AmdInitEnv(EnvParams); |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 226 | timestamp_add_now(TS_AGESA_INIT_ENV_DONE); |
| 227 | |
Marshall Dawson | 3aed84a | 2017-12-13 20:59:23 -0700 | [diff] [blame] | 228 | if (status != AGESA_SUCCESS) |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 229 | agesawrapper_readeventlog(EnvParams->StdHeader.HeapStatus); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 230 | |
| 231 | return status; |
| 232 | } |
| 233 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 234 | VOID *agesawrapper_getlateinitptr(int pick) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 235 | { |
| 236 | switch (pick) { |
| 237 | case PICK_DMI: |
| 238 | return DmiTable; |
| 239 | case PICK_PSTATE: |
| 240 | return AcpiPstate; |
| 241 | case PICK_SRAT: |
| 242 | return AcpiSrat; |
| 243 | case PICK_SLIT: |
| 244 | return AcpiSlit; |
| 245 | case PICK_WHEA_MCE: |
| 246 | return AcpiWheaMce; |
| 247 | case PICK_WHEA_CMC: |
| 248 | return AcpiWheaCmc; |
| 249 | case PICK_ALIB: |
| 250 | return AcpiAlib; |
| 251 | case PICK_IVRS: |
| 252 | return AcpiIvrs; |
| 253 | case PICK_CRAT: |
| 254 | return AcpiCrat; |
| 255 | default: |
| 256 | return NULL; |
| 257 | } |
| 258 | } |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 259 | |
| 260 | AGESA_STATUS agesawrapper_amdinitmid(void) |
| 261 | { |
| 262 | AGESA_STATUS status; |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 263 | AMD_INTERFACE_PARAMS AmdParamStruct = { |
| 264 | .AgesaFunctionName = AMD_INIT_MID, |
| 265 | .AllocationMethod = PostMemDram, |
| 266 | .StdHeader.CalloutPtr = &GetBiosCallout, |
| 267 | }; |
| 268 | AMD_MID_PARAMS *MidParams; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 269 | |
| 270 | /* Enable MMIO on AMD CPU Address Map Controller */ |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 271 | amd_initcpuio(); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 272 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 273 | AmdCreateStruct(&AmdParamStruct); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 274 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 275 | MidParams = (AMD_MID_PARAMS *)AmdParamStruct.NewStructPtr; |
| 276 | SetFchMidParams(&MidParams->FchInterface); |
| 277 | SetNbMidParams(&MidParams->GnbMidConfiguration); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 278 | |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 279 | timestamp_add_now(TS_AGESA_INIT_MID_START); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 280 | status = AmdInitMid(MidParams); |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 281 | timestamp_add_now(TS_AGESA_INIT_MID_DONE); |
| 282 | |
Marshall Dawson | 3aed84a | 2017-12-13 20:59:23 -0700 | [diff] [blame] | 283 | if (status != AGESA_SUCCESS) |
| 284 | agesawrapper_readeventlog(AmdParamStruct.StdHeader.HeapStatus); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 285 | AmdReleaseStruct(&AmdParamStruct); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 286 | |
| 287 | return status; |
| 288 | } |
| 289 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 290 | AGESA_STATUS agesawrapper_amdinitlate(void) |
| 291 | { |
| 292 | AGESA_STATUS Status; |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 293 | AMD_INTERFACE_PARAMS AmdParamStruct = { |
| 294 | .AgesaFunctionName = AMD_INIT_LATE, |
| 295 | .AllocationMethod = PostMemDram, |
| 296 | .StdHeader.CalloutPtr = &GetBiosCallout, |
| 297 | }; |
| 298 | AMD_LATE_PARAMS *LateParams; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 299 | |
Richard Spiegel | fc51127 | 2017-12-11 16:23:58 -0700 | [diff] [blame] | 300 | /* |
| 301 | * NOTE: if not call amdcreatestruct, the initializer |
| 302 | * (AmdInitLateInitializer) would not be called. |
| 303 | */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 304 | AmdCreateStruct(&AmdParamStruct); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 305 | LateParams = (AMD_LATE_PARAMS *)AmdParamStruct.NewStructPtr; |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 306 | |
| 307 | timestamp_add_now(TS_AGESA_INIT_LATE_START); |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 308 | Status = AmdInitLate(LateParams); |
Martin Roth | bc5c3e7 | 2017-12-09 10:40:45 -0700 | [diff] [blame] | 309 | timestamp_add_now(TS_AGESA_INIT_LATE_DONE); |
| 310 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 311 | if (Status != AGESA_SUCCESS) { |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 312 | agesawrapper_readeventlog(LateParams->StdHeader.HeapStatus); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 313 | ASSERT(Status == AGESA_SUCCESS); |
| 314 | } |
| 315 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 316 | DmiTable = LateParams->DmiTable; |
| 317 | AcpiPstate = LateParams->AcpiPState; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 318 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 319 | AcpiWheaMce = LateParams->AcpiWheaMce; |
| 320 | AcpiWheaCmc = LateParams->AcpiWheaCmc; |
| 321 | AcpiAlib = LateParams->AcpiAlib; |
| 322 | AcpiIvrs = LateParams->AcpiIvrs; |
| 323 | AcpiCrat = LateParams->AcpiCrat; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 324 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 325 | printk(BIOS_DEBUG, "DmiTable:%p, AcpiPstatein: %p, AcpiSrat:%p," |
| 326 | "AcpiSlit:%p, Mce:%p, Cmc:%p," |
| 327 | "Alib:%p, AcpiIvrs:%p in %s\n", |
| 328 | DmiTable, AcpiPstate, AcpiSrat, |
| 329 | AcpiSlit, AcpiWheaMce, AcpiWheaCmc, |
| 330 | AcpiAlib, AcpiIvrs, __func__); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 331 | |
| 332 | /* AmdReleaseStruct (&AmdParamStruct); */ |
| 333 | return Status; |
| 334 | } |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 335 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 336 | AGESA_STATUS agesawrapper_amdlaterunaptask(UINT32 Func, UINTN Data, |
| 337 | VOID *ConfigPtr) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 338 | { |
| 339 | AGESA_STATUS Status; |
| 340 | AP_EXE_PARAMS ApExeParams; |
| 341 | |
Aaron Durbin | e3f7d44 | 2017-11-03 11:44:10 -0600 | [diff] [blame] | 342 | memset(&ApExeParams, 0, sizeof(ApExeParams)); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 343 | |
| 344 | ApExeParams.StdHeader.AltImageBasePtr = 0; |
| 345 | ApExeParams.StdHeader.CalloutPtr = &GetBiosCallout; |
| 346 | ApExeParams.StdHeader.Func = 0; |
| 347 | ApExeParams.StdHeader.ImageBasePtr = 0; |
| 348 | ApExeParams.FunctionNumber = Func; |
| 349 | ApExeParams.RelatedDataBlock = ConfigPtr; |
| 350 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 351 | Status = AmdLateRunApTask(&ApExeParams); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 352 | if (Status != AGESA_SUCCESS) { |
Marshall Dawson | 3aed84a | 2017-12-13 20:59:23 -0700 | [diff] [blame] | 353 | /* agesawrapper_readeventlog(); */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 354 | ASSERT(Status == AGESA_SUCCESS); |
| 355 | } |
| 356 | |
| 357 | return Status; |
| 358 | } |
| 359 | |
Aaron Durbin | 02b43aa | 2017-12-12 14:56:41 -0700 | [diff] [blame] | 360 | static int agesa_locate_file(const char *name, struct region_device *rdev, |
| 361 | uint32_t type) |
| 362 | { |
| 363 | struct cbfsf fh; |
| 364 | |
| 365 | if (cbfs_boot_locate(&fh, name, &type)) |
| 366 | return -1; |
| 367 | |
| 368 | cbfs_file_data(rdev, &fh); |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static int agesa_locate_raw_file(const char *name, struct region_device *rdev) |
| 373 | { |
| 374 | return agesa_locate_file(name, rdev, CBFS_TYPE_RAW); |
| 375 | } |
| 376 | |
Aaron Durbin | 931ed7f | 2017-12-22 17:13:17 -0700 | [diff] [blame] | 377 | static int agesa_locate_stage_file_early(const char *name, |
| 378 | struct region_device *rdev) |
Aaron Durbin | 02b43aa | 2017-12-12 14:56:41 -0700 | [diff] [blame] | 379 | { |
| 380 | const size_t metadata_sz = sizeof(struct cbfs_stage); |
| 381 | |
| 382 | if (agesa_locate_file(name, rdev, CBFS_TYPE_STAGE)) |
| 383 | return -1; |
| 384 | |
| 385 | /* Peel off the cbfs stage metadata. */ |
| 386 | return rdev_chain(rdev, rdev, metadata_sz, |
| 387 | region_device_sz(rdev) - metadata_sz); |
| 388 | } |
| 389 | |
Aaron Durbin | 931ed7f | 2017-12-22 17:13:17 -0700 | [diff] [blame] | 390 | static int agesa_locate_stage_file_ramstage(const char *name, |
| 391 | struct region_device *rdev) |
| 392 | { |
| 393 | struct prog prog = PROG_INIT(PROG_REFCODE, name); |
| 394 | struct rmod_stage_load rmod_agesa = { |
| 395 | .cbmem_id = CBMEM_ID_REFCODE, |
| 396 | .prog = &prog, |
| 397 | }; |
| 398 | |
| 399 | if (prog_locate(&prog)) |
| 400 | return -1; |
| 401 | if (rmodule_stage_load(&rmod_agesa) < 0) |
| 402 | return -1; |
| 403 | |
| 404 | return rdev_chain(rdev, prog_rdev(&prog), 0, |
| 405 | region_device_sz(prog_rdev(&prog))); |
| 406 | } |
| 407 | |
| 408 | static int agesa_locate_stage_file(const char *name, struct region_device *rdev) |
| 409 | { |
Daniel Kurtz | 462e470 | 2018-01-05 15:40:52 -0700 | [diff] [blame] | 410 | if (!ENV_RAMSTAGE || !IS_ENABLED(CONFIG_AGESA_SPLIT_MEMORY_FILES)) |
Aaron Durbin | 931ed7f | 2017-12-22 17:13:17 -0700 | [diff] [blame] | 411 | return agesa_locate_stage_file_early(name, rdev); |
| 412 | return agesa_locate_stage_file_ramstage(name, rdev); |
| 413 | } |
| 414 | |
Justin TerAvest | 9226195 | 2017-12-22 15:15:02 -0700 | [diff] [blame] | 415 | static const char *get_agesa_cbfs_name(void) |
| 416 | { |
| 417 | if (!IS_ENABLED(CONFIG_AGESA_SPLIT_MEMORY_FILES)) |
| 418 | return CONFIG_AGESA_CBFS_NAME; |
| 419 | if (!ENV_RAMSTAGE) |
| 420 | return CONFIG_AGESA_PRE_MEMORY_CBFS_NAME; |
| 421 | return CONFIG_AGESA_POST_MEMORY_CBFS_NAME; |
| 422 | } |
| 423 | |
Marshall Dawson | 857a387 | 2017-12-13 20:01:59 -0700 | [diff] [blame^] | 424 | const void *agesawrapper_locate_module(const CHAR8 name[8]) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 425 | { |
Richard Spiegel | fc51127 | 2017-12-11 16:23:58 -0700 | [diff] [blame] | 426 | const void *agesa; |
| 427 | const AMD_IMAGE_HEADER *image; |
Aaron Durbin | 02b43aa | 2017-12-12 14:56:41 -0700 | [diff] [blame] | 428 | struct region_device rdev; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 429 | size_t file_size; |
Justin TerAvest | 9226195 | 2017-12-22 15:15:02 -0700 | [diff] [blame] | 430 | const char *fname; |
Aaron Durbin | 02b43aa | 2017-12-12 14:56:41 -0700 | [diff] [blame] | 431 | int ret; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 432 | |
Justin TerAvest | 9226195 | 2017-12-22 15:15:02 -0700 | [diff] [blame] | 433 | fname = get_agesa_cbfs_name(); |
| 434 | |
Aaron Durbin | 02b43aa | 2017-12-12 14:56:41 -0700 | [diff] [blame] | 435 | if (IS_ENABLED(CONFIG_AGESA_BINARY_PI_AS_STAGE)) |
| 436 | ret = agesa_locate_stage_file(fname, &rdev); |
| 437 | else |
| 438 | ret = agesa_locate_raw_file(fname, &rdev); |
| 439 | |
| 440 | if (ret) |
| 441 | return NULL; |
| 442 | |
| 443 | file_size = region_device_sz(&rdev); |
| 444 | |
| 445 | /* Assume boot device is memory mapped so the mapping can leak. */ |
| 446 | assert(IS_ENABLED(CONFIG_BOOT_DEVICE_MEMORY_MAPPED)); |
| 447 | |
| 448 | agesa = rdev_mmap_full(&rdev); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 449 | |
| 450 | if (!agesa) |
| 451 | return NULL; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 452 | |
Aaron Durbin | 02b43aa | 2017-12-12 14:56:41 -0700 | [diff] [blame] | 453 | image = LibAmdLocateImage(agesa, agesa + file_size, 4096, name); |
| 454 | |
| 455 | if (!image) |
| 456 | return NULL; |
| 457 | |
| 458 | return (AMD_MODULE_HEADER *)image->ModuleInfoOffset; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 459 | } |
Aaron Durbin | a78319b | 2017-12-08 15:38:59 -0700 | [diff] [blame] | 460 | |
| 461 | static MODULE_ENTRY agesa_dispatcher CAR_GLOBAL; |
| 462 | |
| 463 | MODULE_ENTRY agesa_get_dispatcher(void) |
| 464 | { |
| 465 | const AMD_MODULE_HEADER *module; |
| 466 | static const CHAR8 id[8] = AGESA_ID; |
| 467 | MODULE_ENTRY val = car_get_var(agesa_dispatcher); |
| 468 | |
| 469 | if (val != NULL) |
| 470 | return val; |
| 471 | |
| 472 | module = agesawrapper_locate_module(id); |
| 473 | if (!module) |
| 474 | return NULL; |
| 475 | |
| 476 | val = module->ModuleDispatcher; |
| 477 | car_set_var(agesa_dispatcher, val); |
| 478 | |
| 479 | return val; |
| 480 | } |