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