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