IntelFsp2WrapperPkg: Support FSP Dispatch mode
[mirror_edk2.git] / IntelFsp2WrapperPkg / FspWrapperNotifyDxe / FspWrapperNotifyDxe.c
index 0797f44..a2fe18c 100644 (file)
@@ -25,6 +25,9 @@
 #include <Library/FspWrapperPlatformLib.h>\r
 #include <Library/PerformanceLib.h>\r
 #include <Library/HobLib.h>\r
+#include <FspStatusCode.h>\r
+\r
+#define   FSP_API_NOTIFY_PHASE_AFTER_PCI_ENUMERATION     BIT16\r
 \r
 typedef\r
 EFI_STATUS\r
@@ -91,9 +94,9 @@ OnPciEnumerationComplete (
   }\r
 \r
   NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;\r
-  PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x6000);\r
+  PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);\r
   Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
-  PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x607F);\r
+  PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);\r
 \r
   //\r
   // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
@@ -130,16 +133,13 @@ OnReadyToBoot (
 {\r
   NOTIFY_PHASE_PARAMS               NotifyPhaseParams;\r
   EFI_STATUS                        Status;\r
-  ADD_PERFORMANCE_RECORD_PROTOCOL   *AddPerfRecordInterface;\r
-  EFI_PEI_HOB_POINTERS              Hob;\r
-  VOID                              **FspHobListPtr;\r
 \r
   gBS->CloseEvent (Event);\r
 \r
   NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;\r
-  PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x4000);\r
+  PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);\r
   Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
-  PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x407F);\r
+  PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);\r
 \r
   //\r
   // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
@@ -154,23 +154,6 @@ OnReadyToBoot (
   } else {\r
     DEBUG((DEBUG_INFO, "FSP NotifyPhase ReadyToBoot Success.\n"));\r
   }\r
-\r
-  Status = gBS->LocateProtocol (\r
-                  &gAddPerfRecordProtocolGuid,\r
-                  NULL,\r
-                  (VOID**) &AddPerfRecordInterface\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG((DEBUG_INFO, "gAddPerfRecordProtocolGuid - Locate protocol failed\n"));\r
-    return;\r
-  } else {\r
-    Hob.Raw = GetHobList ();\r
-    if (Hob.Raw != NULL) {\r
-      Hob.Raw = GetNextGuidHob (&gFspHobGuid, Hob.Raw);\r
-      FspHobListPtr = GET_GUID_HOB_DATA(Hob.Raw);\r
-      AddPerfRecordInterface->AddPerformanceRecords((VOID *)(UINTN)(((UINT32)(UINTN)*FspHobListPtr) & 0xFFFFFFFF));\r
-    }\r
-  }\r
 }\r
 \r
 /**\r
@@ -189,15 +172,18 @@ OnEndOfFirmware (
   IN VOID       *Context\r
   )\r
 {\r
-  NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
-  EFI_STATUS          Status;\r
+  NOTIFY_PHASE_PARAMS               NotifyPhaseParams;\r
+  EFI_STATUS                        Status;\r
+  ADD_PERFORMANCE_RECORD_PROTOCOL   *AddPerfRecordInterface;\r
+  EFI_PEI_HOB_POINTERS              Hob;\r
+  VOID                              **FspHobListPtr;\r
 \r
   gBS->CloseEvent (Event);\r
 \r
   NotifyPhaseParams.Phase = EnumInitPhaseEndOfFirmware;\r
-  PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x2000);\r
+  PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);\r
   Status = CallFspNotifyPhase (&NotifyPhaseParams);\r
-  PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0x207F);\r
+  PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);\r
 \r
   //\r
   // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
@@ -212,6 +198,21 @@ OnEndOfFirmware (
   } else {\r
     DEBUG((DEBUG_INFO, "FSP NotifyPhase EndOfFirmware Success.\n"));\r
   }\r
+  Status = gBS->LocateProtocol (\r
+                  &gAddPerfRecordProtocolGuid,\r
+                  NULL,\r
+                  (VOID**) &AddPerfRecordInterface\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG((DEBUG_INFO, "gAddPerfRecordProtocolGuid - Locate protocol failed\n"));\r
+    return;\r
+  } else {\r
+    Hob.Raw = GetFirstGuidHob (&gFspHobGuid);\r
+    if (Hob.Raw != NULL) {\r
+      FspHobListPtr = GET_GUID_HOB_DATA (Hob.Raw);\r
+      AddPerfRecordInterface->AddPerformanceRecords ((VOID *)(UINTN)(((UINT32)(UINTN)*FspHobListPtr) & 0xFFFFFFFF));\r
+    }\r
+  }\r
 }\r
 \r
 /**\r
@@ -237,6 +238,7 @@ FspWrapperNotifyDxeEntryPoint (
   EFI_EVENT  ReadyToBootEvent;\r
   VOID       *Registration;\r
   EFI_EVENT  ProtocolNotifyEvent;\r
+  UINT32     FspApiMask;\r
 \r
   //\r
   // Load this driver's image to memory\r
@@ -246,14 +248,17 @@ FspWrapperNotifyDxeEntryPoint (
     return EFI_SUCCESS;\r
   }\r
 \r
-  ProtocolNotifyEvent = EfiCreateProtocolNotifyEvent (\r
-                          &gEfiPciEnumerationCompleteProtocolGuid,\r
-                          TPL_CALLBACK,\r
-                          OnPciEnumerationComplete,\r
-                          NULL,\r
-                          &Registration\r
-                          );\r
-  ASSERT (ProtocolNotifyEvent != NULL);\r
+  FspApiMask = PcdGet32 (PcdSkipFspApi);\r
+  if ((FspApiMask & FSP_API_NOTIFY_PHASE_AFTER_PCI_ENUMERATION) == 0) {\r
+    ProtocolNotifyEvent = EfiCreateProtocolNotifyEvent (\r
+                            &gEfiPciEnumerationCompleteProtocolGuid,\r
+                            TPL_CALLBACK,\r
+                            OnPciEnumerationComplete,\r
+                            NULL,\r
+                            &Registration\r
+                            );\r
+    ASSERT (ProtocolNotifyEvent != NULL);\r
+  }\r
 \r
   Status = EfiCreateEventReadyToBootEx (\r
              TPL_CALLBACK,\r