TianoCore EDK2 master
Loading...
Searching...
No Matches
FspmWrapperPeim.c
Go to the documentation of this file.
1
11#include <PiPei.h>
12
16#include <Library/BaseLib.h>
17#include <Library/DebugLib.h>
20#include <Library/HobLib.h>
21#include <Library/PcdLib.h>
22#include <Library/TimerLib.h>
29
31#include <Ppi/EndOfPeiPhase.h>
34#include <Ppi/Tcg.h>
37#include <FspEas.h>
38#include <FspStatusCode.h>
39#include <FspGlobalData.h>
41#include <Guid/MigratedFvInfo.h>
42
43extern EFI_GUID gFspHobGuid;
44
52 VOID
53 )
54{
55 if (PcdGet64 (PcdFspmUpdDataAddress64) != 0) {
56 return (UINTN)PcdGet64 (PcdFspmUpdDataAddress64);
57 } else {
58 return (UINTN)PcdGet32 (PcdFspmUpdDataAddress);
59 }
60}
61
69 VOID
70 )
71{
72 FSP_INFO_HEADER *FspmHeaderPtr;
73 EFI_STATUS Status;
74 UINT64 TimeStampCounterStart;
75 VOID *FspHobListPtr;
76 VOID *HobData;
77 VOID *FspmUpdDataPtr;
78 UINTN *SourceData;
79
80 DEBUG ((DEBUG_INFO, "PeiFspMemoryInit enter\n"));
81
82 FspHobListPtr = NULL;
83 FspmUpdDataPtr = NULL;
84
85 FspmHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress));
86 DEBUG ((DEBUG_INFO, "FspmHeaderPtr - 0x%x\n", FspmHeaderPtr));
87 if (FspmHeaderPtr == NULL) {
88 return EFI_DEVICE_ERROR;
89 }
90
91 if ((GetFspmUpdDataAddress () == 0) && (FspmHeaderPtr->CfgRegionSize != 0) && (FspmHeaderPtr->CfgRegionOffset != 0)) {
92 //
93 // Copy default FSP-M UPD data from Flash
94 //
95 FspmUpdDataPtr = AllocateZeroPool ((UINTN)FspmHeaderPtr->CfgRegionSize);
96 ASSERT (FspmUpdDataPtr != NULL);
97 SourceData = (UINTN *)((UINTN)FspmHeaderPtr->ImageBase + (UINTN)FspmHeaderPtr->CfgRegionOffset);
98 CopyMem (FspmUpdDataPtr, SourceData, (UINTN)FspmHeaderPtr->CfgRegionSize);
99 } else {
100 //
101 // External UPD is ready, get the buffer from PCD pointer.
102 //
103 FspmUpdDataPtr = (VOID *)GetFspmUpdDataAddress ();
104 ASSERT (FspmUpdDataPtr != NULL);
105 }
106
107 DEBUG ((DEBUG_INFO, "UpdateFspmUpdData enter\n"));
108 UpdateFspmUpdData (FspmUpdDataPtr);
109 if (((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.Revision >= 3) {
110 DEBUG ((DEBUG_INFO, " StackBase - 0x%lx\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.StackBase));
111 DEBUG ((DEBUG_INFO, " StackSize - 0x%lx\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.StackSize));
112 DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.BootLoaderTolumSize));
113 DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.BootMode));
114 } else {
115 DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.NvsBufferPtr));
116 DEBUG ((DEBUG_INFO, " StackBase - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.StackBase));
117 DEBUG ((DEBUG_INFO, " StackSize - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.StackSize));
118 DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.BootLoaderTolumSize));
119 DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.BootMode));
120 }
121
122 DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", &FspHobListPtr));
123
124 TimeStampCounterStart = AsmReadTsc ();
125 Status = CallFspMemoryInit (FspmUpdDataPtr, &FspHobListPtr);
126
127 //
128 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
129 //
130 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
131 DEBUG ((DEBUG_INFO, "FspMemoryInitApi requested reset %r\n", Status));
133 }
134
135 if ((Status != FSP_STATUS_VARIABLE_REQUEST) && EFI_ERROR (Status)) {
136 DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspMemoryInitApi(), Status = %r\n", Status));
137 ASSERT_EFI_ERROR (Status);
138 }
139
140 DEBUG ((DEBUG_INFO, "FspMemoryInit status: %r\n", Status));
141 if (Status == FSP_STATUS_VARIABLE_REQUEST) {
142 //
143 // call to Variable request handler
144 //
145 FspWrapperVariableRequestHandler (&FspHobListPtr, FspMultiPhaseMemInitApiIndex);
146 }
147
148 //
149 // See if MultiPhase process is required or not
150 //
151 FspWrapperMultiPhaseHandler (&FspHobListPtr, FspMultiPhaseMemInitApiIndex); // FspM MultiPhase
152
153 //
154 // Create hobs after memory initialization and not in temp RAM. Hence passing the recorded timestamp here
155 //
156 PERF_START_EX (&gFspApiPerformanceGuid, "EventRec", NULL, TimeStampCounterStart, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
157 PERF_END_EX (&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
158 DEBUG ((DEBUG_INFO, "Total time spent executing FspMemoryInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));
159
160 Status = TestFspMemoryInitApiOutput (FspmUpdDataPtr, &FspHobListPtr);
161 if (EFI_ERROR (Status)) {
162 DEBUG ((DEBUG_ERROR, "ERROR - TestFspMemoryInitApiOutput () fail, Status = %r\n", Status));
163 }
164
165 DEBUG ((DEBUG_INFO, " FspHobListPtr (returned) - 0x%x\n", FspHobListPtr));
166 ASSERT (FspHobListPtr != NULL);
167
168 PostFspmHobProcess (FspHobListPtr);
169
170 //
171 // FspHobList is not complete at this moment.
172 // Save FspHobList pointer to hob, so that it can be got later
173 //
174 HobData = BuildGuidHob (
175 &gFspHobGuid,
176 sizeof (VOID *)
177 );
178 ASSERT (HobData != NULL);
179 CopyMem (HobData, &FspHobListPtr, sizeof (FspHobListPtr));
180
181 return Status;
182}
183
190EFIAPI
192 VOID
193 )
194{
195 EFI_STATUS Status;
197 EFI_PEI_PPI_DESCRIPTOR *MeasurementExcludedPpiList;
198
199 MeasurementExcludedFvPpi = AllocatePool (sizeof (*MeasurementExcludedFvPpi));
200 ASSERT (MeasurementExcludedFvPpi != NULL);
201 if (MeasurementExcludedFvPpi == NULL) {
202 return EFI_OUT_OF_RESOURCES;
203 }
204
205 MeasurementExcludedFvPpi->Count = 1;
206 MeasurementExcludedFvPpi->Fv[0].FvBase = PcdGet32 (PcdFspmBaseAddress);
207 MeasurementExcludedFvPpi->Fv[0].FvLength = ((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FvLength;
208
209 MeasurementExcludedPpiList = AllocatePool (sizeof (*MeasurementExcludedPpiList));
210 ASSERT (MeasurementExcludedPpiList != NULL);
211 if (MeasurementExcludedPpiList == NULL) {
212 return EFI_OUT_OF_RESOURCES;
213 }
214
215 MeasurementExcludedPpiList->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
216 MeasurementExcludedPpiList->Guid = &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid;
217 MeasurementExcludedPpiList->Ppi = MeasurementExcludedFvPpi;
218
219 Status = EFI_SUCCESS;
220
221 if (PcdGet8 (PcdFspModeSelection) == 1) {
222 Status = PeiFspMemoryInit ();
223 ASSERT_EFI_ERROR (Status);
224 } else {
225 Status = PeiServicesInstallPpi (MeasurementExcludedPpiList);
226 ASSERT_EFI_ERROR (Status);
227
229 &((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FileSystemGuid,
230 (VOID *)(UINTN)PcdGet32 (PcdFspmBaseAddress),
231 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FvLength,
232 NULL,
233 NULL
234 );
235 }
236
237 return Status;
238}
239
251EFIAPI
253 IN EFI_PEI_SERVICES **PeiServices,
254 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
255 IN VOID *Ppi
256 );
257
258EFI_PEI_NOTIFY_DESCRIPTOR mTcgPpiNotifyDesc = {
259 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
260 &gEdkiiTcgPpiGuid,
262};
263
275EFIAPI
277 IN EFI_PEI_SERVICES **PeiServices,
278 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
279 IN VOID *Ppi
280 )
281{
282 UINT32 FspMeasureMask;
283 EFI_PHYSICAL_ADDRESS FsptBaseAddress;
284 EFI_PHYSICAL_ADDRESS FspmBaseAddress;
285 EDKII_MIGRATED_FV_INFO *MigratedFvInfo;
287
288 DEBUG ((DEBUG_INFO, "TcgPpiNotify FSPM\n"));
289
290 FspMeasureMask = PcdGet32 (PcdFspMeasurementConfig);
291 FsptBaseAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFsptBaseAddress);
292 FspmBaseAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFspmBaseAddress);
293 Hob.Raw = GetFirstGuidHob (&gEdkiiMigratedFvInfoGuid);
294 while (Hob.Raw != NULL) {
295 MigratedFvInfo = GET_GUID_HOB_DATA (Hob);
296 if ((MigratedFvInfo->FvOrgBase == PcdGet32 (PcdFsptBaseAddress)) && (MigratedFvInfo->FvDataBase != 0)) {
297 //
298 // Found the migrated FspT raw data
299 //
300 FsptBaseAddress = MigratedFvInfo->FvDataBase;
301 }
302
303 if ((MigratedFvInfo->FvOrgBase == PcdGet32 (PcdFspmBaseAddress)) && (MigratedFvInfo->FvDataBase != 0)) {
304 FspmBaseAddress = MigratedFvInfo->FvDataBase;
305 }
306
307 Hob.Raw = GET_NEXT_HOB (Hob);
308 Hob.Raw = GetNextGuidHob (&gEdkiiMigratedFvInfoGuid, Hob.Raw);
309 }
310
311 if ((FspMeasureMask & FSP_MEASURE_FSPT) != 0) {
313 0,
314 "FSPT",
315 FsptBaseAddress,
316 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FsptBaseAddress)->FvLength
317 );
318 }
319
320 if ((FspMeasureMask & FSP_MEASURE_FSPM) != 0) {
322 0,
323 "FSPM",
324 FspmBaseAddress,
325 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FspmBaseAddress)->FvLength
326 );
327 }
328
329 return EFI_SUCCESS;
330}
331
341EFIAPI
343 IN EFI_PEI_FILE_HANDLE FileHandle,
344 IN CONST EFI_PEI_SERVICES **PeiServices
345 )
346{
347 EFI_STATUS Status;
348
349 DEBUG ((DEBUG_INFO, "FspmWrapperPeimEntryPoint\n"));
350
351 Status = PeiServicesNotifyPpi (&mTcgPpiNotifyDesc);
352 ASSERT_EFI_ERROR (Status);
353
355
356 return EFI_SUCCESS;
357}
UINT64 UINTN
UINT64 EFIAPI GetTimeInNanoSecond(IN UINT64 Ticks)
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI BuildGuidHob(IN CONST EFI_GUID *Guid, IN UINTN DataLength)
Definition: HobLib.c:336
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
Definition: HobLib.c:176
UINT64 EFIAPI AsmReadTsc(VOID)
Definition: GccInline.c:555
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI PeiServicesInstallFvInfoPpi(IN CONST EFI_GUID *FvFormat OPTIONAL, IN CONST VOID *FvInfo, IN UINT32 FvInfoSize, IN CONST EFI_GUID *ParentFvName OPTIONAL, IN CONST EFI_GUID *ParentFileName OPTIONAL)
EFI_STATUS EFIAPI PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
EFI_STATUS EFIAPI MeasureFspFirmwareBlob(IN UINT32 PcrIndex, IN CHAR8 *Description OPTIONAL, IN EFI_PHYSICAL_ADDRESS FirmwareBlobBase, IN UINT64 FirmwareBlobLength)
EFI_STATUS EFIAPI CallFspMemoryInit(IN VOID *FspmUpdDataPtr, OUT VOID **HobListPtr)
FSP_INFO_HEADER *EFIAPI FspFindFspHeader(IN EFI_PHYSICAL_ADDRESS FlashFvFspBase)
EFI_STATUS EFIAPI TestFspMemoryInitApiOutput(IN VOID *FspmUpdDataPtr, IN VOID **HobListPtr)
EFI_STATUS EFIAPI PostFspmHobProcess(IN VOID *FspHobList)
EFI_STATUS EFIAPI FspWrapperVariableRequestHandler(IN OUT VOID **FspHobListPtr, IN UINT8 ComponentIndex)
EFI_STATUS EFIAPI FspWrapperMultiPhaseHandler(IN OUT VOID **FspHobListPtr, IN UINT8 ComponentIndex)
VOID EFIAPI CallFspWrapperResetSystem(IN EFI_STATUS FspStatusResetType)
VOID EFIAPI UpdateFspmUpdData(IN OUT VOID *FspUpdRgnPtr)
EFI_STATUS EFIAPI FspmWrapperPeimEntryPoint(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI TcgPpiNotify(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, IN VOID *Ppi)
EFI_STATUS PeiFspMemoryInit(VOID)
EFI_STATUS EFIAPI FspmWrapperInit(VOID)
UINTN GetFspmUpdDataAddress(VOID)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define PERF_START_EX(Handle, Token, Module, TimeStamp, Identifier)
#define PERF_END_EX(Handle, Token, Module, TimeStamp, Identifier)
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
UINT32 CfgRegionOffset
Definition: Base.h:213