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