TianoCore EDK2 master
Loading...
Searching...
No Matches
PeilessSec.c
Go to the documentation of this file.
1
9#include "PeilessSec.h"
10
11#define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) ||\
12 ((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= FixedPcdGet64 (PcdSystemMemoryBase)))
13
14UINT64 mSystemMemoryEnd = FixedPcdGet64 (PcdSystemMemoryBase) +
15 FixedPcdGet64 (PcdSystemMemorySize) - 1;
16
28 IN EFI_GUID *PpiGuid,
29 OUT VOID **Ppi
30 )
31{
32 UINTN PpiListSize;
33 UINTN PpiListCount;
35 UINTN Index;
36
37 PpiListSize = 0;
38 ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);
39 PpiListCount = PpiListSize / sizeof (EFI_PEI_PPI_DESCRIPTOR);
40 for (Index = 0; Index < PpiListCount; Index++, PpiList++) {
41 if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {
42 *Ppi = PpiList->Ppi;
43 return EFI_SUCCESS;
44 }
45 }
46
47 return EFI_NOT_FOUND;
48}
49
58VOID
60 IN UINTN UefiMemoryBase,
61 IN UINTN StackBase,
62 IN UINT64 StartTimeStamp
63 )
64{
66 ARM_MP_CORE_INFO_PPI *ArmMpCoreInfoPpi;
67 UINTN ArmCoreCount;
68 ARM_CORE_INFO *ArmCoreInfoTable;
69 EFI_STATUS Status;
70 CHAR8 Buffer[100];
71 UINTN CharCount;
72 UINTN StacksSize;
73 FIRMWARE_SEC_PERFORMANCE Performance;
74
75 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)
76 ASSERT (
77 IS_XIP () ||
78 ((FixedPcdGet64 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&
79 ((UINT64)(FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT64)mSystemMemoryEnd))
80 );
81
82 // Initialize the architecture specific bits
84
85 // Initialize the Serial Port
87 CharCount = AsciiSPrint (
88 Buffer,
89 sizeof (Buffer),
90 "UEFI firmware (version %s built at %a on %a)\n\r",
91 (CHAR16 *)PcdGetPtr (PcdFirmwareVersionString),
92 __TIME__,
93 __DATE__
94 );
95 SerialPortWrite ((UINT8 *)Buffer, CharCount);
96
97 // Initialize the Debug Agent for Source Level Debugging
98 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);
100
101 // Declare the PI/UEFI memory region
102 HobList = HobConstructor (
103 (VOID *)UefiMemoryBase,
104 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),
105 (VOID *)UefiMemoryBase,
106 (VOID *)StackBase // The top of the UEFI Memory is reserved for the stack
107 );
108 PrePeiSetHobList (HobList);
109
110 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
111 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
112 ASSERT_EFI_ERROR (Status);
113
114 // Create the Stacks HOB
115 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);
116 BuildStackHob (StackBase, StacksSize);
117
118 // TODO: Call CpuPei as a library
119 BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));
120
121 if (ArmIsMpCore ()) {
122 // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid
123 Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID **)&ArmMpCoreInfoPpi);
124
125 // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)
126 ASSERT_EFI_ERROR (Status);
127
128 // Build the MP Core Info Table
129 ArmCoreCount = 0;
130 Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);
131 if (!EFI_ERROR (Status) && (ArmCoreCount > 0)) {
132 // Build MPCore Info HOB
133 BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount);
134 }
135 }
136
137 // Store timer value logged at the beginning of firmware image execution
138 Performance.ResetEnd = GetTimeInNanoSecond (StartTimeStamp);
139
140 // Build SEC Performance Data Hob
141 BuildGuidDataHob (&gEfiFirmwarePerformanceGuid, &Performance, sizeof (Performance));
142
143 // Set the Boot Mode
145
146 // Initialize Platform HOBs (CpuHob and FvHob)
147 Status = PlatformPeim ();
148 ASSERT_EFI_ERROR (Status);
149
150 // Now, the HOB List has been initialized, we can register performance information
151 PERF_START (NULL, "PEI", NULL, StartTimeStamp);
152
153 // SEC phase needs to run library constructors by hand.
154 ProcessLibraryConstructorList ();
155
156 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
157 Status = DecompressFirstFv ();
158 ASSERT_EFI_ERROR (Status);
159
160 // Load the DXE Core and transfer control to it
161 Status = LoadDxeCoreFromFv (NULL, 0);
162 ASSERT_EFI_ERROR (Status);
163}
164
171VOID
173 IN UINTN UefiMemoryBase,
174 IN UINTN StackBase
175 )
176{
177 UINT64 StartTimeStamp;
178
179 // Initialize the platform specific controllers
180 ArmPlatformInitialize (ArmReadMpidr ());
181
183 // We cannot call yet the PerformanceLib because the HOB List has not been initialized
184 StartTimeStamp = GetPerformanceCounter ();
185 } else {
186 StartTimeStamp = 0;
187 }
188
189 // Data Cache enabled on Primary core when MMU is enabled.
190 ArmDisableDataCache ();
191 // Invalidate instruction cache
192 ArmInvalidateInstructionCache ();
193 // Enable Instruction Caches on all cores.
194 ArmEnableInstructionCache ();
195
197 (VOID *)UefiMemoryBase,
198 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)
199 );
200
201 SecMain (UefiMemoryBase, StackBase, StartTimeStamp);
202
203 // DXE Core should always load and never return
204 ASSERT (FALSE);
205}
VOID ArchInitialize(VOID)
UINT64 UINTN
UINT64 EFIAPI GetTimeInNanoSecond(IN UINT64 Ticks)
UINT64 EFIAPI GetPerformanceCounter(VOID)
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)
EFI_BOOT_MODE ArmPlatformGetBootMode(VOID)
EFI_STATUS EFIAPI PrePeiSetHobList(IN VOID *HobList)
VOID *EFIAPI BuildGuidDataHob(IN CONST EFI_GUID *Guid, IN VOID *Data, IN UINTN DataLength)
Definition: HobLib.c:375
VOID EFIAPI BuildCpuHob(IN UINT8 SizeOfMemorySpace, IN UINT8 SizeOfIoSpace)
Definition: HobLib.c:520
VOID EFIAPI BuildStackHob(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
Definition: HobLib.c:546
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
BOOLEAN EFIAPI SaveAndSetDebugTimerInterrupt(IN BOOLEAN EnableStatus)
VOID EFIAPI InitializeDebugAgent(IN UINT32 InitFlag, IN VOID *Context OPTIONAL, IN DEBUG_AGENT_CONTINUE Function OPTIONAL)
BOOLEAN EFIAPI PerformanceMeasurementEnabled(VOID)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#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 ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
EFI_STATUS EFIAPI MemoryPeim(IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, IN UINT64 UefiMemorySize)
#define FixedPcdGet32(TokenName)
Definition: PcdLib.h:92
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define FixedPcdGet64(TokenName)
Definition: PcdLib.h:106
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
STATIC EFI_STATUS GetPlatformPpi(IN EFI_GUID *PpiGuid, OUT VOID **Ppi)
Definition: PeilessSec.c:27
VOID CEntryPoint(IN UINTN UefiMemoryBase, IN UINTN StackBase)
Definition: PeilessSec.c:172
STATIC VOID SecMain(IN UINTN UefiMemoryBase, IN UINTN StackBase, IN UINT64 StartTimeStamp)
Definition: PeilessSec.c:59
EFI_STATUS EFIAPI PlatformPeim(VOID)
#define PERF_START(Handle, Token, Module, TimeStamp)
EFI_STATUS EFIAPI SetBootMode(IN EFI_BOOT_MODE BootMode)
Definition: Hob.c:364
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
UINT64 ResetEnd
Timer value logged at the beginning of firmware image execution, in unit of nanosecond.
Definition: Base.h:213