]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiDriverEntryPoint/DriverEntryPoint.c
Checked in part of MDE library instances following PI and UEFI. It includes:
[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 // The package level header files this module uses
18 //
19 #include <Uefi.h>
20 //
21 // The protocols, PPI and GUID defintions for this module
22 //
23 #include <Protocol/LoadedImage.h>
24 //
25 // The Library classes this module consumes
26 //
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/DebugLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30
31
32 /**
33 Unload function that is registered in the LoadImage protocol. It un-installs
34 protocols produced and deallocates pool used by the driver. Called by the core
35 when unloading the driver.
36
37 @param ImageHandle
38
39 @retval EFI_SUCCESS
40
41 **/
42 STATIC
43 EFI_STATUS
44 EFIAPI
45 _DriverUnloadHandler (
46 EFI_HANDLE ImageHandle
47 )
48 {
49 EFI_STATUS Status;
50
51 //
52 // If an UnloadImage() handler is specified, then call it
53 //
54 Status = ProcessModuleUnloadList (ImageHandle);
55
56 //
57 // If the driver specific unload handler does not return an error, then call all of the
58 // library destructors. If the unload handler returned an error, then the driver can not be
59 // unloaded, and the library destructors should not be called
60 //
61 if (!EFI_ERROR (Status)) {
62 ProcessLibraryDestructorList (ImageHandle, gST);
63 }
64
65 //
66 // Return the status from the driver specific unload handler
67 //
68 return Status;
69 }
70
71
72 /**
73 Enrty point to DXE Driver.
74
75 @param ImageHandle ImageHandle of the loaded driver.
76 @param SystemTable Pointer to the EFI System Table.
77
78 @retval EFI_SUCCESS One or more of the drivers returned a success code.
79 @retval !EFI_SUCESS The return status from the last driver entry point in the list.
80
81 **/
82 EFI_STATUS
83 EFIAPI
84 _ModuleEntryPoint (
85 IN EFI_HANDLE ImageHandle,
86 IN EFI_SYSTEM_TABLE *SystemTable
87 )
88 {
89 EFI_STATUS Status;
90 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
91
92 if (_gUefiDriverRevision != 0) {
93 //
94 // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver
95 //
96 if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {
97 return EFI_INCOMPATIBLE_VERSION;
98 }
99 }
100
101 //
102 // Call constructor for all libraries
103 //
104 ProcessLibraryConstructorList (ImageHandle, SystemTable);
105
106 //
107 // Install unload handler...
108 //
109 if (_gDriverUnloadImageCount != 0) {
110 Status = gBS->HandleProtocol (
111 ImageHandle,
112 &gEfiLoadedImageProtocolGuid,
113 (VOID **)&LoadedImage
114 );
115 ASSERT_EFI_ERROR (Status);
116 LoadedImage->Unload = _DriverUnloadHandler;
117 }
118
119 //
120 // Call the driver entry point
121 //
122 Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);
123
124 //
125 // If all of the drivers returned errors, then invoke all of the library destructors
126 //
127 if (EFI_ERROR (Status)) {
128 ProcessLibraryDestructorList (ImageHandle, SystemTable);
129 }
130
131 //
132 // Return the cummalative return status code from all of the driver entry points
133 //
134 return Status;
135 }
136
137
138 /**
139 Enrty point wrapper of DXE Driver.
140
141 @param ImageHandle ImageHandle of the loaded driver.
142 @param SystemTable Pointer to the EFI System Table.
143
144 @retval EFI_SUCCESS One or more of the drivers returned a success code.
145 @retval !EFI_SUCESS The return status from the last driver entry point in the list.
146
147 **/
148 EFI_STATUS
149 EFIAPI
150 EfiMain (
151 IN EFI_HANDLE ImageHandle,
152 IN EFI_SYSTEM_TABLE *SystemTable
153 )
154 {
155 return _ModuleEntryPoint (ImageHandle, SystemTable);
156 }