]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/EmuBlockIoDxe/DriverConfiguration.c
03f94b0288ba560597c9c9e2052b4d5e04c20fdc
[mirror_edk2.git] / EmulatorPkg / EmuBlockIoDxe / DriverConfiguration.c
1 /**@file
2
3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 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 DriverConfiguration.c
15
16 Abstract:
17
18 **/
19
20 #include "EmuBlockIo.h"
21
22 //
23 // EFI Driver Configuration Functions
24 //
25 EFI_STATUS
26 EFIAPI
27 EmuBlockIoDriverConfigurationSetOptions (
28 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
29 IN EFI_HANDLE ControllerHandle,
30 IN EFI_HANDLE ChildHandle OPTIONAL,
31 IN CHAR8 *Language,
32 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
33 );
34
35 EFI_STATUS
36 EFIAPI
37 EmuBlockIoDriverConfigurationOptionsValid (
38 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
39 IN EFI_HANDLE ControllerHandle,
40 IN EFI_HANDLE ChildHandle OPTIONAL
41 );
42
43 EFI_STATUS
44 EFIAPI
45 EmuBlockIoDriverConfigurationForceDefaults (
46 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
47 IN EFI_HANDLE ControllerHandle,
48 IN EFI_HANDLE ChildHandle OPTIONAL,
49 IN UINT32 DefaultType,
50 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
51 );
52
53 //
54 // EFI Driver Configuration Protocol
55 //
56 EFI_DRIVER_CONFIGURATION_PROTOCOL gEmuBlockIoDriverConfiguration = {
57 EmuBlockIoDriverConfigurationSetOptions,
58 EmuBlockIoDriverConfigurationOptionsValid,
59 EmuBlockIoDriverConfigurationForceDefaults,
60 "eng"
61 };
62
63 /*++
64
65 Routine Description:
66 Allows the user to set controller specific options for a controller that a
67 driver is currently managing.
68
69 Arguments:
70 This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
71 ControllerHandle - The handle of the controller to set options on.
72 ChildHandle - The handle of the child controller to set options on. This
73 is an optional parameter that may be NULL. It will be NULL
74 for device drivers, and for a bus drivers that wish to set
75 options for the bus controller. It will not be NULL for a
76 bus driver that wishes to set options for one of its child
77 controllers.
78 Language - A pointer to a three character ISO 639-2 language identifier.
79 This is the language of the user interface that should be
80 presented to the user, and it must match one of the languages
81 specified in SupportedLanguages. The number of languages
82 supported by a driver is up to the driver writer.
83 ActionRequired - A pointer to the action that the calling agent is required
84 to perform when this function returns. See "Related
85 Definitions" for a list of the actions that the calling
86 agent is required to perform prior to accessing
87 ControllerHandle again.
88
89 Returns:
90 EFI_SUCCESS - The driver specified by This successfully set the
91 configuration options for the controller specified
92 by ControllerHandle..
93 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
94 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
95 EFI_INVALID_PARAMETER - ActionRequired is NULL.
96 EFI_UNSUPPORTED - The driver specified by This does not support setting
97 configuration options for the controller specified by
98 ControllerHandle and ChildHandle.
99 EFI_UNSUPPORTED - The driver specified by This does not support the
100 language specified by Language.
101 EFI_DEVICE_ERROR - A device error occurred while attempt to set the
102 configuration options for the controller specified
103 by ControllerHandle and ChildHandle.
104 EFI_OUT_RESOURCES - There are not enough resources available to set the
105 configuration options for the controller specified
106 by ControllerHandle and ChildHandle.
107
108 --*/
109 EFI_STATUS
110 EFIAPI
111 EmuBlockIoDriverConfigurationSetOptions (
112 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
113 IN EFI_HANDLE ControllerHandle,
114 IN EFI_HANDLE ChildHandle OPTIONAL,
115 IN CHAR8 *Language,
116 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
117 )
118 {
119 EFI_STATUS Status;
120 EFI_BLOCK_IO_PROTOCOL *BlockIo;
121 CHAR8 *SupportedLanguage;
122
123 SupportedLanguage = This->SupportedLanguages;
124
125 Status = EFI_UNSUPPORTED;
126 while (*SupportedLanguage != 0) {
127 if (AsciiStrnCmp (Language, SupportedLanguage, 3) == 0) {
128 Status = EFI_SUCCESS;
129 }
130
131 SupportedLanguage += 3;
132 }
133
134 if (EFI_ERROR (Status)) {
135 return Status;
136 }
137
138 if (ActionRequired == NULL || ControllerHandle == NULL) {
139 return EFI_INVALID_PARAMETER;
140 }
141
142 if (ChildHandle != NULL) {
143 return EFI_UNSUPPORTED;
144 }
145
146 //
147 // Validate controller handle
148 //
149 Status = gBS->OpenProtocol (
150 ControllerHandle,
151 &gEmuIoThunkProtocolGuid,
152 (VOID **)&BlockIo,
153 gEmuBlockIoDriverBinding.DriverBindingHandle,
154 ControllerHandle,
155 EFI_OPEN_PROTOCOL_BY_DRIVER
156 );
157
158 if (!EFI_ERROR (Status)) {
159 gBS->CloseProtocol (
160 ControllerHandle,
161 &gEmuIoThunkProtocolGuid,
162 gEmuBlockIoDriverBinding.DriverBindingHandle,
163 ControllerHandle
164 );
165
166 return EFI_UNSUPPORTED;
167 }
168
169 if (Status == EFI_UNSUPPORTED) {
170 return Status;
171 } else if (Status != EFI_ALREADY_STARTED) {
172 return EFI_INVALID_PARAMETER;
173 }
174
175 *ActionRequired = EfiDriverConfigurationActionNone;
176 return EFI_SUCCESS;
177 }
178
179 /*++
180
181 Routine Description:
182 Tests to see if a controller's current configuration options are valid.
183
184 Arguments:
185 This - A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.
186 ControllerHandle - The handle of the controller to test if it's current
187 configuration options are valid.
188 ChildHandle - The handle of the child controller to test if it's current
189 configuration options are valid. This is an optional
190 parameter that may be NULL. It will be NULL for device
191 drivers. It will also be NULL for a bus drivers that wish
192 to test the configuration options for the bus controller.
193 It will not be NULL for a bus driver that wishes to test
194 configuration options for one of its child controllers.
195
196 Returns:
197 EFI_SUCCESS - The controller specified by ControllerHandle and
198 ChildHandle that is being managed by the driver
199 specified by This has a valid set of configuration
200 options.
201 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
202 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
203 EFI_UNSUPPORTED - The driver specified by This is not currently
204 managing the controller specified by ControllerHandle
205 and ChildHandle.
206 EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
207 ChildHandle that is being managed by the driver
208 specified by This has an invalid set of configuration
209 options.
210
211 --*/
212 EFI_STATUS
213 EFIAPI
214 EmuBlockIoDriverConfigurationOptionsValid (
215 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
216 IN EFI_HANDLE ControllerHandle,
217 IN EFI_HANDLE ChildHandle OPTIONAL
218 )
219 {
220 EFI_STATUS Status;
221 EFI_BLOCK_IO_PROTOCOL *BlockIo;
222
223 if (ChildHandle != NULL) {
224 return EFI_UNSUPPORTED;
225 }
226
227 if (ControllerHandle == NULL) {
228 return EFI_INVALID_PARAMETER;
229 }
230
231 //
232 // Validate controller handle
233 //
234 Status = gBS->OpenProtocol (
235 ControllerHandle,
236 &gEmuIoThunkProtocolGuid,
237 (VOID **)&BlockIo,
238 gEmuBlockIoDriverBinding.DriverBindingHandle,
239 ControllerHandle,
240 EFI_OPEN_PROTOCOL_BY_DRIVER
241 );
242
243 if (!EFI_ERROR (Status)) {
244 gBS->CloseProtocol (
245 ControllerHandle,
246 &gEmuIoThunkProtocolGuid,
247 gEmuBlockIoDriverBinding.DriverBindingHandle,
248 ControllerHandle
249 );
250
251 return EFI_UNSUPPORTED;
252 }
253
254 if (Status == EFI_UNSUPPORTED) {
255 return Status;
256 } else if (Status != EFI_ALREADY_STARTED) {
257 return EFI_INVALID_PARAMETER;
258 }
259
260 return EFI_SUCCESS;
261 }
262
263 /*++
264
265 Routine Description:
266 Forces a driver to set the default configuration options for a controller.
267
268 Arguments:
269 This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
270 ControllerHandle - The handle of the controller to force default configuration options on.
271 ChildHandle - The handle of the child controller to force default configuration options on This is an optional parameter that may be NULL. It will be NULL for device drivers. It will also be NULL for a bus drivers that wish to force default configuration options for the bus controller. It will not be NULL for a bus driver that wishes to force default configuration options for one of its child controllers.
272 DefaultType - The type of default configuration options to force on the controller specified by ControllerHandle and ChildHandle. See Table 9-1 for legal values. A DefaultType of 0x00000000 must be supported by this protocol.
273 ActionRequired - A pointer to the action that the calling agent is required to perform when this function returns. See "Related Definitions" in Section 9.1for a list of the actions that the calling agent is required to perform prior to accessing ControllerHandle again.
274
275 Returns:
276 EFI_SUCCESS - The driver specified by This successfully forced the default configuration options on the controller specified by ControllerHandle and ChildHandle.
277 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
278 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
279 EFI_INVALID_PARAMETER - ActionRequired is NULL.
280 EFI_UNSUPPORTED - The driver specified by This does not support forcing the default configuration options on the controller specified by ControllerHandle and ChildHandle.
281 EFI_UNSUPPORTED - The driver specified by This does not support the configuration type specified by DefaultType.
282 EFI_DEVICE_ERROR - A device error occurred while attempt to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.
283 EFI_OUT_RESOURCES - There are not enough resources available to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.
284
285 --*/
286 EFI_STATUS
287 EFIAPI
288 EmuBlockIoDriverConfigurationForceDefaults (
289 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
290 IN EFI_HANDLE ControllerHandle,
291 IN EFI_HANDLE ChildHandle OPTIONAL,
292 IN UINT32 DefaultType,
293 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
294 )
295 {
296 EFI_STATUS Status;
297 EFI_BLOCK_IO_PROTOCOL *BlockIo;
298
299 if (ChildHandle != NULL) {
300 return EFI_UNSUPPORTED;
301 }
302
303 if (ActionRequired == NULL || ControllerHandle == NULL) {
304 return EFI_INVALID_PARAMETER;
305 }
306
307 //
308 // Validate controller handle
309 //
310 Status = gBS->OpenProtocol (
311 ControllerHandle,
312 &gEmuIoThunkProtocolGuid,
313 (VOID **)&BlockIo,
314 gEmuBlockIoDriverBinding.DriverBindingHandle,
315 ControllerHandle,
316 EFI_OPEN_PROTOCOL_BY_DRIVER
317 );
318
319 if (!EFI_ERROR (Status)) {
320 gBS->CloseProtocol (
321 ControllerHandle,
322 &gEmuIoThunkProtocolGuid,
323 gEmuBlockIoDriverBinding.DriverBindingHandle,
324 ControllerHandle
325 );
326
327 return EFI_UNSUPPORTED;
328 }
329
330 if (Status == EFI_UNSUPPORTED) {
331 return Status;
332 } else if (Status != EFI_ALREADY_STARTED) {
333 return EFI_INVALID_PARAMETER;
334 }
335
336 *ActionRequired = EfiDriverConfigurationActionNone;
337 return EFI_SUCCESS;
338 }