1 | /** @file
|
---|
2 | Entry point to a EFI/DXE driver.
|
---|
3 |
|
---|
4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include <Uefi.h>
|
---|
10 |
|
---|
11 | #include <Protocol/LoadedImage.h>
|
---|
12 |
|
---|
13 | #include <Library/UefiDriverEntryPoint.h>
|
---|
14 | #include <Library/BaseLib.h>
|
---|
15 | #include <Library/DebugLib.h>
|
---|
16 | #include <Library/UefiBootServicesTableLib.h>
|
---|
17 |
|
---|
18 | /**
|
---|
19 | Unloads an image from memory.
|
---|
20 |
|
---|
21 | This function is a callback that a driver registers to do cleanup
|
---|
22 | when the UnloadImage boot service function is called.
|
---|
23 |
|
---|
24 | @param ImageHandle The handle to the image to unload.
|
---|
25 |
|
---|
26 | @return Status returned by all unload().
|
---|
27 |
|
---|
28 | **/
|
---|
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 | ProcessLibraryDestructorList (ImageHandle, gST);
|
---|
49 | }
|
---|
50 |
|
---|
51 | //
|
---|
52 | // Return the status from the driver specific unload handler
|
---|
53 | //
|
---|
54 | return Status;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM
|
---|
59 | Driver, or UEFI Driver.
|
---|
60 |
|
---|
61 | This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver,
|
---|
62 | or UEFI Driver. This function must call ProcessLibraryConstructorList() and
|
---|
63 | ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList()
|
---|
64 | is an error status, then ProcessLibraryDestructorList() must be called. The return
|
---|
65 | value from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount
|
---|
66 | is greater than zero, then an unload handler must be registered for this image
|
---|
67 | and the unload handler must invoke ProcessModuleUnloadList().
|
---|
68 | If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than
|
---|
69 | _gUefiDriverRevison, then return EFI_INCOMPATIBLE_VERSION.
|
---|
70 |
|
---|
71 |
|
---|
72 | @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver,
|
---|
73 | DXE SMM Driver, or UEFI Driver.
|
---|
74 | @param SystemTable A pointer to the EFI System Table.
|
---|
75 |
|
---|
76 | @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM
|
---|
77 | Driver, or UEFI Driver exited normally.
|
---|
78 | @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
|
---|
79 | SystemTable->Hdr.Revision.
|
---|
80 | @retval Other Return value from ProcessModuleEntryPointList().
|
---|
81 |
|
---|
82 | **/
|
---|
83 | EFI_STATUS
|
---|
84 | EFIAPI
|
---|
85 | _ModuleEntryPoint (
|
---|
86 | IN EFI_HANDLE ImageHandle,
|
---|
87 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
88 | )
|
---|
89 | {
|
---|
90 | EFI_STATUS Status;
|
---|
91 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
|
---|
92 |
|
---|
93 | if (_gUefiDriverRevision != 0) {
|
---|
94 | //
|
---|
95 | // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver
|
---|
96 | //
|
---|
97 | if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {
|
---|
98 | return EFI_INCOMPATIBLE_VERSION;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | //
|
---|
103 | // Call constructor for all libraries
|
---|
104 | //
|
---|
105 | ProcessLibraryConstructorList (ImageHandle, SystemTable);
|
---|
106 |
|
---|
107 | //
|
---|
108 | // Install unload handler...
|
---|
109 | //
|
---|
110 | if (_gDriverUnloadImageCount != 0) {
|
---|
111 | Status = gBS->HandleProtocol (
|
---|
112 | ImageHandle,
|
---|
113 | &gEfiLoadedImageProtocolGuid,
|
---|
114 | (VOID **)&LoadedImage
|
---|
115 | );
|
---|
116 | ASSERT_EFI_ERROR (Status);
|
---|
117 | LoadedImage->Unload = _DriverUnloadHandler;
|
---|
118 | }
|
---|
119 |
|
---|
120 | //
|
---|
121 | // Call the driver entry point
|
---|
122 | //
|
---|
123 | Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);
|
---|
124 |
|
---|
125 | //
|
---|
126 | // If all of the drivers returned errors, then invoke all of the library destructors
|
---|
127 | //
|
---|
128 | if (EFI_ERROR (Status)) {
|
---|
129 | ProcessLibraryDestructorList (ImageHandle, SystemTable);
|
---|
130 | }
|
---|
131 |
|
---|
132 | //
|
---|
133 | // Return the cummalative return status code from all of the driver entry points
|
---|
134 | //
|
---|
135 | return Status;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | Required by the EBC compiler and identical in functionality to _ModuleEntryPoint().
|
---|
140 |
|
---|
141 | This function is required to call _ModuleEntryPoint() passing in ImageHandle,
|
---|
142 | and SystemTable.
|
---|
143 |
|
---|
144 | @param ImageHandle The image handle of the DXE Driver, DXE Runtime Driver, DXE
|
---|
145 | SMM Driver, or UEFI Driver.
|
---|
146 | @param SystemTable A pointer to the EFI System Table.
|
---|
147 |
|
---|
148 | @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM
|
---|
149 | Driver, or UEFI Driver exited normally.
|
---|
150 | @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
|
---|
151 | SystemTable->Hdr.Revision.
|
---|
152 | @retval Other Return value from ProcessModuleEntryPointList().
|
---|
153 | **/
|
---|
154 | EFI_STATUS
|
---|
155 | EFIAPI
|
---|
156 | EfiMain (
|
---|
157 | IN EFI_HANDLE ImageHandle,
|
---|
158 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
159 | )
|
---|
160 | {
|
---|
161 | return _ModuleEntryPoint (ImageHandle, SystemTable);
|
---|
162 | }
|
---|