]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
MdePkg: Clean up source files
[mirror_edk2.git] / MdePkg / Library / UefiDriverEntryPoint / DriverEntryPoint.c
1 /** @file
2 Entry point to a EFI/DXE driver.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16
17 #include <Uefi.h>
18
19 #include <Protocol/LoadedImage.h>
20
21 #include <Library/UefiDriverEntryPoint.h>
22 #include <Library/BaseLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
25
26
27 /**
28 Unloads an image from memory.
29
30 This function is a callback that a driver registers to do cleanup
31 when the UnloadImage boot service function is called.
32
33 @param ImageHandle The handle to the image to unload.
34
35 @return Status returned by all unload().
36
37 **/
38 EFI_STATUS
39 EFIAPI
40 _DriverUnloadHandler (
41 EFI_HANDLE ImageHandle
42 )
43 {
44 EFI_STATUS Status;
45
46 //
47 // If an UnloadImage() handler is specified, then call it
48 //
49 Status = ProcessModuleUnloadList (ImageHandle);
50
51 //
52 // If the driver specific unload handler does not return an error, then call all of the
53 // library destructors. If the unload handler returned an error, then the driver can not be
54 // unloaded, and the library destructors should not be called
55 //
56 if (!EFI_ERROR (Status)) {
57 ProcessLibraryDestructorList (ImageHandle, gST);
58 }
59
60 //
61 // Return the status from the driver specific unload handler
62 //
63 return Status;
64 }
65
66
67 /**
68 The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM
69 Driver, or UEFI Driver.
70
71 This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver,
72 or UEFI Driver. This function must call ProcessLibraryConstructorList() and
73 ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList()
74 is an error status, then ProcessLibraryDestructorList() must be called. The return
75 value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount
76 is greater than zero, then an unload handler must be registered for this image
77 and the unload handler must invoke ProcessModuleUnloadList().
78 If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than
79 _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION.
80
81
82 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver,
83 DXE SMM Driver, or UEFI Driver.
84 @param SystemTable A pointer to the EFI System Table.
85
86 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM
87 Driver, or UEFI Driver exited normally.
88 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
89 SystemTable->Hdr.Revision.
90 @retval Other Return value from ProcessModuleEntryPointList().
91
92 **/
93 EFI_STATUS
94 EFIAPI
95 _ModuleEntryPoint (
96 IN EFI_HANDLE ImageHandle,
97 IN EFI_SYSTEM_TABLE *SystemTable
98 )
99 {
100 EFI_STATUS Status;
101 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
102
103 if (_gUefiDriverRevision != 0) {
104 //
105 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver
106 //
107 if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {
108 return EFI_INCOMPATIBLE_VERSION;
109 }
110 }
111
112 //
113 // Call constructor for all libraries
114 //
115 ProcessLibraryConstructorList (ImageHandle, SystemTable);
116
117 //
118 // Install unload handler...
119 //
120 if (_gDriverUnloadImageCount != 0) {
121 Status = gBS->HandleProtocol (
122 ImageHandle,
123 &gEfiLoadedImageProtocolGuid,
124 (VOID **)&LoadedImage
125 );
126 ASSERT_EFI_ERROR (Status);
127 LoadedImage->Unload = _DriverUnloadHandler;
128 }
129
130 //
131 // Call the driver entry point
132 //
133 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);
134
135 //
136 // If all of the drivers returned errors, then invoke all of the library destructors
137 //
138 if (EFI_ERROR (Status)) {
139 ProcessLibraryDestructorList (ImageHandle, SystemTable);
140 }
141
142 //
143 // Return the cummalative return status code from all of the driver entry points
144 //
145 return Status;
146 }
147
148
149 /**
150 Required by the EBC compiler and identical in functionality to _ModuleEntryPoint().
151
152 This function is required to call _ModuleEntryPoint() passing in ImageHandle,
153 and SystemTable.
154
155 @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE
156 SMM Driver, or UEFI Driver.
157 @param SystemTable A pointer to the EFI System Table.
158
159 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM
160 Driver, or UEFI Driver exited normally.
161 @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
162 SystemTable->Hdr.Revision.
163 @retval Other Return value from ProcessModuleEntryPointList().
164 **/
165 EFI_STATUS
166 EFIAPI
167 EfiMain (
168 IN EFI_HANDLE ImageHandle,
169 IN EFI_SYSTEM_TABLE *SystemTable
170 )
171 {
172 return _ModuleEntryPoint (ImageHandle, SystemTable);
173 }