TianoCore EDK2 master
Loading...
Searching...
No Matches
Sec.c
Go to the documentation of this file.
1
10#include "Sec.h"
11
34EFIAPI
36 IN CONST EFI_PEI_SERVICES **PeiServices,
37 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
38 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
39 IN UINTN CopySize
40 )
41{
42 VOID *OldHeap;
43 VOID *NewHeap;
44 VOID *OldStack;
45 VOID *NewStack;
46 UINTN HeapSize;
47
48 HeapSize = ALIGN_VALUE (CopySize / 2, CPU_STACK_ALIGNMENT);
49
50 OldHeap = (VOID *)(UINTN)TemporaryMemoryBase;
51 NewHeap = (VOID *)((UINTN)PermanentMemoryBase + (CopySize - HeapSize));
52
53 OldStack = (VOID *)((UINTN)TemporaryMemoryBase + HeapSize);
54 NewStack = (VOID *)(UINTN)PermanentMemoryBase;
55
56 //
57 // Migrate the temporary memory stack to permanent memory stack.
58 //
59 CopyMem (NewStack, OldStack, CopySize - HeapSize);
60
61 //
62 // Migrate the temporary memory heap to permanent memory heap.
63 //
64 CopyMem (NewHeap, OldHeap, HeapSize);
65
66 SecSwitchStack ((UINTN)NewStack - (UINTN)OldStack);
67
68 return EFI_SUCCESS;
69}
70
71STATIC CONST EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi = {
73};
74
75STATIC CONST EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = {
76 {
77 EFI_PEI_PPI_DESCRIPTOR_PPI,
78 &gEfiTemporaryRamSupportPpiGuid,
79 (VOID *)&mTemporaryRamSupportPpi
80 }
81};
82
91VOID
93 OUT UINTN *PpiListSize,
95 )
96{
97 EFI_PEI_PPI_DESCRIPTOR *PlatformPpiList;
98 UINTN PlatformPpiListSize;
99 UINTN ListBase;
100 EFI_PEI_PPI_DESCRIPTOR *LastPpi;
101
102 // Get the Platform PPIs
103 PlatformPpiListSize = 0;
104 ArmPlatformGetPlatformPpiList (&PlatformPpiListSize, &PlatformPpiList);
105
106 // Copy the Common and Platform PPis in Temporary Memory
107 ListBase = PcdGet64 (PcdCPUCoresStackBase);
108 CopyMem ((VOID *)ListBase, gCommonPpiTable, sizeof (gCommonPpiTable));
109 CopyMem ((VOID *)(ListBase + sizeof (gCommonPpiTable)), PlatformPpiList, PlatformPpiListSize);
110
111 // Set the Terminate flag on the last PPI entry
112 LastPpi = (EFI_PEI_PPI_DESCRIPTOR *)ListBase +
113 ((sizeof (gCommonPpiTable) + PlatformPpiListSize) / sizeof (EFI_PEI_PPI_DESCRIPTOR)) - 1;
114 LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
115
116 *PpiList = (EFI_PEI_PPI_DESCRIPTOR *)ListBase;
117 *PpiListSize = sizeof (gCommonPpiTable) + PlatformPpiListSize;
118}
119
125STATIC
126VOID
128 VOID
129 )
130{
131 CHAR8 Buffer[100];
132 UINTN CharCount;
133
134 CharCount = AsciiSPrint (
135 Buffer,
136 sizeof (Buffer),
137 "UEFI firmware (version %s built at %a on %a)\n\r",
138 (CHAR16 *)PcdGetPtr (PcdFirmwareVersionString),
139 __TIME__,
140 __DATE__
141 );
142
143 // Because we are directly bit banging the serial port instead of going through the DebugLib, we need to make sure
144 // the serial port is initialized before we write to it
146 SerialPortWrite ((UINT8 *)Buffer, CharCount);
147}
148
155STATIC
156VOID
157EFIAPI
159 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
160 )
161{
162 EFI_SEC_PEI_HAND_OFF SecCoreData;
163 UINTN PpiListSize;
164 EFI_PEI_PPI_DESCRIPTOR *PpiList;
165 UINTN TemporaryRamBase;
166 UINTN TemporaryRamSize;
167
168 CreatePpiList (&PpiListSize, &PpiList);
169
170 // Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at
171 // the base of the primary core stack
172 PpiListSize = ALIGN_VALUE (PpiListSize, CPU_STACK_ALIGNMENT);
173 TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize;
174 TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize;
175
176 //
177 // Bind this information into the SEC hand-off state
178 // Note: this must be in sync with the stuff in the asm file
179 // Note also: HOBs (pei temp ram) MUST be above stack
180 //
181 SecCoreData.DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);
182 SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress);
183 SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize);
184 SecCoreData.TemporaryRamBase = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack)
185 SecCoreData.TemporaryRamSize = TemporaryRamSize;
186 SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;
188 SecCoreData.StackBase = (VOID *)((UINTN)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize);
189 SecCoreData.StackSize = (TemporaryRamBase + TemporaryRamSize) - (UINTN)SecCoreData.StackBase;
190
191 // Jump to PEI core entry point
192 (PeiCoreEntryPoint)(&SecCoreData, PpiList);
193}
194
201VOID
203 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
204 )
205{
206 if (!ArmMmuEnabled ()) {
207 // Data Cache enabled on Primary core when MMU is enabled.
208 ArmDisableDataCache ();
209 // Invalidate instruction cache
210 ArmInvalidateInstructionCache ();
211 // Enable Instruction Caches on all cores.
212 ArmEnableInstructionCache ();
213
215 (VOID *)(UINTN)PcdGet64 (PcdCPUCoresStackBase),
216 PcdGet32 (PcdCPUCorePrimaryStackSize)
217 );
218 }
219
220 // Write VBAR - The Exception Vector table must be aligned to its requirement
221 // Note: The AArch64 Vector table must be 2k-byte aligned - if this assertion fails ensure
222 // 'Align=4K' is defined into your FDF for this module.
223 ASSERT (((UINTN)PeiVectorTable & ARM_VECTOR_TABLE_ALIGNMENT) == 0);
224 ArmWriteVBar ((UINTN)PeiVectorTable);
225
226 // Enable Floating Point
227 if (FixedPcdGet32 (PcdVFPEnabled)) {
228 ArmEnableVFP ();
229 }
230
231 // Invoke "ProcessLibraryConstructorList" to have all library constructors
232 // called.
233 ProcessLibraryConstructorList ();
234
236
237 // Initialize the Debug Agent for Source Level Debugging
238 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);
240
241 // Initialize the platform specific controllers
242 ArmPlatformInitialize (ArmReadMpidr ());
243
244 // Goto primary Main.
245 SecMain (PeiCoreEntryPoint);
246
247 // PEI Core should always load and never return
248 ASSERT (FALSE);
249}
UINT64 UINTN
#define CPU_STACK_ALIGNMENT
VOID *EFIAPI InvalidateDataCacheRange(IN VOID *Address, IN UINTN Length)
RETURN_STATUS EFIAPI SerialPortInitialize(VOID)
Definition: SerialPortLib.c:25
UINTN EFIAPI SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
Definition: SerialPortLib.c:52
RETURN_STATUS ArmPlatformInitialize(IN UINTN MpId)
VOID ArmPlatformGetPlatformPpiList(OUT UINTN *PpiListSize, OUT EFI_PEI_PPI_DESCRIPTOR **PpiList)
STATIC EFI_STATUS EFIAPI SecTemporaryRamSupport(IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, IN UINTN CopySize)
Definition: Sec.c:35
VOID CEntryPoint(IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint)
Definition: Sec.c:202
STATIC VOID EFIAPI SecMain(IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint)
Definition: Sec.c:158
STATIC VOID PrintFirmwareVersion(VOID)
Definition: Sec.c:127
STATIC VOID CreatePpiList(OUT UINTN *PpiListSize, OUT EFI_PEI_PPI_DESCRIPTOR **PpiList)
Definition: Sec.c:92
VOID PeiVectorTable(VOID)
VOID SecSwitchStack(INTN StackDelta)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI SaveAndSetDebugTimerInterrupt(IN BOOLEAN EnableStatus)
VOID EFIAPI InitializeDebugAgent(IN UINT32 InitFlag, IN VOID *Context OPTIONAL, IN DEBUG_AGENT_CONTINUE Function OPTIONAL)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define ALIGN_VALUE(Value, Alignment)
Definition: Base.h:948
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define FixedPcdGet32(TokenName)
Definition: PcdLib.h:92
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
VOID(EFIAPI * EFI_PEI_CORE_ENTRY_POINT)(IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
Definition: PiPeiCis.h:1051
struct _EFI_SEC_PEI_HAND_OFF EFI_SEC_PEI_HAND_OFF
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
VOID * BootFirmwareVolumeBase
Definition: PiPeiCis.h:965
UINTN BootFirmwareVolumeSize
Definition: PiPeiCis.h:970
VOID * PeiTemporaryRamBase
Definition: PiPeiCis.h:991