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