2 This will be invoked only once. It will call FspMemoryInit API,
3 register TemporaryRamDonePpi to call TempRamExit API, and register MemoryDiscoveredPpi
4 notify to call FspSiliconInit API.
6 Copyright (c) 2014 - 2020, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <Library/PeimEntryPoint.h>
15 #include <Library/PeiServicesLib.h>
16 #include <Library/PeiServicesTablePointerLib.h>
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/HobLib.h>
22 #include <Library/PcdLib.h>
23 #include <Library/TimerLib.h>
24 #include <Library/PerformanceLib.h>
25 #include <Library/FspWrapperPlatformLib.h>
26 #include <Library/FspWrapperHobProcessLib.h>
27 #include <Library/FspWrapperApiLib.h>
28 #include <Library/FspMeasurementLib.h>
30 #include <Ppi/FspSiliconInitDone.h>
31 #include <Ppi/EndOfPeiPhase.h>
32 #include <Ppi/MemoryDiscovered.h>
33 #include <Ppi/SecPlatformInformation.h>
35 #include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>
36 #include <Library/FspWrapperApiTestLib.h>
38 #include <FspStatusCode.h>
40 extern EFI_GUID gFspHobGuid
;
43 Call FspMemoryInit API.
45 @return Status returned by FspMemoryInit API.
52 FSP_INFO_HEADER
*FspmHeaderPtr
;
54 UINT64 TimeStampCounterStart
;
57 FSPM_UPD_COMMON
*FspmUpdDataPtr
;
60 DEBUG ((DEBUG_INFO
, "PeiFspMemoryInit enter\n"));
63 FspmUpdDataPtr
= NULL
;
65 FspmHeaderPtr
= (FSP_INFO_HEADER
*) FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress
));
66 DEBUG ((DEBUG_INFO
, "FspmHeaderPtr - 0x%x\n", FspmHeaderPtr
));
67 if (FspmHeaderPtr
== NULL
) {
68 return EFI_DEVICE_ERROR
;
71 if (PcdGet32 (PcdFspmUpdDataAddress
) == 0 && (FspmHeaderPtr
->CfgRegionSize
!= 0) && (FspmHeaderPtr
->CfgRegionOffset
!= 0)) {
73 // Copy default FSP-M UPD data from Flash
75 FspmUpdDataPtr
= (FSPM_UPD_COMMON
*)AllocateZeroPool ((UINTN
)FspmHeaderPtr
->CfgRegionSize
);
76 ASSERT (FspmUpdDataPtr
!= NULL
);
77 SourceData
= (UINTN
*)((UINTN
)FspmHeaderPtr
->ImageBase
+ (UINTN
)FspmHeaderPtr
->CfgRegionOffset
);
78 CopyMem (FspmUpdDataPtr
, SourceData
, (UINTN
)FspmHeaderPtr
->CfgRegionSize
);
81 // External UPD is ready, get the buffer from PCD pointer.
83 FspmUpdDataPtr
= (FSPM_UPD_COMMON
*)PcdGet32 (PcdFspmUpdDataAddress
);
84 ASSERT (FspmUpdDataPtr
!= NULL
);
87 DEBUG ((DEBUG_INFO
, "UpdateFspmUpdData enter\n"));
88 UpdateFspmUpdData ((VOID
*)FspmUpdDataPtr
);
89 DEBUG ((DEBUG_INFO
, " NvsBufferPtr - 0x%x\n", FspmUpdDataPtr
->FspmArchUpd
.NvsBufferPtr
));
90 DEBUG ((DEBUG_INFO
, " StackBase - 0x%x\n", FspmUpdDataPtr
->FspmArchUpd
.StackBase
));
91 DEBUG ((DEBUG_INFO
, " StackSize - 0x%x\n", FspmUpdDataPtr
->FspmArchUpd
.StackSize
));
92 DEBUG ((DEBUG_INFO
, " BootLoaderTolumSize - 0x%x\n", FspmUpdDataPtr
->FspmArchUpd
.BootLoaderTolumSize
));
93 DEBUG ((DEBUG_INFO
, " BootMode - 0x%x\n", FspmUpdDataPtr
->FspmArchUpd
.BootMode
));
94 DEBUG ((DEBUG_INFO
, " HobListPtr - 0x%x\n", &FspHobListPtr
));
96 TimeStampCounterStart
= AsmReadTsc ();
97 Status
= CallFspMemoryInit (FspmUpdDataPtr
, &FspHobListPtr
);
98 // Create hobs after memory initialization and not in temp RAM. Hence passing the recorded timestamp here
99 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, TimeStampCounterStart
, FSP_STATUS_CODE_MEMORY_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_ENTRY
);
100 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_MEMORY_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_EXIT
);
101 DEBUG ((DEBUG_INFO
, "Total time spent executing FspMemoryInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart
), 1000000)));
104 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
106 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
107 DEBUG((DEBUG_INFO
, "FspMemoryInitApi requested reset 0x%x\n", Status
));
108 CallFspWrapperResetSystem ((UINT32
)Status
);
111 if (EFI_ERROR(Status
)) {
112 DEBUG ((DEBUG_ERROR
, "ERROR - Failed to execute FspMemoryInitApi(), Status = %r\n", Status
));
114 DEBUG((DEBUG_INFO
, "FspMemoryInit status: 0x%x\n", Status
));
115 ASSERT_EFI_ERROR (Status
);
118 Status
= TestFspMemoryInitApiOutput (FspmUpdDataPtr
, &FspHobListPtr
);
119 if (EFI_ERROR (Status
)) {
120 DEBUG ((DEBUG_ERROR
, "ERROR - TestFspMemoryInitApiOutput () fail, Status = %r\n", Status
));
123 DEBUG ((DEBUG_INFO
, " FspHobListPtr (returned) - 0x%x\n", FspHobListPtr
));
124 ASSERT (FspHobListPtr
!= NULL
);
126 PostFspmHobProcess (FspHobListPtr
);
129 // FspHobList is not complete at this moment.
130 // Save FspHobList pointer to hob, so that it can be got later
132 HobData
= BuildGuidHob (
136 ASSERT (HobData
!= NULL
);
137 CopyMem (HobData
, &FspHobListPtr
, sizeof (FspHobListPtr
));
143 Do FSP initialization.
145 @return FSP initialization status.
154 EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI
*MeasurementExcludedFvPpi
;
155 EFI_PEI_PPI_DESCRIPTOR
*MeasurementExcludedPpiList
;
157 MeasurementExcludedFvPpi
= AllocatePool (sizeof(*MeasurementExcludedFvPpi
));
158 ASSERT(MeasurementExcludedFvPpi
!= NULL
);
159 MeasurementExcludedFvPpi
->Count
= 1;
160 MeasurementExcludedFvPpi
->Fv
[0].FvBase
= PcdGet32 (PcdFspmBaseAddress
);
161 MeasurementExcludedFvPpi
->Fv
[0].FvLength
= ((EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) PcdGet32 (PcdFspmBaseAddress
))->FvLength
;
163 MeasurementExcludedPpiList
= AllocatePool (sizeof(*MeasurementExcludedPpiList
));
164 ASSERT(MeasurementExcludedPpiList
!= NULL
);
165 MeasurementExcludedPpiList
->Flags
= EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
166 MeasurementExcludedPpiList
->Guid
= &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid
;
167 MeasurementExcludedPpiList
->Ppi
= MeasurementExcludedFvPpi
;
169 Status
= EFI_SUCCESS
;
171 if (PcdGet8 (PcdFspModeSelection
) == 1) {
172 Status
= PeiFspMemoryInit ();
173 ASSERT_EFI_ERROR (Status
);
175 Status
= PeiServicesInstallPpi (MeasurementExcludedPpiList
);
176 ASSERT_EFI_ERROR (Status
);
178 PeiServicesInstallFvInfoPpi (
180 (VOID
*)(UINTN
) PcdGet32 (PcdFspmBaseAddress
),
181 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) PcdGet32 (PcdFspmBaseAddress
))->FvLength
,
191 This function is called after TCG installed PPI.
193 @param[in] PeiServices Pointer to PEI Services Table.
194 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
195 caused this function to execute.
196 @param[in] Ppi Pointer to the PPI data associated with this function.
198 @retval EFI_STATUS Always return EFI_SUCCESS
203 IN EFI_PEI_SERVICES
**PeiServices
,
204 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
208 EFI_PEI_NOTIFY_DESCRIPTOR mTcgPpiNotifyDesc
= {
209 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
215 This function is called after TCG installed PPI.
217 @param[in] PeiServices Pointer to PEI Services Table.
218 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
219 caused this function to execute.
220 @param[in] Ppi Pointer to the PPI data associated with this function.
222 @retval EFI_STATUS Always return EFI_SUCCESS
227 IN EFI_PEI_SERVICES
**PeiServices
,
228 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
232 UINT32 FspMeasureMask
;
234 DEBUG ((DEBUG_INFO
, "TcgPpiNotify FSPM\n"));
236 FspMeasureMask
= PcdGet32 (PcdFspMeasurementConfig
);
238 if ((FspMeasureMask
& FSP_MEASURE_FSPT
) != 0) {
239 MeasureFspFirmwareBlob (0, "FSPT", PcdGet32(PcdFsptBaseAddress
),
240 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) PcdGet32 (PcdFsptBaseAddress
))->FvLength
);
243 if ((FspMeasureMask
& FSP_MEASURE_FSPM
) != 0) {
244 MeasureFspFirmwareBlob (0, "FSPM", PcdGet32(PcdFspmBaseAddress
),
245 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) PcdGet32 (PcdFspmBaseAddress
))->FvLength
);
252 This is the entrypoint of PEIM
254 @param[in] FileHandle Handle of the file being invoked.
255 @param[in] PeiServices Describes the list of possible PEI Services.
257 @retval EFI_SUCCESS if it completed successfully.
261 FspmWrapperPeimEntryPoint (
262 IN EFI_PEI_FILE_HANDLE FileHandle
,
263 IN CONST EFI_PEI_SERVICES
**PeiServices
268 DEBUG((DEBUG_INFO
, "FspmWrapperPeimEntryPoint\n"));
270 Status
= PeiServicesNotifyPpi (&mTcgPpiNotifyDesc
);
271 ASSERT_EFI_ERROR (Status
);