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