2 Entry point to a EFI/DXE driver.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Protocol/LoadedImage.h>
15 #include <Library/UefiDriverEntryPoint.h>
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
22 Unloads an image from memory.
24 This function is a callback that a driver registers to do cleanup
25 when the UnloadImage boot service function is called.
27 @param ImageHandle The handle to the image to unload.
29 @return Status returned by all unload().
34 _DriverUnloadHandler (
35 EFI_HANDLE ImageHandle
41 // If an UnloadImage() handler is specified, then call it
43 Status
= ProcessModuleUnloadList (ImageHandle
);
46 // If the driver specific unload handler does not return an error, then call all of the
47 // library destructors. If the unload handler returned an error, then the driver can not be
48 // unloaded, and the library destructors should not be called
50 if (!EFI_ERROR (Status
)) {
51 ProcessLibraryDestructorList (ImageHandle
, gST
);
55 // Return the status from the driver specific unload handler
62 The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM
63 Driver, or UEFI Driver.
65 This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver,
66 or UEFI Driver. This function must call ProcessLibraryConstructorList() and
67 ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList()
68 is an error status, then ProcessLibraryDestructorList() must be called. The return
69 value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount
70 is greater than zero, then an unload handler must be registered for this image
71 and the unload handler must invoke ProcessModuleUnloadList().
72 If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than
73 _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION.
76 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver,
77 DXE SMM Driver, or UEFI Driver.
78 @param SystemTable A pointer to the EFI System Table.
80 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM
81 Driver, or UEFI Driver exited normally.
82 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
83 SystemTable->Hdr.Revision.
84 @retval Other Return value from ProcessModuleEntryPointList().
90 IN EFI_HANDLE ImageHandle
,
91 IN EFI_SYSTEM_TABLE
*SystemTable
95 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
97 if (_gUefiDriverRevision
!= 0) {
99 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver
101 if (SystemTable
->Hdr
.Revision
< _gUefiDriverRevision
) {
102 return EFI_INCOMPATIBLE_VERSION
;
107 // Call constructor for all libraries
109 ProcessLibraryConstructorList (ImageHandle
, SystemTable
);
112 // Install unload handler...
114 if (_gDriverUnloadImageCount
!= 0) {
115 Status
= gBS
->HandleProtocol (
117 &gEfiLoadedImageProtocolGuid
,
118 (VOID
**)&LoadedImage
120 ASSERT_EFI_ERROR (Status
);
121 LoadedImage
->Unload
= _DriverUnloadHandler
;
125 // Call the driver entry point
127 Status
= ProcessModuleEntryPointList (ImageHandle
, SystemTable
);
130 // If all of the drivers returned errors, then invoke all of the library destructors
132 if (EFI_ERROR (Status
)) {
133 ProcessLibraryDestructorList (ImageHandle
, SystemTable
);
137 // Return the cummalative return status code from all of the driver entry points
144 Required by the EBC compiler and identical in functionality to _ModuleEntryPoint().
146 This function is required to call _ModuleEntryPoint() passing in ImageHandle,
149 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE
150 SMM Driver, or UEFI Driver.
151 @param SystemTable A pointer to the EFI System Table.
153 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM
154 Driver, or UEFI Driver exited normally.
155 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
156 SystemTable->Hdr.Revision.
157 @retval Other Return value from ProcessModuleEntryPointList().
162 IN EFI_HANDLE ImageHandle
,
163 IN EFI_SYSTEM_TABLE
*SystemTable
166 return _ModuleEntryPoint (ImageHandle
, SystemTable
);