]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
MdePkg/SmiHandlerProfile: Add Context support in Unregister
[mirror_edk2.git] / MdePkg / Library / UefiDriverEntryPoint / DriverEntryPoint.c
... / ...
CommitLineData
1/** @file\r
2 Entry point to a EFI/DXE driver.\r
3\r
4Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
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
16\r
17#include <Uefi.h>\r
18\r
19#include <Protocol/LoadedImage.h>\r
20\r
21#include <Library/UefiDriverEntryPoint.h>\r
22#include <Library/BaseLib.h>\r
23#include <Library/DebugLib.h>\r
24#include <Library/UefiBootServicesTableLib.h>\r
25\r
26\r
27/**\r
28 Unloads an image from memory.\r
29\r
30 This function is a callback that a driver registers to do cleanup \r
31 when the UnloadImage boot service function is called.\r
32\r
33 @param ImageHandle The handle to the image to unload.\r
34\r
35 @return Status returned by all unload().\r
36\r
37**/\r
38EFI_STATUS\r
39EFIAPI\r
40_DriverUnloadHandler (\r
41 EFI_HANDLE ImageHandle\r
42 )\r
43{\r
44 EFI_STATUS Status;\r
45\r
46 //\r
47 // If an UnloadImage() handler is specified, then call it\r
48 //\r
49 Status = ProcessModuleUnloadList (ImageHandle);\r
50\r
51 //\r
52 // If the driver specific unload handler does not return an error, then call all of the\r
53 // library destructors. If the unload handler returned an error, then the driver can not be\r
54 // unloaded, and the library destructors should not be called\r
55 //\r
56 if (!EFI_ERROR (Status)) {\r
57 ProcessLibraryDestructorList (ImageHandle, gST);\r
58 }\r
59\r
60 //\r
61 // Return the status from the driver specific unload handler\r
62 //\r
63 return Status;\r
64}\r
65\r
66\r
67/**\r
68 The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM \r
69 Driver, or UEFI Driver. \r
70\r
71 This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver,\r
72 or UEFI Driver. This function must call ProcessLibraryConstructorList() and\r
73 ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList()\r
74 is an error status, then ProcessLibraryDestructorList() must be called. The return \r
75 value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount \r
76 is greater than zero, then an unload handler must be registered for this image \r
77 and the unload handler must invoke ProcessModuleUnloadList().\r
78 If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than \r
79 _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION.\r
80\r
81\r
82 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, \r
83 DXE SMM Driver, or UEFI Driver.\r
84 @param SystemTable A pointer to the EFI System Table.\r
85\r
86 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM \r
87 Driver, or UEFI Driver exited normally.\r
88 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than \r
89 SystemTable->Hdr.Revision.\r
90 @retval Other Return value from ProcessModuleEntryPointList().\r
91\r
92**/\r
93EFI_STATUS\r
94EFIAPI\r
95_ModuleEntryPoint (\r
96 IN EFI_HANDLE ImageHandle,\r
97 IN EFI_SYSTEM_TABLE *SystemTable\r
98 )\r
99{\r
100 EFI_STATUS Status;\r
101 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
102\r
103 if (_gUefiDriverRevision != 0) {\r
104 //\r
105 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r
106 //\r
107 if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r
108 return EFI_INCOMPATIBLE_VERSION;\r
109 }\r
110 }\r
111\r
112 //\r
113 // Call constructor for all libraries\r
114 //\r
115 ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
116\r
117 //\r
118 // Install unload handler...\r
119 //\r
120 if (_gDriverUnloadImageCount != 0) {\r
121 Status = gBS->HandleProtocol (\r
122 ImageHandle,\r
123 &gEfiLoadedImageProtocolGuid,\r
124 (VOID **)&LoadedImage\r
125 );\r
126 ASSERT_EFI_ERROR (Status);\r
127 LoadedImage->Unload = _DriverUnloadHandler;\r
128 }\r
129\r
130 //\r
131 // Call the driver entry point\r
132 //\r
133 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r
134\r
135 //\r
136 // If all of the drivers returned errors, then invoke all of the library destructors\r
137 //\r
138 if (EFI_ERROR (Status)) {\r
139 ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
140 }\r
141\r
142 //\r
143 // Return the cummalative return status code from all of the driver entry points\r
144 //\r
145 return Status;\r
146}\r
147\r
148\r
149/**\r
150 Required by the EBC compiler and identical in functionality to _ModuleEntryPoint(). \r
151\r
152 This function is required to call _ModuleEntryPoint() passing in ImageHandle,\r
153 and SystemTable.\r
154\r
155 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE \r
156 SMM Driver, or UEFI Driver.\r
157 @param SystemTable A pointer to the EFI System Table.\r
158\r
159 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM \r
160 Driver, or UEFI Driver exited normally.\r
161 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than \r
162 SystemTable->Hdr.Revision.\r
163 @retval Other Return value from ProcessModuleEntryPointList().\r
164**/\r
165EFI_STATUS\r
166EFIAPI\r
167EfiMain (\r
168 IN EFI_HANDLE ImageHandle,\r
169 IN EFI_SYSTEM_TABLE *SystemTable\r
170 )\r
171{\r
172 return _ModuleEntryPoint (ImageHandle, SystemTable);\r
173}\r