1 | /** @file
|
---|
2 | Entry point to a EFI/DXE driver. This version is specific to QEMU, and ties
|
---|
3 | dispatch of the driver in question on the value of a QEMU fw_cfg boolean
|
---|
4 | variable which is referenced by name via a fixed pointer PCD.
|
---|
5 |
|
---|
6 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
7 | Copyright (c) 2022, Google LLC. All rights reserved.<BR>
|
---|
8 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
9 |
|
---|
10 | **/
|
---|
11 |
|
---|
12 | #include <Uefi.h>
|
---|
13 |
|
---|
14 | #include <Protocol/LoadedImage.h>
|
---|
15 |
|
---|
16 | #include <Library/BaseLib.h>
|
---|
17 | #include <Library/DebugLib.h>
|
---|
18 | #include <Library/QemuFwCfgSimpleParserLib.h>
|
---|
19 | #include <Library/UefiBootServicesTableLib.h>
|
---|
20 | #include <Library/UefiDriverEntryPoint.h>
|
---|
21 |
|
---|
22 | /**
|
---|
23 | Unloads an image from memory.
|
---|
24 |
|
---|
25 | This function is a callback that a driver registers to do cleanup
|
---|
26 | when the UnloadImage boot service function is called.
|
---|
27 |
|
---|
28 | @param ImageHandle The handle to the image to unload.
|
---|
29 |
|
---|
30 | @return Status returned by all unload().
|
---|
31 |
|
---|
32 | **/
|
---|
33 | STATIC
|
---|
34 | EFI_STATUS
|
---|
35 | EFIAPI
|
---|
36 | _DriverUnloadHandler (
|
---|
37 | EFI_HANDLE ImageHandle
|
---|
38 | )
|
---|
39 | {
|
---|
40 | EFI_STATUS Status;
|
---|
41 |
|
---|
42 | //
|
---|
43 | // If an UnloadImage() handler is specified, then call it
|
---|
44 | //
|
---|
45 | Status = ProcessModuleUnloadList (ImageHandle);
|
---|
46 |
|
---|
47 | //
|
---|
48 | // If the driver specific unload handler does not return an error, then call
|
---|
49 | // all of the library destructors. If the unload handler returned an error,
|
---|
50 | // then the driver can not be unloaded, and the library destructors should
|
---|
51 | // not be called
|
---|
52 | //
|
---|
53 | if (!EFI_ERROR (Status)) {
|
---|
54 | ProcessLibraryDestructorList (ImageHandle, gST);
|
---|
55 | }
|
---|
56 |
|
---|
57 | //
|
---|
58 | // Return the status from the driver specific unload handler
|
---|
59 | //
|
---|
60 | return Status;
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, or
|
---|
65 | UEFI Driver.
|
---|
66 |
|
---|
67 | @param ImageHandle The image handle of the DXE Driver, DXE
|
---|
68 | Runtime Driver, or UEFI Driver.
|
---|
69 | @param SystemTable A pointer to the EFI System Table.
|
---|
70 |
|
---|
71 | @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, or
|
---|
72 | UEFI Driver exited normally.
|
---|
73 | @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
|
---|
74 | SystemTable->Hdr.Revision.
|
---|
75 | @retval Other Return value from
|
---|
76 | ProcessModuleEntryPointList().
|
---|
77 |
|
---|
78 | **/
|
---|
79 | EFI_STATUS
|
---|
80 | EFIAPI
|
---|
81 | _ModuleEntryPoint (
|
---|
82 | IN EFI_HANDLE ImageHandle,
|
---|
83 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
84 | )
|
---|
85 | {
|
---|
86 | EFI_STATUS Status;
|
---|
87 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
|
---|
88 | RETURN_STATUS RetStatus;
|
---|
89 | BOOLEAN Enabled;
|
---|
90 |
|
---|
91 | if (_gUefiDriverRevision != 0) {
|
---|
92 | //
|
---|
93 | // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI
|
---|
94 | // 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 | RetStatus = QemuFwCfgParseBool (
|
---|
120 | FixedPcdGetPtr (PcdEntryPointOverrideFwCfgVarName),
|
---|
121 | &Enabled
|
---|
122 | );
|
---|
123 | if (!RETURN_ERROR (RetStatus) && !Enabled) {
|
---|
124 | //
|
---|
125 | // The QEMU fw_cfg variable tells us not to load this image. So abort.
|
---|
126 | //
|
---|
127 | Status = EFI_ABORTED;
|
---|
128 | } else {
|
---|
129 | //
|
---|
130 | // Call the driver entry point
|
---|
131 | //
|
---|
132 | Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);
|
---|
133 | }
|
---|
134 |
|
---|
135 | //
|
---|
136 | // If all of the drivers returned errors, or we if are aborting, then invoke
|
---|
137 | // all of the library destructors
|
---|
138 | //
|
---|
139 | if (EFI_ERROR (Status)) {
|
---|
140 | ProcessLibraryDestructorList (ImageHandle, SystemTable);
|
---|
141 | }
|
---|
142 |
|
---|
143 | //
|
---|
144 | // Return the cumulative return status code from all of the driver entry
|
---|
145 | // points
|
---|
146 | //
|
---|
147 | return Status;
|
---|
148 | }
|
---|