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