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
92VOID
94 OUT UINTN *PpiListSize,
96 IN VOID *TransferListBase
97 )
98{
99 EFI_PEI_PPI_DESCRIPTOR *PlatformPpiList;
100 UINTN PlatformPpiListSize;
101 UINTN ListBase;
102 EFI_PEI_PPI_DESCRIPTOR *LastPpi;
103
104 // Get the Platform PPIs
105 PlatformPpiListSize = 0;
106 ArmPlatformGetPlatformPpiList (&PlatformPpiListSize, &PlatformPpiList);
107
108 // Copy the Common and Platform PPis in Temporary Memory
109 ListBase = PcdGet64 (PcdCPUCoresStackBase);
110 CopyMem ((VOID *)ListBase, gCommonPpiTable, sizeof (gCommonPpiTable));
111 CopyMem ((VOID *)(ListBase + sizeof (gCommonPpiTable)), PlatformPpiList, PlatformPpiListSize);
112
113 // Set the Terminate flag on the last PPI entry
114 LastPpi = (EFI_PEI_PPI_DESCRIPTOR *)ListBase +
115 ((sizeof (gCommonPpiTable) + PlatformPpiListSize) / sizeof (EFI_PEI_PPI_DESCRIPTOR)) - 1;
116 *PpiListSize = sizeof (gCommonPpiTable) + PlatformPpiListSize;
117
118 // Add the Transfer List PPI after the Common and Platform PPIs
119 if (TransferListBase != NULL) {
120 LastPpi++;
121 LastPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI;
122 LastPpi->Guid = &gArmTransferListPpiGuid;
123 LastPpi->Ppi = TransferListBase;
124 *PpiListSize += sizeof (EFI_PEI_PPI_DESCRIPTOR);
125 }
126
127 LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
128
129 *PpiList = (EFI_PEI_PPI_DESCRIPTOR *)ListBase;
130}
131
137STATIC
138VOID
140 VOID
141 )
142{
143 CHAR8 Buffer[100];
144 UINTN CharCount;
145
146 CharCount = AsciiSPrint (
147 Buffer,
148 sizeof (Buffer),
149 "UEFI firmware (version %s built at %a on %a)\n\r",
150 (CHAR16 *)PcdGetPtr (PcdFirmwareVersionString),
151 __TIME__,
152 __DATE__
153 );
154
155 // Because we are directly bit banging the serial port instead of going through the DebugLib, we need to make sure
156 // the serial port is initialized before we write to it
158 SerialPortWrite ((UINT8 *)Buffer, CharCount);
159}
160
169STATIC
170VOID
171EFIAPI
173 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint,
174 IN UINTN TransferListBaseAddr
175 )
176{
177 EFI_SEC_PEI_HAND_OFF SecCoreData;
178 UINTN PpiListSize;
179 EFI_PEI_PPI_DESCRIPTOR *PpiList;
180 UINTN TemporaryRamBase;
181 UINTN TemporaryRamSize;
182 VOID *TransferListBase;
183
184 // Dump the Transfer List
185 TransferListBase = (VOID *)TransferListBaseAddr;
186 if (TransferListBase != NULL) {
187 if (TransferListCheckHeader (TransferListBase) != TRANSFER_LIST_OPS_INVALID) {
189 TransferListDump (TransferListBase);
191 } else {
192 TransferListBase = NULL;
193 DEBUG ((DEBUG_ERROR, "%a: No valid operations possible on TransferList found @ 0x%p\n", __func__, TransferListBase));
194 }
195 } else {
196 DEBUG ((DEBUG_INFO, "%a: No TransferList found, continuing boot\n", __func__));
197 }
198
199 CreatePpiList (&PpiListSize, &PpiList, TransferListBase);
200
201 // Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at
202 // the base of the primary core stack
203 PpiListSize = ALIGN_VALUE (PpiListSize, CPU_STACK_ALIGNMENT);
204 TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize;
205 TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize;
206
207 //
208 // Bind this information into the SEC hand-off state
209 // Note: this must be in sync with the stuff in the asm file
210 // Note also: HOBs (pei temp ram) MUST be above stack
211 //
212 SecCoreData.DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);
213 SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress);
214 SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize);
215 SecCoreData.TemporaryRamBase = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack)
216 SecCoreData.TemporaryRamSize = TemporaryRamSize;
217 SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;
219 SecCoreData.StackBase = (VOID *)((UINTN)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize);
220 SecCoreData.StackSize = (TemporaryRamBase + TemporaryRamSize) - (UINTN)SecCoreData.StackBase;
221
222 // Jump to PEI core entry point
223 (PeiCoreEntryPoint)(&SecCoreData, PpiList);
224}
225
234VOID
236 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint,
237 IN UINTN TransferListBaseAddr
238 )
239{
240 if (!ArmMmuEnabled ()) {
241 // Data Cache enabled on Primary core when MMU is enabled.
242 ArmDisableDataCache ();
243 // Invalidate instruction cache
244 ArmInvalidateInstructionCache ();
245 // Enable Instruction Caches on all cores.
246 ArmEnableInstructionCache ();
247
249 (VOID *)(UINTN)PcdGet64 (PcdCPUCoresStackBase),
250 PcdGet32 (PcdCPUCorePrimaryStackSize)
251 );
252 }
253
254 // Write VBAR - The Exception Vector table must be aligned to its requirement
255 // Note: The AArch64 Vector table must be 2k-byte aligned - if this assertion fails ensure
256 // 'Align=4K' is defined into your FDF for this module.
257 ASSERT (((UINTN)PeiVectorTable & ARM_VECTOR_TABLE_ALIGNMENT) == 0);
258 ArmWriteVBar ((UINTN)PeiVectorTable);
259
260 // Invoke "ProcessLibraryConstructorList" to have all library constructors
261 // called.
263
265
266 // Initialize the Debug Agent for Source Level Debugging
267 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);
269
270 // Initialize the platform specific controllers
271 ArmPlatformInitialize (ArmReadMpidr ());
272
273 // Goto primary Main.
274 SecMain (PeiCoreEntryPoint, TransferListBaseAddr);
275
276 // PEI Core should always load and never return
277 ASSERT (FALSE);
278}
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 VOID CreatePpiList(OUT UINTN *PpiListSize, OUT EFI_PEI_PPI_DESCRIPTOR **PpiList, IN VOID *TransferListBase)
Definition: Sec.c:93
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
STATIC VOID PrintFirmwareVersion(VOID)
Definition: Sec.c:139
VOID CEntryPoint(IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint, IN UINTN TransferListBaseAddr)
Definition: Sec.c:235
STATIC VOID EFIAPI SecMain(IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint, IN UINTN TransferListBaseAddr)
Definition: Sec.c:172
VOID PeiVectorTable(VOID)
VOID SecSwitchStack(INTN StackDelta)
VOID EFIAPI ProcessLibraryConstructorList(IN EFI_HANDLE ImageHandle, IN EFI_MM_SYSTEM_TABLE *MmSystemTable)
VOID EFIAPI TransferListDump(IN TRANSFER_LIST_HEADER *TransferListHeader)
TRANSFER_LIST_OPS EFIAPI TransferListCheckHeader(IN TRANSFER_LIST_HEADER *TransferListHeader)
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 VOID
Definition: Base.h:269
#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 DEBUG_CODE_BEGIN()
Definition: DebugLib.h:565
#define DEBUG(Expression)
Definition: DebugLib.h:435
#define DEBUG_CODE_END()
Definition: DebugLib.h:579
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#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