]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
Code Scrub the common includes in MdePkg.
[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 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 Enrty point to DXE Driver.
67
68 @param ImageHandle ImageHandle of the loaded driver.
69 @param SystemTable Pointer to the EFI System Table.
70
71 @retval EFI_SUCCESS One or more of the drivers returned a success code.
72 @retval !EFI_SUCESS The return status from the last driver entry point in the list.
73
74 **/
75 EFI_STATUS
76 EFIAPI
77 _ModuleEntryPoint (
78 IN EFI_HANDLE ImageHandle,
79 IN EFI_SYSTEM_TABLE *SystemTable
80 )
81 {
82 EFI_STATUS Status;
83 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
84
85 if (_gUefiDriverRevision != 0) {
86 //
87 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver
88 //
89 if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {
90 return EFI_INCOMPATIBLE_VERSION;
91 }
92 }
93
94 //
95 // Call constructor for all libraries
96 //
97 ProcessLibraryConstructorList (ImageHandle, SystemTable);
98
99 //
100 // Install unload handler...
101 //
102 if (_gDriverUnloadImageCount != 0) {
103 Status = gBS->HandleProtocol (
104 ImageHandle,
105 &gEfiLoadedImageProtocolGuid,
106 (VOID **)&LoadedImage
107 );
108 ASSERT_EFI_ERROR (Status);
109 LoadedImage->Unload = _DriverUnloadHandler;
110 }
111
112 //
113 // Call the driver entry point
114 //
115 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);
116
117 //
118 // If all of the drivers returned errors, then invoke all of the library destructors
119 //
120 if (EFI_ERROR (Status)) {
121 ProcessLibraryDestructorList (ImageHandle, SystemTable);
122 }
123
124 //
125 // Return the cummalative return status code from all of the driver entry points
126 //
127 return Status;
128 }
129
130
131 /**
132 Enrty point wrapper of DXE Driver.
133
134 @param ImageHandle ImageHandle of the loaded driver.
135 @param SystemTable Pointer to the EFI System Table.
136
137 @retval EFI_SUCCESS One or more of the drivers returned a success code.
138 @retval !EFI_SUCESS The return status from the last driver entry point in the list.
139
140 **/
141 EFI_STATUS
142 EFIAPI
143 EfiMain (
144 IN EFI_HANDLE ImageHandle,
145 IN EFI_SYSTEM_TABLE *SystemTable
146 )
147 {
148 return _ModuleEntryPoint (ImageHandle, SystemTable);
149 }