2 Interpret and execute the S3 data in S3 boot script.
4 Copyright (c) 2006 - 2013, 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 read operation
644 @param Width Width of the operation.
645 @param Address Address of the operation.
646 @param Count Count of the number of accesses to perform.
647 @param Buffer Pointer to the buffer read from PCI config space
649 @retval EFI_SUCCESS The read succeed.
650 @retval EFI_INVALID_PARAMETER if Width is not defined
651 @note A known Limitations in the implementation which is 64bits operations are not supported.
656 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
668 Out
.Buf
= (UINT8
*) Buffer
;
670 PciAddress
= PCI_ADDRESS_ENCODE (Address
);
672 Status
= BuildLoopData (Width
, PciAddress
, &AddressStride
, &BufferStride
);
673 if (EFI_ERROR (Status
)) {
677 // Loop for each iteration and move the data
679 for (; Count
> 0; Count
--, PciAddress
+= AddressStride
, Out
.Buf
+= BufferStride
) {
681 case S3BootScriptWidthUint8
:
682 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint8 - 0x%08x\n", PciAddress
));
683 *Out
.Uint8
= PciRead8 (PciAddress
);
685 case S3BootScriptWidthFifoUint8
:
686 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint8 - 0x%08x\n", PciAddress
));
687 *Out
.Uint8
= PciRead8 (PciAddress
);
689 case S3BootScriptWidthFillUint8
:
690 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint8 - 0x%08x\n", PciAddress
));
691 *Out
.Uint8
= PciRead8 (PciAddress
);
694 case S3BootScriptWidthUint16
:
695 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint16 - 0x%08x\n", PciAddress
));
696 *Out
.Uint16
= PciRead16 (PciAddress
);
698 case S3BootScriptWidthFifoUint16
:
699 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint16 - 0x%08x\n", PciAddress
));
700 *Out
.Uint16
= PciRead16 (PciAddress
);
702 case S3BootScriptWidthFillUint16
:
703 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint16 - 0x%08x\n", PciAddress
));
704 *Out
.Uint16
= PciRead16 (PciAddress
);
707 case S3BootScriptWidthUint32
:
708 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint32 - 0x%08x\n", PciAddress
));
709 *Out
.Uint32
= PciRead32 (PciAddress
);
711 case S3BootScriptWidthFifoUint32
:
712 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint32 - 0x%08x\n", PciAddress
));
713 *Out
.Uint32
= PciRead32 (PciAddress
);
715 case S3BootScriptWidthFillUint32
:
716 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint32 - 0x%08x\n", PciAddress
));
717 *Out
.Uint32
= PciRead32 (PciAddress
);
721 return EFI_INVALID_PARAMETER
;
728 Performance PCI configuration write operation
730 @param Width Width of the operation.
731 @param Address Address of the operation.
732 @param Count Count of the number of accesses to perform.
733 @param Buffer Pointer to the buffer write to PCI config space
735 @retval EFI_SUCCESS The write succeed.
736 @retval EFI_INVALID_PARAMETER if Width is not defined
737 @note A known Limitations in the implementation which is 64bits operations are not supported.
742 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
751 UINTN OriginalPciAddress
;
756 In
.Buf
= (UINT8
*) Buffer
;
758 PciAddress
= PCI_ADDRESS_ENCODE (Address
);
760 Status
= BuildLoopData (Width
, PciAddress
, &AddressStride
, &BufferStride
);
761 if (EFI_ERROR (Status
)) {
765 // Loop for each iteration and move the data
767 OriginalPciAddress
= PciAddress
;
768 OriginalIn
.Buf
= In
.Buf
;
769 for (; Count
> 0; Count
--, PciAddress
+= AddressStride
, In
.Buf
+= BufferStride
) {
771 case S3BootScriptWidthUint8
:
772 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint8 - 0x%08x (0x%02x)\n", PciAddress
, (UINTN
)*In
.Uint8
));
773 PciWrite8 (PciAddress
, *In
.Uint8
);
775 case S3BootScriptWidthFifoUint8
:
776 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint8 - 0x%08x (0x%02x)\n", OriginalPciAddress
, (UINTN
)*In
.Uint8
));
777 PciWrite8 (OriginalPciAddress
, *In
.Uint8
);
779 case S3BootScriptWidthFillUint8
:
780 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint8 - 0x%08x (0x%02x)\n", PciAddress
, (UINTN
)*OriginalIn
.Uint8
));
781 PciWrite8 (PciAddress
, *OriginalIn
.Uint8
);
783 case S3BootScriptWidthUint16
:
784 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint16 - 0x%08x (0x%04x)\n", PciAddress
, (UINTN
)*In
.Uint16
));
785 PciWrite16 (PciAddress
, *In
.Uint16
);
787 case S3BootScriptWidthFifoUint16
:
788 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint16 - 0x%08x (0x%04x)\n", OriginalPciAddress
, (UINTN
)*In
.Uint16
));
789 PciWrite16 (OriginalPciAddress
, *In
.Uint16
);
791 case S3BootScriptWidthFillUint16
:
792 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint16 - 0x%08x (0x%04x)\n", PciAddress
, (UINTN
)*OriginalIn
.Uint16
));
793 PciWrite16 (PciAddress
, *OriginalIn
.Uint16
);
795 case S3BootScriptWidthUint32
:
796 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthUint32 - 0x%08x (0x%08x)\n", PciAddress
, (UINTN
)*In
.Uint32
));
797 PciWrite32 (PciAddress
, *In
.Uint32
);
799 case S3BootScriptWidthFifoUint32
:
800 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFifoUint32 - 0x%08x (0x%08x)\n", OriginalPciAddress
, (UINTN
)*In
.Uint32
));
801 PciWrite32 (OriginalPciAddress
, *In
.Uint32
);
803 case S3BootScriptWidthFillUint32
:
804 DEBUG ((EFI_D_INFO
, "S3BootScriptWidthFillUint32 - 0x%08x (0x%08x)\n", (UINTN
)PciAddress
, (UINTN
)*OriginalIn
.Uint32
));
805 PciWrite32 (PciAddress
, *OriginalIn
.Uint32
);
808 return EFI_INVALID_PARAMETER
;
814 Performance PCI configuration 2 read operation
816 @param Width Width of the operation.
817 @param Segment Pci segment number
818 @param Address Address of the operation.
819 @param Count Count of the number of accesses to perform.
820 @param Buffer Pointer to the buffer to read from PCI config space.
822 @retval EFI_SUCCESS The data was written to the EFI System.
823 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.
825 The Buffer is not aligned for the given Width.
826 Address is outside the legal range of I/O ports.
827 @note A known Limitations in the implementation which is the 'Segment' parameter is assumed as
828 Zero, or else, assert.
832 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
841 return ScriptPciCfgRead (Width
, Address
, Count
, Buffer
);
844 Performance PCI configuration 2 write operation
846 @param Width Width of the operation.
847 @param Segment Pci segment number
848 @param Address Address of the operation.
849 @param Count Count of the number of accesses to perform.
850 @param Buffer Pointer to the buffer to write to PCI config space.
852 @retval EFI_SUCCESS The data was written to the EFI System.
853 @retval EFI_INVALID_PARAMETER Width is invalid for this EFI System.
855 The Buffer is not aligned for the given Width.
856 Address is outside the legal range of I/O ports.
857 @note A known Limitations in the implementation which is the 'Segment' parameter is assumed as
858 Zero, or else, assert.
864 IN S3_BOOT_SCRIPT_LIB_WIDTH Width
,
872 return ScriptPciCfgWrite (Width
, Address
, Count
, Buffer
);
875 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE OP code.
877 @param Script The pointer of typed node in boot script table
879 @retval EFI_SUCCESS The operation was executed successfully
882 BootScriptExecutePciCfgWrite (
887 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
890 EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE PciCfgWrite
;
892 CopyMem ((VOID
*)&PciCfgWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
));
894 Width
= (S3_BOOT_SCRIPT_LIB_WIDTH
)PciCfgWrite
.Width
;
895 Address
= PciCfgWrite
.Address
;
896 Count
= PciCfgWrite
.Count
;
897 Buffer
= Script
+ sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE
);
899 DEBUG ((EFI_D_INFO
, "BootScriptExecutePciCfgWrite - 0x%08x, 0x%08x, 0x%08x\n", PCI_ADDRESS_ENCODE (Address
), Count
, (UINTN
)Width
));
900 return ScriptPciCfgWrite (Width
, Address
, Count
, Buffer
);
903 Interprete the boot script node with EFI_BOOT_SCRIPT_IO_READ_WRITE OP code.
905 @param Script The pointer of typed node in boot script table
906 @param AndMask Mask value for 'and' operation
907 @param OrMask Mask value for 'or' operation
909 @retval EFI_SUCCESS The operation was executed successfully
912 BootScriptExecuteIoReadWrite (
921 EFI_BOOT_SCRIPT_IO_READ_WRITE IoReadWrite
;
925 CopyMem((VOID
*)&IoReadWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_IO_READ_WRITE
));
927 DEBUG ((EFI_D_INFO
, "BootScriptExecuteIoReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN
)IoReadWrite
.Address
, AndMask
, OrMask
));
929 Status
= ScriptIoRead (
930 (S3_BOOT_SCRIPT_LIB_WIDTH
) IoReadWrite
.Width
,
935 if (!EFI_ERROR (Status
)) {
936 Data
= (Data
& AndMask
) | OrMask
;
937 Status
= ScriptIoWrite (
938 (S3_BOOT_SCRIPT_LIB_WIDTH
) IoReadWrite
.Width
,
947 Interprete the boot script node with EFI_BOOT_SCRIPT_MEM_READ_WRITE OP code.
949 @param Script The pointer of typed node in boot script table
950 @param AndMask Mask value for 'and' operation
951 @param OrMask Mask value for 'or' operation
953 @retval EFI_SUCCESS The operation was executed successfully
956 BootScriptExecuteMemoryReadWrite (
965 EFI_BOOT_SCRIPT_MEM_READ_WRITE MemReadWrite
;
969 CopyMem((VOID
*)&MemReadWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_MEM_READ_WRITE
));
971 DEBUG ((EFI_D_INFO
, "BootScriptExecuteMemoryReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN
)MemReadWrite
.Address
, AndMask
, OrMask
));
973 Status
= ScriptMemoryRead (
974 (S3_BOOT_SCRIPT_LIB_WIDTH
) MemReadWrite
.Width
,
975 MemReadWrite
.Address
,
979 if (!EFI_ERROR (Status
)) {
980 Data
= (Data
& AndMask
) | OrMask
;
981 Status
= ScriptMemoryWrite (
982 (S3_BOOT_SCRIPT_LIB_WIDTH
) MemReadWrite
.Width
,
983 MemReadWrite
.Address
,
991 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CFG_READ_WRITE OP code.
993 @param Script The pointer of typed node in boot script table
994 @param AndMask Mask value for 'and' operation
995 @param OrMask Mask value for 'or' operation
997 @retval EFI_SUCCESS The operation was executed successfully
1000 BootScriptExecutePciCfgReadWrite (
1009 EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE PciCfgReadWrite
;
1013 CopyMem((VOID
*)&PciCfgReadWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
));
1015 DEBUG ((EFI_D_INFO
, "BootScriptExecutePciCfgReadWrite - 0x%08x, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfgReadWrite
.Address
), AndMask
, OrMask
));
1017 Status
= ScriptPciCfgRead (
1018 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfgReadWrite
.Width
,
1019 PciCfgReadWrite
.Address
,
1023 if (EFI_ERROR (Status
)) {
1027 Data
= (Data
& AndMask
) | OrMask
;
1029 Status
= ScriptPciCfgWrite (
1030 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfgReadWrite
.Width
,
1031 PciCfgReadWrite
.Address
,
1039 Interprete the boot script node with EFI_BOOT_SCRIPT_SMBUS_EXECUTE OP code.
1041 @param Script The pointer of typed node in boot script table
1043 @retval EFI_SUCCESS The operation was executed successfully
1044 @retval EFI_UNSUPPORTED Cannot locate smbus ppi or occur error of script execution
1045 @retval Others Result of script execution
1048 BootScriptExecuteSmbusExecute (
1054 EFI_BOOT_SCRIPT_SMBUS_EXECUTE SmbusExecuteEntry
;
1056 CopyMem ((VOID
*)&SmbusExecuteEntry
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_SMBUS_EXECUTE
));
1058 DEBUG ((EFI_D_INFO
, "BootScriptExecuteSmbusExecute - 0x%08x, 0x%08x\n", (UINTN
)SmbusExecuteEntry
.SmBusAddress
, (UINTN
)SmbusExecuteEntry
.Operation
));
1060 SmBusAddress
= (UINTN
)SmbusExecuteEntry
.SmBusAddress
;
1061 DataSize
= (UINTN
) SmbusExecuteEntry
.DataSize
;
1062 return SmbusExecute (
1064 (EFI_SMBUS_OPERATION
) SmbusExecuteEntry
.Operation
,
1066 Script
+ sizeof (EFI_BOOT_SCRIPT_SMBUS_EXECUTE
)
1070 Interprete the boot script node with EFI_BOOT_SCRIPT_STALL OP code.
1072 @param Script The pointer of typed node in boot script table
1074 @retval EFI_SUCCESS The operation was executed successfully
1077 BootScriptExecuteStall (
1081 EFI_BOOT_SCRIPT_STALL Stall
;
1083 CopyMem ((VOID
*)&Stall
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_STALL
));
1085 DEBUG ((EFI_D_INFO
, "BootScriptExecuteStall - 0x%08x\n", (UINTN
)Stall
.Duration
));
1087 MicroSecondDelay ((UINTN
) Stall
.Duration
);
1091 Interprete the boot script node with EFI_BOOT_SCRIPT_DISPATCH OP code.
1093 @param Script The pointer of typed node in boot script table
1094 @retval EFI_SUCCESS The operation was executed successfully
1097 BootScriptExecuteDispatch (
1102 DISPATCH_ENTRYPOINT_FUNC EntryFunc
;
1103 EFI_BOOT_SCRIPT_DISPATCH ScriptDispatch
;
1105 CopyMem ((VOID
*)&ScriptDispatch
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_DISPATCH
));
1106 EntryFunc
= (DISPATCH_ENTRYPOINT_FUNC
) (UINTN
) (ScriptDispatch
.EntryPoint
);
1108 DEBUG ((EFI_D_INFO
, "BootScriptExecuteDispatch - 0x%08x\n", (UINTN
)ScriptDispatch
.EntryPoint
));
1110 Status
= EntryFunc (NULL
, NULL
);
1115 Interprete the boot script node with EFI_BOOT_SCRIPT_DISPATCH_2 OP code.
1117 @param Script The pointer of typed node in boot script table
1118 @retval EFI_SUCCESS The operation was executed successfully
1121 BootScriptExecuteDispatch2 (
1126 DISPATCH_ENTRYPOINT_FUNC EntryFunc
;
1127 EFI_BOOT_SCRIPT_DISPATCH_2 ScriptDispatch2
;
1129 CopyMem ((VOID
*)&ScriptDispatch2
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_DISPATCH_2
));
1131 DEBUG ((EFI_D_INFO
, "BootScriptExecuteDispatch2 - 0x%08x(0x%08x)\n", (UINTN
)ScriptDispatch2
.EntryPoint
, (UINTN
)ScriptDispatch2
.Context
));
1133 EntryFunc
= (DISPATCH_ENTRYPOINT_FUNC
) (UINTN
) (ScriptDispatch2
.EntryPoint
);
1135 Status
= EntryFunc (NULL
, (VOID
*) (UINTN
) ScriptDispatch2
.Context
);
1140 Interprete the boot script node with EFI_BOOT_SCRIPT_MEM_POLL OP code.
1142 @param Script The pointer of typed node in boot script table
1143 @param AndMask Mask value for 'and' operation
1144 @param OrMask Mask value for 'or' operation
1146 @retval EFI_DEVICE_ERROR Data polled from memory does not equal to
1147 the epecting data within the Loop Times.
1148 @retval EFI_SUCCESS The operation was executed successfully
1151 BootScriptExecuteMemPoll (
1161 EFI_BOOT_SCRIPT_MEM_POLL MemPoll
;
1163 CopyMem ((VOID
*)&MemPoll
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_MEM_POLL
));
1165 DEBUG ((EFI_D_INFO
, "BootScriptExecuteMemPoll - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN
)MemPoll
.Address
, AndMask
, OrMask
));
1168 Status
= ScriptMemoryRead (
1169 (S3_BOOT_SCRIPT_LIB_WIDTH
) MemPoll
.Width
,
1174 if ((!EFI_ERROR (Status
)) && (Data
& AndMask
) == OrMask
) {
1178 for (LoopTimes
= 0; LoopTimes
< MemPoll
.LoopTimes
; LoopTimes
++) {
1179 MicroSecondDelay ((UINTN
)MemPoll
.Duration
);
1182 Status
= ScriptMemoryRead (
1183 (S3_BOOT_SCRIPT_LIB_WIDTH
) MemPoll
.Width
,
1188 if ((!EFI_ERROR (Status
)) && (Data
& AndMask
) == OrMask
) {
1193 if (LoopTimes
< MemPoll
.LoopTimes
) {
1196 return EFI_DEVICE_ERROR
;
1200 Execute the boot script to interpret the Store arbitrary information.
1201 This opcode is a no-op on dispatch and is only used for debugging script issues.
1203 @param Script The pointer of node in boot script table
1207 BootScriptExecuteInformation (
1213 EFI_BOOT_SCRIPT_INFORMATION Information
;
1214 UINT8
*InformationData
;
1216 CopyMem ((VOID
*)&Information
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_INFORMATION
));
1218 InformationData
= Script
+ sizeof (EFI_BOOT_SCRIPT_INFORMATION
);
1219 DEBUG ((EFI_D_INFO
, "BootScriptExecuteInformation - 0x%08x\n", (UINTN
) InformationData
));
1221 DEBUG ((EFI_D_INFO
, "BootScriptInformation: "));
1222 for (Index
= 0; Index
< Information
.InformationLength
; Index
++) {
1223 DEBUG ((EFI_D_INFO
, "%02x ", InformationData
[Index
]));
1225 DEBUG ((EFI_D_INFO
, "\n"));
1229 Execute the boot script to interpret the Label information.
1231 @param Script The pointer of node in boot script table
1235 BootScriptExecuteLabel (
1241 EFI_BOOT_SCRIPT_INFORMATION Information
;
1242 UINT8
*InformationData
;
1244 CopyMem ((VOID
*)&Information
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_INFORMATION
));
1246 InformationData
= Script
+ sizeof (EFI_BOOT_SCRIPT_INFORMATION
);
1247 DEBUG ((EFI_D_INFO
, "BootScriptExecuteLabel - 0x%08x\n", (UINTN
) InformationData
));
1249 DEBUG ((EFI_D_INFO
, "BootScriptLabel: "));
1250 for (Index
= 0; Index
< Information
.InformationLength
; Index
++) {
1251 DEBUG ((EFI_D_INFO
, "%02x ", InformationData
[Index
]));
1253 DEBUG ((EFI_D_INFO
, "\n"));
1257 calculate the mask value for 'and' and 'or' operation
1258 @param ScriptHeader The pointer of header of node in boot script table
1259 @param AndMask The Mask value for 'and' operation
1260 @param OrMask The Mask value for 'or' operation
1261 @param Script Pointer to the entry.
1266 IN EFI_BOOT_SCRIPT_COMMON_HEADER
*ScriptHeader
,
1267 OUT UINT64
*AndMask
,
1275 switch (ScriptHeader
->OpCode
) {
1276 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
:
1277 Size
= sizeof (EFI_BOOT_SCRIPT_IO_READ_WRITE
);
1280 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
:
1281 Size
= sizeof (EFI_BOOT_SCRIPT_MEM_READ_WRITE
);
1284 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
:
1285 Size
= sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE
);
1287 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
:
1288 Size
= sizeof (EFI_BOOT_SCRIPT_MEM_POLL
);
1291 case EFI_BOOT_SCRIPT_IO_POLL_OPCODE
:
1292 Size
= sizeof (EFI_BOOT_SCRIPT_IO_POLL
);
1295 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
:
1296 Size
= sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
);
1299 case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE
:
1300 Size
= sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
);
1303 case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE
:
1304 Size
= sizeof (EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
);
1311 DataPtr
= Script
+ Size
;
1313 switch (ScriptHeader
->Width
) {
1314 case S3BootScriptWidthUint8
:
1315 *AndMask
= (UINT64
) *(DataPtr
+ 1);
1316 *OrMask
= (UINT64
) (*DataPtr
);
1319 case S3BootScriptWidthUint16
:
1320 *AndMask
= (UINT64
) (*(UINT16
*) (DataPtr
+ 2));
1321 *OrMask
= (UINT64
) (*(UINT16
*) DataPtr
);
1324 case S3BootScriptWidthUint32
:
1325 *AndMask
= (UINT64
) (*(UINT32
*) (DataPtr
+ 4));
1326 *OrMask
= (UINT64
) (*(UINT32
*) DataPtr
);
1329 case S3BootScriptWidthUint64
:
1330 *AndMask
= (UINT64
) (*(UINT64
*) (DataPtr
+ 8));
1331 *OrMask
= (UINT64
) (*(UINT64
*) DataPtr
);
1341 Interprete the boot script node with EFI_BOOT_SCRIPT_IO_POLL OP code.
1343 @param Script The pointer of typed node in boot script table
1344 @param AndMask Mask value for 'and' operation
1345 @param OrMask Mask value for 'or' operation
1347 @retval EFI_DEVICE_ERROR Data polled from memory does not equal to
1348 the epecting data within the Loop Times.
1349 @retval EFI_SUCCESS The operation was executed successfully
1352 BootScriptExecuteIoPoll (
1361 EFI_BOOT_SCRIPT_IO_POLL IoPoll
;
1363 CopyMem ((VOID
*)&IoPoll
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_IO_POLL
));
1365 DEBUG ((EFI_D_INFO
, "BootScriptExecuteIoPoll - 0x%08x, 0x%016lx, 0x%016lx\n", (UINTN
)IoPoll
.Address
, AndMask
, OrMask
));
1368 Status
= ScriptIoRead (
1369 (S3_BOOT_SCRIPT_LIB_WIDTH
) IoPoll
.Width
,
1374 if ((!EFI_ERROR (Status
)) && (Data
& AndMask
) == OrMask
) {
1377 for (LoopTimes
= 0; LoopTimes
< IoPoll
.Delay
; LoopTimes
++) {
1378 NanoSecondDelay (100);
1380 Status
= ScriptIoRead (
1381 (S3_BOOT_SCRIPT_LIB_WIDTH
) IoPoll
.Width
,
1386 if ((!EFI_ERROR (Status
)) &&(Data
& AndMask
) == OrMask
) {
1391 if (LoopTimes
< IoPoll
.Delay
) {
1394 return EFI_DEVICE_ERROR
;
1398 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE OP code.
1400 @param Script The pointer of S3 boot script
1402 @retval EFI_SUCCESS The operation was executed successfully
1406 BootScriptExecutePciCfg2Write (
1411 S3_BOOT_SCRIPT_LIB_WIDTH Width
;
1415 EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE PciCfg2Write
;
1417 CopyMem ((VOID
*)&PciCfg2Write
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
));
1419 Width
= (S3_BOOT_SCRIPT_LIB_WIDTH
)PciCfg2Write
.Width
;
1420 Segment
= PciCfg2Write
.Segment
;
1421 Address
= PciCfg2Write
.Address
;
1422 Count
= PciCfg2Write
.Count
;
1423 Buffer
= Script
+ sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE
);
1425 DEBUG ((EFI_D_INFO
, "BootScriptExecutePciCfg2Write - 0x%04x, 0x%08x, 0x%08x, 0x%08x\n", Segment
, PCI_ADDRESS_ENCODE (Address
), Count
, (UINTN
)Width
));
1426 return ScriptPciCfg2Write (Width
, Segment
, Address
, Count
, Buffer
);
1431 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE OP code.
1433 @param Script The pointer of S3 boot script
1434 @param AndMask Mask value for 'and' operation
1435 @param OrMask Mask value for 'or' operation
1437 @retval EFI_SUCCESS The operation was executed successfully
1441 BootScriptExecutePciCfg2ReadWrite (
1449 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE PciCfg2ReadWrite
;
1453 CopyMem ((VOID
*)&PciCfg2ReadWrite
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE
));
1455 DEBUG ((EFI_D_INFO
, "BootScriptExecutePciCfg2ReadWrite - 0x%04x, 0x%08x, 0x%016lx, 0x%016lx\n", PciCfg2ReadWrite
.Segment
, PCI_ADDRESS_ENCODE (PciCfg2ReadWrite
.Address
), AndMask
, OrMask
));
1457 Status
= ScriptPciCfg2Read (
1458 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfg2ReadWrite
.Width
,
1459 PciCfg2ReadWrite
.Segment
,
1460 PciCfg2ReadWrite
.Address
,
1464 if (EFI_ERROR (Status
)) {
1468 Data
= (Data
& AndMask
) | OrMask
;
1469 Status
= ScriptPciCfg2Write (
1470 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfg2ReadWrite
.Width
,
1471 PciCfg2ReadWrite
.Segment
,
1472 PciCfg2ReadWrite
.Address
,
1479 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG_POLL OP code.
1481 @param Script The pointer of S3 boot script
1482 @param AndMask Mask value for 'and' operation
1483 @param OrMask Mask value for 'or' operation
1485 @retval EFI_SUCCESS The operation was executed successfully
1486 @retval EFI_DEVICE_ERROR Data polled from Pci configuration space does not equal to
1487 epecting data within the Loop Times.
1490 BootScriptPciCfgPoll (
1499 EFI_BOOT_SCRIPT_PCI_CONFIG_POLL PciCfgPoll
;
1500 CopyMem ((VOID
*)&PciCfgPoll
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG_POLL
));
1502 DEBUG ((EFI_D_INFO
, "BootScriptPciCfgPoll - 0x%08x, 0x%016lx, 0x%016lx\n", PCI_ADDRESS_ENCODE (PciCfgPoll
.Address
), AndMask
, OrMask
));
1505 Status
= ScriptPciCfgRead (
1506 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfgPoll
.Width
,
1511 if ((!EFI_ERROR (Status
)) &&(Data
& AndMask
) == OrMask
) {
1515 for (LoopTimes
= 0; LoopTimes
< PciCfgPoll
.Delay
; LoopTimes
++) {
1516 NanoSecondDelay (100);
1518 Status
= ScriptPciCfgRead (
1519 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfgPoll
.Width
,
1524 if ((!EFI_ERROR (Status
)) &&
1525 (Data
& AndMask
) == OrMask
) {
1530 if (LoopTimes
< PciCfgPoll
.Delay
) {
1533 return EFI_DEVICE_ERROR
;
1538 Interprete the boot script node with EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL OP code.
1540 @param Script The pointer of S3 Boot Script
1541 @param AndMask Mask value for 'and' operation
1542 @param OrMask Mask value for 'or' operation
1544 @retval EFI_SUCCESS The operation was executed successfully
1545 @retval EFI_DEVICE_ERROR Data polled from Pci configuration space does not equal to
1546 epecting data within the Loop Times.
1550 BootScriptPciCfg2Poll (
1559 EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL PciCfg2Poll
;
1562 CopyMem ((VOID
*)&PciCfg2Poll
, (VOID
*)Script
, sizeof(EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL
));
1564 DEBUG ((EFI_D_INFO
, "BootScriptPciCfg2Poll - 0x%04x, 0x%08x, 0x%016lx, 0x%016lx\n", PciCfg2Poll
.Segment
, PCI_ADDRESS_ENCODE (PciCfg2Poll
.Address
), AndMask
, OrMask
));
1566 Status
= ScriptPciCfg2Read (
1567 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfg2Poll
.Width
,
1568 PciCfg2Poll
.Segment
,
1569 PciCfg2Poll
.Address
,
1573 if ((!EFI_ERROR (Status
)) && (Data
& AndMask
) == OrMask
) {
1577 for (LoopTimes
= 0; LoopTimes
< PciCfg2Poll
.Delay
; LoopTimes
++) {
1578 NanoSecondDelay (100);
1581 Status
= ScriptPciCfg2Read (
1582 (S3_BOOT_SCRIPT_LIB_WIDTH
) PciCfg2Poll
.Width
,
1583 PciCfg2Poll
.Segment
,
1584 PciCfg2Poll
.Address
,
1588 if ((!EFI_ERROR (Status
)) && (Data
& AndMask
) == OrMask
) {
1593 if (LoopTimes
< PciCfg2Poll
.Delay
) {
1596 return EFI_DEVICE_ERROR
;
1602 Executes the S3 boot script table.
1604 @retval RETURN_SUCCESS The boot script table was executed successfully.
1605 @retval RETURN_UNSUPPORTED Invalid script table or opcode.
1607 @note A known Limitations in the implementation: When interpreting the opcode EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
1608 EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE and EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE, the 'Segment' parameter is assumed as
1609 Zero, or else, assert.
1613 S3BootScriptExecute (
1623 EFI_BOOT_SCRIPT_COMMON_HEADER ScriptHeader
;
1624 EFI_BOOT_SCRIPT_TABLE_HEADER TableHeader
;
1625 Script
= mS3BootScriptTablePtr
->TableBase
;
1627 CopyMem ((VOID
*)&TableHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_TABLE_HEADER
));
1629 return EFI_INVALID_PARAMETER
;
1632 DEBUG ((EFI_D_INFO
, "S3BootScriptExecute:\n"));
1633 if (TableHeader
.OpCode
!= S3_BOOT_SCRIPT_LIB_TABLE_OPCODE
) {
1634 return EFI_UNSUPPORTED
;
1637 DEBUG ((EFI_D_INFO
, "TableHeader - 0x%08x\n", Script
));
1639 StartAddress
= (UINTN
) Script
;
1640 TableLength
= TableHeader
.TableLength
;
1641 Script
= Script
+ TableHeader
.Length
;
1642 Status
= EFI_SUCCESS
;
1646 DEBUG ((EFI_D_INFO
, "TableHeader.TableLength - 0x%08x\n", (UINTN
)TableLength
));
1648 while ((UINTN
) Script
< (UINTN
) (StartAddress
+ TableLength
)) {
1649 DEBUG ((EFI_D_INFO
, "ExecuteBootScript - %08x\n", (UINTN
)Script
));
1651 CopyMem ((VOID
*)&ScriptHeader
, Script
, sizeof(EFI_BOOT_SCRIPT_COMMON_HEADER
));
1652 switch (ScriptHeader
.OpCode
) {
1654 case EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
:
1655 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE\n"));
1656 Status
= BootScriptExecuteMemoryWrite (Script
);
1659 case EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
:
1660 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE\n"));
1661 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1662 Status
= BootScriptExecuteMemoryReadWrite (
1669 case EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
:
1670 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_IO_WRITE_OPCODE\n"));
1671 Status
= BootScriptExecuteIoWrite (Script
);
1674 case EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
:
1675 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE\n"));
1676 Status
= BootScriptExecutePciCfgWrite (Script
);
1679 case EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
:
1680 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE\n"));
1681 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1682 Status
= BootScriptExecutePciCfgReadWrite (
1688 case EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE
:
1689 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG2_WRITE_OPCODE\n"));
1690 Status
= BootScriptExecutePciCfg2Write (Script
);
1693 case EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE
:
1694 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG2_READ_WRITE_OPCODE\n"));
1695 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1696 Status
= BootScriptExecutePciCfg2ReadWrite (
1702 case EFI_BOOT_SCRIPT_DISPATCH_OPCODE
:
1703 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_DISPATCH_OPCODE\n"));
1704 Status
= BootScriptExecuteDispatch (Script
);
1707 case EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE
:
1708 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE\n"));
1709 Status
= BootScriptExecuteDispatch2 (Script
);
1712 case EFI_BOOT_SCRIPT_INFORMATION_OPCODE
:
1713 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_INFORMATION_OPCODE\n"));
1714 BootScriptExecuteInformation (Script
);
1717 case S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE
:
1718 DEBUG ((EFI_D_INFO
, "S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE\n"));
1719 DEBUG ((EFI_D_INFO
, "S3BootScriptDone - %r\n", EFI_SUCCESS
));
1722 case EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
:
1723 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE\n"));
1724 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1725 Status
= BootScriptExecuteIoReadWrite (
1732 case EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
:
1733 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE\n"));
1734 Status
= BootScriptExecuteSmbusExecute (Script
);
1737 case EFI_BOOT_SCRIPT_STALL_OPCODE
:
1738 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_STALL_OPCODE\n"));
1739 Status
= BootScriptExecuteStall (Script
);
1742 case EFI_BOOT_SCRIPT_MEM_POLL_OPCODE
:
1743 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_MEM_POLL_OPCODE\n"));
1744 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1745 Status
= BootScriptExecuteMemPoll (Script
, AndMask
, OrMask
);
1749 case EFI_BOOT_SCRIPT_IO_POLL_OPCODE
:
1750 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_IO_POLL_OPCODE\n"));
1751 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1752 Status
= BootScriptExecuteIoPoll (Script
, AndMask
, OrMask
);
1755 case EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE
:
1756 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG_POLL_OPCODE\n"));
1757 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1758 Status
= BootScriptPciCfgPoll (Script
, AndMask
, OrMask
);
1761 case EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE
:
1762 DEBUG ((EFI_D_INFO
, "EFI_BOOT_SCRIPT_PCI_CONFIG2_POLL_OPCODE\n"));
1763 CheckAndOrMask (&ScriptHeader
, &AndMask
, &OrMask
, Script
);
1764 Status
= BootScriptPciCfg2Poll (Script
, AndMask
, OrMask
);
1767 case S3_BOOT_SCRIPT_LIB_LABEL_OPCODE
:
1771 DEBUG ((EFI_D_INFO
, "S3_BOOT_SCRIPT_LIB_LABEL_OPCODE\n"));
1772 BootScriptExecuteLabel (Script
);
1775 DEBUG ((EFI_D_INFO
, "S3BootScriptDone - %r\n", EFI_UNSUPPORTED
));
1776 return EFI_UNSUPPORTED
;
1779 if (EFI_ERROR (Status
)) {
1780 DEBUG ((EFI_D_INFO
, "S3BootScriptDone - %r\n", Status
));
1784 Script
= Script
+ ScriptHeader
.Length
;
1787 DEBUG ((EFI_D_INFO
, "S3BootScriptDone - %r\n", Status
));