2 Entry point to a EFI/DXE driver.
4 Copyright (c) 2006 - 2008, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Protocol/LoadedImage.h>
21 #include <Library/UefiDriverEntryPoint.h>
22 #include <Library/DebugLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
27 Unload function that is registered in the LoadImage protocol. It un-installs
28 protocols produced and deallocates pool used by the driver. Called by the core
29 when unloading the driver.
31 @param ImageHandle ImageHandle of the loaded driver.
33 @return Status returned by all unload().
38 _DriverUnloadHandler (
39 EFI_HANDLE ImageHandle
45 // If an UnloadImage() handler is specified, then call it
47 Status
= ProcessModuleUnloadList (ImageHandle
);
50 // If the driver specific unload handler does not return an error, then call all of the
51 // library destructors. If the unload handler returned an error, then the driver can not be
52 // unloaded, and the library destructors should not be called
54 if (!EFI_ERROR (Status
)) {
55 ProcessLibraryDestructorList (ImageHandle
, gST
);
59 // Return the status from the driver specific unload handler
66 The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM Driver, or UEFI Driver.
68 This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver,
69 or UEFI Driver. This function must call ProcessLibraryConstructorList() and
70 ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList()
71 is an error status, then ProcessLibraryDestructorList() must be called. The return value
72 from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount is greater
73 than zero, then an unload handler must be registered for this image and the unload handler
74 must invoke ProcessModuleUnloadList().
75 If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than _gUefiDriverRevison,
76 then return EFI_INCOMPATIBLE_VERSION.
79 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE SMM Driver, or UEFI Driver.
80 @param SystemTable A pointer to the EFI System Table.
82 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM Driver,
83 or UEFI Driver exited normally.
84 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than SystemTable->Hdr.Revision.
85 @retval Other Return value from ProcessModuleEntryPointList().
91 IN EFI_HANDLE ImageHandle
,
92 IN EFI_SYSTEM_TABLE
*SystemTable
96 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
98 if (_gUefiDriverRevision
!= 0) {
100 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver
102 if (SystemTable
->Hdr
.Revision
< _gUefiDriverRevision
) {
103 return EFI_INCOMPATIBLE_VERSION
;
108 // Call constructor for all libraries
110 ProcessLibraryConstructorList (ImageHandle
, SystemTable
);
113 // Install unload handler...
115 if (_gDriverUnloadImageCount
!= 0) {
116 Status
= gBS
->HandleProtocol (
118 &gEfiLoadedImageProtocolGuid
,
119 (VOID
**)&LoadedImage
121 ASSERT_EFI_ERROR (Status
);
122 LoadedImage
->Unload
= _DriverUnloadHandler
;
126 // Call the driver entry point
128 Status
= ProcessModuleEntryPointList (ImageHandle
, SystemTable
);
131 // If all of the drivers returned errors, then invoke all of the library destructors
133 if (EFI_ERROR (Status
)) {
134 ProcessLibraryDestructorList (ImageHandle
, SystemTable
);
138 // Return the cummalative return status code from all of the driver entry points
145 Required by the EBC compiler and identical in functionality to _ModuleEntryPoint().
147 This function is required to call _ModuleEntryPoint() passing in ImageHandle, and SystemTable.
149 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE SMM Driver, or UEFI Driver.
150 @param SystemTable A pointer to the EFI System Table.
152 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM Driver,
153 or UEFI Driver exited normally.
154 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than SystemTable->Hdr.Revision.
155 @retval Other Return value from ProcessModuleEntryPointList().
160 IN EFI_HANDLE ImageHandle
,
161 IN EFI_SYSTEM_TABLE
*SystemTable
164 return _ModuleEntryPoint (ImageHandle
, SystemTable
);