VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.c@ 101291

Last change on this file since 101291 was 101291, checked in by vboxsync, 14 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

  • Property svn:eol-style set to native
File size: 10.7 KB
Line 
1/** @file
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.
5
6 Copyright (c) 2014 - 2022, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#include <PiPei.h>
12
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/FspWrapperMultiPhaseProcessLib.h>
27#include <Library/FspWrapperApiLib.h>
28#include <Library/FspMeasurementLib.h>
29
30#include <Ppi/FspSiliconInitDone.h>
31#include <Ppi/EndOfPeiPhase.h>
32#include <Ppi/MemoryDiscovered.h>
33#include <Ppi/SecPlatformInformation.h>
34#include <Ppi/Tcg.h>
35#include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>
36#include <Library/FspWrapperApiTestLib.h>
37#include <FspEas.h>
38#include <FspStatusCode.h>
39#include <FspGlobalData.h>
40#include <Library/FspCommonLib.h>
41
42extern EFI_GUID gFspHobGuid;
43
44/**
45 Get the FSP M UPD Data address
46
47 @return FSP-M UPD Data Address
48**/
49UINTN
50GetFspmUpdDataAddress (
51 VOID
52 )
53{
54 if (PcdGet64 (PcdFspmUpdDataAddress64) != 0) {
55 return (UINTN)PcdGet64 (PcdFspmUpdDataAddress64);
56 } else {
57 return (UINTN)PcdGet32 (PcdFspmUpdDataAddress);
58 }
59}
60
61/**
62 Call FspMemoryInit API.
63
64 @return Status returned by FspMemoryInit API.
65**/
66EFI_STATUS
67PeiFspMemoryInit (
68 VOID
69 )
70{
71 FSP_INFO_HEADER *FspmHeaderPtr;
72 EFI_STATUS Status;
73 UINT64 TimeStampCounterStart;
74 VOID *FspHobListPtr;
75 VOID *HobData;
76 VOID *FspmUpdDataPtr;
77 UINTN *SourceData;
78
79 DEBUG ((DEBUG_INFO, "PeiFspMemoryInit enter\n"));
80
81 FspHobListPtr = NULL;
82 FspmUpdDataPtr = NULL;
83
84 FspmHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress));
85 DEBUG ((DEBUG_INFO, "FspmHeaderPtr - 0x%x\n", FspmHeaderPtr));
86 if (FspmHeaderPtr == NULL) {
87 return EFI_DEVICE_ERROR;
88 }
89
90 if ((GetFspmUpdDataAddress () == 0) && (FspmHeaderPtr->CfgRegionSize != 0) && (FspmHeaderPtr->CfgRegionOffset != 0)) {
91 //
92 // Copy default FSP-M UPD data from Flash
93 //
94 FspmUpdDataPtr = AllocateZeroPool ((UINTN)FspmHeaderPtr->CfgRegionSize);
95 ASSERT (FspmUpdDataPtr != NULL);
96 SourceData = (UINTN *)((UINTN)FspmHeaderPtr->ImageBase + (UINTN)FspmHeaderPtr->CfgRegionOffset);
97 CopyMem (FspmUpdDataPtr, SourceData, (UINTN)FspmHeaderPtr->CfgRegionSize);
98 } else {
99 //
100 // External UPD is ready, get the buffer from PCD pointer.
101 //
102 FspmUpdDataPtr = (VOID *)GetFspmUpdDataAddress ();
103 ASSERT (FspmUpdDataPtr != NULL);
104 }
105
106 DEBUG ((DEBUG_INFO, "UpdateFspmUpdData enter\n"));
107 UpdateFspmUpdData (FspmUpdDataPtr);
108 if (((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.Revision >= 3) {
109 DEBUG ((DEBUG_INFO, " StackBase - 0x%lx\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.StackBase));
110 DEBUG ((DEBUG_INFO, " StackSize - 0x%lx\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.StackSize));
111 DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.BootLoaderTolumSize));
112 DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.BootMode));
113 } else {
114 DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.NvsBufferPtr));
115 DEBUG ((DEBUG_INFO, " StackBase - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.StackBase));
116 DEBUG ((DEBUG_INFO, " StackSize - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.StackSize));
117 DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.BootLoaderTolumSize));
118 DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.BootMode));
119 }
120
121 DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", &FspHobListPtr));
122
123 TimeStampCounterStart = AsmReadTsc ();
124 Status = CallFspMemoryInit (FspmUpdDataPtr, &FspHobListPtr);
125
126 //
127 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
128 //
129 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
130 DEBUG ((DEBUG_INFO, "FspMemoryInitApi requested reset %r\n", Status));
131 CallFspWrapperResetSystem (Status);
132 }
133
134 if ((Status != FSP_STATUS_VARIABLE_REQUEST) && EFI_ERROR (Status)) {
135 DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspMemoryInitApi(), Status = %r\n", Status));
136 ASSERT_EFI_ERROR (Status);
137 }
138
139 DEBUG ((DEBUG_INFO, "FspMemoryInit status: %r\n", Status));
140 if (Status == FSP_STATUS_VARIABLE_REQUEST) {
141 //
142 // call to Variable request handler
143 //
144 FspWrapperVariableRequestHandler (&FspHobListPtr, FspMultiPhaseMemInitApiIndex);
145 }
146
147 //
148 // See if MultiPhase process is required or not
149 //
150 FspWrapperMultiPhaseHandler (&FspHobListPtr, FspMultiPhaseMemInitApiIndex); // FspM MultiPhase
151
152 //
153 // Create hobs after memory initialization and not in temp RAM. Hence passing the recorded timestamp here
154 //
155 PERF_START_EX (&gFspApiPerformanceGuid, "EventRec", NULL, TimeStampCounterStart, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
156 PERF_END_EX (&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
157 DEBUG ((DEBUG_INFO, "Total time spent executing FspMemoryInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));
158
159 Status = TestFspMemoryInitApiOutput (FspmUpdDataPtr, &FspHobListPtr);
160 if (EFI_ERROR (Status)) {
161 DEBUG ((DEBUG_ERROR, "ERROR - TestFspMemoryInitApiOutput () fail, Status = %r\n", Status));
162 }
163
164 DEBUG ((DEBUG_INFO, " FspHobListPtr (returned) - 0x%x\n", FspHobListPtr));
165 ASSERT (FspHobListPtr != NULL);
166
167 PostFspmHobProcess (FspHobListPtr);
168
169 //
170 // FspHobList is not complete at this moment.
171 // Save FspHobList pointer to hob, so that it can be got later
172 //
173 HobData = BuildGuidHob (
174 &gFspHobGuid,
175 sizeof (VOID *)
176 );
177 ASSERT (HobData != NULL);
178 CopyMem (HobData, &FspHobListPtr, sizeof (FspHobListPtr));
179
180 return Status;
181}
182
183/**
184 Do FSP initialization.
185
186 @return FSP initialization status.
187**/
188EFI_STATUS
189EFIAPI
190FspmWrapperInit (
191 VOID
192 )
193{
194 EFI_STATUS Status;
195 EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI *MeasurementExcludedFvPpi;
196 EFI_PEI_PPI_DESCRIPTOR *MeasurementExcludedPpiList;
197
198 MeasurementExcludedFvPpi = AllocatePool (sizeof (*MeasurementExcludedFvPpi));
199 ASSERT (MeasurementExcludedFvPpi != NULL);
200 MeasurementExcludedFvPpi->Count = 1;
201 MeasurementExcludedFvPpi->Fv[0].FvBase = PcdGet32 (PcdFspmBaseAddress);
202 MeasurementExcludedFvPpi->Fv[0].FvLength = ((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FvLength;
203
204 MeasurementExcludedPpiList = AllocatePool (sizeof (*MeasurementExcludedPpiList));
205 ASSERT (MeasurementExcludedPpiList != NULL);
206 MeasurementExcludedPpiList->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
207 MeasurementExcludedPpiList->Guid = &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid;
208 MeasurementExcludedPpiList->Ppi = MeasurementExcludedFvPpi;
209
210 Status = EFI_SUCCESS;
211
212 if (PcdGet8 (PcdFspModeSelection) == 1) {
213 Status = PeiFspMemoryInit ();
214 ASSERT_EFI_ERROR (Status);
215 } else {
216 Status = PeiServicesInstallPpi (MeasurementExcludedPpiList);
217 ASSERT_EFI_ERROR (Status);
218
219 PeiServicesInstallFvInfoPpi (
220 &((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FileSystemGuid,
221 (VOID *)(UINTN)PcdGet32 (PcdFspmBaseAddress),
222 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FvLength,
223 NULL,
224 NULL
225 );
226 }
227
228 return Status;
229}
230
231/**
232 This function is called after TCG installed PPI.
233
234 @param[in] PeiServices Pointer to PEI Services Table.
235 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
236 caused this function to execute.
237 @param[in] Ppi Pointer to the PPI data associated with this function.
238
239 @retval EFI_STATUS Always return EFI_SUCCESS
240**/
241EFI_STATUS
242EFIAPI
243TcgPpiNotify (
244 IN EFI_PEI_SERVICES **PeiServices,
245 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
246 IN VOID *Ppi
247 );
248
249EFI_PEI_NOTIFY_DESCRIPTOR mTcgPpiNotifyDesc = {
250 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
251 &gEdkiiTcgPpiGuid,
252 TcgPpiNotify
253};
254
255/**
256 This function is called after TCG installed PPI.
257
258 @param[in] PeiServices Pointer to PEI Services Table.
259 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
260 caused this function to execute.
261 @param[in] Ppi Pointer to the PPI data associated with this function.
262
263 @retval EFI_STATUS Always return EFI_SUCCESS
264**/
265EFI_STATUS
266EFIAPI
267TcgPpiNotify (
268 IN EFI_PEI_SERVICES **PeiServices,
269 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
270 IN VOID *Ppi
271 )
272{
273 UINT32 FspMeasureMask;
274
275 DEBUG ((DEBUG_INFO, "TcgPpiNotify FSPM\n"));
276
277 FspMeasureMask = PcdGet32 (PcdFspMeasurementConfig);
278
279 if ((FspMeasureMask & FSP_MEASURE_FSPT) != 0) {
280 MeasureFspFirmwareBlob (
281 0,
282 "FSPT",
283 PcdGet32 (PcdFsptBaseAddress),
284 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFsptBaseAddress))->FvLength
285 );
286 }
287
288 if ((FspMeasureMask & FSP_MEASURE_FSPM) != 0) {
289 MeasureFspFirmwareBlob (
290 0,
291 "FSPM",
292 PcdGet32 (PcdFspmBaseAddress),
293 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FvLength
294 );
295 }
296
297 return EFI_SUCCESS;
298}
299
300/**
301 This is the entrypoint of PEIM
302
303 @param[in] FileHandle Handle of the file being invoked.
304 @param[in] PeiServices Describes the list of possible PEI Services.
305
306 @retval EFI_SUCCESS if it completed successfully.
307**/
308EFI_STATUS
309EFIAPI
310FspmWrapperPeimEntryPoint (
311 IN EFI_PEI_FILE_HANDLE FileHandle,
312 IN CONST EFI_PEI_SERVICES **PeiServices
313 )
314{
315 EFI_STATUS Status;
316
317 DEBUG ((DEBUG_INFO, "FspmWrapperPeimEntryPoint\n"));
318
319 Status = PeiServicesNotifyPpi (&mTcgPpiNotifyDesc);
320 ASSERT_EFI_ERROR (Status);
321
322 FspmWrapperInit ();
323
324 return EFI_SUCCESS;
325}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette