efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 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 |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "agesawrapper.h" |
| 21 | #include "amdlib.h" |
| 22 | #include "BiosCallOuts.h" |
| 23 | #include "Ids.h" |
| 24 | #include "OptionsIds.h" |
| 25 | #include "heapManager.h" |
Kimarie Hoot | eef45f9 | 2013-03-08 13:54:10 -0700 | [diff] [blame^] | 26 | #include <northbridge/amd/agesa/family15/dimmSpd.h> |
| 27 | #include <arch/io.h> |
| 28 | #include <arch/romcc_io.h> |
| 29 | |
| 30 | #ifdef __PRE_RAM__ |
| 31 | /* These defines are used to select the appropriate socket for the SPD read |
| 32 | * because this is a multi-socket design. |
| 33 | */ |
| 34 | #define PCI_REG_GPIO_56_to_53_CNTRL (0x52) |
| 35 | #define GPIO_OUT_BIT_GPIO53 (BIT0) |
| 36 | #define GPIO_OUT_BIT_GPIO54 (BIT1) |
| 37 | #define GPIO_OUT_ENABLE_BIT_GPIO53 (BIT4) |
| 38 | #define GPIO_OUT_ENABLE_BIT_GPIO54 (BIT5) |
| 39 | |
| 40 | #define GPIO_OUT_BIT_GPIO54_to_53_MASK \ |
| 41 | (GPIO_OUT_BIT_GPIO54 | GPIO_OUT_BIT_GPIO53) |
| 42 | #define GPIO_OUT_ENABLE_BIT_GPIO54_to_53_MASK \ |
| 43 | (GPIO_OUT_ENABLE_BIT_GPIO54 | GPIO_OUT_ENABLE_BIT_GPIO53) |
| 44 | |
| 45 | static UINT8 select_socket(UINT8 socket_id) |
| 46 | { |
| 47 | device_t sm_dev = PCI_DEV(0, 0x14, 0); //SMBus |
| 48 | UINT8 value = 0; |
| 49 | UINT8 gpio56_to_53 = 0; |
| 50 | |
| 51 | /* Configure GPIO54,53 to select the desired socket |
| 52 | * GPIO54,53 control the HC4052 S1,S0 |
| 53 | * S1 S0 true table |
| 54 | * 0 0 channel 1 (Socket1) |
| 55 | * 0 1 channel 2 (Socket2) |
| 56 | * 1 0 channel 3 (Socket3) |
| 57 | * 1 1 channel 4 (Socket4) |
| 58 | */ |
| 59 | gpio56_to_53 = pci_read_config8(sm_dev, PCI_REG_GPIO_56_to_53_CNTRL); |
| 60 | value = gpio56_to_53 & (~GPIO_OUT_BIT_GPIO54_to_53_MASK); |
| 61 | value |= socket_id; |
| 62 | value &= (~GPIO_OUT_ENABLE_BIT_GPIO54_to_53_MASK); // 0=Output Enabled, 1=Tristate |
| 63 | pci_write_config8(sm_dev, PCI_REG_GPIO_56_to_53_CNTRL, value); |
| 64 | |
| 65 | return gpio56_to_53; |
| 66 | } |
| 67 | |
| 68 | static void restore_socket(UINT8 original_value) |
| 69 | { |
| 70 | device_t sm_dev = PCI_DEV(0, 0x14, 0); //SMBus |
| 71 | pci_write_config8(sm_dev, PCI_REG_GPIO_56_to_53_CNTRL, original_value); |
| 72 | } |
| 73 | #endif |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 74 | |
Aladyshev Konstantin | 3d63b0a | 2012-12-19 00:58:35 +0400 | [diff] [blame] | 75 | STATIC BIOS_CALLOUT_STRUCT BiosCallouts[] = |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 76 | { |
| 77 | { |
| 78 | AGESA_ALLOCATE_BUFFER, |
| 79 | BiosAllocateBuffer |
| 80 | }, |
| 81 | |
| 82 | { |
| 83 | AGESA_DEALLOCATE_BUFFER, |
| 84 | BiosDeallocateBuffer |
| 85 | }, |
| 86 | |
| 87 | { |
| 88 | AGESA_DO_RESET, |
| 89 | BiosReset |
| 90 | }, |
| 91 | |
| 92 | { |
| 93 | AGESA_LOCATE_BUFFER, |
| 94 | BiosLocateBuffer |
| 95 | }, |
| 96 | |
| 97 | { |
| 98 | AGESA_READ_SPD, |
| 99 | BiosReadSpd |
| 100 | }, |
| 101 | |
| 102 | { |
| 103 | AGESA_READ_SPD_RECOVERY, |
| 104 | BiosDefaultRet |
| 105 | }, |
| 106 | |
| 107 | { |
| 108 | AGESA_RUNFUNC_ONAP, |
| 109 | BiosRunFuncOnAp |
| 110 | }, |
| 111 | |
| 112 | { |
| 113 | AGESA_GET_IDS_INIT_DATA, |
| 114 | BiosGetIdsInitData |
| 115 | }, |
| 116 | |
| 117 | { |
| 118 | AGESA_HOOKBEFORE_DQS_TRAINING, |
| 119 | BiosHookBeforeDQSTraining |
| 120 | }, |
| 121 | |
| 122 | { |
| 123 | AGESA_HOOKBEFORE_DRAM_INIT, |
| 124 | BiosHookBeforeDramInit |
| 125 | }, |
| 126 | { |
| 127 | AGESA_HOOKBEFORE_EXIT_SELF_REF, |
| 128 | BiosHookBeforeExitSelfRefresh |
| 129 | }, |
| 130 | }; |
| 131 | |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 132 | AGESA_STATUS GetBiosCallout (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 133 | { |
| 134 | UINTN i; |
| 135 | AGESA_STATUS CalloutStatus; |
Aladyshev Konstantin | 3d63b0a | 2012-12-19 00:58:35 +0400 | [diff] [blame] | 136 | UINTN CallOutCount = sizeof (BiosCallouts) / sizeof (BiosCallouts [0]); |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 137 | |
Aladyshev Konstantin | 3d63b0a | 2012-12-19 00:58:35 +0400 | [diff] [blame] | 138 | for (i = 0; i < CallOutCount; i++) { |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 139 | if (BiosCallouts[i].CalloutName == Func) { |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
Aladyshev Konstantin | 3d63b0a | 2012-12-19 00:58:35 +0400 | [diff] [blame] | 144 | if(i >= CallOutCount) { |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 145 | return AGESA_UNSUPPORTED; |
| 146 | } |
| 147 | |
| 148 | CalloutStatus = BiosCallouts[i].CalloutPtr (Func, Data, ConfigPtr); |
| 149 | |
| 150 | return CalloutStatus; |
| 151 | } |
| 152 | |
| 153 | |
| 154 | CONST IDS_NV_ITEM IdsData[] = |
| 155 | { |
| 156 | /*{ |
| 157 | AGESA_IDS_NV_MAIN_PLL_CON, |
| 158 | 0x1 |
| 159 | }, |
| 160 | { |
| 161 | AGESA_IDS_NV_MAIN_PLL_FID_EN, |
| 162 | 0x1 |
| 163 | }, |
| 164 | { |
| 165 | AGESA_IDS_NV_MAIN_PLL_FID, |
| 166 | 0x8 |
| 167 | }, |
| 168 | |
| 169 | { |
| 170 | AGESA_IDS_NV_CUSTOM_NB_PSTATE, |
| 171 | }, |
| 172 | { |
| 173 | AGESA_IDS_NV_CUSTOM_NB_P0_DIV_CTRL, |
| 174 | }, |
| 175 | { |
| 176 | AGESA_IDS_NV_CUSTOM_NB_P1_DIV_CTRL, |
| 177 | }, |
| 178 | { |
| 179 | AGESA_IDS_NV_FORCE_NB_PSTATE, |
| 180 | }, |
| 181 | */ |
| 182 | { |
| 183 | 0xFFFF, |
| 184 | 0xFFFF |
| 185 | } |
| 186 | }; |
| 187 | |
| 188 | #define NUM_IDS_ENTRIES (sizeof (IdsData) / sizeof (IDS_NV_ITEM)) |
| 189 | |
| 190 | AGESA_STATUS BiosGetIdsInitData (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 191 | { |
| 192 | UINTN i; |
| 193 | IDS_NV_ITEM *IdsPtr; |
| 194 | |
| 195 | IdsPtr = ((IDS_CALLOUT_STRUCT *) ConfigPtr)->IdsNvPtr; |
| 196 | |
| 197 | if (Data == IDS_CALLOUT_INIT) { |
| 198 | for (i = 0; i < NUM_IDS_ENTRIES; i++) { |
| 199 | IdsPtr[i].IdsNvValue = IdsData[i].IdsNvValue; |
| 200 | IdsPtr[i].IdsNvId = IdsData[i].IdsNvId; |
| 201 | } |
| 202 | } |
| 203 | return AGESA_SUCCESS; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | AGESA_STATUS BiosAllocateBuffer (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 208 | { |
| 209 | UINT32 AvailableHeapSize; |
| 210 | UINT8 *BiosHeapBaseAddr; |
| 211 | UINT32 CurrNodeOffset; |
| 212 | UINT32 PrevNodeOffset; |
| 213 | UINT32 FreedNodeOffset; |
| 214 | UINT32 BestFitNodeOffset; |
| 215 | UINT32 BestFitPrevNodeOffset; |
| 216 | UINT32 NextFreeOffset; |
| 217 | BIOS_BUFFER_NODE *CurrNodePtr; |
| 218 | BIOS_BUFFER_NODE *FreedNodePtr; |
| 219 | BIOS_BUFFER_NODE *BestFitNodePtr; |
| 220 | BIOS_BUFFER_NODE *BestFitPrevNodePtr; |
| 221 | BIOS_BUFFER_NODE *NextFreePtr; |
| 222 | BIOS_HEAP_MANAGER *BiosHeapBasePtr; |
| 223 | AGESA_BUFFER_PARAMS *AllocParams; |
| 224 | |
| 225 | AllocParams = ((AGESA_BUFFER_PARAMS *) ConfigPtr); |
| 226 | AllocParams->BufferPointer = NULL; |
| 227 | |
| 228 | AvailableHeapSize = BIOS_HEAP_SIZE - sizeof (BIOS_HEAP_MANAGER); |
| 229 | BiosHeapBaseAddr = (UINT8 *) BIOS_HEAP_START_ADDRESS; |
| 230 | BiosHeapBasePtr = (BIOS_HEAP_MANAGER *) BIOS_HEAP_START_ADDRESS; |
| 231 | |
| 232 | if (BiosHeapBasePtr->StartOfAllocatedNodes == 0) { |
| 233 | /* First allocation */ |
| 234 | CurrNodeOffset = sizeof (BIOS_HEAP_MANAGER); |
| 235 | CurrNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + CurrNodeOffset); |
| 236 | CurrNodePtr->BufferHandle = AllocParams->BufferHandle; |
| 237 | CurrNodePtr->BufferSize = AllocParams->BufferLength; |
| 238 | CurrNodePtr->NextNodeOffset = 0; |
| 239 | AllocParams->BufferPointer = (UINT8 *) CurrNodePtr + sizeof (BIOS_BUFFER_NODE); |
| 240 | |
| 241 | /* Update the remaining free space */ |
| 242 | FreedNodeOffset = CurrNodeOffset + CurrNodePtr->BufferSize + sizeof (BIOS_BUFFER_NODE); |
| 243 | FreedNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + FreedNodeOffset); |
| 244 | FreedNodePtr->BufferSize = AvailableHeapSize - sizeof (BIOS_BUFFER_NODE) - CurrNodePtr->BufferSize; |
| 245 | FreedNodePtr->NextNodeOffset = 0; |
| 246 | |
| 247 | /* Update the offsets for Allocated and Freed nodes */ |
| 248 | BiosHeapBasePtr->StartOfAllocatedNodes = CurrNodeOffset; |
| 249 | BiosHeapBasePtr->StartOfFreedNodes = FreedNodeOffset; |
| 250 | } else { |
| 251 | /* Find out whether BufferHandle has been allocated on the heap. */ |
| 252 | /* If it has, return AGESA_BOUNDS_CHK */ |
| 253 | CurrNodeOffset = BiosHeapBasePtr->StartOfAllocatedNodes; |
| 254 | CurrNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + CurrNodeOffset); |
| 255 | |
| 256 | while (CurrNodeOffset != 0) { |
| 257 | CurrNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + CurrNodeOffset); |
| 258 | if (CurrNodePtr->BufferHandle == AllocParams->BufferHandle) { |
| 259 | return AGESA_BOUNDS_CHK; |
| 260 | } |
| 261 | CurrNodeOffset = CurrNodePtr->NextNodeOffset; |
| 262 | /* If BufferHandle has not been allocated on the heap, CurrNodePtr here points |
| 263 | to the end of the allocated nodes list. |
| 264 | */ |
| 265 | |
| 266 | } |
| 267 | /* Find the node that best fits the requested buffer size */ |
| 268 | FreedNodeOffset = BiosHeapBasePtr->StartOfFreedNodes; |
| 269 | PrevNodeOffset = FreedNodeOffset; |
| 270 | BestFitNodeOffset = 0; |
| 271 | BestFitPrevNodeOffset = 0; |
| 272 | while (FreedNodeOffset != 0) { |
| 273 | FreedNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + FreedNodeOffset); |
| 274 | if (FreedNodePtr->BufferSize >= (AllocParams->BufferLength + sizeof (BIOS_BUFFER_NODE))) { |
| 275 | if (BestFitNodeOffset == 0) { |
| 276 | /* First node that fits the requested buffer size */ |
| 277 | BestFitNodeOffset = FreedNodeOffset; |
| 278 | BestFitPrevNodeOffset = PrevNodeOffset; |
| 279 | } else { |
| 280 | /* Find out whether current node is a better fit than the previous nodes */ |
| 281 | BestFitNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + BestFitNodeOffset); |
| 282 | if (BestFitNodePtr->BufferSize > FreedNodePtr->BufferSize) { |
| 283 | BestFitNodeOffset = FreedNodeOffset; |
| 284 | BestFitPrevNodeOffset = PrevNodeOffset; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | PrevNodeOffset = FreedNodeOffset; |
| 289 | FreedNodeOffset = FreedNodePtr->NextNodeOffset; |
| 290 | } /* end of while loop */ |
| 291 | |
| 292 | |
| 293 | if (BestFitNodeOffset == 0) { |
| 294 | /* If we could not find a node that fits the requested buffer */ |
| 295 | /* size, return AGESA_BOUNDS_CHK */ |
| 296 | return AGESA_BOUNDS_CHK; |
| 297 | } else { |
| 298 | BestFitNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + BestFitNodeOffset); |
| 299 | BestFitPrevNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + BestFitPrevNodeOffset); |
| 300 | |
| 301 | /* If BestFitNode is larger than the requested buffer, fragment the node further */ |
| 302 | if (BestFitNodePtr->BufferSize > (AllocParams->BufferLength + sizeof (BIOS_BUFFER_NODE))) { |
| 303 | NextFreeOffset = BestFitNodeOffset + AllocParams->BufferLength + sizeof (BIOS_BUFFER_NODE); |
| 304 | |
| 305 | NextFreePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + NextFreeOffset); |
| 306 | NextFreePtr->BufferSize = BestFitNodePtr->BufferSize - (AllocParams->BufferLength + sizeof (BIOS_BUFFER_NODE)); |
| 307 | NextFreePtr->NextNodeOffset = BestFitNodePtr->NextNodeOffset; |
| 308 | } else { |
| 309 | /* Otherwise, next free node is NextNodeOffset of BestFitNode */ |
| 310 | NextFreeOffset = BestFitNodePtr->NextNodeOffset; |
| 311 | } |
| 312 | |
| 313 | /* If BestFitNode is the first buffer in the list, then update |
| 314 | StartOfFreedNodes to reflect the new free node |
| 315 | */ |
| 316 | if (BestFitNodeOffset == BiosHeapBasePtr->StartOfFreedNodes) { |
| 317 | BiosHeapBasePtr->StartOfFreedNodes = NextFreeOffset; |
| 318 | } else { |
| 319 | BestFitPrevNodePtr->NextNodeOffset = NextFreeOffset; |
| 320 | } |
| 321 | |
| 322 | /* Add BestFitNode to the list of Allocated nodes */ |
| 323 | CurrNodePtr->NextNodeOffset = BestFitNodeOffset; |
| 324 | BestFitNodePtr->BufferSize = AllocParams->BufferLength; |
| 325 | BestFitNodePtr->BufferHandle = AllocParams->BufferHandle; |
| 326 | BestFitNodePtr->NextNodeOffset = 0; |
| 327 | |
| 328 | /* Remove BestFitNode from list of Freed nodes */ |
| 329 | AllocParams->BufferPointer = (UINT8 *) BestFitNodePtr + sizeof (BIOS_BUFFER_NODE); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | return AGESA_SUCCESS; |
| 334 | } |
| 335 | |
| 336 | AGESA_STATUS BiosDeallocateBuffer (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 337 | { |
| 338 | |
| 339 | UINT8 *BiosHeapBaseAddr; |
| 340 | UINT32 AllocNodeOffset; |
| 341 | UINT32 PrevNodeOffset; |
| 342 | UINT32 NextNodeOffset; |
| 343 | UINT32 FreedNodeOffset; |
| 344 | UINT32 EndNodeOffset; |
| 345 | BIOS_BUFFER_NODE *AllocNodePtr; |
| 346 | BIOS_BUFFER_NODE *PrevNodePtr; |
| 347 | BIOS_BUFFER_NODE *FreedNodePtr; |
| 348 | BIOS_BUFFER_NODE *NextNodePtr; |
| 349 | BIOS_HEAP_MANAGER *BiosHeapBasePtr; |
| 350 | AGESA_BUFFER_PARAMS *AllocParams; |
| 351 | |
| 352 | BiosHeapBaseAddr = (UINT8 *) BIOS_HEAP_START_ADDRESS; |
| 353 | BiosHeapBasePtr = (BIOS_HEAP_MANAGER *) BIOS_HEAP_START_ADDRESS; |
| 354 | |
| 355 | AllocParams = (AGESA_BUFFER_PARAMS *) ConfigPtr; |
| 356 | |
| 357 | /* Find target node to deallocate in list of allocated nodes. |
| 358 | Return AGESA_BOUNDS_CHK if the BufferHandle is not found |
| 359 | */ |
| 360 | AllocNodeOffset = BiosHeapBasePtr->StartOfAllocatedNodes; |
| 361 | AllocNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + AllocNodeOffset); |
| 362 | PrevNodeOffset = AllocNodeOffset; |
| 363 | |
| 364 | while (AllocNodePtr->BufferHandle != AllocParams->BufferHandle) { |
| 365 | if (AllocNodePtr->NextNodeOffset == 0) { |
| 366 | return AGESA_BOUNDS_CHK; |
| 367 | } |
| 368 | PrevNodeOffset = AllocNodeOffset; |
| 369 | AllocNodeOffset = AllocNodePtr->NextNodeOffset; |
| 370 | AllocNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + AllocNodeOffset); |
| 371 | } |
| 372 | |
| 373 | /* Remove target node from list of allocated nodes */ |
| 374 | PrevNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + PrevNodeOffset); |
| 375 | PrevNodePtr->NextNodeOffset = AllocNodePtr->NextNodeOffset; |
| 376 | |
| 377 | /* Zero out the buffer, and clear the BufferHandle */ |
| 378 | LibAmdMemFill ((UINT8 *)AllocNodePtr + sizeof (BIOS_BUFFER_NODE), 0, AllocNodePtr->BufferSize, &(AllocParams->StdHeader)); |
| 379 | AllocNodePtr->BufferHandle = 0; |
| 380 | AllocNodePtr->BufferSize += sizeof (BIOS_BUFFER_NODE); |
| 381 | |
| 382 | /* Add deallocated node in order to the list of freed nodes */ |
| 383 | FreedNodeOffset = BiosHeapBasePtr->StartOfFreedNodes; |
| 384 | FreedNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + FreedNodeOffset); |
| 385 | |
| 386 | EndNodeOffset = AllocNodeOffset + AllocNodePtr->BufferSize; |
| 387 | |
| 388 | if (AllocNodeOffset < FreedNodeOffset) { |
| 389 | /* Add to the start of the freed list */ |
| 390 | if (EndNodeOffset == FreedNodeOffset) { |
| 391 | /* If the freed node is adjacent to the first node in the list, concatenate both nodes */ |
| 392 | AllocNodePtr->BufferSize += FreedNodePtr->BufferSize; |
| 393 | AllocNodePtr->NextNodeOffset = FreedNodePtr->NextNodeOffset; |
| 394 | |
| 395 | /* Clear the BufferSize and NextNodeOffset of the previous first node */ |
| 396 | FreedNodePtr->BufferSize = 0; |
| 397 | FreedNodePtr->NextNodeOffset = 0; |
| 398 | |
| 399 | } else { |
| 400 | /* Otherwise, add freed node to the start of the list |
| 401 | Update NextNodeOffset and BufferSize to include the |
| 402 | size of BIOS_BUFFER_NODE |
| 403 | */ |
| 404 | AllocNodePtr->NextNodeOffset = FreedNodeOffset; |
| 405 | } |
| 406 | /* Update StartOfFreedNodes to the new first node */ |
| 407 | BiosHeapBasePtr->StartOfFreedNodes = AllocNodeOffset; |
| 408 | } else { |
| 409 | /* Traverse list of freed nodes to find where the deallocated node |
| 410 | should be place |
| 411 | */ |
| 412 | NextNodeOffset = FreedNodeOffset; |
| 413 | NextNodePtr = FreedNodePtr; |
| 414 | while (AllocNodeOffset > NextNodeOffset) { |
| 415 | PrevNodeOffset = NextNodeOffset; |
| 416 | if (NextNodePtr->NextNodeOffset == 0) { |
| 417 | break; |
| 418 | } |
| 419 | NextNodeOffset = NextNodePtr->NextNodeOffset; |
| 420 | NextNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + NextNodeOffset); |
| 421 | } |
| 422 | |
| 423 | /* If deallocated node is adjacent to the next node, |
| 424 | concatenate both nodes |
| 425 | */ |
| 426 | if (NextNodeOffset == EndNodeOffset) { |
| 427 | NextNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + NextNodeOffset); |
| 428 | AllocNodePtr->BufferSize += NextNodePtr->BufferSize; |
| 429 | AllocNodePtr->NextNodeOffset = NextNodePtr->NextNodeOffset; |
| 430 | |
| 431 | NextNodePtr->BufferSize = 0; |
| 432 | NextNodePtr->NextNodeOffset = 0; |
| 433 | } else { |
| 434 | /*AllocNodePtr->NextNodeOffset = FreedNodePtr->NextNodeOffset; */ |
| 435 | AllocNodePtr->NextNodeOffset = NextNodeOffset; |
| 436 | } |
| 437 | /* If deallocated node is adjacent to the previous node, |
| 438 | concatenate both nodes |
| 439 | */ |
| 440 | PrevNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + PrevNodeOffset); |
| 441 | EndNodeOffset = PrevNodeOffset + PrevNodePtr->BufferSize; |
| 442 | if (AllocNodeOffset == EndNodeOffset) { |
| 443 | PrevNodePtr->NextNodeOffset = AllocNodePtr->NextNodeOffset; |
| 444 | PrevNodePtr->BufferSize += AllocNodePtr->BufferSize; |
| 445 | |
| 446 | AllocNodePtr->BufferSize = 0; |
| 447 | AllocNodePtr->NextNodeOffset = 0; |
| 448 | } else { |
| 449 | PrevNodePtr->NextNodeOffset = AllocNodeOffset; |
| 450 | } |
| 451 | } |
| 452 | return AGESA_SUCCESS; |
| 453 | } |
| 454 | |
| 455 | AGESA_STATUS BiosLocateBuffer (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 456 | { |
| 457 | UINT32 AllocNodeOffset; |
| 458 | UINT8 *BiosHeapBaseAddr; |
| 459 | BIOS_BUFFER_NODE *AllocNodePtr; |
| 460 | BIOS_HEAP_MANAGER *BiosHeapBasePtr; |
| 461 | AGESA_BUFFER_PARAMS *AllocParams; |
| 462 | |
| 463 | AllocParams = (AGESA_BUFFER_PARAMS *) ConfigPtr; |
| 464 | |
| 465 | BiosHeapBaseAddr = (UINT8 *) BIOS_HEAP_START_ADDRESS; |
| 466 | BiosHeapBasePtr = (BIOS_HEAP_MANAGER *) BIOS_HEAP_START_ADDRESS; |
| 467 | |
| 468 | AllocNodeOffset = BiosHeapBasePtr->StartOfAllocatedNodes; |
| 469 | AllocNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + AllocNodeOffset); |
| 470 | |
| 471 | while (AllocParams->BufferHandle != AllocNodePtr->BufferHandle) { |
| 472 | if (AllocNodePtr->NextNodeOffset == 0) { |
| 473 | AllocParams->BufferPointer = NULL; |
| 474 | AllocParams->BufferLength = 0; |
| 475 | return AGESA_BOUNDS_CHK; |
| 476 | } else { |
| 477 | AllocNodeOffset = AllocNodePtr->NextNodeOffset; |
| 478 | AllocNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + AllocNodeOffset); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | AllocParams->BufferPointer = (UINT8 *) ((UINT8 *) AllocNodePtr + sizeof (BIOS_BUFFER_NODE)); |
| 483 | AllocParams->BufferLength = AllocNodePtr->BufferSize; |
| 484 | |
| 485 | return AGESA_SUCCESS; |
| 486 | |
| 487 | } |
| 488 | |
| 489 | AGESA_STATUS BiosRunFuncOnAp (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 490 | { |
| 491 | AGESA_STATUS Status; |
| 492 | |
| 493 | Status = agesawrapper_amdlaterunaptask (Data, ConfigPtr); |
| 494 | return Status; |
| 495 | } |
| 496 | |
| 497 | AGESA_STATUS BiosReset (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 498 | { |
| 499 | AGESA_STATUS Status; |
| 500 | UINT8 Value; |
| 501 | UINTN ResetType; |
| 502 | AMD_CONFIG_PARAMS *StdHeader; |
| 503 | |
| 504 | ResetType = Data; |
| 505 | StdHeader = ConfigPtr; |
| 506 | |
| 507 | // |
| 508 | // Perform the RESET based upon the ResetType. In case of |
| 509 | // WARM_RESET_WHENVER and COLD_RESET_WHENEVER, the request will go to |
| 510 | // AmdResetManager. During the critical condition, where reset is required |
| 511 | // immediately, the reset will be invoked directly by writing 0x04 to port |
| 512 | // 0xCF9 (Reset Port). |
| 513 | // |
| 514 | switch (ResetType) { |
| 515 | case WARM_RESET_WHENEVER: |
| 516 | case COLD_RESET_WHENEVER: |
| 517 | break; |
| 518 | |
| 519 | case WARM_RESET_IMMEDIATELY: |
| 520 | case COLD_RESET_IMMEDIATELY: |
| 521 | Value = 0x06; |
| 522 | LibAmdIoWrite (AccessWidth8, 0xCf9, &Value, StdHeader); |
| 523 | break; |
| 524 | |
| 525 | default: |
| 526 | break; |
| 527 | } |
| 528 | |
| 529 | Status = 0; |
| 530 | return Status; |
| 531 | } |
| 532 | |
| 533 | AGESA_STATUS BiosReadSpd (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 534 | { |
| 535 | AGESA_STATUS Status; |
Kimarie Hoot | eef45f9 | 2013-03-08 13:54:10 -0700 | [diff] [blame^] | 536 | #ifdef __PRE_RAM__ |
| 537 | UINT8 original_value = 0; |
| 538 | |
| 539 | if (ConfigPtr == NULL) |
| 540 | return AGESA_ERROR; |
| 541 | |
| 542 | original_value = select_socket(((AGESA_READ_SPD_PARAMS *)ConfigPtr)->SocketId); |
| 543 | |
| 544 | Status = agesa_ReadSPD (Func, Data, ConfigPtr); |
| 545 | |
| 546 | restore_socket(original_value); |
| 547 | #else |
| 548 | Status = AGESA_UNSUPPORTED; |
| 549 | #endif |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 550 | |
| 551 | return Status; |
| 552 | } |
| 553 | |
| 554 | AGESA_STATUS BiosDefaultRet (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 555 | { |
| 556 | return AGESA_UNSUPPORTED; |
| 557 | } |
| 558 | |
| 559 | /* Call the host environment interface to provide a user hook opportunity. */ |
| 560 | AGESA_STATUS BiosHookBeforeDQSTraining (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 561 | { |
| 562 | return AGESA_SUCCESS; |
| 563 | } |
| 564 | |
| 565 | /* Call the host environment interface to provide a user hook opportunity. */ |
| 566 | AGESA_STATUS BiosHookBeforeDramInit (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 567 | { |
| 568 | return AGESA_SUCCESS; |
| 569 | } |
| 570 | |
| 571 | /* Call the host environment interface to provide a user hook opportunity. */ |
| 572 | AGESA_STATUS BiosHookBeforeExitSelfRefresh (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 573 | { |
| 574 | return AGESA_SUCCESS; |
| 575 | } |
| 576 | |