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