Updated the function comments in UefiDriverEntryLib to fix EDKT502.
[mirror_edk2.git] / MdePkg / Library / UefiDriverEntryPoint / DriverEntryPoint.c
CommitLineData
878ddf1f 1/** @file\r
2 Entry point to a EFI/DXE driver.\r
3\r
4Copyright (c) 2006, Intel Corporation<BR>\r
5All rights reserved. This 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
8c8a13bf 15\r
16EFI_EVENT _mDriverExitBootServicesNotifyEvent;\r
17\r
878ddf1f 18/**\r
19 Unload function that is registered in the LoadImage protocol. It un-installs\r
20 protocols produced and deallocates pool used by the driver. Called by the core\r
21 when unloading the driver.\r
22\r
23 @param ImageHandle\r
24\r
25 @retval EFI_SUCCESS\r
26\r
27**/\r
28EFI_STATUS\r
29EFIAPI\r
30_DriverUnloadHandler (\r
31 EFI_HANDLE ImageHandle\r
32 )\r
33{\r
34 EFI_STATUS Status;\r
35\r
36 //\r
37 // If an UnloadImage() handler is specified, then call it\r
38 //\r
39 Status = ProcessModuleUnloadList (ImageHandle);\r
40\r
41 //\r
42 // If the driver specific unload handler does not return an error, then call all of the\r
43 // library destructors. If the unload handler returned an error, then the driver can not be\r
44 // unloaded, and the library destructors should not be called\r
45 //\r
46 if (!EFI_ERROR (Status)) {\r
756e4264 47 //\r
48 // Close our ExitBootServices () notify function\r
49 //\r
50 if (_gDriverExitBootServicesEvent[0] != NULL) {\r
51 Status = gBS->CloseEvent (_mDriverExitBootServicesNotifyEvent);\r
52 ASSERT_EFI_ERROR (Status);\r
53 }\r
54\r
878ddf1f 55 ProcessLibraryDestructorList (ImageHandle, gST);\r
56 }\r
57\r
58 //\r
59 // Return the status from the driver specific unload handler\r
60 //\r
61 return Status;\r
62}\r
63\r
8c8a13bf 64\r
65/**\r
66 Notification Entry of ExitBootService event. In the entry, all notifications in _gDriverExitBootServicesEvent[] \r
67 would be invoked.\r
68\r
69 @param Event The Event that is being processed.\r
70 @param Context Event Context.\r
71\r
72**/\r
756e4264 73VOID\r
74EFIAPI\r
75_DriverExitBootServices (\r
76 IN EFI_EVENT Event,\r
77 IN VOID *Context\r
78 )\r
756e4264 79{\r
80 EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
81 UINTN Index;\r
82\r
83 for (Index = 0; _gDriverExitBootServicesEvent[Index] != NULL; Index++) {\r
84 ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];\r
85 ChildNotifyEventHandler (Event, NULL);\r
86 }\r
87}\r
88\r
878ddf1f 89/**\r
90 Enrty point to DXE Driver.\r
91\r
92 @param ImageHandle ImageHandle of the loaded driver.\r
93 @param SystemTable Pointer to the EFI System Table.\r
94\r
95 @retval EFI_SUCCESS One or more of the drivers returned a success code.\r
96 @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r
97\r
98**/\r
99EFI_STATUS\r
100EFIAPI\r
101_ModuleEntryPoint (\r
102 IN EFI_HANDLE ImageHandle,\r
103 IN EFI_SYSTEM_TABLE *SystemTable\r
104 )\r
105{\r
106 EFI_STATUS Status;\r
107 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
108\r
109 if (_gUefiDriverRevision != 0) {\r
110 //\r
111 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r
112 //\r
113 if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r
114 return EFI_INCOMPATIBLE_VERSION;\r
115 }\r
116 }\r
117\r
118 //\r
119 // Call constructor for all libraries\r
120 //\r
121 ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
122\r
756e4264 123 //\r
124 // Register our ExitBootServices () notify function\r
125 //\r
126 if (_gDriverExitBootServicesEvent[0] != NULL) {\r
127 Status = gBS->CreateEvent (\r
128 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
129 EFI_TPL_NOTIFY,\r
130 _DriverExitBootServices,\r
131 NULL,\r
132 &_mDriverExitBootServicesNotifyEvent\r
133 );\r
134\r
135 ASSERT_EFI_ERROR (Status);\r
136 }\r
137\r
878ddf1f 138 //\r
139 // Install unload handler...\r
140 //\r
141 if (_gDriverUnloadImageCount != 0) {\r
142 Status = gBS->HandleProtocol (\r
143 ImageHandle,\r
144 &gEfiLoadedImageProtocolGuid,\r
145 (VOID **)&LoadedImage\r
146 );\r
147 ASSERT_EFI_ERROR (Status);\r
148 LoadedImage->Unload = _DriverUnloadHandler;\r
149 }\r
150\r
151 //\r
152 // Call the driver entry point\r
153 //\r
154 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r
155\r
156 //\r
157 // If all of the drivers returned errors, then invoke all of the library destructors\r
158 //\r
159 if (EFI_ERROR (Status)) {\r
756e4264 160 //\r
161 // Close our ExitBootServices () notify function\r
162 //\r
163 if (_gDriverExitBootServicesEvent[0] != NULL) {\r
164 Status = gBS->CloseEvent (_mDriverExitBootServicesNotifyEvent);\r
165 ASSERT_EFI_ERROR (Status);\r
166 }\r
167\r
878ddf1f 168 ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
169 }\r
170\r
171 //\r
172 // Return the cummalative return status code from all of the driver entry points\r
173 //\r
174 return Status;\r
175}\r
176\r
177\r
178/**\r
179 Enrty point wrapper of DXE Driver.\r
180\r
181 @param ImageHandle ImageHandle of the loaded driver.\r
182 @param SystemTable Pointer to the EFI System Table.\r
183\r
184 @retval EFI_SUCCESS One or more of the drivers returned a success code.\r
185 @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r
186\r
187**/\r
188EFI_STATUS\r
189EFIAPI\r
190EfiMain (\r
191 IN EFI_HANDLE ImageHandle,\r
192 IN EFI_SYSTEM_TABLE *SystemTable\r
193 )\r
194{\r
195 return _ModuleEntryPoint (ImageHandle, SystemTable);\r
196}\r