]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 - 2018, Intel Corporation. All rights reserved.<BR>\r
5SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include <Uefi.h>\r
10\r
11#include <Protocol/LoadedImage.h>\r
12\r
13#include <Library/UefiDriverEntryPoint.h>\r
14#include <Library/BaseLib.h>\r
15#include <Library/DebugLib.h>\r
16#include <Library/UefiBootServicesTableLib.h>\r
17\r
18/**\r
19 Unloads an image from memory.\r
20\r
21 This function is a callback that a driver registers to do cleanup\r
22 when the UnloadImage boot service function is called.\r
23\r
24 @param ImageHandle The handle to the image to unload.\r
25\r
26 @return Status returned by all unload().\r
27\r
28**/\r
29EFI_STATUS\r
30EFIAPI\r
31_DriverUnloadHandler (\r
32 EFI_HANDLE ImageHandle\r
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
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
57/**\r
58 The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM\r
59 Driver, or UEFI Driver.\r
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
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
67 and the unload handler must invoke ProcessModuleUnloadList().\r
68 If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than\r
69 _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION.\r
70\r
71\r
72 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver,\r
73 DXE SMM Driver, or UEFI Driver.\r
74 @param SystemTable A pointer to the EFI System Table.\r
75\r
76 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM\r
77 Driver, or UEFI Driver exited normally.\r
78 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than\r
79 SystemTable->Hdr.Revision.\r
80 @retval Other Return value from ProcessModuleEntryPointList().\r
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
102 //\r
103 // Call constructor for all libraries\r
104 //\r
105 ProcessLibraryConstructorList (ImageHandle, SystemTable);\r
106\r
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
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
138/**\r
139 Required by the EBC compiler and identical in functionality to _ModuleEntryPoint().\r
140\r
141 This function is required to call _ModuleEntryPoint() passing in ImageHandle,\r
142 and SystemTable.\r
143\r
144 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE\r
145 SMM Driver, or UEFI Driver.\r
146 @param SystemTable A pointer to the EFI System Table.\r
147\r
148 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM\r
149 Driver, or UEFI Driver exited normally.\r
150 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than\r
151 SystemTable->Hdr.Revision.\r
152 @retval Other Return value from ProcessModuleEntryPointList().\r
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