]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Bus/Pci/IdeBus/Dxe/DriverConfiguration.c
Initial import.
[mirror_edk2.git] / EdkModulePkg / Bus / Pci / IdeBus / Dxe / 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
20 #include "IDEBus.h"
21
22 CHAR16 *OptionString[4] = {
23 L"Enable Primary Master (Y/N)? -->",
24 L"Enable Primary Slave (Y/N)? -->",
25 L"Enable Secondary Master (Y/N)? -->",
26 L"Enable Secondary Slave (Y/N)? -->"
27 };
28 //
29 // EFI Driver Configuration Functions
30 //
31 EFI_STATUS
32 IDEBusDriverConfigurationSetOptions (
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 IDEBusDriverConfigurationOptionsValid (
42 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
43 IN EFI_HANDLE ControllerHandle,
44 IN EFI_HANDLE ChildHandle OPTIONAL
45 );
46
47 EFI_STATUS
48 IDEBusDriverConfigurationForceDefaults (
49 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
50 IN EFI_HANDLE ControllerHandle,
51 IN EFI_HANDLE ChildHandle OPTIONAL,
52 IN UINT32 DefaultType,
53 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
54 );
55
56 //
57 // EFI Driver Configuration Protocol
58 //
59 EFI_DRIVER_CONFIGURATION_PROTOCOL gIDEBusDriverConfiguration = {
60 IDEBusDriverConfigurationSetOptions,
61 IDEBusDriverConfigurationOptionsValid,
62 IDEBusDriverConfigurationForceDefaults,
63 "eng"
64 };
65
66 EFI_STATUS
67 GetResponse (
68 VOID
69 )
70 /*++
71
72 Routine Description:
73
74 TODO: Add function description
75
76 Arguments:
77
78 None
79
80 Returns:
81
82 EFI_ABORTED - TODO: Add description for return value
83 EFI_SUCCESS - TODO: Add description for return value
84 EFI_NOT_FOUND - TODO: Add description for return value
85
86 --*/
87 {
88 EFI_STATUS Status;
89 EFI_INPUT_KEY Key;
90
91 while (TRUE) {
92 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
93 if (!EFI_ERROR (Status)) {
94 if (Key.ScanCode == SCAN_ESC) {
95 return EFI_ABORTED;
96 }
97
98 switch (Key.UnicodeChar) {
99
100 //
101 // fall through
102 //
103 case L'y':
104 case L'Y':
105 gST->ConOut->OutputString (gST->ConOut, L"Y\n");
106 return EFI_SUCCESS;
107
108 //
109 // fall through
110 //
111 case L'n':
112 case L'N':
113 gST->ConOut->OutputString (gST->ConOut, L"N\n");
114 return EFI_NOT_FOUND;
115 }
116
117 }
118 }
119 }
120
121 EFI_STATUS
122 IDEBusDriverConfigurationSetOptions (
123 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
124 IN EFI_HANDLE ControllerHandle,
125 IN EFI_HANDLE ChildHandle OPTIONAL,
126 IN CHAR8 *Language,
127 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
128 )
129 /*++
130
131 Routine Description:
132 Allows the user to set controller specific options for a controller that a
133 driver is currently managing.
134
135 Arguments:
136 This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL
137 instance.
138 ControllerHandle - The handle of the controller to set options on.
139 ChildHandle - The handle of the child controller to set options on.
140 This is an optional parameter that may be NULL.
141 It will be NULL for device drivers, and for a bus drivers
142 that wish to set options for the bus controller.
143 It will not be NULL for a bus driver that wishes to set
144 options for one of its child controllers.
145 Language - A pointer to a three character ISO 639-2 language
146 identifier. This is the language of the user interface
147 that should be presented to the user, and it must match
148 one of the languages specified in SupportedLanguages.
149 The number of languages supported by a driver is up to
150 the driver writer.
151 ActionRequired - A pointer to the action that the calling agent is
152 required to perform when this function returns.
153 See "Related Definitions" for a list of the actions that
154 the calling agent is required to perform prior to
155 accessing ControllerHandle again.
156
157 Returns:
158 EFI_SUCCESS - The driver specified by This successfully set the
159 configuration options for the controller specified
160 by ControllerHandle..
161 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
162 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a
163 valid EFI_HANDLE.
164 EFI_INVALID_PARAMETER - ActionRequired is NULL.
165 EFI_UNSUPPORTED - The driver specified by This does not support
166 setting configuration options for the controller
167 specified by ControllerHandle and ChildHandle.
168 EFI_UNSUPPORTED - The driver specified by This does not support the
169 language specified by Language.
170 EFI_DEVICE_ERROR - A device error occurred while attempt to set the
171 configuration options for the controller specified
172 by ControllerHandle and ChildHandle.
173 EFI_OUT_RESOURCES - There are not enough resources available to set the
174 configuration options for the controller specified
175 by ControllerHandle and ChildHandle.
176
177 --*/
178 {
179 EFI_STATUS Status;
180 UINT8 Value;
181 UINT8 NewValue;
182 UINTN DataSize;
183 UINTN Index;
184 UINT32 Attributes;
185
186 if (ChildHandle != NULL) {
187 return EFI_UNSUPPORTED;
188 }
189
190 *ActionRequired = EfiDriverConfigurationActionNone;
191
192 DataSize = sizeof (Value);
193 Status = gRT->GetVariable (
194 L"Configuration",
195 &gEfiCallerIdGuid,
196 &Attributes,
197 &DataSize,
198 &Value
199 );
200
201 gST->ConOut->OutputString (gST->ConOut, L"IDE Bus Driver Configuration\n");
202 gST->ConOut->OutputString (gST->ConOut, L"===============================\n");
203
204 NewValue = 0;
205 for (Index = 0; Index < 4; Index++) {
206 gST->ConOut->OutputString (gST->ConOut, OptionString[Index]);
207
208 Status = GetResponse ();
209 if (Status == EFI_ABORTED) {
210 return EFI_SUCCESS;
211 }
212
213 if (!EFI_ERROR (Status)) {
214 NewValue |= (UINT8) (1 << Index);
215 }
216 }
217
218 if (EFI_ERROR (Status) || (NewValue != Value)) {
219 gRT->SetVariable (
220 L"Configuration",
221 &gEfiCallerIdGuid,
222 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
223 sizeof (NewValue),
224 &NewValue
225 );
226
227 *ActionRequired = EfiDriverConfigurationActionRestartController;
228 } else {
229 *ActionRequired = EfiDriverConfigurationActionNone;
230 }
231
232 return EFI_SUCCESS;
233 }
234
235 EFI_STATUS
236 IDEBusDriverConfigurationOptionsValid (
237 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
238 IN EFI_HANDLE ControllerHandle,
239 IN EFI_HANDLE ChildHandle OPTIONAL
240 )
241 /*++
242
243 Routine Description:
244 Tests to see if a controller's current configuration options are valid.
245
246 Arguments:
247 This - A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL
248 instance.
249 ControllerHandle - The handle of the controller to test if it's current
250 configuration options are valid.
251 ChildHandle - The handle of the child controller to test if it's
252 current
253 configuration options are valid. This is an optional
254 parameter that may be NULL. It will be NULL for device
255 drivers. It will also be NULL for a bus drivers that
256 wish to test the configuration options for the bus
257 controller. It will not be NULL for a bus driver that
258 wishes to test configuration options for one of
259 its child controllers.
260
261 Returns:
262 EFI_SUCCESS - The controller specified by ControllerHandle and
263 ChildHandle that is being managed by the driver
264 specified by This has a valid set of configuration
265 options.
266 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
267 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid
268 EFI_HANDLE.
269 EFI_UNSUPPORTED - The driver specified by This is not currently
270 managing the controller specified by
271 ControllerHandle and ChildHandle.
272 EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
273 ChildHandle that is being managed by the driver
274 specified by This has an invalid set of
275 configuration options.
276
277 --*/
278 {
279 EFI_STATUS Status;
280 UINT8 Value;
281 UINTN DataSize;
282 UINT32 Attributes;
283
284 if (ChildHandle != NULL) {
285 return EFI_UNSUPPORTED;
286 }
287
288 DataSize = sizeof (Value);
289 Status = gRT->GetVariable (
290 L"Configuration",
291 &gEfiCallerIdGuid,
292 &Attributes,
293 &DataSize,
294 &Value
295 );
296 if (EFI_ERROR (Status) || Value > 0x0f) {
297 return EFI_DEVICE_ERROR;
298 }
299
300 return EFI_SUCCESS;
301 }
302
303 EFI_STATUS
304 IDEBusDriverConfigurationForceDefaults (
305 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
306 IN EFI_HANDLE ControllerHandle,
307 IN EFI_HANDLE ChildHandle OPTIONAL,
308 IN UINT32 DefaultType,
309 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
310 )
311 /*++
312
313 Routine Description:
314 Forces a driver to set the default configuration options for a controller.
315
316 Arguments:
317 This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL
318 instance.
319 ControllerHandle - The handle of the controller to force default
320 configuration options on.
321 ChildHandle - The handle of the child controller to force default
322 configuration options on This is an optional parameter
323 that may be NULL. It will be NULL for device drivers.
324 It will also be NULL for a bus drivers that wish to
325 force default configuration options for the bus
326 controller. It will not be NULL for a bus driver that
327 wishes to force default configuration options for one
328 of its child controllers.
329 DefaultType - The type of default configuration options to force on
330 the controller specified by ControllerHandle and
331 ChildHandle. See Table 9-1 for legal values.
332 A DefaultType of 0x00000000 must be supported
333 by this protocol.
334 ActionRequired - A pointer to the action that the calling agent
335 is required to perform when this function returns.
336
337
338 Returns:
339 EFI_SUCCESS - The driver specified by This successfully forced
340 the default configuration options on the
341 controller specified by ControllerHandle and
342 ChildHandle.
343 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
344 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a
345 valid EFI_HANDLE.
346 EFI_INVALID_PARAMETER - ActionRequired is NULL.
347 EFI_UNSUPPORTED - The driver specified by This does not support
348 forcing the default configuration options on
349 the controller specified by ControllerHandle
350 and ChildHandle.
351 EFI_UNSUPPORTED - The driver specified by This does not support
352 the configuration type specified by DefaultType.
353 EFI_DEVICE_ERROR - A device error occurred while attempt to force
354 the default configuration options on the controller
355 specified by ControllerHandle and ChildHandle.
356 EFI_OUT_RESOURCES - There are not enough resources available to force
357 the default configuration options on the controller
358 specified by ControllerHandle and ChildHandle.
359
360 --*/
361 {
362 UINT8 Value;
363
364 if (ChildHandle != NULL) {
365 return EFI_UNSUPPORTED;
366 }
367
368 Value = 0x0f;
369 gRT->SetVariable (
370 L"Configuration",
371 &gEfiCallerIdGuid,
372 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
373 sizeof (Value),
374 &Value
375 );
376 *ActionRequired = EfiDriverConfigurationActionRestartController;
377 return EFI_SUCCESS;
378 }