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 - 2021, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Library/PeimEntryPoint.h>
14 #include <Library/PeiServicesLib.h>
15 #include <Library/PeiServicesTablePointerLib.h>
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/HobLib.h>
21 #include <Library/PcdLib.h>
22 #include <Library/TimerLib.h>
23 #include <Library/PerformanceLib.h>
24 #include <Library/FspWrapperPlatformLib.h>
25 #include <Library/FspWrapperHobProcessLib.h>
26 #include <Library/FspWrapperApiLib.h>
27 #include <Library/FspMeasurementLib.h>
29 #include <Ppi/FspSiliconInitDone.h>
30 #include <Ppi/EndOfPeiPhase.h>
31 #include <Ppi/MemoryDiscovered.h>
32 #include <Ppi/SecPlatformInformation.h>
34 #include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>
35 #include <Library/FspWrapperApiTestLib.h>
37 #include <FspStatusCode.h>
39 extern EFI_GUID gFspHobGuid
;
42 Get the FSP M UPD Data address
44 @return FSP-M UPD Data Address
49 GetFspmUpdDataAddress (
53 if (PcdGet64 (PcdFspmUpdDataAddress64
) != 0) {
54 return (UINTN
) PcdGet64 (PcdFspmUpdDataAddress64
);
56 return (UINTN
) PcdGet32 (PcdFspmUpdDataAddress
);
61 Call FspMemoryInit API.
63 @return Status returned by FspMemoryInit API.
70 FSP_INFO_HEADER
*FspmHeaderPtr
;
72 UINT64 TimeStampCounterStart
;
75 FSPM_UPD_COMMON
*FspmUpdDataPtr
;
78 DEBUG ((DEBUG_INFO
, "PeiFspMemoryInit enter\n"));
81 FspmUpdDataPtr
= NULL
;
83 FspmHeaderPtr
= (FSP_INFO_HEADER
*)FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress
));
84 DEBUG ((DEBUG_INFO
, "FspmHeaderPtr - 0x%x\n", FspmHeaderPtr
));
85 if (FspmHeaderPtr
== NULL
) {
86 return EFI_DEVICE_ERROR
;
89 if ((GetFspmUpdDataAddress () == 0) && (FspmHeaderPtr
->CfgRegionSize
!= 0) && (FspmHeaderPtr
->CfgRegionOffset
!= 0)) {
91 // Copy default FSP-M UPD data from Flash
93 FspmUpdDataPtr
= (FSPM_UPD_COMMON
*)AllocateZeroPool ((UINTN
)FspmHeaderPtr
->CfgRegionSize
);
94 ASSERT (FspmUpdDataPtr
!= NULL
);
95 SourceData
= (UINTN
*)((UINTN
)FspmHeaderPtr
->ImageBase
+ (UINTN
)FspmHeaderPtr
->CfgRegionOffset
);
96 CopyMem (FspmUpdDataPtr
, SourceData
, (UINTN
)FspmHeaderPtr
->CfgRegionSize
);
99 // External UPD is ready, get the buffer from PCD pointer.
101 FspmUpdDataPtr
= (FSPM_UPD_COMMON
*) GetFspmUpdDataAddress();
102 ASSERT (FspmUpdDataPtr
!= NULL
);
105 DEBUG ((DEBUG_INFO
, "UpdateFspmUpdData enter\n"));
106 UpdateFspmUpdData ((VOID
*)FspmUpdDataPtr
);
107 DEBUG ((DEBUG_INFO
, " NvsBufferPtr - 0x%x\n", FspmUpdDataPtr
->FspmArchUpd
.NvsBufferPtr
));
108 DEBUG ((DEBUG_INFO
, " StackBase - 0x%x\n", FspmUpdDataPtr
->FspmArchUpd
.StackBase
));
109 DEBUG ((DEBUG_INFO
, " StackSize - 0x%x\n", FspmUpdDataPtr
->FspmArchUpd
.StackSize
));
110 DEBUG ((DEBUG_INFO
, " BootLoaderTolumSize - 0x%x\n", FspmUpdDataPtr
->FspmArchUpd
.BootLoaderTolumSize
));
111 DEBUG ((DEBUG_INFO
, " BootMode - 0x%x\n", FspmUpdDataPtr
->FspmArchUpd
.BootMode
));
112 DEBUG ((DEBUG_INFO
, " HobListPtr - 0x%x\n", &FspHobListPtr
));
114 TimeStampCounterStart
= AsmReadTsc ();
115 Status
= CallFspMemoryInit (FspmUpdDataPtr
, &FspHobListPtr
);
116 // Create hobs after memory initialization and not in temp RAM. Hence passing the recorded timestamp here
117 PERF_START_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, TimeStampCounterStart
, FSP_STATUS_CODE_MEMORY_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_ENTRY
);
118 PERF_END_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_MEMORY_INIT
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_EXIT
);
119 DEBUG ((DEBUG_INFO
, "Total time spent executing FspMemoryInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart
), 1000000)));
122 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
124 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
125 DEBUG ((DEBUG_INFO
, "FspMemoryInitApi requested reset 0x%x\n", Status
));
126 CallFspWrapperResetSystem ((UINT32
)Status
);
129 if (EFI_ERROR (Status
)) {
130 DEBUG ((DEBUG_ERROR
, "ERROR - Failed to execute FspMemoryInitApi(), Status = %r\n", Status
));
133 DEBUG ((DEBUG_INFO
, "FspMemoryInit status: 0x%x\n", Status
));
134 ASSERT_EFI_ERROR (Status
);
136 Status
= TestFspMemoryInitApiOutput (FspmUpdDataPtr
, &FspHobListPtr
);
137 if (EFI_ERROR (Status
)) {
138 DEBUG ((DEBUG_ERROR
, "ERROR - TestFspMemoryInitApiOutput () fail, Status = %r\n", Status
));
141 DEBUG ((DEBUG_INFO
, " FspHobListPtr (returned) - 0x%x\n", FspHobListPtr
));
142 ASSERT (FspHobListPtr
!= NULL
);
144 PostFspmHobProcess (FspHobListPtr
);
147 // FspHobList is not complete at this moment.
148 // Save FspHobList pointer to hob, so that it can be got later
150 HobData
= BuildGuidHob (
154 ASSERT (HobData
!= NULL
);
155 CopyMem (HobData
, &FspHobListPtr
, sizeof (FspHobListPtr
));
161 Do FSP initialization.
163 @return FSP initialization status.
172 EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI
*MeasurementExcludedFvPpi
;
173 EFI_PEI_PPI_DESCRIPTOR
*MeasurementExcludedPpiList
;
175 MeasurementExcludedFvPpi
= AllocatePool (sizeof (*MeasurementExcludedFvPpi
));
176 ASSERT (MeasurementExcludedFvPpi
!= NULL
);
177 MeasurementExcludedFvPpi
->Count
= 1;
178 MeasurementExcludedFvPpi
->Fv
[0].FvBase
= PcdGet32 (PcdFspmBaseAddress
);
179 MeasurementExcludedFvPpi
->Fv
[0].FvLength
= ((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)PcdGet32 (PcdFspmBaseAddress
))->FvLength
;
181 MeasurementExcludedPpiList
= AllocatePool (sizeof (*MeasurementExcludedPpiList
));
182 ASSERT (MeasurementExcludedPpiList
!= NULL
);
183 MeasurementExcludedPpiList
->Flags
= EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
184 MeasurementExcludedPpiList
->Guid
= &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid
;
185 MeasurementExcludedPpiList
->Ppi
= MeasurementExcludedFvPpi
;
187 Status
= EFI_SUCCESS
;
189 if (PcdGet8 (PcdFspModeSelection
) == 1) {
190 Status
= PeiFspMemoryInit ();
191 ASSERT_EFI_ERROR (Status
);
193 Status
= PeiServicesInstallPpi (MeasurementExcludedPpiList
);
194 ASSERT_EFI_ERROR (Status
);
196 PeiServicesInstallFvInfoPpi (
198 (VOID
*)(UINTN
)PcdGet32 (PcdFspmBaseAddress
),
199 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)PcdGet32 (PcdFspmBaseAddress
))->FvLength
,
209 This function is called after TCG installed PPI.
211 @param[in] PeiServices Pointer to PEI Services Table.
212 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
213 caused this function to execute.
214 @param[in] Ppi Pointer to the PPI data associated with this function.
216 @retval EFI_STATUS Always return EFI_SUCCESS
221 IN EFI_PEI_SERVICES
**PeiServices
,
222 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
226 EFI_PEI_NOTIFY_DESCRIPTOR mTcgPpiNotifyDesc
= {
227 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
233 This function is called after TCG installed PPI.
235 @param[in] PeiServices Pointer to PEI Services Table.
236 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
237 caused this function to execute.
238 @param[in] Ppi Pointer to the PPI data associated with this function.
240 @retval EFI_STATUS Always return EFI_SUCCESS
245 IN EFI_PEI_SERVICES
**PeiServices
,
246 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
250 UINT32 FspMeasureMask
;
252 DEBUG ((DEBUG_INFO
, "TcgPpiNotify FSPM\n"));
254 FspMeasureMask
= PcdGet32 (PcdFspMeasurementConfig
);
256 if ((FspMeasureMask
& FSP_MEASURE_FSPT
) != 0) {
257 MeasureFspFirmwareBlob (
260 PcdGet32 (PcdFsptBaseAddress
),
261 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)PcdGet32 (PcdFsptBaseAddress
))->FvLength
265 if ((FspMeasureMask
& FSP_MEASURE_FSPM
) != 0) {
266 MeasureFspFirmwareBlob (
269 PcdGet32 (PcdFspmBaseAddress
),
270 (UINT32
)((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)PcdGet32 (PcdFspmBaseAddress
))->FvLength
278 This is the entrypoint of PEIM
280 @param[in] FileHandle Handle of the file being invoked.
281 @param[in] PeiServices Describes the list of possible PEI Services.
283 @retval EFI_SUCCESS if it completed successfully.
287 FspmWrapperPeimEntryPoint (
288 IN EFI_PEI_FILE_HANDLE FileHandle
,
289 IN CONST EFI_PEI_SERVICES
**PeiServices
294 DEBUG ((DEBUG_INFO
, "FspmWrapperPeimEntryPoint\n"));
296 Status
= PeiServicesNotifyPpi (&mTcgPpiNotifyDesc
);
297 ASSERT_EFI_ERROR (Status
);