2 Entry point to a EFI/DXE driver.
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 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/BaseLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
28 Unload function that is registered in the LoadImage protocol. It un-installs
29 protocols produced and deallocates pool used by the driver. Called by the core
30 when unloading the driver.
32 @param ImageHandle ImageHandle of the loaded driver.
34 @return Status returned by all unload().
39 _DriverUnloadHandler (
40 EFI_HANDLE ImageHandle
46 // If an UnloadImage() handler is specified, then call it
48 Status
= ProcessModuleUnloadList (ImageHandle
);
51 // If the driver specific unload handler does not return an error, then call all of the
52 // library destructors. If the unload handler returned an error, then the driver can not be
53 // unloaded, and the library destructors should not be called
55 if (!EFI_ERROR (Status
)) {
56 ProcessLibraryDestructorList (ImageHandle
, gST
);
60 // Return the status from the driver specific unload handler
67 The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM
68 Driver, or UEFI Driver.
70 This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver,
71 or UEFI Driver. This function must call ProcessLibraryConstructorList() and
72 ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList()
73 is an error status, then ProcessLibraryDestructorList() must be called. The return
74 value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount
75 is greater than zero, then an unload handler must be registered for this image
76 and the unload handler must invoke ProcessModuleUnloadList().
77 If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than
78 _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION.
81 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver,
82 DXE SMM Driver, or UEFI Driver.
83 @param SystemTable A pointer to the EFI System Table.
85 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM
86 Driver, or UEFI Driver exited normally.
87 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
88 SystemTable->Hdr.Revision.
89 @retval Other Return value from ProcessModuleEntryPointList().
95 IN EFI_HANDLE ImageHandle
,
96 IN EFI_SYSTEM_TABLE
*SystemTable
100 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
102 if (_gUefiDriverRevision
!= 0) {
104 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver
106 if (SystemTable
->Hdr
.Revision
< _gUefiDriverRevision
) {
107 return EFI_INCOMPATIBLE_VERSION
;
112 // Call constructor for all libraries
114 ProcessLibraryConstructorList (ImageHandle
, SystemTable
);
117 // Install unload handler...
119 if (_gDriverUnloadImageCount
!= 0) {
120 Status
= gBS
->HandleProtocol (
122 &gEfiLoadedImageProtocolGuid
,
123 (VOID
**)&LoadedImage
125 ASSERT_EFI_ERROR (Status
);
126 LoadedImage
->Unload
= _DriverUnloadHandler
;
130 // Call the driver entry point
132 Status
= ProcessModuleEntryPointList (ImageHandle
, SystemTable
);
135 // If all of the drivers returned errors, then invoke all of the library destructors
137 if (EFI_ERROR (Status
)) {
138 ProcessLibraryDestructorList (ImageHandle
, SystemTable
);
142 // Return the cummalative return status code from all of the driver entry points
149 Required by the EBC compiler and identical in functionality to _ModuleEntryPoint().
151 This function is required to call _ModuleEntryPoint() passing in ImageHandle,
154 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE
155 SMM Driver, or UEFI Driver.
156 @param SystemTable A pointer to the EFI System Table.
158 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM
159 Driver, or UEFI Driver exited normally.
160 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
161 SystemTable->Hdr.Revision.
162 @retval Other Return value from ProcessModuleEntryPointList().
167 IN EFI_HANDLE ImageHandle
,
168 IN EFI_SYSTEM_TABLE
*SystemTable
171 return _ModuleEntryPoint (ImageHandle
, SystemTable
);