1 /** @file 2 Support for S3 boot script lib. This file defined some internal macro and internal 3 data structure 4 5 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> 6 7 This program and the accompanying materials 8 are licensed and made available under the terms and conditions 9 of the BSD License which accompanies this distribution. The 10 full text of the license may be found at 11 http://opensource.org/licenses/bsd-license.php 12 13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 15 16 **/ 17 #ifndef __INTERNAL_BOOT_SCRIPT_LIB__ 18 #define __INTERNAL_BOOT_SCRIPT_LIB__ 19 20 #include <PiDxe.h> 21 22 #include <Guid/EventGroup.h> 23 #include <Protocol/SmmBase2.h> 24 #include <Protocol/DxeSmmReadyToLock.h> 25 #include <Protocol/SmmReadyToLock.h> 26 #include <Protocol/SmmExitBootServices.h> 27 #include <Protocol/SmmLegacyBoot.h> 28 29 #include <Library/S3BootScriptLib.h> 30 31 #include <Library/UefiBootServicesTableLib.h> 32 #include <Library/BaseLib.h> 33 #include <Library/PcdLib.h> 34 #include <Library/SmbusLib.h> 35 #include <Library/IoLib.h> 36 #include <Library/PciSegmentLib.h> 37 #include <Library/DebugLib.h> 38 #include <Library/BaseMemoryLib.h> 39 #include <Library/TimerLib.h> 40 #include <Library/UefiLib.h> 41 #include <Library/LockBoxLib.h> 42 43 #include "BootScriptInternalFormat.h" 44 45 #define MAX_IO_ADDRESS 0xFFFF 46 47 // 48 // Macro to convert a UEFI PCI address + segment to a PCI Segment Library PCI address 49 // 50 #define PCI_ADDRESS_ENCODE(S, A) PCI_SEGMENT_LIB_ADDRESS( \ 51 S, \ 52 ((((UINTN)(A)) & 0xff000000) >> 24), \ 53 ((((UINTN)(A)) & 0x00ff0000) >> 16), \ 54 ((((UINTN)(A)) & 0xff00) >> 8), \ 55 ((RShiftU64 ((A), 32) & 0xfff) | ((A) & 0xff)) \ 56 ) 57 58 typedef union { 59 UINT8 volatile *Buf; 60 UINT8 volatile *Uint8; 61 UINT16 volatile *Uint16; 62 UINT32 volatile *Uint32; 63 UINT64 volatile *Uint64; 64 UINTN volatile Uint; 65 } PTR; 66 67 68 // Minimum and maximum length for SMBus bus block protocols defined in SMBus spec 2.0. 69 // 70 #define MIN_SMBUS_BLOCK_LEN 1 71 #define MAX_SMBUS_BLOCK_LEN 32 72 73 // 74 // The boot script private data. 75 // 76 typedef struct { 77 UINT8 *TableBase; 78 UINT32 TableLength; // Record the actual memory length 79 UINT16 TableMemoryPageNumber; // Record the page number Allocated for the table 80 BOOLEAN InSmm; // Record if this library is in SMM. 81 BOOLEAN AtRuntime; // Record if current state is after SmmExitBootServices or SmmLegacyBoot. 82 UINT32 BootTimeScriptLength; // Maintain boot time script length in LockBox after SmmReadyToLock in SMM. 83 BOOLEAN SmmLocked; // Record if current state is after SmmReadyToLock 84 BOOLEAN BackFromS3; // Indicate that the system is back from S3. 85 } SCRIPT_TABLE_PRIVATE_DATA; 86 87 typedef 88 EFI_STATUS 89 (EFIAPI *DISPATCH_ENTRYPOINT_FUNC) ( 90 IN EFI_HANDLE ImageHandle, 91 IN VOID *Context 92 ); 93 94 extern SCRIPT_TABLE_PRIVATE_DATA *mS3BootScriptTablePtr; 95 96 // 97 // Define Opcode for Label which is implementation specific and no standard spec define. 98 // 99 #define S3_BOOT_SCRIPT_LIB_LABEL_OPCODE 0xFE 100 101 /// 102 /// The opcode indicate the start of the boot script table. 103 /// 104 #define S3_BOOT_SCRIPT_LIB_TABLE_OPCODE 0xAA 105 /// 106 /// The opcode indicate the end of the boot script table. 107 /// 108 #define S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE 0xFF 109 110 111 #endif //__INTERNAL_BOOT_SCRIPT_LIB__ 112 113