TianoCore EDK2 master
Loading...
Searching...
No Matches
FspPlatformNotify.c
Go to the documentation of this file.
1
8#include <PiPei.h>
11#include <Library/BaseLib.h>
13#include <Library/PcdLib.h>
14#include <Library/DebugLib.h>
15#include <Library/HobLib.h>
18#include <Guid/EventGroup.h>
19#include <FspEas.h>
20#include <FspStatusCode.h>
24extern EFI_GUID gFspPerformanceDataGuid;
25
26EFI_PEI_PPI_DESCRIPTOR mPeiPostPciEnumerationPpi = {
27 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
28 &gEfiPciEnumerationCompleteProtocolGuid,
29 NULL
30};
31
32EFI_PEI_PPI_DESCRIPTOR mPeiReadyToBootPpi = {
33 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
34 &gEfiEventReadyToBootGuid,
35 NULL
36};
37
38EFI_PEI_PPI_DESCRIPTOR mPeiEndOfFirmwarePpi = {
39 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
40 &gFspEventEndOfFirmwareGuid,
41 NULL
42};
43
44UINT32 mFspNotifySequence[] = {
48};
49
60EFIAPI
62 IN UINT32 NotificationCode
63 )
64{
65 EFI_STATUS Status;
66
67 Status = EFI_SUCCESS;
68
69 switch (NotificationCode) {
71 //
72 // Do POST PCI initialization if needed
73 //
74 DEBUG ((DEBUG_INFO | DEBUG_INIT, "FSP Post PCI Enumeration ...\n"));
75 PeiServicesInstallPpi (&mPeiPostPciEnumerationPpi);
76 break;
77
79 //
80 // Ready To Boot
81 //
82 DEBUG ((DEBUG_INFO| DEBUG_INIT, "FSP Ready To Boot ...\n"));
83 PeiServicesInstallPpi (&mPeiReadyToBootPpi);
84 break;
85
87 //
88 // End of Firmware
89 //
90 DEBUG ((DEBUG_INFO| DEBUG_INIT, "FSP End of Firmware ...\n"));
91 PeiServicesInstallPpi (&mPeiEndOfFirmwarePpi);
92 break;
93
94 default:
95 Status = EFI_INVALID_PARAMETER;
96 break;
97 }
98
99 return Status;
100}
101
108VOID
109EFIAPI
111 IN EFI_STATUS Status
112 )
113{
114 volatile EFI_STATUS FspStatus;
115
116 FspStatus = Status;
117 //
118 // Convert to FSP EAS defined API return codes
119 //
120 switch (Status) {
121 case EFI_SUCCESS:
122 case EFI_INVALID_PARAMETER:
123 case EFI_UNSUPPORTED:
124 case EFI_DEVICE_ERROR:
125 break;
126 default:
127 DEBUG ((DEBUG_INFO | DEBUG_INIT, "FspSiliconInitApi() Invalid Error - [Status: 0x%08X]\n", Status));
128 Status = EFI_DEVICE_ERROR; // Force to known error.
129 break;
130 }
131
132 //
133 // This is the end of the FspSiliconInit API
134 // Give control back to the boot loader
135 //
136 SetFspMeasurePoint (FSP_PERF_ID_API_FSP_SILICON_INIT_EXIT);
137 DEBUG ((DEBUG_INFO | DEBUG_INIT, "FspSiliconInitApi() - [Status: 0x%08X] - End\n", Status));
138 PERF_END_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
139 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
140 if (GetFspGlobalDataPointer ()->FspMode == FSP_IN_API_MODE) {
141 do {
142 SetFspApiReturnStatus (Status);
144 if (Status != EFI_SUCCESS) {
145 DEBUG ((DEBUG_ERROR, "!!!ERROR: FspSiliconInitApi() - [Status: 0x%08X] - Error encountered during previous API and cannot proceed further\n", Status));
146 }
147 } while (FspStatus != EFI_SUCCESS);
148 }
149}
150
157VOID
158EFIAPI
160 IN EFI_STATUS Status,
161 IN OUT VOID **HobListPtr
162 )
163{
164 FSP_GLOBAL_DATA *FspData;
165 volatile EFI_STATUS FspStatus;
166
167 FspStatus = Status;
168 //
169 // Calling use FspMemoryInit API
170 // Update HOB and return the control directly
171 //
172 if (HobListPtr == NULL) {
173 HobListPtr = (VOID **)GetFspApiParameter2 ();
174 }
175
176 if (HobListPtr != NULL) {
177 *HobListPtr = (VOID *)GetHobList ();
178 }
179
180 //
181 // Convert to FSP EAS defined API return codes
182 //
183 switch (Status) {
184 case EFI_SUCCESS:
185 case EFI_INVALID_PARAMETER:
186 case EFI_UNSUPPORTED:
187 case EFI_DEVICE_ERROR:
188 case EFI_OUT_OF_RESOURCES:
189 break;
190 default:
191 DEBUG ((DEBUG_INFO | DEBUG_INIT, "FspMemoryInitApi() Invalid Error [Status: 0x%08X]\n", Status));
192 Status = EFI_DEVICE_ERROR; // Force to known error.
193 break;
194 }
195
196 //
197 // This is the end of the FspMemoryInit API
198 // Give control back to the boot loader
199 //
200 DEBUG ((DEBUG_INFO | DEBUG_INIT, "FspMemoryInitApi() - [Status: 0x%08X] - End\n", Status));
201 SetFspMeasurePoint (FSP_PERF_ID_API_FSP_MEMORY_INIT_EXIT);
202 FspData = GetFspGlobalDataPointer ();
203 PERF_START_EX (&gFspPerformanceDataGuid, "EventRec", NULL, (FspData->PerfData[0] & FSP_PERFORMANCE_DATA_TIMER_MASK), FSP_STATUS_CODE_TEMP_RAM_INIT | FSP_STATUS_CODE_COMMON_CODE| FSP_STATUS_CODE_API_ENTRY);
204 PERF_END_EX (&gFspPerformanceDataGuid, "EventRec", NULL, (FspData->PerfData[1] & FSP_PERFORMANCE_DATA_TIMER_MASK), FSP_STATUS_CODE_TEMP_RAM_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
205 PERF_START_EX (&gFspPerformanceDataGuid, "EventRec", NULL, (FspData->PerfData[2] & FSP_PERFORMANCE_DATA_TIMER_MASK), FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
206 PERF_END_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
207 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
208 if (GetFspGlobalDataPointer ()->FspMode == FSP_IN_API_MODE) {
209 do {
210 SetFspApiReturnStatus (Status);
212 if (Status != EFI_SUCCESS) {
213 DEBUG ((DEBUG_ERROR, "!!!ERROR: FspMemoryInitApi() - [Status: 0x%08X] - Error encountered during previous API and cannot proceed further\n", Status));
214 }
215 } while (FspStatus != EFI_SUCCESS);
216 }
217
218 //
219 // The TempRamExitApi is called
220 //
221 if (GetFspApiCallingIndex () == TempRamExitApiIndex) {
222 SetPhaseStatusCode (FSP_STATUS_CODE_TEMP_RAM_EXIT);
223 SetFspMeasurePoint (FSP_PERF_ID_API_TEMP_RAM_EXIT_ENTRY);
224 PERF_START_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_TEMP_RAM_EXIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
225 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_TEMP_RAM_EXIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
226 DEBUG ((DEBUG_INFO | DEBUG_INIT, "TempRamExitApi() - Begin\n"));
227 } else {
228 SetPhaseStatusCode (FSP_STATUS_CODE_SILICON_INIT);
229 SetFspMeasurePoint (FSP_PERF_ID_API_FSP_SILICON_INIT_ENTRY);
230 PERF_START_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
231 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
232 DEBUG ((DEBUG_INFO | DEBUG_INIT, "FspSiliconInitApi() - Begin\n"));
233 }
234}
235
242VOID
243EFIAPI
245 IN EFI_STATUS Status
246 )
247{
248 //
249 volatile EFI_STATUS FspStatus;
250
251 FspStatus = Status;
252 // Convert to FSP EAS defined API return codes
253 //
254 switch (Status) {
255 case EFI_SUCCESS:
256 case EFI_INVALID_PARAMETER:
257 case EFI_UNSUPPORTED:
258 case EFI_DEVICE_ERROR:
259 break;
260 default:
261 DEBUG ((DEBUG_INFO | DEBUG_INIT, "TempRamExitApi() Invalid Error - [Status: 0x%08X]\n", Status));
262 Status = EFI_DEVICE_ERROR; // Force to known error.
263 break;
264 }
265
266 //
267 // This is the end of the TempRamExit API
268 // Give control back to the boot loader
269 //
270 DEBUG ((DEBUG_INFO | DEBUG_INIT, "TempRamExitApi() - [Status: 0x%08X] - End\n", Status));
271 SetFspMeasurePoint (FSP_PERF_ID_API_TEMP_RAM_EXIT_EXIT);
272 PERF_END_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_TEMP_RAM_EXIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
273 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_TEMP_RAM_EXIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
274 if (GetFspGlobalDataPointer ()->FspMode == FSP_IN_API_MODE) {
275 do {
276 SetFspApiReturnStatus (Status);
278 if (Status != EFI_SUCCESS) {
279 DEBUG ((DEBUG_ERROR, "!!!ERROR: TempRamExitApi() - [Status: 0x%08X] - Error encountered during previous API and cannot proceed further\n", Status));
280 }
281 } while (FspStatus != EFI_SUCCESS);
282 }
283
284 SetPhaseStatusCode (FSP_STATUS_CODE_SILICON_INIT);
285 SetFspMeasurePoint (FSP_PERF_ID_API_FSP_SILICON_INIT_ENTRY);
286 PERF_START_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
287 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_SILICON_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
288 DEBUG ((DEBUG_INFO | DEBUG_INIT, "SiliconInitApi() - Begin\n"));
289}
290
298VOID
299EFIAPI
301 VOID
302 )
303{
304 EFI_STATUS Status;
305 UINT32 NotificationValue;
306 UINT32 NotificationCount;
307 UINT8 Count;
308 volatile EFI_STATUS FspStatus;
309
310 NotificationCount = 0;
311 while (NotificationCount < sizeof (mFspNotifySequence) / sizeof (UINT32)) {
312 Count = (UINT8)((NotificationCount << 1) & 0x07);
313 SetFspMeasurePoint (FSP_PERF_ID_API_NOTIFY_POST_PCI_ENTRY + Count);
314
315 if (NotificationCount == 0) {
316 SetPhaseStatusCode (FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION);
317 PERF_START_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
318 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
319 } else if (NotificationCount == 1) {
320 SetPhaseStatusCode (FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION);
321 PERF_START_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
322 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
323 } else if (NotificationCount == 2) {
324 SetPhaseStatusCode (FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION);
325 PERF_START_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
326 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
327 }
328
329 NotificationValue = ((NOTIFY_PHASE_PARAMS *)(UINTN)GetFspApiParameter ())->Phase;
330 DEBUG ((DEBUG_INFO | DEBUG_INIT, "NotifyPhaseApi() - Begin [Phase: %08X]\n", NotificationValue));
331 if (mFspNotifySequence[NotificationCount] != NotificationValue) {
332 //
333 // Notify code does not follow the predefined order
334 //
335 DEBUG ((DEBUG_INFO, "Unsupported FSP Notification Value\n"));
336 Status = EFI_UNSUPPORTED;
337 } else {
338 //
339 // Process Notification and Give control back to the boot loader framework caller
340 //
341 Status = FspNotificationHandler (NotificationValue);
342 if (!EFI_ERROR (Status)) {
343 NotificationCount++;
344 }
345 }
346
347 DEBUG ((DEBUG_INFO | DEBUG_INIT, "NotifyPhaseApi() - End [Status: 0x%08X]\n", Status));
348 SetFspMeasurePoint (FSP_PERF_ID_API_NOTIFY_POST_PCI_EXIT + Count);
349
350 if ((NotificationCount - 1) == 0) {
351 PERF_END_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
352 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
353 } else if ((NotificationCount - 1) == 1) {
354 PERF_END_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
355 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
356 } else if ((NotificationCount - 1) == 2) {
357 PERF_END_EX (&gFspPerformanceDataGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
358 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
359 }
360
361 if (GetFspGlobalDataPointer ()->FspMode == FSP_IN_API_MODE) {
362 FspStatus = Status;
363 do {
364 SetFspApiReturnStatus (Status);
366 if (Status != EFI_SUCCESS) {
367 DEBUG ((DEBUG_ERROR, "!!!ERROR: NotifyPhaseApi() [Phase: %08X] - Failed - [Status: 0x%08X]\n", NotificationValue, Status));
368 }
369 } while (FspStatus != EFI_SUCCESS);
370 }
371 }
372
373 //
374 // Control goes back to the PEI Core and it dispatches further PEIMs.
375 // DXEIPL is the final one to transfer control back to the boot loader.
376 //
377}
378
383VOID
384EFIAPI
386 VOID
387 )
388{
390}
391
397VOID
398EFIAPI
400 IN OUT VOID **HobListPtr
401 )
402{
403 FspMemoryInitDone2 (EFI_SUCCESS, HobListPtr);
404}
405
410VOID
411EFIAPI
413 VOID
414 )
415{
417}
UINT64 UINTN
VOID *EFIAPI GetHobList(VOID)
Definition: HobLib.c:76
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
@ EnumInitPhaseAfterPciEnumeration
Definition: FspApi.h:470
@ EnumInitPhaseReadyToBoot
Definition: FspApi.h:475
@ EnumInitPhaseEndOfFirmware
Definition: FspApi.h:481
VOID EFIAPI SetFspApiReturnStatus(IN UINTN ReturnStatus)
Definition: FspCommonLib.c:160
FSP_GLOBAL_DATA *EFIAPI GetFspGlobalDataPointer(VOID)
Definition: FspCommonLib.c:73
UINT8 EFIAPI GetFspApiCallingIndex(VOID)
Definition: FspCommonLib.c:500
UINTN EFIAPI GetFspApiParameter2(VOID)
Definition: FspCommonLib.c:124
UINTN EFIAPI GetFspApiParameter(VOID)
Definition: FspCommonLib.c:90
UINT64 EFIAPI SetFspMeasurePoint(IN UINT8 Id)
Definition: FspCommonLib.c:411
VOID EFIAPI SetPhaseStatusCode(UINT32 StatusCode)
Definition: FspCommonLib.c:545
VOID EFIAPI FspMemoryInitDone2(IN EFI_STATUS Status, IN OUT VOID **HobListPtr)
VOID EFIAPI FspSiliconInitDone(VOID)
VOID EFIAPI FspMemoryInitDone(IN OUT VOID **HobListPtr)
VOID EFIAPI FspWaitForNotify(VOID)
VOID EFIAPI FspTempRamExitDone(VOID)
VOID EFIAPI FspTempRamExitDone2(IN EFI_STATUS Status)
VOID EFIAPI FspSiliconInitDone2(IN EFI_STATUS Status)
EFI_STATUS EFIAPI FspNotificationHandler(IN UINT32 NotificationCode)
EFI_STATUS EFIAPI Pei2LoaderSwitchStack(VOID)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define REPORT_STATUS_CODE(Type, Value)
#define PERF_START_EX(Handle, Token, Module, TimeStamp, Identifier)
#define PERF_END_EX(Handle, Token, Module, TimeStamp, Identifier)
#define EFI_PROGRESS_CODE
Definition: PiStatusCode.h:43
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213