]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptExecute.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Library / PiDxeS3BootScriptLib / BootScriptExecute.c
CommitLineData
64d14edf 1/** @file\r
3a03e95e 2 Interpret and execute the S3 data in S3 boot script.\r
64d14edf 3\r
3d20524a 4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
64d14edf 5\r
9d510e61 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
64d14edf 7\r
8**/\r
9#include "InternalBootScriptLib.h"\r
10\r
64d14edf 11/**\r
12 Executes an SMBus operation to an SMBus controller. Returns when either the command has been\r
13 executed or an error is encountered in doing the operation.\r
14\r
15 The SmbusExecute() function provides a standard way to execute an operation as defined in the System\r
16 Management Bus (SMBus) Specification. The resulting transaction will be either that the SMBus\r
17 slave devices accept this transaction or that this function returns with error.\r
18\r
3a03e95e 19 @param SmbusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length,\r
64d14edf 20 and PEC.\r
21 @param Operation Signifies which particular SMBus hardware protocol instance that\r
22 it will use to execute the SMBus transactions. This SMBus\r
23 hardware protocol is defined by the SMBus Specification and is\r
24 not related to EFI.\r
25 @param Length Signifies the number of bytes that this operation will do. The\r
26 maximum number of bytes can be revision specific and operation\r
27 specific. This field will contain the actual number of bytes that\r
28 are executed for this operation. Not all operations require this\r
29 argument.\r
30 @param Buffer Contains the value of data to execute to the SMBus slave device.\r
31 Not all operations require this argument. The length of this\r
32 buffer is identified by Length.\r
33\r
34 @retval EFI_SUCCESS The last data that was returned from the access matched the poll\r
35 exit criteria.\r
36 @retval EFI_CRC_ERROR Checksum is not correct (PEC is incorrect).\r
37 @retval EFI_TIMEOUT Timeout expired before the operation was completed. Timeout is\r
38 determined by the SMBus host controller device.\r
39 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
40 @retval EFI_DEVICE_ERROR The request was not completed because a failure that was\r
41 reflected in the Host Status Register bit. Device errors are a\r
42 result of a transaction collision, illegal command field,\r
43 unclaimed cycle (host initiated), or bus errors (collisions).\r
44 @retval EFI_INVALID_PARAMETER Operation is not defined in EFI_SMBUS_OPERATION.\r
45 @retval EFI_INVALID_PARAMETER Length/Buffer is NULL for operations except for EfiSmbusQuickRead\r
46 and EfiSmbusQuickWrite. Length is outside the range of valid\r
47 values.\r
48 @retval EFI_UNSUPPORTED The SMBus operation or PEC is not supported.\r
49 @retval EFI_BUFFER_TOO_SMALL Buffer is not sufficient for this operation.\r
50\r
51**/\r
52EFI_STATUS\r
5f56b0ff 53InternalSmbusExecute (\r
1436aea4
MK
54 IN UINTN SmbusAddress,\r
55 IN EFI_SMBUS_OPERATION Operation,\r
56 IN OUT UINTN *Length,\r
57 IN OUT VOID *Buffer\r
64d14edf 58 )\r
59{\r
1436aea4
MK
60 EFI_STATUS Status;\r
61 UINT8 WorkBuffer[MAX_SMBUS_BLOCK_LEN];\r
64d14edf 62\r
64d14edf 63 switch (Operation) {\r
64 case EfiSmbusQuickRead:\r
87000d77 65 DEBUG ((DEBUG_INFO, "EfiSmbusQuickRead - 0x%08x\n", SmbusAddress));\r
64d14edf 66 SmBusQuickRead (SmbusAddress, &Status);\r
67 break;\r
68 case EfiSmbusQuickWrite:\r
87000d77 69 DEBUG ((DEBUG_INFO, "EfiSmbusQuickWrite - 0x%08x\n", SmbusAddress));\r
64d14edf 70 SmBusQuickWrite (SmbusAddress, &Status);\r
71 break;\r
72 case EfiSmbusReceiveByte:\r
87000d77 73 DEBUG ((DEBUG_INFO, "EfiSmbusReceiveByte - 0x%08x\n", SmbusAddress));\r
2a956f74 74 SmBusReceiveByte (SmbusAddress, &Status);\r
64d14edf 75 break;\r
76 case EfiSmbusSendByte:\r
1436aea4
MK
77 DEBUG ((DEBUG_INFO, "EfiSmbusSendByte - 0x%08x (0x%02x)\n", SmbusAddress, (UINTN)*(UINT8 *)Buffer));\r
78 SmBusSendByte (SmbusAddress, *(UINT8 *)Buffer, &Status);\r
64d14edf 79 break;\r
80 case EfiSmbusReadByte:\r
87000d77 81 DEBUG ((DEBUG_INFO, "EfiSmbusReadByte - 0x%08x\n", SmbusAddress));\r
2a956f74 82 SmBusReadDataByte (SmbusAddress, &Status);\r
64d14edf 83 break;\r
84 case EfiSmbusWriteByte:\r
1436aea4
MK
85 DEBUG ((DEBUG_INFO, "EfiSmbusWriteByte - 0x%08x (0x%02x)\n", SmbusAddress, (UINTN)*(UINT8 *)Buffer));\r
86 SmBusWriteDataByte (SmbusAddress, *(UINT8 *)Buffer, &Status);\r
64d14edf 87 break;\r
88 case EfiSmbusReadWord:\r
87000d77 89 DEBUG ((DEBUG_INFO, "EfiSmbusReadWord - 0x%08x\n", SmbusAddress));\r
2a956f74 90 SmBusReadDataWord (SmbusAddress, &Status);\r
64d14edf 91 break;\r
92 case EfiSmbusWriteWord:\r
1436aea4
MK
93 DEBUG ((DEBUG_INFO, "EfiSmbusWriteWord - 0x%08x (0x%04x)\n", SmbusAddress, (UINTN)*(UINT16 *)Buffer));\r
94 SmBusWriteDataWord (SmbusAddress, *(UINT16 *)Buffer, &Status);\r
64d14edf 95 break;\r
96 case EfiSmbusProcessCall:\r
1436aea4
MK
97 DEBUG ((DEBUG_INFO, "EfiSmbusProcessCall - 0x%08x (0x%04x)\n", SmbusAddress, (UINTN)*(UINT16 *)Buffer));\r
98 SmBusProcessCall (SmbusAddress, *(UINT16 *)Buffer, &Status);\r
64d14edf 99 break;\r
100 case EfiSmbusReadBlock:\r
87000d77 101 DEBUG ((DEBUG_INFO, "EfiSmbusReadBlock - 0x%08x\n", SmbusAddress));\r
2a956f74 102 SmBusReadBlock (SmbusAddress, WorkBuffer, &Status);\r
64d14edf 103 break;\r
104 case EfiSmbusWriteBlock:\r
87000d77 105 DEBUG ((DEBUG_INFO, "EfiSmbusWriteBlock - 0x%08x\n", SmbusAddress));\r
2a956f74 106 SmBusWriteBlock ((SmbusAddress + SMBUS_LIB_ADDRESS (0, 0, (*Length), FALSE)), Buffer, &Status);\r
64d14edf 107 break;\r
108 case EfiSmbusBWBRProcessCall:\r
87000d77 109 DEBUG ((DEBUG_INFO, "EfiSmbusBWBRProcessCall - 0x%08x\n", SmbusAddress));\r
2a956f74 110 SmBusBlockProcessCall ((SmbusAddress + SMBUS_LIB_ADDRESS (0, 0, (*Length), FALSE)), Buffer, WorkBuffer, &Status);\r
64d14edf 111 break;\r
2a956f74
SZ
112 default:\r
113 return EFI_INVALID_PARAMETER;\r
64d14edf 114 }\r
115\r
3a03e95e 116 return Status;\r
64d14edf 117}\r
118\r
119/**\r
120 Translates boot script width and address stride to MDE library interface.\r
121\r
122\r
123 @param Width Width of the operation.\r
124 @param Address Address of the operation.\r
125 @param AddressStride Instride for stepping input buffer.\r
3a03e95e 126 @param BufferStride Outstride for stepping output buffer.\r
64d14edf 127\r
128 @retval EFI_SUCCESS Successful translation.\r
129 @retval EFI_INVALID_PARAMETER Width or Address is invalid.\r
130**/\r
131EFI_STATUS\r
132BuildLoopData (\r
1436aea4 133 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r
64d14edf 134 IN UINT64 Address,\r
135 OUT UINTN *AddressStride,\r
136 OUT UINTN *BufferStride\r
137 )\r
138{\r
1436aea4 139 UINTN AlignMask;\r
64d14edf 140\r
141 if (Width >= S3BootScriptWidthMaximum) {\r
142 return EFI_INVALID_PARAMETER;\r
143 }\r
144\r
1436aea4
MK
145 *AddressStride = (UINT32)(1 << (Width & 0x03));\r
146 *BufferStride = *AddressStride;\r
64d14edf 147\r
1436aea4 148 AlignMask = *AddressStride - 1;\r
64d14edf 149 if ((Address & AlignMask) != 0) {\r
150 return EFI_INVALID_PARAMETER;\r
151 }\r
152\r
1436aea4 153 if ((Width >= S3BootScriptWidthFifoUint8) && (Width <= S3BootScriptWidthFifoUint64)) {\r
64d14edf 154 *AddressStride = 0;\r
155 }\r
156\r
1436aea4 157 if ((Width >= S3BootScriptWidthFillUint8) && (Width <= S3BootScriptWidthFillUint64)) {\r
64d14edf 158 *BufferStride = 0;\r
159 }\r
160\r
161 return EFI_SUCCESS;\r
162}\r
163\r
164/**\r
30f80497 165 Perform IO read operation\r
3a03e95e 166\r
64d14edf 167 @param[in] Width Width of the operation.\r
168 @param[in] Address Address of the operation.\r
169 @param[in] Count Count of the number of accesses to perform.\r
3a03e95e 170 @param[out] Buffer Pointer to the buffer to read from I/O space.\r
64d14edf 171\r
172 @retval EFI_SUCCESS The data was written to the EFI System.\r
173 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.\r
174 Buffer is NULL.\r
175 The Buffer is not aligned for the given Width.\r
3a03e95e
SZ
176 Address is outside the legal range of I/O ports.\r
177\r
64d14edf 178**/\r
179EFI_STATUS\r
180ScriptIoRead (\r
1436aea4
MK
181 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r
182 IN UINT64 Address,\r
183 IN UINTN Count,\r
184 OUT VOID *Buffer\r
64d14edf 185 )\r
186{\r
187 EFI_STATUS Status;\r
188 UINTN AddressStride;\r
189 UINTN BufferStride;\r
190 PTR Out;\r
191\r
1436aea4 192 Out.Buf = (UINT8 *)Buffer;\r
64d14edf 193\r
194 if (Address > MAX_IO_ADDRESS) {\r
195 return EFI_INVALID_PARAMETER;\r
196 }\r
197\r
198 Status = BuildLoopData (Width, Address, &AddressStride, &BufferStride);\r
199 if (EFI_ERROR (Status)) {\r
200 return Status;\r
201 }\r
1436aea4 202\r
64d14edf 203 //\r
204 // Loop for each iteration and move the data\r
205 //\r
1436aea4 206 for ( ; Count > 0; Count--, Address += AddressStride, Out.Buf += BufferStride) {\r
64d14edf 207 switch (Width) {\r
1436aea4
MK
208 case S3BootScriptWidthUint8:\r
209 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint8 - 0x%08x\n", (UINTN)Address));\r
210 *Out.Uint8 = IoRead8 ((UINTN)Address);\r
211 break;\r
212 case S3BootScriptWidthFifoUint8:\r
213 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x\n", (UINTN)Address));\r
214 *Out.Uint8 = IoRead8 ((UINTN)Address);\r
215 break;\r
216 case S3BootScriptWidthFillUint8:\r
217 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint8 - 0x%08x\n", (UINTN)Address));\r
218 *Out.Uint8 = IoRead8 ((UINTN)Address);\r
219 break;\r
64d14edf 220\r
1436aea4
MK
221 case S3BootScriptWidthUint16:\r
222 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint16 - 0x%08x\n", (UINTN)Address));\r
223 *Out.Uint16 = IoRead16 ((UINTN)Address);\r
224 break;\r
225 case S3BootScriptWidthFifoUint16:\r
226 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x\n", (UINTN)Address));\r
227 *Out.Uint16 = IoRead16 ((UINTN)Address);\r
228 break;\r
229 case S3BootScriptWidthFillUint16:\r
230 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint16 - 0x%08x\n", (UINTN)Address));\r
231 *Out.Uint16 = IoRead16 ((UINTN)Address);\r
232 break;\r
64d14edf 233\r
1436aea4
MK
234 case S3BootScriptWidthUint32:\r
235 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint32 - 0x%08x\n", (UINTN)Address));\r
236 *Out.Uint32 = IoRead32 ((UINTN)Address);\r
237 break;\r
238 case S3BootScriptWidthFifoUint32:\r
239 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x\n", (UINTN)Address));\r
240 *Out.Uint32 = IoRead32 ((UINTN)Address);\r
241 break;\r
242 case S3BootScriptWidthFillUint32:\r
243 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint32 - 0x%08x\n", (UINTN)Address));\r
244 *Out.Uint32 = IoRead32 ((UINTN)Address);\r
245 break;\r
64d14edf 246\r
1436aea4
MK
247 case S3BootScriptWidthUint64:\r
248 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint64 - 0x%08x\n", (UINTN)Address));\r
249 *Out.Uint64 = IoRead64 ((UINTN)Address);\r
250 break;\r
251 case S3BootScriptWidthFifoUint64:\r
252 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint64 - 0x%08x\n", (UINTN)Address));\r
253 *Out.Uint64 = IoRead64 ((UINTN)Address);\r
254 break;\r
255 case S3BootScriptWidthFillUint64:\r
256 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint64 - 0x%08x\n", (UINTN)Address));\r
257 *Out.Uint64 = IoRead64 ((UINTN)Address);\r
258 break;\r
30f80497 259\r
1436aea4
MK
260 default:\r
261 return EFI_INVALID_PARAMETER;\r
64d14edf 262 }\r
263 }\r
264\r
265 return EFI_SUCCESS;\r
266}\r
267\r
268/**\r
30f80497 269 Perform IO write operation\r
3a03e95e 270\r
64d14edf 271 @param[in] Width Width of the operation.\r
272 @param[in] Address Address of the operation.\r
273 @param[in] Count Count of the number of accesses to perform.\r
3a03e95e 274 @param[in] Buffer Pointer to the buffer to write to I/O space.\r
64d14edf 275\r
276 @retval EFI_SUCCESS The data was written to the EFI System.\r
277 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.\r
278 Buffer is NULL.\r
279 The Buffer is not aligned for the given Width.\r
3a03e95e
SZ
280 Address is outside the legal range of I/O ports.\r
281\r
64d14edf 282**/\r
283EFI_STATUS\r
284ScriptIoWrite (\r
285 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r
1436aea4
MK
286 IN UINT64 Address,\r
287 IN UINTN Count,\r
288 IN VOID *Buffer\r
64d14edf 289 )\r
290{\r
291 EFI_STATUS Status;\r
292 UINTN AddressStride;\r
293 UINTN BufferStride;\r
294 UINT64 OriginalAddress;\r
295 PTR In;\r
296 PTR OriginalIn;\r
297\r
1436aea4 298 In.Buf = (UINT8 *)Buffer;\r
64d14edf 299\r
300 if (Address > MAX_IO_ADDRESS) {\r
301 return EFI_INVALID_PARAMETER;\r
302 }\r
303\r
304 Status = BuildLoopData (Width, Address, &AddressStride, &BufferStride);\r
305 if (EFI_ERROR (Status)) {\r
306 return Status;\r
307 }\r
1436aea4 308\r
64d14edf 309 //\r
310 // Loop for each iteration and move the data\r
311 //\r
312 OriginalAddress = Address;\r
1436aea4
MK
313 OriginalIn.Buf = In.Buf;\r
314 for ( ; Count > 0; Count--, Address += AddressStride, In.Buf += BufferStride) {\r
64d14edf 315 switch (Width) {\r
316 case S3BootScriptWidthUint8:\r
87000d77 317 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint8 - 0x%08x (0x%02x)\n", (UINTN)Address, (UINTN)*In.Uint8));\r
1436aea4 318 IoWrite8 ((UINTN)Address, *In.Uint8);\r
3a03e95e 319 break;\r
64d14edf 320 case S3BootScriptWidthFifoUint8:\r
87000d77 321 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x (0x%02x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint8));\r
1436aea4 322 IoWrite8 ((UINTN)OriginalAddress, *In.Uint8);\r
3a03e95e 323 break;\r
64d14edf 324 case S3BootScriptWidthFillUint8:\r
87000d77 325 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint8 - 0x%08x (0x%02x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint8));\r
1436aea4 326 IoWrite8 ((UINTN)Address, *OriginalIn.Uint8);\r
64d14edf 327 break;\r
328 case S3BootScriptWidthUint16:\r
87000d77 329 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint16 - 0x%08x (0x%04x)\n", (UINTN)Address, (UINTN)*In.Uint16));\r
1436aea4 330 IoWrite16 ((UINTN)Address, *In.Uint16);\r
3a03e95e 331 break;\r
64d14edf 332 case S3BootScriptWidthFifoUint16:\r
87000d77 333 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x (0x%04x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint16));\r
1436aea4 334 IoWrite16 ((UINTN)OriginalAddress, *In.Uint16);\r
3a03e95e 335 break;\r
64d14edf 336 case S3BootScriptWidthFillUint16:\r
87000d77 337 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint16 - 0x%08x (0x%04x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint16));\r
1436aea4 338 IoWrite16 ((UINTN)Address, *OriginalIn.Uint16);\r
64d14edf 339 break;\r
340 case S3BootScriptWidthUint32:\r
87000d77 341 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint32 - 0x%08x (0x%08x)\n", (UINTN)Address, (UINTN)*In.Uint32));\r
1436aea4 342 IoWrite32 ((UINTN)Address, *In.Uint32);\r
3a03e95e 343 break;\r
64d14edf 344 case S3BootScriptWidthFifoUint32:\r
87000d77 345 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x (0x%08x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint32));\r
1436aea4 346 IoWrite32 ((UINTN)OriginalAddress, *In.Uint32);\r
64d14edf 347 break;\r
348 case S3BootScriptWidthFillUint32:\r
87000d77 349 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint32 - 0x%08x (0x%08x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint32));\r
1436aea4 350 IoWrite32 ((UINTN)Address, *OriginalIn.Uint32);\r
64d14edf 351 break;\r
352 case S3BootScriptWidthUint64:\r
87000d77 353 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint64 - 0x%08x (0x%016lx)\n", (UINTN)Address, *In.Uint64));\r
1436aea4 354 IoWrite64 ((UINTN)Address, *In.Uint64);\r
3a03e95e 355 break;\r
64d14edf 356 case S3BootScriptWidthFifoUint64:\r
87000d77 357 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint64 - 0x%08x (0x%016lx)\n", (UINTN)OriginalAddress, *In.Uint64));\r
1436aea4 358 IoWrite64 ((UINTN)OriginalAddress, *In.Uint64);\r
3a03e95e 359 break;\r
64d14edf 360 case S3BootScriptWidthFillUint64:\r
87000d77 361 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint64 - 0x%08x (0x%016lx)\n", (UINTN)Address, *OriginalIn.Uint64));\r
1436aea4 362 IoWrite64 ((UINTN)Address, *OriginalIn.Uint64);\r
64d14edf 363 break;\r
364 default:\r
365 return EFI_INVALID_PARAMETER;\r
366 }\r
367 }\r
3a03e95e 368\r
64d14edf 369 return EFI_SUCCESS;\r
370}\r
1436aea4 371\r
64d14edf 372/**\r
e0cb5e18 373 Interpret the boot script node with EFI_BOOT_SCRIPT_IO_WRITE OP code.\r
3a03e95e 374\r
64d14edf 375 @param Script Pointer to the node which is to be interpreted.\r
376\r
377 @retval EFI_SUCCESS The data was written to the EFI System.\r
378 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.\r
379 Buffer is NULL.\r
380 The Buffer is not aligned for the given Width.\r
3a03e95e
SZ
381 Address is outside the legal range of I/O ports.\r
382\r
64d14edf 383**/\r
384EFI_STATUS\r
385BootScriptExecuteIoWrite (\r
1436aea4 386 IN UINT8 *Script\r
64d14edf 387 )\r
388{\r
1436aea4
MK
389 S3_BOOT_SCRIPT_LIB_WIDTH Width;\r
390 UINT64 Address;\r
391 UINTN Count;\r
64d14edf 392 VOID *Buffer;\r
1436aea4 393 EFI_BOOT_SCRIPT_IO_WRITE IoWrite;\r
3a03e95e 394\r
1436aea4
MK
395 CopyMem ((VOID *)&IoWrite, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_IO_WRITE));\r
396 Width = (S3_BOOT_SCRIPT_LIB_WIDTH)IoWrite.Width;\r
64d14edf 397 Address = IoWrite.Address;\r
1436aea4
MK
398 Count = IoWrite.Count;\r
399 Buffer = Script + sizeof (EFI_BOOT_SCRIPT_IO_WRITE);\r
30f80497 400\r
87000d77 401 DEBUG ((DEBUG_INFO, "BootScriptExecuteIoWrite - 0x%08x, 0x%08x, 0x%08x\n", (UINTN)Address, Count, (UINTN)Width));\r
1436aea4 402 return ScriptIoWrite (Width, Address, Count, Buffer);\r
64d14edf 403}\r
1436aea4 404\r
64d14edf 405/**\r
406 Perform memory read operation\r
3a03e95e 407\r
64d14edf 408 @param Width Width of the operation.\r
409 @param Address Address of the operation.\r
410 @param Count Count of the number of accesses to perform.\r
3a03e95e 411 @param Buffer Pointer to the buffer read from memory.\r
64d14edf 412\r
413 @retval EFI_SUCCESS The data was written to the EFI System.\r
414 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.\r
415 Buffer is NULL.\r
416 The Buffer is not aligned for the given Width.\r
3a03e95e
SZ
417 @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count\r
418 is not valid for this EFI System.\r
419\r
64d14edf 420**/\r
421EFI_STATUS\r
422ScriptMemoryRead (\r
1436aea4
MK
423 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r
424 IN UINT64 Address,\r
425 IN UINTN Count,\r
426 IN OUT VOID *Buffer\r
64d14edf 427 )\r
428{\r
429 EFI_STATUS Status;\r
430 UINTN AddressStride;\r
431 UINTN BufferStride;\r
432 PTR Out;\r
433\r
434 Out.Buf = Buffer;\r
435\r
1436aea4 436 Status = BuildLoopData (Width, Address, &AddressStride, &BufferStride);\r
64d14edf 437 if (EFI_ERROR (Status)) {\r
438 return Status;\r
439 }\r
1436aea4 440\r
64d14edf 441 //\r
442 // Loop for each iteration and move the data\r
443 //\r
1436aea4 444 for ( ; Count > 0; Count--, Address += AddressStride, Out.Buf += BufferStride) {\r
64d14edf 445 switch (Width) {\r
1436aea4
MK
446 case S3BootScriptWidthUint8:\r
447 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint8 - 0x%08x\n", (UINTN)Address));\r
448 *Out.Uint8 = MmioRead8 ((UINTN)Address);\r
449 break;\r
450 case S3BootScriptWidthFifoUint8:\r
451 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x\n", (UINTN)Address));\r
452 *Out.Uint8 = MmioRead8 ((UINTN)Address);\r
453 break;\r
454 case S3BootScriptWidthFillUint8:\r
455 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint8 - 0x%08x\n", (UINTN)Address));\r
456 *Out.Uint8 = MmioRead8 ((UINTN)Address);\r
457 break;\r
64d14edf 458\r
1436aea4
MK
459 case S3BootScriptWidthUint16:\r
460 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint16 - 0x%08x\n", (UINTN)Address));\r
461 *Out.Uint16 = MmioRead16 ((UINTN)Address);\r
462 break;\r
463 case S3BootScriptWidthFifoUint16:\r
464 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x\n", (UINTN)Address));\r
465 *Out.Uint16 = MmioRead16 ((UINTN)Address);\r
466 break;\r
467 case S3BootScriptWidthFillUint16:\r
468 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint16 - 0x%08x\n", (UINTN)Address));\r
469 *Out.Uint16 = MmioRead16 ((UINTN)Address);\r
470 break;\r
64d14edf 471\r
1436aea4
MK
472 case S3BootScriptWidthUint32:\r
473 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint32 - 0x%08x\n", (UINTN)Address));\r
474 *Out.Uint32 = MmioRead32 ((UINTN)Address);\r
475 break;\r
476 case S3BootScriptWidthFifoUint32:\r
477 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x\n", (UINTN)Address));\r
478 *Out.Uint32 = MmioRead32 ((UINTN)Address);\r
479 break;\r
480 case S3BootScriptWidthFillUint32:\r
481 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint32 - 0x%08x\n", (UINTN)Address));\r
482 *Out.Uint32 = MmioRead32 ((UINTN)Address);\r
483 break;\r
64d14edf 484\r
1436aea4
MK
485 case S3BootScriptWidthUint64:\r
486 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint64 - 0x%08x\n", (UINTN)Address));\r
487 *Out.Uint64 = MmioRead64 ((UINTN)Address);\r
488 break;\r
489 case S3BootScriptWidthFifoUint64:\r
490 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint64 - 0x%08x\n", (UINTN)Address));\r
491 *Out.Uint64 = MmioRead64 ((UINTN)Address);\r
492 break;\r
493 case S3BootScriptWidthFillUint64:\r
494 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint64 - 0x%08x\n", (UINTN)Address));\r
495 *Out.Uint64 = MmioRead64 ((UINTN)Address);\r
496 break;\r
64d14edf 497\r
1436aea4
MK
498 default:\r
499 return EFI_UNSUPPORTED;\r
64d14edf 500 }\r
501 }\r
502\r
503 return EFI_SUCCESS;\r
504}\r
1436aea4 505\r
64d14edf 506/**\r
30f80497 507 Perform memory write operation\r
3a03e95e 508\r
64d14edf 509 @param Width Width of the operation.\r
510 @param Address Address of the operation.\r
511 @param Count Count of the number of accesses to perform.\r
3a03e95e 512 @param Buffer Pointer to the buffer write to memory.\r
64d14edf 513\r
514 @retval EFI_SUCCESS The data was written to the EFI System.\r
515 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.\r
516 Buffer is NULL.\r
517 The Buffer is not aligned for the given Width.\r
3a03e95e
SZ
518 @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count\r
519 is not valid for this EFI System.\r
520\r
64d14edf 521**/\r
522EFI_STATUS\r
523ScriptMemoryWrite (\r
1436aea4
MK
524 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r
525 IN UINT64 Address,\r
526 IN UINTN Count,\r
527 IN OUT VOID *Buffer\r
64d14edf 528 )\r
529{\r
530 EFI_STATUS Status;\r
531 UINTN AddressStride;\r
3a03e95e 532 UINT64 OriginalAddress;\r
64d14edf 533 UINTN BufferStride;\r
534 PTR In;\r
535 PTR OriginalIn;\r
536\r
1436aea4 537 In.Buf = Buffer;\r
64d14edf 538\r
1436aea4 539 Status = BuildLoopData (Width, Address, &AddressStride, &BufferStride);\r
64d14edf 540 if (EFI_ERROR (Status)) {\r
541 return Status;\r
542 }\r
1436aea4 543\r
64d14edf 544 //\r
545 // Loop for each iteration and move the data\r
546 //\r
547 OriginalAddress = Address;\r
1436aea4
MK
548 OriginalIn.Buf = In.Buf;\r
549 for ( ; Count > 0; Count--, Address += AddressStride, In.Buf += BufferStride) {\r
64d14edf 550 switch (Width) {\r
551 case S3BootScriptWidthUint8:\r
87000d77 552 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint8 - 0x%08x (0x%02x)\n", (UINTN)Address, (UINTN)*In.Uint8));\r
1436aea4 553 MmioWrite8 ((UINTN)Address, *In.Uint8);\r
3a03e95e 554 break;\r
64d14edf 555 case S3BootScriptWidthFifoUint8:\r
87000d77 556 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint8 - 0x%08x (0x%02x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint8));\r
1436aea4 557 MmioWrite8 ((UINTN)OriginalAddress, *In.Uint8);\r
3a03e95e 558 break;\r
64d14edf 559 case S3BootScriptWidthFillUint8:\r
87000d77 560 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint8 - 0x%08x (0x%02x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint8));\r
1436aea4 561 MmioWrite8 ((UINTN)Address, *OriginalIn.Uint8);\r
64d14edf 562 break;\r
563 case S3BootScriptWidthUint16:\r
87000d77 564 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint16 - 0x%08x (0x%04x)\n", (UINTN)Address, (UINTN)*In.Uint16));\r
1436aea4 565 MmioWrite16 ((UINTN)Address, *In.Uint16);\r
3a03e95e 566 break;\r
64d14edf 567 case S3BootScriptWidthFifoUint16:\r
87000d77 568 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint16 - 0x%08x (0x%04x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint16));\r
1436aea4 569 MmioWrite16 ((UINTN)OriginalAddress, *In.Uint16);\r
3a03e95e 570 break;\r
64d14edf 571 case S3BootScriptWidthFillUint16:\r
87000d77 572 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint16 - 0x%08x (0x%04x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint16));\r
1436aea4 573 MmioWrite16 ((UINTN)Address, *OriginalIn.Uint16);\r
64d14edf 574 break;\r
575 case S3BootScriptWidthUint32:\r
87000d77 576 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint32 - 0x%08x (0x%08x)\n", (UINTN)Address, (UINTN)*In.Uint32));\r
1436aea4 577 MmioWrite32 ((UINTN)Address, *In.Uint32);\r
3a03e95e 578 break;\r
64d14edf 579 case S3BootScriptWidthFifoUint32:\r
87000d77 580 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint32 - 0x%08x (0x%08x)\n", (UINTN)OriginalAddress, (UINTN)*In.Uint32));\r
1436aea4 581 MmioWrite32 ((UINTN)OriginalAddress, *In.Uint32);\r
3a03e95e 582 break;\r
64d14edf 583 case S3BootScriptWidthFillUint32:\r
87000d77 584 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint32 - 0x%08x (0x%08x)\n", (UINTN)Address, (UINTN)*OriginalIn.Uint32));\r
1436aea4 585 MmioWrite32 ((UINTN)Address, *OriginalIn.Uint32);\r
64d14edf 586 break;\r
587 case S3BootScriptWidthUint64:\r
87000d77 588 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint64 - 0x%08x (0x%016lx)\n", (UINTN)Address, *In.Uint64));\r
1436aea4 589 MmioWrite64 ((UINTN)Address, *In.Uint64);\r
3a03e95e 590 break;\r
64d14edf 591 case S3BootScriptWidthFifoUint64:\r
87000d77 592 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint64 - 0x%08x (0x%016lx)\n", (UINTN)OriginalAddress, *In.Uint64));\r
1436aea4 593 MmioWrite64 ((UINTN)OriginalAddress, *In.Uint64);\r
3a03e95e 594 break;\r
64d14edf 595 case S3BootScriptWidthFillUint64:\r
87000d77 596 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint64 - 0x%08x (0x%016lx)\n", (UINTN)Address, *OriginalIn.Uint64));\r
1436aea4 597 MmioWrite64 ((UINTN)Address, *OriginalIn.Uint64);\r
64d14edf 598 break;\r
599 default:\r
600 return EFI_UNSUPPORTED;\r
601 }\r
602 }\r
1436aea4 603\r
64d14edf 604 return EFI_SUCCESS;\r
605}\r
1436aea4 606\r
64d14edf 607/**\r
e0cb5e18 608 Interpret the boot script node with EFI_BOOT_SCRIPT_MEM_WRITE OP code.\r
64d14edf 609\r
610 @param[in] Script Pointer to the node which is to be interpreted.\r
3a03e95e 611\r
64d14edf 612 @retval EFI_SUCCESS The data was written to the EFI System.\r
613 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.\r
614 Buffer is NULL.\r
615 The Buffer is not aligned for the given Width.\r
3a03e95e
SZ
616 @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count\r
617 is not valid for this EFI System.\r
618\r
64d14edf 619**/\r
620EFI_STATUS\r
621BootScriptExecuteMemoryWrite (\r
1436aea4 622 IN UINT8 *Script\r
64d14edf 623 )\r
624{\r
1436aea4
MK
625 VOID *Buffer;\r
626 S3_BOOT_SCRIPT_LIB_WIDTH Width;\r
627 UINT64 Address;\r
628 UINTN Count;\r
64d14edf 629 EFI_BOOT_SCRIPT_MEM_WRITE MemWrite;\r
3a03e95e 630\r
1436aea4 631 CopyMem ((VOID *)&MemWrite, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_MEM_WRITE));\r
64d14edf 632 Width = (S3_BOOT_SCRIPT_LIB_WIDTH)MemWrite.Width;\r
633 Address = MemWrite.Address;\r
634 Count = MemWrite.Count;\r
1436aea4 635 Buffer = Script + sizeof (EFI_BOOT_SCRIPT_MEM_WRITE);\r
64d14edf 636\r
87000d77 637 DEBUG ((DEBUG_INFO, "BootScriptExecuteMemoryWrite - 0x%08x, 0x%08x, 0x%08x\n", (UINTN)Address, Count, (UINTN)Width));\r
1436aea4 638 return ScriptMemoryWrite (Width, Address, Count, Buffer);\r
3a03e95e 639}\r
1436aea4 640\r
64d14edf 641/**\r
3d20524a 642 Performance PCI configuration 2 read operation\r
64d14edf 643\r
644 @param Width Width of the operation.\r
3d20524a 645 @param Segment Pci segment number\r
64d14edf 646 @param Address Address of the operation.\r
30f80497
SZ
647 @param Count Count of the number of accesses to perform.\r
648 @param Buffer Pointer to the buffer read from PCI config space\r
3a03e95e 649\r
64d14edf 650 @retval EFI_SUCCESS The read succeed.\r
3a03e95e 651 @retval EFI_INVALID_PARAMETER if Width is not defined\r
2a956f74
SZ
652 @note A known Limitations in the implementation which is 64bits operations are not supported.\r
653\r
64d14edf 654**/\r
655EFI_STATUS\r
3d20524a 656ScriptPciCfg2Read (\r
1436aea4
MK
657 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r
658 IN UINT16 Segment,\r
659 IN UINT64 Address,\r
660 IN UINTN Count,\r
661 OUT VOID *Buffer\r
64d14edf 662 )\r
663{\r
30f80497
SZ
664 EFI_STATUS Status;\r
665 UINTN AddressStride;\r
666 UINTN BufferStride;\r
667 PTR Out;\r
3d20524a 668 UINT64 PciAddress;\r
30f80497 669\r
1436aea4 670 Out.Buf = (UINT8 *)Buffer;\r
30f80497 671\r
3d20524a 672 PciAddress = PCI_ADDRESS_ENCODE (Segment, Address);\r
30f80497
SZ
673\r
674 Status = BuildLoopData (Width, PciAddress, &AddressStride, &BufferStride);\r
675 if (EFI_ERROR (Status)) {\r
676 return Status;\r
677 }\r
1436aea4 678\r
30f80497
SZ
679 //\r
680 // Loop for each iteration and move the data\r
681 //\r
1436aea4 682 for ( ; Count > 0; Count--, PciAddress += AddressStride, Out.Buf += BufferStride) {\r
64d14edf 683 switch (Width) {\r
1436aea4
MK
684 case S3BootScriptWidthUint8:\r
685 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint8 - 0x%016lx\n", PciAddress));\r
686 *Out.Uint8 = PciSegmentRead8 (PciAddress);\r
687 break;\r
688 case S3BootScriptWidthFifoUint8:\r
689 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint8 - 0x%016lx\n", PciAddress));\r
690 *Out.Uint8 = PciSegmentRead8 (PciAddress);\r
691 break;\r
692 case S3BootScriptWidthFillUint8:\r
693 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint8 - 0x%016lx\n", PciAddress));\r
694 *Out.Uint8 = PciSegmentRead8 (PciAddress);\r
695 break;\r
64d14edf 696\r
1436aea4
MK
697 case S3BootScriptWidthUint16:\r
698 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint16 - 0x%016lx\n", PciAddress));\r
699 *Out.Uint16 = PciSegmentRead16 (PciAddress);\r
700 break;\r
701 case S3BootScriptWidthFifoUint16:\r
702 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint16 - 0x%016lx\n", PciAddress));\r
703 *Out.Uint16 = PciSegmentRead16 (PciAddress);\r
704 break;\r
705 case S3BootScriptWidthFillUint16:\r
706 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint16 - 0x%016lx\n", PciAddress));\r
707 *Out.Uint16 = PciSegmentRead16 (PciAddress);\r
708 break;\r
64d14edf 709\r
1436aea4
MK
710 case S3BootScriptWidthUint32:\r
711 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint32 - 0x%016lx\n", PciAddress));\r
712 *Out.Uint32 = PciSegmentRead32 (PciAddress);\r
713 break;\r
714 case S3BootScriptWidthFifoUint32:\r
715 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint32 - 0x%016lx\n", PciAddress));\r
716 *Out.Uint32 = PciSegmentRead32 (PciAddress);\r
717 break;\r
718 case S3BootScriptWidthFillUint32:\r
719 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint32 - 0x%016lx\n", PciAddress));\r
720 *Out.Uint32 = PciSegmentRead32 (PciAddress);\r
721 break;\r
64d14edf 722\r
1436aea4
MK
723 default:\r
724 return EFI_INVALID_PARAMETER;\r
30f80497 725 }\r
64d14edf 726 }\r
1436aea4 727\r
30f80497 728 return EFI_SUCCESS;\r
64d14edf 729}\r
730\r
731/**\r
3d20524a 732 Performance PCI configuration 2 write operation\r
64d14edf 733\r
734 @param Width Width of the operation.\r
3d20524a 735 @param Segment Pci segment number\r
64d14edf 736 @param Address Address of the operation.\r
30f80497
SZ
737 @param Count Count of the number of accesses to perform.\r
738 @param Buffer Pointer to the buffer write to PCI config space\r
3a03e95e 739\r
64d14edf 740 @retval EFI_SUCCESS The write succeed.\r
3a03e95e 741 @retval EFI_INVALID_PARAMETER if Width is not defined\r
2a956f74
SZ
742 @note A known Limitations in the implementation which is 64bits operations are not supported.\r
743\r
64d14edf 744**/\r
745EFI_STATUS\r
3d20524a 746ScriptPciCfg2Write (\r
1436aea4
MK
747 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r
748 IN UINT16 Segment,\r
749 IN UINT64 Address,\r
750 IN UINTN Count,\r
751 IN VOID *Buffer\r
64d14edf 752 )\r
753{\r
30f80497
SZ
754 EFI_STATUS Status;\r
755 UINTN AddressStride;\r
756 UINTN BufferStride;\r
3d20524a 757 UINT64 OriginalPciAddress;\r
30f80497
SZ
758 PTR In;\r
759 PTR OriginalIn;\r
3d20524a 760 UINT64 PciAddress;\r
30f80497 761\r
1436aea4 762 In.Buf = (UINT8 *)Buffer;\r
30f80497 763\r
3d20524a 764 PciAddress = PCI_ADDRESS_ENCODE (Segment, Address);\r
30f80497
SZ
765\r
766 Status = BuildLoopData (Width, PciAddress, &AddressStride, &BufferStride);\r
767 if (EFI_ERROR (Status)) {\r
768 return Status;\r
64d14edf 769 }\r
1436aea4 770\r
30f80497
SZ
771 //\r
772 // Loop for each iteration and move the data\r
773 //\r
774 OriginalPciAddress = PciAddress;\r
1436aea4
MK
775 OriginalIn.Buf = In.Buf;\r
776 for ( ; Count > 0; Count--, PciAddress += AddressStride, In.Buf += BufferStride) {\r
30f80497
SZ
777 switch (Width) {\r
778 case S3BootScriptWidthUint8:\r
87000d77 779 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint8 - 0x%016lx (0x%02x)\n", PciAddress, (UINTN)*In.Uint8));\r
3d20524a 780 PciSegmentWrite8 (PciAddress, *In.Uint8);\r
3a03e95e 781 break;\r
30f80497 782 case S3BootScriptWidthFifoUint8:\r
87000d77 783 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint8 - 0x%016lx (0x%02x)\n", OriginalPciAddress, (UINTN)*In.Uint8));\r
3d20524a 784 PciSegmentWrite8 (OriginalPciAddress, *In.Uint8);\r
3a03e95e 785 break;\r
30f80497 786 case S3BootScriptWidthFillUint8:\r
87000d77 787 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint8 - 0x%016lx (0x%02x)\n", PciAddress, (UINTN)*OriginalIn.Uint8));\r
3d20524a 788 PciSegmentWrite8 (PciAddress, *OriginalIn.Uint8);\r
30f80497
SZ
789 break;\r
790 case S3BootScriptWidthUint16:\r
87000d77 791 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint16 - 0x%016lx (0x%04x)\n", PciAddress, (UINTN)*In.Uint16));\r
3d20524a 792 PciSegmentWrite16 (PciAddress, *In.Uint16);\r
3a03e95e 793 break;\r
30f80497 794 case S3BootScriptWidthFifoUint16:\r
87000d77 795 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint16 - 0x%016lx (0x%04x)\n", OriginalPciAddress, (UINTN)*In.Uint16));\r
3d20524a 796 PciSegmentWrite16 (OriginalPciAddress, *In.Uint16);\r
3a03e95e 797 break;\r
30f80497 798 case S3BootScriptWidthFillUint16:\r
87000d77 799 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint16 - 0x%016lx (0x%04x)\n", PciAddress, (UINTN)*OriginalIn.Uint16));\r
3d20524a 800 PciSegmentWrite16 (PciAddress, *OriginalIn.Uint16);\r
30f80497
SZ
801 break;\r
802 case S3BootScriptWidthUint32:\r
87000d77 803 DEBUG ((DEBUG_INFO, "S3BootScriptWidthUint32 - 0x%016lx (0x%08x)\n", PciAddress, (UINTN)*In.Uint32));\r
3d20524a 804 PciSegmentWrite32 (PciAddress, *In.Uint32);\r
3a03e95e 805 break;\r
30f80497 806 case S3BootScriptWidthFifoUint32:\r
87000d77 807 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFifoUint32 - 0x%016lx (0x%08x)\n", OriginalPciAddress, (UINTN)*In.Uint32));\r
3d20524a 808 PciSegmentWrite32 (OriginalPciAddress, *In.Uint32);\r
3a03e95e 809 break;\r
30f80497 810 case S3BootScriptWidthFillUint32:\r
87000d77 811 DEBUG ((DEBUG_INFO, "S3BootScriptWidthFillUint32 - 0x%016lx (0x%08x)\n", (UINTN)PciAddress, (UINTN)*OriginalIn.Uint32));\r
3d20524a 812 PciSegmentWrite32 (PciAddress, *OriginalIn.Uint32);\r
30f80497
SZ
813 break;\r
814 default:\r
815 return EFI_INVALID_PARAMETER;\r
816 }\r
817 }\r
1436aea4 818\r
30f80497 819 return EFI_SUCCESS;\r
64d14edf 820}\r
1436aea4 821\r
64d14edf 822/**\r
3d20524a 823 Performance PCI configuration read operation\r
3a03e95e 824\r
64d14edf 825 @param Width Width of the operation.\r
64d14edf 826 @param Address Address of the operation.\r
30f80497
SZ
827 @param Count Count of the number of accesses to perform.\r
828 @param Buffer Pointer to the buffer to read from PCI config space.\r
64d14edf 829\r
830 @retval EFI_SUCCESS The data was written to the EFI System.\r
831 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.\r
832 Buffer is NULL.\r
833 The Buffer is not aligned for the given Width.\r
834 Address is outside the legal range of I/O ports.\r
3d20524a 835\r
64d14edf 836**/\r
837EFI_STATUS\r
3d20524a 838ScriptPciCfgRead (\r
1436aea4
MK
839 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r
840 IN UINT64 Address,\r
841 IN UINTN Count,\r
842 OUT VOID *Buffer\r
64d14edf 843 )\r
844{\r
3d20524a 845 return ScriptPciCfg2Read (Width, 0, Address, Count, Buffer);\r
64d14edf 846}\r
1436aea4 847\r
64d14edf 848/**\r
3d20524a 849 Performance PCI configuration write operation\r
3a03e95e 850\r
64d14edf 851 @param Width Width of the operation.\r
64d14edf 852 @param Address Address of the operation.\r
30f80497
SZ
853 @param Count Count of the number of accesses to perform.\r
854 @param Buffer Pointer to the buffer to write to PCI config space.\r
64d14edf 855\r
856 @retval EFI_SUCCESS The data was written to the EFI System.\r
857 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.\r
858 Buffer is NULL.\r
859 The Buffer is not aligned for the given Width.\r
860 Address is outside the legal range of I/O ports.\r
3a03e95e 861\r
64d14edf 862**/\r
863EFI_STATUS\r
864EFIAPI\r
3d20524a 865ScriptPciCfgWrite (\r
1436aea4
MK
866 IN S3_BOOT_SCRIPT_LIB_WIDTH Width,\r
867 IN UINT64 Address,\r
868 IN UINTN Count,\r
869 IN VOID *Buffer\r
64d14edf 870 )\r
871{\r
3d20524a 872 return ScriptPciCfg2Write (Width, 0, Address, Count, Buffer);\r
64d14edf 873}\r
1436aea4 874\r
64d14edf 875/**\r
e0cb5e18 876 Interpret the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE OP code.\r
3a03e95e
SZ
877\r
878 @param Script The pointer of typed node in boot script table\r
879\r
64d14edf 880 @retval EFI_SUCCESS The operation was executed successfully\r
881**/\r
882EFI_STATUS\r
883BootScriptExecutePciCfgWrite (\r
1436aea4 884 IN UINT8 *Script\r
64d14edf 885 )\r
886{\r
30f80497
SZ
887 VOID *Buffer;\r
888 S3_BOOT_SCRIPT_LIB_WIDTH Width;\r
889 UINT64 Address;\r
890 UINTN Count;\r
891 EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE PciCfgWrite;\r
64d14edf 892\r
1436aea4 893 CopyMem ((VOID *)&PciCfgWrite, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE));\r
64d14edf 894\r
30f80497
SZ
895 Width = (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfgWrite.Width;\r
896 Address = PciCfgWrite.Address;\r
897 Count = PciCfgWrite.Count;\r
1436aea4 898 Buffer = Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE);\r
64d14edf 899\r
87000d77 900 DEBUG ((DEBUG_INFO, "BootScriptExecutePciCfgWrite - 0x%016lx, 0x%08x, 0x%08x\n", PCI_ADDRESS_ENCODE (0, Address), Count, (UINTN)Width));\r
30f80497 901 return ScriptPciCfgWrite (Width, Address, Count, Buffer);\r
64d14edf 902}\r
1436aea4 903\r
64d14edf 904/**\r
e0cb5e18 905 Interpret the boot script node with EFI_BOOT_SCRIPT_IO_READ_WRITE OP code.\r
64d14edf 906\r
3a03e95e 907 @param Script The pointer of typed node in boot script table\r
64d14edf 908 @param AndMask Mask value for 'and' operation\r
909 @param OrMask Mask value for 'or' operation\r
910\r
911 @retval EFI_SUCCESS The operation was executed successfully\r
912**/\r
913EFI_STATUS\r
914BootScriptExecuteIoReadWrite (\r
1436aea4
MK
915 IN UINT8 *Script,\r
916 IN UINT64 AndMask,\r
917 IN UINT64 OrMask\r
64d14edf 918 )\r
919\r
920{\r
1436aea4
MK
921 EFI_STATUS Status;\r
922 UINT64 Data;\r
923 EFI_BOOT_SCRIPT_IO_READ_WRITE IoReadWrite;\r
3a03e95e 924\r
64d14edf 925 Data = 0;\r
3a03e95e 926\r
1436aea4 927 CopyMem ((VOID *)&IoReadWrite, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE));\r
64d14edf 928\r
87000d77 929 DEBUG ((DEBUG_INFO, "BootScriptExecuteIoReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)IoReadWrite.Address, AndMask, OrMask));\r
64d14edf 930\r
931 Status = ScriptIoRead (\r
1436aea4 932 (S3_BOOT_SCRIPT_LIB_WIDTH)IoReadWrite.Width,\r
64d14edf 933 IoReadWrite.Address,\r
934 1,\r
935 &Data\r
936 );\r
937 if (!EFI_ERROR (Status)) {\r
1436aea4 938 Data = (Data & AndMask) | OrMask;\r
64d14edf 939 Status = ScriptIoWrite (\r
1436aea4 940 (S3_BOOT_SCRIPT_LIB_WIDTH)IoReadWrite.Width,\r
64d14edf 941 IoReadWrite.Address,\r
942 1,\r
943 &Data\r
944 );\r
945 }\r
1436aea4 946\r
64d14edf 947 return Status;\r
948}\r
1436aea4 949\r
64d14edf 950/**\r
e0cb5e18 951 Interpret the boot script node with EFI_BOOT_SCRIPT_MEM_READ_WRITE OP code.\r
64d14edf 952\r
3a03e95e 953 @param Script The pointer of typed node in boot script table\r
64d14edf 954 @param AndMask Mask value for 'and' operation\r
955 @param OrMask Mask value for 'or' operation\r
956\r
957 @retval EFI_SUCCESS The operation was executed successfully\r
958**/\r
959EFI_STATUS\r
960BootScriptExecuteMemoryReadWrite (\r
1436aea4
MK
961 IN UINT8 *Script,\r
962 IN UINT64 AndMask,\r
963 IN UINT64 OrMask\r
64d14edf 964 )\r
965\r
966{\r
1436aea4
MK
967 EFI_STATUS Status;\r
968 UINT64 Data;\r
64d14edf 969 EFI_BOOT_SCRIPT_MEM_READ_WRITE MemReadWrite;\r
3a03e95e 970\r
64d14edf 971 Data = 0;\r
3a03e95e 972\r
1436aea4 973 CopyMem ((VOID *)&MemReadWrite, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE));\r
64d14edf 974\r
87000d77 975 DEBUG ((DEBUG_INFO, "BootScriptExecuteMemoryReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)MemReadWrite.Address, AndMask, OrMask));\r
3a03e95e 976\r
64d14edf 977 Status = ScriptMemoryRead (\r
1436aea4 978 (S3_BOOT_SCRIPT_LIB_WIDTH)MemReadWrite.Width,\r
64d14edf 979 MemReadWrite.Address,\r
980 1,\r
981 &Data\r
982 );\r
983 if (!EFI_ERROR (Status)) {\r
1436aea4 984 Data = (Data & AndMask) | OrMask;\r
64d14edf 985 Status = ScriptMemoryWrite (\r
1436aea4 986 (S3_BOOT_SCRIPT_LIB_WIDTH)MemReadWrite.Width,\r
64d14edf 987 MemReadWrite.Address,\r
988 1,\r
989 &Data\r
990 );\r
991 }\r
1436aea4 992\r
64d14edf 993 return Status;\r
994}\r
1436aea4 995\r
64d14edf 996/**\r
e0cb5e18 997 Interpret the boot script node with EFI_BOOT_SCRIPT_PCI_CFG_READ_WRITE OP code.\r
64d14edf 998\r
3a03e95e 999 @param Script The pointer of typed node in boot script table\r
64d14edf 1000 @param AndMask Mask value for 'and' operation\r
1001 @param OrMask Mask value for 'or' operation\r
1002\r
1003 @retval EFI_SUCCESS The operation was executed successfully\r
1004**/\r
1005EFI_STATUS\r
1006BootScriptExecutePciCfgReadWrite (\r
1436aea4
MK
1007 IN UINT8 *Script,\r
1008 IN UINT64 AndMask,\r
1009 IN UINT64 OrMask\r
64d14edf 1010 )\r
1011\r
1012{\r
1436aea4
MK
1013 EFI_STATUS Status;\r
1014 UINT64 Data;\r
64d14edf 1015 EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE PciCfgReadWrite;\r
0f4e03da
SZ
1016\r
1017 Data = 0;\r
1018\r
1436aea4 1019 CopyMem ((VOID *)&PciCfgReadWrite, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE));\r
64d14edf 1020\r
87000d77 1021 DEBUG ((DEBUG_INFO, "BootScriptExecutePciCfgReadWrite - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (0, PciCfgReadWrite.Address), AndMask, OrMask));\r
3a03e95e 1022\r
64d14edf 1023 Status = ScriptPciCfgRead (\r
1436aea4 1024 (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfgReadWrite.Width,\r
64d14edf 1025 PciCfgReadWrite.Address,\r
30f80497 1026 1,\r
64d14edf 1027 &Data\r
1028 );\r
1029 if (EFI_ERROR (Status)) {\r
1030 return Status;\r
1031 }\r
1032\r
1033 Data = (Data & AndMask) | OrMask;\r
1034\r
1035 Status = ScriptPciCfgWrite (\r
1436aea4 1036 (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfgReadWrite.Width,\r
64d14edf 1037 PciCfgReadWrite.Address,\r
30f80497 1038 1,\r
64d14edf 1039 &Data\r
1040 );\r
1041\r
1042 return Status;\r
1043}\r
1436aea4 1044\r
64d14edf 1045/**\r
e0cb5e18 1046 Interpret the boot script node with EFI_BOOT_SCRIPT_SMBUS_EXECUTE OP code.\r
64d14edf 1047\r
3a03e95e
SZ
1048 @param Script The pointer of typed node in boot script table\r
1049\r
64d14edf 1050 @retval EFI_SUCCESS The operation was executed successfully\r
1051 @retval EFI_UNSUPPORTED Cannot locate smbus ppi or occur error of script execution\r
3a03e95e 1052 @retval Others Result of script execution\r
64d14edf 1053**/\r
1054EFI_STATUS\r
1055BootScriptExecuteSmbusExecute (\r
1436aea4 1056 IN UINT8 *Script\r
64d14edf 1057 )\r
1058{\r
1436aea4
MK
1059 UINTN SmBusAddress;\r
1060 UINTN DataSize;\r
1061 EFI_BOOT_SCRIPT_SMBUS_EXECUTE SmbusExecuteEntry;\r
3a03e95e 1062\r
1436aea4 1063 CopyMem ((VOID *)&SmbusExecuteEntry, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE));\r
64d14edf 1064\r
87000d77 1065 DEBUG ((DEBUG_INFO, "BootScriptExecuteSmbusExecute - 0x%08x, 0x%08x\n", (UINTN)SmbusExecuteEntry.SmBusAddress, (UINTN)SmbusExecuteEntry.Operation));\r
64d14edf 1066\r
1067 SmBusAddress = (UINTN)SmbusExecuteEntry.SmBusAddress;\r
1436aea4 1068 DataSize = (UINTN)SmbusExecuteEntry.DataSize;\r
5f56b0ff 1069 return InternalSmbusExecute (\r
64d14edf 1070 SmBusAddress,\r
1436aea4 1071 (EFI_SMBUS_OPERATION)SmbusExecuteEntry.Operation,\r
64d14edf 1072 &DataSize,\r
1073 Script + sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE)\r
1074 );\r
1075}\r
1436aea4 1076\r
64d14edf 1077/**\r
e0cb5e18 1078 Interpret the boot script node with EFI_BOOT_SCRIPT_STALL OP code.\r
64d14edf 1079\r
3a03e95e
SZ
1080 @param Script The pointer of typed node in boot script table\r
1081\r
64d14edf 1082 @retval EFI_SUCCESS The operation was executed successfully\r
1083**/\r
1084EFI_STATUS\r
1085BootScriptExecuteStall (\r
1436aea4 1086 IN UINT8 *Script\r
64d14edf 1087 )\r
1088{\r
1436aea4 1089 EFI_BOOT_SCRIPT_STALL Stall;\r
3a03e95e 1090\r
1436aea4 1091 CopyMem ((VOID *)&Stall, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_STALL));\r
64d14edf 1092\r
87000d77 1093 DEBUG ((DEBUG_INFO, "BootScriptExecuteStall - 0x%08x\n", (UINTN)Stall.Duration));\r
64d14edf 1094\r
1436aea4 1095 MicroSecondDelay ((UINTN)Stall.Duration);\r
64d14edf 1096 return EFI_SUCCESS;\r
1097}\r
1436aea4 1098\r
64d14edf 1099/**\r
e0cb5e18 1100 Interpret the boot script node with EFI_BOOT_SCRIPT_DISPATCH OP code.\r
3a03e95e
SZ
1101\r
1102 @param Script The pointer of typed node in boot script table\r
30f80497 1103 @retval EFI_SUCCESS The operation was executed successfully\r
64d14edf 1104**/\r
1105EFI_STATUS\r
1106BootScriptExecuteDispatch (\r
1436aea4 1107 IN UINT8 *Script\r
64d14edf 1108 )\r
1109{\r
1110 EFI_STATUS Status;\r
1111 DISPATCH_ENTRYPOINT_FUNC EntryFunc;\r
1112 EFI_BOOT_SCRIPT_DISPATCH ScriptDispatch;\r
3a03e95e 1113\r
1436aea4
MK
1114 CopyMem ((VOID *)&ScriptDispatch, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_DISPATCH));\r
1115 EntryFunc = (DISPATCH_ENTRYPOINT_FUNC)(UINTN)(ScriptDispatch.EntryPoint);\r
64d14edf 1116\r
87000d77 1117 DEBUG ((DEBUG_INFO, "BootScriptExecuteDispatch - 0x%08x\n", (UINTN)ScriptDispatch.EntryPoint));\r
64d14edf 1118\r
1436aea4 1119 Status = EntryFunc (NULL, NULL);\r
64d14edf 1120\r
1121 return Status;\r
1122}\r
1436aea4 1123\r
64d14edf 1124/**\r
e0cb5e18 1125 Interpret the boot script node with EFI_BOOT_SCRIPT_DISPATCH_2 OP code.\r
64d14edf 1126\r
3a03e95e 1127 @param Script The pointer of typed node in boot script table\r
64d14edf 1128 @retval EFI_SUCCESS The operation was executed successfully\r
1129**/\r
1130EFI_STATUS\r
1131BootScriptExecuteDispatch2 (\r
1436aea4 1132 IN UINT8 *Script\r
64d14edf 1133 )\r
1134{\r
1436aea4
MK
1135 EFI_STATUS Status;\r
1136 DISPATCH_ENTRYPOINT_FUNC EntryFunc;\r
64d14edf 1137 EFI_BOOT_SCRIPT_DISPATCH_2 ScriptDispatch2;\r
3a03e95e 1138\r
1436aea4 1139 CopyMem ((VOID *)&ScriptDispatch2, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_DISPATCH_2));\r
64d14edf 1140\r
87000d77 1141 DEBUG ((DEBUG_INFO, "BootScriptExecuteDispatch2 - 0x%08x(0x%08x)\n", (UINTN)ScriptDispatch2.EntryPoint, (UINTN)ScriptDispatch2.Context));\r
3a03e95e 1142\r
1436aea4 1143 EntryFunc = (DISPATCH_ENTRYPOINT_FUNC)(UINTN)(ScriptDispatch2.EntryPoint);\r
64d14edf 1144\r
1436aea4 1145 Status = EntryFunc (NULL, (VOID *)(UINTN)ScriptDispatch2.Context);\r
64d14edf 1146\r
1147 return Status;\r
1148}\r
1436aea4 1149\r
64d14edf 1150/**\r
e0cb5e18 1151 Interpret the boot script node with EFI_BOOT_SCRIPT_MEM_POLL OP code.\r
64d14edf 1152\r
3a03e95e 1153 @param Script The pointer of typed node in boot script table\r
64d14edf 1154 @param AndMask Mask value for 'and' operation\r
1155 @param OrMask Mask value for 'or' operation\r
3a03e95e
SZ
1156\r
1157 @retval EFI_DEVICE_ERROR Data polled from memory does not equal to\r
64d14edf 1158 the epecting data within the Loop Times.\r
1159 @retval EFI_SUCCESS The operation was executed successfully\r
1160**/\r
1161EFI_STATUS\r
1162BootScriptExecuteMemPoll (\r
1436aea4
MK
1163 IN UINT8 *Script,\r
1164 IN UINT64 AndMask,\r
1165 IN UINT64 OrMask\r
64d14edf 1166 )\r
1167{\r
1436aea4
MK
1168 UINT64 Data;\r
1169 UINT64 LoopTimes;\r
1170 EFI_STATUS Status;\r
1171 EFI_BOOT_SCRIPT_MEM_POLL MemPoll;\r
3a03e95e 1172\r
1436aea4 1173 CopyMem ((VOID *)&MemPoll, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_MEM_POLL));\r
64d14edf 1174\r
87000d77 1175 DEBUG ((DEBUG_INFO, "BootScriptExecuteMemPoll - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)MemPoll.Address, AndMask, OrMask));\r
64d14edf 1176\r
1436aea4 1177 Data = 0;\r
64d14edf 1178 Status = ScriptMemoryRead (\r
1436aea4
MK
1179 (S3_BOOT_SCRIPT_LIB_WIDTH)MemPoll.Width,\r
1180 MemPoll.Address,\r
1181 1,\r
1182 &Data\r
1183 );\r
1184 if ((!EFI_ERROR (Status)) && ((Data & AndMask) == OrMask)) {\r
64d14edf 1185 return EFI_SUCCESS;\r
1186 }\r
1187\r
1188 for (LoopTimes = 0; LoopTimes < MemPoll.LoopTimes; LoopTimes++) {\r
30522140 1189 MicroSecondDelay ((UINTN)MemPoll.Duration);\r
64d14edf 1190\r
1436aea4 1191 Data = 0;\r
64d14edf 1192 Status = ScriptMemoryRead (\r
1436aea4 1193 (S3_BOOT_SCRIPT_LIB_WIDTH)MemPoll.Width,\r
64d14edf 1194 MemPoll.Address,\r
1195 1,\r
1196 &Data\r
1197 );\r
1436aea4
MK
1198 if ((!EFI_ERROR (Status)) && ((Data & AndMask) == OrMask)) {\r
1199 return EFI_SUCCESS;\r
1200 }\r
64d14edf 1201 }\r
1202\r
1203 if (LoopTimes < MemPoll.LoopTimes) {\r
1204 return EFI_SUCCESS;\r
1205 } else {\r
1206 return EFI_DEVICE_ERROR;\r
1207 }\r
1208}\r
1436aea4 1209\r
64d14edf 1210/**\r
30f80497 1211 Execute the boot script to interpret the Store arbitrary information.\r
64d14edf 1212 This opcode is a no-op on dispatch and is only used for debugging script issues.\r
1213\r
3a03e95e
SZ
1214 @param Script The pointer of node in boot script table\r
1215\r
64d14edf 1216**/\r
1217VOID\r
1218BootScriptExecuteInformation (\r
1436aea4 1219 IN UINT8 *Script\r
64d14edf 1220 )\r
1221\r
1222{\r
1436aea4
MK
1223 UINT32 Index;\r
1224 EFI_BOOT_SCRIPT_INFORMATION Information;\r
1225 UINT8 *InformationData;\r
f6ec0c77 1226\r
1436aea4 1227 CopyMem ((VOID *)&Information, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_INFORMATION));\r
f6ec0c77 1228\r
93b21ade 1229 InformationData = Script + sizeof (EFI_BOOT_SCRIPT_INFORMATION);\r
1436aea4 1230 DEBUG ((DEBUG_INFO, "BootScriptExecuteInformation - 0x%08x\n", (UINTN)InformationData));\r
f6ec0c77 1231\r
87000d77 1232 DEBUG ((DEBUG_INFO, "BootScriptInformation: "));\r
f6ec0c77 1233 for (Index = 0; Index < Information.InformationLength; Index++) {\r
87000d77 1234 DEBUG ((DEBUG_INFO, "%02x ", InformationData[Index]));\r
f6ec0c77 1235 }\r
1436aea4 1236\r
87000d77 1237 DEBUG ((DEBUG_INFO, "\n"));\r
64d14edf 1238}\r
8e4585bb
SZ
1239\r
1240/**\r
3a03e95e
SZ
1241 Execute the boot script to interpret the Label information.\r
1242\r
1243 @param Script The pointer of node in boot script table\r
8e4585bb 1244\r
8e4585bb
SZ
1245**/\r
1246VOID\r
1247BootScriptExecuteLabel (\r
1436aea4 1248 IN UINT8 *Script\r
8e4585bb
SZ
1249 )\r
1250\r
1251{\r
1436aea4
MK
1252 UINT32 Index;\r
1253 EFI_BOOT_SCRIPT_INFORMATION Information;\r
1254 UINT8 *InformationData;\r
8e4585bb 1255\r
1436aea4 1256 CopyMem ((VOID *)&Information, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_INFORMATION));\r
8e4585bb 1257\r
93b21ade 1258 InformationData = Script + sizeof (EFI_BOOT_SCRIPT_INFORMATION);\r
1436aea4 1259 DEBUG ((DEBUG_INFO, "BootScriptExecuteLabel - 0x%08x\n", (UINTN)InformationData));\r
8e4585bb 1260\r
87000d77 1261 DEBUG ((DEBUG_INFO, "BootScriptLabel: "));\r
8e4585bb 1262 for (Index = 0; Index < Information.InformationLength; Index++) {\r
87000d77 1263 DEBUG ((DEBUG_INFO, "%02x ", InformationData[Index]));\r
8e4585bb 1264 }\r
1436aea4 1265\r
87000d77 1266 DEBUG ((DEBUG_INFO, "\n"));\r
8e4585bb
SZ
1267}\r
1268\r
64d14edf 1269/**\r
1270 calculate the mask value for 'and' and 'or' operation\r
3a03e95e 1271 @param ScriptHeader The pointer of header of node in boot script table\r
64d14edf 1272 @param AndMask The Mask value for 'and' operation\r
1273 @param OrMask The Mask value for 'or' operation\r
1274 @param Script Pointer to the entry.\r
1275\r
1276**/\r
1277VOID\r
1278CheckAndOrMask (\r
1279 IN EFI_BOOT_SCRIPT_COMMON_HEADER *ScriptHeader,\r
1436aea4
MK
1280 OUT UINT64 *AndMask,\r
1281 OUT UINT64 *OrMask,\r
1282 IN UINT8 *Script\r
64d14edf 1283 )\r
1284{\r
1436aea4
MK
1285 UINT8 *DataPtr;\r
1286 UINTN Size;\r
64d14edf 1287\r
1288 switch (ScriptHeader->OpCode) {\r
1436aea4
MK
1289 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE:\r
1290 Size = sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE);\r
1291 break;\r
1292\r
1293 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE:\r
1294 Size = sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE);\r
1295 break;\r
1296\r
1297 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE:\r
1298 Size = sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE);\r
1299 break;\r
1300 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE:\r
1301 Size = sizeof (EFI_BOOT_SCRIPT_MEM_POLL);\r
1302 break;\r
1303\r
1304 case EFI_BOOT_SCRIPT_IO_POLL_OPCODE:\r
1305 Size = sizeof (EFI_BOOT_SCRIPT_IO_POLL);\r
1306 break;\r
1307\r
1308 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE:\r
1309 Size = sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE);\r
1310 break;\r
1311\r
1312 case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE:\r
1313 Size = sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL);\r
1314 break;\r
1315\r
1316 case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE:\r
1317 Size = sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL);\r
1318 break;\r
1319\r
1320 default:\r
1321 return;\r
64d14edf 1322 }\r
3a03e95e 1323\r
64d14edf 1324 DataPtr = Script + Size;\r
1325\r
1326 switch (ScriptHeader->Width) {\r
1436aea4
MK
1327 case S3BootScriptWidthUint8:\r
1328 *AndMask = (UINT64)(*(UINT8 *)(DataPtr + 1));\r
1329 *OrMask = (UINT64)(*DataPtr);\r
1330 break;\r
1331\r
1332 case S3BootScriptWidthUint16:\r
1333 *AndMask = (UINT64)(*(UINT16 *)(DataPtr + 2));\r
1334 *OrMask = (UINT64)(*(UINT16 *)DataPtr);\r
1335 break;\r
1336\r
1337 case S3BootScriptWidthUint32:\r
1338 *AndMask = (UINT64)(*(UINT32 *)(DataPtr + 4));\r
1339 *OrMask = (UINT64)(*(UINT32 *)DataPtr);\r
1340 break;\r
1341\r
1342 case S3BootScriptWidthUint64:\r
1343 *AndMask = (UINT64)(*(UINT64 *)(DataPtr + 8));\r
1344 *OrMask = (UINT64)(*(UINT64 *)DataPtr);\r
1345 break;\r
1346\r
1347 default:\r
1348 break;\r
64d14edf 1349 }\r
1350\r
1351 return;\r
1352}\r
1436aea4 1353\r
64d14edf 1354/**\r
e0cb5e18 1355 Interpret the boot script node with EFI_BOOT_SCRIPT_IO_POLL OP code.\r
64d14edf 1356\r
3a03e95e 1357 @param Script The pointer of typed node in boot script table\r
64d14edf 1358 @param AndMask Mask value for 'and' operation\r
1359 @param OrMask Mask value for 'or' operation\r
3a03e95e
SZ
1360\r
1361 @retval EFI_DEVICE_ERROR Data polled from memory does not equal to\r
64d14edf 1362 the epecting data within the Loop Times.\r
1363 @retval EFI_SUCCESS The operation was executed successfully\r
1364**/\r
1365EFI_STATUS\r
1366BootScriptExecuteIoPoll (\r
1436aea4
MK
1367 IN UINT8 *Script,\r
1368 IN UINT64 AndMask,\r
1369 IN UINT64 OrMask\r
64d14edf 1370 )\r
1371{\r
1436aea4
MK
1372 EFI_STATUS Status;\r
1373 UINT64 Data;\r
1374 UINT64 LoopTimes;\r
1375 EFI_BOOT_SCRIPT_IO_POLL IoPoll;\r
3a03e95e 1376\r
1436aea4 1377 CopyMem ((VOID *)&IoPoll, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_IO_POLL));\r
64d14edf 1378\r
87000d77 1379 DEBUG ((DEBUG_INFO, "BootScriptExecuteIoPoll - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN)IoPoll.Address, AndMask, OrMask));\r
64d14edf 1380\r
1436aea4 1381 Data = 0;\r
64d14edf 1382 Status = ScriptIoRead (\r
1436aea4 1383 (S3_BOOT_SCRIPT_LIB_WIDTH)IoPoll.Width,\r
64d14edf 1384 IoPoll.Address,\r
1385 1,\r
1386 &Data\r
1387 );\r
1436aea4 1388 if ((!EFI_ERROR (Status)) && ((Data & AndMask) == OrMask)) {\r
64d14edf 1389 return EFI_SUCCESS;\r
1390 }\r
1436aea4 1391\r
64d14edf 1392 for (LoopTimes = 0; LoopTimes < IoPoll.Delay; LoopTimes++) {\r
1393 NanoSecondDelay (100);\r
1436aea4 1394 Data = 0;\r
64d14edf 1395 Status = ScriptIoRead (\r
1436aea4 1396 (S3_BOOT_SCRIPT_LIB_WIDTH)IoPoll.Width,\r
64d14edf 1397 IoPoll.Address,\r
1398 1,\r
1399 &Data\r
1400 );\r
1436aea4 1401 if ((!EFI_ERROR (Status)) && ((Data & AndMask) == OrMask)) {\r
64d14edf 1402 return EFI_SUCCESS;\r
3a03e95e 1403 }\r
64d14edf 1404 }\r
1405\r
1406 if (LoopTimes < IoPoll.Delay) {\r
1407 return EFI_SUCCESS;\r
1408 } else {\r
1409 return EFI_DEVICE_ERROR;\r
1410 }\r
1411}\r
1436aea4 1412\r
64d14edf 1413/**\r
e0cb5e18 1414 Interpret the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE OP code.\r
64d14edf 1415\r
1416 @param Script The pointer of S3 boot script\r
1417\r
1418 @retval EFI_SUCCESS The operation was executed successfully\r
1419\r
1420**/\r
1421EFI_STATUS\r
1422BootScriptExecutePciCfg2Write (\r
1436aea4 1423 IN UINT8 *Script\r
64d14edf 1424 )\r
1425{\r
1436aea4
MK
1426 VOID *Buffer;\r
1427 S3_BOOT_SCRIPT_LIB_WIDTH Width;\r
1428 UINT16 Segment;\r
1429 UINT64 Address;\r
1430 UINTN Count;\r
1431 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE PciCfg2Write;\r
3a03e95e 1432\r
1436aea4 1433 CopyMem ((VOID *)&PciCfg2Write, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE));\r
64d14edf 1434\r
30f80497
SZ
1435 Width = (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfg2Write.Width;\r
1436 Segment = PciCfg2Write.Segment;\r
1437 Address = PciCfg2Write.Address;\r
1438 Count = PciCfg2Write.Count;\r
1436aea4 1439 Buffer = Script + sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE);\r
30f80497 1440\r
87000d77 1441 DEBUG ((DEBUG_INFO, "BootScriptExecutePciCfg2Write - 0x%016lx, 0x%08x, 0x%08x\n", PCI_ADDRESS_ENCODE (Segment, Address), Count, (UINTN)Width));\r
30f80497 1442 return ScriptPciCfg2Write (Width, Segment, Address, Count, Buffer);\r
64d14edf 1443}\r
1444\r
64d14edf 1445/**\r
e0cb5e18 1446 Interpret the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE OP code.\r
3a03e95e 1447\r
64d14edf 1448 @param Script The pointer of S3 boot script\r
1449 @param AndMask Mask value for 'and' operation\r
1450 @param OrMask Mask value for 'or' operation\r
1451\r
1452 @retval EFI_SUCCESS The operation was executed successfully\r
1453\r
1454**/\r
1455EFI_STATUS\r
1456BootScriptExecutePciCfg2ReadWrite (\r
1436aea4
MK
1457 IN UINT8 *Script,\r
1458 IN UINT64 AndMask,\r
1459 IN UINT64 OrMask\r
64d14edf 1460 )\r
1461{\r
1436aea4
MK
1462 UINT64 Data;\r
1463 EFI_STATUS Status;\r
1464 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE PciCfg2ReadWrite;\r
0f4e03da
SZ
1465\r
1466 Data = 0;\r
1467\r
1436aea4 1468 CopyMem ((VOID *)&PciCfg2ReadWrite, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE));\r
64d14edf 1469\r
87000d77 1470 DEBUG ((DEBUG_INFO, "BootScriptExecutePciCfg2ReadWrite - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfg2ReadWrite.Segment, PciCfg2ReadWrite.Address), AndMask, OrMask));\r
3a03e95e 1471\r
64d14edf 1472 Status = ScriptPciCfg2Read (\r
1436aea4 1473 (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfg2ReadWrite.Width,\r
64d14edf 1474 PciCfg2ReadWrite.Segment,\r
1475 PciCfg2ReadWrite.Address,\r
30f80497 1476 1,\r
64d14edf 1477 &Data\r
1478 );\r
1479 if (EFI_ERROR (Status)) {\r
1480 return Status;\r
1481 }\r
1482\r
1436aea4 1483 Data = (Data & AndMask) | OrMask;\r
64d14edf 1484 Status = ScriptPciCfg2Write (\r
1436aea4 1485 (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfg2ReadWrite.Width,\r
64d14edf 1486 PciCfg2ReadWrite.Segment,\r
1487 PciCfg2ReadWrite.Address,\r
30f80497 1488 1,\r
64d14edf 1489 &Data\r
1490 );\r
1491 return Status;\r
1492}\r
1436aea4 1493\r
64d14edf 1494/**\r
e0cb5e18 1495 Interpret the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG_POLL OP code.\r
3a03e95e 1496\r
64d14edf 1497 @param Script The pointer of S3 boot script\r
1498 @param AndMask Mask value for 'and' operation\r
1499 @param OrMask Mask value for 'or' operation\r
1500\r
1501 @retval EFI_SUCCESS The operation was executed successfully\r
3a03e95e 1502 @retval EFI_DEVICE_ERROR Data polled from Pci configuration space does not equal to\r
64d14edf 1503 epecting data within the Loop Times.\r
1504**/\r
1505EFI_STATUS\r
1506BootScriptPciCfgPoll (\r
1436aea4
MK
1507 IN UINT8 *Script,\r
1508 IN UINT64 AndMask,\r
1509 IN UINT64 OrMask\r
64d14edf 1510 )\r
1511{\r
1436aea4
MK
1512 UINT64 Data;\r
1513 UINT64 LoopTimes;\r
1514 EFI_STATUS Status;\r
1515 EFI_BOOT_SCRIPT_PCI_CONFIG_POLL PciCfgPoll;\r
1516\r
1517 CopyMem ((VOID *)&PciCfgPoll, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL));\r
64d14edf 1518\r
87000d77 1519 DEBUG ((DEBUG_INFO, "BootScriptPciCfgPoll - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (0, PciCfgPoll.Address), AndMask, OrMask));\r
3a03e95e 1520\r
1436aea4 1521 Data = 0;\r
64d14edf 1522 Status = ScriptPciCfgRead (\r
1436aea4 1523 (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfgPoll.Width,\r
64d14edf 1524 PciCfgPoll.Address,\r
30f80497 1525 1,\r
64d14edf 1526 &Data\r
1527 );\r
1436aea4 1528 if ((!EFI_ERROR (Status)) && ((Data & AndMask) == OrMask)) {\r
64d14edf 1529 return EFI_SUCCESS;\r
1530 }\r
1531\r
1532 for (LoopTimes = 0; LoopTimes < PciCfgPoll.Delay; LoopTimes++) {\r
1533 NanoSecondDelay (100);\r
1436aea4 1534 Data = 0;\r
64d14edf 1535 Status = ScriptPciCfgRead (\r
1436aea4 1536 (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfgPoll.Width,\r
64d14edf 1537 PciCfgPoll.Address,\r
30f80497 1538 1,\r
64d14edf 1539 &Data\r
1540 );\r
1541 if ((!EFI_ERROR (Status)) &&\r
1436aea4
MK
1542 ((Data & AndMask) == OrMask))\r
1543 {\r
64d14edf 1544 return EFI_SUCCESS;\r
1545 }\r
1546 }\r
1547\r
1548 if (LoopTimes < PciCfgPoll.Delay) {\r
1549 return EFI_SUCCESS;\r
1550 } else {\r
1551 return EFI_DEVICE_ERROR;\r
1552 }\r
1553}\r
1554\r
1555/**\r
e0cb5e18 1556 Interpret the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL OP code.\r
3a03e95e 1557\r
64d14edf 1558 @param Script The pointer of S3 Boot Script\r
1559 @param AndMask Mask value for 'and' operation\r
1560 @param OrMask Mask value for 'or' operation\r
1561\r
1562 @retval EFI_SUCCESS The operation was executed successfully\r
3a03e95e 1563 @retval EFI_DEVICE_ERROR Data polled from Pci configuration space does not equal to\r
64d14edf 1564 epecting data within the Loop Times.\r
1565\r
1566**/\r
1567EFI_STATUS\r
1568BootScriptPciCfg2Poll (\r
1436aea4
MK
1569 IN UINT8 *Script,\r
1570 IN UINT64 AndMask,\r
1571 IN UINT64 OrMask\r
64d14edf 1572 )\r
1573{\r
1436aea4
MK
1574 EFI_STATUS Status;\r
1575 UINT64 Data;\r
1576 UINT64 LoopTimes;\r
1577 EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL PciCfg2Poll;\r
64d14edf 1578\r
1579 Data = 0;\r
1436aea4 1580 CopyMem ((VOID *)&PciCfg2Poll, (VOID *)Script, sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL));\r
64d14edf 1581\r
87000d77 1582 DEBUG ((DEBUG_INFO, "BootScriptPciCfg2Poll - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfg2Poll.Segment, PciCfg2Poll.Address), AndMask, OrMask));\r
3a03e95e 1583\r
64d14edf 1584 Status = ScriptPciCfg2Read (\r
1436aea4 1585 (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfg2Poll.Width,\r
64d14edf 1586 PciCfg2Poll.Segment,\r
1587 PciCfg2Poll.Address,\r
30f80497 1588 1,\r
64d14edf 1589 &Data\r
1590 );\r
1436aea4 1591 if ((!EFI_ERROR (Status)) && ((Data & AndMask) == OrMask)) {\r
64d14edf 1592 return EFI_SUCCESS;\r
1593 }\r
1594\r
1595 for (LoopTimes = 0; LoopTimes < PciCfg2Poll.Delay; LoopTimes++) {\r
1596 NanoSecondDelay (100);\r
1597\r
1436aea4 1598 Data = 0;\r
64d14edf 1599 Status = ScriptPciCfg2Read (\r
1436aea4 1600 (S3_BOOT_SCRIPT_LIB_WIDTH)PciCfg2Poll.Width,\r
3a03e95e 1601 PciCfg2Poll.Segment,\r
64d14edf 1602 PciCfg2Poll.Address,\r
30f80497 1603 1,\r
64d14edf 1604 &Data\r
1605 );\r
1436aea4 1606 if ((!EFI_ERROR (Status)) && ((Data & AndMask) == OrMask)) {\r
64d14edf 1607 return EFI_SUCCESS;\r
1608 }\r
1609 }\r
1610\r
1611 if (LoopTimes < PciCfg2Poll.Delay) {\r
1612 return EFI_SUCCESS;\r
1613 } else {\r
1614 return EFI_DEVICE_ERROR;\r
1615 }\r
64d14edf 1616}\r
1617\r
1618/**\r
1619 Executes the S3 boot script table.\r
3a03e95e 1620\r
64d14edf 1621 @retval RETURN_SUCCESS The boot script table was executed successfully.\r
3a03e95e
SZ
1622 @retval RETURN_UNSUPPORTED Invalid script table or opcode.\r
1623\r
64d14edf 1624**/\r
1625RETURN_STATUS\r
1626EFIAPI\r
1627S3BootScriptExecute (\r
1628 VOID\r
1629 )\r
1630{\r
1436aea4
MK
1631 EFI_STATUS Status;\r
1632 UINT8 *Script;\r
1633 UINTN StartAddress;\r
1634 UINT32 TableLength;\r
1635 UINT64 AndMask;\r
1636 UINT64 OrMask;\r
64d14edf 1637 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader;\r
1638 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader;\r
1436aea4 1639\r
64d14edf 1640 Script = mS3BootScriptTablePtr->TableBase;\r
3a03e95e 1641 if (Script != 0) {\r
1436aea4 1642 CopyMem ((VOID *)&TableHeader, Script, sizeof (EFI_BOOT_SCRIPT_TABLE_HEADER));\r
64d14edf 1643 } else {\r
1644 return EFI_INVALID_PARAMETER;\r
1645 }\r
1646\r
87000d77 1647 DEBUG ((DEBUG_INFO, "S3BootScriptExecute:\n"));\r
64d14edf 1648 if (TableHeader.OpCode != S3_BOOT_SCRIPT_LIB_TABLE_OPCODE) {\r
1649 return EFI_UNSUPPORTED;\r
1650 }\r
1651\r
87000d77 1652 DEBUG ((DEBUG_INFO, "TableHeader - 0x%08x\n", Script));\r
3a03e95e 1653\r
1436aea4
MK
1654 StartAddress = (UINTN)Script;\r
1655 TableLength = TableHeader.TableLength;\r
1656 Script = Script + TableHeader.Length;\r
1657 Status = EFI_SUCCESS;\r
1658 AndMask = 0;\r
1659 OrMask = 0;\r
64d14edf 1660\r
87000d77
MK
1661 DEBUG ((DEBUG_INFO, "TableHeader.Version - 0x%04x\n", (UINTN)TableHeader.Version));\r
1662 DEBUG ((DEBUG_INFO, "TableHeader.TableLength - 0x%08x\n", (UINTN)TableLength));\r
64d14edf 1663\r
1436aea4 1664 while ((UINTN)Script < (UINTN)(StartAddress + TableLength)) {\r
87000d77 1665 DEBUG ((DEBUG_INFO, "ExecuteBootScript - %08x\n", (UINTN)Script));\r
3a03e95e 1666\r
1436aea4 1667 CopyMem ((VOID *)&ScriptHeader, Script, sizeof (EFI_BOOT_SCRIPT_COMMON_HEADER));\r
64d14edf 1668 switch (ScriptHeader.OpCode) {\r
1436aea4
MK
1669 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE:\r
1670 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE\n"));\r
1671 Status = BootScriptExecuteMemoryWrite (Script);\r
1672 break;\r
64d14edf 1673\r
1436aea4
MK
1674 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE:\r
1675 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE\n"));\r
1676 CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
1677 Status = BootScriptExecuteMemoryReadWrite (\r
1678 Script,\r
1679 AndMask,\r
1680 OrMask\r
1681 );\r
1682 break;\r
64d14edf 1683\r
1436aea4
MK
1684 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE:\r
1685 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_IO_WRITE_OPCODE\n"));\r
1686 Status = BootScriptExecuteIoWrite (Script);\r
1687 break;\r
64d14edf 1688\r
1436aea4
MK
1689 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE:\r
1690 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE\n"));\r
1691 Status = BootScriptExecutePciCfgWrite (Script);\r
1692 break;\r
64d14edf 1693\r
1436aea4
MK
1694 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE:\r
1695 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE\n"));\r
1696 CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
1697 Status = BootScriptExecutePciCfgReadWrite (\r
1698 Script,\r
1699 AndMask,\r
1700 OrMask\r
1701 );\r
1702 break;\r
1703 case EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE:\r
1704 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE\n"));\r
1705 Status = BootScriptExecutePciCfg2Write (Script);\r
1706 break;\r
64d14edf 1707\r
1436aea4
MK
1708 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE:\r
1709 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE\n"));\r
1710 CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
1711 Status = BootScriptExecutePciCfg2ReadWrite (\r
1712 Script,\r
1713 AndMask,\r
1714 OrMask\r
1715 );\r
1716 break;\r
1717 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE:\r
1718 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_DISPATCH_OPCODE\n"));\r
1719 Status = BootScriptExecuteDispatch (Script);\r
1720 break;\r
64d14edf 1721\r
1436aea4
MK
1722 case EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE:\r
1723 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE\n"));\r
1724 Status = BootScriptExecuteDispatch2 (Script);\r
1725 break;\r
64d14edf 1726\r
1436aea4
MK
1727 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE:\r
1728 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_INFORMATION_OPCODE\n"));\r
1729 BootScriptExecuteInformation (Script);\r
1730 break;\r
64d14edf 1731\r
1436aea4
MK
1732 case S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE:\r
1733 DEBUG ((DEBUG_INFO, "S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE\n"));\r
1734 DEBUG ((DEBUG_INFO, "S3BootScriptDone - %r\n", EFI_SUCCESS));\r
1735 return EFI_SUCCESS;\r
1736\r
1737 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE:\r
1738 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE\n"));\r
1739 CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
1740 Status = BootScriptExecuteIoReadWrite (\r
1741 Script,\r
1742 AndMask,\r
1743 OrMask\r
1744 );\r
1745 break;\r
64d14edf 1746\r
1436aea4
MK
1747 case EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE:\r
1748 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE\n"));\r
1749 Status = BootScriptExecuteSmbusExecute (Script);\r
1750 break;\r
64d14edf 1751\r
1436aea4
MK
1752 case EFI_BOOT_SCRIPT_STALL_OPCODE:\r
1753 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_STALL_OPCODE\n"));\r
1754 Status = BootScriptExecuteStall (Script);\r
1755 break;\r
64d14edf 1756\r
1436aea4
MK
1757 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE:\r
1758 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_MEM_POLL_OPCODE\n"));\r
1759 CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
1760 Status = BootScriptExecuteMemPoll (Script, AndMask, OrMask);\r
64d14edf 1761\r
1436aea4 1762 break;\r
3a03e95e 1763\r
1436aea4
MK
1764 case EFI_BOOT_SCRIPT_IO_POLL_OPCODE:\r
1765 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_IO_POLL_OPCODE\n"));\r
1766 CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
1767 Status = BootScriptExecuteIoPoll (Script, AndMask, OrMask);\r
1768 break;\r
3a03e95e 1769\r
1436aea4
MK
1770 case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE:\r
1771 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE\n"));\r
1772 CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
1773 Status = BootScriptPciCfgPoll (Script, AndMask, OrMask);\r
1774 break;\r
3a03e95e 1775\r
1436aea4
MK
1776 case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE:\r
1777 DEBUG ((DEBUG_INFO, "EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE\n"));\r
1778 CheckAndOrMask (&ScriptHeader, &AndMask, &OrMask, Script);\r
1779 Status = BootScriptPciCfg2Poll (Script, AndMask, OrMask);\r
1780 break;\r
3a03e95e 1781\r
1436aea4
MK
1782 case S3_BOOT_SCRIPT_LIB_LABEL_OPCODE:\r
1783 //\r
1784 // For label\r
1785 //\r
1786 DEBUG ((DEBUG_INFO, "S3_BOOT_SCRIPT_LIB_LABEL_OPCODE\n"));\r
1787 BootScriptExecuteLabel (Script);\r
1788 break;\r
1789 default:\r
1790 DEBUG ((DEBUG_INFO, "S3BootScriptDone - %r\n", EFI_UNSUPPORTED));\r
1791 return EFI_UNSUPPORTED;\r
64d14edf 1792 }\r
1793\r
1794 if (EFI_ERROR (Status)) {\r
87000d77 1795 DEBUG ((DEBUG_INFO, "S3BootScriptDone - %r\n", Status));\r
64d14edf 1796 return Status;\r
1797 }\r
1798\r
1436aea4 1799 Script = Script + ScriptHeader.Length;\r
64d14edf 1800 }\r
1801\r
87000d77 1802 DEBUG ((DEBUG_INFO, "S3BootScriptDone - %r\n", Status));\r
64d14edf 1803\r
1804 return Status;\r
1805}\r