]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OldMdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
Moved the MdePkg to OldMdePkg so that new code in MdePkg does not break existing...
[mirror_edk2.git] / OldMdePkg / Library / UefiDriverEntryPoint / DriverEntryPoint.c
diff --git a/OldMdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c b/OldMdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
new file mode 100644 (file)
index 0000000..9ec19e3
--- /dev/null
@@ -0,0 +1,198 @@
+/** @file\r
+  Entry point to a EFI/DXE driver.\r
+\r
+Copyright (c) 2006, Intel Corporation<BR>\r
+All rights reserved. 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
+\r
+EFI_EVENT  _mDriverExitBootServicesNotifyEvent;\r
+\r
+/**\r
+  Unload function that is registered in the LoadImage protocol.  It un-installs\r
+  protocols produced and deallocates pool used by the driver.  Called by the core\r
+  when unloading the driver.\r
+\r
+  @param  ImageHandle\r
+\r
+  @retval EFI_SUCCESS\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+_DriverUnloadHandler (\r
+  EFI_HANDLE ImageHandle\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // If an UnloadImage() handler is specified, then call it\r
+  //\r
+  Status = ProcessModuleUnloadList (ImageHandle);\r
+\r
+  //\r
+  // If the driver specific unload handler does not return an error, then call all of the\r
+  // library destructors.  If the unload handler returned an error, then the driver can not be\r
+  // unloaded, and the library destructors should not be called\r
+  //\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Close our ExitBootServices () notify function\r
+    //\r
+    if (_gDriverExitBootServicesEvent[0] != NULL) {\r
+      Status = gBS->CloseEvent (_mDriverExitBootServicesNotifyEvent);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+\r
+    ProcessLibraryDestructorList (ImageHandle, gST);\r
+  }\r
+\r
+  //\r
+  // Return the status from the driver specific unload handler\r
+  //\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Notification Entry of ExitBootService event. In the entry, all notifications in _gDriverExitBootServicesEvent[] \r
+  would be invoked.\r
+\r
+  @param Event   The Event that is being processed.\r
+  @param Context Event Context.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+_DriverExitBootServices (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+{\r
+  EFI_EVENT_NOTIFY  ChildNotifyEventHandler;\r
+  UINTN             Index;\r
+\r
+  for (Index = 0; _gDriverExitBootServicesEvent[Index] != NULL; Index++) {\r
+    ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];\r
+    ChildNotifyEventHandler (Event, NULL);\r
+  }\r
+}\r
+\r
+/**\r
+  Enrty point to DXE Driver.\r
+\r
+  @param  ImageHandle ImageHandle of the loaded driver.\r
+  @param  SystemTable Pointer to the EFI System Table.\r
+\r
+  @retval  EFI_SUCCESS One or more of the drivers returned a success code.\r
+  @retval  !EFI_SUCESS The return status from the last driver entry point in the list.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+_ModuleEntryPoint (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+  EFI_LOADED_IMAGE_PROTOCOL  *LoadedImage;\r
+\r
+  if (_gUefiDriverRevision != 0) {\r
+    //\r
+    // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r
+    //\r
+    if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r
+      return EFI_INCOMPATIBLE_VERSION;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Call constructor for all libraries\r
+  //\r
+  ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
+\r
+  //\r
+  // Register our ExitBootServices () notify function\r
+  //\r
+  if (_gDriverExitBootServicesEvent[0] != NULL) {\r
+    Status = gBS->CreateEvent (\r
+                    EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
+                    EFI_TPL_NOTIFY,\r
+                    _DriverExitBootServices,\r
+                    NULL,\r
+                    &_mDriverExitBootServicesNotifyEvent\r
+                    );\r
+\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  //\r
+  //  Install unload handler...\r
+  //\r
+  if (_gDriverUnloadImageCount != 0) {\r
+    Status = gBS->HandleProtocol (\r
+                    ImageHandle,\r
+                    &gEfiLoadedImageProtocolGuid,\r
+                    (VOID **)&LoadedImage\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+    LoadedImage->Unload = _DriverUnloadHandler;\r
+  }\r
+\r
+  //\r
+  // Call the driver entry point\r
+  //\r
+  Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r
+\r
+  //\r
+  // If all of the drivers returned errors, then invoke all of the library destructors\r
+  //\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Close our ExitBootServices () notify function\r
+    //\r
+    if (_gDriverExitBootServicesEvent[0] != NULL) {\r
+      Status = gBS->CloseEvent (_mDriverExitBootServicesNotifyEvent);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+\r
+    ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
+  }\r
+\r
+  //\r
+  // Return the cummalative return status code from all of the driver entry points\r
+  //\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Enrty point wrapper of DXE Driver.\r
+\r
+  @param  ImageHandle ImageHandle of the loaded driver.\r
+  @param  SystemTable Pointer to the EFI System Table.\r
+\r
+  @retval  EFI_SUCCESS One or more of the drivers returned a success code.\r
+  @retval  !EFI_SUCESS The return status from the last driver entry point in the list.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiMain (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  return _ModuleEntryPoint (ImageHandle, SystemTable);\r
+}\r