3 Copyright (c) 2007 - 2009, 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/PlatformDriverOverrideLib.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 DriverImagePath On input, a pointer to the previous driver device path returned by
108 GetDriverPath(). On output, a pointer to the next driver
109 device path. Passing in a pointer to NULL, will return the first
110 driver device path for ControllerHandle.
112 @retval EFI_UNSUPPORTED
117 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
118 IN EFI_HANDLE ControllerHandle
,
119 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DriverImagePath
122 return EFI_UNSUPPORTED
;
127 Used to associate a driver image handle with a device path that was returned on a prior call to the
128 GetDriverPath() service. This driver image handle will then be available through the
129 GetDriver() service. This driver doesn't support this API.
131 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
133 @param ControllerHandle The device handle of the controller.
134 @param DriverImagePath A pointer to the driver device path that was returned in a prior
135 call to GetDriverPath().
136 @param DriverImageHandle The driver image handle that was returned by LoadImage()
137 when the driver specified by DriverImagePath was loaded
140 @retval EFI_UNSUPPORTED
145 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*This
,
146 IN EFI_HANDLE ControllerHandle
,
147 IN EFI_DEVICE_PATH_PROTOCOL
*DriverImagePath
,
148 IN EFI_HANDLE DriverImageHandle
151 return EFI_UNSUPPORTED
;
154 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL mPlatformDriverOverride
= {
161 Platform Driver Override driver entry point, install the Platform Driver Override Protocol
163 @param ImageHandle ImageHandle of the loaded driver.
164 @param SystemTable Pointer to the EFI System Table.
166 @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM Driver,
167 or UEFI Driver exited normally.
168 @retval EFI_ALREADY_STARTED A protocol instance has been installed. Not need install again.
172 PlatformDriverOverrideEntry (
173 IN EFI_HANDLE ImageHandle
,
174 IN EFI_SYSTEM_TABLE
*SystemTable
181 mCallerImageHandle
= ImageHandle
;
184 // According to UEFI spec, there can be at most a single instance
185 // in the system of the EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL.
186 // So here we check the existence.
188 Status
= gBS
->LocateProtocol (
189 &gEfiPlatformDriverOverrideProtocolGuid
,
194 // If there was no error, assume there is an installation and return error
196 if (!EFI_ERROR (Status
)) {
197 return EFI_ALREADY_STARTED
;
201 // Install platform driver override protocol
204 Status
= gBS
->InstallProtocolInterface (
206 &gEfiPlatformDriverOverrideProtocolGuid
,
207 EFI_NATIVE_INTERFACE
,
208 &mPlatformDriverOverride
210 ASSERT_EFI_ERROR (Status
);