]> git.proxmox.com Git - mirror_edk2.git/blob - 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
1 /** @file
2
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
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/PlatDriOverLib.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 DriverImageHandle On input, a pointer to the previous driver image handle returned
108 by GetDriverPath(). On output, a pointer to the next driver
109 device path.
110
111 @retval EFI_UNSUPPORTED
112 **/
113 EFI_STATUS
114 EFIAPI
115 GetDriverPath (
116 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL *This,
117 IN EFI_HANDLE ControllerHandle,
118 IN OUT EFI_DEVICE_PATH_PROTOCOL **DriverImagePath
119 )
120 {
121 return EFI_UNSUPPORTED;
122 }
123
124
125 /**
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.
129
130 @param This A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_
131 PROTOCOL instance.
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
137 into memory.
138
139 @retval EFI_UNSUPPORTED
140 **/
141 EFI_STATUS
142 EFIAPI
143 DriverLoaded (
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
148 )
149 {
150 return EFI_UNSUPPORTED;
151 }
152
153 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL mPlatformDriverOverride = {
154 GetDriver,
155 GetDriverPath,
156 DriverLoaded
157 };
158
159 /**
160 Platform Driver Override driver entry point, install the Platform Driver Override Protocol
161
162 @param ImageHandle ImageHandle of the loaded driver.
163 @param SystemTable Pointer to the EFI System Table.
164
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.
168 **/
169 EFI_STATUS
170 EFIAPI
171 PlatformDriverOverrideEntry (
172 IN EFI_HANDLE ImageHandle,
173 IN EFI_SYSTEM_TABLE *SystemTable
174 )
175 {
176 EFI_HANDLE Handle;
177 EFI_STATUS Status;
178 VOID *Instance;
179
180 mCallerImageHandle = ImageHandle;
181
182 //
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.
186 //
187 Status = gBS->LocateProtocol (
188 &gEfiPlatformDriverOverrideProtocolGuid,
189 NULL,
190 &Instance
191 );
192 //
193 // If there was no error, assume there is an installation and return error
194 //
195 if (!EFI_ERROR (Status)) {
196 return EFI_ALREADY_STARTED;
197 }
198
199 //
200 // Install platform driver override protocol
201 //
202 Handle = NULL;
203 Status = gBS->InstallProtocolInterface (
204 &Handle,
205 &gEfiPlatformDriverOverrideProtocolGuid,
206 EFI_NATIVE_INTERFACE,
207 &mPlatformDriverOverride
208 );
209 ASSERT_EFI_ERROR (Status);
210 return EFI_SUCCESS;
211 }