]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
Modify the EFI_USB_DATA_DIRECTION according to UEFI specification 2.1 page 708.
[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, 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
15/**\r
16 Unload function that is registered in the LoadImage protocol. It un-installs\r
17 protocols produced and deallocates pool used by the driver. Called by the core\r
18 when unloading the driver.\r
19\r
20 @param ImageHandle\r
21\r
22 @retval EFI_SUCCESS\r
23\r
24**/\r
25\r
26EFI_EVENT _mDriverExitBootServicesNotifyEvent;\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
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
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
64VOID\r
65EFIAPI\r
66_DriverExitBootServices (\r
67 IN EFI_EVENT Event,\r
68 IN VOID *Context\r
69 )\r
70/*++\r
71\r
72Routine Description:\r
73\r
74 Set AtRuntime flag as TRUE after ExitBootServices\r
75\r
76Arguments:\r
77\r
78 Event - The Event that is being processed\r
79 \r
80 Context - Event Context\r
81\r
82Returns: \r
83\r
84 None\r
85\r
86--*/\r
87{\r
88 EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
89 UINTN Index;\r
90\r
91 for (Index = 0; _gDriverExitBootServicesEvent[Index] != NULL; Index++) {\r
92 ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];\r
93 ChildNotifyEventHandler (Event, NULL);\r
94 }\r
95}\r
96\r
97/**\r
98 Enrty point to DXE Driver.\r
99\r
100 @param ImageHandle ImageHandle of the loaded driver.\r
101 @param SystemTable Pointer to the EFI System Table.\r
102\r
103 @retval EFI_SUCCESS One or more of the drivers returned a success code.\r
104 @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r
105\r
106**/\r
107EFI_STATUS\r
108EFIAPI\r
109_ModuleEntryPoint (\r
110 IN EFI_HANDLE ImageHandle,\r
111 IN EFI_SYSTEM_TABLE *SystemTable\r
112 )\r
113{\r
114 EFI_STATUS Status;\r
115 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
116\r
117 if (_gUefiDriverRevision != 0) {\r
118 //\r
119 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r
120 //\r
121 if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r
122 return EFI_INCOMPATIBLE_VERSION;\r
123 }\r
124 }\r
125\r
126 //\r
127 // Call constructor for all libraries\r
128 //\r
129 ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
130\r
131 //\r
132 // Register our ExitBootServices () notify function\r
133 //\r
134 if (_gDriverExitBootServicesEvent[0] != NULL) {\r
135 Status = gBS->CreateEvent (\r
136 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
137 EFI_TPL_NOTIFY,\r
138 _DriverExitBootServices,\r
139 NULL,\r
140 &_mDriverExitBootServicesNotifyEvent\r
141 );\r
142\r
143 ASSERT_EFI_ERROR (Status);\r
144 }\r
145\r
146 //\r
147 // Install unload handler...\r
148 //\r
149 if (_gDriverUnloadImageCount != 0) {\r
150 Status = gBS->HandleProtocol (\r
151 ImageHandle,\r
152 &gEfiLoadedImageProtocolGuid,\r
153 (VOID **)&LoadedImage\r
154 );\r
155 ASSERT_EFI_ERROR (Status);\r
156 LoadedImage->Unload = _DriverUnloadHandler;\r
157 }\r
158\r
159 //\r
160 // Call the driver entry point\r
161 //\r
162 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r
163\r
164 //\r
165 // If all of the drivers returned errors, then invoke all of the library destructors\r
166 //\r
167 if (EFI_ERROR (Status)) {\r
168 //\r
169 // Close our ExitBootServices () notify function\r
170 //\r
171 if (_gDriverExitBootServicesEvent[0] != NULL) {\r
172 Status = gBS->CloseEvent (_mDriverExitBootServicesNotifyEvent);\r
173 ASSERT_EFI_ERROR (Status);\r
174 }\r
175\r
176 ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
177 }\r
178\r
179 //\r
180 // Return the cummalative return status code from all of the driver entry points\r
181 //\r
182 return Status;\r
183}\r
184\r
185\r
186/**\r
187 Enrty point wrapper of DXE Driver.\r
188\r
189 @param ImageHandle ImageHandle of the loaded driver.\r
190 @param SystemTable Pointer to the EFI System Table.\r
191\r
192 @retval EFI_SUCCESS One or more of the drivers returned a success code.\r
193 @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r
194\r
195**/\r
196EFI_STATUS\r
197EFIAPI\r
198EfiMain (\r
199 IN EFI_HANDLE ImageHandle,\r
200 IN EFI_SYSTEM_TABLE *SystemTable\r
201 )\r
202{\r
203 return _ModuleEntryPoint (ImageHandle, SystemTable);\r
204}\r