]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | Entry point to a EFI/DXE driver.\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
8c8a13bf | 15 | \r |
16 | EFI_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 | |
58251024 | 28 | STATIC\r |
878ddf1f | 29 | EFI_STATUS\r |
30 | EFIAPI\r | |
31 | _DriverUnloadHandler (\r | |
32 | EFI_HANDLE ImageHandle\r | |
33 | )\r | |
34 | {\r | |
35 | EFI_STATUS Status;\r | |
36 | \r | |
37 | //\r | |
38 | // If an UnloadImage() handler is specified, then call it\r | |
39 | //\r | |
40 | Status = ProcessModuleUnloadList (ImageHandle);\r | |
41 | \r | |
42 | //\r | |
43 | // If the driver specific unload handler does not return an error, then call all of the\r | |
44 | // library destructors. If the unload handler returned an error, then the driver can not be\r | |
45 | // unloaded, and the library destructors should not be called\r | |
46 | //\r | |
47 | if (!EFI_ERROR (Status)) {\r | |
756e4264 | 48 | //\r |
49 | // Close our ExitBootServices () notify function\r | |
50 | //\r | |
51 | if (_gDriverExitBootServicesEvent[0] != NULL) {\r | |
52 | Status = gBS->CloseEvent (_mDriverExitBootServicesNotifyEvent);\r | |
53 | ASSERT_EFI_ERROR (Status);\r | |
54 | }\r | |
55 | \r | |
878ddf1f | 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 | |
8c8a13bf | 65 | \r |
66 | /**\r | |
93b0fbc8 | 67 | Notification Entry of ExitBootService event. In the entry, all notifications in _gDriverExitBootServicesEvent[]\r |
8c8a13bf | 68 | would be invoked.\r |
69 | \r | |
70 | @param Event The Event that is being processed.\r | |
71 | @param Context Event Context.\r | |
72 | \r | |
73 | **/\r | |
58251024 | 74 | STATIC\r |
756e4264 | 75 | VOID\r |
76 | EFIAPI\r | |
77 | _DriverExitBootServices (\r | |
78 | IN EFI_EVENT Event,\r | |
79 | IN VOID *Context\r | |
80 | )\r | |
756e4264 | 81 | {\r |
82 | EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r | |
83 | UINTN Index;\r | |
84 | \r | |
85 | for (Index = 0; _gDriverExitBootServicesEvent[Index] != NULL; Index++) {\r | |
86 | ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];\r | |
87 | ChildNotifyEventHandler (Event, NULL);\r | |
88 | }\r | |
89 | }\r | |
90 | \r | |
878ddf1f | 91 | /**\r |
92 | Enrty point to DXE Driver.\r | |
93 | \r | |
94 | @param ImageHandle ImageHandle of the loaded driver.\r | |
95 | @param SystemTable Pointer to the EFI System Table.\r | |
96 | \r | |
97 | @retval EFI_SUCCESS One or more of the drivers returned a success code.\r | |
98 | @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r | |
99 | \r | |
100 | **/\r | |
101 | EFI_STATUS\r | |
102 | EFIAPI\r | |
103 | _ModuleEntryPoint (\r | |
104 | IN EFI_HANDLE ImageHandle,\r | |
105 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
106 | )\r | |
107 | {\r | |
108 | EFI_STATUS Status;\r | |
109 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
110 | \r | |
111 | if (_gUefiDriverRevision != 0) {\r | |
112 | //\r | |
113 | // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r | |
114 | //\r | |
115 | if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r | |
116 | return EFI_INCOMPATIBLE_VERSION;\r | |
117 | }\r | |
118 | }\r | |
119 | \r | |
120 | //\r | |
121 | // Call constructor for all libraries\r | |
122 | //\r | |
123 | ProcessLibraryConstructorList (ImageHandle, SystemTable);\r | |
124 | \r | |
756e4264 | 125 | //\r |
126 | // Register our ExitBootServices () notify function\r | |
127 | //\r | |
128 | if (_gDriverExitBootServicesEvent[0] != NULL) {\r | |
129 | Status = gBS->CreateEvent (\r | |
93b0fbc8 | 130 | EVT_SIGNAL_EXIT_BOOT_SERVICES,\r |
131 | TPL_NOTIFY,\r | |
756e4264 | 132 | _DriverExitBootServices,\r |
133 | NULL,\r | |
134 | &_mDriverExitBootServicesNotifyEvent\r | |
135 | );\r | |
136 | \r | |
137 | ASSERT_EFI_ERROR (Status);\r | |
138 | }\r | |
139 | \r | |
878ddf1f | 140 | //\r |
141 | // Install unload handler...\r | |
142 | //\r | |
143 | if (_gDriverUnloadImageCount != 0) {\r | |
144 | Status = gBS->HandleProtocol (\r | |
145 | ImageHandle,\r | |
146 | &gEfiLoadedImageProtocolGuid,\r | |
147 | (VOID **)&LoadedImage\r | |
148 | );\r | |
149 | ASSERT_EFI_ERROR (Status);\r | |
150 | LoadedImage->Unload = _DriverUnloadHandler;\r | |
151 | }\r | |
152 | \r | |
153 | //\r | |
154 | // Call the driver entry point\r | |
155 | //\r | |
156 | Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r | |
157 | \r | |
158 | //\r | |
159 | // If all of the drivers returned errors, then invoke all of the library destructors\r | |
160 | //\r | |
161 | if (EFI_ERROR (Status)) {\r | |
756e4264 | 162 | //\r |
163 | // Close our ExitBootServices () notify function\r | |
164 | //\r | |
165 | if (_gDriverExitBootServicesEvent[0] != NULL) {\r | |
166 | Status = gBS->CloseEvent (_mDriverExitBootServicesNotifyEvent);\r | |
167 | ASSERT_EFI_ERROR (Status);\r | |
168 | }\r | |
169 | \r | |
878ddf1f | 170 | ProcessLibraryDestructorList (ImageHandle, SystemTable);\r |
171 | }\r | |
172 | \r | |
173 | //\r | |
174 | // Return the cummalative return status code from all of the driver entry points\r | |
175 | //\r | |
176 | return Status;\r | |
177 | }\r | |
178 | \r | |
179 | \r | |
180 | /**\r | |
181 | Enrty point wrapper of DXE Driver.\r | |
182 | \r | |
183 | @param ImageHandle ImageHandle of the loaded driver.\r | |
184 | @param SystemTable Pointer to the EFI System Table.\r | |
185 | \r | |
186 | @retval EFI_SUCCESS One or more of the drivers returned a success code.\r | |
187 | @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r | |
188 | \r | |
189 | **/\r | |
190 | EFI_STATUS\r | |
191 | EFIAPI\r | |
192 | EfiMain (\r | |
193 | IN EFI_HANDLE ImageHandle,\r | |
194 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
195 | )\r | |
196 | {\r | |
197 | return _ModuleEntryPoint (ImageHandle, SystemTable);\r | |
198 | }\r |