]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFspWrapperPkg/FspNotifyDxe/FspNotifyDxe.c
Add IntelFspWrapper to support boot EDKII on FSP bin.
[mirror_edk2.git] / IntelFspWrapperPkg / FspNotifyDxe / FspNotifyDxe.c
diff --git a/IntelFspWrapperPkg/FspNotifyDxe/FspNotifyDxe.c b/IntelFspWrapperPkg/FspNotifyDxe/FspNotifyDxe.c
new file mode 100644 (file)
index 0000000..7beedc4
--- /dev/null
@@ -0,0 +1,149 @@
+/** @file\r
+  This driver will register two callbacks to call fsp's notifies.\r
+\r
+  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Protocol/PciEnumerationComplete.h>\r
+\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/FspApiLib.h>\r
+\r
+FSP_INFO_HEADER *mFspHeader = NULL;\r
+\r
+/**\r
+  PciEnumerationComplete Protocol notification event handler.\r
+\r
+  @param[in] Event    Event whose notification function is being invoked.\r
+  @param[in] Context  Pointer to the notification function's context.\r
+**/\r
+VOID\r
+EFIAPI\r
+OnPciEnumerationComplete (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
+  EFI_STATUS          Status;\r
+  FSP_STATUS          FspStatus;\r
+  VOID                *Interface;\r
+\r
+  //\r
+  // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration.\r
+  // Just return if it is not found.\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiPciEnumerationCompleteProtocolGuid,\r
+                  NULL,\r
+                  &Interface\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return ;\r
+  }\r
+\r
+  NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;\r
+  FspStatus = CallFspNotifyPhase (mFspHeader, &NotifyPhaseParams);\r
+  if (FspStatus != FSP_SUCCESS) {\r
+    DEBUG((DEBUG_ERROR, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", FspStatus));\r
+  } else {\r
+    DEBUG((DEBUG_INFO, "FSP NotifyPhase AfterPciEnumeration Success.\n"));\r
+  }\r
+}\r
+\r
+/**\r
+  Notification function of EVT_GROUP_READY_TO_BOOT event group.\r
+\r
+  This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.\r
+  When the Boot Manager is about to load and execute a boot option, it reclaims variable\r
+  storage if free size is below the threshold.\r
+\r
+  @param[in] Event        Event whose notification function is being invoked.\r
+  @param[in] Context      Pointer to the notification function's context.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+OnReadyToBoot (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
+  FSP_STATUS          FspStatus;\r
+\r
+  gBS->CloseEvent (Event);\r
+\r
+  NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;\r
+  FspStatus = CallFspNotifyPhase (mFspHeader, &NotifyPhaseParams);\r
+  if (FspStatus != FSP_SUCCESS) {\r
+    DEBUG((DEBUG_ERROR, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", FspStatus));\r
+  } else {\r
+    DEBUG((DEBUG_INFO, "FSP NotifyPhase ReadyToBoot Success.\n"));\r
+  }\r
+}\r
+\r
+/**\r
+  Main entry for the FSP DXE module.\r
+\r
+  This routine registers two callbacks to call fsp's notifies.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FspDxeEntryPoint (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  EFI_EVENT  ReadyToBootEvent;\r
+  VOID       *Registration;\r
+  EFI_EVENT  ProtocolNotifyEvent;\r
+\r
+  mFspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));\r
+  DEBUG ((DEBUG_INFO, "FspHeader - 0x%x\n", mFspHeader));\r
+  if (mFspHeader == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  ProtocolNotifyEvent = EfiCreateProtocolNotifyEvent (\r
+                          &gEfiPciEnumerationCompleteProtocolGuid,\r
+                          TPL_CALLBACK,\r
+                          OnPciEnumerationComplete,\r
+                          NULL,\r
+                          &Registration\r
+                          );\r
+  ASSERT (ProtocolNotifyEvent != NULL);\r
+\r
+  Status = EfiCreateEventReadyToBootEx (\r
+             TPL_CALLBACK,\r
+             OnReadyToBoot,\r
+             NULL,\r
+             &ReadyToBootEvent\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r