]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
Update UefiDriverEntryPoint library by adding BaseLib library class required by AutoG...
[mirror_edk2.git] / MdePkg / Library / UefiDriverEntryPoint / DriverEntryPoint.c
CommitLineData
e386b444 1/** @file\r
2 Entry point to a EFI/DXE driver.\r
3\r
6517edbe 4Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
19388d29 5This program and the accompanying materials\r
e386b444 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15\r
c892d846 16\r
c7d265a9 17#include <Uefi.h>\r
c892d846 18\r
c7d265a9 19#include <Protocol/LoadedImage.h>\r
c892d846 20\r
c7d265a9 21#include <Library/UefiDriverEntryPoint.h>\r
6517edbe 22#include <Library/BaseLib.h>\r
c7d265a9 23#include <Library/DebugLib.h>\r
24#include <Library/UefiBootServicesTableLib.h>\r
e386b444 25\r
26\r
27/**\r
28 Unload function that is registered in the LoadImage protocol. It un-installs\r
29 protocols produced and deallocates pool used by the driver. Called by the core\r
30 when unloading the driver.\r
31\r
373b5cf9 32 @param ImageHandle ImageHandle of the loaded driver.\r
e386b444 33\r
373b5cf9 34 @return Status returned by all unload().\r
e386b444 35\r
36**/\r
e386b444 37EFI_STATUS\r
38EFIAPI\r
39_DriverUnloadHandler (\r
40 EFI_HANDLE ImageHandle\r
41 )\r
42{\r
43 EFI_STATUS Status;\r
44\r
45 //\r
46 // If an UnloadImage() handler is specified, then call it\r
47 //\r
48 Status = ProcessModuleUnloadList (ImageHandle);\r
49\r
50 //\r
51 // If the driver specific unload handler does not return an error, then call all of the\r
52 // library destructors. If the unload handler returned an error, then the driver can not be\r
53 // unloaded, and the library destructors should not be called\r
54 //\r
55 if (!EFI_ERROR (Status)) {\r
e386b444 56 ProcessLibraryDestructorList (ImageHandle, gST);\r
57 }\r
58\r
59 //\r
60 // Return the status from the driver specific unload handler\r
61 //\r
62 return Status;\r
63}\r
64\r
65\r
e386b444 66/**\r
58380e9c 67 The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM \r
68 Driver, or UEFI Driver. \r
66770ccb 69\r
70 This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver,\r
71 or UEFI Driver. This function must call ProcessLibraryConstructorList() and\r
72 ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList()\r
58380e9c 73 is an error status, then ProcessLibraryDestructorList() must be called. The return \r
74 value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount \r
75 is greater than zero, then an unload handler must be registered for this image \r
76 and the unload handler must invoke ProcessModuleUnloadList().\r
77 If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than \r
78 _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION.\r
e386b444 79\r
e386b444 80\r
58380e9c 81 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, \r
82 DXE SMM Driver, or UEFI Driver.\r
f6d2bcc6 83 @param SystemTable A pointer to the EFI System Table.\r
66770ccb 84\r
58380e9c 85 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM \r
86 Driver, or UEFI Driver exited normally.\r
87 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than \r
88 SystemTable->Hdr.Revision.\r
66770ccb 89 @retval Other Return value from ProcessModuleEntryPointList().\r
e386b444 90\r
91**/\r
92EFI_STATUS\r
93EFIAPI\r
94_ModuleEntryPoint (\r
95 IN EFI_HANDLE ImageHandle,\r
96 IN EFI_SYSTEM_TABLE *SystemTable\r
97 )\r
98{\r
99 EFI_STATUS Status;\r
100 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
101\r
102 if (_gUefiDriverRevision != 0) {\r
103 //\r
104 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r
105 //\r
106 if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r
107 return EFI_INCOMPATIBLE_VERSION;\r
108 }\r
109 }\r
110\r
c7d265a9 111 //\r
112 // Call constructor for all libraries\r
113 //\r
114 ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
115\r
e386b444 116 //\r
117 // Install unload handler...\r
118 //\r
119 if (_gDriverUnloadImageCount != 0) {\r
120 Status = gBS->HandleProtocol (\r
121 ImageHandle,\r
122 &gEfiLoadedImageProtocolGuid,\r
123 (VOID **)&LoadedImage\r
124 );\r
125 ASSERT_EFI_ERROR (Status);\r
126 LoadedImage->Unload = _DriverUnloadHandler;\r
127 }\r
128\r
e386b444 129 //\r
130 // Call the driver entry point\r
131 //\r
132 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r
133\r
134 //\r
135 // If all of the drivers returned errors, then invoke all of the library destructors\r
136 //\r
137 if (EFI_ERROR (Status)) {\r
138 ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
139 }\r
140\r
141 //\r
142 // Return the cummalative return status code from all of the driver entry points\r
143 //\r
144 return Status;\r
145}\r
146\r
147\r
148/**\r
66770ccb 149 Required by the EBC compiler and identical in functionality to _ModuleEntryPoint(). \r
150\r
58380e9c 151 This function is required to call _ModuleEntryPoint() passing in ImageHandle,\r
152 and SystemTable.\r
e386b444 153\r
58380e9c 154 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE \r
155 SMM Driver, or UEFI Driver.\r
f6d2bcc6 156 @param SystemTable A pointer to the EFI System Table.\r
e386b444 157\r
58380e9c 158 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM \r
159 Driver, or UEFI Driver exited normally.\r
160 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than \r
161 SystemTable->Hdr.Revision.\r
66770ccb 162 @retval Other Return value from ProcessModuleEntryPointList().\r
e386b444 163**/\r
164EFI_STATUS\r
165EFIAPI\r
166EfiMain (\r
167 IN EFI_HANDLE ImageHandle,\r
168 IN EFI_SYSTEM_TABLE *SystemTable\r
169 )\r
170{\r
171 return _ModuleEntryPoint (ImageHandle, SystemTable);\r
172}\r