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