]>
Commit | Line | Data |
---|---|---|
e386b444 | 1 | /** @file\r |
2 | Entry point to a EFI/DXE driver.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2007, 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 | |
15 | \r | |
16 | //\r | |
17 | // Include common header file for this module.\r | |
18 | //\r | |
19 | #include "CommonHeader.h"\r | |
20 | \r | |
21 | \r | |
22 | /**\r | |
23 | Unload function that is registered in the LoadImage protocol. It un-installs\r | |
24 | protocols produced and deallocates pool used by the driver. Called by the core\r | |
25 | when unloading the driver.\r | |
26 | \r | |
27 | @param ImageHandle\r | |
28 | \r | |
29 | @retval EFI_SUCCESS\r | |
30 | \r | |
31 | **/\r | |
32 | STATIC\r | |
33 | EFI_STATUS\r | |
34 | EFIAPI\r | |
35 | _DriverUnloadHandler (\r | |
36 | EFI_HANDLE ImageHandle\r | |
37 | )\r | |
38 | {\r | |
39 | EFI_STATUS Status;\r | |
40 | \r | |
41 | //\r | |
42 | // If an UnloadImage() handler is specified, then call it\r | |
43 | //\r | |
44 | Status = ProcessModuleUnloadList (ImageHandle);\r | |
45 | \r | |
46 | //\r | |
47 | // If the driver specific unload handler does not return an error, then call all of the\r | |
48 | // library destructors. If the unload handler returned an error, then the driver can not be\r | |
49 | // unloaded, and the library destructors should not be called\r | |
50 | //\r | |
51 | if (!EFI_ERROR (Status)) {\r | |
52 | \r | |
53 | ProcessLibraryDestructorList (ImageHandle, gST);\r | |
54 | }\r | |
55 | \r | |
56 | //\r | |
57 | // Return the status from the driver specific unload handler\r | |
58 | //\r | |
59 | return Status;\r | |
60 | }\r | |
61 | \r | |
62 | \r | |
63 | /**\r | |
64 | Notification Entry of ExitBootService event. In the entry, all notifications in _gDriverExitBootServicesEvent[]\r | |
65 | would be invoked.\r | |
66 | \r | |
67 | @param Event The Event that is being processed.\r | |
68 | @param Context Event Context.\r | |
69 | \r | |
70 | **/\r | |
71 | STATIC\r | |
72 | VOID\r | |
73 | EFIAPI\r | |
74 | _DriverExitBootServices (\r | |
75 | IN EFI_EVENT Event,\r | |
76 | IN VOID *Context\r | |
77 | )\r | |
78 | {\r | |
79 | EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r | |
80 | UINTN Index;\r | |
81 | \r | |
82 | for (Index = 0; _gDriverExitBootServicesEvent[Index] != NULL; Index++) {\r | |
83 | ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];\r | |
84 | ChildNotifyEventHandler (Event, NULL);\r | |
85 | }\r | |
86 | }\r | |
87 | \r | |
88 | /**\r | |
89 | Enrty point to DXE Driver.\r | |
90 | \r | |
91 | @param ImageHandle ImageHandle of the loaded driver.\r | |
92 | @param SystemTable Pointer to the EFI System Table.\r | |
93 | \r | |
94 | @retval EFI_SUCCESS One or more of the drivers returned a success code.\r | |
95 | @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r | |
96 | \r | |
97 | **/\r | |
98 | EFI_STATUS\r | |
99 | EFIAPI\r | |
100 | _ModuleEntryPoint (\r | |
101 | IN EFI_HANDLE ImageHandle,\r | |
102 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
103 | )\r | |
104 | {\r | |
105 | EFI_STATUS Status;\r | |
106 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
107 | \r | |
108 | if (_gUefiDriverRevision != 0) {\r | |
109 | //\r | |
110 | // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r | |
111 | //\r | |
112 | if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r | |
113 | return EFI_INCOMPATIBLE_VERSION;\r | |
114 | }\r | |
115 | }\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 constructor for all libraries\r | |
132 | //\r | |
133 | ProcessLibraryConstructorList (ImageHandle, SystemTable);\r | |
134 | \r | |
135 | //\r | |
136 | // Call the driver entry point\r | |
137 | //\r | |
138 | Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r | |
139 | \r | |
140 | //\r | |
141 | // If all of the drivers returned errors, then invoke all of the library destructors\r | |
142 | //\r | |
143 | if (EFI_ERROR (Status)) {\r | |
144 | ProcessLibraryDestructorList (ImageHandle, SystemTable);\r | |
145 | }\r | |
146 | \r | |
147 | //\r | |
148 | // Return the cummalative return status code from all of the driver entry points\r | |
149 | //\r | |
150 | return Status;\r | |
151 | }\r | |
152 | \r | |
153 | \r | |
154 | /**\r | |
155 | Enrty point wrapper of DXE Driver.\r | |
156 | \r | |
157 | @param ImageHandle ImageHandle of the loaded driver.\r | |
158 | @param SystemTable Pointer to the EFI System Table.\r | |
159 | \r | |
160 | @retval EFI_SUCCESS One or more of the drivers returned a success code.\r | |
161 | @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r | |
162 | \r | |
163 | **/\r | |
164 | EFI_STATUS\r | |
165 | EFIAPI\r | |
166 | EfiMain (\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 |