2 Interpret and execute the S3 data in S3 boot script.
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "InternalBootScriptLib.h"
19 Executes an SMBus operation to an SMBus controller. Returns when either the command has been
20 executed or an error is encountered in doing the operation.
22 The SmbusExecute() function provides a standard way to execute an operation as defined in the System
23 Management Bus (SMBus) Specification. The resulting transaction will be either that the SMBus
24 slave devices accept this transaction or that this function returns with error.
26 @param SmbusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length,
28 @param Operation Signifies which particular SMBus hardware protocol instance that
29 it will use to execute the SMBus transactions. This SMBus
30 hardware protocol is defined by the SMBus Specification and is
32 @param Length Signifies the number of bytes that this operation will do. The
33 maximum number of bytes can be revision specific and operation
34 specific. This field will contain the actual number of bytes that
35 are executed for this operation. Not all operations require this
37 @param Buffer Contains the value of data to execute to the SMBus slave device.
38 Not all operations require this argument. The length of this
39 buffer is identified by Length.
41 @retval EFI_SUCCESS The last data that was returned from the access matched the poll
43 @retval EFI_CRC_ERROR Checksum is not correct (PEC is incorrect).
44 @retval EFI_TIMEOUT Timeout expired before the operation was completed. Timeout is
45 determined by the SMBus host controller device.
46 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
47 @retval EFI_DEVICE_ERROR The request was not completed because a failure that was
48 reflected in the Host Status Register bit. Device errors are a
49 result of a transaction collision, illegal command field,
50 unclaimed cycle (host initiated), or bus errors (collisions).
51 @retval EFI_INVALID_PARAMETER Operation is not defined in EFI_SMBUS_OPERATION.
52 @retval EFI_INVALID_PARAMETER Length/Buffer is NULL for operations except for EfiSmbusQuickRead
53 and EfiSmbusQuickWrite. Length is outside the range of valid
55 @retval EFI_UNSUPPORTED The SMBus operation or PEC is not supported.
56 @retval EFI_BUFFER_TOO_SMALL Buffer is not sufficient for this operation.
61 IN UINTN SmbusAddress
,
62 IN EFI_SMBUS_OPERATION Operation
,
68 UINT8 WorkBuffer
[MAX_SMBUS_BLOCK_LEN
];
71 case EfiSmbusQuickRead
:
72 DEBUG ((EFI_D_INFO
, "EfiSmbusQuickRead - 0x%08x\n", SmbusAddress
));
73 SmBusQuickRead (SmbusAddress
, &Status
);
75 case EfiSmbusQuickWrite
:
76 DEBUG ((EFI_D_INFO
, "EfiSmbusQuickWrite - 0x%08x\n", SmbusAddress
));
77 SmBusQuickWrite (SmbusAddress
, &Status
);
79 case EfiSmbusReceiveByte
:
80 DEBUG ((EFI_D_INFO
, "EfiSmbusReceiveByte - 0x%08x\n", SmbusAddress
));
81 SmBusReceiveByte (SmbusAddress
, &Status
);
83 case EfiSmbusSendByte
:
84 DEBUG ((EFI_D_INFO
, "EfiSmbusSendByte - 0x%08x (0x%02x)\n", SmbusAddress
, (UINTN
)*(UINT8
*) Buffer
));
85 SmBusSendByte (SmbusAddress
, *(UINT8
*) Buffer
, &Status
);
87 case EfiSmbusReadByte
:
88 DEBUG ((EFI_D_INFO
, "EfiSmbusReadByte - 0x%08x\n", SmbusAddress
));
89 SmBusReadDataByte (SmbusAddress
, &Status
);
91 case EfiSmbusWriteByte
:
92 DEBUG ((EFI_D_INFO
, "EfiSmbusWriteByte - 0x%08x (0x%02x)\n", SmbusAddress
, (UINTN
)*(UINT8
*) Buffer
));
93 SmBusWriteDataByte (SmbusAddress
, *(UINT8
*) Buffer
, &Status
);
95 case EfiSmbusReadWord
:
96 DEBUG ((EFI_D_INFO
, "EfiSmbusReadWord - 0x%08x\n", SmbusAddress
));
97 SmBusReadDataWord (SmbusAddress
, &Status
);
99 case EfiSmbusWriteWord
:
100 DEBUG ((EFI_D_INFO
, "EfiSmbusWriteWord - 0x%08x (0x%04x)\n", SmbusAddress
, (UINTN
)*(UINT16
*) Buffer
));
101 SmBusWriteDataWord (SmbusAddress
, *(UINT16
*) Buffer
, &Status
);
103 case EfiSmbusProcessCall
:
104 DEBUG ((EFI_D_INFO
, "EfiSmbusProcessCall - 0x%08x (0x%04x)\n", SmbusAddress
, (UINTN
)*(UINT16
*) Buffer
));
105 SmBusProcessCall (SmbusAddress
, *(UINT16
*) Buffer
, &Status
);
107 case EfiSmbusReadBlock
:
108 DEBUG ((EFI_D_INFO
, "EfiSmbusReadBlock - 0x%08x\n", SmbusAddress
));
109 SmBusReadBlock (SmbusAddress
, WorkBuffer
, &Status
);
111 case EfiSmbusWriteBlock
:
112 DEBUG ((EFI_D_INFO
, "EfiSmbusWriteBlock - 0x%08x\n", SmbusAddress
));
113 SmBusWriteBlock ((SmbusAddress
+ SMBUS_LIB_ADDRESS (0, 0, (*Length
), FALSE
)), Buffer
, &Status
);
115 case EfiSmbusBWBRProcessCall
:
116 DEBUG ((EFI_D_INFO
, "EfiSmbusBWBRProcessCall - 0x%08x\n", SmbusAddress
));
117 SmBusBlockProcessCall ((SmbusAddress
+ SMBUS_LIB_ADDRESS (0, 0, (*Length
), FALSE
)), Buffer
, WorkBuffer
, &Status
);
120 return EFI_INVALID_PARAMETER
;
127 Translates boot script width and address stride to MDE library interface.
130 @param Width Width of the operation.
131 @param Address Address of the operation.
132 @param AddressStride Instride for stepping input buffer.
133 @param BufferStride Outstride for stepping output buffer.
135 @retval EFI_SUCCESS Successful translation.
136 @retval EFI_INVALID_PARAMETER Width or Address is invalid.
140 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
142 OUT UINTN
*AddressStride
,
143 OUT UINTN
*BufferStride
148 if (Width
>= S3BootScriptWidthMaximum
) {
149 return EFI_INVALID_PARAMETER
;
152 *AddressStride
= (UINT32
)(1 << (Width
& 0x03));
153 *BufferStride
= *AddressStride
;
155 AlignMask
= *AddressStride
- 1;
156 if ((Address
& AlignMask
) != 0) {
157 return EFI_INVALID_PARAMETER
;
160 if (Width
>= S3BootScriptWidthFifoUint8
&& Width
<= S3BootScriptWidthFifoUint64
) {
164 if (Width
>= S3BootScriptWidthFillUint8
&& Width
<= S3BootScriptWidthFillUint64
) {
172 Perform IO read operation
174 @param[in] Width Width of the operation.
175 @param[in] Address Address of the operation.
176 @param[in] Count Count of the number of accesses to perform.
177 @param[out] Buffer Pointer to the buffer to read from I/O space.
179 @retval EFI_SUCCESS The data was written to the EFI System.
180 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.
182 The Buffer is not aligned for the given Width.
183 Address is outside the legal range of I/O ports.
188 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
199 Out
.Buf
= (UINT8
*) Buffer
;
201 if (Address
> MAX_IO_ADDRESS
) {
202 return EFI_INVALID_PARAMETER
;
205 Status
= BuildLoopData (Width
, Address
, &AddressStride
, &BufferStride
);
206 if (EFI_ERROR (Status
)) {
210 // Loop for each iteration and move the data
212 for (; Count
> 0; Count
--, Address
+= AddressStride
, Out
.Buf
+= BufferStride
) {
215 case S3BootScriptWidthUint8
:
216 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint8 - 0x%08x\n", (UINTN
) Address
));
217 *Out
.Uint8
= IoRead8 ((UINTN
) Address
);
219 case S3BootScriptWidthFifoUint8
:
220 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint8 - 0x%08x\n", (UINTN
) Address
));
221 *Out
.Uint8
= IoRead8 ((UINTN
) Address
);
223 case S3BootScriptWidthFillUint8
:
224 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint8 - 0x%08x\n", (UINTN
) Address
));
225 *Out
.Uint8
= IoRead8 ((UINTN
) Address
);
228 case S3BootScriptWidthUint16
:
229 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint16 - 0x%08x\n", (UINTN
) Address
));
230 *Out
.Uint16
= IoRead16 ((UINTN
) Address
);
232 case S3BootScriptWidthFifoUint16
:
233 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint16 - 0x%08x\n", (UINTN
) Address
));
234 *Out
.Uint16
= IoRead16 ((UINTN
) Address
);
236 case S3BootScriptWidthFillUint16
:
237 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint16 - 0x%08x\n", (UINTN
) Address
));
238 *Out
.Uint16
= IoRead16 ((UINTN
) Address
);
241 case S3BootScriptWidthUint32
:
242 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint32 - 0x%08x\n", (UINTN
) Address
));
243 *Out
.Uint32
= IoRead32 ((UINTN
) Address
);
245 case S3BootScriptWidthFifoUint32
:
246 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint32 - 0x%08x\n", (UINTN
) Address
));
247 *Out
.Uint32
= IoRead32 ((UINTN
) Address
);
249 case S3BootScriptWidthFillUint32
:
250 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint32 - 0x%08x\n", (UINTN
) Address
));
251 *Out
.Uint32
= IoRead32 ((UINTN
) Address
);
254 case S3BootScriptWidthUint64
:
255 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint64 - 0x%08x\n", (UINTN
) Address
));
256 *Out
.Uint64
= IoRead64 ((UINTN
) Address
);
258 case S3BootScriptWidthFifoUint64
:
259 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint64 - 0x%08x\n", (UINTN
) Address
));
260 *Out
.Uint64
= IoRead64 ((UINTN
) Address
);
262 case S3BootScriptWidthFillUint64
:
263 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint64 - 0x%08x\n", (UINTN
) Address
));
264 *Out
.Uint64
= IoRead64 ((UINTN
) Address
);
268 return EFI_INVALID_PARAMETER
;
276 Perform IO write operation
278 @param[in] Width Width of the operation.
279 @param[in] Address Address of the operation.
280 @param[in] Count Count of the number of accesses to perform.
281 @param[in] Buffer Pointer to the buffer to write to I/O space.
283 @retval EFI_SUCCESS The data was written to the EFI System.
284 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.
286 The Buffer is not aligned for the given Width.
287 Address is outside the legal range of I/O ports.
292 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
301 UINT64 OriginalAddress
;
305 In
.Buf
= (UINT8
*) Buffer
;
307 if (Address
> MAX_IO_ADDRESS
) {
308 return EFI_INVALID_PARAMETER
;
311 Status
= BuildLoopData (Width
, Address
, &AddressStride
, &BufferStride
);
312 if (EFI_ERROR (Status
)) {
316 // Loop for each iteration and move the data
318 OriginalAddress
= Address
;
319 OriginalIn
.Buf
= In
.Buf
;
320 for (; Count
> 0; Count
--, Address
+= AddressStride
, In
.Buf
+= BufferStride
) {
322 case S3BootScriptWidthUint8
:
323 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint8 - 0x%08x (0x%02x)\n", (UINTN
)Address
, (UINTN
)*In
.Uint8
));
324 IoWrite8 ((UINTN
) Address
, *In
.Uint8
);
326 case S3BootScriptWidthFifoUint8
:
327 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint8 - 0x%08x (0x%02x)\n", (UINTN
)OriginalAddress
, (UINTN
)*In
.Uint8
));
328 IoWrite8 ((UINTN
) OriginalAddress
, *In
.Uint8
);
330 case S3BootScriptWidthFillUint8
:
331 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint8 - 0x%08x (0x%02x)\n", (UINTN
)Address
, (UINTN
)*OriginalIn
.Uint8
));
332 IoWrite8 ((UINTN
) Address
, *OriginalIn
.Uint8
);
334 case S3BootScriptWidthUint16
:
335 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint16 - 0x%08x (0x%04x)\n", (UINTN
)Address
, (UINTN
)*In
.Uint16
));
336 IoWrite16 ((UINTN
) Address
, *In
.Uint16
);
338 case S3BootScriptWidthFifoUint16
:
339 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint16 - 0x%08x (0x%04x)\n", (UINTN
)OriginalAddress
, (UINTN
)*In
.Uint16
));
340 IoWrite16 ((UINTN
) OriginalAddress
, *In
.Uint16
);
342 case S3BootScriptWidthFillUint16
:
343 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint16 - 0x%08x (0x%04x)\n", (UINTN
)Address
, (UINTN
)*OriginalIn
.Uint16
));
344 IoWrite16 ((UINTN
) Address
, *OriginalIn
.Uint16
);
346 case S3BootScriptWidthUint32
:
347 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint32 - 0x%08x (0x%08x)\n", (UINTN
)Address
, (UINTN
)*In
.Uint32
));
348 IoWrite32 ((UINTN
) Address
, *In
.Uint32
);
350 case S3BootScriptWidthFifoUint32
:
351 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint32 - 0x%08x (0x%08x)\n", (UINTN
)OriginalAddress
, (UINTN
)*In
.Uint32
));
352 IoWrite32 ((UINTN
) OriginalAddress
, *In
.Uint32
);
354 case S3BootScriptWidthFillUint32
:
355 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint32 - 0x%08x (0x%08x)\n", (UINTN
)Address
, (UINTN
)*OriginalIn
.Uint32
));
356 IoWrite32 ((UINTN
) Address
, *OriginalIn
.Uint32
);
358 case S3BootScriptWidthUint64
:
359 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint64 - 0x%08x (0x%016lx)\n", (UINTN
)Address
, *In
.Uint64
));
360 IoWrite64 ((UINTN
) Address
, *In
.Uint64
);
362 case S3BootScriptWidthFifoUint64
:
363 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint64 - 0x%08x (0x%016lx)\n", (UINTN
)OriginalAddress
, *In
.Uint64
));
364 IoWrite64 ((UINTN
) OriginalAddress
, *In
.Uint64
);
366 case S3BootScriptWidthFillUint64
:
367 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint64 - 0x%08x (0x%016lx)\n", (UINTN
)Address
, *OriginalIn
.Uint64
));
368 IoWrite64 ((UINTN
) Address
, *OriginalIn
.Uint64
);
371 return EFI_INVALID_PARAMETER
;
379 Interprete the boot script node with EFI_BOOT_SCRIPT_IO_WRITE OP code.
381 @param Script Pointer to the node which is to be interpreted.
383 @retval EFI_SUCCESS The data was written to the EFI System.
384 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.
386 The Buffer is not aligned for the given Width.
387 Address is outside the legal range of I/O ports.
391 BootScriptExecuteIoWrite (
395 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
399 EFI_BOOT_SCRIPT_IO_WRITE IoWrite
;
401 CopyMem ((VOID
*)&IoWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_IO_WRITE
));
402 Width
= (S3_BOOT_SCRIPT_LIB_WIDTH
) IoWrite
.Width
;
403 Address
= IoWrite
.Address
;
404 Count
= IoWrite
.Count
;
405 Buffer
= Script
+ sizeof (EFI_BOOT_SCRIPT_IO_WRITE
);
407 DEBUG ((EFI_D_INFO
, "BootScriptExecuteIoWrite - 0x%08x, 0x%08x, 0x%08x\n", (UINTN
)Address
, Count
, (UINTN
)Width
));
408 return ScriptIoWrite(Width
, Address
, Count
, Buffer
);
411 Perform memory read operation
413 @param Width Width of the operation.
414 @param Address Address of the operation.
415 @param Count Count of the number of accesses to perform.
416 @param Buffer Pointer to the buffer read from memory.
418 @retval EFI_SUCCESS The data was written to the EFI System.
419 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.
421 The Buffer is not aligned for the given Width.
422 @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count
423 is not valid for this EFI System.
428 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
441 Status
= BuildLoopData (Width
, Address
, &AddressStride
, &BufferStride
);
442 if (EFI_ERROR (Status
)) {
446 // Loop for each iteration and move the data
448 for (; Count
> 0; Count
--, Address
+= AddressStride
, Out
.Buf
+= BufferStride
) {
450 case S3BootScriptWidthUint8
:
451 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint8 - 0x%08x\n", (UINTN
)Address
));
452 *Out
.Uint8
= MmioRead8 ((UINTN
) Address
);
454 case S3BootScriptWidthFifoUint8
:
455 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint8 - 0x%08x\n", (UINTN
)Address
));
456 *Out
.Uint8
= MmioRead8 ((UINTN
) Address
);
458 case S3BootScriptWidthFillUint8
:
459 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint8 - 0x%08x\n", (UINTN
)Address
));
460 *Out
.Uint8
= MmioRead8 ((UINTN
) Address
);
463 case S3BootScriptWidthUint16
:
464 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint16 - 0x%08x\n", (UINTN
)Address
));
465 *Out
.Uint16
= MmioRead16 ((UINTN
) Address
);
467 case S3BootScriptWidthFifoUint16
:
468 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint16 - 0x%08x\n", (UINTN
)Address
));
469 *Out
.Uint16
= MmioRead16 ((UINTN
) Address
);
471 case S3BootScriptWidthFillUint16
:
472 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint16 - 0x%08x\n", (UINTN
)Address
));
473 *Out
.Uint16
= MmioRead16 ((UINTN
) Address
);
476 case S3BootScriptWidthUint32
:
477 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint32 - 0x%08x\n", (UINTN
)Address
));
478 *Out
.Uint32
= MmioRead32 ((UINTN
) Address
);
480 case S3BootScriptWidthFifoUint32
:
481 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint32 - 0x%08x\n", (UINTN
)Address
));
482 *Out
.Uint32
= MmioRead32 ((UINTN
) Address
);
484 case S3BootScriptWidthFillUint32
:
485 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint32 - 0x%08x\n", (UINTN
)Address
));
486 *Out
.Uint32
= MmioRead32 ((UINTN
) Address
);
489 case S3BootScriptWidthUint64
:
490 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint64 - 0x%08x\n", (UINTN
)Address
));
491 *Out
.Uint64
= MmioRead64 ((UINTN
) Address
);
493 case S3BootScriptWidthFifoUint64
:
494 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint64 - 0x%08x\n", (UINTN
)Address
));
495 *Out
.Uint64
= MmioRead64 ((UINTN
) Address
);
497 case S3BootScriptWidthFillUint64
:
498 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint64 - 0x%08x\n", (UINTN
)Address
));
499 *Out
.Uint64
= MmioRead64 ((UINTN
) Address
);
503 return EFI_UNSUPPORTED
;
510 Perform memory write operation
512 @param Width Width of the operation.
513 @param Address Address of the operation.
514 @param Count Count of the number of accesses to perform.
515 @param Buffer Pointer to the buffer write to memory.
517 @retval EFI_SUCCESS The data was written to the EFI System.
518 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.
520 The Buffer is not aligned for the given Width.
521 @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count
522 is not valid for this EFI System.
527 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
535 UINT64 OriginalAddress
;
542 Status
= BuildLoopData (Width
, Address
, &AddressStride
, &BufferStride
);
543 if (EFI_ERROR (Status
)) {
547 // Loop for each iteration and move the data
549 OriginalAddress
= Address
;
550 OriginalIn
.Buf
= In
.Buf
;
551 for (; Count
> 0; Count
--, Address
+= AddressStride
, In
.Buf
+= BufferStride
) {
553 case S3BootScriptWidthUint8
:
554 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint8 - 0x%08x (0x%02x)\n", (UINTN
)Address
, (UINTN
)*In
.Uint8
));
555 MmioWrite8 ((UINTN
) Address
, *In
.Uint8
);
557 case S3BootScriptWidthFifoUint8
:
558 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint8 - 0x%08x (0x%02x)\n", (UINTN
)OriginalAddress
, (UINTN
)*In
.Uint8
));
559 MmioWrite8 ((UINTN
) OriginalAddress
, *In
.Uint8
);
561 case S3BootScriptWidthFillUint8
:
562 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint8 - 0x%08x (0x%02x)\n", (UINTN
)Address
, (UINTN
)*OriginalIn
.Uint8
));
563 MmioWrite8 ((UINTN
) Address
, *OriginalIn
.Uint8
);
565 case S3BootScriptWidthUint16
:
566 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint16 - 0x%08x (0x%04x)\n", (UINTN
)Address
, (UINTN
)*In
.Uint16
));
567 MmioWrite16 ((UINTN
) Address
, *In
.Uint16
);
569 case S3BootScriptWidthFifoUint16
:
570 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint16 - 0x%08x (0x%04x)\n", (UINTN
)OriginalAddress
, (UINTN
)*In
.Uint16
));
571 MmioWrite16 ((UINTN
) OriginalAddress
, *In
.Uint16
);
573 case S3BootScriptWidthFillUint16
:
574 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint16 - 0x%08x (0x%04x)\n", (UINTN
)Address
, (UINTN
)*OriginalIn
.Uint16
));
575 MmioWrite16 ((UINTN
) Address
, *OriginalIn
.Uint16
);
577 case S3BootScriptWidthUint32
:
578 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint32 - 0x%08x (0x%08x)\n", (UINTN
)Address
, (UINTN
)*In
.Uint32
));
579 MmioWrite32 ((UINTN
) Address
, *In
.Uint32
);
581 case S3BootScriptWidthFifoUint32
:
582 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint32 - 0x%08x (0x%08x)\n", (UINTN
)OriginalAddress
, (UINTN
)*In
.Uint32
));
583 MmioWrite32 ((UINTN
) OriginalAddress
, *In
.Uint32
);
585 case S3BootScriptWidthFillUint32
:
586 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint32 - 0x%08x (0x%08x)\n", (UINTN
)Address
, (UINTN
)*OriginalIn
.Uint32
));
587 MmioWrite32 ((UINTN
) Address
, *OriginalIn
.Uint32
);
589 case S3BootScriptWidthUint64
:
590 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint64 - 0x%08x (0x%016lx)\n", (UINTN
)Address
, *In
.Uint64
));
591 MmioWrite64 ((UINTN
) Address
, *In
.Uint64
);
593 case S3BootScriptWidthFifoUint64
:
594 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint64 - 0x%08x (0x%016lx)\n", (UINTN
)OriginalAddress
, *In
.Uint64
));
595 MmioWrite64 ((UINTN
) OriginalAddress
, *In
.Uint64
);
597 case S3BootScriptWidthFillUint64
:
598 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint64 - 0x%08x (0x%016lx)\n", (UINTN
)Address
, *OriginalIn
.Uint64
));
599 MmioWrite64 ((UINTN
) Address
, *OriginalIn
.Uint64
);
602 return EFI_UNSUPPORTED
;
608 Interprete the boot script node with EFI_BOOT_SCRIPT_MEM_WRITE OP code.
610 @param[in] Script Pointer to the node which is to be interpreted.
612 @retval EFI_SUCCESS The data was written to the EFI System.
613 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.
615 The Buffer is not aligned for the given Width.
616 @retval EFI_UNSUPPORTED The address range specified by Address, Width, and Count
617 is not valid for this EFI System.
621 BootScriptExecuteMemoryWrite (
626 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
629 EFI_BOOT_SCRIPT_MEM_WRITE MemWrite
;
631 CopyMem((VOID
*)&MemWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_MEM_WRITE
));
632 Width
= (S3_BOOT_SCRIPT_LIB_WIDTH
)MemWrite
.Width
;
633 Address
= MemWrite
.Address
;
634 Count
= MemWrite
.Count
;
635 Buffer
= Script
+ sizeof(EFI_BOOT_SCRIPT_MEM_WRITE
);
637 DEBUG ((EFI_D_INFO
, "BootScriptExecuteMemoryWrite - 0x%08x, 0x%08x, 0x%08x\n", (UINTN
)Address
, Count
, (UINTN
)Width
));
638 return ScriptMemoryWrite (Width
,Address
, Count
, Buffer
);
642 Performance PCI configuration 2 read operation
644 @param Width Width of the operation.
645 @param Segment Pci segment number
646 @param Address Address of the operation.
647 @param Count Count of the number of accesses to perform.
648 @param Buffer Pointer to the buffer read from PCI config space
650 @retval EFI_SUCCESS The read succeed.
651 @retval EFI_INVALID_PARAMETER if Width is not defined
652 @note A known Limitations in the implementation which is 64bits operations are not supported.
657 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
670 Out
.Buf
= (UINT8
*) Buffer
;
672 PciAddress
= PCI_ADDRESS_ENCODE (Segment
, Address
);
674 Status
= BuildLoopData (Width
, PciAddress
, &AddressStride
, &BufferStride
);
675 if (EFI_ERROR (Status
)) {
679 // Loop for each iteration and move the data
681 for (; Count
> 0; Count
--, PciAddress
+= AddressStride
, Out
.Buf
+= BufferStride
) {
683 case S3BootScriptWidthUint8
:
684 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint8 - 0x%016lx\n", PciAddress
));
685 *Out
.Uint8
= PciSegmentRead8 (PciAddress
);
687 case S3BootScriptWidthFifoUint8
:
688 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint8 - 0x%016lx\n", PciAddress
));
689 *Out
.Uint8
= PciSegmentRead8 (PciAddress
);
691 case S3BootScriptWidthFillUint8
:
692 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint8 - 0x%016lx\n", PciAddress
));
693 *Out
.Uint8
= PciSegmentRead8 (PciAddress
);
696 case S3BootScriptWidthUint16
:
697 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint16 - 0x%016lx\n", PciAddress
));
698 *Out
.Uint16
= PciSegmentRead16 (PciAddress
);
700 case S3BootScriptWidthFifoUint16
:
701 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint16 - 0x%016lx\n", PciAddress
));
702 *Out
.Uint16
= PciSegmentRead16 (PciAddress
);
704 case S3BootScriptWidthFillUint16
:
705 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint16 - 0x%016lx\n", PciAddress
));
706 *Out
.Uint16
= PciSegmentRead16 (PciAddress
);
709 case S3BootScriptWidthUint32
:
710 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint32 - 0x%016lx\n", PciAddress
));
711 *Out
.Uint32
= PciSegmentRead32 (PciAddress
);
713 case S3BootScriptWidthFifoUint32
:
714 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint32 - 0x%016lx\n", PciAddress
));
715 *Out
.Uint32
= PciSegmentRead32 (PciAddress
);
717 case S3BootScriptWidthFillUint32
:
718 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint32 - 0x%016lx\n", PciAddress
));
719 *Out
.Uint32
= PciSegmentRead32 (PciAddress
);
723 return EFI_INVALID_PARAMETER
;
730 Performance PCI configuration 2 write operation
732 @param Width Width of the operation.
733 @param Segment Pci segment number
734 @param Address Address of the operation.
735 @param Count Count of the number of accesses to perform.
736 @param Buffer Pointer to the buffer write to PCI config space
738 @retval EFI_SUCCESS The write succeed.
739 @retval EFI_INVALID_PARAMETER if Width is not defined
740 @note A known Limitations in the implementation which is 64bits operations are not supported.
745 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
755 UINT64 OriginalPciAddress
;
760 In
.Buf
= (UINT8
*) Buffer
;
762 PciAddress
= PCI_ADDRESS_ENCODE (Segment
, Address
);
764 Status
= BuildLoopData (Width
, PciAddress
, &AddressStride
, &BufferStride
);
765 if (EFI_ERROR (Status
)) {
769 // Loop for each iteration and move the data
771 OriginalPciAddress
= PciAddress
;
772 OriginalIn
.Buf
= In
.Buf
;
773 for (; Count
> 0; Count
--, PciAddress
+= AddressStride
, In
.Buf
+= BufferStride
) {
775 case S3BootScriptWidthUint8
:
776 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint8 - 0x%016lx (0x%02x)\n", PciAddress
, (UINTN
)*In
.Uint8
));
777 PciSegmentWrite8 (PciAddress
, *In
.Uint8
);
779 case S3BootScriptWidthFifoUint8
:
780 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint8 - 0x%016lx (0x%02x)\n", OriginalPciAddress
, (UINTN
)*In
.Uint8
));
781 PciSegmentWrite8 (OriginalPciAddress
, *In
.Uint8
);
783 case S3BootScriptWidthFillUint8
:
784 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint8 - 0x%016lx (0x%02x)\n", PciAddress
, (UINTN
)*OriginalIn
.Uint8
));
785 PciSegmentWrite8 (PciAddress
, *OriginalIn
.Uint8
);
787 case S3BootScriptWidthUint16
:
788 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint16 - 0x%016lx (0x%04x)\n", PciAddress
, (UINTN
)*In
.Uint16
));
789 PciSegmentWrite16 (PciAddress
, *In
.Uint16
);
791 case S3BootScriptWidthFifoUint16
:
792 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint16 - 0x%016lx (0x%04x)\n", OriginalPciAddress
, (UINTN
)*In
.Uint16
));
793 PciSegmentWrite16 (OriginalPciAddress
, *In
.Uint16
);
795 case S3BootScriptWidthFillUint16
:
796 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint16 - 0x%016lx (0x%04x)\n", PciAddress
, (UINTN
)*OriginalIn
.Uint16
));
797 PciSegmentWrite16 (PciAddress
, *OriginalIn
.Uint16
);
799 case S3BootScriptWidthUint32
:
800 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint32 - 0x%016lx (0x%08x)\n", PciAddress
, (UINTN
)*In
.Uint32
));
801 PciSegmentWrite32 (PciAddress
, *In
.Uint32
);
803 case S3BootScriptWidthFifoUint32
:
804 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint32 - 0x%016lx (0x%08x)\n", OriginalPciAddress
, (UINTN
)*In
.Uint32
));
805 PciSegmentWrite32 (OriginalPciAddress
, *In
.Uint32
);
807 case S3BootScriptWidthFillUint32
:
808 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint32 - 0x%016lx (0x%08x)\n", (UINTN
)PciAddress
, (UINTN
)*OriginalIn
.Uint32
));
809 PciSegmentWrite32 (PciAddress
, *OriginalIn
.Uint32
);
812 return EFI_INVALID_PARAMETER
;
818 Performance PCI configuration read operation
820 @param Width Width of the operation.
821 @param Address Address of the operation.
822 @param Count Count of the number of accesses to perform.
823 @param Buffer Pointer to the buffer to read from PCI config space.
825 @retval EFI_SUCCESS The data was written to the EFI System.
826 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.
828 The Buffer is not aligned for the given Width.
829 Address is outside the legal range of I/O ports.
834 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
840 return ScriptPciCfg2Read (Width
, 0, Address
, Count
, Buffer
);
843 Performance PCI configuration write operation
845 @param Width Width of the operation.
846 @param Address Address of the operation.
847 @param Count Count of the number of accesses to perform.
848 @param Buffer Pointer to the buffer to write to PCI config space.
850 @retval EFI_SUCCESS The data was written to the EFI System.
851 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.
853 The Buffer is not aligned for the given Width.
854 Address is outside the legal range of I/O ports.
860 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
866 return ScriptPciCfg2Write (Width
, 0, Address
, Count
, Buffer
);
869 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE OP code.
871 @param Script The pointer of typed node in boot script table
873 @retval EFI_SUCCESS The operation was executed successfully
876 BootScriptExecutePciCfgWrite (
881 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
884 EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE PciCfgWrite
;
886 CopyMem ((VOID
*)&PciCfgWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
));
888 Width
= (S3_BOOT_SCRIPT_LIB_WIDTH
)PciCfgWrite
.Width
;
889 Address
= PciCfgWrite
.Address
;
890 Count
= PciCfgWrite
.Count
;
891 Buffer
= Script
+ sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
);
893 DEBUG ((EFI_D_INFO
, "BootScriptExecutePciCfgWrite - 0x%016lx, 0x%08x, 0x%08x\n", PCI_ADDRESS_ENCODE (0, Address
), Count
, (UINTN
)Width
));
894 return ScriptPciCfgWrite (Width
, Address
, Count
, Buffer
);
897 Interprete the boot script node with EFI_BOOT_SCRIPT_IO_READ_WRITE OP code.
899 @param Script The pointer of typed node in boot script table
900 @param AndMask Mask value for 'and' operation
901 @param OrMask Mask value for 'or' operation
903 @retval EFI_SUCCESS The operation was executed successfully
906 BootScriptExecuteIoReadWrite (
915 EFI_BOOT_SCRIPT_IO_READ_WRITE IoReadWrite
;
919 CopyMem((VOID
*)&IoReadWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_IO_READ_WRITE
));
921 DEBUG ((EFI_D_INFO
, "BootScriptExecuteIoReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN
)IoReadWrite
.Address
, AndMask
, OrMask
));
923 Status
= ScriptIoRead (
924 (S3_BOOT_SCRIPT_LIB_WIDTH
) IoReadWrite
.Width
,
929 if (!EFI_ERROR (Status
)) {
930 Data
= (Data
& AndMask
) | OrMask
;
931 Status
= ScriptIoWrite (
932 (S3_BOOT_SCRIPT_LIB_WIDTH
) IoReadWrite
.Width
,
941 Interprete the boot script node with EFI_BOOT_SCRIPT_MEM_READ_WRITE OP code.
943 @param Script The pointer of typed node in boot script table
944 @param AndMask Mask value for 'and' operation
945 @param OrMask Mask value for 'or' operation
947 @retval EFI_SUCCESS The operation was executed successfully
950 BootScriptExecuteMemoryReadWrite (
959 EFI_BOOT_SCRIPT_MEM_READ_WRITE MemReadWrite
;
963 CopyMem((VOID
*)&MemReadWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_MEM_READ_WRITE
));
965 DEBUG ((EFI_D_INFO
, "BootScriptExecuteMemoryReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN
)MemReadWrite
.Address
, AndMask
, OrMask
));
967 Status
= ScriptMemoryRead (
968 (S3_BOOT_SCRIPT_LIB_WIDTH
) MemReadWrite
.Width
,
969 MemReadWrite
.Address
,
973 if (!EFI_ERROR (Status
)) {
974 Data
= (Data
& AndMask
) | OrMask
;
975 Status
= ScriptMemoryWrite (
976 (S3_BOOT_SCRIPT_LIB_WIDTH
) MemReadWrite
.Width
,
977 MemReadWrite
.Address
,
985 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CFG_READ_WRITE OP code.
987 @param Script The pointer of typed node in boot script table
988 @param AndMask Mask value for 'and' operation
989 @param OrMask Mask value for 'or' operation
991 @retval EFI_SUCCESS The operation was executed successfully
994 BootScriptExecutePciCfgReadWrite (
1003 EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE PciCfgReadWrite
;
1007 CopyMem((VOID
*)&PciCfgReadWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
));
1009 DEBUG ((EFI_D_INFO
, "BootScriptExecutePciCfgReadWrite - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (0, PciCfgReadWrite
.Address
), AndMask
, OrMask
));
1011 Status
= ScriptPciCfgRead (
1012 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfgReadWrite
.Width
,
1013 PciCfgReadWrite
.Address
,
1017 if (EFI_ERROR (Status
)) {
1021 Data
= (Data
& AndMask
) | OrMask
;
1023 Status
= ScriptPciCfgWrite (
1024 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfgReadWrite
.Width
,
1025 PciCfgReadWrite
.Address
,
1033 Interprete the boot script node with EFI_BOOT_SCRIPT_SMBUS_EXECUTE OP code.
1035 @param Script The pointer of typed node in boot script table
1037 @retval EFI_SUCCESS The operation was executed successfully
1038 @retval EFI_UNSUPPORTED Cannot locate smbus ppi or occur error of script execution
1039 @retval Others Result of script execution
1042 BootScriptExecuteSmbusExecute (
1048 EFI_BOOT_SCRIPT_SMBUS_EXECUTE SmbusExecuteEntry
;
1050 CopyMem ((VOID
*)&SmbusExecuteEntry
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_SMBUS_EXECUTE
));
1052 DEBUG ((EFI_D_INFO
, "BootScriptExecuteSmbusExecute - 0x%08x, 0x%08x\n", (UINTN
)SmbusExecuteEntry
.SmBusAddress
, (UINTN
)SmbusExecuteEntry
.Operation
));
1054 SmBusAddress
= (UINTN
)SmbusExecuteEntry
.SmBusAddress
;
1055 DataSize
= (UINTN
) SmbusExecuteEntry
.DataSize
;
1056 return SmbusExecute (
1058 (EFI_SMBUS_OPERATION
) SmbusExecuteEntry
.Operation
,
1060 Script
+ sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
)
1064 Interprete the boot script node with EFI_BOOT_SCRIPT_STALL OP code.
1066 @param Script The pointer of typed node in boot script table
1068 @retval EFI_SUCCESS The operation was executed successfully
1071 BootScriptExecuteStall (
1075 EFI_BOOT_SCRIPT_STALL Stall
;
1077 CopyMem ((VOID
*)&Stall
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_STALL
));
1079 DEBUG ((EFI_D_INFO
, "BootScriptExecuteStall - 0x%08x\n", (UINTN
)Stall
.Duration
));
1081 MicroSecondDelay ((UINTN
) Stall
.Duration
);
1085 Interprete the boot script node with EFI_BOOT_SCRIPT_DISPATCH OP code.
1087 @param Script The pointer of typed node in boot script table
1088 @retval EFI_SUCCESS The operation was executed successfully
1091 BootScriptExecuteDispatch (
1096 DISPATCH_ENTRYPOINT_FUNC EntryFunc
;
1097 EFI_BOOT_SCRIPT_DISPATCH ScriptDispatch
;
1099 CopyMem ((VOID
*)&ScriptDispatch
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_DISPATCH
));
1100 EntryFunc
= (DISPATCH_ENTRYPOINT_FUNC
) (UINTN
) (ScriptDispatch
.EntryPoint
);
1102 DEBUG ((EFI_D_INFO
, "BootScriptExecuteDispatch - 0x%08x\n", (UINTN
)ScriptDispatch
.EntryPoint
));
1104 Status
= EntryFunc (NULL
, NULL
);
1109 Interprete the boot script node with EFI_BOOT_SCRIPT_DISPATCH_2 OP code.
1111 @param Script The pointer of typed node in boot script table
1112 @retval EFI_SUCCESS The operation was executed successfully
1115 BootScriptExecuteDispatch2 (
1120 DISPATCH_ENTRYPOINT_FUNC EntryFunc
;
1121 EFI_BOOT_SCRIPT_DISPATCH_2 ScriptDispatch2
;
1123 CopyMem ((VOID
*)&ScriptDispatch2
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_DISPATCH_2
));
1125 DEBUG ((EFI_D_INFO
, "BootScriptExecuteDispatch2 - 0x%08x(0x%08x)\n", (UINTN
)ScriptDispatch2
.EntryPoint
, (UINTN
)ScriptDispatch2
.Context
));
1127 EntryFunc
= (DISPATCH_ENTRYPOINT_FUNC
) (UINTN
) (ScriptDispatch2
.EntryPoint
);
1129 Status
= EntryFunc (NULL
, (VOID
*) (UINTN
) ScriptDispatch2
.Context
);
1134 Interprete the boot script node with EFI_BOOT_SCRIPT_MEM_POLL OP code.
1136 @param Script The pointer of typed node in boot script table
1137 @param AndMask Mask value for 'and' operation
1138 @param OrMask Mask value for 'or' operation
1140 @retval EFI_DEVICE_ERROR Data polled from memory does not equal to
1141 the epecting data within the Loop Times.
1142 @retval EFI_SUCCESS The operation was executed successfully
1145 BootScriptExecuteMemPoll (
1155 EFI_BOOT_SCRIPT_MEM_POLL MemPoll
;
1157 CopyMem ((VOID
*)&MemPoll
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_MEM_POLL
));
1159 DEBUG ((EFI_D_INFO
, "BootScriptExecuteMemPoll - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN
)MemPoll
.Address
, AndMask
, OrMask
));
1162 Status
= ScriptMemoryRead (
1163 (S3_BOOT_SCRIPT_LIB_WIDTH
) MemPoll
.Width
,
1168 if ((!EFI_ERROR (Status
)) && (Data
& AndMask
) == OrMask
) {
1172 for (LoopTimes
= 0; LoopTimes
< MemPoll
.LoopTimes
; LoopTimes
++) {
1173 MicroSecondDelay ((UINTN
)MemPoll
.Duration
);
1176 Status
= ScriptMemoryRead (
1177 (S3_BOOT_SCRIPT_LIB_WIDTH
) MemPoll
.Width
,
1182 if ((!EFI_ERROR (Status
)) && (Data
& AndMask
) == OrMask
) {
1187 if (LoopTimes
< MemPoll
.LoopTimes
) {
1190 return EFI_DEVICE_ERROR
;
1194 Execute the boot script to interpret the Store arbitrary information.
1195 This opcode is a no-op on dispatch and is only used for debugging script issues.
1197 @param Script The pointer of node in boot script table
1201 BootScriptExecuteInformation (
1207 EFI_BOOT_SCRIPT_INFORMATION Information
;
1208 UINT8
*InformationData
;
1210 CopyMem ((VOID
*)&Information
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_INFORMATION
));
1212 InformationData
= Script
+ sizeof (EFI_BOOT_SCRIPT_INFORMATION
);
1213 DEBUG ((EFI_D_INFO
, "BootScriptExecuteInformation - 0x%08x\n", (UINTN
) InformationData
));
1215 DEBUG ((EFI_D_INFO
, "BootScriptInformation: "));
1216 for (Index
= 0; Index
< Information
.InformationLength
; Index
++) {
1217 DEBUG ((EFI_D_INFO
, "%02x ", InformationData
[Index
]));
1219 DEBUG ((EFI_D_INFO
, "\n"));
1223 Execute the boot script to interpret the Label information.
1225 @param Script The pointer of node in boot script table
1229 BootScriptExecuteLabel (
1235 EFI_BOOT_SCRIPT_INFORMATION Information
;
1236 UINT8
*InformationData
;
1238 CopyMem ((VOID
*)&Information
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_INFORMATION
));
1240 InformationData
= Script
+ sizeof (EFI_BOOT_SCRIPT_INFORMATION
);
1241 DEBUG ((EFI_D_INFO
, "BootScriptExecuteLabel - 0x%08x\n", (UINTN
) InformationData
));
1243 DEBUG ((EFI_D_INFO
, "BootScriptLabel: "));
1244 for (Index
= 0; Index
< Information
.InformationLength
; Index
++) {
1245 DEBUG ((EFI_D_INFO
, "%02x ", InformationData
[Index
]));
1247 DEBUG ((EFI_D_INFO
, "\n"));
1251 calculate the mask value for 'and' and 'or' operation
1252 @param ScriptHeader The pointer of header of node in boot script table
1253 @param AndMask The Mask value for 'and' operation
1254 @param OrMask The Mask value for 'or' operation
1255 @param Script Pointer to the entry.
1260 IN EFI_BOOT_SCRIPT_COMMON_HEADER
*ScriptHeader
,
1261 OUT UINT64
*AndMask
,
1269 switch (ScriptHeader
->OpCode
) {
1270 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
:
1271 Size
= sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
);
1274 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
:
1275 Size
= sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
);
1278 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
:
1279 Size
= sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
);
1281 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
:
1282 Size
= sizeof (EFI_BOOT_SCRIPT_MEM_POLL
);
1285 case EFI_BOOT_SCRIPT_IO_POLL_OPCODE
:
1286 Size
= sizeof (EFI_BOOT_SCRIPT_IO_POLL
);
1289 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
:
1290 Size
= sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
);
1293 case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE
:
1294 Size
= sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
);
1297 case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE
:
1298 Size
= sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
);
1305 DataPtr
= Script
+ Size
;
1307 switch (ScriptHeader
->Width
) {
1308 case S3BootScriptWidthUint8
:
1309 *AndMask
= (UINT64
) (*(UINT8
*) (DataPtr
+ 1));
1310 *OrMask
= (UINT64
) (*DataPtr
);
1313 case S3BootScriptWidthUint16
:
1314 *AndMask
= (UINT64
) (*(UINT16
*) (DataPtr
+ 2));
1315 *OrMask
= (UINT64
) (*(UINT16
*) DataPtr
);
1318 case S3BootScriptWidthUint32
:
1319 *AndMask
= (UINT64
) (*(UINT32
*) (DataPtr
+ 4));
1320 *OrMask
= (UINT64
) (*(UINT32
*) DataPtr
);
1323 case S3BootScriptWidthUint64
:
1324 *AndMask
= (UINT64
) (*(UINT64
*) (DataPtr
+ 8));
1325 *OrMask
= (UINT64
) (*(UINT64
*) DataPtr
);
1335 Interprete the boot script node with EFI_BOOT_SCRIPT_IO_POLL OP code.
1337 @param Script The pointer of typed node in boot script table
1338 @param AndMask Mask value for 'and' operation
1339 @param OrMask Mask value for 'or' operation
1341 @retval EFI_DEVICE_ERROR Data polled from memory does not equal to
1342 the epecting data within the Loop Times.
1343 @retval EFI_SUCCESS The operation was executed successfully
1346 BootScriptExecuteIoPoll (
1355 EFI_BOOT_SCRIPT_IO_POLL IoPoll
;
1357 CopyMem ((VOID
*)&IoPoll
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_IO_POLL
));
1359 DEBUG ((EFI_D_INFO
, "BootScriptExecuteIoPoll - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN
)IoPoll
.Address
, AndMask
, OrMask
));
1362 Status
= ScriptIoRead (
1363 (S3_BOOT_SCRIPT_LIB_WIDTH
) IoPoll
.Width
,
1368 if ((!EFI_ERROR (Status
)) && (Data
& AndMask
) == OrMask
) {
1371 for (LoopTimes
= 0; LoopTimes
< IoPoll
.Delay
; LoopTimes
++) {
1372 NanoSecondDelay (100);
1374 Status
= ScriptIoRead (
1375 (S3_BOOT_SCRIPT_LIB_WIDTH
) IoPoll
.Width
,
1380 if ((!EFI_ERROR (Status
)) &&(Data
& AndMask
) == OrMask
) {
1385 if (LoopTimes
< IoPoll
.Delay
) {
1388 return EFI_DEVICE_ERROR
;
1392 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE OP code.
1394 @param Script The pointer of S3 boot script
1396 @retval EFI_SUCCESS The operation was executed successfully
1400 BootScriptExecutePciCfg2Write (
1405 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
1409 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE PciCfg2Write
;
1411 CopyMem ((VOID
*)&PciCfg2Write
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
));
1413 Width
= (S3_BOOT_SCRIPT_LIB_WIDTH
)PciCfg2Write
.Width
;
1414 Segment
= PciCfg2Write
.Segment
;
1415 Address
= PciCfg2Write
.Address
;
1416 Count
= PciCfg2Write
.Count
;
1417 Buffer
= Script
+ sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
);
1419 DEBUG ((EFI_D_INFO
, "BootScriptExecutePciCfg2Write - 0x%016lx, 0x%08x, 0x%08x\n", PCI_ADDRESS_ENCODE (Segment
, Address
), Count
, (UINTN
)Width
));
1420 return ScriptPciCfg2Write (Width
, Segment
, Address
, Count
, Buffer
);
1425 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE OP code.
1427 @param Script The pointer of S3 boot script
1428 @param AndMask Mask value for 'and' operation
1429 @param OrMask Mask value for 'or' operation
1431 @retval EFI_SUCCESS The operation was executed successfully
1435 BootScriptExecutePciCfg2ReadWrite (
1443 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE PciCfg2ReadWrite
;
1447 CopyMem ((VOID
*)&PciCfg2ReadWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
));
1449 DEBUG ((EFI_D_INFO
, "BootScriptExecutePciCfg2ReadWrite - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfg2ReadWrite
.Segment
, PciCfg2ReadWrite
.Address
), AndMask
, OrMask
));
1451 Status
= ScriptPciCfg2Read (
1452 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfg2ReadWrite
.Width
,
1453 PciCfg2ReadWrite
.Segment
,
1454 PciCfg2ReadWrite
.Address
,
1458 if (EFI_ERROR (Status
)) {
1462 Data
= (Data
& AndMask
) | OrMask
;
1463 Status
= ScriptPciCfg2Write (
1464 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfg2ReadWrite
.Width
,
1465 PciCfg2ReadWrite
.Segment
,
1466 PciCfg2ReadWrite
.Address
,
1473 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG_POLL OP code.
1475 @param Script The pointer of S3 boot script
1476 @param AndMask Mask value for 'and' operation
1477 @param OrMask Mask value for 'or' operation
1479 @retval EFI_SUCCESS The operation was executed successfully
1480 @retval EFI_DEVICE_ERROR Data polled from Pci configuration space does not equal to
1481 epecting data within the Loop Times.
1484 BootScriptPciCfgPoll (
1493 EFI_BOOT_SCRIPT_PCI_CONFIG_POLL PciCfgPoll
;
1494 CopyMem ((VOID
*)&PciCfgPoll
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
));
1496 DEBUG ((EFI_D_INFO
, "BootScriptPciCfgPoll - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (0, PciCfgPoll
.Address
), AndMask
, OrMask
));
1499 Status
= ScriptPciCfgRead (
1500 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfgPoll
.Width
,
1505 if ((!EFI_ERROR (Status
)) &&(Data
& AndMask
) == OrMask
) {
1509 for (LoopTimes
= 0; LoopTimes
< PciCfgPoll
.Delay
; LoopTimes
++) {
1510 NanoSecondDelay (100);
1512 Status
= ScriptPciCfgRead (
1513 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfgPoll
.Width
,
1518 if ((!EFI_ERROR (Status
)) &&
1519 (Data
& AndMask
) == OrMask
) {
1524 if (LoopTimes
< PciCfgPoll
.Delay
) {
1527 return EFI_DEVICE_ERROR
;
1532 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL OP code.
1534 @param Script The pointer of S3 Boot Script
1535 @param AndMask Mask value for 'and' operation
1536 @param OrMask Mask value for 'or' operation
1538 @retval EFI_SUCCESS The operation was executed successfully
1539 @retval EFI_DEVICE_ERROR Data polled from Pci configuration space does not equal to
1540 epecting data within the Loop Times.
1544 BootScriptPciCfg2Poll (
1553 EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL PciCfg2Poll
;
1556 CopyMem ((VOID
*)&PciCfg2Poll
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
));
1558 DEBUG ((EFI_D_INFO
, "BootScriptPciCfg2Poll - 0x%016lx, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfg2Poll
.Segment
, PciCfg2Poll
.Address
), AndMask
, OrMask
));
1560 Status
= ScriptPciCfg2Read (
1561 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfg2Poll
.Width
,
1562 PciCfg2Poll
.Segment
,
1563 PciCfg2Poll
.Address
,
1567 if ((!EFI_ERROR (Status
)) && (Data
& AndMask
) == OrMask
) {
1571 for (LoopTimes
= 0; LoopTimes
< PciCfg2Poll
.Delay
; LoopTimes
++) {
1572 NanoSecondDelay (100);
1575 Status
= ScriptPciCfg2Read (
1576 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfg2Poll
.Width
,
1577 PciCfg2Poll
.Segment
,
1578 PciCfg2Poll
.Address
,
1582 if ((!EFI_ERROR (Status
)) && (Data
& AndMask
) == OrMask
) {
1587 if (LoopTimes
< PciCfg2Poll
.Delay
) {
1590 return EFI_DEVICE_ERROR
;
1596 Executes the S3 boot script table.
1598 @retval RETURN_SUCCESS The boot script table was executed successfully.
1599 @retval RETURN_UNSUPPORTED Invalid script table or opcode.
1604 S3BootScriptExecute (
1614 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1615 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
1616 Script
= mS3BootScriptTablePtr
->TableBase
;
1618 CopyMem ((VOID
*)&TableHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
1620 return EFI_INVALID_PARAMETER
;
1623 DEBUG ((EFI_D_INFO
, "S3BootScriptExecute:\n"));
1624 if (TableHeader
.OpCode
!= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
) {
1625 return EFI_UNSUPPORTED
;
1628 DEBUG ((EFI_D_INFO
, "TableHeader - 0x%08x\n", Script
));
1630 StartAddress
= (UINTN
) Script
;
1631 TableLength
= TableHeader
.TableLength
;
1632 Script
= Script
+ TableHeader
.Length
;
1633 Status
= EFI_SUCCESS
;
1637 DEBUG ((EFI_D_INFO
, "TableHeader.Version - 0x%04x\n", (UINTN
)TableHeader
.Version
));
1638 DEBUG ((EFI_D_INFO
, "TableHeader.TableLength - 0x%08x\n", (UINTN
)TableLength
));
1640 while ((UINTN
) Script
< (UINTN
) (StartAddress
+ TableLength
)) {
1641 DEBUG ((EFI_D_INFO
, "ExecuteBootScript - %08x\n", (UINTN
)Script
));
1643 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1644 switch (ScriptHeader
.OpCode
) {
1646 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
:
1647 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE\n"));
1648 Status
= BootScriptExecuteMemoryWrite (Script
);
1651 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
:
1652 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE\n"));
1653 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1654 Status
= BootScriptExecuteMemoryReadWrite (
1661 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
:
1662 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_IO_WRITE_OPCODE\n"));
1663 Status
= BootScriptExecuteIoWrite (Script
);
1666 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
:
1667 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE\n"));
1668 Status
= BootScriptExecutePciCfgWrite (Script
);
1671 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
:
1672 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE\n"));
1673 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1674 Status
= BootScriptExecutePciCfgReadWrite (
1680 case EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
:
1681 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE\n"));
1682 Status
= BootScriptExecutePciCfg2Write (Script
);
1685 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
:
1686 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE\n"));
1687 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1688 Status
= BootScriptExecutePciCfg2ReadWrite (
1694 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE
:
1695 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_DISPATCH_OPCODE\n"));
1696 Status
= BootScriptExecuteDispatch (Script
);
1699 case EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE
:
1700 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE\n"));
1701 Status
= BootScriptExecuteDispatch2 (Script
);
1704 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE
:
1705 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_INFORMATION_OPCODE\n"));
1706 BootScriptExecuteInformation (Script
);
1709 case S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE
:
1710 DEBUG ((EFI_D_INFO
, "S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE\n"));
1711 DEBUG ((EFI_D_INFO
, "S3BootScriptDone - %r\n", EFI_SUCCESS
));
1714 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
:
1715 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE\n"));
1716 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1717 Status
= BootScriptExecuteIoReadWrite (
1724 case EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
:
1725 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE\n"));
1726 Status
= BootScriptExecuteSmbusExecute (Script
);
1729 case EFI_BOOT_SCRIPT_STALL_OPCODE
:
1730 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_STALL_OPCODE\n"));
1731 Status
= BootScriptExecuteStall (Script
);
1734 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
:
1735 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_MEM_POLL_OPCODE\n"));
1736 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1737 Status
= BootScriptExecuteMemPoll (Script
, AndMask
, OrMask
);
1741 case EFI_BOOT_SCRIPT_IO_POLL_OPCODE
:
1742 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_IO_POLL_OPCODE\n"));
1743 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1744 Status
= BootScriptExecuteIoPoll (Script
, AndMask
, OrMask
);
1747 case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE
:
1748 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE\n"));
1749 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1750 Status
= BootScriptPciCfgPoll (Script
, AndMask
, OrMask
);
1753 case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE
:
1754 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE\n"));
1755 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1756 Status
= BootScriptPciCfg2Poll (Script
, AndMask
, OrMask
);
1759 case S3_BOOT_SCRIPT_LIB_LABEL_OPCODE
:
1763 DEBUG ((EFI_D_INFO
, "S3_BOOT_SCRIPT_LIB_LABEL_OPCODE\n"));
1764 BootScriptExecuteLabel (Script
);
1767 DEBUG ((EFI_D_INFO
, "S3BootScriptDone - %r\n", EFI_UNSUPPORTED
));
1768 return EFI_UNSUPPORTED
;
1771 if (EFI_ERROR (Status
)) {
1772 DEBUG ((EFI_D_INFO
, "S3BootScriptDone - %r\n", Status
));
1776 Script
= Script
+ ScriptHeader
.Length
;
1779 DEBUG ((EFI_D_INFO
, "S3BootScriptDone - %r\n", Status
));