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