MdePkg: introduce standalone MM entry point library implementation
[mirror_edk2.git] / IntelFsp2WrapperPkg / FspWrapperNotifyDxe / FspWrapperNotifyDxe.c
index 30c06b8..a2fe18c 100644 (file)
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/FspWrapperApiLib.h>\r
+#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
@@ -90,9 +94,18 @@ 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
+  //\r
+  if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
+    DEBUG((DEBUG_INFO, "FSP NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status));\r
+    CallFspWrapperResetSystem ((UINT32)Status);\r
+  }\r
+\r
   if (Status != EFI_SUCCESS) {\r
     DEBUG((DEBUG_ERROR, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", Status));\r
   } else {\r
@@ -120,38 +133,27 @@ 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
+  //\r
+  if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
+    DEBUG((DEBUG_INFO, "FSP NotifyPhase ReadyToBoot requested reset 0x%x\n", Status));\r
+    CallFspWrapperResetSystem ((UINT32)Status);\r
+  }\r
+\r
   if (Status != EFI_SUCCESS) {\r
     DEBUG((DEBUG_ERROR, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", Status));\r
   } 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
@@ -170,20 +172,47 @@ 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
+  //\r
+  if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
+    DEBUG((DEBUG_INFO, "FSP NotifyPhase EndOfFirmware requested reset 0x%x\n", Status));\r
+    CallFspWrapperResetSystem ((UINT32)Status);\r
+  }\r
+\r
   if (Status != EFI_SUCCESS) {\r
     DEBUG((DEBUG_ERROR, "FSP NotifyPhase EndOfFirmware failed, status: 0x%x\n", Status));\r
   } 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
@@ -209,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
@@ -218,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