]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/PlatformDriverOverride/PlatformDriOverrideDxe/PlatformDriOverride.c
Change library class PlatDriOverLib to PlatformDriOverrideLib
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriverOverride / PlatformDriOverrideDxe / PlatformDriOverride.c
CommitLineData
a6f164a7 1/** @file\r
2\r
e4b99ad9 3Copyright (c) 2007 - 2009, Intel Corporation\r
a6f164a7 4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
a6f164a7 12**/\r
13\r
68dbca6c 14#include <Uefi.h>\r
a6f164a7 15\r
68dbca6c
LG
16#include <Library/BaseLib.h>\r
17#include <Library/DebugLib.h>\r
18#include <Library/UefiDriverEntryPoint.h>\r
19#include <Library/UefiBootServicesTableLib.h>\r
e4b99ad9 20#include <Library/PlatformDriverOverrideLib.h>\r
68dbca6c 21#include <Protocol/PlatformDriverOverride.h>\r
a6f164a7 22\r
fe1e36e5 23LIST_ENTRY mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);\r
24BOOLEAN mEnvironmentVariableRead = FALSE;\r
68dbca6c 25EFI_HANDLE mCallerImageHandle = NULL;\r
a6f164a7 26\r
27/**\r
28 Retrieves the image handle of the platform override driver for a controller in the system.\r
29\r
30 @param This A pointer to the\r
31 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.\r
32 @param ControllerHandle The device handle of the controller to check if a\r
33 driver override exists.\r
34 @param DriverImageHandle On input, a pointer to the previous driver image\r
35 handle returned by GetDriver(). On output, a\r
36 pointer to the next driver image handle. Passing\r
37 in a NULL, will return the first driver image\r
38 handle for ControllerHandle.\r
39\r
40 @retval EFI_SUCCESS The driver override for ControllerHandle was\r
41 returned in DriverImageHandle.\r
42 @retval EFI_NOT_FOUND A driver override for ControllerHandle was not\r
43 found.\r
44 @retval EFI_INVALID_PARAMETER The handle specified by ControllerHandle is not a\r
45 valid handle. DriverImageHandle is not a handle\r
46 that was returned on a previous call to\r
47 GetDriver().\r
48\r
49**/\r
a6f164a7 50EFI_STATUS\r
51EFIAPI\r
52GetDriver (\r
68dbca6c 53 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r
a6f164a7 54 IN EFI_HANDLE ControllerHandle,\r
68dbca6c 55 IN OUT EFI_HANDLE *DriverImageHandle\r
a6f164a7 56 )\r
57{\r
58 EFI_STATUS Status;\r
68dbca6c 59\r
a6f164a7 60 //\r
61 // Check that ControllerHandle is a valid handle\r
62 //\r
63 if (ControllerHandle == NULL) {\r
64 return EFI_INVALID_PARAMETER;\r
65 }\r
66\r
67 //\r
68 // Read the environment variable(s) that contain the override mappings from Controller Device Path to\r
69 // a set of Driver Device Paths, and initialize in memory database of the overrides that map Controller\r
70 // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed\r
71 // once and finished in first call.\r
72 //\r
73 if (!mEnvironmentVariableRead) {\r
74 mEnvironmentVariableRead = TRUE;\r
75\r
76 Status = InitOverridesMapping (&mMappingDataBase);\r
68dbca6c
LG
77 if (EFI_ERROR (Status)){\r
78 DEBUG ((DEBUG_ERROR, "The status to Get Platform Driver Override Variable is %r\n", Status));\r
a6f164a7 79 InitializeListHead (&mMappingDataBase);\r
80 return EFI_NOT_FOUND;\r
81 }\r
82 }\r
68dbca6c 83\r
a6f164a7 84 //\r
68dbca6c 85 // if the environment variable does not exist, just return not found\r
a6f164a7 86 //\r
87 if (IsListEmpty (&mMappingDataBase)) {\r
88 return EFI_NOT_FOUND;\r
89 }\r
90\r
91 return GetDriverFromMapping (\r
a6f164a7 92 ControllerHandle,\r
93 DriverImageHandle,\r
94 &mMappingDataBase,\r
95 mCallerImageHandle\r
96 );\r
a6f164a7 97}\r
98\r
a6f164a7 99/**\r
68dbca6c
LG
100 Retrieves the device path of the platform override driver for a controller in the system.\r
101 This driver doesn't support this API.\r
102\r
103 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r
104 PROTOCOL instance. \r
105 @param ControllerHandle The device handle of the controller to check if a driver override\r
106 exists. \r
276a49b6
LG
107 @param DriverImagePath On input, a pointer to the previous driver device path returned by\r
108 GetDriverPath(). On output, a pointer to the next driver\r
109 device path. Passing in a pointer to NULL, will return the first\r
110 driver device path for ControllerHandle.\r
cebc8d48
LG
111 \r
112 @retval EFI_UNSUPPORTED\r
a6f164a7 113**/\r
a6f164a7 114EFI_STATUS\r
115EFIAPI\r
116GetDriverPath (\r
68dbca6c 117 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r
a6f164a7 118 IN EFI_HANDLE ControllerHandle,\r
119 IN OUT EFI_DEVICE_PATH_PROTOCOL **DriverImagePath\r
120 )\r
121{\r
122 return EFI_UNSUPPORTED;\r
123}\r
124\r
125\r
126/**\r
68dbca6c
LG
127 Used to associate a driver image handle with a device path that was returned on a prior call to the\r
128 GetDriverPath() service. This driver image handle will then be available through the \r
129 GetDriver() service. This driver doesn't support this API.\r
130\r
131 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r
132 PROTOCOL instance. \r
133 @param ControllerHandle The device handle of the controller. \r
134 @param DriverImagePath A pointer to the driver device path that was returned in a prior\r
135 call to GetDriverPath(). \r
136 @param DriverImageHandle The driver image handle that was returned by LoadImage()\r
137 when the driver specified by DriverImagePath was loaded \r
138 into memory. \r
cebc8d48
LG
139 \r
140 @retval EFI_UNSUPPORTED\r
a6f164a7 141**/\r
a6f164a7 142EFI_STATUS\r
143EFIAPI\r
144DriverLoaded (\r
68dbca6c 145 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r
a6f164a7 146 IN EFI_HANDLE ControllerHandle,\r
68dbca6c 147 IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath,\r
a6f164a7 148 IN EFI_HANDLE DriverImageHandle\r
149 )\r
150{\r
151 return EFI_UNSUPPORTED;\r
152}\r
68dbca6c
LG
153\r
154EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL mPlatformDriverOverride = {\r
155 GetDriver,\r
156 GetDriverPath,\r
157 DriverLoaded\r
158};\r
159\r
160/**\r
161 Platform Driver Override driver entry point, install the Platform Driver Override Protocol\r
162\r
163 @param ImageHandle ImageHandle of the loaded driver.\r
164 @param SystemTable Pointer to the EFI System Table.\r
165\r
166 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM Driver,\r
167 or UEFI Driver exited normally.\r
168 @retval EFI_ALREADY_STARTED A protocol instance has been installed. Not need install again.\r
169**/\r
170EFI_STATUS\r
171EFIAPI\r
172PlatformDriverOverrideEntry (\r
173 IN EFI_HANDLE ImageHandle,\r
174 IN EFI_SYSTEM_TABLE *SystemTable\r
175 )\r
176{\r
177 EFI_HANDLE Handle;\r
178 EFI_STATUS Status;\r
179 VOID *Instance;\r
180\r
181 mCallerImageHandle = ImageHandle;\r
182\r
183 //\r
184 // According to UEFI spec, there can be at most a single instance\r
185 // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.\r
186 // So here we check the existence.\r
187 //\r
188 Status = gBS->LocateProtocol (\r
189 &gEfiPlatformDriverOverrideProtocolGuid,\r
190 NULL,\r
191 &Instance\r
192 );\r
193 //\r
194 // If there was no error, assume there is an installation and return error\r
195 //\r
196 if (!EFI_ERROR (Status)) {\r
197 return EFI_ALREADY_STARTED;\r
198 }\r
199\r
200 //\r
201 // Install platform driver override protocol\r
202 //\r
203 Handle = NULL;\r
204 Status = gBS->InstallProtocolInterface (\r
205 &Handle,\r
206 &gEfiPlatformDriverOverrideProtocolGuid,\r
207 EFI_NATIVE_INTERFACE,\r
208 &mPlatformDriverOverride\r
209 );\r
210 ASSERT_EFI_ERROR (Status);\r
211 return EFI_SUCCESS;\r
212}\r