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