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