3 Copyright (c) 2007 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/UefiDriverEntryPoint.h>
19 #include <Library/UefiBootServicesTableLib.h>
20 #include <Library/PlatDriOverLib.h>
21 #include <Protocol/PlatformDriverOverride.h>
23 LIST_ENTRY mMappingDataBase
= INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase
);
24 BOOLEAN mEnvironmentVariableRead
= FALSE
;
25 EFI_HANDLE mCallerImageHandle
= NULL
;
28 Retrieves the image handle of the platform override driver for a controller in the system.
30 @param This A pointer to the
31 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.
32 @param ControllerHandle The device handle of the controller to check if a
33 driver override exists.
34 @param DriverImageHandle On input, a pointer to the previous driver image
35 handle returned by GetDriver(). On output, a
36 pointer to the next driver image handle. Passing
37 in a NULL, will return the first driver image
38 handle for ControllerHandle.
40 @retval EFI_SUCCESS The driver override for ControllerHandle was
41 returned in DriverImageHandle.
42 @retval EFI_NOT_FOUND A driver override for ControllerHandle was not
44 @retval EFI_INVALID_PARAMETER The handle specified by ControllerHandle is not a
45 valid handle. DriverImageHandle is not a handle
46 that was returned on a previous call to
53 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
54 IN EFI_HANDLE ControllerHandle
,
55 IN OUT EFI_HANDLE
*DriverImageHandle
61 // Check that ControllerHandle is a valid handle
63 if (ControllerHandle
== NULL
) {
64 return EFI_INVALID_PARAMETER
;
68 // Read the environment variable(s) that contain the override mappings from Controller Device Path to
69 // a set of Driver Device Paths, and initialize in memory database of the overrides that map Controller
70 // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed
71 // once and finished in first call.
73 if (!mEnvironmentVariableRead
) {
74 mEnvironmentVariableRead
= TRUE
;
76 Status
= InitOverridesMapping (&mMappingDataBase
);
77 if (EFI_ERROR (Status
)){
78 DEBUG ((DEBUG_ERROR
, "The status to Get Platform Driver Override Variable is %r\n", Status
));
79 InitializeListHead (&mMappingDataBase
);
85 // if the environment variable does not exist, just return not found
87 if (IsListEmpty (&mMappingDataBase
)) {
91 return GetDriverFromMapping (
100 Retrieves the device path of the platform override driver for a controller in the system.
101 This driver doesn't support this API.
103 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
105 @param ControllerHandle The device handle of the controller to check if a driver override
107 @param DriverImageHandle On input, a pointer to the previous driver image handle returned
108 by GetDriverPath(). On output, a pointer to the next driver
111 @retval EFI_UNSUPPORTED
116 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
117 IN EFI_HANDLE ControllerHandle
,
118 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DriverImagePath
121 return EFI_UNSUPPORTED
;
126 Used to associate a driver image handle with a device path that was returned on a prior call to the
127 GetDriverPath() service. This driver image handle will then be available through the
128 GetDriver() service. This driver doesn't support this API.
130 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
132 @param ControllerHandle The device handle of the controller.
133 @param DriverImagePath A pointer to the driver device path that was returned in a prior
134 call to GetDriverPath().
135 @param DriverImageHandle The driver image handle that was returned by LoadImage()
136 when the driver specified by DriverImagePath was loaded
139 @retval EFI_UNSUPPORTED
144 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
145 IN EFI_HANDLE ControllerHandle
,
146 IN EFI_DEVICE_PATH_PROTOCOL
*DriverImagePath
,
147 IN EFI_HANDLE DriverImageHandle
150 return EFI_UNSUPPORTED
;
153 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL mPlatformDriverOverride
= {
160 Platform Driver Override driver entry point, install the Platform Driver Override Protocol
162 @param ImageHandle ImageHandle of the loaded driver.
163 @param SystemTable Pointer to the EFI System Table.
165 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM Driver,
166 or UEFI Driver exited normally.
167 @retval EFI_ALREADY_STARTED A protocol instance has been installed. Not need install again.
171 PlatformDriverOverrideEntry (
172 IN EFI_HANDLE ImageHandle
,
173 IN EFI_SYSTEM_TABLE
*SystemTable
180 mCallerImageHandle
= ImageHandle
;
183 // According to UEFI spec, there can be at most a single instance
184 // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.
185 // So here we check the existence.
187 Status
= gBS
->LocateProtocol (
188 &gEfiPlatformDriverOverrideProtocolGuid
,
193 // If there was no error, assume there is an installation and return error
195 if (!EFI_ERROR (Status
)) {
196 return EFI_ALREADY_STARTED
;
200 // Install platform driver override protocol
203 Status
= gBS
->InstallProtocolInterface (
205 &gEfiPlatformDriverOverrideProtocolGuid
,
206 EFI_NATIVE_INTERFACE
,
207 &mPlatformDriverOverride
209 ASSERT_EFI_ERROR (Status
);