]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/PlatformDriverOverride/PlatformDriOverrideDxe/PlatformDriOverride.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriverOverride / PlatformDriOverrideDxe / PlatformDriOverride.c
1 /** @file
2
3 Copyright (c) 2007, 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 Module Name:
13
14 PlatformDriOverride.c
15
16 Abstract:
17
18
19 **/
20
21
22 #include "PlatformDriOverride.h"
23
24 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL gPlatformDriverOverride = {
25 GetDriver,
26 GetDriverPath,
27 DriverLoaded
28 };
29
30 LIST_ENTRY mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);
31 BOOLEAN mEnvironmentVariableRead = FALSE;
32 EFI_HANDLE mCallerImageHandle;
33
34
35 EFI_STATUS
36 EFIAPI
37 PlatformDriverOverrideEntry (
38 IN EFI_HANDLE ImageHandle,
39 IN EFI_SYSTEM_TABLE *SystemTable
40 )
41 /*++
42
43 Routine Description:
44 Platform Driver Override driver entry point, install the Platform Driver Override Protocol
45
46 Arguments:
47 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
48
49 Returns:
50 EFI_STATUS
51
52 --*/
53 {
54 mEnvironmentVariableRead = FALSE;
55 mCallerImageHandle = ImageHandle;
56 InitializeListHead (&mMappingDataBase);
57 return InstallPlatformDriverOverrideProtocol (&gPlatformDriverOverride);
58 }
59
60
61 /**
62 Retrieves the image handle of the platform override driver for a controller in the system.
63
64 @param This A pointer to the
65 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.
66 @param ControllerHandle The device handle of the controller to check if a
67 driver override exists.
68 @param DriverImageHandle On input, a pointer to the previous driver image
69 handle returned by GetDriver(). On output, a
70 pointer to the next driver image handle. Passing
71 in a NULL, will return the first driver image
72 handle for ControllerHandle.
73
74 @retval EFI_SUCCESS The driver override for ControllerHandle was
75 returned in DriverImageHandle.
76 @retval EFI_NOT_FOUND A driver override for ControllerHandle was not
77 found.
78 @retval EFI_INVALID_PARAMETER The handle specified by ControllerHandle is not a
79 valid handle. DriverImageHandle is not a handle
80 that was returned on a previous call to
81 GetDriver().
82
83 **/
84 EFI_STATUS
85 EFIAPI
86 GetDriver (
87 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL * This,
88 IN EFI_HANDLE ControllerHandle,
89 IN OUT EFI_HANDLE * DriverImageHandle
90 )
91 {
92 EFI_STATUS Status;
93 //
94 // Check that ControllerHandle is a valid handle
95 //
96 if (ControllerHandle == NULL) {
97 return EFI_INVALID_PARAMETER;
98 }
99
100 //
101 // Read the environment variable(s) that contain the override mappings from Controller Device Path to
102 // a set of Driver Device Paths, and initialize in memory database of the overrides that map Controller
103 // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed
104 // once and finished in first call.
105 //
106 if (!mEnvironmentVariableRead) {
107 mEnvironmentVariableRead = TRUE;
108
109 Status = InitOverridesMapping (&mMappingDataBase);
110 if (Status == EFI_NOT_FOUND) {
111 InitializeListHead (&mMappingDataBase);
112 return EFI_NOT_FOUND;
113 } else if (Status == EFI_VOLUME_CORRUPTED){
114 DEBUG ((DEBUG_ERROR, "Platform Driver Override Variable is corrupt\n"));
115 //
116 // The environment variable(s) that contain the override mappings from Controller Device Path to
117 // a set of Driver Device Paths is corrupted, platform code can use LibDeleteOverridesVariables to
118 // delete all orverride variables as a policy. Here can be IBV/OEM customized.
119 //
120
121 //LibDeleteOverridesVariables();
122 InitializeListHead (&mMappingDataBase);
123 return EFI_NOT_FOUND;
124 } else if (EFI_ERROR (Status)){
125 InitializeListHead (&mMappingDataBase);
126 return EFI_NOT_FOUND;
127 }
128 }
129 //
130 // if the environment variable does not exist or the variable appears to be corrupt, just return not found
131 //
132 if (IsListEmpty (&mMappingDataBase)) {
133 return EFI_NOT_FOUND;
134 }
135
136 return GetDriverFromMapping (
137 This,
138 ControllerHandle,
139 DriverImageHandle,
140 &mMappingDataBase,
141 mCallerImageHandle
142 );
143
144 }
145
146
147 /**
148 For the use of the ControllerHandle parameter in the GetDriverPath() and DriverLoaded() APIs
149 makes those APIs very difficult to use, so not support.
150
151
152
153 **/
154 EFI_STATUS
155 EFIAPI
156 GetDriverPath (
157 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL * This,
158 IN EFI_HANDLE ControllerHandle,
159 IN OUT EFI_DEVICE_PATH_PROTOCOL **DriverImagePath
160 )
161 {
162 return EFI_UNSUPPORTED;
163 }
164
165
166 /**
167 For the use of the ControllerHandle parameter in the GetDriverPath() and DriverLoaded() APIs
168 makes those APIs very difficult to use, so not support.
169
170
171
172 **/
173 EFI_STATUS
174 EFIAPI
175 DriverLoaded (
176 IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL * This,
177 IN EFI_HANDLE ControllerHandle,
178 IN EFI_DEVICE_PATH_PROTOCOL * DriverImagePath,
179 IN EFI_HANDLE DriverImageHandle
180 )
181 {
182 return EFI_UNSUPPORTED;
183 }