]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
remove some comments introduced by tools.
[mirror_edk2.git] / MdePkg / Library / UefiDriverEntryPoint / DriverEntryPoint.c
1 /** @file
2 Entry point to a EFI/DXE driver.
3
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. 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
32
33 @retval EFI_SUCCESS
34
35 **/
36 STATIC
37 EFI_STATUS
38 EFIAPI
39 _DriverUnloadHandler (
40 EFI_HANDLE ImageHandle
41 )
42 {
43 EFI_STATUS Status;
44
45 //
46 // If an UnloadImage() handler is specified, then call it
47 //
48 Status = ProcessModuleUnloadList (ImageHandle);
49
50 //
51 // If the driver specific unload handler does not return an error, then call all of the
52 // library destructors. If the unload handler returned an error, then the driver can not be
53 // unloaded, and the library destructors should not be called
54 //
55 if (!EFI_ERROR (Status)) {
56 ProcessLibraryDestructorList (ImageHandle, gST);
57 }
58
59 //
60 // Return the status from the driver specific unload handler
61 //
62 return Status;
63 }
64
65
66 /**
67 Enrty point to DXE Driver.
68
69 @param ImageHandle ImageHandle of the loaded driver.
70 @param SystemTable Pointer to the EFI System Table.
71
72 @retval EFI_SUCCESS One or more of the drivers returned a success code.
73 @retval !EFI_SUCESS The return status from the last driver entry point in the list.
74
75 **/
76 EFI_STATUS
77 EFIAPI
78 _ModuleEntryPoint (
79 IN EFI_HANDLE ImageHandle,
80 IN EFI_SYSTEM_TABLE *SystemTable
81 )
82 {
83 EFI_STATUS Status;
84 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
85
86 if (_gUefiDriverRevision != 0) {
87 //
88 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver
89 //
90 if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {
91 return EFI_INCOMPATIBLE_VERSION;
92 }
93 }
94
95 //
96 // Call constructor for all libraries
97 //
98 ProcessLibraryConstructorList (ImageHandle, SystemTable);
99
100 //
101 // Install unload handler...
102 //
103 if (_gDriverUnloadImageCount != 0) {
104 Status = gBS->HandleProtocol (
105 ImageHandle,
106 &gEfiLoadedImageProtocolGuid,
107 (VOID **)&LoadedImage
108 );
109 ASSERT_EFI_ERROR (Status);
110 LoadedImage->Unload = _DriverUnloadHandler;
111 }
112
113 //
114 // Call the driver entry point
115 //
116 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);
117
118 //
119 // If all of the drivers returned errors, then invoke all of the library destructors
120 //
121 if (EFI_ERROR (Status)) {
122 ProcessLibraryDestructorList (ImageHandle, SystemTable);
123 }
124
125 //
126 // Return the cummalative return status code from all of the driver entry points
127 //
128 return Status;
129 }
130
131
132 /**
133 Enrty point wrapper of DXE Driver.
134
135 @param ImageHandle ImageHandle of the loaded driver.
136 @param SystemTable Pointer to the EFI System Table.
137
138 @retval EFI_SUCCESS One or more of the drivers returned a success code.
139 @retval !EFI_SUCESS The return status from the last driver entry point in the list.
140
141 **/
142 EFI_STATUS
143 EFIAPI
144 EfiMain (
145 IN EFI_HANDLE ImageHandle,
146 IN EFI_SYSTEM_TABLE *SystemTable
147 )
148 {
149 return _ModuleEntryPoint (ImageHandle, SystemTable);
150 }