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