zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * S3 save/restore script |
| 6 | * |
| 7 | * |
| 8 | * |
| 9 | * @xrefitem bom "File Content Label" "Release Content" |
| 10 | * @e project: AGESA |
| 11 | * @e sub-project: GNB |
| 12 | * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ |
| 13 | * |
| 14 | */ |
| 15 | /* |
| 16 | ***************************************************************************** |
| 17 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 18 | * Copyright (c) 2008 - 2012, Advanced Micro Devices, Inc. |
| 19 | * All rights reserved. |
| 20 | * |
| 21 | * Redistribution and use in source and binary forms, with or without |
| 22 | * modification, are permitted provided that the following conditions are met: |
| 23 | * * Redistributions of source code must retain the above copyright |
| 24 | * notice, this list of conditions and the following disclaimer. |
| 25 | * * Redistributions in binary form must reproduce the above copyright |
| 26 | * notice, this list of conditions and the following disclaimer in the |
| 27 | * documentation and/or other materials provided with the distribution. |
| 28 | * * Neither the name of Advanced Micro Devices, Inc. nor the names of |
| 29 | * its contributors may be used to endorse or promote products derived |
| 30 | * from this software without specific prior written permission. |
| 31 | * |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 33 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 34 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 35 | * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY |
| 36 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 37 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 38 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 39 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 40 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 41 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 42 | * *************************************************************************** |
| 43 | * |
| 44 | */ |
| 45 | |
| 46 | /*---------------------------------------------------------------------------------------- |
| 47 | * M O D U L E S U S E D |
| 48 | *---------------------------------------------------------------------------------------- |
| 49 | */ |
| 50 | #include "Porting.h" |
| 51 | #include "AMD.h" |
| 52 | #include "AGESA.h" |
| 53 | #include "Ids.h" |
| 54 | #include "amdlib.h" |
| 55 | #include "heapManager.h" |
| 56 | #include "S3SaveState.h" |
| 57 | #include "Filecode.h" |
| 58 | CODE_GROUP (G3_DXE) |
| 59 | RDATA_GROUP (G3_DXE) |
| 60 | |
| 61 | #define FILECODE PROC_COMMON_S3SAVESTATE_FILECODE |
| 62 | /*---------------------------------------------------------------------------------------- |
| 63 | * D E F I N I T I O N S A N D M A C R O S |
| 64 | *---------------------------------------------------------------------------------------- |
| 65 | */ |
| 66 | |
| 67 | |
| 68 | /*---------------------------------------------------------------------------------------- |
| 69 | * T Y P E D E F S A N D S T R U C T U R E S |
| 70 | *---------------------------------------------------------------------------------------- |
| 71 | */ |
| 72 | extern S3_SCRIPT_CONFIGURATION OptionS3ScriptConfiguration; |
| 73 | |
| 74 | /*---------------------------------------------------------------------------------------- |
| 75 | * P R O T O T Y P E S O F L O C A L F U N C T I O N S |
| 76 | *---------------------------------------------------------------------------------------- |
| 77 | */ |
| 78 | AGESA_STATUS |
| 79 | S3SaveStateExtendTableLenth ( |
| 80 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 81 | IN OUT S3_SAVE_TABLE_HEADER **S3SaveTable |
| 82 | ); |
| 83 | |
| 84 | /*----------------------------------------------------------------------------------------*/ |
| 85 | /** |
| 86 | * Initialize S3 Script framework |
| 87 | * |
| 88 | * |
| 89 | * |
| 90 | * @param[in] StdHeader Pointer to standard header |
| 91 | */ |
| 92 | AGESA_STATUS |
| 93 | S3ScriptInit ( |
| 94 | IN AMD_CONFIG_PARAMS *StdHeader |
| 95 | ) |
| 96 | { |
| 97 | return OptionS3ScriptConfiguration.Init (StdHeader); |
| 98 | } |
| 99 | |
| 100 | /*----------------------------------------------------------------------------------------*/ |
| 101 | /** |
| 102 | * Initialize S3 Script framework |
| 103 | * |
| 104 | * |
| 105 | * |
| 106 | * @param[in] StdHeader Pointer to standard header |
| 107 | */ |
| 108 | AGESA_STATUS |
| 109 | S3ScriptInitStateStub ( |
| 110 | IN AMD_CONFIG_PARAMS *StdHeader |
| 111 | ) |
| 112 | { |
| 113 | return AGESA_SUCCESS; |
| 114 | } |
| 115 | |
| 116 | /*----------------------------------------------------------------------------------------*/ |
| 117 | /** |
| 118 | * Initialize S3 Script framework |
| 119 | * |
| 120 | * |
| 121 | * |
| 122 | * @param[in] StdHeader Pointer to standard header |
| 123 | */ |
| 124 | AGESA_STATUS |
| 125 | S3ScriptInitState ( |
| 126 | IN AMD_CONFIG_PARAMS *StdHeader |
| 127 | ) |
| 128 | { |
| 129 | AGESA_STATUS Status; |
| 130 | ALLOCATE_HEAP_PARAMS AllocHeapParams; |
| 131 | |
| 132 | AllocHeapParams.RequestedBufferSize = S3_TABLE_LENGTH; |
| 133 | AllocHeapParams.BufferHandle = AMD_S3_SCRIPT_SAVE_TABLE_HANDLE; |
| 134 | AllocHeapParams.Persist = HEAP_SYSTEM_MEM; |
| 135 | Status = HeapAllocateBuffer (&AllocHeapParams, StdHeader); |
| 136 | if (Status == AGESA_SUCCESS) { |
| 137 | ((S3_SAVE_TABLE_HEADER *) AllocHeapParams.BufferPtr)->TableLength = S3_TABLE_LENGTH; |
| 138 | ((S3_SAVE_TABLE_HEADER *) AllocHeapParams.BufferPtr)->SaveOffset = sizeof (S3_SAVE_TABLE_HEADER); |
| 139 | ((S3_SAVE_TABLE_HEADER *) AllocHeapParams.BufferPtr)->Locked = FALSE; |
| 140 | } |
| 141 | return Status; |
| 142 | } |
| 143 | |
| 144 | /*----------------------------------------------------------------------------------------*/ |
| 145 | /** |
| 146 | * Initialize S3 Script framework |
| 147 | * |
| 148 | * |
| 149 | * |
| 150 | * @param[in] StdHeader Pointer to standard header |
| 151 | * @param[in,out] S3SaveTable S3 save table header |
| 152 | */ |
| 153 | AGESA_STATUS |
| 154 | S3SaveStateExtendTableLenth ( |
| 155 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 156 | IN OUT S3_SAVE_TABLE_HEADER **S3SaveTable |
| 157 | ) |
| 158 | { |
| 159 | AGESA_STATUS Status; |
| 160 | ALLOCATE_HEAP_PARAMS AllocHeapParams; |
| 161 | VOID *TempBuffer; |
| 162 | UINT16 NewTableLength; |
| 163 | UINT16 CurrentTableLength; |
| 164 | //Allocate temporary buffer |
| 165 | NewTableLength = (*S3SaveTable)->TableLength + S3_TABLE_LENGTH_INCREMENT; |
| 166 | AllocHeapParams.RequestedBufferSize = NewTableLength; |
| 167 | AllocHeapParams.BufferHandle = AMD_S3_SCRIPT_TEMP_BUFFER_HANDLE; |
| 168 | AllocHeapParams.Persist = StdHeader->HeapStatus; |
| 169 | Status = HeapAllocateBuffer (&AllocHeapParams, StdHeader); |
| 170 | if (Status != AGESA_SUCCESS) { |
| 171 | return Status; |
| 172 | } |
| 173 | //Save current table length |
| 174 | CurrentTableLength = (*S3SaveTable)->TableLength; |
| 175 | //Update table length |
| 176 | (*S3SaveTable)->TableLength = NewTableLength; |
| 177 | //Copy S3 save toable to temporary location |
| 178 | LibAmdMemCopy (AllocHeapParams.BufferPtr, *S3SaveTable, CurrentTableLength, StdHeader); |
| 179 | //Save pointer to temp buffer |
| 180 | TempBuffer = AllocHeapParams.BufferPtr; |
| 181 | // Free original S3 save buffer |
| 182 | HeapDeallocateBuffer (AMD_S3_SCRIPT_SAVE_TABLE_HANDLE, StdHeader); |
| 183 | |
| 184 | AllocHeapParams.RequestedBufferSize = NewTableLength; |
| 185 | AllocHeapParams.BufferHandle = AMD_S3_SCRIPT_SAVE_TABLE_HANDLE; |
| 186 | AllocHeapParams.Persist = StdHeader->HeapStatus; |
| 187 | Status = HeapAllocateBuffer (&AllocHeapParams, StdHeader); |
| 188 | if (Status != AGESA_SUCCESS) { |
| 189 | return Status; |
| 190 | } |
| 191 | LibAmdMemCopy (AllocHeapParams.BufferPtr, TempBuffer, AllocHeapParams.RequestedBufferSize, StdHeader); |
| 192 | *S3SaveTable = (S3_SAVE_TABLE_HEADER*) AllocHeapParams.BufferPtr; |
| 193 | HeapDeallocateBuffer (AMD_S3_SCRIPT_TEMP_BUFFER_HANDLE, StdHeader); |
| 194 | return Status; |
| 195 | } |
| 196 | |
| 197 | |
| 198 | /*----------------------------------------------------------------------------------------*/ |
| 199 | /** |
| 200 | * Initialize S3 Script framework |
| 201 | * |
| 202 | * |
| 203 | * |
| 204 | * @param[in] StdHeader Pointer to standard header |
| 205 | * @param[out] S3SaveTable S3 save table header |
| 206 | */ |
| 207 | AGESA_STATUS |
| 208 | S3ScriptGetS3SaveTable ( |
| 209 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 210 | OUT S3_SAVE_TABLE_HEADER **S3SaveTable |
| 211 | ) |
| 212 | { |
| 213 | AGESA_STATUS Status; |
| 214 | LOCATE_HEAP_PTR LocHeapParams; |
| 215 | LocHeapParams.BufferHandle = AMD_S3_SCRIPT_SAVE_TABLE_HANDLE; |
| 216 | Status = HeapLocateBuffer (&LocHeapParams, StdHeader); |
| 217 | if (Status != AGESA_SUCCESS) { |
| 218 | *S3SaveTable = NULL; |
| 219 | return Status; |
| 220 | } |
| 221 | *S3SaveTable = (S3_SAVE_TABLE_HEADER *) LocHeapParams.BufferPtr; |
| 222 | return AGESA_SUCCESS; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | /*----------------------------------------------------------------------------------------*/ |
| 227 | /** |
| 228 | * Save S3 write opcode |
| 229 | * |
| 230 | * |
| 231 | * |
| 232 | * @param[in] StdHeader Pointer to standard header |
| 233 | * @param[in] OpCode Operation opcode |
| 234 | * @param[in] Width Width |
| 235 | * @param[in] Address Register address |
| 236 | * @param[in] Count Number of register writes |
| 237 | * @param[in] Buffer Pointer to write buffer |
| 238 | */ |
| 239 | AGESA_STATUS |
| 240 | S3SaveStateSaveWriteOp ( |
| 241 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 242 | IN UINT16 OpCode, |
| 243 | IN ACCESS_WIDTH Width, |
| 244 | IN UINT64 Address, |
| 245 | IN UINT32 Count, |
Arthur Heymans | 8d3640d | 2022-05-16 12:27:36 +0200 | [diff] [blame^] | 246 | CONST IN VOID *Buffer |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 247 | ) |
| 248 | { |
| 249 | S3_SAVE_TABLE_HEADER *S3SaveTablePtr; |
| 250 | S3_WRITE_OP_HEADER *SaveOffsetPtr; |
| 251 | UINT32 OpCodeLength; |
| 252 | UINT32 WidthLength; |
| 253 | AGESA_STATUS Status; |
| 254 | |
| 255 | Status = S3ScriptGetS3SaveTable (StdHeader, &S3SaveTablePtr); |
| 256 | if (Status != AGESA_SUCCESS) { |
| 257 | return Status; |
| 258 | } |
| 259 | if (S3SaveTablePtr->Locked) { |
| 260 | return AGESA_UNSUPPORTED; |
| 261 | } |
| 262 | WidthLength = LibAmdAccessWidth (Width); |
| 263 | OpCodeLength = sizeof (S3_WRITE_OP_HEADER) + WidthLength * Count; |
| 264 | if ((S3SaveTablePtr->SaveOffset + OpCodeLength) > S3SaveTablePtr->TableLength) { |
| 265 | Status = S3SaveStateExtendTableLenth (StdHeader, &S3SaveTablePtr); |
| 266 | if (Status != AGESA_SUCCESS) { |
| 267 | return Status; |
| 268 | } |
| 269 | } |
| 270 | S3_SCRIPT_DEBUG_CODE ( |
Angel Pons | b382b89 | 2021-05-09 16:11:30 +0200 | [diff] [blame] | 271 | IDS_HDT_CONSOLE (S3_TRACE, " S3 Save: %s Address: 0x%016llx Data: ", S3SaveDebugOpcodeString (StdHeader, OpCode), Address); |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 272 | S3SaveDebugPrintHexArray (StdHeader, Buffer, Count, Width); |
| 273 | IDS_HDT_CONSOLE (S3_TRACE, "\n"); |
| 274 | ); |
| 275 | SaveOffsetPtr = (S3_WRITE_OP_HEADER *) ((UINT8 *) S3SaveTablePtr + S3SaveTablePtr->SaveOffset); |
| 276 | SaveOffsetPtr->OpCode = OpCode; |
| 277 | SaveOffsetPtr->Width = Width; |
| 278 | SaveOffsetPtr->Count = Count; |
| 279 | SaveOffsetPtr->Address = Address; |
| 280 | LibAmdMemCopy ( |
| 281 | (UINT8 *) SaveOffsetPtr + sizeof (S3_WRITE_OP_HEADER), |
| 282 | Buffer, |
| 283 | WidthLength * Count, |
| 284 | StdHeader |
| 285 | ); |
| 286 | S3SaveTablePtr->SaveOffset += OpCodeLength; |
| 287 | return AGESA_SUCCESS; |
| 288 | } |
| 289 | |
| 290 | /*----------------------------------------------------------------------------------------*/ |
| 291 | /** |
| 292 | * Save S3 write opcode |
| 293 | * |
| 294 | * |
| 295 | * |
| 296 | * @param[in] StdHeader Pointer to standard header |
| 297 | * @param[in] OpCode Operation opcode |
| 298 | * @param[in] Width Width |
| 299 | * @param[in] Address Register address |
| 300 | * @param[in] Data Pointer to data |
| 301 | * @param[in] DataMask Pointer data mask |
| 302 | */ |
| 303 | AGESA_STATUS |
| 304 | S3SaveStateSaveReadWriteOp ( |
| 305 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 306 | IN UINT16 OpCode, |
| 307 | IN ACCESS_WIDTH Width, |
| 308 | IN UINT64 Address, |
| 309 | IN VOID *Data, |
| 310 | IN VOID *DataMask |
| 311 | ) |
| 312 | { |
| 313 | |
| 314 | S3_SAVE_TABLE_HEADER *S3SaveTablePtr; |
| 315 | S3_READ_WRITE_OP_HEADER *SaveOffsetPtr; |
| 316 | UINT32 OpCodeLength; |
| 317 | UINT32 WidthLength; |
| 318 | AGESA_STATUS Status; |
| 319 | |
| 320 | Status = S3ScriptGetS3SaveTable (StdHeader, &S3SaveTablePtr); |
| 321 | if (Status != AGESA_SUCCESS) { |
| 322 | return Status; |
| 323 | } |
| 324 | if (S3SaveTablePtr->Locked) { |
| 325 | return AGESA_UNSUPPORTED; |
| 326 | } |
| 327 | WidthLength = LibAmdAccessWidth (Width); |
| 328 | OpCodeLength = sizeof (S3_READ_WRITE_OP_HEADER) + WidthLength * 2; |
| 329 | if ((S3SaveTablePtr->SaveOffset + OpCodeLength) > S3SaveTablePtr->TableLength) { |
| 330 | Status = S3SaveStateExtendTableLenth (StdHeader, &S3SaveTablePtr); |
| 331 | if (Status != AGESA_SUCCESS) { |
| 332 | return Status; |
| 333 | } |
| 334 | } |
| 335 | S3_SCRIPT_DEBUG_CODE ( |
Angel Pons | b382b89 | 2021-05-09 16:11:30 +0200 | [diff] [blame] | 336 | IDS_HDT_CONSOLE (S3_TRACE, " S3 Save: %s Address: 0x%016llx Data: ", S3SaveDebugOpcodeString (StdHeader, OpCode), Address); |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 337 | S3SaveDebugPrintHexArray (StdHeader, Data, 1, Width); |
| 338 | IDS_HDT_CONSOLE (S3_TRACE, " Mask: "); |
| 339 | S3SaveDebugPrintHexArray (StdHeader, DataMask, 1, Width); |
| 340 | IDS_HDT_CONSOLE (S3_TRACE, "\n"); |
| 341 | ); |
| 342 | SaveOffsetPtr = (S3_READ_WRITE_OP_HEADER *) ((UINT8 *) S3SaveTablePtr + S3SaveTablePtr->SaveOffset); |
| 343 | SaveOffsetPtr->OpCode = OpCode; |
| 344 | SaveOffsetPtr->Width = Width; |
| 345 | SaveOffsetPtr->Address = Address; |
| 346 | |
| 347 | LibAmdMemCopy ( |
| 348 | (UINT8 *) SaveOffsetPtr + sizeof (S3_READ_WRITE_OP_HEADER), |
| 349 | Data, |
| 350 | WidthLength, |
| 351 | StdHeader |
| 352 | ); |
| 353 | LibAmdMemCopy ( |
| 354 | (UINT8 *) SaveOffsetPtr + sizeof (S3_READ_WRITE_OP_HEADER) + WidthLength, |
| 355 | DataMask, |
| 356 | WidthLength, |
| 357 | StdHeader |
| 358 | ); |
| 359 | S3SaveTablePtr->SaveOffset += OpCodeLength; |
| 360 | return AGESA_SUCCESS; |
| 361 | } |
| 362 | |
| 363 | |
| 364 | /*----------------------------------------------------------------------------------------*/ |
| 365 | /** |
| 366 | * Save S3 poll opcode |
| 367 | * |
| 368 | * |
| 369 | * |
| 370 | * @param[in] StdHeader Pointer to standard header |
| 371 | * @param[in] OpCode Operation opcode |
| 372 | * @param[in] Width Width |
| 373 | * @param[in] Address Register address |
| 374 | * @param[in] Data Pointer to data |
| 375 | * @param[in] DataMask Pointer data mask |
| 376 | * @param[in] Delay Time delay for poll |
| 377 | */ |
| 378 | AGESA_STATUS |
| 379 | S3SaveStateSavePollOp ( |
| 380 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 381 | IN UINT16 OpCode, |
| 382 | IN ACCESS_WIDTH Width, |
| 383 | IN UINT64 Address, |
| 384 | IN VOID *Data, |
| 385 | IN VOID *DataMask, |
| 386 | IN UINT64 Delay |
| 387 | ) |
| 388 | { |
| 389 | |
| 390 | S3_SAVE_TABLE_HEADER *S3SaveTablePtr; |
| 391 | S3_POLL_OP_HEADER *SaveOffsetPtr; |
| 392 | UINT32 OpCodeLength; |
| 393 | UINT32 WidthLength; |
| 394 | AGESA_STATUS Status; |
| 395 | |
| 396 | Status = S3ScriptGetS3SaveTable (StdHeader, &S3SaveTablePtr); |
| 397 | if (Status != AGESA_SUCCESS) { |
| 398 | return Status; |
| 399 | } |
| 400 | if (S3SaveTablePtr->Locked) { |
| 401 | return AGESA_UNSUPPORTED; |
| 402 | } |
| 403 | WidthLength = LibAmdAccessWidth (Width); |
| 404 | OpCodeLength = sizeof (S3_POLL_OP_HEADER) + WidthLength * 2; |
| 405 | if ((S3SaveTablePtr->SaveOffset + OpCodeLength) > S3SaveTablePtr->TableLength) { |
| 406 | Status = S3SaveStateExtendTableLenth (StdHeader, &S3SaveTablePtr); |
| 407 | if (Status != AGESA_SUCCESS) { |
| 408 | return Status; |
| 409 | } |
| 410 | } |
| 411 | S3_SCRIPT_DEBUG_CODE ( |
Angel Pons | b382b89 | 2021-05-09 16:11:30 +0200 | [diff] [blame] | 412 | IDS_HDT_CONSOLE (S3_TRACE, " S3 Save: %s Address: 0x%016llx Data: ", S3SaveDebugOpcodeString (StdHeader, OpCode), Address); |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 413 | S3SaveDebugPrintHexArray (StdHeader, Data, 1, Width); |
| 414 | IDS_HDT_CONSOLE (S3_TRACE, " Mask: "); |
| 415 | S3SaveDebugPrintHexArray (StdHeader, DataMask, 1, Width); |
| 416 | IDS_HDT_CONSOLE (S3_TRACE, "\n"); |
| 417 | ); |
| 418 | SaveOffsetPtr = (S3_POLL_OP_HEADER *) ((UINT8 *) S3SaveTablePtr + S3SaveTablePtr->SaveOffset); |
| 419 | SaveOffsetPtr->OpCode = OpCode; |
| 420 | SaveOffsetPtr->Width = Width; |
| 421 | SaveOffsetPtr->Delay = Delay; |
| 422 | SaveOffsetPtr->Address = Address; |
| 423 | |
| 424 | LibAmdMemCopy ( |
| 425 | (UINT8 *) SaveOffsetPtr + sizeof (S3_POLL_OP_HEADER), |
| 426 | Data, |
| 427 | WidthLength, |
| 428 | StdHeader |
| 429 | ); |
| 430 | LibAmdMemCopy ( |
| 431 | (UINT8 *) SaveOffsetPtr + sizeof (S3_POLL_OP_HEADER) + WidthLength, |
| 432 | DataMask, |
| 433 | WidthLength, |
| 434 | StdHeader |
| 435 | ); |
| 436 | S3SaveTablePtr->SaveOffset += OpCodeLength; |
| 437 | return AGESA_SUCCESS; |
| 438 | } |
| 439 | |
| 440 | /*----------------------------------------------------------------------------------------*/ |
| 441 | /** |
| 442 | * Save S3 info opcode |
| 443 | * |
| 444 | * |
| 445 | * |
| 446 | * @param[in] StdHeader Pointer to standard header |
| 447 | * @param[in] OpCode Operation opcode |
| 448 | * @param[in] InformationLength Info length |
| 449 | * @param[in] Information Pointer to information |
| 450 | */ |
| 451 | AGESA_STATUS |
| 452 | S3SaveStateSaveInfoOp ( |
| 453 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 454 | IN UINT16 OpCode, |
| 455 | IN UINT32 InformationLength, |
| 456 | IN VOID *Information |
| 457 | ) |
| 458 | { |
| 459 | |
| 460 | S3_SAVE_TABLE_HEADER *S3SaveTablePtr; |
| 461 | S3_INFO_OP_HEADER *SaveOffsetPtr; |
| 462 | UINT32 OpCodeLength; |
| 463 | |
| 464 | AGESA_STATUS Status; |
| 465 | |
| 466 | Status = S3ScriptGetS3SaveTable (StdHeader, &S3SaveTablePtr); |
| 467 | if (Status != AGESA_SUCCESS) { |
| 468 | return Status; |
| 469 | } |
| 470 | if (S3SaveTablePtr->Locked) { |
| 471 | return AGESA_UNSUPPORTED; |
| 472 | } |
| 473 | OpCodeLength = sizeof (S3_INFO_OP_HEADER) + InformationLength; |
| 474 | if ((S3SaveTablePtr->SaveOffset + OpCodeLength) > S3SaveTablePtr->TableLength) { |
| 475 | Status = S3SaveStateExtendTableLenth (StdHeader, &S3SaveTablePtr); |
| 476 | if (Status != AGESA_SUCCESS) { |
| 477 | return Status; |
| 478 | } |
| 479 | } |
| 480 | SaveOffsetPtr = (S3_INFO_OP_HEADER *) ((UINT8 *) S3SaveTablePtr + S3SaveTablePtr->SaveOffset); |
| 481 | SaveOffsetPtr->OpCode = OpCode; |
| 482 | SaveOffsetPtr->Length = InformationLength; |
| 483 | S3_SCRIPT_DEBUG_CODE ( |
Angel Pons | b382b89 | 2021-05-09 16:11:30 +0200 | [diff] [blame] | 484 | IDS_HDT_CONSOLE (S3_TRACE, " S3 Save: Info: %p\n", Information); |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 485 | ); |
| 486 | LibAmdMemCopy ( |
| 487 | (UINT8 *) SaveOffsetPtr + sizeof (S3_INFO_OP_HEADER), |
| 488 | Information, |
| 489 | InformationLength, |
| 490 | StdHeader |
| 491 | ); |
| 492 | S3SaveTablePtr->SaveOffset += OpCodeLength; |
| 493 | return AGESA_SUCCESS; |
| 494 | } |
| 495 | |
| 496 | /*----------------------------------------------------------------------------------------*/ |
| 497 | /** |
| 498 | * Save S3 dispatch opcode |
| 499 | * |
| 500 | * |
| 501 | * |
| 502 | * @param[in] StdHeader Pointer to standard header |
| 503 | * @param[in] OpCode Operation opcode |
| 504 | * @param[in] FunctionId Function ID |
| 505 | * @param[in] ContextLength Context length |
| 506 | * @param[in] Context Pointer to Context |
| 507 | */ |
| 508 | AGESA_STATUS |
| 509 | S3SaveStateSaveDispatchOp ( |
| 510 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 511 | IN UINT16 OpCode, |
| 512 | IN UINT16 FunctionId, |
| 513 | IN UINT16 ContextLength, |
| 514 | IN VOID *Context |
| 515 | ) |
| 516 | { |
| 517 | |
| 518 | S3_SAVE_TABLE_HEADER *S3SaveTablePtr; |
| 519 | S3_DISPATCH_OP_HEADER *SaveOffsetPtr; |
| 520 | UINT32 OpCodeLength; |
| 521 | AGESA_STATUS Status; |
| 522 | |
| 523 | Status = S3ScriptGetS3SaveTable (StdHeader, &S3SaveTablePtr); |
| 524 | if (Status != AGESA_SUCCESS) { |
| 525 | return Status; |
| 526 | } |
| 527 | if (S3SaveTablePtr->Locked) { |
| 528 | return AGESA_UNSUPPORTED; |
| 529 | } |
| 530 | OpCodeLength = sizeof (S3_DISPATCH_OP_HEADER) + ContextLength; |
| 531 | if ((S3SaveTablePtr->SaveOffset + OpCodeLength) > S3SaveTablePtr->TableLength) { |
| 532 | Status = S3SaveStateExtendTableLenth (StdHeader, &S3SaveTablePtr); |
| 533 | if (Status != AGESA_SUCCESS) { |
| 534 | return Status; |
| 535 | } |
| 536 | } |
| 537 | S3_SCRIPT_DEBUG_CODE ( |
| 538 | IDS_HDT_CONSOLE (S3_TRACE, " S3 Save: %s Function Id: 0x%02x, Context: ", S3SaveDebugOpcodeString (StdHeader, OpCode), FunctionId); |
| 539 | S3SaveDebugPrintHexArray (StdHeader, Context, ContextLength, AccessWidth8); |
| 540 | IDS_HDT_CONSOLE (S3_TRACE, "\n"); |
| 541 | ); |
| 542 | SaveOffsetPtr = (S3_DISPATCH_OP_HEADER *) ((UINT8 *) S3SaveTablePtr + S3SaveTablePtr->SaveOffset); |
| 543 | SaveOffsetPtr->OpCode = OpCode; |
| 544 | SaveOffsetPtr->Length = ContextLength; |
| 545 | SaveOffsetPtr->FunctionId = FunctionId; |
| 546 | LibAmdMemCopy ( |
| 547 | (UINT8 *) SaveOffsetPtr + sizeof (S3_DISPATCH_OP_HEADER), |
| 548 | Context, |
| 549 | ContextLength, |
| 550 | StdHeader |
| 551 | ); |
| 552 | |
| 553 | S3SaveTablePtr->SaveOffset += OpCodeLength; |
| 554 | return AGESA_SUCCESS; |
| 555 | } |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | /*----------------------------------------------------------------------------------------*/ |
| 561 | /** |
| 562 | * Save S3 debug support |
| 563 | * |
| 564 | * |
| 565 | * |
| 566 | * @param[in] StdHeader Pointer to standard header |
| 567 | * @param[in] Op Opcode |
| 568 | */ |
| 569 | CHAR8* |
| 570 | S3SaveDebugOpcodeString ( |
| 571 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 572 | IN UINT16 Op |
| 573 | ) |
| 574 | { |
| 575 | switch (Op) { |
| 576 | case SAVE_STATE_IO_WRITE_OPCODE: |
| 577 | return (CHAR8 *)"IO WR"; |
| 578 | case SAVE_STATE_IO_READ_WRITE_OPCODE: |
| 579 | return (CHAR8 *)"IO RD/WR"; |
| 580 | case SAVE_STATE_IO_POLL_OPCODE: |
| 581 | return (CHAR8 *)"IO POLL"; |
| 582 | case SAVE_STATE_MEM_WRITE_OPCODE: |
| 583 | return (CHAR8 *)"MEM WR"; |
| 584 | case SAVE_STATE_MEM_READ_WRITE_OPCODE: |
| 585 | return (CHAR8 *)"MEM RD/WR"; |
| 586 | case SAVE_STATE_MEM_POLL_OPCODE: |
| 587 | return (CHAR8 *)"MEM POLL"; |
| 588 | case SAVE_STATE_PCI_CONFIG_WRITE_OPCODE: |
| 589 | return (CHAR8 *)"PCI WR"; |
| 590 | case SAVE_STATE_PCI_CONFIG_READ_WRITE_OPCODE: |
| 591 | return (CHAR8 *)"PCI RD/WR"; |
| 592 | case SAVE_STATE_PCI_CONFIG_POLL_OPCODE: |
| 593 | return (CHAR8 *)"PCI POLL"; |
| 594 | case SAVE_STATE_STALL_OPCODE: |
| 595 | return (CHAR8 *)"STALL"; |
| 596 | case SAVE_STATE_DISPATCH_OPCODE: |
| 597 | return (CHAR8 *)"DISPATCH"; |
| 598 | default: |
| 599 | IDS_ERROR_TRAP; |
| 600 | } |
| 601 | return (CHAR8 *)"!!! Unrecognize opcode !!!"; |
| 602 | } |
| 603 | |
| 604 | |
| 605 | /*----------------------------------------------------------------------------------------*/ |
| 606 | /** |
| 607 | * Save S3 debug support |
| 608 | * |
| 609 | * |
| 610 | * |
| 611 | * @param[in] StdHeader Pointer to standard header |
| 612 | * @param[in] Array Array |
| 613 | * @param[in] Count Count of element in array |
| 614 | * @param[in] Width Array Element width |
| 615 | */ |
| 616 | VOID |
| 617 | S3SaveDebugPrintHexArray ( |
| 618 | IN AMD_CONFIG_PARAMS *StdHeader, |
Arthur Heymans | 8d3640d | 2022-05-16 12:27:36 +0200 | [diff] [blame^] | 619 | CONST IN VOID *Array, |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 620 | IN UINT32 Count, |
| 621 | IN ACCESS_WIDTH Width |
| 622 | ) |
| 623 | { |
| 624 | UINTN Index; |
| 625 | |
| 626 | for (Index = 0; Index < Count; Index++) { |
| 627 | switch (Width) { |
| 628 | case AccessWidth8: |
| 629 | case AccessS3SaveWidth8: |
| 630 | IDS_HDT_CONSOLE (S3_TRACE, "0x%02x", *((UINT8*)Array + Index)); |
| 631 | break; |
| 632 | case AccessWidth16: |
| 633 | case AccessS3SaveWidth16: |
| 634 | IDS_HDT_CONSOLE (S3_TRACE, "0x%04x", *((UINT16*)Array + Index)); |
| 635 | break; |
| 636 | case AccessWidth32: |
| 637 | case AccessS3SaveWidth32: |
| 638 | IDS_HDT_CONSOLE (S3_TRACE, "0x%08x", *((UINT32*)Array + Index)); |
| 639 | break; |
| 640 | case AccessWidth64: |
| 641 | case AccessS3SaveWidth64: |
| 642 | //IDS_HDT_CONSOLE (S3_TRACE, "0x%08x%08x", ((UINT32*) ((UINT64*)Array + Index)[1], ((UINT32*) ((UINT64*)Array + Index))[0])); |
| 643 | break; |
| 644 | default: |
| 645 | IDS_ERROR_TRAP; |
| 646 | } |
| 647 | if (Index < (Count - 1)) { |
| 648 | IDS_HDT_CONSOLE (S3_TRACE, ", "); |
| 649 | } |
| 650 | } |
| 651 | } |