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