1 /** @file
2 
3   Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
4   SPDX-License-Identifier: BSD-2-Clause-Patent
5 
6 **/
7 
8 #ifndef _SEC_CORE_H_
9 #define _SEC_CORE_H_
10 
11 
12 #include <PiPei.h>
13 #include <Ppi/TemporaryRamSupport.h>
14 
15 #include <Library/BaseLib.h>
16 #include <Library/IoLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/PciCf8Lib.h>
21 #include <Library/SerialPortLib.h>
22 #include <Library/FspSwitchStackLib.h>
23 #include <Library/FspCommonLib.h>
24 #include <Library/UefiCpuLib.h>
25 #include <FspEas.h>
26 
27 typedef VOID (*PEI_CORE_ENTRY) ( \
28   IN CONST  EFI_SEC_PEI_HAND_OFF    *SecCoreData, \
29   IN CONST  EFI_PEI_PPI_DESCRIPTOR  *PpiList \
30 );
31 
32 typedef struct _SEC_IDT_TABLE {
33   //
34   // Reserved 8 bytes preceding IDT to store EFI_PEI_SERVICES**, since IDT base
35   // address should be 8-byte alignment.
36   // Note: For IA32, only the 4 bytes immediately preceding IDT is used to store
37   // EFI_PEI_SERVICES**
38   //
39   UINT64            PeiService;
40   UINT64            IdtTable[FixedPcdGet8 (PcdFspMaxInterruptSupported)];
41 } SEC_IDT_TABLE;
42 
43 /**
44   Switch the stack in the temporary memory to the one in the permanent memory.
45 
46   This function must be invoked after the memory migration immediately. The relative
47   position of the stack in the temporary and permanent memory is same.
48 
49   @param[in] TemporaryMemoryBase  Base address of the temporary memory.
50   @param[in] PermenentMemoryBase  Base address of the permanent memory.
51 **/
52 VOID
53 EFIAPI
54 SecSwitchStack (
55   IN UINT32   TemporaryMemoryBase,
56   IN UINT32   PermenentMemoryBase
57   );
58 
59 /**
60   This service of the TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into
61   permanent memory.
62 
63   @param[in] PeiServices            Pointer to the PEI Services Table.
64   @param[in] TemporaryMemoryBase    Source Address in temporary memory from which the SEC or PEIM will copy the
65                                 Temporary RAM contents.
66   @param[in] PermanentMemoryBase    Destination Address in permanent memory into which the SEC or PEIM will copy the
67                                 Temporary RAM contents.
68   @param[in] CopySize               Amount of memory to migrate from temporary to permanent memory.
69 
70   @retval EFI_SUCCESS           The data was successfully returned.
71   @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when
72                                 TemporaryMemoryBase > PermanentMemoryBase.
73 
74 **/
75 EFI_STATUS
76 EFIAPI
77 SecTemporaryRamSupport (
78   IN CONST EFI_PEI_SERVICES   **PeiServices,
79   IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,
80   IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,
81   IN UINTN                    CopySize
82   );
83 
84 
85 /**
86 
87   Entry point to the C language phase of SEC. After the SEC assembly
88   code has initialized some temporary memory and set up the stack,
89   the control is transferred to this function.
90 
91 
92   @param[in] SizeOfRam          Size of the temporary memory available for use.
93   @param[in] TempRamBase        Base address of temporary ram
94   @param[in] BootFirmwareVolume Base address of the Boot Firmware Volume.
95   @param[in] PeiCore            PeiCore entry point.
96   @param[in] BootLoaderStack    BootLoader stack.
97   @param[in] ApiIdx             the index of API.
98 
99   @return This function never returns.
100 
101 **/
102 VOID
103 EFIAPI
104 SecStartup (
105   IN UINT32                   SizeOfRam,
106   IN UINT32                   TempRamBase,
107   IN VOID                    *BootFirmwareVolume,
108   IN PEI_CORE_ENTRY           PeiCore,
109   IN UINT32                   BootLoaderStack,
110   IN UINT32                   ApiIdx
111   );
112 
113 /**
114   Autogenerated function that calls the library constructors for all of the module's
115   dependent libraries.  This function must be called by the SEC Core once a stack has
116   been established.
117 
118 **/
119 VOID
120 EFIAPI
121 ProcessLibraryConstructorList (
122   VOID
123   );
124 
125 /**
126 
127   Return value of esp.
128 
129   @return  value of esp.
130 
131 **/
132 UINT32
133 EFIAPI
134 AsmReadEsp (
135   VOID
136   );
137 
138 #endif
139