1 | /** @file
|
---|
2 | This will be invoked only once. It will call FspSmmInit API,
|
---|
3 | to call MmIplPei to load MM Core and dispatch all Standalone
|
---|
4 | MM drivers.
|
---|
5 |
|
---|
6 | Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 |
|
---|
9 | **/
|
---|
10 |
|
---|
11 | #include <PiPei.h>
|
---|
12 | #include <FspEas.h>
|
---|
13 | #include <FspStatusCode.h>
|
---|
14 | #include <FspGlobalData.h>
|
---|
15 | #include <Library/PeimEntryPoint.h>
|
---|
16 | #include <Library/PeiServicesLib.h>
|
---|
17 | #include <Library/PeiServicesTablePointerLib.h>
|
---|
18 | #include <Library/BaseLib.h>
|
---|
19 | #include <Library/DebugLib.h>
|
---|
20 | #include <Library/BaseMemoryLib.h>
|
---|
21 | #include <Library/HobLib.h>
|
---|
22 | #include <Library/MemoryAllocationLib.h>
|
---|
23 | #include <Library/FspWrapperPlatformLib.h>
|
---|
24 | #include <Library/TimerLib.h>
|
---|
25 | #include <Library/PerformanceLib.h>
|
---|
26 | #include <Library/FspWrapperApiLib.h>
|
---|
27 | #include <Library/FspWrapperHobProcessLib.h>
|
---|
28 | #include <Library/FspWrapperApiTestLib.h>
|
---|
29 | #include <Library/FspMeasurementLib.h>
|
---|
30 | #include <Ppi/Tcg.h>
|
---|
31 | #include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>
|
---|
32 |
|
---|
33 | /**
|
---|
34 | Call FspSmmInit API.
|
---|
35 |
|
---|
36 | @return Status returned by FspSmmInit API.
|
---|
37 | **/
|
---|
38 | EFI_STATUS
|
---|
39 | FspiWrapperInitApiMode (
|
---|
40 | VOID
|
---|
41 | )
|
---|
42 | {
|
---|
43 | FSP_INFO_HEADER *FspiHeaderPtr;
|
---|
44 | EFI_STATUS Status;
|
---|
45 | UINT64 TimeStampCounterStart;
|
---|
46 | EFI_HOB_GUID_TYPE *GuidHob;
|
---|
47 | VOID *FspHobListPtr;
|
---|
48 | VOID *FspiUpdDataPtr;
|
---|
49 | UINTN *SourceData;
|
---|
50 |
|
---|
51 | DEBUG ((DEBUG_INFO, "PeiFspSmmInit enter\n"));
|
---|
52 |
|
---|
53 | FspHobListPtr = NULL;
|
---|
54 | FspiUpdDataPtr = NULL;
|
---|
55 |
|
---|
56 | FspiHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspiBaseAddress));
|
---|
57 | DEBUG ((DEBUG_INFO, "FspiHeaderPtr - 0x%x\n", FspiHeaderPtr));
|
---|
58 | if (FspiHeaderPtr == NULL) {
|
---|
59 | return EFI_DEVICE_ERROR;
|
---|
60 | }
|
---|
61 |
|
---|
62 | if ((PcdGet64 (PcdFspiUpdDataAddress) == 0) && (FspiHeaderPtr->CfgRegionSize != 0) && (FspiHeaderPtr->CfgRegionOffset != 0)) {
|
---|
63 | //
|
---|
64 | // Copy default FSP-I UPD data from Flash
|
---|
65 | //
|
---|
66 | FspiUpdDataPtr = AllocateZeroPool ((UINTN)FspiHeaderPtr->CfgRegionSize);
|
---|
67 | ASSERT (FspiUpdDataPtr != NULL);
|
---|
68 | SourceData = (UINTN *)((UINTN)FspiHeaderPtr->ImageBase + (UINTN)FspiHeaderPtr->CfgRegionOffset);
|
---|
69 | CopyMem (FspiUpdDataPtr, SourceData, (UINTN)FspiHeaderPtr->CfgRegionSize);
|
---|
70 | } else {
|
---|
71 | //
|
---|
72 | // External UPD is ready, get the buffer from PCD pointer.
|
---|
73 | //
|
---|
74 | FspiUpdDataPtr = (VOID *)(UINTN)PcdGet64 (PcdFspiUpdDataAddress);
|
---|
75 | ASSERT (FspiUpdDataPtr != NULL);
|
---|
76 | }
|
---|
77 |
|
---|
78 | DEBUG ((DEBUG_INFO, "UpdateFspiUpdData enter\n"));
|
---|
79 | UpdateFspiUpdData (FspiUpdDataPtr);
|
---|
80 | DEBUG ((DEBUG_INFO, " BootloaderSmmFvBaseAddress - 0x%lx\n", ((FSPI_UPD_COMMON *)FspiUpdDataPtr)->FspiArchUpd.BootloaderSmmFvBaseAddress));
|
---|
81 | DEBUG ((DEBUG_INFO, " BootloaderSmmFvLength - 0x%lx\n", ((FSPI_UPD_COMMON *)FspiUpdDataPtr)->FspiArchUpd.BootloaderSmmFvLength));
|
---|
82 | DEBUG ((DEBUG_INFO, " BootloaderSmmFvContextData - 0x%lx\n", ((FSPI_UPD_COMMON *)FspiUpdDataPtr)->FspiArchUpd.BootloaderSmmFvContextData));
|
---|
83 | DEBUG ((DEBUG_INFO, " BootloaderSmmFvContextDataLength - 0x%lx\n", ((FSPI_UPD_COMMON *)FspiUpdDataPtr)->FspiArchUpd.BootloaderSmmFvContextDataLength));
|
---|
84 |
|
---|
85 | //
|
---|
86 | // Get FspHobList
|
---|
87 | //
|
---|
88 | GuidHob = GetFirstGuidHob (&gFspHobGuid);
|
---|
89 | ASSERT (GuidHob != NULL);
|
---|
90 | FspHobListPtr = *(VOID **)GET_GUID_HOB_DATA (GuidHob);
|
---|
91 | DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", &FspHobListPtr));
|
---|
92 |
|
---|
93 | TimeStampCounterStart = AsmReadTsc ();
|
---|
94 | Status = CallFspSmmInit (FspiUpdDataPtr);
|
---|
95 |
|
---|
96 | //
|
---|
97 | // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
|
---|
98 | //
|
---|
99 | if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
|
---|
100 | DEBUG ((DEBUG_INFO, "FspSmmInitApi requested reset %r\n", Status));
|
---|
101 | CallFspWrapperResetSystem (Status);
|
---|
102 | }
|
---|
103 |
|
---|
104 | if (EFI_ERROR (Status)) {
|
---|
105 | DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspSmmInitApi(), Status = %r\n", Status));
|
---|
106 | ASSERT_EFI_ERROR (Status);
|
---|
107 | }
|
---|
108 |
|
---|
109 | DEBUG ((DEBUG_INFO, "FspSmmInit status: %r\n", Status));
|
---|
110 | //
|
---|
111 | // Create hobs after FspSmmInit. Hence passing the recorded timestamp here
|
---|
112 | //
|
---|
113 | PERF_START_EX (&gFspApiPerformanceGuid, "EventRec", NULL, TimeStampCounterStart, FSP_STATUS_CODE_FSPSMM_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
|
---|
114 | PERF_END_EX (&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_FSPSMM_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
|
---|
115 | DEBUG ((DEBUG_INFO, "Total time spent executing FspSmmInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));
|
---|
116 |
|
---|
117 | Status = TestFspSmmInitApiOutput (FspiUpdDataPtr);
|
---|
118 | if (EFI_ERROR (Status)) {
|
---|
119 | DEBUG ((DEBUG_ERROR, "ERROR - TestFspSmmInitApiOutput () fail, Status = %r\n", Status));
|
---|
120 | }
|
---|
121 |
|
---|
122 | DEBUG ((DEBUG_INFO, " FspHobListPtr (returned) - 0x%x\n", FspHobListPtr));
|
---|
123 | ASSERT (FspHobListPtr != NULL);
|
---|
124 |
|
---|
125 | PostFspiHobProcess (FspHobListPtr);
|
---|
126 |
|
---|
127 | return Status;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | Do FSP SMM initialization in Dispatch mode.
|
---|
132 |
|
---|
133 | @retval FSP SMM initialization status.
|
---|
134 | **/
|
---|
135 | EFI_STATUS
|
---|
136 | EFIAPI
|
---|
137 | FspiWrapperInitDispatchMode (
|
---|
138 | VOID
|
---|
139 | )
|
---|
140 | {
|
---|
141 | EFI_STATUS Status;
|
---|
142 | EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI *MeasurementExcludedFvPpi;
|
---|
143 | EFI_PEI_PPI_DESCRIPTOR *MeasurementExcludedPpiList;
|
---|
144 |
|
---|
145 | MeasurementExcludedFvPpi = AllocatePool (sizeof (*MeasurementExcludedFvPpi));
|
---|
146 | if (MeasurementExcludedFvPpi != NULL) {
|
---|
147 | MeasurementExcludedFvPpi->Count = 1;
|
---|
148 | MeasurementExcludedFvPpi->Fv[0].FvBase = PcdGet32 (PcdFspiBaseAddress);
|
---|
149 | MeasurementExcludedFvPpi->Fv[0].FvLength = ((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspiBaseAddress))->FvLength;
|
---|
150 | } else {
|
---|
151 | ASSERT (MeasurementExcludedFvPpi != NULL);
|
---|
152 | }
|
---|
153 |
|
---|
154 | MeasurementExcludedPpiList = AllocatePool (sizeof (*MeasurementExcludedPpiList));
|
---|
155 | if (MeasurementExcludedPpiList != NULL) {
|
---|
156 | MeasurementExcludedPpiList->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
|
---|
157 | MeasurementExcludedPpiList->Guid = &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid;
|
---|
158 | MeasurementExcludedPpiList->Ppi = MeasurementExcludedFvPpi;
|
---|
159 |
|
---|
160 | Status = PeiServicesInstallPpi (MeasurementExcludedPpiList);
|
---|
161 | ASSERT_EFI_ERROR (Status);
|
---|
162 | } else {
|
---|
163 | ASSERT (MeasurementExcludedPpiList != NULL);
|
---|
164 | }
|
---|
165 |
|
---|
166 | //
|
---|
167 | // FSP-I Wrapper running in Dispatch mode and reports FSP-I FV to PEI dispatcher.
|
---|
168 | //
|
---|
169 | PeiServicesInstallFvInfoPpi (
|
---|
170 | &((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspiBaseAddress))->FileSystemGuid,
|
---|
171 | (VOID *)(UINTN)PcdGet32 (PcdFspiBaseAddress),
|
---|
172 | (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspiBaseAddress))->FvLength,
|
---|
173 | NULL,
|
---|
174 | NULL
|
---|
175 | );
|
---|
176 |
|
---|
177 | return EFI_SUCCESS;
|
---|
178 | }
|
---|
179 |
|
---|
180 | /**
|
---|
181 | This function is called after TCG installed PPI.
|
---|
182 |
|
---|
183 | @param[in] PeiServices Pointer to PEI Services Table.
|
---|
184 | @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
|
---|
185 | caused this function to execute.
|
---|
186 | @param[in] Ppi Pointer to the PPI data associated with this function.
|
---|
187 |
|
---|
188 | @retval EFI_STATUS Always return EFI_SUCCESS
|
---|
189 | **/
|
---|
190 | EFI_STATUS
|
---|
191 | EFIAPI
|
---|
192 | TcgPpiNotify (
|
---|
193 | IN EFI_PEI_SERVICES **PeiServices,
|
---|
194 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
|
---|
195 | IN VOID *Ppi
|
---|
196 | );
|
---|
197 |
|
---|
198 | EFI_PEI_NOTIFY_DESCRIPTOR mTcgPpiNotifyDesc = {
|
---|
199 | (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
---|
200 | &gEdkiiTcgPpiGuid,
|
---|
201 | TcgPpiNotify
|
---|
202 | };
|
---|
203 |
|
---|
204 | /**
|
---|
205 | This function is called after TCG installed PPI.
|
---|
206 |
|
---|
207 | @param[in] PeiServices Pointer to PEI Services Table.
|
---|
208 | @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
|
---|
209 | caused this function to execute.
|
---|
210 | @param[in] Ppi Pointer to the PPI data associated with this function.
|
---|
211 |
|
---|
212 | @retval EFI_STATUS Always return EFI_SUCCESS
|
---|
213 | **/
|
---|
214 | EFI_STATUS
|
---|
215 | EFIAPI
|
---|
216 | TcgPpiNotify (
|
---|
217 | IN EFI_PEI_SERVICES **PeiServices,
|
---|
218 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
|
---|
219 | IN VOID *Ppi
|
---|
220 | )
|
---|
221 | {
|
---|
222 | UINT32 FspMeasureMask;
|
---|
223 |
|
---|
224 | DEBUG ((DEBUG_INFO, "TcgPpiNotify FSPI\n"));
|
---|
225 |
|
---|
226 | FspMeasureMask = PcdGet32 (PcdFspMeasurementConfig);
|
---|
227 |
|
---|
228 | if ((FspMeasureMask & FSP_MEASURE_FSPI) != 0) {
|
---|
229 | MeasureFspFirmwareBlob (
|
---|
230 | 0,
|
---|
231 | "FSPI",
|
---|
232 | PcdGet32 (PcdFspiBaseAddress),
|
---|
233 | (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspiBaseAddress))->FvLength
|
---|
234 | );
|
---|
235 | }
|
---|
236 |
|
---|
237 | return EFI_SUCCESS;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /**
|
---|
241 | This is the entrypoint of PEIM.
|
---|
242 |
|
---|
243 | @param[in] FileHandle Handle of the file being invoked.
|
---|
244 | @param[in] PeiServices Describes the list of possible PEI Services.
|
---|
245 |
|
---|
246 | @retval EFI_SUCCESS if it completed successfully.
|
---|
247 | **/
|
---|
248 | EFI_STATUS
|
---|
249 | EFIAPI
|
---|
250 | FspiWrapperPeimEntryPoint (
|
---|
251 | IN EFI_PEI_FILE_HANDLE FileHandle,
|
---|
252 | IN CONST EFI_PEI_SERVICES **PeiServices
|
---|
253 | )
|
---|
254 | {
|
---|
255 | EFI_STATUS Status;
|
---|
256 |
|
---|
257 | DEBUG ((DEBUG_INFO, "FspiWrapperPeimEntryPoint\n"));
|
---|
258 |
|
---|
259 | Status = PeiServicesNotifyPpi (&mTcgPpiNotifyDesc);
|
---|
260 | ASSERT_EFI_ERROR (Status);
|
---|
261 |
|
---|
262 | if (PcdGet8 (PcdFspModeSelection) == 1) {
|
---|
263 | Status = FspiWrapperInitApiMode ();
|
---|
264 | } else {
|
---|
265 | Status = FspiWrapperInitDispatchMode ();
|
---|
266 | }
|
---|
267 |
|
---|
268 | return Status;
|
---|
269 | }
|
---|