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   SPDX-License-Identifier: BSD-2-Clause-Patent
8 
9 **/
10 #ifndef __INTERNAL_BOOT_SCRIPT_LIB__
11 #define __INTERNAL_BOOT_SCRIPT_LIB__
12 
13 #include <PiDxe.h>
14 
15 #include <Guid/EventGroup.h>
16 #include <Protocol/SmmBase2.h>
17 #include <Protocol/DxeSmmReadyToLock.h>
18 #include <Protocol/SmmReadyToLock.h>
19 #include <Protocol/SmmExitBootServices.h>
20 #include <Protocol/SmmLegacyBoot.h>
21 
22 #include <Library/S3BootScriptLib.h>
23 
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/BaseLib.h>
26 #include <Library/PcdLib.h>
27 #include <Library/SmbusLib.h>
28 #include <Library/IoLib.h>
29 #include <Library/PciSegmentLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/TimerLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/LockBoxLib.h>
35 
36 #include "BootScriptInternalFormat.h"
37 
38 #define MAX_IO_ADDRESS 0xFFFF
39 
40 //
41 // Macro to convert a UEFI PCI address + segment to a PCI Segment Library PCI address
42 //
43 #define PCI_ADDRESS_ENCODE(S, A) PCI_SEGMENT_LIB_ADDRESS( \
44                                    S, \
45                                    ((((UINTN)(A)) & 0xff000000) >> 24), \
46                                    ((((UINTN)(A)) & 0x00ff0000) >> 16), \
47                                    ((((UINTN)(A)) & 0xff00) >> 8), \
48                                    ((RShiftU64 ((A), 32) & 0xfff) | ((A) & 0xff)) \
49                                    )
50 
51 typedef union {
52   UINT8 volatile  *Buf;
53   UINT8 volatile  *Uint8;
54   UINT16 volatile *Uint16;
55   UINT32 volatile *Uint32;
56   UINT64 volatile *Uint64;
57   UINTN volatile   Uint;
58 } PTR;
59 
60 
61 // Minimum and maximum length for SMBus bus block protocols defined in SMBus spec 2.0.
62 //
63 #define MIN_SMBUS_BLOCK_LEN               1
64 #define MAX_SMBUS_BLOCK_LEN               32
65 
66 //
67 // The boot script private data.
68 //
69 typedef struct {
70   UINT8     *TableBase;
71   UINT32    TableLength;            // Record the actual memory length
72   UINT16    TableMemoryPageNumber;  // Record the page number Allocated for the table
73   BOOLEAN   InSmm;                  // Record if this library is in SMM.
74   BOOLEAN   AtRuntime;              // Record if current state is after SmmExitBootServices or SmmLegacyBoot.
75   UINT32    BootTimeScriptLength;   // Maintain boot time script length in LockBox after SmmReadyToLock in SMM.
76   BOOLEAN   SmmLocked;              // Record if current state is after SmmReadyToLock
77   BOOLEAN   BackFromS3;             // Indicate that the system is back from S3.
78 } SCRIPT_TABLE_PRIVATE_DATA;
79 
80 typedef
81 EFI_STATUS
82 (EFIAPI *DISPATCH_ENTRYPOINT_FUNC) (
83   IN EFI_HANDLE ImageHandle,
84   IN VOID       *Context
85   );
86 
87 extern SCRIPT_TABLE_PRIVATE_DATA       *mS3BootScriptTablePtr;
88 
89 //
90 // Define Opcode for Label which is implementation specific and no standard spec define.
91 //
92 #define  S3_BOOT_SCRIPT_LIB_LABEL_OPCODE    0xFE
93 
94 ///
95 /// The opcode indicate the start of the boot script table.
96 ///
97 #define S3_BOOT_SCRIPT_LIB_TABLE_OPCODE                  0xAA
98 ///
99 /// The opcode indicate the end of the boot script table.
100 ///
101 #define S3_BOOT_SCRIPT_LIB_TERMINATE_OPCODE              0xFF
102 
103 
104 #endif //__INTERNAL_BOOT_SCRIPT_LIB__
105 
106