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