]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[mirror_edk2.git] / MdePkg / Library / UefiDriverEntryPoint / DriverEntryPoint.c
CommitLineData
e386b444 1/** @file\r
2 Entry point to a EFI/DXE driver.\r
3\r
9095d37b 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
19388d29 5This program and the accompanying materials\r
e386b444 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
6517edbe 22#include <Library/BaseLib.h>\r
c7d265a9 23#include <Library/DebugLib.h>\r
24#include <Library/UefiBootServicesTableLib.h>\r
e386b444 25\r
26\r
27/**\r
7eb2c64d 28 Unloads an image from memory.\r
e386b444 29\r
9095d37b 30 This function is a callback that a driver registers to do cleanup\r
7eb2c64d
LG
31 when the UnloadImage boot service function is called.\r
32\r
33 @param ImageHandle The handle to the image to unload.\r
e386b444 34\r
373b5cf9 35 @return Status returned by all unload().\r
e386b444 36\r
37**/\r
e386b444 38EFI_STATUS\r
39EFIAPI\r
40_DriverUnloadHandler (\r
41 EFI_HANDLE ImageHandle\r
42 )\r
43{\r
44 EFI_STATUS Status;\r
45\r
46 //\r
47 // If an UnloadImage() handler is specified, then call it\r
48 //\r
49 Status = ProcessModuleUnloadList (ImageHandle);\r
50\r
51 //\r
52 // If the driver specific unload handler does not return an error, then call all of the\r
53 // library destructors. If the unload handler returned an error, then the driver can not be\r
54 // unloaded, and the library destructors should not be called\r
55 //\r
56 if (!EFI_ERROR (Status)) {\r
e386b444 57 ProcessLibraryDestructorList (ImageHandle, gST);\r
58 }\r
59\r
60 //\r
61 // Return the status from the driver specific unload handler\r
62 //\r
63 return Status;\r
64}\r
65\r
66\r
e386b444 67/**\r
9095d37b
LG
68 The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM\r
69 Driver, or UEFI Driver.\r
66770ccb 70\r
71 This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver,\r
72 or UEFI Driver. This function must call ProcessLibraryConstructorList() and\r
73 ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList()\r
9095d37b
LG
74 is an error status, then ProcessLibraryDestructorList() must be called. The return\r
75 value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount\r
76 is greater than zero, then an unload handler must be registered for this image\r
58380e9c 77 and the unload handler must invoke ProcessModuleUnloadList().\r
9095d37b 78 If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than\r
58380e9c 79 _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION.\r
e386b444 80\r
e386b444 81\r
9095d37b 82 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver,\r
58380e9c 83 DXE SMM Driver, or UEFI Driver.\r
f6d2bcc6 84 @param SystemTable A pointer to the EFI System Table.\r
66770ccb 85\r
9095d37b 86 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM\r
58380e9c 87 Driver, or UEFI Driver exited normally.\r
9095d37b 88 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than\r
58380e9c 89 SystemTable->Hdr.Revision.\r
66770ccb 90 @retval Other Return value from ProcessModuleEntryPointList().\r
e386b444 91\r
92**/\r
93EFI_STATUS\r
94EFIAPI\r
95_ModuleEntryPoint (\r
96 IN EFI_HANDLE ImageHandle,\r
97 IN EFI_SYSTEM_TABLE *SystemTable\r
98 )\r
99{\r
100 EFI_STATUS Status;\r
101 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
102\r
103 if (_gUefiDriverRevision != 0) {\r
104 //\r
105 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r
106 //\r
107 if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r
108 return EFI_INCOMPATIBLE_VERSION;\r
109 }\r
110 }\r
111\r
c7d265a9 112 //\r
113 // Call constructor for all libraries\r
114 //\r
115 ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
116\r
e386b444 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
e386b444 130 //\r
131 // Call the driver entry point\r
132 //\r
133 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r
134\r
135 //\r
136 // If all of the drivers returned errors, then invoke all of the library destructors\r
137 //\r
138 if (EFI_ERROR (Status)) {\r
139 ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
140 }\r
141\r
142 //\r
143 // Return the cummalative return status code from all of the driver entry points\r
144 //\r
145 return Status;\r
146}\r
147\r
148\r
149/**\r
9095d37b 150 Required by the EBC compiler and identical in functionality to _ModuleEntryPoint().\r
66770ccb 151\r
58380e9c 152 This function is required to call _ModuleEntryPoint() passing in ImageHandle,\r
153 and SystemTable.\r
e386b444 154\r
9095d37b 155 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE\r
58380e9c 156 SMM Driver, or UEFI Driver.\r
f6d2bcc6 157 @param SystemTable A pointer to the EFI System Table.\r
e386b444 158\r
9095d37b 159 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM\r
58380e9c 160 Driver, or UEFI Driver exited normally.\r
9095d37b 161 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than\r
58380e9c 162 SystemTable->Hdr.Revision.\r
66770ccb 163 @retval Other Return value from ProcessModuleEntryPointList().\r
e386b444 164**/\r
165EFI_STATUS\r
166EFIAPI\r
167EfiMain (\r
168 IN EFI_HANDLE ImageHandle,\r
169 IN EFI_SYSTEM_TABLE *SystemTable\r
170 )\r
171{\r
172 return _ModuleEntryPoint (ImageHandle, SystemTable);\r
173}\r