]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
MdePkg: Replace BSD License with BSD+Patent License
[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
9344f092 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
e386b444 6\r
7**/\r
8\r
9\r
c892d846 10\r
c7d265a9 11#include <Uefi.h>\r
c892d846 12\r
c7d265a9 13#include <Protocol/LoadedImage.h>\r
c892d846 14\r
c7d265a9 15#include <Library/UefiDriverEntryPoint.h>\r
6517edbe 16#include <Library/BaseLib.h>\r
c7d265a9 17#include <Library/DebugLib.h>\r
18#include <Library/UefiBootServicesTableLib.h>\r
e386b444 19\r
20\r
21/**\r
7eb2c64d 22 Unloads an image from memory.\r
e386b444 23\r
9095d37b 24 This function is a callback that a driver registers to do cleanup\r
7eb2c64d
LG
25 when the UnloadImage boot service function is called.\r
26\r
27 @param ImageHandle The handle to the image to unload.\r
e386b444 28\r
373b5cf9 29 @return Status returned by all unload().\r
e386b444 30\r
31**/\r
e386b444 32EFI_STATUS\r
33EFIAPI\r
34_DriverUnloadHandler (\r
35 EFI_HANDLE ImageHandle\r
36 )\r
37{\r
38 EFI_STATUS Status;\r
39\r
40 //\r
41 // If an UnloadImage() handler is specified, then call it\r
42 //\r
43 Status = ProcessModuleUnloadList (ImageHandle);\r
44\r
45 //\r
46 // If the driver specific unload handler does not return an error, then call all of the\r
47 // library destructors. If the unload handler returned an error, then the driver can not be\r
48 // unloaded, and the library destructors should not be called\r
49 //\r
50 if (!EFI_ERROR (Status)) {\r
e386b444 51 ProcessLibraryDestructorList (ImageHandle, gST);\r
52 }\r
53\r
54 //\r
55 // Return the status from the driver specific unload handler\r
56 //\r
57 return Status;\r
58}\r
59\r
60\r
e386b444 61/**\r
9095d37b
LG
62 The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM\r
63 Driver, or UEFI Driver.\r
66770ccb 64\r
65 This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver,\r
66 or UEFI Driver. This function must call ProcessLibraryConstructorList() and\r
67 ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList()\r
9095d37b
LG
68 is an error status, then ProcessLibraryDestructorList() must be called. The return\r
69 value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount\r
70 is greater than zero, then an unload handler must be registered for this image\r
58380e9c 71 and the unload handler must invoke ProcessModuleUnloadList().\r
9095d37b 72 If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than\r
58380e9c 73 _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION.\r
e386b444 74\r
e386b444 75\r
9095d37b 76 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver,\r
58380e9c 77 DXE SMM Driver, or UEFI Driver.\r
f6d2bcc6 78 @param SystemTable A pointer to the EFI System Table.\r
66770ccb 79\r
9095d37b 80 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM\r
58380e9c 81 Driver, or UEFI Driver exited normally.\r
9095d37b 82 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than\r
58380e9c 83 SystemTable->Hdr.Revision.\r
66770ccb 84 @retval Other Return value from ProcessModuleEntryPointList().\r
e386b444 85\r
86**/\r
87EFI_STATUS\r
88EFIAPI\r
89_ModuleEntryPoint (\r
90 IN EFI_HANDLE ImageHandle,\r
91 IN EFI_SYSTEM_TABLE *SystemTable\r
92 )\r
93{\r
94 EFI_STATUS Status;\r
95 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
96\r
97 if (_gUefiDriverRevision != 0) {\r
98 //\r
99 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r
100 //\r
101 if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r
102 return EFI_INCOMPATIBLE_VERSION;\r
103 }\r
104 }\r
105\r
c7d265a9 106 //\r
107 // Call constructor for all libraries\r
108 //\r
109 ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
110\r
e386b444 111 //\r
112 // Install unload handler...\r
113 //\r
114 if (_gDriverUnloadImageCount != 0) {\r
115 Status = gBS->HandleProtocol (\r
116 ImageHandle,\r
117 &gEfiLoadedImageProtocolGuid,\r
118 (VOID **)&LoadedImage\r
119 );\r
120 ASSERT_EFI_ERROR (Status);\r
121 LoadedImage->Unload = _DriverUnloadHandler;\r
122 }\r
123\r
e386b444 124 //\r
125 // Call the driver entry point\r
126 //\r
127 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r
128\r
129 //\r
130 // If all of the drivers returned errors, then invoke all of the library destructors\r
131 //\r
132 if (EFI_ERROR (Status)) {\r
133 ProcessLibraryDestructorList (ImageHandle, SystemTable);\r
134 }\r
135\r
136 //\r
137 // Return the cummalative return status code from all of the driver entry points\r
138 //\r
139 return Status;\r
140}\r
141\r
142\r
143/**\r
9095d37b 144 Required by the EBC compiler and identical in functionality to _ModuleEntryPoint().\r
66770ccb 145\r
58380e9c 146 This function is required to call _ModuleEntryPoint() passing in ImageHandle,\r
147 and SystemTable.\r
e386b444 148\r
9095d37b 149 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE\r
58380e9c 150 SMM Driver, or UEFI Driver.\r
f6d2bcc6 151 @param SystemTable A pointer to the EFI System Table.\r
e386b444 152\r
9095d37b 153 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM\r
58380e9c 154 Driver, or UEFI Driver exited normally.\r
9095d37b 155 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than\r
58380e9c 156 SystemTable->Hdr.Revision.\r
66770ccb 157 @retval Other Return value from ProcessModuleEntryPointList().\r
e386b444 158**/\r
159EFI_STATUS\r
160EFIAPI\r
161EfiMain (\r
162 IN EFI_HANDLE ImageHandle,\r
163 IN EFI_SYSTEM_TABLE *SystemTable\r
164 )\r
165{\r
166 return _ModuleEntryPoint (ImageHandle, SystemTable);\r
167}\r