]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/PlatformDriverOverride/PlatformDriOverrideDxe/PlatformDriOverride.c
Code Clean for Driver PlatformDriOverrideDxe and PlatOverMngr application. And Clean...
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriverOverride / PlatformDriOverrideDxe / PlatformDriOverride.c
CommitLineData
a6f164a7 1/** @file\r
2\r
68dbca6c 3Copyright (c) 2007 - 2008, 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
20#include <Library/PlatDriOverLib.h>\r
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
107 @param DriverImageHandle On input, a pointer to the previous driver image handle returned\r
108 by GetDriverPath(). On output, a pointer to the next driver \r
109 device path.\r
cebc8d48
LG
110 \r
111 @retval EFI_UNSUPPORTED\r
a6f164a7 112**/\r
a6f164a7 113EFI_STATUS\r
114EFIAPI\r
115GetDriverPath (\r
68dbca6c 116 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r
a6f164a7 117 IN EFI_HANDLE ControllerHandle,\r
118 IN OUT EFI_DEVICE_PATH_PROTOCOL **DriverImagePath\r
119 )\r
120{\r
121 return EFI_UNSUPPORTED;\r
122}\r
123\r
124\r
125/**\r
68dbca6c
LG
126 Used to associate a driver image handle with a device path that was returned on a prior call to the\r
127 GetDriverPath() service. This driver image handle will then be available through the \r
128 GetDriver() service. This driver doesn't support this API.\r
129\r
130 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r
131 PROTOCOL instance. \r
132 @param ControllerHandle The device handle of the controller. \r
133 @param DriverImagePath A pointer to the driver device path that was returned in a prior\r
134 call to GetDriverPath(). \r
135 @param DriverImageHandle The driver image handle that was returned by LoadImage()\r
136 when the driver specified by DriverImagePath was loaded \r
137 into memory. \r
cebc8d48
LG
138 \r
139 @retval EFI_UNSUPPORTED\r
a6f164a7 140**/\r
a6f164a7 141EFI_STATUS\r
142EFIAPI\r
143DriverLoaded (\r
68dbca6c 144 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r
a6f164a7 145 IN EFI_HANDLE ControllerHandle,\r
68dbca6c 146 IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath,\r
a6f164a7 147 IN EFI_HANDLE DriverImageHandle\r
148 )\r
149{\r
150 return EFI_UNSUPPORTED;\r
151}\r
68dbca6c
LG
152\r
153EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL mPlatformDriverOverride = {\r
154 GetDriver,\r
155 GetDriverPath,\r
156 DriverLoaded\r
157};\r
158\r
159/**\r
160 Platform Driver Override driver entry point, install the Platform Driver Override Protocol\r
161\r
162 @param ImageHandle ImageHandle of the loaded driver.\r
163 @param SystemTable Pointer to the EFI System Table.\r
164\r
165 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM Driver,\r
166 or UEFI Driver exited normally.\r
167 @retval EFI_ALREADY_STARTED A protocol instance has been installed. Not need install again.\r
168**/\r
169EFI_STATUS\r
170EFIAPI\r
171PlatformDriverOverrideEntry (\r
172 IN EFI_HANDLE ImageHandle,\r
173 IN EFI_SYSTEM_TABLE *SystemTable\r
174 )\r
175{\r
176 EFI_HANDLE Handle;\r
177 EFI_STATUS Status;\r
178 VOID *Instance;\r
179\r
180 mCallerImageHandle = ImageHandle;\r
181\r
182 //\r
183 // According to UEFI spec, there can be at most a single instance\r
184 // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.\r
185 // So here we check the existence.\r
186 //\r
187 Status = gBS->LocateProtocol (\r
188 &gEfiPlatformDriverOverrideProtocolGuid,\r
189 NULL,\r
190 &Instance\r
191 );\r
192 //\r
193 // If there was no error, assume there is an installation and return error\r
194 //\r
195 if (!EFI_ERROR (Status)) {\r
196 return EFI_ALREADY_STARTED;\r
197 }\r
198\r
199 //\r
200 // Install platform driver override protocol\r
201 //\r
202 Handle = NULL;\r
203 Status = gBS->InstallProtocolInterface (\r
204 &Handle,\r
205 &gEfiPlatformDriverOverrideProtocolGuid,\r
206 EFI_NATIVE_INTERFACE,\r
207 &mPlatformDriverOverride\r
208 );\r
209 ASSERT_EFI_ERROR (Status);\r
210 return EFI_SUCCESS;\r
211}\r