]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/PlatformDriverOverride/PlatformDriOverrideDxe/PlatformDriOverride.c
Change library class PlatDriOverLib to PlatformDriOverrideLib
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriverOverride / PlatformDriOverrideDxe / PlatformDriOverride.c
1 /** @file
2
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
8
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.
11
12 **/
13
14 #include <Uefi.h>
15
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>
22
23 LIST_ENTRY mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);
24 BOOLEAN mEnvironmentVariableRead = FALSE;
25 EFI_HANDLE mCallerImageHandle = NULL;
26
27 /**
28 Retrieves the image handle of the platform override driver for a controller in the system.
29
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.
39
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
43 found.
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
47 GetDriver().
48
49 **/
50 EFI_STATUS
51 EFIAPI
52 GetDriver (
53 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,
54 IN EFI_HANDLE ControllerHandle,
55 IN OUT EFI_HANDLE *DriverImageHandle
56 )
57 {
58 EFI_STATUS Status;
59
60 //
61 // Check that ControllerHandle is a valid handle
62 //
63 if (ControllerHandle == NULL) {
64 return EFI_INVALID_PARAMETER;
65 }
66
67 //
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.
72 //
73 if (!mEnvironmentVariableRead) {
74 mEnvironmentVariableRead = TRUE;
75
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);
80 return EFI_NOT_FOUND;
81 }
82 }
83
84 //
85 // if the environment variable does not exist, just return not found
86 //
87 if (IsListEmpty (&mMappingDataBase)) {
88 return EFI_NOT_FOUND;
89 }
90
91 return GetDriverFromMapping (
92 ControllerHandle,
93 DriverImageHandle,
94 &mMappingDataBase,
95 mCallerImageHandle
96 );
97 }
98
99 /**
100 Retrieves the device path of the platform override driver for a controller in the system.
101 This driver doesn't support this API.
102
103 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
104 PROTOCOL instance.
105 @param ControllerHandle The device handle of the controller to check if a driver override
106 exists.
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.
111
112 @retval EFI_UNSUPPORTED
113 **/
114 EFI_STATUS
115 EFIAPI
116 GetDriverPath (
117 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,
118 IN EFI_HANDLE ControllerHandle,
119 IN OUT EFI_DEVICE_PATH_PROTOCOL **DriverImagePath
120 )
121 {
122 return EFI_UNSUPPORTED;
123 }
124
125
126 /**
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.
130
131 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
132 PROTOCOL instance.
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
138 into memory.
139
140 @retval EFI_UNSUPPORTED
141 **/
142 EFI_STATUS
143 EFIAPI
144 DriverLoaded (
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
149 )
150 {
151 return EFI_UNSUPPORTED;
152 }
153
154 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL mPlatformDriverOverride = {
155 GetDriver,
156 GetDriverPath,
157 DriverLoaded
158 };
159
160 /**
161 Platform Driver Override driver entry point, install the Platform Driver Override Protocol
162
163 @param ImageHandle ImageHandle of the loaded driver.
164 @param SystemTable Pointer to the EFI System Table.
165
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.
169 **/
170 EFI_STATUS
171 EFIAPI
172 PlatformDriverOverrideEntry (
173 IN EFI_HANDLE ImageHandle,
174 IN EFI_SYSTEM_TABLE *SystemTable
175 )
176 {
177 EFI_HANDLE Handle;
178 EFI_STATUS Status;
179 VOID *Instance;
180
181 mCallerImageHandle = ImageHandle;
182
183 //
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.
187 //
188 Status = gBS->LocateProtocol (
189 &gEfiPlatformDriverOverrideProtocolGuid,
190 NULL,
191 &Instance
192 );
193 //
194 // If there was no error, assume there is an installation and return error
195 //
196 if (!EFI_ERROR (Status)) {
197 return EFI_ALREADY_STARTED;
198 }
199
200 //
201 // Install platform driver override protocol
202 //
203 Handle = NULL;
204 Status = gBS->InstallProtocolInterface (
205 &Handle,
206 &gEfiPlatformDriverOverrideProtocolGuid,
207 EFI_NATIVE_INTERFACE,
208 &mPlatformDriverOverride
209 );
210 ASSERT_EFI_ERROR (Status);
211 return EFI_SUCCESS;
212 }