]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatformDriOverride.c
Change directory name PlatformDriOverride to PlatformDriOverrideDxe.
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriOverrideDxe / PlatformDriOverride.c
... / ...
CommitLineData
1/** @file\r
2\r
3Copyright (c) 2007 - 2009, Intel Corporation\r
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
12**/\r
13\r
14#include <Uefi.h>\r
15\r
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/PlatformDriverOverrideLib.h>\r
21#include <Protocol/PlatformDriverOverride.h>\r
22\r
23LIST_ENTRY mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);\r
24BOOLEAN mEnvironmentVariableRead = FALSE;\r
25EFI_HANDLE mCallerImageHandle = NULL;\r
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
50EFI_STATUS\r
51EFIAPI\r
52GetDriver (\r
53 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r
54 IN EFI_HANDLE ControllerHandle,\r
55 IN OUT EFI_HANDLE *DriverImageHandle\r
56 )\r
57{\r
58 EFI_STATUS Status;\r
59\r
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
77 if (EFI_ERROR (Status)){\r
78 DEBUG ((DEBUG_ERROR, "The status to Get Platform Driver Override Variable is %r\n", Status));\r
79 InitializeListHead (&mMappingDataBase);\r
80 return EFI_NOT_FOUND;\r
81 }\r
82 }\r
83\r
84 //\r
85 // if the environment variable does not exist, just return not found\r
86 //\r
87 if (IsListEmpty (&mMappingDataBase)) {\r
88 return EFI_NOT_FOUND;\r
89 }\r
90\r
91 return GetDriverFromMapping (\r
92 ControllerHandle,\r
93 DriverImageHandle,\r
94 &mMappingDataBase,\r
95 mCallerImageHandle\r
96 );\r
97}\r
98\r
99/**\r
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 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
111 \r
112 @retval EFI_UNSUPPORTED\r
113**/\r
114EFI_STATUS\r
115EFIAPI\r
116GetDriverPath (\r
117 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r
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
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
139 \r
140 @retval EFI_UNSUPPORTED\r
141**/\r
142EFI_STATUS\r
143EFIAPI\r
144DriverLoaded (\r
145 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,\r
146 IN EFI_HANDLE ControllerHandle,\r
147 IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath,\r
148 IN EFI_HANDLE DriverImageHandle\r
149 )\r
150{\r
151 return EFI_UNSUPPORTED;\r
152}\r
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